@needle-tools/engine 2.39.0-pre → 2.40.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 (54) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/needle-engine.d.ts +118 -35
  3. package/dist/needle-engine.js +352 -352
  4. package/dist/needle-engine.js.map +3 -3
  5. package/dist/needle-engine.min.js +59 -59
  6. package/dist/needle-engine.min.js.map +3 -3
  7. package/lib/engine/api.d.ts +1 -0
  8. package/lib/engine/api.js +1 -0
  9. package/lib/engine/api.js.map +1 -1
  10. package/lib/engine/engine_gizmos.d.ts +24 -0
  11. package/lib/engine/engine_gizmos.js +97 -5
  12. package/lib/engine/engine_gizmos.js.map +1 -1
  13. package/lib/engine/engine_input.d.ts +2 -0
  14. package/lib/engine/engine_input.js +9 -2
  15. package/lib/engine/engine_input.js.map +1 -1
  16. package/lib/engine/engine_networking.d.ts +1 -0
  17. package/lib/engine/engine_networking.js +9 -0
  18. package/lib/engine/engine_networking.js.map +1 -1
  19. package/lib/engine/engine_physics.d.ts +20 -2
  20. package/lib/engine/engine_physics.js +133 -16
  21. package/lib/engine/engine_physics.js.map +1 -1
  22. package/lib/engine/engine_three_utils.js +1 -22
  23. package/lib/engine/engine_three_utils.js.map +1 -1
  24. package/lib/engine/engine_types.d.ts +12 -6
  25. package/lib/engine/engine_types.js +22 -5
  26. package/lib/engine/engine_types.js.map +1 -1
  27. package/lib/engine/engine_utils.d.ts +8 -0
  28. package/lib/engine/engine_utils.js +22 -0
  29. package/lib/engine/engine_utils.js.map +1 -1
  30. package/lib/engine/extensions/NEEDLE_lightmaps.js +1 -1
  31. package/lib/engine/extensions/NEEDLE_lightmaps.js.map +1 -1
  32. package/lib/engine-components/Component.d.ts +18 -0
  33. package/lib/engine-components/Component.js +15 -2
  34. package/lib/engine-components/Component.js.map +1 -1
  35. package/lib/engine-components/Joints.d.ts +5 -1
  36. package/lib/engine-components/Joints.js +17 -7
  37. package/lib/engine-components/Joints.js.map +1 -1
  38. package/lib/engine-components/codegen/components.d.ts +1 -0
  39. package/lib/engine-components/codegen/components.js +1 -0
  40. package/lib/engine-components/codegen/components.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/engine/api.ts +2 -1
  43. package/src/engine/codegen/register_types.js +4 -0
  44. package/src/engine/engine_gizmos.ts +117 -5
  45. package/src/engine/engine_input.ts +12 -2
  46. package/src/engine/engine_networking.ts +10 -0
  47. package/src/engine/engine_physics.ts +159 -17
  48. package/src/engine/engine_three_utils.ts +1 -29
  49. package/src/engine/engine_types.ts +33 -14
  50. package/src/engine/engine_utils.ts +27 -0
  51. package/src/engine/extensions/NEEDLE_lightmaps.ts +1 -1
  52. package/src/engine-components/Component.ts +30 -4
  53. package/src/engine-components/Joints.ts +19 -7
  54. package/src/engine-components/codegen/components.ts +1 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ 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.40.0-pre] - 2022-11-05
8
+ - Add support for deleting all room state by calling ``context.connection.sendDeleteRemoteStateAll()`` (requires backend to update ``@needle-tools/needle-tiny-networking-ws`` to ``^1.1.0-pre``)
9
+ - Add Hinge joint
10
+ - Add ``Gizmos.DrawLine``, ``DrawRay`` ``DrawWireSphere`` and ``DrawSphere``
11
+ - Add: physics Collision Contacts now contain information about ``impulse`` and ``friction``
12
+ - Add ``physics.raycastPhysicsFast`` as a first method to raycast against physics colliders, the returning object contains the point in worldspace and the collider. This is the most simplest and thus fastest way to raycast using Rapier. More complex options will follow in future versions.
13
+ - Fix joint matrix calculation
14
+ - Fix and improve physics Contacts point calculations
15
+ - Fix issue in physics event callbacks where ``onCollisionStay`` and ``onCollisionExit`` would only be called when ``onCollisionEnter`` was defined
16
+
7
17
  ## [2.39.0-pre] - 2022-11-04
