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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/needle-engine.d.ts +2960 -2794
  3. package/dist/needle-engine.js +456 -456
  4. package/dist/needle-engine.js.map +4 -4
  5. package/dist/needle-engine.min.js +67 -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_element.js +2 -2
  18. package/lib/engine/engine_element.js.map +1 -1
  19. package/lib/engine/engine_gameobject.d.ts +33 -0
  20. package/lib/engine/engine_gameobject.js +449 -0
  21. package/lib/engine/engine_gameobject.js.map +1 -0
  22. package/lib/engine/engine_gltf.d.ts +13 -2
  23. package/lib/engine/engine_gltf.js +7 -1
  24. package/lib/engine/engine_gltf.js.map +1 -1
  25. package/lib/engine/engine_gltf_builtin_components.d.ts +3 -3
  26. package/lib/engine/engine_gltf_builtin_components.js +2 -3
  27. package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
  28. package/lib/engine/engine_lightdata.d.ts +1 -1
  29. package/lib/engine/engine_lightdata.js.map +1 -1
  30. package/lib/engine/engine_mainloop_utils.d.ts +2 -2
  31. package/lib/engine/engine_mainloop_utils.js +7 -6
  32. package/lib/engine/engine_mainloop_utils.js.map +1 -1
  33. package/lib/engine/engine_networking.d.ts +2 -11
  34. package/lib/engine/engine_networking.js +1 -7
  35. package/lib/engine/engine_networking.js.map +1 -1
  36. package/lib/engine/engine_networking_files.d.ts +1 -1
  37. package/lib/engine/engine_networking_files.js +8 -7
  38. package/lib/engine/engine_networking_files.js.map +1 -1
  39. package/lib/engine/engine_networking_files_default_components.d.ts +2 -2
  40. package/lib/engine/engine_networking_files_default_components.js +38 -43
  41. package/lib/engine/engine_networking_files_default_components.js.map +1 -1
  42. package/lib/engine/engine_networking_instantiate.d.ts +8 -6
  43. package/lib/engine/engine_networking_instantiate.js +12 -9
  44. package/lib/engine/engine_networking_instantiate.js.map +1 -1
  45. package/lib/engine/engine_networking_types.d.ts +14 -0
  46. package/lib/engine/engine_networking_types.js +8 -0
  47. package/lib/engine/engine_networking_types.js.map +1 -0
  48. package/lib/engine/engine_physics.d.ts +1 -25
  49. package/lib/engine/engine_physics.js +17 -61
  50. package/lib/engine/engine_physics.js.map +1 -1
  51. package/lib/engine/engine_rendererdata.d.ts +1 -1
  52. package/lib/engine/engine_rendererdata.js.map +1 -1
  53. package/lib/engine/engine_scenetools.d.ts +2 -2
  54. package/lib/engine/engine_scenetools.js +22 -5
  55. package/lib/engine/engine_scenetools.js.map +1 -1
  56. package/lib/engine/engine_serialization_builtin_serializer.d.ts +1 -1
  57. package/lib/engine/engine_serialization_core.d.ts +1 -1
  58. package/lib/engine/engine_serialization_decorator.d.ts +1 -1
  59. package/lib/engine/engine_setup.d.ts +14 -15
  60. package/lib/engine/engine_setup.js +34 -23
  61. package/lib/engine/engine_setup.js.map +1 -1
  62. package/lib/engine/engine_three_utils.js +0 -6
  63. package/lib/engine/engine_three_utils.js.map +1 -1
  64. package/lib/engine/engine_types.d.ts +103 -0
  65. package/lib/engine/engine_types.js +49 -0
  66. package/lib/engine/engine_types.js.map +1 -0
  67. package/lib/engine/engine_utils.d.ts +1 -1
  68. package/lib/engine/engine_utils.js.map +1 -1
  69. package/lib/engine/extensions/NEEDLE_components.js +2 -2
  70. package/lib/engine/extensions/NEEDLE_components.js.map +1 -1
  71. package/lib/engine/extensions/NEEDLE_deferred_texture.d.ts +1 -1
  72. package/lib/engine/extensions/NEEDLE_lighting_settings.d.ts +1 -1
  73. package/lib/engine/extensions/NEEDLE_lightmaps.d.ts +1 -1
  74. package/lib/engine/extensions/NEEDLE_render_objects.d.ts +2 -2
  75. package/lib/engine/extensions/NEEDLE_techniques_webgl.d.ts +1 -1
  76. package/lib/engine/extensions/NEEDLE_techniques_webgl.js +3 -2
  77. package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
  78. package/lib/engine/extensions/extensions.d.ts +1 -1
  79. package/lib/engine-components/Animator.js.map +1 -1
  80. package/lib/engine-components/AvatarLoader.js +6 -5
  81. package/lib/engine-components/AvatarLoader.js.map +1 -1
  82. package/lib/engine-components/Camera.d.ts +2 -2
  83. package/lib/engine-components/Camera.js +6 -12
  84. package/lib/engine-components/Camera.js.map +1 -1
  85. package/lib/engine-components/CameraUtils.d.ts +3 -0
  86. package/lib/engine-components/CameraUtils.js +15 -0
  87. package/lib/engine-components/CameraUtils.js.map +1 -0
  88. package/lib/engine-components/Component.d.ts +16 -50
  89. package/lib/engine-components/Component.js +67 -466
  90. package/lib/engine-components/Component.js.map +1 -1
  91. package/lib/engine-components/Duplicatable.js +2 -1
  92. package/lib/engine-components/Duplicatable.js.map +1 -1
  93. package/lib/engine-components/LODGroup.js.map +1 -1
  94. package/lib/engine-components/Light.d.ts +2 -1
  95. package/lib/engine-components/Light.js +2 -2
  96. package/lib/engine-components/Light.js.map +1 -1
  97. package/lib/engine-components/NestedGltf.js +2 -1
  98. package/lib/engine-components/NestedGltf.js.map +1 -1
  99. package/lib/engine-components/OrbitControls.js +4 -2
  100. package/lib/engine-components/OrbitControls.js.map +1 -1
  101. package/lib/engine-components/Renderer.d.ts +3 -2
  102. package/lib/engine-components/Renderer.js +2 -0
  103. package/lib/engine-components/Renderer.js.map +1 -1
  104. package/lib/engine-components/{Rigidbody.d.ts → RigidBody.d.ts} +2 -1
  105. package/lib/engine-components/{Rigidbody.js → RigidBody.js} +1 -1
  106. package/lib/engine-components/{Rigidbody.js.map → RigidBody.js.map} +1 -1
  107. package/lib/engine-components/ScreenCapture.js.map +1 -1
  108. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  109. package/lib/engine-components/SyncedCamera.js +2 -1
  110. package/lib/engine-components/SyncedCamera.js.map +1 -1
  111. package/lib/engine-components/SyncedTransform.js.map +1 -1
  112. package/lib/engine-components/TestRunner.js.map +1 -1
  113. package/lib/engine-components/Voip.js +2 -1
  114. package/lib/engine-components/Voip.js.map +1 -1
  115. package/lib/engine-components/WebXR.js.map +1 -1
  116. package/lib/engine-components/WebXRController.js +28 -8
  117. package/lib/engine-components/WebXRController.js.map +1 -1
  118. package/lib/engine-components/WebXRGrabRendering.d.ts +1 -1
  119. package/lib/engine-components/WebXRGrabRendering.js +1 -1
  120. package/lib/engine-components/WebXRGrabRendering.js.map +1 -1
  121. package/lib/engine-components/WebXRSync.js +1 -1
  122. package/lib/engine-components/WebXRSync.js.map +1 -1
  123. package/lib/engine-components/avatar/Avatar_Brain_LookAt.js.map +1 -1
  124. package/lib/engine-components/codegen/components.d.ts +1 -1
  125. package/lib/engine-components/codegen/components.js +1 -1
  126. package/lib/engine-components/codegen/components.js.map +1 -1
  127. package/lib/engine-components/js-extensions/ExtensionUtils.d.ts +4 -0
  128. package/lib/engine-components/js-extensions/ExtensionUtils.js +56 -0
  129. package/lib/engine-components/js-extensions/ExtensionUtils.js.map +1 -0
  130. package/lib/engine-components/js-extensions/Object3D.js +16 -41
  131. package/lib/engine-components/js-extensions/Object3D.js.map +1 -1
  132. package/lib/engine-components/js-extensions/Vector.d.ts +2 -0
  133. package/lib/engine-components/js-extensions/Vector.js +16 -0
  134. package/lib/engine-components/js-extensions/Vector.js.map +1 -0
  135. package/lib/engine-components/timeline/PlayableDirector.d.ts +2 -1
  136. package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
  137. package/lib/engine-components/ui/BaseUIComponent.d.ts +1 -0
  138. package/lib/engine-components/ui/BaseUIComponent.js +11 -5
  139. package/lib/engine-components/ui/BaseUIComponent.js.map +1 -1
  140. package/lib/engine-components/ui/Canvas.d.ts +3 -0
  141. package/lib/engine-components/ui/Canvas.js +12 -1
  142. package/lib/engine-components/ui/Canvas.js.map +1 -1
  143. package/lib/engine-components/ui/CanvasScaler.d.ts +0 -0
  144. package/lib/engine-components/ui/CanvasScaler.js +17 -0
  145. package/lib/engine-components/ui/CanvasScaler.js.map +1 -0
  146. package/lib/engine-components/ui/EventSystem.d.ts +1 -1
  147. package/lib/engine-components/ui/EventSystem.js +11 -31
  148. package/lib/engine-components/ui/EventSystem.js.map +1 -1
  149. package/lib/engine-components/ui/Graphic.js +2 -1
  150. package/lib/engine-components/ui/Graphic.js.map +1 -1
  151. package/lib/engine-components/ui/Keyboard.js +2 -1
  152. package/lib/engine-components/ui/Keyboard.js.map +1 -1
  153. package/lib/engine-components/ui/RaycastUtils.d.ts +11 -0
  154. package/lib/engine-components/ui/RaycastUtils.js +62 -0
  155. package/lib/engine-components/ui/RaycastUtils.js.map +1 -0
  156. package/lib/engine-components/ui/Raycaster.js.map +1 -1
  157. package/lib/engine-components/ui/Text.js +8 -3
  158. package/lib/engine-components/ui/Text.js.map +1 -1
  159. package/lib/engine-components/ui/Utils.js +3 -2
  160. package/lib/engine-components/ui/Utils.js.map +1 -1
  161. package/lib/needle-engine.d.ts +3 -1
  162. package/lib/needle-engine.js +4 -2
  163. package/lib/needle-engine.js.map +1 -1
  164. package/package.json +12 -1
  165. package/src/engine/api.ts +3 -0
  166. package/src/engine/codegen/register_types.js +2 -2
  167. package/src/engine/engine_addressables.ts +12 -10
  168. package/src/engine/{engine_components.js → engine_components.ts} +37 -47
  169. package/src/engine/engine_element.ts +2 -2
  170. package/src/engine/engine_gameobject.ts +506 -0
  171. package/src/engine/engine_gltf.ts +21 -2
  172. package/src/engine/engine_gltf_builtin_components.ts +8 -7
  173. package/src/engine/engine_lightdata.ts +1 -1
  174. package/src/engine/engine_mainloop_utils.ts +13 -11
  175. package/src/engine/engine_networking.ts +3 -14
  176. package/src/engine/engine_networking_files.ts +14 -11
  177. package/src/engine/engine_networking_files_default_components.ts +53 -52
  178. package/src/engine/engine_networking_instantiate.ts +24 -14
  179. package/src/engine/engine_networking_types.ts +19 -0
  180. package/src/engine/engine_physics.ts +20 -82
  181. package/src/engine/engine_rendererdata.ts +1 -1
  182. package/src/engine/engine_scenetools.ts +30 -6
  183. package/src/engine/engine_serialization_core.ts +1 -1
  184. package/src/engine/engine_serialization_decorator.ts +1 -1
  185. package/src/engine/engine_setup.ts +51 -37
  186. package/src/engine/engine_three_utils.ts +0 -8
  187. package/src/engine/engine_types.ts +180 -0
  188. package/src/engine/engine_utils.ts +1 -3
  189. package/src/engine/extensions/NEEDLE_components.ts +2 -2
  190. package/src/engine/extensions/NEEDLE_deferred_texture.ts +1 -1
  191. package/src/engine/extensions/NEEDLE_lighting_settings.ts +1 -1
  192. package/src/engine/extensions/NEEDLE_lightmaps.ts +1 -1
  193. package/src/engine/extensions/NEEDLE_render_objects.ts +4 -4
  194. package/src/engine/extensions/NEEDLE_techniques_webgl.ts +5 -4
  195. package/src/engine/extensions/extensions.ts +1 -1
  196. package/src/engine-components/Animator.ts +3 -3
  197. package/src/engine-components/AvatarLoader.ts +6 -5
  198. package/src/engine-components/Camera.ts +10 -13
  199. package/src/engine-components/CameraUtils.ts +15 -0
  200. package/src/engine-components/Component.ts +83 -536
  201. package/src/engine-components/Duplicatable.ts +4 -3
  202. package/src/engine-components/LODGroup.ts +1 -1
  203. package/src/engine-components/Light.ts +3 -2
  204. package/src/engine-components/NestedGltf.ts +2 -1
  205. package/src/engine-components/OrbitControls.ts +5 -5
  206. package/src/engine-components/Renderer.ts +5 -1
  207. package/src/engine-components/RigidBody.ts +2 -1
  208. package/src/engine-components/ScreenCapture.ts +1 -1
  209. package/src/engine-components/SpectatorCamera.ts +7 -5
  210. package/src/engine-components/SyncedCamera.ts +2 -1
  211. package/src/engine-components/SyncedTransform.ts +1 -1
  212. package/src/engine-components/TestRunner.ts +1 -2
  213. package/src/engine-components/Voip.ts +2 -1
  214. package/src/engine-components/WebXR.ts +2 -2
  215. package/src/engine-components/WebXRController.ts +30 -10
  216. package/src/engine-components/WebXRGrabRendering.ts +1 -1
  217. package/src/engine-components/WebXRSync.ts +1 -1
  218. package/src/engine-components/avatar/Avatar_Brain_LookAt.ts +2 -1
  219. package/src/engine-components/codegen/components.ts +1 -1
  220. package/src/engine-components/js-extensions/ExtensionUtils.ts +66 -0
  221. package/src/engine-components/js-extensions/Object3D.ts +22 -48
  222. package/src/engine-components/js-extensions/Vector.ts +17 -0
  223. package/src/engine-components/timeline/PlayableDirector.ts +2 -1
  224. package/src/engine-components/ui/BaseUIComponent.ts +17 -6
  225. package/src/engine-components/ui/Canvas.ts +14 -2
  226. package/src/engine-components/ui/CanvasScaler.ts +21 -0
  227. package/src/engine-components/ui/EventSystem.ts +11 -25
  228. package/src/engine-components/ui/Graphic.ts +2 -1
  229. package/src/engine-components/ui/Keyboard.ts +2 -1
  230. package/src/engine-components/ui/RaycastUtils.ts +64 -0
  231. package/src/engine-components/ui/Raycaster.ts +2 -0
  232. package/src/engine-components/ui/Text.ts +8 -4
  233. package/src/engine-components/ui/Utils.ts +3 -2
  234. package/src/needle-engine.ts +7 -2
