@needle-tools/engine 2.36.0-pre → 2.37.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 (102) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/needle-engine.d.ts +171 -141
  3. package/dist/needle-engine.js +451 -437
  4. package/dist/needle-engine.js.map +4 -4
  5. package/dist/needle-engine.min.js +82 -82
  6. package/dist/needle-engine.min.js.map +4 -4
  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/debug/debug.d.ts +1 -0
  11. package/lib/engine/debug/debug.js +3 -0
  12. package/lib/engine/debug/debug.js.map +1 -1
  13. package/lib/engine/engine_gameobject.js +2 -1
  14. package/lib/engine/engine_gameobject.js.map +1 -1
  15. package/lib/engine/engine_physics.d.ts +33 -42
  16. package/lib/engine/engine_physics.js +431 -383
  17. package/lib/engine/engine_physics.js.map +1 -1
  18. package/lib/engine/engine_physics.types.d.ts +16 -0
  19. package/lib/engine/engine_physics.types.js +19 -0
  20. package/lib/engine/engine_physics.types.js.map +1 -0
  21. package/lib/engine/engine_serialization_core.d.ts +3 -0
  22. package/lib/engine/engine_serialization_core.js +5 -0
  23. package/lib/engine/engine_serialization_core.js.map +1 -1
  24. package/lib/engine/engine_setup.js +3 -1
  25. package/lib/engine/engine_setup.js.map +1 -1
  26. package/lib/engine/engine_types.d.ts +45 -26
  27. package/lib/engine/engine_types.js +24 -37
  28. package/lib/engine/engine_types.js.map +1 -1
  29. package/lib/engine/engine_util_decorator.d.ts +6 -0
  30. package/lib/engine/engine_util_decorator.js +54 -0
  31. package/lib/engine/engine_util_decorator.js.map +1 -0
  32. package/lib/engine/engine_utils.d.ts +1 -1
  33. package/lib/engine/engine_utils.js +1 -1
  34. package/lib/engine/engine_utils.js.map +1 -1
  35. package/lib/engine/extensions/NEEDLE_gameobject_data.js +2 -0
  36. package/lib/engine/extensions/NEEDLE_gameobject_data.js.map +1 -1
  37. package/lib/engine-components/Animation.d.ts +6 -5
  38. package/lib/engine-components/Animation.js +0 -7
  39. package/lib/engine-components/Animation.js.map +1 -1
  40. package/lib/engine-components/BoxHelperComponent.js +1 -0
  41. package/lib/engine-components/BoxHelperComponent.js.map +1 -1
  42. package/lib/engine-components/Collider.d.ts +7 -2
  43. package/lib/engine-components/Collider.js +27 -15
  44. package/lib/engine-components/Collider.js.map +1 -1
  45. package/lib/engine-components/Component.d.ts +6 -15
  46. package/lib/engine-components/Component.js +7 -112
  47. package/lib/engine-components/Component.js.map +1 -1
  48. package/lib/engine-components/DragControls.js +9 -6
  49. package/lib/engine-components/DragControls.js.map +1 -1
  50. package/lib/engine-components/NavMesh.d.ts +0 -5
  51. package/lib/engine-components/NavMesh.js +100 -10
  52. package/lib/engine-components/NavMesh.js.map +1 -1
  53. package/lib/engine-components/NestedGltf.js +2 -0
  54. package/lib/engine-components/NestedGltf.js.map +1 -1
  55. package/lib/engine-components/RigidBody.d.ts +40 -25
  56. package/lib/engine-components/RigidBody.js +253 -142
  57. package/lib/engine-components/RigidBody.js.map +1 -1
  58. package/lib/engine-components/SpatialTrigger.js +1 -1
  59. package/lib/engine-components/SpatialTrigger.js.map +1 -1
  60. package/lib/engine-components/SpectatorCamera.d.ts +1 -0
  61. package/lib/engine-components/SpectatorCamera.js +9 -2
  62. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  63. package/lib/engine-components/SpringJoint.d.ts +0 -13
  64. package/lib/engine-components/SpringJoint.js +42 -41
  65. package/lib/engine-components/SpringJoint.js.map +1 -1
  66. package/lib/engine-components/VideoPlayer.js.map +1 -1
  67. package/lib/engine-components/WebXR.d.ts +1 -0
  68. package/lib/engine-components/WebXR.js +10 -2
  69. package/lib/engine-components/WebXR.js.map +1 -1
  70. package/lib/engine-components/WebXRController.js +12 -6
  71. package/lib/engine-components/WebXRController.js.map +1 -1
  72. package/lib/engine-components/codegen/components.d.ts +1 -3
  73. package/lib/engine-components/codegen/components.js +1 -3
  74. package/lib/engine-components/codegen/components.js.map +1 -1
  75. package/package.json +3 -4
  76. package/src/engine/api.ts +2 -1
  77. package/src/engine/codegen/register_types.js +4 -12
  78. package/src/engine/debug/debug.ts +4 -0
  79. package/src/engine/engine_gameobject.ts +4 -4
  80. package/src/engine/engine_physics.ts +460 -421
  81. package/src/engine/engine_physics.types.ts +19 -0
  82. package/src/engine/engine_serialization_core.ts +8 -1
  83. package/src/engine/engine_setup.ts +5 -1
  84. package/src/engine/engine_types.ts +82 -56
  85. package/src/engine/engine_util_decorator.ts +69 -0
  86. package/src/engine/engine_utils.ts +3 -3
  87. package/src/engine/extensions/NEEDLE_gameobject_data.ts +2 -0
  88. package/src/engine-components/Animation.ts +10 -12
  89. package/src/engine-components/BoxHelperComponent.ts +1 -0
  90. package/src/engine-components/Collider.ts +29 -29
  91. package/src/engine-components/Component.ts +15 -130
  92. package/src/engine-components/DragControls.ts +9 -5
  93. package/src/engine-components/NavMesh.ts +114 -115
  94. package/src/engine-components/NestedGltf.ts +2 -0
  95. package/src/engine-components/RigidBody.ts +258 -149
  96. package/src/engine-components/SpatialTrigger.ts +1 -1
  97. package/src/engine-components/SpectatorCamera.ts +10 -2
  98. package/src/engine-components/SpringJoint.ts +41 -41
  99. package/src/engine-components/VideoPlayer.ts +1 -2
  100. package/src/engine-components/WebXR.ts +12 -2
  101. package/src/engine-components/WebXRController.ts +16 -7
  102. package/src/engine-components/codegen/components.ts +1 -3
