@babylonjs/core 6.11.2 → 6.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/Cameras/freeCamera.js +14 -10
  2. package/Cameras/freeCamera.js.map +1 -1
  3. package/Cameras/targetCamera.d.ts +5 -0
  4. package/Cameras/targetCamera.js +47 -12
  5. package/Cameras/targetCamera.js.map +1 -1
  6. package/Debug/skeletonViewer.js +2 -2
  7. package/Debug/skeletonViewer.js.map +1 -1
  8. package/DeviceInput/eventFactory.js +7 -0
  9. package/DeviceInput/eventFactory.js.map +1 -1
  10. package/Engines/Processors/shaderCodeCursor.js +32 -8
  11. package/Engines/Processors/shaderCodeCursor.js.map +1 -1
  12. package/Engines/thinEngine.js +2 -2
  13. package/Engines/thinEngine.js.map +1 -1
  14. package/Inputs/scene.inputManager.js +4 -0
  15. package/Inputs/scene.inputManager.js.map +1 -1
  16. package/Layers/effectLayer.d.ts +4 -0
  17. package/Layers/effectLayer.js +2 -2
  18. package/Layers/effectLayer.js.map +1 -1
  19. package/Layers/glowLayer.d.ts +4 -0
  20. package/Layers/glowLayer.js +2 -1
  21. package/Layers/glowLayer.js.map +1 -1
  22. package/Materials/greasedLinePluginMaterial.js +10 -9
  23. package/Materials/greasedLinePluginMaterial.js.map +1 -1
  24. package/Meshes/mesh.d.ts +4 -0
  25. package/Meshes/mesh.js +10 -0
  26. package/Meshes/mesh.js.map +1 -1
  27. package/Meshes/trailMesh.js +10 -2
  28. package/Meshes/trailMesh.js.map +1 -1
  29. package/Misc/sceneSerializer.js +68 -49
  30. package/Misc/sceneSerializer.js.map +1 -1
  31. package/Particles/gpuParticleSystem.d.ts +8 -1
  32. package/Particles/gpuParticleSystem.js +16 -4
  33. package/Particles/gpuParticleSystem.js.map +1 -1
  34. package/Physics/v2/Plugins/havokPlugin.d.ts +5 -3
  35. package/Physics/v2/Plugins/havokPlugin.js +53 -24
  36. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  37. package/XR/features/WebXRControllerMovement.d.ts +2 -1
  38. package/XR/features/WebXRControllerMovement.js +10 -10
  39. package/XR/features/WebXRControllerMovement.js.map +1 -1
  40. package/XR/webXRCamera.js +5 -0
  41. package/XR/webXRCamera.js.map +1 -1
  42. package/package.json +1 -1
  43. package/scene.d.ts +6 -0
  44. package/scene.js +13 -0
  45. package/scene.js.map +1 -1
@@ -3,6 +3,9 @@ import { Mesh } from "../Meshes/mesh.js";
3
3
  import { Vector3 } from "../Maths/math.vector.js";
4
4
  import { VertexBuffer } from "../Buffers/buffer.js";
5
5
  import { VertexData } from "../Meshes/mesh.vertexData.js";
6
+ Mesh._TrailMeshParser = (parsedMesh, scene) => {
7
+ return TrailMesh.Parse(parsedMesh, scene);
8
+ };
6
9
  /**
7
10
  * Class used to create a trail following a mesh
8
11
  */
@@ -145,6 +148,7 @@ export class TrailMesh extends Mesh {
145
148
  */
146
149
  serialize(serializationObject) {
147
150
  super.serialize(serializationObject);
151
+ serializationObject.generatorId = this._generator.id;
148
152
  }
149
153
  /**
150
154
  * Parses a serialized trail mesh
@@ -153,8 +157,12 @@ export class TrailMesh extends Mesh {
153
157
  * @returns the created trail mesh
154
158
  */
155
159
  static Parse(parsedMesh, scene) {
156
- var _a;
157
- return new TrailMesh(parsedMesh.name, parsedMesh._generator, scene, (_a = parsedMesh.diameter) !== null && _a !== void 0 ? _a : parsedMesh._diameter, parsedMesh._length, parsedMesh._autoStart);
160
+ var _a, _b;
161
+ const generator = (_a = scene.getLastMeshById(parsedMesh.generatorId)) !== null && _a !== void 0 ? _a : scene.getLastTransformNodeById(parsedMesh.generatorId);
162
+ if (!generator) {
163
+ throw new Error("TrailMesh: generator not found with ID " + parsedMesh.generatorId);
164
+ }
165
+ return new TrailMesh(parsedMesh.name, generator, scene, (_b = parsedMesh.diameter) !== null && _b !== void 0 ? _b : parsedMesh._diameter, parsedMesh._length, parsedMesh._autoStart);
158
166
  }
159
167
  }
