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