@needle-tools/engine 2.35.2-pre → 2.35.4-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 +11 -0
- package/dist/needle-engine.d.ts +324 -295
- package/dist/needle-engine.js +3339 -230
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +34 -34
- package/dist/needle-engine.min.js.map +4 -4
- package/lib/engine/engine.d.ts +1 -0
- package/lib/engine/engine_components.js +5 -0
- package/lib/engine/engine_components.js.map +1 -1
- package/lib/engine/engine_element.d.ts +2 -1
- package/lib/engine/engine_element.js +4 -1
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_loading.js +19 -8
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_gltf.d.ts +2 -2
- package/lib/engine/engine_gltf.js +5 -1
- package/lib/engine/engine_gltf.js.map +1 -1
- package/lib/engine/engine_networking.js +4 -0
- package/lib/engine/engine_networking.js.map +1 -1
- package/lib/engine/engine_networking_utils.d.ts +1 -0
- package/lib/engine/engine_networking_utils.js +3 -0
- package/lib/engine/engine_networking_utils.js.map +1 -1
- package/lib/engine/engine_scenetools.d.ts +9 -0
- package/lib/engine/engine_scenetools.js +2 -2
- package/lib/engine/engine_scenetools.js.map +1 -1
- package/lib/engine/engine_types.d.ts +5 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_deferred_texture.js +33 -1
- package/lib/engine/extensions/NEEDLE_deferred_texture.js.map +1 -1
- package/lib/engine-components/Component.js +7 -1
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/DragControls.d.ts +1 -0
- package/lib/engine-components/DragControls.js +11 -6
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/Renderer.d.ts +5 -1
- package/lib/engine-components/Renderer.js +11 -3
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/ScreenCapture.d.ts +7 -1
- package/lib/engine-components/ScreenCapture.js +12 -5
- package/lib/engine-components/ScreenCapture.js.map +1 -1
- package/lib/engine-components/WebXR.d.ts +1 -1
- package/lib/engine-components/WebXR.js +12 -8
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/js-extensions/ExtensionUtils.d.ts +3 -1
- package/lib/engine-components/js-extensions/ExtensionUtils.js +18 -8
- package/lib/engine-components/js-extensions/ExtensionUtils.js.map +1 -1
- package/lib/engine-components/js-extensions/Object3D.js +18 -15
- package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
- package/lib/engine-components/js-extensions/Vector.js +3 -3
- package/lib/engine-components/js-extensions/Vector.js.map +1 -1
- package/package.json +10 -1
- package/src/engine/engine_components.ts +5 -0
- package/src/engine/engine_element.ts +7 -2
- package/src/engine/engine_element_loading.ts +20 -9
- package/src/engine/engine_gltf.ts +8 -4
- package/src/engine/engine_networking.ts +7 -3
- package/src/engine/engine_networking_utils.ts +4 -0
- package/src/engine/engine_scenetools.ts +2 -2
- package/src/engine/engine_types.ts +10 -6
- package/src/engine/extensions/NEEDLE_deferred_texture.ts +36 -3
- package/src/engine-components/Component.ts +9 -1
- package/src/engine-components/DragControls.ts +10 -8
- package/src/engine-components/Renderer.ts +13 -3
- package/src/engine-components/ScreenCapture.ts +20 -5
- package/src/engine-components/WebXR.ts +17 -11
- package/src/engine-components/js-extensions/ExtensionUtils.ts +27 -12
- package/src/engine-components/js-extensions/Object3D.ts +23 -16
- package/src/engine-components/js-extensions/Vector.ts +6 -4
|
@@ -7,7 +7,7 @@ import { getParam, getPath } from "../engine_utils";
|
|
|
7
7
|
|
|
8
8
|
export const EXTENSION_NAME = "NEEDLE_deferred_texture";
|
|
9
9
|
|
|
10
|
-
const debug = getParam("
|
|
10
|
+
const debug = getParam("debugprogressive");
|
|
11
11
|
|
|
12
12
|
declare type DeferredTextureModel = {
|
|
13
13
|
uri: string;
|
|
@@ -15,9 +15,30 @@ declare type DeferredTextureModel = {
|
|
|
15
15
|
usage?: string,
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const debug_toggle_maps: Map<Material, { [key: string]: { original: Texture, lod0: Texture } }> = new Map();
|
|
19
|
+
let show_lod0 = false;
|
|
20
|
+
if (debug) {
|
|
21
|
+
window.addEventListener("keyup", evt => {
|
|
22
|
+
if (evt.key === "p") {
|
|
23
|
+
debug_toggle_maps.forEach((map, material) => {
|
|
24
|
+
Object.entries(map).forEach(([key, value]) => {
|
|
25
|
+
if (show_lod0) {
|
|
26
|
+
material[key] = value.lod0;
|
|
27
|
+
} else {
|
|
28
|
+
material[key] = value.original;
|
|
29
|
+
}
|
|
30
|
+
material.needsUpdate = true;
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
show_lod0 = !show_lod0;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
18
38
|
export class NEEDLE_deferred_texture implements GLTFLoaderPlugin {
|
|
19
39
|
|
|
20
|
-
|
|
40
|
+
|
|
41
|
+
static assignTextureLOD(context: Context, source: SourceIdentifier | undefined, material: Material, level: number = 0) {
|
|
21
42
|
if (!material) return;
|
|
22
43
|
for (const slot of Object.keys(material)) {
|
|
23
44
|
const val = material[slot];
|
|
@@ -32,6 +53,18 @@ export class NEEDLE_deferred_texture implements GLTFLoaderPlugin {
|
|
|
32
53
|
material[slot] = t;
|
|
33
54
|
material.needsUpdate = true;
|
|
34
55
|
|
|
56
|
+
if (debug) {
|
|
57
|
+
let debug_map = debug_toggle_maps.get(material);
|
|
58
|
+
if (!debug_map) {
|
|
59
|
+
debug_map = {};
|
|
60
|
+
debug_toggle_maps.set(material, debug_map);
|
|
61
|
+
}
|
|
62
|
+
let entry = debug_map[slot];
|
|
63
|
+
if (!entry) {
|
|
64
|
+
entry = debug_map[slot] = { original: val, lod0: t };
|
|
65
|
+
}
|
|
66
|
+
entry.lod0 = t;
|
|
67
|
+
}
|
|
35
68
|
}
|
|
36
69
|
});
|
|
37
70
|
}
|
|
@@ -93,7 +126,7 @@ export class NEEDLE_deferred_texture implements GLTFLoaderPlugin {
|
|
|
93
126
|
private static cache = new Map<string, DeferredTextureModel>();
|
|
94
127
|
private static resolved: { [key: string]: Texture } = {};
|
|
95
128
|
|
|
96
|
-
private static async getOrLoadTexture(context: Context, source
|
|
129
|
+
private static async getOrLoadTexture(context: Context, source: SourceIdentifier | undefined, material: Material, slot: string, current: Texture, _level: number): Promise<Texture | null> {
|
|
97
130
|
|
|
98
131
|
const key = current.uuid;
|
|
99
132
|
const ext: DeferredTextureModel | undefined = NEEDLE_deferred_texture.cache.get(key);// || current.userData.deferred;
|
|
@@ -113,6 +113,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
113
113
|
|
|
114
114
|
public static invoke(go: THREE.Object3D | null | undefined, functionName: string, children: boolean = false, ...args: any) {
|
|
115
115
|
if (!go) return;
|
|
116
|
+
|
|
116
117
|
// console.log(go);
|
|
117
118
|
this.foreachComponent(go, c => {
|
|
118
119
|
const fn = c[functionName];
|
|
@@ -382,6 +383,8 @@ class Component implements IComponent, EventTarget {
|
|
|
382
383
|
// console.trace("INTERNAL ENABLE");
|
|
383
384
|
this.__didEnable = true;
|
|
384
385
|
this.onEnable();
|
|
386
|
+
// if we do this after processing the callback
|
|
387
|
+
this.__isEnabled = true;
|
|
385
388
|
return true;
|
|
386
389
|
}
|
|
387
390
|
|
|
@@ -391,6 +394,8 @@ class Component implements IComponent, EventTarget {
|
|
|
391
394
|
this._collisionExitRoutine = undefined;
|
|
392
395
|
this.onDisable();
|
|
393
396
|
this._collisions?.clear();
|
|
397
|
+
// if we do this after processing the callback
|
|
398
|
+
this.__isEnabled = false;
|
|
394
399
|
}
|
|
395
400
|
|
|
396
401
|
__internalDestroy() {
|
|
@@ -415,7 +420,10 @@ class Component implements IComponent, EventTarget {
|
|
|
415
420
|
}
|
|
416
421
|
|
|
417
422
|
// need to check here because codegen is calling this before everything is setup
|
|
418
|
-
if (!this.__didAwake)
|
|
423
|
+
if (!this.__didAwake) {
|
|
424
|
+
this.__isEnabled = val;
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
419
427
|
if (val) {
|
|
420
428
|
this.__internalEnable();
|
|
421
429
|
} else {
|
|
@@ -13,6 +13,7 @@ import { getWorldPosition, getWorldQuaternion, setWorldPosition } from "../engin
|
|
|
13
13
|
import { KeyCode } from "../engine/engine_input";
|
|
14
14
|
import { nameofFactory } from "../engine/engine_utils";
|
|
15
15
|
import { InstancingUtil } from "../engine/engine_instancing";
|
|
16
|
+
import { OrbitControls } from "./OrbitControls";
|
|
16
17
|
|
|
17
18
|
const debug = false;
|
|
18
19
|
|
|
@@ -43,7 +44,7 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
43
44
|
// public targets: THREE.Object3D[] | null = null;
|
|
44
45
|
|
|
45
46
|
// private controls: Control | null = null;
|
|
46
|
-
|
|
47
|
+
private orbit: OrbitControls | null = null;
|
|
47
48
|
|
|
48
49
|
private selectStartEventListener: ((controls: DragControls, args: SelectArgs) => void)[] = [];
|
|
49
50
|
private selectEndEventListener: Array<Function> = [];
|
|
@@ -70,7 +71,7 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
70
71
|
|
|
71
72
|
|
|
72
73
|
start() {
|
|
73
|
-
|
|
74
|
+
this.orbit = GameObject.findObjectOfType(OrbitControls, this.context);
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
private static lastHovered: THREE.Object3D;
|
|
@@ -148,8 +149,11 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
148
149
|
this.onUpdateDrag();
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
|
|
153
|
+
if (this._isDragging) {
|
|
154
|
+
if (this._dragHelper?.hasSelected === false) {
|
|
155
|
+
this.onDragEnd(null);
|
|
156
|
+
}
|
|
153
157
|
}
|
|
154
158
|
}
|
|
155
159
|
|
|
@@ -197,7 +201,7 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
197
201
|
object = args.attached;
|
|
198
202
|
this._isDragging = true;
|
|
199
203
|
this._dragHelper.setSelected(object, this.context);
|
|
200
|
-
|
|
204
|
+
if (this.orbit) this.orbit.enabled = false;
|
|
201
205
|
|
|
202
206
|
const sync = GameObject.getComponentInChildren(object, SyncedTransform);
|
|
203
207
|
if (debug)
|
|
@@ -239,7 +243,7 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
239
243
|
if (debug)
|
|
240
244
|
console.log("DRAG END", selected, selected?.visible)
|
|
241
245
|
this._dragHelper.setSelected(null, this.context);
|
|
242
|
-
|
|
246
|
+
if (this.orbit) this.orbit.enabled = true;
|
|
243
247
|
if (evt?.object) {
|
|
244
248
|
const sync = GameObject.getComponentInChildren(evt.object, SyncedTransform);
|
|
245
249
|
if (sync) {
|
|
@@ -316,7 +320,6 @@ class DragHelper {
|
|
|
316
320
|
}
|
|
317
321
|
|
|
318
322
|
setSelected(newSelected: THREE.Object3D | null, context: Context) {
|
|
319
|
-
|
|
320
323
|
if (this._selected && context) {
|
|
321
324
|
for (const rb of this._rbs) {
|
|
322
325
|
rb.wakeUp();
|
|
@@ -343,7 +346,6 @@ class DragHelper {
|
|
|
343
346
|
this._groundMarker.removeFromParent();
|
|
344
347
|
}
|
|
345
348
|
|
|
346
|
-
|
|
347
349
|
if (this._selected) {
|
|
348
350
|
if (!context) {
|
|
349
351
|
console.error("DragHelper: no context");
|
|
@@ -17,8 +17,8 @@ export { InstancingUtil } from "../engine/engine_instancing";
|
|
|
17
17
|
const suppressInstancing = getParam("noInstancing");
|
|
18
18
|
const debugLightmap = getParam("debuglightmaps") ? true : false;
|
|
19
19
|
const debugInstancing = getParam("debuginstancing");
|
|
20
|
-
const debugProgressiveLoading = getParam("
|
|
21
|
-
const suppressProgressiveLoading = getParam("
|
|
20
|
+
const debugProgressiveLoading = getParam("debugprogressive");
|
|
21
|
+
const suppressProgressiveLoading = getParam("noprogressive");
|
|
22
22
|
|
|
23
23
|
export class FieldWithDefault {
|
|
24
24
|
public path: string | null = null;
|
|
@@ -133,7 +133,7 @@ export class Renderer extends Behaviour implements IRenderer {
|
|
|
133
133
|
// private _materialProperties: Array<MaterialProperties> | undefined = undefined;
|
|
134
134
|
private _lightmaps?: RendererLightmap[];
|
|
135
135
|
|
|
136
|
-
get
|
|
136
|
+
get sharedMesh(): Mesh | undefined {
|
|
137
137
|
if (this.gameObject.type === "Mesh") {
|
|
138
138
|
return this.gameObject as unknown as Mesh
|
|
139
139
|
}
|
|
@@ -143,10 +143,20 @@ export class Renderer extends Behaviour implements IRenderer {
|
|
|
143
143
|
return undefined;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
get sharedMaterial(): THREE.Material {
|
|
147
|
+
return this.sharedMaterials[0];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
set sharedMaterial(mat: THREE.Material) {
|
|
151
|
+
this.sharedMaterials[0] = mat;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**@deprecated please use sharedMaterial */
|
|
146
155
|
get material(): THREE.Material {
|
|
147
156
|
return this.sharedMaterials[0];
|
|
148
157
|
}
|
|
149
158
|
|
|
159
|
+
/**@deprecated please use sharedMaterial */
|
|
150
160
|
set material(mat: THREE.Material) {
|
|
151
161
|
this.sharedMaterials[0] = mat;
|
|
152
162
|
}
|
|
@@ -31,6 +31,12 @@ function disposeStream(str: MediaStream | null | undefined) {
|
|
|
31
31
|
cap.stop();
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
declare type ScreenCaptureOptions = {
|
|
35
|
+
device?: ScreenCaptureDevice,
|
|
36
|
+
deviceId?: string,
|
|
37
|
+
constraints?: MediaTrackConstraints,
|
|
38
|
+
}
|
|
39
|
+
|
|
34
40
|
export class ScreenCapture extends Behaviour implements IPointerClickHandler {
|
|
35
41
|
|
|
36
42
|
onPointerClick() {
|
|
@@ -82,7 +88,8 @@ export class ScreenCapture extends Behaviour implements IPointerClickHandler {
|
|
|
82
88
|
private _currentMode: ScreenCaptureMode = ScreenCaptureMode.Idle;
|
|
83
89
|
|
|
84
90
|
awake() {
|
|
85
|
-
|
|
91
|
+
if (debug)
|
|
92
|
+
console.log(this);
|
|
86
93
|
AudioSource.registerWaitForAllowAudio(() => {
|
|
87
94
|
if (this.videoPlayer && this._currentStream && this._currentMode === ScreenCaptureMode.Receiving) {
|
|
88
95
|
this.videoPlayer.setVideo(this._currentStream);
|
|
@@ -105,12 +112,16 @@ export class ScreenCapture extends Behaviour implements IPointerClickHandler {
|
|
|
105
112
|
this._net.addEventListener(PeerEvent.ReceiveVideo, this.onReceiveVideo.bind(this));
|
|
106
113
|
}
|
|
107
114
|
|
|
108
|
-
async share() {
|
|
115
|
+
async share(opts?: ScreenCaptureOptions) {
|
|
116
|
+
|
|
117
|
+
if (opts?.device)
|
|
118
|
+
this.device = opts.device;
|
|
119
|
+
|
|
109
120
|
this._requestOpen = true;
|
|
110
121
|
try {
|
|
111
122
|
if (this.videoPlayer) {
|
|
112
123
|
|
|
113
|
-
const settings: MediaTrackConstraints = {
|
|
124
|
+
const settings: MediaTrackConstraints = opts?.constraints ?? {
|
|
114
125
|
echoCancellation: true,
|
|
115
126
|
autoGainControl: false,
|
|
116
127
|
};
|
|
@@ -122,7 +133,7 @@ export class ScreenCapture extends Behaviour implements IPointerClickHandler {
|
|
|
122
133
|
switch (this.device) {
|
|
123
134
|
// Capture a connected camera
|
|
124
135
|
case ScreenCaptureDevice.Camera:
|
|
125
|
-
this.tryShareUserCamera(displayMediaOptions);
|
|
136
|
+
this.tryShareUserCamera(displayMediaOptions, opts);
|
|
126
137
|
break;
|
|
127
138
|
|
|
128
139
|
// capture any screen, will show a popup
|
|
@@ -197,7 +208,7 @@ export class ScreenCapture extends Behaviour implements IPointerClickHandler {
|
|
|
197
208
|
|
|
198
209
|
|
|
199
210
|
|
|
200
|
-
private async tryShareUserCamera(opts: DisplayMediaStreamConstraints) {
|
|
211
|
+
private async tryShareUserCamera(opts: DisplayMediaStreamConstraints, options?: ScreenCaptureOptions) {
|
|
201
212
|
|
|
202
213
|
// let newWindow = open('', 'example', 'width=300,height=300');
|
|
203
214
|
// if (window) {
|
|
@@ -212,6 +223,10 @@ export class ScreenCapture extends Behaviour implements IPointerClickHandler {
|
|
|
212
223
|
if (!this._requestOpen) break;
|
|
213
224
|
if (dev.kind !== "videoinput") continue;
|
|
214
225
|
const id = dev.deviceId;
|
|
226
|
+
if (options?.deviceId !== undefined) {
|
|
227
|
+
if (id !== options.deviceId)
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
215
230
|
if (opts.video !== false) {
|
|
216
231
|
if (typeof opts.video === "undefined" || typeof opts.video === "boolean") {
|
|
217
232
|
opts.video = {};
|
|
@@ -13,11 +13,11 @@ import { ControllerType, WebXRController } from "./WebXRController";
|
|
|
13
13
|
import { WebARSessionRoot } from "./WebARSessionRoot";
|
|
14
14
|
import { getWorldPosition, getWorldQuaternion, setWorldPosition, setWorldQuaternion } from "../engine/engine_three_utils";
|
|
15
15
|
import { XRRig } from "./WebXRRig";
|
|
16
|
-
import { EngineElement } from "../engine/engine_element";
|
|
17
16
|
import { AssetReference } from "../engine/engine_addressables";
|
|
18
17
|
import { serializeable } from "../engine/engine_serialization_decorator";
|
|
19
18
|
import { WebXRSync } from "./WebXRSync";
|
|
20
19
|
import { XRSessionMode } from "../engine/engine_setup";
|
|
20
|
+
import { INeedleEngineComponent } from "../engine/engine_types";
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
export async function detectARSupport() {
|
|
@@ -210,7 +210,7 @@ export class WebXR extends Behaviour {
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
// VR support
|
|
213
|
-
if (this.createVRButton && this.enableVR
|
|
213
|
+
if (this.createVRButton && this.enableVR) {
|
|
214
214
|
vrButton = WebXR.createVRButton(this);
|
|
215
215
|
this._vrButton = vrButton;
|
|
216
216
|
buttonsContainer.appendChild(vrButton);
|
|
@@ -477,16 +477,17 @@ export class WebAR {
|
|
|
477
477
|
this._webxr = webxr;
|
|
478
478
|
}
|
|
479
479
|
|
|
480
|
-
private arDomOverlay:
|
|
481
|
-
private arOverlayElement: HTMLElement | null = null;
|
|
480
|
+
private arDomOverlay: HTMLElement | null = null;
|
|
481
|
+
private arOverlayElement: INeedleEngineComponent | HTMLElement | null = null;
|
|
482
482
|
private noHitTestAvailable: boolean = false;
|
|
483
483
|
private didPlaceARSessionRoot: boolean = false;
|
|
484
484
|
|
|
485
485
|
getAROverlayContainer(): HTMLElement | null {
|
|
486
|
-
this.arDomOverlay = this.webxr.context.domElement as
|
|
486
|
+
this.arDomOverlay = this.webxr.context.domElement as HTMLElement;
|
|
487
487
|
// for react cases we dont have an Engine Element
|
|
488
|
-
|
|
489
|
-
|
|
488
|
+
const element : any = this.arDomOverlay;
|
|
489
|
+
if (element.getAROverlayContainer)
|
|
490
|
+
this.arOverlayElement = element.getAROverlayContainer();
|
|
490
491
|
else this.arOverlayElement = this.arDomOverlay;
|
|
491
492
|
return this.arOverlayElement;
|
|
492
493
|
}
|
|
@@ -548,13 +549,14 @@ export class WebAR {
|
|
|
548
549
|
else console.warn("No WebARSessionRoot found in scene")
|
|
549
550
|
|
|
550
551
|
if (this.arDomOverlay && this.arOverlayElement) {
|
|
551
|
-
|
|
552
|
+
const el = this.arOverlayElement as INeedleEngineComponent;
|
|
553
|
+
el.onEnterAR?.call(el, session, this.arOverlayElement);
|
|
552
554
|
}
|
|
553
555
|
|
|
554
556
|
this.context.mainCameraComponent?.applyClearFlagsIfIsActiveCamera();
|
|
555
557
|
}
|
|
556
558
|
|
|
557
|
-
onEnd(
|
|
559
|
+
onEnd(session: THREE.XRSession) {
|
|
558
560
|
if (this._previousParent) {
|
|
559
561
|
console.log("ADD", this._previousParent);
|
|
560
562
|
GameObject.addComponent(this._previousParent as GameObject, this.webxr);
|
|
@@ -565,9 +567,13 @@ export class WebAR {
|
|
|
565
567
|
context.scene.background = this.previousBackground;
|
|
566
568
|
context.scene.environment = this.previousEnvironment;
|
|
567
569
|
if (this.sessionRoot) {
|
|
568
|
-
this.sessionRoot.onEnd(this.webxr.Rig,
|
|
570
|
+
this.sessionRoot.onEnd(this.webxr.Rig, session);
|
|
571
|
+
}
|
|
572
|
+
if (this.arDomOverlay)
|
|
573
|
+
{
|
|
574
|
+
const el = this.arOverlayElement as INeedleEngineComponent;
|
|
575
|
+
el.onExitAR?.call(el, session);
|
|
569
576
|
}
|
|
570
|
-
if (this.arDomOverlay) this.arDomOverlay.onExitAR(_session);
|
|
571
577
|
|
|
572
578
|
this.context.mainCameraComponent?.applyClearFlagsIfIsActiveCamera();
|
|
573
579
|
}
|
|
@@ -1,19 +1,32 @@
|
|
|
1
|
+
import { Object3D } from "three";
|
|
2
|
+
import { Constructor } from "../../engine/engine_types";
|
|
1
3
|
|
|
2
|
-
const handlers
|
|
4
|
+
const handlers: Map<any, ApplyPrototypeExtension> = new Map();
|
|
3
5
|
|
|
4
|
-
export function applyPrototypeExtensions(obj :
|
|
5
|
-
if(!obj) return;
|
|
6
|
-
const prototype = obj
|
|
7
|
-
|
|
6
|
+
export function applyPrototypeExtensions<T>(obj: any, prototype : Constructor<T>) {
|
|
7
|
+
if (!obj) return;
|
|
8
|
+
// const prototype = Object.getPrototypeOf(obj);
|
|
9
|
+
// console.log("TEST", prototype)
|
|
10
|
+
if (!prototype) {
|
|
11
|
+
console.warn("No prototype found", obj, obj.prototype, obj.constructor);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
8
14
|
let handler = handlers.get(prototype);
|
|
9
|
-
if(
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
if (handler) {
|
|
16
|
+
// console.log("OK", prototype);
|
|
17
|
+
handler.apply(obj);
|
|
12
18
|
}
|
|
13
|
-
|
|
19
|
+
// applyPrototypeExtensions(prototype);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function registerPrototypeExtensions<T>(type: Constructor<T>) {
|
|
23
|
+
console.log("Register", type.prototype.constructor.name);
|
|
24
|
+
const handler = createPrototypeExtensionHandler(type.prototype);
|
|
25
|
+
handlers.set(type, handler);
|
|
14
26
|
}
|
|
15
27
|
|
|
16
|
-
|
|
28
|
+
|
|
29
|
+
function createPrototypeExtensionHandler(prototype: any) {
|
|
17
30
|
return new ApplyPrototypeExtension(prototype);
|
|
18
31
|
}
|
|
19
32
|
|
|
@@ -31,9 +44,11 @@ class ApplyPrototypeExtension implements IApplyPrototypeExtension {
|
|
|
31
44
|
this.$symbol = Symbol("prototype-extension");
|
|
32
45
|
// used to decorate cloned object3D objects with the same added components defined above
|
|
33
46
|
this.extensions = Object.keys(prototype);
|
|
47
|
+
// console.log(this.extensions);
|
|
34
48
|
this.descriptors = new Array<PropertyDescriptor | undefined>();
|
|
35
49
|
for (let i = 0; i < this.extensions.length; i++) {
|
|
36
50
|
const key = this.extensions[i];
|
|
51
|
+
// console.log(key);
|
|
37
52
|
const descriptor = Object.getOwnPropertyDescriptor(prototype, key);
|
|
38
53
|
if (descriptor) {
|
|
39
54
|
this.descriptors.push(descriptor);
|
|
@@ -41,7 +56,7 @@ class ApplyPrototypeExtension implements IApplyPrototypeExtension {
|
|
|
41
56
|
}
|
|
42
57
|
}
|
|
43
58
|
|
|
44
|
-
apply(object:
|
|
59
|
+
apply(object: Object3D): void {
|
|
45
60
|
|
|
46
61
|
if (object[this.$symbol]) return;
|
|
47
62
|
object[this.$symbol] = true;
|
|
@@ -58,7 +73,7 @@ class ApplyPrototypeExtension implements IApplyPrototypeExtension {
|
|
|
58
73
|
// continue;
|
|
59
74
|
// }
|
|
60
75
|
// }
|
|
61
|
-
// console.
|
|
76
|
+
// console.warn("DEFINE", object, key);
|
|
62
77
|
Object.defineProperty(object, key, desc);
|
|
63
78
|
}
|
|
64
79
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyPrototypeExtensions } from "./ExtensionUtils";
|
|
1
|
+
import { applyPrototypeExtensions, registerPrototypeExtensions } from "./ExtensionUtils";
|
|
2
2
|
import { Object3D } from "three";
|
|
3
3
|
import { Constructor, ConstructorConcrete, IComponent } from "../../engine/engine_types"
|
|
4
4
|
import { IComponent as Component } from "../../engine/engine_types";
|
|
@@ -6,24 +6,12 @@ import { addNewComponentInstance, getComponent, getComponentInChildren, getCompo
|
|
|
6
6
|
|
|
7
7
|
// used to decorate cloned object3D objects with the same added components defined above
|
|
8
8
|
export function apply(object: Object3D) {
|
|
9
|
-
if (object && object.isObject3D === true)
|
|
10
|
-
applyPrototypeExtensions(object);
|
|
9
|
+
if (object && object.isObject3D === true) {
|
|
10
|
+
applyPrototypeExtensions(object, Object3D);
|
|
11
|
+
}
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
|
|
14
|
-
// this is a fix to allow gameObject active animation be applied to a three object
|
|
15
|
-
if (!Object.getOwnPropertyDescriptor(Object3D.prototype, "activeSelf")) {
|
|
16
|
-
Object.defineProperty(Object3D.prototype, "activeSelf", {
|
|
17
|
-
get: function () {
|
|
18
|
-
return this.visible;
|
|
19
|
-
},
|
|
20
|
-
set: function (val: boolean | number) {
|
|
21
|
-
const state = typeof val === "number" ? val > 0.5 : val;
|
|
22
|
-
this.visible = state;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
15
|
|
|
28
16
|
// do we still need this?
|
|
29
17
|
Object3D.prototype["SetActive"] = function (active: boolean) {
|
|
@@ -65,3 +53,22 @@ Object3D.prototype["getComponentInParent"] = function <T extends IComponent>(typ
|
|
|
65
53
|
Object3D.prototype["getComponentsInParent"] = function <T>(type: Constructor<T>, arr?: []) {
|
|
66
54
|
return getComponentsInParent(this, type, arr);
|
|
67
55
|
}
|
|
56
|
+
|
|
57
|
+
// this is a fix to allow gameObject active animation be applied to a three object
|
|
58
|
+
if (!Object.getOwnPropertyDescriptor(Object3D.prototype, "activeSelf")) {
|
|
59
|
+
Object.defineProperty(Object3D.prototype, "activeSelf", {
|
|
60
|
+
get: function () {
|
|
61
|
+
return this.visible;
|
|
62
|
+
},
|
|
63
|
+
set: function (val: boolean | number) {
|
|
64
|
+
const state = typeof val === "number" ? val > 0.5 : val;
|
|
65
|
+
this.visible = state;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
// do this after adding the component extensions
|
|
74
|
+
registerPrototypeExtensions(Object3D);
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import { applyPrototypeExtensions } from "./ExtensionUtils";
|
|
1
|
+
import { applyPrototypeExtensions, registerPrototypeExtensions } from "./ExtensionUtils";
|
|
2
2
|
import { Mathf } from "../../engine/engine_math";
|
|
3
3
|
import { Vector3 } from "three";
|
|
4
4
|
|
|
5
5
|
export function apply(object: Vector3) {
|
|
6
6
|
if (object && object.isVector3 === true) {
|
|
7
|
-
|
|
8
|
-
applyPrototypeExtensions(object);
|
|
7
|
+
applyPrototypeExtensions(object, Vector3);
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
|
|
11
|
+
|
|
12
12
|
Vector3.prototype["slerp"] = function (end: Vector3, t: number) {
|
|
13
13
|
const len1 = this.length();
|
|
14
14
|
const len2 = end.length();
|
|
15
15
|
const targetLen = Mathf.lerp(len1, len2, t);
|
|
16
16
|
return this.lerp(end, t).normalize().multiplyScalar(targetLen);
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
registerPrototypeExtensions(Vector3);
|