160
168
  //# sourceMapping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AC;IAED;;;;;OAKG;IACI,KAAK,CAAC,OAAe,EAAE,EAAE,YAA2B;QACvD,OAAO,IAAI,SAAS,CAAC,IAAI,EAAE,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC3J,CAAC;IAED;;;OAGG;IACI,SAAS,CAAC,mBAAwB;QACrC,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,UAAe,EAAE,KAAY;;QAC7C,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,UAAU,EAAE,KAAK,EAAE,MAAA,UAAU,CAAC,QAAQ,mCAAI,UAAU,CAAC,SAAS,EAAE,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;IAChK,CAAC;CACJ","sourcesContent":["import { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { VertexData } from \"../Meshes/mesh.vertexData\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\n\r\n/**\r\n * Class used to create a trail following a mesh\r\n */\r\nexport class TrailMesh extends Mesh {\r\n /**\r\n * The diameter of the trail, i.e. the width of the ribbon.\r\n */\r\n public diameter: number;\r\n\r\n private _generator: TransformNode;\r\n private _autoStart: boolean;\r\n private _running: boolean;\r\n private _length: number;\r\n private _sectionPolygonPointsCount: number = 4;\r\n private _sectionVectors: Array<Vector3>;\r\n private _sectionNormalVectors: Array<Vector3>;\r\n private _beforeRenderObserver: Nullable<Observer<Scene>>;\r\n\r\n /**\r\n * Creates a new TrailMesh.\r\n * @param name The value used by scene.getMeshByName() to do a lookup.\r\n * @param generator The mesh or transform node to generate a trail.\r\n * @param scene The scene to add this mesh to.\r\n * @param diameter Diameter of trailing mesh. Default is 1.\r\n * @param length Length of trailing mesh. Default is 60.\r\n * @param autoStart Automatically start trailing mesh. Default true.\r\n */\r\n constructor(name: string, generator: TransformNode, scene?: Scene, diameter: number = 1, length: number = 60, autoStart: boolean = true) {\r\n super(name, scene);\r\n\r\n this._running = false;\r\n this._autoStart = autoStart;\r\n this._generator = generator;\r\n this.diameter = diameter;\r\n this._length = length;\r\n this._sectionVectors = [];\r\n this._sectionNormalVectors = [];\r\n for (let i: number = 0; i < this._sectionPolygonPointsCount; i++) {\r\n this._sectionVectors[i] = Vector3.Zero();\r\n this._sectionNormalVectors[i] = Vector3.Zero();\r\n }\r\n this._createMesh();\r\n }\r\n\r\n /**\r\n * \"TrailMesh\"\r\n * @returns \"TrailMesh\"\r\n */\r\n public getClassName(): string {\r\n return \"TrailMesh\";\r\n }\r\n\r\n private _createMesh(): void {\r\n const data: VertexData = new VertexData();\r\n const positions: Array<number> = [];\r\n const normals: Array<number> = [];\r\n const indices: Array<number> = [];\r\n let meshCenter = Vector3.Zero();\r\n if (this._generator instanceof AbstractMesh && this._generator.hasBoundingInfo) {\r\n meshCenter = this._generator.getBoundingInfo().boundingBox.centerWorld;\r\n } else {\r\n meshCenter = this._generator.position;\r\n }\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i < this._sectionPolygonPointsCount; i++) {\r\n positions.push(meshCenter.x + Math.cos(i * alpha) * this.diameter, meshCenter.y + Math.sin(i * alpha) * this.diameter, meshCenter.z);\r\n }\r\n for (let i: number = 1; i <= this._length; i++) {\r\n for (let j: number = 0; j < this._sectionPolygonPointsCount; j++) {\r\n positions.push(meshCenter.x + Math.cos(j * alpha) * this.diameter, meshCenter.y + Math.sin(j * alpha) * this.diameter, meshCenter.z);\r\n }\r\n const l: number = positions.length / 3 - 2 * this._sectionPolygonPointsCount;\r\n for (let j: number = 0; j < this._sectionPolygonPointsCount - 1; j++) {\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount, l + j + this._sectionPolygonPointsCount + 1);\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount + 1, l + j + 1);\r\n }\r\n indices.push(l + this._sectionPolygonPointsCount - 1, l + this._sectionPolygonPointsCount - 1 + this._sectionPolygonPointsCount, l + this._sectionPolygonPointsCount);\r\n indices.push(l + this._sectionPolygonPointsCount - 1, l + this._sectionPolygonPointsCount, l);\r\n }\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n data.positions = positions;\r\n data.normals = normals;\r\n data.indices = indices;\r\n data.applyToMesh(this, true);\r\n if (this._autoStart) {\r\n this.start();\r\n }\r\n }\r\n\r\n /**\r\n * Start trailing mesh.\r\n */\r\n public start(): void {\r\n if (!this._running) {\r\n this._running = true;\r\n this._beforeRenderObserver = this.getScene().onBeforeRenderObservable.add(() => {\r\n this.update();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Stop trailing mesh.\r\n */\r\n public stop(): void {\r\n if (this._beforeRenderObserver && this._running) {\r\n this._running = false;\r\n this.getScene().onBeforeRenderObservable.remove(this._beforeRenderObserver);\r\n }\r\n }\r\n\r\n /**\r\n * Update trailing mesh geometry.\r\n */\r\n public update(): void {\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n const wm = this._generator.getWorldMatrix();\r\n if (positions && normals) {\r\n for (let i: number = 3 * this._sectionPolygonPointsCount; i < positions.length; i++) {\r\n positions[i - 3 * this._sectionPolygonPointsCount] = positions[i] - (normals[i] / this._length) * this.diameter;\r\n }\r\n for (let i: number = 3 * this._sectionPolygonPointsCount; i < normals.length; i++) {\r\n normals[i - 3 * this._sectionPolygonPointsCount] = normals[i];\r\n }\r\n const l: number = positions.length - 3 * this._sectionPolygonPointsCount;\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i < this._sectionPolygonPointsCount; i++) {\r\n this._sectionVectors[i].copyFromFloats(Math.cos(i * alpha) * this.diameter, Math.sin(i * alpha) * this.diameter, 0);\r\n this._sectionNormalVectors[i].copyFromFloats(Math.cos(i * alpha), Math.sin(i * alpha), 0);\r\n Vector3.TransformCoordinatesToRef(this._sectionVectors[i], wm, this._sectionVectors[i]);\r\n Vector3.TransformNormalToRef(this._sectionNormalVectors[i], wm, this._sectionNormalVectors[i]);\r\n }\r\n for (let i: number = 0; i < this._sectionPolygonPointsCount; i++) {\r\n positions[l + 3 * i] = this._sectionVectors[i].x;\r\n positions[l + 3 * i + 1] = this._sectionVectors[i].y;\r\n positions[l + 3 * i + 2] = this._sectionVectors[i].z;\r\n normals[l + 3 * i] = this._sectionNormalVectors[i].x;\r\n normals[l + 3 * i + 1] = this._sectionNormalVectors[i].y;\r\n normals[l + 3 * i + 2] = this._sectionNormalVectors[i].z;\r\n }\r\n this.updateVerticesData(VertexBuffer.PositionKind, positions, true, false);\r\n this.updateVerticesData(VertexBuffer.NormalKind, normals, true, false);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a new TrailMesh object.\r\n * @param name is a string, the name given to the new mesh\r\n * @param newGenerator use new generator object for cloned trail mesh\r\n * @returns a new mesh\r\n */\r\n public clone(name: string = \"\", newGenerator: TransformNode): TrailMesh {\r\n return new TrailMesh(name, newGenerator === undefined ? this._generator : newGenerator, this.getScene(), this.diameter, this._length, this._autoStart);\r\n }\r\n\r\n /**\r\n * Serializes this trail mesh\r\n * @param serializationObject object to write serialization to\r\n */\r\n public serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n }\r\n\r\n /**\r\n * Parses a serialized trail mesh\r\n * @param parsedMesh the serialized mesh\r\n * @param scene the scene to create the trail mesh in\r\n * @returns the created trail mesh\r\n */\r\n public static Parse(parsedMesh: any, scene: Scene): TrailMesh {\r\n return new TrailMesh(parsedMesh.name, parsedMesh._generator, scene, parsedMesh.diameter ?? parsedMesh._diameter, parsedMesh._length, parsedMesh._autoStart);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"trailMesh.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/trailMesh.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAItC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAGvD,IAAI,CAAC,gBAAgB,GAAG,CAAC,UAAe,EAAE,KAAY,EAAE,EAAE;IACtD,OAAO,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,IAAI;IAe/B;;;;;;;;OAQG;IACH,YAAY,IAAY,EAAE,SAAwB,EAAE,KAAa,EAAE,WAAmB,CAAC,EAAE,SAAiB,EAAE,EAAE,YAAqB,IAAI;QACnI,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAff,+BAA0B,GAAW,CAAC,CAAC;QAiB3C,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,qBAAqB,GAAG,EAAE,CAAC;QAChC,K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AAU,CAAC,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;IACpJ,CAAC;CACJ","sourcesContent":["import { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport type { Scene } from \"../scene\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { VertexData } from \"../Meshes/mesh.vertexData\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\n\r\nMesh._TrailMeshParser = (parsedMesh: any, scene: Scene) => {\r\n return TrailMesh.Parse(parsedMesh, scene);\r\n};\r\n\r\n/**\r\n * Class used to create a trail following a mesh\r\n */\r\nexport class TrailMesh extends Mesh {\r\n /**\r\n * The diameter of the trail, i.e. the width of the ribbon.\r\n */\r\n public diameter: number;\r\n\r\n private _generator: TransformNode;\r\n private _autoStart: boolean;\r\n private _running: boolean;\r\n private _length: number;\r\n private _sectionPolygonPointsCount: number = 4;\r\n private _sectionVectors: Array<Vector3>;\r\n private _sectionNormalVectors: Array<Vector3>;\r\n private _beforeRenderObserver: Nullable<Observer<Scene>>;\r\n\r\n /**\r\n * Creates a new TrailMesh.\r\n * @param name The value used by scene.getMeshByName() to do a lookup.\r\n * @param generator The mesh or transform node to generate a trail.\r\n * @param scene The scene to add this mesh to.\r\n * @param diameter Diameter of trailing mesh. Default is 1.\r\n * @param length Length of trailing mesh. Default is 60.\r\n * @param autoStart Automatically start trailing mesh. Default true.\r\n */\r\n constructor(name: string, generator: TransformNode, scene?: Scene, diameter: number = 1, length: number = 60, autoStart: boolean = true) {\r\n super(name, scene);\r\n\r\n this._running = false;\r\n this._autoStart = autoStart;\r\n this._generator = generator;\r\n this.diameter = diameter;\r\n this._length = length;\r\n this._sectionVectors = [];\r\n this._sectionNormalVectors = [];\r\n for (let i: number = 0; i < this._sectionPolygonPointsCount; i++) {\r\n this._sectionVectors[i] = Vector3.Zero();\r\n this._sectionNormalVectors[i] = Vector3.Zero();\r\n }\r\n this._createMesh();\r\n }\r\n\r\n /**\r\n * \"TrailMesh\"\r\n * @returns \"TrailMesh\"\r\n */\r\n public getClassName(): string {\r\n return \"TrailMesh\";\r\n }\r\n\r\n private _createMesh(): void {\r\n const data: VertexData = new VertexData();\r\n const positions: Array<number> = [];\r\n const normals: Array<number> = [];\r\n const indices: Array<number> = [];\r\n let meshCenter = Vector3.Zero();\r\n if (this._generator instanceof AbstractMesh && this._generator.hasBoundingInfo) {\r\n meshCenter = this._generator.getBoundingInfo().boundingBox.centerWorld;\r\n } else {\r\n meshCenter = this._generator.position;\r\n }\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i < this._sectionPolygonPointsCount; i++) {\r\n positions.push(meshCenter.x + Math.cos(i * alpha) * this.diameter, meshCenter.y + Math.sin(i * alpha) * this.diameter, meshCenter.z);\r\n }\r\n for (let i: number = 1; i <= this._length; i++) {\r\n for (let j: number = 0; j < this._sectionPolygonPointsCount; j++) {\r\n positions.push(meshCenter.x + Math.cos(j * alpha) * this.diameter, meshCenter.y + Math.sin(j * alpha) * this.diameter, meshCenter.z);\r\n }\r\n const l: number = positions.length / 3 - 2 * this._sectionPolygonPointsCount;\r\n for (let j: number = 0; j < this._sectionPolygonPointsCount - 1; j++) {\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount, l + j + this._sectionPolygonPointsCount + 1);\r\n indices.push(l + j, l + j + this._sectionPolygonPointsCount + 1, l + j + 1);\r\n }\r\n indices.push(l + this._sectionPolygonPointsCount - 1, l + this._sectionPolygonPointsCount - 1 + this._sectionPolygonPointsCount, l + this._sectionPolygonPointsCount);\r\n indices.push(l + this._sectionPolygonPointsCount - 1, l + this._sectionPolygonPointsCount, l);\r\n }\r\n VertexData.ComputeNormals(positions, indices, normals);\r\n data.positions = positions;\r\n data.normals = normals;\r\n data.indices = indices;\r\n data.applyToMesh(this, true);\r\n if (this._autoStart) {\r\n this.start();\r\n }\r\n }\r\n\r\n /**\r\n * Start trailing mesh.\r\n */\r\n public start(): void {\r\n if (!this._running) {\r\n this._running = true;\r\n this._beforeRenderObserver = this.getScene().onBeforeRenderObservable.add(() => {\r\n this.update();\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Stop trailing mesh.\r\n */\r\n public stop(): void {\r\n if (this._beforeRenderObserver && this._running) {\r\n this._running = false;\r\n this.getScene().onBeforeRenderObservable.remove(this._beforeRenderObserver);\r\n }\r\n }\r\n\r\n /**\r\n * Update trailing mesh geometry.\r\n */\r\n public update(): void {\r\n const positions = this.getVerticesData(VertexBuffer.PositionKind);\r\n const normals = this.getVerticesData(VertexBuffer.NormalKind);\r\n const wm = this._generator.getWorldMatrix();\r\n if (positions && normals) {\r\n for (let i: number = 3 * this._sectionPolygonPointsCount; i < positions.length; i++) {\r\n positions[i - 3 * this._sectionPolygonPointsCount] = positions[i] - (normals[i] / this._length) * this.diameter;\r\n }\r\n for (let i: number = 3 * this._sectionPolygonPointsCount; i < normals.length; i++) {\r\n normals[i - 3 * this._sectionPolygonPointsCount] = normals[i];\r\n }\r\n const l: number = positions.length - 3 * this._sectionPolygonPointsCount;\r\n const alpha: number = (2 * Math.PI) / this._sectionPolygonPointsCount;\r\n for (let i: number = 0; i < this._sectionPolygonPointsCount; i++) {\r\n this._sectionVectors[i].copyFromFloats(Math.cos(i * alpha) * this.diameter, Math.sin(i * alpha) * this.diameter, 0);\r\n this._sectionNormalVectors[i].copyFromFloats(Math.cos(i * alpha), Math.sin(i * alpha), 0);\r\n Vector3.TransformCoordinatesToRef(this._sectionVectors[i], wm, this._sectionVectors[i]);\r\n Vector3.TransformNormalToRef(this._sectionNormalVectors[i], wm, this._sectionNormalVectors[i]);\r\n }\r\n for (let i: number = 0; i < this._sectionPolygonPointsCount; i++) {\r\n positions[l + 3 * i] = this._sectionVectors[i].x;\r\n positions[l + 3 * i + 1] = this._sectionVectors[i].y;\r\n positions[l + 3 * i + 2] = this._sectionVectors[i].z;\r\n normals[l + 3 * i] = this._sectionNormalVectors[i].x;\r\n normals[l + 3 * i + 1] = this._sectionNormalVectors[i].y;\r\n normals[l + 3 * i + 2] = this._sectionNormalVectors[i].z;\r\n }\r\n this.updateVerticesData(VertexBuffer.PositionKind, positions, true, false);\r\n this.updateVerticesData(VertexBuffer.NormalKind, normals, true, false);\r\n }\r\n }\r\n\r\n /**\r\n * Returns a new TrailMesh object.\r\n * @param name is a string, the name given to the new mesh\r\n * @param newGenerator use new generator object for cloned trail mesh\r\n * @returns a new mesh\r\n */\r\n public clone(name: string = \"\", newGenerator: TransformNode): TrailMesh {\r\n return new TrailMesh(name, newGenerator === undefined ? this._generator : newGenerator, this.getScene(), this.diameter, this._length, this._autoStart);\r\n }\r\n\r\n /**\r\n * Serializes this trail mesh\r\n * @param serializationObject object to write serialization to\r\n */\r\n public serialize(serializationObject: any): void {\r\n super.serialize(serializationObject);\r\n\r\n serializationObject.generatorId = this._generator.id;\r\n }\r\n\r\n /**\r\n * Parses a serialized trail mesh\r\n * @param parsedMesh the serialized mesh\r\n * @param scene the scene to create the trail mesh in\r\n * @returns the created trail mesh\r\n */\r\n public static Parse(parsedMesh: any, scene: Scene): TrailMesh {\r\n const generator = scene.getLastMeshById(parsedMesh.generatorId) ?? scene.getLastTransformNodeById(parsedMesh.generatorId);\r\n\r\n if (!generator) {\r\n throw new Error(\"TrailMesh: generator not found with ID \" + parsedMesh.generatorId);\r\n }\r\n\r\n return new TrailMesh(parsedMesh.name, generator, scene, parsedMesh.diameter ?? parsedMesh._diameter, parsedMesh._length, parsedMesh._autoStart);\r\n }\r\n}\r\n"]}
