@needle-tools/engine 2.34.0-pre → 2.35.1-pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/needle-engine.d.ts +3128 -2942
  3. package/dist/needle-engine.js +455 -455
  4. package/dist/needle-engine.js.map +4 -4
  5. package/dist/needle-engine.min.js +54 -54
  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 +17 -0
  15. package/lib/engine/engine_components.js +240 -0
  16. package/lib/engine/engine_components.js.map +1 -0
  17. package/lib/engine/engine_element.js +4 -3
  18. package/lib/engine/engine_element.js.map +1 -1
  19. package/lib/engine/engine_element_loading.js +4 -1
  20. package/lib/engine/engine_element_loading.js.map +1 -1
  21. package/lib/engine/engine_gameobject.d.ts +33 -0
  22. package/lib/engine/engine_gameobject.js +449 -0
  23. package/lib/engine/engine_gameobject.js.map +1 -0
  24. package/lib/engine/engine_gltf.d.ts +13 -2
  25. package/lib/engine/engine_gltf.js +7 -1
  26. package/lib/engine/engine_gltf.js.map +1 -1
  27. package/lib/engine/engine_gltf_builtin_components.d.ts +3 -3
  28. package/lib/engine/engine_gltf_builtin_components.js +2 -3
  29. package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
  30. package/lib/engine/engine_lightdata.d.ts +1 -1
  31. package/lib/engine/engine_lightdata.js.map +1 -1
  32. package/lib/engine/engine_mainloop_utils.d.ts +2 -2
  33. package/lib/engine/engine_mainloop_utils.js +7 -6
  34. package/lib/engine/engine_mainloop_utils.js.map +1 -1
  35. package/lib/engine/engine_networking.d.ts +6 -10
  36. package/lib/engine/engine_networking.js +7 -11
  37. package/lib/engine/engine_networking.js.map +1 -1
  38. package/lib/engine/engine_networking_files.d.ts +1 -1
  39. package/lib/engine/engine_networking_files.js +8 -7
  40. package/lib/engine/engine_networking_files.js.map +1 -1
  41. package/lib/engine/engine_networking_files_default_components.d.ts +2 -2
  42. package/lib/engine/engine_networking_files_default_components.js +38 -43
  43. package/lib/engine/engine_networking_files_default_components.js.map +1 -1
  44. package/lib/engine/engine_networking_instantiate.d.ts +8 -6
  45. package/lib/engine/engine_networking_instantiate.js +12 -9
  46. package/lib/engine/engine_networking_instantiate.js.map +1 -1
  47. package/lib/engine/engine_networking_types.d.ts +14 -0
  48. package/lib/engine/engine_networking_types.js +8 -0
  49. package/lib/engine/engine_networking_types.js.map +1 -0
  50. package/lib/engine/engine_physics.d.ts +5 -24
  51. package/lib/engine/engine_physics.js +27 -61
  52. package/lib/engine/engine_physics.js.map +1 -1
  53. package/lib/engine/engine_rendererdata.d.ts +1 -1
  54. package/lib/engine/engine_rendererdata.js.map +1 -1
  55. package/lib/engine/engine_scenetools.d.ts +2 -2
  56. package/lib/engine/engine_scenetools.js +22 -5
  57. package/lib/engine/engine_scenetools.js.map +1 -1
  58. package/lib/engine/engine_serialization_builtin_serializer.d.ts +1 -1
  59. package/lib/engine/engine_serialization_core.d.ts +1 -1
  60. package/lib/engine/engine_serialization_decorator.d.ts +1 -1
  61. package/lib/engine/engine_setup.d.ts +14 -15
  62. package/lib/engine/engine_setup.js +34 -23
  63. package/lib/engine/engine_setup.js.map +1 -1
  64. package/lib/engine/engine_three_utils.js +0 -6
  65. package/lib/engine/engine_three_utils.js.map +1 -1
  66. package/lib/engine/engine_types.d.ts +108 -0
  67. package/lib/engine/engine_types.js +50 -0
  68. package/lib/engine/engine_types.js.map +1 -0
  69. package/lib/engine/engine_utils.d.ts +1 -1
  70. package/lib/engine/engine_utils.js.map +1 -1
  71. package/lib/engine/extensions/NEEDLE_components.js +2 -2
  72. package/lib/engine/extensions/NEEDLE_components.js.map +1 -1
  73. package/lib/engine/extensions/NEEDLE_deferred_texture.d.ts +1 -1
  74. package/lib/engine/extensions/NEEDLE_lighting_settings.d.ts +1 -1
  75. package/lib/engine/extensions/NEEDLE_lightmaps.d.ts +1 -1
  76. package/lib/engine/extensions/NEEDLE_render_objects.d.ts +2 -2
  77. package/lib/engine/extensions/NEEDLE_techniques_webgl.d.ts +1 -1
  78. package/lib/engine/extensions/NEEDLE_techniques_webgl.js +3 -2
  79. package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
  80. package/lib/engine/extensions/extensions.d.ts +1 -1
  81. package/lib/engine-components/Animator.js.map +1 -1
  82. package/lib/engine-components/AvatarLoader.js +6 -5
  83. package/lib/engine-components/AvatarLoader.js.map +1 -1
  84. package/lib/engine-components/Camera.d.ts +2 -2
  85. package/lib/engine-components/Camera.js +6 -12
  86. package/lib/engine-components/Camera.js.map +1 -1
  87. package/lib/engine-components/CameraUtils.d.ts +3 -0
  88. package/lib/engine-components/CameraUtils.js +15 -0
  89. package/lib/engine-components/CameraUtils.js.map +1 -0
  90. package/lib/engine-components/Collider.d.ts +3 -1
  91. package/lib/engine-components/Collider.js +11 -0
  92. package/lib/engine-components/Collider.js.map +1 -1
  93. package/lib/engine-components/Component.d.ts +21 -55
  94. package/lib/engine-components/Component.js +67 -466
  95. package/lib/engine-components/Component.js.map +1 -1
  96. package/lib/engine-components/Duplicatable.js +2 -1
  97. package/lib/engine-components/Duplicatable.js.map +1 -1
  98. package/lib/engine-components/LODGroup.js.map +1 -1
  99. package/lib/engine-components/Light.d.ts +2 -1
  100. package/lib/engine-components/Light.js +2 -2
  101. package/lib/engine-components/Light.js.map +1 -1
  102. package/lib/engine-components/NestedGltf.js +2 -1
  103. package/lib/engine-components/NestedGltf.js.map +1 -1
  104. package/lib/engine-components/Networking.d.ts +3 -1
  105. package/lib/engine-components/Networking.js +3 -0
  106. package/lib/engine-components/Networking.js.map +1 -1
  107. package/lib/engine-components/OrbitControls.js +4 -2
  108. package/lib/engine-components/OrbitControls.js.map +1 -1
  109. package/lib/engine-components/Renderer.d.ts +3 -2
  110. package/lib/engine-components/Renderer.js +2 -0
  111. package/lib/engine-components/Renderer.js.map +1 -1
  112. package/lib/engine-components/{Rigidbody.d.ts → RigidBody.d.ts} +2 -1
  113. package/lib/engine-components/{Rigidbody.js → RigidBody.js} +1 -1
  114. package/lib/engine-components/{Rigidbody.js.map → RigidBody.js.map} +1 -1
  115. package/lib/engine-components/ScreenCapture.js.map +1 -1
  116. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  117. package/lib/engine-components/SyncedCamera.js +2 -1
  118. package/lib/engine-components/SyncedCamera.js.map +1 -1
  119. package/lib/engine-components/SyncedTransform.js.map +1 -1
  120. package/lib/engine-components/TestRunner.js.map +1 -1
  121. package/lib/engine-components/Voip.js +2 -1
  122. package/lib/engine-components/Voip.js.map +1 -1
  123. package/lib/engine-components/WebXR.js.map +1 -1
  124. package/lib/engine-components/WebXRController.js +28 -8
  125. package/lib/engine-components/WebXRController.js.map +1 -1
  126. package/lib/engine-components/WebXRGrabRendering.d.ts +1 -1
  127. package/lib/engine-components/WebXRGrabRendering.js +1 -1
  128. package/lib/engine-components/WebXRGrabRendering.js.map +1 -1
  129. package/lib/engine-components/WebXRSync.js +1 -1
  130. package/lib/engine-components/WebXRSync.js.map +1 -1
  131. package/lib/engine-components/avatar/Avatar_Brain_LookAt.js.map +1 -1
  132. package/lib/engine-components/codegen/components.d.ts +1 -1
  133. package/lib/engine-components/codegen/components.js +1 -1
  134. package/lib/engine-components/codegen/components.js.map +1 -1
  135. package/lib/engine-components/js-extensions/ExtensionUtils.d.ts +4 -0
  136. package/lib/engine-components/js-extensions/ExtensionUtils.js +56 -0
  137. package/lib/engine-components/js-extensions/ExtensionUtils.js.map +1 -0
  138. package/lib/engine-components/js-extensions/Object3D.js +27 -50
  139. package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
  140. package/lib/engine-components/js-extensions/Vector.d.ts +2 -0
  141. package/lib/engine-components/js-extensions/Vector.js +16 -0
  142. package/lib/engine-components/js-extensions/Vector.js.map +1 -0
  143. package/lib/engine-components/timeline/PlayableDirector.d.ts +2 -1
  144. package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
  145. package/lib/engine-components/ui/BaseUIComponent.d.ts +1 -0
  146. package/lib/engine-components/ui/BaseUIComponent.js +11 -5
  147. package/lib/engine-components/ui/BaseUIComponent.js.map +1 -1
  148. package/lib/engine-components/ui/Canvas.d.ts +3 -0
  149. package/lib/engine-components/ui/Canvas.js +12 -1
  150. package/lib/engine-components/ui/Canvas.js.map +1 -1
  151. package/lib/engine-components/ui/CanvasScaler.d.ts +0 -0
  152. package/lib/engine-components/ui/CanvasScaler.js +17 -0
  153. package/lib/engine-components/ui/CanvasScaler.js.map +1 -0
  154. package/lib/engine-components/ui/EventSystem.d.ts +1 -1
  155. package/lib/engine-components/ui/EventSystem.js +11 -31
  156. package/lib/engine-components/ui/EventSystem.js.map +1 -1
  157. package/lib/engine-components/ui/Graphic.js +2 -1
  158. package/lib/engine-components/ui/Graphic.js.map +1 -1
  159. package/lib/engine-components/ui/Keyboard.js +2 -1
  160. package/lib/engine-components/ui/Keyboard.js.map +1 -1
  161. package/lib/engine-components/ui/RaycastUtils.d.ts +11 -0
  162. package/lib/engine-components/ui/RaycastUtils.js +62 -0
  163. package/lib/engine-components/ui/RaycastUtils.js.map +1 -0
  164. package/lib/engine-components/ui/Raycaster.js.map +1 -1
  165. package/lib/engine-components/ui/Text.js +8 -3
  166. package/lib/engine-components/ui/Text.js.map +1 -1
  167. package/lib/engine-components/ui/Utils.js +3 -2
  168. package/lib/engine-components/ui/Utils.js.map +1 -1
  169. package/lib/needle-engine.d.ts +3 -1
  170. package/lib/needle-engine.js +4 -2
  171. package/lib/needle-engine.js.map +1 -1
  172. package/package.json +12 -1
  173. package/src/engine/api.ts +3 -0
  174. package/src/engine/codegen/register_types.js +2 -2
  175. package/src/engine/engine_addressables.ts +12 -10
  176. package/src/engine/{engine_components.js → engine_components.ts} +66 -61
  177. package/src/engine/engine_element.ts +4 -3
  178. package/src/engine/engine_element_loading.ts +5 -1
  179. package/src/engine/engine_gameobject.ts +506 -0
  180. package/src/engine/engine_gltf.ts +21 -2
  181. package/src/engine/engine_gltf_builtin_components.ts +8 -7
  182. package/src/engine/engine_lightdata.ts +1 -1
  183. package/src/engine/engine_mainloop_utils.ts +13 -11
  184. package/src/engine/engine_networking.ts +14 -17
  185. package/src/engine/engine_networking_files.ts +14 -11
  186. package/src/engine/engine_networking_files_default_components.ts +53 -52
  187. package/src/engine/engine_networking_instantiate.ts +24 -14
  188. package/src/engine/engine_networking_types.ts +19 -0
  189. package/src/engine/engine_physics.ts +45 -77
  190. package/src/engine/engine_rendererdata.ts +1 -1
  191. package/src/engine/engine_scenetools.ts +30 -6
  192. package/src/engine/engine_serialization_core.ts +1 -1
  193. package/src/engine/engine_serialization_decorator.ts +1 -1
  194. package/src/engine/engine_setup.ts +51 -37
  195. package/src/engine/engine_three_utils.ts +0 -8
  196. package/src/engine/engine_types.ts +188 -0
  197. package/src/engine/engine_utils.ts +1 -3
  198. package/src/engine/extensions/NEEDLE_components.ts +2 -2
  199. package/src/engine/extensions/NEEDLE_deferred_texture.ts +1 -1
  200. package/src/engine/extensions/NEEDLE_lighting_settings.ts +1 -1
  201. package/src/engine/extensions/NEEDLE_lightmaps.ts +1 -1
  202. package/src/engine/extensions/NEEDLE_render_objects.ts +4 -4
  203. package/src/engine/extensions/NEEDLE_techniques_webgl.ts +5 -4
  204. package/src/engine/extensions/extensions.ts +1 -1
  205. package/src/engine-components/Animator.ts +3 -3
  206. package/src/engine-components/AvatarLoader.ts +6 -5
  207. package/src/engine-components/Camera.ts +10 -13
  208. package/src/engine-components/CameraUtils.ts +15 -0
  209. package/src/engine-components/Collider.ts +17 -2
  210. package/src/engine-components/Component.ts +87 -541
  211. package/src/engine-components/Duplicatable.ts +4 -3
  212. package/src/engine-components/LODGroup.ts +1 -1
  213. package/src/engine-components/Light.ts +3 -2
  214. package/src/engine-components/NestedGltf.ts +2 -1
  215. package/src/engine-components/Networking.ts +6 -1
  216. package/src/engine-components/OrbitControls.ts +5 -5
  217. package/src/engine-components/Renderer.ts +5 -1
  218. package/src/engine-components/RigidBody.ts +2 -1
  219. package/src/engine-components/ScreenCapture.ts +1 -1
  220. package/src/engine-components/SpectatorCamera.ts +7 -5
  221. package/src/engine-components/SyncedCamera.ts +2 -1
  222. package/src/engine-components/SyncedTransform.ts +1 -1
  223. package/src/engine-components/TestRunner.ts +1 -2
  224. package/src/engine-components/Voip.ts +2 -1
  225. package/src/engine-components/WebXR.ts +2 -2
  226. package/src/engine-components/WebXRController.ts +30 -10
  227. package/src/engine-components/WebXRGrabRendering.ts +1 -1
  228. package/src/engine-components/WebXRSync.ts +1 -1
  229. package/src/engine-components/avatar/Avatar_Brain_LookAt.ts +2 -1
  230. package/src/engine-components/codegen/components.ts +1 -1
  231. package/src/engine-components/js-extensions/ExtensionUtils.ts +66 -0
  232. package/src/engine-components/js-extensions/Object3D.ts +37 -61
  233. package/src/engine-components/js-extensions/Vector.ts +17 -0
  234. package/src/engine-components/timeline/PlayableDirector.ts +2 -1
  235. package/src/engine-components/ui/BaseUIComponent.ts +17 -6
  236. package/src/engine-components/ui/Canvas.ts +14 -2
  237. package/src/engine-components/ui/CanvasScaler.ts +21 -0
  238. package/src/engine-components/ui/EventSystem.ts +11 -25
  239. package/src/engine-components/ui/Graphic.ts +2 -1
  240. package/src/engine-components/ui/Keyboard.ts +2 -1
  241. package/src/engine-components/ui/RaycastUtils.ts +64 -0
  242. package/src/engine-components/ui/Raycaster.ts +2 -0
  243. package/src/engine-components/ui/Text.ts +8 -4
  244. package/src/engine-components/ui/Utils.ts +3 -2
  245. package/src/needle-engine.ts +7 -2
