@needle-tools/engine 2.40.0-pre → 2.41.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 (52) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/needle-engine.d.ts +269 -123
  3. package/dist/needle-engine.js +389 -389
  4. package/dist/needle-engine.js.map +4 -4
  5. package/dist/needle-engine.min.js +41 -41
  6. package/dist/needle-engine.min.js.map +4 -4
  7. package/lib/engine/engine_gizmos.d.ts +1 -0
  8. package/lib/engine/engine_gizmos.js +16 -4
  9. package/lib/engine/engine_gizmos.js.map +1 -1
  10. package/lib/engine/engine_math.d.ts +9 -6
  11. package/lib/engine/engine_math.js +9 -0
  12. package/lib/engine/engine_math.js.map +1 -1
  13. package/lib/engine/engine_physics.js +14 -6
  14. package/lib/engine/engine_physics.js.map +1 -1
  15. package/lib/engine/engine_serialization_core.js +2 -0
  16. package/lib/engine/engine_serialization_core.js.map +1 -1
  17. package/lib/engine/engine_utils.d.ts +1 -0
  18. package/lib/engine/engine_utils.js +3 -0
  19. package/lib/engine/engine_utils.js.map +1 -1
  20. package/lib/engine-components/AnimationCurve.js +20 -5
  21. package/lib/engine-components/AnimationCurve.js.map +1 -1
  22. package/lib/engine-components/Light.d.ts +2 -0
  23. package/lib/engine-components/Light.js +33 -9
  24. package/lib/engine-components/Light.js.map +1 -1
  25. package/lib/engine-components/ParticleSystem.d.ts +15 -26
  26. package/lib/engine-components/ParticleSystem.js +251 -184
  27. package/lib/engine-components/ParticleSystem.js.map +1 -1
  28. package/lib/engine-components/ParticleSystemModules.d.ts +208 -63
  29. package/lib/engine-components/ParticleSystemModules.js +640 -153
  30. package/lib/engine-components/ParticleSystemModules.js.map +1 -1
  31. package/lib/engine-components/WebXR.js +8 -3
  32. package/lib/engine-components/WebXR.js.map +1 -1
  33. package/lib/engine-components/codegen/components.d.ts +6 -0
  34. package/lib/engine-components/codegen/components.js +6 -0
  35. package/lib/engine-components/codegen/components.js.map +1 -1
  36. package/package.json +3 -1
  37. package/src/engine/codegen/register_types.js +24 -0
  38. package/src/engine/engine_gizmos.ts +19 -4
  39. package/src/engine/engine_math.ts +19 -6
  40. package/src/engine/engine_physics.ts +17 -7
  41. package/src/engine/engine_serialization_core.ts +1 -0
  42. package/src/engine/engine_utils.ts +5 -0
  43. package/src/engine-components/AnimationCurve.ts +25 -11
  44. package/src/engine-components/Light.ts +39 -8
  45. package/src/engine-components/ParticleSystem.ts +314 -194
  46. package/src/engine-components/ParticleSystemModules.ts +537 -154
  47. package/src/engine-components/WebXR.ts +11 -8
  48. package/src/engine-components/codegen/components.ts +6 -0
  49. package/src/engine/dist/engine_physics.js +0 -739
  50. package/src/engine/dist/engine_setup.js +0 -777
  51. package/src/engine-components/dist/CharacterController.js +0 -123
  52. package/src/engine-components/dist/RigidBody.js +0 -458
@@ -1,6 +1,6 @@
1
1
  import { Behaviour, GameObject } from "./Component";
2
2
  import * as THREE from "three";
3
- import { getParam } from "../engine/engine_utils";
3
+ import { getParam, isMobileDevice } from "../engine/engine_utils";
4
4
  import { setWorldPositionXYZ } from "../engine/engine_three_utils";
5
5
  import { FrameEvent } from "../engine/engine_setup";
6
6
  import { serializeable } from "../engine/engine_serialization_decorator";
@@ -8,6 +8,7 @@ import { Color, DirectionalLight, OrthographicCamera } from "three";
8
8
  import { WebXR, WebXREvent } from "./WebXR";
9
9
  import { WebARSessionRoot } from "./WebARSessionRoot";
10
10
  import { ILight } from "../engine/engine_types";
11
+ import { Mathf } from "../engine/engine_math";
11
12
 
12
13
  // https://threejs.org/examples/webgl_shadowmap_csm.html
13
14
 
