@relu-interactives/spatial-ecs 0.3.0 → 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.
- package/dist/{System-CYWZ_Zx5.d.cts → System-vrU46Vuw.d.cts} +16 -2
- package/dist/{System-CYWZ_Zx5.d.ts → System-vrU46Vuw.d.ts} +16 -2
- package/dist/{Video-AIQYTAAr.d.cts → XRRig-CAmf04NX.d.ts} +131 -4
- package/dist/{Video-DlZ4G9ig.d.ts → XRRig-Cu-EyliG.d.cts} +131 -4
- package/dist/{chunk-PZ4CAALA.js → chunk-67WGASUJ.js} +3 -3
- package/dist/{chunk-PZ4CAALA.js.map → chunk-67WGASUJ.js.map} +1 -1
- package/dist/{chunk-AT5SPSPM.js → chunk-JWTRFJBL.js} +168 -83
- package/dist/chunk-JWTRFJBL.js.map +1 -0
- package/dist/{chunk-7JFSEV7A.js → chunk-SALBG747.js} +757 -6
- package/dist/chunk-SALBG747.js.map +1 -0
- package/dist/{chunk-7BPHZWQ6.js → chunk-U3MDYKPV.js} +47 -3
- package/dist/chunk-U3MDYKPV.js.map +1 -0
- package/dist/components/index.cjs +44 -0
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +3 -3
- package/dist/components/index.d.ts +3 -3
- package/dist/components/index.js +1 -1
- package/dist/factories/index.cjs +236 -107
- package/dist/factories/index.cjs.map +1 -1
- package/dist/factories/index.d.cts +9 -3
- package/dist/factories/index.d.ts +9 -3
- package/dist/factories/index.js +3 -3
- package/dist/index-Bc0YCz1A.d.cts +514 -0
- package/dist/index-CRmfSYdj.d.ts +514 -0
- package/dist/{index-Gr8aCPRM.d.cts → index-CUFd71ri.d.cts} +12 -3
- package/dist/{index-BwiRJNIT.d.ts → index-w1oqWl_M.d.ts} +12 -3
- package/dist/index.cjs +1107 -198
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -8
- package/dist/index.d.ts +42 -8
- package/dist/index.js +26 -8
- package/dist/index.js.map +1 -1
- package/dist/systems/index.cjs +799 -1
- package/dist/systems/index.cjs.map +1 -1
- package/dist/systems/index.d.cts +3 -278
- package/dist/systems/index.d.ts +3 -278
- package/dist/systems/index.js +3 -3
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/worldSnapshotUtils.d.cts +1 -1
- package/dist/worldSnapshotUtils.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chunk-7BPHZWQ6.js.map +0 -1
- package/dist/chunk-7JFSEV7A.js.map +0 -1
- package/dist/chunk-AT5SPSPM.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { resolveDracoDecoderPath, applyTransform, SHARED_MODEL_RESOURCE_FLAG } from './chunk-
|
|
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 } from './chunk-
|
|
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';
|
|
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();
|
|
@@ -501,6 +503,7 @@ var _CameraSyncSystem = class _CameraSyncSystem {
|
|
|
501
503
|
update(world) {
|
|
502
504
|
const entityIds = world.query(CameraComponent, Object3DRef);
|
|
503
505
|
const windowAspect = readWindowAspect();
|
|
506
|
+
const xrCamera = world.isXrPresenting() ? world.getCamera() : null;
|
|
504
507
|
const alive = new Set(entityIds);
|
|
505
508
|
for (const trackedId of this.signatures.keys()) {
|
|
506
509
|
if (!alive.has(trackedId)) {
|
|
@@ -517,6 +520,9 @@ var _CameraSyncSystem = class _CameraSyncSystem {
|
|
|
517
520
|
if (!(camera instanceof THREE7.Camera)) {
|
|
518
521
|
continue;
|
|
519
522
|
}
|
|
523
|
+
if (xrCamera !== null && camera === xrCamera) {
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
520
526
|
const nextSignature = buildSignature(component, camera, windowAspect);
|
|
521
527
|
if (this.signatures.get(entityId) === nextSignature) {
|
|
522
528
|
continue;
|
|
@@ -3488,7 +3494,9 @@ var HYDRATABLE_ENTITY_KINDS = /* @__PURE__ */ new Set([
|
|
|
3488
3494
|
"areaLight",
|
|
3489
3495
|
"instancedMesh",
|
|
3490
3496
|
"instanceSlot",
|
|
3491
|
-
"scriptObject"
|
|
3497
|
+
"scriptObject",
|
|
3498
|
+
"xrRig",
|
|
3499
|
+
"teleportArea"
|
|
3492
3500
|
]);
|
|
3493
3501
|
|
|
3494
3502
|
// core/hydration/hydrateWorld.ts
|
|
@@ -4735,6 +4743,49 @@ var _Behaviour = class _Behaviour {
|
|
|
4735
4743
|
*/
|
|
4736
4744
|
onTargetLost(target) {
|
|
4737
4745
|
}
|
|
4746
|
+
// ─── WebXR (VR / MR) hooks ────────────────────────────────────────────────
|
|
4747
|
+
// Dispatched by XRSessionSystem / XRInteractionSystem, following the same
|
|
4748
|
+
// pattern as the AR hooks above: public no-op methods that subclasses opt
|
|
4749
|
+
// into by overriding. They never fire outside an immersive session.
|
|
4750
|
+
/**
|
|
4751
|
+
* Called once when an immersive session starts. Optional XR hook.
|
|
4752
|
+
*
|
|
4753
|
+
* Use it to set up XR-only state. Inspect `capabilities` rather than guessing
|
|
4754
|
+
* by device: feature support differs sharply per headset (for example Vision
|
|
4755
|
+
* Pro grants no passthrough on the web today).
|
|
4756
|
+
*
|
|
4757
|
+
* @param capabilities - What the session actually granted, read from
|
|
4758
|
+
* `XRSession.enabledFeatures`.
|
|
4759
|
+
*/
|
|
4760
|
+
onXRSessionStart(capabilities) {
|
|
4761
|
+
}
|
|
4762
|
+
/** Called once when the immersive session ends. Optional XR hook. */
|
|
4763
|
+
onXRSessionEnd() {
|
|
4764
|
+
}
|
|
4765
|
+
/**
|
|
4766
|
+
* Called when a primary action begins — controller trigger, hand pinch, or
|
|
4767
|
+
* Vision Pro gaze-pinch. Optional XR hook.
|
|
4768
|
+
*
|
|
4769
|
+
* @param input - Normalized state for the source that acted.
|
|
4770
|
+
*/
|
|
4771
|
+
onSelectStart(input) {
|
|
4772
|
+
}
|
|
4773
|
+
/** Called when the primary action ends. Optional XR hook. */
|
|
4774
|
+
onSelectEnd(input) {
|
|
4775
|
+
}
|
|
4776
|
+
/**
|
|
4777
|
+
* Called when this entity is grabbed. Optional XR hook.
|
|
4778
|
+
*
|
|
4779
|
+
* Only fires for entities carrying an enabled, grabbable
|
|
4780
|
+
* `XRInteractableComponent`.
|
|
4781
|
+
*
|
|
4782
|
+
* @param input - The source doing the grabbing.
|
|
4783
|
+
*/
|
|
4784
|
+
onGrab(input) {
|
|
4785
|
+
}
|
|
4786
|
+
/** Called when this entity is released. Optional XR hook. */
|
|
4787
|
+
onRelease(input) {
|
|
4788
|
+
}
|
|
4738
4789
|
};
|
|
4739
4790
|
__name(_Behaviour, "Behaviour");
|
|
4740
4791
|
/**
|
|
@@ -5582,12 +5633,16 @@ var ScriptObjectSystem = _ScriptObjectSystem;
|
|
|
5582
5633
|
var _TransformSyncSystem = class _TransformSyncSystem {
|
|
5583
5634
|
update(world) {
|
|
5584
5635
|
const entities = world.query(TransformComponent, Object3DRef);
|
|
5636
|
+
const xrCamera = world.isXrPresenting() ? world.getCamera() : null;
|
|
5585
5637
|
for (const entityId of entities) {
|
|
5586
5638
|
const transform = world.getComponent(entityId, TransformComponent);
|
|
5587
5639
|
const object = world.getComponent(entityId, Object3DRef)?.object;
|
|
5588
5640
|
if (!transform || !object) {
|
|
5589
5641
|
continue;
|
|
5590
5642
|
}
|
|
5643
|
+
if (xrCamera !== null && object === xrCamera) {
|
|
5644
|
+
continue;
|
|
5645
|
+
}
|
|
5591
5646
|
applyTransform(object, transform);
|
|
5592
5647
|
object.updateMatrixWorld(true);
|
|
5593
5648
|
}
|
|
@@ -5838,7 +5893,703 @@ var _VideoSystem = class _VideoSystem {
|
|
|
5838
5893
|
};
|
|
5839
5894
|
__name(_VideoSystem, "VideoSystem");
|
|
5840
5895
|
var VideoSystem = _VideoSystem;
|
|
5896
|
+
function handednessOf(source) {
|
|
5897
|
+
const value = source.handedness;
|
|
5898
|
+
return value === "left" || value === "right" ? value : "none";
|
|
5899
|
+
}
|
|
5900
|
+
__name(handednessOf, "handednessOf");
|
|
5901
|
+
function kindOf(source) {
|
|
5902
|
+
const mode = source.targetRayMode;
|
|
5903
|
+
if (mode === "transient-pointer") return "transient-pointer";
|
|
5904
|
+
if (mode === "gaze") return "gaze";
|
|
5905
|
+
if (source.hand) return "hand";
|
|
5906
|
+
return "controller";
|
|
5907
|
+
}
|
|
5908
|
+
__name(kindOf, "kindOf");
|
|
5909
|
+
function blankState(source) {
|
|
5910
|
+
return {
|
|
5911
|
+
handedness: handednessOf(source),
|
|
5912
|
+
kind: kindOf(source),
|
|
5913
|
+
connected: true,
|
|
5914
|
+
rayOrigin: new THREE7.Vector3(),
|
|
5915
|
+
rayDirection: new THREE7.Vector3(0, 0, -1),
|
|
5916
|
+
gripPosition: null,
|
|
5917
|
+
gripQuaternion: null,
|
|
5918
|
+
select: false,
|
|
5919
|
+
selectStart: false,
|
|
5920
|
+
selectEnd: false,
|
|
5921
|
+
squeeze: false,
|
|
5922
|
+
squeezeStart: false,
|
|
5923
|
+
squeezeEnd: false,
|
|
5924
|
+
axes: [],
|
|
5925
|
+
hasAxes: false,
|
|
5926
|
+
buttons: []
|
|
5927
|
+
};
|
|
5928
|
+
}
|
|
5929
|
+
__name(blankState, "blankState");
|
|
5930
|
+
var _XRInputSystem = class _XRInputSystem {
|
|
5931
|
+
constructor() {
|
|
5932
|
+
this.records = /* @__PURE__ */ new Map();
|
|
5933
|
+
this.session = null;
|
|
5934
|
+
this.onSelectStart = /* @__PURE__ */ __name((event) => this.mark(event, "pendingSelectStart"), "onSelectStart");
|
|
5935
|
+
this.onSelectEnd = /* @__PURE__ */ __name((event) => this.mark(event, "pendingSelectEnd"), "onSelectEnd");
|
|
5936
|
+
this.onSqueezeStart = /* @__PURE__ */ __name((event) => this.mark(event, "pendingSqueezeStart"), "onSqueezeStart");
|
|
5937
|
+
this.onSqueezeEnd = /* @__PURE__ */ __name((event) => this.mark(event, "pendingSqueezeEnd"), "onSqueezeEnd");
|
|
5938
|
+
}
|
|
5939
|
+
mark(event, flag) {
|
|
5940
|
+
const record = this.ensureRecord(event.inputSource);
|
|
5941
|
+
record[flag] = true;
|
|
5942
|
+
}
|
|
5943
|
+
ensureRecord(source) {
|
|
5944
|
+
let record = this.records.get(source);
|
|
5945
|
+
if (!record) {
|
|
5946
|
+
record = {
|
|
5947
|
+
source,
|
|
5948
|
+
state: blankState(source),
|
|
5949
|
+
pendingSelectStart: false,
|
|
5950
|
+
pendingSelectEnd: false,
|
|
5951
|
+
pendingSqueezeStart: false,
|
|
5952
|
+
pendingSqueezeEnd: false,
|
|
5953
|
+
removed: false
|
|
5954
|
+
};
|
|
5955
|
+
this.records.set(source, record);
|
|
5956
|
+
}
|
|
5957
|
+
return record;
|
|
5958
|
+
}
|
|
5959
|
+
/** Bind to a session. Called by {@link XRSessionSystem} on session start. */
|
|
5960
|
+
attachSession(session) {
|
|
5961
|
+
this.detachSession();
|
|
5962
|
+
this.session = session;
|
|
5963
|
+
session.addEventListener("selectstart", this.onSelectStart);
|
|
5964
|
+
session.addEventListener("selectend", this.onSelectEnd);
|
|
5965
|
+
session.addEventListener(
|
|
5966
|
+
"squeezestart",
|
|
5967
|
+
this.onSqueezeStart
|
|
5968
|
+
);
|
|
5969
|
+
session.addEventListener("squeezeend", this.onSqueezeEnd);
|
|
5970
|
+
}
|
|
5971
|
+
/** Unbind and drop all per-source state. */
|
|
5972
|
+
detachSession() {
|
|
5973
|
+
const session = this.session;
|
|
5974
|
+
if (session) {
|
|
5975
|
+
session.removeEventListener(
|
|
5976
|
+
"selectstart",
|
|
5977
|
+
this.onSelectStart
|
|
5978
|
+
);
|
|
5979
|
+
session.removeEventListener(
|
|
5980
|
+
"selectend",
|
|
5981
|
+
this.onSelectEnd
|
|
5982
|
+
);
|
|
5983
|
+
session.removeEventListener(
|
|
5984
|
+
"squeezestart",
|
|
5985
|
+
this.onSqueezeStart
|
|
5986
|
+
);
|
|
5987
|
+
session.removeEventListener(
|
|
5988
|
+
"squeezeend",
|
|
5989
|
+
this.onSqueezeEnd
|
|
5990
|
+
);
|
|
5991
|
+
}
|
|
5992
|
+
this.session = null;
|
|
5993
|
+
this.records.clear();
|
|
5994
|
+
}
|
|
5995
|
+
update(world) {
|
|
5996
|
+
for (const [source, record] of this.records) {
|
|
5997
|
+
if (record.removed) {
|
|
5998
|
+
this.records.delete(source);
|
|
5999
|
+
continue;
|
|
6000
|
+
}
|
|
6001
|
+
record.state.selectStart = false;
|
|
6002
|
+
record.state.selectEnd = false;
|
|
6003
|
+
record.state.squeezeStart = false;
|
|
6004
|
+
record.state.squeezeEnd = false;
|
|
6005
|
+
}
|
|
6006
|
+
const session = this.session;
|
|
6007
|
+
if (!session || !world.isXrPresenting()) return;
|
|
6008
|
+
const renderer = world.getRenderer();
|
|
6009
|
+
const referenceSpace = renderer.xr.getReferenceSpace();
|
|
6010
|
+
const frame = renderer.xr.getFrame?.();
|
|
6011
|
+
const live = /* @__PURE__ */ new Set();
|
|
6012
|
+
for (const source of session.inputSources) {
|
|
6013
|
+
live.add(source);
|
|
6014
|
+
const record = this.ensureRecord(source);
|
|
6015
|
+
const state = record.state;
|
|
6016
|
+
state.connected = true;
|
|
6017
|
+
state.handedness = handednessOf(source);
|
|
6018
|
+
state.kind = kindOf(source);
|
|
6019
|
+
if (frame && referenceSpace && source.targetRaySpace) {
|
|
6020
|
+
const pose = frame.getPose(source.targetRaySpace, referenceSpace);
|
|
6021
|
+
if (pose) {
|
|
6022
|
+
const m = new THREE7.Matrix4().fromArray(pose.transform.matrix);
|
|
6023
|
+
state.rayOrigin.setFromMatrixPosition(m);
|
|
6024
|
+
state.rayDirection.set(0, 0, -1).applyQuaternion(
|
|
6025
|
+
new THREE7.Quaternion().setFromRotationMatrix(m)
|
|
6026
|
+
).normalize();
|
|
6027
|
+
}
|
|
6028
|
+
}
|
|
6029
|
+
if (frame && referenceSpace && source.gripSpace) {
|
|
6030
|
+
const gripPose = frame.getPose(source.gripSpace, referenceSpace);
|
|
6031
|
+
if (gripPose) {
|
|
6032
|
+
const m = new THREE7.Matrix4().fromArray(gripPose.transform.matrix);
|
|
6033
|
+
state.gripPosition ?? (state.gripPosition = new THREE7.Vector3());
|
|
6034
|
+
state.gripQuaternion ?? (state.gripQuaternion = new THREE7.Quaternion());
|
|
6035
|
+
state.gripPosition.setFromMatrixPosition(m);
|
|
6036
|
+
state.gripQuaternion.setFromRotationMatrix(m);
|
|
6037
|
+
}
|
|
6038
|
+
} else {
|
|
6039
|
+
state.gripPosition = null;
|
|
6040
|
+
state.gripQuaternion = null;
|
|
6041
|
+
}
|
|
6042
|
+
const gamepad = source.gamepad;
|
|
6043
|
+
if (gamepad) {
|
|
6044
|
+
state.axes = Array.from(gamepad.axes);
|
|
6045
|
+
state.hasAxes = gamepad.axes.some((axis) => Number.isFinite(axis));
|
|
6046
|
+
state.buttons = gamepad.buttons.map((button) => button.pressed);
|
|
6047
|
+
} else {
|
|
6048
|
+
state.axes = [];
|
|
6049
|
+
state.hasAxes = false;
|
|
6050
|
+
state.buttons = [];
|
|
6051
|
+
}
|
|
6052
|
+
if (record.pendingSelectStart) {
|
|
6053
|
+
state.select = true;
|
|
6054
|
+
state.selectStart = true;
|
|
6055
|
+
record.pendingSelectStart = false;
|
|
6056
|
+
}
|
|
6057
|
+
if (record.pendingSelectEnd) {
|
|
6058
|
+
state.select = false;
|
|
6059
|
+
state.selectEnd = true;
|
|
6060
|
+
record.pendingSelectEnd = false;
|
|
6061
|
+
}
|
|
6062
|
+
if (record.pendingSqueezeStart) {
|
|
6063
|
+
state.squeeze = true;
|
|
6064
|
+
state.squeezeStart = true;
|
|
6065
|
+
record.pendingSqueezeStart = false;
|
|
6066
|
+
}
|
|
6067
|
+
if (record.pendingSqueezeEnd) {
|
|
6068
|
+
state.squeeze = false;
|
|
6069
|
+
state.squeezeEnd = true;
|
|
6070
|
+
record.pendingSqueezeEnd = false;
|
|
6071
|
+
}
|
|
6072
|
+
}
|
|
6073
|
+
for (const [source, record] of this.records) {
|
|
6074
|
+
if (live.has(source)) continue;
|
|
6075
|
+
record.state.connected = false;
|
|
6076
|
+
record.removed = true;
|
|
6077
|
+
}
|
|
6078
|
+
}
|
|
6079
|
+
/** Every input source active this frame. */
|
|
6080
|
+
getInputs() {
|
|
6081
|
+
return Array.from(this.records.values(), (record) => record.state);
|
|
6082
|
+
}
|
|
6083
|
+
/** The first source for a hand, or null. Prefer this for hand-specific logic. */
|
|
6084
|
+
getInput(handedness) {
|
|
6085
|
+
for (const record of this.records.values()) {
|
|
6086
|
+
if (record.state.handedness === handedness) return record.state;
|
|
6087
|
+
}
|
|
6088
|
+
return null;
|
|
6089
|
+
}
|
|
6090
|
+
/** True while ANY source is selecting — the portable "is the user acting" check. */
|
|
6091
|
+
isSelecting() {
|
|
6092
|
+
for (const record of this.records.values()) {
|
|
6093
|
+
if (record.state.select) return true;
|
|
6094
|
+
}
|
|
6095
|
+
return false;
|
|
6096
|
+
}
|
|
6097
|
+
dispose() {
|
|
6098
|
+
this.detachSession();
|
|
6099
|
+
}
|
|
6100
|
+
};
|
|
6101
|
+
__name(_XRInputSystem, "XRInputSystem");
|
|
6102
|
+
var XRInputSystem = _XRInputSystem;
|
|
6103
|
+
var RAYLESS_HOLD_DISTANCE = 0.5;
|
|
6104
|
+
var _XRInteractionSystem = class _XRInteractionSystem {
|
|
6105
|
+
constructor(inputSystem) {
|
|
6106
|
+
this.raycaster = new THREE7.Raycaster();
|
|
6107
|
+
/** Which entity each source is holding. Keyed by source state identity. */
|
|
6108
|
+
this.grabs = /* @__PURE__ */ new Map();
|
|
6109
|
+
this.hoveredEntityId = null;
|
|
6110
|
+
this.inputSystem = inputSystem;
|
|
6111
|
+
}
|
|
6112
|
+
update(world) {
|
|
6113
|
+
if (!world.isXrPresenting()) {
|
|
6114
|
+
this.releaseAll(world);
|
|
6115
|
+
return;
|
|
6116
|
+
}
|
|
6117
|
+
const inputs = this.inputSystem.getInputs();
|
|
6118
|
+
const interactables = this.collectInteractables(world);
|
|
6119
|
+
this.hoveredEntityId = null;
|
|
6120
|
+
for (const input of inputs) {
|
|
6121
|
+
if (!input.connected) {
|
|
6122
|
+
this.release(world, input);
|
|
6123
|
+
continue;
|
|
6124
|
+
}
|
|
6125
|
+
const held = this.grabs.get(input);
|
|
6126
|
+
if (held) {
|
|
6127
|
+
this.moveHeld(world, input, held);
|
|
6128
|
+
if (input.selectEnd) this.release(world, input);
|
|
6129
|
+
continue;
|
|
6130
|
+
}
|
|
6131
|
+
const hitEntityId = this.raycast(input, interactables);
|
|
6132
|
+
if (hitEntityId === null) continue;
|
|
6133
|
+
if (this.hoveredEntityId === null) {
|
|
6134
|
+
this.hoveredEntityId = hitEntityId;
|
|
6135
|
+
}
|
|
6136
|
+
const interactable = world.getComponent(
|
|
6137
|
+
hitEntityId,
|
|
6138
|
+
XRInteractableComponent
|
|
6139
|
+
);
|
|
6140
|
+
if (input.selectStart && interactable?.grabbable) {
|
|
6141
|
+
this.grab(world, input, hitEntityId);
|
|
6142
|
+
}
|
|
6143
|
+
}
|
|
6144
|
+
}
|
|
6145
|
+
collectInteractables(world) {
|
|
6146
|
+
const out = [];
|
|
6147
|
+
for (const entityId of world.query(XRInteractableComponent, Object3DRef)) {
|
|
6148
|
+
const interactable = world.getComponent(entityId, XRInteractableComponent);
|
|
6149
|
+
if (!interactable?.enabled || !interactable.pointable) continue;
|
|
6150
|
+
if (!world.isEntityVisible(entityId)) continue;
|
|
6151
|
+
const object = world.getComponent(entityId, Object3DRef)?.object;
|
|
6152
|
+
if (object) out.push({ entityId, object });
|
|
6153
|
+
}
|
|
6154
|
+
return out;
|
|
6155
|
+
}
|
|
6156
|
+
/** Entity id of the nearest pointable hit along this source's ray, or null. */
|
|
6157
|
+
raycast(input, interactables) {
|
|
6158
|
+
if (interactables.length === 0) return null;
|
|
6159
|
+
this.raycaster.set(input.rayOrigin, input.rayDirection);
|
|
6160
|
+
let nearestId = null;
|
|
6161
|
+
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
6162
|
+
for (const entry of interactables) {
|
|
6163
|
+
const hit = this.raycaster.intersectObject(entry.object, true)[0];
|
|
6164
|
+
if (!hit) continue;
|
|
6165
|
+
if (hit.distance < nearestDistance) {
|
|
6166
|
+
nearestDistance = hit.distance;
|
|
6167
|
+
nearestId = entry.entityId;
|
|
6168
|
+
}
|
|
6169
|
+
}
|
|
6170
|
+
return nearestId;
|
|
6171
|
+
}
|
|
6172
|
+
grab(world, input, entityId) {
|
|
6173
|
+
const transform = world.getComponent(entityId, TransformComponent);
|
|
6174
|
+
if (!transform) return;
|
|
6175
|
+
const hand = this.handPosition(input);
|
|
6176
|
+
const offset = new THREE7.Vector3(
|
|
6177
|
+
transform.position.x - hand.x,
|
|
6178
|
+
transform.position.y - hand.y,
|
|
6179
|
+
transform.position.z - hand.z
|
|
6180
|
+
);
|
|
6181
|
+
const physics = world.getComponent(entityId, PhysicsComponent);
|
|
6182
|
+
let restoreBodyType = null;
|
|
6183
|
+
const interactable = world.getComponent(entityId, XRInteractableComponent);
|
|
6184
|
+
if (physics && interactable?.grabMode === "kinematic") {
|
|
6185
|
+
restoreBodyType = physics.values.rigidbody.type;
|
|
6186
|
+
physics.values.rigidbody.type = "kinematicPosition";
|
|
6187
|
+
}
|
|
6188
|
+
this.grabs.set(input, { entityId, offset, restoreBodyType });
|
|
6189
|
+
this.dispatch(world, entityId, (b) => b.onGrab(input));
|
|
6190
|
+
}
|
|
6191
|
+
moveHeld(world, input, held) {
|
|
6192
|
+
const transform = world.getComponent(held.entityId, TransformComponent);
|
|
6193
|
+
if (!transform) return;
|
|
6194
|
+
const hand = this.handPosition(input);
|
|
6195
|
+
transform.position.x = hand.x + held.offset.x;
|
|
6196
|
+
transform.position.y = hand.y + held.offset.y;
|
|
6197
|
+
transform.position.z = hand.z + held.offset.z;
|
|
6198
|
+
}
|
|
6199
|
+
release(world, input) {
|
|
6200
|
+
const held = this.grabs.get(input);
|
|
6201
|
+
if (!held) return;
|
|
6202
|
+
this.grabs.delete(input);
|
|
6203
|
+
if (held.restoreBodyType !== null) {
|
|
6204
|
+
const physics = world.getComponent(held.entityId, PhysicsComponent);
|
|
6205
|
+
if (physics) {
|
|
6206
|
+
physics.values.rigidbody.type = held.restoreBodyType;
|
|
6207
|
+
}
|
|
6208
|
+
}
|
|
6209
|
+
this.dispatch(world, held.entityId, (b) => b.onRelease(input));
|
|
6210
|
+
}
|
|
6211
|
+
releaseAll(world) {
|
|
6212
|
+
for (const input of Array.from(this.grabs.keys())) {
|
|
6213
|
+
this.release(world, input);
|
|
6214
|
+
}
|
|
6215
|
+
}
|
|
6216
|
+
/**
|
|
6217
|
+
* Where the "hand" is for this source. Controllers and tracked hands report a
|
|
6218
|
+
* grip pose; gaze and transient-pointer sources have none, so we hold the
|
|
6219
|
+
* object a fixed distance along the ray instead.
|
|
6220
|
+
*/
|
|
6221
|
+
handPosition(input) {
|
|
6222
|
+
if (input.gripPosition) return input.gripPosition;
|
|
6223
|
+
return new THREE7.Vector3().copy(input.rayDirection).multiplyScalar(RAYLESS_HOLD_DISTANCE).add(input.rayOrigin);
|
|
6224
|
+
}
|
|
6225
|
+
dispatch(world, entityId, visit) {
|
|
6226
|
+
const script = world.getComponent(entityId, ScriptComponent);
|
|
6227
|
+
const instances = script?.scriptInstances;
|
|
6228
|
+
if (!instances) return;
|
|
6229
|
+
for (const instance of instances.values()) {
|
|
6230
|
+
if (!(instance instanceof Behaviour)) continue;
|
|
6231
|
+
try {
|
|
6232
|
+
visit(instance);
|
|
6233
|
+
} catch (error) {
|
|
6234
|
+
console.error("[XRInteractionSystem] Behaviour hook failed:", error);
|
|
6235
|
+
}
|
|
6236
|
+
}
|
|
6237
|
+
}
|
|
6238
|
+
/** Entity currently under a pointer this frame, or null. */
|
|
6239
|
+
getHoveredEntityId() {
|
|
6240
|
+
return this.hoveredEntityId;
|
|
6241
|
+
}
|
|
6242
|
+
/** True when any source is holding something. */
|
|
6243
|
+
isGrabbing() {
|
|
6244
|
+
return this.grabs.size > 0;
|
|
6245
|
+
}
|
|
6246
|
+
};
|
|
6247
|
+
__name(_XRInteractionSystem, "XRInteractionSystem");
|
|
6248
|
+
var XRInteractionSystem = _XRInteractionSystem;
|
|
6249
|
+
var UP = new THREE7.Vector3(0, 1, 0);
|
|
6250
|
+
var AXIS_DEADZONE = 0.5;
|
|
6251
|
+
var _XRLocomotionSystem = class _XRLocomotionSystem {
|
|
6252
|
+
constructor(inputSystem) {
|
|
6253
|
+
this.raycaster = new THREE7.Raycaster();
|
|
6254
|
+
/** Per-source latch so one stick push yields exactly one snap turn. */
|
|
6255
|
+
this.turnLatched = /* @__PURE__ */ new WeakSet();
|
|
6256
|
+
/** Where the pointer currently lands, for the consumer to draw a marker. */
|
|
6257
|
+
this.teleportPoint = null;
|
|
6258
|
+
this.inputSystem = inputSystem;
|
|
6259
|
+
}
|
|
6260
|
+
update(world, deltaTime) {
|
|
6261
|
+
this.teleportPoint = null;
|
|
6262
|
+
if (!world.isXrPresenting()) return;
|
|
6263
|
+
const rigEntityId = world.query(XRRigComponent, TransformComponent)[0];
|
|
6264
|
+
if (typeof rigEntityId !== "number") return;
|
|
6265
|
+
const rig = world.getComponent(rigEntityId, XRRigComponent);
|
|
6266
|
+
const rigTransform = world.getComponent(rigEntityId, TransformComponent);
|
|
6267
|
+
if (!rig || !rigTransform) return;
|
|
6268
|
+
const inputs = this.inputSystem.getInputs();
|
|
6269
|
+
if (inputs.length === 0) return;
|
|
6270
|
+
if (rig.snapTurn) {
|
|
6271
|
+
this.applySnapTurn(rig, rigTransform, inputs);
|
|
6272
|
+
}
|
|
6273
|
+
if (rig.locomotion === "teleport") {
|
|
6274
|
+
this.applyTeleport(world, rigTransform, inputs);
|
|
6275
|
+
} else if (rig.locomotion === "smooth") {
|
|
6276
|
+
this.applySmoothMove(world, rig, rigTransform, inputs, deltaTime);
|
|
6277
|
+
}
|
|
6278
|
+
}
|
|
6279
|
+
/**
|
|
6280
|
+
* Snap turning, not smooth turning — rotating the view continuously is the
|
|
6281
|
+
* single biggest cause of VR nausea, so the comfort-safe option is the one
|
|
6282
|
+
* wired to the stick.
|
|
6283
|
+
*/
|
|
6284
|
+
applySnapTurn(rig, transform, inputs) {
|
|
6285
|
+
for (const input of inputs) {
|
|
6286
|
+
if (!input.hasAxes || input.axes.length < 3) continue;
|
|
6287
|
+
const x = input.axes[2] ?? 0;
|
|
6288
|
+
const source = input;
|
|
6289
|
+
if (Math.abs(x) < AXIS_DEADZONE) {
|
|
6290
|
+
this.turnLatched.delete(source);
|
|
6291
|
+
continue;
|
|
6292
|
+
}
|
|
6293
|
+
if (this.turnLatched.has(source)) continue;
|
|
6294
|
+
this.turnLatched.add(source);
|
|
6295
|
+
const step = THREE7.MathUtils.degToRad(rig.snapTurnDegrees);
|
|
6296
|
+
transform.rotation.y -= Math.sign(x) * step;
|
|
6297
|
+
}
|
|
6298
|
+
}
|
|
6299
|
+
applySmoothMove(world, rig, transform, inputs, deltaTime) {
|
|
6300
|
+
for (const input of inputs) {
|
|
6301
|
+
if (!input.hasAxes || input.axes.length < 2) continue;
|
|
6302
|
+
const x = input.axes[0] ?? 0;
|
|
6303
|
+
const y = input.axes[1] ?? 0;
|
|
6304
|
+
if (Math.abs(x) < 0.15 && Math.abs(y) < 0.15) continue;
|
|
6305
|
+
const camera = world.getCamera();
|
|
6306
|
+
const forward = new THREE7.Vector3();
|
|
6307
|
+
camera.getWorldDirection(forward);
|
|
6308
|
+
forward.y = 0;
|
|
6309
|
+
if (forward.lengthSq() < 1e-6) continue;
|
|
6310
|
+
forward.normalize();
|
|
6311
|
+
const right = new THREE7.Vector3().crossVectors(forward, UP).normalize();
|
|
6312
|
+
const step = rig.moveSpeed * Math.max(0, deltaTime);
|
|
6313
|
+
transform.position.x += (forward.x * -y + right.x * x) * step;
|
|
6314
|
+
transform.position.z += (forward.z * -y + right.z * x) * step;
|
|
6315
|
+
}
|
|
6316
|
+
}
|
|
6317
|
+
applyTeleport(world, transform, inputs) {
|
|
6318
|
+
const targets = this.collectTeleportTargets(world);
|
|
6319
|
+
if (targets.length === 0) return;
|
|
6320
|
+
for (const input of inputs) {
|
|
6321
|
+
this.raycaster.set(input.rayOrigin, input.rayDirection);
|
|
6322
|
+
const hit = this.raycaster.intersectObjects(targets, true)[0];
|
|
6323
|
+
if (!hit) continue;
|
|
6324
|
+
this.teleportPoint = hit.point.clone();
|
|
6325
|
+
if (input.selectEnd) {
|
|
6326
|
+
transform.position.x = hit.point.x;
|
|
6327
|
+
transform.position.y = hit.point.y;
|
|
6328
|
+
transform.position.z = hit.point.z;
|
|
6329
|
+
}
|
|
6330
|
+
}
|
|
6331
|
+
}
|
|
6332
|
+
collectTeleportTargets(world) {
|
|
6333
|
+
const objects = [];
|
|
6334
|
+
for (const entityId of world.query(VRTeleportAreaComponent, Object3DRef)) {
|
|
6335
|
+
const area = world.getComponent(entityId, VRTeleportAreaComponent);
|
|
6336
|
+
if (!area?.enabled) continue;
|
|
6337
|
+
if (!world.isEntityVisible(entityId)) continue;
|
|
6338
|
+
const object = world.getComponent(entityId, Object3DRef)?.object;
|
|
6339
|
+
if (object) objects.push(object);
|
|
6340
|
+
}
|
|
6341
|
+
return objects;
|
|
6342
|
+
}
|
|
6343
|
+
/**
|
|
6344
|
+
* Where the teleport pointer currently lands this frame, or null.
|
|
6345
|
+
* Consumers use this to render an aim marker.
|
|
6346
|
+
*/
|
|
6347
|
+
getTeleportPoint() {
|
|
6348
|
+
return this.teleportPoint;
|
|
6349
|
+
}
|
|
6350
|
+
};
|
|
6351
|
+
__name(_XRLocomotionSystem, "XRLocomotionSystem");
|
|
6352
|
+
var XRLocomotionSystem = _XRLocomotionSystem;
|
|
6353
|
+
|
|
6354
|
+
// core/xr/types.ts
|
|
6355
|
+
var NO_XR_CAPABILITIES = {
|
|
6356
|
+
mode: "inline",
|
|
6357
|
+
handTracking: false,
|
|
6358
|
+
planeDetection: false,
|
|
6359
|
+
meshDetection: false,
|
|
6360
|
+
depthSensing: false,
|
|
6361
|
+
anchors: false,
|
|
6362
|
+
hitTest: false,
|
|
6363
|
+
enabledFeatures: []
|
|
6364
|
+
};
|
|
6365
|
+
function readXrCapabilities(session, mode = "immersive-vr") {
|
|
6366
|
+
if (!session) return NO_XR_CAPABILITIES;
|
|
6367
|
+
const raw = session.enabledFeatures;
|
|
6368
|
+
const features = Array.isArray(raw) ? Array.from(raw) : [];
|
|
6369
|
+
const has = /* @__PURE__ */ __name((name) => features.includes(name), "has");
|
|
6370
|
+
return {
|
|
6371
|
+
mode,
|
|
6372
|
+
handTracking: has("hand-tracking"),
|
|
6373
|
+
planeDetection: has("plane-detection"),
|
|
6374
|
+
meshDetection: has("mesh-detection"),
|
|
6375
|
+
depthSensing: has("depth-sensing"),
|
|
6376
|
+
anchors: has("anchors"),
|
|
6377
|
+
hitTest: has("hit-test"),
|
|
6378
|
+
enabledFeatures: features
|
|
6379
|
+
};
|
|
6380
|
+
}
|
|
6381
|
+
__name(readXrCapabilities, "readXrCapabilities");
|
|
6382
|
+
|
|
6383
|
+
// core/systems/XRSessionSystem.ts
|
|
6384
|
+
var _XRSessionSystem = class _XRSessionSystem {
|
|
6385
|
+
constructor(inputSystem) {
|
|
6386
|
+
this.presenting = false;
|
|
6387
|
+
this.capabilities = NO_XR_CAPABILITIES;
|
|
6388
|
+
this.inputSystem = inputSystem ?? null;
|
|
6389
|
+
}
|
|
6390
|
+
update(world) {
|
|
6391
|
+
const presenting = world.isXrPresenting();
|
|
6392
|
+
if (presenting !== this.presenting) {
|
|
6393
|
+
this.presenting = presenting;
|
|
6394
|
+
if (presenting) {
|
|
6395
|
+
this.handleSessionStart(world);
|
|
6396
|
+
} else {
|
|
6397
|
+
this.handleSessionEnd(world);
|
|
6398
|
+
}
|
|
6399
|
+
}
|
|
6400
|
+
if (presenting) {
|
|
6401
|
+
this.dispatchInputEdges(world);
|
|
6402
|
+
}
|
|
6403
|
+
}
|
|
6404
|
+
handleSessionStart(world) {
|
|
6405
|
+
const session = world.getRenderer().xr.getSession();
|
|
6406
|
+
const mode = session && session.environmentBlendMode !== "opaque" ? "immersive-ar" : "immersive-vr";
|
|
6407
|
+
this.capabilities = readXrCapabilities(session ?? null, mode);
|
|
6408
|
+
if (session && this.inputSystem) {
|
|
6409
|
+
this.inputSystem.attachSession(session);
|
|
6410
|
+
}
|
|
6411
|
+
this.forEachBehaviour(world, (behaviour) => {
|
|
6412
|
+
behaviour.onXRSessionStart(this.capabilities);
|
|
6413
|
+
});
|
|
6414
|
+
}
|
|
6415
|
+
handleSessionEnd(world) {
|
|
6416
|
+
this.capabilities = NO_XR_CAPABILITIES;
|
|
6417
|
+
this.inputSystem?.detachSession();
|
|
6418
|
+
this.forEachBehaviour(world, (behaviour) => {
|
|
6419
|
+
behaviour.onXRSessionEnd();
|
|
6420
|
+
});
|
|
6421
|
+
}
|
|
6422
|
+
/**
|
|
6423
|
+
* Relay this frame's one-frame select edges. Polling the latched state (rather
|
|
6424
|
+
* than dispatching from the DOM event) keeps hook delivery on the ECS tick, so
|
|
6425
|
+
* a Behaviour's `onSelectStart` always observes the same world state its
|
|
6426
|
+
* `onUpdate` would.
|
|
6427
|
+
*/
|
|
6428
|
+
dispatchInputEdges(world) {
|
|
6429
|
+
const inputs = this.inputSystem?.getInputs();
|
|
6430
|
+
if (!inputs || inputs.length === 0) return;
|
|
6431
|
+
for (const input of inputs) {
|
|
6432
|
+
if (input.selectStart) {
|
|
6433
|
+
this.forEachBehaviour(world, (b) => b.onSelectStart(input));
|
|
6434
|
+
}
|
|
6435
|
+
if (input.selectEnd) {
|
|
6436
|
+
this.forEachBehaviour(world, (b) => b.onSelectEnd(input));
|
|
6437
|
+
}
|
|
6438
|
+
}
|
|
6439
|
+
}
|
|
6440
|
+
forEachBehaviour(world, visit) {
|
|
6441
|
+
for (const entityId of world.query(ScriptComponent)) {
|
|
6442
|
+
const script = world.getComponent(entityId, ScriptComponent);
|
|
6443
|
+
const instances = script?.scriptInstances;
|
|
6444
|
+
if (!instances) continue;
|
|
6445
|
+
for (const instance of instances.values()) {
|
|
6446
|
+
if (!(instance instanceof Behaviour)) continue;
|
|
6447
|
+
try {
|
|
6448
|
+
visit(instance);
|
|
6449
|
+
} catch (error) {
|
|
6450
|
+
console.error("[XRSessionSystem] Behaviour hook failed:", error);
|
|
6451
|
+
}
|
|
6452
|
+
}
|
|
6453
|
+
}
|
|
6454
|
+
}
|
|
6455
|
+
/** What the active session granted. `NO_XR_CAPABILITIES` when not presenting. */
|
|
6456
|
+
getCapabilities() {
|
|
6457
|
+
return this.capabilities;
|
|
6458
|
+
}
|
|
6459
|
+
/** True while an immersive session is presenting. */
|
|
6460
|
+
isPresenting() {
|
|
6461
|
+
return this.presenting;
|
|
6462
|
+
}
|
|
6463
|
+
/** Convenience passthrough so consumers need only hold this system. */
|
|
6464
|
+
getInputs() {
|
|
6465
|
+
return this.inputSystem?.getInputs() ?? [];
|
|
6466
|
+
}
|
|
6467
|
+
};
|
|
6468
|
+
__name(_XRSessionSystem, "XRSessionSystem");
|
|
6469
|
+
var XRSessionSystem = _XRSessionSystem;
|
|
6470
|
+
function buildGeometry2(area) {
|
|
6471
|
+
if (area.shape === "cylinder") {
|
|
6472
|
+
const radius = Math.max(5e-3, area.width / 2);
|
|
6473
|
+
return new THREE7.CircleGeometry(radius, 48);
|
|
6474
|
+
}
|
|
6475
|
+
return new THREE7.PlaneGeometry(
|
|
6476
|
+
Math.max(0.01, area.width),
|
|
6477
|
+
Math.max(0.01, area.depth)
|
|
6478
|
+
);
|
|
6479
|
+
}
|
|
6480
|
+
__name(buildGeometry2, "buildGeometry");
|
|
6481
|
+
function signatureOf(area) {
|
|
6482
|
+
return `${area.shape}:${area.width}:${area.depth}`;
|
|
6483
|
+
}
|
|
6484
|
+
__name(signatureOf, "signatureOf");
|
|
6485
|
+
var _VRTeleportAreaSystem = class _VRTeleportAreaSystem {
|
|
6486
|
+
constructor() {
|
|
6487
|
+
this.signatures = /* @__PURE__ */ new Map();
|
|
6488
|
+
}
|
|
6489
|
+
update(world) {
|
|
6490
|
+
const entityIds = world.query(VRTeleportAreaComponent, Object3DRef);
|
|
6491
|
+
const alive = new Set(entityIds);
|
|
6492
|
+
for (const tracked of this.signatures.keys()) {
|
|
6493
|
+
if (!alive.has(tracked)) this.signatures.delete(tracked);
|
|
6494
|
+
}
|
|
6495
|
+
for (const entityId of entityIds) {
|
|
6496
|
+
const area = world.getComponent(entityId, VRTeleportAreaComponent);
|
|
6497
|
+
const object = world.getComponent(entityId, Object3DRef)?.object;
|
|
6498
|
+
if (!area || !(object instanceof THREE7.Mesh)) continue;
|
|
6499
|
+
const signature = signatureOf(area);
|
|
6500
|
+
if (this.signatures.get(entityId) === signature) continue;
|
|
6501
|
+
this.signatures.set(entityId, signature);
|
|
6502
|
+
object.geometry?.dispose?.();
|
|
6503
|
+
object.geometry = buildGeometry2(area);
|
|
6504
|
+
}
|
|
6505
|
+
}
|
|
6506
|
+
};
|
|
6507
|
+
__name(_VRTeleportAreaSystem, "VRTeleportAreaSystem");
|
|
6508
|
+
var VRTeleportAreaSystem = _VRTeleportAreaSystem;
|
|
6509
|
+
var _XRControllerVisualSystem = class _XRControllerVisualSystem {
|
|
6510
|
+
constructor(slots = 2) {
|
|
6511
|
+
this.controllerModelFactory = new XRControllerModelFactory();
|
|
6512
|
+
this.handModelFactory = new XRHandModelFactory();
|
|
6513
|
+
this.group = new THREE7.Group();
|
|
6514
|
+
this.built = false;
|
|
6515
|
+
this.attachedTo = null;
|
|
6516
|
+
/** Index → whether we've already attached visuals for that slot. */
|
|
6517
|
+
this.ready = /* @__PURE__ */ new Set();
|
|
6518
|
+
this.slots = slots;
|
|
6519
|
+
this.group.name = "XRControllerVisuals";
|
|
6520
|
+
this.group.userData.ecsPreviewHidden = true;
|
|
6521
|
+
}
|
|
6522
|
+
update(world) {
|
|
6523
|
+
const renderer = world.getRenderer();
|
|
6524
|
+
if (!renderer.xr?.enabled) return;
|
|
6525
|
+
this.ensureAttached(world);
|
|
6526
|
+
if (this.built) return;
|
|
6527
|
+
for (let index = 0; index < this.slots; index += 1) {
|
|
6528
|
+
if (this.ready.has(index)) continue;
|
|
6529
|
+
const controller = renderer.xr.getController(index);
|
|
6530
|
+
const grip = renderer.xr.getControllerGrip(index);
|
|
6531
|
+
const hand = renderer.xr.getHand(index);
|
|
6532
|
+
if (!controller || !grip || !hand) continue;
|
|
6533
|
+
controller.add(this.createRay());
|
|
6534
|
+
this.group.add(controller);
|
|
6535
|
+
grip.add(this.controllerModelFactory.createControllerModel(grip));
|
|
6536
|
+
this.group.add(grip);
|
|
6537
|
+
hand.add(this.handModelFactory.createHandModel(hand, "mesh"));
|
|
6538
|
+
this.group.add(hand);
|
|
6539
|
+
this.ready.add(index);
|
|
6540
|
+
}
|
|
6541
|
+
if (this.ready.size >= this.slots) {
|
|
6542
|
+
this.built = true;
|
|
6543
|
+
}
|
|
6544
|
+
}
|
|
6545
|
+
/**
|
|
6546
|
+
* Parent the visuals to the XR rig when there is one, so locomotion moves the
|
|
6547
|
+
* hands with the player. Falls back to the scene root.
|
|
6548
|
+
*/
|
|
6549
|
+
ensureAttached(world) {
|
|
6550
|
+
const camera = world.getCamera();
|
|
6551
|
+
const target = camera.parent ?? world.getScene();
|
|
6552
|
+
if (this.attachedTo === target) return;
|
|
6553
|
+
target.add(this.group);
|
|
6554
|
+
this.attachedTo = target;
|
|
6555
|
+
}
|
|
6556
|
+
createRay() {
|
|
6557
|
+
const geometry = new THREE7.BufferGeometry().setFromPoints([
|
|
6558
|
+
new THREE7.Vector3(0, 0, 0),
|
|
6559
|
+
new THREE7.Vector3(0, 0, -5)
|
|
6560
|
+
]);
|
|
6561
|
+
const material = new THREE7.LineBasicMaterial({
|
|
6562
|
+
color: "#4da3ff",
|
|
6563
|
+
transparent: true,
|
|
6564
|
+
opacity: 0.6,
|
|
6565
|
+
depthTest: false
|
|
6566
|
+
});
|
|
6567
|
+
const line = new THREE7.Line(geometry, material);
|
|
6568
|
+
line.name = "XRPointerRay";
|
|
6569
|
+
line.renderOrder = 999;
|
|
6570
|
+
return line;
|
|
6571
|
+
}
|
|
6572
|
+
dispose() {
|
|
6573
|
+
this.group.removeFromParent();
|
|
6574
|
+
this.group.traverse((child) => {
|
|
6575
|
+
const mesh = child;
|
|
6576
|
+
mesh.geometry?.dispose?.();
|
|
6577
|
+
const material = mesh.material;
|
|
6578
|
+
if (Array.isArray(material)) {
|
|
6579
|
+
for (const entry of material) entry.dispose?.();
|
|
6580
|
+
} else {
|
|
6581
|
+
material?.dispose?.();
|
|
6582
|
+
}
|
|
6583
|
+
});
|
|
6584
|
+
this.group.clear();
|
|
6585
|
+
this.ready.clear();
|
|
6586
|
+
this.built = false;
|
|
6587
|
+
this.attachedTo = null;
|
|
6588
|
+
}
|
|
6589
|
+
};
|
|
6590
|
+
__name(_XRControllerVisualSystem, "XRControllerVisualSystem");
|
|
6591
|
+
var XRControllerVisualSystem = _XRControllerVisualSystem;
|
|
5841
6592
|
|
|
5842
|
-
export { ADDED_NODE_MARKER_COMPONENT, AnimationSystem, AudioSystem, Behaviour, CameraSyncSystem, EnvironmentSyncSystem, HYDRATABLE_ENTITY_KINDS, InputSystem, InstancedMeshSystem, KeyboardKeys, LightSyncSystem, MaterialSyncSystem, MeshGeometrySystem, NODE_KEY_SEPARATOR, 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, buildComponentValueMaps, buildNodeKeyMapsFromSnapshot, buildNodeMapsFromSnapshot, canonicalizeComponentValue, clearPrefabCache, collectDiffPaths, collectEntitySubtree, collectSnapshotSubtreeIds, computeInstanceOverrides, decanonicalizeComponentValue, despawnPrefab, encodeOverride, findSnapshotRootEntityIds, findTopLevelNestedRegions, groupOverridePaths, hydrateWorldFromSnapshot, hydrateWorldFromSnapshotDetailed, indexSnapshotByEntity, instantiateSubtree, loadPrefab, mergeComponentValue, parseOverride, parsePrefabAsset, prefabFileVersionFor, restoreComponentState, restorePostCreateComponents, setPrefabAssetUrlResolver, spawnPrefab };
|
|
5843
|
-
//# sourceMappingURL=chunk-
|
|
5844
|
-
//# sourceMappingURL=chunk-
|
|
6593
|
+
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 };
|
|
6594
|
+
//# sourceMappingURL=chunk-SALBG747.js.map
|
|
6595
|
+
//# sourceMappingURL=chunk-SALBG747.js.map
|