@relu-interactives/spatial-ecs 0.3.6 → 0.3.7

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/index.d.cts CHANGED
@@ -3,8 +3,8 @@ export { A as AssetInput, t as CheckboxInput, u as ColorInput, v as ComponentFac
3
3
  import * as THREE from 'three';
4
4
  import { O as Object3DRef, af as XrHandPreset } from './XRInteractor-I2q6TKtF.cjs';
5
5
  export { an as AnimationStateCallbacks, ao as AnimationStateMachine, ap as AnimationStateManager, aq as StateMachine } from './XRInteractor-I2q6TKtF.cjs';
6
- import { X as XrCapabilities, a as XrInputState } from './index-C5FrDt3z.cjs';
7
- export { A as AnimationSystem, b as AudioSystem, C as CameraSyncSystem, E as EnvironmentSyncSystem, I as InstancedMeshSystem, L as LightSyncSystem, M as MaterialSyncSystem, c as MeshGeometrySystem, d as ModuleLoader, N as NO_XR_CAPABILITIES, O as ObjectVisibilitySystem, P as PhysicsSyncSystem, e as PostprocessingSyncSystem, S as SCRIPT_OBJECT_ROOT_FLAG, f as ScriptBehaviourSystem, g as ScriptObjectSystem, h as SelectionContext, V as VRTeleportAreaSystem, i as VideoSystem, j as XRControllerVisualSystem, k as XRInputSystem, l as XRInteractionSystem, m as XRLocomotionSystem, n as XRSessionSystem, o as XRTeleportVisualSystem, p as XrHandedness, q as XrInputKind, r as readXrCapabilities } from './index-C5FrDt3z.cjs';
6
+ import { X as XrCapabilities, a as XrInputState } from './index-B9nwRDf9.cjs';
7
+ export { A as AnimationSystem, b as AudioSystem, C as CameraSyncSystem, E as EnvironmentSyncSystem, I as InstancedMeshSystem, L as LightSyncSystem, M as MaterialSyncSystem, c as MeshGeometrySystem, d as ModuleLoader, N as NO_XR_CAPABILITIES, O as ObjectVisibilitySystem, P as PhysicsSyncSystem, e as PostprocessingSyncSystem, S as SCRIPT_OBJECT_ROOT_FLAG, f as ScriptBehaviourSystem, g as ScriptObjectSystem, h as SelectionContext, V as VRTeleportAreaSystem, i as VideoSystem, j as XRControllerVisualSystem, k as XRInputSystem, l as XRInteractionSystem, m as XRLocomotionSystem, n as XRSessionSystem, o as XRTeleportVisualSystem, p as XrHandedness, q as XrInputKind, r as readXrCapabilities } from './index-B9nwRDf9.cjs';
8
8
  export { i as CoreComponents } from './index-BltjPEhg.cjs';
9
9
  export { createAnimationComponent, createAudioComponent, createCameraComponent, createEntityTypeComponent, createEnvironmentComponent, createImageComponent, createImageTargetAnchorComponent, createImageTargetComponent, createInstanceSlotComponent, createInstancedMeshComponent, createLightComponent, createMaterialComponent, createMeshComponent, createMeshGeometryComponent, createModelComponent, createNameComponent, createObject3DRefComponent, createParentIdComponent, createPhysicsComponent, createPostprocessingComponent, createScriptComponent, createScriptObjectComponent, createSelectableComponent, createSelectionTransformStateComponent, createSpriteComponent, createTransformComponent, createVRTeleportAreaComponent, createVideoComponent, createXRInteractableComponent, createXRInteractorComponent, createXRInteractorSideComponent, createXRRigComponent, registerDefaultComponentFactories, registerDefaultFactories } from './factories/index.cjs';
10
10
  import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader.js';
package/dist/index.d.ts CHANGED
@@ -3,8 +3,8 @@ export { A as AssetInput, t as CheckboxInput, u as ColorInput, v as ComponentFac
3
3
  import * as THREE from 'three';
4
4
  import { O as Object3DRef, af as XrHandPreset } from './XRInteractor-CCUzSqg9.js';
5
5
  export { an as AnimationStateCallbacks, ao as AnimationStateMachine, ap as AnimationStateManager, aq as StateMachine } from './XRInteractor-CCUzSqg9.js';
6
- import { X as XrCapabilities, a as XrInputState } from './index-BpbmZuOz.js';
7
- export { A as AnimationSystem, b as AudioSystem, C as CameraSyncSystem, E as EnvironmentSyncSystem, I as InstancedMeshSystem, L as LightSyncSystem, M as MaterialSyncSystem, c as MeshGeometrySystem, d as ModuleLoader, N as NO_XR_CAPABILITIES, O as ObjectVisibilitySystem, P as PhysicsSyncSystem, e as PostprocessingSyncSystem, S as SCRIPT_OBJECT_ROOT_FLAG, f as ScriptBehaviourSystem, g as ScriptObjectSystem, h as SelectionContext, V as VRTeleportAreaSystem, i as VideoSystem, j as XRControllerVisualSystem, k as XRInputSystem, l as XRInteractionSystem, m as XRLocomotionSystem, n as XRSessionSystem, o as XRTeleportVisualSystem, p as XrHandedness, q as XrInputKind, r as readXrCapabilities } from './index-BpbmZuOz.js';
6
+ import { X as XrCapabilities, a as XrInputState } from './index-_q9TVDI5.js';
7
+ export { A as AnimationSystem, b as AudioSystem, C as CameraSyncSystem, E as EnvironmentSyncSystem, I as InstancedMeshSystem, L as LightSyncSystem, M as MaterialSyncSystem, c as MeshGeometrySystem, d as ModuleLoader, N as NO_XR_CAPABILITIES, O as ObjectVisibilitySystem, P as PhysicsSyncSystem, e as PostprocessingSyncSystem, S as SCRIPT_OBJECT_ROOT_FLAG, f as ScriptBehaviourSystem, g as ScriptObjectSystem, h as SelectionContext, V as VRTeleportAreaSystem, i as VideoSystem, j as XRControllerVisualSystem, k as XRInputSystem, l as XRInteractionSystem, m as XRLocomotionSystem, n as XRSessionSystem, o as XRTeleportVisualSystem, p as XrHandedness, q as XrInputKind, r as readXrCapabilities } from './index-_q9TVDI5.js';
8
8
  export { i as CoreComponents } from './index-W8pUajCW.js';
9
9
  export { createAnimationComponent, createAudioComponent, createCameraComponent, createEntityTypeComponent, createEnvironmentComponent, createImageComponent, createImageTargetAnchorComponent, createImageTargetComponent, createInstanceSlotComponent, createInstancedMeshComponent, createLightComponent, createMaterialComponent, createMeshComponent, createMeshGeometryComponent, createModelComponent, createNameComponent, createObject3DRefComponent, createParentIdComponent, createPhysicsComponent, createPostprocessingComponent, createScriptComponent, createScriptObjectComponent, createSelectableComponent, createSelectionTransformStateComponent, createSpriteComponent, createTransformComponent, createVRTeleportAreaComponent, createVideoComponent, createXRInteractableComponent, createXRInteractorComponent, createXRInteractorSideComponent, createXRRigComponent, registerDefaultComponentFactories, registerDefaultFactories } from './factories/index.js';
10
10
  import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { MeshGeometrySystem, InstancedMeshSystem, EnvironmentSyncSystem, PostprocessingSyncSystem, LightSyncSystem, MaterialSyncSystem, VRTeleportAreaSystem, PhysicsSyncSystem, AnimationSystem, AudioSystem, VideoSystem, CameraSyncSystem, TransformSyncSystem, ObjectVisibilitySystem, RenderSystem, spawnPrefab, despawnPrefab, buildNodeKeyMapsFromSnapshot, indexSnapshotByEntity, findTopLevelNestedRegions, collectSnapshotSubtreeIds, groupOverridePaths, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, canonicalizeComponentValue, mergeComponentValue, decanonicalizeComponentValue, computeInstanceOverrides, collectEntitySubtree, ADDED_NODE_MARKER_COMPONENT } from './chunk-WRJ2K3LZ.js';
2
- 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 } from './chunk-WRJ2K3LZ.js';
1
+ import { MeshGeometrySystem, InstancedMeshSystem, EnvironmentSyncSystem, PostprocessingSyncSystem, LightSyncSystem, MaterialSyncSystem, VRTeleportAreaSystem, PhysicsSyncSystem, AnimationSystem, AudioSystem, VideoSystem, CameraSyncSystem, TransformSyncSystem, ObjectVisibilitySystem, RenderSystem, spawnPrefab, despawnPrefab, buildNodeKeyMapsFromSnapshot, indexSnapshotByEntity, findTopLevelNestedRegions, collectSnapshotSubtreeIds, groupOverridePaths, OVERRIDE_DIFF_EXCLUDED_COMPONENTS, OVERRIDE_ROOT_EXCLUDED_COMPONENTS, canonicalizeComponentValue, mergeComponentValue, decanonicalizeComponentValue, computeInstanceOverrides, collectEntitySubtree, ADDED_NODE_MARKER_COMPONENT } from './chunk-O6FJA4XW.js';
2
+ 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 } from './chunk-O6FJA4XW.js';
3
3
  import { registerDefaultFactories } from './chunk-FQTOC7HK.js';