@@ -27,59 +27,74 @@ const SerializeMesh = (mesh, serializationScene) => {
27
27
  }
28
28
  return serializationObject;
29
29
  };
30
- const FinalizeSingleMesh = (mesh, serializationObject) => {
31
- //only works if the mesh is already loaded
32
- if (mesh.delayLoadState === 1 || mesh.delayLoadState === 0) {
33
- const serializeMaterial = (material) => {
34
- serializationObject.materials = serializationObject.materials || [];
35
- if (mesh.material && !serializationObject.materials.some((mat) => mat.id === mesh.material.id)) {
36
- serializationObject.materials.push(material.serialize());
37
- }
38
- };
39
- //serialize material
40
- if (mesh.material && !mesh.material.doNotSerialize) {
41
- if (mesh.material instanceof MultiMaterial) {
42
- serializationObject.multiMaterials = serializationObject.multiMaterials || [];
43
- if (!serializationObject.multiMaterials.some((mat) => mat.id === mesh.material.id)) {
44
- serializationObject.multiMaterials.push(mesh.material.serialize());
45
- for (const submaterial of mesh.material.subMaterials) {
46
- if (submaterial) {
47
- serializeMaterial(submaterial);
30
+ const FinalizeSingleNode = (node, serializationObject) => {
31
+ if (node._isMesh) {
32
+ const mesh = node;
33
+ //only works if the mesh is already loaded
34
+ if (mesh.delayLoadState === 1 || mesh.delayLoadState === 0) {
35
+ const serializeMaterial = (material) => {
36
+ serializationObject.materials = serializationObject.materials || [];
37
+ if (mesh.material && !serializationObject.materials.some((mat) => mat.id === mesh.material.id)) {
38
+ serializationObject.materials.push(material.serialize());
39
+ }
40
+ };
41
+ //serialize material
42
+ if (mesh.material && !mesh.material.doNotSerialize) {
43
+ if (mesh.material instanceof MultiMaterial) {
44
+ serializationObject.multiMaterials = serializationObject.multiMaterials || [];
45
+ if (!serializationObject.multiMaterials.some((mat) => mat.id === mesh.material.id)) {
46
+ serializationObject.multiMaterials.push(mesh.material.serialize());
47
+ for (const submaterial of mesh.material.subMaterials) {
48
+ if (submaterial) {
49
+ serializeMaterial(submaterial);
50
+ }
48
51
  }
49
52
  }
50
53
  }
54
+ else {
55
+ serializeMaterial(mesh.material);
56
+ }
51
57
  }
52
- else {
53
- serializeMaterial(mesh.material);
58
+ else if (!mesh.material) {
59
+ serializeMaterial(mesh.getScene().defaultMaterial);
54
60
  }
55
- }
56
- else if (!mesh.material) {
57
- serializeMaterial(mesh.getScene().defaultMaterial);
58
- }
59
- //serialize geometry
60
- const geometry = mesh._geometry;
61
- if (geometry) {
62
- if (!serializationObject.geometries) {
63
- serializationObject.geometries = {};
64
- serializationObject.geometries.boxes = [];
65
- serializationObject.geometries.spheres = [];
66
- serializationObject.geometries.cylinders = [];
67
- serializationObject.geometries.toruses = [];
68
- serializationObject.geometries.grounds = [];
69
- serializationObject.geometries.planes = [];
70
- serializationObject.geometries.torusKnots = [];
71
- serializationObject.geometries.vertexData = [];
61
+ //serialize geometry
62
+ const geometry = mesh._geometry;
63
+ if (geometry) {
64
+ if (!serializationObject.geometries) {
65
+ serializationObject.geometries = {};
66
+ serializationObject.geometries.boxes = [];
67
+ serializationObject.geometries.spheres = [];
68
+ serializationObject.geometries.cylinders = [];
69
+ serializationObject.geometries.toruses = [];
70
+ serializationObject.geometries.grounds = [];
71
+ serializationObject.geometries.planes = [];
72
+ serializationObject.geometries.torusKnots = [];
73
+ serializationObject.geometries.vertexData = [];
74
+ }
75
+ SerializeGeometry(geometry, serializationObject.geometries);
72
76
  }
73
- SerializeGeometry(geometry, serializationObject.geometries);
74
- }
75
- // Skeletons
76
- if (mesh.skeleton && !mesh.skeleton.doNotSerialize) {
77
- serializationObject.skeletons = serializationObject.skeletons || [];
78
- serializationObject.skeletons.push(mesh.skeleton.serialize());
77
+ // Skeletons
78
+ if (mesh.skeleton && !mesh.skeleton.doNotSerialize) {
79
+ serializationObject.skeletons = serializationObject.skeletons || [];
80
+ serializationObject.skeletons.push(mesh.skeleton.serialize());
81
+ }
82
+ //serialize the actual mesh
83
+ serializationObject.meshes = serializationObject.meshes || [];
84
+ serializationObject.meshes.push(SerializeMesh(mesh, serializationObject));
79
85
  }
80
- //serialize the actual mesh
81
- serializationObject.meshes = serializationObject.meshes || [];
82
- serializationObject.meshes.push(SerializeMesh(mesh, serializationObject));
86
+ }
87
+ else if (node.getClassName() === "TransformNode") {
88
+ const transformNode = node;
89
+ serializationObject.transformNodes.push(transformNode.serialize());
90
+ }
91
+ else if (node.getClassName().indexOf("Camera") !== -1) {
92
+ const camera = node;
93
+ serializationObject.cameras.push(camera.serialize());
94
+ }
95
+ else if (node.getClassName().indexOf("Light") !== -1) {
96
+ const light = node;
97
+ serializationObject.lights.push(light.serialize());
83
98
  }
84
99
  };
85
100
  /**
@@ -125,7 +140,7 @@ export class SceneSerializer {
125
140
  serializationObject.fogDensity = scene.fogDensity;
126
141
  }
127
142
  //Physics
128
- if (scene.isPhysicsEnabled()) {
143
+ if (scene.isPhysicsEnabled && scene.isPhysicsEnabled()) {
129
144
  const physicEngine = scene.getPhysicsEngine();
130
145
  if (physicEngine) {
131
146
  serializationObject.physicsEnabled = true;
@@ -324,6 +339,10 @@ export class SceneSerializer {
324
339
  */
325
340
  static SerializeMesh(toSerialize /* Mesh || Mesh[] */, withParents = false, withChildren = false) {
326
341
  const serializationObject = {};
342
+ serializationObject.meshes = [];
343
+ serializationObject.transformNodes = [];
344
+ serializationObject.cameras = [];
345
+ serializationObject.lights = [];
327
346
  SceneSerializer.ClearCache();
328
347
  toSerialize = toSerialize instanceof Array ? toSerialize : [toSerialize];
329
348
  if (withParents || withChildren) {
@@ -331,7 +350,7 @@ export class SceneSerializer {
331
350
  for (let i = 0; i < toSerialize.length; ++i) {
332
351
  if (withChildren) {
333
352
  toSerialize[i].getDescendants().forEach((node) => {
334
- if (node instanceof Mesh && toSerialize.indexOf(node) < 0 && !node.doNotSerialize) {
353
+ if (toSerialize.indexOf(node) < 0 && !node.doNotSerialize) {
335
354
  toSerialize.push(node);
336
355
  }
337
356
  });
@@ -343,7 +362,7 @@ export class SceneSerializer {
343
362
  }
344
363
  }
345
364
  toSerialize.forEach((mesh) => {
346
- FinalizeSingleMesh(mesh, serializationObject);
365
+ FinalizeSingleNode(mesh, serializationObject);
347
366
  });
348
367
  return serializationObject;
349
368
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sceneSerializer.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/sceneSerializer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,SAAS,E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\r\nimport { MultiMaterial } from \"../Materials/multiMaterial\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Light } from \"../Lights/light\";\r\nimport { SerializationHelper } from \"./decorators\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport type { CubeTexture } from \"../Materials/Textures/cubeTexture\";\r\n\r\nlet serializedGeometries: Geometry[] = [];\r\nconst SerializeGeometry = (geometry: Geometry, serializationGeometries: any): any => {\r\n if (geometry.doNotSerialize) {\r\n return;\r\n }\r\n\r\n serializationGeometries.vertexData.push(geometry.serializeVerticeData());\r\n\r\n (<any>serializedGeometries)[geometry.id] = true;\r\n};\r\n\r\nconst SerializeMesh = (mesh: Mesh, serializationScene: any): any => {\r\n const serializationObject: any = {};\r\n\r\n // Geometry\r\n const geometry = mesh._geometry;\r\n if (geometry) {\r\n if (!mesh.getScene().getGeometryById(geometry.id)) {\r\n // Geometry was in the memory but not added to the scene, nevertheless it's better to serialize to be able to reload the mesh with its geometry\r\n SerializeGeometry(geometry, serializationScene.geometries);\r\n }\r\n }\r\n\r\n // Custom\r\n if (mesh.serialize) {\r\n mesh.serialize(serializationObject);\r\n }\r\n\r\n return serializationObject;\r\n};\r\n\r\nconst FinalizeSingleMesh = (mesh: Mesh, serializationObject: any) => {\r\n //only works if the mesh is already loaded\r\n if (mesh.delayLoadState === Constants.DELAYLOADSTATE_LOADED || mesh.delayLoadState === Constants.DELAYLOADSTATE_NONE) {\r\n const serializeMaterial = (material: Material) => {\r\n serializationObject.materials = serializationObject.materials || [];\r\n if (mesh.material && !serializationObject.materials.some((mat: Material) => mat.id === (<Material>mesh.material).id)) {\r\n serializationObject.materials.push(material.serialize());\r\n }\r\n };\r\n\r\n //serialize material\r\n if (mesh.material && !mesh.material.doNotSerialize) {\r\n if (mesh.material instanceof MultiMaterial) {\r\n serializationObject.multiMaterials = serializationObject.multiMaterials || [];\r\n if (!serializationObject.multiMaterials.some((mat: Material) => mat.id === (<Material>mesh.material).id)) {\r\n serializationObject.multiMaterials.push(mesh.material.serialize());\r\n for (const submaterial of mesh.material.subMaterials) {\r\n if (submaterial) {\r\n serializeMaterial(submaterial);\r\n }\r\n }\r\n }\r\n } else {\r\n serializeMaterial(mesh.material);\r\n }\r\n } else if (!mesh.material) {\r\n serializeMaterial(mesh.getScene().defaultMaterial);\r\n }\r\n\r\n //serialize geometry\r\n const geometry = mesh._geometry;\r\n if (geometry) {\r\n if (!serializationObject.geometries) {\r\n serializationObject.geometries = {};\r\n\r\n serializationObject.geometries.boxes = [];\r\n serializationObject.geometries.spheres = [];\r\n serializationObject.geometries.cylinders = [];\r\n serializationObject.geometries.toruses = [];\r\n serializationObject.geometries.grounds = [];\r\n serializationObject.geometries.planes = [];\r\n serializationObject.geometries.torusKnots = [];\r\n serializationObject.geometries.vertexData = [];\r\n }\r\n\r\n SerializeGeometry(geometry, serializationObject.geometries);\r\n }\r\n // Skeletons\r\n if (mesh.skeleton && !mesh.skeleton.doNotSerialize) {\r\n serializationObject.skeletons = serializationObject.skeletons || [];\r\n serializationObject.skeletons.push(mesh.skeleton.serialize());\r\n }\r\n\r\n //serialize the actual mesh\r\n serializationObject.meshes = serializationObject.meshes || [];\r\n serializationObject.meshes.push(SerializeMesh(mesh, serializationObject));\r\n }\r\n};\r\n\r\n/**\r\n * Class used to serialize a scene into a string\r\n */\r\nexport class SceneSerializer {\r\n /**\r\n * Clear cache used by a previous serialization\r\n */\r\n public static ClearCache(): void {\r\n serializedGeometries = [];\r\n }\r\n\r\n /**\r\n * Serialize a scene into a JSON compatible object\r\n * Note that if the current engine does not support synchronous texture reading (like WebGPU), you should use SerializeAsync instead\r\n * as else you may not retrieve the proper base64 encoded texture data (when using the Texture.ForceSerializeBuffers flag)\r\n * @param scene defines the scene to serialize\r\n * @returns a JSON compatible object\r\n */\r\n public static Serialize(scene: Scene): any {\r\n return SceneSerializer._Serialize(scene);\r\n }\r\n\r\n private static _Serialize(scene: Scene, checkSyncReadSupported = true): any {\r\n const serializationObject: any = {};\r\n\r\n if (checkSyncReadSupported && !scene.getEngine()._features.supportSyncTextureRead && Texture.ForceSerializeBuffers) {\r\n console.warn(\"The serialization object may not contain the proper base64 encoded texture data! You should use the SerializeAsync method instead.\");\r\n }\r\n\r\n SceneSerializer.ClearCache();\r\n\r\n // Scene\r\n serializationObject.useDelayedTextureLoading = scene.useDelayedTextureLoading;\r\n serializationObject.autoClear = scene.autoClear;\r\n serializationObject.clearColor = scene.clearColor.asArray();\r\n serializationObject.ambientColor = scene.ambientColor.asArray();\r\n serializationObject.gravity = scene.gravity.asArray();\r\n serializationObject.collisionsEnabled = scene.collisionsEnabled;\r\n serializationObject.useRightHandedSystem = scene.useRightHandedSystem;\r\n\r\n // Fog\r\n if (scene.fogMode && scene.fogMode !== 0) {\r\n serializationObject.fogMode = scene.fogMode;\r\n serializationObject.fogColor = scene.fogColor.asArray();\r\n serializationObject.fogStart = scene.fogStart;\r\n serializationObject.fogEnd = scene.fogEnd;\r\n serializationObject.fogDensity = scene.fogDensity;\r\n }\r\n\r\n //Physics\r\n if (scene.isPhysicsEnabled()) {\r\n const physicEngine = scene.getPhysicsEngine();\r\n\r\n if (physicEngine) {\r\n serializationObject.physicsEnabled = true;\r\n serializationObject.physicsGravity = physicEngine.gravity.asArray();\r\n serializationObject.physicsEngine = physicEngine.getPhysicsPluginName();\r\n }\r\n }\r\n\r\n // Metadata\r\n if (scene.metadata) {\r\n serializationObject.metadata = scene.metadata;\r\n }\r\n\r\n // Morph targets\r\n serializationObject.morphTargetManagers = [];\r\n for (const abstractMesh of scene.meshes) {\r\n const manager = (<Mesh>abstractMesh).morphTargetManager;\r\n\r\n if (manager) {\r\n serializationObject.morphTargetManagers.push(manager.serialize());\r\n }\r\n }\r\n\r\n // Lights\r\n serializationObject.lights = [];\r\n let index: number;\r\n let light: Light;\r\n for (index = 0; index < scene.lights.length; index++) {\r\n light = scene.lights[index];\r\n\r\n if (!light.doNotSerialize) {\r\n serializationObject.lights.push(light.serialize());\r\n }\r\n }\r\n\r\n // Cameras\r\n serializationObject.cameras = [];\r\n for (index = 0; index < scene.cameras.length; index++) {\r\n const camera = scene.cameras[index];\r\n\r\n if (!camera.doNotSerialize) {\r\n serializationObject.cameras.push(camera.serialize());\r\n }\r\n }\r\n\r\n if (scene.activeCamera) {\r\n serializationObject.activeCameraID = scene.activeCamera.id;\r\n }\r\n\r\n // Animations\r\n SerializationHelper.AppendSerializedAnimations(scene, serializationObject);\r\n\r\n // Animation Groups\r\n if (scene.animationGroups && scene.animationGroups.length > 0) {\r\n serializationObject.animationGroups = [];\r\n for (let animationGroupIndex = 0; animationGroupIndex < scene.animationGroups.length; animationGroupIndex++) {\r\n const animationGroup = scene.animationGroups[animationGroupIndex];\r\n\r\n serializationObject.animationGroups.push(animationGroup.serialize());\r\n }\r\n }\r\n\r\n // Reflection probes\r\n if (scene.reflectionProbes && scene.reflectionProbes.length > 0) {\r\n serializationObject.reflectionProbes = [];\r\n\r\n for (index = 0; index < scene.reflectionProbes.length; index++) {\r\n const reflectionProbe = scene.reflectionProbes[index];\r\n serializationObject.reflectionProbes.push(reflectionProbe.serialize());\r\n }\r\n }\r\n\r\n // Materials\r\n serializationObject.materials = [];\r\n serializationObject.multiMaterials = [];\r\n let material: Material;\r\n for (index = 0; index < scene.materials.length; index++) {\r\n material = scene.materials[index];\r\n if (!material.doNotSerialize) {\r\n serializationObject.materials.push(material.serialize());\r\n }\r\n }\r\n\r\n // MultiMaterials\r\n serializationObject.multiMaterials = [];\r\n for (index = 0; index < scene.multiMaterials.length; index++) {\r\n const multiMaterial = scene.multiMaterials[index];\r\n serializationObject.multiMaterials.push(multiMaterial.serialize());\r\n }\r\n\r\n // Environment texture\r\n if (scene.environmentTexture) {\r\n if ((scene.environmentTexture as CubeTexture)._files) {\r\n serializationObject.environmentTexture = scene.environmentTexture.serialize();\r\n } else {\r\n serializationObject.environmentTexture = scene.environmentTexture.name;\r\n serializationObject.environmentTextureRotationY = (scene.environmentTexture as CubeTexture).rotationY;\r\n }\r\n }\r\n\r\n // Environment Intensity\r\n serializationObject.environmentIntensity = scene.environmentIntensity;\r\n\r\n // Skeletons\r\n serializationObject.skeletons = [];\r\n for (index = 0; index < scene.skeletons.length; index++) {\r\n const skeleton = scene.skeletons[index];\r\n if (!skeleton.doNotSerialize) {\r\n serializationObject.skeletons.push(skeleton.serialize());\r\n }\r\n }\r\n\r\n // Transform nodes\r\n serializationObject.transformNodes = [];\r\n for (index = 0; index < scene.transformNodes.length; index++) {\r\n if (!scene.transformNodes[index].doNotSerialize) {\r\n serializationObject.transformNodes.push(scene.transformNodes[index].serialize());\r\n }\r\n }\r\n\r\n // Geometries\r\n serializationObject.geometries = {};\r\n\r\n serializationObject.geometries.boxes = [];\r\n serializationObject.geometries.spheres = [];\r\n serializationObject.geometries.cylinders = [];\r\n serializationObject.geometries.toruses = [];\r\n serializationObject.geometries.grounds = [];\r\n serializationObject.geometries.planes = [];\r\n serializationObject.geometries.torusKnots = [];\r\n serializationObject.geometries.vertexData = [];\r\n\r\n serializedGeometries = [];\r\n const geometries = scene.getGeometries();\r\n for (index = 0; index < geometries.length; index++) {\r\n const geometry = geometries[index];\r\n\r\n if (geometry.isReady()) {\r\n SerializeGeometry(geometry, serializationObject.geometries);\r\n }\r\n }\r\n\r\n // Meshes\r\n serializationObject.meshes = [];\r\n for (index = 0; index < scene.meshes.length; index++) {\r\n const abstractMesh = scene.meshes[index];\r\n\r\n if (abstractMesh instanceof Mesh) {\r\n const mesh = abstractMesh;\r\n if (!mesh.doNotSerialize) {\r\n if (mesh.delayLoadState === Constants.DELAYLOADSTATE_LOADED || mesh.delayLoadState === Constants.DELAYLOADSTATE_NONE) {\r\n serializationObject.meshes.push(SerializeMesh(mesh, serializationObject));\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Particles Systems\r\n serializationObject.particleSystems = [];\r\n for (index = 0; index < scene.particleSystems.length; index++) {\r\n serializationObject.particleSystems.push(scene.particleSystems[index].serialize(false));\r\n }\r\n\r\n // Post processes\r\n serializationObject.postProcesses = [];\r\n for (index = 0; index < scene.postProcesses.length; index++) {\r\n serializationObject.postProcesses.push(scene.postProcesses[index].serialize());\r\n }\r\n\r\n // Action Manager\r\n if (scene.actionManager) {\r\n serializationObject.actions = scene.actionManager.serialize(\"scene\");\r\n }\r\n\r\n // Components\r\n for (const component of scene._serializableComponents) {\r\n component.serialize(serializationObject);\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Serialize a scene into a JSON compatible object\r\n * @param scene defines the scene to serialize\r\n * @returns a JSON promise compatible object\r\n */\r\n public static SerializeAsync(scene: Scene): Promise<any> {\r\n const serializationObject = SceneSerializer._Serialize(scene, false);\r\n\r\n const promises: Array<Promise<any>> = [];\r\n\r\n this._CollectPromises(serializationObject, promises);\r\n\r\n return Promise.all(promises).then(() => serializationObject);\r\n }\r\n\r\n private static _CollectPromises(obj: any, promises: Array<Promise<any>>): void {\r\n if (Array.isArray(obj)) {\r\n for (let i = 0; i < obj.length; ++i) {\r\n const o = obj[i];\r\n if (o instanceof Promise) {\r\n promises.push(o.then((res: any) => (obj[i] = res)));\r\n } else if (o instanceof Object || Array.isArray(o)) {\r\n this._CollectPromises(o, promises);\r\n }\r\n }\r\n } else if (obj instanceof Object) {\r\n for (const name in obj) {\r\n if (Object.prototype.hasOwnProperty.call(obj, name)) {\r\n const o = obj[name];\r\n if (o instanceof Promise) {\r\n promises.push(o.then((res: any) => (obj[name] = res)));\r\n } else if (o instanceof Object || Array.isArray(o)) {\r\n this._CollectPromises(o, promises);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Serialize a mesh into a JSON compatible object\r\n * @param toSerialize defines the mesh to serialize\r\n * @param withParents defines if parents must be serialized as well\r\n * @param withChildren defines if children must be serialized as well\r\n * @returns a JSON compatible object\r\n */\r\n public static SerializeMesh(toSerialize: any /* Mesh || Mesh[] */, withParents: boolean = false, withChildren: boolean = false): any {\r\n const serializationObject: any = {};\r\n\r\n SceneSerializer.ClearCache();\r\n\r\n toSerialize = toSerialize instanceof Array ? toSerialize : [toSerialize];\r\n\r\n if (withParents || withChildren) {\r\n //deliberate for loop! not for each, appended should be processed as well.\r\n for (let i = 0; i < toSerialize.length; ++i) {\r\n if (withChildren) {\r\n toSerialize[i].getDescendants().forEach((node: Node) => {\r\n if (node instanceof Mesh && toSerialize.indexOf(node) < 0 && !node.doNotSerialize) {\r\n toSerialize.push(node);\r\n }\r\n });\r\n }\r\n //make sure the array doesn't contain the object already\r\n if (withParents && toSerialize[i].parent && toSerialize.indexOf(toSerialize[i].parent) < 0 && !toSerialize[i].parent.doNotSerialize) {\r\n toSerialize.push(toSerialize[i].parent);\r\n }\r\n }\r\n }\r\n\r\n toSerialize.forEach((mesh: Mesh) => {\r\n FinalizeSingleMesh(mesh, serializationObject);\r\n });\r\n\r\n return serializationObject;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"sceneSerializer.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/sceneSerializer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAI3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAMxD,IAAI,oBAAoB,GAAe,EAAE,CAAC;AAC1C,MAAM,iBAAiB,GAAG,CAAC,QAAkB,EAAE,uBAA4B,EAAO,EAAE;IAChF,IAAI,QAAQ,CAAC,cAAc,EAAE;QACzB,OAAO;KACV;IAED,uBAAuB,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAEnE,oBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;AACpD,CAAC,CAAC;AAEF,MAAM,a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AAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;iBAC3C;aACJ;SACJ;QAED,WAAW,CAAC,OAAO,CAAC,CAAC,IAAU,EAAE,EAAE;YAC/B,kBAAkB,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QAEH,OAAO,mBAAmB,CAAC;IAC/B,CAAC;CACJ","sourcesContent":["import type { Geometry } from \"../Meshes/geometry\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { MultiMaterial } from \"../Materials/multiMaterial\";\r\nimport type { Material } from \"../Materials/material\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Light } from \"../Lights/light\";\r\nimport { SerializationHelper } from \"./decorators\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport type { CubeTexture } from \"../Materials/Textures/cubeTexture\";\r\nimport type { Node } from \"../node\";\r\nimport type { TransformNode } from \"../Meshes/transformNode\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\n\r\nlet serializedGeometries: Geometry[] = [];\r\nconst SerializeGeometry = (geometry: Geometry, serializationGeometries: any): any => {\r\n if (geometry.doNotSerialize) {\r\n return;\r\n }\r\n\r\n serializationGeometries.vertexData.push(geometry.serializeVerticeData());\r\n\r\n (<any>serializedGeometries)[geometry.id] = true;\r\n};\r\n\r\nconst SerializeMesh = (mesh: Mesh, serializationScene: any): any => {\r\n const serializationObject: any = {};\r\n\r\n // Geometry\r\n const geometry = mesh._geometry;\r\n if (geometry) {\r\n if (!mesh.getScene().getGeometryById(geometry.id)) {\r\n // Geometry was in the memory but not added to the scene, nevertheless it's better to serialize to be able to reload the mesh with its geometry\r\n SerializeGeometry(geometry, serializationScene.geometries);\r\n }\r\n }\r\n\r\n // Custom\r\n if (mesh.serialize) {\r\n mesh.serialize(serializationObject);\r\n }\r\n\r\n return serializationObject;\r\n};\r\n\r\nconst FinalizeSingleNode = (node: Node, serializationObject: any) => {\r\n if ((node as Mesh)._isMesh) {\r\n const mesh = node as Mesh;\r\n //only works if the mesh is already loaded\r\n if (mesh.delayLoadState === Constants.DELAYLOADSTATE_LOADED || mesh.delayLoadState === Constants.DELAYLOADSTATE_NONE) {\r\n const serializeMaterial = (material: Material) => {\r\n serializationObject.materials = serializationObject.materials || [];\r\n if (mesh.material && !serializationObject.materials.some((mat: Material) => mat.id === (<Material>mesh.material).id)) {\r\n serializationObject.materials.push(material.serialize());\r\n }\r\n };\r\n\r\n //serialize material\r\n if (mesh.material && !mesh.material.doNotSerialize) {\r\n if (mesh.material instanceof MultiMaterial) {\r\n serializationObject.multiMaterials = serializationObject.multiMaterials || [];\r\n if (!serializationObject.multiMaterials.some((mat: Material) => mat.id === (<Material>mesh.material).id)) {\r\n serializationObject.multiMaterials.push(mesh.material.serialize());\r\n for (const submaterial of mesh.material.subMaterials) {\r\n if (submaterial) {\r\n serializeMaterial(submaterial);\r\n }\r\n }\r\n }\r\n } else {\r\n serializeMaterial(mesh.material);\r\n }\r\n } else if (!mesh.material) {\r\n serializeMaterial(mesh.getScene().defaultMaterial);\r\n }\r\n\r\n //serialize geometry\r\n const geometry = mesh._geometry;\r\n if (geometry) {\r\n if (!serializationObject.geometries) {\r\n serializationObject.geometries = {};\r\n\r\n serializationObject.geometries.boxes = [];\r\n serializationObject.geometries.spheres = [];\r\n serializationObject.geometries.cylinders = [];\r\n serializationObject.geometries.toruses = [];\r\n serializationObject.geometries.grounds = [];\r\n serializationObject.geometries.planes = [];\r\n serializationObject.geometries.torusKnots = [];\r\n serializationObject.geometries.vertexData = [];\r\n }\r\n\r\n SerializeGeometry(geometry, serializationObject.geometries);\r\n }\r\n // Skeletons\r\n if (mesh.skeleton && !mesh.skeleton.doNotSerialize) {\r\n serializationObject.skeletons = serializationObject.skeletons || [];\r\n serializationObject.skeletons.push(mesh.skeleton.serialize());\r\n }\r\n\r\n //serialize the actual mesh\r\n serializationObject.meshes = serializationObject.meshes || [];\r\n serializationObject.meshes.push(SerializeMesh(mesh, serializationObject));\r\n }\r\n } else if (node.getClassName() === \"TransformNode\") {\r\n const transformNode = node as TransformNode;\r\n serializationObject.transformNodes.push(transformNode.serialize());\r\n } else if (node.getClassName().indexOf(\"Camera\") !== -1) {\r\n const camera = node as Camera;\r\n serializationObject.cameras.push(camera.serialize());\r\n } else if (node.getClassName().indexOf(\"Light\") !== -1) {\r\n const light = node as Light;\r\n serializationObject.lights.push(light.serialize());\r\n }\r\n};\r\n\r\n/**\r\n * Class used to serialize a scene into a string\r\n */\r\nexport class SceneSerializer {\r\n /**\r\n * Clear cache used by a previous serialization\r\n */\r\n public static ClearCache(): void {\r\n serializedGeometries = [];\r\n }\r\n\r\n /**\r\n * Serialize a scene into a JSON compatible object\r\n * Note that if the current engine does not support synchronous texture reading (like WebGPU), you should use SerializeAsync instead\r\n * as else you may not retrieve the proper base64 encoded texture data (when using the Texture.ForceSerializeBuffers flag)\r\n * @param scene defines the scene to serialize\r\n * @returns a JSON compatible object\r\n */\r\n public static Serialize(scene: Scene): any {\r\n return SceneSerializer._Serialize(scene);\r\n }\r\n\r\n private static _Serialize(scene: Scene, checkSyncReadSupported = true): any {\r\n const serializationObject: any = {};\r\n\r\n if (checkSyncReadSupported && !scene.getEngine()._features.supportSyncTextureRead && Texture.ForceSerializeBuffers) {\r\n console.warn(\"The serialization object may not contain the proper base64 encoded texture data! You should use the SerializeAsync method instead.\");\r\n }\r\n\r\n SceneSerializer.ClearCache();\r\n\r\n // Scene\r\n serializationObject.useDelayedTextureLoading = scene.useDelayedTextureLoading;\r\n serializationObject.autoClear = scene.autoClear;\r\n serializationObject.clearColor = scene.clearColor.asArray();\r\n serializationObject.ambientColor = scene.ambientColor.asArray();\r\n serializationObject.gravity = scene.gravity.asArray();\r\n serializationObject.collisionsEnabled = scene.collisionsEnabled;\r\n serializationObject.useRightHandedSystem = scene.useRightHandedSystem;\r\n\r\n // Fog\r\n if (scene.fogMode && scene.fogMode !== 0) {\r\n serializationObject.fogMode = scene.fogMode;\r\n serializationObject.fogColor = scene.fogColor.asArray();\r\n serializationObject.fogStart = scene.fogStart;\r\n serializationObject.fogEnd = scene.fogEnd;\r\n serializationObject.fogDensity = scene.fogDensity;\r\n }\r\n\r\n //Physics\r\n if (scene.isPhysicsEnabled && scene.isPhysicsEnabled()) {\r\n const physicEngine = scene.getPhysicsEngine();\r\n\r\n if (physicEngine) {\r\n serializationObject.physicsEnabled = true;\r\n serializationObject.physicsGravity = physicEngine.gravity.asArray();\r\n serializationObject.physicsEngine = physicEngine.getPhysicsPluginName();\r\n }\r\n }\r\n\r\n // Metadata\r\n if (scene.metadata) {\r\n serializationObject.metadata = scene.metadata;\r\n }\r\n\r\n // Morph targets\r\n serializationObject.morphTargetManagers = [];\r\n for (const abstractMesh of scene.meshes) {\r\n const manager = (<Mesh>abstractMesh).morphTargetManager;\r\n\r\n if (manager) {\r\n serializationObject.morphTargetManagers.push(manager.serialize());\r\n }\r\n }\r\n\r\n // Lights\r\n serializationObject.lights = [];\r\n let index: number;\r\n let light: Light;\r\n for (index = 0; index < scene.lights.length; index++) {\r\n light = scene.lights[index];\r\n\r\n if (!light.doNotSerialize) {\r\n serializationObject.lights.push(light.serialize());\r\n }\r\n }\r\n\r\n // Cameras\r\n serializationObject.cameras = [];\r\n for (index = 0; index < scene.cameras.length; index++) {\r\n const camera = scene.cameras[index];\r\n\r\n if (!camera.doNotSerialize) {\r\n serializationObject.cameras.push(camera.serialize());\r\n }\r\n }\r\n\r\n if (scene.activeCamera) {\r\n serializationObject.activeCameraID = scene.activeCamera.id;\r\n }\r\n\r\n // Animations\r\n SerializationHelper.AppendSerializedAnimations(scene, serializationObject);\r\n\r\n // Animation Groups\r\n if (scene.animationGroups && scene.animationGroups.length > 0) {\r\n serializationObject.animationGroups = [];\r\n for (let animationGroupIndex = 0; animationGroupIndex < scene.animationGroups.length; animationGroupIndex++) {\r\n const animationGroup = scene.animationGroups[animationGroupIndex];\r\n\r\n serializationObject.animationGroups.push(animationGroup.serialize());\r\n }\r\n }\r\n\r\n // Reflection probes\r\n if (scene.reflectionProbes && scene.reflectionProbes.length > 0) {\r\n serializationObject.reflectionProbes = [];\r\n\r\n for (index = 0; index < scene.reflectionProbes.length; index++) {\r\n const reflectionProbe = scene.reflectionProbes[index];\r\n serializationObject.reflectionProbes.push(reflectionProbe.serialize());\r\n }\r\n }\r\n\r\n // Materials\r\n serializationObject.materials = [];\r\n serializationObject.multiMaterials = [];\r\n let material: Material;\r\n for (index = 0; index < scene.materials.length; index++) {\r\n material = scene.materials[index];\r\n if (!material.doNotSerialize) {\r\n serializationObject.materials.push(material.serialize());\r\n }\r\n }\r\n\r\n // MultiMaterials\r\n serializationObject.multiMaterials = [];\r\n for (index = 0; index < scene.multiMaterials.length; index++) {\r\n const multiMaterial = scene.multiMaterials[index];\r\n serializationObject.multiMaterials.push(multiMaterial.serialize());\r\n }\r\n\r\n // Environment texture\r\n if (scene.environmentTexture) {\r\n if ((scene.environmentTexture as CubeTexture)._files) {\r\n serializationObject.environmentTexture = scene.environmentTexture.serialize();\r\n } else {\r\n serializationObject.environmentTexture = scene.environmentTexture.name;\r\n serializationObject.environmentTextureRotationY = (scene.environmentTexture as CubeTexture).rotationY;\r\n }\r\n }\r\n\r\n // Environment Intensity\r\n serializationObject.environmentIntensity = scene.environmentIntensity;\r\n\r\n // Skeletons\r\n serializationObject.skeletons = [];\r\n for (index = 0; index < scene.skeletons.length; index++) {\r\n const skeleton = scene.skeletons[index];\r\n if (!skeleton.doNotSerialize) {\r\n serializationObject.skeletons.push(skeleton.serialize());\r\n }\r\n }\r\n\r\n // Transform nodes\r\n serializationObject.transformNodes = [];\r\n for (index = 0; index < scene.transformNodes.length; index++) {\r\n if (!scene.transformNodes[index].doNotSerialize) {\r\n serializationObject.transformNodes.push(scene.transformNodes[index].serialize());\r\n }\r\n }\r\n\r\n // Geometries\r\n serializationObject.geometries = {};\r\n\r\n serializationObject.geometries.boxes = [];\r\n serializationObject.geometries.spheres = [];\r\n serializationObject.geometries.cylinders = [];\r\n serializationObject.geometries.toruses = [];\r\n serializationObject.geometries.grounds = [];\r\n serializationObject.geometries.planes = [];\r\n serializationObject.geometries.torusKnots = [];\r\n serializationObject.geometries.vertexData = [];\r\n\r\n serializedGeometries = [];\r\n const geometries = scene.getGeometries();\r\n for (index = 0; index < geometries.length; index++) {\r\n const geometry = geometries[index];\r\n\r\n if (geometry.isReady()) {\r\n SerializeGeometry(geometry, serializationObject.geometries);\r\n }\r\n }\r\n\r\n // Meshes\r\n serializationObject.meshes = [];\r\n for (index = 0; index < scene.meshes.length; index++) {\r\n const abstractMesh = scene.meshes[index];\r\n\r\n if (abstractMesh instanceof Mesh) {\r\n const mesh = abstractMesh;\r\n if (!mesh.doNotSerialize) {\r\n if (mesh.delayLoadState === Constants.DELAYLOADSTATE_LOADED || mesh.delayLoadState === Constants.DELAYLOADSTATE_NONE) {\r\n serializationObject.meshes.push(SerializeMesh(mesh, serializationObject));\r\n }\r\n }\r\n }\r\n }\r\n\r\n // Particles Systems\r\n serializationObject.particleSystems = [];\r\n for (index = 0; index < scene.particleSystems.length; index++) {\r\n serializationObject.particleSystems.push(scene.particleSystems[index].serialize(false));\r\n }\r\n\r\n // Post processes\r\n serializationObject.postProcesses = [];\r\n for (index = 0; index < scene.postProcesses.length; index++) {\r\n serializationObject.postProcesses.push(scene.postProcesses[index].serialize());\r\n }\r\n\r\n // Action Manager\r\n if (scene.actionManager) {\r\n serializationObject.actions = scene.actionManager.serialize(\"scene\");\r\n }\r\n\r\n // Components\r\n for (const component of scene._serializableComponents) {\r\n component.serialize(serializationObject);\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Serialize a scene into a JSON compatible object\r\n * @param scene defines the scene to serialize\r\n * @returns a JSON promise compatible object\r\n */\r\n public static SerializeAsync(scene: Scene): Promise<any> {\r\n const serializationObject = SceneSerializer._Serialize(scene, false);\r\n\r\n const promises: Array<Promise<any>> = [];\r\n\r\n this._CollectPromises(serializationObject, promises);\r\n\r\n return Promise.all(promises).then(() => serializationObject);\r\n }\r\n\r\n private static _CollectPromises(obj: any, promises: Array<Promise<any>>): void {\r\n if (Array.isArray(obj)) {\r\n for (let i = 0; i < obj.length; ++i) {\r\n const o = obj[i];\r\n if (o instanceof Promise) {\r\n promises.push(o.then((res: any) => (obj[i] = res)));\r\n } else if (o instanceof Object || Array.isArray(o)) {\r\n this._CollectPromises(o, promises);\r\n }\r\n }\r\n } else if (obj instanceof Object) {\r\n for (const name in obj) {\r\n if (Object.prototype.hasOwnProperty.call(obj, name)) {\r\n const o = obj[name];\r\n if (o instanceof Promise) {\r\n promises.push(o.then((res: any) => (obj[name] = res)));\r\n } else if (o instanceof Object || Array.isArray(o)) {\r\n this._CollectPromises(o, promises);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Serialize a mesh into a JSON compatible object\r\n * @param toSerialize defines the mesh to serialize\r\n * @param withParents defines if parents must be serialized as well\r\n * @param withChildren defines if children must be serialized as well\r\n * @returns a JSON compatible object\r\n */\r\n public static SerializeMesh(toSerialize: any /* Mesh || Mesh[] */, withParents: boolean = false, withChildren: boolean = false): any {\r\n const serializationObject: any = {};\r\n serializationObject.meshes = [];\r\n serializationObject.transformNodes = [];\r\n serializationObject.cameras = [];\r\n serializationObject.lights = [];\r\n\r\n SceneSerializer.ClearCache();\r\n\r\n toSerialize = toSerialize instanceof Array ? toSerialize : [toSerialize];\r\n\r\n if (withParents || withChildren) {\r\n //deliberate for loop! not for each, appended should be processed as well.\r\n for (let i = 0; i < toSerialize.length; ++i) {\r\n if (withChildren) {\r\n toSerialize[i].getDescendants().forEach((node: Node) => {\r\n if (toSerialize.indexOf(node) < 0 && !node.doNotSerialize) {\r\n toSerialize.push(node);\r\n }\r\n });\r\n }\r\n //make sure the array doesn't contain the object already\r\n if (withParents && toSerialize[i].parent && toSerialize.indexOf(toSerialize[i].parent) < 0 && !toSerialize[i].parent.doNotSerialize) {\r\n toSerialize.push(toSerialize[i].parent);\r\n }\r\n }\r\n }\r\n\r\n toSerialize.forEach((mesh: Node) => {\r\n FinalizeSingleNode(mesh, serializationObject);\r\n });\r\n\r\n return serializationObject;\r\n }\r\n}\r\n"]}
@@ -28,7 +28,7 @@ export declare class GPUParticleSystem extends BaseParticleSystem implements IDi
28
28
  */
29
29
  layerMask: number;
30
30
  private _capacity;
31
- private _activeCount;
31
+ private _maxActiveParticleCount;
32
32
  private _currentActiveCount;
33
33
  private _accumulatedCount;
34
34
  private _updateBuffer;
@@ -82,6 +82,13 @@ export declare class GPUParticleSystem extends BaseParticleSystem implements IDi
82
82
  forceDepthWrite: boolean;
83
83
  /**
84
84
  * Gets or set the number of active particles
85
+ * The value cannot be greater than "capacity" (if it is, it will be limited to "capacity").
86
+ */
87
+ get maxActiveParticleCount(): number;
88
+ set maxActiveParticleCount(value: number);
89
+ /**
90
+ * Gets or set the number of active particles
91
+ * @deprecated Please use maxActiveParticleCount instead.
85
92
  */
86
93
  get activeParticleCount(): number;
87
94
  set activeParticleCount(value: number);
@@ -45,12 +45,23 @@ export class GPUParticleSystem extends BaseParticleSystem {
45
45
  }
46
46
  /**
47
47
  * Gets or set the number of active particles
48
+ * The value cannot be greater than "capacity" (if it is, it will be limited to "capacity").
49
+ */
50
+ get maxActiveParticleCount() {
51
+ return this._maxActiveParticleCount;
52
+ }
53
+ set maxActiveParticleCount(value) {
54
+ this._maxActiveParticleCount = Math.min(value, this._capacity);
55
+ }
56
+ /**
57
+ * Gets or set the number of active particles
58
+ * @deprecated Please use maxActiveParticleCount instead.
48
59
  */
49
60
  get activeParticleCount() {
50
- return this._activeCount;
61
+ return this.maxActiveParticleCount;
51
62
  }
52
63
  set activeParticleCount(value) {
53
- this._activeCount = Math.min(value, this._capacity);
64
+ this.maxActiveParticleCount = value;
54
65
  }
55
66
  /**
56
67
  * Is this system ready to be used/rendered
@@ -634,7 +645,7 @@ export class GPUParticleSystem extends BaseParticleSystem {
634
645
  fullOptions.capacity = optionsAsNumber;
635
646
  }
636
647
  this._capacity = fullOptions.capacity;
637
- this._activeCount = fullOptions.capacity;
648
+ this._maxActiveParticleCount = fullOptions.capacity;
638
649
  this._currentActiveCount = 0;
639
650
  this._isAnimationSheetEnabled = isAnimationSheetEnabled;
640
651
  this.particleEmitterType = new BoxParticleEmitter();
@@ -1304,8 +1315,9 @@ export class GPUParticleSystem extends BaseParticleSystem {
1304
1315
  if (this._accumulatedCount > 1) {
1305
1316
  const intPart = this._accumulatedCount | 0;
1306
1317
  this._accumulatedCount -= intPart;
1307
- this._currentActiveCount = Math.min(this._activeCount, this._currentActiveCount + intPart);
1318
+ this._currentActiveCount += intPart;
1308
1319
  }
1320
+ this._currentActiveCount = Math.min(this._maxActiveParticleCount, this._currentActiveCount);
1309
1321
  if (!this._currentActiveCount) {
1310
1322
  return 0;
1311
1323
  }