@playcanvas/inspector 0.1.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/LICENSE +19 -0
- package/README.md +110 -0
- package/package.json +62 -0
- package/src/asset-usage.js +108 -0
- package/src/asset-view.js +370 -0
- package/src/camera-view.js +128 -0
- package/src/debug.js +31 -0
- package/src/describe.js +302 -0
- package/src/entity-inspector-script.js +130 -0
- package/src/frame-graph-view.js +767 -0
- package/src/hierarchy-view.js +475 -0
- package/src/index.js +4 -0
- package/src/input/fly-controller.js +116 -0
- package/src/input/input.js +299 -0
- package/src/input/math.js +8 -0
- package/src/input/orbit-controller.js +158 -0
- package/src/input/pose.js +207 -0
- package/src/inspector.js +3293 -0
- package/src/instance-survey.js +50 -0
- package/src/list-view.js +410 -0
- package/src/material-view.js +197 -0
- package/src/memory-view.js +344 -0
- package/src/mesh-view.js +235 -0
- package/src/model.js +170 -0
- package/src/node-model.js +404 -0
- package/src/physics-debug.js +527 -0
- package/src/physics-view.js +314 -0
- package/src/picker/picker.js +545 -0
- package/src/picker/render-pass-picker.js +206 -0
- package/src/property-view.js +628 -0
- package/src/render-target-view.js +288 -0
- package/src/renderers/texture-renderer-shaders.js +139 -0
- package/src/renderers/texture-renderer.js +430 -0
- package/src/renderers/wire-renderer.js +954 -0
- package/src/script-view.js +288 -0
- package/src/shader-view.js +287 -0
- package/src/styles.js +918 -0
- package/src/texture-view.js +186 -0
- package/src/tooltip.js +72 -0
- package/src/viewport-tools.js +695 -0
- package/types/asset-usage.d.ts +23 -0
- package/types/asset-view.d.ts +94 -0
- package/types/camera-view.d.ts +45 -0
- package/types/debug.d.ts +14 -0
- package/types/describe.d.ts +43 -0
- package/types/entity-inspector-script.d.ts +87 -0
- package/types/frame-graph-view.d.ts +155 -0
- package/types/hierarchy-view.d.ts +172 -0
- package/types/index.d.ts +3 -0
- package/types/input/fly-controller.d.ts +42 -0
- package/types/input/input.d.ts +192 -0
- package/types/input/math.d.ts +1 -0
- package/types/input/orbit-controller.d.ts +63 -0
- package/types/input/pose.d.ts +126 -0
- package/types/inspector.d.ts +1304 -0
- package/types/instance-survey.d.ts +35 -0
- package/types/list-view.d.ts +151 -0
- package/types/material-view.d.ts +63 -0
- package/types/memory-view.d.ts +95 -0
- package/types/mesh-view.d.ts +89 -0
- package/types/model.d.ts +104 -0
- package/types/node-model.d.ts +54 -0
- package/types/physics-debug.d.ts +254 -0
- package/types/physics-view.d.ts +81 -0
- package/types/picker/picker.d.ts +255 -0
- package/types/picker/render-pass-picker.d.ts +47 -0
- package/types/property-view.d.ts +189 -0
- package/types/render-target-view.d.ts +98 -0
- package/types/renderers/texture-renderer-shaders.d.ts +9 -0
- package/types/renderers/texture-renderer.d.ts +231 -0
- package/types/renderers/wire-renderer.d.ts +347 -0
- package/types/script-view.d.ts +56 -0
- package/types/shader-view.d.ts +46 -0
- package/types/styles.d.ts +22 -0
- package/types/texture-view.d.ts +30 -0
- package/types/tooltip.d.ts +17 -0
- package/types/viewport-tools.d.ts +237 -0
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import { Vec3 } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { WireRenderer } from './renderers/wire-renderer.js';
|
|
4
|
+
|
|
5
|
+
/** @import { Color } from 'playcanvas' */
|
|
6
|
+
/** @import { AppBase } from 'playcanvas' */
|
|
7
|
+
/** @import { Layer } from 'playcanvas' */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Bullet's `btIDebugDraw` mode flags, combined into {@link AmmoDebugDraw#mode}.
|
|
11
|
+
*
|
|
12
|
+
* @ignore
|
|
13
|
+
* @type {{ WIREFRAME: number, AABB: number, CONTACT_POINTS: number, NO_DEACTIVATION: number,
|
|
14
|
+
* CONSTRAINTS: number, CONSTRAINT_LIMITS: number, NORMALS: number, FRAMES: number }}
|
|
15
|
+
*/
|
|
16
|
+
const DEBUG_DRAW = {
|
|
17
|
+
/** Collision shapes, colored by activation state. */
|
|
18
|
+
WIREFRAME: 1,
|
|
19
|
+
/** Axis-aligned bounds of each body. */
|
|
20
|
+
AABB: 2,
|
|
21
|
+
/** Contact points with their normals. Reported during the physics step itself. */
|
|
22
|
+
CONTACT_POINTS: 8,
|
|
23
|
+
/** Not a drawing flag: stops bodies from falling asleep while set. */
|
|
24
|
+
NO_DEACTIVATION: 16,
|
|
25
|
+
/** Joint frames. */
|
|
26
|
+
CONSTRAINTS: 2048,
|
|
27
|
+
/** Joint limits. */
|
|
28
|
+
CONSTRAINT_LIMITS: 4096,
|
|
29
|
+
/** Face normals of mesh shapes. */
|
|
30
|
+
NORMALS: 16384,
|
|
31
|
+
/** Local axes of each body. */
|
|
32
|
+
FRAMES: 32768
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// the flags that make debugDrawWorld emit lines
|
|
36
|
+
const DRAW_FLAGS = DEBUG_DRAW.WIREFRAME | DEBUG_DRAW.AABB | DEBUG_DRAW.CONTACT_POINTS | DEBUG_DRAW.CONSTRAINTS |
|
|
37
|
+
DEBUG_DRAW.CONSTRAINT_LIMITS | DEBUG_DRAW.NORMALS | DEBUG_DRAW.FRAMES;
|
|
38
|
+
|
|
39
|
+
// btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT: debugDrawWorld skips objects carrying this flag
|
|
40
|
+
const CF_DISABLE_VISUALIZE_OBJECT = 32;
|
|
41
|
+
|
|
42
|
+
const CONTACT_NORMAL_LENGTH = 0.25;
|
|
43
|
+
const CONTACT_CROSS_SIZE = 0.04;
|
|
44
|
+
const INITIAL_SEGMENTS = 4096;
|
|
45
|
+
|
|
46
|
+
const _a = new Vec3();
|
|
47
|
+
const _b = new Vec3();
|
|
48
|
+
const _c = new Vec3();
|
|
49
|
+
const _d = new Vec3();
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {Vec3} a - A point.
|
|
53
|
+
* @param {Vec3} b - Another point.
|
|
54
|
+
* @returns {number} The squared distance between them.
|
|
55
|
+
*/
|
|
56
|
+
function distanceSq(a, b) {
|
|
57
|
+
const x = a.x - b.x;
|
|
58
|
+
const y = a.y - b.y;
|
|
59
|
+
const z = a.z - b.z;
|
|
60
|
+
return x * x + y * y + z * z;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Draws the state of the Ammo dynamics world through Bullet's own debug drawer, so what you see is
|
|
65
|
+
* exactly what the physics engine simulates: compound and mesh shapes, contact points, joints.
|
|
66
|
+
*
|
|
67
|
+
* Bullet hands over every line as a pair of `btVector3` pointers. Those are read straight out of
|
|
68
|
+
* the Ammo heap into a growing pair of typed arrays, so a frame of thousands of lines allocates
|
|
69
|
+
* nothing, and the whole batch is submitted with one {@link WireRenderer#linesPacked} call.
|
|
70
|
+
*
|
|
71
|
+
* Contact points arrive during the physics step rather than from `debugDrawWorld`, so lines are
|
|
72
|
+
* accumulated across the frame and only reset once {@link AmmoDebugDraw#update} has drawn them.
|
|
73
|
+
*
|
|
74
|
+
* Usable on its own:
|
|
75
|
+
*
|
|
76
|
+
* ```javascript
|
|
77
|
+
* const physicsDebug = new AmmoDebugDraw(app);
|
|
78
|
+
* physicsDebug.enabled = true;
|
|
79
|
+
* physicsDebug.mode = DEBUG_DRAW.WIREFRAME | DEBUG_DRAW.CONTACT_POINTS;
|
|
80
|
+
* app.on('update', () => physicsDebug.update()); // fires after the physics step
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @ignore
|
|
84
|
+
*/
|
|
85
|
+
class AmmoDebugDraw {
|
|
86
|
+
/**
|
|
87
|
+
* The app whose rigid body system is drawn.
|
|
88
|
+
*
|
|
89
|
+
* @type {AppBase}
|
|
90
|
+
*/
|
|
91
|
+
app;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The renderer the lines go through. Its layer and depth test are applied on every flush from
|
|
95
|
+
* {@link depthTest} and {@link layer}.
|
|
96
|
+
*
|
|
97
|
+
* @type {WireRenderer}
|
|
98
|
+
*/
|
|
99
|
+
wire;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Whether the world is drawn. While off, {@link mode} still applies its simulation flags such
|
|
103
|
+
* as {@link DEBUG_DRAW.NO_DEACTIVATION}.
|
|
104
|
+
*
|
|
105
|
+
* @type {boolean}
|
|
106
|
+
*/
|
|
107
|
+
enabled = false;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A combination of {@link DEBUG_DRAW} flags.
|
|
111
|
+
*
|
|
112
|
+
* @type {number}
|
|
113
|
+
*/
|
|
114
|
+
mode = DEBUG_DRAW.WIREFRAME;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Whether the lines are depth tested against the scene. Off shows the physics world through
|
|
118
|
+
* the geometry.
|
|
119
|
+
*
|
|
120
|
+
* @type {boolean}
|
|
121
|
+
*/
|
|
122
|
+
depthTest = false;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The layer to draw into, or null for the immediate layer.
|
|
126
|
+
*
|
|
127
|
+
* @type {Layer|null}
|
|
128
|
+
*/
|
|
129
|
+
layer = null;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Only lines within this distance of {@link center} are drawn, in meters. Zero draws everything.
|
|
133
|
+
*
|
|
134
|
+
* @type {number}
|
|
135
|
+
*/
|
|
136
|
+
range = 0;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The point {@link range} is measured from, typically the camera position.
|
|
140
|
+
*
|
|
141
|
+
* @type {Vec3|null}
|
|
142
|
+
*/
|
|
143
|
+
center = null;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* When culling by range, drop lines with only one end in range instead of keeping them.
|
|
147
|
+
*
|
|
148
|
+
* @type {boolean}
|
|
149
|
+
*/
|
|
150
|
+
cullPartial = false;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Overrides the colors Bullet assigns, which encode the activation state. Null keeps them.
|
|
154
|
+
*
|
|
155
|
+
* @type {Color|null}
|
|
156
|
+
*/
|
|
157
|
+
color = null;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The number of line segments drawn by the last {@link update}.
|
|
161
|
+
*
|
|
162
|
+
* @type {number}
|
|
163
|
+
*/
|
|
164
|
+
lineCount = 0;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The number of line segments dropped by range culling in the last {@link update}.
|
|
168
|
+
*
|
|
169
|
+
* @type {number}
|
|
170
|
+
*/
|
|
171
|
+
culledCount = 0;
|
|
172
|
+
|
|
173
|
+
/** @private */
|
|
174
|
+
_positions = new Float32Array(INITIAL_SEGMENTS * 6);
|
|
175
|
+
|
|
176
|
+
/** @private */
|
|
177
|
+
_colors = new Float32Array(INITIAL_SEGMENTS * 8);
|
|
178
|
+
|
|
179
|
+
/** @private */
|
|
180
|
+
_count = 0;
|
|
181
|
+
|
|
182
|
+
/** @private */
|
|
183
|
+
_culled = 0;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @type {any}
|
|
187
|
+
* @private
|
|
188
|
+
*/
|
|
189
|
+
_drawer = null;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* @type {any}
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
195
|
+
_world = null;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Native bodies excluded from the drawing, see {@link hideBody}.
|
|
199
|
+
*
|
|
200
|
+
* @type {Set<any>}
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
203
|
+
_hiddenBodies = new Set();
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Whether a debug drawer can be attached right now: Ammo is loaded with `DebugDrawer` support
|
|
207
|
+
* and the rigid body system has created its world.
|
|
208
|
+
*
|
|
209
|
+
* @param {AppBase} app - The app.
|
|
210
|
+
* @returns {boolean} True when {@link attach} would succeed.
|
|
211
|
+
*/
|
|
212
|
+
static isAvailable(app) {
|
|
213
|
+
const Ammo = /** @type {any} */ (globalThis).Ammo;
|
|
214
|
+
return !!(Ammo?.DebugDrawer && app.systems.rigidbody?.dynamicsWorld);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @param {AppBase} app - The app.
|
|
219
|
+
* @param {WireRenderer} [wire] - The renderer to draw through. Defaults to a new one.
|
|
220
|
+
*/
|
|
221
|
+
constructor(app, wire) {
|
|
222
|
+
this.app = app;
|
|
223
|
+
this.wire = wire ?? new WireRenderer(app);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Whether a debug drawer is currently installed on the world.
|
|
228
|
+
*
|
|
229
|
+
* @type {boolean}
|
|
230
|
+
*/
|
|
231
|
+
get attached() {
|
|
232
|
+
return !!this._drawer;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Installs the debug drawer on the dynamics world. Called on demand by {@link update}.
|
|
237
|
+
*
|
|
238
|
+
* @returns {boolean} False when Ammo or the world is not available.
|
|
239
|
+
*/
|
|
240
|
+
attach() {
|
|
241
|
+
if (this._drawer) return true;
|
|
242
|
+
if (!AmmoDebugDraw.isAvailable(this.app)) return false;
|
|
243
|
+
|
|
244
|
+
const Ammo = /** @type {any} */ (globalThis).Ammo;
|
|
245
|
+
const drawer = new Ammo.DebugDrawer();
|
|
246
|
+
drawer.drawLine = (from, to, color) => this._drawLine(from, to, color);
|
|
247
|
+
drawer.drawContactPoint = (point, normal, distance, lifeTime, color) => this._drawContactPoint(point, normal, color);
|
|
248
|
+
drawer.reportErrorWarning = () => {};
|
|
249
|
+
drawer.draw3dText = () => {};
|
|
250
|
+
drawer.setDebugMode = (mode) => {
|
|
251
|
+
this.mode = mode;
|
|
252
|
+
};
|
|
253
|
+
// while disabled nothing is reported, so Bullet neither calls back nor keeps bodies awake
|
|
254
|
+
drawer.getDebugMode = () => (this.enabled ? this.mode : 0);
|
|
255
|
+
|
|
256
|
+
this._world = this.app.systems.rigidbody.dynamicsWorld;
|
|
257
|
+
this._world.setDebugDrawer(drawer);
|
|
258
|
+
this._drawer = drawer;
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Removes the debug drawer from the world and frees it.
|
|
264
|
+
*/
|
|
265
|
+
detach() {
|
|
266
|
+
for (const body of this._hiddenBodies) {
|
|
267
|
+
this._setVisualizeFlag(body, true);
|
|
268
|
+
}
|
|
269
|
+
this._hiddenBodies.clear();
|
|
270
|
+
|
|
271
|
+
if (!this._drawer) return;
|
|
272
|
+
try {
|
|
273
|
+
this._world?.setDebugDrawer(null);
|
|
274
|
+
} catch (e) {
|
|
275
|
+
// the world may already be gone
|
|
276
|
+
}
|
|
277
|
+
this._releaseDrawer();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Excludes a body from the drawing by flagging it for Bullet. The flag is re-applied every
|
|
282
|
+
* frame, as the engine rewrites collision flags when it rebuilds a body.
|
|
283
|
+
*
|
|
284
|
+
* @param {any} body - The native `btRigidBody`.
|
|
285
|
+
*/
|
|
286
|
+
hideBody(body) {
|
|
287
|
+
this._hiddenBodies.add(body);
|
|
288
|
+
this._setVisualizeFlag(body, false);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Draws a body again after {@link hideBody}.
|
|
293
|
+
*
|
|
294
|
+
* @param {any} body - The native `btRigidBody`.
|
|
295
|
+
*/
|
|
296
|
+
showBody(body) {
|
|
297
|
+
if (this._hiddenBodies.delete(body)) {
|
|
298
|
+
this._setVisualizeFlag(body, true);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Drops a hidden body without touching it, for a body the engine has destroyed.
|
|
304
|
+
*
|
|
305
|
+
* @param {any} body - The native `btRigidBody`.
|
|
306
|
+
*/
|
|
307
|
+
forgetBody(body) {
|
|
308
|
+
this._hiddenBodies.delete(body);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* @param {any} body - The native `btRigidBody`.
|
|
313
|
+
* @returns {boolean} Whether the body is excluded from the drawing.
|
|
314
|
+
*/
|
|
315
|
+
isBodyHidden(body) {
|
|
316
|
+
return this._hiddenBodies.has(body);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* @param {any} body - The native `btRigidBody`.
|
|
321
|
+
* @param {boolean} visible - Whether Bullet should draw it.
|
|
322
|
+
* @private
|
|
323
|
+
*/
|
|
324
|
+
_setVisualizeFlag(body, visible) {
|
|
325
|
+
try {
|
|
326
|
+
const flags = body.getCollisionFlags();
|
|
327
|
+
const next = visible ? (flags & ~CF_DISABLE_VISUALIZE_OBJECT) : (flags | CF_DISABLE_VISUALIZE_OBJECT);
|
|
328
|
+
if (next !== flags) body.setCollisionFlags(next);
|
|
329
|
+
} catch (e) {
|
|
330
|
+
// a body without a native counterpart yet
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Draws the world for this frame. Call once per frame after the physics step, for example from
|
|
336
|
+
* a script's `postUpdate`.
|
|
337
|
+
*/
|
|
338
|
+
update() {
|
|
339
|
+
const world = this.app.systems.rigidbody?.dynamicsWorld ?? null;
|
|
340
|
+
|
|
341
|
+
// the world was destroyed or recreated under us
|
|
342
|
+
if (this._drawer && world !== this._world) {
|
|
343
|
+
this._releaseDrawer();
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (!this.enabled) {
|
|
347
|
+
this._count = 0;
|
|
348
|
+
this._culled = 0;
|
|
349
|
+
this.lineCount = 0;
|
|
350
|
+
this.culledCount = 0;
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (!this._drawer && !this.attach()) return;
|
|
355
|
+
|
|
356
|
+
if (this.mode & DRAW_FLAGS) {
|
|
357
|
+
for (const body of this._hiddenBodies) {
|
|
358
|
+
this._setVisualizeFlag(body, false);
|
|
359
|
+
}
|
|
360
|
+
this._world.debugDrawWorld();
|
|
361
|
+
}
|
|
362
|
+
this._flush();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Submits the accumulated lines and resets the buffers.
|
|
367
|
+
*
|
|
368
|
+
* @private
|
|
369
|
+
*/
|
|
370
|
+
_flush() {
|
|
371
|
+
const count = this._count;
|
|
372
|
+
if (count > 0) {
|
|
373
|
+
const wire = this.wire;
|
|
374
|
+
wire.depthTest = this.depthTest;
|
|
375
|
+
wire.layer = this.layer;
|
|
376
|
+
wire.linesPacked(this._positions.subarray(0, count * 6), this._colors.subarray(0, count * 8));
|
|
377
|
+
}
|
|
378
|
+
this.lineCount = count;
|
|
379
|
+
this.culledCount = this._culled;
|
|
380
|
+
this._count = 0;
|
|
381
|
+
this._culled = 0;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* @private
|
|
386
|
+
*/
|
|
387
|
+
_releaseDrawer() {
|
|
388
|
+
const Ammo = /** @type {any} */ (globalThis).Ammo;
|
|
389
|
+
try {
|
|
390
|
+
Ammo?.destroy?.(this._drawer);
|
|
391
|
+
} catch (e) {
|
|
392
|
+
// nothing to do
|
|
393
|
+
}
|
|
394
|
+
this._drawer = null;
|
|
395
|
+
this._world = null;
|
|
396
|
+
this._count = 0;
|
|
397
|
+
this._culled = 0;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Reads a `btVector3` at a heap pointer.
|
|
402
|
+
*
|
|
403
|
+
* @param {number} ptr - The pointer.
|
|
404
|
+
* @param {Vec3} out - Receives the vector.
|
|
405
|
+
* @private
|
|
406
|
+
*/
|
|
407
|
+
_read(ptr, out) {
|
|
408
|
+
const Ammo = /** @type {any} */ (globalThis).Ammo;
|
|
409
|
+
const heap = Ammo.HEAPF32;
|
|
410
|
+
if (heap) {
|
|
411
|
+
const i = ptr >> 2;
|
|
412
|
+
out.set(heap[i], heap[i + 1], heap[i + 2]);
|
|
413
|
+
} else {
|
|
414
|
+
const v = Ammo.wrapPointer(ptr, Ammo.btVector3);
|
|
415
|
+
out.set(v.x(), v.y(), v.z());
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @param {number} from - Pointer to the start point.
|
|
421
|
+
* @param {number} to - Pointer to the end point.
|
|
422
|
+
* @param {number} color - Pointer to the color.
|
|
423
|
+
* @private
|
|
424
|
+
*/
|
|
425
|
+
_drawLine(from, to, color) {
|
|
426
|
+
this._read(from, _a);
|
|
427
|
+
this._read(to, _b);
|
|
428
|
+
|
|
429
|
+
if (this.range > 0 && this.center) {
|
|
430
|
+
const rangeSq = this.range * this.range;
|
|
431
|
+
const inA = distanceSq(_a, this.center) <= rangeSq;
|
|
432
|
+
const inB = distanceSq(_b, this.center) <= rangeSq;
|
|
433
|
+
const keep = this.cullPartial ? (inA && inB) : (inA || inB);
|
|
434
|
+
if (!keep) {
|
|
435
|
+
this._culled++;
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
this._read(color, _c);
|
|
441
|
+
this._push(_a, _b, _c);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Draws a contact as its normal plus a small cross at the point.
|
|
446
|
+
*
|
|
447
|
+
* @param {number} point - Pointer to the contact point on the second body.
|
|
448
|
+
* @param {number} normal - Pointer to the contact normal.
|
|
449
|
+
* @param {number} color - Pointer to the color.
|
|
450
|
+
* @private
|
|
451
|
+
*/
|
|
452
|
+
_drawContactPoint(point, normal, color) {
|
|
453
|
+
this._read(point, _a);
|
|
454
|
+
this._read(normal, _b);
|
|
455
|
+
this._read(color, _c);
|
|
456
|
+
|
|
457
|
+
_b.mulScalar(CONTACT_NORMAL_LENGTH).add(_a);
|
|
458
|
+
this._push(_a, _b, _c);
|
|
459
|
+
|
|
460
|
+
const s = CONTACT_CROSS_SIZE;
|
|
461
|
+
_b.set(_a.x - s, _a.y, _a.z);
|
|
462
|
+
_d.set(_a.x + s, _a.y, _a.z);
|
|
463
|
+
this._push(_b, _d, _c);
|
|
464
|
+
_b.set(_a.x, _a.y - s, _a.z);
|
|
465
|
+
_d.set(_a.x, _a.y + s, _a.z);
|
|
466
|
+
this._push(_b, _d, _c);
|
|
467
|
+
_b.set(_a.x, _a.y, _a.z - s);
|
|
468
|
+
_d.set(_a.x, _a.y, _a.z + s);
|
|
469
|
+
this._push(_b, _d, _c);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* @param {Vec3} a - The start point.
|
|
474
|
+
* @param {Vec3} b - The end point.
|
|
475
|
+
* @param {Vec3} c - The color as rgb.
|
|
476
|
+
* @private
|
|
477
|
+
*/
|
|
478
|
+
_push(a, b, c) {
|
|
479
|
+
const i = this._count;
|
|
480
|
+
if ((i + 1) * 6 > this._positions.length) {
|
|
481
|
+
this._grow();
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
const positions = this._positions;
|
|
485
|
+
let p = i * 6;
|
|
486
|
+
positions[p++] = a.x;
|
|
487
|
+
positions[p++] = a.y;
|
|
488
|
+
positions[p++] = a.z;
|
|
489
|
+
positions[p++] = b.x;
|
|
490
|
+
positions[p++] = b.y;
|
|
491
|
+
positions[p++] = b.z;
|
|
492
|
+
|
|
493
|
+
const override = this.color;
|
|
494
|
+
const r = override ? override.r : c.x;
|
|
495
|
+
const g = override ? override.g : c.y;
|
|
496
|
+
const bl = override ? override.b : c.z;
|
|
497
|
+
const alpha = override ? override.a : 1;
|
|
498
|
+
|
|
499
|
+
const colors = this._colors;
|
|
500
|
+
let k = i * 8;
|
|
501
|
+
colors[k++] = r;
|
|
502
|
+
colors[k++] = g;
|
|
503
|
+
colors[k++] = bl;
|
|
504
|
+
colors[k++] = alpha;
|
|
505
|
+
colors[k++] = r;
|
|
506
|
+
colors[k++] = g;
|
|
507
|
+
colors[k++] = bl;
|
|
508
|
+
colors[k++] = alpha;
|
|
509
|
+
|
|
510
|
+
this._count = i + 1;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* @private
|
|
515
|
+
*/
|
|
516
|
+
_grow() {
|
|
517
|
+
const positions = new Float32Array(this._positions.length * 2);
|
|
518
|
+
positions.set(this._positions);
|
|
519
|
+
this._positions = positions;
|
|
520
|
+
|
|
521
|
+
const colors = new Float32Array(this._colors.length * 2);
|
|
522
|
+
colors.set(this._colors);
|
|
523
|
+
this._colors = colors;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
export { AmmoDebugDraw, DEBUG_DRAW };
|