Browse Source

Merge pull request #663 from julien-moreau/master

Adding glTF file loader
David Catuhe 10 years ago
parent
commit
e330b737b4

+ 44 - 0
loaders/glTF/README.md

@@ -0,0 +1,44 @@
+# Babylon.js glTF File Loader
+
+# Usage
+The glTF file loader is a SceneLoader plugin.
+Just reference the loader in your HTML file:
+
+```
+<script src="babylon.2.1.js"></script>
+<script src="babylon.glTFFileLoader.js"></script>
+```
+
+And then, call the scene loader:
+```
+BABYLON.SceneLoader.Load("./", "duck.gltf", engine, function (scene) { 
+   // do somethings with the scene
+});
+```
+
+## Supported features
+* Load scenes (SceneLoader.Load)
+* Import geometries
+    * From binary files
+    * From base64 buffers
+* Import lights
+* Import cameras
+* Import and set custom shaders (if no shaders, the Babylon.js default material is applied)
+    * Automatically bind attributes
+    * Automatically bind matrices
+    * Set uniforms
+* Import and set animations
+
+## Unsupported features
+* ImportMesh function
+* Skinning
+    * Skeletons
+    * Bones
+    * Hardware skinning (shaders support)
+* Shaders
+    * Set uniforms with types MAT2 and MAT3
+* Handle dummy nodes (empty nodes)
+
+## To improve
+* Y is UP
+* Test on more animations

File diff suppressed because it is too large
+ 1012 - 0
loaders/glTF/babylon.glTFFileLoader.js


File diff suppressed because it is too large
+ 1192 - 0
loaders/glTF/babylon.glTFFileLoader.ts


+ 1 - 0
loaders/glTF/babylon.glTFFileLoaderInterfaces.js

@@ -0,0 +1 @@
+//# sourceMappingURL=babylon.glTFFileLoaderInterfaces.js.map

+ 266 - 0
loaders/glTF/babylon.glTFFileLoaderInterfaces.ts