@@ -1,6 +1,5 @@
1
1
  import { DepthTexture, PerspectiveCamera, WebGLRenderer, WebGLRenderTarget } from 'three'
2
2
  import * as THREE from 'three'
3
- import { Behaviour, Component, GameObject } from '../engine-components/Component';
4
3
  import { Input } from './engine_input';
5
4
  import { Physics } from './engine_physics';
6
5
  import { Time } from './engine_time';
@@ -10,8 +9,6 @@ import { beginListenDestroy, beginListenInstantiate } from './engine_networking_
10
9
  import * as looputils from './engine_mainloop_utils';
11
10
  import * as utils from "./engine_utils";
12
11
 
13
- import { Camera, createCameraWithOrbitControl } from '../engine-components/Camera';
14
-
15
12
  import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
16
13
  import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass';
17
14
 
@@ -21,23 +18,27 @@ import { AssetDatabase } from './engine_assetdatabase';
21
18
  import { logHierarchy } from './engine_three_utils';
22
19
 
23
20
  import * as Stats from 'three/examples/jsm/libs/stats.module';
24
- import { Light } from '../engine-components/Light';
25
21
  import { RendererData } from './engine_rendererdata';
26
22
  import { Addressables } from './engine_addressables';
27
23
  import { Application } from './engine_application';
