Needle Engine

Changes between version 3.22.1 and 3.22.2
Files changed (24) hide show
  1. src/engine-components/AudioSource.ts +1 -1
  2. src/engine/engine_gameobject.ts +4 -1
  3. src/engine/engine_math.ts +4 -1
  4. src/engine/engine_physics_rapier.ts +38 -28
  5. src/engine/engine_physics.types.ts +6 -5
  6. src/engine/engine_scenetools.ts +17 -1
  7. src/engine/engine_types.ts +1 -0
  8. src/engine-components/ui/RectTransform.ts +13 -6
  9. src/engine-components/RigidBody.ts +9 -2
  10. src/engine-schemes/dist/api.js.meta +7 -0
  11. src/engine/dist/api.js.meta +7 -0
  12. src/engine-components/dist/AudioSource.js.meta +7 -0
  13. src/engine/dist/engine_networking_streams.js.meta +7 -0
  14. src/engine-schemes/dist/schemes.js.meta +7 -0
  15. src/engine-components/dist/ScreenCapture.js.meta +7 -0
  16. src/engine-schemes/dist/synced-camera-model.js.meta +7 -0
  17. src/engine-schemes/dist/synced-transform-model.js.meta +7 -0
  18. src/engine-schemes/dist/transform.js.meta +7 -0
  19. src/engine-schemes/dist/vec2.js.meta +7 -0
  20. src/engine-schemes/dist/vec3.js.meta +7 -0
  21. src/engine-schemes/dist/vec4.js.meta +7 -0
  22. src/engine-components/dist/VideoPlayer.js.meta +7 -0
  23. src/engine-components/dist/Voip2.js.meta +7 -0
  24. src/engine-schemes/dist/vr-user-state-buffer.js.meta +7 -0
src/engine-components/AudioSource.ts CHANGED
@@ -196,7 +196,7 @@
196
196
  onDisable() {
197
197
  globalThis.removeEventListener('visibilitychange', this.onVisibilityChanged);
198
198
  this.context.application.removeEventListener(ApplicationEvents.MuteChanged, this.onApplicationMuteChanged);
199
- this.stop();
199
+ this.pause();
200
200
  }
201
201
 
