@needle-tools/engine 2.31.0-pre → 2.32.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 (46) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/needle-engine.d.ts +148 -141
  3. package/dist/needle-engine.js +332 -332
  4. package/dist/needle-engine.js.map +4 -4
  5. package/dist/needle-engine.min.js +17 -17
  6. package/dist/needle-engine.min.js.map +4 -4
  7. package/lib/engine/debug/error_overlay.js +4 -4
  8. package/lib/engine/debug/error_overlay.js.map +1 -1
  9. package/lib/engine/engine_input.d.ts +87 -102
  10. package/lib/engine/engine_input.js +173 -99
  11. package/lib/engine/engine_input.js.map +1 -1
  12. package/lib/engine/engine_mainloop_utils.d.ts +2 -1
  13. package/lib/engine/engine_mainloop_utils.js +5 -2
  14. package/lib/engine/engine_mainloop_utils.js.map +1 -1
  15. package/lib/engine/engine_physics.d.ts +5 -1
  16. package/lib/engine/engine_physics.js +72 -22
  17. package/lib/engine/engine_physics.js.map +1 -1
  18. package/lib/engine/engine_setup.js +7 -3
  19. package/lib/engine/engine_setup.js.map +1 -1
  20. package/lib/engine/engine_utils.d.ts +9 -7
  21. package/lib/engine/engine_utils.js +35 -2
  22. package/lib/engine/engine_utils.js.map +1 -1
  23. package/lib/engine-components/Component.d.ts +10 -3
  24. package/lib/engine-components/Component.js +98 -40
  25. package/lib/engine-components/Component.js.map +1 -1
  26. package/lib/engine-components/OrbitControls.d.ts +2 -0
  27. package/lib/engine-components/OrbitControls.js +9 -0
  28. package/lib/engine-components/OrbitControls.js.map +1 -1
  29. package/lib/engine-components/Rigidbody.d.ts +12 -6
  30. package/lib/engine-components/Rigidbody.js +64 -17
  31. package/lib/engine-components/Rigidbody.js.map +1 -1
  32. package/lib/engine-components/XRFlag.js.map +1 -1
  33. package/lib/engine-components/ui/Text.js +2 -1
  34. package/lib/engine-components/ui/Text.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/engine/debug/error_overlay.ts +3 -3
  37. package/src/engine/engine_input.ts +179 -103
  38. package/src/engine/engine_mainloop_utils.ts +6 -2
  39. package/src/engine/engine_physics.ts +86 -24
  40. package/src/engine/engine_setup.ts +8 -3
  41. package/src/engine/engine_utils.ts +50 -4
  42. package/src/engine-components/Component.ts +109 -40
  43. package/src/engine-components/OrbitControls.ts +11 -1
  44. package/src/engine-components/RigidBody.ts +76 -20
  45. package/src/engine-components/XRFlag.ts +0 -2
  46. package/src/engine-components/ui/Text.ts +2 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ All notable changes to this package will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.32.0-pre] - 2022-10-15
8
+ - Add: start implementing trigger callbacks for ``onTriggerEnter``, ``onTriggerExit`` and ``onTriggerStay``
9
+ - Change: ``GameObject.setActive`` now updates ``isActiveAndEnabled`` state and executes ``awake`` and ``onEnable`` calls when the object was activated for the first time (e.g. when instantiating from an previously inactive prefab)
10
+ - Change: improve collision callback events for components (``onCollisionEnter``, ``onCollisionExit`` and ``onCollisionStay``)
11
+ - Change: this.context.input keycode enums are now strings
12
+ - Fix: local dev error overlay now also displays errors that happen before web component is completely loaded (e.g. when script has import error)
13
+ - Fix: Rigidbody force is now correctly applied when the component was just instantiated (from inactive prefab) and added to the physics world for the first time
14
+ - Fix: DragControls component keyboard events ("space" and "d" for modifying height and rotation)
15
+
16
+ ## [2.31.1-pre] - 2022-10-14
17
+ - Change: Rigidbody now tracks position changes to detect when to update/override simulated physics body
18
+ - Fix: loading relative font paths when exported via Asset context menu
19
+
7
20
  ## [2.31.0-pre] - 2022-10-13
