Procházet zdrojové kódy

removing at ignores

Kacey Coley před 7 roky
rodič
revize
ae9fb40f16

+ 2 - 5
serializers/src/glTF/2.0/babylon.glTFAnimation.ts

@@ -66,7 +66,6 @@ module BABYLON.GLTF2 {
      */
     export class _GLTFAnimation {
         /**
-         * @ignore
          * 
          * Creates glTF channel animation from BabylonJS animation.
          * @param babylonMesh - BabylonJS mesh.
@@ -165,7 +164,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
          * 
          * @param babylonMesh 
          * @param runtimeGLTFAnimation 
@@ -211,7 +209,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
          * 
          * @param babylonScene 
          * @param glTFAnimations 
@@ -580,7 +577,7 @@ module BABYLON.GLTF2 {
                         break;
                     }
                     default: {
-                        throw new Error(`glTFAnimation: Unsupported component type "${componentName}" for scale animation!`);
+                        Tools.Error(`glTFAnimation: Unsupported component type "${componentName}" for scale animation!`);
                     }
                 }
 
@@ -601,7 +598,7 @@ module BABYLON.GLTF2 {
                 outputs.push(value);
             }
             else {
-                throw new Error('glTFAnimation: Unsupported key frame values for animation!');
+                Tools.Error('glTFAnimation: Unsupported key frame values for animation!');
             }
         }
 

+ 0 - 16
serializers/src/glTF/2.0/babylon.glTFExporter.ts

@@ -108,8 +108,6 @@ module BABYLON.GLTF2 {
         private shouldExportMesh: ((mesh: Mesh) => boolean);
 
         /**
-         * @ignore
-         * 
          * Creates a glTF Exporter instance, which can accept optional exporter options
          * @param babylonScene Babylon scene object
          * @param options Options to modify the behavior of the exporter
@@ -267,8 +265,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Generates data for .gltf and .bin files based on the glTF prefix string
          * @param glTFPrefix Text to use when prefixing a glTF file
          * @returns GLTFData with glTF file data
@@ -318,8 +314,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Generates a glb file from the json and binary data
          * Returns an object with the glb file name as the key and data as the value
          * @param glTFPrefix 
@@ -793,8 +787,6 @@ module BABYLON.GLTF2 {
             this._dataView = new DataView(this._arrayBuffer);
         }
         /**
-         * @ignore
-         * 
          * Get an array buffer with the length of the byte offset
          * @returns ArrayBuffer resized to the byte offset
          */
@@ -803,8 +795,6 @@ module BABYLON.GLTF2 {
             return this._arrayBuffer;
         }
         /**
-         * @ignore
-         * 
          * Get the byte offset of the array buffer
          * @returns byte offset
          */
@@ -812,8 +802,6 @@ module BABYLON.GLTF2 {
             return this._byteOffset;
         }
         /**
-         * @ignore
-         * 
          * Stores an UInt8 in the array buffer
          * @param entry 
          */
@@ -824,8 +812,6 @@ module BABYLON.GLTF2 {
             this._dataView.setUint8(this._byteOffset++, entry);
         }
         /**
-         * @ignore
-         * 
          * Stores a Float32 in the array buffer
          * @param entry 
          */
@@ -837,8 +823,6 @@ module BABYLON.GLTF2 {
             this._byteOffset += 4;
         }
         /**
-         * @ignore
-         * 
          * Stores an UInt32 in the array buffer
          * @param entry 
          */

+ 83 - 90
serializers/src/glTF/2.0/babylon.glTFMaterial.ts

@@ -83,8 +83,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Gets the materials from a Babylon scene and converts them to glTF materials
          * @param scene babylonjs scene
          * @param mimeType texture mime type
@@ -107,14 +105,12 @@ module BABYLON.GLTF2 {
                     _GLTFMaterial._ConvertPBRMaterial(babylonMaterial, mimeType, images, textures, materials, imageData, hasTextureCoords);
                 }
                 else {
-                    throw new Error("Unsupported material type: " + babylonMaterial.name);
+                    Tools.Error("Unsupported material type: " + babylonMaterial.name);
                 }
             }
         }
 
         /**
-         * @ignore
-         * 
          * Makes a copy of the glTF material without the texture parameters
          * @param originalMaterial original glTF material
          * @returns glTF material without texture parameters
@@ -139,8 +135,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Specifies if the material has any texture parameters present
          * @param material glTF Material
          * @returns boolean specifying if texture parameters are present
@@ -160,8 +154,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Converts a Babylon StandardMaterial to a glTF Metallic Roughness Material
          * @param babylonStandardMaterial 
          * @returns glTF Metallic Roughness Material representation
@@ -223,8 +215,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Computes the metallic factor
          * @param diffuse diffused value
          * @param specular specular value
@@ -245,13 +235,11 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Gets the glTF alpha mode from the Babylon Material
          * @param babylonMaterial Babylon Material
          * @returns The Babylon alpha mode value
          */
