@relu-interactives/spatial-ecs 0.3.12 → 0.3.14

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.
Files changed (45) hide show
  1. package/dist/{System-31wk-A0g.d.cts → System-BhnLw0fZ.d.cts} +7 -0
  2. package/dist/{System-31wk-A0g.d.ts → System-BhnLw0fZ.d.ts} +7 -0
  3. package/dist/{XRHandPose-DawOR0uR.d.cts → XRHandPose-LR4EhboN.d.cts} +25 -9
  4. package/dist/{XRHandPose-DhAd9Qi6.d.ts → XRHandPose-SZ7ou63b.d.ts} +25 -9
  5. package/dist/{chunk-OMDYLFTN.js → chunk-3LDQ4GVZ.js} +5 -5
  6. package/dist/chunk-3LDQ4GVZ.js.map +1 -0
  7. package/dist/{chunk-7ZIN6TGT.js → chunk-PNQ7HDQC.js} +3 -3
  8. package/dist/{chunk-7ZIN6TGT.js.map → chunk-PNQ7HDQC.js.map} +1 -1
  9. package/dist/{chunk-ID7U4FER.js → chunk-UHJ4MDIM.js} +7 -4
  10. package/dist/chunk-UHJ4MDIM.js.map +1 -0
  11. package/dist/{chunk-LCJ6IH2O.js → chunk-XHMOFI3Q.js} +104 -16
  12. package/dist/chunk-XHMOFI3Q.js.map +1 -0
  13. package/dist/components/index.cjs +3 -3
  14. package/dist/components/index.cjs.map +1 -1
  15. package/dist/components/index.d.cts +3 -3
  16. package/dist/components/index.d.ts +3 -3
  17. package/dist/components/index.js +1 -1
  18. package/dist/docs/guide/vr-and-hand-poses.md +5 -3
  19. package/dist/factories/index.cjs +6 -3
  20. package/dist/factories/index.cjs.map +1 -1
  21. package/dist/factories/index.d.cts +2 -2
  22. package/dist/factories/index.d.ts +2 -2
  23. package/dist/factories/index.js +3 -3
  24. package/dist/{index-Xm3im4Pt.d.cts → index-BL5EWkwY.d.cts} +2 -2
  25. package/dist/{index-B49322Q3.d.ts → index-ByiUoIoh.d.ts} +2 -2
  26. package/dist/{index-DJ9bn9SF.d.cts → index-CbrjAm_8.d.cts} +23 -1
  27. package/dist/{index-M0I5B3JA.d.ts → index-CvIXdHzx.d.ts} +23 -1
  28. package/dist/index.cjs +106 -14
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +45 -8
  31. package/dist/index.d.ts +45 -8
  32. package/dist/index.js +8 -8
  33. package/dist/systems/index.cjs +102 -14
  34. package/dist/systems/index.cjs.map +1 -1
  35. package/dist/systems/index.d.cts +2 -2
  36. package/dist/systems/index.d.ts +2 -2
  37. package/dist/systems/index.js +3 -3
  38. package/dist/types.d.cts +1 -1
  39. package/dist/types.d.ts +1 -1
  40. package/dist/worldSnapshotUtils.d.cts +1 -1
  41. package/dist/worldSnapshotUtils.d.ts +1 -1
  42. package/package.json +1 -1
  43. package/dist/chunk-ID7U4FER.js.map +0 -1
  44. package/dist/chunk-LCJ6IH2O.js.map +0 -1
  45. package/dist/chunk-OMDYLFTN.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { resolveDracoDecoderPath, applyTransform, SHARED_MODEL_RESOURCE_FLAG } from './chunk-7ZIN6TGT.js';