@@ -6,21 +6,17 @@ let serverUrl = 'wss://needle-tiny-starter.glitch.me/socket';
6
6
  import { Websocket, WebsocketBuilder } from 'websocket-ts';
7
7
  import { Behaviour, GameObject } from '../engine-components/Component';
8
8
  import { Networking } from '../engine-components/Networking';
9
- import { Context, ContextArgs } from './engine_setup';
9
+ import { Context } from './engine_setup';
10
10
  import * as utils from "./engine_utils";
11
11
  import * as flatbuffers from 'flatbuffers';
12
12
  import * as schemes from "../engine-schemes/schemes";
13
13
  import { PeerNetworking } from './engine_networking_peer';
14
+ import { IModel, INetworkConnection, SendQueue } from './engine_networking_types';
14
15
 
15
16
  export const debugNet = utils.getParam("debugnet") ? true : false;
16
17
  export const debugOwner = debugNet || utils.getParam("debugowner") ? true : false;
17
18
 
18
19
 
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
22
- }
23
-
24
20
  export declare interface IConnectionData {
25
21
  id: string;
26
22
  }
@@ -225,18 +221,11 @@ export class OwnershipModel {
225
221
  }
226
222
 
227
223
 
228
- export enum SendQueue {
229
- OnConnection,
230
- OnRoomJoin,
231
- Queued,
232
- Immediate,
233
- }
234
-
235
224
  export declare type BinaryCallback = {
236
225
  (data: any | flatbuffers.ByteBuffer): void;
237
226
  }
