David Catuhe 6 år sedan
förälder
incheckning
00f8da269b
24 ändrade filer med 961 tillägg och 293 borttagningar
  1. 67 20
      Playground/babylon.d.txt
  2. 7 0
      dist/preview release/babylon.d.ts
  3. 1 1
      dist/preview release/babylon.js
  4. 24 10
      dist/preview release/babylon.max.js
  5. 1 1
      dist/preview release/babylon.max.js.map
  6. 14 0
      dist/preview release/babylon.module.d.ts
  7. 1 1
      dist/preview release/inspector/babylon.inspector.bundle.js
  8. 5 5
      dist/preview release/inspector/babylon.inspector.bundle.max.js
  9. 1 1
      dist/preview release/inspector/babylon.inspector.bundle.max.js.map
  10. 1 1
      dist/preview release/inspector/babylon.inspector.d.ts
  11. 3 3
      dist/preview release/inspector/babylon.inspector.module.d.ts
  12. 283 86
      dist/preview release/serializers/babylon.glTF2Serializer.js
  13. 1 1
      dist/preview release/serializers/babylon.glTF2Serializer.js.map
  14. 1 1
      dist/preview release/serializers/babylon.glTF2Serializer.min.js
  15. 61 17
      dist/preview release/serializers/babylonjs.serializers.d.ts
  16. 293 90
      dist/preview release/serializers/babylonjs.serializers.js
  17. 1 1
      dist/preview release/serializers/babylonjs.serializers.js.map
  18. 1 1
      dist/preview release/serializers/babylonjs.serializers.min.js
  19. 134 37
      dist/preview release/serializers/babylonjs.serializers.module.d.ts
  20. 14 0
      dist/preview release/viewer/babylon.module.d.ts
  21. 19 5
      dist/preview release/viewer/babylon.viewer.d.ts
  22. 5 5
      dist/preview release/viewer/babylon.viewer.js
  23. 1 1
      dist/preview release/viewer/babylon.viewer.max.js
  24. 22 5
      dist/preview release/viewer/babylon.viewer.module.d.ts

+ 67 - 20
Playground/babylon.d.txt