4
4
  export { createAnimationComponent, createAudioComponent, createCameraComponent, createEntityTypeComponent, createEnvironmentComponent, createImageComponent, createImageTargetAnchorComponent, createImageTargetComponent, createInstanceSlotComponent, createInstancedMeshComponent, createLightComponent, createMaterialComponent, createMeshComponent, createMeshGeometryComponent, createModelComponent, createNameComponent, createObject3DRefComponent, createParentIdComponent, createPhysicsComponent, createPostprocessingComponent, createScriptComponent, createScriptObjectComponent, createSelectableComponent, createSelectionTransformStateComponent, createSpriteComponent, createTransformComponent, createVRTeleportAreaComponent, createVideoComponent, createXRInteractableComponent, createXRInteractorComponent, createXRInteractorSideComponent, createXRRigComponent, registerDefaultComponentFactories, registerDefaultFactories } from './chunk-FQTOC7HK.js';
5
5
  import { ObjectManagementSystem } from './chunk-JRJ3CL5H.js';
@@ -8023,6 +8023,10 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
8023
8023
  /** Curve up to the landing point, for the visual system. Empty when not aiming. */
8024
8024
  this.aimCurve = [];
8025
8025
  this.landingPoint = null;
8026
+ /** True when the current aim lands somewhere the player may actually stand. */
8027
+ this.aimValid = false;
8028
+ /** Sources currently aiming via thumbstick (hysteresis, so it doesn't chatter). */
8029
+ this.stickAiming = /* @__PURE__ */ new WeakSet();
8026
8030
  /** True once we've tried to self-heal camera parenting for this session. */
