@needle-tools/engine 4.1.0-beta.1 → 4.1.0-beta.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/CHANGELOG.md +7 -0
- package/dist/needle-engine.bundle.js +1251 -1230
- package/dist/needle-engine.bundle.light.js +1096 -1075
- package/dist/needle-engine.bundle.light.min.js +81 -82
- package/dist/needle-engine.bundle.light.umd.cjs +93 -94
- package/dist/needle-engine.bundle.min.js +81 -82
- package/dist/needle-engine.bundle.umd.cjs +93 -94
- package/lib/engine/xr/NeedleXRSession.js +3 -0
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- package/lib/engine-components/GroundProjection.d.ts +1 -1
- package/lib/engine-components/GroundProjection.js +39 -32
- package/lib/engine-components/GroundProjection.js.map +1 -1
- package/lib/engine-components/SpatialTrigger.d.ts +2 -2
- package/lib/engine-components/SpatialTrigger.js +4 -4
- package/lib/engine-components/SpatialTrigger.js.map +1 -1
- package/lib/engine-components/TransformGizmo.d.ts +7 -1
- package/lib/engine-components/TransformGizmo.js +39 -32
- package/lib/engine-components/TransformGizmo.js.map +1 -1
- package/lib/engine-components/VideoPlayer.js +0 -1
- package/lib/engine-components/VideoPlayer.js.map +1 -1
- package/lib/engine-components/webxr/WebXRRig.d.ts +11 -1
- package/lib/engine-components/webxr/WebXRRig.js +13 -1
- package/lib/engine-components/webxr/WebXRRig.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/xr/NeedleXRSession.ts +3 -0
- package/src/engine-components/GroundProjection.ts +46 -38
- package/src/engine-components/SpatialTrigger.ts +6 -6
- package/src/engine-components/TransformGizmo.ts +41 -33
- package/src/engine-components/VideoPlayer.ts +0 -1
- package/src/engine-components/webxr/WebXRRig.ts +15 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MathUtils,Mesh, MeshBasicMaterial, Object3D } from "three";
|
|
1
|
+
import { MathUtils, Mesh, MeshBasicMaterial, Object3D } from "three";
|
|
2
2
|
import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
|
|
3
3
|
|
|
4
4
|
import * as params from "../engine/engine_default_parameters.js";
|
|
@@ -26,7 +26,15 @@ export class TransformGizmo extends Behaviour {
|
|
|
26
26
|
@serializable()
|
|
27
27
|
public scaleSnap: number = .25;
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Get the underlying three.js TransformControls instance.
|
|
31
|
+
* @returns The TransformControls instance.
|
|
32
|
+
*/
|
|
33
|
+
get control() {
|
|
34
|
+
return this._control;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private _control?: TransformControls;
|
|
30
38
|
private orbit?: OrbitControls;
|
|
31
39
|
|
|
32
40
|
/** @internal */
|
|
@@ -35,12 +43,12 @@ export class TransformGizmo extends Behaviour {
|
|
|
35
43
|
|
|
36
44
|
if (!this.context.mainCamera) return;
|
|
37
45
|
|
|
38
|
-
if (!this.
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
43
|
-
const obj = ("_root" in this.
|
|
46
|
+
if (!this._control) {
|
|
47
|
+
this._control = new TransformControls(this.context.mainCamera, this.context.renderer.domElement);
|
|
48
|
+
this._control.enabled = true;
|
|
49
|
+
this._control.getRaycaster().layers.set(2);
|
|
50
|
+
this._control.size = 1;
|
|
51
|
+
const obj = ("_root" in this._control ? this._control._root : this._control) as Object3D;
|
|
44
52
|
obj.traverse(x => {
|
|
45
53
|
const mesh = x as Mesh;
|
|
46
54
|
mesh.layers.set(2);
|
|
@@ -54,12 +62,12 @@ export class TransformGizmo extends Behaviour {
|
|
|
54
62
|
this.orbit = GameObject.getComponentInParent(this.context.mainCamera, OrbitControls) ?? undefined;
|
|
55
63
|
}
|
|
56
64
|
|
|
57
|
-
if (this.
|
|
58
|
-
const obj = this.
|
|
65
|
+
if (this._control) {
|
|
66
|
+
const obj = this._control.getHelper();
|
|
59
67
|
this.context.scene.add(obj);
|
|
60
|
-
this.
|
|
68
|
+
this._control.attach(this.gameObject);
|
|
61
69
|
|
|
62
|
-
this.
|
|
70
|
+
this._control?.addEventListener('dragging-changed', this.onControlChangedEvent);
|
|
63
71
|
window.addEventListener('keydown', this.windowKeyDownListener);
|
|
64
72
|
window.addEventListener('keyup', this.windowKeyUpListener);
|
|
65
73
|
}
|
|
@@ -67,25 +75,25 @@ export class TransformGizmo extends Behaviour {
|
|
|
67
75
|
|
|
68
76
|
/** @internal */
|
|
69
77
|
onDisable() {
|
|
70
|
-
this.
|
|
71
|
-
this.
|
|
78
|
+
this._control?.getHelper()?.removeFromParent();
|
|
79
|
+
this._control?.removeEventListener('dragging-changed', this.onControlChangedEvent);
|
|
72
80
|
window.removeEventListener('keydown', this.windowKeyDownListener);
|
|
73
81
|
window.removeEventListener('keyup', this.windowKeyUpListener);
|
|
74
82
|
}
|
|
75
83
|
|
|
76
84
|
enableSnapping() {
|
|
77
|
-
if (this.
|
|
78
|
-
this.
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
85
|
+
if (this._control) {
|
|
86
|
+
this._control.setTranslationSnap(this.translationSnap);
|
|
87
|
+
this._control.setRotationSnap(MathUtils.degToRad(this.rotationSnapAngle));
|
|
88
|
+
this._control.setScaleSnap(this.scaleSnap);
|
|
81
89
|
}
|
|
82
90
|
}
|
|
83
91
|
|
|
84
92
|
disableSnapping() {
|
|
85
|
-
if (this.
|
|
86
|
-
this.
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
93
|
+
if (this._control) {
|
|
94
|
+
this._control.setTranslationSnap(null);
|
|
95
|
+
this._control.setRotationSnap(null);
|
|
96
|
+
this._control.setScaleSnap(null);
|
|
89
97
|
}
|
|
90
98
|
}
|
|
91
99
|
|
|
@@ -104,11 +112,11 @@ export class TransformGizmo extends Behaviour {
|
|
|
104
112
|
|
|
105
113
|
private windowKeyDownListener = (event) => {
|
|
106
114
|
if (!this.enabled) return;
|
|
107
|
-
if (!this.
|
|
115
|
+
if (!this._control) return;
|
|
108
116
|
switch (event.keyCode) {
|
|
109
117
|
|
|
110
118
|
case 81: // Q
|
|
111
|
-
this.
|
|
119
|
+
this._control.setSpace(this._control.space === 'local' ? 'world' : 'local');
|
|
112
120
|
break;
|
|
113
121
|
|
|
114
122
|
case 16: // Shift
|
|
@@ -116,40 +124,40 @@ export class TransformGizmo extends Behaviour {
|
|
|
116
124
|
break;
|
|
117
125
|
|
|
118
126
|
case 87: // W
|
|
119
|
-
this.
|
|
127
|
+
this._control.setMode('translate');
|
|
120
128
|
break;
|
|
121
129
|
|
|
122
130
|
case 69: // E
|
|
123
|
-
this.
|
|
131
|
+
this._control.setMode('rotate');
|
|
124
132
|
break;
|
|
125
133
|
|
|
126
134
|
case 82: // R
|
|
127
|
-
this.
|
|
135
|
+
this._control.setMode('scale');
|
|
128
136
|
break;
|
|
129
137
|
case 187:
|
|
130
138
|
case 107: // +, =, num+
|
|
131
|
-
this.
|
|
139
|
+
this._control.setSize(this._control.size + 0.1);
|
|
132
140
|
break;
|
|
133
141
|
|
|
134
142
|
case 189:
|
|
135
143
|
case 109: // -, _, num-
|
|
136
|
-
this.
|
|
144
|
+
this._control.setSize(Math.max(this._control.size - 0.1, 0.1));
|
|
137
145
|
break;
|
|
138
146
|
|
|
139
147
|
case 88: // X
|
|
140
|
-
this.
|
|
148
|
+
this._control.showX = !this._control.showX;
|
|
141
149
|
break;
|
|
142
150
|
|
|
143
151
|
case 89: // Y
|
|
144
|
-
this.
|
|
152
|
+
this._control.showY = !this._control.showY;
|
|
145
153
|
break;
|
|
146
154
|
|
|
147
155
|
case 90: // Z
|
|
148
|
-
this.
|
|
156
|
+
this._control.showZ = !this._control.showZ;
|
|
149
157
|
break;
|
|
150
158
|
|
|
151
159
|
case 32: // Spacebar
|
|
152
|
-
this.
|
|
160
|
+
this._control.enabled = !this._control.enabled;
|
|
153
161
|
break;
|
|
154
162
|
}
|
|
155
163
|
}
|
|
@@ -23,11 +23,21 @@ export class XRRig extends Behaviour implements IXRRig {
|
|
|
23
23
|
|
|
24
24
|
get isActive() { return this.activeAndEnabled && this.gameObject.visible; }
|
|
25
25
|
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Sets this rig to be the active XR rig (needs to be called during an active XR session)
|
|
28
|
+
* Note that this might modify the priority of this rig to be the highest.
|
|
29
|
+
*/
|
|
27
30
|
setAsActiveXRRig() {
|
|
28
31
|
NeedleXRSession.active?.setRigActive(this);
|
|
29
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Sets the priority of the rig.
|
|
35
|
+
*/
|
|
36
|
+
setPriority(value: number) {
|
|
37
|
+
this.priority = value;
|
|
38
|
+
}
|
|
30
39
|
|
|
40
|
+
/** @internal */
|
|
31
41
|
awake(): void {
|
|
32
42
|
if (debug) {
|
|
33
43
|
const gizmoObj = new Object3D() as IGameObject;
|
|
@@ -51,15 +61,18 @@ export class XRRig extends Behaviour implements IXRRig {
|
|
|
51
61
|
|
|
52
62
|
private _startScale?: Vector3;
|
|
53
63
|
|
|
64
|
+
/** @internal */
|
|
54
65
|
onEnterXR(args: NeedleXREventArgs): void {
|
|
55
66
|
this._startScale = this.gameObject.scale.clone();
|
|
56
67
|
args.xr.addRig(this);
|
|
57
|
-
if(debug) console.log("WebXR: add Rig", this.name, this.priority);
|
|
68
|
+
if (debug) console.log("WebXR: add Rig", this.name, this.priority);
|
|
58
69
|
}
|
|
70
|
+
/** @internal */
|
|
59
71
|
onLeaveXR(args: NeedleXREventArgs): void {
|
|
60
72
|
args.xr.removeRig(this);
|
|
61
73
|
if (this._startScale && this.gameObject)
|
|
62
74
|
this.gameObject.scale.copy(this._startScale);
|
|
63
75
|
}
|
|
64
76
|
|
|
77
|
+
|
|
65
78
|
}
|