@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
@@ -5,6 +5,7 @@ import { EventSystem } from "./EventSystem";
5
5
  import { showGizmos } from '../../engine/engine_default_parameters';
6
6
  import { AxesHelper, Object3D } from 'three';
7
7
  import { IGraphic } from './Interfaces';
8
+ import { ShadowCastingMode } from '../Renderer';
8
9
  export const includesDir = "./include";
9
10
 
10
11
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
@@ -19,6 +20,8 @@ ThreeMeshUI.Block.prototype["interactable"] = {
19
20
  }
20
21
  }
21
22
 
23
+ export const $shadowDomOwner = Symbol("shadowDomOwner");
24
+
22
25
  export class BaseUIComponent extends Behaviour {
23
26
 
24
27
  isRoot() { return this.Root?.gameObject === this.gameObject; }
@@ -69,7 +72,7 @@ export class BaseUIComponent extends Behaviour {
69
72
 
70
73
  container.name = this.name + " (" + (this.constructor.name ?? "UI") + ")";
71
74
  container.autoLayout = this._parentComponent.controlsChildLayout;
72
- container.shadowComponentOwner = this;
75
+ container[$shadowDomOwner] = this;
73
76
 
74
77
  // TODO: raycastTarget doesnt work anymore -> i think we need to set the gameObject layer and then check in the raycaster if the shadowComponentOwner is on the correct layer?!
75
78
  // const raycastTarget = (this as unknown as IGraphic).raycastTarget;
@@ -78,14 +81,17 @@ export class BaseUIComponent extends Behaviour {
78
81
 
79
82
  // TODO: only traverse our own hierarchy, we can stop if we find another owner
80
83
  container.traverse(c => {
81
- if (c.shadowComponentOwner === undefined) {
82
- c.shadowComponentOwner = this;
84
+ if (c[$shadowDomOwner] === undefined) {
85
+ c[$shadowDomOwner] = this;
83
86
  }
87
+
84
88
  // // this makes text not render anymore when enabled again
85
89
  // if (raycastTarget === false) {
86
90
  // c.layers.set(2);
87
91
  // }
88
- })
92
+ });
93
+
94
+ let needsUpdate = false;
89
95
 
90
96
  if (this.Root?.gameObject === this.gameObject) {
91
97
  this.gameObject.add(container);
@@ -95,6 +101,7 @@ export class BaseUIComponent extends Behaviour {
95
101
  if (targetShadowComponent) {
96
102
  // console.log("ADD", this.name, "to", this._parentComponent.name, targetShadowComponent);
97
103
  targetShadowComponent?.add(container);
104
+ needsUpdate = true;
98
105
  }
99
106
  }
100
107
  this.shadowComponent = container;
@@ -108,7 +115,11 @@ export class BaseUIComponent extends Behaviour {
108
115
  }
109
116
 
110
117
  this.onAfterAddedToScene();
111
- // this.startCoroutine(this._updateRenderSettingsDelayed(), FrameEvent.OnBeforeRender);
118
+
119
+ // make sure to update the layout when adding content
120
+ // otherwise it will fail when object are enabled at runtime
121
+ if (needsUpdate)
122
+ ThreeMeshUI.update();
112
123
  }
113
124
 
114
125
 
@@ -127,7 +138,7 @@ export class BaseUIComponent extends Behaviour {
127
138
 
128
139
  private traverseOwnedShadowComponents(current: Object3D, owner: any, callback: (obj: any) => void) {
129
140
  if (!current) return;
130
- if (current["shadowComponentOwner"] === owner) {
141
+ if (current[$shadowDomOwner] === owner) {
131
142
  callback(current);
132
143
  for (const ch of current.children) {
133
144
  this.traverseOwnedShadowComponents(ch, owner, callback);
@@ -4,6 +4,9 @@ import { FrameEvent } from "../../engine/engine_setup";
4
4
  import { BaseUIComponent, UIRootComponent } from "./BaseUIComponent";
5
5
  import { Mathf } from "../../engine/engine_math";
6
6
  import * as THREE from "three";
7
+ import { getComponentsInChildren } from "../../engine/engine_components";
8
+ import { IComponent } from "../../engine/engine_types";
9
+ import { GameObject } from "../Component";
7
10
 
8
11
  export enum RenderMode {
9
12
  ScreenSpaceOverlay = 0,
@@ -84,6 +87,15 @@ export class Canvas extends UIRootComponent {
84
87
  return this._rootCanvas;
85
88
  }
86
89
 
90
+ private _scaleFactor: number = 1;
91
+ @serializeable()
92
+ get scaleFactor(): number {
93
+ return this._scaleFactor;
94
+ }
95
+ private set scaleFactor(val: number) {
96
+ this._scaleFactor = val;
97
+ }
98
+
87
99
  awake() {
88
100
  this.shadowComponent = this.gameObject;
89
101
  super.awake();
@@ -118,7 +130,7 @@ export class Canvas extends UIRootComponent {
118
130
  this.updateRenderMode();
119
131
  // this.onWillUpdateRenderSettings();
120
132
  updateRenderSettingsRecursive(this.shadowComponent, this);
121
- for (const ch of this.gameObject.getComponentsInChildren(BaseUIComponent)) {
133
+ for (const ch of GameObject.getComponentsInChildren(this.gameObject, BaseUIComponent)) {
122
134
  updateRenderSettingsRecursive(ch.shadowComponent!, this);
123
135
  }
124
136
  }
@@ -126,7 +138,7 @@ export class Canvas extends UIRootComponent {
126
138
 
127
139
  private _activeRenderMode: RenderMode = -1;
128
140
 
129
- private get isScreenSpace() : boolean {
141
+ private get isScreenSpace(): boolean {
130
142
  return this._activeRenderMode === RenderMode.ScreenSpaceCamera || this._activeRenderMode === RenderMode.ScreenSpaceOverlay;
131
143
  }
132
144
 
@@ -0,0 +1,21 @@
1
+ // import { serializeable } from "../../engine/engine_serialization";
2
+ // import { Behaviour } from "../Component";
3
+
4
+
5
+ // export class CanvasScaler extends Behaviour {
6
+
7
+ // private _dynamicPixelsPerUnit: number = 1;
8
+
9
+ // @serializeable()
10
+ // get dynamicPixelsPerUnit(): number {
11
+ // return this._dynamicPixelsPerUnit;
12
+ // }
13
+
14
+ // private set dynamicPixelsPerUnit(val: number) {
15
+ // this._dynamicPixelsPerUnit = val;
16
+ // }
17
+
18
+ // awake() {
19
+ // console.log(this);
20
+ // }
21
+ // }
@@ -11,6 +11,8 @@ import { InputEvents, KeyCode } from "../../engine/engine_input";
11
11
  import { Object3D } from "three";
12
12
  import { ICanvasGroup, IGraphic } from "./Interfaces";
13
13
  import { getParam } from "../../engine/engine_utils";
14
+ import { UIRaycastUtils } from "./RaycastUtils";
15
+ import { $shadowDomOwner } from "./BaseUIComponent";
14
16
 
15
17
  const debug = getParam("debugeventsystem");
16
18
 
@@ -298,6 +300,8 @@ export class EventSystem extends Behaviour {
298
300
  }
299
301
 
300
302
  private handleEventsArray: Array<Behaviour> = [];
303
+ private out: { canvasGroup?: ICanvasGroup } = {};
304
+
301
305
  private handleEvents(object: THREE.Object3D, args: PointerEventData): boolean {
302
306
 
303
307
  if (!this.testIsVisible(object)) {
@@ -318,20 +322,12 @@ export class EventSystem extends Behaviour {
318
322
  // handle potential shadow dom built from three mesh ui
319
323
  if (parent && parent.isUI) {
320
324
  const pressedOrClicked = (args.isPressed || args.isClicked) ?? false;
321
- if (parent.shadowComponentOwner) {
322
- const actualGo = parent.shadowComponentOwner.gameObject;
325
+ if (parent[$shadowDomOwner]) {
326
+ const actualGo = parent[$shadowDomOwner].gameObject;
323
327
  if (actualGo) {
324
- canvasGroup = this.tryFindCanvasGroup(actualGo);
325
- if (canvasGroup?.isCanvasGroup === true) {
326
- if (canvasGroup.blocksRaycasts === false) return false;
327
- if (canvasGroup.interactable === false) return true;
328
- }
329
- // handle Graphic Raycast target
330
- const graphic = GameObject.foreachComponent(actualGo, c => {
331
- if (typeof (c as unknown as IGraphic).raycastTarget === "boolean") return c;
332
- return undefined;
333
- }, false);
334
- if (graphic?.raycastTarget === false) return false;
328
+ const res = UIRaycastUtils.isInteractable(actualGo, this.out);
329
+ if(!res) return this.out.canvasGroup?.interactable ?? false;
330
+ canvasGroup = this.out.canvasGroup ?? null;
335
331
 
336
332
  const handled = this.handleMeshUIIntersection(object, pressedOrClicked);
337
333
  if (!clicked && handled) {
@@ -348,6 +344,8 @@ export class EventSystem extends Behaviour {
348
344
  }
349
345
  }
350
346
 
347
+ if (clicked)
348
+ console.log(this.context.time.frame, object);
351
349
  this.objectsHoveredThisFrame.push(object);
352
350
 
353
351
  if (canvasGroup === null || canvasGroup.interactable) {
@@ -429,18 +427,6 @@ export class EventSystem extends Behaviour {
429
427
  if (!GameObject.isActiveSelf(obj)) return false;
430
428
  return this.testIsVisible(obj.parent);
431
429
  }
432
-
433
- private tryFindCanvasGroup(obj: THREE.Object3D | null): ICanvasGroup | null {
434
- if (!obj) return null;
435
- // test for canvas groups
436
- const res = GameObject.foreachComponent(obj, c => {
437
- const gr = c as unknown as ICanvasGroup;
438
- if (gr.blocksRaycasts !== undefined && gr.interactable !== undefined) return gr;
439
- return undefined;
440
- }, false);
441
- if (res !== undefined) return res;
442
- return this.tryFindCanvasGroup(obj.parent);
443
- }
444
430
  }
445
431
 
446
432
 
@@ -6,6 +6,7 @@ import { serializeable } from '../../engine/engine_serialization_decorator';
6
6
  import { Color, Texture } from 'three';
7
7
  import { RectTransform } from './RectTransform';
8
8
  import { onChange, scheduleAction } from "./Utils"
9
+ import { GameObject } from '../Component';
9
10
 
10
11
 
11
12
  export class Graphic extends BaseUIComponent implements IGraphic {
@@ -45,7 +46,7 @@ export class Graphic extends BaseUIComponent implements IGraphic {
45
46
  private _rect: RectTransform | null = null;
46
47
  protected get rectTransform(): RectTransform {
47
48
  if (!this._rect) {
48
- this._rect = this.gameObject.getComponent(RectTransform);
49
+ this._rect = GameObject.getComponent(this.gameObject, RectTransform);
49
50
  }
50
51
  return this._rect!;
51
52
  }
@@ -4,6 +4,7 @@ import { BaseUIComponent, includesDir } from './BaseUIComponent';
4
4
  import { Text } from './Text';
5
5
  import { getWorldScale } from '../../engine/engine_three_utils';
6
6
  import { RectTransform } from './RectTransform';
7
+ import { GameObject } from '../Component';
7
8
 
8
9
 
9
10
  enum KeymapOption {
@@ -63,7 +64,7 @@ export class Keyboard extends BaseUIComponent {
63
64
 
64
65
  const fontName = this.font ? this.font : "arial";
65
66
 
66
- const rt = this.gameObject.getComponent(RectTransform);
67
+ const rt = GameObject.getComponent(this.gameObject, RectTransform);
67
68
  if(!rt){
68
69
  console.error("Missing rect transform, please add this component inside a canvas");
69
70
  return;
@@ -0,0 +1,64 @@
1
+ import { foreachComponent } from "../../engine/engine_gameobject";
2
+ import { objectSerializer } from "../../engine/engine_serialization_builtin_serializer";
3
+ import { IComponent } from "../../engine/engine_types";
4
+ import { $shadowDomOwner } from "./BaseUIComponent";
5
+ import { ICanvasGroup, IGraphic } from "./Interfaces";
6
+ import { Object3D } from "three";
7
+
8
+
9
+ export class UIRaycastUtils {
10
+
11
+ /** returns the real object when dealing with shadow UI */
12
+ static getObject(obj: Object3D): Object3D {
13
+ const shadowOwner = obj[$shadowDomOwner];
14
+ if(shadowOwner)
15
+ {
16
+ if((shadowOwner as IComponent).isComponent === true) obj = (shadowOwner as IComponent).gameObject;
17
+ else obj = shadowOwner;
18
+ }
19
+ return obj;
20
+ };
21
+
22
+ static isInteractable(obj: THREE.Object3D, out?: { canvasGroup?: ICanvasGroup, graphic?: IGraphic }): boolean {
23
+ if(obj === null || obj === undefined || !obj.visible) return false;
24
+
25
+ obj = this.getObject(obj);
26
+
27
+ if(!obj.visible) return false;
28
+
29
+ const canvasGroup = this.tryFindCanvasGroup(obj);
30
+ if (canvasGroup?.isCanvasGroup === true) {
31
+ if (out) out.canvasGroup = canvasGroup as ICanvasGroup;
32
+ if (canvasGroup.blocksRaycasts === false) return false;
33
+ if (canvasGroup.interactable === false) return false;
34
+ }
35
+ // handle Graphic Raycast target
36
+ const graphic = foreachComponent(obj, c => {
37
+ if ((c as unknown as IGraphic).isGraphic === true) return c;
38
+ return undefined;
39
+ }, false);
40
+ // console.log(obj, graphic?.raycastTarget);
41
+ if (out) {
42
+ if (graphic?.isGraphic === true)
43
+ out.graphic = graphic as IGraphic;
44
+ }
45
+ if (graphic?.raycastTarget === false) return false;
46
+
47
+ console.log(graphic);
48
+ return true;
49
+ }
50
+
51
+
52
+ private static tryFindCanvasGroup(obj: THREE.Object3D | null): ICanvasGroup | null {
53
+ if (!obj) return null;
54
+ // test for canvas groups
55
+ const res = foreachComponent(obj, c => {
56
+ const gr = c as unknown as ICanvasGroup;
57
+ if (gr.blocksRaycasts !== undefined && gr.interactable !== undefined) return gr;
58
+ return undefined;
59
+ }, false);
60
+ if (res !== undefined) return res;
61
+ return this.tryFindCanvasGroup(obj.parent);
62
+ }
63
+ }
64
+
@@ -44,4 +44,6 @@ export class GraphicRaycaster extends ObjectRaycaster {
44
44
  eventCamera: Camera | null = null;
45
45
  ignoreReversedGraphics: boolean = false;
46
46
  rootRaycaster: GraphicRaycaster | null = null;
47
+
48
+
47
49
  }
@@ -1,6 +1,6 @@
1
1
  import { Graphic } from './Graphic';
2
2
  import * as ThreeMeshUI from 'three-mesh-ui'
3
- import { includesDir } from "./BaseUIComponent";
3
+ import { $shadowDomOwner, includesDir } from "./BaseUIComponent";
4
4
  import { RectTransform } from './RectTransform';
5
5
  import { Color } from 'three';
6
6
  import { FrameEvent } from '../../engine/engine_setup';
@@ -163,11 +163,15 @@ export class Text extends Graphic {
163
163
  private _textContainer: any = null;
164
164
 
165
165
  private getTextOpts(): object {
166
+ let fontSize = this.fontSize;
167
+ // if (this.canvas) {
168
+ // fontSize /= this.canvas?.scaleFactor;
169
+ // }
166
170
  const textOpts = {
167
171
  content: this.text,
168
172
  fontColor: this.color,
169
173
  fontOpacity: this.color.alpha,
170
- fontSize: this.fontSize,
174
+ fontSize: fontSize,
171
175
  fontKerning: "normal",
172
176
  };
173
177
  this.font = this.font?.toLocaleLowerCase();
@@ -274,8 +278,8 @@ export class Text extends Graphic {
274
278
  private ensureShadowComponentOwner() {
275
279
  if (this.shadowComponent) {
276
280
  this.shadowComponent.traverse(c => {
277
- if (c["shadowComponentOwner"] === undefined)
278
- c["shadowComponentOwner"] = this;
281
+ if (c[$shadowDomOwner] === undefined)
282
+ c[$shadowDomOwner] = this;
279
283
  });
280
284
  }
281
285
  }
@@ -2,6 +2,7 @@
2
2
  import { FrontSide, DoubleSide, BackSide, TetrahedronGeometry } from "three"
3
3
  import { FrameEvent } from "../../engine/engine_setup";
4
4
  import { Behaviour, GameObject } from "../Component";
5
+ import { $shadowDomOwner } from "./BaseUIComponent";
5
6
 
6
7
  // export function makeNonRaycastable(obj: THREE.Object3D | null | undefined, recursive: boolean = false) {
7
8
  // if (!obj) return;
@@ -14,7 +15,7 @@ import { Behaviour, GameObject } from "../Component";
14
15
  // }
15
16
 
16
17
  export function isUIObject(obj: THREE.Object3D) {
17
- return obj["isUI"] === true || typeof obj["shadowComponentOwner"] === "object";
18
+ return obj["isUI"] === true || typeof obj[$shadowDomOwner] === "object";
18
19
  }
19
20
 
20
21
  export type RenderSettings = {
@@ -27,7 +28,7 @@ export type RenderSettings = {
27
28
 
28
29
  export function updateRenderSettings(shadowComponent: THREE.Object3D, settings: RenderSettings) {
29
30
  if (!shadowComponent) return;
30
- // const owner = shadowComponent["shadowComponentOwner"];
31
+ // const owner = shadowComponent[$shadowDomOwner];
31
32
  // if (!owner)
32
33
  // console.log(shadowComponent)
33
34
  const mat = shadowComponent["material"];
@@ -1,17 +1,20 @@
1
1
  import "./engine/engine_element";
2
2
  import "./engine/engine_setup";
3
- import * as Components from "./engine-components/codegen/components";
3
+ import "./engine/codegen/register_types";
4
4
  // import "./engine/engine_mainloop";
5
5
  // import "./engine-components/DomOverlay";
6
6
 
7
+
7
8
  export { GameObject, Behaviour } from "./engine-components/Component";
8
9
  export { serializeable } from "./engine/engine_serialization_decorator";
9
- export { Collision } from "./engine/engine_physics";
10
+ export { Collision } from "./engine/engine_types";
11
+ export * from "./engine/api";
10
12
  export * from "./engine-components/codegen/components";
11
13
 
12
14
 
13
15
  export * from "./engine-components/js-extensions/Object3D";
14
16
 
17
+
15
18
  // make accessible for external javascript
16
19
  import { Context } from "./engine/engine_setup";
17
20
  const Needle = { Context: Context };
@@ -23,6 +26,8 @@ function registerGlobal(obj: object) {
23
26
  }
24
27
  import * as Component from "./engine-components/Component";
25
28
  registerGlobal(Component);
29
+
30
+ import * as Components from "./engine-components/codegen/components";
26
31
  registerGlobal(Components);
27
32
 
28
33
  import { GameObject } from "./engine-components/Component";