@babylonjs/core 5.53.1 → 5.54.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.
package/Meshes/trailMesh.d.ts
CHANGED
|
@@ -5,17 +5,20 @@ import type { TransformNode } from "../Meshes/transformNode";
|
|
|
5
5
|
* Class used to create a trail following a mesh
|
|
6
6
|
*/
|
|
7
7
|
export declare class TrailMesh extends Mesh {
|
|
8
|
+
/**
|
|
9
|
+
* The diameter of the trail, i.e. the width of the ribbon.
|
|
10
|
+
*/
|
|
11
|
+
diameter: number;
|
|
8
12
|
private _generator;
|
|
9
13
|
private _autoStart;
|
|
10
14
|
private _running;
|
|
11
|
-
private _diameter;
|
|
12
15
|
private _length;
|
|
13
16
|
private _sectionPolygonPointsCount;
|
|
14
17
|
private _sectionVectors;
|
|
15
18
|
private _sectionNormalVectors;
|
|
16
19
|
private _beforeRenderObserver;
|
|
17
20
|
/**
|
|
18
|
-
*
|
|
21
|
+
* Creates a new TrailMesh.
|
|
19
22
|
* @param name The value used by scene.getMeshByName() to do a lookup.
|
|
20
23
|
* @param generator The mesh or transform node to generate a trail.
|
|
21
24
|
* @param scene The scene to add this mesh to.
|
package/Meshes/trailMesh.js
CHANGED
|
@@ -8,7 +8,7 @@ import { VertexData } from "../Meshes/mesh.vertexData.js";
|
|
|
8
8
|
*/
|
|
9
9
|
export class TrailMesh extends Mesh {
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Creates a new TrailMesh.
|
|
12
12
|
* @param name The value used by scene.getMeshByName() to do a lookup.
|
|
13
13
|
* @param generator The mesh or transform node to generate a trail.
|
|
14
14
|
* @param scene The scene to add this mesh to.
|
|
@@ -22,7 +22,7 @@ export class TrailMesh extends Mesh {
|
|
|
22
22
|
this._running = false;
|
|
23
23
|
this._autoStart = autoStart;
|
|
24
24
|
this._generator = generator;
|
|
25
|
-
this.
|
|
25
|
+
this.diameter = diameter;
|
|
26
26
|
this._length = length;
|
|
27
27
|
this._sectionVectors = [];
|
|
28
28
|
this._sectionNormalVectors = [];
|
|
@@ -53,11 +53,11 @@ export class TrailMesh extends Mesh {
|
|
|
53
53
|
}
|
|
54
54
|
const alpha = (2 * Math.PI) / this._sectionPolygonPointsCount;
|
|
55
55
|
for (let i = 0; i < this._sectionPolygonPointsCount; i++) {
|
|
56
|
-
positions.push(meshCenter.x + Math.cos(i * alpha) * this.
|
|
56
|
+
positions.push(meshCenter.x + Math.cos(i * alpha) * this.diameter, meshCenter.y + Math.sin(i * alpha) * this.diameter, meshCenter.z);
|
|
57
57
|
}
|
|
58
58
|
for (let i = 1; i <= this._length; i++) {
|
|
59
59
|
for (let j = 0; j < this._sectionPolygonPointsCount; j++) {
|
|
60
|
-
positions.push(meshCenter.x + Math.cos(j * alpha) * this.
|
|
60
|
+
positions.push(meshCenter.x + Math.cos(j * alpha) * this.diameter, meshCenter.y + Math.sin(j * alpha) * this.diameter, meshCenter.z);
|
|
61
61
|
}
|
|
62
62
|
const l = positions.length / 3 - 2 * this._sectionPolygonPointsCount;
|
|
63
63
|
for (let j = 0; j < this._sectionPolygonPointsCount - 1; j++) {
|
|
@@ -105,7 +105,7 @@ export class TrailMesh extends Mesh {
|
|
|
105
105
|
const wm = this._generator.getWorldMatrix();
|
|
106
106
|
if (positions && normals) {
|
|
107
107
|
for (let i = 3 * this._sectionPolygonPointsCount; i < positions.length; i++) {
|
|
108
|
-
positions[i - 3 * this._sectionPolygonPointsCount] = positions[i] - (normals[i] / this._length) * this.
|
|
108
|
+
positions[i - 3 * this._sectionPolygonPointsCount] = positions[i] - (normals[i] / this._length) * this.diameter;
|
|
109
109
|
}
|
|
110
110
|
for (let i = 3 * this._sectionPolygonPointsCount; i < normals.length; i++) {
|
|
111
111
|
normals[i - 3 * this._sectionPolygonPointsCount] = normals[i];
|
|
@@ -113,7 +113,7 @@ export class TrailMesh extends Mesh {
|
|
|
113
113
|
const l = positions.length - 3 * this._sectionPolygonPointsCount;
|
|
114
114
|
const alpha = (2 * Math.PI) / this._sectionPolygonPointsCount;
|
|
115
115
|
for (let i = 0; i < this._sectionPolygonPointsCount; i++) {
|
|
116
|
-
this._sectionVectors[i].copyFromFloats(Math.cos(i * alpha) * this.
|
|
116
|
+
this._sectionVectors[i].copyFromFloats(Math.cos(i * alpha) * this.diameter, Math.sin(i * alpha) * this.diameter, 0);
|
|
117
117
|
this._sectionNormalVectors[i].copyFromFloats(Math.cos(i * alpha), Math.sin(i * alpha), 0);
|
|
118
118
|
Vector3.TransformCoordinatesToRef(this._sectionVectors[i], wm, this._sectionVectors[i]);
|
|
119
119
|
Vector3.TransformNormalToRef(this._sectionNormalVectors[i], wm, this._sectionNormalVectors[i]);
|
|
@@ -137,7 +137,7 @@ export class TrailMesh extends Mesh {
|
|
|
137
137
|
* @returns a new mesh
|
|
138
138
|
*/
|
|
139
139
|
clone(name = "", newGenerator) {
|
|
140
|
-
return new TrailMesh(name, newGenerator === undefined ? this._generator : newGenerator, this.getScene(), this.
|
|
140
|
+
return new TrailMesh(name, newGenerator === undefined ? this._generator : newGenerator, this.getScene(), this.diameter, this._length, this._autoStart);
|
|
141
141
|
}
|
|
142
142
|
/**
|
|
143
143
|
* Serializes this trail mesh
|
|
@@ -153,7 +153,8 @@ export class TrailMesh extends Mesh {
|
|
|
153
153
|
* @returns the created trail mesh
|
|
154
154
|
*/
|
|
155
155
|
static Parse(parsedMesh, scene) {
|
|
156
|
-
|
|
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);
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
//# sourceMappingURL=trailMesh.js.map
|
package/Meshes/trailMesh.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trailMesh.js","sourceRoot":"","sources":["../../../../lts/core/generated/Meshes/trailMesh.ts"],"names":[],"mapp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AS,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC5J,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,UAAU,CAAC,SAAS,EAAE,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;IACzI,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 private _generator: TransformNode;\r\n private _autoStart: boolean;\r\n private _running: boolean;\r\n private _diameter: number;\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 * @constructor\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._length, parsedMesh._autoStart);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"trailMesh.js","sourceRoot":"","sources":["../../../../l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AI,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"]}
|
package/Misc/sceneRecorder.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sceneRecorder.js","sourceRoot":"","sources":["../../../../lts/core/generated/Misc/sceneRecorder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,aAAa;IAA1B;QACY,kBAAa,GAAoB,IAAI,CAAC;IAuSlD,CAAC;IApSG;;;OAGG;IACI,KAAK,CAAC,KAAY;QACrB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;QAE3B,mBAAmB,CAAC,oBAAoB,GAAG,IAAI,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,eAAe,CAAC,SAAS,CAAC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Q,KAAK,IAAI,EAAE;gBAC1D,IAAI,CAAC,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;aACnD;SACJ;IACL,CAAC;IAEO,MAAM,CAAC,oBAAoB,CAAC,OAAc,EAAE,KAAY,EAAE,MAA2B,EAAE,MAA2B;QACtH,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;YAC1B,SAAS;YACT,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,KAAK,SAAS,EAAE;gBACnD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;gBAE/C,IAAI,YAAY,EAAE;oBACd,2EAA2E;oBAC3E,IAAI,CAAC,wBAAwB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;oBACpD,sDAAsD;oBACtD,mBAAmB,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;iBAC1E;aACJ;iBAAM,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE;gBAChE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAC/C,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE,CAAC;aACrB;iBAAM;gBACH,MAAM;gBACN,MAAM,CAAC,MAAM,CAAC,CAAC;aAClB;SACJ;IACL,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { SceneSerializer } from \"./sceneSerializer\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { Light } from \"../Lights/light\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport { Skeleton } from \"../Bones/skeleton\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { MultiMaterial } from \"../Materials/multiMaterial\";\r\nimport { TransformNode } from \"../Meshes/transformNode\";\r\nimport { ParticleSystem } from \"../Particles/particleSystem\";\r\nimport { MorphTargetManager } from \"../Morph/morphTargetManager\";\r\nimport { ShadowGenerator } from \"../Lights/Shadows/shadowGenerator\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { SerializationHelper } from \"./decorators\";\r\n\r\n/**\r\n * Class used to record delta files between 2 scene states\r\n */\r\nexport class SceneRecorder {\r\n private _trackedScene: Nullable<Scene> = null;\r\n private _savedJSON: any;\r\n\r\n /**\r\n * Track a given scene. This means the current scene state will be considered the original state\r\n * @param scene defines the scene to track\r\n */\r\n public track(scene: Scene) {\r\n this._trackedScene = scene;\r\n\r\n SerializationHelper.AllowLoadingUniqueId = true;\r\n this._savedJSON = SceneSerializer.Serialize(scene);\r\n SerializationHelper.AllowLoadingUniqueId = false;\r\n }\r\n\r\n /**\r\n * Get the delta between current state and original state\r\n * @returns a any containing the delta\r\n */\r\n public getDelta(): any {\r\n if (!this._trackedScene) {\r\n return null;\r\n }\r\n\r\n const currentForceSerializeBuffers = Texture.ForceSerializeBuffers;\r\n Texture.ForceSerializeBuffers = false;\r\n\r\n SerializationHelper.AllowLoadingUniqueId = true;\r\n const newJSON = SceneSerializer.Serialize(this._trackedScene);\r\n SerializationHelper.AllowLoadingUniqueId = false;\r\n const deltaJSON: any = {};\r\n\r\n for (const node in newJSON) {\r\n this._compareCollections(node, this._savedJSON[node], newJSON[node], deltaJSON);\r\n }\r\n\r\n Texture.ForceSerializeBuffers = currentForceSerializeBuffers;\r\n\r\n return deltaJSON;\r\n }\r\n\r\n private _compareArray(key: string, original: any[], current: any[], deltaJSON: any) {\r\n if (original.length === 0 && current.length === 0) {\r\n return true;\r\n }\r\n\r\n // Numbers?\r\n if ((original.length && !isNaN(original[0])) || (current.length && !isNaN(current[0]))) {\r\n if (original.length !== current.length) {\r\n return false;\r\n }\r\n\r\n if (original.length === 0) {\r\n return true;\r\n }\r\n for (let index = 0; index < original.length; index++) {\r\n if (original[index] !== current[index]) {\r\n deltaJSON[key] = current;\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n // let's use uniqueId to find similar objects\r\n const originalUniqueIds: number[] = [];\r\n for (let index = 0; index < original.length; index++) {\r\n const originalObject = original[index];\r\n const originalUniqueId = originalObject.uniqueId;\r\n\r\n originalUniqueIds.push(originalUniqueId);\r\n // Look for that object in current state\r\n const currentObjects = current.filter((c) => c.uniqueId === originalUniqueId);\r\n if (currentObjects.length) {\r\n // We have a candidate\r\n const currentObject = currentObjects[0];\r\n\r\n const newObject: any = {};\r\n if (!this._compareObjects(originalObject, currentObject, newObject)) {\r\n if (!deltaJSON[key]) {\r\n deltaJSON[key] = [];\r\n }\r\n newObject.__state = {\r\n id: currentObject.id || currentObject.name,\r\n };\r\n deltaJSON[key].push(newObject);\r\n }\r\n } else {\r\n // We need to delete\r\n const newObject: any = {\r\n __state: {\r\n deleteId: originalObject.id || originalObject.name,\r\n },\r\n };\r\n deltaJSON[key].push(newObject);\r\n }\r\n }\r\n\r\n // Checking for new objects\r\n for (let index = 0; index < current.length; index++) {\r\n const currentObject = current[index];\r\n const currentUniqueId = currentObject.uniqueId;\r\n\r\n // Object was added\r\n if (originalUniqueIds.indexOf(currentUniqueId) === -1) {\r\n if (!deltaJSON[key]) {\r\n deltaJSON[key] = [];\r\n }\r\n\r\n deltaJSON[key].push(currentObject);\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n private _compareObjects(originalObjet: any, currentObject: any, deltaJSON: any) {\r\n let aDifferenceWasFound = false;\r\n\r\n for (const prop in originalObjet) {\r\n if (!Object.prototype.hasOwnProperty.call(originalObjet, prop)) {\r\n continue;\r\n }\r\n const originalValue = originalObjet[prop];\r\n const currentValue = currentObject[prop];\r\n let diffFound = false;\r\n\r\n if (Array.isArray(originalValue)) {\r\n diffFound = JSON.stringify(originalValue) !== JSON.stringify(currentValue);\r\n } else if (!isNaN(originalValue) || Object.prototype.toString.call(originalValue) == \"[object String]\") {\r\n diffFound = originalValue !== currentValue;\r\n } else if (typeof originalValue === \"object\" && typeof currentValue === \"object\") {\r\n const newObject = {};\r\n if (!this._compareObjects(originalValue, currentValue, newObject)) {\r\n deltaJSON[prop] = newObject;\r\n aDifferenceWasFound = true;\r\n }\r\n }\r\n\r\n if (diffFound) {\r\n aDifferenceWasFound = true;\r\n deltaJSON[prop] = currentValue;\r\n }\r\n }\r\n\r\n return !aDifferenceWasFound;\r\n }\r\n\r\n private _compareCollections(key: string, original: any[], current: any[], deltaJSON: any) {\r\n // Same ?\r\n if (original === current) {\r\n return;\r\n }\r\n\r\n if (original && current) {\r\n // Array?\r\n if (Array.isArray(original) && Array.isArray(current)) {\r\n if (this._compareArray(key, original, current, deltaJSON)) {\r\n return;\r\n }\r\n } else if (typeof original === \"object\" && typeof current === \"object\") {\r\n // Object\r\n const newObject = {};\r\n if (!this._compareObjects(original, current, newObject)) {\r\n deltaJSON[key] = newObject;\r\n }\r\n return;\r\n }\r\n }\r\n }\r\n\r\n private static GetShadowGeneratorById(scene: Scene, id: string) {\r\n const allGenerators = scene.lights.map((l) => l.getShadowGenerators());\r\n\r\n for (const generators of allGenerators) {\r\n if (generators) {\r\n const iterator = generators.values();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const generator = key.value;\r\n if (generator && generator.id === id) {\r\n return generator;\r\n }\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Apply a given delta to a given scene\r\n * @param deltaJSON defines the JSON containing the delta\r\n * @param scene defines the scene to apply the delta to\r\n */\r\n public static ApplyDelta(deltaJSON: any | string, scene: Scene) {\r\n if (typeof deltaJSON === \"string\") {\r\n deltaJSON = JSON.parse(deltaJSON);\r\n }\r\n\r\n // Scene\r\n const anyScene = scene as any;\r\n for (const prop in deltaJSON) {\r\n const source = deltaJSON[prop];\r\n const property = anyScene[prop];\r\n\r\n if (Array.isArray(property) || prop === \"shadowGenerators\") {\r\n // Restore array\r\n switch (prop) {\r\n case \"cameras\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getCameraById.bind(scene), (data) => Camera.Parse(data, scene));\r\n break;\r\n case \"lights\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getLightById.bind(scene), (data) => Light.Parse(data, scene));\r\n break;\r\n case \"shadowGenerators\":\r\n this._ApplyDeltaForEntity(\r\n source,\r\n scene,\r\n (id) => this.GetShadowGeneratorById(scene, id),\r\n (data) => ShadowGenerator.Parse(data, scene)\r\n );\r\n break;\r\n case \"meshes\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMeshById.bind(scene), (data) => Mesh.Parse(data, scene, \"\"));\r\n break;\r\n case \"skeletons\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getSkeletonById.bind(scene), (data) => Skeleton.Parse(data, scene));\r\n break;\r\n case \"materials\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMaterialById.bind(scene), (data) => Material.Parse(data, scene, \"\"));\r\n break;\r\n case \"multiMaterials\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMaterialById.bind(scene), (data) => MultiMaterial.Parse(data, scene, \"\"));\r\n break;\r\n case \"transformNodes\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getTransformNodeById.bind(scene), (data) => TransformNode.Parse(data, scene, \"\"));\r\n break;\r\n case \"particleSystems\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getParticleSystemById.bind(scene), (data) => ParticleSystem.Parse(data, scene, \"\"));\r\n break;\r\n case \"morphTargetManagers\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMorphTargetById.bind(scene), (data) => MorphTargetManager.Parse(data, scene));\r\n break;\r\n case \"postProcesses\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getPostProcessByName.bind(scene), (data) => PostProcess.Parse(data, scene, \"\"));\r\n break;\r\n }\r\n } else if (!isNaN(property)) {\r\n anyScene[prop] = source;\r\n } else if (property.fromArray) {\r\n property.fromArray(source);\r\n }\r\n }\r\n }\r\n\r\n private static _ApplyPropertiesToEntity(deltaJSON: any, entity: any) {\r\n for (const prop in deltaJSON) {\r\n const source = deltaJSON[prop];\r\n const property = entity[prop];\r\n\r\n if (property === undefined) {\r\n continue;\r\n }\r\n\r\n if (!isNaN(property) || Array.isArray(property)) {\r\n entity[prop] = source;\r\n } else if (property.fromArray) {\r\n property.fromArray(source);\r\n } else if (typeof property === \"object\" && property !== null) {\r\n this._ApplyPropertiesToEntity(source, property);\r\n }\r\n }\r\n }\r\n\r\n private static _ApplyDeltaForEntity(sources: any[], scene: Scene, finder: (id: string) => any, addNew: (data: any) => void) {\r\n for (const source of sources) {\r\n // Update\r\n if (source.__state && source.__state.id !== undefined) {\r\n const targetEntity = finder(source.__state.id);\r\n\r\n if (targetEntity) {\r\n // This first pass applies properties that aren't on the serialization list\r\n this._ApplyPropertiesToEntity(source, targetEntity);\r\n // The second pass applies the serializable properties\r\n SerializationHelper.ParseProperties(source, targetEntity, scene, null);\r\n }\r\n } else if (source.__state && source.__state.deleteId !== undefined) {\r\n const target = finder(source.__state.deleteId);\r\n target?.dispose();\r\n } else {\r\n // New\r\n addNew(source);\r\n }\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"sceneRecorder.js","sourceRoot":"","sources":["../../../../lts/core/generated/Misc/sceneRecorder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CA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,YAAY,CAAC,CAAC;oBACpD,sDAAsD;oBACtD,mBAAmB,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;iBAC1E;aACJ;iBAAM,IAAI,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE;gBAChE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAC/C,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE,CAAC;aACrB;iBAAM;gBACH,MAAM;gBACN,MAAM,CAAC,MAAM,CAAC,CAAC;aAClB;SACJ;IACL,CAAC;CACJ","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { SceneSerializer } from \"./sceneSerializer\";\r\nimport { Mesh } from \"../Meshes/mesh\";\r\nimport { Light } from \"../Lights/light\";\r\nimport { Camera } from \"../Cameras/camera\";\r\nimport { Skeleton } from \"../Bones/skeleton\";\r\nimport { Material } from \"../Materials/material\";\r\nimport { MultiMaterial } from \"../Materials/multiMaterial\";\r\nimport { TransformNode } from \"../Meshes/transformNode\";\r\nimport { ParticleSystem } from \"../Particles/particleSystem\";\r\nimport { MorphTargetManager } from \"../Morph/morphTargetManager\";\r\nimport { ShadowGenerator } from \"../Lights/Shadows/shadowGenerator\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { SerializationHelper } from \"./decorators\";\r\n\r\n/**\r\n * Class used to record delta files between 2 scene states\r\n */\r\nexport class SceneRecorder {\r\n private _trackedScene: Nullable<Scene> = null;\r\n private _savedJSON: any;\r\n\r\n /**\r\n * Track a given scene. This means the current scene state will be considered the original state\r\n * @param scene defines the scene to track\r\n */\r\n public track(scene: Scene) {\r\n this._trackedScene = scene;\r\n\r\n SerializationHelper.AllowLoadingUniqueId = true;\r\n this._savedJSON = SceneSerializer.Serialize(scene);\r\n SerializationHelper.AllowLoadingUniqueId = false;\r\n }\r\n\r\n /**\r\n * Get the delta between current state and original state\r\n * @returns a any containing the delta\r\n */\r\n public getDelta(): any {\r\n if (!this._trackedScene) {\r\n return null;\r\n }\r\n\r\n const currentForceSerializeBuffers = Texture.ForceSerializeBuffers;\r\n Texture.ForceSerializeBuffers = false;\r\n\r\n SerializationHelper.AllowLoadingUniqueId = true;\r\n const newJSON = SceneSerializer.Serialize(this._trackedScene);\r\n SerializationHelper.AllowLoadingUniqueId = false;\r\n const deltaJSON: any = {};\r\n\r\n for (const node in newJSON) {\r\n this._compareCollections(node, this._savedJSON[node], newJSON[node], deltaJSON);\r\n }\r\n\r\n Texture.ForceSerializeBuffers = currentForceSerializeBuffers;\r\n\r\n return deltaJSON;\r\n }\r\n\r\n private _compareArray(key: string, original: any[], current: any[], deltaJSON: any) {\r\n if (original.length === 0 && current.length === 0) {\r\n return true;\r\n }\r\n\r\n // Numbers?\r\n if ((original.length && !isNaN(original[0])) || (current.length && !isNaN(current[0]))) {\r\n if (original.length !== current.length) {\r\n return false;\r\n }\r\n\r\n if (original.length === 0) {\r\n return true;\r\n }\r\n for (let index = 0; index < original.length; index++) {\r\n if (original[index] !== current[index]) {\r\n deltaJSON[key] = current;\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n // let's use uniqueId to find similar objects\r\n const originalUniqueIds: number[] = [];\r\n for (let index = 0; index < original.length; index++) {\r\n const originalObject = original[index];\r\n const originalUniqueId = originalObject.uniqueId;\r\n\r\n originalUniqueIds.push(originalUniqueId);\r\n // Look for that object in current state\r\n const currentObjects = current.filter((c) => c.uniqueId === originalUniqueId);\r\n if (currentObjects.length) {\r\n // We have a candidate\r\n const currentObject = currentObjects[0];\r\n\r\n const newObject: any = {};\r\n if (!this._compareObjects(originalObject, currentObject, newObject)) {\r\n if (!deltaJSON[key]) {\r\n deltaJSON[key] = [];\r\n }\r\n newObject.__state = {\r\n id: currentObject.id || currentObject.name,\r\n };\r\n deltaJSON[key].push(newObject);\r\n }\r\n } else {\r\n // We need to delete\r\n const newObject: any = {\r\n __state: {\r\n deleteId: originalObject.id || originalObject.name,\r\n },\r\n };\r\n if (!deltaJSON[key]) {\r\n deltaJSON[key] = [];\r\n }\r\n deltaJSON[key].push(newObject);\r\n }\r\n }\r\n\r\n // Checking for new objects\r\n for (let index = 0; index < current.length; index++) {\r\n const currentObject = current[index];\r\n const currentUniqueId = currentObject.uniqueId;\r\n\r\n // Object was added\r\n if (originalUniqueIds.indexOf(currentUniqueId) === -1) {\r\n if (!deltaJSON[key]) {\r\n deltaJSON[key] = [];\r\n }\r\n\r\n deltaJSON[key].push(currentObject);\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n private _compareObjects(originalObjet: any, currentObject: any, deltaJSON: any) {\r\n let aDifferenceWasFound = false;\r\n\r\n for (const prop in originalObjet) {\r\n if (!Object.prototype.hasOwnProperty.call(originalObjet, prop)) {\r\n continue;\r\n }\r\n const originalValue = originalObjet[prop];\r\n const currentValue = currentObject[prop];\r\n let diffFound = false;\r\n\r\n if (Array.isArray(originalValue)) {\r\n diffFound = JSON.stringify(originalValue) !== JSON.stringify(currentValue);\r\n } else if (!isNaN(originalValue) || Object.prototype.toString.call(originalValue) == \"[object String]\") {\r\n diffFound = originalValue !== currentValue;\r\n } else if (typeof originalValue === \"object\" && typeof currentValue === \"object\") {\r\n const newObject = {};\r\n if (!this._compareObjects(originalValue, currentValue, newObject)) {\r\n deltaJSON[prop] = newObject;\r\n aDifferenceWasFound = true;\r\n }\r\n }\r\n\r\n if (diffFound) {\r\n aDifferenceWasFound = true;\r\n deltaJSON[prop] = currentValue;\r\n }\r\n }\r\n\r\n return !aDifferenceWasFound;\r\n }\r\n\r\n private _compareCollections(key: string, original: any[], current: any[], deltaJSON: any) {\r\n // Same ?\r\n if (original === current) {\r\n return;\r\n }\r\n\r\n if (original && current) {\r\n // Array?\r\n if (Array.isArray(original) && Array.isArray(current)) {\r\n if (this._compareArray(key, original, current, deltaJSON)) {\r\n return;\r\n }\r\n } else if (typeof original === \"object\" && typeof current === \"object\") {\r\n // Object\r\n const newObject = {};\r\n if (!this._compareObjects(original, current, newObject)) {\r\n deltaJSON[key] = newObject;\r\n }\r\n return;\r\n }\r\n }\r\n }\r\n\r\n private static GetShadowGeneratorById(scene: Scene, id: string) {\r\n const allGenerators = scene.lights.map((l) => l.getShadowGenerators());\r\n\r\n for (const generators of allGenerators) {\r\n if (generators) {\r\n const iterator = generators.values();\r\n for (let key = iterator.next(); key.done !== true; key = iterator.next()) {\r\n const generator = key.value;\r\n if (generator && generator.id === id) {\r\n return generator;\r\n }\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n }\r\n\r\n /**\r\n * Apply a given delta to a given scene\r\n * @param deltaJSON defines the JSON containing the delta\r\n * @param scene defines the scene to apply the delta to\r\n */\r\n public static ApplyDelta(deltaJSON: any | string, scene: Scene) {\r\n if (typeof deltaJSON === \"string\") {\r\n deltaJSON = JSON.parse(deltaJSON);\r\n }\r\n\r\n // Scene\r\n const anyScene = scene as any;\r\n for (const prop in deltaJSON) {\r\n const source = deltaJSON[prop];\r\n const property = anyScene[prop];\r\n\r\n if (Array.isArray(property) || prop === \"shadowGenerators\") {\r\n // Restore array\r\n switch (prop) {\r\n case \"cameras\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getCameraById.bind(scene), (data) => Camera.Parse(data, scene));\r\n break;\r\n case \"lights\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getLightById.bind(scene), (data) => Light.Parse(data, scene));\r\n break;\r\n case \"shadowGenerators\":\r\n this._ApplyDeltaForEntity(\r\n source,\r\n scene,\r\n (id) => this.GetShadowGeneratorById(scene, id),\r\n (data) => ShadowGenerator.Parse(data, scene)\r\n );\r\n break;\r\n case \"meshes\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMeshById.bind(scene), (data) => Mesh.Parse(data, scene, \"\"));\r\n break;\r\n case \"skeletons\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getSkeletonById.bind(scene), (data) => Skeleton.Parse(data, scene));\r\n break;\r\n case \"materials\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMaterialById.bind(scene), (data) => Material.Parse(data, scene, \"\"));\r\n break;\r\n case \"multiMaterials\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMaterialById.bind(scene), (data) => MultiMaterial.Parse(data, scene, \"\"));\r\n break;\r\n case \"transformNodes\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getTransformNodeById.bind(scene), (data) => TransformNode.Parse(data, scene, \"\"));\r\n break;\r\n case \"particleSystems\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getParticleSystemById.bind(scene), (data) => ParticleSystem.Parse(data, scene, \"\"));\r\n break;\r\n case \"morphTargetManagers\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getMorphTargetById.bind(scene), (data) => MorphTargetManager.Parse(data, scene));\r\n break;\r\n case \"postProcesses\":\r\n this._ApplyDeltaForEntity(source, scene, scene.getPostProcessByName.bind(scene), (data) => PostProcess.Parse(data, scene, \"\"));\r\n break;\r\n }\r\n } else if (!isNaN(property)) {\r\n anyScene[prop] = source;\r\n } else if (property.fromArray) {\r\n property.fromArray(source);\r\n }\r\n }\r\n }\r\n\r\n private static _ApplyPropertiesToEntity(deltaJSON: any, entity: any) {\r\n for (const prop in deltaJSON) {\r\n const source = deltaJSON[prop];\r\n const property = entity[prop];\r\n\r\n if (property === undefined) {\r\n continue;\r\n }\r\n\r\n if (!isNaN(property) || Array.isArray(property)) {\r\n entity[prop] = source;\r\n } else if (property.fromArray) {\r\n property.fromArray(source);\r\n } else if (typeof property === \"object\" && property !== null) {\r\n this._ApplyPropertiesToEntity(source, property);\r\n }\r\n }\r\n }\r\n\r\n private static _ApplyDeltaForEntity(sources: any[], scene: Scene, finder: (id: string) => any, addNew: (data: any) => void) {\r\n for (const source of sources) {\r\n // Update\r\n if (source.__state && source.__state.id !== undefined) {\r\n const targetEntity = finder(source.__state.id);\r\n\r\n if (targetEntity) {\r\n // This first pass applies properties that aren't on the serialization list\r\n this._ApplyPropertiesToEntity(source, targetEntity);\r\n // The second pass applies the serializable properties\r\n SerializationHelper.ParseProperties(source, targetEntity, scene, null);\r\n }\r\n } else if (source.__state && source.__state.deleteId !== undefined) {\r\n const target = finder(source.__state.deleteId);\r\n target?.dispose();\r\n } else {\r\n // New\r\n addNew(source);\r\n }\r\n }\r\n }\r\n}\r\n"]}
|