@needle-tools/engine 2.34.0-pre → 2.35.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 +11 -0
- package/dist/needle-engine.d.ts +2960 -2794
- package/dist/needle-engine.js +456 -456
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +67 -67
- 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 +16 -0
- package/lib/engine/engine_components.js +223 -0
- package/lib/engine/engine_components.js.map +1 -0
- package/lib/engine/engine_element.js +2 -2
- package/lib/engine/engine_element.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 +2 -11
- package/lib/engine/engine_networking.js +1 -7
- 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 +1 -25
- package/lib/engine/engine_physics.js +17 -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 +103 -0
- package/lib/engine/engine_types.js +49 -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/Component.d.ts +16 -50
- 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/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 +16 -41
- 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} +37 -47
- package/src/engine/engine_element.ts +2 -2
- 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 +3 -14
- 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 +20 -82
- 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 +180 -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/Component.ts +83 -536
- 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/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 +22 -48
- 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,22 +1,15 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
|
-
import * as object from "../engine/engine_components"
|
|
3
2
|
import { Mathf } from "../engine/engine_math";
|
|
4
3
|
import * as threeutils from "../engine/engine_three_utils";
|
|
5
|
-
import * as utils from "../engine/engine_utils";
|
|
6
4
|
import { activeInHierarchyFieldName } from "../engine/engine_constants";
|
|
7
5
|
import { Context, FrameEvent } from "../engine/engine_setup";
|
|
8
6
|
import * as main from "../engine/engine_mainloop_utils";
|
|
9
7
|
import { Object3D } from "three";
|
|
10
|
-
import {
|
|
11
|
-
import { SourceIdentifier } from "../engine/
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export interface UIDProvider {
|
|
17
|
-
seed: number;
|
|
18
|
-
generateUUID(): string;
|
|
19
|
-
}
|
|
8
|
+
import { syncDestroy, syncInstantiate } from "../engine/engine_networking_instantiate";
|
|
9
|
+
import { ConstructorConcrete, SourceIdentifier, IComponent, IGameObject, Constructor, GuidsMap, UIDProvider, Collision } from "../engine/engine_types";
|
|
10
|
+
import { addNewComponentInstance, destroyComponentInstance, findObjectOfType, findObjectsOfType, getComponent, getComponentInChildren, getComponentInParent, getComponents, getComponentsInChildren, getComponentsInParent, getOrAddComponent, moveComponentInstance, removeComponent } from "../engine/engine_components";
|
|
11
|
+
import { findByGuid, destroy, InstantiateOptions, instantiate, HideFlags, foreachComponent, markAsInstancedRendered, isActiveInHierarchy, isActiveSelf, isUsingInstancing } from "../engine/engine_gameobject";
|
|
12
|
+
|
|
20
13
|
|
|
21
14
|
// export interface ISerializationCallbackReceiver {
|
|
22
15
|
// onBeforeSerialize?(): object | void;
|
|
@@ -26,54 +19,7 @@ export interface UIDProvider {
|
|
|
26
19
|
// onDeserialize?(key: string, value: any): any | void;
|
|
27
20
|
// }
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export enum HideFlags {
|
|
32
|
-
None = 0,
|
|
33
|
-
HideInHierarchy = 1,
|
|
34
|
-
HideInInspector = 2,
|
|
35
|
-
DontSaveInEditor = 4,
|
|
36
|
-
NotEditable = 8,
|
|
37
|
-
DontSaveInBuild = 16, // 0x00000010
|
|
38
|
-
DontUnloadUnusedAsset = 32, // 0x00000020
|
|
39
|
-
DontSave = DontUnloadUnusedAsset | DontSaveInBuild | DontSaveInEditor, // 0x00000034
|
|
40
|
-
HideAndDontSave = DontSave | NotEditable | HideInHierarchy, // 0x0000003D
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// TODO: figure out what is best here!
|
|
44
|
-
// https://stackoverflow.com/a/67229348
|
|
45
|
-
// https://stackoverflow.com/questions/36886082/abstract-constructor-type-in-typescript
|
|
46
|
-
// type Constructor<T> = Function & { prototype: T } // << this includes abstract constructor types
|
|
47
|
-
export type Constructor<T> = abstract new (...args: any[]) => T; // abstract to support @serializable and also getComponent with abstract types
|
|
48
|
-
export type ConstructorConcrete<T> = new (...args: any[]) => T;
|
|
49
|
-
|
|
50
|
-
export type GuidsMap = { [key: string]: string };
|
|
51
|
-
|
|
52
|
-
type FunctionName = string;
|
|
53
|
-
|
|
54
|
-
export class InstantiateOptions {
|
|
55
|
-
idProvider?: UIDProvider | undefined;
|
|
56
|
-
|
|
57
|
-
//** parent guid */
|
|
58
|
-
parent?: string | undefined | Object3D;
|
|
59
|
-
/** for duplicatable parenting */
|
|
60
|
-
keepWorldPosition?: boolean
|
|
61
|
-
position?: THREE.Vector3 | undefined;
|
|
62
|
-
rotation?: THREE.Quaternion | undefined;
|
|
63
|
-
scale?: THREE.Vector3 | undefined;
|
|
64
|
-
|
|
65
|
-
visible?: boolean | undefined;
|
|
66
|
-
|
|
67
|
-
context?: Context | undefined;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
declare class NewGameObjectReferenceInfo {
|
|
71
|
-
original: THREE.Object3D;
|
|
72
|
-
clone: THREE.Object3D;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
abstract class GameObject extends THREE.Object3D implements THREE.Object3D {
|
|
22
|
+
abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGameObject {
|
|
77
23
|
|
|
78
24
|
guid: string | undefined;
|
|
79
25
|
|
|
@@ -86,450 +32,41 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D {
|
|
|
86
32
|
}
|
|
87
33
|
|
|
88
34
|
public static isActiveSelf(go: THREE.Object3D): boolean {
|
|
89
|
-
return
|
|
35
|
+
return isActiveSelf(go);
|
|
90
36
|
}
|
|
91
37
|
|
|
92
38
|
public static isActiveInHierarchy(go: THREE.Object3D): boolean {
|
|
93
|
-
return
|
|
39
|
+
return isActiveInHierarchy(go);
|
|
94
40
|
}
|
|
95
41
|
|
|
96
42
|
public static markAsInstancedRendered(go: THREE.Object3D, instanced: boolean) {
|
|
97
|
-
go
|
|
43
|
+
markAsInstancedRendered(go, instanced);
|
|
98
44
|
}
|
|
99
45
|
|
|
100
|
-
public static isUsingInstancing(instance: THREE.Object3D): boolean { return
|
|
46
|
+
public static isUsingInstancing(instance: THREE.Object3D): boolean { return isUsingInstancing(instance); }
|
|
101
47
|
|
|
102
48
|
public static foreachComponent(instance: THREE.Object3D, cb: (comp: Component) => any, recursive: boolean = true): any {
|
|
103
|
-
|
|
104
|
-
if (instance.userData.components) {
|
|
105
|
-
for (let i = 0; i < instance.userData.components.length; i++) {
|
|
106
|
-
const comp = instance.userData.components[i];
|
|
107
|
-
if (comp instanceof Behaviour) {
|
|
108
|
-
const res = cb(comp);
|
|
109
|
-
if (res !== undefined) return res;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (recursive && instance.children) {
|
|
115
|
-
for (let i = 0; i < instance.children.length; i++) {
|
|
116
|
-
const child = instance.children[i];
|
|
117
|
-
if (!child) continue;
|
|
118
|
-
const res = GameObject.foreachComponent(child, cb, recursive);
|
|
119
|
-
if (res !== undefined) return res;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
public static instantiateSynced(instance: GameObject | THREE.Object3D | null, opts: InstantiateOptions): GameObject | null {
|
|
125
|
-
if (!instance) return null;
|
|
126
|
-
return syncInstantiate(instance, opts);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public static instantiate(instance: GameObject | THREE.Object3D | null, opts: InstantiateOptions | null = null): GameObject | null {
|
|
130
|
-
if (instance === null) return null;
|
|
131
|
-
|
|
132
|
-
let options: InstantiateOptions | null = null;
|
|
133
|
-
if (opts !== null) {
|
|
134
|
-
// if x is defined assume this is a vec3 - this is just to not break everything at once and stay a little bit backwards compatible
|
|
135
|
-
if (opts["x"] !== undefined) {
|
|
136
|
-
options = new InstantiateOptions();
|
|
137
|
-
options.position = opts as unknown as THREE.Vector3;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
// if (opts instanceof InstantiateOptions)
|
|
141
|
-
options = opts as InstantiateOptions;
|
|
142
|
-
// else {
|
|
143
|
-
// options = new InstantiateOptions();
|
|
144
|
-
// Object.assign(options, opts);
|
|
145
|
-
// }
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
let context = Context.Current;
|
|
150
|
-
if (options?.context) context = options.context;
|
|
151
|
-
if (debug && context.alias)
|
|
152
|
-
console.log("context", context.alias);
|
|
153
|
-
|
|
154
|
-
// we need to create the id provider before calling internal instantiate because cloned gameobjects also create new guids
|
|
155
|
-
if (options && !options.idProvider) {
|
|
156
|
-
options.idProvider = new InstantiateIdProvider(Date.now());
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const components: Array<Behaviour> = [];
|
|
160
|
-
const goMapping: { [key: string]: NewGameObjectReferenceInfo } = {}; // used to resolve references on components to components on other gameobjects to their new counterpart
|
|
161
|
-
const skinnedMeshes: { [key: string]: NewGameObjectReferenceInfo } = {};
|
|
162
|
-
const clone = this.internalInstantiate(context, instance, options, components, goMapping, skinnedMeshes);
|
|
163
|
-
|
|
164
|
-
if (clone) {
|
|
165
|
-
this.resolveReferences(goMapping);
|
|
166
|
-
this.resolveAndBindSkinnedMeshBones(skinnedMeshes, goMapping);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (debug) {
|
|
170
|
-
threeutils.logHierarchy(instance, true);
|
|
171
|
-
threeutils.logHierarchy(clone, true);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const guidsMap: GuidsMap = {};
|
|
175
|
-
for (const i in components) {
|
|
176
|
-
const copy = components[i];
|
|
177
|
-
const oldGuid = copy.guid;
|
|
178
|
-
if (options && options.idProvider) {
|
|
179
|
-
copy.guid = options.idProvider.generateUUID();
|
|
180
|
-
guidsMap[oldGuid] = copy.guid;
|
|
181
|
-
if (debug)
|
|
182
|
-
console.log(copy.name, copy.guid)
|
|
183
|
-
}
|
|
184
|
-
object.registerComponent(copy, context);
|
|
185
|
-
if (copy.__internalNewInstanceCreated)
|
|
186
|
-
copy.__internalNewInstanceCreated();
|
|
187
|
-
}
|
|
188
|
-
for (const i in components) {
|
|
189
|
-
const copy = components[i];
|
|
190
|
-
if (copy.resolveGuids)
|
|
191
|
-
copy.resolveGuids(guidsMap);
|
|
192
|
-
if (copy.enabled === false) continue;
|
|
193
|
-
else copy.enabled = true;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
main.processNewScripts(context);
|
|
197
|
-
|
|
198
|
-
return clone as GameObject;
|
|
49
|
+
return foreachComponent(instance, cb as (comp : IComponent) => any, recursive);
|
|
199
50
|
}
|
|
200
51
|
|
|
201
|
-
|
|
202
|
-
context: Context, instance: GameObject | THREE.Object3D, opts: InstantiateOptions | null,
|
|
203
|
-
componentsList: Array<Behaviour>,
|
|
204
|
-
newGameObjectsMap: { [key: string]: NewGameObjectReferenceInfo },
|
|
205
|
-
skinnedMeshesMap: { [key: string]: NewGameObjectReferenceInfo }
|
|
206
|
-
)
|
|
207
|
-
: GameObject | THREE.Object3D | null {
|
|
52
|
+
public static instantiateSynced(instance: GameObject | Object3D | null, opts: InstantiateOptions): GameObject | null {
|
|
208
53
|
if (!instance) return null;
|
|
209
|
-
|
|
210
|
-
// e.g. user data we want to manually clone
|
|
211
|
-
// also children throw errors (e.g. recursive toJson with nested meshes)
|
|
212
|
-
const userData = instance.userData;
|
|
213
|
-
instance.userData = {};
|
|
214
|
-
const children = instance.children;
|
|
215
|
-
instance.children = [];
|
|
216
|
-
let clone: THREE.Object3D | GameObject;
|
|
217
|
-
clone = instance.clone(false);
|
|
218
|
-
Object3DExtensions.apply(clone);
|
|
219
|
-
instance.userData = userData;
|
|
220
|
-
instance.children = children;
|
|
221
|
-
|
|
222
|
-
// make reference from old id to new object
|
|
223
|
-
newGameObjectsMap[instance.uuid] = { original: instance, clone: clone };
|
|
224
|
-
|
|
225
|
-
if (instance.type === "SkinnedMesh") {
|
|
226
|
-
skinnedMeshesMap[instance.uuid] = { original: instance, clone: clone };
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// DO NOT EVER RENAME BECAUSE IT BREAKS / MIGHT BREAK ANIMATIONS
|
|
230
|
-
// clone.name += " (Clone)";
|
|
231
|
-
|
|
232
|
-
if (opts?.visible !== undefined)
|
|
233
|
-
clone.visible = opts.visible;
|
|
234
|
-
|
|
235
|
-
if (opts?.idProvider) {
|
|
236
|
-
clone.uuid = opts.idProvider.generateUUID();
|
|
237
|
-
const cloneGo: GameObject = clone as GameObject;
|
|
238
|
-
if (cloneGo) cloneGo.guid = clone.uuid;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (instance.animations && instance.animations.length > 0) {
|
|
242
|
-
clone.animations = [...instance.animations];
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const parent = instance.parent;
|
|
246
|
-
if (parent) {
|
|
247
|
-
parent.add(clone);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// apply transform
|
|
251
|
-
if (opts?.position) {
|
|
252
|
-
threeutils.setWorldPosition(clone, opts.position);
|
|
253
|
-
}
|
|
254
|
-
else clone.position.copy(instance.position);
|
|
255
|
-
if (opts?.rotation) {
|
|
256
|
-
threeutils.setWorldQuaternion(clone, opts.rotation);
|
|
257
|
-
// clone.quaternion.copy(opts.rotation);
|
|
258
|
-
}
|
|
259
|
-
else clone.quaternion.copy(instance.quaternion);
|
|
260
|
-
if (opts?.scale) {
|
|
261
|
-
// TODO: make set world scale work
|
|
262
|
-
clone.scale.copy(opts.scale);
|
|
263
|
-
}
|
|
264
|
-
else clone.scale.copy(instance.scale);
|
|
265
|
-
|
|
266
|
-
if (opts?.parent && opts.parent !== "scene") {
|
|
267
|
-
let requestedParent: Object3D | null = null;
|
|
268
|
-
if (typeof opts.parent === "string") {
|
|
269
|
-
requestedParent = utils.tryFindObject(opts.parent, context.scene, true);
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
requestedParent = opts.parent;
|
|
273
|
-
}
|
|
274
|
-
if (requestedParent) {
|
|
275
|
-
const func = opts.keepWorldPosition === true ? requestedParent.attach : requestedParent.add;
|
|
276
|
-
if (!func) console.error("Invalid parent object", requestedParent, "received when instantiating:", instance);
|
|
277
|
-
else func.call(requestedParent, clone);
|
|
278
|
-
}
|
|
279
|
-
else console.warn("could not find parent:", opts.parent);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
for (const [key, value] of Object.entries(instance.userData)) {
|
|
283
|
-
if (key === "components") continue;
|
|
284
|
-
clone.userData[key] = value;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (instance.userData?.components) {
|
|
288
|
-
const components = instance.userData.components;
|
|
289
|
-
const newComponents: Behaviour[] = [];
|
|
290
|
-
clone.userData.components = newComponents;
|
|
291
|
-
for (let i = 0; i < components.length; i++) {
|
|
292
|
-
const comp = components[i];
|
|
293
|
-
const copy = Object.create(comp);
|
|
294
|
-
Object.assign(copy, comp);
|
|
295
|
-
newComponents.push(copy);
|
|
296
|
-
copy.gameObject = clone;
|
|
297
|
-
// copy.transform = clone;
|
|
298
|
-
componentsList.push(copy);
|
|
299
|
-
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// children should just clone the original transform
|
|
304
|
-
if (opts) {
|
|
305
|
-
opts.position = undefined;
|
|
306
|
-
opts.rotation = undefined;
|
|
307
|
-
opts.scale = undefined;
|
|
308
|
-
opts.parent = undefined;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
for (const ch in instance.children) {
|
|
312
|
-
const child = instance.children[ch];
|
|
313
|
-
const newChild = GameObject.internalInstantiate(context, child as GameObject, opts, componentsList, newGameObjectsMap, skinnedMeshesMap);
|
|
314
|
-
if (newChild)
|
|
315
|
-
clone.add(newChild);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return clone;
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
private static resolveAndBindSkinnedMeshBones(
|
|
323
|
-
skinnedMeshes: { [key: string]: NewGameObjectReferenceInfo },
|
|
324
|
-
newObjectsMap: { [key: string]: NewGameObjectReferenceInfo }
|
|
325
|
-
) {
|
|
326
|
-
for (const key in skinnedMeshes) {
|
|
327
|
-
const val = skinnedMeshes[key];
|
|
328
|
-
const original = val.original as THREE.SkinnedMesh;
|
|
329
|
-
const originalSkeleton = original.skeleton;
|
|
330
|
-
const clone = val.clone as THREE.SkinnedMesh;
|
|
331
|
-
// clone.updateWorldMatrix(true, true);
|
|
332
|
-
if (!originalSkeleton) {
|
|
333
|
-
console.warn("Skinned mesh has no skeleton?", val);
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
const originalBones = originalSkeleton.bones;
|
|
337
|
-
const clonedSkeleton = clone.skeleton.clone();
|
|
338
|
-
|
|
339
|
-
clone.skeleton = clonedSkeleton;
|
|
340
|
-
clone.bindMatrix.clone().copy(original.bindMatrix);
|
|
341
|
-
// console.log(clone.bindMatrix)
|
|
342
|
-
clone.bindMatrixInverse.copy(original.bindMatrixInverse);
|
|
343
|
-
// clone.bindMatrix.multiplyScalar(.025);
|
|
344
|
-
// console.assert(originalSkeleton.uuid !== clonedSkeleton.uuid);
|
|
345
|
-
// console.assert(originalBones.length === clonedSkeleton.bones.length);
|
|
346
|
-
const bones: Array<THREE.Bone> = [];
|
|
347
|
-
clonedSkeleton.bones = bones;
|
|
348
|
-
for (let i = 0; i < originalBones.length; i++) {
|
|
349
|
-
const bone = originalBones[i];
|
|
350
|
-
const newBoneInfo = newObjectsMap[bone.uuid];
|
|
351
|
-
const clonedBone = newBoneInfo.clone as THREE.Bone;
|
|
352
|
-
// console.log("NEW BONE: ", clonedBone, "BEFORE", newBoneInfo.original);
|
|
353
|
-
bones.push(clonedBone);
|
|
354
|
-
}
|
|
355
|
-
// clone.skeleton = new THREE.Skeleton(bones);
|
|
356
|
-
// clone.skeleton.update();
|
|
357
|
-
// clone.pose();
|
|
358
|
-
// clone.scale.set(1,1,1);
|
|
359
|
-
// clone.position.y += .1;
|
|
360
|
-
// console.log("ORIG", original, "CLONE", clone);
|
|
361
|
-
}
|
|
362
|
-
for (const key in skinnedMeshes) {
|
|
363
|
-
const clone = skinnedMeshes[key].clone as THREE.SkinnedMesh;
|
|
364
|
-
clone.skeleton.update();
|
|
365
|
-
// clone.skeleton.calculateInverses();
|
|
366
|
-
clone.bind(clone.skeleton, clone.bindMatrix);
|
|
367
|
-
clone.updateMatrixWorld(true);
|
|
368
|
-
// clone.pose();
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// private static bindNewSkinnedMeshBones(source, clone) {
|
|
373
|
-
// const sourceLookup = new Map();
|
|
374
|
-
// const cloneLookup = new Map();
|
|
375
|
-
// // const clone = source.clone(false);
|
|
376
|
-
|
|
377
|
-
// function parallelTraverse(a, b, callback) {
|
|
378
|
-
// callback(a, b);
|
|
379
|
-
// for (let i = 0; i < a.children.length; i++) {
|
|
380
|
-
// parallelTraverse(a.children[i], b.children[i], callback);
|
|
381
|
-
// }
|
|
382
|
-
// }
|
|
383
|
-
// parallelTraverse(source, clone, function (sourceNode, clonedNode) {
|
|
384
|
-
// sourceLookup.set(clonedNode, sourceNode);
|
|
385
|
-
// cloneLookup.set(sourceNode, clonedNode);
|
|
386
|
-
// });
|
|
387
|
-
|
|
388
|
-
// clone.traverse(function (node) {
|
|
389
|
-
// if (!node.isSkinnedMesh) return;
|
|
390
|
-
// const clonedMesh = node;
|
|
391
|
-
// const sourceMesh = sourceLookup.get(node);
|
|
392
|
-
// const sourceBones = sourceMesh.skeleton.bones;
|
|
393
|
-
|
|
394
|
-
// clonedMesh.skeleton = sourceMesh.skeleton.clone();
|
|
395
|
-
// clonedMesh.bindMatrix.copy(sourceMesh.bindMatrix);
|
|
396
|
-
|
|
397
|
-
// clonedMesh.skeleton.bones = sourceBones.map(function (bone) {
|
|
398
|
-
// return cloneLookup.get(bone);
|
|
399
|
-
// });
|
|
400
|
-
// clonedMesh.bind(clonedMesh.skeleton, clonedMesh.bindMatrix);
|
|
401
|
-
// });
|
|
402
|
-
// return clone;
|
|
403
|
-
|
|
404
|
-
// }
|
|
405
|
-
|
|
406
|
-
private static resolveReferences(newObjectsMap: { [key: string]: NewGameObjectReferenceInfo }) {
|
|
407
|
-
// for every object that is newly created we want to update references to their newly created counterparts
|
|
408
|
-
// e.g. a collider instance referencing a rigidbody instance should be updated so that
|
|
409
|
-
// the cloned collider does not reference the cloned rigidbody (instead of the original rigidbody)
|
|
410
|
-
for (const key in newObjectsMap) {
|
|
411
|
-
const val = newObjectsMap[key];
|
|
412
|
-
const clone = val.clone;
|
|
413
|
-
// resolve references
|
|
414
|
-
if (clone.userData?.components) {
|
|
415
|
-
for (let i = 0; i < clone.userData.components.length; i++) {
|
|
416
|
-
const copy = clone.userData.components[i];
|
|
417
|
-
// find referenced within a cloned gameobject
|
|
418
|
-
const entries = Object.entries(copy);
|
|
419
|
-
// console.log(copy, entries);
|
|
420
|
-
for (const [key, value] of entries) {
|
|
421
|
-
if (Array.isArray(value)) {
|
|
422
|
-
const clonedArray: Array<any> = [];
|
|
423
|
-
copy[key] = clonedArray;
|
|
424
|
-
// console.log(copy, key, value, copy[key]);
|
|
425
|
-
for (let i = 0; i < value.length; i++) {
|
|
426
|
-
const entry = value[i];
|
|
427
|
-
// push value types into new array
|
|
428
|
-
if (typeof entry !== "object") {
|
|
429
|
-
clonedArray.push(entry);
|
|
430
|
-
continue;
|
|
431
|
-
}
|
|
432
|
-
const res: any = this.postProcessNewInstance(copy, key, entry, newObjectsMap);
|
|
433
|
-
if (res !== undefined)
|
|
434
|
-
clonedArray.push(res);
|
|
435
|
-
else clonedArray.push(entry);
|
|
436
|
-
}
|
|
437
|
-
// console.log(copy[key])
|
|
438
|
-
}
|
|
439
|
-
else if (typeof value === "object") {
|
|
440
|
-
const res = this.postProcessNewInstance(copy, key, value, newObjectsMap);
|
|
441
|
-
if (res !== undefined) {
|
|
442
|
-
copy[key] = res;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
54
|
+
return syncInstantiate(instance as any, opts) as GameObject | null;
|
|
450
55
|
}
|
|
451
56
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
const originalGameObjectReference = value["gameObject"];
|
|
455
|
-
// console.log(key, value, originalGameObjectReference);
|
|
456
|
-
if (originalGameObjectReference) {
|
|
457
|
-
const id = originalGameObjectReference.uuid;
|
|
458
|
-
const newGameObject = newObjectsMap[id]?.clone;
|
|
459
|
-
if (!newGameObject) {
|
|
460
|
-
// reference has not changed!
|
|
461
|
-
if (debug)
|
|
462
|
-
console.log("reference did not change", key, copy, value);
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
const index = originalGameObjectReference.userData.components.indexOf(value);
|
|
466
|
-
if (index >= 0) {
|
|
467
|
-
if (debug)
|
|
468
|
-
console.log(key, id);
|
|
469
|
-
const found = newGameObject.userData.components[index];
|
|
470
|
-
return found;
|
|
471
|
-
}
|
|
472
|
-
else {
|
|
473
|
-
console.warn("could not find component", key, value);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
} else if (value instanceof THREE.Object3D) {
|
|
477
|
-
// console.log(value);
|
|
478
|
-
if (key === "gameObject") return;
|
|
479
|
-
const originalGameObjectReference = value;
|
|
480
|
-
if (originalGameObjectReference) {
|
|
481
|
-
const id = originalGameObjectReference.uuid;
|
|
482
|
-
const newGameObject = newObjectsMap[id]?.clone;
|
|
483
|
-
if (newGameObject) {
|
|
484
|
-
if (debug)
|
|
485
|
-
console.log(key, "old", value, "new", newGameObject);
|
|
486
|
-
return newGameObject;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
57
|
+
public static instantiate(instance: GameObject | Object3D | null, opts: InstantiateOptions | null = null): GameObject | null {
|
|
58
|
+
return instantiate(instance, opts) as GameObject | null;
|
|
490
59
|
}
|
|
491
60
|
|
|
492
61
|
public static destroySynced(instance: THREE.Object3D | Component, context?: Context, recursive: boolean = true) {
|
|
493
62
|
if (!instance) return;
|
|
494
63
|
const go = instance as GameObject;
|
|
495
64
|
context = context ?? Context.Current;
|
|
496
|
-
syncDestroy(go, context.connection, recursive);
|
|
65
|
+
syncDestroy(go as any, context.connection, recursive);
|
|
497
66
|
}
|
|
498
67
|
|
|
499
68
|
public static destroy(instance: THREE.Object3D | Component, recursive: boolean = true, isRoot: boolean = true) {
|
|
500
|
-
|
|
501
|
-
if (comp.isComponent) {
|
|
502
|
-
comp.destroy();
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
const obj = instance as GameObject;
|
|
507
|
-
if (debug) console.log(obj);
|
|
508
|
-
|
|
509
|
-
if (recursive && obj.children) {
|
|
510
|
-
for (const ch of obj.children) {
|
|
511
|
-
GameObject.destroy(ch, recursive, false);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
const components = obj.userData.components;
|
|
516
|
-
if (components) {
|
|
517
|
-
let lastLength = components.length;
|
|
518
|
-
for (let i = 0; i < components.length; i++) {
|
|
519
|
-
const comp: Behaviour = components[i];
|
|
520
|
-
if (comp.destroy) {
|
|
521
|
-
if (debug) console.log("destroying", comp);
|
|
522
|
-
comp.destroy();
|
|
523
|
-
}
|
|
524
|
-
// components will be removed from componentlist in destroy
|
|
525
|
-
if (components.length < lastLength) {
|
|
526
|
-
lastLength = components.length;
|
|
527
|
-
i--;
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
if (isRoot)
|
|
532
|
-
obj.removeFromParent();
|
|
69
|
+
return destroy(instance, recursive, isRoot);
|
|
533
70
|
}
|
|
534
71
|
|
|
535
72
|
/**
|
|
@@ -570,11 +107,11 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D {
|
|
|
570
107
|
}, true);
|
|
571
108
|
}
|
|
572
109
|
|
|
573
|
-
public static invokeOnChildren(go: THREE.Object3D | null | undefined, functionName: string
|
|
110
|
+
public static invokeOnChildren(go: THREE.Object3D | null | undefined, functionName: string, ...args: any) {
|
|
574
111
|
this.invoke(go, functionName, true, args);
|
|
575
112
|
}
|
|
576
113
|
|
|
577
|
-
public static invoke(go: THREE.Object3D | null | undefined, functionName: string
|
|
114
|
+
public static invoke(go: THREE.Object3D | null | undefined, functionName: string, children: boolean = false, ...args: any) {
|
|
578
115
|
if (!go) return;
|
|
579
116
|
// console.log(go);
|
|
580
117
|
this.foreachComponent(go, c => {
|
|
@@ -589,26 +126,25 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D {
|
|
|
589
126
|
|
|
590
127
|
public static addNewComponent<T extends Behaviour>(go: GameObject | THREE.Object3D, type: ConstructorConcrete<T>, callAwake: boolean = true): T {
|
|
591
128
|
const instance = new type();
|
|
592
|
-
|
|
593
|
-
|
|
129
|
+
//@ts-ignore
|
|
130
|
+
addNewComponentInstance(go, instance, callAwake);
|
|
131
|
+
return instance
|
|
594
132
|
}
|
|
595
133
|
|
|
596
134
|
public static addComponent(go: GameObject, instance: Component): void {
|
|
597
135
|
if (instance.gameObject == null) {
|
|
598
136
|
throw new Error("Did you mean to create a new component? Use addNewComponent");
|
|
599
137
|
}
|
|
600
|
-
|
|
138
|
+
moveComponentInstance(instance as any, go);
|
|
601
139
|
}
|
|
602
140
|
|
|
603
141
|
public static removeComponent(instance: Component): Component {
|
|
604
|
-
|
|
142
|
+
removeComponent(instance.gameObject, instance as any);
|
|
605
143
|
return instance;
|
|
606
144
|
}
|
|
607
145
|
|
|
608
|
-
public static getOrAddComponent<T>(go: GameObject | THREE.Object3D, typeName:
|
|
609
|
-
|
|
610
|
-
if (comp) return comp;
|
|
611
|
-
return this.addNewComponent(go, typeName as unknown as ConstructorConcrete<Behaviour>) as unknown as T;
|
|
146
|
+
public static getOrAddComponent<T extends IComponent>(go: GameObject | THREE.Object3D, typeName: ConstructorConcrete<T>): T {
|
|
147
|
+
return getOrAddComponent<any>(go, typeName);
|
|
612
148
|
}
|
|
613
149
|
|
|
614
150
|
public static getComponent<T>(go: GameObject | THREE.Object3D | null, typeName: Constructor<T> | null): T | null {
|
|
@@ -617,42 +153,43 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D {
|
|
|
617
153
|
// not ideal, but I dont know a good/sane way to do this otherwise
|
|
618
154
|
// const res = TypeStore.get(typeName);
|
|
619
155
|
// if(res) typeName = res;
|
|
620
|
-
return
|
|
156
|
+
return getComponent(typeName as any, go);
|
|
621
157
|
}
|
|
622
158
|
|
|
623
159
|
public static getComponents<T>(go: GameObject | THREE.Object3D | null, typeName: Constructor<T> | null, arr: T[] | null = null): T[] {
|
|
624
160
|
if (go === null) return arr ?? [];
|
|
625
|
-
return
|
|
161
|
+
return getComponents(typeName, go, arr);
|
|
626
162
|
}
|
|
627
163
|
|
|
628
|
-
public static findByGuid(guid: string, hierarchy: THREE.Object3D): GameObject |
|
|
629
|
-
|
|
164
|
+
public static findByGuid(guid: string, hierarchy: THREE.Object3D): GameObject | Component | null | undefined {
|
|
165
|
+
const res = findByGuid(guid, hierarchy);
|
|
166
|
+
return res as GameObject | Component | null | undefined;
|
|
630
167
|
}
|
|
631
168
|
|
|
632
169
|
public static findObjectOfType<T>(typeName: Constructor<T> | string, context?: Context | THREE.Object3D, includeInactive: boolean = true): T | null {
|
|
633
|
-
return
|
|
170
|
+
return findObjectOfType(typeName, context, includeInactive);
|
|
634
171
|
}
|
|
635
172
|
|
|
636
173
|
public static findObjectsOfType<T>(typeName: Constructor<T>, context?: Context | THREE.Object3D): Array<T> {
|
|
637
174
|
const arr = [];
|
|
638
|
-
|
|
175
|
+
findObjectsOfType(typeName, arr, context);
|
|
639
176
|
return arr;
|
|
640
177
|
}
|
|
641
178
|
|
|
642
179
|
public static getComponentInChildren<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T> | null): T | null {
|
|
643
|
-
return
|
|
180
|
+
return getComponentInChildren(typeName, go);
|
|
644
181
|
}
|
|
645
182
|
|
|
646
|
-
public static getComponentsInChildren<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T
|
|
647
|
-
return
|
|
183
|
+
public static getComponentsInChildren<T extends IComponent>(go: GameObject | THREE.Object3D, typeName: Constructor<T>, arr: T[] | null = null): Array<T> {
|
|
184
|
+
return getComponentsInChildren<T>(typeName, go, arr ?? undefined) as T[]
|
|
648
185
|
}
|
|
649
186
|
|
|
650
187
|
public static getComponentInParent<T>(go: GameObject | THREE.Object3D | Array<Object3D>, typeName: Constructor<T>): T | null {
|
|
651
|
-
return
|
|
188
|
+
return getComponentInParent(typeName, go);
|
|
652
189
|
}
|
|
653
190
|
|
|
654
191
|
public static getComponentsInParent<T>(go: GameObject | THREE.Object3D, typeName: Constructor<T>, arr: Array<T> | null = null): Array<T> {
|
|
655
|
-
return
|
|
192
|
+
return getComponentsInParent(typeName, go, arr);
|
|
656
193
|
}
|
|
657
194
|
|
|
658
195
|
public static getAllComponents(go: GameObject | THREE.Object3D): Behaviour[] {
|
|
@@ -684,7 +221,7 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D {
|
|
|
684
221
|
|
|
685
222
|
|
|
686
223
|
|
|
687
|
-
class Component implements EventTarget {
|
|
224
|
+
class Component implements IComponent, EventTarget {
|
|
688
225
|
|
|
689
226
|
get isComponent(): boolean { return true; }
|
|
690
227
|
|
|
@@ -754,6 +291,12 @@ class Component implements EventTarget {
|
|
|
754
291
|
return res;
|
|
755
292
|
}
|
|
756
293
|
|
|
294
|
+
private set __isActiveInHierarchy(val: boolean)
|
|
295
|
+
{
|
|
296
|
+
if (!this.gameObject) return;
|
|
297
|
+
this.gameObject[activeInHierarchyFieldName] = val;
|
|
298
|
+
}
|
|
299
|
+
|
|
757
300
|
gameObject!: GameObject;
|
|
758
301
|
guid: string = "invalid";
|
|
759
302
|
sourceId?: SourceIdentifier;
|
|
@@ -796,14 +339,13 @@ class Component implements EventTarget {
|
|
|
796
339
|
this.context.unregisterCoroutineUpdate(routine, evt);
|
|
797
340
|
}
|
|
798
341
|
|
|
799
|
-
public get destroyed() {
|
|
342
|
+
public get destroyed() : boolean {
|
|
800
343
|
return this.__destroyed;
|
|
801
344
|
}
|
|
802
345
|
|
|
803
346
|
public destroy() {
|
|
804
|
-
if (this.
|
|
805
|
-
|
|
806
|
-
object.destroyComponentInstance(this);
|
|
347
|
+
if (this.__destroyed) return;
|
|
348
|
+
this.__internalDestroy();
|
|
807
349
|
}
|
|
808
350
|
|
|
809
351
|
protected __didAwake: boolean = false;
|
|
@@ -836,11 +378,12 @@ class Component implements EventTarget {
|
|
|
836
378
|
if (this.start) this.start();
|
|
837
379
|
}
|
|
838
380
|
|
|
839
|
-
__internalEnable() {
|
|
840
|
-
if (this.__didEnable) return;
|
|
381
|
+
__internalEnable() : boolean {
|
|
382
|
+
if (this.__didEnable) return false;
|
|
841
383
|
// console.trace("INTERNAL ENABLE");
|
|
842
384
|
this.__didEnable = true;
|
|
843
385
|
this.onEnable();
|
|
386
|
+
return true;
|
|
844
387
|
}
|
|
845
388
|
|
|
846
389
|
__internalDisable() {
|
|
@@ -851,7 +394,38 @@ class Component implements EventTarget {
|
|
|
851
394
|
this._collisions?.clear();
|
|
852
395
|
}
|
|
853
396
|
|
|
397
|
+
__internalDestroy() {
|
|
398
|
+
if (this.__destroyed) return;
|
|
399
|
+
this.__destroyed = true;
|
|
400
|
+
this.destroy?.call(this);
|
|
401
|
+
// console.log("destroy", this);
|
|
402
|
+
destroyComponentInstance(this as any);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// isActiveAndEnabled: boolean = false;
|
|
406
|
+
|
|
407
|
+
get enabled(): boolean {
|
|
408
|
+
return this.__isEnabled ?? true; // if it has no enabled field it is always enabled
|
|
409
|
+
}
|
|
410
|
+
set enabled(val: boolean) {
|
|
411
|
+
// when called from animationclip we receive numbers
|
|
412
|
+
// due to interpolation they can be anything between 0 and 1
|
|
413
|
+
if (typeof val === "number") {
|
|
414
|
+
if (val >= 0.5) val = true;
|
|
415
|
+
else val = false;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// need to check here because codegen is calling this before everything is setup
|
|
419
|
+
if (!this.__didAwake) return;
|
|
420
|
+
if (val) {
|
|
421
|
+
this.__internalEnable();
|
|
422
|
+
} else {
|
|
423
|
+
this.__internalDisable();
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
854
427
|
constructor() {
|
|
428
|
+
// super();
|
|
855
429
|
this.__internalNewInstanceCreated();
|
|
856
430
|
}
|
|
857
431
|
|
|
@@ -1052,9 +626,8 @@ class Component implements EventTarget {
|
|
|
1052
626
|
this.worldQuaternion = Component._worldQuaternionBuffer;
|
|
1053
627
|
}
|
|
1054
628
|
|
|
1055
|
-
private static _forward: THREE.Vector3 = new THREE.Vector3(
|
|
629
|
+
private static _forward: THREE.Vector3 = new THREE.Vector3();
|
|
1056
630
|
public get forward(): THREE.Vector3 {
|
|
1057
|
-
|
|
1058
631
|
return Component._forward.set(0, 0, -1).applyQuaternion(this.worldQuaternion);
|
|
1059
632
|
}
|
|
1060
633
|
|
|
@@ -1089,32 +662,6 @@ class Component implements EventTarget {
|
|
|
1089
662
|
}
|
|
1090
663
|
|
|
1091
664
|
class Behaviour extends Component {
|
|
1092
|
-
// isActiveAndEnabled: boolean = false;
|
|
1093
|
-
|
|
1094
|
-
get enabled(): boolean {
|
|
1095
|
-
return this.__isEnabled ?? true; // if it has no enabled field it is always enabled
|
|
1096
|
-
}
|
|
1097
|
-
set enabled(val: boolean) {
|
|
1098
|
-
|
|
1099
|
-
// when called from animationclip we receive numbers
|
|
1100
|
-
// due to interpolation they can be anything between 0 and 1
|
|
1101
|
-
if (typeof val === "number") {
|
|
1102
|
-
if (val >= 0.5) val = true;
|
|
1103
|
-
else val = false;
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
if (val === this.__isEnabled) return;
|
|
1107
|
-
|
|
1108
|
-
this.__isEnabled = val;
|
|
1109
|
-
// console.log(val);
|
|
1110
|
-
// need to check here because codegen is calling this before everything is setup
|
|
1111
|
-
if (!this.__didAwake) return;
|
|
1112
|
-
if (val) {
|
|
1113
|
-
this.__internalEnable();
|
|
1114
|
-
} else {
|
|
1115
|
-
this.__internalDisable();
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
665
|
}
|
|
1119
666
|
|
|
1120
667
|
export { Behaviour, Component, GameObject };
|