@@ -30305,6 +30305,13 @@ declare module BABYLON {
         dispose(): void;
         private _checkAnimationGroupEnded;
         /**
+         * Clone the current animation group and returns a copy
+         * @param newName defines the name of the new group
+         * @param targetConverter defines an optional function used to convert current animation targets to new ones
+         * @returns the new aniamtion group
+         */
+        clone(newName: string, targetConverter?: (oldTarget: any) => any): AnimationGroup;
+        /**
          * Returns a new AnimationGroup object parsed from the source provided.
          * @param parsedAnimationGroup defines the source
          * @param scene defines the scene that will receive the animationGroup
@@ -58558,8 +58565,21 @@ declare module BABYLON.GLTF2.Exporter {
          * @param meshPrimitive glTF mesh primitive
          * @param babylonSubMesh Babylon submesh
          * @param binaryWriter glTF serializer binary writer instance
+         * @returns nullable IMeshPrimitive promise
          */
         postExportMeshPrimitiveAsync?(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Nullable<Promise<IMeshPrimitive>>;
+        /**
+         * Define this method to modify the default behavior when exporting a node
+         * @param context The context when exporting the node
+         * @param node glTF node
+         * @param babylonNode BabylonJS node
+         * @returns nullable INode promise
+         */
+        postExportNodeAsync?(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+        /**
+         * Called after the exporter state changes to EXPORTING
+         */
+        onExporting?(): void;
     }
 }
 declare module BABYLON.GLTF2.Exporter {
@@ -58799,11 +58819,11 @@ declare module BABYLON {
      */
     export interface IExportOptions {
         /**
-         * Function which indicates whether a babylon mesh should be exported 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)
+         * Function which indicates whether a babylon node should be exported or not
+         * @param node source Babylon node. It is used to check whether it should be exported to glTF or not
+         * @returns boolean, which indicates whether the node should be exported (true) or not (false)
          */
-        shouldExportTransformNode?(transformNode: TransformNode): boolean;
+        shouldExportNode?(node: Node): boolean;
         /**
          * The sample rate to bake animation curves
          */
@@ -58925,6 +58945,9 @@ declare module BABYLON.GLTF2.Exporter {
      */
     export class _Exporter {
         /**
+         * Stores the glTF to export
+         */
glTF: IGLTF;
+        /**
          * Stores all generated buffer views, which represents views into the main glTF buffer data
          */
bufferViews: IBufferView[];
         /**
@@ -58935,10 +58958,6 @@ declare module BABYLON.GLTF2.Exporter {
          */
         private _nodes;
         /**
-         * Stores the glTF asset information, which represents the glTF version and this file generator
-         */
-        private _asset;
-        /**
          * Stores all the generated glTF scenes, which stores multiple node hierarchies
          */
         private _scenes;
@@ -58973,8 +58992,7 @@ declare module BABYLON.GLTF2.Exporter {
         private _totalByteLength;
         /**
          * Stores a reference to the Babylon scene containing the source geometry and material information
-         */
-        private _babylonScene;
+         */
babylonScene: Scene;
         /**
          * Stores a map of the image data, where the key is the file name and the value
          * is the image data
@@ -58990,23 +59008,22 @@ declare module BABYLON.GLTF2.Exporter {
         private _nodeMap;
         /**
          * Specifies if the Babylon scene should be converted to right-handed on export
-         */
-        private _convertToRightHandedSystem;
+         */
convertToRightHandedSystem: boolean;
         /**
          * Baked animation sample rate
          */
         private _animationSampleRate;
         /**
-         * Callback which specifies if a transform node should be exported or not
+         * Callback which specifies if a node should be exported or not
          */
-        private _shouldExportTransformNode;
+        private _shouldExportNode;
         private _localEngine;
glTFMaterialExporter: _GLTFMaterialExporter;
         private _extensions;
-        private _extensionsUsed;
-        private _extensionsRequired;
         private static _ExtensionNames;
         private static _ExtensionFactories;
-        private _applyExtensions;
extensionsPreExportTextureAsync(context: string, babylonTexture: Texture, mimeType: ImageMimeType): Nullable<Promise<BaseTexture>>;
extensionsPostExportMeshPrimitiveAsync(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Nullable<Promise<IMeshPrimitive>>;
+        private _applyExtensions;
extensionsPreExportTextureAsync(context: string, babylonTexture: Texture, mimeType: ImageMimeType): Nullable<Promise<BaseTexture>>;
extensionsPostExportMeshPrimitiveAsync(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Nullable<Promise<IMeshPrimitive>>;
extensionsPostExportNodeAsync(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+        private _forEachExtensions;
+        private _extensionsOnExporting;
         /**
          * Load glTF serializer extensions
          */
@@ -59179,7 +59196,7 @@ declare module BABYLON.GLTF2.Exporter {
          * Creates a mapping of Node unique id to node index and handles animations
          * @param babylonScene Babylon Scene
          * @param nodes Babylon transform nodes
-         * @param shouldExportTransformNode Callback specifying if a transform node should be exported
+         * @param shouldExportNode Callback specifying if a transform node should be exported
          * @param binaryWriter Buffer to write binary data to
          * @returns Node mapping of unique id to index
          */
@@ -59323,7 +59340,7 @@ declare module BABYLON.GLTF2.Exporter {
         /**
          * @ignore
          * Create node animations from the transform node animations
-         * @param babylonTransformNode
+         * @param babylonNode
          * @param runtimeGLTFAnimation
          * @param idleGLTFAnimations
          * @param nodeMap
@@ -59332,7 +59349,7 @@ declare module BABYLON.GLTF2.Exporter {
          * @param bufferViews
          * @param accessors
          * @param convertToRightHandedSystem
-         */
private static _CreateNodeAnimationFromTransformNodeAnimations(babylonTransformNode: TransformNode, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
+         */
private static _CreateNodeAnimationFromNodeAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
             [key: number]: number;
         }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
         /**
@@ -59464,6 +59481,36 @@ declare module BABYLON.GLTF2.Exporter.Extensions {
         textureTransformTextureAsync(babylonTexture: Texture, offset: Vector2, rotation: number, scale: Vector2, scene: Scene): Promise<BaseTexture>;
     }
 }
+declare module BABYLON.GLTF2.Exporter.Extensions {
+    /**
+     * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
+     */
+    export class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
+        /** The name of this extension. */
+        readonly name: string;
+        /** Defines whether this extension is enabled. */
+        enabled: boolean;
+        /** Defines whether this extension is required */
+        required: boolean;
+        /** Reference to the glTF exporter */
+        private _exporter;
+        private _lights;
+        /** @hidden */
+        constructor(exporter: _Exporter);
+        /** @hidden */
+        dispose(): void;
+        /** @hidden */
+        onExporting(): void;
+        /**
+         * Define this method to modify the default behavior when exporting a node
+         * @param context The context when exporting the node
+         * @param node glTF node
+         * @param babylonNode BabylonJS node
+         * @returns nullable INode promise
+         */
+        postExportNodeAsync(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+    }
+}
 /**
  * @ignoreChildren
  * @ignore

+ 7 - 0
dist/preview release/babylon.d.ts

@@ -30810,6 +30810,13 @@ declare module BABYLON {
         dispose(): void;
         private _checkAnimationGroupEnded;
         /**
+         * Clone the current animation group and returns a copy
+         * @param newName defines the name of the new group
+         * @param targetConverter defines an optional function used to convert current animation targets to new ones
+         * @returns the new aniamtion group
+         */
+        clone(newName: string, targetConverter?: (oldTarget: any) => any): AnimationGroup;
+        /**
          * Returns a new AnimationGroup object parsed from the source provided.
          * @param parsedAnimationGroup defines the source
          * @param scene defines the scene that will receive the animationGroup

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/babylon.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 24 - 10
dist/preview release/babylon.max.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/babylon.max.js.map


+ 14 - 0
dist/preview release/babylon.module.d.ts

@@ -31543,6 +31543,13 @@ declare module "babylonjs/Animations/animationGroup" {
         dispose(): void;
         private _checkAnimationGroupEnded;
         /**
+         * Clone the current animation group and returns a copy
+         * @param newName defines the name of the new group
+         * @param targetConverter defines an optional function used to convert current animation targets to new ones
+         * @returns the new aniamtion group
+         */
+        clone(newName: string, targetConverter?: (oldTarget: any) => any): AnimationGroup;
+        /**
          * Returns a new AnimationGroup object parsed from the source provided.
          * @param parsedAnimationGroup defines the source
          * @param scene defines the scene that will receive the animationGroup
@@ -87358,6 +87365,13 @@ declare module BABYLON {
         dispose(): void;
         private _checkAnimationGroupEnded;
         /**
+         * Clone the current animation group and returns a copy
+         * @param newName defines the name of the new group
+         * @param targetConverter defines an optional function used to convert current animation targets to new ones
+         * @returns the new aniamtion group
+         */
+        clone(newName: string, targetConverter?: (oldTarget: any) => any): AnimationGroup;
+        /**
          * Returns a new AnimationGroup object parsed from the source provided.
          * @param parsedAnimationGroup defines the source
          * @param scene defines the scene that will receive the animationGroup

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/inspector/babylon.inspector.bundle.js


+ 5 - 5
dist/preview release/inspector/babylon.inspector.bundle.max.js

@@ -36649,11 +36649,11 @@ var ToolsTabComponent = /** @class */ (function (_super) {
         });
         this.setState({ tag: "Stop recording" });
     };
-    ToolsTabComponent.prototype.shouldExport = function (transformNode) {
+    ToolsTabComponent.prototype.shouldExport = function (node) {
         // No skybox
-        if (transformNode instanceof babylonjs_Misc_videoRecorder__WEBPACK_IMPORTED_MODULE_5__["Mesh"]) {
-            if (transformNode.material) {
-                var material = transformNode.material;
+        if (node instanceof babylonjs_Misc_videoRecorder__WEBPACK_IMPORTED_MODULE_5__["Mesh"]) {
+            if (node.material) {
+                var material = node.material;
                 var reflectionTexture = material.reflectionTexture;
                 if (reflectionTexture && reflectionTexture.coordinatesMode === babylonjs_Misc_videoRecorder__WEBPACK_IMPORTED_MODULE_5__["Texture"].SKYBOX_MODE) {
                     return false;
@@ -36666,7 +36666,7 @@ var ToolsTabComponent = /** @class */ (function (_super) {
         var _this = this;
         var scene = this.props.scene;
         babylonjs_serializers_glTF_2_0_index__WEBPACK_IMPORTED_MODULE_7__["GLTF2Export"].GLBAsync(scene, "scene", {
-            shouldExportTransformNode: function (transformNode) { return _this.shouldExport(transformNode); }
+            shouldExportNode: function (node) { return _this.shouldExport(node); }
         }).then(function (glb) {
             glb.downloadFiles();
         });

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/inspector/babylon.inspector.bundle.max.js.map


+ 1 - 1
dist/preview release/inspector/babylon.inspector.d.ts

@@ -1004,7 +1004,7 @@ declare module INSPECTOR {
         componentWillUnmount(): void;
         captureScreenshot(): void;
         recordVideo(): void;
-        shouldExport(transformNode: BABYLON.TransformNode): boolean;
+        shouldExport(node: BABYLON.Node): boolean;
         exportGLTF(): void;
         exportBabylon(): void;
         createEnvTexture(): void;

+ 3 - 3
dist/preview release/inspector/babylon.inspector.module.d.ts

@@ -1256,7 +1256,7 @@ declare module "babylonjs-inspector/components/actionTabs/tabs/tools/gltfCompone
 }
 declare module "babylonjs-inspector/components/actionTabs/tabs/toolsTabComponent" {
     import { PaneComponent, IPaneComponentProps } from "babylonjs-inspector/components/actionTabs/paneComponent";
-    import { TransformNode } from "babylonjs/Meshes/transformNode";
+    import { Node } from "babylonjs/node";
     export class ToolsTabComponent extends PaneComponent {
         private _videoRecorder;
         constructor(props: IPaneComponentProps);
@@ -1264,7 +1264,7 @@ declare module "babylonjs-inspector/components/actionTabs/tabs/toolsTabComponent
         componentWillUnmount(): void;
         captureScreenshot(): void;
         recordVideo(): void;
-        shouldExport(transformNode: TransformNode): boolean;
+        shouldExport(node: Node): boolean;
         exportGLTF(): void;
         exportBabylon(): void;
         createEnvTexture(): void;
@@ -2763,7 +2763,7 @@ declare module INSPECTOR {
         componentWillUnmount(): void;
         captureScreenshot(): void;
         recordVideo(): void;
-        shouldExport(transformNode: BABYLON.TransformNode): boolean;
+        shouldExport(node: BABYLON.Node): boolean;
         exportGLTF(): void;
         exportBabylon(): void;
         createEnvTexture(): void;

+ 283 - 86
dist/preview release/serializers/babylon.glTF2Serializer.js

@@ -127,6 +127,169 @@ module.exports = g;
 
 /***/ }),
 
+/***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
+/*!****************************************************!*\
+  !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
+  \****************************************************/
+/*! exports provided: KHR_lights_punctual */
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
+
+"use strict";
+__webpack_require__.r(__webpack_exports__);
+/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return KHR_lights_punctual; });
+/* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
+/* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
+/* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFExporter */ "./glTF/2.0/glTFExporter.ts");
+/* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
+
+
+
+
+
+
+var NAME = "KHR_lights_punctual";
+var LightType;
+(function (LightType) {
+    LightType["DIRECTIONAL"] = "directional";
+    LightType["POINT"] = "point";
+    LightType["SPOT"] = "spot";
+})(LightType || (LightType = {}));
+/**
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
+ */
+var KHR_lights_punctual = /** @class */ (function () {
+    /** @hidden */
+    function KHR_lights_punctual(exporter) {
+        /** The name of this extension. */
+        this.name = NAME;
+        /** Defines whether this extension is enabled. */
+        this.enabled = true;
+        /** Defines whether this extension is required */
+        this.required = false;
+        this._exporter = exporter;
+    }
+    /** @hidden */
+    KHR_lights_punctual.prototype.dispose = function () {
+        delete this._exporter;
+        delete this._lights;
+    };
+    /** @hidden */
+    KHR_lights_punctual.prototype.onExporting = function () {
+        if (this._lights) {
+            if (this._exporter._glTF.extensionsUsed == null) {
+                this._exporter._glTF.extensionsUsed = [];
+            }
+            if (this._exporter._glTF.extensionsUsed.indexOf(NAME) === -1) {
+                this._exporter._glTF.extensionsUsed.push(NAME);
+            }
+            if (this.required) {
+                if (this._exporter._glTF.extensionsRequired == null) {
+                    this._exporter._glTF.extensionsRequired = [];
+                }
+                if (this._exporter._glTF.extensionsRequired.indexOf(NAME) === -1) {
+                    this._exporter._glTF.extensionsRequired.push(NAME);
+                }
+            }
+            if (this._exporter._glTF.extensions == null) {
+                this._exporter._glTF.extensions = {};
+            }
+            this._exporter._glTF.extensions[NAME] = this._lights;
+        }
+    };
+    /**
+     * Define this method to modify the default behavior when exporting a node
+     * @param context The context when exporting the node
+     * @param node glTF node
+     * @param babylonNode BabylonJS node
+     * @returns nullable INode promise
+     */
+    KHR_lights_punctual.prototype.postExportNodeAsync = function (context, node, babylonNode) {
+        var _this = this;
+        return new Promise(function (resolve, reject) {
+            if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["ShadowLight"]) {
+                var babylonLight = babylonNode;
+                var light = void 0;
+                var lightType = (babylonLight.getTypeID() == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_POINTLIGHT ? LightType.POINT : (babylonLight.getTypeID() == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_DIRECTIONALLIGHT ? LightType.DIRECTIONAL : (babylonLight.getTypeID() == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_SPOTLIGHT ? LightType.SPOT : null)));
+                if (lightType == null) {
+                    babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + ": Light " + babylonLight.name + " is not supported in " + NAME);
+                }
+                else {
+                    var lightPosition = babylonLight.position.clone();
+                    if (!lightPosition.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero())) {
+                        if (_this._exporter._convertToRightHandedSystem) {
+                            _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(lightPosition);
+                        }
+                        node.translation = lightPosition.asArray();
+                    }
+                    if (lightType !== LightType.POINT) {
+                        var localAxis = babylonLight.direction;
+                        var yaw = -Math.atan2(localAxis.z, localAxis.x) + Math.PI / 2;
+                        var len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);
+                        var pitch = -Math.atan2(localAxis.y, len);
+                        var lightRotationQuaternion = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(yaw, pitch, 0);
+                        if (_this._exporter._convertToRightHandedSystem) {
+                            _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(lightRotationQuaternion);
+                        }
+                        if (!lightRotationQuaternion.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity())) {
+                            node.rotation = lightRotationQuaternion.asArray();
+                        }
+                    }
+                    if (babylonLight.falloffType !== babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF) {
+                        babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + ": Light falloff for " + babylonLight.name + " does not match the " + NAME + " specification!");
+                    }
+                    light = {
+                        type: lightType
+                    };
+                    if (!babylonLight.diffuse.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White())) {
+                        light.color = babylonLight.diffuse.asArray();
+                    }
+                    if (babylonLight.intensity !== 1.0) {
+                        light.intensity = babylonLight.intensity;
+                    }
+                    if (babylonLight.range !== Number.MAX_VALUE) {
+                        light.range = babylonLight.range;
+                    }
+                    if (lightType === LightType.SPOT) {
+                        var babylonSpotLight = babylonLight;
+                        if (babylonSpotLight.angle !== Math.PI / 2.0) {
+                            if (light.spot == null) {
+                                light.spot = {};
+                            }
+                            light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;
+                        }
+                        if (babylonSpotLight.innerAngle !== 0) {
+                            if (light.spot == null) {
+                                light.spot = {};
+                            }
+                            light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;
+                        }
+                    }
+                    if (_this._lights == null) {
+                        _this._lights = {
+                            lights: []
+                        };
+                    }
+                    _this._lights.lights.push(light);
+                    if (node.extensions == null) {
+                        node.extensions = {};
+                    }
+                    var lightReference = {
+                        light: _this._lights.lights.length - 1
+                    };
+                    node.extensions[NAME] = lightReference;
+                }
+            }
+            resolve(node);
+        });
+    };
+    return KHR_lights_punctual;
+}());
+
+_glTFExporter__WEBPACK_IMPORTED_MODULE_1__["_Exporter"].RegisterExtension(NAME, function (exporter) { return new KHR_lights_punctual(exporter); });
+
+
+/***/ }),
+
 /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
 /*!******************************************************!*\
   !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
@@ -235,7 +398,7 @@ _glTFExporter__WEBPACK_IMPORTED_MODULE_1__["_Exporter"].RegisterExtension(NAME,
 /*!**************************************!*\
   !*** ./glTF/2.0/Extensions/index.ts ***!
   \**************************************/
-/*! exports provided: KHR_texture_transform */
+/*! exports provided: KHR_texture_transform, KHR_lights_punctual */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
@@ -243,6 +406,10 @@ __webpack_require__.r(__webpack_exports__);
 /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_0__["KHR_texture_transform"]; });
 
+/* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
+
+
 
 
 
@@ -267,6 +434,7 @@ __webpack_require__.r(__webpack_exports__);
 
 
 
+
 /**
  * @hidden
  * Enum for handling in tangent and out tangent.
@@ -375,7 +543,7 @@ var _GLTFAnimation = /** @class */ (function () {
     /**
      * @ignore
      * Create node animations from the transform node animations
-     * @param babylonTransformNode
+     * @param babylonNode
      * @param runtimeGLTFAnimation
      * @param idleGLTFAnimations
      * @param nodeMap
@@ -385,21 +553,23 @@ var _GLTFAnimation = /** @class */ (function () {
      * @param accessors
      * @param convertToRightHandedSystem
      */
-    _GLTFAnimation._CreateNodeAnimationFromTransformNodeAnimations = function (babylonTransformNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
+    _GLTFAnimation._CreateNodeAnimationFromNodeAnimations = function (babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
         var glTFAnimation;
-        if (babylonTransformNode.animations) {
-            for (var _i = 0, _a = babylonTransformNode.animations; _i < _a.length; _i++) {
-                var animation = _a[_i];
-                var animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);
-                if (animationInfo) {
-                    glTFAnimation = {
-                        name: animation.name,
-                        samplers: [],
-                        channels: []
-                    };
-                    _GLTFAnimation.AddAnimation("" + animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonTransformNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
-                    if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
-                        idleGLTFAnimations.push(glTFAnimation);
+        if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]) {
+            if (babylonNode.animations) {
+                for (var _i = 0, _a = babylonNode.animations; _i < _a.length; _i++) {
+                    var animation = _a[_i];
+                    var animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);
+                    if (animationInfo) {
+                        glTFAnimation = {
+                            name: animation.name,
+                            samplers: [],
+                            channels: []
+                        };
+                        _GLTFAnimation.AddAnimation("" + animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
+                        if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
+                            idleGLTFAnimations.push(glTFAnimation);
+                        }
                     }
                 }
             }
@@ -1010,6 +1180,7 @@ __webpack_require__.r(__webpack_exports__);
 
 
 
+
 /**
  * Converts Babylon Scene into glTF 2.0.
  * @hidden
@@ -1022,9 +1193,9 @@ var _Exporter = /** @class */ (function () {
      */
     function _Exporter(babylonScene, options) {
         this._extensions = {};
-        this._asset = { generator: "BabylonJS", version: "2.0" };
-        this._extensionsUsed = [];
-        this._extensionsRequired = [];
+        this._glTF = {
+            asset: { generator: "BabylonJS", version: "2.0" }
+        };
         this._babylonScene = babylonScene;
         this._bufferViews = [];
         this._accessors = [];
@@ -1040,7 +1211,7 @@ var _Exporter = /** @class */ (function () {
         this._imageData = {};
         this._convertToRightHandedSystem = this._babylonScene.useRightHandedSystem ? false : true;
         var _options = options || {};
-        this._shouldExportTransformNode = _options.shouldExportTransformNode ? _options.shouldExportTransformNode : function (babylonTransformNode) { return true; };
+        this._shouldExportNode = _options.shouldExportNode ? _options.shouldExportNode : function (babylonNode) { return true; };
         this._animationSampleRate = _options.animationSampleRate ? _options.animationSampleRate : 1 / 60;
         this._glTFMaterialExporter = new _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_1__["_GLTFMaterialExporter"](this);
         this._loadExtensions();
@@ -1076,14 +1247,29 @@ var _Exporter = /** @class */ (function () {
     _Exporter.prototype._extensionsPostExportMeshPrimitiveAsync = function (context, meshPrimitive, babylonSubMesh, binaryWriter) {
         return this._applyExtensions(meshPrimitive, function (extension) { return extension.postExportMeshPrimitiveAsync && extension.postExportMeshPrimitiveAsync(context, meshPrimitive, babylonSubMesh, binaryWriter); });
     };
+    _Exporter.prototype._extensionsPostExportNodeAsync = function (context, node, babylonNode) {
+        return this._applyExtensions(node, function (extension) { return extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode); });
+    };
+    _Exporter.prototype._forEachExtensions = function (action) {
+        for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
+            var name_2 = _a[_i];
+            var extension = this._extensions[name_2];
+            if (extension.enabled) {
+                action(extension);
+            }
+        }
+    };
+    _Exporter.prototype._extensionsOnExporting = function () {
+        this._forEachExtensions(function (extension) { return extension.onExporting && extension.onExporting(); });
+    };
     /**
      * Load glTF serializer extensions
      */
     _Exporter.prototype._loadExtensions = function () {
         for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
-            var name_2 = _a[_i];
-            var extension = _Exporter._ExtensionFactories[name_2](this);
-            this._extensions[name_2] = extension;
+            var name_3 = _a[_i];
+            var extension = _Exporter._ExtensionFactories[name_3](this);
+            this._extensions[name_3] = extension;
         }
     };
     /**
@@ -1515,52 +1701,43 @@ var _Exporter = /** @class */ (function () {
         var imageData;
         var bufferView;
         var byteOffset = this._totalByteLength;
-        var glTF = {
-            asset: this._asset
-        };
-        if (this._extensionsUsed && this._extensionsUsed.length) {
-            glTF.extensionsUsed = this._extensionsUsed;
-        }
-        if (this._extensionsRequired && this._extensionsRequired.length) {
-            glTF.extensionsRequired = this._extensionsRequired;
-        }
         if (buffer.byteLength) {
-            glTF.buffers = [buffer];
+            this._glTF.buffers = [buffer];
         }
         if (this._nodes && this._nodes.length) {
-            glTF.nodes = this._nodes;
+            this._glTF.nodes = this._nodes;
         }
         if (this._meshes && this._meshes.length) {
-            glTF.meshes = this._meshes;
+            this._glTF.meshes = this._meshes;
         }
         if (this._scenes && this._scenes.length) {
-            glTF.scenes = this._scenes;
-            glTF.scene = 0;
+            this._glTF.scenes = this._scenes;
+            this._glTF.scene = 0;
         }
         if (this._bufferViews && this._bufferViews.length) {
-            glTF.bufferViews = this._bufferViews;
+            this._glTF.bufferViews = this._bufferViews;
         }
         if (this._accessors && this._accessors.length) {
-            glTF.accessors = this._accessors;
+            this._glTF.accessors = this._accessors;
         }
         if (this._animations && this._animations.length) {
-            glTF.animations = this._animations;
+            this._glTF.animations = this._animations;
         }
         if (this._materials && this._materials.length) {
-            glTF.materials = this._materials;
+            this._glTF.materials = this._materials;
         }
         if (this._textures && this._textures.length) {
-            glTF.textures = this._textures;
+            this._glTF.textures = this._textures;
         }
         if (this._samplers && this._samplers.length) {
-            glTF.samplers = this._samplers;
+            this._glTF.samplers = this._samplers;
         }
         if (this._images && this._images.length) {
             if (!shouldUseGlb) {
-                glTF.images = this._images;
+                this._glTF.images = this._images;
             }
             else {
-                glTF.images = [];
+                this._glTF.images = [];
                 this._images.forEach(function (image) {
                     if (image.uri) {
                         imageData = _this._imageData[image.uri];
@@ -1572,10 +1749,10 @@ var _Exporter = /** @class */ (function () {
                         image.name = imageName;
                         image.mimeType = imageData.mimeType;
                         image.uri = undefined;
-                        if (!glTF.images) {
-                            glTF.images = [];
+                        if (!_this._glTF.images) {
+                            _this._glTF.images = [];
                         }
-                        glTF.images.push(image);
+                        _this._glTF.images.push(image);
                     }
                 });
                 // Replace uri with bufferview and mime type for glb
@@ -1585,7 +1762,7 @@ var _Exporter = /** @class */ (function () {
         if (!shouldUseGlb) {
             buffer.uri = glTFPrefix + ".bin";
         }
-        var jsonText = prettyPrint ? JSON.stringify(glTF, null, 2) : JSON.stringify(glTF);
+        var jsonText = prettyPrint ? JSON.stringify(this._glTF, null, 2) : JSON.stringify(this._glTF);
         return jsonText;
     };
     /**
@@ -1596,6 +1773,7 @@ var _Exporter = /** @class */ (function () {
     _Exporter.prototype._generateGLTFAsync = function (glTFPrefix) {
         var _this = this;
         return this._generateBinaryAsync().then(function (binaryBuffer) {
+            _this._extensionsOnExporting();
             var jsonText = _this.generateJSON(false, glTFPrefix, true);
             var bin = new Blob([binaryBuffer], { type: 'application/octet-stream' });
             var glTFFileName = glTFPrefix + '.gltf';
@@ -1644,6 +1822,7 @@ var _Exporter = /** @class */ (function () {
     _Exporter.prototype._generateGLBAsync = function (glTFPrefix) {
         var _this = this;
         return this._generateBinaryAsync().then(function (binaryBuffer) {
+            _this._extensionsOnExporting();
             var jsonText = _this.generateJSON(true);
             var glbFileName = glTFPrefix + '.glb';
             var headerLength = 12;
@@ -2039,9 +2218,9 @@ var _Exporter = /** @class */ (function () {
         var glTFNodeIndex;
         var glTFNode;
         var directDescendents;
-        var nodes = babylonScene.transformNodes.concat(babylonScene.meshes);
+        var nodes = babylonScene.transformNodes.concat(babylonScene.meshes, babylonScene.lights);
         return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(babylonScene.materials, "image/png" /* PNG */, true).then(function () {
-            return _this.createNodeMapAndAnimationsAsync(babylonScene, nodes, _this._shouldExportTransformNode, binaryWriter).then(function (nodeMap) {
+            return _this.createNodeMapAndAnimationsAsync(babylonScene, nodes, _this._shouldExportNode, binaryWriter).then(function (nodeMap) {
                 _this._nodeMap = nodeMap;
                 _this._totalByteLength = binaryWriter.getByteOffset();
                 if (_this._totalByteLength == undefined) {
@@ -2049,13 +2228,13 @@ var _Exporter = /** @class */ (function () {
                 }
                 // Build Hierarchy with the node map.
                 for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
-                    var babylonTransformNode = nodes_1[_i];
-                    glTFNodeIndex = _this._nodeMap[babylonTransformNode.uniqueId];
-                    if (glTFNodeIndex != null) {
+                    var babylonNode = nodes_1[_i];
+                    glTFNodeIndex = _this._nodeMap[babylonNode.uniqueId];
+                    if (glTFNodeIndex !== undefined) {
                         glTFNode = _this._nodes[glTFNodeIndex];
-                        if (!babylonTransformNode.parent) {
-                            if (!_this._shouldExportTransformNode(babylonTransformNode)) {
-                                babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("Omitting " + babylonTransformNode.name + " from scene.");
+                        if (!babylonNode.parent) {
+                            if (!_this._shouldExportNode(babylonNode)) {
+                                babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("Omitting " + babylonNode.name + " from scene.");
                             }
                             else {
                                 if (_this._convertToRightHandedSystem) {
@@ -2068,7 +2247,7 @@ var _Exporter = /** @class */ (function () {
                                 scene.nodes.push(glTFNodeIndex);
                             }
                         }
-                        directDescendents = babylonTransformNode.getDescendants(true);
+                        directDescendents = babylonNode.getDescendants(true);
                         if (!glTFNode.children && directDescendents && directDescendents.length) {
                             var children = [];
                             for (var _a = 0, directDescendents_1 = directDescendents; _a < directDescendents_1.length; _a++) {
@@ -2093,11 +2272,11 @@ var _Exporter = /** @class */ (function () {
      * Creates a mapping of Node unique id to node index and handles animations
      * @param babylonScene Babylon Scene
      * @param nodes Babylon transform nodes
-     * @param shouldExportTransformNode Callback specifying if a transform node should be exported
+     * @param shouldExportNode Callback specifying if a transform node should be exported
      * @param binaryWriter Buffer to write binary data to
      * @returns Node mapping of unique id to index
      */
-    _Exporter.prototype.createNodeMapAndAnimationsAsync = function (babylonScene, nodes, shouldExportTransformNode, binaryWriter) {
+    _Exporter.prototype.createNodeMapAndAnimationsAsync = function (babylonScene, nodes, shouldExportNode, binaryWriter) {
         var _this = this;
         var promiseChain = Promise.resolve();
         var nodeMap = {};
@@ -2108,29 +2287,38 @@ var _Exporter = /** @class */ (function () {
             samplers: []
         };
         var idleGLTFAnimations = [];
-        var _loop_1 = function (babylonTransformNode) {
-            if (shouldExportTransformNode(babylonTransformNode)) {
+        var _loop_1 = function (babylonNode) {
+            if (shouldExportNode(babylonNode)) {
                 promiseChain = promiseChain.then(function () {
-                    return _this.createNodeAsync(babylonTransformNode, binaryWriter).then(function (node) {
-                        var directDescendents = babylonTransformNode.getDescendants(true, function (node) { return (node instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]); });
-                        if (directDescendents.length || node.mesh != null) {
-                            _this._nodes.push(node);
-                            nodeIndex = _this._nodes.length - 1;
-                            nodeMap[babylonTransformNode.uniqueId] = nodeIndex;
+                    return _this.createNodeAsync(babylonNode, binaryWriter).then(function (node) {
+                        var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode);
+                        if (promise == null) {
+                            babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Not exporting node " + babylonNode.name);
+                            return Promise.resolve();
                         }
-                        if (!babylonScene.animationGroups.length && babylonTransformNode.animations.length) {
-                            _glTFAnimation__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]._CreateNodeAnimationFromTransformNodeAnimations(babylonTransformNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystem, _this._animationSampleRate);
+                        else {
+                            return promise.then(function (node) {
+                                var directDescendents = babylonNode.getDescendants(true, function (node) { return (node instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Node"]); });
+                                if (directDescendents.length || node.mesh != null || (node.extensions)) {
+                                    _this._nodes.push(node);
+                                    nodeIndex = _this._nodes.length - 1;
+                                    nodeMap[babylonNode.uniqueId] = nodeIndex;
+                                }
+                                if (!babylonScene.animationGroups.length && babylonNode.animations.length) {
+                                    _glTFAnimation__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]._CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystem, _this._animationSampleRate);
+                                }
+                            });
                         }
                     });
                 });
             }
             else {
-                "Excluding mesh " + babylonTransformNode.name;
+                "Excluding node " + babylonNode.name;
             }
         };
         for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
-            var babylonTransformNode = nodes_2[_i];
-            _loop_1(babylonTransformNode);
+            var babylonNode = nodes_2[_i];
+            _loop_1(babylonNode);
         }
         return promiseChain.then(function () {
             if (runtimeGLTFAnimation.channels.length && runtimeGLTFAnimation.samplers.length) {
@@ -2153,25 +2341,30 @@ var _Exporter = /** @class */ (function () {
      * @param binaryWriter Buffer for storing geometry data
      * @returns glTF node
      */
-    _Exporter.prototype.createNodeAsync = function (babylonTransformNode, binaryWriter) {
+    _Exporter.prototype.createNodeAsync = function (babylonNode, binaryWriter) {
         var _this = this;
         return Promise.resolve().then(function () {
             // create node to hold translation/rotation/scale and the mesh
             var node = {};
             // create mesh
             var mesh = { primitives: [] };
-            if (babylonTransformNode.name) {
-                node.name = babylonTransformNode.name;
+            if (babylonNode.name) {
+                node.name = babylonNode.name;
+            }
+            if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]) {
+                // Set transformation
+                _this.setNodeTransformation(node, babylonNode);
+                return _this.setPrimitiveAttributesAsync(mesh, babylonNode, binaryWriter).then(function () {
+                    if (mesh.primitives.length) {
+                        _this._meshes.push(mesh);
+                        node.mesh = _this._meshes.length - 1;
+                    }
+                    return node;
+                });
             }
-            // Set transformation
-            _this.setNodeTransformation(node, babylonTransformNode);
-            return _this.setPrimitiveAttributesAsync(mesh, babylonTransformNode, binaryWriter).then(function () {
-                if (mesh.primitives.length) {
-                    _this._meshes.push(mesh);
-                    node.mesh = _this._meshes.length - 1;
-                }
+            else {
                 return node;
-            });
+            }
         });
     };
     _Exporter._ExtensionNames = new Array();
@@ -3778,7 +3971,7 @@ var _GLTFUtilities = /** @class */ (function () {
 /*!***************************!*\
   !*** ./glTF/2.0/index.ts ***!
   \***************************/
-/*! exports provided: GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform */
+/*! exports provided: GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
@@ -3809,6 +4002,8 @@ __webpack_require__.r(__webpack_exports__);
 /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_texture_transform"]; });
 
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_lights_punctual"]; });
+
 
 
 
@@ -3863,7 +4058,7 @@ var __IGLTFExporterExtension = 0; // I am here to allow dts to be created
 /*!******************************************!*\
   !*** ./legacy/legacy-glTF2Serializer.ts ***!
   \******************************************/
-/*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform */
+/*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
@@ -3893,6 +4088,8 @@ __webpack_require__.r(__webpack_exports__);
 
 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_texture_transform"]; });
 
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_lights_punctual"]; });
+
 
 
 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/serializers/babylon.glTF2Serializer.js.map


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/serializers/babylon.glTF2Serializer.min.js


+ 61 - 17
dist/preview release/serializers/babylonjs.serializers.d.ts

@@ -64,8 +64,21 @@ declare module BABYLON.GLTF2.Exporter {
          * @param meshPrimitive glTF mesh primitive
          * @param babylonSubMesh Babylon submesh
          * @param binaryWriter glTF serializer binary writer instance
+         * @returns nullable IMeshPrimitive promise
          */
         postExportMeshPrimitiveAsync?(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Nullable<Promise<IMeshPrimitive>>;
+        /**
+         * Define this method to modify the default behavior when exporting a node
+         * @param context The context when exporting the node
+         * @param node glTF node
+         * @param babylonNode BabylonJS node
+         * @returns nullable INode promise
+         */
+        postExportNodeAsync?(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+        /**
+         * Called after the exporter state changes to EXPORTING
+         */
+        onExporting?(): void;
     }
 }
 declare module BABYLON.GLTF2.Exporter {
@@ -316,11 +329,11 @@ declare module BABYLON {
      */
     export interface IExportOptions {
         /**
-         * Function which indicates whether a babylon mesh should be exported 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)
+         * Function which indicates whether a babylon node should be exported or not
+         * @param node source Babylon node. It is used to check whether it should be exported to glTF or not
+         * @returns boolean, which indicates whether the node should be exported (true) or not (false)
          */
-        shouldExportTransformNode?(transformNode: TransformNode): boolean;
+        shouldExportNode?(node: Node): boolean;
         /**
          * The sample rate to bake animation curves
          */
@@ -456,6 +469,10 @@ declare module BABYLON.GLTF2.Exporter {
      */
     export class _Exporter {
         /**
+         * Stores the glTF to export
+         */
+        _glTF: IGLTF;
+        /**
          * Stores all generated buffer views, which represents views into the main glTF buffer data
          */
         _bufferViews: IBufferView[];
@@ -468,10 +485,6 @@ declare module BABYLON.GLTF2.Exporter {
          */
         private _nodes;
         /**
-         * Stores the glTF asset information, which represents the glTF version and this file generator
-         */
-        private _asset;
-        /**
          * Stores all the generated glTF scenes, which stores multiple node hierarchies
          */
         private _scenes;
@@ -512,7 +525,7 @@ declare module BABYLON.GLTF2.Exporter {
         /**
          * Stores a reference to the Babylon scene containing the source geometry and material information
          */
-        private _babylonScene;
+        _babylonScene: Scene;
         /**
          * Stores a map of the image data, where the key is the file name and the value
          * is the image data
@@ -530,25 +543,26 @@ declare module BABYLON.GLTF2.Exporter {
         /**
          * Specifies if the Babylon scene should be converted to right-handed on export
          */
-        private _convertToRightHandedSystem;
+        _convertToRightHandedSystem: boolean;
         /**
          * Baked animation sample rate
          */
         private _animationSampleRate;
         /**
-         * Callback which specifies if a transform node should be exported or not
+         * Callback which specifies if a node should be exported or not
          */
-        private _shouldExportTransformNode;
+        private _shouldExportNode;
         private _localEngine;
         _glTFMaterialExporter: _GLTFMaterialExporter;
         private _extensions;
-        private _extensionsUsed;
-        private _extensionsRequired;
         private static _ExtensionNames;
         private static _ExtensionFactories;
         private _applyExtensions;
         _extensionsPreExportTextureAsync(context: string, babylonTexture: Texture, mimeType: ImageMimeType): Nullable<Promise<BaseTexture>>;
         _extensionsPostExportMeshPrimitiveAsync(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Nullable<Promise<IMeshPrimitive>>;
+        _extensionsPostExportNodeAsync(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+        private _forEachExtensions;
+        private _extensionsOnExporting;
         /**
          * Load glTF serializer extensions
          */
@@ -724,7 +738,7 @@ declare module BABYLON.GLTF2.Exporter {
          * Creates a mapping of Node unique id to node index and handles animations
          * @param babylonScene Babylon Scene
          * @param nodes Babylon transform nodes
-         * @param shouldExportTransformNode Callback specifying if a transform node should be exported
+         * @param shouldExportNode Callback specifying if a transform node should be exported
          * @param binaryWriter Buffer to write binary data to
          * @returns Node mapping of unique id to index
          */
@@ -869,7 +883,7 @@ declare module BABYLON.GLTF2.Exporter {
         /**
          * @ignore
          * Create node animations from the transform node animations
-         * @param babylonTransformNode
+         * @param babylonNode
          * @param runtimeGLTFAnimation
          * @param idleGLTFAnimations
          * @param nodeMap
@@ -879,7 +893,7 @@ declare module BABYLON.GLTF2.Exporter {
          * @param accessors
          * @param convertToRightHandedSystem
          */
-        static _CreateNodeAnimationFromTransformNodeAnimations(babylonTransformNode: TransformNode, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
+        static _CreateNodeAnimationFromNodeAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
             [key: number]: number;
         }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
         /**
@@ -1011,4 +1025,34 @@ declare module BABYLON.GLTF2.Exporter.Extensions {
          */
         textureTransformTextureAsync(babylonTexture: Texture, offset: Vector2, rotation: number, scale: Vector2, scene: Scene): Promise<BaseTexture>;
     }
+}
+declare module BABYLON.GLTF2.Exporter.Extensions {
+    /**
+     * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
+     */
+    export class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
+        /** The name of this extension. */
+        readonly name: string;
+        /** Defines whether this extension is enabled. */
+        enabled: boolean;
+        /** Defines whether this extension is required */
+        required: boolean;
+        /** Reference to the glTF exporter */
+        private _exporter;
+        private _lights;
+        /** @hidden */
+        constructor(exporter: _Exporter);
+        /** @hidden */
+        dispose(): void;
+        /** @hidden */
+        onExporting(): void;
+        /**
+         * Define this method to modify the default behavior when exporting a node
+         * @param context The context when exporting the node
+         * @param node glTF node
+         * @param babylonNode BabylonJS node
+         * @returns nullable INode promise
+         */
+        postExportNodeAsync(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+    }
 }

+ 293 - 90
dist/preview release/serializers/babylonjs.serializers.js

@@ -305,6 +305,169 @@ var OBJExport = /** @class */ (function () {
 
 /***/ }),
 
+/***/ "./glTF/2.0/Extensions/KHR_lights_punctual.ts":
+/*!****************************************************!*\
+  !*** ./glTF/2.0/Extensions/KHR_lights_punctual.ts ***!
+  \****************************************************/
+/*! exports provided: KHR_lights_punctual */
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
+
+"use strict";
+__webpack_require__.r(__webpack_exports__);
+/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return KHR_lights_punctual; });
+/* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! babylonjs/Maths/math */ "babylonjs/Maths/math");
+/* harmony import */ var babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__);
+/* harmony import */ var _glTFExporter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../glTFExporter */ "./glTF/2.0/glTFExporter.ts");
+/* harmony import */ var _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../glTFUtilities */ "./glTF/2.0/glTFUtilities.ts");
+
+
+
+
+
+
+var NAME = "KHR_lights_punctual";
+var LightType;
+(function (LightType) {
+    LightType["DIRECTIONAL"] = "directional";
+    LightType["POINT"] = "point";
+    LightType["SPOT"] = "spot";
+})(LightType || (LightType = {}));
+/**
+ * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
+ */
+var KHR_lights_punctual = /** @class */ (function () {
+    /** @hidden */
+    function KHR_lights_punctual(exporter) {
+        /** The name of this extension. */
+        this.name = NAME;
+        /** Defines whether this extension is enabled. */
+        this.enabled = true;
+        /** Defines whether this extension is required */
+        this.required = false;
+        this._exporter = exporter;
+    }
+    /** @hidden */
+    KHR_lights_punctual.prototype.dispose = function () {
+        delete this._exporter;
+        delete this._lights;
+    };
+    /** @hidden */
+    KHR_lights_punctual.prototype.onExporting = function () {
+        if (this._lights) {
+            if (this._exporter._glTF.extensionsUsed == null) {
+                this._exporter._glTF.extensionsUsed = [];
+            }
+            if (this._exporter._glTF.extensionsUsed.indexOf(NAME) === -1) {
+                this._exporter._glTF.extensionsUsed.push(NAME);
+            }
+            if (this.required) {
+                if (this._exporter._glTF.extensionsRequired == null) {
+                    this._exporter._glTF.extensionsRequired = [];
+                }
+                if (this._exporter._glTF.extensionsRequired.indexOf(NAME) === -1) {
+                    this._exporter._glTF.extensionsRequired.push(NAME);
+                }
+            }
+            if (this._exporter._glTF.extensions == null) {
+                this._exporter._glTF.extensions = {};
+            }
+            this._exporter._glTF.extensions[NAME] = this._lights;
+        }
+    };
+    /**
+     * Define this method to modify the default behavior when exporting a node
+     * @param context The context when exporting the node
+     * @param node glTF node
+     * @param babylonNode BabylonJS node
+     * @returns nullable INode promise
+     */
+    KHR_lights_punctual.prototype.postExportNodeAsync = function (context, node, babylonNode) {
+        var _this = this;
+        return new Promise(function (resolve, reject) {
+            if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["ShadowLight"]) {
+                var babylonLight = babylonNode;
+                var light = void 0;
+                var lightType = (babylonLight.getTypeID() == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_POINTLIGHT ? LightType.POINT : (babylonLight.getTypeID() == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_DIRECTIONALLIGHT ? LightType.DIRECTIONAL : (babylonLight.getTypeID() == babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].LIGHTTYPEID_SPOTLIGHT ? LightType.SPOT : null)));
+                if (lightType == null) {
+                    babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + ": Light " + babylonLight.name + " is not supported in " + NAME);
+                }
+                else {
+                    var lightPosition = babylonLight.position.clone();
+                    if (!lightPosition.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Vector3"].Zero())) {
+                        if (_this._exporter._convertToRightHandedSystem) {
+                            _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedPositionVector3FromRef(lightPosition);
+                        }
+                        node.translation = lightPosition.asArray();
+                    }
+                    if (lightType !== LightType.POINT) {
+                        var localAxis = babylonLight.direction;
+                        var yaw = -Math.atan2(localAxis.z, localAxis.x) + Math.PI / 2;
+                        var len = Math.sqrt(localAxis.x * localAxis.x + localAxis.z * localAxis.z);
+                        var pitch = -Math.atan2(localAxis.y, len);
+                        var lightRotationQuaternion = babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].RotationYawPitchRoll(yaw, pitch, 0);
+                        if (_this._exporter._convertToRightHandedSystem) {
+                            _glTFUtilities__WEBPACK_IMPORTED_MODULE_2__["_GLTFUtilities"]._GetRightHandedQuaternionFromRef(lightRotationQuaternion);
+                        }
+                        if (!lightRotationQuaternion.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Quaternion"].Identity())) {
+                            node.rotation = lightRotationQuaternion.asArray();
+                        }
+                    }
+                    if (babylonLight.falloffType !== babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Light"].FALLOFF_GLTF) {
+                        babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn(context + ": Light falloff for " + babylonLight.name + " does not match the " + NAME + " specification!");
+                    }
+                    light = {
+                        type: lightType
+                    };
+                    if (!babylonLight.diffuse.equals(babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Color3"].White())) {
+                        light.color = babylonLight.diffuse.asArray();
+                    }
+                    if (babylonLight.intensity !== 1.0) {
+                        light.intensity = babylonLight.intensity;
+                    }
+                    if (babylonLight.range !== Number.MAX_VALUE) {
+                        light.range = babylonLight.range;
+                    }
+                    if (lightType === LightType.SPOT) {
+                        var babylonSpotLight = babylonLight;
+                        if (babylonSpotLight.angle !== Math.PI / 2.0) {
+                            if (light.spot == null) {
+                                light.spot = {};
+                            }
+                            light.spot.outerConeAngle = babylonSpotLight.angle / 2.0;
+                        }
+                        if (babylonSpotLight.innerAngle !== 0) {
+                            if (light.spot == null) {
+                                light.spot = {};
+                            }
+                            light.spot.innerConeAngle = babylonSpotLight.innerAngle / 2.0;
+                        }
+                    }
+                    if (_this._lights == null) {
+                        _this._lights = {
+                            lights: []
+                        };
+                    }
+                    _this._lights.lights.push(light);
+                    if (node.extensions == null) {
+                        node.extensions = {};
+                    }
+                    var lightReference = {
+                        light: _this._lights.lights.length - 1
+                    };
+                    node.extensions[NAME] = lightReference;
+                }
+            }
+            resolve(node);
+        });
+    };
+    return KHR_lights_punctual;
+}());
+
+_glTFExporter__WEBPACK_IMPORTED_MODULE_1__["_Exporter"].RegisterExtension(NAME, function (exporter) { return new KHR_lights_punctual(exporter); });
+
+
+/***/ }),
+
 /***/ "./glTF/2.0/Extensions/KHR_texture_transform.ts":
 /*!******************************************************!*\
   !*** ./glTF/2.0/Extensions/KHR_texture_transform.ts ***!
@@ -413,7 +576,7 @@ _glTFExporter__WEBPACK_IMPORTED_MODULE_1__["_Exporter"].RegisterExtension(NAME,
 /*!**************************************!*\
   !*** ./glTF/2.0/Extensions/index.ts ***!
   \**************************************/
-/*! exports provided: KHR_texture_transform */
+/*! exports provided: KHR_texture_transform, KHR_lights_punctual */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
@@ -421,6 +584,10 @@ __webpack_require__.r(__webpack_exports__);
 /* harmony import */ var _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./KHR_texture_transform */ "./glTF/2.0/Extensions/KHR_texture_transform.ts");
 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _KHR_texture_transform__WEBPACK_IMPORTED_MODULE_0__["KHR_texture_transform"]; });
 
+/* harmony import */ var _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./KHR_lights_punctual */ "./glTF/2.0/Extensions/KHR_lights_punctual.ts");
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _KHR_lights_punctual__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
+
+
 
 
 
@@ -445,6 +612,7 @@ __webpack_require__.r(__webpack_exports__);
 
 
 
+
 /**
  * @hidden
  * Enum for handling in tangent and out tangent.
@@ -553,7 +721,7 @@ var _GLTFAnimation = /** @class */ (function () {
     /**
      * @ignore
      * Create node animations from the transform node animations
-     * @param babylonTransformNode
+     * @param babylonNode
      * @param runtimeGLTFAnimation
      * @param idleGLTFAnimations
      * @param nodeMap
@@ -563,21 +731,23 @@ var _GLTFAnimation = /** @class */ (function () {
      * @param accessors
      * @param convertToRightHandedSystem
      */
-    _GLTFAnimation._CreateNodeAnimationFromTransformNodeAnimations = function (babylonTransformNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
+    _GLTFAnimation._CreateNodeAnimationFromNodeAnimations = function (babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, nodes, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationSampleRate) {
         var glTFAnimation;
-        if (babylonTransformNode.animations) {
-            for (var _i = 0, _a = babylonTransformNode.animations; _i < _a.length; _i++) {
-                var animation = _a[_i];
-                var animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);
-                if (animationInfo) {
-                    glTFAnimation = {
-                        name: animation.name,
-                        samplers: [],
-                        channels: []
-                    };
-                    _GLTFAnimation.AddAnimation("" + animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonTransformNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
-                    if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
-                        idleGLTFAnimations.push(glTFAnimation);
+        if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]) {
+            if (babylonNode.animations) {
+                for (var _i = 0, _a = babylonNode.animations; _i < _a.length; _i++) {
+                    var animation = _a[_i];
+                    var animationInfo = _GLTFAnimation._DeduceAnimationInfo(animation);
+                    if (animationInfo) {
+                        glTFAnimation = {
+                            name: animation.name,
+                            samplers: [],
+                            channels: []
+                        };
+                        _GLTFAnimation.AddAnimation("" + animation.name, animation.hasRunningRuntimeAnimations ? runtimeGLTFAnimation : glTFAnimation, babylonNode, animation, animationInfo.dataAccessorType, animationInfo.animationChannelTargetPath, nodeMap, binaryWriter, bufferViews, accessors, convertToRightHandedSystem, animationInfo.useQuaternion, animationSampleRate);
+                        if (glTFAnimation.samplers.length && glTFAnimation.channels.length) {
+                            idleGLTFAnimations.push(glTFAnimation);
+                        }
                     }
                 }
             }
@@ -1188,6 +1358,7 @@ __webpack_require__.r(__webpack_exports__);
 
 
 
+
 /**
  * Converts Babylon Scene into glTF 2.0.
  * @hidden
@@ -1200,9 +1371,9 @@ var _Exporter = /** @class */ (function () {
      */
     function _Exporter(babylonScene, options) {
         this._extensions = {};
-        this._asset = { generator: "BabylonJS", version: "2.0" };
-        this._extensionsUsed = [];
-        this._extensionsRequired = [];
+        this._glTF = {
+            asset: { generator: "BabylonJS", version: "2.0" }
+        };
         this._babylonScene = babylonScene;
         this._bufferViews = [];
         this._accessors = [];
@@ -1218,7 +1389,7 @@ var _Exporter = /** @class */ (function () {
         this._imageData = {};
         this._convertToRightHandedSystem = this._babylonScene.useRightHandedSystem ? false : true;
         var _options = options || {};
-        this._shouldExportTransformNode = _options.shouldExportTransformNode ? _options.shouldExportTransformNode : function (babylonTransformNode) { return true; };
+        this._shouldExportNode = _options.shouldExportNode ? _options.shouldExportNode : function (babylonNode) { return true; };
         this._animationSampleRate = _options.animationSampleRate ? _options.animationSampleRate : 1 / 60;
         this._glTFMaterialExporter = new _glTFMaterialExporter__WEBPACK_IMPORTED_MODULE_1__["_GLTFMaterialExporter"](this);
         this._loadExtensions();
@@ -1254,14 +1425,29 @@ var _Exporter = /** @class */ (function () {
     _Exporter.prototype._extensionsPostExportMeshPrimitiveAsync = function (context, meshPrimitive, babylonSubMesh, binaryWriter) {
         return this._applyExtensions(meshPrimitive, function (extension) { return extension.postExportMeshPrimitiveAsync && extension.postExportMeshPrimitiveAsync(context, meshPrimitive, babylonSubMesh, binaryWriter); });
     };
+    _Exporter.prototype._extensionsPostExportNodeAsync = function (context, node, babylonNode) {
+        return this._applyExtensions(node, function (extension) { return extension.postExportNodeAsync && extension.postExportNodeAsync(context, node, babylonNode); });
+    };
+    _Exporter.prototype._forEachExtensions = function (action) {
+        for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
+            var name_2 = _a[_i];
+            var extension = this._extensions[name_2];
+            if (extension.enabled) {
+                action(extension);
+            }
+        }
+    };
+    _Exporter.prototype._extensionsOnExporting = function () {
+        this._forEachExtensions(function (extension) { return extension.onExporting && extension.onExporting(); });
+    };
     /**
      * Load glTF serializer extensions
      */
     _Exporter.prototype._loadExtensions = function () {
         for (var _i = 0, _a = _Exporter._ExtensionNames; _i < _a.length; _i++) {
-            var name_2 = _a[_i];
-            var extension = _Exporter._ExtensionFactories[name_2](this);
-            this._extensions[name_2] = extension;
+            var name_3 = _a[_i];
+            var extension = _Exporter._ExtensionFactories[name_3](this);
+            this._extensions[name_3] = extension;
         }
     };
     /**
@@ -1693,52 +1879,43 @@ var _Exporter = /** @class */ (function () {
         var imageData;
         var bufferView;
         var byteOffset = this._totalByteLength;
-        var glTF = {
-            asset: this._asset
-        };
-        if (this._extensionsUsed && this._extensionsUsed.length) {
-            glTF.extensionsUsed = this._extensionsUsed;
-        }
-        if (this._extensionsRequired && this._extensionsRequired.length) {
-            glTF.extensionsRequired = this._extensionsRequired;
-        }
         if (buffer.byteLength) {
-            glTF.buffers = [buffer];
+            this._glTF.buffers = [buffer];
         }
         if (this._nodes && this._nodes.length) {
-            glTF.nodes = this._nodes;
+            this._glTF.nodes = this._nodes;
         }
         if (this._meshes && this._meshes.length) {
-            glTF.meshes = this._meshes;
+            this._glTF.meshes = this._meshes;
         }
         if (this._scenes && this._scenes.length) {
-            glTF.scenes = this._scenes;
-            glTF.scene = 0;
+            this._glTF.scenes = this._scenes;
+            this._glTF.scene = 0;
         }
         if (this._bufferViews && this._bufferViews.length) {
-            glTF.bufferViews = this._bufferViews;
+            this._glTF.bufferViews = this._bufferViews;
         }
         if (this._accessors && this._accessors.length) {
-            glTF.accessors = this._accessors;
+            this._glTF.accessors = this._accessors;
         }
         if (this._animations && this._animations.length) {
-            glTF.animations = this._animations;
+            this._glTF.animations = this._animations;
         }
         if (this._materials && this._materials.length) {
-            glTF.materials = this._materials;
+            this._glTF.materials = this._materials;
         }
         if (this._textures && this._textures.length) {
-            glTF.textures = this._textures;
+            this._glTF.textures = this._textures;
         }
         if (this._samplers && this._samplers.length) {
-            glTF.samplers = this._samplers;
+            this._glTF.samplers = this._samplers;
         }
         if (this._images && this._images.length) {
             if (!shouldUseGlb) {
-                glTF.images = this._images;
+                this._glTF.images = this._images;
             }
             else {
-                glTF.images = [];
+                this._glTF.images = [];
                 this._images.forEach(function (image) {
                     if (image.uri) {
                         imageData = _this._imageData[image.uri];
@@ -1750,10 +1927,10 @@ var _Exporter = /** @class */ (function () {
                         image.name = imageName;
                         image.mimeType = imageData.mimeType;
                         image.uri = undefined;
-                        if (!glTF.images) {
-                            glTF.images = [];
+                        if (!_this._glTF.images) {
+                            _this._glTF.images = [];
                         }
-                        glTF.images.push(image);
+                        _this._glTF.images.push(image);
                     }
                 });
                 // Replace uri with bufferview and mime type for glb
@@ -1763,7 +1940,7 @@ var _Exporter = /** @class */ (function () {
         if (!shouldUseGlb) {
             buffer.uri = glTFPrefix + ".bin";
         }
-        var jsonText = prettyPrint ? JSON.stringify(glTF, null, 2) : JSON.stringify(glTF);
+        var jsonText = prettyPrint ? JSON.stringify(this._glTF, null, 2) : JSON.stringify(this._glTF);
         return jsonText;
     };
     /**
@@ -1774,6 +1951,7 @@ var _Exporter = /** @class */ (function () {
     _Exporter.prototype._generateGLTFAsync = function (glTFPrefix) {
         var _this = this;
         return this._generateBinaryAsync().then(function (binaryBuffer) {
+            _this._extensionsOnExporting();
             var jsonText = _this.generateJSON(false, glTFPrefix, true);
             var bin = new Blob([binaryBuffer], { type: 'application/octet-stream' });
             var glTFFileName = glTFPrefix + '.gltf';
@@ -1822,6 +2000,7 @@ var _Exporter = /** @class */ (function () {
     _Exporter.prototype._generateGLBAsync = function (glTFPrefix) {
         var _this = this;
         return this._generateBinaryAsync().then(function (binaryBuffer) {
+            _this._extensionsOnExporting();
             var jsonText = _this.generateJSON(true);
             var glbFileName = glTFPrefix + '.glb';
             var headerLength = 12;
@@ -2217,9 +2396,9 @@ var _Exporter = /** @class */ (function () {
         var glTFNodeIndex;
         var glTFNode;
         var directDescendents;
-        var nodes = babylonScene.transformNodes.concat(babylonScene.meshes);
+        var nodes = babylonScene.transformNodes.concat(babylonScene.meshes, babylonScene.lights);
         return this._glTFMaterialExporter._convertMaterialsToGLTFAsync(babylonScene.materials, "image/png" /* PNG */, true).then(function () {
-            return _this.createNodeMapAndAnimationsAsync(babylonScene, nodes, _this._shouldExportTransformNode, binaryWriter).then(function (nodeMap) {
+            return _this.createNodeMapAndAnimationsAsync(babylonScene, nodes, _this._shouldExportNode, binaryWriter).then(function (nodeMap) {
                 _this._nodeMap = nodeMap;
                 _this._totalByteLength = binaryWriter.getByteOffset();
                 if (_this._totalByteLength == undefined) {
@@ -2227,13 +2406,13 @@ var _Exporter = /** @class */ (function () {
                 }
                 // Build Hierarchy with the node map.
                 for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
-                    var babylonTransformNode = nodes_1[_i];
-                    glTFNodeIndex = _this._nodeMap[babylonTransformNode.uniqueId];
-                    if (glTFNodeIndex != null) {
+                    var babylonNode = nodes_1[_i];
+                    glTFNodeIndex = _this._nodeMap[babylonNode.uniqueId];
+                    if (glTFNodeIndex !== undefined) {
                         glTFNode = _this._nodes[glTFNodeIndex];
-                        if (!babylonTransformNode.parent) {
-                            if (!_this._shouldExportTransformNode(babylonTransformNode)) {
-                                babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("Omitting " + babylonTransformNode.name + " from scene.");
+                        if (!babylonNode.parent) {
+                            if (!_this._shouldExportNode(babylonNode)) {
+                                babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Log("Omitting " + babylonNode.name + " from scene.");
                             }
                             else {
                                 if (_this._convertToRightHandedSystem) {
@@ -2246,7 +2425,7 @@ var _Exporter = /** @class */ (function () {
                                 scene.nodes.push(glTFNodeIndex);
                             }
                         }
-                        directDescendents = babylonTransformNode.getDescendants(true);
+                        directDescendents = babylonNode.getDescendants(true);
                         if (!glTFNode.children && directDescendents && directDescendents.length) {
                             var children = [];
                             for (var _a = 0, directDescendents_1 = directDescendents; _a < directDescendents_1.length; _a++) {
@@ -2271,11 +2450,11 @@ var _Exporter = /** @class */ (function () {
      * Creates a mapping of Node unique id to node index and handles animations
      * @param babylonScene Babylon Scene
      * @param nodes Babylon transform nodes
-     * @param shouldExportTransformNode Callback specifying if a transform node should be exported
+     * @param shouldExportNode Callback specifying if a transform node should be exported
      * @param binaryWriter Buffer to write binary data to
      * @returns Node mapping of unique id to index
      */
-    _Exporter.prototype.createNodeMapAndAnimationsAsync = function (babylonScene, nodes, shouldExportTransformNode, binaryWriter) {
+    _Exporter.prototype.createNodeMapAndAnimationsAsync = function (babylonScene, nodes, shouldExportNode, binaryWriter) {
         var _this = this;
         var promiseChain = Promise.resolve();
         var nodeMap = {};
@@ -2286,29 +2465,38 @@ var _Exporter = /** @class */ (function () {
             samplers: []
         };
         var idleGLTFAnimations = [];
-        var _loop_1 = function (babylonTransformNode) {
-            if (shouldExportTransformNode(babylonTransformNode)) {
+        var _loop_1 = function (babylonNode) {
+            if (shouldExportNode(babylonNode)) {
                 promiseChain = promiseChain.then(function () {
-                    return _this.createNodeAsync(babylonTransformNode, binaryWriter).then(function (node) {
-                        var directDescendents = babylonTransformNode.getDescendants(true, function (node) { return (node instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]); });
-                        if (directDescendents.length || node.mesh != null) {
-                            _this._nodes.push(node);
-                            nodeIndex = _this._nodes.length - 1;
-                            nodeMap[babylonTransformNode.uniqueId] = nodeIndex;
+                    return _this.createNodeAsync(babylonNode, binaryWriter).then(function (node) {
+                        var promise = _this._extensionsPostExportNodeAsync("createNodeAsync", node, babylonNode);
+                        if (promise == null) {
+                            babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Tools"].Warn("Not exporting node " + babylonNode.name);
+                            return Promise.resolve();
                         }
-                        if (!babylonScene.animationGroups.length && babylonTransformNode.animations.length) {
-                            _glTFAnimation__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]._CreateNodeAnimationFromTransformNodeAnimations(babylonTransformNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystem, _this._animationSampleRate);
+                        else {
+                            return promise.then(function (node) {
+                                var directDescendents = babylonNode.getDescendants(true, function (node) { return (node instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["Node"]); });
+                                if (directDescendents.length || node.mesh != null || (node.extensions)) {
+                                    _this._nodes.push(node);
+                                    nodeIndex = _this._nodes.length - 1;
+                                    nodeMap[babylonNode.uniqueId] = nodeIndex;
+                                }
+                                if (!babylonScene.animationGroups.length && babylonNode.animations.length) {
+                                    _glTFAnimation__WEBPACK_IMPORTED_MODULE_4__["_GLTFAnimation"]._CreateNodeAnimationFromNodeAnimations(babylonNode, runtimeGLTFAnimation, idleGLTFAnimations, nodeMap, _this._nodes, binaryWriter, _this._bufferViews, _this._accessors, _this._convertToRightHandedSystem, _this._animationSampleRate);
+                                }
+                            });
                         }
                     });
                 });
             }
             else {
-                "Excluding mesh " + babylonTransformNode.name;
+                "Excluding node " + babylonNode.name;
             }
         };
         for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
-            var babylonTransformNode = nodes_2[_i];
-            _loop_1(babylonTransformNode);
+            var babylonNode = nodes_2[_i];
+            _loop_1(babylonNode);
         }
         return promiseChain.then(function () {
             if (runtimeGLTFAnimation.channels.length && runtimeGLTFAnimation.samplers.length) {
@@ -2331,25 +2519,30 @@ var _Exporter = /** @class */ (function () {
      * @param binaryWriter Buffer for storing geometry data
      * @returns glTF node
      */
-    _Exporter.prototype.createNodeAsync = function (babylonTransformNode, binaryWriter) {
+    _Exporter.prototype.createNodeAsync = function (babylonNode, binaryWriter) {
         var _this = this;
         return Promise.resolve().then(function () {
             // create node to hold translation/rotation/scale and the mesh
             var node = {};
             // create mesh
             var mesh = { primitives: [] };
-            if (babylonTransformNode.name) {
-                node.name = babylonTransformNode.name;
-            }
-            // Set transformation
-            _this.setNodeTransformation(node, babylonTransformNode);
-            return _this.setPrimitiveAttributesAsync(mesh, babylonTransformNode, binaryWriter).then(function () {
-                if (mesh.primitives.length) {
-                    _this._meshes.push(mesh);
-                    node.mesh = _this._meshes.length - 1;
-                }
+            if (babylonNode.name) {
+                node.name = babylonNode.name;
+            }
+            if (babylonNode instanceof babylonjs_Maths_math__WEBPACK_IMPORTED_MODULE_0__["TransformNode"]) {
+                // Set transformation
+                _this.setNodeTransformation(node, babylonNode);
+                return _this.setPrimitiveAttributesAsync(mesh, babylonNode, binaryWriter).then(function () {
+                    if (mesh.primitives.length) {
+                        _this._meshes.push(mesh);
+                        node.mesh = _this._meshes.length - 1;
+                    }
+                    return node;
+                });
+            }
+            else {
                 return node;
-            });
+            }
         });
     };
     _Exporter._ExtensionNames = new Array();
@@ -3956,7 +4149,7 @@ var _GLTFUtilities = /** @class */ (function () {
 /*!***************************!*\
   !*** ./glTF/2.0/index.ts ***!
   \***************************/
-/*! exports provided: GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform */
+/*! exports provided: GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
@@ -3987,6 +4180,8 @@ __webpack_require__.r(__webpack_exports__);
 /* harmony import */ var _Extensions__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./Extensions */ "./glTF/2.0/Extensions/index.ts");
 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_texture_transform"]; });
 
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _Extensions__WEBPACK_IMPORTED_MODULE_7__["KHR_lights_punctual"]; });
+
 
 
 
@@ -4041,7 +4236,7 @@ var __IGLTFExporterExtension = 0; // I am here to allow dts to be created
 /*!***********************!*\
   !*** ./glTF/index.ts ***!
   \***********************/
-/*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform */
+/*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
@@ -4068,6 +4263,8 @@ __webpack_require__.r(__webpack_exports__);
 
 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
 
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _2_0__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
+
 
 
 
@@ -4078,7 +4275,7 @@ __webpack_require__.r(__webpack_exports__);
 /*!******************!*\
   !*** ./index.ts ***!
   \******************/
-/*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, OBJExport, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform */
+/*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, OBJExport, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
@@ -4107,6 +4304,8 @@ __webpack_require__.r(__webpack_exports__);
 
 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
 
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _glTF__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
+
 
 
 
@@ -4117,7 +4316,7 @@ __webpack_require__.r(__webpack_exports__);
 /*!******************************************!*\
   !*** ./legacy/legacy-glTF2Serializer.ts ***!
   \******************************************/
-/*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform */
+/*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, KHR_texture_transform, KHR_lights_punctual */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
@@ -4147,6 +4346,8 @@ __webpack_require__.r(__webpack_exports__);
 
 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_texture_transform"]; });
 
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _glTF_2_0__WEBPACK_IMPORTED_MODULE_4__["KHR_lights_punctual"]; });
+
 
 
 
@@ -4228,7 +4429,7 @@ if (typeof globalObject !== "undefined") {
 /*!**************************!*\
   !*** ./legacy/legacy.ts ***!
   \**************************/
-/*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, OBJExport, KHR_texture_transform */
+/*! exports provided: __IGLTFExporterExtension, GLTFData, GLTF2Export, _GLTFAnimation, _Exporter, _BinaryWriter, __IGLTFExporterExtensionV2, _GLTFMaterialExporter, _GLTFUtilities, OBJExport, KHR_texture_transform, KHR_lights_punctual */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
@@ -4255,6 +4456,8 @@ __webpack_require__.r(__webpack_exports__);
 
 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_texture_transform", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["KHR_texture_transform"]; });
 
+/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "KHR_lights_punctual", function() { return _legacy_glTF2Serializer__WEBPACK_IMPORTED_MODULE_1__["KHR_lights_punctual"]; });
+
 /* harmony import */ var _legacy_objSerializer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./legacy-objSerializer */ "./legacy/legacy-objSerializer.ts");
 /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "OBJExport", function() { return _legacy_objSerializer__WEBPACK_IMPORTED_MODULE_2__["OBJExport"]; });
 

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/serializers/babylonjs.serializers.js.map


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/serializers/babylonjs.serializers.min.js


+ 134 - 37
dist/preview release/serializers/babylonjs.serializers.module.d.ts

@@ -47,7 +47,8 @@ declare module "babylonjs-serializers/glTF/glTFFileExporter" {
     }
 }
 declare module "babylonjs-serializers/glTF/2.0/glTFExporterExtension" {
-    import { ImageMimeType, IMeshPrimitive } from "babylonjs-gltf2interface";
+    import { ImageMimeType, IMeshPrimitive, INode } from "babylonjs-gltf2interface";
+    import { Node } from "babylonjs/node";
     import { Nullable } from "babylonjs/types";
     import { Texture } from "babylonjs/Materials/Textures/texture";
     import { SubMesh } from "babylonjs/Meshes/subMesh";
@@ -75,8 +76,21 @@ declare module "babylonjs-serializers/glTF/2.0/glTFExporterExtension" {
          * @param meshPrimitive glTF mesh primitive
          * @param babylonSubMesh Babylon submesh
          * @param binaryWriter glTF serializer binary writer instance
+         * @returns nullable IMeshPrimitive promise
          */
         postExportMeshPrimitiveAsync?(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Nullable<Promise<IMeshPrimitive>>;
+        /**
+         * Define this method to modify the default behavior when exporting a node
+         * @param context The context when exporting the node
+         * @param node glTF node
+         * @param babylonNode BabylonJS node
+         * @returns nullable INode promise
+         */
+        postExportNodeAsync?(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+        /**
+         * Called after the exporter state changes to EXPORTING
+         */
+        onExporting?(): void;
     }
 }
 declare module "babylonjs-serializers/glTF/2.0/glTFMaterialExporter" {
@@ -330,7 +344,7 @@ declare module "babylonjs-serializers/glTF/2.0/glTFData" {
     }
 }
 declare module "babylonjs-serializers/glTF/2.0/glTFSerializer" {
-    import { TransformNode } from "babylonjs/Meshes/transformNode";
+    import { Node } from "babylonjs/node";
     import { Scene } from "babylonjs/scene";
     import { GLTFData } from "babylonjs-serializers/glTF/2.0/glTFData";
     /**
@@ -338,11 +352,11 @@ declare module "babylonjs-serializers/glTF/2.0/glTFSerializer" {
      */
     export interface IExportOptions {
         /**
-         * Function which indicates whether a babylon mesh should be exported 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)
+         * Function which indicates whether a babylon node should be exported or not
+         * @param node source Babylon node. It is used to check whether it should be exported to glTF or not
+         * @returns boolean, which indicates whether the node should be exported (true) or not (false)
          */
-        shouldExportTransformNode?(transformNode: TransformNode): boolean;
+        shouldExportNode?(node: Node): boolean;
         /**
          * The sample rate to bake animation curves
          */
@@ -475,9 +489,10 @@ declare module "babylonjs-serializers/glTF/2.0/glTFUtilities" {
     }
 }
 declare module "babylonjs-serializers/glTF/2.0/glTFExporter" {
-    import { IBufferView, IAccessor, IMaterial, ITexture, IImage, ISampler, ImageMimeType, IMeshPrimitive } from "babylonjs-gltf2interface";
+    import { IBufferView, IAccessor, INode, IMaterial, ITexture, IImage, ISampler, ImageMimeType, IMeshPrimitive, IGLTF } from "babylonjs-gltf2interface";
     import { FloatArray, Nullable } from "babylonjs/types";
     import { Vector3, Vector4 } from "babylonjs/Maths/math";
+    import { Node } from "babylonjs/node";
     import { SubMesh } from "babylonjs/Meshes/subMesh";
     import { BaseTexture } from "babylonjs/Materials/Textures/baseTexture";
     import { Texture } from "babylonjs/Materials/Textures/texture";
@@ -493,6 +508,10 @@ declare module "babylonjs-serializers/glTF/2.0/glTFExporter" {
      */
     export class _Exporter {
         /**
+         * Stores the glTF to export
+         */
+        _glTF: IGLTF;
+        /**
          * Stores all generated buffer views, which represents views into the main glTF buffer data
          */
         _bufferViews: IBufferView[];
@@ -505,10 +524,6 @@ declare module "babylonjs-serializers/glTF/2.0/glTFExporter" {
          */
         private _nodes;
         /**
-         * Stores the glTF asset information, which represents the glTF version and this file generator
-         */
-        private _asset;
-        /**
          * Stores all the generated glTF scenes, which stores multiple node hierarchies
          */
         private _scenes;
@@ -549,7 +564,7 @@ declare module "babylonjs-serializers/glTF/2.0/glTFExporter" {
         /**
          * Stores a reference to the Babylon scene containing the source geometry and material information
          */
-        private _babylonScene;
+        _babylonScene: Scene;
         /**
          * Stores a map of the image data, where the key is the file name and the value
          * is the image data
@@ -567,25 +582,26 @@ declare module "babylonjs-serializers/glTF/2.0/glTFExporter" {
         /**
          * Specifies if the Babylon scene should be converted to right-handed on export
          */
-        private _convertToRightHandedSystem;
+        _convertToRightHandedSystem: boolean;
         /**
          * Baked animation sample rate
          */
         private _animationSampleRate;
         /**
-         * Callback which specifies if a transform node should be exported or not
+         * Callback which specifies if a node should be exported or not
          */
-        private _shouldExportTransformNode;
+        private _shouldExportNode;
         private _localEngine;
         _glTFMaterialExporter: _GLTFMaterialExporter;
         private _extensions;
-        private _extensionsUsed;
-        private _extensionsRequired;
         private static _ExtensionNames;
         private static _ExtensionFactories;
         private _applyExtensions;
         _extensionsPreExportTextureAsync(context: string, babylonTexture: Texture, mimeType: ImageMimeType): Nullable<Promise<BaseTexture>>;
         _extensionsPostExportMeshPrimitiveAsync(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Nullable<Promise<IMeshPrimitive>>;
+        _extensionsPostExportNodeAsync(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+        private _forEachExtensions;
+        private _extensionsOnExporting;
         /**
          * Load glTF serializer extensions
          */
@@ -761,7 +777,7 @@ declare module "babylonjs-serializers/glTF/2.0/glTFExporter" {
          * Creates a mapping of Node unique id to node index and handles animations
          * @param babylonScene Babylon Scene
          * @param nodes Babylon transform nodes
-         * @param shouldExportTransformNode Callback specifying if a transform node should be exported
+         * @param shouldExportNode Callback specifying if a transform node should be exported
          * @param binaryWriter Buffer to write binary data to
          * @returns Node mapping of unique id to index
          */
@@ -843,6 +859,7 @@ declare module "babylonjs-serializers/glTF/2.0/glTFExporter" {
 }
 declare module "babylonjs-serializers/glTF/2.0/glTFAnimation" {
     import { AnimationSamplerInterpolation, AnimationChannelTargetPath, AccessorType, IAnimation, INode, IBufferView, IAccessor } from "babylonjs-gltf2interface";
+    import { Node } from "babylonjs/node";
     import { Nullable } from "babylonjs/types";
     import { Animation } from "babylonjs/Animations/animation";
     import { TransformNode } from "babylonjs/Meshes/transformNode";
@@ -912,7 +929,7 @@ declare module "babylonjs-serializers/glTF/2.0/glTFAnimation" {
         /**
          * @ignore
          * Create node animations from the transform node animations
-         * @param babylonTransformNode
+         * @param babylonNode
          * @param runtimeGLTFAnimation
          * @param idleGLTFAnimations
          * @param nodeMap
@@ -922,7 +939,7 @@ declare module "babylonjs-serializers/glTF/2.0/glTFAnimation" {
          * @param accessors
          * @param convertToRightHandedSystem
          */
-        static _CreateNodeAnimationFromTransformNodeAnimations(babylonTransformNode: TransformNode, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
+        static _CreateNodeAnimationFromNodeAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
             [key: number]: number;
         }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
         /**
@@ -1064,8 +1081,44 @@ declare module "babylonjs-serializers/glTF/2.0/Extensions/KHR_texture_transform"
         textureTransformTextureAsync(babylonTexture: Texture, offset: Vector2, rotation: number, scale: Vector2, scene: Scene): Promise<BaseTexture>;
     }
 }
+declare module "babylonjs-serializers/glTF/2.0/Extensions/KHR_lights_punctual" {
+    import { Node } from "babylonjs/node";
+    import { INode } from "babylonjs-gltf2interface";
+    import { IGLTFExporterExtensionV2 } from "babylonjs-serializers/glTF/2.0/glTFExporterExtension";
+    import { _Exporter } from "babylonjs-serializers/glTF/2.0/glTFExporter";
+    import { Nullable } from 'babylonjs';
+    /**
+     * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
+     */
+    export class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
+        /** The name of this extension. */
+        readonly name: string;
+        /** Defines whether this extension is enabled. */
+        enabled: boolean;
+        /** Defines whether this extension is required */
+        required: boolean;
+        /** Reference to the glTF exporter */
+        private _exporter;
+        private _lights;
+        /** @hidden */
+        constructor(exporter: _Exporter);
+        /** @hidden */
+        dispose(): void;
+        /** @hidden */
+        onExporting(): void;
+        /**
+         * Define this method to modify the default behavior when exporting a node
+         * @param context The context when exporting the node
+         * @param node glTF node
+         * @param babylonNode BabylonJS node
+         * @returns nullable INode promise
+         */
+        postExportNodeAsync(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+    }
+}
 declare module "babylonjs-serializers/glTF/2.0/Extensions/index" {
     export * from "babylonjs-serializers/glTF/2.0/Extensions/KHR_texture_transform";
+    export * from "babylonjs-serializers/glTF/2.0/Extensions/KHR_lights_punctual";
 }
 declare module "babylonjs-serializers/glTF/2.0/index" {
     export * from "babylonjs-serializers/glTF/2.0/glTFAnimation";
@@ -1166,8 +1219,21 @@ declare module BABYLON.GLTF2.Exporter {
          * @param meshPrimitive glTF mesh primitive
          * @param babylonSubMesh Babylon submesh
          * @param binaryWriter glTF serializer binary writer instance
+         * @returns nullable IMeshPrimitive promise
          */
         postExportMeshPrimitiveAsync?(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Nullable<Promise<IMeshPrimitive>>;
+        /**
+         * Define this method to modify the default behavior when exporting a node
+         * @param context The context when exporting the node
+         * @param node glTF node
+         * @param babylonNode BabylonJS node
+         * @returns nullable INode promise
+         */
+        postExportNodeAsync?(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+        /**
+         * Called after the exporter state changes to EXPORTING
+         */
+        onExporting?(): void;
     }
 }
 declare module BABYLON.GLTF2.Exporter {
@@ -1418,11 +1484,11 @@ declare module BABYLON {
      */
     export interface IExportOptions {
         /**
-         * Function which indicates whether a babylon mesh should be exported 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)
+         * Function which indicates whether a babylon node should be exported or not
+         * @param node source Babylon node. It is used to check whether it should be exported to glTF or not
+         * @returns boolean, which indicates whether the node should be exported (true) or not (false)
          */
-        shouldExportTransformNode?(transformNode: TransformNode): boolean;
+        shouldExportNode?(node: Node): boolean;
         /**
          * The sample rate to bake animation curves
          */
@@ -1558,6 +1624,10 @@ declare module BABYLON.GLTF2.Exporter {
      */
     export class _Exporter {
         /**
+         * Stores the glTF to export
+         */
+        _glTF: IGLTF;
+        /**
          * Stores all generated buffer views, which represents views into the main glTF buffer data
          */
         _bufferViews: IBufferView[];
@@ -1570,10 +1640,6 @@ declare module BABYLON.GLTF2.Exporter {
          */
         private _nodes;
         /**
-         * Stores the glTF asset information, which represents the glTF version and this file generator
-         */
-        private _asset;
-        /**
          * Stores all the generated glTF scenes, which stores multiple node hierarchies
          */
         private _scenes;
@@ -1614,7 +1680,7 @@ declare module BABYLON.GLTF2.Exporter {
         /**
          * Stores a reference to the Babylon scene containing the source geometry and material information
          */
-        private _babylonScene;
+        _babylonScene: Scene;
         /**
          * Stores a map of the image data, where the key is the file name and the value
          * is the image data
@@ -1632,25 +1698,26 @@ declare module BABYLON.GLTF2.Exporter {
         /**
          * Specifies if the Babylon scene should be converted to right-handed on export
          */
-        private _convertToRightHandedSystem;
+        _convertToRightHandedSystem: boolean;
         /**
          * Baked animation sample rate
          */
         private _animationSampleRate;
         /**
-         * Callback which specifies if a transform node should be exported or not
+         * Callback which specifies if a node should be exported or not
          */
-        private _shouldExportTransformNode;
+        private _shouldExportNode;
         private _localEngine;
         _glTFMaterialExporter: _GLTFMaterialExporter;
         private _extensions;
-        private _extensionsUsed;
-        private _extensionsRequired;
         private static _ExtensionNames;
         private static _ExtensionFactories;
         private _applyExtensions;
         _extensionsPreExportTextureAsync(context: string, babylonTexture: Texture, mimeType: ImageMimeType): Nullable<Promise<BaseTexture>>;
         _extensionsPostExportMeshPrimitiveAsync(context: string, meshPrimitive: IMeshPrimitive, babylonSubMesh: SubMesh, binaryWriter: _BinaryWriter): Nullable<Promise<IMeshPrimitive>>;
+        _extensionsPostExportNodeAsync(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+        private _forEachExtensions;
+        private _extensionsOnExporting;
         /**
          * Load glTF serializer extensions
          */
@@ -1826,7 +1893,7 @@ declare module BABYLON.GLTF2.Exporter {
          * Creates a mapping of Node unique id to node index and handles animations
          * @param babylonScene Babylon Scene
          * @param nodes Babylon transform nodes
-         * @param shouldExportTransformNode Callback specifying if a transform node should be exported
+         * @param shouldExportNode Callback specifying if a transform node should be exported
          * @param binaryWriter Buffer to write binary data to
          * @returns Node mapping of unique id to index
          */
@@ -1971,7 +2038,7 @@ declare module BABYLON.GLTF2.Exporter {
         /**
          * @ignore
          * Create node animations from the transform node animations
-         * @param babylonTransformNode
+         * @param babylonNode
          * @param runtimeGLTFAnimation
          * @param idleGLTFAnimations
          * @param nodeMap
@@ -1981,7 +2048,7 @@ declare module BABYLON.GLTF2.Exporter {
          * @param accessors
          * @param convertToRightHandedSystem
          */
-        static _CreateNodeAnimationFromTransformNodeAnimations(babylonTransformNode: TransformNode, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
+        static _CreateNodeAnimationFromNodeAnimations(babylonNode: Node, runtimeGLTFAnimation: IAnimation, idleGLTFAnimations: IAnimation[], nodeMap: {
             [key: number]: number;
         }, nodes: INode[], binaryWriter: _BinaryWriter, bufferViews: IBufferView[], accessors: IAccessor[], convertToRightHandedSystem: boolean, animationSampleRate: number): void;
         /**
@@ -2113,4 +2180,34 @@ declare module BABYLON.GLTF2.Exporter.Extensions {
          */
         textureTransformTextureAsync(babylonTexture: Texture, offset: Vector2, rotation: number, scale: Vector2, scene: Scene): Promise<BaseTexture>;
     }
+}
+declare module BABYLON.GLTF2.Exporter.Extensions {
+    /**
+     * [Specification](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_lights_punctual/README.md)
+     */
+    export class KHR_lights_punctual implements IGLTFExporterExtensionV2 {
+        /** The name of this extension. */
+        readonly name: string;
+        /** Defines whether this extension is enabled. */
+        enabled: boolean;
+        /** Defines whether this extension is required */
+        required: boolean;
+        /** Reference to the glTF exporter */
+        private _exporter;
+        private _lights;
+        /** @hidden */
+        constructor(exporter: _Exporter);
+        /** @hidden */
+        dispose(): void;
+        /** @hidden */
+        onExporting(): void;
+        /**
+         * Define this method to modify the default behavior when exporting a node
+         * @param context The context when exporting the node
+         * @param node glTF node
+         * @param babylonNode BabylonJS node
+         * @returns nullable INode promise
+         */
+        postExportNodeAsync(context: string, node: INode, babylonNode: Node): Nullable<Promise<INode>>;
+    }
 }

+ 14 - 0
dist/preview release/viewer/babylon.module.d.ts

@@ -31543,6 +31543,13 @@ declare module "babylonjs/Animations/animationGroup" {
         dispose(): void;
         private _checkAnimationGroupEnded;
         /**
+         * Clone the current animation group and returns a copy
+         * @param newName defines the name of the new group
+         * @param targetConverter defines an optional function used to convert current animation targets to new ones
+         * @returns the new aniamtion group
+         */
+        clone(newName: string, targetConverter?: (oldTarget: any) => any): AnimationGroup;
+        /**
          * Returns a new AnimationGroup object parsed from the source provided.
          * @param parsedAnimationGroup defines the source
          * @param scene defines the scene that will receive the animationGroup
@@ -87358,6 +87365,13 @@ declare module BABYLON {
         dispose(): void;
         private _checkAnimationGroupEnded;
         /**
+         * Clone the current animation group and returns a copy
+         * @param newName defines the name of the new group
+         * @param targetConverter defines an optional function used to convert current animation targets to new ones
+         * @returns the new aniamtion group
+         */
+        clone(newName: string, targetConverter?: (oldTarget: any) => any): AnimationGroup;
+        /**
          * Returns a new AnimationGroup object parsed from the source provided.
          * @param parsedAnimationGroup defines the source
          * @param scene defines the scene that will receive the animationGroup

+ 19 - 5
dist/preview release/viewer/babylon.viewer.d.ts

@@ -169,11 +169,11 @@ declare module BabylonViewer {
                 * Mainly used for help and errors
                 * @param subScreen the name of the subScreen. Those can be defined in the configuration object
                 */
-            showOverlayScreen(subScreen: string): Promise<string> | Promise<Template>;
+            showOverlayScreen(subScreen: string): Promise<Template> | Promise<string>;
             /**
                 * Hide the overlay screen.
                 */
-            hideOverlayScreen(): Promise<string> | Promise<Template>;
+            hideOverlayScreen(): Promise<Template> | Promise<string>;
             /**
                 * show the viewer (in case it was hidden)
                 *
@@ -190,11 +190,11 @@ declare module BabylonViewer {
                 * Show the loading screen.
                 * The loading screen can be configured using the configuration object
                 */
-            showLoadingScreen(): Promise<string> | Promise<Template>;
+            showLoadingScreen(): Promise<Template> | Promise<string>;
             /**
                 * Hide the loading screen
                 */
-            hideLoadingScreen(): Promise<string> | Promise<Template>;
+            hideLoadingScreen(): Promise<Template> | Promise<string>;
             dispose(): void;
             protected _onConfigurationLoaded(configuration: ViewerConfiguration): void;
     }
@@ -926,7 +926,7 @@ declare module BabylonViewer {
       * @param name the name of the custom optimizer configuration
       * @param upgrade set to true if you want to upgrade optimizer and false if you want to degrade
       */
-    export function getCustomOptimizerByName(name: string, upgrade?: boolean): (sceneManager: SceneManager) => boolean;
+    export function getCustomOptimizerByName(name: string, upgrade?: boolean): typeof extendedUpgrade;
     export function registerCustomOptimizer(name: string, optimizer: (sceneManager: SceneManager) => boolean): void;
 }
 declare module BabylonViewer {
@@ -1558,6 +1558,20 @@ declare module BabylonViewer {
     export function addLoaderPlugin(name: string, plugin: ILoaderPlugin): void;
 }
 declare module BabylonViewer {
+    /**
+        * A custom upgrade-oriented function configuration for the scene optimizer.
+        *
+        * @param viewer the viewer to optimize
+        */
+    export function extendedUpgrade(sceneManager: SceneManager): boolean;
+    /**
+        * A custom degrade-oriented function configuration for the scene optimizer.
+        *
+        * @param viewer the viewer to optimize
+        */
+    export function extendedDegrade(sceneManager: SceneManager): boolean;
+}
+declare module BabylonViewer {
     export interface IEnvironmentMapConfiguration {
             /**
                 * Environment map texture path in relative to the asset folder.

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 5 - 5
dist/preview release/viewer/babylon.viewer.js


Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1 - 1
dist/preview release/viewer/babylon.viewer.max.js


+ 22 - 5
dist/preview release/viewer/babylon.viewer.module.d.ts

@@ -201,11 +201,11 @@ declare module 'babylonjs-viewer/viewer/defaultViewer' {
                 * Mainly used for help and errors
                 * @param subScreen the name of the subScreen. Those can be defined in the configuration object
                 */
-            showOverlayScreen(subScreen: string): Promise<string> | Promise<Template>;
+            showOverlayScreen(subScreen: string): Promise<Template> | Promise<string>;
             /**
                 * Hide the overlay screen.
                 */
-            hideOverlayScreen(): Promise<string> | Promise<Template>;
+            hideOverlayScreen(): Promise<Template> | Promise<string>;
             /**
                 * show the viewer (in case it was hidden)
                 *
@@ -222,11 +222,11 @@ declare module 'babylonjs-viewer/viewer/defaultViewer' {
                 * Show the loading screen.
                 * The loading screen can be configured using the configuration object
                 */
-            showLoadingScreen(): Promise<string> | Promise<Template>;
+            showLoadingScreen(): Promise<Template> | Promise<string>;
             /**
                 * Hide the loading screen
                 */
-            hideLoadingScreen(): Promise<string> | Promise<Template>;
+            hideLoadingScreen(): Promise<Template> | Promise<string>;
             dispose(): void;
             protected _onConfigurationLoaded(configuration: ViewerConfiguration): void;
     }
@@ -987,13 +987,14 @@ declare module 'babylonjs-viewer/templating/viewerTemplatePlugin' {
 }
 
 declare module 'babylonjs-viewer/optimizer/custom' {
+    import { extendedUpgrade } from "babylonjs-viewer/optimizer/custom/extended";
     import { SceneManager } from "babylonjs-viewer/managers/sceneManager";
     /**
       *
       * @param name the name of the custom optimizer configuration
       * @param upgrade set to true if you want to upgrade optimizer and false if you want to degrade
       */
-    export function getCustomOptimizerByName(name: string, upgrade?: boolean): (sceneManager: SceneManager) => boolean;
+    export function getCustomOptimizerByName(name: string, upgrade?: boolean): typeof extendedUpgrade;
     export function registerCustomOptimizer(name: string, optimizer: (sceneManager: SceneManager) => boolean): void;
 }
 
@@ -1664,6 +1665,22 @@ declare module 'babylonjs-viewer/loader/plugins' {
     export function addLoaderPlugin(name: string, plugin: ILoaderPlugin): void;
 }
 
+declare module 'babylonjs-viewer/optimizer/custom/extended' {
+    import { SceneManager } from 'babylonjs-viewer/managers/sceneManager';
+    /**
+        * A custom upgrade-oriented function configuration for the scene optimizer.
+        *
+        * @param viewer the viewer to optimize
+        */
+    export function extendedUpgrade(sceneManager: SceneManager): boolean;
+    /**
+        * A custom degrade-oriented function configuration for the scene optimizer.
+        *
+        * @param viewer the viewer to optimize
+        */
+    export function extendedDegrade(sceneManager: SceneManager): boolean;
+}
+
 declare module 'babylonjs-viewer/configuration/interfaces' {
     export * from 'babylonjs-viewer/configuration/interfaces/cameraConfiguration';
     export * from 'babylonjs-viewer/configuration/interfaces/colorGradingConfiguration';