2
- import { AnimationComponent, ModelComponent, CameraComponent, Object3DRef, Environment, Postprocessing, TransformComponent, PhysicsComponent, setPhysicsLiveRef, LightComponent, MaterialComponent, DEFAULT_MESH_GEOMETRY_PARAMETERS, MeshGeometryComponent, InstancedMeshComponent, ParentId, ScriptComponent, ScriptObjectComponent, XRRigComponent, VRTeleportAreaComponent, XRInteractableComponent, createAttachPoint, XRHandPoseComponent, createHandPoseEntry, XRInteractorComponent, XRInteractorSideComponent, InstanceSlotComponent, Name, ImageComponent, SpriteComponent, VideoComponent, AudioComponent, ImageTarget, Selectable, PrefabNode, PrefabInstance, handPoseDefinitionFor, getHandPosePreset } from './chunk-OMDYLFTN.js';
1
+ import { resolveDracoDecoderPath, applyTransform, SHARED_MODEL_RESOURCE_FLAG } from './chunk-PNQ7HDQC.js';
2
+ import { AnimationComponent, ModelComponent, CameraComponent, Object3DRef, Environment, Postprocessing, TransformComponent, PhysicsComponent, setPhysicsLiveRef, LightComponent, MaterialComponent, DEFAULT_MESH_GEOMETRY_PARAMETERS, MeshGeometryComponent, InstancedMeshComponent, ParentId, ScriptComponent, ScriptObjectComponent, XRRigComponent, VRTeleportAreaComponent, XRInteractableComponent, createAttachPoint, XRHandPoseComponent, createHandPoseEntry, XRInteractorComponent, XRInteractorSideComponent, InstanceSlotComponent, Name, ImageComponent, SpriteComponent, VideoComponent, AudioComponent, ImageTarget, Selectable, PrefabNode, PrefabInstance, handPoseDefinitionFor, getHandPosePreset } from './chunk-3LDQ4GVZ.js';
3
3
  import { __name } from './chunk-OY7ZODZP.js';
4
4
  import * as THREE19 from 'three';
5
5
  import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
@@ -3051,11 +3051,15 @@ function restorePostCreateComponents(world, objectManagementSystem, targetEntity
3051
3051
  )
3052
3052
  );
3053
3053
  }
