@babylonjs/core 7.30.1 → 7.31.1
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/Engines/WebGPU/webgpuCacheRenderPipeline.js +8 -0
- package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
- package/Engines/WebGPU/webgpuConstants.d.ts +16 -2
- package/Engines/WebGPU/webgpuConstants.js +15 -0
- package/Engines/WebGPU/webgpuConstants.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/constants.d.ts +8 -0
- package/Engines/constants.js +8 -0
- package/Engines/constants.js.map +1 -1
- package/Engines/engine.d.ts +22 -6
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +192 -24
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Meshes/abstractMesh.js +1 -0
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/csg2.d.ts +5 -0
- package/Meshes/csg2.js +17 -7
- package/Meshes/csg2.js.map +1 -1
- package/Meshes/transformNode.d.ts +5 -0
- package/Meshes/transformNode.js +12 -3
- package/Meshes/transformNode.js.map +1 -1
- package/Misc/snapshotRenderingHelper.d.ts +8 -0
- package/Misc/snapshotRenderingHelper.js +50 -8
- package/Misc/snapshotRenderingHelper.js.map +1 -1
- package/Shaders/ShadersInclude/backgroundVertexDeclaration.js +5 -1
- package/Shaders/ShadersInclude/backgroundVertexDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/defaultVertexDeclaration.js +5 -1
- package/Shaders/ShadersInclude/defaultVertexDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/pbrVertexDeclaration.js +3 -0
- package/Shaders/ShadersInclude/pbrVertexDeclaration.js.map +1 -1
- package/Shaders/lod.fragment.js +1 -1
- package/Shaders/lod.fragment.js.map +1 -1
- package/Shaders/spriteMap.fragment.js +12 -13
- package/Shaders/spriteMap.fragment.js.map +1 -1
- package/package.json +1 -1
package/Meshes/csg2.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Mesh } from "./mesh";
|
|
2
2
|
import type { IDisposable, Scene } from "../scene.js";
|
|
3
3
|
import { VertexData } from "./mesh.vertexData";
|
|
4
|
+
import type { Material } from "../Materials/material.js";
|
|
4
5
|
/**
|
|
5
6
|
* Interface to customize the Manifold library import
|
|
6
7
|
*/
|
|
@@ -30,6 +31,10 @@ export interface IMeshRebuildOptions {
|
|
|
30
31
|
* True to center the mesh on 0,0,0
|
|
31
32
|
*/
|
|
32
33
|
centerMesh?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Defines a material to use for that mesh. When not defined the system will either reuse the one from the source or create a multimaterial if several materials were involved
|
|
36
|
+
*/
|
|
37
|
+
materialToUse?: Material;
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
35
40
|
* Interface to customize the vertex data rebuild options
|
package/Meshes/csg2.js
CHANGED
|
@@ -43,7 +43,7 @@ export class CSG2 {
|
|
|
43
43
|
}
|
|
44
44
|
_process(operation, csg) {
|
|
45
45
|
if (this.numProp !== csg.numProp) {
|
|
46
|
-
throw new Error("CSG must
|
|
46
|
+
throw new Error("CSG must be used with geometries having the same number of properties");
|
|
47
47
|
}
|
|
48
48
|
return new CSG2(Manifold[operation](this._manifold, csg._manifold), this.numProp, this._vertexStructure);
|
|
49
49
|
}
|
|
@@ -159,13 +159,18 @@ export class CSG2 {
|
|
|
159
159
|
materialIndex++;
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
if (
|
|
163
|
-
|
|
164
|
-
multiMaterial.subMaterials = materials;
|
|
165
|
-
output.material = multiMaterial;
|
|
162
|
+
if (localOptions.materialToUse) {
|
|
163
|
+
output.material = localOptions.materialToUse;
|
|
166
164
|
}
|
|
167
165
|
else {
|
|
168
|
-
|
|
166
|
+
if (materials.length > 1) {
|
|
167
|
+
const multiMaterial = new MultiMaterial(name, scene);
|
|
168
|
+
multiMaterial.subMaterials = materials;
|
|
169
|
+
output.material = multiMaterial;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
output.material = materials[0];
|
|
173
|
+
}
|
|
169
174
|
}
|
|
170
175
|
return output;
|
|
171
176
|
}
|
|
@@ -192,12 +197,17 @@ export class CSG2 {
|
|
|
192
197
|
}
|
|
193
198
|
const manifoldMesh = new ManifoldMesh({ numProp: numProp, vertProperties, triVerts, runIndex, runOriginalID });
|
|
194
199
|
manifoldMesh.merge();
|
|
200
|
+
let returnValue;
|
|
195
201
|
try {
|
|
196
|
-
|
|
202
|
+
returnValue = new CSG2(new Manifold(manifoldMesh), numProp, structure);
|
|
197
203
|
}
|
|
198
204
|
catch (e) {
|
|
199
205
|
throw new Error("Error while creating the CSG: " + e.message);
|
|
200
206
|
}
|
|
207
|
+
if (returnValue._manifold.genus() < 0) {
|
|
208
|
+
throw new Error("Incorrect volume detected. Make sure you are not using a double sided geometry");
|
|
209
|
+
}
|
|
210
|
+
return returnValue;
|
|
201
211
|
}
|
|
202
212
|
static _Construct(data, worldMatrix, runIndex, runOriginalID) {
|
|
203
213
|
// Create the MeshGL for I/O with Manifold library.
|
package/Meshes/csg2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csg2.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/csg2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAG9B,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,0BAAyB;AAC1C,OAAO,EAAE,aAAa,EAAE,sCAAqC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,sBAAsB,EAAE,mCAAkC;AAGnE,OAAO,EAAE,OAAO,EAAE,gCAA+B;AAEjD;;GAEG;AACH,gEAAg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CAAC;IAEF,IAAI,YAAY,CAAC,gBAAgB,EAAE;QAC/B,QAAQ,GAAG,YAAY,CAAC,gBAAgB,CAAC;QACzC,YAAY,GAAG,YAAY,CAAC,oBAAoB,CAAC;KACpD;SAAM;QACH,MAAM,MAAM,GAAG,MAAM,sBAAsB,CACvC;kCACsB,YAAY,CAAC,WAAW;;;;;SAKjD,CACA,CAAC;QAEF,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC3B,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC;KAC9B;IAED,0FAA0F;IAC1F,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import { Mesh } from \"./mesh\";\r\nimport type { IDisposable, Scene } from \"core/scene\";\r\nimport type { IVertexDataLike } from \"./mesh.vertexData\";\r\nimport { VertexData } from \"./mesh.vertexData\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { MultiMaterial } from \"core/Materials/multiMaterial\";\r\nimport { SubMesh } from \"./subMesh\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { _LoadScriptModuleAsync } from \"core/Misc/tools.internals\";\r\nimport type { FloatArray, Nullable } from \"core/types\";\r\nimport type { Matrix } from \"core/Maths/math.vector\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\n\r\n/**\r\n * Main manifold library\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nlet Manifold: any;\r\n\r\n/**\r\n * Manifold mesh\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nlet ManifoldMesh: any;\r\n\r\n/**\r\n * First ID to use for materials indexing\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nlet FirstID: number;\r\n\r\n/**\r\n * Interface to customize the Manifold library import\r\n */\r\nexport interface ICSG2Options {\r\n /**\r\n * Custom manifold URL\r\n */\r\n manifoldUrl?: string;\r\n /**\r\n * Custom manifold instance\r\n */\r\n manifoldInstance: any;\r\n /**\r\n * Custom manifold mesh instance\r\n */\r\n manifoldMeshInstance: any;\r\n}\r\n\r\n/**\r\n * Interface to customize the mesh rebuild options\r\n */\r\nexport interface IMeshRebuildOptions {\r\n /**\r\n * Rebuild normals\r\n */\r\n rebuildNormals?: boolean;\r\n /**\r\n * True to center the mesh on 0,0,0\r\n */\r\n centerMesh?: boolean;\r\n}\r\n\r\n/**\r\n * Interface to customize the vertex data rebuild options\r\n */\r\nexport interface IVertexDataRebuildOptions {\r\n /**\r\n * Rebuild normals\r\n */\r\n rebuildNormals?: boolean;\r\n}\r\n\r\ninterface IManifoldMesh {\r\n numProp: number;\r\n vertProperties: Float32Array;\r\n triVerts: Uint32Array;\r\n runIndex: Uint32Array;\r\n runOriginalID: Uint32Array;\r\n numRun: number;\r\n}\r\n\r\ninterface IManifoldVertexComponent {\r\n stride: number;\r\n kind: string;\r\n data?: FloatArray;\r\n}\r\n\r\n/**\r\n * Wrapper around the Manifold library\r\n * https://manifoldcad.org/\r\n * Use this class to perform fast boolean operations on meshes\r\n * #IW43EB#15 - basic operations\r\n * #JUKXQD#6104 - skull vs box\r\n * #JUKXQD#6111 - skull vs vertex data\r\n */\r\nexport class CSG2 implements IDisposable {\r\n private _manifold: any;\r\n private _numProp: number;\r\n private _vertexStructure: IManifoldVertexComponent[];\r\n\r\n /**\r\n * Return the size of a vertex (at least 3 for the position)\r\n */\r\n public get numProp() {\r\n return this._numProp;\r\n }\r\n\r\n private constructor(manifold: any, numProp: number, vertexStructure: IManifoldVertexComponent[]) {\r\n this._manifold = manifold;\r\n this._numProp = numProp;\r\n this._vertexStructure = vertexStructure;\r\n }\r\n\r\n private _process(operation: \"difference\" | \"intersection\" | \"union\", csg: CSG2) {\r\n if (this.numProp !== csg.numProp) {\r\n throw new Error(\"CSG must have the same number of properties\");\r\n }\r\n return new CSG2(Manifold[operation](this._manifold, csg._manifold), this.numProp, this._vertexStructure);\r\n }\r\n\r\n /**\r\n * Run a difference operation between two CSG\r\n * @param csg defines the CSG to use to create the difference\r\n * @returns a new csg\r\n */\r\n public subtract(csg: CSG2) {\r\n return this._process(\"difference\", csg);\r\n }\r\n\r\n /**\r\n * Run an intersection operation between two CSG\r\n * @param csg defines the CSG to use to create the intersection\r\n * @returns a new csg\r\n */\r\n public intersect(csg: CSG2) {\r\n return this._process(\"intersection\", csg);\r\n }\r\n\r\n /**\r\n * Run an union operation between two CSG\r\n * @param csg defines the CSG to use to create the union\r\n * @returns a new csg\r\n */\r\n public add(csg: CSG2) {\r\n return this._process(\"union\", csg);\r\n }\r\n\r\n /**\r\n * Print debug information about the CSG\r\n */\r\n public printDebug() {\r\n Logger.Log(\"Genus:\" + this._manifold.genus());\r\n const properties = this._manifold.getProperties();\r\n Logger.Log(\"Volume:\" + properties.volume);\r\n Logger.Log(\"surface area:\" + properties.surfaceArea);\r\n }\r\n\r\n /**\r\n * Generate a vertex data from the CSG\r\n * @param options defines the options to use to rebuild the vertex data\r\n * @returns a new vertex data\r\n */\r\n public toVertexData(options?: Partial<IVertexDataRebuildOptions>): VertexData {\r\n const localOptions = {\r\n rebuildNormals: false,\r\n ...options,\r\n };\r\n const vertexData = new VertexData();\r\n const normalComponent = this._vertexStructure.find((c) => c.kind === VertexBuffer.NormalKind);\r\n const manifoldMesh: IManifoldMesh = this._manifold.getMesh(localOptions.rebuildNormals && normalComponent ? [3, 4, 5] : undefined);\r\n\r\n vertexData.indices = manifoldMesh.triVerts.length > 65535 ? new Uint32Array(manifoldMesh.triVerts) : new Uint16Array(manifoldMesh.triVerts);\r\n\r\n for (let i = 0; i < manifoldMesh.triVerts.length; i += 3) {\r\n vertexData.indices[i] = manifoldMesh.triVerts[i + 2];\r\n vertexData.indices[i + 1] = manifoldMesh.triVerts[i + 1];\r\n vertexData.indices[i + 2] = manifoldMesh.triVerts[i];\r\n }\r\n\r\n const vertexCount = manifoldMesh.vertProperties.length / manifoldMesh.numProp;\r\n\r\n // Attributes\r\n let offset = 0;\r\n for (let componentIndex = 0; componentIndex < this._vertexStructure.length; componentIndex++) {\r\n const component = this._vertexStructure[componentIndex];\r\n\r\n const data = new Float32Array(vertexCount * component.stride);\r\n for (let i = 0; i < vertexCount; i++) {\r\n for (let strideIndex = 0; strideIndex < component.stride; strideIndex++) {\r\n data[i * component.stride + strideIndex] = manifoldMesh.vertProperties[i * manifoldMesh.numProp + offset + strideIndex];\r\n }\r\n }\r\n vertexData.set(data, component.kind);\r\n offset += component.stride;\r\n }\r\n\r\n // Rebuild mesh from vertex data\r\n return vertexData;\r\n }\r\n\r\n /**\r\n * Generate a mesh from the CSG\r\n * @param name defines the name of the mesh\r\n * @param scene defines the scene to use to create the mesh\r\n * @param options defines the options to use to rebuild the mesh\r\n * @returns a new Mesh\r\n */\r\n public toMesh(name: string, scene?: Scene, options?: Partial<IMeshRebuildOptions>): Mesh {\r\n const localOptions = {\r\n rebuildNormals: false,\r\n centerMesh: true,\r\n ...options,\r\n };\r\n const vertexData = this.toVertexData({ rebuildNormals: localOptions.rebuildNormals });\r\n const normalComponent = this._vertexStructure.find((c) => c.kind === VertexBuffer.NormalKind);\r\n const manifoldMesh: IManifoldMesh = this._manifold.getMesh(localOptions.rebuildNormals && normalComponent ? [3, 4, 5] : undefined);\r\n const vertexCount = manifoldMesh.vertProperties.length / manifoldMesh.numProp;\r\n\r\n // Rebuild mesh from vertex data\r\n const output = new Mesh(name, scene);\r\n vertexData.applyToMesh(output);\r\n\r\n // Center mesh\r\n if (localOptions.centerMesh) {\r\n const extents = output.getBoundingInfo().boundingSphere.center;\r\n output.position.set(-extents.x, -extents.y, -extents.z);\r\n output.bakeCurrentTransformIntoVertices();\r\n }\r\n\r\n // Submeshes\r\n let id = manifoldMesh.runOriginalID[0];\r\n let start = manifoldMesh.runIndex[0];\r\n let materialIndex = 0;\r\n const materials: Material[] = [];\r\n scene = output.getScene();\r\n for (let run = 0; run < manifoldMesh.numRun; ++run) {\r\n const nextID = manifoldMesh.runOriginalID[run + 1];\r\n if (nextID !== id) {\r\n const end = manifoldMesh.runIndex[run + 1];\r\n new SubMesh(materialIndex, 0, vertexCount, start, end - start, output);\r\n materials.push(scene.getMaterialByUniqueID(id - FirstID) || scene.defaultMaterial);\r\n id = nextID;\r\n start = end;\r\n materialIndex++;\r\n }\r\n }\r\n\r\n if (materials.length > 1) {\r\n const multiMaterial = new MultiMaterial(name, scene);\r\n multiMaterial.subMaterials = materials;\r\n output.material = multiMaterial;\r\n } else {\r\n output.material = materials[0];\r\n }\r\n\r\n return output;\r\n }\r\n\r\n /**\r\n * Dispose the CSG resources\r\n */\r\n public dispose() {\r\n if (this._manifold) {\r\n this._manifold.delete();\r\n this._manifold = null;\r\n }\r\n }\r\n\r\n private static _ProcessData(\r\n vertexCount: number,\r\n triVerts: Uint32Array,\r\n structure: IManifoldVertexComponent[],\r\n numProp: number,\r\n runIndex?: Uint32Array,\r\n runOriginalID?: Uint32Array\r\n ) {\r\n const vertProperties = new Float32Array(vertexCount * structure.reduce((acc, cur) => acc + cur.stride, 0));\r\n\r\n for (let i = 0; i < vertexCount; i++) {\r\n let offset = 0;\r\n for (let idx = 0; idx < structure.length; idx++) {\r\n const component = structure[idx];\r\n\r\n for (let strideIndex = 0; strideIndex < component.stride; strideIndex++) {\r\n vertProperties[i * numProp + offset + strideIndex] = component.data![i * component.stride + strideIndex];\r\n }\r\n offset += component.stride;\r\n }\r\n }\r\n\r\n const manifoldMesh = new ManifoldMesh({ numProp: numProp, vertProperties, triVerts, runIndex, runOriginalID });\r\n manifoldMesh.merge();\r\n\r\n try {\r\n return new CSG2(new Manifold(manifoldMesh), numProp, structure);\r\n } catch (e) {\r\n throw new Error(\"Error while creating the CSG: \" + e.message);\r\n }\r\n }\r\n\r\n private static _Construct(data: IVertexDataLike, worldMatrix: Nullable<Matrix>, runIndex?: Uint32Array, runOriginalID?: Uint32Array) {\r\n // Create the MeshGL for I/O with Manifold library.\r\n const triVerts = new Uint32Array(data.indices!.length);\r\n\r\n // Revert order\r\n for (let i = 0; i < data.indices!.length; i += 3) {\r\n triVerts[i] = data.indices![i + 2];\r\n triVerts[i + 1] = data.indices![i + 1];\r\n triVerts[i + 2] = data.indices![i];\r\n }\r\n\r\n const tempVector3 = new Vector3();\r\n let numProp = 3;\r\n const structure: IManifoldVertexComponent[] = [{ stride: 3, kind: VertexBuffer.PositionKind }];\r\n\r\n if (!worldMatrix) {\r\n structure[0].data = data.positions!;\r\n } else {\r\n const positions = new Float32Array(data.positions!.length);\r\n for (let i = 0; i < data.positions!.length; i += 3) {\r\n Vector3.TransformCoordinatesFromFloatsToRef(data.positions![i], data.positions![i + 1], data.positions![i + 2], worldMatrix, tempVector3);\r\n tempVector3.toArray(positions, i);\r\n }\r\n structure[0].data = positions;\r\n }\r\n\r\n // Normals\r\n const sourceNormals = data.normals!;\r\n if (sourceNormals) {\r\n numProp += 3;\r\n structure.push({ stride: 3, kind: VertexBuffer.NormalKind });\r\n if (!worldMatrix) {\r\n structure[1].data = sourceNormals;\r\n } else {\r\n const normals = new Float32Array(sourceNormals.length);\r\n for (let i = 0; i < sourceNormals.length; i += 3) {\r\n Vector3.TransformNormalFromFloatsToRef(sourceNormals[i], sourceNormals[i + 1], sourceNormals[i + 2], worldMatrix, tempVector3);\r\n tempVector3.toArray(normals, i);\r\n }\r\n structure[1].data = normals;\r\n }\r\n }\r\n\r\n // UVs\r\n for (const kind of [VertexBuffer.UVKind, VertexBuffer.UV2Kind, VertexBuffer.UV3Kind, VertexBuffer.UV4Kind, VertexBuffer.UV5Kind, VertexBuffer.UV6Kind]) {\r\n const sourceUV = (data as any)[kind === VertexBuffer.UVKind ? \"uvs\" : kind];\r\n if (sourceUV) {\r\n numProp += 2;\r\n structure.push({ stride: 2, kind: kind, data: sourceUV });\r\n }\r\n }\r\n\r\n // Colors\r\n const sourceColors = data.colors;\r\n if (sourceColors) {\r\n numProp += 4;\r\n structure.push({ stride: 4, kind: VertexBuffer.ColorKind, data: sourceColors });\r\n }\r\n\r\n return this._ProcessData(data.positions!.length / 3, triVerts, structure, numProp, runIndex, runOriginalID);\r\n }\r\n\r\n /**\r\n * Create a new Constructive Solid Geometry from a vertexData\r\n * @param vertexData defines the vertexData to use to create the CSG\r\n * @returns a new CSG2 class\r\n */\r\n public static FromVertexData(vertexData: VertexData): CSG2 {\r\n const sourceVertices = vertexData.positions;\r\n const sourceIndices = vertexData.indices;\r\n\r\n if (!sourceVertices || !sourceIndices) {\r\n throw new Error(\"The vertexData must at least have positions and indices\");\r\n }\r\n\r\n return this._Construct(vertexData, null);\r\n }\r\n\r\n /**\r\n * Create a new Constructive Solid Geometry from a mesh\r\n * @param mesh defines the mesh to use to create the CSG\r\n * @param ignoreWorldMatrix defines if the world matrix should be ignored\r\n * @returns a new CSG2 class\r\n */\r\n public static FromMesh(mesh: Mesh, ignoreWorldMatrix = false): any {\r\n const sourceVertices = mesh.getVerticesData(VertexBuffer.PositionKind);\r\n const sourceIndices = mesh.getIndices();\r\n const worldMatrix = mesh.computeWorldMatrix(true);\r\n\r\n if (!sourceVertices || !sourceIndices) {\r\n throw new Error(\"The mesh must at least have positions and indices\");\r\n }\r\n\r\n // Create a triangle run for each submesh (material)\r\n const starts = [...Array(mesh.subMeshes.length)].map((_, idx) => mesh.subMeshes[idx].indexStart);\r\n\r\n // Map the materials to ID.\r\n const sourceMaterial = mesh.material || mesh.getScene().defaultMaterial;\r\n const isMultiMaterial = sourceMaterial.getClassName() === \"MultiMaterial\";\r\n const originalIDs = [...Array(mesh.subMeshes.length)].map((_, idx) => {\r\n if (isMultiMaterial) {\r\n return FirstID + (sourceMaterial as MultiMaterial).subMaterials[mesh.subMeshes[idx].materialIndex]!.uniqueId;\r\n }\r\n\r\n return FirstID + sourceMaterial.uniqueId;\r\n });\r\n\r\n // List the runs in sequence.\r\n const indices = Array.from(starts.keys());\r\n indices.sort((a, b) => starts[a] - starts[b]);\r\n const runIndex = new Uint32Array(indices.map((i) => starts[i]));\r\n const runOriginalID = new Uint32Array(indices.map((i) => originalIDs[i]));\r\n\r\n // Process\r\n const data = {\r\n positions: sourceVertices,\r\n indices: sourceIndices,\r\n normals: mesh.getVerticesData(VertexBuffer.NormalKind),\r\n colors: mesh.getVerticesData(VertexBuffer.ColorKind),\r\n uvs: mesh.getVerticesData(VertexBuffer.UVKind),\r\n uvs2: mesh.getVerticesData(VertexBuffer.UV2Kind),\r\n uvs3: mesh.getVerticesData(VertexBuffer.UV3Kind),\r\n uvs4: mesh.getVerticesData(VertexBuffer.UV4Kind),\r\n uvs5: mesh.getVerticesData(VertexBuffer.UV5Kind),\r\n uvs6: mesh.getVerticesData(VertexBuffer.UV6Kind),\r\n };\r\n return this._Construct(data, ignoreWorldMatrix ? null : worldMatrix, runIndex, runOriginalID);\r\n }\r\n}\r\n\r\n/**\r\n * Checks if the Manifold library is ready\r\n * @returns true if the Manifold library is ready\r\n */\r\nexport function IsCSG2Ready() {\r\n return Manifold !== undefined;\r\n}\r\n\r\n/**\r\n * Initialize the Manifold library\r\n * @param options defines the options to use to initialize the library\r\n */\r\nexport async function InitializeCSG2Async(options?: Partial<ICSG2Options>) {\r\n const localOptions = {\r\n manifoldUrl: \"https://unpkg.com/manifold-3d@2.5.1\",\r\n ...options,\r\n };\r\n\r\n if (localOptions.manifoldInstance) {\r\n Manifold = localOptions.manifoldInstance;\r\n ManifoldMesh = localOptions.manifoldMeshInstance;\r\n } else {\r\n const result = await _LoadScriptModuleAsync(\r\n `\r\n import Module from '${localOptions.manifoldUrl}/manifold.js';\r\n const wasm = await Module();\r\n wasm.setup();\r\n const {Manifold, Mesh} = wasm;\r\n const returnedValue = {Manifold, Mesh};\r\n `\r\n );\r\n\r\n Manifold = result.Manifold;\r\n ManifoldMesh = result.Mesh;\r\n }\r\n\r\n // Reserve IDs for materials (we consider that there will be no more than 65536 materials)\r\n FirstID = Manifold.reserveIDs(65536);\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"csg2.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/csg2.ts"],"names":[],"mappings":"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YAAY,CAAC,OAAO,CAAC;YAChD,IAAI,EAAE,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC;YAChD,IAAI,EAAE,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC;YAChD,IAAI,EAAE,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC;YAChD,IAAI,EAAE,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC;SACnD,CAAC;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;IAClG,CAAC;CACJ;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW;IACvB,OAAO,QAAQ,KAAK,SAAS,CAAC;AAClC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAA+B;IACrE,MAAM,YAAY,GAAG;QACjB,WAAW,EAAE,qCAAqC;QAClD,GAAG,OAAO;KACb,CAAC;IAEF,IAAI,YAAY,CAAC,gBAAgB,EAAE;QAC/B,QAAQ,GAAG,YAAY,CAAC,gBAAgB,CAAC;QACzC,YAAY,GAAG,YAAY,CAAC,oBAAoB,CAAC;KACpD;SAAM;QACH,MAAM,MAAM,GAAG,MAAM,sBAAsB,CACvC;kCACsB,YAAY,CAAC,WAAW;;;;;SAKjD,CACA,CAAC;QAEF,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC3B,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC;KAC9B;IAED,0FAA0F;IAC1F,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import { Mesh } from \"./mesh\";\r\nimport type { IDisposable, Scene } from \"core/scene\";\r\nimport type { IVertexDataLike } from \"./mesh.vertexData\";\r\nimport { VertexData } from \"./mesh.vertexData\";\r\nimport { VertexBuffer } from \"../Buffers/buffer\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { MultiMaterial } from \"core/Materials/multiMaterial\";\r\nimport { SubMesh } from \"./subMesh\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { _LoadScriptModuleAsync } from \"core/Misc/tools.internals\";\r\nimport type { FloatArray, Nullable } from \"core/types\";\r\nimport type { Matrix } from \"core/Maths/math.vector\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\n\r\n/**\r\n * Main manifold library\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nlet Manifold: any;\r\n\r\n/**\r\n * Manifold mesh\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nlet ManifoldMesh: any;\r\n\r\n/**\r\n * First ID to use for materials indexing\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nlet FirstID: number;\r\n\r\n/**\r\n * Interface to customize the Manifold library import\r\n */\r\nexport interface ICSG2Options {\r\n /**\r\n * Custom manifold URL\r\n */\r\n manifoldUrl?: string;\r\n /**\r\n * Custom manifold instance\r\n */\r\n manifoldInstance: any;\r\n /**\r\n * Custom manifold mesh instance\r\n */\r\n manifoldMeshInstance: any;\r\n}\r\n\r\n/**\r\n * Interface to customize the mesh rebuild options\r\n */\r\nexport interface IMeshRebuildOptions {\r\n /**\r\n * Rebuild normals\r\n */\r\n rebuildNormals?: boolean;\r\n /**\r\n * True to center the mesh on 0,0,0\r\n */\r\n centerMesh?: boolean;\r\n /**\r\n * Defines a material to use for that mesh. When not defined the system will either reuse the one from the source or create a multimaterial if several materials were involved\r\n */\r\n materialToUse?: Material;\r\n}\r\n\r\n/**\r\n * Interface to customize the vertex data rebuild options\r\n */\r\nexport interface IVertexDataRebuildOptions {\r\n /**\r\n * Rebuild normals\r\n */\r\n rebuildNormals?: boolean;\r\n}\r\n\r\ninterface IManifoldMesh {\r\n numProp: number;\r\n vertProperties: Float32Array;\r\n triVerts: Uint32Array;\r\n runIndex: Uint32Array;\r\n runOriginalID: Uint32Array;\r\n numRun: number;\r\n}\r\n\r\ninterface IManifoldVertexComponent {\r\n stride: number;\r\n kind: string;\r\n data?: FloatArray;\r\n}\r\n\r\n/**\r\n * Wrapper around the Manifold library\r\n * https://manifoldcad.org/\r\n * Use this class to perform fast boolean operations on meshes\r\n * #IW43EB#15 - basic operations\r\n * #JUKXQD#6104 - skull vs box\r\n * #JUKXQD#6111 - skull vs vertex data\r\n */\r\nexport class CSG2 implements IDisposable {\r\n private _manifold: any;\r\n private _numProp: number;\r\n private _vertexStructure: IManifoldVertexComponent[];\r\n\r\n /**\r\n * Return the size of a vertex (at least 3 for the position)\r\n */\r\n public get numProp() {\r\n return this._numProp;\r\n }\r\n\r\n private constructor(manifold: any, numProp: number, vertexStructure: IManifoldVertexComponent[]) {\r\n this._manifold = manifold;\r\n this._numProp = numProp;\r\n this._vertexStructure = vertexStructure;\r\n }\r\n\r\n private _process(operation: \"difference\" | \"intersection\" | \"union\", csg: CSG2) {\r\n if (this.numProp !== csg.numProp) {\r\n throw new Error(\"CSG must be used with geometries having the same number of properties\");\r\n }\r\n return new CSG2(Manifold[operation](this._manifold, csg._manifold), this.numProp, this._vertexStructure);\r\n }\r\n\r\n /**\r\n * Run a difference operation between two CSG\r\n * @param csg defines the CSG to use to create the difference\r\n * @returns a new csg\r\n */\r\n public subtract(csg: CSG2) {\r\n return this._process(\"difference\", csg);\r\n }\r\n\r\n /**\r\n * Run an intersection operation between two CSG\r\n * @param csg defines the CSG to use to create the intersection\r\n * @returns a new csg\r\n */\r\n public intersect(csg: CSG2) {\r\n return this._process(\"intersection\", csg);\r\n }\r\n\r\n /**\r\n * Run an union operation between two CSG\r\n * @param csg defines the CSG to use to create the union\r\n * @returns a new csg\r\n */\r\n public add(csg: CSG2) {\r\n return this._process(\"union\", csg);\r\n }\r\n\r\n /**\r\n * Print debug information about the CSG\r\n */\r\n public printDebug() {\r\n Logger.Log(\"Genus:\" + this._manifold.genus());\r\n const properties = this._manifold.getProperties();\r\n Logger.Log(\"Volume:\" + properties.volume);\r\n Logger.Log(\"surface area:\" + properties.surfaceArea);\r\n }\r\n\r\n /**\r\n * Generate a vertex data from the CSG\r\n * @param options defines the options to use to rebuild the vertex data\r\n * @returns a new vertex data\r\n */\r\n public toVertexData(options?: Partial<IVertexDataRebuildOptions>): VertexData {\r\n const localOptions = {\r\n rebuildNormals: false,\r\n ...options,\r\n };\r\n const vertexData = new VertexData();\r\n const normalComponent = this._vertexStructure.find((c) => c.kind === VertexBuffer.NormalKind);\r\n const manifoldMesh: IManifoldMesh = this._manifold.getMesh(localOptions.rebuildNormals && normalComponent ? [3, 4, 5] : undefined);\r\n\r\n vertexData.indices = manifoldMesh.triVerts.length > 65535 ? new Uint32Array(manifoldMesh.triVerts) : new Uint16Array(manifoldMesh.triVerts);\r\n\r\n for (let i = 0; i < manifoldMesh.triVerts.length; i += 3) {\r\n vertexData.indices[i] = manifoldMesh.triVerts[i + 2];\r\n vertexData.indices[i + 1] = manifoldMesh.triVerts[i + 1];\r\n vertexData.indices[i + 2] = manifoldMesh.triVerts[i];\r\n }\r\n\r\n const vertexCount = manifoldMesh.vertProperties.length / manifoldMesh.numProp;\r\n\r\n // Attributes\r\n let offset = 0;\r\n for (let componentIndex = 0; componentIndex < this._vertexStructure.length; componentIndex++) {\r\n const component = this._vertexStructure[componentIndex];\r\n\r\n const data = new Float32Array(vertexCount * component.stride);\r\n for (let i = 0; i < vertexCount; i++) {\r\n for (let strideIndex = 0; strideIndex < component.stride; strideIndex++) {\r\n data[i * component.stride + strideIndex] = manifoldMesh.vertProperties[i * manifoldMesh.numProp + offset + strideIndex];\r\n }\r\n }\r\n vertexData.set(data, component.kind);\r\n offset += component.stride;\r\n }\r\n\r\n // Rebuild mesh from vertex data\r\n return vertexData;\r\n }\r\n\r\n /**\r\n * Generate a mesh from the CSG\r\n * @param name defines the name of the mesh\r\n * @param scene defines the scene to use to create the mesh\r\n * @param options defines the options to use to rebuild the mesh\r\n * @returns a new Mesh\r\n */\r\n public toMesh(name: string, scene?: Scene, options?: Partial<IMeshRebuildOptions>): Mesh {\r\n const localOptions = {\r\n rebuildNormals: false,\r\n centerMesh: true,\r\n ...options,\r\n };\r\n const vertexData = this.toVertexData({ rebuildNormals: localOptions.rebuildNormals });\r\n const normalComponent = this._vertexStructure.find((c) => c.kind === VertexBuffer.NormalKind);\r\n const manifoldMesh: IManifoldMesh = this._manifold.getMesh(localOptions.rebuildNormals && normalComponent ? [3, 4, 5] : undefined);\r\n const vertexCount = manifoldMesh.vertProperties.length / manifoldMesh.numProp;\r\n\r\n // Rebuild mesh from vertex data\r\n const output = new Mesh(name, scene);\r\n vertexData.applyToMesh(output);\r\n\r\n // Center mesh\r\n if (localOptions.centerMesh) {\r\n const extents = output.getBoundingInfo().boundingSphere.center;\r\n output.position.set(-extents.x, -extents.y, -extents.z);\r\n output.bakeCurrentTransformIntoVertices();\r\n }\r\n\r\n // Submeshes\r\n let id = manifoldMesh.runOriginalID[0];\r\n let start = manifoldMesh.runIndex[0];\r\n let materialIndex = 0;\r\n const materials: Material[] = [];\r\n scene = output.getScene();\r\n for (let run = 0; run < manifoldMesh.numRun; ++run) {\r\n const nextID = manifoldMesh.runOriginalID[run + 1];\r\n if (nextID !== id) {\r\n const end = manifoldMesh.runIndex[run + 1];\r\n new SubMesh(materialIndex, 0, vertexCount, start, end - start, output);\r\n materials.push(scene.getMaterialByUniqueID(id - FirstID) || scene.defaultMaterial);\r\n id = nextID;\r\n start = end;\r\n materialIndex++;\r\n }\r\n }\r\n\r\n if (localOptions.materialToUse) {\r\n output.material = localOptions.materialToUse;\r\n } else {\r\n if (materials.length > 1) {\r\n const multiMaterial = new MultiMaterial(name, scene);\r\n multiMaterial.subMaterials = materials;\r\n output.material = multiMaterial;\r\n } else {\r\n output.material = materials[0];\r\n }\r\n }\r\n\r\n return output;\r\n }\r\n\r\n /**\r\n * Dispose the CSG resources\r\n */\r\n public dispose() {\r\n if (this._manifold) {\r\n this._manifold.delete();\r\n this._manifold = null;\r\n }\r\n }\r\n\r\n private static _ProcessData(\r\n vertexCount: number,\r\n triVerts: Uint32Array,\r\n structure: IManifoldVertexComponent[],\r\n numProp: number,\r\n runIndex?: Uint32Array,\r\n runOriginalID?: Uint32Array\r\n ) {\r\n const vertProperties = new Float32Array(vertexCount * structure.reduce((acc, cur) => acc + cur.stride, 0));\r\n\r\n for (let i = 0; i < vertexCount; i++) {\r\n let offset = 0;\r\n for (let idx = 0; idx < structure.length; idx++) {\r\n const component = structure[idx];\r\n\r\n for (let strideIndex = 0; strideIndex < component.stride; strideIndex++) {\r\n vertProperties[i * numProp + offset + strideIndex] = component.data![i * component.stride + strideIndex];\r\n }\r\n offset += component.stride;\r\n }\r\n }\r\n\r\n const manifoldMesh = new ManifoldMesh({ numProp: numProp, vertProperties, triVerts, runIndex, runOriginalID });\r\n manifoldMesh.merge();\r\n\r\n let returnValue: CSG2;\r\n try {\r\n returnValue = new CSG2(new Manifold(manifoldMesh), numProp, structure);\r\n } catch (e) {\r\n throw new Error(\"Error while creating the CSG: \" + e.message);\r\n }\r\n\r\n if (returnValue._manifold.genus() < 0) {\r\n throw new Error(\"Incorrect volume detected. Make sure you are not using a double sided geometry\");\r\n }\r\n\r\n return returnValue;\r\n }\r\n\r\n private static _Construct(data: IVertexDataLike, worldMatrix: Nullable<Matrix>, runIndex?: Uint32Array, runOriginalID?: Uint32Array) {\r\n // Create the MeshGL for I/O with Manifold library.\r\n const triVerts = new Uint32Array(data.indices!.length);\r\n\r\n // Revert order\r\n for (let i = 0; i < data.indices!.length; i += 3) {\r\n triVerts[i] = data.indices![i + 2];\r\n triVerts[i + 1] = data.indices![i + 1];\r\n triVerts[i + 2] = data.indices![i];\r\n }\r\n\r\n const tempVector3 = new Vector3();\r\n let numProp = 3;\r\n const structure: IManifoldVertexComponent[] = [{ stride: 3, kind: VertexBuffer.PositionKind }];\r\n\r\n if (!worldMatrix) {\r\n structure[0].data = data.positions!;\r\n } else {\r\n const positions = new Float32Array(data.positions!.length);\r\n for (let i = 0; i < data.positions!.length; i += 3) {\r\n Vector3.TransformCoordinatesFromFloatsToRef(data.positions![i], data.positions![i + 1], data.positions![i + 2], worldMatrix, tempVector3);\r\n tempVector3.toArray(positions, i);\r\n }\r\n structure[0].data = positions;\r\n }\r\n\r\n // Normals\r\n const sourceNormals = data.normals!;\r\n if (sourceNormals) {\r\n numProp += 3;\r\n structure.push({ stride: 3, kind: VertexBuffer.NormalKind });\r\n if (!worldMatrix) {\r\n structure[1].data = sourceNormals;\r\n } else {\r\n const normals = new Float32Array(sourceNormals.length);\r\n for (let i = 0; i < sourceNormals.length; i += 3) {\r\n Vector3.TransformNormalFromFloatsToRef(sourceNormals[i], sourceNormals[i + 1], sourceNormals[i + 2], worldMatrix, tempVector3);\r\n tempVector3.toArray(normals, i);\r\n }\r\n structure[1].data = normals;\r\n }\r\n }\r\n\r\n // UVs\r\n for (const kind of [VertexBuffer.UVKind, VertexBuffer.UV2Kind, VertexBuffer.UV3Kind, VertexBuffer.UV4Kind, VertexBuffer.UV5Kind, VertexBuffer.UV6Kind]) {\r\n const sourceUV = (data as any)[kind === VertexBuffer.UVKind ? \"uvs\" : kind];\r\n if (sourceUV) {\r\n numProp += 2;\r\n structure.push({ stride: 2, kind: kind, data: sourceUV });\r\n }\r\n }\r\n\r\n // Colors\r\n const sourceColors = data.colors;\r\n if (sourceColors) {\r\n numProp += 4;\r\n structure.push({ stride: 4, kind: VertexBuffer.ColorKind, data: sourceColors });\r\n }\r\n\r\n return this._ProcessData(data.positions!.length / 3, triVerts, structure, numProp, runIndex, runOriginalID);\r\n }\r\n\r\n /**\r\n * Create a new Constructive Solid Geometry from a vertexData\r\n * @param vertexData defines the vertexData to use to create the CSG\r\n * @returns a new CSG2 class\r\n */\r\n public static FromVertexData(vertexData: VertexData): CSG2 {\r\n const sourceVertices = vertexData.positions;\r\n const sourceIndices = vertexData.indices;\r\n\r\n if (!sourceVertices || !sourceIndices) {\r\n throw new Error(\"The vertexData must at least have positions and indices\");\r\n }\r\n\r\n return this._Construct(vertexData, null);\r\n }\r\n\r\n /**\r\n * Create a new Constructive Solid Geometry from a mesh\r\n * @param mesh defines the mesh to use to create the CSG\r\n * @param ignoreWorldMatrix defines if the world matrix should be ignored\r\n * @returns a new CSG2 class\r\n */\r\n public static FromMesh(mesh: Mesh, ignoreWorldMatrix = false): any {\r\n const sourceVertices = mesh.getVerticesData(VertexBuffer.PositionKind);\r\n const sourceIndices = mesh.getIndices();\r\n const worldMatrix = mesh.computeWorldMatrix(true);\r\n\r\n if (!sourceVertices || !sourceIndices) {\r\n throw new Error(\"The mesh must at least have positions and indices\");\r\n }\r\n\r\n // Create a triangle run for each submesh (material)\r\n const starts = [...Array(mesh.subMeshes.length)].map((_, idx) => mesh.subMeshes[idx].indexStart);\r\n\r\n // Map the materials to ID.\r\n const sourceMaterial = mesh.material || mesh.getScene().defaultMaterial;\r\n const isMultiMaterial = sourceMaterial.getClassName() === \"MultiMaterial\";\r\n const originalIDs = [...Array(mesh.subMeshes.length)].map((_, idx) => {\r\n if (isMultiMaterial) {\r\n return FirstID + (sourceMaterial as MultiMaterial).subMaterials[mesh.subMeshes[idx].materialIndex]!.uniqueId;\r\n }\r\n\r\n return FirstID + sourceMaterial.uniqueId;\r\n });\r\n\r\n // List the runs in sequence.\r\n const indices = Array.from(starts.keys());\r\n indices.sort((a, b) => starts[a] - starts[b]);\r\n const runIndex = new Uint32Array(indices.map((i) => starts[i]));\r\n const runOriginalID = new Uint32Array(indices.map((i) => originalIDs[i]));\r\n\r\n // Process\r\n const data = {\r\n positions: sourceVertices,\r\n indices: sourceIndices,\r\n normals: mesh.getVerticesData(VertexBuffer.NormalKind),\r\n colors: mesh.getVerticesData(VertexBuffer.ColorKind),\r\n uvs: mesh.getVerticesData(VertexBuffer.UVKind),\r\n uvs2: mesh.getVerticesData(VertexBuffer.UV2Kind),\r\n uvs3: mesh.getVerticesData(VertexBuffer.UV3Kind),\r\n uvs4: mesh.getVerticesData(VertexBuffer.UV4Kind),\r\n uvs5: mesh.getVerticesData(VertexBuffer.UV5Kind),\r\n uvs6: mesh.getVerticesData(VertexBuffer.UV6Kind),\r\n };\r\n return this._Construct(data, ignoreWorldMatrix ? null : worldMatrix, runIndex, runOriginalID);\r\n }\r\n}\r\n\r\n/**\r\n * Checks if the Manifold library is ready\r\n * @returns true if the Manifold library is ready\r\n */\r\nexport function IsCSG2Ready() {\r\n return Manifold !== undefined;\r\n}\r\n\r\n/**\r\n * Initialize the Manifold library\r\n * @param options defines the options to use to initialize the library\r\n */\r\nexport async function InitializeCSG2Async(options?: Partial<ICSG2Options>) {\r\n const localOptions = {\r\n manifoldUrl: \"https://unpkg.com/manifold-3d@2.5.1\",\r\n ...options,\r\n };\r\n\r\n if (localOptions.manifoldInstance) {\r\n Manifold = localOptions.manifoldInstance;\r\n ManifoldMesh = localOptions.manifoldMeshInstance;\r\n } else {\r\n const result = await _LoadScriptModuleAsync(\r\n `\r\n import Module from '${localOptions.manifoldUrl}/manifold.js';\r\n const wasm = await Module();\r\n wasm.setup();\r\n const {Manifold, Mesh} = wasm;\r\n const returnedValue = {Manifold, Mesh};\r\n `\r\n );\r\n\r\n Manifold = result.Manifold;\r\n ManifoldMesh = result.Mesh;\r\n }\r\n\r\n // Reserve IDs for materials (we consider that there will be no more than 65536 materials)\r\n FirstID = Manifold.reserveIDs(65536);\r\n}\r\n"]}
|
|
@@ -151,6 +151,11 @@ export declare class TransformNode extends Node {
|
|
|
151
151
|
*/
|
|
152
152
|
get rotationQuaternion(): Nullable<Quaternion>;
|
|
153
153
|
set rotationQuaternion(quaternion: Nullable<Quaternion>);
|
|
154
|
+
/**
|
|
155
|
+
* Allow user to specify custom mechanism for mark as dirty
|
|
156
|
+
*/
|
|
157
|
+
customMarkAsDirty: () => void;
|
|
158
|
+
private _markAsDirtyInternal;
|
|
154
159
|
/**
|
|
155
160
|
* The forward direction of that transform in world space.
|
|
156
161
|
*/
|
package/Meshes/transformNode.js
CHANGED
|
@@ -130,7 +130,7 @@ export class TransformNode extends Node {
|
|
|
130
130
|
}
|
|
131
131
|
set position(newPosition) {
|
|
132
132
|
this._position = newPosition;
|
|
133
|
-
this.
|
|
133
|
+
this._markAsDirtyInternal();
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* return true if a pivot has been set
|
|
@@ -155,7 +155,7 @@ export class TransformNode extends Node {
|
|
|
155
155
|
set rotation(newRotation) {
|
|
156
156
|
this._rotation = newRotation;
|
|
157
157
|
this._rotationQuaternion = null;
|
|
158
|
-
this.
|
|
158
|
+
this._markAsDirtyInternal();
|
|
159
159
|
}
|
|
160
160
|
/**
|
|
161
161
|
* Gets or sets the scaling property : a Vector3 defining the node scaling along each local axis X, Y, Z (default is (1.0, 1.0, 1.0)).
|
|
@@ -165,7 +165,7 @@ export class TransformNode extends Node {
|
|
|
165
165
|
}
|
|
166
166
|
set scaling(newScaling) {
|
|
167
167
|
this._scaling = newScaling;
|
|
168
|
-
this.
|
|
168
|
+
this._markAsDirtyInternal();
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
171
|
* Gets or sets the rotation Quaternion property : this a Quaternion object defining the node rotation by using a unit quaternion (undefined by default, but can be null).
|
|
@@ -180,7 +180,16 @@ export class TransformNode extends Node {
|
|
|
180
180
|
if (quaternion) {
|
|
181
181
|
this._rotation.setAll(0.0);
|
|
182
182
|
}
|
|
183
|
+
this._markAsDirtyInternal();
|
|
184
|
+
}
|
|
185
|
+
_markAsDirtyInternal() {
|
|
186
|
+
if (this._isDirty) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
183
189
|
this._isDirty = true;
|
|
190
|
+
if (this.customMarkAsDirty) {
|
|
191
|
+
this.customMarkAsDirty();
|
|
192
|
+
}
|
|
184
193
|
}
|
|
185
194
|
/**
|
|
186
195
|
* The forward direction of that transform in world space.
|