Pārlūkot izejas kodu

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 8 gadi atpakaļ
vecāks
revīzija
35789c8fb1

+ 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);
         }
 
         /**

+ 1 - 1
src/Materials/babylon.pbrMaterial.ts

@@ -996,7 +996,7 @@
 
             // Attribs
             if (mesh) {
-                if (!mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
+                if (!scene.getEngine().getCaps().standardDerivatives && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
                     mesh.createNormals(true);
                     Tools.Warn("PBRMaterial: Normals have been created for the mesh: " + mesh.name);
                 }

+ 2 - 2
src/Mesh/babylon.abstractMesh.ts

@@ -2180,8 +2180,8 @@
             } else {
                 normals = [];
             }
-            
-            VertexData.ComputeNormals(positions, indices, normals);
+
+            VertexData.ComputeNormals(positions, indices, normals, { useRightHandedSystem: this.getScene().useRightHandedSystem });
             this.setVerticesData(VertexBuffer.NormalKind, normals, updatable);
         } 
 

+ 6 - 4
src/Mesh/babylon.mesh.vertexData.ts

@@ -2126,7 +2126,7 @@
          * bInfo : optional bounding info, required for facetPartitioning computation
          */
         public static ComputeNormals(positions: any, indices: any, normals: any,
-            options?: { facetNormals?: any, facetPositions?: any, facetPartitioning?: any, ratio?: number, bInfo?: any, bbSize?: Vector3, subDiv?: any}): void {
+            options?: { facetNormals?: any, facetPositions?: any, facetPartitioning?: any, ratio?: number, bInfo?: any, bbSize?: Vector3, subDiv?: any, useRightHandedSystem?: boolean }): void {
 
             // temporary scalar variables
             var index = 0;                      // facet index     
@@ -2152,10 +2152,12 @@
             var computeFacetNormals = false;
             var computeFacetPositions = false;
             var computeFacetPartitioning = false;
+            var faceNormalSign = 1;
             if (options) {
                 computeFacetNormals = (options.facetNormals) ? true : false;
                 computeFacetPositions = (options.facetPositions) ? true : false;
                 computeFacetPartitioning = (options.facetPartitioning) ? true : false;
+                faceNormalSign = (options.useRightHandedSystem === true) ? -1 : 1;
             }
 
             // facetPartitioning reinit if needed
@@ -2215,9 +2217,9 @@
                 p3p2z = positions[v3z] - positions[v2z];
 
                 // compute the face normal with the cross product
-                faceNormalx = p1p2y * p3p2z - p1p2z * p3p2y;
-                faceNormaly = p1p2z * p3p2x - p1p2x * p3p2z;
-                faceNormalz = p1p2x * p3p2y - p1p2y * p3p2x;
+                faceNormalx = faceNormalSign * (p1p2y * p3p2z - p1p2z * p3p2y);
+                faceNormaly = faceNormalSign * (p1p2z * p3p2x - p1p2x * p3p2z);
+                faceNormalz = faceNormalSign * (p1p2x * p3p2y - p1p2y * p3p2x);
                 // normalize this normal and store it in the array facetData
                 length = Math.sqrt(faceNormalx * faceNormalx + faceNormaly * faceNormaly + faceNormalz * faceNormalz);
                 length = (length === 0) ? 1.0 : length;

+ 1 - 1
src/Shaders/pbr.fragment.fx

@@ -144,7 +144,7 @@ void main(void) {
 #ifdef NORMAL
 	vec3 normalW = normalize(vNormalW);
 #else
-	vec3 normalW = vec3(1.0, 1.0, 1.0);
+	vec3 normalW = normalize(cross(dFdx(vPositionW), dFdy(vPositionW)));
 #endif
 
 #include<bumpFragment>