@relu-interactives/spatial-ecs 0.3.1 → 0.3.4

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 (39) hide show
  1. package/dist/{XRRig-Cu-EyliG.d.cts → XRRig-2686IqLQ.d.cts} +5 -5
  2. package/dist/{XRRig-CAmf04NX.d.ts → XRRig-D2QURXl1.d.ts} +5 -5
  3. package/dist/{chunk-67WGASUJ.js → chunk-2LVFGVWI.js} +3 -3
  4. package/dist/{chunk-67WGASUJ.js.map → chunk-2LVFGVWI.js.map} +1 -1
  5. package/dist/{chunk-PCOZLCXS.js → chunk-4BZYK3JP.js} +14 -6
  6. package/dist/chunk-4BZYK3JP.js.map +1 -0
  7. package/dist/{chunk-U3MDYKPV.js → chunk-6QC2PJLD.js} +4 -3
  8. package/dist/chunk-6QC2PJLD.js.map +1 -0
  9. package/dist/{chunk-VXUVNC7S.js → chunk-ID266ZUA.js} +199 -5
  10. package/dist/chunk-ID266ZUA.js.map +1 -0
  11. package/dist/components/index.cjs +2 -1
  12. package/dist/components/index.cjs.map +1 -1
  13. package/dist/components/index.d.cts +2 -2
  14. package/dist/components/index.d.ts +2 -2
  15. package/dist/components/index.js +1 -1
  16. package/dist/factories/index.cjs +12 -3
  17. package/dist/factories/index.cjs.map +1 -1
  18. package/dist/factories/index.d.cts +1 -1
  19. package/dist/factories/index.d.ts +1 -1
  20. package/dist/factories/index.js +3 -3
  21. package/dist/{index-YYypJaVw.d.cts → index-Bc0YCz1A.d.cts} +27 -1
  22. package/dist/{index-w1oqWl_M.d.ts → index-BtKOaHfY.d.ts} +1 -1
  23. package/dist/{index-D84o_UA6.d.ts → index-CRmfSYdj.d.ts} +27 -1
  24. package/dist/{index-CUFd71ri.d.cts → index-Xu238jLn.d.cts} +1 -1
  25. package/dist/index.cjs +210 -3
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.cts +8 -5
  28. package/dist/index.d.ts +8 -5
  29. package/dist/index.js +10 -8
  30. package/dist/index.js.map +1 -1
  31. package/dist/systems/index.cjs +198 -1
  32. package/dist/systems/index.cjs.map +1 -1
  33. package/dist/systems/index.d.cts +1 -1
  34. package/dist/systems/index.d.ts +1 -1
  35. package/dist/systems/index.js +3 -3
  36. package/package.json +1 -1
  37. package/dist/chunk-PCOZLCXS.js.map +0 -1
  38. package/dist/chunk-U3MDYKPV.js.map +0 -1
  39. package/dist/chunk-VXUVNC7S.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { resolveDracoDecoderPath, applyTransform, SHARED_MODEL_RESOURCE_FLAG } from './chunk-67WGASUJ.js';
2
- import { AnimationComponent, ModelComponent, CameraComponent, Object3DRef, Environment, Postprocessing, TransformComponent, PhysicsComponent, setPhysicsLiveRef, LightComponent, MaterialComponent, DEFAULT_MESH_GEOMETRY_PARAMETERS, MeshGeometryComponent, InstancedMeshComponent, ParentId, ScriptComponent, ScriptObjectComponent, InstanceSlotComponent, Name, ImageComponent, SpriteComponent, VideoComponent, AudioComponent, ImageTarget, Selectable, PrefabNode, PrefabInstance, XRInteractableComponent, XRRigComponent, VRTeleportAreaComponent } from './chunk-U3MDYKPV.js';
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';
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';
@@ -18,6 +18,8 @@ import { OutputPass } from 'three/examples/jsm/postprocessing/OutputPass.js';
18
18
  import { HueSaturationShader } from 'three/examples/jsm/shaders/HueSaturationShader.js';
19
19
  import { SepiaShader } from 'three/examples/jsm/shaders/SepiaShader.js';
20
20
  import { VignetteShader } from 'three/examples/jsm/shaders/VignetteShader.js';