@@ -87,6 +88,7 @@ export class Light extends Behaviour implements ILight {
87
88
 
88
89
  @serializeable()
89
90
  private type: LightType = 0;
91
+
90
92
  public range: number = 1;
91
93
  public spotAngle: number = 1;
92
94
  public innerSpotAngle: number = 1;
@@ -137,7 +139,8 @@ export class Light extends Behaviour implements ILight {
137
139
  set shadows(val: LightShadows) {
138
140
  this._shadows = val;
139
141
  if (this.light) {
140
- this.light.castShadow = val === LightShadows.Hard || val === LightShadows.Soft;
142
+ this.light.castShadow = val !== LightShadows.None;
143
+ this.updateShadowSoftHard();
141
144
  }
142
145
  }
143
146
  get shadows(): LightShadows { return this._shadows; }
@@ -284,9 +287,9 @@ export class Light extends Behaviour implements ILight {
284
287
  }
285
288
 
286
289
  createLight() {
287
- if (this.light) return;
288
- let lightAlreadyCreated = this.selfIsLight;
289
- if (lightAlreadyCreated) {
290
+ const lightAlreadyCreated = this.selfIsLight;
291
+
292
+ if (lightAlreadyCreated && !this.light) {
290
293
  this.light = this.gameObject as unknown as THREE.Light;
291
294
 
292
295
  switch (this.type) {
@@ -295,7 +298,7 @@ export class Light extends Behaviour implements ILight {
295
298
  break;
296
299
  }
297
300
  }
298
- else {
301
+ else if(!this.light) {
299
302
  switch (this.type) {
300
303
  case LightType.Directional:
301
304
  // console.log(this);
@@ -339,7 +342,7 @@ export class Light extends Behaviour implements ILight {
339
342
  }
340
343
 
341
344
 
342
- if (this.light !== undefined) {
345
+ if (this.light) {
343
346
  this._intensity = this.light.intensity;
344
347
 
345
348
  if (this.shadows !== LightShadows.None) {
@@ -356,6 +359,9 @@ export class Light extends Behaviour implements ILight {
356
359
  this.light.shadow.mapSize.width = 2048;
357
360
  this.light.shadow.mapSize.height = 2048;
358
361
  }
362
+ // this.light.shadow.needsUpdate = true;
363
+ // console.log(this.light.shadow.mapSize);
364
+ // return;
359
365
 
360
366
  if (debug)
361
367
  console.log("Override shadow bias?", this._overrideShadowBiasSettings, this.shadowBias, this.shadowNormalBias);
@@ -370,7 +376,8 @@ export class Light extends Behaviour implements ILight {
370
376
  this.light.shadow.normalBias = this.shadowNormalBias * .0001;
371
377
  }
372
378
 
373
- // console.log(this.light.shadow, this);
379
+ this.updateShadowSoftHard();
380
+
374
381
  const cam = this.light.shadow.camera as THREE.OrthographicCamera;
375
382
  cam.near = this.shadowNearPlane;
376
383
  // use shadow distance that was set explictly (if any)
@@ -399,6 +406,8 @@ export class Light extends Behaviour implements ILight {
399
406
  cam.top *= sy;
400
407
  cam.bottom *= sy;
401
408
  }
409
+
410
+
402
411
  this.light.shadow.needsUpdate = true;
403
412
  if (debug)
404
413
  this.context.scene.add(new THREE.CameraHelper(cam));
@@ -425,6 +434,28 @@ export class Light extends Behaviour implements ILight {
425
434
  }
426
435
  }
427
436
 
437
+ static allowChangingRendererShadowMapType: boolean = true;
438
+
439
+ private updateShadowSoftHard() {
440
+ if (!this.light) return;
441
+ if (this.shadows === LightShadows.Soft) {
442
+ const radius = this.light.shadow.mapSize.width / 1024 * 5;
443
+ const samples = Mathf.clamp(Math.round(radius), 2, 10);
444
+ this.light.shadow.radius = radius;
445
+ this.light.shadow.blurSamples = samples;
446
+ if (isMobileDevice()) {
447
+ this.light.shadow.radius *= .5;
448
+ this.light.shadow.blurSamples = Math.floor(this.light.shadow.blurSamples * .5);
449
+ }
450
+ if (Light.allowChangingRendererShadowMapType)
451
+ this.context.renderer.shadowMap.type = THREE.VSMShadowMap;
452
+ }
453
+ else {
454
+ this.light.shadow.radius = 1;
455
+ this.light.shadow.blurSamples = 1;
456
+ }
457
+ }
458
+
428
459
  private setDirectionalLight(dirLight: DirectionalLight) {
429
460
  dirLight.add(dirLight.target);
430
461
  dirLight.target.position.set(0, 0, -1);