@needle-tools/engine 4.3.0-alpha → 4.3.0-alpha.1

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 (101) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/needle-engine.bundle.js +1467 -222
  3. package/dist/needle-engine.bundle.light.js +1467 -222
  4. package/dist/needle-engine.bundle.light.min.js +32 -32
  5. package/dist/needle-engine.bundle.light.umd.cjs +3 -3
  6. package/dist/needle-engine.bundle.min.js +3 -3
  7. package/dist/needle-engine.bundle.umd.cjs +3 -3
  8. package/dist/needle-engine.light.d.ts +9 -9
  9. package/lib/engine/engine_types.d.ts +162 -17
  10. package/lib/engine-components/Animator.d.ts +129 -21
  11. package/lib/engine-components/Animator.js +115 -21
  12. package/lib/engine-components/Animator.js.map +1 -1
  13. package/lib/engine-components/AnimatorController.d.ts +161 -32
  14. package/lib/engine-components/AnimatorController.js +176 -29
  15. package/lib/engine-components/AnimatorController.js.map +1 -1
  16. package/lib/engine-components/AudioListener.d.ts +16 -5
  17. package/lib/engine-components/AudioListener.js +16 -5
  18. package/lib/engine-components/AudioListener.js.map +1 -1
  19. package/lib/engine-components/AudioSource.d.ts +120 -28
  20. package/lib/engine-components/AudioSource.js +120 -37
  21. package/lib/engine-components/AudioSource.js.map +1 -1
  22. package/lib/engine-components/AvatarLoader.d.ts +61 -0
  23. package/lib/engine-components/AvatarLoader.js +61 -1
  24. package/lib/engine-components/AvatarLoader.js.map +1 -1
  25. package/lib/engine-components/AxesHelper.d.ts +19 -1
  26. package/lib/engine-components/AxesHelper.js +19 -1
  27. package/lib/engine-components/AxesHelper.js.map +1 -1
  28. package/lib/engine-components/BoxHelperComponent.d.ts +26 -0
  29. package/lib/engine-components/BoxHelperComponent.js +26 -0
  30. package/lib/engine-components/BoxHelperComponent.js.map +1 -1
  31. package/lib/engine-components/Camera.d.ts +126 -37
  32. package/lib/engine-components/Camera.js +139 -37
  33. package/lib/engine-components/Camera.js.map +1 -1
  34. package/lib/engine-components/CameraUtils.js +20 -0
  35. package/lib/engine-components/CameraUtils.js.map +1 -1
  36. package/lib/engine-components/Collider.d.ts +95 -21
  37. package/lib/engine-components/Collider.js +100 -23
  38. package/lib/engine-components/Collider.js.map +1 -1
  39. package/lib/engine-components/Component.d.ts +554 -106
  40. package/lib/engine-components/Component.js +352 -81
  41. package/lib/engine-components/Component.js.map +1 -1
  42. package/lib/engine-components/DragControls.d.ts +95 -21
  43. package/lib/engine-components/DragControls.js +126 -32
  44. package/lib/engine-components/DragControls.js.map +1 -1
  45. package/lib/engine-components/DropListener.d.ts +99 -16
  46. package/lib/engine-components/DropListener.js +119 -14
  47. package/lib/engine-components/DropListener.js.map +1 -1
  48. package/lib/engine-components/Light.d.ts +102 -5
  49. package/lib/engine-components/Light.js +102 -44
  50. package/lib/engine-components/Light.js.map +1 -1
  51. package/lib/engine-components/NeedleMenu.d.ts +28 -11
  52. package/lib/engine-components/NeedleMenu.js +28 -11
  53. package/lib/engine-components/NeedleMenu.js.map +1 -1
  54. package/lib/engine-components/Networking.d.ts +37 -5
  55. package/lib/engine-components/Networking.js +37 -5
  56. package/lib/engine-components/Networking.js.map +1 -1
  57. package/lib/engine-components/SceneSwitcher.js +44 -0
  58. package/lib/engine-components/SceneSwitcher.js.map +1 -1
  59. package/lib/engine-components/SpatialTrigger.d.ts +66 -1
  60. package/lib/engine-components/SpatialTrigger.js +74 -2
  61. package/lib/engine-components/SpatialTrigger.js.map +1 -1
  62. package/lib/engine-components/SpectatorCamera.d.ts +66 -4
  63. package/lib/engine-components/SpectatorCamera.js +132 -6
  64. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  65. package/lib/engine-components/SyncedTransform.d.ts +45 -6
  66. package/lib/engine-components/SyncedTransform.js +45 -6
  67. package/lib/engine-components/SyncedTransform.js.map +1 -1
  68. package/lib/engine-components/TransformGizmo.d.ts +49 -3
  69. package/lib/engine-components/TransformGizmo.js +49 -3
  70. package/lib/engine-components/TransformGizmo.js.map +1 -1
  71. package/lib/engine-components/webxr/WebXR.d.ts +131 -22
  72. package/lib/engine-components/webxr/WebXR.js +132 -23
  73. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  74. package/lib/engine-components-experimental/networking/PlayerSync.d.ts +82 -9
  75. package/lib/engine-components-experimental/networking/PlayerSync.js +76 -11
  76. package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
  77. package/package.json +1 -1
  78. package/src/engine/engine_types.ts +179 -18
  79. package/src/engine-components/Animator.ts +142 -22
  80. package/src/engine-components/AnimatorController.ts +184 -34
  81. package/src/engine-components/AudioListener.ts +16 -5
  82. package/src/engine-components/AudioSource.ts +126 -37
  83. package/src/engine-components/AvatarLoader.ts +61 -2
  84. package/src/engine-components/AxesHelper.ts +21 -1
  85. package/src/engine-components/BoxHelperComponent.ts +26 -0
  86. package/src/engine-components/Camera.ts +147 -41
  87. package/src/engine-components/CameraUtils.ts +20 -0
  88. package/src/engine-components/Collider.ts +102 -27
  89. package/src/engine-components/Component.ts +605 -129
  90. package/src/engine-components/DragControls.ts +134 -38
  91. package/src/engine-components/DropListener.ts +143 -23
  92. package/src/engine-components/Light.ts +105 -44
  93. package/src/engine-components/NeedleMenu.ts +29 -11
  94. package/src/engine-components/Networking.ts +37 -6
  95. package/src/engine-components/SceneSwitcher.ts +48 -1
  96. package/src/engine-components/SpatialTrigger.ts +80 -3
  97. package/src/engine-components/SpectatorCamera.ts +136 -18
  98. package/src/engine-components/SyncedTransform.ts +50 -7
  99. package/src/engine-components/TransformGizmo.ts +49 -4
  100. package/src/engine-components/webxr/WebXR.ts +144 -27
  101. package/src/engine-components-experimental/networking/PlayerSync.ts +85 -13
