@needle-tools/engine 4.1.0-beta.3 → 4.1.0-beta.5

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 (75) hide show
  1. package/CHANGELOG.md +29 -18
  2. package/components.needle.json +1 -1
  3. package/dist/gltf-progressive.js +59 -59
  4. package/dist/gltf-progressive.light.js +59 -59
  5. package/dist/gltf-progressive.light.min.js +6 -6
  6. package/dist/gltf-progressive.light.umd.cjs +5 -5
  7. package/dist/gltf-progressive.min.js +6 -6
  8. package/dist/gltf-progressive.umd.cjs +5 -5
  9. package/dist/needle-engine.bundle.js +2774 -2753
  10. package/dist/needle-engine.bundle.light.js +2773 -2752
  11. package/dist/needle-engine.bundle.light.min.js +110 -110
  12. package/dist/needle-engine.bundle.light.umd.cjs +101 -101
  13. package/dist/needle-engine.bundle.min.js +110 -110
  14. package/dist/needle-engine.bundle.umd.cjs +113 -113
  15. package/dist/needle-engine.js +202 -201
  16. package/dist/needle-engine.light.d.ts +14263 -0
  17. package/dist/needle-engine.light.js +202 -201
  18. package/dist/needle-engine.light.min.js +1 -1
  19. package/dist/needle-engine.light.umd.cjs +1 -1
  20. package/dist/needle-engine.min.js +1 -1
  21. package/dist/needle-engine.umd.cjs +1 -1
  22. package/dist/three-examples.js +2795 -2436
  23. package/dist/three-examples.light.js +2795 -2436
  24. package/dist/three-examples.light.min.js +47 -15
  25. package/dist/three-examples.light.umd.cjs +47 -15
  26. package/dist/three-examples.min.js +47 -15
  27. package/dist/three-examples.umd.cjs +47 -15
  28. package/dist/three.js +67 -62
  29. package/dist/three.light.js +67 -62
  30. package/dist/three.light.min.js +170 -170
  31. package/dist/three.light.umd.cjs +170 -170
  32. package/dist/three.min.js +170 -170
  33. package/dist/three.umd.cjs +170 -170
  34. package/dist/vendor.js +1 -1
  35. package/dist/vendor.light.js +1 -1
  36. package/dist/vendor.light.min.js +1 -1
  37. package/dist/vendor.min.js +1 -1
  38. package/lib/engine/engine_context.d.ts +3 -2
  39. package/lib/engine/engine_context.js +26 -4
  40. package/lib/engine/engine_context.js.map +1 -1
  41. package/lib/engine/engine_physics_rapier.d.ts +1 -1
  42. package/lib/engine/engine_physics_rapier.js +17 -12
  43. package/lib/engine/engine_physics_rapier.js.map +1 -1
  44. package/lib/engine/engine_types.d.ts +1 -1
  45. package/lib/engine-components/Camera.d.ts +7 -4
  46. package/lib/engine-components/Camera.js +13 -10
  47. package/lib/engine-components/Camera.js.map +1 -1
  48. package/lib/engine-components/Collider.js +4 -5
  49. package/lib/engine-components/Collider.js.map +1 -1
  50. package/lib/engine-components/OrbitControls.js +1 -1
  51. package/lib/engine-components/OrbitControls.js.map +1 -1
  52. package/lib/engine-components/RigidBody.js +2 -2
  53. package/lib/engine-components/RigidBody.js.map +1 -1
  54. package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +1 -1
  55. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +1 -1
  56. package/lib/engine-components/export/usdz/index.d.ts +1 -1
  57. package/lib/engine-components/export/usdz/index.js +1 -1
  58. package/lib/engine-components/export/usdz/index.js.map +1 -1
  59. package/lib/engine-components/particlesystem/ParticleSystem.d.ts +5 -6
  60. package/lib/engine-components/particlesystem/ParticleSystem.js +23 -9
  61. package/lib/engine-components/particlesystem/ParticleSystem.js.map +1 -1
  62. package/lib/engine-components/particlesystem/ParticleSystemModules.js +7 -1
  63. package/lib/engine-components/particlesystem/ParticleSystemModules.js.map +1 -1
  64. package/package.json +4 -3
  65. package/src/engine/engine_context.ts +31 -8
  66. package/src/engine/engine_physics_rapier.ts +20 -10
  67. package/src/engine/engine_types.ts +1 -1
  68. package/src/engine-components/Camera.ts +14 -11
  69. package/src/engine-components/Collider.ts +4 -4
  70. package/src/engine-components/OrbitControls.ts +1 -1
  71. package/src/engine-components/RigidBody.ts +2 -2
  72. package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +1 -1
  73. package/src/engine-components/export/usdz/index.ts +1 -1
  74. package/src/engine-components/particlesystem/ParticleSystem.ts +26 -10
  75. package/src/engine-components/particlesystem/ParticleSystemModules.ts +9 -2
