فهرست منبع

cleanup and using async functions for gltf export

Kacey Coley 7 سال پیش
والد
کامیت
679d915cd3

+ 4 - 6
inspector/src/tabs/GLTFTab.ts

@@ -26,13 +26,11 @@ module INSPECTOR {
             button.innerText = 'Export GLB';
 
             button.addEventListener('click', () => {
-                const data = BABYLON.GLTF2Export.GLB(inspector.scene, name.value || "scene", {
-                    shouldExportMesh: mesh => !GLTFTab._IsSkyBox(mesh)
+                BABYLON.GLTF2Export.GLBAsync(inspector.scene, name.value || "scene", {
+                    shouldExportTransformNode: transformNode => !GLTFTab._IsSkyBox(transformNode)
+                }).then((glb) => {
+                    glb.downloadFiles();
                 });
-
-                if (data) {
-                    data.downloadFiles();
-                }
             });
         }
 

+ 0 - 1
serializers/src/glTF/2.0/babylon.glTFAnimation.ts

@@ -735,7 +735,6 @@ module BABYLON.GLTF2 {
                                 tangent = Quaternion.FromArray([0, 1, 0, 0]).multiply(Quaternion.FromArray(tangent)).asArray();
                             }
                         }
-
                     }
                     else {
                         tangent = [0, 0, 0, 0];

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

@@ -587,7 +587,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
@@ -1049,7 +1048,6 @@ module BABYLON.GLTF2 {
                             if (babylonIndices) {
                                 if (sideOrientation === Material.ClockWiseSideOrientation) {
                                     this.reorderIndicesBasedOnPrimitiveMode(submesh, primitiveMode, babylonIndices, byteOffset, binaryWriter);
-                                  //  this.flipNormalsAndTangents(submesh, vertexAttributeBufferViews, binaryWriter);
                                 }
                             }
                             else {

+ 0 - 3
serializers/src/glTF/2.0/babylon.glTFMaterial.ts

@@ -5,7 +5,6 @@ module BABYLON.GLTF2 {
      * Interface for storing specular glossiness factors
      * @hidden
      */
-
     interface _IPBRSpecularGlossiness {
         /** 
          * Represents the linear diffuse factors of the material
@@ -25,7 +24,6 @@ module BABYLON.GLTF2 {
      * Interface for storing metallic roughness factors
      * @hidden
      */
-
     interface _IPBRMetallicRoughness {
         /** 
          * Represents the albedo color of the material
@@ -52,7 +50,6 @@ module BABYLON.GLTF2 {
     /**
      * Utility methods for working with glTF material conversion properties.  This class should only be used internally
      * @hidden
-
      */
     export class _GLTFMaterial {
         /**

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

@@ -7,10 +7,10 @@ module BABYLON {
     export interface IExportOptions {
         /**
          * Function which indicates whether a babylon mesh should be exported or not
-         * @param mesh source Babylon mesh. It is used to check whether it should be exported to glTF or not
+         * @param transformNode source Babylon transform node. It is used to check whether it should be exported to glTF or not
          * @returns boolean, which indicates whether the mesh should be exported (true) or not (false)
          */
-        shouldExportTransformNode?(mesh: TransformNode): boolean;
+        shouldExportTransformNode?(transformNode: TransformNode): boolean;
         /**
          * The sample rate to bake animation curves
          */
@@ -29,16 +29,10 @@ 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?: IExportOptions): Nullable<GLTFData> {
-            if (scene.isReady()) {
+        private static GLTF(scene: Scene, filePrefix: string, options?: IExportOptions): GLTFData {
             const glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");
             const gltfGenerator = new GLTF2._Exporter(scene, options);
             return gltfGenerator._generateGLTF(glTFPrefix);
-            }
-            else {
-                Tools.Error('glTF Serializer: Scene is not ready!');
-                return null;
-            }
         }
 
         /**
@@ -49,7 +43,7 @@ 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 GLTFAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<Nullable<GLTFData>> {
+        public static GLTFAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData> {
             return Promise.resolve(scene.whenReadyAsync()).then(() => {
                 return GLTF2Export.GLTF(scene, filePrefix, options);
             });
@@ -62,16 +56,10 @@ 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?: IExportOptions): Nullable<GLTFData> {
-            if (scene.isReady()) {
+        private static GLB(scene: Scene, filePrefix: string, options?: IExportOptions): GLTFData {
             const glTFPrefix = filePrefix.replace(/\.[^/.]+$/, "");
             const gltfGenerator = new GLTF2._Exporter(scene, options);
             return gltfGenerator._generateGLB(glTFPrefix);
-            }
-            else {
-                Tools.Error('glTF Serializer: Scene is not ready!');
-                return null;
-            }
         }
 
         /**
@@ -81,7 +69,7 @@ module BABYLON {
          * @param options Exporter options
          * @returns Returns an object with a .glb filename as key and data as value
          */
-        public static GLBAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<Nullable<GLTFData>> {
+        public static GLBAsync(scene: Scene, filePrefix: string, options?: IExportOptions): Promise<GLTFData> {
             return Promise.resolve(scene.whenReadyAsync()).then(() => {
                 return GLTF2Export.GLB(scene, filePrefix, options);
             });