3054
- if (typeof sourceInteractable.throwOnRelease === "boolean") {
3055
- interactable.throwOnRelease = sourceInteractable.throwOnRelease;
3054
+ if (typeof sourceInteractable.applyVelocityOnRelease === "boolean") {
3055
+ interactable.applyVelocityOnRelease = sourceInteractable.applyVelocityOnRelease;
3056
+ } else if (typeof sourceInteractable.throwOnRelease === "boolean") {
3057
+ interactable.applyVelocityOnRelease = sourceInteractable.throwOnRelease;
3056
3058
  }
3057
- if (typeof sourceInteractable.throwStrength === "number") {
3058
- interactable.throwStrength = sourceInteractable.throwStrength;
3059
+ if (typeof sourceInteractable.velocityScale === "number") {
3060
+ interactable.velocityScale = sourceInteractable.velocityScale;
3061
+ } else if (typeof sourceInteractable.throwStrength === "number") {
3062
+ interactable.velocityScale = sourceInteractable.throwStrength;
3059
3063
  }
3060
3064
  const grabPos = asRecord(sourceInteractable.grabOffsetPosition);
3061
3065
  if (grabPos) {
@@ -3131,8 +3135,10 @@ function restorePostCreateComponents(world, objectManagementSystem, targetEntity
3131
3135
  if (typeof sourceInteractor.handEmissiveIntensity === "number") {
3132
3136
  interactor.handEmissiveIntensity = sourceInteractor.handEmissiveIntensity;
3133
3137
  }
3134
- if (typeof sourceInteractor.showRay === "boolean") {
3135
- interactor.showRay = sourceInteractor.showRay;
3138
+ if (typeof sourceInteractor.rayVisibility === "string") {
3139
+ interactor.rayVisibility = sourceInteractor.rayVisibility;
3140
+ } else if (typeof sourceInteractor.showRay === "boolean") {
3141
+ interactor.rayVisibility = sourceInteractor.showRay ? "interacting" : "never";
3136
3142
  }
3137
3143
  if (typeof sourceInteractor.rayColor === "string") {
3138
3144
  interactor.rayColor = sourceInteractor.rayColor;
@@ -3939,6 +3945,7 @@ function hydrateWorldFromSnapshotDetailed(snapshot, world, objectManagementSyste
3939
3945
  isDefault: true
3940
3946
  };
3941
3947
  }
3948
+ payload.skipDefaultChildren = true;
3942
3949
  const createdEntityId = objectManagementSystem.createNow(kind, world, payload);
3943
3950
  idMap.set(sourceEntityId, createdEntityId);
3944
3951
  }
@@ -7115,8 +7122,8 @@ var _XRInteractionSystem = class _XRInteractionSystem {
7115
7122
  if (held.restoreBodyType !== null && physics) {
7116
7123
  physics.values.rigidbody.type = held.restoreBodyType;
7117
7124
  const dynamic = held.restoreBodyType === "dynamic";
7118
- if (dynamic && interactable?.throwOnRelease) {
7119
- const velocity = held.tracker.computeVelocity(this.elapsed).multiplyScalar(interactable.throwStrength);
7125
+ if (dynamic && interactable?.applyVelocityOnRelease) {
7126
+ const velocity = held.tracker.computeVelocity(this.elapsed).multiplyScalar(interactable.velocityScale);
7120
7127
  const spin = held.angularVelocity;
7121
7128
  setPhysicsLiveRef(physics, "pendingVelocity", {
7122
7129
  linear: { x: velocity.x, y: velocity.y, z: velocity.z },
@@ -7197,6 +7204,25 @@ var _XRInteractionSystem = class _XRInteractionSystem {
7197
7204
  isGrabbing() {
7198
7205
  return this.grabs.size > 0;
7199
7206
  }
7207
+ /**
7208
+ * Whether this hand's primary action is committed to interaction.
7209
+ *
7210
+ * True while the hand holds something, and also while it merely HOVERS a
7211
+ * grabbable — because the pinch that is about to grab must not be read as a
7212
+ * teleport by the locomotion system. Without the hover half, the first pinch
7213
+ * of a grab teleports the player, and so does the pinch that takes an object
7214
+ * from the other hand.
7215
+ */
7216
+ isHandBusy(world, handedness) {
7217
+ if (this.isGrabbingWith(handedness)) return true;
7218
+ const hover = this.getHoverFor(handedness);
7219
+ if (!hover) return false;
7220
+ const interactable = world.getComponent(
7221
+ hover.entityId,
7222
+ XRInteractableComponent
7223
+ );
7224
+ return Boolean(interactable?.enabled && interactable.grabbable);
7225
+ }
7200
7226
  /** True when THIS hand is holding something. */
7201
7227
  isGrabbingWith(handedness) {
7202
7228
  for (const input of this.grabs.keys()) {
@@ -7268,6 +7294,42 @@ function arcGroundCrossing(points, groundY) {
7268
7294
  }
7269
7295
  __name(arcGroundCrossing, "arcGroundCrossing");
7270
7296
 
7297
+ // core/xr/teleportAimGate.ts
7298
+ var _TeleportAimGate = class _TeleportAimGate {
7299
+ constructor() {
7300
+ this.aiming = /* @__PURE__ */ new WeakSet();
7301
+ }
7302
+ /**
7303
+ * Feed one frame for one source.
7304
+ *
7305
+ * @returns whether the teleport should commit this frame.
7306
+ */
7307
+ update(source, aiming, releasing) {
7308
+ const hadAim = this.aiming.has(source);
7309
+ if (aiming) this.aiming.add(source);
7310
+ if (!releasing) return false;
7311
+ this.aiming.delete(source);
7312
+ return hadAim;
7313
+ }
7314
+ /** True if this source currently has an aim engaged. */
7315
+ isAiming(source) {
7316
+ return this.aiming.has(source);
7317
+ }
7318
+ /**
7319
+ * Drop a source's aim without committing.
7320
+ *
7321
+ * Called when a hand starts interacting, so the release that ends the grab
7322
+ * cannot cash in an aim engaged before it.
7323
+ *
7324
+ * @returns whether an aim was actually discarded.
7325
+ */
7326
+ cancel(source) {
7327
+ return this.aiming.delete(source);
7328
+ }
7329
+ };
7330
+ __name(_TeleportAimGate, "TeleportAimGate");
7331
+ var TeleportAimGate = _TeleportAimGate;
7332
+
7271
7333
  // core/systems/XRLocomotionSystem.ts
7272
7334
  var UP = new THREE19.Vector3(0, 1, 0);
7273
7335
  var AXIS_DEADZONE = 0.5;
@@ -7285,10 +7347,24 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
7285
7347
  this.aimValid = false;
7286
7348
  /** Sources currently aiming via thumbstick (hysteresis, so it doesn't chatter). */
7287
7349
  this.stickAiming = /* @__PURE__ */ new WeakSet();
7350
+ /** Gates teleport commits on a prior aim. See {@link TeleportAimGate}. */
7351
+ this.teleportAim = new TeleportAimGate();
7288
7352
  /** True once we've tried to self-heal camera parenting for this session. */
7289
7353
  this.parentingChecked = false;
7354
+ /**
7355
+ * Optional; when wired, hands busy grabbing are excluded from teleport.
7356
+ *
7357
+ * On hand tracking the SAME pinch drives both grabbing and teleport aiming,
7358
+ * so without this a user who picks something up is teleported at the same
7359
+ * moment.
7360
+ */
7361
+ this.interactionSystem = null;
7290
7362
  this.inputSystem = inputSystem;
7291
7363
  }
7364
+ /** Wire the interaction system so grabs suppress teleport on that hand. */
7365
+ setInteractionSystem(interactionSystem) {
7366
+ this.interactionSystem = interactionSystem;
7367
+ }
7292
7368
  update(world, deltaTime) {
7293
7369
  this.aimCurve = [];
7294
7370
  this.landingPoint = null;
@@ -7407,9 +7483,18 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
7407
7483
  const targets = this.collectTeleportTargets(world);
7408
7484
  for (const input of inputs) {
7409
7485
  const source = input;
7486
+ if (input.handedness !== "none" && this.interactionSystem?.isHandBusy(world, input.handedness)) {
7487
+ if (this.teleportAim.cancel(source)) {
7488
+ this.aimCurve = [];
7489
+ this.landingPoint = null;
7490
+ this.aimValid = false;
7491
+ }
7492
+ continue;
7493
+ }
7410
7494
  const stick = this.readStickAim(input, source);
7411
7495
  const aiming = input.select || stick.aiming;
7412
- const commit = input.selectEnd || stick.released;
7496
+ const releasing = input.selectEnd || stick.released;
7497
+ const commit = this.teleportAim.update(source, aiming, releasing);
7413
7498
  if (!aiming && !commit) continue;
7414
7499
  const points = sampleTeleportArc(
7415
7500
  input.rayOrigin,
@@ -7882,9 +7967,12 @@ var _XRControllerVisualSystem = class _XRControllerVisualSystem {
7882
7967
  * clutter implying the whole scene is clickable.
7883
7968
  */
7884
7969
  shouldShowRay(interactor, side) {
7885
- if (interactor && !interactor.showRay) return false;
7970
+ const visibility = interactor?.rayVisibility ?? "interacting";
7971
+ if (visibility === "never") return false;
7972
+ if (visibility === "always") return true;
7886
7973
  if (!this.interactionSystem) return true;
7887
- return this.interactionSystem.getHoverFor(side) !== null || this.interactionSystem.isGrabbingWith(side);
7974
+ if (this.interactionSystem.isGrabbingWith(side)) return false;
7975
+ return this.interactionSystem.getHoverFor(side) !== null;
7888
7976
  }
7889
7977
  /** Push the author's ray colour and thickness onto the mesh. */
7890
7978
  applyRayStyle(ray, interactor) {
@@ -8772,6 +8860,6 @@ var _XRHoverVisualSystem = class _XRHoverVisualSystem {
8772
8860
  __name(_XRHoverVisualSystem, "XRHoverVisualSystem");
8773
8861
  var XRHoverVisualSystem = _XRHoverVisualSystem;
8774
8862
 
8775
- export { ADDED_NODE_MARKER_COMPONENT, ARC_GRAVITY, ARC_MAX_TIME, ARC_SPEED, ARC_STEPS, AnimationSystem, AudioSystem, Behaviour, CURLED_COS, CameraSyncSystem, DEFAULT_ENTER_CONFIDENCE, DEFAULT_EXIT_CONFIDENCE, DEFAULT_LOST_GRACE_SECONDS, DEFAULT_MIN_HOLD_SECONDS, EnvironmentSyncSystem, FALLBACK_HAND_SCALE, HYDRATABLE_ENTITY_KINDS, HandPoseTracker, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MATCH_FALLOFF, MAX_PLAUSIBLE_SPEED, MAX_SAMPLE_AGE_SECONDS, MaterialSyncSystem, MeshGeometrySystem, NODE_KEY_SEPARATOR, NO_XR_CAPABILITIES, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, ObjectVisibilitySystem, PINCH_FINGERS, PREFAB_FILE_VERSION, PREFAB_FILE_VERSION_NESTED, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, SCRIPT_OBJECT_ROOT_FLAG, STRAIGHT_COS, ScriptBehaviourSystem, ScriptObject, ScriptObjectSystem, ThrowVelocityTracker, TransformSyncSystem, VELOCITY_SAMPLES, VRTeleportAreaSystem, VideoSystem, XRControllerVisualSystem, XRHandPoseSystem, XRHoverVisualSystem, XRInputSystem, XRInteractionSystem, XRLocomotionSystem, XRSessionSystem, XRTeleportVisualSystem, XR_FINGERS, XR_HOVER_SHELL_FLAG, angularVelocityFrom, applyHandMaterial, arcGroundCrossing, buildComponentValueMaps, buildNodeKeyMapsFromSnapshot, buildNodeMapsFromSnapshot, canonicalizeComponentValue, clearPrefabCache, collectDiffPaths, collectEntitySubtree, collectSnapshotSubtreeIds, computeFingerCurl, computeHandShape, computeInstanceOverrides, computePalmPose, computePalmWidth, computePinch, computeSpread, createHandMaterial, decanonicalizeComponentValue, despawnPrefab, encodeOverride, estimateHandScale, findSnapshotRootEntityIds, findTopLevelNestedRegions, groupOverridePaths, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, indexSnapshotByEntity, instantiateSubtree, loadPrefab, matchHandPose, mergeComponentValue, parseOverride, parsePrefabAsset, prefabFileVersionFor, readXrCapabilities, restoreComponentState, restorePostCreateComponents, sampleTeleportArc, setPrefabAssetUrlResolver, spawnPrefab };
8776
- //# sourceMappingURL=chunk-LCJ6IH2O.js.map
8777
- //# sourceMappingURL=chunk-LCJ6IH2O.js.map
8863
+ export { ADDED_NODE_MARKER_COMPONENT, ARC_GRAVITY, ARC_MAX_TIME, ARC_SPEED, ARC_STEPS, AnimationSystem, AudioSystem, Behaviour, CURLED_COS, CameraSyncSystem, DEFAULT_ENTER_CONFIDENCE, DEFAULT_EXIT_CONFIDENCE, DEFAULT_LOST_GRACE_SECONDS, DEFAULT_MIN_HOLD_SECONDS, EnvironmentSyncSystem, FALLBACK_HAND_SCALE, HYDRATABLE_ENTITY_KINDS, HandPoseTracker, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MATCH_FALLOFF, MAX_PLAUSIBLE_SPEED, MAX_SAMPLE_AGE_SECONDS, MaterialSyncSystem, MeshGeometrySystem, NODE_KEY_SEPARATOR, NO_XR_CAPABILITIES, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, ObjectVisibilitySystem, PINCH_FINGERS, PREFAB_FILE_VERSION, PREFAB_FILE_VERSION_NESTED, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, SCRIPT_OBJECT_ROOT_FLAG, STRAIGHT_COS, ScriptBehaviourSystem, ScriptObject, ScriptObjectSystem, TeleportAimGate, ThrowVelocityTracker, TransformSyncSystem, VELOCITY_SAMPLES, VRTeleportAreaSystem, VideoSystem, XRControllerVisualSystem, XRHandPoseSystem, XRHoverVisualSystem, XRInputSystem, XRInteractionSystem, XRLocomotionSystem, XRSessionSystem, XRTeleportVisualSystem, XR_FINGERS, XR_HOVER_SHELL_FLAG, angularVelocityFrom, applyHandMaterial, arcGroundCrossing, buildComponentValueMaps, buildNodeKeyMapsFromSnapshot, buildNodeMapsFromSnapshot, canonicalizeComponentValue, clearPrefabCache, collectDiffPaths, collectEntitySubtree, collectSnapshotSubtreeIds, computeFingerCurl, computeHandShape, computeInstanceOverrides, computePalmPose, computePalmWidth, computePinch, computeSpread, createHandMaterial, decanonicalizeComponentValue, despawnPrefab, encodeOverride, estimateHandScale, findSnapshotRootEntityIds, findTopLevelNestedRegions, groupOverridePaths, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, indexSnapshotByEntity, instantiateSubtree, loadPrefab, matchHandPose, mergeComponentValue, parseOverride, parsePrefabAsset, prefabFileVersionFor, readXrCapabilities, restoreComponentState, restorePostCreateComponents, sampleTeleportArc, setPrefabAssetUrlResolver, spawnPrefab };
8864
+ //# sourceMappingURL=chunk-XHMOFI3Q.js.map
8865
+ //# sourceMappingURL=chunk-XHMOFI3Q.js.map