@relu-interactives/spatial-ecs 0.3.4 → 0.3.6

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 (44) hide show
  1. package/dist/{System-vrU46Vuw.d.cts → System-TmC2EijF.d.cts} +2 -2
  2. package/dist/{System-vrU46Vuw.d.ts → System-TmC2EijF.d.ts} +2 -2
  3. package/dist/{XRRig-2686IqLQ.d.cts → XRInteractor-CCUzSqg9.d.ts} +96 -2
  4. package/dist/{XRRig-D2QURXl1.d.ts → XRInteractor-I2q6TKtF.d.cts} +96 -2
  5. package/dist/{chunk-4BZYK3JP.js → chunk-FQTOC7HK.js} +135 -88
  6. package/dist/chunk-FQTOC7HK.js.map +1 -0
  7. package/dist/{chunk-2LVFGVWI.js → chunk-JRJ3CL5H.js} +3 -3
  8. package/dist/{chunk-2LVFGVWI.js.map → chunk-JRJ3CL5H.js.map} +1 -1
  9. package/dist/{chunk-6QC2PJLD.js → chunk-N4GKZ7IV.js} +29 -3
  10. package/dist/chunk-N4GKZ7IV.js.map +1 -0
  11. package/dist/{chunk-ID266ZUA.js → chunk-WRJ2K3LZ.js} +525 -41
  12. package/dist/chunk-WRJ2K3LZ.js.map +1 -0
  13. package/dist/components/index.cjs +26 -0
  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/factories/index.cjs +185 -112
  19. package/dist/factories/index.cjs.map +1 -1
  20. package/dist/factories/index.d.cts +7 -3
  21. package/dist/factories/index.d.ts +7 -3
  22. package/dist/factories/index.js +3 -3
  23. package/dist/{index-BtKOaHfY.d.ts → index-BltjPEhg.d.cts} +10 -3
  24. package/dist/{index-CRmfSYdj.d.ts → index-BpbmZuOz.d.ts} +92 -16
  25. package/dist/{index-Bc0YCz1A.d.cts → index-C5FrDt3z.d.cts} +92 -16
  26. package/dist/{index-Xu238jLn.d.cts → index-W8pUajCW.d.ts} +10 -3
  27. package/dist/index.cjs +829 -261
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +76 -9
  30. package/dist/index.d.ts +76 -9
  31. package/dist/index.js +8 -8
  32. package/dist/systems/index.cjs +532 -36
  33. package/dist/systems/index.cjs.map +1 -1
  34. package/dist/systems/index.d.cts +2 -2
  35. package/dist/systems/index.d.ts +2 -2
  36. package/dist/systems/index.js +3 -3
  37. package/dist/types.d.cts +1 -1
  38. package/dist/types.d.ts +1 -1
  39. package/dist/worldSnapshotUtils.d.cts +1 -1
  40. package/dist/worldSnapshotUtils.d.ts +1 -1
  41. package/package.json +1 -1
  42. package/dist/chunk-4BZYK3JP.js.map +0 -1
  43. package/dist/chunk-6QC2PJLD.js.map +0 -1
  44. package/dist/chunk-ID266ZUA.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { resolveDracoDecoderPath, applyTransform, SHARED_MODEL_RESOURCE_FLAG } from './chunk-2LVFGVWI.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, InstanceSlotComponent, Name, ImageComponent, SpriteComponent, VideoComponent, AudioComponent, ImageTarget, Selectable, PrefabNode, PrefabInstance } from './chunk-6QC2PJLD.js';
1
+ import { resolveDracoDecoderPath, applyTransform, SHARED_MODEL_RESOURCE_FLAG } from './chunk-JRJ3CL5H.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, XRInteractorComponent, XRInteractorSideComponent, InstanceSlotComponent, Name, ImageComponent, SpriteComponent, VideoComponent, AudioComponent, ImageTarget, Selectable, PrefabNode, PrefabInstance } from './chunk-N4GKZ7IV.js';
3
3
  import { __name } from './chunk-OY7ZODZP.js';
4
4
  import * as THREE7 from 'three';
5
5
  import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
@@ -2791,6 +2791,14 @@ function buildComponentValueMaps(snapshot) {
2791
2791
  snapshot.components,
2792
2792
  "XRInteractableComponent"
2793
2793
  ),
2794
+ xrInteractorValues: readByComponent(
2795
+ snapshot.components,
2796
+ "XRInteractorComponent"
2797
+ ),
2798
+ xrInteractorSideValues: readByComponent(
2799
+ snapshot.components,
2800
+ "XRInteractorSideComponent"
2801
+ ),
2794
2802
  instancedMeshValues: readByComponent(snapshot.components, "InstancedMeshComponent"),
2795
2803
  instanceSlotValues: readByComponent(snapshot.components, "InstanceSlotComponent"),
2796
2804
  prefabNodeValues: readByComponent(snapshot.components, "PrefabNode"),
@@ -2977,6 +2985,60 @@ function restorePostCreateComponents(world, objectManagementSystem, targetEntity
2977
2985
  }
2978
2986
  }
2979
2987
  }
