@babylonjs/core 7.30.0 → 7.30.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/webgpuCacheBindGroups.js +13 -2
- package/Engines/WebGPU/webgpuCacheBindGroups.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheSampler.js +2 -3
- package/Engines/WebGPU/webgpuCacheSampler.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Materials/Background/backgroundMaterial.js +1 -11
- package/Materials/Background/backgroundMaterial.js.map +1 -1
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.d.ts +8 -0
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js +43 -34
- package/Materials/GaussianSplatting/gaussianSplattingMaterial.js.map +1 -1
- package/Materials/Node/Blocks/GaussianSplatting/gaussianBlock.d.ts +32 -0
- package/Materials/Node/Blocks/GaussianSplatting/gaussianBlock.js +64 -0
- package/Materials/Node/Blocks/GaussianSplatting/gaussianBlock.js.map +1 -0
- package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.d.ts +48 -0
- package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.js +102 -0
- package/Materials/Node/Blocks/GaussianSplatting/gaussianSplattingBlock.js.map +1 -0
- package/Materials/Node/Blocks/GaussianSplatting/index.d.ts +3 -0
- package/Materials/Node/Blocks/GaussianSplatting/index.js +4 -0
- package/Materials/Node/Blocks/GaussianSplatting/index.js.map +1 -0
- package/Materials/Node/Blocks/GaussianSplatting/splatReaderBlock.d.ts +40 -0
- package/Materials/Node/Blocks/GaussianSplatting/splatReaderBlock.js +96 -0
- package/Materials/Node/Blocks/GaussianSplatting/splatReaderBlock.js.map +1 -0
- package/Materials/Node/Blocks/Input/inputBlock.js +6 -0
- package/Materials/Node/Blocks/Input/inputBlock.js.map +1 -1
- package/Materials/Node/Blocks/index.d.ts +1 -0
- package/Materials/Node/Blocks/index.js +1 -0
- package/Materials/Node/Blocks/index.js.map +1 -1
- package/Materials/Node/Enums/nodeMaterialModes.d.ts +3 -1
- package/Materials/Node/Enums/nodeMaterialModes.js +2 -0
- package/Materials/Node/Enums/nodeMaterialModes.js.map +1 -1
- package/Materials/Node/index.d.ts +1 -0
- package/Materials/Node/index.js +1 -0
- package/Materials/Node/index.js.map +1 -1
- package/Materials/Node/nodeMaterialDefault.d.ts +6 -0
- package/Materials/Node/nodeMaterialDefault.js +53 -0
- package/Materials/Node/nodeMaterialDefault.js.map +1 -0
- package/Materials/PBR/pbrBaseMaterial.js +1 -11
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/Textures/texture.js +7 -3
- package/Materials/Textures/texture.js.map +1 -1
- package/Materials/Textures/textureSampler.d.ts +1 -1
- package/Materials/Textures/textureSampler.js.map +1 -1
- package/Materials/material.d.ts +5 -1
- package/Materials/material.js +19 -1
- package/Materials/material.js.map +1 -1
- package/Materials/materialPluginManager.js +2 -2
- package/Materials/materialPluginManager.js.map +1 -1
- package/Materials/pushMaterial.d.ts +1 -1
- package/Materials/pushMaterial.js +2 -2
- package/Materials/pushMaterial.js.map +1 -1
- package/Materials/standardMaterial.js +1 -11
- package/Materials/standardMaterial.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.d.ts +11 -0
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +72 -37
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Meshes/Node/Blocks/Set/aggregatorBlock.d.ts +76 -0
- package/Meshes/Node/Blocks/Set/aggregatorBlock.js +210 -0
- package/Meshes/Node/Blocks/Set/aggregatorBlock.js.map +1 -0
- package/Meshes/Node/Blocks/booleanGeometryBlock.d.ts +6 -0
- package/Meshes/Node/Blocks/booleanGeometryBlock.js +16 -4
- package/Meshes/Node/Blocks/booleanGeometryBlock.js.map +1 -1
- package/Meshes/Node/Blocks/geometryTransformBlock.d.ts +6 -0
- package/Meshes/Node/Blocks/geometryTransformBlock.js +14 -2
- package/Meshes/Node/Blocks/geometryTransformBlock.js.map +1 -1
- package/Meshes/Node/index.d.ts +1 -0
- package/Meshes/Node/index.js +1 -0
- package/Meshes/Node/index.js.map +1 -1
- package/Meshes/Node/nodeGeometry.d.ts +1 -1
- package/Meshes/Node/nodeGeometry.js +14 -1
- package/Meshes/Node/nodeGeometry.js.map +1 -1
- package/Meshes/Node/nodeGeometryBlock.d.ts +4 -0
- package/Meshes/Node/nodeGeometryBlock.js +6 -0
- package/Meshes/Node/nodeGeometryBlock.js.map +1 -1
- package/Meshes/csg.d.ts +1 -0
- package/Meshes/csg.js +1 -0
- package/Meshes/csg.js.map +1 -1
- package/Meshes/csg2.d.ts +126 -0
- package/Meshes/csg2.js +350 -0
- package/Meshes/csg2.js.map +1 -0
- package/Meshes/index.d.ts +1 -0
- package/Meshes/index.js +1 -0
- package/Meshes/index.js.map +1 -1
- package/Meshes/mesh.js +3 -1
- package/Meshes/mesh.js.map +1 -1
- package/Meshes/mesh.vertexData.d.ts +66 -1
- package/Meshes/mesh.vertexData.js.map +1 -1
- package/Misc/dumpTools.js +1 -0
- package/Misc/dumpTools.js.map +1 -1
- package/Misc/tools.d.ts +2 -1
- package/Misc/tools.internals.d.ts +13 -0
- package/Misc/tools.internals.js +48 -0
- package/Misc/tools.internals.js.map +1 -0
- package/Misc/tools.js +13 -4
- package/Misc/tools.js.map +1 -1
- package/Morph/morphTarget.js +1 -0
- package/Morph/morphTarget.js.map +1 -1
- package/Shaders/ShadersInclude/gaussianSplatting.d.ts +5 -0
- package/Shaders/ShadersInclude/gaussianSplatting.js +33 -0
- package/Shaders/ShadersInclude/gaussianSplatting.js.map +1 -0
- package/Shaders/ShadersInclude/gaussianSplattingFragmentDeclaration.d.ts +7 -0
- package/Shaders/ShadersInclude/gaussianSplattingFragmentDeclaration.js +19 -0
- package/Shaders/ShadersInclude/gaussianSplattingFragmentDeclaration.js.map +1 -0
- package/Shaders/ShadersInclude/gaussianSplattingUboDeclaration.js +1 -1
- package/Shaders/ShadersInclude/gaussianSplattingUboDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/gaussianSplattingVertexDeclaration.js +1 -2
- package/Shaders/ShadersInclude/gaussianSplattingVertexDeclaration.js.map +1 -1
- package/Shaders/gaussianSplatting.fragment.d.ts +1 -2
- package/Shaders/gaussianSplatting.fragment.js +5 -10
- package/Shaders/gaussianSplatting.fragment.js.map +1 -1
- package/Shaders/gaussianSplatting.vertex.d.ts +1 -0
- package/Shaders/gaussianSplatting.vertex.js +4 -21
- package/Shaders/gaussianSplatting.vertex.js.map +1 -1
- package/package.json +1 -1
package/Meshes/csg2.js
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { Mesh } from "./mesh.js";
|
|
2
|
+
import { VertexData } from "./mesh.vertexData.js";
|
|
3
|
+
import { VertexBuffer } from "../Buffers/buffer.js";
|
|
4
|
+
import { Logger } from "../Misc/logger.js";
|
|
5
|
+
import { MultiMaterial } from "../Materials/multiMaterial.js";
|
|
6
|
+
import { SubMesh } from "./subMesh.js";
|
|
7
|
+
import { _LoadScriptModuleAsync } from "../Misc/tools.internals.js";
|
|
8
|
+
import { Vector3 } from "../Maths/math.vector.js";
|
|
9
|
+
/**
|
|
10
|
+
* Main manifold library
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
13
|
+
let Manifold;
|
|
14
|
+
/**
|
|
15
|
+
* Manifold mesh
|
|
16
|
+
*/
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
18
|
+
let ManifoldMesh;
|
|
19
|
+
/**
|
|
20
|
+
* First ID to use for materials indexing
|
|
21
|
+
*/
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
23
|
+
let FirstID;
|
|
24
|
+
/**
|
|
25
|
+
* Wrapper around the Manifold library
|
|
26
|
+
* https://manifoldcad.org/
|
|
27
|
+
* Use this class to perform fast boolean operations on meshes
|
|
28
|
+
* #IW43EB#15 - basic operations
|
|
29
|
+
* #JUKXQD#6104 - skull vs box
|
|
30
|
+
* #JUKXQD#6111 - skull vs vertex data
|
|
31
|
+
*/
|
|
32
|
+
export class CSG2 {
|
|
33
|
+
/**
|
|
34
|
+
* Return the size of a vertex (at least 3 for the position)
|
|
35
|
+
*/
|
|
36
|
+
get numProp() {
|
|
37
|
+
return this._numProp;
|
|
38
|
+
}
|
|
39
|
+
constructor(manifold, numProp, vertexStructure) {
|
|
40
|
+
this._manifold = manifold;
|
|
41
|
+
this._numProp = numProp;
|
|
42
|
+
this._vertexStructure = vertexStructure;
|
|
43
|
+
}
|
|
44
|
+
_process(operation, csg) {
|
|
45
|
+
if (this.numProp !== csg.numProp) {
|
|
46
|
+
throw new Error("CSG must have the same number of properties");
|
|
47
|
+
}
|
|
48
|
+
return new CSG2(Manifold[operation](this._manifold, csg._manifold), this.numProp, this._vertexStructure);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Run a difference operation between two CSG
|
|
52
|
+
* @param csg defines the CSG to use to create the difference
|
|
53
|
+
* @returns a new csg
|
|
54
|
+
*/
|
|
55
|
+
subtract(csg) {
|
|
56
|
+
return this._process("difference", csg);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Run an intersection operation between two CSG
|
|
60
|
+
* @param csg defines the CSG to use to create the intersection
|
|
61
|
+
* @returns a new csg
|
|
62
|
+
*/
|
|
63
|
+
intersect(csg) {
|
|
64
|
+
return this._process("intersection", csg);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Run an union operation between two CSG
|
|
68
|
+
* @param csg defines the CSG to use to create the union
|
|
69
|
+
* @returns a new csg
|
|
70
|
+
*/
|
|
71
|
+
add(csg) {
|
|
72
|
+
return this._process("union", csg);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Print debug information about the CSG
|
|
76
|
+
*/
|
|
77
|
+
printDebug() {
|
|
78
|
+
Logger.Log("Genus:" + this._manifold.genus());
|
|
79
|
+
const properties = this._manifold.getProperties();
|
|
80
|
+
Logger.Log("Volume:" + properties.volume);
|
|
81
|
+
Logger.Log("surface area:" + properties.surfaceArea);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Generate a vertex data from the CSG
|
|
85
|
+
* @param options defines the options to use to rebuild the vertex data
|
|
86
|
+
* @returns a new vertex data
|
|
87
|
+
*/
|
|
88
|
+
toVertexData(options) {
|
|
89
|
+
const localOptions = {
|
|
90
|
+
rebuildNormals: false,
|
|
91
|
+
...options,
|
|
92
|
+
};
|
|
93
|
+
const vertexData = new VertexData();
|
|
94
|
+
const normalComponent = this._vertexStructure.find((c) => c.kind === VertexBuffer.NormalKind);
|
|
95
|
+
const manifoldMesh = this._manifold.getMesh(localOptions.rebuildNormals && normalComponent ? [3, 4, 5] : undefined);
|
|
96
|
+
vertexData.indices = manifoldMesh.triVerts.length > 65535 ? new Uint32Array(manifoldMesh.triVerts) : new Uint16Array(manifoldMesh.triVerts);
|
|
97
|
+
for (let i = 0; i < manifoldMesh.triVerts.length; i += 3) {
|
|
98
|
+
vertexData.indices[i] = manifoldMesh.triVerts[i + 2];
|
|
99
|
+
vertexData.indices[i + 1] = manifoldMesh.triVerts[i + 1];
|
|
100
|
+
vertexData.indices[i + 2] = manifoldMesh.triVerts[i];
|
|
101
|
+
}
|
|
102
|
+
const vertexCount = manifoldMesh.vertProperties.length / manifoldMesh.numProp;
|
|
103
|
+
// Attributes
|
|
104
|
+
let offset = 0;
|
|
105
|
+
for (let componentIndex = 0; componentIndex < this._vertexStructure.length; componentIndex++) {
|
|
106
|
+
const component = this._vertexStructure[componentIndex];
|
|
107
|
+
const data = new Float32Array(vertexCount * component.stride);
|
|
108
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
109
|
+
for (let strideIndex = 0; strideIndex < component.stride; strideIndex++) {
|
|
110
|
+
data[i * component.stride + strideIndex] = manifoldMesh.vertProperties[i * manifoldMesh.numProp + offset + strideIndex];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
vertexData.set(data, component.kind);
|
|
114
|
+
offset += component.stride;
|
|
115
|
+
}
|
|
116
|
+
// Rebuild mesh from vertex data
|
|
117
|
+
return vertexData;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Generate a mesh from the CSG
|
|
121
|
+
* @param name defines the name of the mesh
|
|
122
|
+
* @param scene defines the scene to use to create the mesh
|
|
123
|
+
* @param options defines the options to use to rebuild the mesh
|
|
124
|
+
* @returns a new Mesh
|
|
125
|
+
*/
|
|
126
|
+
toMesh(name, scene, options) {
|
|
127
|
+
const localOptions = {
|
|
128
|
+
rebuildNormals: false,
|
|
129
|
+
centerMesh: true,
|
|
130
|
+
...options,
|
|
131
|
+
};
|
|
132
|
+
const vertexData = this.toVertexData({ rebuildNormals: localOptions.rebuildNormals });
|
|
133
|
+
const normalComponent = this._vertexStructure.find((c) => c.kind === VertexBuffer.NormalKind);
|
|
134
|
+
const manifoldMesh = this._manifold.getMesh(localOptions.rebuildNormals && normalComponent ? [3, 4, 5] : undefined);
|
|
135
|
+
const vertexCount = manifoldMesh.vertProperties.length / manifoldMesh.numProp;
|
|
136
|
+
// Rebuild mesh from vertex data
|
|
137
|
+
const output = new Mesh(name, scene);
|
|
138
|
+
vertexData.applyToMesh(output);
|
|
139
|
+
// Center mesh
|
|
140
|
+
if (localOptions.centerMesh) {
|
|
141
|
+
const extents = output.getBoundingInfo().boundingSphere.center;
|
|
142
|
+
output.position.set(-extents.x, -extents.y, -extents.z);
|
|
143
|
+
output.bakeCurrentTransformIntoVertices();
|
|
144
|
+
}
|
|
145
|
+
// Submeshes
|
|
146
|
+
let id = manifoldMesh.runOriginalID[0];
|
|
147
|
+
let start = manifoldMesh.runIndex[0];
|
|
148
|
+
let materialIndex = 0;
|
|
149
|
+
const materials = [];
|
|
150
|
+
scene = output.getScene();
|
|
151
|
+
for (let run = 0; run < manifoldMesh.numRun; ++run) {
|
|
152
|
+
const nextID = manifoldMesh.runOriginalID[run + 1];
|
|
153
|
+
if (nextID !== id) {
|
|
154
|
+
const end = manifoldMesh.runIndex[run + 1];
|
|
155
|
+
new SubMesh(materialIndex, 0, vertexCount, start, end - start, output);
|
|
156
|
+
materials.push(scene.getMaterialByUniqueID(id - FirstID) || scene.defaultMaterial);
|
|
157
|
+
id = nextID;
|
|
158
|
+
start = end;
|
|
159
|
+
materialIndex++;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (materials.length > 1) {
|
|
163
|
+
const multiMaterial = new MultiMaterial(name, scene);
|
|
164
|
+
multiMaterial.subMaterials = materials;
|
|
165
|
+
output.material = multiMaterial;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
output.material = materials[0];
|
|
169
|
+
}
|
|
170
|
+
return output;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Dispose the CSG resources
|
|
174
|
+
*/
|
|
175
|
+
dispose() {
|
|
176
|
+
if (this._manifold) {
|
|
177
|
+
this._manifold.delete();
|
|
178
|
+
this._manifold = null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
static _ProcessData(vertexCount, triVerts, structure, numProp, runIndex, runOriginalID) {
|
|
182
|
+
const vertProperties = new Float32Array(vertexCount * structure.reduce((acc, cur) => acc + cur.stride, 0));
|
|
183
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
184
|
+
let offset = 0;
|
|
185
|
+
for (let idx = 0; idx < structure.length; idx++) {
|
|
186
|
+
const component = structure[idx];
|
|
187
|
+
for (let strideIndex = 0; strideIndex < component.stride; strideIndex++) {
|
|
188
|
+
vertProperties[i * numProp + offset + strideIndex] = component.data[i * component.stride + strideIndex];
|
|
189
|
+
}
|
|
190
|
+
offset += component.stride;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const manifoldMesh = new ManifoldMesh({ numProp: numProp, vertProperties, triVerts, runIndex, runOriginalID });
|
|
194
|
+
manifoldMesh.merge();
|
|
195
|
+
try {
|
|
196
|
+
return new CSG2(new Manifold(manifoldMesh), numProp, structure);
|
|
197
|
+
}
|
|
198
|
+
catch (e) {
|
|
199
|
+
throw new Error("Error while creating the CSG: " + e.message);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
static _Construct(data, worldMatrix, runIndex, runOriginalID) {
|
|
203
|
+
// Create the MeshGL for I/O with Manifold library.
|
|
204
|
+
const triVerts = new Uint32Array(data.indices.length);
|
|
205
|
+
// Revert order
|
|
206
|
+
for (let i = 0; i < data.indices.length; i += 3) {
|
|
207
|
+
triVerts[i] = data.indices[i + 2];
|
|
208
|
+
triVerts[i + 1] = data.indices[i + 1];
|
|
209
|
+
triVerts[i + 2] = data.indices[i];
|
|
210
|
+
}
|
|
211
|
+
const tempVector3 = new Vector3();
|
|
212
|
+
let numProp = 3;
|
|
213
|
+
const structure = [{ stride: 3, kind: VertexBuffer.PositionKind }];
|
|
214
|
+
if (!worldMatrix) {
|
|
215
|
+
structure[0].data = data.positions;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
const positions = new Float32Array(data.positions.length);
|
|
219
|
+
for (let i = 0; i < data.positions.length; i += 3) {
|
|
220
|
+
Vector3.TransformCoordinatesFromFloatsToRef(data.positions[i], data.positions[i + 1], data.positions[i + 2], worldMatrix, tempVector3);
|
|
221
|
+
tempVector3.toArray(positions, i);
|
|
222
|
+
}
|
|
223
|
+
structure[0].data = positions;
|
|
224
|
+
}
|
|
225
|
+
// Normals
|
|
226
|
+
const sourceNormals = data.normals;
|
|
227
|
+
if (sourceNormals) {
|
|
228
|
+
numProp += 3;
|
|
229
|
+
structure.push({ stride: 3, kind: VertexBuffer.NormalKind });
|
|
230
|
+
if (!worldMatrix) {
|
|
231
|
+
structure[1].data = sourceNormals;
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
const normals = new Float32Array(sourceNormals.length);
|
|
235
|
+
for (let i = 0; i < sourceNormals.length; i += 3) {
|
|
236
|
+
Vector3.TransformNormalFromFloatsToRef(sourceNormals[i], sourceNormals[i + 1], sourceNormals[i + 2], worldMatrix, tempVector3);
|
|
237
|
+
tempVector3.toArray(normals, i);
|
|
238
|
+
}
|
|
239
|
+
structure[1].data = normals;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// UVs
|
|
243
|
+
for (const kind of [VertexBuffer.UVKind, VertexBuffer.UV2Kind, VertexBuffer.UV3Kind, VertexBuffer.UV4Kind, VertexBuffer.UV5Kind, VertexBuffer.UV6Kind]) {
|
|
244
|
+
const sourceUV = data[kind === VertexBuffer.UVKind ? "uvs" : kind];
|
|
245
|
+
if (sourceUV) {
|
|
246
|
+
numProp += 2;
|
|
247
|
+
structure.push({ stride: 2, kind: kind, data: sourceUV });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// Colors
|
|
251
|
+
const sourceColors = data.colors;
|
|
252
|
+
if (sourceColors) {
|
|
253
|
+
numProp += 4;
|
|
254
|
+
structure.push({ stride: 4, kind: VertexBuffer.ColorKind, data: sourceColors });
|
|
255
|
+
}
|
|
256
|
+
return this._ProcessData(data.positions.length / 3, triVerts, structure, numProp, runIndex, runOriginalID);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Create a new Constructive Solid Geometry from a vertexData
|
|
260
|
+
* @param vertexData defines the vertexData to use to create the CSG
|
|
261
|
+
* @returns a new CSG2 class
|
|
262
|
+
*/
|
|
263
|
+
static FromVertexData(vertexData) {
|
|
264
|
+
const sourceVertices = vertexData.positions;
|
|
265
|
+
const sourceIndices = vertexData.indices;
|
|
266
|
+
if (!sourceVertices || !sourceIndices) {
|
|
267
|
+
throw new Error("The vertexData must at least have positions and indices");
|
|
268
|
+
}
|
|
269
|
+
return this._Construct(vertexData, null);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Create a new Constructive Solid Geometry from a mesh
|
|
273
|
+
* @param mesh defines the mesh to use to create the CSG
|
|
274
|
+
* @param ignoreWorldMatrix defines if the world matrix should be ignored
|
|
275
|
+
* @returns a new CSG2 class
|
|
276
|
+
*/
|
|
277
|
+
static FromMesh(mesh, ignoreWorldMatrix = false) {
|
|
278
|
+
const sourceVertices = mesh.getVerticesData(VertexBuffer.PositionKind);
|
|
279
|
+
const sourceIndices = mesh.getIndices();
|
|
280
|
+
const worldMatrix = mesh.computeWorldMatrix(true);
|
|
281
|
+
if (!sourceVertices || !sourceIndices) {
|
|
282
|
+
throw new Error("The mesh must at least have positions and indices");
|
|
283
|
+
}
|
|
284
|
+
// Create a triangle run for each submesh (material)
|
|
285
|
+
const starts = [...Array(mesh.subMeshes.length)].map((_, idx) => mesh.subMeshes[idx].indexStart);
|
|
286
|
+
// Map the materials to ID.
|
|
287
|
+
const sourceMaterial = mesh.material || mesh.getScene().defaultMaterial;
|
|
288
|
+
const isMultiMaterial = sourceMaterial.getClassName() === "MultiMaterial";
|
|
289
|
+
const originalIDs = [...Array(mesh.subMeshes.length)].map((_, idx) => {
|
|
290
|
+
if (isMultiMaterial) {
|
|
291
|
+
return FirstID + sourceMaterial.subMaterials[mesh.subMeshes[idx].materialIndex].uniqueId;
|
|
292
|
+
}
|
|
293
|
+
return FirstID + sourceMaterial.uniqueId;
|
|
294
|
+
});
|
|
295
|
+
// List the runs in sequence.
|
|
296
|
+
const indices = Array.from(starts.keys());
|
|
297
|
+
indices.sort((a, b) => starts[a] - starts[b]);
|
|
298
|
+
const runIndex = new Uint32Array(indices.map((i) => starts[i]));
|
|
299
|
+
const runOriginalID = new Uint32Array(indices.map((i) => originalIDs[i]));
|
|
300
|
+
// Process
|
|
301
|
+
const data = {
|
|
302
|
+
positions: sourceVertices,
|
|
303
|
+
indices: sourceIndices,
|
|
304
|
+
normals: mesh.getVerticesData(VertexBuffer.NormalKind),
|
|
305
|
+
colors: mesh.getVerticesData(VertexBuffer.ColorKind),
|
|
306
|
+
uvs: mesh.getVerticesData(VertexBuffer.UVKind),
|
|
307
|
+
uvs2: mesh.getVerticesData(VertexBuffer.UV2Kind),
|
|
308
|
+
uvs3: mesh.getVerticesData(VertexBuffer.UV3Kind),
|
|
309
|
+
uvs4: mesh.getVerticesData(VertexBuffer.UV4Kind),
|
|
310
|
+
uvs5: mesh.getVerticesData(VertexBuffer.UV5Kind),
|
|
311
|
+
uvs6: mesh.getVerticesData(VertexBuffer.UV6Kind),
|
|
312
|
+
};
|
|
313
|
+
return this._Construct(data, ignoreWorldMatrix ? null : worldMatrix, runIndex, runOriginalID);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Checks if the Manifold library is ready
|
|
318
|
+
* @returns true if the Manifold library is ready
|
|
319
|
+
*/
|
|
320
|
+
export function IsCSG2Ready() {
|
|
321
|
+
return Manifold !== undefined;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Initialize the Manifold library
|
|
325
|
+
* @param options defines the options to use to initialize the library
|
|
326
|
+
*/
|
|
327
|
+
export async function InitializeCSG2Async(options) {
|
|
328
|
+
const localOptions = {
|
|
329
|
+
manifoldUrl: "https://unpkg.com/manifold-3d@2.5.1",
|
|
330
|
+
...options,
|
|
331
|
+
};
|
|
332
|
+
if (localOptions.manifoldInstance) {
|
|
333
|
+
Manifold = localOptions.manifoldInstance;
|
|
334
|
+
ManifoldMesh = localOptions.manifoldMeshInstance;
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
const result = await _LoadScriptModuleAsync(`
|
|
338
|
+
import Module from '${localOptions.manifoldUrl}/manifold.js';
|
|
339
|
+
const wasm = await Module();
|
|
340
|
+
wasm.setup();
|
|
341
|
+
const {Manifold, Mesh} = wasm;
|
|
342
|
+
const returnedValue = {Manifold, Mesh};
|
|
343
|
+
`);
|
|
344
|
+
Manifold = result.Manifold;
|
|
345
|
+
ManifoldMesh = result.Mesh;
|
|
346
|
+
}
|
|
347
|
+
// Reserve IDs for materials (we consider that there will be no more than 65536 materials)
|
|
348
|
+
FirstID = Manifold.reserveIDs(65536);
|
|
349
|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AC,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\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"]}
|
package/Meshes/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * from "./WebGPU/webgpuDataBuffer";
|
|
|
30
30
|
export * from "./GreasedLine/greasedLineMesh";
|
|
31
31
|
export * from "./GreasedLine/greasedLineRibbonMesh";
|
|
32
32
|
export * from "./GreasedLine/greasedLineBaseMesh";
|
|
33
|
+
export * from "./csg2";
|
|
33
34
|
import "./thinInstanceMesh";
|
|
34
35
|
export * from "./thinInstanceMesh";
|
|
35
36
|
export * from "./Node/index";
|
package/Meshes/index.js
CHANGED
|
@@ -32,6 +32,7 @@ export * from "./WebGPU/webgpuDataBuffer.js";
|
|
|
32
32
|
export * from "./GreasedLine/greasedLineMesh.js";
|
|
33
33
|
export * from "./GreasedLine/greasedLineRibbonMesh.js";
|
|
34
34
|
export * from "./GreasedLine/greasedLineBaseMesh.js";
|
|
35
|
+
export * from "./csg2.js";
|
|
35
36
|
import "./thinInstanceMesh.js";
|
|
36
37
|
// eslint-disable-next-line no-duplicate-imports
|
|
37
38
|
export * from "./thinInstanceMesh.js";
|
package/Meshes/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/index.ts"],"names":[],"mappings":"AA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AC9D,cAAc,kDAAkD,CAAC;AACjE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,6CAA6C,CAAC;AAC5D,cAAc,iDAAiD,CAAC;AAChE,cAAc,mDAAmD,CAAC;AAClE,cAAc,sDAAsD,CAAC;AACrE,cAAc,oDAAoD,CAAC","sourcesContent":["/* eslint-disable import/export */\r\n/* eslint-disable import/no-internal-modules */\r\nexport * from \"./abstractMesh\";\r\nimport \"./abstractMesh.decalMap\";\r\nexport * from \"./abstractMesh.hotSpot\";\r\nexport * from \"./Compression/index\";\r\nexport * from \"./csg\";\r\nexport * from \"./meshUVSpaceRenderer\";\r\nexport * from \"./geometry\";\r\nexport * from \"./groundMesh\";\r\nexport * from \"./goldbergMesh\";\r\nexport * from \"./trailMesh\";\r\nexport * from \"./instancedMesh\";\r\nexport * from \"./linesMesh\";\r\nexport * from \"./mesh\";\r\nexport * from \"./mesh.vertexData\";\r\nexport * from \"./meshBuilder\";\r\nexport * from \"./meshSimplification\";\r\nexport * from \"./meshSimplificationSceneComponent\";\r\nexport * from \"./meshUtils\";\r\nexport * from \"./polygonMesh\";\r\nexport * from \"./geodesicMesh\";\r\nexport * from \"./subMesh\";\r\nexport * from \"./subMesh.project\";\r\nexport * from \"./lattice\";\r\nexport * from \"./lattice.material\";\r\nexport * from \"./meshLODLevel\";\r\nexport * from \"./transformNode\";\r\nexport * from \"./Builders/index\";\r\nexport * from \"./WebGL/webGLDataBuffer\";\r\nexport * from \"./WebGPU/webgpuDataBuffer\";\r\nexport * from \"./GreasedLine/greasedLineMesh\";\r\nexport * from \"./GreasedLine/greasedLineRibbonMesh\";\r\nexport * from \"./GreasedLine/greasedLineBaseMesh\";\r\nimport \"./thinInstanceMesh\";\r\n// eslint-disable-next-line no-duplicate-imports\r\nexport * from \"./thinInstanceMesh\";\r\nexport * from \"./Node/index\";\r\nexport * from \"./GaussianSplatting/gaussianSplattingMesh\";\r\n\r\n// LineMesh\r\nexport * from \"../Shaders/color.fragment\";\r\nexport * from \"../Shaders/color.vertex\";\r\nexport * from \"../ShadersWGSL/color.fragment\";\r\nexport * from \"../ShadersWGSL/color.vertex\";\r\n\r\n// MeshUVSPaceRenderer\r\nexport * from \"../Shaders/meshUVSpaceRenderer.vertex\";\r\nexport * from \"../Shaders/meshUVSpaceRenderer.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererMasker.vertex\";\r\nexport * from \"../Shaders/meshUVSpaceRendererMasker.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererFinaliser.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererFinaliser.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRenderer.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRenderer.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererMasker.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererMasker.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererFinaliser.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererFinaliser.vertex\";\r\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/core/src/Meshes/index.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,+CAA+C;AAC/C,cAAc,gBAAgB,CAAC;AAC/B,OAAO,yBAAyB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,OAAO,CAAC;AACtB,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oCAAoC,CAAC;AACnD,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,mCAAmC,CAAC;AAClD,cAAc,QAAQ,CAAC;AACvB,OAAO,oBAAoB,CAAC;AAC5B,gDAAgD;AAChD,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,2CAA2C,CAAC;AAE1D,WAAW;AACX,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAE5C,sBAAsB;AACtB,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,kDAAkD,CAAC;AACjE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,6CAA6C,CAAC;AAC5D,cAAc,iDAAiD,CAAC;AAChE,cAAc,mDAAmD,CAAC;AAClE,cAAc,sDAAsD,CAAC;AACrE,cAAc,oDAAoD,CAAC","sourcesContent":["/* eslint-disable import/export */\r\n/* eslint-disable import/no-internal-modules */\r\nexport * from \"./abstractMesh\";\r\nimport \"./abstractMesh.decalMap\";\r\nexport * from \"./abstractMesh.hotSpot\";\r\nexport * from \"./Compression/index\";\r\nexport * from \"./csg\";\r\nexport * from \"./meshUVSpaceRenderer\";\r\nexport * from \"./geometry\";\r\nexport * from \"./groundMesh\";\r\nexport * from \"./goldbergMesh\";\r\nexport * from \"./trailMesh\";\r\nexport * from \"./instancedMesh\";\r\nexport * from \"./linesMesh\";\r\nexport * from \"./mesh\";\r\nexport * from \"./mesh.vertexData\";\r\nexport * from \"./meshBuilder\";\r\nexport * from \"./meshSimplification\";\r\nexport * from \"./meshSimplificationSceneComponent\";\r\nexport * from \"./meshUtils\";\r\nexport * from \"./polygonMesh\";\r\nexport * from \"./geodesicMesh\";\r\nexport * from \"./subMesh\";\r\nexport * from \"./subMesh.project\";\r\nexport * from \"./lattice\";\r\nexport * from \"./lattice.material\";\r\nexport * from \"./meshLODLevel\";\r\nexport * from \"./transformNode\";\r\nexport * from \"./Builders/index\";\r\nexport * from \"./WebGL/webGLDataBuffer\";\r\nexport * from \"./WebGPU/webgpuDataBuffer\";\r\nexport * from \"./GreasedLine/greasedLineMesh\";\r\nexport * from \"./GreasedLine/greasedLineRibbonMesh\";\r\nexport * from \"./GreasedLine/greasedLineBaseMesh\";\r\nexport * from \"./csg2\";\r\nimport \"./thinInstanceMesh\";\r\n// eslint-disable-next-line no-duplicate-imports\r\nexport * from \"./thinInstanceMesh\";\r\nexport * from \"./Node/index\";\r\nexport * from \"./GaussianSplatting/gaussianSplattingMesh\";\r\n\r\n// LineMesh\r\nexport * from \"../Shaders/color.fragment\";\r\nexport * from \"../Shaders/color.vertex\";\r\nexport * from \"../ShadersWGSL/color.fragment\";\r\nexport * from \"../ShadersWGSL/color.vertex\";\r\n\r\n// MeshUVSPaceRenderer\r\nexport * from \"../Shaders/meshUVSpaceRenderer.vertex\";\r\nexport * from \"../Shaders/meshUVSpaceRenderer.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererMasker.vertex\";\r\nexport * from \"../Shaders/meshUVSpaceRendererMasker.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererFinaliser.fragment\";\r\nexport * from \"../Shaders/meshUVSpaceRendererFinaliser.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRenderer.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRenderer.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererMasker.vertex\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererMasker.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererFinaliser.fragment\";\r\nexport * from \"../ShadersWGSL/meshUVSpaceRendererFinaliser.vertex\";\r\n"]}
|
package/Meshes/mesh.js
CHANGED
|
@@ -3010,7 +3010,9 @@ export class Mesh extends AbstractMesh {
|
|
|
3010
3010
|
* @returns a new InstancedMesh
|
|
3011
3011
|
*/
|
|
3012
3012
|
createInstance(name) {
|
|
3013
|
-
|
|
3013
|
+
const instance = Mesh._instancedMeshFactory(name, this);
|
|
3014
|
+
instance.parent = this.parent;
|
|
3015
|
+
return instance;
|
|
3014
3016
|
}
|
|
3015
3017
|
/**
|
|
3016
3018
|
* Synchronises all the mesh instance submeshes to the current mesh submeshes, if any.
|