@babylonjs/core 5.28.0 → 5.29.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/Actions/actionManager.js +2 -0
- package/Actions/actionManager.js.map +1 -1
- package/Cameras/camera.js +4 -4
- package/Cameras/camera.js.map +1 -1
- package/Collisions/pickingInfo.d.ts +0 -2
- package/Collisions/pickingInfo.js +0 -2
- package/Collisions/pickingInfo.js.map +1 -1
- package/Culling/ray.js +5 -0
- package/Culling/ray.js.map +1 -1
- package/Engines/Extensions/engine.videoTexture.js +6 -3
- package/Engines/Extensions/engine.videoTexture.js.map +1 -1
- package/Engines/renderTargetWrapper.d.ts +2 -1
- package/Engines/renderTargetWrapper.js +1 -0
- package/Engines/renderTargetWrapper.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Events/pointerEvents.d.ts +11 -6
- package/Events/pointerEvents.js +24 -6
- package/Events/pointerEvents.js.map +1 -1
- package/Inputs/scene.inputManager.d.ts +9 -1
- package/Inputs/scene.inputManager.js +76 -37
- package/Inputs/scene.inputManager.js.map +1 -1
- package/Layers/effectLayer.js +2 -6
- package/Layers/effectLayer.js.map +1 -1
- package/Materials/PBR/pbrMetallicRoughnessMaterial.d.ts +1 -1
- package/Materials/PBR/pbrMetallicRoughnessMaterial.js +1 -1
- package/Materials/PBR/pbrMetallicRoughnessMaterial.js.map +1 -1
- package/Materials/Textures/htmlElementTexture.d.ts +5 -0
- package/Materials/Textures/htmlElementTexture.js +4 -1
- package/Materials/Textures/htmlElementTexture.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.d.ts +1 -1
- package/Materials/Textures/renderTargetTexture.js +2 -2
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/Textures/videoTexture.d.ts +6 -1
- package/Materials/Textures/videoTexture.js +7 -2
- package/Materials/Textures/videoTexture.js.map +1 -1
- package/Maths/math.vector.d.ts +390 -319
- package/Maths/math.vector.js +298 -153
- package/Maths/math.vector.js.map +1 -1
- package/Meshes/Builders/decalBuilder.d.ts +8 -0
- package/Meshes/Builders/decalBuilder.js +270 -51
- package/Meshes/Builders/decalBuilder.js.map +1 -1
- package/Meshes/mesh.js +40 -0
- package/Meshes/mesh.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.d.ts +14 -8
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js +16 -6
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js.map +1 -1
- package/PostProcesses/blurPostProcess.d.ts +2 -1
- package/PostProcesses/blurPostProcess.js +3 -2
- package/PostProcesses/blurPostProcess.js.map +1 -1
- package/PostProcesses/circleOfConfusionPostProcess.js +2 -1
- package/PostProcesses/circleOfConfusionPostProcess.js.map +1 -1
- package/PostProcesses/depthOfFieldBlurPostProcess.d.ts +2 -1
- package/PostProcesses/depthOfFieldBlurPostProcess.js +3 -5
- package/PostProcesses/depthOfFieldBlurPostProcess.js.map +1 -1
- package/PostProcesses/depthOfFieldEffect.js +9 -4
- package/PostProcesses/depthOfFieldEffect.js.map +1 -1
- package/PostProcesses/depthOfFieldMergePostProcess.js.map +1 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.js +2 -6
- package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
- package/Rendering/depthRenderer.js +2 -6
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js +2 -6
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Rendering/renderingGroup.d.ts +4 -0
- package/Rendering/renderingGroup.js +7 -1
- package/Rendering/renderingGroup.js.map +1 -1
- package/Rendering/renderingManager.d.ts +5 -0
- package/Rendering/renderingManager.js +15 -0
- package/Rendering/renderingManager.js.map +1 -1
- package/Shaders/circleOfConfusion.fragment.js +1 -1
- package/Shaders/circleOfConfusion.fragment.js.map +1 -1
- package/Shaders/depthOfFieldMerge.fragment.js +1 -1
- package/Shaders/depthOfFieldMerge.fragment.js.map +1 -1
- package/Shaders/kernelBlur.fragment.js +2 -2
- package/Shaders/kernelBlur.fragment.js.map +1 -1
- package/XR/webXRRenderTargetTextureProvider.js +1 -0
- package/XR/webXRRenderTargetTextureProvider.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +5 -0
- package/scene.js +10 -6
- package/scene.js.map +1 -1
|
@@ -9,6 +9,10 @@ import type { AbstractMesh } from "../abstractMesh";
|
|
|
9
9
|
* * The parameter `size` (Vector3, default `(1, 1, 1)`) sets the decal scaling
|
|
10
10
|
* * The parameter `angle` (float in radian, default 0) sets the angle to rotate the decal
|
|
11
11
|
* * The parameter `captureUVS` defines if we need to capture the uvs or compute them
|
|
12
|
+
* * The parameter `cullBackFaces` defines if the back faces should be removed from the decal mesh
|
|
13
|
+
* * The parameter `localMode` defines that the computations should be done with the local mesh coordinates instead of the world space coordinates.
|
|
14
|
+
* * Use this mode if you want the decal to be parented to the sourceMesh and move/rotate with it.
|
|
15
|
+
* Note: Meshes with morph targets are not supported!
|
|
12
16
|
* @param name defines the name of the mesh
|
|
13
17
|
* @param sourceMesh defines the mesh where the decal must be applied
|
|
14
18
|
* @param options defines the options used to create the mesh
|
|
@@ -17,6 +21,8 @@ import type { AbstractMesh } from "../abstractMesh";
|
|
|
17
21
|
* @param options.size
|
|
18
22
|
* @param options.angle
|
|
19
23
|
* @param options.captureUVS
|
|
24
|
+
* @param options.cullBackFaces
|
|
25
|
+
* @param options.localMode
|
|
20
26
|
* @returns the decal mesh
|
|
21
27
|
* @see https://doc.babylonjs.com/how_to/decals
|
|
22
28
|
*/
|
|
@@ -26,6 +32,8 @@ export declare function CreateDecal(name: string, sourceMesh: AbstractMesh, opti
|
|
|
26
32
|
size?: Vector3;
|
|
27
33
|
angle?: number;
|
|
28
34
|
captureUVS?: boolean;
|
|
35
|
+
cullBackFaces?: boolean;
|
|
36
|
+
localMode?: boolean;
|
|
29
37
|
}): Mesh;
|
|
30
38
|
/**
|
|
31
39
|
* Class containing static functions to help procedurally build meshes
|
|
@@ -1,9 +1,33 @@
|
|
|
1
1
|
import { Vector3, Matrix, Vector2 } from "../../Maths/math.vector.js";
|
|
2
|
+
import { Scalar } from "../../Maths/math.scalar.js";
|
|
2
3
|
import { Mesh } from "../mesh.js";
|
|
3
4
|
import { VertexBuffer } from "../../Buffers/buffer.js";
|
|
4
5
|
import { VertexData } from "../mesh.vertexData.js";
|
|
5
|
-
import { PositionNormalTextureVertex } from "../../Maths/math.vertexFormat.js";
|
|
6
6
|
import { CompatibilityOptions } from "../../Compat/compatibilityOptions.js";
|
|
7
|
+
const xpAxis = new Vector3(1, 0, 0);
|
|
8
|
+
const xnAxis = new Vector3(-1, 0, 0);
|
|
9
|
+
const ypAxis = new Vector3(0, 1, 0);
|
|
10
|
+
const ynAxis = new Vector3(0, -1, 0);
|
|
11
|
+
const zpAxis = new Vector3(0, 0, 1);
|
|
12
|
+
const znAxis = new Vector3(0, 0, -1);
|
|
13
|
+
/** @internal */
|
|
14
|
+
class DecalVertex {
|
|
15
|
+
constructor(position = Vector3.Zero(), normal = Vector3.Up(), uv = Vector2.Zero(), vertexIdx = 0, vertexIdxForBones = 0, localPositionOverride = null, localNormalOverride = null, matrixIndicesOverride = null, matrixWeightsOverride = null) {
|
|
16
|
+
this.position = position;
|
|
17
|
+
this.normal = normal;
|
|
18
|
+
this.uv = uv;
|
|
19
|
+
this.vertexIdx = vertexIdx;
|
|
20
|
+
this.vertexIdxForBones = vertexIdxForBones;
|
|
21
|
+
this.localPositionOverride = localPositionOverride;
|
|
22
|
+
this.localNormalOverride = localNormalOverride;
|
|
23
|
+
this.matrixIndicesOverride = matrixIndicesOverride;
|
|
24
|
+
this.matrixWeightsOverride = matrixWeightsOverride;
|
|
25
|
+
}
|
|
26
|
+
clone() {
|
|
27
|
+
var _a, _b, _c, _d;
|
|
28
|
+
return new DecalVertex(this.position.clone(), this.normal.clone(), this.uv.clone(), this.vertexIdx, this.vertexIdxForBones, (_a = this.localPositionOverride) === null || _a === void 0 ? void 0 : _a.slice(), (_b = this.localNormalOverride) === null || _b === void 0 ? void 0 : _b.slice(), (_c = this.matrixIndicesOverride) === null || _c === void 0 ? void 0 : _c.slice(), (_d = this.matrixWeightsOverride) === null || _d === void 0 ? void 0 : _d.slice());
|
|
29
|
+
}
|
|
30
|
+
}
|
|
7
31
|
/**
|
|
8
32
|
* Creates a decal mesh.
|
|
9
33
|
* A decal is a mesh usually applied as a model onto the surface of another mesh. So don't forget the parameter `sourceMesh` depicting the decal
|
|
@@ -12,6 +36,10 @@ import { CompatibilityOptions } from "../../Compat/compatibilityOptions.js";
|
|
|
12
36
|
* * The parameter `size` (Vector3, default `(1, 1, 1)`) sets the decal scaling
|
|
13
37
|
* * The parameter `angle` (float in radian, default 0) sets the angle to rotate the decal
|
|
14
38
|
* * The parameter `captureUVS` defines if we need to capture the uvs or compute them
|
|
39
|
+
* * The parameter `cullBackFaces` defines if the back faces should be removed from the decal mesh
|
|
40
|
+
* * The parameter `localMode` defines that the computations should be done with the local mesh coordinates instead of the world space coordinates.
|
|
41
|
+
* * Use this mode if you want the decal to be parented to the sourceMesh and move/rotate with it.
|
|
42
|
+
* Note: Meshes with morph targets are not supported!
|
|
15
43
|
* @param name defines the name of the mesh
|
|
16
44
|
* @param sourceMesh defines the mesh where the decal must be applied
|
|
17
45
|
* @param options defines the options used to create the mesh
|
|
@@ -20,14 +48,25 @@ import { CompatibilityOptions } from "../../Compat/compatibilityOptions.js";
|
|
|
20
48
|
* @param options.size
|
|
21
49
|
* @param options.angle
|
|
22
50
|
* @param options.captureUVS
|
|
51
|
+
* @param options.cullBackFaces
|
|
52
|
+
* @param options.localMode
|
|
23
53
|
* @returns the decal mesh
|
|
24
54
|
* @see https://doc.babylonjs.com/how_to/decals
|
|
25
55
|
*/
|
|
26
56
|
export function CreateDecal(name, sourceMesh, options) {
|
|
57
|
+
const hasSkeleton = !!sourceMesh.skeleton;
|
|
58
|
+
const useLocalComputation = options.localMode || hasSkeleton;
|
|
59
|
+
const meshHasOverridenMaterial = sourceMesh.overrideMaterialSideOrientation !== null && sourceMesh.overrideMaterialSideOrientation !== undefined;
|
|
27
60
|
const indices = sourceMesh.getIndices();
|
|
28
|
-
const positions = sourceMesh.getVerticesData(VertexBuffer.PositionKind);
|
|
29
|
-
const normals = sourceMesh.getVerticesData(VertexBuffer.NormalKind);
|
|
61
|
+
const positions = hasSkeleton ? sourceMesh.getPositionData(true, true) : sourceMesh.getVerticesData(VertexBuffer.PositionKind);
|
|
62
|
+
const normals = hasSkeleton ? sourceMesh.getNormalsData(true, true) : sourceMesh.getVerticesData(VertexBuffer.NormalKind);
|
|
63
|
+
const localPositions = useLocalComputation ? (hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.PositionKind) : positions) : null;
|
|
64
|
+
const localNormals = useLocalComputation ? (hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.NormalKind) : normals) : null;
|
|
30
65
|
const uvs = sourceMesh.getVerticesData(VertexBuffer.UVKind);
|
|
66
|
+
const matIndices = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesIndicesKind) : null;
|
|
67
|
+
const matWeights = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesWeightsKind) : null;
|
|
68
|
+
const matIndicesExtra = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesIndicesExtraKind) : null;
|
|
69
|
+
const matWeightsExtra = hasSkeleton ? sourceMesh.getVerticesData(VertexBuffer.MatricesWeightsExtraKind) : null;
|
|
31
70
|
const position = options.position || Vector3.Zero();
|
|
32
71
|
let normal = options.normal || Vector3.Up();
|
|
33
72
|
const size = options.size || Vector3.One();
|
|
@@ -52,35 +91,111 @@ export function CreateDecal(name, sourceMesh, options) {
|
|
|
52
91
|
vertexData.positions = [];
|
|
53
92
|
vertexData.normals = [];
|
|
54
93
|
vertexData.uvs = [];
|
|
94
|
+
vertexData.matricesIndices = hasSkeleton ? [] : null;
|
|
95
|
+
vertexData.matricesWeights = hasSkeleton ? [] : null;
|
|
96
|
+
vertexData.matricesIndicesExtra = matIndicesExtra ? [] : null;
|
|
97
|
+
vertexData.matricesWeightsExtra = matWeightsExtra ? [] : null;
|
|
55
98
|
let currentVertexDataIndex = 0;
|
|
56
99
|
const extractDecalVector3 = (indexId) => {
|
|
57
|
-
const result = new
|
|
100
|
+
const result = new DecalVertex();
|
|
58
101
|
if (!indices || !positions || !normals) {
|
|
59
102
|
return result;
|
|
60
103
|
}
|
|
61
104
|
const vertexId = indices[indexId];
|
|
62
|
-
result.
|
|
105
|
+
result.vertexIdx = vertexId * 3;
|
|
106
|
+
result.vertexIdxForBones = vertexId * 4;
|
|
63
107
|
// Send vector to decal local world
|
|
64
|
-
result.position = Vector3
|
|
108
|
+
result.position = new Vector3(positions[vertexId * 3], positions[vertexId * 3 + 1], positions[vertexId * 3 + 2]);
|
|
109
|
+
Vector3.TransformCoordinatesToRef(result.position, transformMatrix, result.position);
|
|
65
110
|
// Get normal
|
|
66
111
|
result.normal = new Vector3(normals[vertexId * 3], normals[vertexId * 3 + 1], normals[vertexId * 3 + 2]);
|
|
67
|
-
|
|
112
|
+
Vector3.TransformNormalToRef(result.normal, transformMatrix, result.normal);
|
|
68
113
|
if (options.captureUVS && uvs) {
|
|
69
114
|
const v = uvs[vertexId * 2 + 1];
|
|
70
115
|
result.uv = new Vector2(uvs[vertexId * 2], CompatibilityOptions.UseOpenGLOrientationForUV ? 1 - v : v);
|
|
71
116
|
}
|
|
72
117
|
return result;
|
|
73
|
-
};
|
|
118
|
+
};
|
|
119
|
+
const emptyArray = [0, 0, 0, 0];
|
|
120
|
+
// Inspired by https://github.com/mrdoob/three.js/blob/eee231960882f6f3b6113405f524956145148146/examples/js/geometries/DecalGeometry.js
|
|
74
121
|
const clip = (vertices, axis) => {
|
|
75
122
|
if (vertices.length === 0) {
|
|
76
123
|
return vertices;
|
|
77
124
|
}
|
|
78
125
|
const clipSize = 0.5 * Math.abs(Vector3.Dot(size, axis));
|
|
126
|
+
const indexOf = (arr, val, start, num) => {
|
|
127
|
+
for (let i = 0; i < num; ++i) {
|
|
128
|
+
if (arr[start + i] === val) {
|
|
129
|
+
return start + i;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return -1;
|
|
133
|
+
};
|
|
79
134
|
const clipVertices = (v0, v1) => {
|
|
135
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
80
136
|
const clipFactor = Vector3.GetClipFactor(v0.position, v1.position, axis, clipSize);
|
|
81
|
-
|
|
137
|
+
let indices = emptyArray;
|
|
138
|
+
let weights = emptyArray;
|
|
139
|
+
if (matIndices && matWeights) {
|
|
140
|
+
const mat0Index = v0.matrixIndicesOverride ? 0 : v0.vertexIdxForBones;
|
|
141
|
+
const v0Indices = (_a = v0.matrixIndicesOverride) !== null && _a !== void 0 ? _a : matIndices;
|
|
142
|
+
const v0Weights = (_b = v0.matrixWeightsOverride) !== null && _b !== void 0 ? _b : matWeights;
|
|
143
|
+
const mat1Index = v1.matrixIndicesOverride ? 0 : v1.vertexIdxForBones;
|
|
144
|
+
const v1Indices = (_c = v1.matrixIndicesOverride) !== null && _c !== void 0 ? _c : matIndices;
|
|
145
|
+
const v1Weights = (_d = v1.matrixWeightsOverride) !== null && _d !== void 0 ? _d : matWeights;
|
|
146
|
+
indices = [0, 0, 0, 0];
|
|
147
|
+
weights = [0, 0, 0, 0];
|
|
148
|
+
let index = 0;
|
|
149
|
+
for (let i = 0; i < 4; ++i) {
|
|
150
|
+
if (v0Weights[mat0Index + i] > 0) {
|
|
151
|
+
const idx = indexOf(v1Indices, v0Indices[mat0Index + i], mat1Index, 4);
|
|
152
|
+
indices[index] = v0Indices[mat0Index + i];
|
|
153
|
+
weights[index] = Scalar.Lerp(v0Weights[mat0Index + i], idx >= 0 ? v1Weights[idx] : 0, clipFactor);
|
|
154
|
+
index++;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
for (let i = 0; i < 4 && index < 4; ++i) {
|
|
158
|
+
const ind = v1Indices[mat1Index + i];
|
|
159
|
+
if (indexOf(v0Indices, ind, mat0Index, 4) !== -1)
|
|
160
|
+
continue;
|
|
161
|
+
indices[index] = ind;
|
|
162
|
+
weights[index] = Scalar.Lerp(0, v1Weights[mat1Index + i], clipFactor);
|
|
163
|
+
index++;
|
|
164
|
+
}
|
|
165
|
+
const sumw = weights[0] + weights[1] + weights[2] + weights[3];
|
|
166
|
+
weights[0] /= sumw;
|
|
167
|
+
weights[1] /= sumw;
|
|
168
|
+
weights[2] /= sumw;
|
|
169
|
+
weights[3] /= sumw;
|
|
170
|
+
}
|
|
171
|
+
const v0LocalPositionX = v0.localPositionOverride ? v0.localPositionOverride[0] : (_e = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v0.vertexIdx]) !== null && _e !== void 0 ? _e : 0;
|
|
172
|
+
const v0LocalPositionY = v0.localPositionOverride ? v0.localPositionOverride[1] : (_f = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v0.vertexIdx + 1]) !== null && _f !== void 0 ? _f : 0;
|
|
173
|
+
const v0LocalPositionZ = v0.localPositionOverride ? v0.localPositionOverride[2] : (_g = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v0.vertexIdx + 2]) !== null && _g !== void 0 ? _g : 0;
|
|
174
|
+
const v1LocalPositionX = v1.localPositionOverride ? v1.localPositionOverride[0] : (_h = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v1.vertexIdx]) !== null && _h !== void 0 ? _h : 0;
|
|
175
|
+
const v1LocalPositionY = v1.localPositionOverride ? v1.localPositionOverride[1] : (_j = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v1.vertexIdx + 1]) !== null && _j !== void 0 ? _j : 0;
|
|
176
|
+
const v1LocalPositionZ = v1.localPositionOverride ? v1.localPositionOverride[2] : (_k = localPositions === null || localPositions === void 0 ? void 0 : localPositions[v1.vertexIdx + 2]) !== null && _k !== void 0 ? _k : 0;
|
|
177
|
+
const v0LocalNormalX = v0.localNormalOverride ? v0.localNormalOverride[0] : (_l = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v0.vertexIdx]) !== null && _l !== void 0 ? _l : 0;
|
|
178
|
+
const v0LocalNormalY = v0.localNormalOverride ? v0.localNormalOverride[1] : (_m = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v0.vertexIdx + 1]) !== null && _m !== void 0 ? _m : 0;
|
|
179
|
+
const v0LocalNormalZ = v0.localNormalOverride ? v0.localNormalOverride[2] : (_o = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v0.vertexIdx + 2]) !== null && _o !== void 0 ? _o : 0;
|
|
180
|
+
const v1LocalNormalX = v1.localNormalOverride ? v1.localNormalOverride[0] : (_p = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v1.vertexIdx]) !== null && _p !== void 0 ? _p : 0;
|
|
181
|
+
const v1LocalNormalY = v1.localNormalOverride ? v1.localNormalOverride[1] : (_q = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v1.vertexIdx + 1]) !== null && _q !== void 0 ? _q : 0;
|
|
182
|
+
const v1LocalNormalZ = v1.localNormalOverride ? v1.localNormalOverride[2] : (_r = localNormals === null || localNormals === void 0 ? void 0 : localNormals[v1.vertexIdx + 2]) !== null && _r !== void 0 ? _r : 0;
|
|
183
|
+
const interpNormalX = v0LocalNormalX + (v1LocalNormalX - v0LocalNormalX) * clipFactor;
|
|
184
|
+
const interpNormalY = v0LocalNormalY + (v1LocalNormalY - v0LocalNormalY) * clipFactor;
|
|
185
|
+
const interpNormalZ = v0LocalNormalZ + (v1LocalNormalZ - v0LocalNormalZ) * clipFactor;
|
|
186
|
+
const norm = Math.sqrt(interpNormalX * interpNormalX + interpNormalY * interpNormalY + interpNormalZ * interpNormalZ);
|
|
187
|
+
return new DecalVertex(Vector3.Lerp(v0.position, v1.position, clipFactor), Vector3.Lerp(v0.normal, v1.normal, clipFactor).normalize(), Vector2.Lerp(v0.uv, v1.uv, clipFactor), -1, -1, localPositions
|
|
188
|
+
? [
|
|
189
|
+
v0LocalPositionX + (v1LocalPositionX - v0LocalPositionX) * clipFactor,
|
|
190
|
+
v0LocalPositionY + (v1LocalPositionY - v0LocalPositionY) * clipFactor,
|
|
191
|
+
v0LocalPositionZ + (v1LocalPositionZ - v0LocalPositionZ) * clipFactor,
|
|
192
|
+
]
|
|
193
|
+
: null, localNormals ? [interpNormalX / norm, interpNormalY / norm, interpNormalZ / norm] : null, indices, weights);
|
|
82
194
|
};
|
|
83
|
-
|
|
195
|
+
let clipResult = null;
|
|
196
|
+
if (vertices.length > 3) {
|
|
197
|
+
clipResult = new Array();
|
|
198
|
+
}
|
|
84
199
|
for (let index = 0; index < vertices.length; index += 3) {
|
|
85
200
|
let total = 0;
|
|
86
201
|
let nV1 = null;
|
|
@@ -96,11 +211,17 @@ export function CreateDecal(name, sourceMesh, options) {
|
|
|
96
211
|
total = (v1Out ? 1 : 0) + (v2Out ? 1 : 0) + (v3Out ? 1 : 0);
|
|
97
212
|
switch (total) {
|
|
98
213
|
case 0:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
214
|
+
if (vertices.length > 3) {
|
|
215
|
+
clipResult.push(vertices[index]);
|
|
216
|
+
clipResult.push(vertices[index + 1]);
|
|
217
|
+
clipResult.push(vertices[index + 2]);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
clipResult = vertices;
|
|
221
|
+
}
|
|
102
222
|
break;
|
|
103
223
|
case 1:
|
|
224
|
+
clipResult = clipResult !== null && clipResult !== void 0 ? clipResult : new Array();
|
|
104
225
|
if (v1Out) {
|
|
105
226
|
nV1 = vertices[index + 1];
|
|
106
227
|
nV2 = vertices[index + 2];
|
|
@@ -112,12 +233,12 @@ export function CreateDecal(name, sourceMesh, options) {
|
|
|
112
233
|
nV2 = vertices[index + 2];
|
|
113
234
|
nV3 = clipVertices(vertices[index + 1], nV1);
|
|
114
235
|
nV4 = clipVertices(vertices[index + 1], nV2);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
236
|
+
clipResult.push(nV3);
|
|
237
|
+
clipResult.push(nV2.clone());
|
|
238
|
+
clipResult.push(nV1.clone());
|
|
239
|
+
clipResult.push(nV2.clone());
|
|
240
|
+
clipResult.push(nV3.clone());
|
|
241
|
+
clipResult.push(nV4);
|
|
121
242
|
break;
|
|
122
243
|
}
|
|
123
244
|
if (v3Out) {
|
|
@@ -127,68 +248,158 @@ export function CreateDecal(name, sourceMesh, options) {
|
|
|
127
248
|
nV4 = clipVertices(vertices[index + 2], nV2);
|
|
128
249
|
}
|
|
129
250
|
if (nV1 && nV2 && nV3 && nV4) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
251
|
+
clipResult.push(nV1.clone());
|
|
252
|
+
clipResult.push(nV2.clone());
|
|
253
|
+
clipResult.push(nV3);
|
|
254
|
+
clipResult.push(nV4);
|
|
255
|
+
clipResult.push(nV3.clone());
|
|
256
|
+
clipResult.push(nV2.clone());
|
|
136
257
|
}
|
|
137
258
|
break;
|
|
138
259
|
case 2:
|
|
260
|
+
clipResult = clipResult !== null && clipResult !== void 0 ? clipResult : new Array();
|
|
139
261
|
if (!v1Out) {
|
|
140
262
|
nV1 = vertices[index].clone();
|
|
141
263
|
nV2 = clipVertices(nV1, vertices[index + 1]);
|
|
142
264
|
nV3 = clipVertices(nV1, vertices[index + 2]);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
265
|
+
clipResult.push(nV1);
|
|
266
|
+
clipResult.push(nV2);
|
|
267
|
+
clipResult.push(nV3);
|
|
146
268
|
}
|
|
147
269
|
if (!v2Out) {
|
|
148
270
|
nV1 = vertices[index + 1].clone();
|
|
149
271
|
nV2 = clipVertices(nV1, vertices[index + 2]);
|
|
150
272
|
nV3 = clipVertices(nV1, vertices[index]);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
273
|
+
clipResult.push(nV1);
|
|
274
|
+
clipResult.push(nV2);
|
|
275
|
+
clipResult.push(nV3);
|
|
154
276
|
}
|
|
155
277
|
if (!v3Out) {
|
|
156
278
|
nV1 = vertices[index + 2].clone();
|
|
157
279
|
nV2 = clipVertices(nV1, vertices[index]);
|
|
158
280
|
nV3 = clipVertices(nV1, vertices[index + 1]);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
281
|
+
clipResult.push(nV1);
|
|
282
|
+
clipResult.push(nV2);
|
|
283
|
+
clipResult.push(nV3);
|
|
162
284
|
}
|
|
163
285
|
break;
|
|
164
286
|
case 3:
|
|
165
287
|
break;
|
|
166
288
|
}
|
|
167
289
|
}
|
|
168
|
-
return
|
|
290
|
+
return clipResult;
|
|
169
291
|
};
|
|
292
|
+
const oneFaceVertices = new Array(3);
|
|
170
293
|
for (let index = 0; index < indices.length; index += 3) {
|
|
171
|
-
let faceVertices =
|
|
172
|
-
faceVertices
|
|
173
|
-
|
|
174
|
-
|
|
294
|
+
let faceVertices = oneFaceVertices;
|
|
295
|
+
faceVertices[0] = extractDecalVector3(index);
|
|
296
|
+
if (meshHasOverridenMaterial && useLocalComputation) {
|
|
297
|
+
faceVertices[1] = extractDecalVector3(index + 2);
|
|
298
|
+
faceVertices[2] = extractDecalVector3(index + 1);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
faceVertices[1] = extractDecalVector3(index + 1);
|
|
302
|
+
faceVertices[2] = extractDecalVector3(index + 2);
|
|
303
|
+
}
|
|
304
|
+
if (options.cullBackFaces) {
|
|
305
|
+
// If all the normals of the vertices of the face are pointing away from the view direction we discard the face.
|
|
306
|
+
// As computations are done in the decal coordinate space, the viewDirection is (0,0,1), so when dot(vertexNormal, -viewDirection) <= 0 the vertex is culled
|
|
307
|
+
if (-faceVertices[0].normal.z <= 0 && -faceVertices[1].normal.z <= 0 && -faceVertices[2].normal.z <= 0) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
175
311
|
// Clip
|
|
176
|
-
faceVertices = clip(faceVertices,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
faceVertices = clip(faceVertices,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
312
|
+
faceVertices = clip(faceVertices, xpAxis);
|
|
313
|
+
if (!faceVertices)
|
|
314
|
+
continue;
|
|
315
|
+
faceVertices = clip(faceVertices, xnAxis);
|
|
316
|
+
if (!faceVertices)
|
|
317
|
+
continue;
|
|
318
|
+
faceVertices = clip(faceVertices, ypAxis);
|
|
319
|
+
if (!faceVertices)
|
|
320
|
+
continue;
|
|
321
|
+
faceVertices = clip(faceVertices, ynAxis);
|
|
322
|
+
if (!faceVertices)
|
|
323
|
+
continue;
|
|
324
|
+
faceVertices = clip(faceVertices, zpAxis);
|
|
325
|
+
if (!faceVertices)
|
|
326
|
+
continue;
|
|
327
|
+
faceVertices = clip(faceVertices, znAxis);
|
|
328
|
+
if (!faceVertices)
|
|
183
329
|
continue;
|
|
184
|
-
}
|
|
185
330
|
// Add UVs and get back to world
|
|
186
331
|
for (let vIndex = 0; vIndex < faceVertices.length; vIndex++) {
|
|
187
332
|
const vertex = faceVertices[vIndex];
|
|
188
333
|
//TODO check for Int32Array | Uint32Array | Uint16Array
|
|
189
334
|
vertexData.indices.push(currentVertexDataIndex);
|
|
190
|
-
|
|
191
|
-
|
|
335
|
+
if (useLocalComputation) {
|
|
336
|
+
if (vertex.localPositionOverride) {
|
|
337
|
+
vertexData.positions[currentVertexDataIndex * 3] = vertex.localPositionOverride[0];
|
|
338
|
+
vertexData.positions[currentVertexDataIndex * 3 + 1] = vertex.localPositionOverride[1];
|
|
339
|
+
vertexData.positions[currentVertexDataIndex * 3 + 2] = vertex.localPositionOverride[2];
|
|
340
|
+
}
|
|
341
|
+
else if (localPositions) {
|
|
342
|
+
vertexData.positions[currentVertexDataIndex * 3] = localPositions[vertex.vertexIdx];
|
|
343
|
+
vertexData.positions[currentVertexDataIndex * 3 + 1] = localPositions[vertex.vertexIdx + 1];
|
|
344
|
+
vertexData.positions[currentVertexDataIndex * 3 + 2] = localPositions[vertex.vertexIdx + 2];
|
|
345
|
+
}
|
|
346
|
+
if (vertex.localNormalOverride) {
|
|
347
|
+
vertexData.normals[currentVertexDataIndex * 3] = vertex.localNormalOverride[0];
|
|
348
|
+
vertexData.normals[currentVertexDataIndex * 3 + 1] = vertex.localNormalOverride[1];
|
|
349
|
+
vertexData.normals[currentVertexDataIndex * 3 + 2] = vertex.localNormalOverride[2];
|
|
350
|
+
}
|
|
351
|
+
else if (localNormals) {
|
|
352
|
+
vertexData.normals[currentVertexDataIndex * 3] = localNormals[vertex.vertexIdx];
|
|
353
|
+
vertexData.normals[currentVertexDataIndex * 3 + 1] = localNormals[vertex.vertexIdx + 1];
|
|
354
|
+
vertexData.normals[currentVertexDataIndex * 3 + 2] = localNormals[vertex.vertexIdx + 2];
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
vertex.position.toArray(vertexData.positions, currentVertexDataIndex * 3);
|
|
359
|
+
vertex.normal.toArray(vertexData.normals, currentVertexDataIndex * 3);
|
|
360
|
+
}
|
|
361
|
+
if (vertexData.matricesIndices && vertexData.matricesWeights) {
|
|
362
|
+
if (vertex.matrixIndicesOverride) {
|
|
363
|
+
vertexData.matricesIndices[currentVertexDataIndex * 4] = vertex.matrixIndicesOverride[0];
|
|
364
|
+
vertexData.matricesIndices[currentVertexDataIndex * 4 + 1] = vertex.matrixIndicesOverride[1];
|
|
365
|
+
vertexData.matricesIndices[currentVertexDataIndex * 4 + 2] = vertex.matrixIndicesOverride[2];
|
|
366
|
+
vertexData.matricesIndices[currentVertexDataIndex * 4 + 3] = vertex.matrixIndicesOverride[3];
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
if (matIndices) {
|
|
370
|
+
vertexData.matricesIndices[currentVertexDataIndex * 4] = matIndices[vertex.vertexIdxForBones];
|
|
371
|
+
vertexData.matricesIndices[currentVertexDataIndex * 4 + 1] = matIndices[vertex.vertexIdxForBones + 1];
|
|
372
|
+
vertexData.matricesIndices[currentVertexDataIndex * 4 + 2] = matIndices[vertex.vertexIdxForBones + 2];
|
|
373
|
+
vertexData.matricesIndices[currentVertexDataIndex * 4 + 3] = matIndices[vertex.vertexIdxForBones + 3];
|
|
374
|
+
}
|
|
375
|
+
if (matIndicesExtra && vertexData.matricesIndicesExtra) {
|
|
376
|
+
vertexData.matricesIndicesExtra[currentVertexDataIndex * 4] = matIndicesExtra[vertex.vertexIdxForBones];
|
|
377
|
+
vertexData.matricesIndicesExtra[currentVertexDataIndex * 4 + 1] = matIndicesExtra[vertex.vertexIdxForBones + 1];
|
|
378
|
+
vertexData.matricesIndicesExtra[currentVertexDataIndex * 4 + 2] = matIndicesExtra[vertex.vertexIdxForBones + 2];
|
|
379
|
+
vertexData.matricesIndicesExtra[currentVertexDataIndex * 4 + 3] = matIndicesExtra[vertex.vertexIdxForBones + 3];
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (vertex.matrixWeightsOverride) {
|
|
383
|
+
vertexData.matricesWeights[currentVertexDataIndex * 4] = vertex.matrixWeightsOverride[0];
|
|
384
|
+
vertexData.matricesWeights[currentVertexDataIndex * 4 + 1] = vertex.matrixWeightsOverride[1];
|
|
385
|
+
vertexData.matricesWeights[currentVertexDataIndex * 4 + 2] = vertex.matrixWeightsOverride[2];
|
|
386
|
+
vertexData.matricesWeights[currentVertexDataIndex * 4 + 3] = vertex.matrixWeightsOverride[3];
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
if (matWeights) {
|
|
390
|
+
vertexData.matricesWeights[currentVertexDataIndex * 4] = matWeights[vertex.vertexIdxForBones];
|
|
391
|
+
vertexData.matricesWeights[currentVertexDataIndex * 4 + 1] = matWeights[vertex.vertexIdxForBones + 1];
|
|
392
|
+
vertexData.matricesWeights[currentVertexDataIndex * 4 + 2] = matWeights[vertex.vertexIdxForBones + 2];
|
|
393
|
+
vertexData.matricesWeights[currentVertexDataIndex * 4 + 3] = matWeights[vertex.vertexIdxForBones + 3];
|
|
394
|
+
}
|
|
395
|
+
if (matWeightsExtra && vertexData.matricesWeightsExtra) {
|
|
396
|
+
vertexData.matricesWeightsExtra[currentVertexDataIndex * 4] = matWeightsExtra[vertex.vertexIdxForBones];
|
|
397
|
+
vertexData.matricesWeightsExtra[currentVertexDataIndex * 4 + 1] = matWeightsExtra[vertex.vertexIdxForBones + 1];
|
|
398
|
+
vertexData.matricesWeightsExtra[currentVertexDataIndex * 4 + 2] = matWeightsExtra[vertex.vertexIdxForBones + 2];
|
|
399
|
+
vertexData.matricesWeightsExtra[currentVertexDataIndex * 4 + 3] = matWeightsExtra[vertex.vertexIdxForBones + 3];
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
192
403
|
if (!options.captureUVS) {
|
|
193
404
|
vertexData.uvs.push(0.5 + vertex.position.x / size.x);
|
|
194
405
|
const v = 0.5 + vertex.position.y / size.y;
|
|
@@ -203,8 +414,16 @@ export function CreateDecal(name, sourceMesh, options) {
|
|
|
203
414
|
// Return mesh
|
|
204
415
|
const decal = new Mesh(name, sourceMesh.getScene());
|
|
205
416
|
vertexData.applyToMesh(decal);
|
|
206
|
-
|
|
207
|
-
|
|
417
|
+
if (useLocalComputation) {
|
|
418
|
+
decal.skeleton = sourceMesh.skeleton;
|
|
419
|
+
decal.parent = sourceMesh;
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
decal.position = position.clone();
|
|
423
|
+
decal.rotation = new Vector3(pitch, yaw, angle);
|
|
424
|
+
}
|
|
425
|
+
decal.computeWorldMatrix(true);
|
|
426
|
+
decal.refreshBoundingInfo(true, true);
|
|
208
427
|
return decal;
|
|
209
428
|
}
|
|
210
429
|
/**
|