8
21
  - Add: inital ScreenCapture component for sharing screens and camera streams across all connected users
9
22
  - Add: ``onCollisionEnter``, ``onCollisionStay`` and ``onCollisionExit`` event methods to components
@@ -59,14 +59,16 @@ declare module "engine/engine_utils" {
59
59
  export function delay(milliseconds: number): Promise<void>;
60
60
  export function getPath(source: SourceIdentifier | undefined, uri: string): string;
61
61
  export type WriteCallback = (data: any) => void;
62
- export class Watch {
62
+ export interface IWatch {
63
+ subscribeWrite(callback: WriteCallback): any;
64
+ apply(): any;
65
+ revoke(): any;
66
+ dispose(): any;
67
+ }
68
+ export class Watch implements IWatch {
69
+ private readonly _watches;
70
+ constructor(object: object, str: string[] | string);
63
71
  subscribeWrite(callback: WriteCallback): void;
64
- private writeCallbacks;
65
- constructor(object: object, prop: string);
66
- private _applied;
67
- private _object;
68
- private _prop;
69
- private _wrapperProp;
70
72
  apply(): void;
71
73
  revoke(): void;
72
74
  dispose(): void;
@@ -79,9 +81,10 @@ declare module "engine/engine_constants" {
79
81
  declare module "engine/engine_mainloop_utils" {
80
82
  import { Context } from "engine/engine_setup";
81
83
  import { Component } from "engine-components/Component";
84
+ import { Object3D } from 'three';
82
85
  export function processNewScripts(context: Context): void;
83
86
  export function processRemoveFromScene(script: Component): void;
84
- export function processStart(context: Context): void;
87
+ export function processStart(context: Context, object?: Object3D): void;
85
88
  export function addScriptToArrays(script: any, context: Context): void;
86
89
  export function removeScriptFromContext(script: any, context: Context): void;
87
90
  export function updateIsActive(): void;
@@ -350,27 +353,6 @@ declare module "engine/engine_networking_instantiate" {
350
353
  export type PrefabProviderCallback = (guid: string) => Promise<GameObject | null>;
351
354
  export function registerPrefabProvider(key: string, fn: PrefabProviderCallback): void;
352
355
  }
353
- declare module "engine-components/ui/Utils" {
354
- import { FrameEvent } from "engine/engine_setup";
355
- import { Behaviour } from "engine-components/Component";
356
- export function isUIObject(obj: THREE.Object3D): boolean;
357
- export type RenderSettings = {
358
- renderOnTop?: boolean;
359
- doubleSided?: boolean;
360
- depthWrite?: boolean;
361
- castShadows?: boolean;
362
- receiveShadows?: boolean;
363
- };
364
- export function updateRenderSettings(shadowComponent: THREE.Object3D, settings: RenderSettings): void;
365
- export type RevocableProxy = {
366
- proxy: any;
367
- revoke: () => void;
368
- };
369
- /** internal method to proxy a field to detect changes */
370
- export function onChange<T extends object>(caller: T, field: string, callback: (newValue: any, oldValue: any) => void): RevocableProxy;
371
- /** internal method to schedula a function at a specific moment in the update loop */
372
- export function scheduleAction(caller: Behaviour, action: Function, timing?: FrameEvent): void;
373
- }
374
356
  declare module "engine/engine_serialization_decorator" {
375
357
  import { Constructor } from "engine-components/Component";
376
358
  export type TypeResolver<T> = (data: any) => Constructor<T> | null;
@@ -386,6 +368,7 @@ declare module "engine-components/Rigidbody" {
386
368
  import { Behaviour } from "engine-components/Component";
387
369
  import * as CANNON from 'cannon-es';
388
370
  import * as THREE from 'three';
371
+ import { Vector3 } from "three";
389
372
  export class Rigidbody extends Behaviour {
390
373
  mass: number;
391
374
  set isKinematic(kinematic: boolean);
@@ -401,20 +384,25 @@ declare module "engine-components/Rigidbody" {
401
384
  private currentVelocity;
402
385
  private _smoothedVelocity;
403
386
  private lastWorldPosition;
404
- private dirty;
405
- private transformProxy?;
387
+ private _ignoreChange;
388
+ private _dirty;
389
+ private _positionWatch?;
390
+ private _matrixWatch?;
391
+ private _setMatrix;
392
+ constructor();
406
393
  awake(): void;
407
- start(): void;
408
394
  onEnable(): void;
409
395
  onDisable(): void;
410
396
  onDestroy(): void;
411
- earlyUpdate(): void;
412
397
  onBeforeRender(): void;
413
398
  initialize(): void;
414
399
  wakeUp(): void;
415
- applyForce(vec: THREE.Vector3, rel: THREE.Vector3 | undefined): void;
400
+ applyForce(vec: THREE.Vector3, rel?: THREE.Vector3): void;
401
+ setForce(x: number, y: number, z: number): void;
416
402
  getVelocity(): THREE.Vector3;
417
- setVelocity(x: number, y: number, z: number): void;
403
+ setVelocity(x: number | Vector3, y: number, z: number): void;
404
+ getTorque(): THREE.Vector3;
405
+ setTorque(x: number | Vector3, y: number, z: number): void;
418
406
  get smoothedVelocity(): THREE.Vector3;
419
407
  setAngularVelocity(x: number, y: number, z: number): void;
420
408
  private static copyVector3;
@@ -666,6 +654,8 @@ declare module "engine/engine_physics" {
666
654
  addSphereCollider(obj: THREE.Object3D, center: THREE.Vector3, radius: number, rb: Rigidbody | null): CANNON.Shape;
667
655
  addMeshCollider(_obj: THREE.Object3D): void;
668
656
  private isAlreadyRegistered;
657
+ private readonly tempMat1;
658
+ private readonly tempMat2;
669
659
  private addShape;
670
660
  step(deltaTime: number): void;
671
661
  private temp;
@@ -679,14 +669,16 @@ declare module "engine/engine_physics" {
679
669
  private onEndContact;
680
670
  }
681
671
  export class Collision {
672
+ private readonly invert;
682
673
  private readonly collision;
674
+ private readonly targetBody;
683
675
  readonly me: Object3D;
684
676
  private _normal?;
685
677
  get normal(): Vector3;
686
678
  private _collider?;
687
679
  get collider(): Collider;
688
680
  get gameObject(): Object3D;
689
- constructor(obj: Object3D, collision: CannonCollision);
681
+ constructor(obj: Object3D, collision: CannonCollision, invert?: boolean);
690
682
  }
691
683
  }
692
684
  declare module "engine-components/Component" {
@@ -729,7 +721,7 @@ declare module "engine-components/Component" {
729
721
  }
730
722
  abstract class GameObject extends THREE.Object3D implements THREE.Object3D {
731
723
  guid: string | undefined;
732
- static setActive(go: THREE.Object3D, active: boolean): void;
724
+ static setActive(go: THREE.Object3D, active: boolean, processStart?: boolean): void;
733
725
  static isActiveSelf(go: THREE.Object3D): boolean;
734
726
  static isActiveInHierarchy(go: THREE.Object3D): boolean;
735
727
  static markAsInstancedRendered(go: THREE.Object3D, instanced: boolean): void;
@@ -812,7 +804,11 @@ declare module "engine-components/Component" {
812
804
  onAfterRender?(): void;
813
805
  onCollisionEnter?(col: Collision): any;
814
806
  onCollisionExit?(col: Collision): any;
807
+ onCollisionExitRaw?(col: Collision): any;
815
808
  onCollisionStay?(col: Collision): any;
809
+ onTriggerEnter?(col: Collision): any;
810
+ onTriggerStay?(col: Collision): any;
811
+ onTriggerExit?(col: Collision): any;
816
812
  startCoroutine(routine: Generator, evt?: FrameEvent): Generator;
817
813
  stopCoroutine(routine: Generator, evt?: FrameEvent): void;
818
814
  get destroyed(): boolean;
@@ -830,9 +826,12 @@ declare module "engine-components/Component" {
830
826
  constructor();
831
827
  private _collisionExitRoutine;
832
828
  private _collisions;
829
+ private _triggerExitRoutine;
830
+ private _triggerCollisions;
831
+ get collisionsCount(): number;
833
832
  private __internalResetsCachedPhysicsData;
834
- __internalHandleCollision(col: Collision): void;
835
- sendExitCollisionEvent(obj: Object3D): void;
833
+ __internalHandleCollision(col: Collision, isTriggerCollision: boolean): void;
834
+ __internalHandleExitCollisionEvent(obj: Object3D, isTriggerCollision: boolean): void;
836
835
  private __waitForCollisionExit;
837
836
  private static _worldPositionBuffer;
838
837
  private static _worldQuaternionBuffer;
@@ -1048,9 +1047,9 @@ declare module "engine/engine_input" {
1048
1047
  private _pointerEvent;
1049
1048
  getKeyDown(): string | null;
1050
1049
  getKeyPressed(): string | null;
1051
- isKeyDown(keyCode: number): boolean;
1052
- isKeyUp(keyCode: number): boolean;
1053
- isKeyPressed(keyCode: number): boolean;
1050
+ isKeyDown(keyCode: KeyCode | string | number): any;
1051
+ isKeyUp(keyCode: KeyCode | string | number): boolean;
1052
+ isKeyPressed(keyCode: KeyCode | string | number): any;
1054
1053
  createPointerDown(args: PointerEventArgs): void;
1055
1054
  createPointerMove(args: PointerEventArgs): void;
1056
1055
  createPointerUp(args: PointerEventArgs): void;
@@ -1078,105 +1077,90 @@ declare module "engine/engine_input" {
1078
1077
  private onDispatchEvent;
1079
1078
  }
1080
1079
  export enum KeyCode {
1081
- BACKSPACE = 8,
1082
- TAB = 9,
1083
- ENTER = 13,
1084
- SHIFT = 16,
1085
- CTRL = 17,
1086
- ALT = 18,
1087
- PAUSE = 19,
1088
- CAPS_LOCK = 20,
1089
- ESCAPE = 27,
1090
- SPACE = 32,
1091
- PAGE_UP = 33,
1092
- PAGE_DOWN = 34,
1093
- END = 35,
1094
- HOME = 36,
1095
- LEFT_ARROW = 37,
1096
- UP_ARROW = 38,
1097
- RIGHT_ARROW = 39,
1098
- DOWN_ARROW = 40,
1099
- INSERT = 45,
1100
- DELETE = 46,
1101
- KEY_0 = 48,
1102
- KEY_1 = 49,
1103
- KEY_2 = 50,
1104
- KEY_3 = 51,
1105
- KEY_4 = 52,
1106
- KEY_5 = 53,
1107
- KEY_6 = 54,
1108
- KEY_7 = 55,
1109
- KEY_8 = 56,
1110
- KEY_9 = 57,
1111
- KEY_A = 65,
1112
- KEY_B = 66,
1113
- KEY_C = 67,
1114
- KEY_D = 68,
1115
- KEY_E = 69,
1116
- KEY_F = 70,
1117
- KEY_G = 71,
1118
- KEY_H = 72,
1119
- KEY_I = 73,
1120
- KEY_J = 74,
1121
- KEY_K = 75,
1122
- KEY_L = 76,
1123
- KEY_M = 77,
1124
- KEY_N = 78,
1125
- KEY_O = 79,
1126
- KEY_P = 80,
1127
- KEY_Q = 81,
1128
- KEY_R = 82,
1129
- KEY_S = 83,
1130
- KEY_T = 84,
1131
- KEY_U = 85,
1132
- KEY_V = 86,
1133
- KEY_W = 87,
1134
- KEY_X = 88,
1135
- KEY_Y = 89,
1136
- KEY_Z = 90,
1137
- LEFT_META = 91,
1138
- RIGHT_META = 92,
1139
- SELECT = 93,
1140
- NUMPAD_0 = 96,
1141
- NUMPAD_1 = 97,
1142
- NUMPAD_2 = 98,
1143
- NUMPAD_3 = 99,
1144
- NUMPAD_4 = 100,
1145
- NUMPAD_5 = 101,
1146
- NUMPAD_6 = 102,
1147
- NUMPAD_7 = 103,
1148
- NUMPAD_8 = 104,
1149
- NUMPAD_9 = 105,
1150
- MULTIPLY = 106,
1151
- ADD = 107,
1152
- SUBTRACT = 109,
1153
- DECIMAL = 110,
1154
- DIVIDE = 111,
1155
- F1 = 112,
1156
- F2 = 113,
1157
- F3 = 114,
1158
- F4 = 115,
1159
- F5 = 116,
1160
- F6 = 117,
1161
- F7 = 118,
1162
- F8 = 119,
1163
- F9 = 120,
1164
- F10 = 121,
1165
- F11 = 122,
1166
- F12 = 123,
1167
- NUM_LOCK = 144,
1168
- SCROLL_LOCK = 145,
1169
- SEMICOLON = 186,
1170
- EQUALS = 187,
1171
- COMMA = 188,
1172
- DASH = 189,
1173
- PERIOD = 190,
1174
- FORWARD_SLASH = 191,
1175
- GRAVE_ACCENT = 192,
1176
- OPEN_BRACKET = 219,
1177
- BACK_SLASH = 220,
1178
- CLOSE_BRACKET = 221,
1179
- SINGLE_QUOTE = 222
1080
+ BACKSPACE = "Backspace",
1081
+ TAB = "Tab",
1082
+ ENTER = "Enter",
1083
+ SHIFT = "Shift",
1084
+ CTRL = "Control",
1085
+ ALT = "Alt",
1086
+ PAUSE = "Pause",
1087
+ CAPS_LOCK = "CapsLock",
1088
+ ESCAPE = "Escape",
1089
+ SPACE = " ",
1090
+ PAGE_UP = "PageUp",
1091
+ PAGE_DOWN = "PageDown",
1092
+ END = "End",
1093
+ HOME = "Home",
1094
+ LEFT_ARROW = "ArrowLeft",
1095
+ UP_ARROW = "ArrowUp",
1096
+ RIGHT_ARROW = "ArrowRight",
1097
+ DOWN_ARROW = "ArrowDown",
1098
+ INSERT = "Insert",
1099
+ DELETE = "Delete",
1100
+ KEY_0 = "0",
1101
+ KEY_1 = "1",
1102
+ KEY_2 = "2",
1103
+ KEY_3 = "3",
1104
+ KEY_4 = "4",
1105
+ KEY_5 = "5",
1106
+ KEY_6 = "6",
1107
+ KEY_7 = "7",
1108
+ KEY_8 = "8",
1109
+ KEY_9 = "9",
1110
+ KEY_A = "a",
1111
+ KEY_B = "b",
1112
+ KEY_C = "c",
1113
+ KEY_D = "d",
1114
+ KEY_E = "e",
1115
+ KEY_F = "f",
1116
+ KEY_G = "g",
1117
+ KEY_H = "h",
1118
+ KEY_I = "i",
1119
+ KEY_K = "k",
1120
+ KEY_J = "j",
1121
+ KEY_L = "l",
1122
+ KEY_M = "m",
1123
+ KEY_N = "n",
1124
+ KEY_O = "o",
1125
+ KEY_P = "p",
1126
+ KEY_Q = "q",
1127
+ KEY_R = "r",
1128
+ KEY_S = "s",
1129
+ KEY_T = "t",
1130
+ KEY_U = "u",
1131
+ KEY_V = "v",
1132
+ KEY_W = "w",
1133
+ KEY_X = "x",
1134
+ KEY_Z = "z",
1135
+ KEY_Y = "y",
1136
+ SELECT = "Select",
1137
+ NUMPAD_0 = "Numpad0",
1138
+ NUMPAD_1 = "Numpad1",
1139
+ NUMPAD_2 = "Numpad2",
1140
+ NUMPAD_3 = "Numpad3",
1141
+ NUMPAD_4 = "Numpad4",
1142
+ NUMPAD_5 = "Numpad5",
1143
+ NUMPAD_6 = "Numpad6",
1144
+ NUMPAD_7 = "Numpad7",
1145
+ NUMPAD_8 = "Numpad8",
1146
+ NUMPAD_9 = "Numpad9",
1147
+ MULTIPLY = "Multiply",
1148
+ ADD = "Add",
1149
+ SUBTRACT = "Subtract",
1150
+ DECIMAL = "Decimal",
1151
+ DIVIDE = "Divide",
1152
+ F1 = "F1",
1153
+ F2 = "F2",
1154
+ F3 = "F3",
1155
+ F4 = "F4",
1156
+ F5 = "F5",
1157
+ F6 = "F6",
1158
+ F7 = "F7",
1159
+ F8 = "F8",
1160
+ F9 = "F9",
1161
+ F10 = "F10",
1162
+ F11 = "F11",
1163
+ F12 = "F12"
1180
1164
  }
1181
1165
  }
1182
1166
  declare module "engine/engine_time" {
@@ -1236,9 +1220,11 @@ declare module "engine-components/OrbitControls" {
1236
1220
  private _cameraTargetPosition;
1237
1221
  private _inputs;
1238
1222
  private _enableTime;
1223
+ private _startedListeningToKeyEvents;
1239
1224
  awake(): void;
1240
1225
  onEnable(): void;
1241
1226
  onDisable(): void;
1227
+ onDestroy(): void;
1242
1228
  start(): void;
1243
1229
  private startRaycastDelayed;
1244
1230
  onBeforeRender(): void;
@@ -4612,6 +4598,27 @@ declare module "engine-components/ui/BaseUIComponent" {
4612
4598
  awake(): void;
4613
4599
  }
4614
4600
  }
4601
+ declare module "engine-components/ui/Utils" {
4602
+ import { FrameEvent } from "engine/engine_setup";
4603
+ import { Behaviour } from "engine-components/Component";
4604
+ export function isUIObject(obj: THREE.Object3D): boolean;
4605
+ export type RenderSettings = {
4606
+ renderOnTop?: boolean;
4607
+ doubleSided?: boolean;
4608
+ depthWrite?: boolean;
4609
+ castShadows?: boolean;
4610
+ receiveShadows?: boolean;
4611
+ };
4612
+ export function updateRenderSettings(shadowComponent: THREE.Object3D, settings: RenderSettings): void;
4613
+ export type RevocableProxy = {
4614
+ proxy: any;
4615
+ revoke: () => void;
4616
+ };
4617
+ /** internal method to proxy a field to detect changes */
4618
+ export function onChange<T extends object>(caller: T, field: string, callback: (newValue: any, oldValue: any) => void): RevocableProxy;
4619
+ /** internal method to schedula a function at a specific moment in the update loop */
4620
+ export function scheduleAction(caller: Behaviour, action: Function, timing?: FrameEvent): void;
4621
+ }
4615
4622
  declare module "engine-components/ui/RectTransform" {
4616
4623
  import * as ThreeMeshUI from 'three-mesh-ui';
4617
4624
  import { BaseUIComponent } from "engine-components/ui/BaseUIComponent";