8027
8031
  this.parentingChecked = false;
8028
8032
  this.inputSystem = inputSystem;
@@ -8030,6 +8034,7 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
8030
8034
  update(world, deltaTime) {
8031
8035
  this.aimCurve = [];
8032
8036
  this.landingPoint = null;
8037
+ this.aimValid = false;
8033
8038
  if (!world.isXrPresenting()) {
8034
8039
  this.parentingChecked = false;
8035
8040
  return;
@@ -8037,6 +8042,7 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
8037
8042
  if (!this.parentingChecked) {
8038
8043
  this.parentingChecked = true;
8039
8044
  this.ensureCameraUnderRig(world);
8045
+ this.warnOnIncompleteSetup(world);
8040
8046
  }
8041
8047
  const rigEntityId = world.query(XRRigComponent, TransformComponent)[0];
8042
8048
  if (typeof rigEntityId !== "number") return;
@@ -8054,6 +8060,26 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
8054
8060
  this.applySmoothMove(world, rig, rigTransform, inputs, deltaTime);
8055
8061
  }
8056
8062
  }
8063
+ /**
8064
+ * Name what is missing, once per session.
8065
+ *
8066
+ * Inside a headset there is no console and no inspector, so a scene that
8067
+ * simply cannot move gives the author nothing to go on. These messages are
8068
+ * visible over remote debugging and say exactly which entity to add.
8069
+ */
8070
+ warnOnIncompleteSetup(world) {
8071
+ if (typeof world.query(XRRigComponent)[0] !== "number") {
8072
+ console.warn(
8073
+ "[XRLocomotion] No XR Rig in this scene \u2014 the player cannot move. Add one via Add Object \u2192 VR \u2192 XR Rig (the scene camera is parented to it automatically)."
8074
+ );
8075
+ return;
8076
+ }
8077
+ if (world.query(VRTeleportAreaComponent).length === 0) {
8078
+ console.warn(
8079
+ "[XRLocomotion] No Teleport Area in this scene \u2014 teleport has nowhere to land. Add one via Add Object \u2192 VR \u2192 Teleport Area, or add a Teleport Area component to an existing floor."
8080
+ );
8081
+ }
8082
+ }
8057
8083
  /**
8058
8084
  * Guarantee the render camera is a CHILD of the rig.
8059
8085
  *
@@ -8121,29 +8147,60 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
8121
8147
  }
8122
8148
  applyTeleport(world, transform, inputs) {
8123
8149
  const targets = this.collectTeleportTargets(world);
8124
- if (targets.length === 0) return;
8125
8150
  for (const input of inputs) {
8126
- if (!input.select && !input.selectEnd) continue;
8151
+ const source = input;
8152
+ const stick = this.readStickAim(input, source);
8153
+ const aiming = input.select || stick.aiming;
8154
+ const commit = input.selectEnd || stick.released;
8155
+ if (!aiming && !commit) continue;
8127
8156
  const points = sampleTeleportArc(
8128
8157
  input.rayOrigin,
8129
8158
  input.rayDirection,
8130
8159
  this.arcPoints
8131
8160
  );
8132
8161
  const hit = this.raycastArc(points, targets);
8133
- if (!hit) continue;
8134
- this.landingPoint = hit.point;
8135
- this.aimCurve = points.slice(0, hit.segmentIndex + 1).concat(hit.point);
8136
- if (input.selectEnd) {
8162
+ this.aimCurve = hit ? points.slice(0, hit.segmentIndex + 1).concat(hit.point) : points.slice();
8163
+ this.landingPoint = hit ? hit.point : null;
8164
+ this.aimValid = hit !== null;
8165
+ if (commit && hit) {
8137
8166
  transform.position.x = hit.point.x;
8138
8167
  transform.position.y = hit.point.y;
8139
8168
  transform.position.z = hit.point.z;
8140
8169
  this.aimCurve = [];
8141
8170
  this.landingPoint = null;
8171
+ this.aimValid = false;
8172
+ } else if (commit) {
8173
+ this.aimCurve = [];
8174
+ this.aimValid = false;
8142
8175
  }
8143
8176
  }
8144
8177
  }
8178
+ /**
8179
+ * Thumbstick-forward aiming with hysteresis.
8180
+ *
8181
+ * Engaging at 0.6 and releasing at 0.3 stops a stick resting near the
8182
+ * threshold from flickering the arc on and off — and the release edge is what
8183
+ * commits the teleport, so chatter there would teleport the player randomly.
8184
+ */
8185
+ readStickAim(input, source) {
8186
+ if (!input.hasAxes || input.axes.length < 4) {
8187
+ return { aiming: false, released: false };
8188
+ }
8189
+ const forward = -(input.axes[3] ?? 0);
8190
+ const wasAiming = this.stickAiming.has(source);
8191
+ if (!wasAiming && forward > 0.6) {
8192
+ this.stickAiming.add(source);
8193
+ return { aiming: true, released: false };
8194
+ }
8195
+ if (wasAiming && forward < 0.3) {
8196
+ this.stickAiming.delete(source);
8197
+ return { aiming: false, released: true };
8198
+ }
8199
+ return { aiming: wasAiming, released: false };
8200
+ }
8145
8201
  /** Walk the arc segment-by-segment, returning the first surface hit. */