28
24
  import { LightDataRegistry, ILightDataRegistry } from './engine_lightdata';
29
25
  import { PlayerViewManager } from './engine_playerview';
30
26
 
27
+ import { ICamera as Camera, IComponent, ILight as Light } from "./engine_types"
28
+ import { destroy } from './engine_gameobject';
29
+
31
30
 
32
31
  const debug = utils.getParam("debugSetup");
33
32
  const stats = utils.getParam("stats");
34
33
 
34
+
35
+
35
36
  // this is where functions that setup unity scenes will be pushed into
36
37
  // those will be accessed from our custom html element to load them into their context
37
38
  export const build_scene_functions: { [name: string]: (context: Context) => Promise<void> } = {};
38
39
 
39
40
  declare type CoroutineData = {
40
- comp: Component,
41
+ comp: IComponent,
41
42
  main: Generator,
42
43
  chained?: Array<Generator>
43
44
  }
@@ -79,6 +80,15 @@ export enum XRSessionMode {
79
80
 
80
81
  export declare type OnBeforeRenderCallback = (renderer: THREE.WebGLRenderer, scene: THREE.Scene, camera: THREE.Camera, geometry: THREE.BufferGeometry, material: THREE.Material, group: THREE.Group) => void
81
82
 
83
+
84
+ export function registerComponent(script : IComponent, context?: Context) {
85
+ if (!script) return;
86
+ const new_scripts = context?.new_scripts ?? Context.Current.new_scripts;
87
+ if (!new_scripts.includes(script)) {
88
+ new_scripts.push(script);
89
+ }
90
+ }
91
+
82
92
  export class Context {
83
93
 
84
94
  private static _current: Context;
@@ -128,14 +138,14 @@ export class Context {
128
138
  composer: EffectComposer | null = null;
129
139
 
130
140
  // all scripts
131
- scripts: Behaviour[] = [];
141
+ scripts: IComponent[] = [];
132
142
  // scripts with update event
133
- scripts_earlyUpdate: Behaviour[] = [];
134
- scripts_update: Behaviour[] = [];
135
- scripts_lateUpdate: Behaviour[] = [];
136
- scripts_onBeforeRender: Behaviour[] = [];
137
- scripts_onAfterRender: Behaviour[] = [];
138
- scripts_WithCorroutines: Component[] = [];
143
+ scripts_earlyUpdate: IComponent[] = [];
144
+ scripts_update: IComponent[] = [];
145
+ scripts_lateUpdate: IComponent[] = [];
146
+ scripts_onBeforeRender: IComponent[] = [];
147
+ scripts_onAfterRender: IComponent[] = [];
148
+ scripts_WithCorroutines: IComponent[] = [];
139
149
  coroutines: { [FrameEvent: number]: Array<CoroutineData> } = {}
140
150
 
141
151
  get mainCamera(): THREE.Camera | null {
@@ -154,8 +164,8 @@ export class Context {
154
164
  pre_render_callbacks: Function[] = [];
155
165
  post_render_callbacks: Function[] = [];
156
166
 
157
- new_scripts: Behaviour[] = [];
158
- new_script_start: Component[] = [];
167
+ new_scripts: IComponent[] = [];
168
+ new_script_start: IComponent[] = [];
159
169
  new_scripts_pre_setup_callbacks: Function[] = [];
160
170
  new_scripts_post_setup_callbacks: Function[] = [];
161
171
 
@@ -273,7 +283,7 @@ export class Context {
273
283
  onDestroy() {
274
284
  if (!this._isCreated) return;
275
285
  this._isCreated = false;
276
- GameObject.destroy(this.scene, true);
286
+ destroy(this.scene, true);
277
287
  this.renderer?.setAnimationLoop(null);
278
288
  if (!this.isManagedExternally) {
279
289
  this.renderer?.dispose();
@@ -281,7 +291,7 @@ export class Context {
281
291
 
282
292
  }
283
293
 
284
- registerCoroutineUpdate(script: Component, coroutine: Generator, evt: FrameEvent): Generator {
294
+ registerCoroutineUpdate(script: IComponent, coroutine: Generator, evt: FrameEvent): Generator {
285
295
  if (!this.coroutines[evt]) this.coroutines[evt] = [];
286
296
  this.coroutines[evt].push({ comp: script, main: coroutine });
287
297
  return coroutine;
@@ -293,7 +303,7 @@ export class Context {
293
303
  if (idx >= 0) this.coroutines[evt].splice(idx, 1);
294
304
  }
295
305
 
296
- stopAllCoroutinesFrom(script: Component) {
306
+ stopAllCoroutinesFrom(script: IComponent) {
297
307
  for (const evt in this.coroutines) {
298
308
  const rout: CoroutineData[] = this.coroutines[evt];
299
309
  for (let i = rout.length - 1; i >= 0; i--) {
@@ -446,30 +456,34 @@ export class Context {
446
456
  }
447
457
 
448
458
  if (!this.mainCamera) {
449
- Context._current = this;
450
- const cams = GameObject.findObjectsOfType(Camera, this);
451
- // get main camera, fallback to first camera
452
- const mc: Camera = cams.find(c => c.tag == "MainCamera") ?? cams.find(_ => true) as Camera;
453
- if (mc) {
454
- if (mc.tag !== "MainCamera")
455
- console.warn("No mainCamera configured. Some components rely on a mainCamera object being present. " +
456
- "When exporting your scene, make sure to set the mainCamera tag on your camera. Using \"" + mc.name + "\" as mainCamera now.");
457
- this.setCurrentCamera(mc);
458
- }
459
- else {
460
- console.error("No camera found");
461
- const cam = createCameraWithOrbitControl(this.scene);
462
- this.setCurrentCamera(cam);
463
- }
459
+ // console.error("MISSING camera", this);
460
+ // return;
461
+ // Context._current = this;
462
+ // //@ts-ignore
463
+ // const cams = findObjectsOfType(Camera, this);
464
+ // console.log(cams);
465
+ // // get main camera, fallback to first camera
466
+ // const mc: Camera = cams.find(c => c.tag == "MainCamera") ?? cams.find(_ => true) as Camera;
467
+ // if (mc) {
468
+ // if (mc.tag !== "MainCamera")
469
+ // console.warn("No mainCamera configured. Some components rely on a mainCamera object being present. " +
470
+ // "When exporting your scene, make sure to set the mainCamera tag on your camera. Using \"" + mc.name + "\" as mainCamera now.");
471
+ // this.setCurrentCamera(mc);
472
+ // }
473
+ // else {
474
+ // console.error("No camera found");
475
+ // const cam = createCameraWithOrbitControl(this.scene);
476
+ // this.setCurrentCamera(cam);
477
+ // }
464
478
  }
465
479
 
466
480
  Context._current = this;
467
481
  looputils.processNewScripts(this);
468
482
 
469
- const mainCam = this.mainCameraComponent as Camera;
470
- if (mainCam) {
471
- mainCam.applyClearFlagsIfIsActiveCamera();
472
- }
483
+ // const mainCam = this.mainCameraComponent as Camera;
484
+ // if (mainCam) {
485
+ // mainCam.applyClearFlagsIfIsActiveCamera();
486
+ // }
473
487
 
474
488
  if (!this.isManagedExternally && this.composer && this.mainCamera) {
475
489
  const renderPass = new RenderPass(this.scene, this.mainCamera);
@@ -544,7 +558,7 @@ export class Context {
544
558
  }
545
559
  }
546
560
 
547
- this.mainLight = null;
561
+ // this.mainLight = null;
548
562
  this.executeCoroutines(FrameEvent.LateUpdate);
549
563
 
550
564
  try {
@@ -42,14 +42,6 @@ const _worldPositions = new CircularBuffer(() => new THREE.Vector3(), 100);
42
42
 
43
43
 
44
44
 
45
- THREE.Vector3.prototype["slerp"] = function (end: Vector3, t: number) {
46
- const len1 = this.length();
47
- const len2 = end.length();
48
- const targetLen = Mathf.lerp(len1, len2, t);
49
- return this.lerp(end, t).normalize().multiplyScalar(targetLen);
50
- }
51
-
52
-
53
45
 
54
46
  export function getWorldPosition(obj: THREE.Object3D, vec: THREE.Vector3 | null = null, updateParents: boolean = true): THREE.Vector3 {
55
47
  const wp = vec ?? _worldPositions.get();
@@ -0,0 +1,188 @@
1
+ import { Camera, Color, Material, Object3D, Vector3 } from "three";
2
+ import { Body, ContactEquation } from "cannon-es";
3
+ import { RGBAColor } from "../engine-components/js-extensions/RGBAColor";
4
+
5
+ /** used to find data registered via gltf files e.g. find lightmaps for a Renderer component that were shipped inside a gltf */
6
+ export declare type SourceIdentifier = string;
7
+
8
+ // TODO: figure out what is best here!
9
+ // https://stackoverflow.com/a/67229348
10
+ // https://stackoverflow.com/questions/36886082/abstract-constructor-type-in-typescript
11
+ // type Constructor<T> = Function & { prototype: T } // << this includes abstract constructor types
12
+ export type Constructor<T> = abstract new (...args: any[]) => T; // abstract to support @serializable and also getComponent with abstract types
13
+ export type ConstructorConcrete<T> = new (...args: any[]) => T;
14
+ export type GuidsMap = { [key: string]: string };
15
+
16
+ export interface UIDProvider {
17
+ seed: number;
18
+ generateUUID(): string;
19
+ }
20
+
21
+
22
+
23
+ export declare interface IGameObject extends Object3D {
24
+ guid: string | undefined;
25
+ }
26
+
27
+ export interface IComponent {
28
+ get isComponent(): boolean;
29
+
30
+
31
+ gameObject: IGameObject;
32
+ guid: string;
33
+ enabled: boolean;
34
+ sourceId?: SourceIdentifier;
35
+
36
+ get name(): string;
37
+ get layer(): number;
38
+ get destroyed(): boolean;
39
+
40
+ context: any;
41
+
42
+ get activeAndEnabled(): boolean;
43
+
44
+ __internalNewInstanceCreated();
45
+ __internalAwake();
46
+ __internalStart();
47
+ __internalEnable();
48
+ __internalDisable();
49
+ __internalDestroy();
50
+ resolveGuids?(guidsMap: GuidsMap): void;
51
+
52
+ awake();
53
+ onEnable();
54
+ onDisable();
55
+ onDestroy();
56
+
57
+ start?(): void;
58
+ // available update loop events:
59
+ // earlyUpdate, update, lateUpdate, onBeforeRender, onAfterRender
60
+ earlyUpdate?(): void;
61
+ update?(): void;
62
+ lateUpdate?(): void;
63
+ onBeforeRender?(frame: THREE.XRFrame | null): void;
64
+ onAfterRender?(): void;
65
+
66
+ onCollisionEnter?(col: Collision);
67
+ onCollisionExit?(col: Collision);
68
+ onCollisionExitRaw?(col: Collision);
69
+ onCollisionStay?(col: Collision);
70
+
71
+ onTriggerEnter?(col: Collision);
72
+ onTriggerStay?(col: Collision);
73
+ onTriggerExit?(col: Collision);
74
+
75
+ __internalHandleCollision(col: Collision, isTriggerCollision: boolean);
76
+ __internalHandleExitCollisionEvent(obj: Object3D, isTriggerCollision: boolean);
77
+
78
+ get forward() : Vector3;
79
+ }
80
+
81
+
82
+ export declare interface ICamera extends IComponent {
83
+ applyClearFlagsIfIsActiveCamera(): unknown;
84
+ buildCamera();
85
+ get cam(): Camera;
86
+ nearClipPlane: number;
87
+ farClipPlane: number;
88
+ backgroundColor: RGBAColor | null;
89
+ clearFlags: number;
90
+ aspect: number;
91
+ fieldOfView: number;
92
+ }
93
+
94
+ export declare interface ILight extends IComponent {
95
+ intensity: number;
96
+ color: Color;
97
+ }
98
+
99
+ export declare interface IRenderer extends IComponent {
100
+ material: Material;
101
+ }
102
+
103
+ export declare interface ICollider extends IComponent {
104
+ get isCollider();
105
+ attachedRigidbody: IRigidbody | null;
106
+ isTrigger: boolean;
107
+ }
108
+
109
+ export declare interface IRigidbody extends IComponent {
110
+ initialize(): void;
111
+ body;
112
+ }
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+ export const $physicsKey = Symbol("object");
121
+
122
+ export declare type CannonCollision = {
123
+ body: Body;
124
+ contact: ContactEquation;
125
+ target: Body;
126
+ type: string;
127
+ }
128
+
129
+ export declare type ICollisionContext = {
130
+ getCollider(obj : Object3D) : ICollider;
131
+ }
132
+
133
+ export class Collision {
134
+
135
+ get __internalCollision(): CannonCollision {
136
+ return this.collision;
137
+ }
138
+
139
+ get __internalInvertedSourceReceiver(): boolean {
140
+ return this.invert;
141
+ }
142
+
143
+ private readonly invert: boolean;
144
+ private readonly collision: CannonCollision;
145
+ private readonly targetBody: Body;
146
+ private readonly context : ICollisionContext;
147
+
148
+ readonly me: Object3D;
149
+
150
+ private _normal?: Vector3;
151
+ get normal(): Vector3 {
152
+ if (!this._normal) {
153
+ const vec = this.collision.contact.ni;
154
+ this._normal = new Vector3(vec.x, vec.y, vec.z);
155
+ }
156
+ return this._normal;
157
+ }
158
+
159
+ private _collider?: ICollider;
160
+ get collider(): ICollider {
161
+ if (!this._collider) {
162
+ this._collider = this.context.getCollider(this.gameObject);
163
+ }
164
+ return this._collider;
165
+ }
166
+
167
+ get gameObject(): Object3D {
168
+ return this.targetBody[$physicsKey];
169
+ }
170
+
171
+ // private _point?: Vector3;
172
+ // get point(): Vector3 {
173
+ // if (!this._point) {
174
+ // const c = this.collision.contact;
175
+ // const point = c.bi.position.clone().vadd(c.ri);
176
+ // this._point = new Vector3(point.x, point.y, point.z);
177
+ // }
178
+ // return this._point;
179
+ // }
180
+
181
+ constructor(obj: Object3D, collision: CannonCollision, context : ICollisionContext, invert: boolean = false) {
182
+ this.me = obj;
183
+ this.collision = collision;
184
+ this.context = context;
185
+ this.targetBody = invert ? collision.target : collision.body;
186
+ this.invert = invert;
187
+ }
188
+ }
@@ -1,7 +1,5 @@
1
-
2
-
3
1
  // use for typesafe interface method calls
4
- import { SourceIdentifier } from "./engine_gltf";
2
+ import { SourceIdentifier } from "./engine_types";
5
3
 
6
4
  // https://schneidenbach.gitbooks.io/typescript-cookbook/content/nameof-operator.html
7
5
  export const nameofFactory = <T>() => (name: keyof T) => name;
@@ -1,11 +1,11 @@
1
1
  import { GLTF, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
2
2
  import { NodeToObjectMap, ObjectToNodeMap, SerializationContext } from "../engine_serialization_core";
3
3
  import { GLTFExporter } from 'three/examples/jsm/exporters/GLTFExporter.js';
4
- import { writeBuiltinComponentData } from "../engine_gltf_builtin_components";
5
4
  import { debugExtension } from "../engine_default_parameters";
6
5
  import { builtinComponentKeyName } from "../engine_constants";
7
6
  import { resolveReferences } from "./extension_utils";
8
7
  import { apply } from "../../engine-components/js-extensions/Object3D";
8
+ import { getLoader } from "../engine_gltf";
9
9
 
10
10
  export const debug = debugExtension
11
11
  const componentsArrayExportKey = "$___Export_Components";
@@ -128,7 +128,7 @@ export class NEEDLE_components implements GLTFLoaderPlugin {
128
128
  const serializedComponentData: Array<object | null> = [];
129
129
  for (const comp of components) {
130
130
  this.context.target = comp;
131
- const res = writeBuiltinComponentData(comp, this.context);
131
+ const res = getLoader().writeBuiltinComponentData(comp, this.context);
132
132
  if (res !== null) {
133
133
  serializedComponentData.push(res);
134
134
  // (comp as unknown as ISerializationCallbackReceiver)?.onAfterSerialize?.call(comp);
@@ -1,6 +1,6 @@
1
1
  import { Material, Texture, TextureLoader } from "three";
2
2
  import { GLTF, GLTFLoader, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
3
- import { SourceIdentifier } from "../engine_gltf";
3
+ import { SourceIdentifier } from "../engine_types";
4
4
  import { Context } from "../engine_setup";
5
5
  import { addDracoAndKTX2Loaders } from "../engine_loaders";
6
6
  import { getParam, getPath } from "../engine_utils";
@@ -1,6 +1,6 @@
1
1
  import { AmbientLight, Color, HemisphereLight } from "three";
2
2
  import { GLTF, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
3
- import { SourceIdentifier } from "../engine_gltf";
3
+ import { SourceIdentifier } from "../engine_types";
4
4
  import { Behaviour, GameObject } from "../../engine-components/Component";
5
5
  import { AmbientMode, DefaultReflectionMode } from "../engine_rendererdata";
6
6
  import { LightmapType } from "./NEEDLE_lightmaps";
@@ -1,7 +1,7 @@
1
1
  import { ILightDataRegistry } from "../engine_lightdata";
2
2
  import { FloatType, HalfFloatType, sRGBEncoding, Texture } from "three";
3
3
  import { GLTF, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
4
- import { SourceIdentifier } from "../engine_gltf";
4
+ import { SourceIdentifier } from "../engine_types";
5
5
  import { resolveReferences } from "./extension_utils";
6
6
  import { getParam } from "../engine_utils";
7
7
 
@@ -1,8 +1,8 @@
1
1
 
2
- import { SourceIdentifier } from "../engine_gltf";
2
+ import { SourceIdentifier } from "../engine_types";
3
3
  import { GLTF, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
4
- import { Behaviour } from "../../engine-components/Component";
5
- import { Renderer } from "../../engine-components/Renderer";
4
+ import { IComponent as Component, IRenderer as Renderer } from "../engine_types";
5
+
6
6
  import {
7
7
  // stencil funcs
8
8
  NeverStencilFunc,
@@ -27,7 +27,7 @@ import { getParam } from "../engine_utils";
27
27
 
28
28
  const debug = getParam("debugstencil");
29
29
 
30
- function matchesLayer(stencilLayer: number, comp: Behaviour): boolean {
30
+ function matchesLayer(stencilLayer: number, comp: Component): boolean {
31
31
  return (stencilLayer & 1 << comp.layer) != 0;
32
32
  }
33
33
 
@@ -5,8 +5,9 @@ import { IUniform, RawShaderMaterial, Vector4 } from 'three';
5
5
  import { Context } from '../engine_setup';
6
6
  import { getParam } from "../engine_utils";
7
7
  import * as SHADERDATA from "../shaders/shaderData"
8
- import { Light } from "../../engine-components/Light";
9
- import { SourceIdentifier } from "../engine_gltf";
8
+ import { SourceIdentifier } from "../engine_types";
9
+ import { ILight } from "../engine_types";
10
+ import { getWorldPosition } from "../engine_three_utils";
10
11
 
11
12
  const debug = getParam("debugshaders");
12
13
 
@@ -203,10 +204,10 @@ export class CustomShader extends RawShaderMaterial {
203
204
  this.uniforms["_TimeParameters"].value = context.rendererData.timeVec4;
204
205
  }
205
206
 
206
- const mainLight: Light | null = context?.mainLight;
207
+ const mainLight: ILight | null = context.mainLight;
207
208
  if (mainLight) {
208
209
 
209
- const lp = mainLight.getWorldPosition(CustomShader._mainLightPosition);
210
+ const lp = getWorldPosition(mainLight.gameObject, CustomShader._mainLightPosition);
210
211
  this.uniforms["_MainLightPosition"] = { value: lp.normalize() };
211
212
 
212
213
  CustomShader._mainLightColor.set(mainLight.color.r, mainLight.color.g, mainLight.color.b, 0);
@@ -8,7 +8,7 @@ import { NEEDLE_gameobject_data } from "./NEEDLE_gameobject_data";
8
8
  import { NEEDLE_persistent_assets } from "./NEEDLE_persistent_assets";
9
9
  // import { KHR_animation_pointer } from "./KHR_animation_pointer";
10
10
  import { NEEDLE_lightmaps } from "../extensions/NEEDLE_lightmaps";
11
- import { SourceIdentifier } from "../engine_gltf";
11
+ import { SourceIdentifier } from "../engine_types";
12
12
  import { Context } from "../engine_setup";
13
13
  import { NEEDLE_lighting_settings } from "./NEEDLE_lighting_settings";
14
14
  import { NEEDLE_render_objects } from "./NEEDLE_render_objects";
@@ -1,10 +1,10 @@
1
- import { Behaviour, GameObject } from "./Component";
1
+ import { Behaviour } from "./Component";
2
2
  import * as THREE from 'three'
3
- import { LoopOnce, LoopRepeat, AnimationActionLoopStyles, AnimationAction } from "three";
3
+ import { LoopOnce, AnimationActionLoopStyles, AnimationAction } from "three";
4
4
  import { getParam, deepClone } from "../engine/engine_utils";
5
5
  import { AnimatorControllerModel } from "../engine/extensions/NEEDLE_animator_controller_model";
6
6
  import { AnimatorController } from "./AnimatorController";
7
- import { allProperties, serializeable } from "../engine/engine_serialization_decorator";
7
+ import { serializeable } from "../engine/engine_serialization_decorator";
8
8
  import { Mathf } from "../engine/engine_math";
9
9
 
10
10
  const debug = getParam("debuganimator");
@@ -1,12 +1,13 @@
1
1
  import { GLTF, GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
2
2
  import * as THREE from "three";
3
3
  import * as utils from "../engine/engine_utils"
4
- import * as object from "../engine/engine_gltf_builtin_components";
4
+ // import * as object from "../engine/engine_gltf_builtin_components";
5
5
  import * as loaders from "../engine/engine_loaders"
6
6
  import { Context } from "../engine/engine_setup";
7
- import { GameObject, InstantiateOptions } from "./Component";
7
+ import { GameObject } from "./Component";
8
8
  import { download_file } from "../engine/engine_web_api";
9
- import { parseSync } from "../engine/engine_scenetools";
9
+ import { getLoader } from "../engine/engine_gltf";
10
+ import { InstantiateOptions } from "../engine/engine_gameobject";
10
11
 
11
12
  const debug = utils.getParam("debugavatar");
12
13
 
@@ -103,7 +104,7 @@ export class AvatarLoader {
103
104
  if (!bin) return null;
104
105
  }
105
106
 
106
- const gltf = await parseSync(context, bin, null!, 0);
107
+ const gltf = await getLoader().parseSync(context, bin, null!, 0);
107
108
  return gltf?.scene ?? null;
108
109
  }
109
110
 
@@ -125,7 +126,7 @@ export class AvatarLoader {
125
126
  const url = this.avatarRegistryUrl + "/" + avatarId;
126
127
  loader.load(url,
127
128
  async gltf => {
128
- await object.createBuiltinComponents(context, url, gltf);
129
+ await getLoader().createBuiltinComponents(context, url, gltf, null, undefined);
129
130
  resolve(gltf.scene);
130
131
  },
131
132
  progress => {
@@ -1,11 +1,12 @@
1
1
  import { Behaviour, GameObject } from "./Component";
2
2
  import * as THREE from "three";
3
- import { OrbitControls } from "./OrbitControls";
3
+ // import { OrbitControls } from "./OrbitControls";
4
4
  import { getParam } from "../engine/engine_utils";
5
5
  import { serializeable } from "../engine/engine_serialization_decorator";
6
6
  import { RGBAColor } from "./js-extensions/RGBAColor";
7
7
  import { PerspectiveCamera } from "three";
8
8
  import { XRSessionMode } from "../engine/engine_setup";
9
+ import { ICamera } from "../engine/engine_types"
9
10
 
10
11
  export enum ClearFlags {
11
12
  Skybox = 1,
@@ -15,7 +16,8 @@ export enum ClearFlags {
15
16
 
16
17
  const debug = getParam("debugcam");
17
18
 
18
- export class Camera extends Behaviour {
19
+ export class Camera extends Behaviour implements ICamera {
20
+
19
21
 
20
22
  get aspect(): number {
21
23
  if (this._cam instanceof PerspectiveCamera) return this._cam.aspect;
@@ -104,6 +106,12 @@ export class Camera extends Behaviour {
104
106
  return this._cam!;
105
107
  }
106
108
 
109
+
110
+ // constructor(){
111
+ // super();
112
+ // console.log(this);
113
+ // }
114
+
107
115
  awake() {
108
116
  if (!this.sourceId) {
109
117
  console.warn("Camera has no source - the camera should be exported inside a gltf", this.name);
@@ -239,15 +247,4 @@ class CameraSkybox {
239
247
  }
240
248
  }
241
249
 
242
- }
243
-
244
- export function createCameraWithOrbitControl(scene: THREE.Scene): Camera {
245
- const srcId = "created/implictly";
246
- const go = new THREE.Object3D();
247
- scene.add(go);
248
- const cam = GameObject.addNewComponent(go, Camera, false);
249
- cam.sourceId = srcId;
250
- const orbit = GameObject.addNewComponent(go, OrbitControls, false);
251
- orbit.sourceId = srcId;
252
- return cam;
253
250
  }
@@ -0,0 +1,15 @@
1
+ import { OrbitControls } from "./OrbitControls";
2
+ import { Camera } from "./Camera";
3
+ import { addNewComponentInstance } from "../engine/engine_components";
4
+ import { Object3D, Scene } from "three";
5
+
6
+ export function createCameraWithOrbitControl(scene: Scene): Camera {
7
+ const srcId = "created/implictly";
8
+ const go = new Object3D();
9
+ scene.add(go);
10
+ const cam = addNewComponentInstance(go, new Camera(), false);
11
+ cam.sourceId = srcId;
12
+ const orbit = addNewComponentInstance(go, new OrbitControls(), false);
13
+ orbit.sourceId = srcId;
14
+ return cam as Camera;
15
+ }
@@ -1,10 +1,25 @@
1
1
  import { Behaviour } from "./Component";
2
2
  import { Rigidbody } from "./RigidBody";
3
3
  import { serializeable } from "../engine/engine_serialization_decorator";
4
- import { Vector3 } from "three"
4
+ import { Event, Object3D, Vector3 } from "three"
5
5
  import { Shape } from "cannon-es";
6
+ import { IColliderProvider, registerColliderProvider } from "../engine/engine_physics";
7
+ import { ICollider } from "../engine/engine_types";
8
+ import { getComponentInChildren } from "../engine/engine_components";
9
+
10
+ class ColliderProvider implements IColliderProvider {
11
+ getCollider(obj: Object3D): ICollider {
12
+ return getComponentInChildren<Collider>(obj, Collider);
13
+ }
14
+ }
15
+ registerColliderProvider(new ColliderProvider());
16
+
17
+ export class Collider extends Behaviour implements ICollider {
18
+
19
+ get isCollider(): any {
20
+ return true;
21
+ }
6
22
 
7
- export class Collider extends Behaviour {
8
23
  @serializeable(Rigidbody)
9
24
  attachedRigidbody: Rigidbody | null = null;
10
25
  @serializeable()