21
+ import { XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory.js';
22
+ import { XRHandModelFactory } from 'three/examples/jsm/webxr/XRHandModelFactory.js';
21
23
 
22
24
  function createClipSourceLoader() {
23
25
  const loader = new GLTFLoader();
@@ -2780,6 +2782,15 @@ function buildComponentValueMaps(snapshot) {
2780
2782
  snapshot.components,
2781
2783
  "ScriptObjectComponent"
2782
2784
  ),
2785
+ xrRigValues: readByComponent(snapshot.components, "XRRigComponent"),
2786
+ vrTeleportAreaValues: readByComponent(
2787
+ snapshot.components,
2788
+ "VRTeleportAreaComponent"
2789
+ ),
2790
+ xrInteractableValues: readByComponent(
2791
+ snapshot.components,
2792
+ "XRInteractableComponent"
2793
+ ),
2783
2794
  instancedMeshValues: readByComponent(snapshot.components, "InstancedMeshComponent"),
2784
2795
  instanceSlotValues: readByComponent(snapshot.components, "InstanceSlotComponent"),
2785
2796
  prefabNodeValues: readByComponent(snapshot.components, "PrefabNode"),
@@ -2905,6 +2916,67 @@ function restorePostCreateComponents(world, objectManagementSystem, targetEntity
2905
2916
  soc.data = remapEntityRefsInScriptData(data, idMap);
2906
2917
  }
2907
2918
  }
2919
+ {
2920
+ const sourceXrRig = asRecord(values.xrRigValues.get(sourceEntityId));
2921
+ const rig = world.getComponent(targetEntityId, XRRigComponent);
2922
+ if (sourceXrRig && rig) {
2923
+ if (typeof sourceXrRig.locomotion === "string") {
2924
+ rig.locomotion = sourceXrRig.locomotion;
2925
+ }
2926
+ if (typeof sourceXrRig.moveSpeed === "number") {
2927
+ rig.moveSpeed = sourceXrRig.moveSpeed;
2928
+ }
2929
+ if (typeof sourceXrRig.snapTurn === "boolean") {
2930
+ rig.snapTurn = sourceXrRig.snapTurn;
2931
+ }
2932
+ if (typeof sourceXrRig.snapTurnDegrees === "number") {
2933
+ rig.snapTurnDegrees = sourceXrRig.snapTurnDegrees;
2934
+ }
2935
+ if (typeof sourceXrRig.fallbackEyeHeight === "number") {
2936
+ rig.fallbackEyeHeight = sourceXrRig.fallbackEyeHeight;
2937
+ }
2938
+ }
2939
+ }
2940
+ {
2941
+ const sourceArea = asRecord(values.vrTeleportAreaValues.get(sourceEntityId));
2942
+ const area = world.getComponent(targetEntityId, VRTeleportAreaComponent);
2943
+ if (sourceArea && area) {
2944
+ if (typeof sourceArea.enabled === "boolean") {
2945
+ area.enabled = sourceArea.enabled;
2946
+ }
2947
+ if (typeof sourceArea.shape === "string") {
2948
+ area.shape = sourceArea.shape === "cylinder" ? "circle" : sourceArea.shape;
2949
+ }
2950
+ if (typeof sourceArea.width === "number") area.width = sourceArea.width;
2951
+ if (typeof sourceArea.depth === "number") area.depth = sourceArea.depth;
2952
+ }
2953
+ }
2954
+ {
2955
+ const sourceInteractable = asRecord(
2956
+ values.xrInteractableValues.get(sourceEntityId)
2957
+ );
2958
+ const interactable = world.getComponent(
2959
+ targetEntityId,
2960
+ XRInteractableComponent
2961
+ );
2962
+ if (sourceInteractable && interactable) {
2963
+ if (typeof sourceInteractable.enabled === "boolean") {
2964
+ interactable.enabled = sourceInteractable.enabled;
2965
+ }
2966
+ if (typeof sourceInteractable.grabbable === "boolean") {
2967
+ interactable.grabbable = sourceInteractable.grabbable;
2968
+ }
2969
+ if (typeof sourceInteractable.pointable === "boolean") {
2970
+ interactable.pointable = sourceInteractable.pointable;
2971
+ }
2972
+ if (typeof sourceInteractable.grabMode === "string") {
2973
+ interactable.grabMode = sourceInteractable.grabMode;
2974
+ }
2975
+ if (typeof sourceInteractable.highlightOnHover === "boolean") {
2976
+ interactable.highlightOnHover = sourceInteractable.highlightOnHover;
2977
+ }
2978
+ }
2979
+ }
2908
2980
  {
2909
2981
  const imComponent = world.getComponent(targetEntityId, InstancedMeshComponent);
2910
2982
  if (imComponent && imComponent.instanceEntityIds.length > 0) {
@@ -6465,7 +6537,129 @@ var _XRSessionSystem = class _XRSessionSystem {
6465
6537
  };
6466
6538
  __name(_XRSessionSystem, "XRSessionSystem");
6467
6539
  var XRSessionSystem = _XRSessionSystem;
6540
+ function buildGeometry2(area) {
6541
+ if (area.shape === "circle") {
6542
+ const radius = Math.max(5e-3, area.width / 2);
6543
+ return new THREE7.CircleGeometry(radius, 48);
6544
+ }
6545
+ return new THREE7.PlaneGeometry(
6546
+ Math.max(0.01, area.width),
6547
+ Math.max(0.01, area.depth)
6548
+ );
6549
+ }
6550
+ __name(buildGeometry2, "buildGeometry");
6551
+ function signatureOf(area) {
6552
+ return `${area.shape}:${area.width}:${area.depth}`;
6553
+ }
6554
+ __name(signatureOf, "signatureOf");
6555
+ var _VRTeleportAreaSystem = class _VRTeleportAreaSystem {
6556
+ constructor() {
6557
+ this.signatures = /* @__PURE__ */ new Map();
6558
+ }
6559
+ update(world) {
6560
+ const entityIds = world.query(VRTeleportAreaComponent, Object3DRef);
6561
+ const alive = new Set(entityIds);
6562
+ for (const tracked of this.signatures.keys()) {
6563
+ if (!alive.has(tracked)) this.signatures.delete(tracked);
6564
+ }
6565
+ for (const entityId of entityIds) {
6566
+ const area = world.getComponent(entityId, VRTeleportAreaComponent);
6567
+ const object = world.getComponent(entityId, Object3DRef)?.object;
6568
+ if (!area || !(object instanceof THREE7.Mesh)) continue;
6569
+ const signature = signatureOf(area);
6570
+ if (this.signatures.get(entityId) === signature) continue;
6571
+ this.signatures.set(entityId, signature);
6572
+ object.geometry?.dispose?.();
6573
+ object.geometry = buildGeometry2(area);
6574
+ }
6575
+ }
6576
+ };
6577
+ __name(_VRTeleportAreaSystem, "VRTeleportAreaSystem");
6578
+ var VRTeleportAreaSystem = _VRTeleportAreaSystem;
6579
+ var _XRControllerVisualSystem = class _XRControllerVisualSystem {
6580
+ constructor(slots = 2) {
6581
+ this.controllerModelFactory = new XRControllerModelFactory();
6582
+ this.handModelFactory = new XRHandModelFactory();
6583
+ this.group = new THREE7.Group();
6584
+ this.built = false;
6585
+ this.attachedTo = null;
6586
+ /** Index → whether we've already attached visuals for that slot. */
6587
+ this.ready = /* @__PURE__ */ new Set();
6588
+ this.slots = slots;
6589
+ this.group.name = "XRControllerVisuals";
6590
+ this.group.userData.ecsPreviewHidden = true;
6591
+ }
6592
+ update(world) {
6593
+ const renderer = world.getRenderer();
6594
+ if (!renderer.xr?.enabled) return;
6595
+ 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;
6599
+ const controller = renderer.xr.getController(index);
6600
+ const grip = renderer.xr.getControllerGrip(index);
6601
+ const hand = renderer.xr.getHand(index);
6602
+ 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;
6613
+ }
6614
+ }
6615
+ /**
6616
+ * Parent the visuals to the XR rig when there is one, so locomotion moves the
6617
+ * hands with the player. Falls back to the scene root.
6618
+ */
6619
+ ensureAttached(world) {
6620
+ const camera = world.getCamera();
6621
+ const target = camera.parent ?? world.getScene();
6622
+ if (this.attachedTo === target) return;
6623
+ target.add(this.group);
6624
+ this.attachedTo = target;
6625
+ }
6626
+ createRay() {
6627
+ const geometry = new THREE7.BufferGeometry().setFromPoints([
6628
+ new THREE7.Vector3(0, 0, 0),
6629
+ new THREE7.Vector3(0, 0, -5)
6630
+ ]);
6631
+ const material = new THREE7.LineBasicMaterial({
6632
+ color: "#4da3ff",
6633
+ transparent: true,
6634
+ opacity: 0.6,
6635
+ depthTest: false
6636
+ });
6637
+ const line = new THREE7.Line(geometry, material);
6638
+ line.name = "XRPointerRay";
6639
+ line.renderOrder = 999;
6640
+ return line;
6641
+ }
6642
+ dispose() {
6643
+ this.group.removeFromParent();
6644
+ this.group.traverse((child) => {
6645
+ const mesh = child;
6646
+ mesh.geometry?.dispose?.();
6647
+ const material = mesh.material;
6648
+ if (Array.isArray(material)) {
6649
+ for (const entry of material) entry.dispose?.();
6650
+ } else {
6651
+ material?.dispose?.();
6652
+ }
6653
+ });
6654
+ this.group.clear();
6655
+ this.ready.clear();
6656
+ this.built = false;
6657
+ this.attachedTo = null;
6658
+ }
6659
+ };
6660
+ __name(_XRControllerVisualSystem, "XRControllerVisualSystem");
6661
+ var XRControllerVisualSystem = _XRControllerVisualSystem;
6468
6662
 
6469
- 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, VideoSystem, 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 };
6470
- //# sourceMappingURL=chunk-VXUVNC7S.js.map
6471
- //# sourceMappingURL=chunk-VXUVNC7S.js.map
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