2988
+ {
2989
+ const sourceInteractor = asRecord(
2990
+ values.xrInteractorValues.get(sourceEntityId)
2991
+ );
2992
+ const interactor = world.getComponent(targetEntityId, XRInteractorComponent);
2993
+ if (sourceInteractor && interactor) {
2994
+ if (typeof sourceInteractor.interactorType === "string") {
2995
+ interactor.interactorType = sourceInteractor.interactorType;
2996
+ }
2997
+ if (typeof sourceInteractor.handPreset === "string") {
2998
+ interactor.handPreset = sourceInteractor.handPreset;
2999
+ }
3000
+ if (typeof sourceInteractor.handColor === "string") {
3001
+ interactor.handColor = sourceInteractor.handColor;
3002
+ }
3003
+ if (typeof sourceInteractor.handOpacity === "number") {
3004
+ interactor.handOpacity = sourceInteractor.handOpacity;
3005
+ }
3006
+ if (typeof sourceInteractor.handEmissiveIntensity === "number") {
3007
+ interactor.handEmissiveIntensity = sourceInteractor.handEmissiveIntensity;
3008
+ }
3009
+ if (typeof sourceInteractor.showRay === "boolean") {
3010
+ interactor.showRay = sourceInteractor.showRay;
3011
+ }
3012
+ }
3013
+ }
3014
+ {
3015
+ const sourceSide = asRecord(
3016
+ values.xrInteractorSideValues.get(sourceEntityId)
3017
+ );
3018
+ if (sourceSide && typeof sourceSide.side === "string") {
3019
+ const existing = world.getComponent(
3020
+ targetEntityId,
3021
+ XRInteractorSideComponent
3022
+ );
3023
+ if (existing) {
3024
+ existing.side = sourceSide.side;
3025
+ } else {
3026
+ world.addComponent(
3027
+ targetEntityId,
3028
+ new XRInteractorSideComponent({
3029
+ side: sourceSide.side
3030
+ })
3031
+ );
3032
+ }
3033
+ }
3034
+ }
3035
+ {
3036
+ const sourceRigOrigin = asRecord(values.xrRigValues.get(sourceEntityId));
3037
+ const rigForOrigin = world.getComponent(targetEntityId, XRRigComponent);
3038
+ if (sourceRigOrigin && rigForOrigin && typeof sourceRigOrigin.trackingOrigin === "string") {
3039
+ rigForOrigin.trackingOrigin = sourceRigOrigin.trackingOrigin;
3040
+ }
3041
+ }
2980
3042
  {
2981
3043
  const imComponent = world.getComponent(targetEntityId, InstancedMeshComponent);
2982
3044
  if (imComponent && imComponent.instanceEntityIds.length > 0) {
@@ -3566,6 +3628,7 @@ var HYDRATABLE_ENTITY_KINDS = /* @__PURE__ */ new Set([
3566
3628
  "instanceSlot",
3567
3629
  "scriptObject",
3568
3630
  "xrRig",
3631
+ "xrInteractor",
3569
3632
  "teleportArea"
3570
3633
  ]);
3571
3634
 
@@ -6119,6 +6182,9 @@ var _XRInputSystem = class _XRInputSystem {
6119
6182
  state.hasAxes = false;
6120
6183
  state.buttons = [];
6121
6184
  }
6185
+ }
6186
+ for (const record of this.records.values()) {
6187
+ const state = record.state;
6122
6188
  if (record.pendingSelectStart) {
6123
6189
  state.select = true;
6124
6190
  state.selectStart = true;
@@ -6316,6 +6382,45 @@ var _XRInteractionSystem = class _XRInteractionSystem {
6316
6382
  };
6317
6383
  __name(_XRInteractionSystem, "XRInteractionSystem");
6318
6384
  var XRInteractionSystem = _XRInteractionSystem;
6385
+ var ARC_GRAVITY = 9.8;
6386
+ var ARC_SPEED = 7;
6387
+ var ARC_STEPS = 24;
6388
+ var ARC_MAX_TIME = 2;
6389
+ function sampleTeleportArc(origin, direction, out = [], options) {
6390
+ const speed = options?.speed ?? ARC_SPEED;
6391
+ const gravity = options?.gravity ?? ARC_GRAVITY;
6392
+ const steps = Math.max(2, options?.steps ?? ARC_STEPS);
6393
+ const maxTime = options?.maxTime ?? ARC_MAX_TIME;
6394
+ out.length = 0;
6395
+ const velocity = direction.clone().normalize().multiplyScalar(speed);
6396
+ for (let i = 0; i < steps; i += 1) {
6397
+ const t = i / (steps - 1) * maxTime;
6398
+ out.push(
6399
+ new THREE7.Vector3(
6400
+ origin.x + velocity.x * t,
6401
+ origin.y + velocity.y * t - 0.5 * gravity * t * t,
6402
+ origin.z + velocity.z * t
6403
+ )
6404
+ );
6405
+ }
6406
+ return out;
6407
+ }
6408
+ __name(sampleTeleportArc, "sampleTeleportArc");
6409
+ function arcGroundCrossing(points, groundY) {
6410
+ for (let i = 1; i < points.length; i += 1) {
6411
+ const previous = points[i - 1];
6412
+ const current = points[i];
6413
+ if (previous.y >= groundY && current.y <= groundY) {
6414
+ const span = previous.y - current.y;
6415
+ const alpha = span > 1e-6 ? (previous.y - groundY) / span : 0;
6416
+ return new THREE7.Vector3().lerpVectors(previous, current, alpha);
6417
+ }
6418
+ }
6419
+ return null;
6420
+ }
6421
+ __name(arcGroundCrossing, "arcGroundCrossing");
6422
+
6423
+ // core/systems/XRLocomotionSystem.ts
6319
6424
  var UP = new THREE7.Vector3(0, 1, 0);
6320
6425
  var AXIS_DEADZONE = 0.5;
6321
6426
  var _XRLocomotionSystem = class _XRLocomotionSystem {
@@ -6323,13 +6428,26 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
6323
6428
  this.raycaster = new THREE7.Raycaster();
6324
6429
  /** Per-source latch so one stick push yields exactly one snap turn. */
6325
6430
  this.turnLatched = /* @__PURE__ */ new WeakSet();
6326
- /** Where the pointer currently lands, for the consumer to draw a marker. */
6327
- this.teleportPoint = null;
6431
+ /** Reused arc buffer — aiming runs every frame. */
6432
+ this.arcPoints = [];
6433
+ /** Curve up to the landing point, for the visual system. Empty when not aiming. */
6434
+ this.aimCurve = [];
6435
+ this.landingPoint = null;
6436
+ /** True once we've tried to self-heal camera parenting for this session. */
6437
+ this.parentingChecked = false;
6328
6438
  this.inputSystem = inputSystem;
6329
6439
  }
6330
6440
  update(world, deltaTime) {
6331
- this.teleportPoint = null;
6332
- if (!world.isXrPresenting()) return;
6441
+ this.aimCurve = [];
6442
+ this.landingPoint = null;
6443
+ if (!world.isXrPresenting()) {
6444
+ this.parentingChecked = false;
6445
+ return;
6446
+ }
6447
+ if (!this.parentingChecked) {
6448
+ this.parentingChecked = true;
6449
+ this.ensureCameraUnderRig(world);
6450
+ }
6333
6451
  const rigEntityId = world.query(XRRigComponent, TransformComponent)[0];
6334
6452
  if (typeof rigEntityId !== "number") return;
6335
6453
  const rig = world.getComponent(rigEntityId, XRRigComponent);
@@ -6346,9 +6464,37 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
6346
6464
  this.applySmoothMove(world, rig, rigTransform, inputs, deltaTime);
6347
6465
  }
6348
6466
  }
6467
+ /**
6468
+ * Guarantee the render camera is a CHILD of the rig.
6469
+ *
6470
+ * Locomotion moves the rig, and three composes the head pose against
6471
+ * `camera.parent` — so if the camera sits at the scene root instead, moving
6472
+ * the rig does nothing at all and the player is frozen in place. Scenes
6473
+ * authored before the rig existed (or with the camera re-parented by hand)
6474
+ * would otherwise silently fail to move, which is exactly the symptom that is
6475
+ * hardest to diagnose from inside a headset. Repairing it via `ParentId` lets
6476
+ * `ObjectManagementSystem` reconcile the scene graph normally.
6477
+ */
6478
+ ensureCameraUnderRig(world) {
6479
+ const rigEntityId = world.query(XRRigComponent)[0];
6480
+ if (typeof rigEntityId !== "number") return;
6481
+ const activeCamera = world.getCamera();
6482
+ for (const entityId of world.query(CameraComponent, Object3DRef)) {
6483
+ if (world.getComponent(entityId, Object3DRef)?.object !== activeCamera) {
6484
+ continue;
6485
+ }
6486
+ const parent = world.getComponent(entityId, ParentId);
6487
+ if (parent) {
6488
+ if (parent.value !== rigEntityId) parent.value = rigEntityId;
6489
+ } else {
6490
+ world.addComponent(entityId, new ParentId(rigEntityId));
6491
+ }
6492
+ return;
6493
+ }
6494
+ }
6349
6495
  /**
6350
6496
  * Snap turning, not smooth turning — rotating the view continuously is the
6351
- * single biggest cause of VR nausea, so the comfort-safe option is the one
6497
+ * single biggest cause of VR nausea, so the comfort-safe option is what's
6352
6498
  * wired to the stick.
6353
6499
  */
6354
6500
  applySnapTurn(rig, transform, inputs) {
@@ -6362,8 +6508,7 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
6362
6508
  }
6363
6509
  if (this.turnLatched.has(source)) continue;
6364
6510
  this.turnLatched.add(source);
6365
- const step = THREE7.MathUtils.degToRad(rig.snapTurnDegrees);
6366
- transform.rotation.y -= Math.sign(x) * step;
6511
+ transform.rotation.y -= Math.sign(x) * THREE7.MathUtils.degToRad(rig.snapTurnDegrees);
6367
6512
  }
6368
6513
  }