@@ -0,0 +1,19 @@
1
+
2
+
3
+ export enum CollisionDetectionMode {
4
+ Discrete = 0,
5
+ Continuous = 1,
6
+ }
7
+
8
+ export enum RigidbodyConstraints {
9
+ None = 0,
10
+ FreezePositionX = 2,
11
+ FreezePositionY = 4,
12
+ FreezePositionZ = 8,
13
+ FreezePosition = 14,
14
+ FreezeRotationX = 16,
15
+ FreezeRotationY = 32,
16
+ FreezeRotationZ = 64,
17
+ FreezeRotation = 112,
18
+ FreezeAll = 126,
19
+ }
@@ -3,7 +3,7 @@ import { getParam } from "./engine_utils";
3
3
  import { Object3D } from "three";
4
4
  import { Context } from "./engine_setup";
5
5
  import { isPersistentAsset } from "./extensions/NEEDLE_persistent_assets";
6
- import { SourceIdentifier } from "./engine_types";
6
+ import { IComponent, SourceIdentifier } from "./engine_types";
7
7
  import { debugExtension } from "../engine/engine_default_parameters";
8
8
  import { LogType, showBalloonMessage } from "./debug/debug";
9
9
  import { isLocalNetwork } from "./engine_networking_utils";
@@ -11,6 +11,7 @@ import { $BuiltInTypeFlag } from "./engine_typestore";
11
11
 
12
12
  const debug = getParam("debugserializer");
13
13
 
14
+
14
15
  export type Constructor<T> = { new(...args: any[]): T };
15
16
  export declare type NodeToObjectMap = { [nodeId: string]: Object3D };
16
17
  export declare type ObjectToNodeMap = { [uuid: string]: number };
@@ -516,6 +517,10 @@ function setBuffer(value): Array<any> {
516
517
  }
517
518
 
518
519
 
520
+ /** set to true while assigning properties during instantiation.
521
+ * Used for validate decorator to not invoke callbacks on components that are currently in the process of being built */
522
+ export const $isAssigningProperties = Symbol("assigned component properties");
523
+
519
524
  // const developmentMode = getParam("dev")
