@relu-interactives/spatial-ecs 0.3.1 → 0.3.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.
@@ -18,6 +18,8 @@ var OutputPass_js = require('three/examples/jsm/postprocessing/OutputPass.js');
18
18
  var HueSaturationShader_js = require('three/examples/jsm/shaders/HueSaturationShader.js');
19
19
  var SepiaShader_js = require('three/examples/jsm/shaders/SepiaShader.js');
20
20
  var VignetteShader_js = require('three/examples/jsm/shaders/VignetteShader.js');
21
+ var XRControllerModelFactory_js = require('three/examples/jsm/webxr/XRControllerModelFactory.js');
22
+ var XRHandModelFactory_js = require('three/examples/jsm/webxr/XRHandModelFactory.js');
21
23
 
22
24
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
23
25
  function _interopNamespace(e) {
@@ -8043,6 +8045,128 @@ var _XRSessionSystem = class _XRSessionSystem {
8043
8045
  };
8044
8046
  __name(_XRSessionSystem, "XRSessionSystem");
8045
8047
  var XRSessionSystem = _XRSessionSystem;
8048
+ function buildGeometry2(area) {
8049
+ if (area.shape === "cylinder") {
8050
+ const radius = Math.max(5e-3, area.width / 2);
8051
+ return new THREE14__namespace.CircleGeometry(radius, 48);
8052
+ }
8053
+ return new THREE14__namespace.PlaneGeometry(
8054
+ Math.max(0.01, area.width),
8055
+ Math.max(0.01, area.depth)
8056
+ );
8057
+ }
8058
+ __name(buildGeometry2, "buildGeometry");
8059
+ function signatureOf(area) {
8060
+ return `${area.shape}:${area.width}:${area.depth}`;
8061
+ }
8062
+ __name(signatureOf, "signatureOf");
8063
+ var _VRTeleportAreaSystem = class _VRTeleportAreaSystem {
8064
+ constructor() {
8065
+ this.signatures = /* @__PURE__ */ new Map();
8066
+ }
8067
+ update(world) {
8068
+ const entityIds = world.query(VRTeleportAreaComponent, Object3DRef);
8069
+ const alive = new Set(entityIds);
8070
+ for (const tracked of this.signatures.keys()) {
8071
+ if (!alive.has(tracked)) this.signatures.delete(tracked);
8072
+ }
8073
+ for (const entityId of entityIds) {
8074
+ const area = world.getComponent(entityId, VRTeleportAreaComponent);
8075
+ const object = world.getComponent(entityId, Object3DRef)?.object;
8076
+ if (!area || !(object instanceof THREE14__namespace.Mesh)) continue;
8077
+ const signature = signatureOf(area);
8078
+ if (this.signatures.get(entityId) === signature) continue;
8079
+ this.signatures.set(entityId, signature);
8080
+ object.geometry?.dispose?.();
8081
+ object.geometry = buildGeometry2(area);
8082
+ }
8083
+ }
8084
+ };
8085
+ __name(_VRTeleportAreaSystem, "VRTeleportAreaSystem");
8086
+ var VRTeleportAreaSystem = _VRTeleportAreaSystem;
8087
+ var _XRControllerVisualSystem = class _XRControllerVisualSystem {
8088
+ constructor(slots = 2) {
8089
+ this.controllerModelFactory = new XRControllerModelFactory_js.XRControllerModelFactory();
8090
+ this.handModelFactory = new XRHandModelFactory_js.XRHandModelFactory();
8091
+ this.group = new THREE14__namespace.Group();
8092
+ this.built = false;
8093
+ this.attachedTo = null;
8094
+ /** Index → whether we've already attached visuals for that slot. */
8095
+ this.ready = /* @__PURE__ */ new Set();
8096
+ this.slots = slots;
8097
+ this.group.name = "XRControllerVisuals";
8098
+ this.group.userData.ecsPreviewHidden = true;
8099
+ }
8100
+ update(world) {
8101
+ const renderer = world.getRenderer();
8102
+ if (!renderer.xr?.enabled) return;
8103
+ this.ensureAttached(world);
8104
+ if (this.built) return;
8105
+ for (let index = 0; index < this.slots; index += 1) {
8106
+ if (this.ready.has(index)) continue;
8107
+ const controller = renderer.xr.getController(index);
8108
+ const grip = renderer.xr.getControllerGrip(index);
8109
+ const hand = renderer.xr.getHand(index);
8110
+ if (!controller || !grip || !hand) continue;
8111
+ controller.add(this.createRay());
8112
+ this.group.add(controller);
8113
+ grip.add(this.controllerModelFactory.createControllerModel(grip));
8114
+ this.group.add(grip);
8115
+ hand.add(this.handModelFactory.createHandModel(hand, "mesh"));
8116
+ this.group.add(hand);
8117
+ this.ready.add(index);
8118
+ }
8119
+ if (this.ready.size >= this.slots) {
8120
+ this.built = true;
8121
+ }
8122
+ }
8123
+ /**
8124
+ * Parent the visuals to the XR rig when there is one, so locomotion moves the
8125
+ * hands with the player. Falls back to the scene root.
8126
+ */
8127
+ ensureAttached(world) {
8128
+ const camera = world.getCamera();
8129
+ const target = camera.parent ?? world.getScene();
8130
+ if (this.attachedTo === target) return;
8131
+ target.add(this.group);
8132
+ this.attachedTo = target;
8133
+ }
8134
+ createRay() {
8135
+ const geometry = new THREE14__namespace.BufferGeometry().setFromPoints([
8136
+ new THREE14__namespace.Vector3(0, 0, 0),
8137
+ new THREE14__namespace.Vector3(0, 0, -5)
8138
+ ]);
8139
+ const material = new THREE14__namespace.LineBasicMaterial({
8140
+ color: "#4da3ff",
8141
+ transparent: true,
8142
+ opacity: 0.6,
8143
+ depthTest: false
8144
+ });
8145
+ const line = new THREE14__namespace.Line(geometry, material);
8146
+ line.name = "XRPointerRay";
8147
+ line.renderOrder = 999;
8148
+ return line;
8149
+ }
8150
+ dispose() {
8151
+ this.group.removeFromParent();
8152
+ this.group.traverse((child) => {
8153
+ const mesh = child;
8154
+ mesh.geometry?.dispose?.();
8155
+ const material = mesh.material;
8156
+ if (Array.isArray(material)) {
8157
+ for (const entry of material) entry.dispose?.();
8158
+ } else {
8159
+ material?.dispose?.();
8160
+ }
8161
+ });
8162
+ this.group.clear();
8163
+ this.ready.clear();
8164
+ this.built = false;
8165
+ this.attachedTo = null;
8166
+ }
8167
+ };
8168
+ __name(_XRControllerVisualSystem, "XRControllerVisualSystem");
8169
+ var XRControllerVisualSystem = _XRControllerVisualSystem;
8046
8170
 
8047
8171
  exports.AnimationSystem = AnimationSystem;
8048
8172
  exports.AudioSystem = AudioSystem;
@@ -8063,7 +8187,9 @@ exports.SCRIPT_OBJECT_ROOT_FLAG = SCRIPT_OBJECT_ROOT_FLAG;
8063
8187
  exports.ScriptBehaviourSystem = ScriptBehaviourSystem;
8064
8188
  exports.ScriptObjectSystem = ScriptObjectSystem;
8065
8189
  exports.TransformSyncSystem = TransformSyncSystem;
8190
+ exports.VRTeleportAreaSystem = VRTeleportAreaSystem;
8066
8191
  exports.VideoSystem = VideoSystem;
8192
+ exports.XRControllerVisualSystem = XRControllerVisualSystem;
8067
8193
  exports.XRInputSystem = XRInputSystem;
8068
8194
  exports.XRInteractionSystem = XRInteractionSystem;
8069
8195
  exports.XRLocomotionSystem = XRLocomotionSystem;