瀏覽代碼

Merge pull request #2076 from bghgary/glTFFileLoader

glTF 2.0 loader updates
David Catuhe 8 年之前
父節點
當前提交
6acdd9ee16

+ 2 - 2
loaders/src/glTF/2.0/babylon.glTFLoader.ts

@@ -1154,9 +1154,9 @@ module BABYLON.GLTF2 {
         }
 
         private static _createTextureAsync(runtime: IGLTFRuntime, texture: IGLTFTexture, texCoord: number, url: string, onSuccess: (babylonTexture: Texture) => void, onError: () => void): void {
-            var sampler: IGLTFSampler = texture.sampler ? runtime.gltf.samplers[texture.sampler] : {};
+            var sampler: IGLTFSampler = (texture.sampler === undefined ? {} : runtime.gltf.samplers[texture.sampler]);
             var noMipMaps = (sampler.minFilter === ETextureMinFilter.NEAREST || sampler.minFilter === ETextureMinFilter.LINEAR);
-            var samplingMode = Texture.BILINEAR_SAMPLINGMODE;
+            var samplingMode = GLTFUtils.GetTextureFilterMode(sampler.minFilter);
 
             var babylonTexture = new Texture(url, runtime.babylonScene, noMipMaps, true, samplingMode, () => {
                 onSuccess(babylonTexture);

+ 2 - 55
loaders/src/glTF/2.0/babylon.glTFLoaderInterfaces.ts

@@ -4,11 +4,6 @@ module BABYLON.GLTF2 {
     /**
     * Enums
     */
-    export enum EBufferViewTarget {
-        ARRAY_BUFFER = 34962,
-        ELEMENT_ARRAY_BUFFER = 34963
-    }
-
     export enum EComponentType {
         BYTE = 5120,
         UNSIGNED_BYTE = 5121,
@@ -28,30 +23,6 @@ module BABYLON.GLTF2 {
         TRIANGLE_FAN = 6
     }
 
-    export enum EParameterType {
-        BYTE = 5120,
-        UNSIGNED_BYTE = 5121,
-        SHORT = 5122,
-        UNSIGNED_SHORT = 5123,
-        INT = 5124,
-        UNSIGNED_INT = 5125,
-        FLOAT = 5126,
-        FLOAT_VEC2 = 35664,
-        FLOAT_VEC3 = 35665,
-        FLOAT_VEC4 = 35666,
-        INT_VEC2 = 35667,
-        INT_VEC3 = 35668,
-        INT_VEC4 = 35669,
-        BOOL = 35670,
-        BOOL_VEC2 = 35671,
-        BOOL_VEC3 = 35672,
-        BOOL_VEC4 = 35673,
-        FLOAT_MAT2 = 35674,
-        FLOAT_MAT3 = 35675,
-        FLOAT_MAT4 = 35676,
-        SAMPLER_2D = 35678
-    }
-
     export enum ETextureMagFilter {
         NEAREST = 9728,
         LINEAR = 9729,
@@ -66,25 +37,6 @@ module BABYLON.GLTF2 {
         LINEAR_MIPMAP_LINEAR = 9987
     }
 
-    export enum ETextureFormat {
-        ALPHA = 6406,
-        RGB = 6407,
-        RGBA = 6408,
-        LUMINANCE = 6409,
-        LUMINANCE_ALPHA = 6410
-    }
-
-    export enum ETextureTarget {
-        TEXTURE_2D = 3553
-    }
-
-    export enum ETextureType {
-        UNSIGNED_BYTE = 5121,
-        UNSIGNED_SHORT_5_6_5 = 33635,
-        UNSIGNED_SHORT_4_4_4_4 = 32819,
-        UNSIGNED_SHORT_5_5_5_1 = 32820
-    }
-
     export enum ETextureWrapMode {
         CLAMP_TO_EDGE = 33071,
         MIRRORED_REPEAT = 33648,
@@ -175,10 +127,9 @@ module BABYLON.GLTF2 {
 
     export interface IGLTFBufferView extends IGLTFChildRootProperty {
         buffer: number;
-        byteOffset: number;
+        byteOffset?: number;
         byteLength: number;
         byteStride?: number;
-        target?: EBufferViewTarget;
     }
 
     export interface IGLTFCameraOrthographic extends IGLTFProperty {
@@ -286,12 +237,8 @@ module BABYLON.GLTF2 {
     }
 
     export interface IGLTFTexture extends IGLTFChildRootProperty {
-        format?: ETextureFormat;
-        internalFormat?: ETextureFormat;
-        sampler: number;
+        sampler?: number;
         source: number;
-        target?: ETextureTarget;
-        type?: ETextureType;
 
         // Babylon.js values (optimize, one per coordinate index)
         babylonTextures: Texture[];

+ 3 - 2
loaders/src/glTF/2.0/babylon.glTFLoaderUtils.ts

@@ -77,7 +77,7 @@ module BABYLON.GLTF2 {
         }
 
         public static GetBufferFromBufferView(runtime: IGLTFRuntime, bufferView: IGLTFBufferView, byteOffset: number, byteLength: number, componentType: EComponentType): ArrayBufferView {
-            var byteOffset = bufferView.byteOffset + byteOffset;
+            byteOffset += (bufferView.byteOffset || 0);
 
             var loadedBufferView = runtime.gltf.buffers[bufferView.buffer].loadedBufferView;
             if (byteOffset + byteLength > loadedBufferView.byteLength) {
@@ -104,8 +104,9 @@ module BABYLON.GLTF2 {
          */
         public static GetBufferFromAccessor(runtime: IGLTFRuntime, accessor: IGLTFAccessor): any {
             var bufferView = runtime.gltf.bufferViews[accessor.bufferView];
+            var byteOffset = accessor.byteOffset || 0;
             var byteLength = accessor.count * GLTFUtils.GetByteStrideFromType(accessor);
-            return GLTFUtils.GetBufferFromBufferView(runtime, bufferView, accessor.byteOffset, byteLength, accessor.componentType);
+            return GLTFUtils.GetBufferFromBufferView(runtime, bufferView, byteOffset, byteLength, accessor.componentType);
         }
 
         /**