-        public static _GetAlphaMode(babylonMaterial: Material): MaterialAlphaMode {
+        public static _GetAlphaMode(babylonMaterial: Material): Nullable<MaterialAlphaMode> {
             if (babylonMaterial instanceof StandardMaterial) {
                 const babylonStandardMaterial = babylonMaterial as StandardMaterial;
                 if ((babylonStandardMaterial.alpha != 1.0) ||
@@ -281,7 +269,8 @@ module BABYLON.GLTF2 {
                         return MaterialAlphaMode.BLEND;
                     }
                     default: {
-                        throw new Error("Unsupported alpha mode " + babylonPBRMetallicRoughness.transparencyMode);
+                        Tools.Error("Unsupported alpha mode " + babylonPBRMetallicRoughness.transparencyMode);
+                        return null;
                     }
                 }
             }
@@ -303,18 +292,18 @@ module BABYLON.GLTF2 {
                         return MaterialAlphaMode.BLEND;
                     }
                     default: {
-                        throw new Error("Unsupported alpha mode " + babylonPBRMaterial.transparencyMode);
+                        Tools.Error("Unsupported alpha mode " + babylonPBRMaterial.transparencyMode);
+                        return null;
                     }
                 }
             }
             else {
-                throw new Error("Unsupported Babylon material type");
+                Tools.Error("Unsupported Babylon material type");
+                return null;
             }
         }
 
         /**
-         * @ignore
-         * 
          * Converts a Babylon Standard Material to a glTF Material
          * @param babylonStandardMaterial BJS Standard Material
          * @param mimeType mime type to use for the textures
@@ -385,8 +374,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
          * @param babylonPBRMetalRoughMaterial BJS PBR Metallic Roughness Material
          * @param mimeType mime type to use for the textures
@@ -457,11 +444,12 @@ module BABYLON.GLTF2 {
             }
             if (babylonPBRMetalRoughMaterial.transparencyMode != null) {
                 const alphaMode = _GLTFMaterial._GetAlphaMode(babylonPBRMetalRoughMaterial);
-
-                if (alphaMode !== MaterialAlphaMode.OPAQUE) { //glTF defaults to opaque
-                    glTFMaterial.alphaMode = alphaMode;
-                    if (alphaMode === MaterialAlphaMode.BLEND) {
-                        glTFMaterial.alphaCutoff = babylonPBRMetalRoughMaterial.alphaCutOff;
+                if (alphaMode) {
+                    if (alphaMode !== MaterialAlphaMode.OPAQUE) { //glTF defaults to opaque
+                        glTFMaterial.alphaMode = alphaMode;
+                        if (alphaMode === MaterialAlphaMode.BLEND) {
+                            glTFMaterial.alphaCutoff = babylonPBRMetalRoughMaterial.alphaCutOff;
+                        }
                     }
                 }
             }
@@ -572,7 +560,8 @@ module BABYLON.GLTF2 {
 
             const scene = diffuseTexture ? diffuseTexture.getScene() : specularGlossinessTexture.getScene();
             if (!scene) {
-                throw new Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!");
+                Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Scene from textures is missing!");
+                return null;
             }
 
             const resizedTextures = this._ResizeTexturesToSameDimensions(diffuseTexture, specularGlossinessTexture, scene);
@@ -590,7 +579,8 @@ module BABYLON.GLTF2 {
                 diffuseBuffer = (resizedTextures.texture1.readPixels()) as Uint8Array;
             }
             else {
-                throw new Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: " + resizedTextures.texture1.name);
+                Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: " + resizedTextures.texture1.name);
+                return null;
             }
             pixels = resizedTextures.texture2.readPixels();
 
@@ -598,7 +588,8 @@ module BABYLON.GLTF2 {
                 specularGlossinessBuffer = (resizedTextures.texture2.readPixels()) as Uint8Array;
             }
             else {
-                throw new Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: " + resizedTextures.texture2.name);
+                Tools.Error("_ConvertSpecularGlossinessTexturesToMetallicRoughness: Pixel array buffer type not supported for texture: " + resizedTextures.texture2.name);
+                return null;
             }
 
             const byteLength = specularGlossinessBuffer.byteLength;
@@ -789,14 +780,15 @@ module BABYLON.GLTF2 {
          * @param hasTextureCoords specifies if texture coordinates are present on the submesh to determine if textures should be applied
          * @returns glTF PBR Metallic Roughness factors
          */
