@babylonjs/core 7.8.2 → 7.10.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/Behaviors/Cameras/framingBehavior.d.ts +1 -1
- package/Behaviors/Cameras/framingBehavior.js +1 -1
- package/Behaviors/Cameras/framingBehavior.js.map +1 -1
- package/Behaviors/Meshes/baseSixDofDragBehavior.d.ts +5 -5
- package/Behaviors/Meshes/baseSixDofDragBehavior.js +4 -4
- package/Behaviors/Meshes/baseSixDofDragBehavior.js.map +1 -1
- package/Cameras/touchCamera.js +4 -2
- package/Cameras/touchCamera.js.map +1 -1
- package/Collisions/gpuPicker.d.ts +38 -0
- package/Collisions/gpuPicker.js +256 -0
- package/Collisions/gpuPicker.js.map +1 -0
- package/Collisions/index.d.ts +1 -0
- package/Collisions/index.js +1 -0
- package/Collisions/index.js.map +1 -1
- package/Debug/physicsViewer.d.ts +4 -2
- package/Debug/physicsViewer.js +16 -4
- package/Debug/physicsViewer.js.map +1 -1
- package/Engines/Extensions/engine.views.d.ts +1 -0
- package/Engines/Extensions/engine.views.js +3 -0
- package/Engines/Extensions/engine.views.js.map +1 -0
- package/Engines/abstractEngine.js +3 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/thinEngine.js +8 -7
- package/Engines/thinEngine.js.map +1 -1
- package/Gizmos/boundingBoxGizmo.d.ts +6 -5
- package/Gizmos/boundingBoxGizmo.js +5 -5
- package/Gizmos/boundingBoxGizmo.js.map +1 -1
- package/Gizmos/lightGizmo.js +1 -2
- package/Gizmos/lightGizmo.js.map +1 -1
- package/Helpers/environmentHelper.js +2 -0
- package/Helpers/environmentHelper.js.map +1 -1
- package/LensFlares/lensFlareSystem.js +2 -2
- package/LensFlares/lensFlareSystem.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js +2 -2
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +2 -2
- package/Materials/Node/nodeMaterial.js +6 -6
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.js +20 -8
- package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
- package/Materials/material.d.ts +1 -1
- package/Materials/material.js.map +1 -1
- package/Materials/pushMaterial.d.ts +1 -1
- package/Materials/pushMaterial.js.map +1 -1
- package/Materials/shaderMaterial.d.ts +6 -1
- package/Materials/shaderMaterial.js +8 -1
- package/Materials/shaderMaterial.js.map +1 -1
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +0 -2
- package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
- package/Meshes/Node/Blocks/mergeGeometryBlock.js +15 -11
- package/Meshes/Node/Blocks/mergeGeometryBlock.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +6 -16
- package/Meshes/abstractMesh.js +5 -21
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/mesh.vertexData.js +19 -1
- package/Meshes/mesh.vertexData.js.map +1 -1
- package/Meshes/trailMesh.d.ts +40 -1
- package/Meshes/trailMesh.js +50 -21
- package/Meshes/trailMesh.js.map +1 -1
- package/Meshes/transformNode.d.ts +14 -0
- package/Meshes/transformNode.js +20 -0
- package/Meshes/transformNode.js.map +1 -1
- package/Misc/dumpTools.js +3 -2
- package/Misc/dumpTools.js.map +1 -1
- package/Particles/EmitterTypes/coneParticleEmitter.d.ts +60 -0
- package/Particles/EmitterTypes/coneParticleEmitter.js +88 -0
- package/Particles/EmitterTypes/coneParticleEmitter.js.map +1 -1
- package/Particles/IParticleSystem.d.ts +4 -2
- package/Particles/IParticleSystem.js.map +1 -1
- package/Particles/baseParticleSystem.d.ts +2 -1
- package/Particles/baseParticleSystem.js +3 -0
- package/Particles/baseParticleSystem.js.map +1 -1
- package/Particles/gpuParticleSystem.d.ts +4 -2
- package/Particles/gpuParticleSystem.js +9 -3
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/particleSystem.d.ts +2 -1
- package/Particles/particleSystem.functions.d.ts +2 -1
- package/Particles/particleSystem.functions.js +4 -1
- package/Particles/particleSystem.functions.js.map +1 -1
- package/Particles/particleSystem.js +10 -2
- package/Particles/particleSystem.js.map +1 -1
- package/Particles/thinParticleSystem.d.ts +2 -1
- package/Particles/thinParticleSystem.js +3 -2
- package/Particles/thinParticleSystem.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +3 -0
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.d.ts +14 -0
- package/Physics/v2/Plugins/havokPlugin.js +42 -18
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/Physics/v2/physicsEngine.d.ts +14 -0
- package/Physics/v2/physicsEngine.js +20 -0
- package/Physics/v2/physicsEngine.js.map +1 -1
- package/Rendering/edgesRenderer.js +2 -1
- package/Rendering/edgesRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/lineUboDeclaration.d.ts +7 -0
- package/Shaders/ShadersInclude/lineUboDeclaration.js +14 -0
- package/Shaders/ShadersInclude/lineUboDeclaration.js.map +1 -0
- package/Shaders/ShadersInclude/lineVertexDeclaration.d.ts +5 -0
- package/Shaders/ShadersInclude/lineVertexDeclaration.js +11 -0
- package/Shaders/ShadersInclude/lineVertexDeclaration.js.map +1 -0
- package/Shaders/gpuUpdateParticles.vertex.js +12 -2
- package/Shaders/gpuUpdateParticles.vertex.js.map +1 -1
- package/Shaders/line.vertex.d.ts +2 -0
- package/Shaders/line.vertex.js +5 -2
- package/Shaders/line.vertex.js.map +1 -1
- package/ShadersWGSL/gpuUpdateParticles.compute.js +11 -1
- package/ShadersWGSL/gpuUpdateParticles.compute.js.map +1 -1
- package/XR/features/WebXRControllerMovement.d.ts +14 -1
- package/XR/features/WebXRControllerMovement.js +21 -3
- package/XR/features/WebXRControllerMovement.js.map +1 -1
- package/XR/webXRInputSource.d.ts +1 -1
- package/XR/webXRInputSource.js +3 -3
- package/XR/webXRInputSource.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
|
|
2
|
+
import { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture.js";
|
|
3
|
+
import { ShaderMaterial } from "../Materials/shaderMaterial.js";
|
|
4
|
+
import { Color3, Color4 } from "../Maths/math.color.js";
|
|
5
|
+
import { VertexBuffer } from "../Meshes/buffer.js";
|
|
6
|
+
/**
|
|
7
|
+
* Class used to perform a picking operation using GPU
|
|
8
|
+
* Please note that GPUPIcker cannot pick instances, only meshes
|
|
9
|
+
*/
|
|
10
|
+
export class GPUPicker {
|
|
11
|
+
constructor() {
|
|
12
|
+
this._pickingTexure = null;
|
|
13
|
+
this._idMap = {};
|
|
14
|
+
this._idColors = [];
|
|
15
|
+
this._cachedMaterials = [];
|
|
16
|
+
this._meshRenderingCount = 0;
|
|
17
|
+
this._userDefinedList = false;
|
|
18
|
+
}
|
|
19
|
+
_createRenderTarget(scene, width, height) {
|
|
20
|
+
this._pickingTexure = new RenderTargetTexture("pickingTexure", { width: width, height: height }, scene, false, undefined, 0, false, 1);
|
|
21
|
+
}
|
|
22
|
+
_createColorMaterial(scene) {
|
|
23
|
+
if (this._renderMaterial) {
|
|
24
|
+
this._renderMaterial.dispose();
|
|
25
|
+
}
|
|
26
|
+
const defines = [];
|
|
27
|
+
const options = {
|
|
28
|
+
attributes: [VertexBuffer.PositionKind],
|
|
29
|
+
uniforms: ["world", "viewProjection", "color"],
|
|
30
|
+
needAlphaBlending: false,
|
|
31
|
+
defines: defines,
|
|
32
|
+
useClipPlane: null,
|
|
33
|
+
};
|
|
34
|
+
this._renderMaterial = new ShaderMaterial("colorShader", scene, "color", options, false);
|
|
35
|
+
const callback = (mesh) => {
|
|
36
|
+
if (!mesh) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const effect = this._renderMaterial.getEffect();
|
|
40
|
+
if (!mesh.hasInstances && !mesh.isAnInstance) {
|
|
41
|
+
effect.setColor4("color", this._idColors[mesh.uniqueId], 1);
|
|
42
|
+
}
|
|
43
|
+
this._meshRenderingCount++;
|
|
44
|
+
};
|
|
45
|
+
this._renderMaterial.customBindingObservable.add(callback);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set the list of meshes to pick from
|
|
49
|
+
* @param list defines the list of meshes to pick from
|
|
50
|
+
*/
|
|
51
|
+
setPickingList(list) {
|
|
52
|
+
if (!list) {
|
|
53
|
+
if (this._userDefinedList) {
|
|
54
|
+
for (let index = 0; index < this._pickableMeshes.length; index++) {
|
|
55
|
+
const mesh = this._pickableMeshes[index];
|
|
56
|
+
if (mesh.hasInstances) {
|
|
57
|
+
mesh.removeVerticesData(VertexBuffer.ColorKind);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
this._userDefinedList = false;
|
|
62
|
+
this._pickableMeshes = [];
|
|
63
|
+
this._idMap = {};
|
|
64
|
+
this._idColors = [];
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this._userDefinedList = true;
|
|
68
|
+
this._pickableMeshes = list;
|
|
69
|
+
// We will affect colors and create vertex color buffers
|
|
70
|
+
let id = 1;
|
|
71
|
+
for (let index = 0; index < this._pickableMeshes.length; index++) {
|
|
72
|
+
const mesh = this._pickableMeshes[index];
|
|
73
|
+
mesh.useVertexColors = false;
|
|
74
|
+
if (mesh.isAnInstance) {
|
|
75
|
+
continue; // This will be handled by the source mesh
|
|
76
|
+
}
|
|
77
|
+
const r = (id & 0xff0000) >> 16;
|
|
78
|
+
const g = (id & 0x00ff00) >> 8;
|
|
79
|
+
const b = (id & 0x0000ff) >> 0;
|
|
80
|
+
this._idMap[`${r}_${g}_${b}`] = index;
|
|
81
|
+
id++;
|
|
82
|
+
if (mesh.hasInstances) {
|
|
83
|
+
const instances = mesh.instances;
|
|
84
|
+
const colorData = new Float32Array(4 * (instances.length + 1));
|
|
85
|
+
const engine = mesh.getEngine();
|
|
86
|
+
colorData[0] = r / 255.0;
|
|
87
|
+
colorData[1] = g / 255.0;
|
|
88
|
+
colorData[2] = b / 255.0;
|
|
89
|
+
colorData[3] = 1.0;
|
|
90
|
+
for (let i = 0; i < instances.length; i++) {
|
|
91
|
+
const instance = instances[i];
|
|
92
|
+
const r = (id & 0xff0000) >> 16;
|
|
93
|
+
const g = (id & 0x00ff00) >> 8;
|
|
94
|
+
const b = (id & 0x0000ff) >> 0;
|
|
95
|
+
this._idMap[`${r}_${g}_${b}`] = this._pickableMeshes.indexOf(instance);
|
|
96
|
+
colorData[(i + 1) * 4] = r / 255.0;
|
|
97
|
+
colorData[(i + 1) * 4 + 1] = g / 255.0;
|
|
98
|
+
colorData[(i + 1) * 4 + 2] = b / 255.0;
|
|
99
|
+
colorData[(i + 1) * 4 + 3] = 1.0;
|
|
100
|
+
id++;
|
|
101
|
+
}
|
|
102
|
+
const buffer = new VertexBuffer(engine, colorData, VertexBuffer.ColorKind, false, false, 4, true);
|
|
103
|
+
mesh.setVerticesBuffer(buffer, true);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
this._idColors[mesh.uniqueId] = Color3.FromInts(r, g, b);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Execute a picking operation
|
|
112
|
+
* @param x defines the X coordinates where to run the pick
|
|
113
|
+
* @param y defines the Y coordinates where to run the pick
|
|
114
|
+
* @param scene defines the scene to pick from
|
|
115
|
+
* @param disposeWhenDone defines a boolean indicating we do not want to keep resources alive
|
|
116
|
+
* @returns A promise with the picking results
|
|
117
|
+
*/
|
|
118
|
+
pickAsync(x, y, scene, disposeWhenDone = true) {
|
|
119
|
+
const engine = scene.getEngine();
|
|
120
|
+
const rttSizeW = engine.getRenderWidth();
|
|
121
|
+
const rttSizeH = engine.getRenderHeight();
|
|
122
|
+
if (!this._readbuffer) {
|
|
123
|
+
this._readbuffer = new Uint8Array(engine.isWebGPU ? 256 : 4); // Because of block alignment in WebGPU
|
|
124
|
+
}
|
|
125
|
+
this._meshRenderingCount = 0;
|
|
126
|
+
// Ensure ints
|
|
127
|
+
x = x >> 0;
|
|
128
|
+
y = y >> 0;
|
|
129
|
+
if (x < 0 || y < 0 || x >= rttSizeW || y >= rttSizeH) {
|
|
130
|
+
return Promise.resolve(null);
|
|
131
|
+
}
|
|
132
|
+
// Invert Y
|
|
133
|
+
y = rttSizeH - y;
|
|
134
|
+
if (!this._pickingTexure) {
|
|
135
|
+
this._createRenderTarget(scene, rttSizeW, rttSizeH);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const size = this._pickingTexure.getSize();
|
|
139
|
+
if (size.width !== rttSizeW || size.height !== rttSizeH || this._cachedScene !== scene) {
|
|
140
|
+
this._pickingTexure.dispose();
|
|
141
|
+
this._createRenderTarget(scene, rttSizeW, rttSizeH);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!this._cachedScene || this._cachedScene !== scene) {
|
|
145
|
+
this._createColorMaterial(scene);
|
|
146
|
+
}
|
|
147
|
+
this._cachedScene = scene;
|
|
148
|
+
scene.customRenderTargets.push(this._pickingTexure);
|
|
149
|
+
this._pickingTexure.renderList = [];
|
|
150
|
+
this._pickingTexure.clearColor = new Color4(0, 0, 0, 0);
|
|
151
|
+
// We need to give every mesh an unique color (when there is no picking list)
|
|
152
|
+
this._pickingTexure.onBeforeRender = () => {
|
|
153
|
+
if (!this._userDefinedList) {
|
|
154
|
+
this._pickableMeshes = scene.meshes.filter((m) => m.geometry && m.isPickable && m.onBeforeRenderObservable);
|
|
155
|
+
}
|
|
156
|
+
for (let index = 0; index < this._pickableMeshes.length; index++) {
|
|
157
|
+
const mesh = this._pickableMeshes[index];
|
|
158
|
+
if (!mesh.isAnInstance) {
|
|
159
|
+
this._cachedMaterials[index] = mesh.material;
|
|
160
|
+
if (!this._userDefinedList) {
|
|
161
|
+
// We need to define the color for each mesh as it was not previously defined
|
|
162
|
+
const id = index + 1;
|
|
163
|
+
const r = (id & 0xff0000) >> 16;
|
|
164
|
+
const g = (id & 0x00ff00) >> 8;
|
|
165
|
+
const b = (id & 0x0000ff) >> 0;
|
|
166
|
+
this._idMap[`${r}_${g}_${b}`] = index;
|
|
167
|
+
this._idColors[mesh.uniqueId] = Color3.FromInts(r, g, b);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
mesh.useVertexColors = true; // In that case we will be using vertex colors and not an uniform to support instances
|
|
171
|
+
}
|
|
172
|
+
mesh.material = this._renderMaterial;
|
|
173
|
+
}
|
|
174
|
+
this._pickingTexure?.renderList?.push(mesh);
|
|
175
|
+
}
|
|
176
|
+
// Enable scissor
|
|
177
|
+
if (engine.enableScissor) {
|
|
178
|
+
engine.enableScissor(x, y, 1, 1);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
return new Promise((resolve, reject) => {
|
|
182
|
+
this._pickingTexure.onAfterRender = async () => {
|
|
183
|
+
// Disable scissor
|
|
184
|
+
if (engine.disableScissor) {
|
|
185
|
+
engine.disableScissor();
|
|
186
|
+
}
|
|
187
|
+
if (!this._pickingTexure) {
|
|
188
|
+
reject();
|
|
189
|
+
}
|
|
190
|
+
let pickedMesh = null;
|
|
191
|
+
const wasSuccessfull = this._meshRenderingCount > 0;
|
|
192
|
+
// Restore materials
|
|
193
|
+
for (let index = 0; index < this._pickableMeshes.length; index++) {
|
|
194
|
+
const mesh = this._pickableMeshes[index];
|
|
195
|
+
if (!mesh.isAnInstance) {
|
|
196
|
+
mesh.material = this._cachedMaterials[index];
|
|
197
|
+
if (this._userDefinedList) {
|
|
198
|
+
mesh.useVertexColors = false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (wasSuccessfull) {
|
|
203
|
+
// Remove from the active RTTs
|
|
204
|
+
const index = scene.customRenderTargets.indexOf(this._pickingTexure);
|
|
205
|
+
if (index > -1) {
|
|
206
|
+
scene.customRenderTargets.splice(index, 1);
|
|
207
|
+
}
|
|
208
|
+
// Do the actual picking
|
|
209
|
+
if (await this._readTexturePixelsAsync(x, y)) {
|
|
210
|
+
const colorId = `${this._readbuffer[0]}_${this._readbuffer[1]}_${this._readbuffer[2]}`;
|
|
211
|
+
pickedMesh = this._pickableMeshes[this._idMap[colorId]];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// Clean-up
|
|
215
|
+
if (!this._userDefinedList) {
|
|
216
|
+
this._idMap = {};
|
|
217
|
+
this._idColors = [];
|
|
218
|
+
this._pickableMeshes = [];
|
|
219
|
+
}
|
|
220
|
+
this._pickingTexure.renderList = [];
|
|
221
|
+
if (!wasSuccessfull) {
|
|
222
|
+
this._meshRenderingCount = 0;
|
|
223
|
+
return; // We need to wait for the shaders to be ready
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
if (disposeWhenDone) {
|
|
227
|
+
this.dispose();
|
|
228
|
+
}
|
|
229
|
+
resolve(pickedMesh);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
async _readTexturePixelsAsync(x, y) {
|
|
235
|
+
if (!this._cachedScene || !this._pickingTexure?._texture) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
const engine = this._cachedScene.getEngine();
|
|
239
|
+
await engine._readTexturePixels(this._pickingTexure._texture, 1, 1, -1, 0, this._readbuffer, true, true, x, y);
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
/** Release the resources */
|
|
243
|
+
dispose() {
|
|
244
|
+
if (this._userDefinedList) {
|
|
245
|
+
this.setPickingList(null);
|
|
246
|
+
}
|
|
247
|
+
this._pickableMeshes = [];
|
|
248
|
+
this._cachedScene = null;
|
|
249
|
+
// Cleaning up
|
|
250
|
+
this._pickingTexure?.dispose();
|
|
251
|
+
this._pickingTexure = null;
|
|
252
|
+
this._renderMaterial?.dispose();
|
|
253
|
+
this._renderMaterial = null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=gpuPicker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gpuPicker.js","sourceRoot":"","sources":["../../../../dev/core/src/Collisions/gpuPicker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gCAA+B;AAGnD,OAAO,EAAE,mBAAmB,EAAE,qDAAoD;AAElF,OAAO,EAAE,cAAc,EAAE,uCAAsC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,+BAA8B;AAEvD,OAAO,EAAE,YAAY,EAAE,4BAA2B;AAKlD;;;GAGG;AACH,MAAM,OAAO,SAAS;IAAtB;QACY,mBAAc,GAAkC,IAAI,CAAC;QACrD,WAAM,GAA8B,EAAE,CAAC;QACvC,cAAS,GAAkB,EAAE,CAAC;QAC9B,qBAAgB,GAA8B,EAAE,CAAC;QAKjD,wBAAmB,GAAW,CAAC,CAAC;QAChC,qBAAgB,GAAG,KAAK,CAAC;IA8RrC,CAAC;IA5RW,mBAAmB,CAAC,KAAY,EAAE,KAAa,EAAE,MAAc;QACnE,IAAI,CAAC,cAAc,GAAG,IAAI,mBAAmB,CACzC,eAAe,EACf,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAChC,KAAK,EACL,KAAK,EACL,SAAS,EACT,SAAS,CAAC,wBAAwB,EAClC,KAAK,EACL,SAAS,CAAC,uBAAuB,CACpC,CAAC;IACN,CAAC;IAEO,oBAAoB,CAAC,KAAY;QACrC,IAAI,IAAI,CAAC,eAAe,EAAE;YACtB,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;SAClC;QAED,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG;YACZ,UAAU,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC;YACvC,QAAQ,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC;YAC9C,iBAAiB,EAAE,KAAK;YACxB,OAAO,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AI,CAAC;QAC3B,IAAI,CAAC,eAAe,EAAE,OAAO,EAAE,CAAC;QAChC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;IAChC,CAAC;CACJ","sourcesContent":["import { Constants } from \"core/Engines/constants\";\r\nimport type { Engine } from \"core/Engines/engine\";\r\nimport type { WebGPUEngine } from \"core/Engines/webgpuEngine\";\r\nimport { RenderTargetTexture } from \"core/Materials/Textures/renderTargetTexture\";\r\nimport type { Material } from \"core/Materials/material\";\r\nimport { ShaderMaterial } from \"core/Materials/shaderMaterial\";\r\nimport { Color3, Color4 } from \"core/Maths/math.color\";\r\nimport type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport { VertexBuffer } from \"core/Meshes/buffer\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { Scene } from \"core/scene\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\n/**\r\n * Class used to perform a picking operation using GPU\r\n * Please note that GPUPIcker cannot pick instances, only meshes\r\n */\r\nexport class GPUPicker {\r\n private _pickingTexure: Nullable<RenderTargetTexture> = null;\r\n private _idMap: { [key: string]: number } = {};\r\n private _idColors: Array<Color3> = [];\r\n private _cachedMaterials: Array<Nullable<Material>> = [];\r\n private _cachedScene: Nullable<Scene>;\r\n private _renderMaterial: Nullable<ShaderMaterial>;\r\n private _pickableMeshes: Array<AbstractMesh>;\r\n private _readbuffer: Uint8Array;\r\n private _meshRenderingCount: number = 0;\r\n private _userDefinedList = false;\r\n\r\n private _createRenderTarget(scene: Scene, width: number, height: number) {\r\n this._pickingTexure = new RenderTargetTexture(\r\n \"pickingTexure\",\r\n { width: width, height: height },\r\n scene,\r\n false,\r\n undefined,\r\n Constants.TEXTURETYPE_UNSIGNED_INT,\r\n false,\r\n Constants.TEXTURE_NEAREST_NEAREST\r\n );\r\n }\r\n\r\n private _createColorMaterial(scene: Scene) {\r\n if (this._renderMaterial) {\r\n this._renderMaterial.dispose();\r\n }\r\n\r\n const defines: string[] = [];\r\n const options = {\r\n attributes: [VertexBuffer.PositionKind],\r\n uniforms: [\"world\", \"viewProjection\", \"color\"],\r\n needAlphaBlending: false,\r\n defines: defines,\r\n useClipPlane: null,\r\n };\r\n\r\n this._renderMaterial = new ShaderMaterial(\"colorShader\", scene, \"color\", options, false);\r\n\r\n const callback = (mesh: AbstractMesh | undefined) => {\r\n if (!mesh) {\r\n return;\r\n }\r\n\r\n const effect = this._renderMaterial!.getEffect();\r\n\r\n if (!mesh.hasInstances && !mesh.isAnInstance) {\r\n effect.setColor4(\"color\", this._idColors[mesh.uniqueId], 1);\r\n }\r\n\r\n this._meshRenderingCount++;\r\n };\r\n\r\n this._renderMaterial.customBindingObservable.add(callback);\r\n }\r\n\r\n /**\r\n * Set the list of meshes to pick from\r\n * @param list defines the list of meshes to pick from\r\n */\r\n public setPickingList(list: Nullable<Array<AbstractMesh>>) {\r\n if (!list) {\r\n if (this._userDefinedList) {\r\n for (let index = 0; index < this._pickableMeshes.length; index++) {\r\n const mesh = this._pickableMeshes[index];\r\n if (mesh.hasInstances) {\r\n (mesh as Mesh).removeVerticesData(VertexBuffer.ColorKind);\r\n }\r\n }\r\n }\r\n this._userDefinedList = false;\r\n this._pickableMeshes = [];\r\n this._idMap = {};\r\n this._idColors = [];\r\n return;\r\n }\r\n this._userDefinedList = true;\r\n this._pickableMeshes = list;\r\n\r\n // We will affect colors and create vertex color buffers\r\n let id = 1;\r\n for (let index = 0; index < this._pickableMeshes.length; index++) {\r\n const mesh = this._pickableMeshes[index];\r\n mesh.useVertexColors = false;\r\n\r\n if (mesh.isAnInstance) {\r\n continue; // This will be handled by the source mesh\r\n }\r\n\r\n const r = (id & 0xff0000) >> 16;\r\n const g = (id & 0x00ff00) >> 8;\r\n const b = (id & 0x0000ff) >> 0;\r\n this._idMap[`${r}_${g}_${b}`] = index;\r\n id++;\r\n\r\n if (mesh.hasInstances) {\r\n const instances = (mesh as Mesh).instances;\r\n const colorData = new Float32Array(4 * (instances.length + 1));\r\n const engine = mesh.getEngine();\r\n\r\n colorData[0] = r / 255.0;\r\n colorData[1] = g / 255.0;\r\n colorData[2] = b / 255.0;\r\n colorData[3] = 1.0;\r\n for (let i = 0; i < instances.length; i++) {\r\n const instance = instances[i];\r\n const r = (id & 0xff0000) >> 16;\r\n const g = (id & 0x00ff00) >> 8;\r\n const b = (id & 0x0000ff) >> 0;\r\n this._idMap[`${r}_${g}_${b}`] = this._pickableMeshes.indexOf(instance);\r\n\r\n colorData[(i + 1) * 4] = r / 255.0;\r\n colorData[(i + 1) * 4 + 1] = g / 255.0;\r\n colorData[(i + 1) * 4 + 2] = b / 255.0;\r\n colorData[(i + 1) * 4 + 3] = 1.0;\r\n id++;\r\n }\r\n\r\n const buffer = new VertexBuffer(engine, colorData, VertexBuffer.ColorKind, false, false, 4, true);\r\n (mesh as Mesh).setVerticesBuffer(buffer, true);\r\n } else {\r\n this._idColors[mesh.uniqueId] = Color3.FromInts(r, g, b);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Execute a picking operation\r\n * @param x defines the X coordinates where to run the pick\r\n * @param y defines the Y coordinates where to run the pick\r\n * @param scene defines the scene to pick from\r\n * @param disposeWhenDone defines a boolean indicating we do not want to keep resources alive\r\n * @returns A promise with the picking results\r\n */\r\n public pickAsync(x: number, y: number, scene: Scene, disposeWhenDone = true): Promise<Nullable<AbstractMesh>> {\r\n const engine = scene.getEngine();\r\n const rttSizeW = engine.getRenderWidth();\r\n const rttSizeH = engine.getRenderHeight();\r\n\r\n if (!this._readbuffer) {\r\n this._readbuffer = new Uint8Array(engine.isWebGPU ? 256 : 4); // Because of block alignment in WebGPU\r\n }\r\n\r\n this._meshRenderingCount = 0;\r\n // Ensure ints\r\n x = x >> 0;\r\n y = y >> 0;\r\n\r\n if (x < 0 || y < 0 || x >= rttSizeW || y >= rttSizeH) {\r\n return Promise.resolve(null);\r\n }\r\n\r\n // Invert Y\r\n y = rttSizeH - y;\r\n\r\n if (!this._pickingTexure) {\r\n this._createRenderTarget(scene, rttSizeW, rttSizeH);\r\n } else {\r\n const size = this._pickingTexure.getSize();\r\n\r\n if (size.width !== rttSizeW || size.height !== rttSizeH || this._cachedScene !== scene) {\r\n this._pickingTexure.dispose();\r\n this._createRenderTarget(scene, rttSizeW, rttSizeH);\r\n }\r\n }\r\n\r\n if (!this._cachedScene || this._cachedScene !== scene) {\r\n this._createColorMaterial(scene);\r\n }\r\n\r\n this._cachedScene = scene;\r\n scene.customRenderTargets.push(this._pickingTexure!);\r\n this._pickingTexure!.renderList = [];\r\n this._pickingTexure!.clearColor = new Color4(0, 0, 0, 0);\r\n\r\n // We need to give every mesh an unique color (when there is no picking list)\r\n this._pickingTexure!.onBeforeRender = () => {\r\n if (!this._userDefinedList) {\r\n this._pickableMeshes = scene.meshes.filter((m) => (m as Mesh).geometry && m.isPickable && (m as Mesh).onBeforeRenderObservable) as Mesh[];\r\n }\r\n\r\n for (let index = 0; index < this._pickableMeshes.length; index++) {\r\n const mesh = this._pickableMeshes[index];\r\n if (!mesh.isAnInstance) {\r\n this._cachedMaterials[index] = mesh.material;\r\n if (!this._userDefinedList) {\r\n // We need to define the color for each mesh as it was not previously defined\r\n const id = index + 1;\r\n const r = (id & 0xff0000) >> 16;\r\n const g = (id & 0x00ff00) >> 8;\r\n const b = (id & 0x0000ff) >> 0;\r\n this._idMap[`${r}_${g}_${b}`] = index;\r\n\r\n this._idColors[mesh.uniqueId] = Color3.FromInts(r, g, b);\r\n } else {\r\n mesh.useVertexColors = true; // In that case we will be using vertex colors and not an uniform to support instances\r\n }\r\n mesh.material = this._renderMaterial;\r\n }\r\n this._pickingTexure?.renderList?.push(mesh);\r\n }\r\n\r\n // Enable scissor\r\n if ((engine as WebGPUEngine | Engine).enableScissor) {\r\n (engine as WebGPUEngine | Engine).enableScissor(x, y, 1, 1);\r\n }\r\n };\r\n\r\n return new Promise((resolve, reject) => {\r\n this._pickingTexure!.onAfterRender = async () => {\r\n // Disable scissor\r\n if ((engine as WebGPUEngine | Engine).disableScissor) {\r\n (engine as WebGPUEngine | Engine).disableScissor();\r\n }\r\n\r\n if (!this._pickingTexure) {\r\n reject();\r\n }\r\n\r\n let pickedMesh: Nullable<AbstractMesh> = null;\r\n const wasSuccessfull = this._meshRenderingCount > 0;\r\n\r\n // Restore materials\r\n for (let index = 0; index < this._pickableMeshes.length; index++) {\r\n const mesh = this._pickableMeshes[index];\r\n if (!mesh.isAnInstance) {\r\n mesh.material = this._cachedMaterials[index];\r\n\r\n if (this._userDefinedList) {\r\n mesh.useVertexColors = false;\r\n }\r\n }\r\n }\r\n\r\n if (wasSuccessfull) {\r\n // Remove from the active RTTs\r\n const index = scene.customRenderTargets.indexOf(this._pickingTexure!);\r\n if (index > -1) {\r\n scene.customRenderTargets.splice(index, 1);\r\n }\r\n\r\n // Do the actual picking\r\n if (await this._readTexturePixelsAsync(x, y)) {\r\n const colorId = `${this._readbuffer[0]}_${this._readbuffer[1]}_${this._readbuffer[2]}`;\r\n pickedMesh = this._pickableMeshes[this._idMap[colorId]];\r\n }\r\n }\r\n\r\n // Clean-up\r\n if (!this._userDefinedList) {\r\n this._idMap = {};\r\n this._idColors = [];\r\n\r\n this._pickableMeshes = [];\r\n }\r\n this._pickingTexure!.renderList = [];\r\n\r\n if (!wasSuccessfull) {\r\n this._meshRenderingCount = 0;\r\n return; // We need to wait for the shaders to be ready\r\n } else {\r\n if (disposeWhenDone) {\r\n this.dispose();\r\n }\r\n resolve(pickedMesh);\r\n }\r\n };\r\n });\r\n }\r\n\r\n private async _readTexturePixelsAsync(x: number, y: number) {\r\n if (!this._cachedScene || !this._pickingTexure?._texture) {\r\n return false;\r\n }\r\n const engine = this._cachedScene.getEngine();\r\n await engine._readTexturePixels(this._pickingTexure._texture, 1, 1, -1, 0, this._readbuffer, true, true, x, y);\r\n\r\n return true;\r\n }\r\n\r\n /** Release the resources */\r\n public dispose() {\r\n if (this._userDefinedList) {\r\n this.setPickingList(null);\r\n }\r\n this._pickableMeshes = [];\r\n this._cachedScene = null;\r\n\r\n // Cleaning up\r\n this._pickingTexure?.dispose();\r\n this._pickingTexure = null;\r\n this._renderMaterial?.dispose();\r\n this._renderMaterial = null;\r\n }\r\n}\r\n"]}
|
package/Collisions/index.d.ts
CHANGED
package/Collisions/index.js
CHANGED
package/Collisions/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/core/src/Collisions/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC","sourcesContent":["export * from \"./collider\";\r\nexport * from \"./collisionCoordinator\";\r\nexport * from \"./pickingInfo\";\r\nexport * from \"./intersectionInfo\";\r\nexport * from \"./meshCollisionData\";\r\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/core/src/Collisions/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./collider\";\r\nexport * from \"./collisionCoordinator\";\r\nexport * from \"./pickingInfo\";\r\nexport * from \"./intersectionInfo\";\r\nexport * from \"./meshCollisionData\";\r\nexport * from \"./gpuPicker\";\r\n"]}
|
package/Debug/physicsViewer.d.ts
CHANGED
|
@@ -133,18 +133,20 @@ export declare class PhysicsViewer {
|
|
|
133
133
|
/**
|
|
134
134
|
* Hides a body from the physics engine.
|
|
135
135
|
* @param body - The body to hide.
|
|
136
|
+
* @returns true if body actually removed
|
|
136
137
|
*
|
|
137
138
|
* This function is useful for hiding a body from the physics engine.
|
|
138
139
|
* It removes the body from the utility layer scene and disposes the mesh associated with it.
|
|
139
140
|
* It also unregisters the render function if the number of bodies is 0.
|
|
140
141
|
* This is useful for hiding a body from the physics engine without deleting it.
|
|
141
142
|
*/
|
|
142
|
-
hideBody(body: Nullable<PhysicsBody>):
|
|
143
|
+
hideBody(body: Nullable<PhysicsBody>): boolean;
|
|
143
144
|
/**
|
|
144
145
|
* Hides a body's inertia from the viewer utility layer
|
|
145
146
|
* @param body the body to hide
|
|
147
|
+
* @returns true if inertia actually removed
|
|
146
148
|
*/
|
|
147
|
-
hideInertia(body: Nullable<PhysicsBody>):
|
|
149
|
+
hideInertia(body: Nullable<PhysicsBody>): boolean;
|
|
148
150
|
/**
|
|
149
151
|
* Hide a physics constraint from the viewer utility layer
|
|
150
152
|
* @param constraint the constraint to hide
|
package/Debug/physicsViewer.js
CHANGED
|
@@ -115,21 +115,29 @@ export class PhysicsViewer {
|
|
|
115
115
|
*/
|
|
116
116
|
_updateDebugMeshesV2() {
|
|
117
117
|
const plugin = this._physicsEnginePlugin;
|
|
118
|
-
for (let i = 0; i < this._numBodies;
|
|
118
|
+
for (let i = 0; i < this._numBodies;) {
|
|
119
119
|
const body = this._bodies[i];
|
|
120
|
+
if (body && body.isDisposed && this.hideBody(body)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
120
123
|
const transform = this._bodyMeshes[i];
|
|
121
124
|
if (body && transform) {
|
|
122
125
|
plugin.syncTransform(body, transform);
|
|
123
126
|
}
|
|
127
|
+
i++;
|
|
124
128
|
}
|
|
125
129
|
}
|
|
126
130
|
_updateInertiaMeshes() {
|
|
127
|
-
for (let i = 0; i < this._numInertiaBodies;
|
|
131
|
+
for (let i = 0; i < this._numInertiaBodies;) {
|
|
128
132
|
const body = this._inertiaBodies[i];
|
|
133
|
+
if (body && body.isDisposed && this.hideInertia(body)) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
129
136
|
const mesh = this._inertiaMeshes[i];
|
|
130
137
|
if (body && mesh) {
|
|
131
138
|
this._updateDebugInertia(body, mesh);
|
|
132
139
|
}
|
|
140
|
+
i++;
|
|
133
141
|
}
|
|
134
142
|
}
|
|
135
143
|
_updateDebugInertia(body, inertiaMesh) {
|
|
@@ -376,6 +384,7 @@ export class PhysicsViewer {
|
|
|
376
384
|
/**
|
|
377
385
|
* Hides a body from the physics engine.
|
|
378
386
|
* @param body - The body to hide.
|
|
387
|
+
* @returns true if body actually removed
|
|
379
388
|
*
|
|
380
389
|
* This function is useful for hiding a body from the physics engine.
|
|
381
390
|
* It removes the body from the utility layer scene and disposes the mesh associated with it.
|
|
@@ -384,7 +393,7 @@ export class PhysicsViewer {
|
|
|
384
393
|
*/
|
|
385
394
|
hideBody(body) {
|
|
386
395
|
if (!body || !this._scene || !this._utilityLayer) {
|
|
387
|
-
return;
|
|
396
|
+
return false;
|
|
388
397
|
}
|
|
389
398
|
let removed = false;
|
|
390
399
|
const utilityLayerScene = this._utilityLayer.utilityLayerScene;
|
|
@@ -414,14 +423,16 @@ export class PhysicsViewer {
|
|
|
414
423
|
if (removed && this._numBodies === 0) {
|
|
415
424
|
this._scene.unregisterBeforeRender(this._renderFunction);
|
|
416
425
|
}
|
|
426
|
+
return removed;
|
|
417
427
|
}
|
|
418
428
|
/**
|
|
419
429
|
* Hides a body's inertia from the viewer utility layer
|
|
420
430
|
* @param body the body to hide
|
|
431
|
+
* @returns true if inertia actually removed
|
|
421
432
|
*/
|
|
422
433
|
hideInertia(body) {
|
|
423
434
|
if (!body || !this._scene || !this._utilityLayer) {
|
|
424
|
-
return;
|
|
435
|
+
return false;
|
|
425
436
|
}
|
|
426
437
|
let removed = false;
|
|
427
438
|
const utilityLayerScene = this._utilityLayer.utilityLayerScene;
|
|
@@ -443,6 +454,7 @@ export class PhysicsViewer {
|
|
|
443
454
|
if (removed && this._numInertiaBodies === 0) {
|
|
444
455
|
this._scene.unregisterBeforeRender(this._inertiaRenderFunction);
|
|
445
456
|
}
|
|
457
|
+
return removed;
|
|
446
458
|
}
|
|
447
459
|
/**
|
|
448
460
|
* Hide a physics constraint from the viewer utility layer
|