@needle-tools/engine 2.34.0-pre → 2.35.1-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 +16 -0
- package/dist/needle-engine.d.ts +3128 -2942
- package/dist/needle-engine.js +455 -455
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +54 -54
- package/dist/needle-engine.min.js.map +4 -4
- package/lib/engine/api.d.ts +3 -0
- package/lib/engine/api.js +4 -0
- package/lib/engine/api.js.map +1 -0
- package/lib/engine/engine.d.ts +4 -3
- package/lib/engine/engine_addressables.d.ts +5 -4
- package/lib/engine/engine_addressables.js +8 -7
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_components.d.ts +17 -0
- package/lib/engine/engine_components.js +240 -0
- package/lib/engine/engine_components.js.map +1 -0
- package/lib/engine/engine_element.js +4 -3
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_loading.js +4 -1
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_gameobject.d.ts +33 -0
- package/lib/engine/engine_gameobject.js +449 -0
- package/lib/engine/engine_gameobject.js.map +1 -0
- package/lib/engine/engine_gltf.d.ts +13 -2
- package/lib/engine/engine_gltf.js +7 -1
- package/lib/engine/engine_gltf.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.d.ts +3 -3
- package/lib/engine/engine_gltf_builtin_components.js +2 -3
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_lightdata.d.ts +1 -1
- package/lib/engine/engine_lightdata.js.map +1 -1
- package/lib/engine/engine_mainloop_utils.d.ts +2 -2
- package/lib/engine/engine_mainloop_utils.js +7 -6
- package/lib/engine/engine_mainloop_utils.js.map +1 -1
- package/lib/engine/engine_networking.d.ts +6 -10
- package/lib/engine/engine_networking.js +7 -11
- package/lib/engine/engine_networking.js.map +1 -1
- package/lib/engine/engine_networking_files.d.ts +1 -1
- package/lib/engine/engine_networking_files.js +8 -7
- package/lib/engine/engine_networking_files.js.map +1 -1
- package/lib/engine/engine_networking_files_default_components.d.ts +2 -2
- package/lib/engine/engine_networking_files_default_components.js +38 -43
- package/lib/engine/engine_networking_files_default_components.js.map +1 -1
- package/lib/engine/engine_networking_instantiate.d.ts +8 -6
- package/lib/engine/engine_networking_instantiate.js +12 -9
- package/lib/engine/engine_networking_instantiate.js.map +1 -1
- package/lib/engine/engine_networking_types.d.ts +14 -0
- package/lib/engine/engine_networking_types.js +8 -0
- package/lib/engine/engine_networking_types.js.map +1 -0
- package/lib/engine/engine_physics.d.ts +5 -24
- package/lib/engine/engine_physics.js +27 -61
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_rendererdata.d.ts +1 -1
- package/lib/engine/engine_rendererdata.js.map +1 -1
- package/lib/engine/engine_scenetools.d.ts +2 -2
- package/lib/engine/engine_scenetools.js +22 -5
- package/lib/engine/engine_scenetools.js.map +1 -1
- package/lib/engine/engine_serialization_builtin_serializer.d.ts +1 -1
- package/lib/engine/engine_serialization_core.d.ts +1 -1
- package/lib/engine/engine_serialization_decorator.d.ts +1 -1
- package/lib/engine/engine_setup.d.ts +14 -15
- package/lib/engine/engine_setup.js +34 -23
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_three_utils.js +0 -6
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/engine_types.d.ts +108 -0
- package/lib/engine/engine_types.js +50 -0
- package/lib/engine/engine_types.js.map +1 -0
- package/lib/engine/engine_utils.d.ts +1 -1
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_components.js +2 -2
- package/lib/engine/extensions/NEEDLE_components.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_deferred_texture.d.ts +1 -1
- package/lib/engine/extensions/NEEDLE_lighting_settings.d.ts +1 -1
- package/lib/engine/extensions/NEEDLE_lightmaps.d.ts +1 -1
- package/lib/engine/extensions/NEEDLE_render_objects.d.ts +2 -2
- package/lib/engine/extensions/NEEDLE_techniques_webgl.d.ts +1 -1
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js +3 -2
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
- package/lib/engine/extensions/extensions.d.ts +1 -1
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AvatarLoader.js +6 -5
- package/lib/engine-components/AvatarLoader.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +2 -2
- package/lib/engine-components/Camera.js +6 -12
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CameraUtils.d.ts +3 -0
- package/lib/engine-components/CameraUtils.js +15 -0
- package/lib/engine-components/CameraUtils.js.map +1 -0
- package/lib/engine-components/Collider.d.ts +3 -1
- package/lib/engine-components/Collider.js +11 -0
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +21 -55
- package/lib/engine-components/Component.js +67 -466
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/Duplicatable.js +2 -1
- package/lib/engine-components/Duplicatable.js.map +1 -1
- package/lib/engine-components/LODGroup.js.map +1 -1
- package/lib/engine-components/Light.d.ts +2 -1
- package/lib/engine-components/Light.js +2 -2
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/NestedGltf.js +2 -1
- package/lib/engine-components/NestedGltf.js.map +1 -1
- package/lib/engine-components/Networking.d.ts +3 -1
- package/lib/engine-components/Networking.js +3 -0
- package/lib/engine-components/Networking.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +4 -2
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/Renderer.d.ts +3 -2
- package/lib/engine-components/Renderer.js +2 -0
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/{Rigidbody.d.ts → RigidBody.d.ts} +2 -1
- package/lib/engine-components/{Rigidbody.js → RigidBody.js} +1 -1
- package/lib/engine-components/{Rigidbody.js.map → RigidBody.js.map} +1 -1
- package/lib/engine-components/ScreenCapture.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SyncedCamera.js +2 -1
- package/lib/engine-components/SyncedCamera.js.map +1 -1
- package/lib/engine-components/SyncedTransform.js.map +1 -1
- package/lib/engine-components/TestRunner.js.map +1 -1
- package/lib/engine-components/Voip.js +2 -1
- package/lib/engine-components/Voip.js.map +1 -1
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRController.js +28 -8
- package/lib/engine-components/WebXRController.js.map +1 -1
- package/lib/engine-components/WebXRGrabRendering.d.ts +1 -1
- package/lib/engine-components/WebXRGrabRendering.js +1 -1
- package/lib/engine-components/WebXRGrabRendering.js.map +1 -1
- package/lib/engine-components/WebXRSync.js +1 -1
- package/lib/engine-components/WebXRSync.js.map +1 -1
- package/lib/engine-components/avatar/Avatar_Brain_LookAt.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +1 -1
- package/lib/engine-components/codegen/components.js +1 -1
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/js-extensions/ExtensionUtils.d.ts +4 -0
- package/lib/engine-components/js-extensions/ExtensionUtils.js +56 -0
- package/lib/engine-components/js-extensions/ExtensionUtils.js.map +1 -0
- package/lib/engine-components/js-extensions/Object3D.js +27 -50
- package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
- package/lib/engine-components/js-extensions/Vector.d.ts +2 -0
- package/lib/engine-components/js-extensions/Vector.js +16 -0
- package/lib/engine-components/js-extensions/Vector.js.map +1 -0
- package/lib/engine-components/timeline/PlayableDirector.d.ts +2 -1
- package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
- package/lib/engine-components/ui/BaseUIComponent.d.ts +1 -0
- package/lib/engine-components/ui/BaseUIComponent.js +11 -5
- package/lib/engine-components/ui/BaseUIComponent.js.map +1 -1
- package/lib/engine-components/ui/Canvas.d.ts +3 -0
- package/lib/engine-components/ui/Canvas.js +12 -1
- package/lib/engine-components/ui/Canvas.js.map +1 -1
- package/lib/engine-components/ui/CanvasScaler.d.ts +0 -0
- package/lib/engine-components/ui/CanvasScaler.js +17 -0
- package/lib/engine-components/ui/CanvasScaler.js.map +1 -0
- package/lib/engine-components/ui/EventSystem.d.ts +1 -1
- package/lib/engine-components/ui/EventSystem.js +11 -31
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/lib/engine-components/ui/Graphic.js +2 -1
- package/lib/engine-components/ui/Graphic.js.map +1 -1
- package/lib/engine-components/ui/Keyboard.js +2 -1
- package/lib/engine-components/ui/Keyboard.js.map +1 -1
- package/lib/engine-components/ui/RaycastUtils.d.ts +11 -0
- package/lib/engine-components/ui/RaycastUtils.js +62 -0
- package/lib/engine-components/ui/RaycastUtils.js.map +1 -0
- package/lib/engine-components/ui/Raycaster.js.map +1 -1
- package/lib/engine-components/ui/Text.js +8 -3
- package/lib/engine-components/ui/Text.js.map +1 -1
- package/lib/engine-components/ui/Utils.js +3 -2
- package/lib/engine-components/ui/Utils.js.map +1 -1
- package/lib/needle-engine.d.ts +3 -1
- package/lib/needle-engine.js +4 -2
- package/lib/needle-engine.js.map +1 -1
- package/package.json +12 -1
- package/src/engine/api.ts +3 -0
- package/src/engine/codegen/register_types.js +2 -2
- package/src/engine/engine_addressables.ts +12 -10
- package/src/engine/{engine_components.js → engine_components.ts} +66 -61
- package/src/engine/engine_element.ts +4 -3
- package/src/engine/engine_element_loading.ts +5 -1
- package/src/engine/engine_gameobject.ts +506 -0
- package/src/engine/engine_gltf.ts +21 -2
- package/src/engine/engine_gltf_builtin_components.ts +8 -7
- package/src/engine/engine_lightdata.ts +1 -1
- package/src/engine/engine_mainloop_utils.ts +13 -11
- package/src/engine/engine_networking.ts +14 -17
- package/src/engine/engine_networking_files.ts +14 -11
- package/src/engine/engine_networking_files_default_components.ts +53 -52
- package/src/engine/engine_networking_instantiate.ts +24 -14
- package/src/engine/engine_networking_types.ts +19 -0
- package/src/engine/engine_physics.ts +45 -77
- package/src/engine/engine_rendererdata.ts +1 -1
- package/src/engine/engine_scenetools.ts +30 -6
- package/src/engine/engine_serialization_core.ts +1 -1
- package/src/engine/engine_serialization_decorator.ts +1 -1
- package/src/engine/engine_setup.ts +51 -37
- package/src/engine/engine_three_utils.ts +0 -8
- package/src/engine/engine_types.ts +188 -0
- package/src/engine/engine_utils.ts +1 -3
- package/src/engine/extensions/NEEDLE_components.ts +2 -2
- package/src/engine/extensions/NEEDLE_deferred_texture.ts +1 -1
- package/src/engine/extensions/NEEDLE_lighting_settings.ts +1 -1
- package/src/engine/extensions/NEEDLE_lightmaps.ts +1 -1
- package/src/engine/extensions/NEEDLE_render_objects.ts +4 -4
- package/src/engine/extensions/NEEDLE_techniques_webgl.ts +5 -4
- package/src/engine/extensions/extensions.ts +1 -1
- package/src/engine-components/Animator.ts +3 -3
- package/src/engine-components/AvatarLoader.ts +6 -5
- package/src/engine-components/Camera.ts +10 -13
- package/src/engine-components/CameraUtils.ts +15 -0
- package/src/engine-components/Collider.ts +17 -2
- package/src/engine-components/Component.ts +87 -541
- package/src/engine-components/Duplicatable.ts +4 -3
- package/src/engine-components/LODGroup.ts +1 -1
- package/src/engine-components/Light.ts +3 -2
- package/src/engine-components/NestedGltf.ts +2 -1
- package/src/engine-components/Networking.ts +6 -1
- package/src/engine-components/OrbitControls.ts +5 -5
- package/src/engine-components/Renderer.ts +5 -1
- package/src/engine-components/RigidBody.ts +2 -1
- package/src/engine-components/ScreenCapture.ts +1 -1
- package/src/engine-components/SpectatorCamera.ts +7 -5
- package/src/engine-components/SyncedCamera.ts +2 -1
- package/src/engine-components/SyncedTransform.ts +1 -1
- package/src/engine-components/TestRunner.ts +1 -2
- package/src/engine-components/Voip.ts +2 -1
- package/src/engine-components/WebXR.ts +2 -2
- package/src/engine-components/WebXRController.ts +30 -10
- package/src/engine-components/WebXRGrabRendering.ts +1 -1
- package/src/engine-components/WebXRSync.ts +1 -1
- package/src/engine-components/avatar/Avatar_Brain_LookAt.ts +2 -1
- package/src/engine-components/codegen/components.ts +1 -1
- package/src/engine-components/js-extensions/ExtensionUtils.ts +66 -0
- package/src/engine-components/js-extensions/Object3D.ts +37 -61
- package/src/engine-components/js-extensions/Vector.ts +17 -0
- package/src/engine-components/timeline/PlayableDirector.ts +2 -1
- package/src/engine-components/ui/BaseUIComponent.ts +17 -6
- package/src/engine-components/ui/Canvas.ts +14 -2
- package/src/engine-components/ui/CanvasScaler.ts +21 -0
- package/src/engine-components/ui/EventSystem.ts +11 -25
- package/src/engine-components/ui/Graphic.ts +2 -1
- package/src/engine-components/ui/Keyboard.ts +2 -1
- package/src/engine-components/ui/RaycastUtils.ts +64 -0
- package/src/engine-components/ui/Raycaster.ts +2 -0
- package/src/engine-components/ui/Text.ts +8 -4
- package/src/engine-components/ui/Utils.ts +3 -2
- package/src/needle-engine.ts +7 -2
|
@@ -1,55 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Context } from
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
1
|
+
import { Object3D, Scene } from "three";
|
|
2
|
+
import { Constructor, ConstructorConcrete, IComponent as Component, IComponent, IGameObject } from "./engine_types";
|
|
3
|
+
import { Context, registerComponent } from "./engine_setup";
|
|
4
|
+
import { getParam } from "./engine_utils";
|
|
5
|
+
import { removeScriptFromContext, updateActiveInHierarchyWithoutEventCall } from "./engine_mainloop_utils";
|
|
6
|
+
import { activeInHierarchyFieldName } from "./engine_constants";
|
|
6
7
|
|
|
7
8
|
const debug = getParam("debuggetcomponent");
|
|
8
9
|
|
|
10
|
+
|
|
9
11
|
function tryGetObject(obj) {
|
|
10
|
-
if(obj === null || obj === undefined) return obj;
|
|
11
|
-
if(obj.isObject3D) return obj;
|
|
12
|
+
if (obj === null || obj === undefined) return obj;
|
|
13
|
+
if (obj.isObject3D) return obj;
|
|
12
14
|
// handle threejs intersection object
|
|
13
15
|
if (obj.object && obj.object.isObject3D) return obj.object;
|
|
14
16
|
return obj;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
export function registerComponent(script, context) {
|
|
18
|
-
if (!script) return;
|
|
19
|
-
const new_scripts = context?.new_scripts ?? Context.Current.new_scripts;
|
|
20
|
-
if (!new_scripts.includes(script)) {
|
|
21
|
-
new_scripts.push(script);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
19
|
|
|
25
|
-
export
|
|
20
|
+
export function removeComponent(go: Object3D, componentInstance: IComponent) {
|
|
26
21
|
if (!go) return;
|
|
27
22
|
if (!go.userData.components) return;
|
|
28
23
|
const index = go.userData.components.indexOf(componentInstance);
|
|
29
24
|
if (index < 0) return;
|
|
25
|
+
//@ts-ignore
|
|
30
26
|
componentInstance.gameObject = null;
|
|
31
27
|
go.userData.components.splice(index, 1);
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
|
|
30
|
+
export function getOrAddComponent<T extends IComponent>(go: Object3D, typeName: ConstructorConcrete<T>): T {
|
|
31
|
+
const comp = getComponent(go, typeName);
|
|
32
|
+
if (comp) return comp;
|
|
33
|
+
const newInstance = new typeName();
|
|
34
|
+
return addNewComponentInstance(go, newInstance) as unknown as T;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function addNewComponentInstance<T extends IComponent>(obj: Object3D, componentInstance: T, callAwake = true): IComponent {
|
|
35
38
|
if (!obj.userData) obj.userData = {};
|
|
36
39
|
if (!obj.userData.components) obj.userData.components = [];
|
|
37
40
|
obj.userData.components.push(componentInstance);
|
|
38
|
-
componentInstance.gameObject = obj;
|
|
41
|
+
componentInstance.gameObject = obj as IGameObject;
|
|
39
42
|
// componentInstance.transform = obj;
|
|
40
43
|
registerComponent(componentInstance);
|
|
41
44
|
try {
|
|
42
45
|
if (componentInstance.__internalAwake && callAwake) {
|
|
43
|
-
|
|
46
|
+
updateActiveInHierarchyWithoutEventCall(obj);
|
|
44
47
|
componentInstance.__internalAwake();
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
catch (err) {
|
|
48
51
|
console.error(err);
|
|
49
52
|
}
|
|
53
|
+
return componentInstance;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
|
|
56
|
+
export function moveComponentInstance(obj: Object3D, componentInstance: IComponent) {
|
|
53
57
|
if (componentInstance.gameObject === obj) return;
|
|
54
58
|
// TODO: update raycast array
|
|
55
59
|
if (componentInstance.gameObject && componentInstance.gameObject.userData.components) {
|
|
@@ -59,12 +63,12 @@ const moveComponentInstance = function (componentInstance, obj) {
|
|
|
59
63
|
if (!obj.userData.components) obj.userData.components = [];
|
|
60
64
|
else if (obj.userData.components.includes(componentInstance)) return;
|
|
61
65
|
obj.userData.components.push(componentInstance);
|
|
62
|
-
componentInstance.gameObject = obj;
|
|
66
|
+
componentInstance.gameObject = obj as IGameObject;
|
|
63
67
|
// componentInstance.transform = obj;
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
|
|
67
|
-
|
|
71
|
+
export function destroyComponentInstance(componentInstance: IComponent) {
|
|
68
72
|
// console.log("destroy", componentInstance, componentInstance.onDestroy);
|
|
69
73
|
// TODO: update raycast array
|
|
70
74
|
if (componentInstance.gameObject && componentInstance.gameObject.userData.components) {
|
|
@@ -75,18 +79,25 @@ const destroyComponentInstance = function (componentInstance) {
|
|
|
75
79
|
if (componentInstance.__internalDisable) componentInstance.__internalDisable();
|
|
76
80
|
if (componentInstance.onDestroy) componentInstance.onDestroy();
|
|
77
81
|
removeScriptFromContext(componentInstance, componentInstance.context ?? Context.Current);
|
|
78
|
-
componentInstance.
|
|
82
|
+
componentInstance.__internalDestroy();
|
|
83
|
+
//@ts-ignore
|
|
79
84
|
componentInstance.gameObject = null;
|
|
80
85
|
// console.log("destroyed", index, componentInstance);
|
|
81
86
|
}
|
|
82
87
|
|
|
83
|
-
|
|
88
|
+
function onGetComponent<T>(obj: Object3D | null | undefined, componentType: Constructor<T>, arr?: T[]) {
|
|
89
|
+
if (obj === null || obj === undefined) return;
|
|
90
|
+
if (!obj.isObject3D) {
|
|
91
|
+
console.error("Object is not object3D");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
84
94
|
if (!(obj?.userData?.components)) return null;
|
|
85
95
|
if (debug)
|
|
86
96
|
console.log("FIND", componentType);
|
|
97
|
+
if (componentType === undefined || componentType === null) return;
|
|
87
98
|
for (let i = 0; i < obj.userData.components.length; i++) {
|
|
88
99
|
const component = obj.userData.components[i];
|
|
89
|
-
if (componentType === null || component.constructor.name === componentType
|
|
100
|
+
if (componentType === null || component.constructor.name === componentType["name"] || component.constructor.name === componentType) {
|
|
90
101
|
if (debug)
|
|
91
102
|
console.log("MATCH BY NAME", component)
|
|
92
103
|
if (arr) arr.push(component);
|
|
@@ -111,59 +122,63 @@ const onGetComponent = function (componentType, obj, arr) {
|
|
|
111
122
|
return arr;
|
|
112
123
|
}
|
|
113
124
|
|
|
114
|
-
|
|
115
|
-
return onGetComponent(
|
|
125
|
+
export function getComponent<T>(obj: Object3D, componentType: Constructor<T>) {
|
|
126
|
+
return onGetComponent(obj, componentType);
|
|
116
127
|
}
|
|
117
128
|
|
|
118
|
-
|
|
129
|
+
export function getComponents<T>(obj: Object3D, componentType: Constructor<T>, arr?: T[] | null): T[] {
|
|
119
130
|
if (!arr) arr = [];
|
|
120
|
-
return onGetComponent(
|
|
131
|
+
return onGetComponent(obj, componentType, arr);
|
|
121
132
|
}
|
|
122
133
|
|
|
123
|
-
|
|
124
|
-
const res = getComponent(
|
|
134
|
+
export function getComponentInChildren<T>(obj: Object3D, componentType: Constructor<T>, includeInactive?: boolean) {
|
|
135
|
+
const res = getComponent(obj, componentType);
|
|
125
136
|
if (includeInactive === false && res.enabled === false) return null;
|
|
126
137
|
if (res) return res;
|
|
127
138
|
for (let i = 0; i < obj?.children?.length; i++) {
|
|
128
|
-
const res = getComponentInChildren(
|
|
139
|
+
const res = getComponentInChildren(obj.children[i], componentType);
|
|
129
140
|
if (res) return res;
|
|
130
141
|
}
|
|
131
142
|
return null;
|
|
132
143
|
}
|
|
133
144
|
|
|
134
|
-
|
|
145
|
+
export function getComponentsInChildren<T>(obj: Object3D, componentType: Constructor<T>, arr?: T[]) {
|
|
135
146
|
if (!arr) arr = [];
|
|
136
|
-
getComponents(
|
|
147
|
+
getComponents(obj, componentType, arr);
|
|
137
148
|
for (let i = 0; i < obj?.children?.length; i++) {
|
|
138
|
-
getComponentsInChildren(
|
|
149
|
+
getComponentsInChildren(obj.children[i], componentType, arr);
|
|
139
150
|
}
|
|
140
151
|
return arr;
|
|
141
152
|
}
|
|
142
153
|
|
|
143
|
-
|
|
154
|
+
export function getComponentInParent<T>(obj: Object3D, componentType: Constructor<T>) {
|
|
144
155
|
if (!obj) return null;
|
|
145
156
|
if (Array.isArray(obj)) {
|
|
146
157
|
for (let i = 0; i < obj.length; i++) {
|
|
147
158
|
const o = tryGetObject(obj[i]);
|
|
148
|
-
const res = getComponentInParent(
|
|
159
|
+
const res = getComponentInParent(o, componentType);
|
|
149
160
|
if (res) return res;
|
|
150
161
|
}
|
|
151
162
|
return null;
|
|
152
163
|
}
|
|
153
164
|
// console.log(obj);
|
|
154
|
-
const res = getComponent(
|
|
165
|
+
const res = getComponent(obj, componentType);
|
|
155
166
|
if (res) return res;
|
|
156
|
-
|
|
167
|
+
if (obj.parent)
|
|
168
|
+
return getComponentInParent(obj.parent, componentType);
|
|
169
|
+
return null;
|
|
157
170
|
}
|
|
158
171
|
|
|
159
|
-
|
|
172
|
+
export function getComponentsInParent<T>(obj: Object3D, componentType: Constructor<T>, arr?: T[] | null): T[] {
|
|
160
173
|
if (!arr) arr = [];
|
|
161
174
|
if (!obj) return arr;
|
|
162
|
-
getComponents(
|
|
163
|
-
|
|
175
|
+
getComponents(obj, componentType, arr);
|
|
176
|
+
if (obj.parent)
|
|
177
|
+
return getComponentsInParent(obj.parent, componentType, arr);
|
|
178
|
+
return arr;
|
|
164
179
|
}
|
|
165
180
|
|
|
166
|
-
|
|
181
|
+
export function findObjectOfType<T>(type: Constructor<T>, contextOrScene: Object3D | { scene: Scene }, includeInactive) {
|
|
167
182
|
if (!type) return null;
|
|
168
183
|
if (!contextOrScene) {
|
|
169
184
|
contextOrScene = Context.Current;
|
|
@@ -172,18 +187,23 @@ const findObjectOfType = function (type, contextOrScene, includeInactive) {
|
|
|
172
187
|
return null;
|
|
173
188
|
}
|
|
174
189
|
}
|
|
175
|
-
|
|
190
|
+
|
|
191
|
+
let scene = contextOrScene as Scene;
|
|
192
|
+
if (!scene.isScene) scene = (contextOrScene as { scene: Scene })?.scene;
|
|
193
|
+
if (!scene) return null;
|
|
194
|
+
|
|
195
|
+
// const scene = contextOrScene.isScene === true || contextOrScene.isObject3D === true ? contextOrScene : contextOrScene?.scene;
|
|
176
196
|
for (const i in scene.children) {
|
|
177
197
|
const child = scene.children[i];
|
|
178
198
|
if (includeInactive === false && child[activeInHierarchyFieldName] === false) continue;
|
|
179
199
|
if (child.constructor == type) return child;
|
|
180
|
-
const res = getComponentInChildren(
|
|
200
|
+
const res = getComponentInChildren(child, type);
|
|
181
201
|
if (res) return res;
|
|
182
202
|
}
|
|
183
203
|
return null;
|
|
184
204
|
}
|
|
185
205
|
|
|
186
|
-
|
|
206
|
+
export function findObjectsOfType<T>(type: Constructor<T>, array: T[], contextOrScene) : T[] {
|
|
187
207
|
if (!type) return array;
|
|
188
208
|
if (!contextOrScene) {
|
|
189
209
|
contextOrScene = Context.Current;
|
|
@@ -197,22 +217,7 @@ const findObjectsOfType = function (type, array, contextOrScene) {
|
|
|
197
217
|
for (const i in scene.children) {
|
|
198
218
|
const child = scene.children[i];
|
|
199
219
|
if (child.constructor == type) return child;
|
|
200
|
-
getComponentsInChildren(
|
|
220
|
+
getComponentsInChildren(child, type, array);
|
|
201
221
|
}
|
|
202
222
|
return array;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
export {
|
|
207
|
-
addNewComponentInstance,
|
|
208
|
-
moveComponentInstance,
|
|
209
|
-
destroyComponentInstance,
|
|
210
|
-
getComponent,
|
|
211
|
-
getComponents,
|
|
212
|
-
getComponentInChildren,
|
|
213
|
-
getComponentsInChildren,
|
|
214
|
-
getComponentInParent,
|
|
215
|
-
getComponentsInParent,
|
|
216
|
-
findObjectOfType,
|
|
217
|
-
findObjectsOfType,
|
|
218
223
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Context, build_scene_functions, LoadingOptions, LoadingProgressArgs } from "./engine_setup";
|
|
2
2
|
import { AROverlayHandler, arContainerClassName } from "./engine_element_overlay";
|
|
3
3
|
import { GameObject } from "../engine-components/Component";
|
|
4
|
-
import { loadSync } from "./engine_scenetools";
|
|
5
4
|
import { processNewScripts } from "./engine_mainloop_utils";
|
|
6
5
|
import { calculateProgress01, EngineLoadingView, ILoadingViewHandler } from "./engine_element_loading";
|
|
7
6
|
import { delay, getParam } from "./engine_utils";
|
|
8
7
|
import { setDracoDecoderPath, setDracoDecoderType, setKtx2TranscoderPath } from "./engine_loaders";
|
|
8
|
+
import { getLoader } from "../engine/engine_gltf";
|
|
9
9
|
|
|
10
10
|
const debug = getParam("debugwebcomponent");
|
|
11
11
|
|
|
@@ -42,7 +42,7 @@ class EngineElementSourceFileWatcher {
|
|
|
42
42
|
|
|
43
43
|
this.previousSource = newSource;
|
|
44
44
|
Context.Current = this.context;
|
|
45
|
-
const res = await loadSync(this.context, newSource, this.getHashFromString(newSource));
|
|
45
|
+
const res = await getLoader().loadSync(this.context, newSource, this.getHashFromString(newSource), false);
|
|
46
46
|
if (!isStartup)
|
|
47
47
|
processNewScripts(this.context);
|
|
48
48
|
const obj = res?.scene;
|
|
@@ -162,13 +162,14 @@ export class EngineElement extends HTMLElement {
|
|
|
162
162
|
if (fn) {
|
|
163
163
|
this.classList.add("loading");
|
|
164
164
|
console.log("Needle Engine: Begin loading", alias ?? "");
|
|
165
|
+
const allowOverridingDefaultLoading = false;
|
|
165
166
|
// default loading can be overriden by calling preventDefault in the onload start event
|
|
166
167
|
const useDefaultLoading = this.dispatchEvent(new CustomEvent("loadstart", {
|
|
167
168
|
detail: {
|
|
168
169
|
context: this._context,
|
|
169
170
|
alias: alias
|
|
170
171
|
},
|
|
171
|
-
cancelable:
|
|
172
|
+
cancelable: allowOverridingDefaultLoading
|
|
172
173
|
}));
|
|
173
174
|
if (!this._loadingView && useDefaultLoading)
|
|
174
175
|
this._loadingView = new EngineLoadingView(this);
|
|
@@ -127,6 +127,8 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
127
127
|
|
|
128
128
|
private createLoadingElement(existing?: HTMLElement): HTMLElement {
|
|
129
129
|
this._loadingElement = existing || document.createElement("div");
|
|
130
|
+
this._loadingElement.style.width = "100%";
|
|
131
|
+
|
|
130
132
|
const className = this._loadingElementOptions?.className ?? "loading";
|
|
131
133
|
this._loadingElement.classList.add(className);
|
|
132
134
|
if (this._loadingElementOptions?.additionalClasses) {
|
|
@@ -141,7 +143,7 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
const loadingBarContainer = document.createElement("div");
|
|
144
|
-
const maxWidth =
|
|
146
|
+
const maxWidth = 30;
|
|
145
147
|
loadingBarContainer.style.display = "flex";
|
|
146
148
|
loadingBarContainer.style.width = maxWidth + "%";
|
|
147
149
|
loadingBarContainer.style.height = "2px";
|
|
@@ -171,6 +173,8 @@ export class EngineLoadingView implements ILoadingViewHandler {
|
|
|
171
173
|
messageContainer.style.fontSize = ".8em";
|
|
172
174
|
messageContainer.style.paddingTop = ".5em";
|
|
173
175
|
messageContainer.style.color = "rgba(255,255,255,.5)";
|
|
176
|
+
// messageContainer.style.border = "1px solid rgba(255,255,255,.1)";
|
|
177
|
+
messageContainer.style.justifyContent = "center";
|
|
174
178
|
this._loadingElement.appendChild(messageContainer);
|
|
175
179
|
|
|
176
180
|
return this._loadingElement;
|