8146
8202
  raycastArc(points, targets) {
8203
+ if (targets.length === 0) return null;
8147
8204
  for (let i = 1; i < points.length; i += 1) {
8148
8205
  const from = points[i - 1];
8149
8206
  const to = points[i];
@@ -8174,6 +8231,10 @@ var _XRLocomotionSystem = class _XRLocomotionSystem {
8174
8231
  getAimCurve() {
8175
8232
  return this.aimCurve;
8176
8233
  }
8234
+ /** True when the aim lands on a valid teleport area. */
8235
+ isAimValid() {
8236
+ return this.aimValid;
8237
+ }
8177
8238
  /** Where the arc currently lands, or null when not aiming at a valid area. */
8178
8239
  getLandingPoint() {
8179
8240
  return this.landingPoint;
@@ -8620,6 +8681,7 @@ __name(_XRControllerVisualSystem, "XRControllerVisualSystem");
8620
8681
  var XRControllerVisualSystem = _XRControllerVisualSystem;
8621
8682
  var MARKER_RADIUS = 0.28;
8622
8683
  var ACCENT = new THREE14__namespace.Color("#4da3ff");
8684
+ var BLOCKED = new THREE14__namespace.Color("#ff5a5a");
8623
8685
  var _XRTeleportVisualSystem = class _XRTeleportVisualSystem {
8624
8686
  constructor(locomotionSystem) {
8625
8687
  this.group = new THREE14__namespace.Group();
@@ -8650,16 +8712,22 @@ var _XRTeleportVisualSystem = class _XRTeleportVisualSystem {
8650
8712
  }
8651
8713
  const curve = this.locomotionSystem.getAimCurve();
8652
8714
  const landing = this.locomotionSystem.getLandingPoint();
8653
- if (!landing || curve.length < 2) {
8715
+ const valid = this.locomotionSystem.isAimValid();
8716
+ if (curve.length < 2) {
8654
8717
  this.setVisible(false);
8655
8718
  return;
8656
8719
  }
8657
- this.updateArcGeometry(curve);
8658
- this.marker.position.copy(landing);
8659
- this.marker.position.y += 0.01;
8720
+ this.updateArcGeometry(curve, valid ? ACCENT : BLOCKED);
8721
+ if (valid && landing) {
8722
+ this.marker.position.copy(landing);
8723
+ this.marker.position.y += 0.01;
8724
+ this.marker.visible = true;
8725
+ } else {
8726
+ this.marker.visible = false;
8727
+ }
8660
8728
  this.setVisible(true);
8661
8729
  }
8662
- updateArcGeometry(curve) {
8730
+ updateArcGeometry(curve, tint) {
8663
8731
  const count = curve.length;
8664
8732
  const positions = new Float32Array(count * 3);
8665
8733
  const colors = new Float32Array(count * 3);
@@ -8670,9 +8738,9 @@ var _XRTeleportVisualSystem = class _XRTeleportVisualSystem {
8670
8738
  positions[i * 3 + 2] = point.z;
8671
8739
  const t = count > 1 ? i / (count - 1) : 0;
8672
8740
  const fade = 1 - t * 0.75;
8673
- colors[i * 3] = ACCENT.r * fade;
8674
- colors[i * 3 + 1] = ACCENT.g * fade;
8675
- colors[i * 3 + 2] = ACCENT.b * fade;
8741
+ colors[i * 3] = tint.r * fade;
8742
+ colors[i * 3 + 1] = tint.g * fade;
8743
+ colors[i * 3 + 2] = tint.b * fade;
8676
8744
  }
8677
8745
  this.arcGeometry.setAttribute(
8678
8746
  "position",