6369
6514
  applySmoothMove(world, rig, transform, inputs, deltaTime) {
@@ -6388,17 +6533,42 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
6388
6533
  const targets = this.collectTeleportTargets(world);
6389
6534
  if (targets.length === 0) return;
6390
6535
  for (const input of inputs) {
6391
- this.raycaster.set(input.rayOrigin, input.rayDirection);
6392
- const hit = this.raycaster.intersectObjects(targets, true)[0];
6536
+ if (!input.select && !input.selectEnd) continue;
6537
+ const points = sampleTeleportArc(
6538
+ input.rayOrigin,
6539
+ input.rayDirection,
6540
+ this.arcPoints
6541
+ );
6542
+ const hit = this.raycastArc(points, targets);
6393
6543
  if (!hit) continue;
6394
- this.teleportPoint = hit.point.clone();
6544
+ this.landingPoint = hit.point;
6545
+ this.aimCurve = points.slice(0, hit.segmentIndex + 1).concat(hit.point);
6395
6546
  if (input.selectEnd) {
6396
6547
  transform.position.x = hit.point.x;
6397
6548
  transform.position.y = hit.point.y;
6398
6549
  transform.position.z = hit.point.z;
6550
+ this.aimCurve = [];
6551
+ this.landingPoint = null;
6399
6552
  }
6400
6553
  }
6401
6554
  }