238
227
 
239
- export class NetworkConnection {
228
+ export class NetworkConnection implements INetworkConnection {
240
229
 
241
230
  private context: Context;
242
231
  private _peer: PeerNetworking | null = null;
@@ -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,12 @@ 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 { IComponent as Component, IGameObject as GameObject, ICollider as Collider, IRigidbody as Rigidbody, ICollider, $physicsKey, Collision, CannonCollision } from './engine_types';
8
+ import { Shape } from 'cannon-es';
12
9
  import { InstancingUtil } from './engine_instancing';
10
+ import { foreachComponent } from './engine_gameobject';
13
11
 
14
12
  const debugPhysics = utils.getParam("debugphysics");
15
13
  const debugCollisions = utils.getParam("debugcollisions");
@@ -23,7 +21,6 @@ export class BodyOptions {
23
21
  sleepThreshold: number = .01;
24
22
  }
25
23
 
26
- const bodyObjectKey = Symbol("object");
27
24
 
28
25
  // TODO: refactor to return some kind of handle for adding/removing
29
26
  class PhysicsObject {
@@ -41,17 +38,10 @@ class PhysicsObject {
41
38
  this.parent = obj.parent;
42
39
  this.body = body;
43
40
  if (this.body)
44
- this.body[bodyObjectKey] = obj;
41
+ this.body[$physicsKey] = obj;
45
42
  }
46
43
  }
47
44
 
48
- declare type CannonCollision = {
49
- body: CANNON.Body;
50
- contact: CANNON.ContactEquation;
51
- target: CANNON.Body;
52
- type: string;
53
- }
54
-
55
45
  export class RaycastOptions {
56
46
  ray: THREE.Ray | undefined = undefined;
57
47
  cam: THREE.Camera | undefined | null = undefined;
@@ -649,14 +639,14 @@ export class Physics {
649
639
  const collision = new Collision(obj, event);
650
640
  if (debugCollisions)
651
641
  console.log("collision between", event.contact.bi, event.contact.bj, obj, event);
652
- GameObject.foreachComponent(obj, (c: Component) => {
642
+ foreachComponent(obj, (c: Component) => {
653
643
  c.__internalHandleCollision(collision, false);
654
644
  });
655
645
 
656
646
  // handle triggers
657
647
  if (collision.collider && !collision.collider.attachedRigidbody && collision.collider.isTrigger) {
658
648
  const collision2 = new Collision(collision.gameObject, event, true);
659
- GameObject.foreachComponent(collision.gameObject, (c: Component) => {
649
+ foreachComponent(collision.gameObject, (c: Component) => {
660
650
  c.__internalHandleCollision(collision2, true);
661
651
  });
662
652
  }
@@ -665,76 +655,24 @@ export class Physics {
665
655
  private onEndContact(args: { bodyA: CANNON.Body, bodyB: CANNON.Body }) {
666
656
  // if(args.bodyB.sleepState !== CANNON.Body.AWAKE) return;
667
657
  // console.log("END", CANNON.BODY_SLEEP_STATES, args.bodyB.sleepState);
668
- const obj1 = args.bodyA[bodyObjectKey];
669
- const obj2 = args.bodyB[bodyObjectKey];
658
+ const obj1 = args.bodyA[$physicsKey];
659
+ const obj2 = args.bodyB[$physicsKey];
670
660
  // console.log(obj2);
671
- GameObject.foreachComponent(obj2, (c: Component) => {
661
+
662
+
663
+ foreachComponent(obj2, (c: Component) => {
672
664
  c.__internalHandleExitCollisionEvent(obj1, false);
673
665
  });
674
666
 
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
- }
667
+ // TODO: stop iterating when we found the collider
668
+ foreachComponent(obj1, c => {
669
+ const collider = c as ICollider;
670
+ if (collider.isCollider && !collider.attachedRigidbody && collider.isTrigger) {
671
+ foreachComponent(collider.gameObject, (c: Component) => {
672
+ c.__internalHandleExitCollisionEvent(obj2, true);
673
+ });
674
+ }
675
+ });
682
676
  }
683
677
 
684
678
  }
685
-
686
-
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;
700
-
701
- readonly me: Object3D;
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;
718
- }
719
-
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
- // }
733
-
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