520
525
 
521
526
  /** Object.assign behaviour but check if property is writeable (e.g. getter only properties are skipped) */
@@ -540,6 +545,7 @@ export function assign(target: any, source: any) {
540
545
  // if (developmentMode)
541
546
  // onlyDeclared = false;
542
547
 
548
+ target[$isAssigningProperties] = true;
543
549
  for (const key of Object.keys(source)) {
544
550
  const desc = getPropertyDescriptor(target, key);
545
551
  if (onlyDeclared && desc === undefined) continue;
@@ -550,6 +556,7 @@ export function assign(target: any, source: any) {
550
556
  target[key] = source[key];
551
557
  }
552
558
  }
559
+ delete target[$isAssigningProperties];
553
560
  }
554
561
 
555
562
  // we need to recurse because the property might be defined in a base class
@@ -400,6 +400,10 @@ export class Context {
400
400
  }
401
401
 
402
402
  private async internalOnCreate(buildScene: (context: Context, opts?: LoadingOptions) => Promise<void>, opts?: LoadingOptions) {
403
+
404
+ // TODO: we could configure if we need physics
405
+ await this.physics.createWorld();
406
+
403
407
  // load and create scene
404
408
  let prepare_succeeded = true;
405
409
  try {
@@ -562,7 +566,7 @@ export class Context {
562
566
  this.executeCoroutines(FrameEvent.LateUpdate);
563
567
 
564
568
  try {
565
- const physicsSteps = 2;
569
+ const physicsSteps = 1;
566
570
  const dt = this.time.deltaTime / physicsSteps;
567
571
  for (let i = 0; i < physicsSteps; i++) {
568
572
  this.physics.step(dt);
@@ -1,6 +1,6 @@
1
- import { Camera, Color, Material, Object3D, Vector3 } from "three";
2
- import { Body, ContactEquation } from "cannon-es";
1
+ import { Camera, Color, Material, Object3D, Vector3, Quaternion } from "three";
3
2
  import { RGBAColor } from "../engine-components/js-extensions/RGBAColor";
3
+ import { CollisionDetectionMode, RigidbodyConstraints } from "./engine_physics.types";
4
4
 
5
5
  /** used to find data registered via gltf files e.g. find lightmaps for a Renderer component that were shipped inside a gltf */
6
6
  export declare type SourceIdentifier = string;
@@ -58,9 +58,10 @@ export interface IComponent {
58
58
  onDisable();
59
59
  onDestroy();
60
60
 
61
+ /** called for properties decorated with the @validate decorator */
62
+ onValidate?(property?: string);
63
+
61
64
  start?(): void;
62
- // available update loop events:
63
- // earlyUpdate, update, lateUpdate, onBeforeRender, onAfterRender
64
65
  earlyUpdate?(): void;
65
66
  update?(): void;
66
67
  lateUpdate?(): void;
@@ -69,17 +70,15 @@ export interface IComponent {
69
70
 
70
71
  onCollisionEnter?(col: Collision);
71
72
  onCollisionExit?(col: Collision);
72
- onCollisionExitRaw?(col: Collision);
73
73
  onCollisionStay?(col: Collision);
74
74
 
75
- onTriggerEnter?(col: Collision);
76
- onTriggerStay?(col: Collision);
77
- onTriggerExit?(col: Collision);
78
-
79
- __internalHandleCollision(col: Collision, isTriggerCollision: boolean);
80
- __internalHandleExitCollisionEvent(obj: Object3D, isTriggerCollision: boolean);
75
+ onTriggerEnter?(col: ICollider);
76
+ onTriggerStay?(col: ICollider);
77
+ onTriggerExit?(col: ICollider);
81
78
 
82
79
  get forward(): Vector3;
80
+ get worldPosition(): Vector3;
81
+ get worldQuaternion(): Quaternion;
83
82
  }
84
83
 
85
84
 
@@ -101,8 +100,8 @@ export declare interface ILight extends IComponent {
101
100
  }
102
101
 
103
102
  export declare interface ISharedMaterials {
104
- [num:number] : Material;
105
- get length() : number;
103
+ [num: number]: Material;
104
+ get length(): number;
106
105
  }
107
106
 
108
107
  export declare interface IRenderer extends IComponent {
@@ -110,6 +109,10 @@ export declare interface IRenderer extends IComponent {
110
109
  get sharedMaterials(): ISharedMaterials;
111
110
  }
112
111
 
112
+ // export declare interface IPhysicsComponent extends IComponent {
113
+ // get type() : string;
114
+ // }
115
+
113
116
  export declare interface ICollider extends IComponent {
114
117
  get isCollider();
115
118
  attachedRigidbody: IRigidbody | null;
@@ -117,67 +120,98 @@ export declare interface ICollider extends IComponent {
117
120
  }
118
121
 
119
122
  export declare interface IRigidbody extends IComponent {
120
- initialize(): void;
121
- body;
123
+ constraints: RigidbodyConstraints;
124
+ isKinematic: boolean;
125
+ mass: number;
126
+ drag: number;
127
+ angularDrag: number;
128
+ useGravity: boolean;
129
+ collisionDetectionMode: CollisionDetectionMode;
130
+
131
+ lockPositionX: boolean;
132
+ lockPositionY: boolean;
133
+ lockPositionZ: boolean;
134
+ lockRotationX: boolean;
135
+ lockRotationY: boolean;
136
+ lockRotationZ: boolean;
122
137
  }
123
138
 
124
139
 
140
+ export const $physicsKey = Symbol("object");
125
141
 
126
142
 
143
+ export declare type ICollisionContext = {
144
+ getCollider(obj: Object3D): ICollider;
145
+ }
127
146
 
128
147
 
129
-
130
- export const $physicsKey = Symbol("object");
131
-
132
- export declare type CannonCollision = {
133
- body: Body;
134
- contact: ContactEquation;
135
- target: Body;
136
- type: string;
148
+ export type Vec3 = {
149
+ x: number,
150
+ y: number,
151
+ z: number
137
152
  }
138
153
 
139
- export declare type ICollisionContext = {
140
- getCollider(obj: Object3D): ICollider;
154
+ export type Vec2 = {
155
+ x: number,
156
+ y: number
141
157
  }
142
158
 
143
- export class Collision {
159
+ export class ContactPoint {
144
160
 
145
- get __internalCollision(): CannonCollision {
146
- return this.collision;
147
- }
161
+ readonly localPoint: Vec3;
162
+ readonly distance: number;
163
+ readonly normal: Vec3;
148
164
 
149
- get __internalInvertedSourceReceiver(): boolean {
150
- return this.invert;
165
+ constructor(localPt: Vec3, dist: number, normal: Vec3) {
166
+ this.localPoint = localPt;
167
+ this.distance = dist;
168
+ this.normal = normal;
151
169
  }
152
170
 
153
- private readonly invert: boolean;
154
- private readonly collision: CannonCollision;
155
- private readonly targetBody: Body;
156
- private readonly context: ICollisionContext;
171
+ }
157
172
 
158
- readonly me: Object3D;
173
+ /// all info in here must be readonly because the object is only created once per started collision
174
+ export class Collision {
175
+
176
+ private readonly contacts: ContactPoint[];
159
177
 
160
- private _normal?: Vector3;
161
- get normal(): Vector3 {
162
- if (!this._normal) {
163
- const vec = this.collision.contact.ni;
164
- this._normal = new Vector3(vec.x, vec.y, vec.z);
165
- }
166
- return this._normal;
178
+ constructor(obj: Object3D, otherCollider: ICollider, contacts: ContactPoint[]) {
179
+ this.me = obj;
180
+ this._collider = otherCollider;
181
+ this._gameObject = otherCollider.gameObject;
182
+ this.contacts = contacts;
167
183
  }
168
184
 
169
- private _collider?: ICollider;
185
+ readonly me: Object3D;
186
+ private _collider: ICollider;
187
+
188
+ /** the collider the collision happened with */
170
189
  get collider(): ICollider {
171
- if (!this._collider) {
172
- this._collider = this.context.getCollider(this.gameObject);
173
- }
174
190
  return this._collider;
175
191
  }
176
192
 
193
+ /** the object the collision happened with */
194
+ private _gameObject: Object3D;
177
195
  get gameObject(): Object3D {
178
- return this.targetBody[$physicsKey];
196
+ return this._gameObject;
197
+ }
198
+
199
+ /** the rigidbody we hit, null if none attached */
200
+ get rigidBody(): IRigidbody | null {
201
+ return this.collider?.attachedRigidbody;
179
202
  }
180
203
 
204
+
205
+ // private _normal?: Vector3;
206
+ // get normal(): Vector3 {
207
+ // if (!this._normal) {
208
+ // const vec = this.collision.contact.ni;
209
+ // this._normal = new Vector3(vec.x, vec.y, vec.z);
210
+ // }
211
+ // return this._normal;
212
+ // }
213
+
214
+
181
215
  // private _point?: Vector3;
182
216
  // get point(): Vector3 {
183
217
  // if (!this._point) {
@@ -187,12 +221,4 @@ export class Collision {
187
221
  // }
188
222
  // return this._point;
189
223
  // }
190
-
191
- constructor(obj: Object3D, collision: CannonCollision, context: ICollisionContext, invert: boolean = false) {
192
- this.me = obj;
193
- this.collision = collision;
194
- this.context = context;
195
- this.targetBody = invert ? collision.target : collision.body;
196
- this.invert = invert;
197
- }
198
224
  }
@@ -0,0 +1,69 @@
1
+ import { $isAssigningProperties } from "./engine_serialization_core";
2
+ import { LogType, showBalloonMessage } from "./debug/debug";
3
+ import { IComponent } from "./engine_types";
4
+
5
+
6
+ declare type setter = (v: any) => void;
7
+ declare type getter = () => any;
8
+
9
+ /** create accessor callbacks for a field */
10
+ export const validate = function (set?: setter, get?: getter) {
11
+ // "descriptor : undefined" prevents @validate() to be added to property getters or setters
12
+ return function (target: IComponent | any, propertyKey: string, descriptor?: undefined) {
13
+ createPropertyWrapper(target, propertyKey, descriptor, set, get);
14
+ }
15
+ }
16
+
17
+
18
+ function createPropertyWrapper(target: IComponent | any, propertyKey: string, descriptor?: PropertyDescriptor,
19
+ set?: setter,
20
+ get?: getter) {
21
+
22
+ if (!get && !set && !target.onValidate) return;
23
+
24
+ // this is not undefined when its a property getter or setter already and not just a field
25
+ // we currently only support validation of fields
26
+ if (descriptor !== undefined) {
27
+ console.error("Invalid usage of validate decorator. Only fields can be validated.", target, propertyKey, descriptor);
28
+ showBalloonMessage("Invalid usage of validate decorator. Only fields can be validated. Property: " + propertyKey, LogType.Error);
29
+ return;
30
+ }
31
+
32
+ if (target.__internalAwake) {
33
+ // this is the hidden key we save the original property to
34
+ const $prop = Symbol(propertyKey);
35
+ // save the original awake method
36
+ // we need to delay decoration until the object has been created
37
+ const awake = target.__internalAwake;
38
+ target.__internalAwake = function () {
39
+
40
+ // only build wrapper once per type
41
+ if (this[$prop] === undefined) {
42
+
43
+ // make sure the field is initialized in a hidden property
44
+ this[$prop] = this[propertyKey];
45
+
46
+ Object.defineProperty(this, propertyKey, {
47
+ set: function (v) {
48
+ if (this[$isAssigningProperties] === true) {
49
+ this[$prop] = v;
50
+ }
51
+ else {
52
+ set?.call(this, v);
53
+ const oldValue = this[$prop];
54
+ this[$prop] = v;
55
+ this.onValidate?.call(this, propertyKey, oldValue);
56
+ }
57
+ },
58
+ get: function () {
59
+ get?.call(this);
60
+ return this[$prop];
61
+ },
62
+ });
63
+ }
64
+
65
+ // call the original awake method
66
+ awake.call(this);
67
+ };
68
+ }
69
+ }
@@ -217,7 +217,7 @@ export function getPath(source: SourceIdentifier | undefined, uri: string): stri
217
217
  // }
218
218
 
219
219
 
220
- export type WriteCallback = (data: any) => void;
220
+ export type WriteCallback = (data: any, prop: string) => void;
221
221
 
222
222
  export interface IWatch {
223
223
  subscribeWrite(callback: WriteCallback);
@@ -268,7 +268,7 @@ class WatchImpl implements IWatch {
268
268
  const setter = (value) => {
269
269
  object[this._wrapperProp] = value;
270
270
  for (const write of this.writeCallbacks) {
271
- write(value);
271
+ write(value, this._prop);
272
272
  }
273
273
  }
274
274
  // add the wrapper to the object
@@ -321,7 +321,7 @@ export class Watch implements IWatch {
321
321
  apply() {
322
322
  for (const w of this._watches) {
323
323
  w.apply();
324
- }
324
+ }
325
325
  }
326
326
 
327
327
  revoke() {
@@ -66,6 +66,8 @@ export class NEEDLE_gameobject_data implements GLTFLoaderPlugin {
66
66
 
67
67
  private applyExtensionData(node: Object3D, ext: GameObjectData) {
68
68
  node.userData.layer = ext.layers;
69
+ node.layers.disableAll();
70
+ node.layers.set(ext.layers);
69
71
  node.userData.tag = ext.tag;
70
72
  node.userData.hideFlags = ext.hideFlags;
71
73
  node.userData.static = ext.static;
@@ -5,6 +5,7 @@ import { MixerEvent } from "./Animator";
5
5
  import { serializeable } from "../engine/engine_serialization_decorator";
6
6
  import { InstancingUtil } from "../engine/engine_instancing";
7
7
  import { Mathf } from "../engine/engine_math";
8
+ import { Vec2 } from "../engine/engine_types";
8
9
 
9
10
  export declare class PlayOptions {
10
11
  fadeDuration?: number;
@@ -13,8 +14,8 @@ export declare class PlayOptions {
13
14
  startTime?: number;
14
15
  endTime?: number;
15
16
  clampWhenFinished?: boolean;
16
- minMaxSpeed?: Vector2;
17
- minMaxOffsetNormalized?: Vector2;
17
+ minMaxSpeed?: Vec2;
18
+ minMaxOffsetNormalized?: Vec2;
18
19
  }
19
20
 
20
21
  export class Animation extends Behaviour {
@@ -24,11 +25,8 @@ export class Animation extends Behaviour {
24
25
  @serializeable()
25
26
  randomStartTime: boolean = true;
26
27
 
27
- @serializeable(Vector2)
28
- minMaxSpeed?: Vector2;
29
-
30
- @serializeable(Vector2)
31
- minMaxOffsetNormalized?: Vector2;
28
+ minMaxSpeed?: Vec2;
29
+ minMaxOffsetNormalized?: Vec2;
32
30
 
33
31
  private _tempAnimationClipBeforeGameObjectExisted: AnimationClip | null = null;
34
32
  get clip(): AnimationClip | null {
@@ -129,9 +127,9 @@ export class Animation extends Behaviour {
129
127
  console.error("Could not find clip", clipOrNumber)
130
128
  return;
131
129
  }
132
- if(!options) options = {};
133
- if(!options.minMaxOffsetNormalized) options.minMaxOffsetNormalized = this.minMaxOffsetNormalized;
134
- if(!options.minMaxSpeed) options.minMaxSpeed = this.minMaxSpeed;
130
+ if (!options) options = {};
131
+ if (!options.minMaxOffsetNormalized) options.minMaxOffsetNormalized = this.minMaxOffsetNormalized;
132
+ if (!options.minMaxSpeed) options.minMaxSpeed = this.minMaxSpeed;
135
133
  for (const act of this.actions) {
136
134
  if (act.getClip() === clip) {
137
135
  return this.internalOnPlay(act, options);
@@ -163,8 +161,8 @@ export class Animation extends Behaviour {
163
161
  action.time = 0;
164
162
  action.timeScale = 1;
165
163
  const clip = action.getClip();
166
- if(options?.minMaxOffsetNormalized) action.time = Mathf.lerp(options.minMaxOffsetNormalized.x, options.minMaxOffsetNormalized.y, Math.random()) * clip.duration;
167
- if(options?.minMaxSpeed) action.timeScale = Mathf.lerp(options.minMaxSpeed.x, options.minMaxSpeed.y, Math.random());
164
+ if (options?.minMaxOffsetNormalized) action.time = Mathf.lerp(options.minMaxOffsetNormalized.x, options.minMaxOffsetNormalized.y, Math.random()) * clip.duration;
165
+ if (options?.minMaxSpeed) action.timeScale = Mathf.lerp(options.minMaxSpeed.x, options.minMaxSpeed.y, Math.random());
168
166
  if (options?.clampWhenFinished) action.clampWhenFinished = true;
169
167
  if (options?.startTime !== undefined) action.time = options.startTime;
170
168
 
@@ -55,6 +55,7 @@ export class BoxHelperComponent extends Behaviour {
55
55
  // this.tp.applyMatrix4(obj.matrixWorld);
56
56
  // console.log(this.tp);
57
57
  // console.log(this.box?.min, this.box?.max, this.tp.min, this.tp.max);
58
+ this.updateBox();
58
59
  return this.box?.intersectsBox(BoxHelperComponent.testBox);
59
60
  }
60
61
 
@@ -1,8 +1,7 @@
1
1
  import { Behaviour } from "./Component";
2
2
  import { Rigidbody } from "./RigidBody";
3
3
  import { serializeable } from "../engine/engine_serialization_decorator";
4
- import { Event, Object3D, Vector3 } from "three"
5
- import { Shape } from "cannon-es";
4
+ import { Event, Mesh, Object3D, Vector3 } from "three"
6
5
  import { IColliderProvider, registerColliderProvider } from "../engine/engine_physics";
7
6
  import { ICollider } from "../engine/engine_types";
8
7
  import { getComponentInChildren } from "../engine/engine_components";
@@ -25,14 +24,14 @@ export class Collider extends Behaviour implements ICollider {
25
24
  @serializeable()
26
25
  isTrigger: boolean = false;
27
26
 
28
- protected _shape: Shape | null = null;
29
27
 
30
28
  awake() {
31
29
  super.awake();
32
- this._shape = null;
30
+ if (!this.attachedRigidbody)
31
+ this.attachedRigidbody = this.gameObject.getComponentInParent(Rigidbody);
33
32
  }
34
33
 
35
- start(){
34
+ start() {
36
35
  if (!this.attachedRigidbody)
37
36
  this.attachedRigidbody = this.gameObject.getComponentInParent(Rigidbody);
38
37
  }
@@ -44,9 +43,7 @@ export class Collider extends Behaviour implements ICollider {
44
43
  }
45
44
 
46
45
  onDisable() {
47
- if (this._shape) {
48
-
49
- }
46
+ this.context.physics.removeBody(this);
50
47
  }
51
48
 
52
49
  }
@@ -61,14 +58,8 @@ export class SphereCollider extends Collider {
61
58
 
62
59
  onEnable() {
63
60
  super.onEnable();
64
- if (!this._shape)
65
- this._shape = this.context.physics.addSphereCollider(this.gameObject, this.center, this.radius, this.attachedRigidbody);
61
+ this.context.physics.addSphereCollider(this, this.center, this.radius);
66
62
  }
67
-
68
- // onDisable() {
69
- // // if (this._shape)
70
- // // this.context.physics.removeShape(this.gameObject, this._shape);
71
- // }
72
63
  }
73
64
 
74
65
  export class BoxCollider extends Collider {
@@ -80,22 +71,31 @@ export class BoxCollider extends Collider {
80
71
 
81
72
  onEnable() {
82
73
  super.onEnable();
83
- if (!this._shape)
84
- this._shape = this.context.physics.addBoxCollider(this.gameObject, this.isTrigger, this.center, this.size, this.attachedRigidbody);
74
+ this.context.physics.addBoxCollider(this, this.center, this.size);
85
75
  }
86
-
87
- // onDisable() {
88
- // // if (this._shape) {
89
- // // this.context.physics.removeShape(this.gameObject, this._shape);
90
- // // }
91
- // }
92
76
  }
93
77
 
94
78
 
95
- // export class MeshCollider extends Collider {
79
+ export class MeshCollider extends Collider {
96
80
 
97
- // onEnable() {
98
- // if (this.enabled)
99
- // this.context.physics.addMeshCollider(this.gameObject);
100
- // }
101
- // }
81
+
82
+ sharedMesh?: Mesh;
83
+ @serializeable()
84
+ convex: boolean = false;
85
+
86
+ awake(){
87
+ console.log(this);
88
+ }
89
+
90
+ onEnable() {
91
+ super.onEnable();
92
+ if (!this.sharedMesh?.isMesh) {
93
+ // HACK using the renderer mesh
94
+ if (this.gameObject instanceof Mesh) {
95
+ this.sharedMesh = this.gameObject;
96
+ }
97
+ }
98
+ if (this.sharedMesh?.isMesh)
99
+ this.context.physics.addMeshCollider(this, this.sharedMesh, this.convex);
100
+ }
101
+ }