6555
+ /** Walk the arc segment-by-segment, returning the first surface hit. */
6556
+ raycastArc(points, targets) {
6557
+ for (let i = 1; i < points.length; i += 1) {
6558
+ const from = points[i - 1];
6559
+ const to = points[i];
6560
+ const delta = new THREE7.Vector3().subVectors(to, from);
6561
+ const distance = delta.length();
6562
+ if (distance < 1e-6) continue;
6563
+ this.raycaster.set(from, delta.divideScalar(distance));
6564
+ this.raycaster.far = distance;
6565
+ const hit = this.raycaster.intersectObjects(targets, true)[0];
6566
+ if (hit) {
6567
+ return { point: hit.point.clone(), segmentIndex: i - 1 };
6568
+ }
6569
+ }
6570
+ return null;
6571
+ }
6402
6572
  collectTeleportTargets(world) {
6403
6573
  const objects = [];
6404
6574
  for (const entityId of world.query(VRTeleportAreaComponent, Object3DRef)) {
@@ -6410,12 +6580,13 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
6410
6580
  }
6411
6581
  return objects;
6412
6582
  }
6413
- /**
6414
- * Where the teleport pointer currently lands this frame, or null.
6415
- * Consumers use this to render an aim marker.
6416
- */
6417
- getTeleportPoint() {
6418
- return this.teleportPoint;
6583
+ /** Arc points up to the landing spot this frame; empty when not aiming. */
6584
+ getAimCurve() {
6585
+ return this.aimCurve;
6586
+ }
6587
+ /** Where the arc currently lands, or null when not aiming at a valid area. */
6588
+ getLandingPoint() {
6589
+ return this.landingPoint;
6419
6590
  }
6420
6591
  };
6421
6592
  __name(_XRLocomotionSystem, "XRLocomotionSystem");