@@ -0,0 +1,266 @@
+module BABYLON {
+    /**
+    * Interfaces
+    */
+    export interface IGLTFChildRootProperty {
+        name?: string;
+    }
+
+    export interface IGLTFAccessor extends IGLTFChildRootProperty {
+        bufferView: string;
+        byteOffset: number;
+        byteStride: number;
+        count: number;
+        type: string;
+        componentType: EComponentType;
+
+        max?: number[],
+        min?: number[],
+        name?: string;
+    }
+
+    export interface IGLTFBufferView extends IGLTFChildRootProperty {
+        buffer: string;
+        byteOffset: number;
+        byteLength: number;
+
+        target?: number;
+    }
+
+    export interface IGLTFBuffer extends IGLTFChildRootProperty {
+        uri: string;
+
+        byteLength?: number;
+        type?: string;
+    }
+
+    export interface IGLTFShader extends IGLTFChildRootProperty {
+        uri: string;
+        type: EShaderType;
+    }
+
+    export interface IGLTFProgram extends IGLTFChildRootProperty {
+        attributes: string[];
+        fragmentShader: string;
+        vertexShader: string;
+    }
+
+    export interface IGLTFTechniqueParameter {
+        type: number;
+
+        count?: number;
+        semantic?: string;
+        node?: string;
+        value?: number|boolean|string|Array<any>;
+        source?: string;
+    }
+
+    export interface IGLTFTechniquePassCommonProfile {
+        lightingModel: string;
+        texcoordBindings: Object;
+
+        parameters?: Array<any>;
+    }
+
+    export interface IGLTFTechniquePassInstanceProgram {
+        program: string;
+
+        attributes?: Object;
+        uniforms: Object;
+    }
+
+    export interface IGLTFTechniquePassStates {
+        enable: number[];
+        functions: Object;
+    }
+
+    export interface IGLTFTechniquePassDetails {
+        commonProfile: IGLTFTechniquePassCommonProfile;
+        type: string;
+    }
+
+    export interface IGLTFTechniquePass {
+        details: IGLTFTechniquePassDetails;
+        instanceProgram: IGLTFTechniquePassInstanceProgram;
+        states: Object;
+    }
+
+    export interface IGLTFTechnique extends IGLTFChildRootProperty {
+        parameters: Object;
+        pass: string;
+        passes: Object;
+    }
+
+    export interface IGLTFMaterialInstanceTechnique {
+        technique: string;
+
+        values?: Object;
+    }
+
+    export interface IGLTFMaterial extends IGLTFChildRootProperty {
+        instanceTechnique: IGLTFMaterialInstanceTechnique;
+    }
+
+    export interface IGLTFMeshPrimitive {
+        attributes: Object;
+        indices: string;
+        material: string;
+
+        primitive?: number;
+    }
+
+    export interface IGLTFMesh extends IGLTFChildRootProperty {
+        primitives: IGLTFMeshPrimitive[];
+    }
+
+    export interface IGLTFImage extends IGLTFChildRootProperty {
+        uri: string;
+    }
+
+    export interface IGLTFSampler extends IGLTFChildRootProperty {
+        magFilter?: number;
+        minFilter?: number;
+        wrapS?: number;
+        wrapT?: number;
+    }
+
+    export interface IGLTFTexture extends IGLTFChildRootProperty {
+        sampler: string;
+        source: string;
+
+        format?: number;
+        internalFormat?: number;
+        target?: number;
+        type?: number;
+    }
+
+    export interface IGLTFAmbienLight {
+        color?: number[];
+    }
+
+    export interface IGLTFDirectionalLight {
+        color?: number[];
+    }
+
+    export interface IGLTFPointLight {
+        color?: number[];
+        constantAttenuation?: number;
+        linearAttenuation?: number;
+        quadraticAttenuation?: number;
+    }
+
+    export interface IGLTFSpotLight {
+        color?: number[];
+        constantAttenuation?: number;
+        fallOfAngle?: number;
+        fallOffExponent?: number;
+        linearAttenuation?: number;
+        quadraticAttenuation?: number;
+    }
+
+    export interface IGLTFLight extends IGLTFChildRootProperty {
+        type: string;
+    }
+
+    export interface IGLTFCameraOrthographic {
+        xmag: number;
+        ymag: number;
+        zfar: number;
+        znear: number;
+    }
+
+    export interface IGLTFCameraPerspective {
+        aspectRatio: number;
+        yfov: number;
+        zfar: number;
+        znear: number;
+    }
+
+    export interface IGLTFCamera extends IGLTFChildRootProperty {
+        type: string;
+    }
+
+    export interface IGLTFAnimationChannelTarget {
+        id: string;
+        path: string;
+    }
+
+    export interface IGLTFAnimationChannel {
+        sampler: string;
+        target: IGLTFAnimationChannelTarget;
+    }
+
+    export interface IGLTFAnimationSampler {
+        input: string;
+        output: string;
+
+        interpolation?: string;
+    }
+
+    export interface IGLTFAnimation extends IGLTFChildRootProperty {
+        channels?: IGLTFAnimationChannel[];
+        parameters?: Object;
+        samplers?: Object;
+    }
+
+    export interface IGLTFNodeInstanceSkin {
+        skeletons: string[];
+        skin: string;
+        meshes: string[];
+    }
+
+    export interface IGLTFSkins extends IGLTFChildRootProperty {
+        bindShapeMatrix: number[];
+        inverseBindMatrices: string;
+        jointNames: string[];
+    }
+
+    export interface IGLTFNode extends IGLTFChildRootProperty {
+        camera?: string;
+        children: string[];
+        instanceSkin?: IGLTFNodeInstanceSkin;
+        jointName?: string;
+        light?: string;
+        matrix: number[];
+        meshes?: string[];
+        rotation?: number[];
+        scale?: number[];
+        translation?: number[];
+    }
+
+    export interface IGLTFScene extends IGLTFChildRootProperty {
+        nodes: string[];
+    }
+
+    /**
+    * Runtime
+    */
+    export interface IGLTFRuntime {
+        accessors: Object;
+        buffers: Object;
+        bufferViews: Object;
+        meshes: Object;
+        lights: Object;
+        cameras: Object;
+        nodes: Object;
+        images: Object;
+        textures: Object;
+        shaders: Object;
+        programs: Object;
+        samplers: Object;
+        techniques: Object;
+        materials: Object;
+        animations: Object;
+        skins: Object;
+        currentScene: Object;
+
+        buffersCount: number,
+        shaderscount: number,
+
+        scene: Scene;
+        rootUrl: string;
+        loadedBuffers: number;
+        loadedShaders: number;
+        arrayBuffers: Object;
+    }
+}