@babylonjs/core 6.22.0 → 6.23.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/Animations/animationGroup.d.ts +1 -0
- package/Animations/animationGroup.js +5 -1
- package/Animations/animationGroup.js.map +1 -1
- package/Behaviors/Meshes/pointerDragBehavior.d.ts +4 -3
- package/Behaviors/Meshes/pointerDragBehavior.js +4 -3
- package/Behaviors/Meshes/pointerDragBehavior.js.map +1 -1
- package/Cameras/arcRotateCamera.js +8 -2
- package/Cameras/arcRotateCamera.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheRenderPipeline.js +2 -2
- package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
- package/Engines/WebGPU/webgpuConstants.d.ts +5 -4
- package/Engines/WebGPU/webgpuConstants.js +15 -15
- package/Engines/WebGPU/webgpuConstants.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureHelper.d.ts +1 -0
- package/Engines/WebGPU/webgpuTextureHelper.js +27 -31
- package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
- package/Engines/engine.d.ts +32 -32
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js +2 -2
- package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/{flowGraphConditionalBlock.js → flowGraphBranchBlock.js} +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphBranchBlock.js.map +1 -0
- package/FlowGraph/Blocks/Execution/ControlFlow/index.d.ts +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/index.js +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/index.js.map +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphCustomFunctionBlock.d.ts +23 -0
- package/FlowGraph/Blocks/Execution/flowGraphCustomFunctionBlock.js +18 -0
- package/FlowGraph/Blocks/Execution/flowGraphCustomFunctionBlock.js.map +1 -0
- package/Gizmos/boundingBoxGizmo.js +13 -11
- package/Gizmos/boundingBoxGizmo.js.map +1 -1
- package/Gizmos/gizmo.js +3 -1
- package/Gizmos/gizmo.js.map +1 -1
- package/Gizmos/planeRotationGizmo.js +5 -0
- package/Gizmos/planeRotationGizmo.js.map +1 -1
- package/Gizmos/positionGizmo.d.ts +4 -0
- package/Gizmos/positionGizmo.js +6 -0
- package/Gizmos/positionGizmo.js.map +1 -1
- package/Gizmos/rotationGizmo.d.ts +4 -0
- package/Gizmos/rotationGizmo.js +6 -0
- package/Gizmos/rotationGizmo.js.map +1 -1
- package/Gizmos/scaleGizmo.d.ts +4 -0
- package/Gizmos/scaleGizmo.js +6 -0
- package/Gizmos/scaleGizmo.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.d.ts +4 -1
- package/Materials/Textures/Procedurals/proceduralTexture.js +10 -8
- package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
- package/Materials/uniformBuffer.js +1 -1
- package/Materials/uniformBuffer.js.map +1 -1
- package/Maths/math.vector.js +3 -3
- package/Maths/math.vector.js.map +1 -1
- package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.d.ts +4 -4
- package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.js +4 -4
- package/Meshes/Node/Blocks/Instances/instantiateOnVolumeBlock.js.map +1 -1
- package/Meshes/Node/Blocks/Sources/meshBlock.d.ts +4 -0
- package/Meshes/Node/Blocks/Sources/meshBlock.js +18 -0
- package/Meshes/Node/Blocks/Sources/meshBlock.js.map +1 -1
- package/Meshes/Node/Blocks/booleanGeometryBlock.d.ts +58 -0
- package/Meshes/Node/Blocks/booleanGeometryBlock.js +155 -0
- package/Meshes/Node/Blocks/booleanGeometryBlock.js.map +1 -0
- package/Meshes/Node/Blocks/mergeGeometryBlock.js +0 -2
- package/Meshes/Node/Blocks/mergeGeometryBlock.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/csg.d.ts +169 -1
- package/Meshes/csg.js +107 -43
- package/Meshes/csg.js.map +1 -1
- package/Meshes/mesh.d.ts +10 -0
- package/Meshes/mesh.js +33 -0
- package/Meshes/mesh.js.map +1 -1
- package/Misc/tools.d.ts +0 -1
- package/Misc/tools.js +1 -5
- package/Misc/tools.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +7 -0
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js +6 -0
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
- package/PostProcesses/screenSpaceCurvaturePostProcess.js +3 -0
- package/PostProcesses/screenSpaceCurvaturePostProcess.js.map +1 -1
- package/PostProcesses/screenSpaceReflectionPostProcess.js +6 -0
- package/PostProcesses/screenSpaceReflectionPostProcess.js.map +1 -1
- package/Rendering/depthPeelingRenderer.js +6 -0
- package/Rendering/depthPeelingRenderer.js.map +1 -1
- package/Rendering/geometryBufferRenderer.d.ts +4 -0
- package/Rendering/geometryBufferRenderer.js +7 -0
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/lightFragment.js +4 -4
- package/Shaders/ShadersInclude/lightFragment.js.map +1 -1
- package/Shaders/ShadersInclude/shadowsFragmentFunctions.js +41 -42
- package/Shaders/ShadersInclude/shadowsFragmentFunctions.js.map +1 -1
- package/Shaders/geometry.fragment.js +4 -0
- package/Shaders/geometry.fragment.js.map +1 -1
- package/Shaders/geometry.vertex.js +4 -0
- package/Shaders/geometry.vertex.js.map +1 -1
- package/package.json +1 -1
- package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphConditionalBlock.js.map +0 -1
- /package/FlowGraph/Blocks/Execution/ControlFlow/{flowGraphConditionalBlock.d.ts → flowGraphBranchBlock.d.ts} +0 -0
package/Meshes/csg.d.ts
CHANGED
|
@@ -1,8 +1,163 @@
|
|
|
1
1
|
import type { Nullable } from "../types";
|
|
2
2
|
import type { Scene } from "../scene";
|
|
3
|
-
import { Quaternion, Matrix, Vector3 } from "../Maths/math.vector";
|
|
3
|
+
import { Quaternion, Matrix, Vector3, Vector2 } from "../Maths/math.vector";
|
|
4
4
|
import { Mesh } from "../Meshes/mesh";
|
|
5
5
|
import type { Material } from "../Materials/material";
|
|
6
|
+
import { Color4 } from "../Maths/math.color";
|
|
7
|
+
import { VertexData } from "./mesh.vertexData";
|
|
8
|
+
/**
|
|
9
|
+
* Represents a vertex of a polygon. Use your own vertex class instead of this
|
|
10
|
+
* one to provide additional features like texture coordinates and vertex
|
|
11
|
+
* colors. Custom vertex classes need to provide a `pos` property and `clone()`,
|
|
12
|
+
* `flip()`, and `interpolate()` methods that behave analogous to the ones
|
|
13
|
+
* defined by `BABYLON.CSG.Vertex`. This class provides `normal` so convenience
|
|
14
|
+
* functions like `BABYLON.CSG.sphere()` can return a smooth vertex normal, but `normal`
|
|
15
|
+
* is not used anywhere else.
|
|
16
|
+
* Same goes for uv, it allows to keep the original vertex uv coordinates of the 2 meshes
|
|
17
|
+
*/
|
|
18
|
+
declare class Vertex {
|
|
19
|
+
/**
|
|
20
|
+
* The position of the vertex
|
|
21
|
+
*/
|
|
22
|
+
pos: Vector3;
|
|
23
|
+
/**
|
|
24
|
+
* The normal of the vertex
|
|
25
|
+
*/
|
|
26
|
+
normal: Vector3;
|
|
27
|
+
/**
|
|
28
|
+
* The texture coordinate of the vertex
|
|
29
|
+
*/
|
|
30
|
+
uv?: Vector2 | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The texture coordinate of the vertex
|
|
33
|
+
*/
|
|
34
|
+
vertColor?: Color4 | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Initializes the vertex
|
|
37
|
+
* @param pos The position of the vertex
|
|
38
|
+
* @param normal The normal of the vertex
|
|
39
|
+
* @param uv The texture coordinate of the vertex
|
|
40
|
+
* @param vertColor The RGBA color of the vertex
|
|
41
|
+
*/
|
|
42
|
+
constructor(
|
|
43
|
+
/**
|
|
44
|
+
* The position of the vertex
|
|
45
|
+
*/
|
|
46
|
+
pos: Vector3,
|
|
47
|
+
/**
|
|
48
|
+
* The normal of the vertex
|
|
49
|
+
*/
|
|
50
|
+
normal: Vector3,
|
|
51
|
+
/**
|
|
52
|
+
* The texture coordinate of the vertex
|
|
53
|
+
*/
|
|
54
|
+
uv?: Vector2 | undefined,
|
|
55
|
+
/**
|
|
56
|
+
* The texture coordinate of the vertex
|
|
57
|
+
*/
|
|
58
|
+
vertColor?: Color4 | undefined);
|
|
59
|
+
/**
|
|
60
|
+
* Make a clone, or deep copy, of the vertex
|
|
61
|
+
* @returns A new Vertex
|
|
62
|
+
*/
|
|
63
|
+
clone(): Vertex;
|
|
64
|
+
/**
|
|
65
|
+
* Invert all orientation-specific data (e.g. vertex normal). Called when the
|
|
66
|
+
* orientation of a polygon is flipped.
|
|
67
|
+
*/
|
|
68
|
+
flip(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Create a new vertex between this vertex and `other` by linearly
|
|
71
|
+
* interpolating all properties using a parameter of `t`. Subclasses should
|
|
72
|
+
* override this to interpolate additional properties.
|
|
73
|
+
* @param other the vertex to interpolate against
|
|
74
|
+
* @param t The factor used to linearly interpolate between the vertices
|
|
75
|
+
*/
|
|
76
|
+
interpolate(other: Vertex, t: number): Vertex;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Represents a plane in 3D space.
|
|
80
|
+
*/
|
|
81
|
+
declare class Plane {
|
|
82
|
+
normal: Vector3;
|
|
83
|
+
w: number;
|
|
84
|
+
/**
|
|
85
|
+
* Initializes the plane
|
|
86
|
+
* @param normal The normal for the plane
|
|
87
|
+
* @param w
|
|
88
|
+
*/
|
|
89
|
+
constructor(normal: Vector3, w: number);
|
|
90
|
+
/**
|
|
91
|
+
* `CSG.Plane.EPSILON` is the tolerance used by `splitPolygon()` to decide if a
|
|
92
|
+
* point is on the plane
|
|
93
|
+
*/
|
|
94
|
+
static EPSILON: number;
|
|
95
|
+
/**
|
|
96
|
+
* Construct a plane from three points
|
|
97
|
+
* @param a Point a
|
|
98
|
+
* @param b Point b
|
|
99
|
+
* @param c Point c
|
|
100
|
+
*/
|
|
101
|
+
static FromPoints(a: Vector3, b: Vector3, c: Vector3): Nullable<Plane>;
|
|
102
|
+
/**
|
|
103
|
+
* Clone, or make a deep copy of the plane
|
|
104
|
+
* @returns a new Plane
|
|
105
|
+
*/
|
|
106
|
+
clone(): Plane;
|
|
107
|
+
/**
|
|
108
|
+
* Flip the face of the plane
|
|
109
|
+
*/
|
|
110
|
+
flip(): void;
|
|
111
|
+
/**
|
|
112
|
+
* Split `polygon` by this plane if needed, then put the polygon or polygon
|
|
113
|
+
* fragments in the appropriate lists. Coplanar polygons go into either
|
|
114
|
+
`* coplanarFront` or `coplanarBack` depending on their orientation with
|
|
115
|
+
* respect to this plane. Polygons in front or in back of this plane go into
|
|
116
|
+
* either `front` or `back`
|
|
117
|
+
* @param polygon The polygon to be split
|
|
118
|
+
* @param coplanarFront Will contain polygons coplanar with the plane that are oriented to the front of the plane
|
|
119
|
+
* @param coplanarBack Will contain polygons coplanar with the plane that are oriented to the back of the plane
|
|
120
|
+
* @param front Will contain the polygons in front of the plane
|
|
121
|
+
* @param back Will contain the polygons begind the plane
|
|
122
|
+
*/
|
|
123
|
+
splitPolygon(polygon: Polygon, coplanarFront: Polygon[], coplanarBack: Polygon[], front: Polygon[], back: Polygon[]): void;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Represents a convex polygon. The vertices used to initialize a polygon must
|
|
127
|
+
* be coplanar and form a convex loop.
|
|
128
|
+
*
|
|
129
|
+
* Each convex polygon has a `shared` property, which is shared between all
|
|
130
|
+
* polygons that are clones of each other or were split from the same polygon.
|
|
131
|
+
* This can be used to define per-polygon properties (such as surface color)
|
|
132
|
+
*/
|
|
133
|
+
declare class Polygon {
|
|
134
|
+
/**
|
|
135
|
+
* Vertices of the polygon
|
|
136
|
+
*/
|
|
137
|
+
vertices: Vertex[];
|
|
138
|
+
/**
|
|
139
|
+
* Properties that are shared across all polygons
|
|
140
|
+
*/
|
|
141
|
+
shared: any;
|
|
142
|
+
/**
|
|
143
|
+
* A plane formed from the vertices of the polygon
|
|
144
|
+
*/
|
|
145
|
+
plane: Plane;
|
|
146
|
+
/**
|
|
147
|
+
* Initializes the polygon
|
|
148
|
+
* @param vertices The vertices of the polygon
|
|
149
|
+
* @param shared The properties shared across all polygons
|
|
150
|
+
*/
|
|
151
|
+
constructor(vertices: Vertex[], shared: any);
|
|
152
|
+
/**
|
|
153
|
+
* Clones, or makes a deep copy, or the polygon
|
|
154
|
+
*/
|
|
155
|
+
clone(): Polygon;
|
|
156
|
+
/**
|
|
157
|
+
* Flips the faces of the polygon
|
|
158
|
+
*/
|
|
159
|
+
flip(): void;
|
|
160
|
+
}
|
|
6
161
|
/**
|
|
7
162
|
* Class for building Constructive Solid Geometry
|
|
8
163
|
*/
|
|
@@ -28,6 +183,12 @@ export declare class CSG {
|
|
|
28
183
|
* Stores the scaling vector
|
|
29
184
|
*/
|
|
30
185
|
scaling: Vector3;
|
|
186
|
+
/**
|
|
187
|
+
* Convert a VertexData to CSG
|
|
188
|
+
* @param mesh defines the VertexData to convert to CSG
|
|
189
|
+
* @returns the new CSG
|
|
190
|
+
*/
|
|
191
|
+
static FromVertexData(data: VertexData): CSG;
|
|
31
192
|
/**
|
|
32
193
|
* Convert the Mesh to CSG
|
|
33
194
|
* @param mesh The Mesh to convert to CSG
|
|
@@ -96,6 +257,12 @@ export declare class CSG {
|
|
|
96
257
|
* @returns This CSG
|
|
97
258
|
*/
|
|
98
259
|
copyTransformAttributes(csg: CSG): CSG;
|
|
260
|
+
/**
|
|
261
|
+
* Build vertex data from CSG
|
|
262
|
+
* Coordinates here are in world space
|
|
263
|
+
* @returns the final vertex data
|
|
264
|
+
*/
|
|
265
|
+
toVertexData(onBeforePolygonProcessing?: Nullable<(polygon: Polygon) => void>, onAfterPolygonProcessing?: Nullable<() => void>): VertexData;
|
|
99
266
|
/**
|
|
100
267
|
* Build Raw mesh from CSG
|
|
101
268
|
* Coordinates here are in world space
|
|
@@ -115,3 +282,4 @@ export declare class CSG {
|
|
|
115
282
|
*/
|
|
116
283
|
toMesh(name: string, material?: Nullable<Material>, scene?: Scene, keepSubMeshes?: boolean): Mesh;
|
|
117
284
|
}
|
|
285
|
+
export {};
|
package/Meshes/csg.js
CHANGED
|
@@ -4,6 +4,7 @@ import { SubMesh } from "../Meshes/subMesh.js";
|
|
|
4
4
|
import { Mesh } from "../Meshes/mesh.js";
|
|
5
5
|
import { Color4 } from "../Maths/math.color.js";
|
|
6
6
|
|
|
7
|
+
import { VertexData } from "./mesh.vertexData.js";
|
|
7
8
|
/**
|
|
8
9
|
* Unique ID when we import meshes from Babylon to CSG
|
|
9
10
|
*/
|
|
@@ -379,6 +380,50 @@ export class CSG {
|
|
|
379
380
|
constructor() {
|
|
380
381
|
this._polygons = new Array();
|
|
381
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* Convert a VertexData to CSG
|
|
385
|
+
* @param mesh defines the VertexData to convert to CSG
|
|
386
|
+
* @returns the new CSG
|
|
387
|
+
*/
|
|
388
|
+
static FromVertexData(data) {
|
|
389
|
+
let vertex, polygon, vertices;
|
|
390
|
+
const polygons = new Array();
|
|
391
|
+
const indices = data.indices;
|
|
392
|
+
const positions = data.positions;
|
|
393
|
+
const normals = data.normals;
|
|
394
|
+
const uvs = data.uvs;
|
|
395
|
+
const vertColors = data.colors;
|
|
396
|
+
if (!indices || !positions) {
|
|
397
|
+
throw "BABYLON.CSG: VertexData must at least contain positions and indices";
|
|
398
|
+
}
|
|
399
|
+
for (let i = 0; i < indices.length; i += 3) {
|
|
400
|
+
vertices = [];
|
|
401
|
+
for (let j = 0; j < 3; j++) {
|
|
402
|
+
const indexIndices = i + j;
|
|
403
|
+
const offset = indices[indexIndices];
|
|
404
|
+
const normal = normals ? Vector3.FromArray(normals, offset * 3) : Vector3.Zero();
|
|
405
|
+
const uv = uvs ? Vector2.FromArray(uvs, offset * 2) : undefined;
|
|
406
|
+
const vertColor = vertColors ? Color4.FromArray(vertColors, offset * 4) : undefined;
|
|
407
|
+
const position = Vector3.FromArray(positions, offset * 3);
|
|
408
|
+
vertex = new Vertex(position, normal, uv, vertColor);
|
|
409
|
+
vertices.push(vertex);
|
|
410
|
+
}
|
|
411
|
+
polygon = new Polygon(vertices, { subMeshId: 0, meshId: currentCSGMeshId, materialIndex: 0 });
|
|
412
|
+
// To handle the case of degenerated triangle
|
|
413
|
+
// polygon.plane == null <=> the polygon does not represent 1 single plane <=> the triangle is degenerated
|
|
414
|
+
if (polygon.plane) {
|
|
415
|
+
polygons.push(polygon);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const csg = CSG._FromPolygons(polygons);
|
|
419
|
+
csg.matrix = Matrix.Identity();
|
|
420
|
+
csg.position = Vector3.Zero();
|
|
421
|
+
csg.rotation = Vector3.Zero();
|
|
422
|
+
csg.scaling = Vector3.One();
|
|
423
|
+
csg.rotationQuaternion = Quaternion.Identity();
|
|
424
|
+
currentCSGMeshId++;
|
|
425
|
+
return csg;
|
|
426
|
+
}
|
|
382
427
|
/**
|
|
383
428
|
* Convert the Mesh to CSG
|
|
384
429
|
* @param mesh The Mesh to convert to CSG
|
|
@@ -595,17 +640,14 @@ export class CSG {
|
|
|
595
640
|
return this;
|
|
596
641
|
}
|
|
597
642
|
/**
|
|
598
|
-
* Build
|
|
643
|
+
* Build vertex data from CSG
|
|
599
644
|
* Coordinates here are in world space
|
|
600
|
-
* @
|
|
601
|
-
* @param scene The Scene
|
|
602
|
-
* @param keepSubMeshes Specifies if the submeshes should be kept
|
|
603
|
-
* @returns A new Mesh
|
|
645
|
+
* @returns the final vertex data
|
|
604
646
|
*/
|
|
605
|
-
|
|
647
|
+
toVertexData(onBeforePolygonProcessing = null, onAfterPolygonProcessing = null) {
|
|
606
648
|
const matrix = this.matrix.clone();
|
|
607
649
|
matrix.invert();
|
|
608
|
-
const
|
|
650
|
+
const polygons = this._polygons;
|
|
609
651
|
const vertices = [];
|
|
610
652
|
const indices = [];
|
|
611
653
|
const normals = [];
|
|
@@ -615,39 +657,14 @@ export class CSG {
|
|
|
615
657
|
const normal = Vector3.Zero();
|
|
616
658
|
const uv = Vector2.Zero();
|
|
617
659
|
const vertColor = new Color4(0, 0, 0, 0);
|
|
618
|
-
const polygons = this._polygons;
|
|
619
660
|
const polygonIndices = [0, 0, 0];
|
|
620
|
-
let polygon;
|
|
621
661
|
const vertice_dict = {};
|
|
622
662
|
let vertex_idx;
|
|
623
|
-
let currentIndex = 0;
|
|
624
|
-
const subMeshDict = {};
|
|
625
|
-
let subMeshObj;
|
|
626
|
-
if (keepSubMeshes) {
|
|
627
|
-
// Sort Polygons, since subMeshes are indices range
|
|
628
|
-
polygons.sort((a, b) => {
|
|
629
|
-
if (a.shared.meshId === b.shared.meshId) {
|
|
630
|
-
return a.shared.subMeshId - b.shared.subMeshId;
|
|
631
|
-
}
|
|
632
|
-
else {
|
|
633
|
-
return a.shared.meshId - b.shared.meshId;
|
|
634
|
-
}
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
663
|
for (let i = 0, il = polygons.length; i < il; i++) {
|
|
638
|
-
polygon = polygons[i];
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
subMeshDict[polygon.shared.meshId] = {};
|
|
664
|
+
const polygon = polygons[i];
|
|
665
|
+
if (onBeforePolygonProcessing) {
|
|
666
|
+
onBeforePolygonProcessing(polygon);
|
|
642
667
|
}
|
|
643
|
-
if (!subMeshDict[polygon.shared.meshId][polygon.shared.subMeshId]) {
|
|
644
|
-
subMeshDict[polygon.shared.meshId][polygon.shared.subMeshId] = {
|
|
645
|
-
indexStart: +Infinity,
|
|
646
|
-
indexEnd: -Infinity,
|
|
647
|
-
materialIndex: polygon.shared.materialIndex,
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
subMeshObj = subMeshDict[polygon.shared.meshId][polygon.shared.subMeshId];
|
|
651
668
|
for (let j = 2, jl = polygon.vertices.length; j < jl; j++) {
|
|
652
669
|
polygonIndices[0] = 0;
|
|
653
670
|
polygonIndices[1] = j - 1;
|
|
@@ -700,21 +717,68 @@ export class CSG {
|
|
|
700
717
|
vertex_idx = vertice_dict[localVertex.x + "," + localVertex.y + "," + localVertex.z] = vertices.length / 3 - 1;
|
|
701
718
|
}
|
|
702
719
|
indices.push(vertex_idx);
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
720
|
+
if (onAfterPolygonProcessing) {
|
|
721
|
+
onAfterPolygonProcessing();
|
|
722
|
+
}
|
|
706
723
|
}
|
|
707
724
|
}
|
|
708
725
|
}
|
|
709
|
-
|
|
710
|
-
|
|
726
|
+
const result = new VertexData();
|
|
727
|
+
result.positions = vertices;
|
|
728
|
+
result.normals = normals;
|
|
711
729
|
if (uvs) {
|
|
712
|
-
|
|
730
|
+
result.uvs = uvs;
|
|
713
731
|
}
|
|
714
732
|
if (vertColors) {
|
|
715
|
-
|
|
733
|
+
result.colors = vertColors;
|
|
734
|
+
}
|
|
735
|
+
result.indices = indices;
|
|
736
|
+
return result;
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Build Raw mesh from CSG
|
|
740
|
+
* Coordinates here are in world space
|
|
741
|
+
* @param name The name of the mesh geometry
|
|
742
|
+
* @param scene The Scene
|
|
743
|
+
* @param keepSubMeshes Specifies if the submeshes should be kept
|
|
744
|
+
* @returns A new Mesh
|
|
745
|
+
*/
|
|
746
|
+
buildMeshGeometry(name, scene, keepSubMeshes) {
|
|
747
|
+
const mesh = new Mesh(name, scene);
|
|
748
|
+
const polygons = this._polygons;
|
|
749
|
+
let currentIndex = 0;
|
|
750
|
+
const subMeshDict = {};
|
|
751
|
+
let subMeshObj;
|
|
752
|
+
if (keepSubMeshes) {
|
|
753
|
+
// Sort Polygons, since subMeshes are indices range
|
|
754
|
+
polygons.sort((a, b) => {
|
|
755
|
+
if (a.shared.meshId === b.shared.meshId) {
|
|
756
|
+
return a.shared.subMeshId - b.shared.subMeshId;
|
|
757
|
+
}
|
|
758
|
+
else {
|
|
759
|
+
return a.shared.meshId - b.shared.meshId;
|
|
760
|
+
}
|
|
761
|
+
});
|
|
716
762
|
}
|
|
717
|
-
|
|
763
|
+
const vertexData = this.toVertexData((polygon) => {
|
|
764
|
+
// Building SubMeshes
|
|
765
|
+
if (!subMeshDict[polygon.shared.meshId]) {
|
|
766
|
+
subMeshDict[polygon.shared.meshId] = {};
|
|
767
|
+
}
|
|
768
|
+
if (!subMeshDict[polygon.shared.meshId][polygon.shared.subMeshId]) {
|
|
769
|
+
subMeshDict[polygon.shared.meshId][polygon.shared.subMeshId] = {
|
|
770
|
+
indexStart: +Infinity,
|
|
771
|
+
indexEnd: -Infinity,
|
|
772
|
+
materialIndex: polygon.shared.materialIndex,
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
subMeshObj = subMeshDict[polygon.shared.meshId][polygon.shared.subMeshId];
|
|
776
|
+
}, () => {
|
|
777
|
+
subMeshObj.indexStart = Math.min(currentIndex, subMeshObj.indexStart);
|
|
778
|
+
subMeshObj.indexEnd = Math.max(currentIndex, subMeshObj.indexEnd);
|
|
779
|
+
currentIndex++;
|
|
780
|
+
});
|
|
781
|
+
vertexData.applyToMesh(mesh);
|
|
718
782
|
if (keepSubMeshes) {
|
|
719
783
|
// We offset the materialIndex by the previous number of materials in the CSG mixed meshes
|
|
720
784
|
let materialIndexOffset = 0, materialMaxIndex;
|