@zephyr3d/scene 0.9.0 → 0.9.2
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/dist/animation/animationset.js +135 -133
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/cloth/gpu_cloth_system.js +9 -1
- package/dist/animation/cloth/gpu_cloth_system.js.map +1 -1
- package/dist/animation/fixed_geometry_cache_track.js +5 -1
- package/dist/animation/fixed_geometry_cache_track.js.map +1 -1
- package/dist/animation/geometry_cache_utils.js +20 -4
- package/dist/animation/geometry_cache_utils.js.map +1 -1
- package/dist/animation/ik/ik_angle_constraint.js +2 -6
- package/dist/animation/ik/ik_angle_constraint.js.map +1 -1
- package/dist/animation/ik/two_bone_ik_solver.js +2 -6
- package/dist/animation/ik/two_bone_ik_solver.js.map +1 -1
- package/dist/animation/joint_dynamics/collision.js +60 -12
- package/dist/animation/joint_dynamics/collision.js.map +1 -1
- package/dist/animation/joint_dynamics/constraints.js +20 -4
- package/dist/animation/joint_dynamics/constraints.js.map +1 -1
- package/dist/animation/joint_dynamics/controller.js +151 -103
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +21 -11
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics/types.js +15 -3
- package/dist/animation/joint_dynamics/types.js.map +1 -1
- package/dist/animation/pca_geometry_cache_track.js +5 -1
- package/dist/animation/pca_geometry_cache_track.js.map +1 -1
- package/dist/animation/skeleton.js +2 -2
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/skeleton_modifier.js +2 -6
- package/dist/animation/skeleton_modifier.js.map +1 -1
- package/dist/animation/spring/spring_system.js +87 -114
- package/dist/animation/spring/spring_system.js.map +1 -1
- package/dist/app/app.js.map +1 -1
- package/dist/app/engine.js +1 -1
- package/dist/app/engine.js.map +1 -1
- package/dist/app/screen.js +4 -4
- package/dist/app/screen.js.map +1 -1
- package/dist/app/scriptingsystem.js +24 -1
- package/dist/app/scriptingsystem.js.map +1 -1
- package/dist/app/scriptregistry.js +165 -144
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +2 -2
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +3 -3
- package/dist/asset/model.js.map +1 -1
- package/dist/camera/camera.js +185 -185
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/orbit.js.map +1 -1
- package/dist/index.d.ts +794 -261
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/material/material.js +290 -288
- package/dist/material/material.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +13 -26
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/pbrmr.js +1 -11
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/sprite.js +6 -6
- package/dist/material/sprite.js.map +1 -1
- package/dist/material/terrain-cm.js +2 -2
- package/dist/material/terrain-cm.js.map +1 -1
- package/dist/posteffect/taa.js +31 -39
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/drawable.js +5 -1
- package/dist/render/drawable.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +29 -3
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/executor.js +283 -33
- package/dist/render/rendergraph/executor.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +338 -108
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/history_resource_manager.js +236 -156
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +10 -0
- package/dist/render/rendergraph/history_resources.js.map +1 -0
- package/dist/render/rendergraph/rendergraph.js +162 -35
- package/dist/render/rendergraph/rendergraph.js.map +1 -1
- package/dist/render/rendergraph/types.js +36 -16
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/rendertarget.js +5 -1
- package/dist/render/rendertarget.js.map +1 -1
- package/dist/render/screenrendertarget.js +5 -1
- package/dist/render/screenrendertarget.js.map +1 -1
- package/dist/render/sky.js +4 -4
- package/dist/render/sky.js.map +1 -1
- package/dist/scene/basesprite.js +2 -2
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/graph_node.js +1 -1
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +4 -20
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/particlesys.js +1 -1
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene_node.js +2 -2
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/script_attachment.js +15 -3
- package/dist/scene/script_attachment.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +3 -3
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shapes/box.js +1 -1
- package/dist/shapes/box.js.map +1 -1
- package/dist/shapes/capsule.js +0 -3
- package/dist/shapes/capsule.js.map +1 -1
- package/dist/shapes/cylinder.js +0 -3
- package/dist/shapes/cylinder.js.map +1 -1
- package/dist/shapes/plane.js +0 -3
- package/dist/shapes/plane.js.map +1 -1
- package/dist/shapes/tetrahedron.js +3 -9
- package/dist/shapes/tetrahedron.js.map +1 -1
- package/dist/shapes/torus.js +4 -7
- package/dist/shapes/torus.js.map +1 -1
- package/dist/utility/blueprint/material/inputs.js +3 -3
- package/dist/utility/blueprint/material/inputs.js.map +1 -1
- package/dist/utility/blueprint/material/ir.js +493 -493
- package/dist/utility/blueprint/material/ir.js.map +1 -1
- package/dist/utility/serialization/manager.js +34 -3
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +45 -0
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +53 -0
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/common.js +10 -0
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +30 -0
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +63 -0
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +11 -0
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/misc.js +2 -0
- package/dist/utility/serialization/scene/misc.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +19 -0
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +22 -0
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +33 -0
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +39 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/script.js +2 -0
- package/dist/utility/serialization/scene/script.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +6 -0
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +9 -0
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +21 -0
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/serialization/types.js +5 -1
- package/dist/utility/serialization/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -3,8 +3,18 @@ import { buildConstraints, buildSurfaceFaces } from './constraints.js';
|
|
|
3
3
|
import { simulate, applyAngleLimits, applyResult } from './solver.js';
|
|
4
4
|
import { Vector3, Quaternion, Matrix4x4, clamp01 } from '@zephyr3d/base';
|
|
5
5
|
|
|
6
|
-
// High-level orchestrator
|
|
7
|
-
|
|
6
|
+
// High-level orchestrator - SPCRJointDynamicsController API
|
|
7
|
+
/**
|
|
8
|
+
* High-level controller for joint dynamics simulation.
|
|
9
|
+
*
|
|
10
|
+
* This class manages the physics simulation for a hierarchy of bones, including constraints,
|
|
11
|
+
* colliders, and grabbers. It provides an API for initializing the system with bone data and
|
|
12
|
+
* transforms, stepping the simulation each frame, and modifying colliders and grabbers at runtime.
|
|
13
|
+
* The controller handles the internal state and logic for blending between animation and physics,
|
|
14
|
+
* applying forces, and enforcing constraints.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/ class JointDynamicsSystemController {
|
|
8
18
|
_config;
|
|
9
19
|
_pointsR = [];
|
|
10
20
|
_pointsRW = [];
|
|
@@ -43,14 +53,14 @@ class JointDynamicsSystemController {
|
|
|
43
53
|
constructor(config){
|
|
44
54
|
this._config = config;
|
|
45
55
|
}
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
* @param rootTransform
|
|
49
|
-
* @param rootPoints
|
|
50
|
-
* @param pointTransforms
|
|
51
|
-
* @param colliders
|
|
52
|
-
* @param grabbers
|
|
53
|
-
* @param flatPlanes
|
|
56
|
+
/**
|
|
57
|
+
* Initializes the physics system.
|
|
58
|
+
* @param rootTransform - Root bone transform used to detect root motion.
|
|
59
|
+
* @param rootPoints - Root nodes of the bone hierarchy. Multiple roots are allowed.
|
|
60
|
+
* @param pointTransforms - Transform array for all physics points. Order must match `BoneNode.index`.
|
|
61
|
+
* @param colliders - Collider array (spheres/capsules).
|
|
62
|
+
* @param grabbers - Grabber array used for interactions such as mouse dragging.
|
|
63
|
+
* @param flatPlanes - Plane limiters such as the floor to prevent penetration.
|
|
54
64
|
*/ initialize(rootTransform, rootPoints, pointTransforms, colliders, grabbers, flatPlanes) {
|
|
55
65
|
this._rootTransform = rootTransform;
|
|
56
66
|
this._pointTransforms = pointTransforms;
|
|
@@ -61,7 +71,7 @@ class JointDynamicsSystemController {
|
|
|
61
71
|
this._surfaceConstraints = buildSurfaceFaces(rootPoints, this._config.constraintOptions.isLoop);
|
|
62
72
|
// Flatten bone hierarchy to point list, build parent map
|
|
63
73
|
const allPoints = [];
|
|
64
|
-
const parentMap = new Map(); // child index
|
|
74
|
+
const parentMap = new Map(); // child index -> parent index
|
|
65
75
|
function walk(node) {
|
|
66
76
|
allPoints.push(node);
|
|
67
77
|
for (const c of node.children){
|
|
@@ -140,10 +150,11 @@ class JointDynamicsSystemController {
|
|
|
140
150
|
}
|
|
141
151
|
this._initialized = true;
|
|
142
152
|
}
|
|
143
|
-
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
153
|
+
/**
|
|
154
|
+
* Advances the simulation by one frame.
|
|
155
|
+
* Internal flow: read current transforms, run Verlet integration and constraint solving,
|
|
156
|
+
* then write the result back to the transforms.
|
|
157
|
+
* @param deltaTime - Frame delta time in seconds. Internally subdivided by `subSteps`.
|
|
147
158
|
*/ step(deltaTime) {
|
|
148
159
|
if (!this._initialized || !this._rootTransform) {
|
|
149
160
|
return;
|
|
@@ -218,10 +229,10 @@ class JointDynamicsSystemController {
|
|
|
218
229
|
this._previousRootPosition = rootPos;
|
|
219
230
|
this._previousRootRotation = rootRot;
|
|
220
231
|
}
|
|
221
|
-
/**
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
232
|
+
/**
|
|
233
|
+
* Returns the simulated results for all points as world-space positions and rotations.
|
|
234
|
+
* Usually this does not need to be called manually because `step()` already writes the
|
|
235
|
+
* output back to the transforms.
|
|
225
236
|
*/ getResults() {
|
|
226
237
|
const transformRots = this._pointTransforms.map((t)=>t.getWorldRotation());
|
|
227
238
|
const transformLocalRots = this._pointTransforms.map((t)=>t.getLocalRotation());
|
|
@@ -231,10 +242,10 @@ class JointDynamicsSystemController {
|
|
|
231
242
|
rotation: o.rotation
|
|
232
243
|
}));
|
|
233
244
|
}
|
|
234
|
-
/**
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
245
|
+
/**
|
|
246
|
+
* Compensates for teleportation by resetting the previous root transform to the current one.
|
|
247
|
+
* Call this after a character warp or teleport to avoid a large root-motion impulse on the
|
|
248
|
+
* next simulation step.
|
|
238
249
|
*/ warp() {
|
|
239
250
|
if (!this._rootTransform) {
|
|
240
251
|
return;
|
|
@@ -242,10 +253,10 @@ class JointDynamicsSystemController {
|
|
|
242
253
|
this._previousRootPosition = this._rootTransform.getWorldPosition();
|
|
243
254
|
this._previousRootRotation = this._rootTransform.getWorldRotation();
|
|
244
255
|
}
|
|
245
|
-
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
256
|
+
/**
|
|
257
|
+
* Resets all physics state.
|
|
258
|
+
* Each simulated point is snapped back to the current transform position and grab state
|
|
259
|
+
* is cleared.
|
|
249
260
|
*/ reset() {
|
|
250
261
|
for(let i = 0; i < this._pointsRW.length; i++){
|
|
251
262
|
const pos = this._pointTransforms[i].getWorldPosition();
|
|
@@ -255,10 +266,10 @@ class JointDynamicsSystemController {
|
|
|
255
266
|
}
|
|
256
267
|
this._fakeWaveCounter = 0;
|
|
257
268
|
}
|
|
258
|
-
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* @param index
|
|
269
|
+
/**
|
|
270
|
+
* Releases a fixed point so it becomes dynamic, for example when cloth is detached.
|
|
271
|
+
* The point state is reset to avoid a sudden impulse.
|
|
272
|
+
* @param index - Point index.
|
|
262
273
|
*/ releasePoint(index) {
|
|
263
274
|
if (index < 0 || index >= this._pointsR.length) {
|
|
264
275
|
return;
|
|
@@ -269,10 +280,10 @@ class JointDynamicsSystemController {
|
|
|
269
280
|
this._pointsRW[index].positionPrevious = pos.clone();
|
|
270
281
|
this._pointsRW[index].grabberIndex = -1;
|
|
271
282
|
}
|
|
272
|
-
/**
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
* @param index
|
|
283
|
+
/**
|
|
284
|
+
* Fixes a dynamic point back to the animation pose, for example when an item is reattached.
|
|
285
|
+
* The point grab state is cleared.
|
|
286
|
+
* @param index - Point index.
|
|
276
287
|
*/ fixPoint(index) {
|
|
277
288
|
if (index < 0 || index >= this._pointsR.length) {
|
|
278
289
|
return;
|
|
@@ -280,44 +291,47 @@ class JointDynamicsSystemController {
|
|
|
280
291
|
this._pointsR[index].weight = 0;
|
|
281
292
|
this._pointsRW[index].grabberIndex = -1;
|
|
282
293
|
}
|
|
283
|
-
/**
|
|
284
|
-
*
|
|
285
|
-
* @param index
|
|
294
|
+
/**
|
|
295
|
+
* Returns whether a point is fixed to animation (`weight = 0`).
|
|
296
|
+
* @param index - Point index.
|
|
286
297
|
*/ isPointFixed(index) {
|
|
287
298
|
if (index < 0 || index >= this._pointsR.length) {
|
|
288
299
|
return false;
|
|
289
300
|
}
|
|
290
301
|
return this._pointsR[index].weight <= EPSILON;
|
|
291
302
|
}
|
|
292
|
-
/**
|
|
303
|
+
/** Gets the total number of physics points. */ get pointCount() {
|
|
293
304
|
return this._pointsR.length;
|
|
294
305
|
}
|
|
295
|
-
/**
|
|
296
|
-
*
|
|
297
|
-
* blendRatio
|
|
298
|
-
* @param seconds
|
|
306
|
+
/**
|
|
307
|
+
* Fades physics in by blending from animation pose to simulation.
|
|
308
|
+
* `blendRatio` moves from `1` (animation only) to `0` (physics only).
|
|
309
|
+
* @param seconds - Transition duration in seconds.
|
|
299
310
|
*/ fadeIn(seconds) {
|
|
300
311
|
this._fadeState = 'in';
|
|
301
312
|
this._fadeTimer = 0;
|
|
302
313
|
this._fadeDuration = seconds;
|
|
303
314
|
}
|
|
304
|
-
/**
|
|
305
|
-
*
|
|
306
|
-
* blendRatio
|
|
307
|
-
* @param seconds
|
|
315
|
+
/**
|
|
316
|
+
* Fades physics out by blending from simulation back to animation pose.
|
|
317
|
+
* `blendRatio` moves from `0` (physics only) to `1` (animation only).
|
|
318
|
+
* @param seconds - Transition duration in seconds.
|
|
308
319
|
*/ fadeOut(seconds) {
|
|
309
320
|
this._fadeState = 'out';
|
|
310
321
|
this._fadeTimer = 0;
|
|
311
322
|
this._fadeDuration = seconds;
|
|
312
323
|
}
|
|
313
|
-
/**
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
* @param wind
|
|
324
|
+
/**
|
|
325
|
+
* Sets the global wind force vector.
|
|
326
|
+
* The final wind contribution is still scaled per point by `windForceScale` and mass.
|
|
327
|
+
* @param wind - Wind vector in world space.
|
|
317
328
|
*/ setWindForce(wind) {
|
|
318
329
|
this._config.windForce = wind;
|
|
319
330
|
}
|
|
320
|
-
/**
|
|
331
|
+
/**
|
|
332
|
+
* Enable/disable broad-phase pruning for runtime performance comparison
|
|
333
|
+
* @param enabled - `true` to enable broad-phase, `false` to disable.
|
|
334
|
+
*/ setBroadPhaseEnabled(enabled) {
|
|
321
335
|
this._config.enableBroadPhase = enabled;
|
|
322
336
|
}
|
|
323
337
|
/** The blend ratio for the physics simulation */ get blendRatio() {
|
|
@@ -326,17 +340,23 @@ class JointDynamicsSystemController {
|
|
|
326
340
|
set blendRatio(value) {
|
|
327
341
|
this._config.blendRatio = clamp01(value);
|
|
328
342
|
}
|
|
329
|
-
/**
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
343
|
+
/**
|
|
344
|
+
* Pauses or resumes the physics simulation.
|
|
345
|
+
* While paused, the system still follows root motion but skips force integration and
|
|
346
|
+
* constraint solving.
|
|
347
|
+
* @param paused - `true` to pause, `false` to resume.
|
|
333
348
|
*/ setPaused(paused) {
|
|
334
349
|
this._isPaused = paused;
|
|
335
350
|
}
|
|
336
|
-
/**
|
|
337
|
-
* Enable or disable a collider by current array index.
|
|
338
|
-
* Transform state is still read from the collider's TransformAccess each frame.
|
|
339
|
-
* Prefer setColliderEnabled(handle, enabled) for runtime-owned colliders.
|
|
351
|
+
/**
|
|
352
|
+
* Enable or disable a collider by current array index.
|
|
353
|
+
* Transform state is still read from the collider's TransformAccess each frame.
|
|
354
|
+
* Prefer setColliderEnabled(handle, enabled) for runtime-owned colliders.
|
|
355
|
+
*
|
|
356
|
+
* @param index - Collider index in the current array. Note that this may change when colliders are added or removed.
|
|
357
|
+
* @param enabled - `true` to enable the collider, `false` to disable it.
|
|
358
|
+
*
|
|
359
|
+
* @returns `true` if the index is valid and the collider was updated, `false` if the index is out of range.
|
|
340
360
|
*/ setColliderEnabledAt(index, enabled) {
|
|
341
361
|
if (index >= 0 && index < this._collidersRW.length) {
|
|
342
362
|
this._collidersRW[index].enabled = enabled ? 1 : 0;
|
|
@@ -344,9 +364,12 @@ class JointDynamicsSystemController {
|
|
|
344
364
|
}
|
|
345
365
|
return false;
|
|
346
366
|
}
|
|
347
|
-
/**
|
|
348
|
-
* Enable or disable a runtime collider by stable handle.
|
|
349
|
-
*
|
|
367
|
+
/**
|
|
368
|
+
* Enable or disable a runtime collider by stable handle.
|
|
369
|
+
*
|
|
370
|
+
* @param handle - Stable handle for the collider to enable or disable.
|
|
371
|
+
* @param enabled - `true` to enable the collider, `false` to disable it.
|
|
372
|
+
* @returns true if the handle is still valid.
|
|
350
373
|
*/ setColliderEnabled(handle, enabled) {
|
|
351
374
|
const index = this._getColliderIndex(handle);
|
|
352
375
|
if (index === -1) {
|
|
@@ -354,9 +377,11 @@ class JointDynamicsSystemController {
|
|
|
354
377
|
}
|
|
355
378
|
return this.setColliderEnabledAt(index, enabled);
|
|
356
379
|
}
|
|
357
|
-
/**
|
|
358
|
-
* Add a collider at runtime.
|
|
359
|
-
* @
|
|
380
|
+
/**
|
|
381
|
+
* Add a collider at runtime.
|
|
382
|
+
* @param r - Read-only collider data such as shape and size.
|
|
383
|
+
* @param transform - TransformAccess that provides the collider's position and rotation each frame.
|
|
384
|
+
* @returns A stable handle that remains valid until this collider is removed.
|
|
360
385
|
*/ addCollider(r, transform) {
|
|
361
386
|
const id = this._nextColliderHandleId++;
|
|
362
387
|
this._collidersR.push(r);
|
|
@@ -369,9 +394,10 @@ class JointDynamicsSystemController {
|
|
|
369
394
|
id
|
|
370
395
|
};
|
|
371
396
|
}
|
|
372
|
-
/**
|
|
373
|
-
* Remove a collider by stable handle.
|
|
374
|
-
* @
|
|
397
|
+
/**
|
|
398
|
+
* Remove a collider by stable handle.
|
|
399
|
+
* @param handle - Stable handle for the collider to remove.
|
|
400
|
+
* @returns true if the collider existed and was removed.
|
|
375
401
|
*/ removeCollider(handle) {
|
|
376
402
|
const index = this._getColliderIndex(handle);
|
|
377
403
|
if (index === -1) {
|
|
@@ -379,9 +405,10 @@ class JointDynamicsSystemController {
|
|
|
379
405
|
}
|
|
380
406
|
return this.removeColliderAt(index);
|
|
381
407
|
}
|
|
382
|
-
/**
|
|
383
|
-
* Remove a collider by current array index.
|
|
384
|
-
*
|
|
408
|
+
/**
|
|
409
|
+
* Remove a collider by current array index.
|
|
410
|
+
* @param index - Collider index in the current array. Note that this may change when colliders are added or removed.
|
|
411
|
+
* Prefer removeCollider(handle) for runtime-owned colliders.
|
|
385
412
|
*/ removeColliderAt(index) {
|
|
386
413
|
if (index < 0 || index >= this._collidersR.length) {
|
|
387
414
|
return false;
|
|
@@ -393,9 +420,11 @@ class JointDynamicsSystemController {
|
|
|
393
420
|
this._rebuildColliderHandleMap();
|
|
394
421
|
return true;
|
|
395
422
|
}
|
|
396
|
-
/**
|
|
397
|
-
* Enable or disable a flat plane by current array index.
|
|
398
|
-
*
|
|
423
|
+
/**
|
|
424
|
+
* Enable or disable a flat plane by current array index.
|
|
425
|
+
* @param index - Flat plane index in the current array. Note that this may change when flat planes are added or removed.
|
|
426
|
+
* @param enabled - `true` to enable the flat plane, `false` to disable it.
|
|
427
|
+
* @returns `true` if the index is valid and the flat plane was updated, `false` if the index is out of range.
|
|
399
428
|
*/ setFlatPlaneEnabledAt(index, enabled) {
|
|
400
429
|
if (index < 0 || index >= this._flatPlaneAll.length) {
|
|
401
430
|
return false;
|
|
@@ -404,9 +433,11 @@ class JointDynamicsSystemController {
|
|
|
404
433
|
this._rebuildActiveFlatPlanes();
|
|
405
434
|
return true;
|
|
406
435
|
}
|
|
407
|
-
/**
|
|
408
|
-
* Enable or disable a runtime flat plane by stable handle.
|
|
409
|
-
* @
|
|
436
|
+
/**
|
|
437
|
+
* Enable or disable a runtime flat plane by stable handle.
|
|
438
|
+
* @param handle - Stable handle for the flat plane to enable or disable.
|
|
439
|
+
* @param enabled - `true` to enable the flat plane, `false` to disable it.
|
|
440
|
+
* @returns true if the handle is still valid.
|
|
410
441
|
*/ setFlatPlaneEnabled(handle, enabled) {
|
|
411
442
|
const index = this._getFlatPlaneIndex(handle);
|
|
412
443
|
if (index === -1) {
|
|
@@ -414,9 +445,11 @@ class JointDynamicsSystemController {
|
|
|
414
445
|
}
|
|
415
446
|
return this.setFlatPlaneEnabledAt(index, enabled);
|
|
416
447
|
}
|
|
417
|
-
/**
|
|
418
|
-
* Add a flat plane at runtime.
|
|
419
|
-
* @
|
|
448
|
+
/**
|
|
449
|
+
* Add a flat plane at runtime.
|
|
450
|
+
* @param up - Up direction of the plane. The normal is computed as `Vector3.normalize(up)`.
|
|
451
|
+
* @param position - A point on the plane. The distance is computed as `-Vector3.dot(normal, position)`.
|
|
452
|
+
* @returns A stable handle that remains valid until this flat plane is removed.
|
|
420
453
|
*/ addFlatPlane(up, position) {
|
|
421
454
|
const id = this._nextFlatPlaneHandleId++;
|
|
422
455
|
const normal = Vector3.normalize(up);
|
|
@@ -433,9 +466,10 @@ class JointDynamicsSystemController {
|
|
|
433
466
|
id
|
|
434
467
|
};
|
|
435
468
|
}
|
|
436
|
-
/**
|
|
437
|
-
* Remove a flat plane by stable handle.
|
|
438
|
-
* @
|
|
469
|
+
/**
|
|
470
|
+
* Remove a flat plane by stable handle.
|
|
471
|
+
* @param handle - Stable handle for the flat plane to remove.
|
|
472
|
+
* @returns true if the flat plane existed and was removed.
|
|
439
473
|
*/ removeFlatPlane(handle) {
|
|
440
474
|
const index = this._getFlatPlaneIndex(handle);
|
|
441
475
|
if (index === -1) {
|
|
@@ -443,9 +477,10 @@ class JointDynamicsSystemController {
|
|
|
443
477
|
}
|
|
444
478
|
return this.removeFlatPlaneAt(index);
|
|
445
479
|
}
|
|
446
|
-
/**
|
|
447
|
-
* Remove a flat plane by current array index.
|
|
448
|
-
*
|
|
480
|
+
/**
|
|
481
|
+
* Remove a flat plane by current array index.
|
|
482
|
+
* @param index - Flat plane index in the current array. Note that this may change when flat planes are added or removed.
|
|
483
|
+
* @returns true if the index was valid and the flat plane was removed, false if the index was out of range.
|
|
449
484
|
*/ removeFlatPlaneAt(index) {
|
|
450
485
|
if (index < 0 || index >= this._flatPlaneAll.length) {
|
|
451
486
|
return false;
|
|
@@ -457,10 +492,14 @@ class JointDynamicsSystemController {
|
|
|
457
492
|
this._rebuildActiveFlatPlanes();
|
|
458
493
|
return true;
|
|
459
494
|
}
|
|
460
|
-
/**
|
|
461
|
-
* Enable or disable a grabber by current array index.
|
|
462
|
-
* Transform state is still read from the grabber's TransformAccess each frame.
|
|
463
|
-
* Prefer setGrabberEnabled(handle, enabled) for runtime-owned grabbers.
|
|
495
|
+
/**
|
|
496
|
+
* Enable or disable a grabber by current array index.
|
|
497
|
+
* Transform state is still read from the grabber's TransformAccess each frame.
|
|
498
|
+
* Prefer setGrabberEnabled(handle, enabled) for runtime-owned grabbers.
|
|
499
|
+
*
|
|
500
|
+
* @param index - Grabber index in the current array. Note that this may change when grabbers are added or removed.
|
|
501
|
+
* @param enabled - `true` to enable the grabber, `false` to disable it.
|
|
502
|
+
* @returns `true` if the index is valid and the grabber was updated, `false` if the index is out of range.
|
|
464
503
|
*/ setGrabberEnabledAt(index, enabled) {
|
|
465
504
|
if (index >= 0 && index < this._grabbersRW.length) {
|
|
466
505
|
this._grabbersRW[index].enabled = enabled ? 1 : 0;
|
|
@@ -471,9 +510,11 @@ class JointDynamicsSystemController {
|
|
|
471
510
|
}
|
|
472
511
|
return false;
|
|
473
512
|
}
|
|
474
|
-
/**
|
|
475
|
-
* Enable or disable a runtime grabber by stable handle.
|
|
476
|
-
* @
|
|
513
|
+
/**
|
|
514
|
+
* Enable or disable a runtime grabber by stable handle.
|
|
515
|
+
* @param handle - Stable handle for the grabber to enable or disable.
|
|
516
|
+
* @param enabled - `true` to enable the grabber, `false` to disable it.
|
|
517
|
+
* @returns true if the handle is still valid.
|
|
477
518
|
*/ setGrabberEnabled(handle, enabled) {
|
|
478
519
|
const index = this._getGrabberIndex(handle);
|
|
479
520
|
if (index === -1) {
|
|
@@ -481,9 +522,12 @@ class JointDynamicsSystemController {
|
|
|
481
522
|
}
|
|
482
523
|
return this.setGrabberEnabledAt(index, enabled);
|
|
483
524
|
}
|
|
484
|
-
/**
|
|
485
|
-
* Add a grabber at runtime.
|
|
486
|
-
* @
|
|
525
|
+
/**
|
|
526
|
+
* Add a grabber at runtime.
|
|
527
|
+
* @param r - Read-only grabber data such as interaction radius.
|
|
528
|
+
* @param transform - TransformAccess that provides the grabber's position each frame.
|
|
529
|
+
* @param enabled - Whether the grabber starts enabled. The grabber can still be moved by its transform while disabled, but it won't affect any points until enabled.
|
|
530
|
+
* @returns A stable handle that remains valid until this grabber is removed.
|
|
487
531
|
*/ addGrabber(r, transform, enabled = false) {
|
|
488
532
|
const id = this._nextGrabberHandleId++;
|
|
489
533
|
this._grabbersR.push(r);
|
|
@@ -499,9 +543,10 @@ class JointDynamicsSystemController {
|
|
|
499
543
|
id
|
|
500
544
|
};
|
|
501
545
|
}
|
|
502
|
-
/**
|
|
503
|
-
* Remove a grabber by stable handle.
|
|
504
|
-
* @
|
|
546
|
+
/**
|
|
547
|
+
* Remove a grabber by stable handle.
|
|
548
|
+
* @param handle - Stable handle for the grabber to remove.
|
|
549
|
+
* @returns true if the grabber existed and was removed.
|
|
505
550
|
*/ removeGrabber(handle) {
|
|
506
551
|
const index = this._getGrabberIndex(handle);
|
|
507
552
|
if (index === -1) {
|
|
@@ -509,9 +554,12 @@ class JointDynamicsSystemController {
|
|
|
509
554
|
}
|
|
510
555
|
return this.removeGrabberAt(index);
|
|
511
556
|
}
|
|
512
|
-
/**
|
|
513
|
-
* Remove a grabber by current array index.
|
|
514
|
-
* Prefer removeGrabber(handle) for runtime-owned grabbers.
|
|
557
|
+
/**
|
|
558
|
+
* Remove a grabber by current array index.
|
|
559
|
+
* Prefer removeGrabber(handle) for runtime-owned grabbers.
|
|
560
|
+
*
|
|
561
|
+
* @param index - Grabber index in the current array. Note that this may change when grabbers are added or removed.
|
|
562
|
+
* @returns true if the index was valid and the grabber was removed, false if the index was out of range.
|
|
515
563
|
*/ removeGrabberAt(index) {
|
|
516
564
|
if (index < 0 || index >= this._grabbersR.length) {
|
|
517
565
|
return false;
|