@@ -8,125 +8,339 @@ import type { Collision, ComponentInit, Constructor, ConstructorConcrete, GuidsM
8
8
  import type { INeedleXRSessionEventReceiver, NeedleXRControllerEventArgs, NeedleXREventArgs } from "../engine/engine_xr.js";
9
9
  import { type IPointerEventHandler, PointerEventData } from "./ui/PointerEvents.js";
10
10
  /**
11
- * All {@type Object3D} types that are loaded in Needle Engine do automatically receive the GameObject extensions like `addComponent` etc.
12
- * Many of the GameObject methods can be imported directly via `@needle-tools/engine` as well:
11
+ * Base class for objects in Needle Engine. Extends {@link Object3D} from three.js.
12
+ * GameObjects can have components attached to them, which can be used to add functionality to the object.
13
+ * They manage their components and provide methods to add, remove and get components.
14
+ *
15
+ * All {@link Object3D} types loaded in Needle Engine have methods like {@link addComponent}.
16
+ * These methods are available directly on the GameObject instance:
17
+ * ```typescript
18
+ * target.addComponent(MyComponent);
19
+ * ```
20
+ *
21
+ * And can be called statically on the GameObject class as well:
13
22
  * ```typescript
14
- * import { addComponent } from "@needle-tools/engine";
23
+ * GameObject.setActive(target, true);
15
24
  * ```
16
25
  */
17
26
  export declare abstract class GameObject extends Object3D implements Object3D, IGameObject {
27
+ /**
28
+ * Indicates if the GameObject is currently active. Inactive GameObjects will not be rendered or updated.
29
+ * When the activeSelf state changes, components will receive {@link Component.onEnable} or {@link Component.onDisable} callbacks.
30
+ */
18
31
  abstract activeSelf: boolean;
19
- /** @deprecated use `addComponent` */
32
+ /** @deprecated Use {@link addComponent} instead */
20
33
  abstract addNewComponent<T extends IComponent>(type: ConstructorConcrete<T>, init?: ComponentInit<T>): T;
21
- /** creates a new component on this gameObject */
34
+ /**
35
+ * Creates a new component on this gameObject or adds an existing component instance
36
+ * @param comp Component type constructor or existing component instance
37
+ * @param init Optional initialization values for the component
38
+ * @returns The newly created or added component
39
+ */
22
40
  abstract addComponent<T extends IComponent>(comp: T | ConstructorConcrete<T>, init?: ComponentInit<T>): T;
41
+ /**
42
+ * Removes a component from this GameObject
43
+ * @param comp Component instance to remove
44
+ * @returns The removed component
45
+ */
23
46
  abstract removeComponent<T extends IComponent>(comp: T): T;
47
+ /**
48
+ * Gets an existing component of the specified type or adds a new one if it doesn't exist
49
+ * @param typeName Constructor of the component type to get or add
50
+ * @returns The existing or newly added component
51
+ */
24
52
  abstract getOrAddComponent<T>(typeName: ConstructorConcrete<T> | null): T;
53
+ /**
54
+ * Gets a component of the specified type attached to this GameObject
55
+ * @param type Constructor of the component type to get
56
+ * @returns The component if found, otherwise null
57
+ */
25
58
  abstract getComponent<T>(type: Constructor<T>): T | null;
59
+ /**
60
+ * Gets all components of the specified type attached to this GameObject
61
+ * @param type Constructor of the component type to get
62
+ * @param arr Optional array to populate with the components
63
+ * @returns Array of components
64
+ */
26
65
  abstract getComponents<T>(type: Constructor<T>, arr?: T[]): Array<T>;
66
+ /**
67
+ * Gets a component of the specified type in this GameObject's children hierarchy
68
+ * @param type Constructor of the component type to get
69
+ * @returns The first matching component if found, otherwise null
70
+ */
27
71
  abstract getComponentInChildren<T>(type: Constructor<T>): T | null;
72
+ /**
73
+ * Gets all components of the specified type in this GameObject's children hierarchy
74
+ * @param type Constructor of the component type to get
75
+ * @param arr Optional array to populate with the components
76
+ * @returns Array of components
77
+ */
28
78
  abstract getComponentsInChildren<T>(type: Constructor<T>, arr?: T[]): Array<T>;
79
+ /**
80
+ * Gets a component of the specified type in this GameObject's parent hierarchy
81
+ * @param type Constructor of the component type to get
82
+ * @returns The first matching component if found, otherwise null
83
+ */
29
84
  abstract getComponentInParent<T>(type: Constructor<T>): T | null;
85
+ /**
86
+ * Gets all components of the specified type in this GameObject's parent hierarchy
87
+ * @param type Constructor of the component type to get
88
+ * @param arr Optional array to populate with the components
89
+ * @returns Array of components
90
+ */
30
91
  abstract getComponentsInParent<T>(type: Constructor<T>, arr?: T[]): Array<T>;
92
+ /**
93
+ * The position of this GameObject in world space
94
+ */
31
95
  abstract get worldPosition(): Vector3;
32
96
  abstract set worldPosition(val: Vector3);
97
+ /**
98
+ * The rotation of this GameObject in world space as a quaternion
99
+ */
33
100
  abstract set worldQuaternion(val: Quaternion);
34
101
  abstract get worldQuaternion(): Quaternion;
102
+ /**
103
+ * The rotation of this GameObject in world space in euler angles (degrees)
104
+ */
35
105
  abstract set worldRotation(val: Vector3);
36
106
  abstract get worldRotation(): Vector3;
107
+ /**
108
+ * The scale of this GameObject in world space
109
+ */
37
110
  abstract set worldScale(val: Vector3);
38
111
  abstract get worldScale(): Vector3;
112
+ /**
113
+ * The forward direction vector of this GameObject in world space
114
+ */
39
115
  abstract get worldForward(): Vector3;
116
+ /**
117
+ * The right direction vector of this GameObject in world space
118
+ */
40
119
  abstract get worldRight(): Vector3;
120
+ /**
121
+ * The up direction vector of this GameObject in world space
122
+ */
41
123
  abstract get worldUp(): Vector3;
124
+ /**
125
+ * Unique identifier for this GameObject
126
+ */
42
127
  guid: string | undefined;
128
+ /**
129
+ * Destroys this GameObject and all its components.
130
+ * Internally, this is added to the three.js {@link Object3D} prototype.
131
+ */
43
132
  abstract destroy(): any;
133
+ /**
134
+ * Checks if a GameObject has been destroyed
135
+ * @param go The GameObject to check
136
+ * @returns True if the GameObject has been destroyed
137
+ */
44
138
  static isDestroyed(go: Object3D): boolean;
139
+ /**
140
+ * Sets the active state of a GameObject
141
+ * @param go The GameObject to modify
142
+ * @param active Whether the GameObject should be active
143
+ * @param processStart Whether to process the start callbacks if being activated
144
+ */
45
145
  static setActive(go: Object3D, active: boolean, processStart?: boolean): void;
46
- /** If the object is active (same as go.visible) */
146
+ /**
147
+ * Checks if the GameObject itself is active (same as go.visible)
148
+ * @param go The GameObject to check
149
+ * @returns True if the GameObject is active
150
+ */
47
151
  static isActiveSelf(go: Object3D): boolean;
48
- /** If the object is active in the hierarchy (e.g. if any parent is invisible or not in the scene it will be false)
49
- * @param go object to check
50
- */
152
+ /**
153
+ * Checks if the GameObject is active in the hierarchy (e.g. if any parent is invisible or not in the scene it will be false)
154
+ * @param go The GameObject to check
155
+ * @returns True if the GameObject is active in the hierarchy
156
+ */
51
157
  static isActiveInHierarchy(go: Object3D): boolean;
158
+ /**
159
+ * Marks a GameObject to be rendered using instancing
160
+ * @param go The GameObject to mark
161
+ * @param instanced Whether the GameObject should use instanced rendering
162
+ */
52
163
  static markAsInstancedRendered(go: Object3D, instanced: boolean): void;
164
+ /**
165
+ * Checks if a GameObject is using instanced rendering
166
+ * @param instance The GameObject to check
167
+ * @returns True if the GameObject is using instanced rendering
168
+ */
53
169
  static isUsingInstancing(instance: Object3D): boolean;
54
- /** Run a callback for all components of the provided type on the provided object and its children (if recursive is true)
55
- * @param instance object to run the method on
56
- * @param cb callback to run on each component, "return undefined;" to continue and "return <anything>;" to break the loop
57
- * @param recursive if true, the method will be run on all children as well
58
- * @returns the last return value of the callback
170
+ /**
171
+ * Executes a callback for all components of the provided type on the provided object and its children
172
+ * @param instance Object to run the method on
173
+ * @param cb Callback to run on each component, "return undefined;" to continue and "return <anything>;" to break the loop
174
+ * @param recursive If true, the method will be run on all children as well
175
+ * @returns The last return value of the callback
59
176
  */
60
177
  static foreachComponent(instance: Object3D, cb: (comp: Component) => any, recursive?: boolean): any;
61
- /** Creates a new instance of the provided object. The new instance will be created on all connected clients
62
- * @param instance object to instantiate
63
- * @param opts options for the instantiation
178
+ /**
179
+ * Creates a new instance of the provided object that will be replicated to all connected clients
180
+ * @param instance Object to instantiate
181
+ * @param opts Options for the instantiation
182
+ * @returns The newly created instance or null if creation failed
64
183
  */
65
184
  static instantiateSynced(instance: GameObject | Object3D | null, opts: SyncInstantiateOptions): GameObject | null;
66
- /** Creates a new instance of the provided object (like cloning it including all components and children)
67
- * @param instance object to instantiate
68
- * @param opts options for the instantiation (e.g. with what parent, position, etc.)
69
- */
185
+ /**
186
+ * Creates a new instance of the provided object (like cloning it including all components and children)
187
+ * @param instance Object to instantiate
188
+ * @param opts Options for the instantiation (e.g. with what parent, position, etc.)
189
+ * @returns The newly created instance
190
+ */
70
191
  static instantiate(instance: AssetReference, opts?: IInstantiateOptions | null | undefined): Promise<Object3D | null>;
71
192
  static instantiate(instance: GameObject | Object3D, opts?: IInstantiateOptions | null | undefined): GameObject;
72
- /** Destroys a object on all connected clients (if you are in a networked session)
73
- * @param instance object to destroy
74
- */
193
+ /**
194
+ * Destroys an object on all connected clients (if in a networked session)
195
+ * @param instance Object to destroy
196
+ * @param context Optional context to use
197
+ * @param recursive If true, all children will be destroyed as well
198
+ */
75
199
  static destroySynced(instance: Object3D | Component, context?: Context, recursive?: boolean): void;
76
- /** Destroys a object
77
- * @param instance object to destroy
78
- * @param recursive if true, all children will be destroyed as well. true by default
200
+ /**
201
+ * Destroys an object
202
+ * @param instance Object to destroy
203
+ * @param recursive If true, all children will be destroyed as well. Default: true
79
204
  */
80
205
  static destroy(instance: Object3D | Component, recursive?: boolean): void;
81
206
  /**
82
- * Add an object to parent and also ensure all components are being registered
207
+ * Adds an object to parent and ensures all components are properly registered
208
+ * @param instance Object to add
209
+ * @param parent Parent to add the object to
210
+ * @param context Optional context to use
83
211
  */
84
212
  static add(instance: Object3D | null | undefined, parent: Object3D, context?: Context): void;
85
213
  /**
86
214
  * Removes the object from its parent and deactivates all of its components
215
+ * @param instance Object to remove
87
216
  */
88
217
  static remove(instance: Object3D | null | undefined): void;
89
- /** Invokes a method on all components including children (if a method with that name exists) */
218
+ /**
219
+ * Invokes a method on all components including children (if a method with that name exists)
220
+ * @param go GameObject to invoke the method on
221
+ * @param functionName Name of the method to invoke
222
+ * @param args Arguments to pass to the method
223
+ */
90
224
  static invokeOnChildren(go: Object3D | null | undefined, functionName: string, ...args: any): void;
91
- /** Invokes a method on all components that have a method matching the provided name
92
- * @param go object to invoke the method on all components
93
- * @param functionName name of the method to invoke
225
+ /**
226
+ * Invokes a method on all components that have a method matching the provided name
227
+ * @param go GameObject to invoke the method on
228
+ * @param functionName Name of the method to invoke
229
+ * @param children Whether to invoke on children as well
230
+ * @param args Arguments to pass to the method
94
231
  */
95
232
  static invoke(go: Object3D | null | undefined, functionName: string, children?: boolean, ...args: any): void;
96
233
  /** @deprecated use `addComponent` */
97
234
  static addNewComponent<T extends IComponent>(go: IGameObject | Object3D, type: T | ConstructorConcrete<T>, init?: ComponentInit<T>, callAwake?: boolean): T;
98
235
  /**
99
- * Add a new component (or move an existing component) to the provided object
100
- * @param go object to add the component to
101
- * @param instanceOrType if an instance is provided it will be moved to the new object, if a type is provided a new instance will be created and moved to the new object
102
- * @param init optional init object to initialize the component with
103
- * @param callAwake if true, the component will be added and awake will be called immediately
236
+ * Adds a new component (or moves an existing component) to the provided object
237
+ * @param go Object to add the component to
238
+ * @param instanceOrType If an instance is provided it will be moved to the new object, if a type is provided a new instance will be created
239
+ * @param init Optional init object to initialize the component with
240
+ * @param opts Optional options for adding the component
241
+ * @returns The added or moved component
104
242
  */
105
243
  static addComponent<T extends IComponent>(go: IGameObject | Object3D, instanceOrType: T | ConstructorConcrete<T>, init?: ComponentInit<T>, opts?: {
106
244
  callAwake: boolean;
107
245
  }): T;
108
246
  /**
109
247
  * Moves a component to a new object
110
- * @param go component to move the component to
111
- * @param instance component to move to the GO
248
+ * @param go GameObject to move the component to
249
+ * @param instance Component to move
250
+ * @returns The moved component
112
251
  */
113
252
  static moveComponent<T extends IComponent>(go: IGameObject | Object3D, instance: T | ConstructorConcrete<T>): T;
114
- /** Removes a component from its object
115
- * @param instance component to remove
253
+ /**
254
+ * Removes a component from its object
255
+ * @param instance Component to remove
256
+ * @returns The removed component
116
257
  */
117
258
  static removeComponent<T extends IComponent>(instance: T): T;
259
+ /**
260
+ * Gets or adds a component of the specified type
261
+ * @param go GameObject to get or add the component to
262
+ * @param typeName Constructor of the component type
263
+ * @returns The existing or newly added component
264
+ */
118
265
  static getOrAddComponent<T extends IComponent>(go: IGameObject | Object3D, typeName: ConstructorConcrete<T>): T;
119
- /** Gets a component on the provided object */
266
+ /**
267
+ * Gets a component on the provided object
268
+ * @param go GameObject to get the component from
269
+ * @param typeName Constructor of the component type
270
+ * @returns The component if found, otherwise null
271
+ */
120
272
  static getComponent<T extends IComponent>(go: IGameObject | Object3D | null, typeName: Constructor<T> | null): T | null;
273
+ /**
274
+ * Gets all components of the specified type on the provided object
275
+ * @param go GameObject to get the components from
276
+ * @param typeName Constructor of the component type
277
+ * @param arr Optional array to populate with the components
278
+ * @returns Array of components
279
+ */
121
280
  static getComponents<T extends IComponent>(go: IGameObject | Object3D | null, typeName: Constructor<T>, arr?: T[] | null): T[];
281
+ /**
282
+ * Finds an object or component by its unique identifier
283
+ * @param guid Unique identifier to search for
284
+ * @param hierarchy Root object to search in
285
+ * @returns The found GameObject or Component, or null/undefined if not found
286
+ */
122
287
  static findByGuid(guid: string, hierarchy: Object3D): GameObject | Component | null | undefined;
288
+ /**
289
+ * Finds the first object of the specified component type in the scene
290
+ * @param typeName Constructor of the component type
291
+ * @param context Context or root object to search in
292
+ * @param includeInactive Whether to include inactive objects in the search
293
+ * @returns The first matching component if found, otherwise null
294
+ */
123
295
  static findObjectOfType<T extends IComponent>(typeName: Constructor<T>, context?: Context | Object3D, includeInactive?: boolean): T | null;
296
+ /**
297
+ * Finds all objects of the specified component type in the scene
298
+ * @param typeName Constructor of the component type
299
+ * @param context Context or root object to search in
300
+ * @returns Array of matching components
301
+ */
124
302
  static findObjectsOfType<T extends IComponent>(typeName: Constructor<T>, context?: Context | Object3D): Array<T>;
303
+ /**
304
+ * Gets a component of the specified type in the gameObject's children hierarchy
305
+ * @param go GameObject to search in
306
+ * @param typeName Constructor of the component type
307
+ * @returns The first matching component if found, otherwise null
308
+ */
125
309
  static getComponentInChildren<T extends IComponent>(go: IGameObject | Object3D, typeName: Constructor<T>): T | null;
310
+ /**
311
+ * Gets all components of the specified type in the gameObject's children hierarchy
312
+ * @param go GameObject to search in
313
+ * @param typeName Constructor of the component type
314
+ * @param arr Optional array to populate with the components
315
+ * @returns Array of components
316
+ */
126
317
  static getComponentsInChildren<T extends IComponent>(go: IGameObject | Object3D, typeName: Constructor<T>, arr?: T[] | null): Array<T>;
318
+ /**
319
+ * Gets a component of the specified type in the gameObject's parent hierarchy
320
+ * @param go GameObject to search in
321
+ * @param typeName Constructor of the component type
322
+ * @returns The first matching component if found, otherwise null
323
+ */
127
324
  static getComponentInParent<T extends IComponent>(go: IGameObject | Object3D, typeName: Constructor<T>): T | null;
325
+ /**
326
+ * Gets all components of the specified type in the gameObject's parent hierarchy
327
+ * @param go GameObject to search in
328
+ * @param typeName Constructor of the component type
329
+ * @param arr Optional array to populate with the components
330
+ * @returns Array of components
331
+ */
128
332
  static getComponentsInParent<T extends IComponent>(go: IGameObject | Object3D, typeName: Constructor<T>, arr?: Array<T> | null): Array<T>;
333
+ /**
334
+ * Gets all components on the gameObject
335
+ * @param go GameObject to get components from
336
+ * @returns Array of all components
337
+ */
129
338
  static getAllComponents(go: IGameObject | Object3D): Component[];
339
+ /**
340
+ * Iterates through all components on the gameObject
341
+ * @param go GameObject to iterate components on
342
+ * @returns Generator yielding each component
343
+ */
130
344
  static iterateComponents(go: IGameObject | Object3D): Generator<any, void, unknown>;
131
345
  }
132
346
  /**
@@ -156,132 +370,284 @@ export declare abstract class GameObject extends Object3D implements Object3D, I
156
370
  * @group Components
157
371
  */
158
372
  export declare abstract class Component implements IComponent, EventTarget, Partial<INeedleXRSessionEventReceiver>, Partial<IPointerEventHandler> {
159
- /** @internal */
373
+ /**
374
+ * Indicates whether this object is a component
375
+ * @internal
376
+ */
160
377
  get isComponent(): boolean;
161
378
  private __context;
162
- /** Use the context to get access to many Needle Engine features and use physics, timing, access the camera or scene */
379
+ /**
380
+ * The context this component belongs to, providing access to the runtime environment
381
+ * including physics, timing utilities, camera, and scene
382
+ */
163
383
  get context(): Context;
164
384
  set context(context: Context);
165
- /** shorthand for `this.context.scene`
166
- * @returns the scene of the context */
385
+ /**
386
+ * Shorthand accessor for the current scene from the context
387
+ * @returns The scene this component belongs to
388
+ */
167
389
  get scene(): Scene;
168
- /** @returns the layer of the gameObject this component is attached to */
390
+ /**
391
+ * The layer value of the GameObject this component is attached to
392
+ * Used for visibility and physics filtering
393
+ */
169
394
  get layer(): number;
170
- /** @returns the name of the gameObject this component is attached to */
395
+ /**
396
+ * The name of the GameObject this component is attached to
397
+ * Used for debugging and finding objects
398
+ */
171
399
  get name(): string;
172
400
  private __name?;
173
401
  set name(str: string);
174
- /** @returns the tag of the gameObject this component is attached to */
402
+ /**
403
+ * The tag of the GameObject this component is attached to
404
+ * Used for categorizing objects and efficient lookup
405
+ */
175
406
  get tag(): string;
176
407
  set tag(str: string);
177
- /** Is the gameObject marked as static */
408
+ /**
409
+ * Indicates whether the GameObject is marked as static
410
+ * Static objects typically don't move and can be optimized by the engine
411
+ */
178
412
  get static(): boolean;
179
413
  set static(value: boolean);
180
- /** @returns true if the object is enabled and active in the hierarchy */
414
+ /**
415
+ * Checks if this component is currently active (enabled and part of an active GameObject hierarchy)
416
+ * Components that are inactive won't receive lifecycle method calls
417
+ * @returns True if the component is enabled and all parent GameObjects are active
418
+ */
181
419
  get activeAndEnabled(): boolean;
182
420
  private get __isActive();
183
421
  private get __isActiveInHierarchy();
184
422
  private set __isActiveInHierarchy(value);
185
- /** the object this component is attached to. Note that this is a threejs Object3D with some additional features */
423
+ /**
424
+ * Reference to the GameObject this component is attached to
425
+ * This is a three.js Object3D with additional GameObject functionality
426
+ */
186
427
  gameObject: GameObject;
187
- /** the unique identifier for this component */
428
+ /**
429
+ * Unique identifier for this component instance,
430
+ * used for finding and tracking components
431
+ */
188
432
  guid: string;
189
- /** holds the source identifier this object was created with/from (e.g. if it was part of a glTF file the sourceId holds the url to the glTF) */
433
+ /**
434
+ * Identifier for the source asset that created this component.
435
+ * For example, URL to the glTF file this component was loaded from
436
+ */
190
437
  sourceId?: SourceIdentifier;
191
- /** called on a component with a map of old to new guids (e.g. when instantiate generated new guids and e.g. timeline track bindings needs to remape them) */
438
+ /**
439
+ * Called when this component needs to remap guids after an instantiate operation.
440
+ * @param guidsMap Mapping from old guids to newly generated guids
441
+ */
192
442
  resolveGuids?(guidsMap: GuidsMap): void;
193
- /** called once when the component becomes active for the first time (once per component)
194
- * This is the first callback to be called */
443
+ /**
444
+ * Called once when the component becomes active for the first time.
445
+ * This is the first lifecycle callback to be invoked
446
+ */
195
447
  awake(): void;
196
- /** called every time when the component gets enabled (this is invoked after awake and before start)
197
- * or when it becomes active in the hierarchy (e.g. if a parent object or this.gameObject gets set to visible)
198
- */
448
+ /**
449
+ * Called every time the component becomes enabled or active in the hierarchy.
450
+ * Invoked after {@link awake} and before {@link start}.
451
+ */
199
452
  onEnable(): void;
200
- /** called every time the component gets disabled or if a parent object (or this.gameObject) gets set to invisible */
453
+ /**
454
+ * Called every time the component becomes disabled or inactive in the hierarchy.
455
+ * Invoked when the component or any parent GameObject becomes invisible
456
+ */
201
457
  onDisable(): void;
202
- /** Called when the component gets destroyed */
458
+ /**
459
+ * Called when the component is destroyed.
460
+ * Use for cleanup operations like removing event listeners
461
+ */
203
462
  onDestroy(): void;
204
- /** called when you decorate fields with the @validate() decorator
205
- * @param prop the name of the field that was changed
463
+ /**
464
+ * Called when a field decorated with @validate() is modified.
465
+ * @param prop The name of the field that was changed
206
466
  */
207
467
  onValidate?(prop?: string): void;
208
- /** Called for all scripts when the context gets paused or unpaused */
468
+ /**
469
+ * Called when the context's pause state changes.
470
+ * @param isPaused Whether the context is currently paused
471
+ * @param wasPaused The previous pause state
472
+ */
209
473
  onPausedChanged?(isPaused: boolean, wasPaused: boolean): void;
210
- /** called at the beginning of a frame (once per component) */
474
+ /**
475
+ * Called once at the beginning of the first frame after the component is enabled.
476
+ * Use for initialization that requires other components to be awake.
477
+ */
211
478
  start?(): void;
212
- /** first callback in a frame (called every frame when implemented) */
479
+ /**
480
+ * Called at the beginning of each frame before regular updates.
481
+ * Use for logic that needs to run before standard update callbacks.
482
+ */
213
483
  earlyUpdate?(): void;
214
- /** regular callback in a frame (called every frame when implemented) */
484
+ /**
485
+ * Called once per frame during the main update loop.
486
+ * The primary location for frame-based game logic.
487
+ */
215
488
  update?(): void;
216
- /** late callback in a frame (called every frame when implemented) */
489
+ /**
490
+ * Called after all update functions have been called.
491
+ * Use for calculations that depend on other components being updated first.
492
+ */
217
493
  lateUpdate?(): void;
218
- /** called before the scene gets rendered in the main update loop */
494
+ /**
495
+ * Called immediately before the scene is rendered.
496
+ * @param frame Current XRFrame if in an XR session, null otherwise
497
+ */
219
498
  onBeforeRender?(frame: XRFrame | null): void;
220
- /** called after the scene was rendered */
499
+ /**
500
+ * Called after the scene has been rendered.
501
+ * Use for post-processing or UI updates that should happen after rendering
502
+ */
221
503
  onAfterRender?(): void;
504
+ /**
505
+ * Called when this component's collider begins colliding with another collider.
506
+ * @param col Information about the collision that occurred
507
+ */
222
508
  onCollisionEnter?(col: Collision): any;
509
+ /**
510
+ * Called when this component's collider stops colliding with another collider.
511
+ * @param col Information about the collision that ended
512
+ */
223
513
  onCollisionExit?(col: Collision): any;
514
+ /**
515
+ * Called each frame while this component's collider is colliding with another collider
516
+ * @param col Information about the ongoing collision
517
+ */
224
518
  onCollisionStay?(col: Collision): any;
519
+ /**
520
+ * Called when this component's trigger collider is entered by another collider
521
+ * @param col The collider that entered this trigger
522
+ */
225
523
  onTriggerEnter?(col: ICollider): any;
524
+ /**
525
+ * Called each frame while another collider is inside this component's trigger collider
526
+ * @param col The collider that is inside this trigger
527
+ */
226
528
  onTriggerStay?(col: ICollider): any;
529
+ /**
530
+ * Called when another collider exits this component's trigger collider
531
+ * @param col The collider that exited this trigger
532
+ */
227
533
  onTriggerExit?(col: ICollider): any;
228
- /** Optional callback, you can implement this to only get callbacks for VR or AR sessions if necessary.
229
- * @returns true if the mode is supported (if false the mode is not supported by this component and it will not receive XR callbacks for this mode)
230
- */
534
+ /**
535
+ * Determines if this component supports a specific XR mode
536
+ * @param mode The XR session mode to check support for
537
+ * @returns True if the component supports the specified mode
538
+ */
231
539
  supportsXR?(mode: XRSessionMode): boolean;
232
- /** Called before the XR session is requested. Use this callback if you want to modify the session init features */
540
+ /**
541
+ * Called before an XR session is requested
542
+ * Use to modify session initialization parameters
543
+ * @param mode The XR session mode being requested
544
+ * @param args The session initialization parameters that can be modified
545
+ */
233
546
  onBeforeXR?(mode: XRSessionMode, args: XRSessionInit): void;
234
- /** Callback when this component joins a xr session (or becomes active in a running XR session) */
547
+ /**
548
+ * Called when this component joins an XR session or becomes active in a running session
549
+ * @param args Event data for the XR session
550
+ */
235
551
  onEnterXR?(args: NeedleXREventArgs): void;
236
- /** Callback when a xr session updates (while it is still active in XR session) */
552
+ /**
553
+ * Called each frame while this component is active in an XR session
554
+ * @param args Event data for the current XR frame
555
+ */
237
556
  onUpdateXR?(args: NeedleXREventArgs): void;
238
- /** Callback when this component exists a xr session (or when it becomes inactive in a running XR session) */
557
+ /**
558
+ * Called when this component exits an XR session or becomes inactive during a session
559
+ * @param args Event data for the XR session
560
+ */
239
561
  onLeaveXR?(args: NeedleXREventArgs): void;
240
- /** Callback when a controller is connected/added while in a XR session
241
- * OR when the component joins a running XR session that has already connected controllers
242
- * OR when the component becomes active during a running XR session that has already connected controllers */
562
+ /**
563
+ * Called when an XR controller is connected or when this component becomes active
564
+ * in a session with existing controllers
565
+ * @param args Event data for the controller that was added
566
+ */
243
567
  onXRControllerAdded?(args: NeedleXRControllerEventArgs): void;
244
- /** callback when a controller is removed while in a XR session
245
- * OR when the component becomes inactive during a running XR session
246
- */
568
+ /**
569
+ * Called when an XR controller is disconnected or when this component becomes inactive
570
+ * during a session with controllers
571
+ * @param args Event data for the controller that was removed
572
+ */
247
573
  onXRControllerRemoved?(args: NeedleXRControllerEventArgs): void;
574
+ /**
575
+ * Called when a pointer enters this component's GameObject
576
+ * @param args Data about the pointer event
577
+ */
248
578
  onPointerEnter?(args: PointerEventData): any;
579
+ /**
580
+ * Called when a pointer moves while over this component's GameObject
581
+ * @param args Data about the pointer event
582
+ */
249
583
  onPointerMove?(args: PointerEventData): any;
584
+ /**
585
+ * Called when a pointer exits this component's GameObject
586
+ * @param args Data about the pointer event
587
+ */
250
588
  onPointerExit?(args: PointerEventData): any;
589
+ /**
590
+ * Called when a pointer button is pressed while over this component's GameObject
591
+ * @param args Data about the pointer event
592
+ */
251
593
  onPointerDown?(args: PointerEventData): any;
594
+ /**
595
+ * Called when a pointer button is released while over this component's GameObject
596
+ * @param args Data about the pointer event
597
+ */
252
598
  onPointerUp?(args: PointerEventData): any;
599
+ /**
600
+ * Called when a pointer completes a click interaction with this component's GameObject
601
+ * @param args Data about the pointer event
602
+ */
253
603
  onPointerClick?(args: PointerEventData): any;
254
- /** starts a coroutine (javascript generator function)
255
- * `yield` will wait for the next frame:
256
- * - Use `yield WaitForSeconds(1)` to wait for 1 second.
257
- * - Use `yield WaitForFrames(10)` to wait for 10 frames.
258
- * - Use `yield new Promise(...)` to wait for a promise to resolve.
259
- * @param routine generator function to start
260
- * @param evt event to register the coroutine for (default: FrameEvent.Update). Note that all coroutine FrameEvent callbacks are invoked after the matching regular component callbacks. For example `FrameEvent.Update` will be called after regular component `update()` methods)
261
- * @returns the generator function (use it to stop the coroutine with `stopCoroutine`)
604
+ /**
605
+ * Starts a coroutine that can yield to wait for events.
606
+ * Coroutines allow for time-based sequencing of operations without blocking.
607
+ * Coroutines are based on generator functions, a JavaScript language feature.
608
+ *
609
+ * @param routine Generator function to start
610
+ * @param evt Event to register the coroutine for (default: FrameEvent.Update)
611
+ * @returns The generator function that can be used to stop the coroutine
262
612
  * @example
613
+ * Time-based sequencing of operations
263
614
  * ```ts
264
- * onEnable() { this.startCoroutine(this.myCoroutine()); }
615
+ * *myCoroutine() {
616
+ * yield WaitForSeconds(1); // wait for 1 second
617
+ * yield WaitForFrames(10); // wait for 10 frames
618
+ * yield new Promise(resolve => setTimeout(resolve, 1000)); // wait for a promise to resolve
619
+ * }
620
+ * ```
621
+ * @example
622
+ * Coroutine that logs a message every 5 frames
623
+ * ```ts
624
+ * onEnable() {
625
+ * this.startCoroutine(this.myCoroutine());
626
+ * }
265
627
  * private *myCoroutine() {
266
- * while(this.activeAndEnabled) {
267
- * console.log("Hello World", this.context.time.frame);
268
- * // wait for 5 frames
269
- * for(let i = 0; i < 5; i++) yield;
270
- * }
628
+ * while(this.activeAndEnabled) {
629
+ * console.log("Hello World", this.context.time.frame);
630
+ * // wait for 5 frames
631
+ * for(let i = 0; i < 5; i++) yield;
632
+ * }
271
633
  * }
272
634
  * ```
273
635
  */
274
636
  startCoroutine(routine: Generator, evt?: FrameEvent): Generator;
275
637
  /**
276
- * Stop a coroutine that was previously started with `startCoroutine`
277
- * @param routine the routine to be stopped
278
- * @param evt the frame event to unregister the routine from (default: FrameEvent.Update)
638
+ * Stops a coroutine that was previously started with startCoroutine
639
+ * @param routine The routine to be stopped
640
+ * @param evt The frame event the routine was registered with
279
641
  */
280
642
  stopCoroutine(routine: Generator, evt?: FrameEvent): void;
281
- /** @returns true if this component was destroyed (`this.destroy()`) or the whole object this component was part of */
643
+ /**
644
+ * Checks if this component has been destroyed
645
+ * @returns True if the component or its GameObject has been destroyed
646
+ */
282
647
  get destroyed(): boolean;
283
648
  /**
284
- * Destroys this component (and removes it from the object)
649
+ * Destroys this component and removes it from its GameObject
650
+ * After destruction, the component will no longer receive lifecycle callbacks
285
651
  */
286
652
  destroy(): void;
287
653
  /** @internal */
@@ -300,6 +666,11 @@ export declare abstract class Component implements IComponent, EventTarget, Part
300
666
  constructor(init?: ComponentInit<Component>);
301
667
  /** @internal */
302
668
  __internalNewInstanceCreated(init?: ComponentInit<this>): this;
669
+ /**
670
+ * Initializes component properties from an initialization object
671
+ * @param init Object with properties to copy to this component
672
+ * @internal
673
+ */
303
674
  _internalInit(init?: ComponentInit<this>): void;
304
675
  /** @internal */
305
676
  __internalAwake(): void;
@@ -311,31 +682,108 @@ export declare abstract class Component implements IComponent, EventTarget, Part
311
682
  __internalDisable(isRemovingFromScene?: boolean): void;
312
683
  /** @internal */
313
684
  __internalDestroy(): void;
685
+ /**
686
+ * Controls whether this component is enabled
687
+ * Disabled components don't receive lifecycle callbacks
688
+ */
314
689
  get enabled(): boolean;
315
690
  set enabled(val: boolean);
691
+ /**
692
+ * Gets the position of this component's GameObject in world space
693
+ */
316
694
  get worldPosition(): Vector3;
695
+ /**
696
+ * Sets the position of this component's GameObject in world space
697
+ * @param val The world position vector to set
698
+ */
317
699
  set worldPosition(val: Vector3);
700
+ /**
701
+ * Sets the position of this component's GameObject in world space using individual coordinates
702
+ * @param x X-coordinate in world space
703
+ * @param y Y-coordinate in world space
704
+ * @param z Z-coordinate in world space
705
+ */
318
706
  setWorldPosition(x: number, y: number, z: number): void;
707
+ /**
708
+ * Gets the rotation of this component's GameObject in world space as a quaternion
709
+ */
319
710
  get worldQuaternion(): Quaternion;
711
+ /**
712
+ * Sets the rotation of this component's GameObject in world space using a quaternion
713
+ * @param val The world rotation quaternion to set
714
+ */
320
715
  set worldQuaternion(val: Quaternion);
716
+ /**
717
+ * Sets the rotation of this component's GameObject in world space using quaternion components
718
+ * @param x X component of the quaternion
719
+ * @param y Y component of the quaternion
720
+ * @param z Z component of the quaternion
721
+ * @param w W component of the quaternion
722
+ */
321
723
  setWorldQuaternion(x: number, y: number, z: number, w: number): void;
724
+ /**
725
+ * Gets the rotation of this component's GameObject in world space as Euler angles (in radians)
726
+ */
322
727
  get worldEuler(): Euler;
728
+ /**
729
+ * Sets the rotation of this component's GameObject in world space using Euler angles (in radians)
730
+ * @param val The world rotation Euler angles to set
731
+ */
323
732
  set worldEuler(val: Euler);
733
+ /**
734
+ * Gets the rotation of this component's GameObject in world space as Euler angles (in degrees)
735
+ */
324
736
  get worldRotation(): Vector3;
737
+ /**
738
+ * Sets the rotation of this component's GameObject in world space using Euler angles (in degrees)
739
+ * @param val The world rotation vector to set (in degrees)
740
+ */
325
741
  set worldRotation(val: Vector3);
742
+ /**
743
+ * Sets the rotation of this component's GameObject in world space using individual Euler angles
744
+ * @param x X-axis rotation
745
+ * @param y Y-axis rotation
746
+ * @param z Z-axis rotation
747
+ * @param degrees Whether the values are in degrees (true) or radians (false)
748
+ */
326
749
  setWorldRotation(x: number, y: number, z: number, degrees?: boolean): void;
327
750
  private static _forward;
328
- /** Forward (0,0,-1) vector in world space */
751
+ /**
752
+ * Gets the forward direction vector (0,0,-1) of this component's GameObject in world space
753
+ */
329
754
  get forward(): Vector3;
330
755
  private static _right;
331
- /** Right (1,0,0) vector in world space */
756
+ /**
757
+ * Gets the right direction vector (1,0,0) of this component's GameObject in world space
758
+ */
332
759
  get right(): Vector3;
333
760
  private static _up;
334
- /** Up (0,1,0) vector in world space */
761
+ /**
762
+ * Gets the up direction vector (0,1,0) of this component's GameObject in world space
763
+ */
335
764
  get up(): Vector3;
765
+ /**
766
+ * Storage for event listeners registered to this component
767
+ * @private
768
+ */
336
769
  private _eventListeners;
770
+ /**
771
+ * Registers an event listener for the specified event type
772
+ * @param type The event type to listen for
773
+ * @param listener The callback function to execute when the event occurs
774
+ */
337
775
  addEventListener<T extends Event>(type: string, listener: (evt: T) => any): void;
776
+ /**
777
+ * Removes a previously registered event listener
778
+ * @param type The event type the listener was registered for
779
+ * @param listener The callback function to remove
780
+ */
338
781
  removeEventListener<T extends Event>(type: string, listener: (arg: T) => any): void;
782
+ /**
783
+ * Dispatches an event to all registered listeners
784
+ * @param evt The event object to dispatch
785
+ * @returns Always returns false (standard implementation of EventTarget)
786
+ */
339
787
  dispatchEvent(evt: Event): boolean;
340
788
  }
341
789
  export { Component as Behaviour };