@@ -6455,6 +6626,8 @@ var _XRSessionSystem = class _XRSessionSystem {
6455
6626
  constructor(inputSystem) {
6456
6627
  this.presenting = false;
6457
6628
  this.capabilities = NO_XR_CAPABILITIES;
6629
+ /** Y compensation applied when a floor-relative space was requested but not granted. */
6630
+ this.appliedOriginOffset = 0;
6458
6631
  this.inputSystem = inputSystem ?? null;
6459
6632
  }
6460
6633
  update(world) {
@@ -6478,11 +6651,59 @@ var _XRSessionSystem = class _XRSessionSystem {
6478
6651
  if (session && this.inputSystem) {
6479
6652
  this.inputSystem.attachSession(session);
6480
6653
  }
6654
+ this.applyTrackingOrigin(world, session ?? null);
6481
6655
  this.forEachBehaviour(world, (behaviour) => {
6482
6656
  behaviour.onXRSessionStart(this.capabilities);
6483
6657
  });
6484
6658
  }
6659
+ /**
6660
+ * Apply the rig's authored tracking origin, and compensate when the device
6661
+ * cannot honour it.
6662
+ *
6663
+ * `floor` (`local-floor`) puts Y=0 on the user's real floor, which is what a
6664
+ * scene authored standing on the ground expects. `eye` (`local`) puts Y=0 at
6665
+ * the headset, for seated experiences.
6666
+ *
6667
+ * The compensation matters: `local-floor` is only ever REQUESTED as an
6668
+ * optional feature (requiring it would make `requestSession` reject outright
6669
+ * on devices that lack it). When it isn't granted, the runtime silently falls
6670
+ * back to `local` — the origin jumps to head height and a floor-authored
6671
+ * scene swallows the user, which is exactly the "I'm standing under the
6672
+ * building" symptom. Offsetting the rig down by the eye height restores the
6673
+ * intended floor relationship instead of leaving it broken.
6674
+ */
6675
+ applyTrackingOrigin(world, session) {
6676
+ const rigEntityId = world.query(XRRigComponent, TransformComponent)[0];
6677
+ if (typeof rigEntityId !== "number") return;
6678
+ const rig = world.getComponent(rigEntityId, XRRigComponent);
6679
+ const transform = world.getComponent(rigEntityId, TransformComponent);
6680
+ if (!rig || !transform) return;
6681
+ const renderer = world.getRenderer();
6682
+ const wantsFloor = rig.trackingOrigin === "floor";
6683
+ try {
6684
+ renderer.xr.setReferenceSpaceType(wantsFloor ? "local-floor" : "local");
6685
+ } catch {
6686
+ }
6687
+ const granted = session?.enabledFeatures;
6688
+ const floorGranted = Array.isArray(granted) ? granted.includes("local-floor") : (
6689
+ // No report at all: trust the request, since a wrong offset is worse
6690
+ // than none on devices that did honour it.
6691
+ true
6692
+ );
6693
+ this.appliedOriginOffset = wantsFloor && !floorGranted ? rig.fallbackEyeHeight : 0;
6694
+ if (this.appliedOriginOffset !== 0) {
6695
+ transform.position.y -= this.appliedOriginOffset;
6696
+ }
6697
+ }
6485
6698
  handleSessionEnd(world) {
6699
+ if (this.appliedOriginOffset !== 0) {
6700
+ const rigEntityId = world.query(XRRigComponent, TransformComponent)[0];
6701
+ if (typeof rigEntityId === "number") {
6702
+ const transform = world.getComponent(rigEntityId, TransformComponent);
6703
+ if (transform) transform.position.y += this.appliedOriginOffset;
6704
+ }
6705
+ this.appliedOriginOffset = 0;
6706
+ }
6486
6707
  this.capabilities = NO_XR_CAPABILITIES;
6487
6708
  this.inputSystem?.detachSession();
6488
6709
  this.forEachBehaviour(world, (behaviour) => {
@@ -6576,16 +6797,75 @@ var _VRTeleportAreaSystem = class _VRTeleportAreaSystem {
6576
6797
  };
6577
6798
  __name(_VRTeleportAreaSystem, "VRTeleportAreaSystem");
6578
6799
  var VRTeleportAreaSystem = _VRTeleportAreaSystem;
6800
+ function createHandMaterial(preset, options) {
6801
+ const color = new THREE7.Color(options.color);
6802
+ switch (preset) {
6803
+ case "ghost":
6804
+ return new THREE7.MeshBasicMaterial({
6805
+ color,
6806
+ transparent: true,
6807
+ opacity: Math.min(1, Math.max(0.05, options.opacity * 0.45)),
6808
+ depthWrite: false,
6809
+ side: THREE7.DoubleSide
6810
+ });
6811
+ case "neon":
6812
+ return new THREE7.MeshStandardMaterial({
6813
+ color,
6814
+ emissive: color,
6815
+ emissiveIntensity: Math.max(0.5, options.emissiveIntensity || 2),
6816
+ roughness: 0.35,
6817
+ metalness: 0,
6818
+ transparent: options.opacity < 1,
6819
+ opacity: options.opacity
6820
+ });
6821
+ case "skeleton":
6822
+ return new THREE7.MeshBasicMaterial({
6823
+ color,
6824
+ wireframe: true,
6825
+ transparent: true,
6826
+ opacity: options.opacity
6827
+ });
6828
+ case "custom":
6829
+ case "default":
6830
+ return new THREE7.MeshStandardMaterial({
6831
+ color,
6832
+ roughness: 0.85,
6833
+ metalness: 0,
6834
+ emissive: color,
6835
+ emissiveIntensity: Math.max(0, options.emissiveIntensity),
6836
+ transparent: options.opacity < 1,
6837
+ opacity: options.opacity,
6838
+ side: THREE7.DoubleSide
6839
+ });
6840
+ default: {
6841
+ return new THREE7.MeshStandardMaterial({ color });
6842
+ }
6843
+ }
6844
+ }
6845
+ __name(createHandMaterial, "createHandMaterial");
6846
+ function applyHandMaterial(root, material) {
6847
+ root.traverse((child) => {
6848
+ const mesh = child;
6849
+ if (!mesh.isMesh) return;
6850
+ mesh.material = material;
6851
+ });
6852
+ }
6853
+ __name(applyHandMaterial, "applyHandMaterial");
6854
+ var SLOTS = [
6855
+ { index: 0, side: "left" },
6856
+ { index: 1, side: "right" }
6857
+ ];
6579
6858
  var _XRControllerVisualSystem = class _XRControllerVisualSystem {
6580
- constructor(slots = 2) {
6859
+ constructor(options) {
6581
6860
  this.controllerModelFactory = new XRControllerModelFactory();
6582
6861
  this.handModelFactory = new XRHandModelFactory();
6583
6862
  this.group = new THREE7.Group();
6584
- this.built = false;
6863
+ this.slots = /* @__PURE__ */ new Map();
6585
6864
  this.attachedTo = null;
6586
- /** Index → whether we've already attached visuals for that slot. */
6587
- this.ready = /* @__PURE__ */ new Set();
6588
- this.slots = slots;
6865
+ /** Last applied preset signature, so materials rebuild only on real change. */
6866
+ this.handStyleSignature = "";
6867
+ this.handMaterial = null;
6868
+ this.interactionSystem = options?.interactionSystem ?? null;
6589
6869
  this.group.name = "XRControllerVisuals";
6590
6870
  this.group.userData.ecsPreviewHidden = true;
6591
6871
  }
@@ -6593,23 +6873,109 @@ var _XRControllerVisualSystem = class _XRControllerVisualSystem {
6593
6873
  const renderer = world.getRenderer();
6594
6874
  if (!renderer.xr?.enabled) return;
6595
6875
  this.ensureAttached(world);
6596
- if (this.built) return;
6597
- for (let index = 0; index < this.slots; index += 1) {
6598
- if (this.ready.has(index)) continue;
6876
+ this.ensureSlots(world);
6877
+ const interactor = this.resolveInteractor(world);
6878
+ const type = interactor?.interactorType ?? "both";
6879
+ const showControllers = type === "controllers" || type === "both";
6880
+ const showHands = type === "hands" || type === "both";
6881
+ this.syncHandMaterial(interactor);
6882
+ for (const { index, side } of SLOTS) {
6883
+ const visuals = this.slots.get(index);
6884
+ if (!visuals) continue;
6885
+ visuals.controllerModel.visible = showControllers;
6886
+ visuals.handModel.visible = showHands;
6887
+ visuals.ray.visible = this.shouldShowRay(interactor);
6888
+ if (showHands && this.handMaterial) {
6889
+ applyHandMaterial(visuals.handModel, this.handMaterial);
6890
+ }
6891
+ this.syncCustomContent(world, visuals, side);
6892
+ }
6893
+ }
6894
+ /** The scene's interactor config, if one was authored. */
6895
+ resolveInteractor(world) {
6896
+ const entityId = world.query(XRInteractorComponent)[0];
6897
+ if (typeof entityId !== "number") return null;
6898
+ return world.getComponent(entityId, XRInteractorComponent) ?? null;
6899
+ }
6900
+ /**
6901
+ * Re-parent the author's left/right interactor content onto the tracked grip
6902
+ * space so it follows the hand.
6903
+ *
6904
+ * `ObjectManagementSystem` reconciles ECS objects back under their ParentId
6905
+ * every frame, so this re-attach has to be re-asserted — the same coexistence
6906
+ * dance the AR anchor system performs.
6907
+ */
6908
+ syncCustomContent(world, visuals, side) {
6909
+ let content = null;
6910
+ for (const entityId of world.query(
6911
+ XRInteractorSideComponent,
6912
+ Object3DRef
6913
+ )) {
6914
+ const slot = world.getComponent(entityId, XRInteractorSideComponent);
6915
+ if (slot?.side !== side) continue;
6916
+ content = world.getComponent(entityId, Object3DRef)?.object ?? null;
6917
+ break;
6918
+ }
6919
+ if (!content) {
6920
+ visuals.attachedCustom = null;
6921
+ return;
6922
+ }
6923
+ if (content.parent !== visuals.grip) {
6924
+ visuals.grip.add(content);
6925
+ }
6926
+ visuals.attachedCustom = content;
6927
+ }
6928
+ /** Rebuild the hand material only when the authored style actually changes. */
6929
+ syncHandMaterial(interactor) {
6930
+ const preset = interactor?.handPreset ?? "default";
6931
+ const color = interactor?.handColor ?? "#e8b48a";
6932
+ const opacity = interactor?.handOpacity ?? 1;
6933
+ const emissive = interactor?.handEmissiveIntensity ?? 0;
6934
+ const signature = `${preset}:${color}:${opacity}:${emissive}`;
6935
+ if (signature === this.handStyleSignature && this.handMaterial) return;
6936
+ this.handStyleSignature = signature;
6937
+ this.handMaterial?.dispose();
6938
+ this.handMaterial = createHandMaterial(preset, {
6939
+ color,
6940
+ opacity,
6941
+ emissiveIntensity: emissive
6942
+ });
6943
+ }
6944
+ /**
6945
+ * The ray is meaningful only when it points at something. Authors can turn it
6946
+ * off entirely; otherwise it appears on hover/grab so it isn't permanent
6947
+ * clutter implying the whole scene is clickable.
6948
+ */
6949
+ shouldShowRay(interactor) {
6950
+ if (interactor && !interactor.showRay) return false;
6951
+ if (!this.interactionSystem) return true;
6952
+ return this.interactionSystem.getHoveredEntityId() !== null || this.interactionSystem.isGrabbing();
6953
+ }
6954
+ /** Lazily build per-slot visuals; the device reports profiles late. */
6955
+ ensureSlots(world) {
6956
+ const renderer = world.getRenderer();
6957
+ for (const { index } of SLOTS) {
6958
+ if (this.slots.has(index)) continue;
6599
6959
  const controller = renderer.xr.getController(index);
6600
6960
  const grip = renderer.xr.getControllerGrip(index);
6601
6961
  const hand = renderer.xr.getHand(index);
6602
6962
  if (!controller || !grip || !hand) continue;
6603
- controller.add(this.createRay());
6604
- this.group.add(controller);
6605
- grip.add(this.controllerModelFactory.createControllerModel(grip));
6606
- this.group.add(grip);
6607
- hand.add(this.handModelFactory.createHandModel(hand, "mesh"));
6608
- this.group.add(hand);
6609
- this.ready.add(index);
6610
- }
6611
- if (this.ready.size >= this.slots) {
6612
- this.built = true;
6963
+ const ray = this.createRay();
6964
+ controller.add(ray);
6965
+ const controllerModel = this.controllerModelFactory.createControllerModel(grip);
6966
+ grip.add(controllerModel);
6967
+ const handModel = this.handModelFactory.createHandModel(hand, "mesh");
6968
+ hand.add(handModel);
6969
+ this.group.add(controller, grip, hand);
6970
+ this.slots.set(index, {
6971
+ controller,
6972
+ grip,
6973
+ hand,
6974
+ ray,
6975
+ controllerModel,
6976
+ handModel,
6977
+ attachedCustom: null
6978
+ });
6613
6979
  }
6614
6980
  }
6615
6981
  /**
@@ -6637,6 +7003,7 @@ var _XRControllerVisualSystem = class _XRControllerVisualSystem {
6637
7003
  const line = new THREE7.Line(geometry, material);
6638
7004
  line.name = "XRPointerRay";
6639
7005
  line.renderOrder = 999;
7006
+ line.visible = false;
6640
7007
  return line;
6641
7008
  }
6642
7009
  dispose() {
@@ -6652,14 +7019,131 @@ var _XRControllerVisualSystem = class _XRControllerVisualSystem {
6652
7019
  }
6653
7020
  });
6654
7021
  this.group.clear();
6655
- this.ready.clear();
6656
- this.built = false;
7022
+ this.slots.clear();
7023
+ this.handMaterial?.dispose();
7024
+ this.handMaterial = null;
7025
+ this.handStyleSignature = "";
6657
7026
  this.attachedTo = null;
6658
7027
  }
6659
7028
  };
6660
7029
  __name(_XRControllerVisualSystem, "XRControllerVisualSystem");
6661
7030
  var XRControllerVisualSystem = _XRControllerVisualSystem;
7031
+ var MARKER_RADIUS = 0.28;
7032
+ var ACCENT = new THREE7.Color("#4da3ff");
7033
+ var _XRTeleportVisualSystem = class _XRTeleportVisualSystem {
7034
+ constructor(locomotionSystem) {
7035
+ this.group = new THREE7.Group();
7036
+ this.arcGeometry = new THREE7.BufferGeometry();
7037
+ this.marker = new THREE7.Group();
7038
+ this.attached = false;
7039
+ this.locomotionSystem = locomotionSystem;
7040
+ this.group.name = "XRTeleportVisuals";
7041
+ this.group.userData.ecsPreviewHidden = true;
7042
+ const arcMaterial = new THREE7.LineBasicMaterial({
7043
+ vertexColors: true,
7044
+ transparent: true,
7045
+ depthTest: false
7046
+ });
7047
+ this.arc = new THREE7.Line(this.arcGeometry, arcMaterial);
7048
+ this.arc.frustumCulled = false;
7049
+ this.arc.renderOrder = 998;
7050
+ this.group.add(this.arc);
7051
+ this.marker.add(this.createRing(), this.createDot());
7052
+ this.marker.renderOrder = 999;
7053
+ this.group.add(this.marker);
7054
+ this.setVisible(false);
7055
+ }
7056
+ update(world) {
7057
+ if (!this.attached) {
7058
+ world.getScene().add(this.group);
7059
+ this.attached = true;
7060
+ }
7061
+ const curve = this.locomotionSystem.getAimCurve();
7062
+ const landing = this.locomotionSystem.getLandingPoint();
7063
+ if (!landing || curve.length < 2) {
7064
+ this.setVisible(false);
7065
+ return;
7066
+ }
7067
+ this.updateArcGeometry(curve);
7068
+ this.marker.position.copy(landing);
7069
+ this.marker.position.y += 0.01;
7070
+ this.setVisible(true);
7071
+ }
7072
+ updateArcGeometry(curve) {
7073
+ const count = curve.length;
7074
+ const positions = new Float32Array(count * 3);
7075
+ const colors = new Float32Array(count * 3);
7076
+ for (let i = 0; i < count; i += 1) {
7077
+ const point = curve[i];
7078
+ positions[i * 3] = point.x;
7079
+ positions[i * 3 + 1] = point.y;
7080
+ positions[i * 3 + 2] = point.z;
7081
+ const t = count > 1 ? i / (count - 1) : 0;
7082
+ const fade = 1 - t * 0.75;
7083
+ colors[i * 3] = ACCENT.r * fade;
7084
+ colors[i * 3 + 1] = ACCENT.g * fade;
7085
+ colors[i * 3 + 2] = ACCENT.b * fade;
7086
+ }
7087
+ this.arcGeometry.setAttribute(
7088
+ "position",
7089
+ new THREE7.BufferAttribute(positions, 3)
7090
+ );
7091
+ this.arcGeometry.setAttribute("color", new THREE7.BufferAttribute(colors, 3));
7092
+ this.arcGeometry.computeBoundingSphere();
7093
+ }
7094
+ createRing() {
7095
+ const geometry = new THREE7.RingGeometry(
7096
+ MARKER_RADIUS * 0.72,
7097
+ MARKER_RADIUS,
7098
+ 48
7099
+ );
7100
+ geometry.rotateX(-Math.PI / 2);
7101
+ return new THREE7.Mesh(
7102
+ geometry,
7103
+ new THREE7.MeshBasicMaterial({
7104
+ color: ACCENT,
7105
+ transparent: true,
7106
+ opacity: 0.9,
7107
+ side: THREE7.DoubleSide,
7108
+ depthTest: false
7109
+ })
7110
+ );
7111
+ }
7112
+ createDot() {
7113
+ const geometry = new THREE7.CircleGeometry(MARKER_RADIUS * 0.16, 24);
7114
+ geometry.rotateX(-Math.PI / 2);
7115
+ return new THREE7.Mesh(
7116
+ geometry,
7117
+ new THREE7.MeshBasicMaterial({
7118
+ color: ACCENT,
7119
+ transparent: true,
7120
+ opacity: 0.55,
7121
+ side: THREE7.DoubleSide,
7122
+ depthTest: false
7123
+ })
7124
+ );
7125
+ }
7126
+ setVisible(visible) {
7127
+ this.group.visible = visible;
7128
+ }
7129
+ dispose() {
7130
+ this.group.removeFromParent();
7131
+ this.group.traverse((child) => {
7132
+ const mesh = child;
7133
+ mesh.geometry?.dispose?.();
7134
+ const material = mesh.material;
7135
+ if (Array.isArray(material)) {
7136
+ for (const entry of material) entry.dispose?.();
7137
+ } else {
7138
+ material?.dispose?.();
7139
+ }
7140
+ });
7141
+ this.attached = false;
7142
+ }
7143
+ };
7144
+ __name(_XRTeleportVisualSystem, "XRTeleportVisualSystem");
7145
+ var XRTeleportVisualSystem = _XRTeleportVisualSystem;
6662
7146
 
6663
- export { ADDED_NODE_MARKER_COMPONENT, AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, HYDRATABLE_ENTITY_KINDS, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, NODE_KEY_SEPARATOR, NO_XR_CAPABILITIES, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, ObjectVisibilitySystem, PREFAB_FILE_VERSION, PREFAB_FILE_VERSION_NESTED, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, SCRIPT_OBJECT_ROOT_FLAG, ScriptBehaviourSystem, ScriptObject, ScriptObjectSystem, TransformSyncSystem, VRTeleportAreaSystem, VideoSystem, XRControllerVisualSystem, XRInputSystem, XRInteractionSystem, XRLocomotionSystem, XRSessionSystem, buildComponentValueMaps, buildNodeKeyMapsFromSnapshot, buildNodeMapsFromSnapshot, canonicalizeComponentValue, clearPrefabCache, collectDiffPaths, collectEntitySubtree, collectSnapshotSubtreeIds, computeInstanceOverrides, decanonicalizeComponentValue, despawnPrefab, encodeOverride, findSnapshotRootEntityIds, findTopLevelNestedRegions, groupOverridePaths, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, indexSnapshotByEntity, instantiateSubtree, loadPrefab, mergeComponentValue, parseOverride, parsePrefabAsset, prefabFileVersionFor, readXrCapabilities, restoreComponentState, restorePostCreateComponents, setPrefabAssetUrlResolver, spawnPrefab };
6664
- //# sourceMappingURL=chunk-ID266ZUA.js.map
6665
- //# sourceMappingURL=chunk-ID266ZUA.js.map
7147
+ export { ADDED_NODE_MARKER_COMPONENT, ARC_GRAVITY, ARC_MAX_TIME, ARC_SPEED, ARC_STEPS, AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, HYDRATABLE_ENTITY_KINDS, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, NODE_KEY_SEPARATOR, NO_XR_CAPABILITIES, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, ObjectVisibilitySystem, PREFAB_FILE_VERSION, PREFAB_FILE_VERSION_NESTED, PhysicsSyncSystem, PostprocessingSyncSystem, RenderSystem, SCRIPT_OBJECT_ROOT_FLAG, ScriptBehaviourSystem, ScriptObject, ScriptObjectSystem, TransformSyncSystem, VRTeleportAreaSystem, VideoSystem, XRControllerVisualSystem, XRInputSystem, XRInteractionSystem, XRLocomotionSystem, XRSessionSystem, XRTeleportVisualSystem, applyHandMaterial, arcGroundCrossing, buildComponentValueMaps, buildNodeKeyMapsFromSnapshot, buildNodeMapsFromSnapshot, canonicalizeComponentValue, clearPrefabCache, collectDiffPaths, collectEntitySubtree, collectSnapshotSubtreeIds, computeInstanceOverrides, createHandMaterial, decanonicalizeComponentValue, despawnPrefab, encodeOverride, findSnapshotRootEntityIds, findTopLevelNestedRegions, groupOverridePaths, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, indexSnapshotByEntity, instantiateSubtree, loadPrefab, mergeComponentValue, parseOverride, parsePrefabAsset, prefabFileVersionFor, readXrCapabilities, restoreComponentState, restorePostCreateComponents, sampleTeleportArc, setPrefabAssetUrlResolver, spawnPrefab };
7148
+ //# sourceMappingURL=chunk-WRJ2K3LZ.js.map
7149
+ //# sourceMappingURL=chunk-WRJ2K3LZ.js.map