-        private static _ConvertSpecGlossFactorsToMetallicRoughness(babylonPBRMaterial: PBRMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness, imageData: { [fileName: string]: { data: Uint8Array, mimeType: ImageMimeType } }, hasTextureCoords: boolean): _IPBRMetallicRoughness {
+        private static _ConvertSpecGlossFactorsToMetallicRoughness(babylonPBRMaterial: PBRMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness, imageData: { [fileName: string]: { data: Uint8Array, mimeType: ImageMimeType } }, hasTextureCoords: boolean): Nullable<_IPBRMetallicRoughness> {
             const specGloss: _IPBRSpecularGlossiness = {
                 diffuseColor: babylonPBRMaterial.albedoColor || Color3.White(),
                 specularColor: babylonPBRMaterial.reflectivityColor || Color3.White(),
                 glossiness: babylonPBRMaterial.microSurface || 1,
             };
             if (babylonPBRMaterial.reflectivityTexture && !babylonPBRMaterial.useMicroSurfaceFromReflectivityMapAlpha) {
-                throw new Error("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture currently not supported");
+                Tools.Error("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture currently not supported");
+                return null;
             }
 
             let metallicRoughnessFactors = this._ConvertSpecularGlossinessTexturesToMetallicRoughness(babylonPBRMaterial.albedoTexture, babylonPBRMaterial.reflectivityTexture, specGloss, mimeType);
@@ -824,8 +816,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Converts a Babylon PBR Metallic Roughness Material to a glTF Material
          * @param babylonPBRMaterial BJS PBR Metallic Roughness Material
          * @param mimeType mime type to use for the textures
@@ -849,73 +839,75 @@ module BABYLON.GLTF2 {
             else {
                 metallicRoughness = this._ConvertSpecGlossFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, images, textures, glTFPbrMetallicRoughness, imageData, hasTextureCoords);
             }
+            if (metallicRoughness) {
+                if (!(this.FuzzyEquals(metallicRoughness.baseColor, Color3.White(), this._epsilon) && babylonPBRMaterial.alpha >= this._epsilon)) {
+                    glTFPbrMetallicRoughness.baseColorFactor = [
+                        metallicRoughness.baseColor.r,
+                        metallicRoughness.baseColor.g,
+                        metallicRoughness.baseColor.b,
+                        babylonPBRMaterial.alpha
+                    ];
+                }
 
-            if (!(this.FuzzyEquals(metallicRoughness.baseColor, Color3.White(), this._epsilon) && babylonPBRMaterial.alpha >= this._epsilon)) {
-                glTFPbrMetallicRoughness.baseColorFactor = [
-                    metallicRoughness.baseColor.r,
-                    metallicRoughness.baseColor.g,
-                    metallicRoughness.baseColor.b,
-                    babylonPBRMaterial.alpha
-                ];
-            }
-
-            if (metallicRoughness.metallic != null && metallicRoughness.metallic !== 1) {
-                glTFPbrMetallicRoughness.metallicFactor = metallicRoughness.metallic;
-            }
-            if (metallicRoughness.roughness != null && metallicRoughness.roughness !== 1) {
-                glTFPbrMetallicRoughness.roughnessFactor = metallicRoughness.roughness;
-            }
-
-            if (babylonPBRMaterial.backFaceCulling != null && !babylonPBRMaterial.backFaceCulling) {
-                if (!babylonPBRMaterial.twoSidedLighting) {
-                    Tools.Warn(babylonPBRMaterial.name + ": Back-face culling enabled and two-sided lighting disabled is not supported in glTF.");
+                if (metallicRoughness.metallic != null && metallicRoughness.metallic !== 1) {
+                    glTFPbrMetallicRoughness.metallicFactor = metallicRoughness.metallic;
                 }
-                glTFMaterial.doubleSided = true;
-            }
-            if (hasTextureCoords) {
-                if (babylonPBRMaterial.bumpTexture) {
-                    const glTFTexture = _GLTFMaterial._ExportTexture(babylonPBRMaterial.bumpTexture, mimeType, images, textures, imageData);
-                    if (glTFTexture) {
-                        glTFMaterial.normalTexture = glTFTexture;
+                if (metallicRoughness.roughness != null && metallicRoughness.roughness !== 1) {
+                    glTFPbrMetallicRoughness.roughnessFactor = metallicRoughness.roughness;
+                }
+
+                if (babylonPBRMaterial.backFaceCulling != null && !babylonPBRMaterial.backFaceCulling) {
+                    if (!babylonPBRMaterial.twoSidedLighting) {
+                        Tools.Warn(babylonPBRMaterial.name + ": Back-face culling enabled and two-sided lighting disabled is not supported in glTF.");
                     }
+                    glTFMaterial.doubleSided = true;
                 }
-                if (babylonPBRMaterial.ambientTexture) {
-                    const glTFTexture = _GLTFMaterial._ExportTexture(babylonPBRMaterial.ambientTexture, mimeType, images, textures, imageData);
-                    if (glTFTexture) {
-                        let occlusionTexture: IMaterialOcclusionTextureInfo = {
-                            index: glTFTexture.index
-                        };
+                if (hasTextureCoords) {
+                    if (babylonPBRMaterial.bumpTexture) {
+                        const glTFTexture = _GLTFMaterial._ExportTexture(babylonPBRMaterial.bumpTexture, mimeType, images, textures, imageData);
+                        if (glTFTexture) {
+                            glTFMaterial.normalTexture = glTFTexture;
+                        }
+                    }
+                    if (babylonPBRMaterial.ambientTexture) {
+                        const glTFTexture = _GLTFMaterial._ExportTexture(babylonPBRMaterial.ambientTexture, mimeType, images, textures, imageData);
+                        if (glTFTexture) {
+                            let occlusionTexture: IMaterialOcclusionTextureInfo = {
+                                index: glTFTexture.index
+                            };
 
-                        glTFMaterial.occlusionTexture = occlusionTexture;
+                            glTFMaterial.occlusionTexture = occlusionTexture;
 
-                        if (babylonPBRMaterial.ambientTextureStrength) {
-                            occlusionTexture.strength = babylonPBRMaterial.ambientTextureStrength;
+                            if (babylonPBRMaterial.ambientTextureStrength) {
+                                occlusionTexture.strength = babylonPBRMaterial.ambientTextureStrength;
+                            }
                         }
                     }
-                }
-                if (babylonPBRMaterial.emissiveTexture) {
-                    const glTFTexture = _GLTFMaterial._ExportTexture(babylonPBRMaterial.emissiveTexture, mimeType, images, textures, imageData);
-                    if (glTFTexture != null) {
-                        glTFMaterial.emissiveTexture = glTFTexture;
+                    if (babylonPBRMaterial.emissiveTexture) {
+                        const glTFTexture = _GLTFMaterial._ExportTexture(babylonPBRMaterial.emissiveTexture, mimeType, images, textures, imageData);
+                        if (glTFTexture != null) {
+                            glTFMaterial.emissiveTexture = glTFTexture;
+                        }
                     }
-                }       
-            }
-            if (!this.FuzzyEquals(babylonPBRMaterial.emissiveColor, Color3.Black(), this._epsilon)) {
-                glTFMaterial.emissiveFactor = babylonPBRMaterial.emissiveColor.asArray();
-            }
-            if (babylonPBRMaterial.transparencyMode != null) {
-                const alphaMode = _GLTFMaterial._GetAlphaMode(babylonPBRMaterial);
-
-                if (alphaMode !== MaterialAlphaMode.OPAQUE) { //glTF defaults to opaque
-                    glTFMaterial.alphaMode = alphaMode;
-                    if (alphaMode === MaterialAlphaMode.BLEND) {
-                        glTFMaterial.alphaCutoff = babylonPBRMaterial.alphaCutOff;
+                }
+                if (!this.FuzzyEquals(babylonPBRMaterial.emissiveColor, Color3.Black(), this._epsilon)) {
+                    glTFMaterial.emissiveFactor = babylonPBRMaterial.emissiveColor.asArray();
+                }
+                if (babylonPBRMaterial.transparencyMode != null) {
+                    const alphaMode = _GLTFMaterial._GetAlphaMode(babylonPBRMaterial);
+                    if (alphaMode) {
+                        if (alphaMode !== MaterialAlphaMode.OPAQUE) { //glTF defaults to opaque
+                            glTFMaterial.alphaMode = alphaMode;
+                            if (alphaMode === MaterialAlphaMode.BLEND) {
+                                glTFMaterial.alphaCutoff = babylonPBRMaterial.alphaCutOff;
+                            }
+                        }
                     }
                 }
-            }
 
-            glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
-            materials.push(glTFMaterial);
+                glTFMaterial.pbrMetallicRoughness = glTFPbrMetallicRoughness;
+                materials.push(glTFMaterial);
+            }
         }
 
         private static GetPixelsFromTexture(babylonTexture: Texture): Uint8Array | Float32Array {
@@ -952,7 +944,8 @@ module BABYLON.GLTF2 {
                 extension = ".png";
             }
             else {
-                throw new Error("Unsupported mime type " + mimeType);
+                Tools.Error("Unsupported mime type " + mimeType);
+                return null;
             }
             textureName = baseFile + extension;
 
@@ -962,7 +955,7 @@ module BABYLON.GLTF2 {
             const size = babylonTexture.getSize();
 
             const base64Data = this._CreateBase64FromCanvas(pixels, size.width, size.height, mimeType);
-   
+
             return this._GetTextureInfoFromBase64(base64Data, textureName, mimeType, images, textures, imageData);
         }
 

+ 6 - 4
serializers/src/glTF/2.0/babylon.glTFSerializer.ts

@@ -29,14 +29,15 @@ module BABYLON {
          * @returns Returns an object with a .gltf file and associates texture names
          * as keys and their data and paths as values
          */
-        public static GLTF(scene: Scene, filePrefix: string, options?: IExporterOptions): GLTFData {
+        public static GLTF(scene: Scene, filePrefix: string, options?: IExporterOptions): Nullable<GLTFData> {
             const glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");
             const gltfGenerator = new GLTF2._Exporter(scene, options);
             if (scene.isReady) {
                 return gltfGenerator._generateGLTF(glTFPrefix);
             }
             else {
-                throw new Error("glTF Serializer: Scene is not ready!");
+                Tools.Error("glTF Serializer: Scene is not ready!");
+                return null;
             } 
         }
 
@@ -47,14 +48,15 @@ module BABYLON {
          * @param options Exporter options
          * @returns Returns an object with a .glb filename as key and data as value
          */
-        public static GLB(scene: Scene, filePrefix: string, options?: IExporterOptions): GLTFData {
+        public static GLB(scene: Scene, filePrefix: string, options?: IExporterOptions): Nullable<GLTFData> {
             const glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");        
             const gltfGenerator = new GLTF2._Exporter(scene, options);
             if (scene.isReady) {
                 return gltfGenerator._generateGLB(glTFPrefix);
             }
             else {
-                throw new Error("glTF Serializer: Scene is not ready!");
+                Tools.Error("glTF Serializer: Scene is not ready!");
+                return null;
             }  
         }
     }

+ 0 - 14
serializers/src/glTF/2.0/babylon.glTFUtilities.ts

@@ -6,8 +6,6 @@ module BABYLON.GLTF2 {
      */
     export class _GLTFUtilities {
         /**
-         * @ignore
-         * 
          * Creates a buffer view based on the supplied arguments
          * @param bufferIndex index value of the specified buffer
          * @param byteOffset byte offset value
@@ -32,8 +30,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Creates an accessor based on the supplied arguments
          * @param bufferviewIndex The index of the bufferview referenced by this accessor
          * @param name The name of the accessor
@@ -62,8 +58,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Calculates the minimum and maximum values of an array of position floats
          * @param positions Positions array of a mesh
          * @param vertexStart Starting vertex offset to calculate min and max values
@@ -104,8 +98,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Converts a new right-handed Vector3
          * @param vector vector3 array
          * @returns right-handed Vector3
@@ -115,8 +107,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Converts a Vector3 to right-handed
          * @param vector Vector3 to convert to right-handed
          */
@@ -125,8 +115,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Converts a Vector4 to right-handed
          * @param vector Vector4 to convert to right-handed
          */
@@ -136,8 +124,6 @@ module BABYLON.GLTF2 {
         }
 
         /**
-         * @ignore
-         * 
          * Converts a Quaternion to right-handed
          * @param quaternion Source quaternion to convert to right-handed
          */