@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
@@ -4,21 +4,19 @@
4
4
  let serverUrl = 'wss://needle-tiny-starter.glitch.me/socket';
5
5
 
6
6
  import { Websocket, WebsocketBuilder } from 'websocket-ts';
7
- import { Behaviour, GameObject } from '../engine-components/Component';
8
- import { Networking } from '../engine-components/Networking';
9
- import { Context, ContextArgs } from './engine_setup';
7
+ // import { Networking } from '../engine-components/Networking';
8
+ import { Context } from './engine_setup';
10
9
  import * as utils from "./engine_utils";
11
10
  import * as flatbuffers from 'flatbuffers';
12
11
  import * as schemes from "../engine-schemes/schemes";
13
12
  import { PeerNetworking } from './engine_networking_peer';
13
+ import { IModel, INetworkConnection, SendQueue } from './engine_networking_types';
14
14
 
15
15
  export const debugNet = utils.getParam("debugnet") ? true : false;
16
16
  export const debugOwner = debugNet || utils.getParam("debugowner") ? true : false;
17
17
 
18
-
19
- export declare interface IModel {
20
- guid: string;
21
- dontSave?: boolean; // if set to true the model will not be saved in the server room state
18
+ export interface INetworkingWebsocketUrlProvider {
19
+ getWebsocketUrl() : string | null;
22
20
  }
23
21
 
24
22
  export declare interface IConnectionData {
@@ -225,18 +223,11 @@ export class OwnershipModel {
225
223
  }
226
224
 
227
225
 
228
- export enum SendQueue {
229
- OnConnection,
230
- OnRoomJoin,
231
- Queued,
232
- Immediate,
233
- }
234
-
235
226
  export declare type BinaryCallback = {
236
227
  (data: any | flatbuffers.ByteBuffer): void;
237
228
  }
238
229
 
239
- export class NetworkConnection {
230
+ export class NetworkConnection implements INetworkConnection {
240
231
 
241
232
  private context: Context;
242
233
  private _peer: PeerNetworking | null = null;
@@ -395,14 +386,20 @@ export class NetworkConnection {
395
386
  }
396
387
  }
397
388
 
389
+ private netWebSocketUrlProvider? : INetworkingWebsocketUrlProvider;
390
+
391
+ public registerProvider(prov : INetworkingWebsocketUrlProvider){
392
+ this.netWebSocketUrlProvider = prov;
393
+ }
394
+
398
395
  public connect() {
399
396
  if (this.connected) return;
400
397
  if (debugNet)
401
398
  console.log("connecting");
402
399
  // this.channel = geckos({ port: 9208, url: 'http://127.0.0.1' });
403
400
  // this.channel.onConnect(this.onConnectGeckosIo.bind(this));
404
- const networking = GameObject.findObjectOfType(Networking, this.context, false);
405
- const overrideUrl = networking?.getWebsocketUrl();
401
+ // const networking = GameObject.findObjectOfType(Networking, this.context, false);
402
+ const overrideUrl = this.netWebSocketUrlProvider?.getWebsocketUrl();
406
403
  if (overrideUrl) {
407
404
  serverUrl = overrideUrl;
408
405
  }
@@ -1,12 +1,15 @@
1
- import { GameObject } from "../engine-components/Component";
2
1
  import { Context } from "../engine/engine_setup";
3
- import { loadSync, parseSync } from "../engine/engine_scenetools";
2
+ // import { loadSync, parseSync } from "../engine/engine_scenetools";
4
3
  import * as THREE from "three";
5
4
  import * as web from "../engine/engine_web_api";
6
- import { IModel, NetworkConnection } from "../engine/engine_networking";
5
+ import { NetworkConnection } from "../engine/engine_networking";
7
6
  import { generateSeed, InstantiateIdProvider } from "../engine/engine_networking_instantiate";
8
7
  import * as def from "./engine_networking_files_default_components"
9
8
  import { GLTF } from 'three/examples/jsm/loaders/GLTFLoader.js'
9
+ import { getLoader } from "../engine/engine_gltf";
10
+ import { IModel } from "./engine_networking_types";
11
+ import { IGameObject } from "./engine_types";
12
+ import { findByGuid } from "./engine_gameobject";
10
13
 
11
14
  export enum File_Event {
12
15
  File_Spawned = "file-spawned",
@@ -50,9 +53,9 @@ export async function addFile(file: File, context: Context, backendUrl?: string)
50
53
  // first load it locally
51
54
  const seed = generateSeed();
52
55
  const prov = new InstantiateIdProvider(seed);
53
- const gltf: GLTF = await loadSync(context, content, prov, true) as GLTF;
56
+ const gltf: GLTF = await getLoader().loadSync(context, content, prov, true) as GLTF;
54
57
  if (gltf && gltf.scene) {
55
- const obj = gltf.scene as unknown as GameObject;
58
+ const obj = gltf.scene as unknown as IGameObject;
56
59
  // if we dont have a guid yet (because components guids are actually created in a callback a bit later)
57
60
  // we just use the same seed and generate a guid for the root only
58
61
  // this should be the exact same guid the instantiate call will produce
@@ -81,9 +84,9 @@ export async function addFileFromUrl(url: URL, context: Context): Promise<GLTF |
81
84
  return new Promise(async (resolve, _reject) => {
82
85
  const seed = generateSeed();
83
86
  const prov = new InstantiateIdProvider(seed);
84
- const gltf: GLTF = await loadSync(context, url.toString(), prov, true) as GLTF;
87
+ const gltf: GLTF = await getLoader().loadSync(context, url.toString(), prov, true) as GLTF;
85
88
  if (gltf && gltf.scene) {
86
- const obj = gltf.scene as unknown as GameObject;
89
+ const obj = gltf.scene as unknown as IGameObject;
87
90
  // handleUpload(context.connection, file, seed, obj); // TODO needs to upload the URL only and store that
88
91
  def.onDynamicObjectAdded(obj, prov, gltf);
89
92
  resolve(gltf);
@@ -108,7 +111,7 @@ export function beginListenFileSpawn(context: Context) {
108
111
  }
109
112
  if (bin) {
110
113
  const prov = new InstantiateIdProvider(evt.seed);
111
- const gltf = await parseSync(context, bin, null!, prov);
114
+ const gltf = await getLoader().parseSync(context, bin, null!, prov);
112
115
  if (gltf && gltf.scene) {
113
116
  const obj = gltf.scene;
114
117
  def.onDynamicObjectAdded(obj, prov, gltf);
@@ -118,7 +121,7 @@ export function beginListenFileSpawn(context: Context) {
118
121
 
119
122
  // add object to proper parent
120
123
  if (evt.parentGuid) {
121
- const parent = GameObject.findByGuid(evt.parentGuid, context.scene) as THREE.Object3D;
124
+ const parent = findByGuid(evt.parentGuid, context.scene) as THREE.Object3D;
122
125
  if ("add" in parent) parent.add(obj);
123
126
  }
124
127
  if (!obj.parent)
@@ -136,7 +139,7 @@ export function beginListenFileSpawn(context: Context) {
136
139
 
137
140
 
138
141
 
139
- async function handleUpload(connection: NetworkConnection, file: File, seed: number, obj: GameObject, backendUrl: string) {
142
+ async function handleUpload(connection: NetworkConnection, file: File, seed: number, obj: IGameObject, backendUrl: string) {
140
143
  if (!connection.connectionId) {
141
144
  console.error("Can not upload file - no connection id");
142
145
  return;
@@ -180,7 +183,7 @@ function addPreview(evt: FileSpawnModel, context: Context) {
180
183
  previews[evt.guid] = box;
181
184
  context.scene.add(box);
182
185
  if (evt.parentGuid) {
183
- const parent = GameObject.findByGuid(evt.parentGuid, context.scene) as THREE.Object3D;
186
+ const parent = findByGuid(evt.parentGuid, context.scene) as THREE.Object3D;
184
187
  if (parent)
185
188
  parent.add(box);
186
189
  }
@@ -1,54 +1,55 @@
1
- import { Behaviour, GameObject, UIDProvider } from "../engine-components/Component";
2
- import { SyncedTransform } from "../engine-components/SyncedTransform";
3
- import { DragControls } from "../engine-components/DragControls"
4
- import { ObjectRaycaster } from "../engine-components/ui/Raycaster";
1
+ // import { SyncedTransform } from "../engine-components/SyncedTransform";
2
+ // import { DragControls } from "../engine-components/DragControls"
3
+ // import { ObjectRaycaster } from "../engine-components/ui/Raycaster";
4
+ import { UIDProvider } from "./engine_types";
5
5
  import { GLTF } from "three/examples/jsm/loaders/GLTFLoader";
6
- import { Animation } from "../engine-components/Animation";
7
- import { Mesh } from "three";
8
-
9
-
10
- export function onDynamicObjectAdded(obj: THREE.Object3D, idProv: UIDProvider, gltf?: GLTF) {
11
-
12
- // this ensures we have a drag component
13
- let drag = GameObject.getComponentInChildren(obj as GameObject, DragControls);
14
- if (!drag) {
15
- drag = GameObject.addNewComponent(obj as GameObject, DragControls, false);
16
- drag.guid = idProv.generateUUID();
17
- }
18
-
19
- // if a drag component is found we add a syncedTransform if none exists
20
- if (drag && !GameObject.getComponent(drag.gameObject, SyncedTransform)) {
21
- const st = GameObject.addNewComponent(drag.gameObject, SyncedTransform, false);
22
- st.guid = idProv.generateUUID();
23
- // st.autoOwnership = true;
24
-
25
- //drag.transformGroup = true;
26
- //drag.targets = [obj];
27
- }
28
-
29
- // if a drag component is found we add a syncedTransform if none exists
30
- if (drag && !GameObject.getComponentInParent(drag.gameObject, ObjectRaycaster)) {
31
- const st = GameObject.addNewComponent(drag.gameObject, ObjectRaycaster, false);
32
- st.guid = idProv.generateUUID();
33
- }
34
-
35
- if (gltf) {
36
- if (gltf.animations?.length > 0) {
37
- const firstAnimation = gltf.animations[0];
38
- const anim = GameObject.addNewComponent(obj, Animation, false);
39
- anim.animations = [firstAnimation];
40
- }
41
- }
42
-
43
- let didDisablFrustumCulling = false;
44
- obj.traverse(o => {
45
- if (!o) return;
46
-
47
- if (o["isSkinnedMesh"] === true) {
48
- if (!didDisablFrustumCulling) console.log("Disabling frustum culling for skinned meshes", gltf);
49
- didDisablFrustumCulling = true;
50
- o.frustumCulled = false;
51
- }
52
-
53
- });
6
+ // import { Animation } from "../engine-components/Animation";
7
+
8
+
9
+ export function onDynamicObjectAdded(_obj: THREE.Object3D, _idProv: UIDProvider, _gltf?: GLTF) {
10
+
11
+ console.warn("Adding components on object has been temporarily disabled");
12
+
13
+ // // this ensures we have a drag component
14
+ // let drag = getComponentInChildren(obj as GameObject, DragControls);
15
+ // if (!drag) {
16
+ // drag = GameObject.addNewComponent(obj as GameObject, DragControls, false);
17
+ // drag.guid = idProv.generateUUID();
18
+ // }
19
+
20
+ // // if a drag component is found we add a syncedTransform if none exists
21
+ // if (drag && !GameObject.getComponent(drag.gameObject, SyncedTransform)) {
22
+ // const st = GameObject.addNewComponent(drag.gameObject, SyncedTransform, false);
23
+ // st.guid = idProv.generateUUID();
24
+ // // st.autoOwnership = true;
25
+
26
+ // //drag.transformGroup = true;
27
+ // //drag.targets = [obj];
28
+ // }
29
+
30
+ // // if a drag component is found we add a syncedTransform if none exists
31
+ // if (drag && !GameObject.getComponentInParent(drag.gameObject, ObjectRaycaster)) {
32
+ // const st = GameObject.addNewComponent(drag.gameObject, ObjectRaycaster, false);
33
+ // st.guid = idProv.generateUUID();
34
+ // }
35
+
36
+ // if (gltf) {
37
+ // if (gltf.animations?.length > 0) {
38
+ // const firstAnimation = gltf.animations[0];
39
+ // const anim = GameObject.addNewComponent(obj, Animation, false);
40
+ // anim.animations = [firstAnimation];
41
+ // }
42
+ // }
43
+
44
+ // let didDisablFrustumCulling = false;
45
+ // obj.traverse(o => {
46
+ // if (!o) return;
47
+
48
+ // if (o["isSkinnedMesh"] === true) {
49
+ // if (!didDisablFrustumCulling) console.log("Disabling frustum culling for skinned meshes", gltf);
50
+ // didDisablFrustumCulling = true;
51
+ // o.frustumCulled = false;
52
+ // }
53
+
54
+ // });
54
55
  }
@@ -1,17 +1,27 @@
1
- import { IModel, NetworkConnection } from "./engine_networking"
1
+ // import { IModel, NetworkConnection } from "./engine_networking"
2
2
  import * as THREE from "three";
3
3
  import { Context } from "./engine_setup"
4
- import { Behaviour, Component, GameObject, InstantiateOptions, UIDProvider } from "../engine-components/Component";
5
4
  import * as utils from "./engine_utils"
6
- const debug = utils.getParam("debugcomponents");
5
+ import { INetworkConnection } from "./engine_networking_types";
6
+ import { IGameObject as GameObject, IComponent as Component } from "./engine_types"
7
7
 
8
8
  // https://github.com/uuidjs/uuid
9
9
  // v5 takes string and namespace
10
10
  import { v5, v1 } from 'uuid';
11
+ import { UIDProvider } from "./engine_types";
12
+ import { IModel } from "./engine_networking_types";
13
+ import { SendQueue } from "./engine_networking_types";
14
+ import { destroy, findByGuid, instantiate } from "./engine_gameobject";
11
15
  import { Object3D } from "three";
12
- const ID_NAMESPACE = 'eff8ba80-635d-11ec-90d6-0242ac120003';
16
+ import { InstantiateOptions } from "./engine_gameobject";
17
+
18
+
19
+ const debug = utils.getParam("debugcomponents");
20
+
13
21
 
14
22
 
23
+ const ID_NAMESPACE = 'eff8ba80-635d-11ec-90d6-0242ac120003';
24
+
15
25
  export class InstantiateIdProvider implements UIDProvider {
16
26
 
17
27
  get seed() {
@@ -63,10 +73,10 @@ export interface IBeforeNetworkedDestroy {
63
73
  onBeforeNetworkedDestroy(networkIds: string[]): void;
64
74
  }
65
75
 
66
- export function syncDestroy(obj: GameObject | Component, con: NetworkConnection, recursive: boolean = true) {
76
+ export function syncDestroy(obj: GameObject | Component, con: INetworkConnection, recursive: boolean = true) {
67
77
  if (!obj) return;
68
78
  const go = obj as GameObject;
69
- GameObject.destroy(obj, recursive);
79
+ destroy(obj, recursive);
70
80
 
71
81
  if (!con) {
72
82
  console.warn("Can not send destroy: No networking connection provided", obj.guid);
@@ -88,12 +98,12 @@ export function syncDestroy(obj: GameObject | Component, con: NetworkConnection,
88
98
  }
89
99
 
90
100
  const model = new DestroyInstanceModel(guid);
91
- con.send(InstantiateEvent.InstanceDestroyed, model);
101
+ con.send(InstantiateEvent.InstanceDestroyed, model, SendQueue.Queued);
92
102
  }
93
103
 
94
- export function sendDestroyed(guid: string, con: NetworkConnection) {
104
+ export function sendDestroyed(guid: string, con: INetworkConnection) {
95
105
  const model = new DestroyInstanceModel(guid);
96
- con.send(InstantiateEvent.InstanceDestroyed, model);
106
+ con.send(InstantiateEvent.InstanceDestroyed, model, SendQueue.Queued);
97
107
  }
98
108
 
99
109
  export function beginListenDestroy(context: Context) {
@@ -101,8 +111,8 @@ export function beginListenDestroy(context: Context) {
101
111
  if (debug)
102
112
  console.log("[Remote] Destroyed", context.scene, data);
103
113
  // TODO: create global lookup table for guids
104
- const obj = GameObject.findByGuid(data.guid, context.scene);
105
- if (obj) GameObject.destroy(obj);
114
+ const obj = findByGuid(data.guid, context.scene);
115
+ if (obj) destroy(obj);
106
116
  });
107
117
  }
108
118
 
@@ -140,7 +150,7 @@ class NewInstanceModel implements IModel {
140
150
  }
141
151
  }
142
152
 
143
- export function syncInstantiate(object: GameObject | THREE.Object3D, opts: InstantiateOptions, hostData?: HostData, save?: boolean): GameObject | null {
153
+ export function syncInstantiate(object: GameObject | Object3D, opts: InstantiateOptions, hostData?: HostData, save?: boolean): GameObject | null {
144
154
 
145
155
  const obj: GameObject = object as GameObject;
146
156
 
@@ -226,7 +236,7 @@ export function beginListenInstantiate(context: Context) {
226
236
  options.context = context;
227
237
  if (debug && context.alias)
228
238
  console.log("[Remote] instantiate in: " + context.alias);
229
- const inst = GameObject.instantiate(obj as GameObject, options);
239
+ const inst = instantiate(obj as GameObject, options);
230
240
 
231
241
  if (inst) {
232
242
  if (model.parent === "scene")
@@ -247,7 +257,7 @@ function instantiateSeeded(obj: GameObject, opts: InstantiateOptions | null): {
247
257
  const seed = generateSeed();
248
258
  const options = opts ?? new InstantiateOptions();
249
259
  options.idProvider = new InstantiateIdProvider(seed);
250
- const instance = GameObject.instantiate(obj, options);
260
+ const instance = instantiate(obj, options);
251
261
  return { seed: seed, instance: instance };
252
262
  }
253
263
 
@@ -0,0 +1,19 @@
1
+ export declare interface IModel {
2
+ guid: string;
3
+ dontSave?: boolean; // if set to true the model will not be saved in the server room state
4
+ }
5
+
6
+
7
+ export enum SendQueue {
8
+ OnConnection,
9
+ OnRoomJoin,
10
+ Queued,
11
+ Immediate,
12
+ }
13
+
14
+ export declare interface INetworkConnection {
15
+ get isConnected(): boolean;
16
+
17
+ send(key: string, data: IModel | object | boolean | null | string | number, queue: SendQueue): unknown;
18
+
19
+ }
@@ -2,14 +2,23 @@ import * as CANNON from 'cannon-es'
2
2
  import * as THREE from 'three'
3
3
  import { Context } from './engine_setup';
4
4
  import cannonDebugger from 'cannon-es-debugger'
5
- import { Rigidbody } from '../engine-components/Rigidbody';
6
5
  import * as utils from "./engine_utils"
7
6
  import * as threeutils from "./engine_three_utils"
8
- import { Behaviour, Component, GameObject } from '../engine-components/Component';
9
- import { Body, RigidVehicle, Shape, Vec3 } from 'cannon-es';
10
- import { Matrix4, Object3D, RGBA_BPTC_Format, Vector3, Wrapping } from 'three';
11
- import { Collider } from '../engine-components/Collider';
7
+ import {
8
+ IComponent as Component,
9
+ IGameObject as GameObject,
10
+ ICollider,
11
+ IRigidbody as Rigidbody, $physicsKey,
12
+ Collision, CannonCollision,
13
+ ICollisionContext,
14
+ IComponent
15
+ }
16
+ from './engine_types';
17
+ import { Shape } from 'cannon-es';
12
18
  import { InstancingUtil } from './engine_instancing';
19
+ import { foreachComponent } from './engine_gameobject';
20
+ import { getComponentInChildren } from './engine_components';
21
+
13
22
 
14
23
  const debugPhysics = utils.getParam("debugphysics");
15
24
  const debugCollisions = utils.getParam("debugcollisions");
@@ -23,7 +32,6 @@ export class BodyOptions {
23
32
  sleepThreshold: number = .01;
24
33
  }
25
34
 
26
- const bodyObjectKey = Symbol("object");
27
35
 
28
36
  // TODO: refactor to return some kind of handle for adding/removing
29
37
  class PhysicsObject {
@@ -41,17 +49,10 @@ class PhysicsObject {
41
49
  this.parent = obj.parent;
42
50
  this.body = body;
43
51
  if (this.body)
44
- this.body[bodyObjectKey] = obj;
52
+ this.body[$physicsKey] = obj;
45
53
  }
46
54
  }
47
55
 
48
- declare type CannonCollision = {
49
- body: CANNON.Body;
50
- contact: CANNON.ContactEquation;
51
- target: CANNON.Body;
52
- type: string;
53
- }
54
-
55
56
  export class RaycastOptions {
56
57
  ray: THREE.Ray | undefined = undefined;
57
58
  cam: THREE.Camera | undefined | null = undefined;
@@ -645,18 +646,20 @@ export class Physics {
645
646
  // console.log("START");
646
647
  }
647
648
 
649
+ private readonly collisionContext: ICollisionContext = new CollisionContext();
650
+
648
651
  private raiseCollisionEvents(obj: THREE.Object3D, event: CannonCollision) {
649
- const collision = new Collision(obj, event);
652
+ const collision = new Collision(obj, event, this.collisionContext);
650
653
  if (debugCollisions)
651
654
  console.log("collision between", event.contact.bi, event.contact.bj, obj, event);
652
- GameObject.foreachComponent(obj, (c: Component) => {
655
+ foreachComponent(obj, (c: Component) => {
653
656
  c.__internalHandleCollision(collision, false);
654
657
  });
655
658
 
656
659
  // handle triggers
657
660
  if (collision.collider && !collision.collider.attachedRigidbody && collision.collider.isTrigger) {
658
- const collision2 = new Collision(collision.gameObject, event, true);
659
- GameObject.foreachComponent(collision.gameObject, (c: Component) => {
661
+ const collision2 = new Collision(collision.gameObject, event, this.collisionContext, true);
662
+ foreachComponent(collision.gameObject, (c: Component) => {
660
663
  c.__internalHandleCollision(collision2, true);
661
664
  });
662
665
  }
@@ -665,76 +668,41 @@ export class Physics {
665
668
  private onEndContact(args: { bodyA: CANNON.Body, bodyB: CANNON.Body }) {
666
669
  // if(args.bodyB.sleepState !== CANNON.Body.AWAKE) return;
667
670
  // console.log("END", CANNON.BODY_SLEEP_STATES, args.bodyB.sleepState);
668
- const obj1 = args.bodyA[bodyObjectKey];
669
- const obj2 = args.bodyB[bodyObjectKey];
671
+ const obj1 = args.bodyA[$physicsKey];
672
+ const obj2 = args.bodyB[$physicsKey];
670
673
  // console.log(obj2);
671
- GameObject.foreachComponent(obj2, (c: Component) => {
674
+
675
+ foreachComponent(obj2, (c: Component) => {
672
676
  c.__internalHandleExitCollisionEvent(obj1, false);
673
677
  });
674
678
 
675
- const collider = GameObject.getComponent(obj1, Collider);
676
- if (collider && !collider.attachedRigidbody && collider.isTrigger) {
677
-
678
- GameObject.foreachComponent(collider.gameObject, (c: Component) => {
679
- c.__internalHandleExitCollisionEvent(obj2, true);
680
- });
681
- }
679
+ // TODO: stop iterating when we found the collider
680
+ foreachComponent(obj1, c => {
681
+ const collider = c as ICollider;
682
+ if (collider.isCollider && !collider.attachedRigidbody && collider.isTrigger) {
683
+ foreachComponent(collider.gameObject, (c: Component) => {
684
+ c.__internalHandleExitCollisionEvent(obj2, true);
685
+ });
686
+ }
687
+ });
682
688
  }
683
689
 
684
690
  }
685
691
 
692
+ export interface IColliderProvider {
693
+ getCollider(obj: THREE.Object3D): ICollider;
694
+ }
686
695
 
687
- export class Collision {
688
-
689
- get __internalCollision(): CannonCollision {
690
- return this.collision;
691
- }
692
-
693
- get __internalInvertedSourceReceiver(): boolean {
694
- return this.invert;
695
- }
696
-
697
- private readonly invert: boolean;
698
- private readonly collision: CannonCollision;
699
- private readonly targetBody: CANNON.Body;
696
+ let colliderProvider: IColliderProvider | null = null;
697
+ export function registerColliderProvider(prov: IColliderProvider) {
698
+ colliderProvider = prov;
699
+ }
700
700
 
701
- readonly me: Object3D;
701
+ class CollisionContext implements ICollisionContext {
702
702
 
703
- private _normal?: Vector3;
704
- get normal(): Vector3 {
705
- if (!this._normal) {
706
- const vec = this.collision.contact.ni;
707
- this._normal = new Vector3(vec.x, vec.y, vec.z);
708
- }
709
- return this._normal;
710
- }
711
-
712
- private _collider?: Collider;
713
- get collider(): Collider {
714
- if (this._collider === undefined) {
715
- this._collider = GameObject.getComponentInChildren(this.gameObject, Collider)!;
716
- }
717
- return this._collider;
703
+ getCollider(obj: THREE.Object3D<THREE.Event>): ICollider {
704
+ return colliderProvider!.getCollider(obj);
718
705
  }
719
706
 
720
- get gameObject(): Object3D {
721
- return this.targetBody[bodyObjectKey];
722
- }
723
-
724
- // private _point?: Vector3;
725
- // get point(): Vector3 {
726
- // if (!this._point) {
727
- // const c = this.collision.contact;
728
- // const point = c.bi.position.clone().vadd(c.ri);
729
- // this._point = new Vector3(point.x, point.y, point.z);
730
- // }
731
- // return this._point;
732
- // }
707
+ }
733
708
 
734
- constructor(obj: Object3D, collision: CannonCollision, invert: boolean = false) {
735
- this.invert = invert;
736
- this.me = obj;
737
- this.collision = collision;
738
- this.targetBody = this.invert ? collision.target : collision.body;
739
- }
740
- }
@@ -1,10 +1,10 @@
1
- import { SourceIdentifier } from "./engine_gltf";
2
1
  import { Vector4, EquirectangularReflectionMapping, sRGBEncoding, WebGLCubeRenderTarget, Texture, LightProbe, Color } from "three";
3
2
  import { LightProbeGenerator } from "three/examples/jsm/lights/LightProbeGenerator.js"
4
3
  import { Context } from "./engine_setup";
5
4
  import { SceneLightSettings } from "./extensions/NEEDLE_lighting_settings";
6
5
  import { createFlatTexture, createTrilightTexture } from "./engine_shaders";
7
6
  import { getParam } from "./engine_utils";
7
+ import { SourceIdentifier } from "./engine_types";
8
8
 
9
9
  const debug = getParam("debugenvlight");
10
10
 
@@ -2,12 +2,36 @@ import { Context } from "./engine_setup"
2
2
  import { Animator } from '../engine-components/Animator';
3
3
  import { Animation } from '../engine-components/Animation';
4
4
  import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
5
- import * as object from "./engine_gltf_builtin_components";
5
+ // import * as object from "./engine_gltf_builtin_components";
6
6
  import * as loaders from "./engine_loaders"
7
- import { GameObject, UIDProvider } from "../engine-components/Component";
8
7
  import * as utils from "./engine_utils";
9
8
  import { registerComponentExtension, registerExtensions } from "./extensions/extensions";
10
- import { SourceIdentifier } from "./engine_gltf";
9
+ import { getLoader, INeedleGltfLoader, registerLoader } from "./engine_gltf";
10
+ import { SourceIdentifier, UIDProvider } from "./engine_types";
11
+ import { createBuiltinComponents, writeBuiltinComponentData } from "./engine_gltf_builtin_components";
12
+ import { SerializationContext } from "./engine_serialization_core";
13
+ import { NEEDLE_components } from "./extensions/NEEDLE_components";
14
+ import { addNewComponentInstance, getComponentInChildren } from "./engine_components";
15
+
16
+
17
+ class NeedleGltfLoader implements INeedleGltfLoader {
18
+ createBuiltinComponents(context: Context, gltfId: string, gltf: any, seed: number | UIDProvider | null, extension?: NEEDLE_components | undefined) {
19
+ return createBuiltinComponents(context, gltfId, gltf, seed, extension);
20
+ }
21
+
22
+ writeBuiltinComponentData(comp: any, context: SerializationContext) {
23
+ return writeBuiltinComponentData(comp, context);
24
+ }
25
+
26
+ parseSync(context: Context, data, path: string, seed: number | UIDProvider | null): Promise<GLTF | undefined> {
27
+ return parseSync(context, data, path, seed);
28
+ }
29
+ loadSync(context: Context, url: string, seed: number | UIDProvider | null, _allowAddingAnimator: boolean, prog?: ((ProgressEvent: any) => void) | undefined): Promise<GLTF | undefined> {
30
+ return loadSync(context, url, seed, _allowAddingAnimator, prog);
31
+ }
32
+ }
33
+
34
+ registerLoader(new NeedleGltfLoader());
11
35
 
12
36
 
13
37
  const printGltf = utils.getParam("printGltf");
@@ -64,7 +88,7 @@ async function handleLoadedGltf(context: Context, gltfId: string, gltf, seed: nu
64
88
  if (printGltf)
65
89
  console.log(gltf);
66
90
  await context.assets.registerGltf(gltf);
67
- await object.createBuiltinComponents(context, gltfId, gltf, seed, componentsExtension);
91
+ await getLoader().createBuiltinComponents(context, gltfId, gltf, seed, componentsExtension);
68
92
 
69
93
  // load and assign animation
70
94
  // we still need this for Animation component
@@ -151,7 +175,7 @@ export function findAnimations(gltf: GLTF, allowAddingAnimator: boolean = false)
151
175
  if (!allowAddingAnimator) {
152
176
  // we only need to search if any animation component is in the scene
153
177
  // otherwise if we dont add anything there is no reason to search and log anything
154
- if (!GameObject.getComponentInChildren(gltf.scene, Animation)) return;
178
+ if (!getComponentInChildren(gltf.scene, Animation)) return;
155
179
  }
156
180
 
157
181
  for (let i = 0; i < gltf.animations.length; i++) {
@@ -168,7 +192,7 @@ export function findAnimations(gltf: GLTF, allowAddingAnimator: boolean = false)
168
192
  let animationComponent = findAnimationGameObjectInParent(obj);
169
193
  if (!animationComponent) {
170
194
  if (allowAddingAnimator)
171
- animationComponent = GameObject.addNewComponent(gltf.scene, Animation);
195
+ animationComponent = addNewComponentInstance(gltf.scene, new Animation());
172
196
  else {
173
197
  console.warn("Failed finding animator for", track.name, objectName);
174
198
  continue;
@@ -3,7 +3,7 @@ import { getParam } from "./engine_utils";
3
3
  import { Object3D } from "three";
4
4
  import { Context } from "./engine_setup";
5
5
  import { isPersistentAsset } from "./extensions/NEEDLE_persistent_assets";
6
- import { SourceIdentifier } from "./engine_gltf";
6
+ import { SourceIdentifier } from "./engine_types";
7
7
  import { debugExtension } from "../engine/engine_default_parameters";
8
8
 
9
9
  const debug = getParam("debugserializer");
@@ -1,4 +1,4 @@
1
- import { Constructor } from "../engine-components/Component"
1
+ import { Constructor } from "./engine_types";
2
2
 
3
3
  export declare type TypeResolver<T> = (data) => Constructor<T> | null;
4
4