@@ -490,7 +490,7 @@ export interface IPhysicsEngine {
490
490
  addSphereCollider(collider: ICollider);
491
491
  addBoxCollider(collider: ICollider, size: Vector3);
492
492
  addCapsuleCollider(collider: ICollider, radius: number, height: number);
493
- addMeshCollider(collider: ICollider, mesh: Mesh, convex: boolean, scale: Vector3);
493
+ addMeshCollider(collider: ICollider, mesh: Mesh, convex: boolean, scale?: Vector3 | undefined);
494
494
 
495
495
  updatePhysicsMaterial(collider: ICollider);
496
496
 
@@ -51,7 +51,7 @@ export class Camera extends Behaviour implements ICamera {
51
51
  }
52
52
  }
53
53
  }
54
- /** The camera's field of view in degrees if it is a perspective camera */
54
+ /** The camera's field of view in degrees if it is a perspective camera. Calls updateProjectionMatrix when set */
55
55
  get fieldOfView(): number | undefined {
56
56
  if (this._cam instanceof PerspectiveCamera) {
57
57
  return this._cam.fov;
@@ -74,7 +74,7 @@ export class Camera extends Behaviour implements ICamera {
74
74
  }
75
75
  }
76
76
 
77
- /** The camera's near clipping plane */
77
+ /** The camera's near clipping plane. Calls updateProjectionMatrix when set */
78
78
  get nearClipPlane(): number { return this._nearClipPlane; }
79
79
  @serializable()
80
80
  set nearClipPlane(val) {
@@ -87,15 +87,7 @@ export class Camera extends Behaviour implements ICamera {
87
87
  }
88
88
  private _nearClipPlane: number = 0.1;
89
89
 
90
- applyClippingPlane() {
91
- if (this._cam) {
92
- this._cam.near = this._nearClipPlane;
93
- this._cam.far = this._farClipPlane;
94
- this._cam.updateProjectionMatrix();
95
- }
96
- }
97
-
98
- /** The camera's far clipping plane */
90
+ /** The camera's far clipping plane. Calls updateProjectionMatrix when set */
99
91
  get farClipPlane(): number { return this._farClipPlane; }
100
92
  @serializable()
101
93
  set farClipPlane(val) {
@@ -108,6 +100,17 @@ export class Camera extends Behaviour implements ICamera {
108
100
  }
109
101
  private _farClipPlane: number = 1000;
110
102
 
103
+ /**
104
+ * Applys both the camera's near and far plane and calls updateProjectionMatrix on the camera.
105
+ */
106
+ applyClippingPlane() {
107
+ if (this._cam) {
108
+ this._cam.near = this._nearClipPlane;
109
+ this._cam.far = this._farClipPlane;
110
+ this._cam.updateProjectionMatrix();
111
+ }
112
+ }
113
+
111
114
  /** The camera's clear flags - determines if the background is a skybox or a solid color or transparent */
112
115
  @serializable()
113
116
  public get clearFlags(): ClearFlags {
@@ -207,12 +207,12 @@ export class MeshCollider extends Collider {
207
207
  const LOD = 0;
208
208
 
209
209
  if (this.sharedMesh?.isMesh) {
210
- this.context.physics.engine.addMeshCollider(this, this.sharedMesh, this.convex, getWorldScale(this.gameObject));
210
+ this.context.physics.engine.addMeshCollider(this, this.sharedMesh, this.convex);
211
211
  NEEDLE_progressive.assignMeshLOD(this.sharedMesh, LOD).then(res => {
212
212
  if (res && this.activeAndEnabled && this.context.physics.engine && this.sharedMesh) {
213
213
  this.context.physics.engine.removeBody(this);
214
214
  this.sharedMesh.geometry = res;
215
- this.context.physics.engine.addMeshCollider(this, this.sharedMesh, this.convex, getWorldScale(this.gameObject));
215
+ this.context.physics.engine.addMeshCollider(this, this.sharedMesh, this.convex);
216
216
  }
217
217
  })
218
218
  }
@@ -224,7 +224,7 @@ export class MeshCollider extends Collider {
224
224
  for (const ch in group.children) {
225
225
  const child = group.children[ch] as Mesh;
226
226
  if (child.isMesh) {
227
- this.context.physics.engine.addMeshCollider(this, child, this.convex, getWorldScale(this.gameObject));
227
+ this.context.physics.engine.addMeshCollider(this, child, this.convex);
228
228
  promises.push(NEEDLE_progressive.assignMeshLOD(child, LOD));
229
229
  }
230
230
  }
@@ -235,7 +235,7 @@ export class MeshCollider extends Collider {
235
235
  for (const r of res) {
236
236
  if (r && this.activeAndEnabled) {
237
237
  mesh.geometry = r;
238
- this.context.physics.engine?.addMeshCollider(this, mesh, this.convex, getWorldScale(this.gameObject));
238
+ this.context.physics.engine?.addMeshCollider(this, mesh, this.convex);
239
239
  }
240
240
  }
241
241
  });
@@ -287,7 +287,7 @@ export class OrbitControls extends Behaviour implements ICameraController {
287
287
  cam = this.gameObject;
288
288
  }
289
289
  if (cam) setCameraController(cam, this, true);
290
- if (!this._controls && cam instanceof PerspectiveCamera) {
290
+ if (!this._controls && cam instanceof Object3D) {
291
291
  this._cameraObject = cam;
292
292
  // Using the parent if possible to make it possible to disable input on the canvas
293
293
  // for having HTML content behind it and still receive input
@@ -324,9 +324,9 @@ export class Rigidbody extends Behaviour implements IRigidbody {
324
324
  console.warn(`Rigidbody could not be created: Rapier physics are explicitly disabled.`);
325
325
  else {
326
326
  MODULES.RAPIER_PHYSICS.ready().then(async () => {
327
- await delayForFrames(1);
327
+ await delayForFrames(3);
328
328
  if (!this.context.physics.engine?.getBody(this))
329
- console.warn(`Rigidbody could not be created. Ensure \"(${this.name}\" has a Collider component.`);
329
+ console.warn(`Rigidbody could not be created. Ensure \"${this.name}\" has a Collider component.`);
330
330
  })
331
331
  }
332
332
  }
@@ -1174,7 +1174,7 @@ declare type ImageReadbackResult = {
1174
1174
  imageBitmap?: ImageBitmap;
1175
1175
  }
1176
1176
 
1177
- /** Reads back a texture from the GPU (can be compressed, a render texture, or aynthing), apply colorScale to it, and return CPU data for further usage.
1177
+ /** Reads back a texture from the GPU (can be compressed, a render texture, or anything), optionally applies RGBA colorScale to it, and returns CPU data for further usage.
1178
1178
  * Note that there are WebGL / WebGPU rules preventing some use of data between WebGL contexts.
1179
1179
  */
1180
1180
  async function decompressGpuTexture( texture, maxTextureSize = Infinity, renderer: WebGLRenderer | null = null, colorScale: Vector4 | undefined = undefined): Promise<ImageReadbackResult> {
@@ -1,3 +1,3 @@
1
1
  export { type UsdzBehaviour } from "./extensions/behavior/Behaviour.js";
2
- export { imageToCanvas, makeNameSafeForUSD, USDZExporter as NeedleUSDZExporter, USDDocument, USDObject, USDWriter,type USDZExporterContext } from "./ThreeUSDZExporter.js";
2
+ export { decompressGpuTexture, imageToCanvas, makeNameSafeForUSD, USDZExporter as NeedleUSDZExporter, USDDocument, USDObject, USDWriter,type USDZExporterContext } from "./ThreeUSDZExporter.js";
3
3
  export { USDZExporter } from "./USDZExporter.js";
@@ -1,4 +1,4 @@
1
- import { AxesHelper, BackSide, Blending, BufferGeometry, FrontSide, LinearSRGBColorSpace, Material, Matrix4, Mesh, NormalBlending, Object3D, PlaneGeometry, Quaternion, SpriteMaterial, Texture, Vector3, Vector4 } from "three";
1
+ import { AxesHelper, BackSide, Blending, BufferGeometry, FrontSide, LinearSRGBColorSpace, Material, Matrix4, Mesh, MeshBasicMaterial, MeshStandardMaterial, NormalBlending, Object3D, PlaneGeometry, Quaternion, SpriteMaterial, Texture, Vector3, Vector4 } from "three";
2
2
  import type { BatchedRenderer, Behavior, BurstParameters, EmissionState, EmitterShape, FunctionColorGenerator, FunctionJSON, FunctionValueGenerator, GeneratorMemory, Particle, ParticleSystemParameters, RecordState, TrailSettings, ValueGenerator } from "three.quarks";
3
3
  import { BatchedParticleRenderer, ConstantColor, ConstantValue, ParticleSystem as _ParticleSystem, RenderMode, TrailParticle, Vector3 as QVector3, Vector4 as QVector4 } from "three.quarks";
4
4
 
@@ -39,10 +39,10 @@ export class ParticleSystemRenderer extends Behaviour {
39
39
  renderMode?: ParticleSystemRenderMode;
40
40
 
41
41
  @serializable(Material)
42
- particleMaterial?: SpriteMaterial;
42
+ particleMaterial?: SpriteMaterial | MeshBasicMaterial;
43
43
 
44
44
  @serializable(Material)
45
- trailMaterial?: SpriteMaterial;
45
+ trailMaterial?: SpriteMaterial | MeshBasicMaterial;
46
46
 
47
47
  // @serializable(Mesh)
48
48
  particleMesh?: Mesh | string;
@@ -68,6 +68,7 @@ export class ParticleSystemRenderer extends Behaviour {
68
68
  // showBalloonWarning(msg);
69
69
  }
70
70
  }
71
+
71
72
  }
72
73
 
73
74
  get transparent(): boolean {
@@ -80,6 +81,24 @@ export class ParticleSystemRenderer extends Behaviour {
80
81
  let material = (trailEnabled === true && this.trailMaterial) ? this.trailMaterial : this.particleMaterial;
81
82
 
82
83
  if (material) {
84
+
85
+ if (material.type === "MeshStandardMaterial") {
86
+ if (debug) console.debug("ParticleSystemRenderer.getMaterial: MeshStandardMaterial detected, converting to MeshBasicMaterial. See https://github.com/Alchemist0823/three.quarks/issues/101");
87
+ if ("map" in material && material.map) {
88
+ material.map.colorSpace = LinearSRGBColorSpace;
89
+ material.map.premultiplyAlpha = false;
90
+ }
91
+ const newMaterial = new MeshBasicMaterial({ map: material.map });
92
+ if (trailEnabled) this.trailMaterial = newMaterial;
93
+ else this.particleMaterial = newMaterial;
94
+ }
95
+
96
+
97
+ if (material.map) {
98
+ material.map.colorSpace = LinearSRGBColorSpace;
99
+ material.map.premultiplyAlpha = false;
100
+ }
101
+
83
102
  if (trailEnabled) {
84
103
  // the particle material for trails must be DoubleSide or BackSide (since otherwise the trail is invisible)
85
104
  if (material.side === FrontSide) {
@@ -896,7 +915,7 @@ export class ParticleSystem extends Behaviour implements IParticleSystem {
896
915
  if (particleSystemBehaviour instanceof ParticleSystemBaseBehaviour) {
897
916
  particleSystemBehaviour.system = this;
898
917
  }
899
- if (isDevEnvironment()) console.log("add behaviour", particleSystemBehaviour);
918
+ if (isDevEnvironment() || debug) console.debug("Add custom ParticleSystem Behaviour", particleSystemBehaviour);
900
919
  this._particleSystem.addBehavior(particleSystemBehaviour);
901
920
  return true;
902
921
  }
@@ -908,6 +927,7 @@ export class ParticleSystem extends Behaviour implements IParticleSystem {
908
927
  const behaviours = this._particleSystem.behaviors;
909
928
  const index = behaviours.indexOf(particleSystemBehaviour);
910
929
  if (index !== -1) {
930
+ if (isDevEnvironment() || debug) console.debug("Remove custom ParticleSystem Behaviour", index, particleSystemBehaviour);
911
931
  behaviours.splice(index, 1);
912
932
  return true;
913
933
  }
@@ -1145,13 +1165,9 @@ export class ParticleSystem extends Behaviour implements IParticleSystem {
1145
1165
  }
1146
1166
  }
1147
1167
 
1148
- private lastMaterialVersion: number = -1;
1168
+ // private lastMaterialVersion: number = -1;
1149
1169
  private onUpdate() {
1150
- const mat = this.renderer.getMaterial(this.trails.enabled);
1151
- if (mat && mat.version != this.lastMaterialVersion && this._particleSystem) {
1152
- this.lastMaterialVersion = mat.version;
1153
- this._particleSystem.texture = this._interface.texture;
1154
- }
1170
+
1155
1171
 
1156
1172
  if (this._bursts) {
1157
1173
  this.emission.bursts = this._bursts;
@@ -1,6 +1,6 @@
1
1
  import { createNoise4D, type NoiseFunction4D } from 'simplex-noise';
2
2
  import { BufferGeometry, Color, Euler, Matrix4, Mesh, Object3D, Quaternion, Triangle, Vector2, Vector3, Vector4 } from "three";
3
- import type { EmitterShape, IParticleSystem as QParticleSystem,Particle, ShapeJSON, Vector3 as QVector3, Vector4 as QVector4 } from "three.quarks";
3
+ import type { EmitterShape, IParticleSystem as QParticleSystem, Particle, ShapeJSON, Vector3 as QVector3, Vector4 as QVector4 } from "three.quarks";
4
4
 
5
5
  import { isDevEnvironment } from '../../engine/debug/index.js';
6
6
  import { Gizmos } from "../../engine/engine_gizmos.js";
@@ -360,9 +360,16 @@ export class MinMaxGradient {
360
360
  this.gradientMax.evaluate(t01, MinMaxGradient._temp2);
361
361
  return MinMaxGradient._temp.lerp(MinMaxGradient._temp2, t);
362
362
 
363
+ case ParticleSystemGradientMode.RandomColor:
364
+ case "RandomColor":
365
+ const random_t = Math.random();
366
+ this.gradientMin.evaluate(t01, MinMaxGradient._temp);
367
+ this.gradientMax.evaluate(t01, MinMaxGradient._temp2);
368
+ return MinMaxGradient._temp.lerp(MinMaxGradient._temp2, random_t);
369
+
363
370
  }
364
371
  // console.warn("Not implemented", ParticleSystemGradientMode[this.mode]);
365
- MinMaxGradient._temp.set(0xff00ff)
372
+ MinMaxGradient._temp.set(0xffffff)
366
373
  MinMaxGradient._temp.alpha = 1;
367
374
  return MinMaxGradient._temp;
368
375
  }