8
18
  - Add: physics FixedJoint
9
19
  - Change: CharacterController now rotates with camera
@@ -48,6 +48,28 @@ declare module "engine/engine_physics.types" {
48
48
  All = -1
49
49
  }
50
50
  }
51
+ declare module "engine/engine_three_utils" {
52
+ import * as THREE from "three";
53
+ import { Vector3 } from "three";
54
+ export function lookAtInverse(obj: THREE.Object3D, target: Vector3): void;
55
+ export function getWorldPosition(obj: THREE.Object3D, vec?: THREE.Vector3 | null, updateParents?: boolean): THREE.Vector3;
56
+ export function setWorldPosition(obj: THREE.Object3D, val: THREE.Vector3): void;
57
+ export function setWorldPositionXYZ(obj: THREE.Object3D, x: number, y: number, z: number): void;
58
+ export function getWorldQuaternion(obj: THREE.Object3D, target?: THREE.Quaternion | null): THREE.Quaternion;
59
+ export function setWorldQuaternion(obj: THREE.Object3D, val: THREE.Quaternion): void;
60
+ export function setWorldQuaternionXYZW(obj: THREE.Object3D, x: number, y: number, z: number, w: number): void;
61
+ export function getWorldScale(obj: THREE.Object3D, vec?: THREE.Vector3 | null): THREE.Vector3;
62
+ export function setWorldScale(obj: THREE.Object3D, vec: THREE.Vector3): void;
63
+ export function forward(obj: THREE.Object3D): THREE.Vector3;
64
+ export function getWorldEuler(obj: THREE.Object3D): THREE.Euler;
65
+ export function setWorldEuler(obj: THREE.Object3D, val: THREE.Euler): void;
66
+ export function getWorldRotation(obj: THREE.Object3D): THREE.Vector3;
67
+ export function setWorldRotation(obj: THREE.Object3D, val: THREE.Vector3): void;
68
+ export function setWorldRotationXYZ(obj: THREE.Object3D, x: number, y: number, z: number, degrees?: boolean): void;
69
+ export function logHierarchy(root: THREE.Object3D | null | undefined, collapsible?: boolean): void;
70
+ export function copyTexture(texture: THREE.Texture): THREE.Texture;
71
+ export function textureToCanvas(texture: THREE.Texture, force?: boolean): HTMLCanvasElement | null;
72
+ }
51
73
  declare module "engine/engine_types" {
52
74
  import { Camera, Color, Material, Object3D, Vector3, Quaternion } from "three";
53
75
  import { RGBAColor } from "engine-components/js-extensions/RGBAColor";
@@ -160,20 +182,26 @@ declare module "engine/engine_types" {
160
182
  export type ICollisionContext = {
161
183
  getCollider(obj: Object3D): ICollider;
162
184
  };
163
- export type Vec3 = {
185
+ export type Vec2 = {
164
186
  x: number;
165
187
  y: number;
166
- z: number;
167
188
  };
168
- export type Vec2 = {
189
+ export type Vec3 = {
169
190
  x: number;
170
191
  y: number;
192
+ z: number;
171
193
  };
172
194
  export class ContactPoint {
173
- readonly localPoint: Vec3;
195
+ private readonly _point;
196
+ private readonly _normal;
174
197
  readonly distance: number;
175
- readonly normal: Vec3;
176
- constructor(localPt: Vec3, dist: number, normal: Vec3);
198
+ readonly impulse: number;
199
+ readonly friction: number;
200
+ /** worldspace point */
201
+ get point(): Vector3;
202
+ /** worldspace normal */
203
+ get normal(): Vector3;
204
+ constructor(point: Vec3, dist: number, normal: Vec3, impulse: number, friction: number);
177
205
  }
178
206
  export class Collision {
179
207
  readonly contacts: ContactPoint[];
@@ -194,6 +222,14 @@ declare module "engine/engine_utils" {
194
222
  export const nameofFactory: <T>() => (name: keyof T) => keyof T;
195
223
  export function nameof<T>(name: keyof T): keyof T;
196
224
  export function isDebugMode(): boolean;
225
+ export class CircularBuffer<T> {
226
+ private _factory;
227
+ private _cache;
228
+ private _maxSize;
229
+ private _index;
230
+ constructor(factory: () => T, maxSize: number);
231
+ get(): T;
232
+ }
197
233
  export function getUrlParams(): URLSearchParams;
198
234
  export function getParam(paramName: string): string | boolean;
199
235
  export function setParam(paramName: string, paramValue: string): void;
@@ -389,6 +425,7 @@ declare module "engine/engine_serialization_core" {
389
425
  declare module "engine/engine_input" {
390
426
  import * as THREE from 'three';
391
427
  import { Context } from "engine/engine_setup";
428
+ import { Vec2 } from "engine/engine_types";
392
429
  export type PointerEventArgs = {
393
430
  button: number;
394
431
  clientX: number;
@@ -470,6 +507,7 @@ declare module "engine/engine_input" {
470
507
  createPointerDown(args: PointerEventArgs): void;
471
508
  createPointerMove(args: PointerEventArgs): void;
472
509
  createPointerUp(args: PointerEventArgs): void;
510
+ convertScreenspaceToRaycastSpace(vec2: Vec2): void;
473
511
  constructor(context: Context);
474
512
  private onLostFocus;
475
513
  private onEndOfFrame;
@@ -580,28 +618,6 @@ declare module "engine/engine_input" {
580
618
  F12 = "F12"
581
619
  }
582
620
  }
583
- declare module "engine/engine_three_utils" {
584
- import * as THREE from "three";
585
- import { Vector3 } from "three";
586
- export function lookAtInverse(obj: THREE.Object3D, target: Vector3): void;
587
- export function getWorldPosition(obj: THREE.Object3D, vec?: THREE.Vector3 | null, updateParents?: boolean): THREE.Vector3;
588
- export function setWorldPosition(obj: THREE.Object3D, val: THREE.Vector3): void;
589
- export function setWorldPositionXYZ(obj: THREE.Object3D, x: number, y: number, z: number): void;
590
- export function getWorldQuaternion(obj: THREE.Object3D, target?: THREE.Quaternion | null): THREE.Quaternion;
591
- export function setWorldQuaternion(obj: THREE.Object3D, val: THREE.Quaternion): void;
592
- export function setWorldQuaternionXYZW(obj: THREE.Object3D, x: number, y: number, z: number, w: number): void;
593
- export function getWorldScale(obj: THREE.Object3D, vec?: THREE.Vector3 | null): THREE.Vector3;
594
- export function setWorldScale(obj: THREE.Object3D, vec: THREE.Vector3): void;
595
- export function forward(obj: THREE.Object3D): THREE.Vector3;
596
- export function getWorldEuler(obj: THREE.Object3D): THREE.Euler;
597
- export function setWorldEuler(obj: THREE.Object3D, val: THREE.Euler): void;
598
- export function getWorldRotation(obj: THREE.Object3D): THREE.Vector3;
599
- export function setWorldRotation(obj: THREE.Object3D, val: THREE.Vector3): void;
600
- export function setWorldRotationXYZ(obj: THREE.Object3D, x: number, y: number, z: number, degrees?: boolean): void;
601
- export function logHierarchy(root: THREE.Object3D | null | undefined, collapsible?: boolean): void;
602
- export function copyTexture(texture: THREE.Texture): THREE.Texture;
603
- export function textureToCanvas(texture: THREE.Texture, force?: boolean): HTMLCanvasElement | null;
604
- }
605
621
  declare module "engine/engine_instancing" {
606
622
  export const NEED_UPDATE_INSTANCE_KEY: unique symbol;
607
623
  export class InstancingUtil {
@@ -749,7 +765,7 @@ declare module "engine/engine_gameobject" {
749
765
  declare module "engine/engine_physics" {
750
766
  import { Camera, Intersection, Layers, Mesh, Object3D, Ray, Raycaster, Vector2, Vector3 } from 'three';
751
767
  import { Context } from "engine/engine_setup";
752
- import { IComponent, ICollider, IRigidbody } from "engine/engine_types";
768
+ import { IComponent, ICollider, IRigidbody, Vec3, Vec2 } from "engine/engine_types";
753
769
  import RAPIER, { RigidBody } from '@dimforge/rapier3d-compat';
754
770
  export type Rapier = typeof RAPIER;
755
771
  export class RaycastOptions {
@@ -786,7 +802,19 @@ declare module "engine/engine_physics" {
786
802
  private tempBoundingBox;
787
803
  private onSphereOverlap;
788
804
  raycastFromRay(ray: Ray, options?: RaycastOptions | null): Array<Intersection>;
805
+ /** raycast against rendered three objects. This might be very slow depending on your scene complexity.
806
+ * We recommend setting objects to IgnoreRaycast layer (2) when you don't need them to be raycasted.
807
+ * Raycasting SkinnedMeshes is specially expensive.
808
+ */
789
809
  raycast(options?: RaycastOptions | null): Array<Intersection>;
810
+ private rapierRay;
811
+ private raycastVectorsBuffer;
812
+ /** raycast against colliders */
813
+ raycastPhysicsFast(origin: Vec2 | Vec3, direction?: Vec3 | undefined, maxDistance?: number, solid?: boolean): null | {
814
+ point: Vector3;
815
+ collider: ICollider;
816
+ };
817
+ private getPhysicsRay;
790
818
  private _tempPosition;
791
819
  private _tempQuaternion;
792
820
  private _tempScale;
@@ -827,11 +855,17 @@ declare module "engine/engine_physics" {
827
855
  private getRigidbodyRelativeMatrix;
828
856
  private static centerConnectionPos;
829
857
  private static centerConnectionRot;
830
- addFixedJoint(body1: IRigidbody, body2: IRigidbody, rel: {
858
+ addFixedJoint(body1: IRigidbody, body2: IRigidbody): void;
859
+ addHingeJoint(body1: IRigidbody, body2: IRigidbody, anchor: {
860
+ x: number;
861
+ y: number;
862
+ z: number;
863
+ }, axis: {
831
864
  x: number;
832
865
  y: number;
833
866
  z: number;
834
867
  }): void;
868
+ private calculateJointRelativeMatrices;
835
869
  }
836
870
  }
837
871
  declare module "engine/engine_time" {
@@ -1024,6 +1058,7 @@ declare module "engine/engine_networking" {
1024
1058
  leaveRoom(room?: string | null): void;
1025
1059
  send(key: string | OwnershipEvent, data?: IModel | object | boolean | null | string | number, queue?: SendQueue): void;
1026
1060
  sendDeleteRemoteState(guid: string): void;
1061
+ sendDeleteRemoteStateAll(): void;
1027
1062
  sendBinary(bin: Uint8Array): void;
1028
1063
  private _defaultMessagesBuffer;
1029
1064
  private _defaultMessagesBufferArray;
@@ -1282,10 +1317,15 @@ declare module "engine-components/Component" {
1282
1317
  sourceId?: SourceIdentifier;
1283
1318
  /** 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) */
1284
1319
  resolveGuids?(guidsMap: GuidsMap): void;
1320
+ /** called once when the component becomes active for the first time */
1285
1321
  awake(): void;
1322
+ /** called every time when the component gets enabled (this is invoked after awake and before start) */
1286
1323
  onEnable(): void;
1287
1324
  onDisable(): void;
1288
1325
  onDestroy(): void;
1326
+ /** called when you decorate fields with the @validate() decorator
1327
+ * @param field the name of the field that was changed
1328
+ */
1289
1329
  onValidate?(prop?: string): void;
1290
1330
  start?(): void;
1291
1331
  earlyUpdate?(): void;
@@ -1303,18 +1343,31 @@ declare module "engine-components/Component" {
1303
1343
  stopCoroutine(routine: Generator, evt?: FrameEvent): void;
1304
1344
  get destroyed(): boolean;
1305
1345
  destroy(): void;
1346
+ /** @internal */
1306
1347
  protected __didAwake: boolean;
1348
+ /** @internal */
1307
1349
  private __didStart;
1350
+ /** @internal */
1308
1351
  protected __didEnable: boolean;
1352
+ /** @internal */
1309
1353
  protected __isEnabled: boolean | undefined;
1354
+ /** @internal */
1310
1355
  private __destroyed;
1356
+ /** @internal */
1311
1357
  get __internalDidAwakeAndStart(): boolean;
1358
+ /** @internal */
1312
1359
  constructor();
1360
+ /** @internal */
1313
1361
  __internalNewInstanceCreated(): void;
1362
+ /** @internal */
1314
1363
  __internalAwake(): void;
1364
+ /** @internal */
1315
1365
  __internalStart(): void;
1366
+ /** @internal */
1316
1367
  __internalEnable(): boolean;
1368
+ /** @internal */
1317
1369
  __internalDisable(): void;
1370
+ /** @internal */
1318
1371
  __internalDestroy(): void;
1319
1372
  get enabled(): boolean;
1320
1373
  set enabled(val: boolean);
@@ -2381,6 +2434,34 @@ declare module "engine/engine_util_decorator" {
2381
2434
  /** create accessor callbacks for a field */
2382
2435
  export const validate: (set?: setter, get?: getter) => (target: IComponent | any, propertyKey: string, descriptor?: undefined) => void;
2383
2436
  }
2437
+ declare module "engine/engine_gizmos" {
2438
+ import * as THREE from 'three';
2439
+ import { ColorRepresentation } from 'three';
2440
+ import { Vec3 } from "engine/engine_types";
2441
+ export class Gizmos {
2442
+ static DrawRay(origin: Vec3, dir: Vec3, color?: ColorRepresentation, duration?: number, depthTest?: boolean): void;
2443
+ static DrawLine(pt0: {
2444
+ x: number;
2445
+ y: number;
2446
+ z: number;
2447
+ }, pt1: {
2448
+ x: number;
2449
+ y: number;
2450
+ z: number;
2451
+ }, color?: ColorRepresentation, duration?: number, depthTest?: boolean): void;
2452
+ static DrawWireSphere(center: {
2453
+ x: number;
2454
+ y: number;
2455
+ z: number;
2456
+ }, radius: number, color?: ColorRepresentation, duration?: number, depthTest?: boolean): void;
2457
+ static DrawSphere(center: {
2458
+ x: number;
2459
+ y: number;
2460
+ z: number;
2461
+ }, radius: number, color?: ColorRepresentation, duration?: number, depthTest?: boolean): void;
2462
+ }
2463
+ export function CreateWireCube(col?: THREE.ColorRepresentation | null): THREE.LineSegments;
2464
+ }
2384
2465
  declare module "engine/api" {
2385
2466
  export { InstancingUtil } from "engine/engine_instancing";
2386
2467
  export * from "engine/engine_gameobject";
@@ -2389,6 +2470,7 @@ declare module "engine/api" {
2389
2470
  export { FrameEvent } from "engine/engine_setup";
2390
2471
  export * from "engine/debug/debug";
2391
2472
  export { validate } from "engine/engine_util_decorator";
2473
+ export { Gizmos } from "engine/engine_gizmos";
2392
2474
  }
2393
2475
  declare module "engine-components/AlignmentConstraint" {
2394
2476
  import { Behaviour } from "engine-components/Component";
@@ -2576,10 +2658,6 @@ declare module "engine-components/BasicIKConstraint" {
2576
2658
  update(): void;
2577
2659
  }
2578
2660
  }
2579
- declare module "engine/engine_gizmos" {
2580
- import * as THREE from 'three';
2581
- export function CreateWireCube(col?: THREE.ColorRepresentation | null): THREE.LineSegments;
2582
- }
2583
2661
  declare module "engine-components/BoxHelperComponent" {
2584
2662
  import { Behaviour } from "engine-components/Component";
2585
2663
  import * as THREE from "three";
@@ -3927,7 +4005,6 @@ declare module "engine-components/Joints" {
3927
4005
  connectedBody?: Rigidbody;
3928
4006
  get rigidBody(): Rigidbody | null;
3929
4007
  private _rigidBody;
3930
- connectedAnchor?: Vector3;
3931
4008
  onEnable(): void;
3932
4009
  private create;
3933
4010
  protected abstract createJoint(self: Rigidbody, other: Rigidbody): any;
@@ -3935,6 +4012,11 @@ declare module "engine-components/Joints" {
3935
4012
  export class FixedJoint extends Joint {
3936
4013
  protected createJoint(self: Rigidbody, other: Rigidbody): void;
3937
4014
  }
4015
+ export class HingeJoint extends Joint {
4016
+ anchor?: Vector3;
4017
+ axis?: Vector3;
4018
+ protected createJoint(self: Rigidbody, other: Rigidbody): void;
4019
+ }
3938
4020
  }
3939
4021
  declare module "engine-components/Light" {
3940
4022
  import { Behaviour } from "engine-components/Component";
@@ -5463,6 +5545,7 @@ declare module "engine-components/codegen/components" {
5463
5545
  export { Interactable } from "engine-components/Interactable";
5464
5546
  export { UsageMarker } from "engine-components/Interactable";
5465
5547
  export { FixedJoint } from "engine-components/Joints";
5548
+ export { HingeJoint } from "engine-components/Joints";
5466
5549
  export { Light } from "engine-components/Light";
5467
5550
  export { LODModel } from "engine-components/LODGroup";
5468
5551
  export { LODGroup } from "engine-components/LODGroup";