@needle-tools/engine 2.28.0-pre → 2.29.0-pre
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 +10 -0
- package/dist/needle-engine.d.ts +188 -131
- package/dist/needle-engine.js +345 -345
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +19 -19
- package/dist/needle-engine.min.js.map +4 -4
- package/lib/engine/engine_input.d.ts +13 -1
- package/lib/engine/engine_input.js +47 -16
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_physics.d.ts +1 -0
- package/lib/engine/engine_physics.js +2 -1
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_playerview.d.ts +26 -0
- package/lib/engine/engine_playerview.js +65 -0
- package/lib/engine/engine_playerview.js.map +1 -0
- package/lib/engine/engine_serialization_core.js +5 -0
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_setup.d.ts +3 -0
- package/lib/engine/engine_setup.js +17 -0
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_lighting_settings.js +6 -2
- package/lib/engine/extensions/NEEDLE_lighting_settings.js.map +1 -1
- package/lib/engine-components/Component.d.ts +1 -1
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/Light.js +1 -0
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +1 -2
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/ParticleSystem.d.ts +0 -1
- package/lib/engine-components/ParticleSystem.js +24 -27
- package/lib/engine-components/ParticleSystem.js.map +1 -1
- package/lib/engine-components/PlayerColor.js +1 -2
- package/lib/engine-components/PlayerColor.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.d.ts +24 -17
- package/lib/engine-components/SpectatorCamera.js +410 -181
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SyncedCamera.d.ts +8 -4
- package/lib/engine-components/SyncedCamera.js +15 -18
- package/lib/engine-components/SyncedCamera.js.map +1 -1
- package/lib/engine-components/WebXR.js +1 -0
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRAvatar.d.ts +3 -0
- package/lib/engine-components/WebXRAvatar.js +16 -0
- package/lib/engine-components/WebXRAvatar.js.map +1 -1
- package/lib/engine-components/WebXRController.js +1 -1
- package/lib/engine-components/WebXRController.js.map +1 -1
- package/lib/engine-components/WebXRSync.js +3 -3
- package/lib/engine-components/WebXRSync.js.map +1 -1
- package/lib/engine-components/XRFlag.d.ts +2 -1
- package/lib/engine-components/XRFlag.js +1 -0
- package/lib/engine-components/XRFlag.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_components.js +16 -0
- package/src/engine/engine_input.ts +62 -20
- package/src/engine/engine_physics.ts +2 -1
- package/src/engine/engine_playerview.ts +80 -0
- package/src/engine/engine_serialization_core.ts +8 -0
- package/src/engine/engine_setup.ts +18 -0
- package/src/engine/extensions/NEEDLE_lighting_settings.ts +4 -2
- package/src/engine-components/Component.ts +1 -1
- package/src/engine-components/Light.ts +3 -0
- package/src/engine-components/OrbitControls.ts +1 -2
- package/src/engine-components/ParticleSystem.ts +25 -26
- package/src/engine-components/PlayerColor.ts +1 -1
- package/src/engine-components/SpectatorCamera.ts +466 -194
- package/src/engine-components/SyncedCamera.ts +23 -22
- package/src/engine-components/WebXR.ts +1 -0
- package/src/engine-components/WebXRAvatar.ts +22 -2
- package/src/engine-components/WebXRController.ts +1 -1
- package/src/engine-components/WebXRSync.ts +3 -3
- package/src/engine-components/XRFlag.ts +1 -0
|
@@ -12,6 +12,7 @@ import { serializeable } from "../engine/engine_serialization_decorator";
|
|
|
12
12
|
import { Object3D } from "three";
|
|
13
13
|
import { AvatarMarker } from "./WebXRAvatar";
|
|
14
14
|
import { AssetReference } from "../engine/engine_addressables";
|
|
15
|
+
import { ViewDevice } from "../engine/engine_playerview";
|
|
15
16
|
|
|
16
17
|
const SyncedCameraModelIdentifier = "SCAM";
|
|
17
18
|
registerType(SyncedCameraModelIdentifier, SyncedCameraModel.getRootAsSyncedCameraModel);
|
|
@@ -33,8 +34,7 @@ class CameraModel {
|
|
|
33
34
|
this.userId = connectionId;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
send(
|
|
37
|
-
const cam = sync.cam?.cam;
|
|
37
|
+
send(cam: THREE.Camera | null | undefined, con: NetworkConnection) {
|
|
38
38
|
if (cam) {
|
|
39
39
|
builder.clear();
|
|
40
40
|
const guid = builder.createString(this.guid);
|
|
@@ -53,23 +53,22 @@ class CameraModel {
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
declare type UserCamInfo =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
56
|
+
declare type UserCamInfo = {
|
|
57
|
+
obj: THREE.Object3D,
|
|
58
|
+
lastUpdate: number;
|
|
59
|
+
userId: string;
|
|
60
|
+
};
|
|
62
61
|
|
|
63
62
|
export class SyncedCamera extends Behaviour {
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
static instances: UserCamInfo[] = [];
|
|
65
|
+
|
|
66
|
+
getCameraObject(userId: string): THREE.Object3D | null {
|
|
66
67
|
const guid = this.userToCamMap[userId];
|
|
67
68
|
if (!guid) return null;
|
|
68
69
|
return this.remoteCams[guid].obj;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
@serializeable(Camera)
|
|
72
|
-
public cam: Camera | null = null;
|
|
73
72
|
@serializeable([Object3D, AssetReference])
|
|
74
73
|
public cameraPrefab: THREE.Object3D | null | AssetReference = null;
|
|
75
74
|
|
|
@@ -97,15 +96,8 @@ export class SyncedCamera extends Behaviour {
|
|
|
97
96
|
if (this.cameraPrefab && "isObject3D" in this.cameraPrefab) {
|
|
98
97
|
this.cameraPrefab.visible = false;
|
|
99
98
|
}
|
|
100
|
-
|
|
101
99
|
}
|
|
102
|
-
}
|
|
103
100
|
|
|
104
|
-
start() {
|
|
105
|
-
if (!this.cam) {
|
|
106
|
-
console.warn("Missing camera, fallback to main camera", this);
|
|
107
|
-
this.cam = this.context.mainCameraComponent as Camera ?? null;
|
|
108
|
-
}
|
|
109
101
|
}
|
|
110
102
|
|
|
111
103
|
onEnable(): void {
|
|
@@ -129,13 +121,17 @@ export class SyncedCamera extends Behaviour {
|
|
|
129
121
|
delete this.remoteCams[guid];
|
|
130
122
|
if (cam)
|
|
131
123
|
delete this.userToCamMap[cam.userId];
|
|
124
|
+
|
|
125
|
+
SyncedCamera.instances.push(cam);
|
|
126
|
+
this.context.players.removePlayerView(cam.userId, ViewDevice.Browser);
|
|
132
127
|
continue;
|
|
133
128
|
}
|
|
134
129
|
}
|
|
135
130
|
|
|
136
131
|
if (WebXR.IsInWebXR) return;
|
|
137
132
|
|
|
138
|
-
|
|
133
|
+
const cam = this.context.mainCamera
|
|
134
|
+
if (cam === null) {
|
|
139
135
|
this.enabled = false;
|
|
140
136
|
return;
|
|
141
137
|
}
|
|
@@ -146,8 +142,8 @@ export class SyncedCamera extends Behaviour {
|
|
|
146
142
|
this._model = new CameraModel(this.context.connection.connectionId, this.context.connection.connectionId + "_camera");
|
|
147
143
|
}
|
|
148
144
|
|
|
149
|
-
const wp = utils.getWorldPosition(
|
|
150
|
-
const wq = utils.getWorldQuaternion(
|
|
145
|
+
const wp = utils.getWorldPosition(cam);
|
|
146
|
+
const wq = utils.getWorldQuaternion(cam);
|
|
151
147
|
if (wp.distanceTo(this._lastWorldPosition) > 0.001 || wq.angleTo(this._lastWorldQuaternion) > 0.01) {
|
|
152
148
|
this._needsUpdate = true;
|
|
153
149
|
}
|
|
@@ -163,7 +159,9 @@ export class SyncedCamera extends Behaviour {
|
|
|
163
159
|
|
|
164
160
|
this._lastUpdateTime = this.context.time.realtimeSinceStartup;
|
|
165
161
|
this._needsUpdate = false;
|
|
166
|
-
this._model.send(
|
|
162
|
+
this._model.send(cam, this.context.connection);
|
|
163
|
+
if (!this.context.isInXR)
|
|
164
|
+
this.context.players.setPlayerView(this.context.connection.connectionId, cam, ViewDevice.Browser);
|
|
167
165
|
}
|
|
168
166
|
|
|
169
167
|
private onReceivedRemoteCameraInfoBin(model: SyncedCameraModel) {
|
|
@@ -183,10 +181,12 @@ export class SyncedCamera extends Behaviour {
|
|
|
183
181
|
rc.obj.visible = true;
|
|
184
182
|
this.gameObject.add(instance);
|
|
185
183
|
this.userToCamMap[userId] = guid;
|
|
184
|
+
SyncedCamera.instances.push(rc);
|
|
186
185
|
|
|
187
186
|
const marker = GameObject.getOrAddComponent(instance, AvatarMarker);
|
|
188
187
|
marker.connectionId = userId;
|
|
189
188
|
marker.avatar = instance;
|
|
189
|
+
|
|
190
190
|
}
|
|
191
191
|
else {
|
|
192
192
|
return;
|
|
@@ -194,6 +194,7 @@ export class SyncedCamera extends Behaviour {
|
|
|
194
194
|
// console.log(this.remoteCams);
|
|
195
195
|
}
|
|
196
196
|
const obj = rc.obj;
|
|
197
|
+
this.context.players.setPlayerView(userId, obj, ViewDevice.Browser);
|
|
197
198
|
rc.lastUpdate = this.context.time.realtimeSinceStartup;
|
|
198
199
|
InstancingUtil.markDirty(obj);
|
|
199
200
|
const pos = model.pos();
|
|
@@ -10,6 +10,7 @@ import { Object3D } from "three";
|
|
|
10
10
|
import { VRUserState } from "./WebXRSync";
|
|
11
11
|
import { getParam } from "../engine/engine_utils";
|
|
12
12
|
import { serializeable } from "../engine/engine_serialization_decorator";
|
|
13
|
+
import { ViewDevice } from "../engine/engine_playerview";
|
|
13
14
|
|
|
14
15
|
export const debug = getParam("debugavatar");
|
|
15
16
|
|
|
@@ -18,8 +19,14 @@ export type AvatarMarkerEventArgs = {
|
|
|
18
19
|
gameObject: Object3D;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
22
|
export class AvatarMarker extends Behaviour {
|
|
23
|
+
|
|
24
|
+
public static getAvatar(index: number): AvatarMarker | null {
|
|
25
|
+
if (index >= 0 && index < AvatarMarker.instances.length)
|
|
26
|
+
return AvatarMarker.instances[index];
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
public static instances: AvatarMarker[] = [];
|
|
24
31
|
|
|
25
32
|
public static onAvatarMarkerCreated(cb: (args: AvatarMarkerEventArgs) => void): Function {
|
|
@@ -55,7 +62,7 @@ export class AvatarMarker extends Behaviour {
|
|
|
55
62
|
cb({ avatarMarker: this, gameObject: this.gameObject });
|
|
56
63
|
}
|
|
57
64
|
|
|
58
|
-
isLocalAvatar(){
|
|
65
|
+
isLocalAvatar() {
|
|
59
66
|
return this.connectionId === this.context.connection.connectionId;
|
|
60
67
|
}
|
|
61
68
|
|
|
@@ -80,7 +87,10 @@ export class WebXRAvatar {
|
|
|
80
87
|
this.updateVisibility();
|
|
81
88
|
}
|
|
82
89
|
|
|
90
|
+
get isWebXRAvatar() { return true; }
|
|
91
|
+
|
|
83
92
|
// TODO: set layers on all avatars
|
|
93
|
+
/** the user id */
|
|
84
94
|
public guid: string;
|
|
85
95
|
|
|
86
96
|
private root: THREE.Object3D | null = null;
|
|
@@ -148,6 +158,16 @@ export class WebXRAvatar {
|
|
|
148
158
|
|
|
149
159
|
this.lastUpdate = state.time;
|
|
150
160
|
if (this.head) {
|
|
161
|
+
|
|
162
|
+
const device = this.webxr.IsInAR ? ViewDevice.Handheld : ViewDevice.Headset;
|
|
163
|
+
let viewObj = this.head;
|
|
164
|
+
// if (this.isLocalAvatar) {
|
|
165
|
+
// if (this.context.mainCamera && this.context.isInXR) {
|
|
166
|
+
// viewObj = this.context.renderer.xr.getCamera(this.context.mainCamera);
|
|
167
|
+
// }
|
|
168
|
+
// }
|
|
169
|
+
this.context.players.setPlayerView(state.guid, viewObj, device);
|
|
170
|
+
|
|
151
171
|
this._canInterpolate = true;
|
|
152
172
|
const ht = this.isLocalAvatar ? this.head : this._headTarget;
|
|
153
173
|
ht.position.set(state.position.x, state.position.y, state.position.z);
|
|
@@ -566,7 +566,7 @@ export class WebXRController extends Behaviour {
|
|
|
566
566
|
const scale = Mathf.clamp(this.lastHit.distance * .01 * factor, .015, .1);
|
|
567
567
|
this._raycastHitPoint.scale.set(scale, scale, scale);
|
|
568
568
|
}
|
|
569
|
-
this._raycastHitPoint.visible = this.lastHit !== null;
|
|
569
|
+
this._raycastHitPoint.visible = this.lastHit !== null && this.lastHit !== undefined;
|
|
570
570
|
}
|
|
571
571
|
return hit;
|
|
572
572
|
}
|
|
@@ -346,8 +346,8 @@ export class WebXRSync extends Behaviour {
|
|
|
346
346
|
|
|
347
347
|
private buildLocalAvatar() {
|
|
348
348
|
if (this.localAvatar) return;
|
|
349
|
-
const
|
|
350
|
-
this.localAvatar = new WebXRAvatar(this.context,
|
|
349
|
+
const connectionId = this.context.connection?.connectionId ?? this.k_LocalAvatarNoNetworkingGuid;
|
|
350
|
+
this.localAvatar = new WebXRAvatar(this.context, connectionId, this.webXR!);
|
|
351
351
|
this.localAvatar.isLocalAvatar = true;
|
|
352
352
|
this.localAvatar.setAvatarOverride(this.getAvatarId());
|
|
353
353
|
this.avatars[this.localAvatar.guid] = this.localAvatar;
|
|
@@ -452,7 +452,7 @@ export class WebXRSync extends Behaviour {
|
|
|
452
452
|
|
|
453
453
|
private getAvatarId() {
|
|
454
454
|
const urlAvatar = utils.getParam("avatar") as string;
|
|
455
|
-
const avatarId = urlAvatar;
|
|
455
|
+
const avatarId = urlAvatar ?? null;
|
|
456
456
|
return avatarId;
|
|
457
457
|
}
|
|
458
458
|
}
|