202
202
  private onVisibilityChanged = () => {
src/engine/engine_gameobject.ts CHANGED
@@ -609,7 +609,10 @@
609
609
  if (value.isVector4 || value.isVector3 || value.isVector2 || value.isQuaternion || value.isEuler) {
610
610
  return value.clone();
611
611
  }
612
- else if(value.isEventList === true){
612
+ else if (value.isColor === true) {
613
+ return value.clone();
614
+ }
615
+ else if (value.isEventList === true) {
613
616
  // create a new instance of the object
614
617
  const copy = new value.constructor();
615
618
  return copy;
src/engine/engine_math.ts CHANGED
@@ -2,7 +2,10 @@
2
2
 
3
3
  class MathHelper {
4
4
 
5
- random(): number {
5
+ random(min?: number, max?: number): number {
6
+ if (min !== undefined && max !== undefined) {
7
+ return Math.random() * (max - min) + min;
8
+ }
6
9
  return Math.random();
7
10
  }
8
11
 
src/engine/engine_physics_rapier.ts CHANGED
@@ -651,35 +651,45 @@
651
651
  // TODO: we might want to update this if the material changes
652
652
  const physicsMaterial = collider.sharedMaterial;
653
653
  if (physicsMaterial) {
654
- desc.setRestitution(physicsMaterial.bounciness);
655
- switch (physicsMaterial.bounceCombine) {
656
- case PhysicsMaterialCombine.Average:
657
- desc.setRestitutionCombineRule(CoefficientCombineRule.Average);
658
- break;
659
- case PhysicsMaterialCombine.Maximum:
660
- desc.setRestitutionCombineRule(CoefficientCombineRule.Max);
661
- break;
662
- case PhysicsMaterialCombine.Minimum:
663
- desc.setRestitutionCombineRule(CoefficientCombineRule.Min);
664
- break;
665
- case PhysicsMaterialCombine.Multiply:
666
- desc.setRestitutionCombineRule(CoefficientCombineRule.Multiply);
667
- break;
654
+
655
+ if (physicsMaterial.bounciness !== undefined)
656
+ desc.setRestitution(physicsMaterial.bounciness);
657
+
658
+ if (physicsMaterial.bounceCombine !== undefined) {
659
+ switch (physicsMaterial.bounceCombine) {
660
+ case PhysicsMaterialCombine.Average:
661
+ desc.setRestitutionCombineRule(CoefficientCombineRule.Average);
662
+ break;
663
+ case PhysicsMaterialCombine.Maximum:
664
+ desc.setRestitutionCombineRule(CoefficientCombineRule.Max);
665
+ break;
666
+ case PhysicsMaterialCombine.Minimum:
667
+ desc.setRestitutionCombineRule(CoefficientCombineRule.Min);
668
+ break;
669
+ case PhysicsMaterialCombine.Multiply:
670
+ desc.setRestitutionCombineRule(CoefficientCombineRule.Multiply);
671
+ break;
672
+ }
668
673
  }
669
- desc.setFriction(physicsMaterial.dynamicFriction);
670
- switch (physicsMaterial.frictionCombine) {
671
- case PhysicsMaterialCombine.Average:
672
- desc.setFrictionCombineRule(CoefficientCombineRule.Average);
673
- break;
674
- case PhysicsMaterialCombine.Maximum:
675
- desc.setFrictionCombineRule(CoefficientCombineRule.Max);
676
- break;
677
- case PhysicsMaterialCombine.Minimum:
678
- desc.setFrictionCombineRule(CoefficientCombineRule.Min);
679
- break;
680
- case PhysicsMaterialCombine.Multiply:
681
- desc.setFrictionCombineRule(CoefficientCombineRule.Multiply);
682
- break;
674
+
675
+ if (physicsMaterial.dynamicFriction !== undefined)
676
+ desc.setFriction(physicsMaterial.dynamicFriction);
677
+
678
+ if (physicsMaterial.frictionCombine !== undefined) {
679
+ switch (physicsMaterial.frictionCombine) {
680
+ case PhysicsMaterialCombine.Average:
681
+ desc.setFrictionCombineRule(CoefficientCombineRule.Average);
682
+ break;
683
+ case PhysicsMaterialCombine.Maximum:
684
+ desc.setFrictionCombineRule(CoefficientCombineRule.Max);
685
+ break;
686
+ case PhysicsMaterialCombine.Minimum:
687
+ desc.setFrictionCombineRule(CoefficientCombineRule.Min);
688
+ break;
689
+ case PhysicsMaterialCombine.Multiply:
690
+ desc.setFrictionCombineRule(CoefficientCombineRule.Multiply);
691
+ break;
692
+ }
683
693
  }
684
694
  }
685
695
 
src/engine/engine_physics.types.ts CHANGED
@@ -8,11 +8,12 @@
8
8
  }
9
9
 
10
10
  export type PhysicsMaterial = {
11
- bounceCombine: PhysicsMaterialCombine;
12
- bounciness: number;
13
- frictionCombine: PhysicsMaterialCombine;
14
- dynamicFriction: number;
15
- staticFriction: number;
11
+ bounceCombine?: PhysicsMaterialCombine;
12
+ bounciness?: number;
13
+ frictionCombine?: PhysicsMaterialCombine;
14
+ dynamicFriction?: number;
15
+ /**@deprecated not used */
16
+ staticFriction?:number;
16
17
  }
17
18
 
18
19
  export enum CollisionDetectionMode {
src/engine/engine_scenetools.ts CHANGED
@@ -106,13 +106,29 @@
106
106
  if (typeof path !== "string") {
107
107
  console.warn("Parse gltf binary without path, this might lead to errors in resolving extensions. Please provide the source path of the gltf/glb file", path, typeof path);
108
108
  }
109
+ if (printGltf) console.log("Parse glTF", path)
109
110
  const loader = await createGLTFLoader(path, context);
110
111
  const componentsExtension = registerComponentExtension(loader);
111
112
  return new Promise((resolve, reject) => {
112
113
  try {
114
+
115
+ // GltfLoader expects a base path for resolving referenced assets
116
+ // https://threejs.org/docs/#examples/en/loaders/GLTFLoader.parse
117
+ // so we make sure that "path" is never a file path
118
+ let gltfLoaderPath = path.split("?")[0].trimEnd();
119
+ if (gltfLoaderPath.endsWith(".glb") || gltfLoaderPath.endsWith(".gltf")) {
120
+ // strip file from path
121
+ const parts = gltfLoaderPath.split("/");
122
+ parts.pop();
123
+ gltfLoaderPath = parts.join("/");
124
+ if (!gltfLoaderPath.endsWith("/")) gltfLoaderPath += "/";
125
+ }
126
+ loader.resourcePath = gltfLoaderPath;
127
+
113
128
  loaders.addDracoAndKTX2Loaders(loader, context);
129
+
114
130
  invokeEvents(GltfLoadEventType.BeforeLoad, new GltfLoadEvent(context, path, loader));
115
- loader.parse(data, path, async res => {
131
+ loader.parse(data, "", async res => {
116
132
  invokeEvents(GltfLoadEventType.AfterLoaded, new GltfLoadEvent(context, path, loader, res));
117
133
  await handleLoadedGltf(context, path, res, seed, componentsExtension);
118
134
  invokeEvents(GltfLoadEventType.FinishedSetup, new GltfLoadEvent(context, path, loader, res));
src/engine/engine_types.ts CHANGED
@@ -211,6 +211,7 @@
211
211
  cullingMask: number;
212
212
  aspect: number;
213
213
  fieldOfView?: number;
214
+ /** x and y are in pixel on the canvas / dom element */
214
215
  screenPointToRay(x: number, y: number, ray?: Ray): Ray;
215
216
  targetTexture: RenderTexture | null;
216
217
  }
src/engine-components/ui/RectTransform.ts CHANGED
@@ -68,29 +68,36 @@
68
68
  // @serializable(Vector2)
69
69
  // offsetMax: Vector2 = new Vector2(0, 0);
70
70
 
71
+ /** Optional min width in pixel, set to undefined to disable it */
72
+ minWidth?: number;
73
+ /** Optional min height in pixel, set to undefined to disable it */
74
+ minHeight?: number;
75
+
71
76
  get width() {
77
+ let width = this.sizeDelta.x;
72
78
  if (this.anchorMin.x !== this.anchorMax.x) {
73
79
  if (this._parentRectTransform) {
74
80
  const parentWidth = this._parentRectTransform.width;
75
81
  const anchorWidth = this.anchorMax.x - this.anchorMin.x;
76
- let width = parentWidth * anchorWidth;
82
+ width = parentWidth * anchorWidth;
77
83
  width += this.sizeDelta.x;
78
- return width;
79
84
  }
80
85
  }
81
- return this.sizeDelta.x;
86
+ if(this.minWidth !== undefined && width < this.minWidth) return this.minWidth;
87
+ return width
82
88
  }
83
89
  get height() {
90
+ let height = this.sizeDelta.y;
84
91
  if (this.anchorMin.y !== this.anchorMax.y) {
85
92
  if (this._parentRectTransform) {
86
93
  const parentHeight = this._parentRectTransform.height;
87
94
  const anchorHeight = this.anchorMax.y - this.anchorMin.y;
88
- let height = parentHeight * anchorHeight;
95
+ height = parentHeight * anchorHeight;
89
96
  height += this.sizeDelta.y;
90
- return height
91
97
  }
92
98
  }
93
- return this.sizeDelta.y;
99
+ if(this.minHeight !== undefined && height < this.minHeight) return this.minHeight;
100
+ return height;
94
101
  }
95
102
 
96
103
  // private lastMatrixWorld!: Matrix4;
src/engine-components/RigidBody.ts CHANGED
@@ -337,9 +337,16 @@
337
337
  this.context.physics.engine?.applyImpulse(this, vec, wakeup);
338
338
  }
339
339
 
340
- public setForce(x: number, y: number, z: number, wakeup: boolean = true) {
340
+ public setForce(x: Vector3 | Vec3 | number, y?: number, z?: number, wakeup: boolean = true) {
341
341
  this.context.physics.engine?.resetForces(this, wakeup);
342
- this.context.physics.engine?.addForce(this, { x, y, z }, wakeup);
342
+ if (typeof x === "number") {
343
+ y ??= 0;
344
+ z ??= 0;
345
+ this.context.physics.engine?.addForce(this, { x, y, z }, wakeup);
346
+ }
347
+ else {
348
+ this.context.physics.engine?.addForce(this, x, wakeup);
349
+ }
343
350
  }
344
351
 
345
352
  public getVelocity(): Vector3 {
src/engine-schemes/dist/api.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: aeb5cd8dfc66d8647a9ae66a8c05b289
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine/dist/api.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: f0e01709ea200b648a0c053c2c79f225
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-components/dist/AudioSource.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: ed9ae84735d6def4b8122977a98ffa67
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine/dist/engine_networking_streams.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 48d3950534f4dae478088f839e8c1578
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-schemes/dist/schemes.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 5f962500714f41d45b62c935327da875
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-components/dist/ScreenCapture.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 426cba1d1719d9240aba902b59b93adb
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-schemes/dist/synced-camera-model.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 1d631bded37bcc249bc1c0f40c3c67be
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-schemes/dist/synced-transform-model.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: e8764b784e44b1346ad7119078221aa2
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-schemes/dist/transform.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: eab38a2bd1b4834448fd9acc5fba06d0
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-schemes/dist/vec2.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: a1b516d1fe960a441be75734a9d63918
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-schemes/dist/vec3.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 8bb79deb329f82d45b65efdbcfcfa590
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-schemes/dist/vec4.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 77f3ae2882ffe74409bea2f9443fb40d
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-components/dist/VideoPlayer.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: f2624a361e4f4e046998075d7c419627
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-components/dist/Voip2.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 92b7a6f0a8029fd4799f91553f3a9a58
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
src/engine-schemes/dist/vr-user-state-buffer.js.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: b82b7d00193cb1d4f851ab843c5bb99f
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant: