@needle-tools/engine 3.7.7-beta → 3.9.0-alpha

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 (116) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/needle-engine.js +473 -87019
  3. package/dist/needle-engine.light.js +473 -84478
  4. package/dist/needle-engine.light.min.js +1 -5805
  5. package/dist/needle-engine.light.umd.cjs +1 -5805
  6. package/dist/needle-engine.min.js +1 -5818
  7. package/dist/needle-engine.umd.cjs +1 -5818
  8. package/lib/engine/codegen/register_types.js +2 -0
  9. package/lib/engine/codegen/register_types.js.map +1 -1
  10. package/lib/engine/debug/debug.d.ts +1 -1
  11. package/lib/engine/engine_context.d.ts +3 -1
  12. package/lib/engine/engine_context.js +18 -13
  13. package/lib/engine/engine_context.js.map +1 -1
  14. package/lib/engine/engine_element.js +15 -8
  15. package/lib/engine/engine_element.js.map +1 -1
  16. package/lib/engine/engine_element_overlay.d.ts +2 -1
  17. package/lib/engine/engine_element_overlay.js +38 -55
  18. package/lib/engine/engine_element_overlay.js.map +1 -1
  19. package/lib/engine/engine_lightdata.js +6 -7
  20. package/lib/engine/engine_lightdata.js.map +1 -1
  21. package/lib/engine/engine_networking_utils.d.ts +1 -1
  22. package/lib/engine/engine_networking_utils.js.map +1 -1
  23. package/lib/engine/engine_scenelighting.js +5 -5
  24. package/lib/engine/engine_scenelighting.js.map +1 -1
  25. package/lib/engine/extensions/NEEDLE_lightmaps.js +3 -3
  26. package/lib/engine/extensions/NEEDLE_lightmaps.js.map +1 -1
  27. package/lib/engine/extensions/NEEDLE_render_objects.js +1 -1
  28. package/lib/engine/extensions/NEEDLE_render_objects.js.map +1 -1
  29. package/lib/engine/extensions/NEEDLE_techniques_webgl.js +4 -1
  30. package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
  31. package/lib/engine/extensions/extensions.d.ts +1 -1
  32. package/lib/engine/extensions/extensions.js +17 -3
  33. package/lib/engine/extensions/extensions.js.map +1 -1
  34. package/lib/engine-components/Camera.js +3 -3
  35. package/lib/engine-components/Camera.js.map +1 -1
  36. package/lib/engine-components/GroundProjection.js +1 -1
  37. package/lib/engine-components/GroundProjection.js.map +1 -1
  38. package/lib/engine-components/Light.js +58 -50
  39. package/lib/engine-components/Light.js.map +1 -1
  40. package/lib/engine-components/Networking.d.ts +1 -1
  41. package/lib/engine-components/OrbitControls.js +4 -3
  42. package/lib/engine-components/OrbitControls.js.map +1 -1
  43. package/lib/engine-components/ParticleSystem.d.ts +2 -1
  44. package/lib/engine-components/ParticleSystem.js +11 -1
  45. package/lib/engine-components/ParticleSystem.js.map +1 -1
  46. package/lib/engine-components/ReflectionProbe.js +3 -3
  47. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  48. package/lib/engine-components/Renderer.d.ts +1 -1
  49. package/lib/engine-components/Renderer.js +16 -13
  50. package/lib/engine-components/Renderer.js.map +1 -1
  51. package/lib/engine-components/RendererLightmap.d.ts +5 -8
  52. package/lib/engine-components/RendererLightmap.js +50 -39
  53. package/lib/engine-components/RendererLightmap.js.map +1 -1
  54. package/lib/engine-components/codegen/components.d.ts +1 -0
  55. package/lib/engine-components/codegen/components.js +1 -0
  56. package/lib/engine-components/codegen/components.js.map +1 -1
  57. package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +1 -1
  58. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js +34 -30
  59. package/lib/engine-components/export/usdz/ThreeUSDZExporter.js.map +1 -1
  60. package/lib/engine-components/export/usdz/USDZExporter.js +2 -0
  61. package/lib/engine-components/export/usdz/USDZExporter.js.map +1 -1
  62. package/lib/engine-components/export/usdz/extensions/USDZText.d.ts +2 -1
  63. package/lib/engine-components/export/usdz/extensions/USDZText.js +40 -3
  64. package/lib/engine-components/export/usdz/extensions/USDZText.js.map +1 -1
  65. package/lib/engine-components/export/usdz/extensions/USDZUI.d.ts +8 -0
  66. package/lib/engine-components/export/usdz/extensions/USDZUI.js +101 -0
  67. package/lib/engine-components/export/usdz/extensions/USDZUI.js.map +1 -0
  68. package/lib/engine-components/ui/BaseUIComponent.js +4 -0
  69. package/lib/engine-components/ui/BaseUIComponent.js.map +1 -1
  70. package/lib/engine-components/ui/Button.d.ts +1 -1
  71. package/lib/engine-components/ui/Button.js +4 -1
  72. package/lib/engine-components/ui/Button.js.map +1 -1
  73. package/lib/engine-components/ui/Canvas.js +9 -1
  74. package/lib/engine-components/ui/Canvas.js.map +1 -1
  75. package/lib/engine-components/ui/EventSystem.js +2 -0
  76. package/lib/engine-components/ui/EventSystem.js.map +1 -1
  77. package/lib/engine-components/ui/Graphic.js +3 -3
  78. package/lib/engine-components/ui/Graphic.js.map +1 -1
  79. package/lib/engine-components/webxr/WebARCameraBackground.d.ts +1 -1
  80. package/lib/engine-components/webxr/WebARCameraBackground.js +2 -2
  81. package/lib/engine-components/webxr/WebARCameraBackground.js.map +1 -1
  82. package/lib/engine-components/webxr/WebXR.js +7 -6
  83. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  84. package/lib/engine-components/webxr/WebXRPlaneTracking.d.ts +1 -1
  85. package/package.json +5 -5
  86. package/src/engine/codegen/register_types.js +2 -0
  87. package/src/engine/engine_context.ts +21 -14
  88. package/src/engine/engine_element.ts +15 -8
  89. package/src/engine/engine_element_overlay.ts +41 -52
  90. package/src/engine/engine_lightdata.ts +6 -8
  91. package/src/engine/engine_networking_utils.ts +1 -1
  92. package/src/engine/engine_scenelighting.ts +5 -5
  93. package/src/engine/extensions/NEEDLE_lightmaps.ts +3 -3
  94. package/src/engine/extensions/NEEDLE_render_objects.ts +10 -8
  95. package/src/engine/extensions/NEEDLE_techniques_webgl.ts +5 -1
  96. package/src/engine/extensions/extensions.ts +19 -4
  97. package/src/engine-components/Camera.ts +3 -3
  98. package/src/engine-components/GroundProjection.ts +1 -1
  99. package/src/engine-components/Light.ts +62 -57
  100. package/src/engine-components/OrbitControls.ts +4 -3
  101. package/src/engine-components/ParticleSystem.ts +14 -0
  102. package/src/engine-components/ReflectionProbe.ts +3 -3
  103. package/src/engine-components/Renderer.ts +21 -17
  104. package/src/engine-components/RendererLightmap.ts +55 -49
  105. package/src/engine-components/codegen/components.ts +1 -0
  106. package/src/engine-components/export/usdz/ThreeUSDZExporter.ts +43 -37
  107. package/src/engine-components/export/usdz/USDZExporter.ts +2 -0
  108. package/src/engine-components/export/usdz/extensions/USDZText.ts +41 -1
  109. package/src/engine-components/export/usdz/extensions/USDZUI.ts +120 -0
  110. package/src/engine-components/ui/BaseUIComponent.ts +5 -0
  111. package/src/engine-components/ui/Button.ts +3 -1
  112. package/src/engine-components/ui/Canvas.ts +7 -1
  113. package/src/engine-components/ui/EventSystem.ts +3 -1
  114. package/src/engine-components/ui/Graphic.ts +3 -3
  115. package/src/engine-components/webxr/WebARCameraBackground.ts +3 -3
  116. package/src/engine-components/webxr/WebXR.ts +7 -7
@@ -1,5 +1,5 @@
1
1
  import { ILightDataRegistry } from "../engine_lightdata";
2
- import { FloatType, HalfFloatType, LinearEncoding, sRGBEncoding, Texture } from "three";
2
+ import { FloatType, HalfFloatType, LinearEncoding, LinearSRGBColorSpace, SRGBColorSpace, sRGBEncoding, Texture } from "three";
3
3
  import { GLTF, GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
4
4
  import { SourceIdentifier } from "../engine_types";
5
5
  import { resolveReferences } from "./extension_utils";
@@ -70,9 +70,9 @@ export class NEEDLE_lightmaps implements GLTFLoaderPlugin {
70
70
  else {
71
71
  // TODO this is most likely wrong for floating point textures
72
72
  if (entry.type !== LightmapType.Lightmap)
73
- tex.encoding = sRGBEncoding;
73
+ tex.colorSpace = SRGBColorSpace;
74
74
  else
75
- tex.encoding = LinearEncoding;
75
+ tex.colorSpace = LinearSRGBColorSpace;
76
76
 
77
77
 
78
78
  // Dont flip skybox textures anymore - previously we exported them flipped when baking in Unity but now we allow to pass through export without re-baking exisitng skybox textures if they use default values. So we expect textures to be NOT flipped anymore
@@ -22,6 +22,8 @@ import {
22
22
  IncrementWrapStencilOp,
23
23
  DecrementWrapStencilOp,
24
24
  InvertStencilOp,
25
+ StencilFunc,
26
+ StencilOp as ThreeStencilOp,
25
27
  } from "three";
26
28
  import { getParam, isDebugMode } from "../engine_utils";
27
29
  import { showBalloonWarning } from "../debug";
@@ -81,10 +83,10 @@ export class NEEDLE_render_objects implements GLTFLoaderPlugin {
81
83
  mat.stencilWriteMask = 255;
82
84
  mat.stencilFuncMask = 255;
83
85
  mat.stencilRef = stencil.value;
84
- mat.stencilFunc = stencil.compareFunc;
85
- mat.stencilZPass = stencil.passOp;
86
- mat.stencilFail = stencil.failOp;
87
- mat.stencilZFail = stencil.zFailOp;
86
+ mat.stencilFunc = stencil.compareFunc as StencilFunc;
87
+ mat.stencilZPass = stencil.passOp as ThreeStencilOp;
88
+ mat.stencilFail = stencil.failOp as ThreeStencilOp;
89
+ mat.stencilZFail = stencil.zFailOp as ThreeStencilOp;
88
90
  obj.sharedMaterials[i] = mat;
89
91
  }
90
92
  }
@@ -116,7 +118,7 @@ export class NEEDLE_render_objects implements GLTFLoaderPlugin {
116
118
  if (stencils && Array.isArray(stencils)) {
117
119
  for (const stencil of stencils) {
118
120
  const obj: StencilSettingsModel = { ...stencil };
119
- obj.compareFunc = ToThreeCompareFunction(obj.compareFunc);
121
+ obj.compareFunc = ToThreeCompareFunction(obj.compareFunc as number);
120
122
  obj.passOp = ToThreeStencilOp(obj.passOp);
121
123
  obj.failOp = ToThreeStencilOp(obj.failOp);
122
124
  obj.zFailOp = ToThreeStencilOp(obj.zFailOp);
@@ -161,7 +163,7 @@ enum CompareFunction {
161
163
  Always,
162
164
  }
163
165
 
164
- function ToThreeStencilOp(op: StencilOp): number {
166
+ function ToThreeStencilOp(op: StencilOp): ThreeStencilOp {
165
167
  switch (op) {
166
168
  case StencilOp.Keep:
167
169
  return KeepStencilOp;
@@ -183,7 +185,7 @@ function ToThreeStencilOp(op: StencilOp): number {
183
185
  return 0;
184
186
  }
185
187
 
186
- function ToThreeCompareFunction(func: CompareFunction): number {
188
+ function ToThreeCompareFunction(func: CompareFunction): StencilFunc {
187
189
  switch (func) {
188
190
  case CompareFunction.Never:
189
191
  return NeverStencilFunc;
@@ -202,7 +204,7 @@ function ToThreeCompareFunction(func: CompareFunction): number {
202
204
  case CompareFunction.Always:
203
205
  return AlwaysStencilFunc;
204
206
  }
205
- return 0;
207
+ return NeverStencilFunc;
206
208
  }
207
209
 
208
210
 
@@ -1,6 +1,6 @@
1
1
  import { GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader";
2
2
  import { FindShaderTechniques, whiteDefaultTexture, ToUnityMatrixArray, SetUnitySphericalHarmonics } from '../engine_shaders';
3
- import { AlwaysDepth, BackSide, Camera, DoubleSide, EqualDepth, FrontSide, GreaterDepth, GreaterEqualDepth, IUniform, LessDepth, LessEqualDepth, LinearEncoding, Material, Matrix4, NotEqualDepth, Object3D, RawShaderMaterial, Vector3, Vector4 } from 'three';
3
+ import { AlwaysDepth, BackSide, Camera, DoubleSide, EqualDepth, FrontSide, GLSL3, GreaterDepth, GreaterEqualDepth, IUniform, LessDepth, LessEqualDepth, LinearEncoding, Material, Matrix4, NotEqualDepth, Object3D, RawShaderMaterial, Vector3, Vector4 } from 'three';
4
4
  import { Context } from '../engine_setup';
5
5
  import { getParam } from "../engine_utils";
6
6
  import * as SHADERDATA from "../shaders/shaderData"
@@ -455,6 +455,10 @@ export class NEEDLE_techniques_webgl implements GLTFLoaderPlugin {
455
455
  // "USE_SHADOWMAP" : true
456
456
  // },
457
457
  });
458
+ material.glslVersion = GLSL3;
459
+ material.vertexShader = material.vertexShader.replace("#version 300 es", "");
460
+ material.fragmentShader = material.fragmentShader.replace("#version 300 es", "");
461
+
458
462
 
459
463
  const culling = uniforms["_Cull"]?.value;
460
464
  switch (culling) {
@@ -15,7 +15,17 @@ import { NEEDLE_render_objects } from "./NEEDLE_render_objects";
15
15
  import { NEEDLE_progressive } from "./NEEDLE_progressive";
16
16
  import { InternalUsageTrackerPlugin } from "./usage_tracker";
17
17
  import { isUsageTrackingEnabled } from "../engine_assetdatabase";
18
- import { GLTFLoaderPlugin } from "three/examples/jsm/loaders/GLTFLoader";
18
+ import { GLTFLoaderPlugin } from "three/examples/jsm/loaders/GLTFLoader.js";
19
+ // import { GLTFAnimationPointerExtension } from "three/examples/jsm/loaders/GLTFLoaderAnimationPointer";
20
+
21
+ // lazily import the GLTFAnimationPointerExtension in case it doesnt exist (e.g. using vanilla three)
22
+ let GLTFAnimationPointerExtension : any;
23
+ import("three/examples/jsm/loaders/GLTFLoaderAnimationPointer").then(mod => {
24
+ GLTFAnimationPointerExtension = mod.GLTFAnimationPointerExtension;
25
+ return GLTFAnimationPointerExtension;
26
+ }).catch(e => {
27
+ console.warn("Failed to import GLTFLoaderAnimationPointer. Please use @needle-tools/three for full KHR_animation support", e);
28
+ });
19
29
 
20
30
  const _addedCustomExtension = new Array<ConstructorConcrete<GLTFLoaderPlugin>>();
21
31
 
@@ -70,8 +80,13 @@ export function registerExtensions(loader: GLTFLoader, context: Context, sourceI
70
80
  for (const ext of _addedCustomExtension)
71
81
  loader.register(p => new ext(p));
72
82
 
73
- const setPointerResolverFunction = loader["setAnimationPointerResolver"];
74
- if (typeof setPointerResolverFunction === "function")
75
- setPointerResolverFunction.bind(loader)(new PointerResolver());
83
+ loader.register(p => {
84
+ if (GLTFAnimationPointerExtension) {
85
+ const ext = new GLTFAnimationPointerExtension(p);
86
+ const setPointerResolverFunction = ext.setAnimationPointerResolver;
87
+ setPointerResolverFunction.bind(ext)(new PointerResolver());
88
+ return ext;
89
+ }
90
+ });
76
91
 
77
92
  }
@@ -8,7 +8,7 @@ import { showBalloonMessage } from "../engine/debug/debug";
8
8
  import { getWorldPosition, Graphics } from "../engine/engine_three_utils";
9
9
  import { Gizmos } from "../engine/engine_gizmos";
10
10
 
11
- import { EquirectangularReflectionMapping, OrthographicCamera, PerspectiveCamera, Ray, sRGBEncoding, Vector3 } from "three";
11
+ import { EquirectangularReflectionMapping, OrthographicCamera, PerspectiveCamera, Ray, SRGBColorSpace, sRGBEncoding, Vector3 } from "three";
12
12
  import { OrbitControls } from "./OrbitControls";
13
13
  import { RenderTexture } from "../engine/engine_texture";
14
14
 
@@ -261,7 +261,7 @@ export class Camera extends Behaviour implements ICamera {
261
261
  else
262
262
  cam = this.gameObject.children[0] as THREE.PerspectiveCamera | THREE.OrthographicCamera | null;
263
263
  if (cam && cam.isCamera) {
264
- if (cam.type === "PerspectiveCamera") {
264
+ if (cam instanceof PerspectiveCamera) {
265
265
  if (this._fov)
266
266
  cam.fov = this._fov;
267
267
  cam.near = this._nearClipPlane;
@@ -391,7 +391,7 @@ class CameraSkybox {
391
391
  else if (this.context.scene.background !== this._skybox) {
392
392
  if (debug)
393
393
  console.log("Set skybox", this._camera, this._skybox);
394
- this._skybox.encoding = sRGBEncoding;
394
+ this._skybox.colorSpace = SRGBColorSpace;
395
395
  this._skybox.mapping = EquirectangularReflectionMapping;
396
396
  this.context.scene.background = this._skybox;
397
397
  }
@@ -1,5 +1,5 @@
1
1
  import { Behaviour, GameObject } from "./Component";
2
- import { GroundProjectedEnv as GroundProjection } from 'three/examples/jsm/objects/GroundProjectedEnv.js';
2
+ import { GroundProjectedSkybox as GroundProjection } from 'three/examples/jsm/objects/GroundProjectedSkybox.js';
3
3
  import { serializable } from "../engine/engine_serialization_decorator";
4
4
  import { Watch as Watch } from "../engine/engine_utils";
5
5
  import { Texture } from "three";
@@ -173,6 +173,7 @@ export class Light extends Behaviour implements ILight {
173
173
  }
174
174
  this.light.intensity = val * factor;
175
175
  }
176
+ if (debug) console.log("Set light intensity to " + this._intensity, val, this)
176
177
  }
177
178
  get intensity(): number { return this._intensity; }
178
179
  private _intensity: number = -1;
@@ -180,7 +181,7 @@ export class Light extends Behaviour implements ILight {
180
181
  @serializable()
181
182
  get shadowDistance(): number {
182
183
  const light = this.light;
183
- if (light) {
184
+ if (light?.shadow) {
184
185
  const cam = light.shadow.camera as OrthographicCamera;
185
186
  return cam.far;
186
187
  }
@@ -189,7 +190,7 @@ export class Light extends Behaviour implements ILight {
189
190
  set shadowDistance(val: number) {
190
191
  this._shadowDistance = val;
191
192
  const light = this.light;
192
- if (light) {
193
+ if (light?.shadow) {
193
194
  const cam = light.shadow.camera as OrthographicCamera;
194
195
  cam.far = val;
195
196
  cam.updateProjectionMatrix();
@@ -203,7 +204,7 @@ export class Light extends Behaviour implements ILight {
203
204
  @serializable()
204
205
  get shadowResolution(): number {
205
206
  const light = this.light;
206
- if (light) {
207
+ if (light?.shadow) {
207
208
  return light.shadow.mapSize.x;
208
209
  }
209
210
  return -1;
@@ -212,7 +213,7 @@ export class Light extends Behaviour implements ILight {
212
213
  if (val === this._shadowResolution) return;
213
214
  this._shadowResolution = val;
214
215
  const light = this.light;
215
- if (light) {
216
+ if (light?.shadow) {
216
217
  light.shadow.mapSize.set(val, val);
217
218
  light.shadow.needsUpdate = true;
218
219
  }
@@ -256,12 +257,13 @@ export class Light extends Behaviour implements ILight {
256
257
  }
257
258
 
258
259
  onEnable(): void {
259
- if(debug) console.log("ENABLE LIGHT", this.name);
260
+ if (debug) console.log("ENABLE LIGHT", this.name);
260
261
  this.createLight();
261
262
  if (this.isBaked) return;
262
263
  else if (this.light) {
263
264
  this.light.visible = true;
264
265
  this.light.intensity = this._intensity;
266
+ if (debug) console.log("Set light intensity to " + this.light.intensity, this.name)
265
267
  if (this.selfIsLight) {
266
268
  // nothing to do
267
269
  }
@@ -275,7 +277,7 @@ export class Light extends Behaviour implements ILight {
275
277
  }
276
278
 
277
279
  onDisable() {
278
- if(debug) console.log("DISABLE LIGHT", this.name);
280
+ if (debug) console.log("DISABLE LIGHT", this.name);
279
281
  if (this.light) {
280
282
  if (this.selfIsLight)
281
283
  this.light.intensity = 0;
@@ -376,61 +378,63 @@ export class Light extends Behaviour implements ILight {
376
378
  }
377
379
  else this.light.castShadow = false;
378
380
 
379
- // shadow intensity is currently not a thing: https://github.com/mrdoob/three.js/pull/14087
380
- if (this._shadowResolution !== undefined && this._shadowResolution > 4) {
381
- this.light.shadow.mapSize.width = this._shadowResolution;
382
- this.light.shadow.mapSize.height = this._shadowResolution;
383
- }
384
- else {
385
- this.light.shadow.mapSize.width = 2048;
386
- this.light.shadow.mapSize.height = 2048;
387
- }
388
- // this.light.shadow.needsUpdate = true;
389
- // console.log(this.light.shadow.mapSize);
390
- // return;
391
-
392
- if (debug)
393
- console.log("Override shadow bias?", this._overrideShadowBiasSettings, this.shadowBias, this.shadowNormalBias);
394
-
395
- this.light.shadow.bias = this.shadowBias;
396
- this.light.shadow.normalBias = this.shadowNormalBias;
397
-
398
- this.updateShadowSoftHard();
381
+ if (this.light.shadow) {
382
+ // shadow intensity is currently not a thing: https://github.com/mrdoob/three.js/pull/14087
383
+ if (this._shadowResolution !== undefined && this._shadowResolution > 4) {
384
+ this.light.shadow.mapSize.width = this._shadowResolution;
385
+ this.light.shadow.mapSize.height = this._shadowResolution;
386
+ }
387
+ else {
388
+ this.light.shadow.mapSize.width = 2048;
389
+ this.light.shadow.mapSize.height = 2048;
390
+ }
391
+ // this.light.shadow.needsUpdate = true;
392
+ // console.log(this.light.shadow.mapSize);
393
+ // return;
394
+
395
+ if (debug)
396
+ console.log("Override shadow bias?", this._overrideShadowBiasSettings, this.shadowBias, this.shadowNormalBias);
397
+
398
+ this.light.shadow.bias = this.shadowBias;
399
+ this.light.shadow.normalBias = this.shadowNormalBias;
400
+
401
+ this.updateShadowSoftHard();
402
+
403
+ const cam = this.light.shadow.camera as THREE.OrthographicCamera;
404
+ cam.near = this.shadowNearPlane;
405
+ // use shadow distance that was set explictly (if any)
406
+ if (this._shadowDistance !== undefined && typeof this._shadowDistance === "number")
407
+ cam.far = this._shadowDistance;
408
+ else // otherwise fallback to object scale and max distance
409
+ cam.far = shadowMaxDistance * Math.abs(this.gameObject.scale.z);
410
+
411
+ // width and height
412
+ this.gameObject.scale.set(1, 1, 1);
413
+ if (this.shadowWidth !== undefined) {
414
+ cam.left = -this.shadowWidth / 2;
415
+ cam.right = this.shadowWidth / 2;
416
+ }
417
+ else {
418
+ const sx = this.gameObject.scale.x;
419
+ cam.left *= sx;
420
+ cam.right *= sx;
421
+ }
422
+ if (this.shadowHeight !== undefined) {
423
+ cam.top = this.shadowHeight / 2;
424
+ cam.bottom = -this.shadowHeight / 2;
425
+ }
426
+ else {
427
+ const sy = this.gameObject.scale.y;
428
+ cam.top *= sy;
429
+ cam.bottom *= sy;
430
+ }
431
+ this.light.shadow.needsUpdate = true;
399
432
 
400
- const cam = this.light.shadow.camera as THREE.OrthographicCamera;
401
- cam.near = this.shadowNearPlane;
402
- // use shadow distance that was set explictly (if any)
403
- if (this._shadowDistance !== undefined && typeof this._shadowDistance === "number")
404
- cam.far = this._shadowDistance;
405
- else // otherwise fallback to object scale and max distance
406
- cam.far = shadowMaxDistance * Math.abs(this.gameObject.scale.z);
407
-
408
- // width and height
409
- this.gameObject.scale.set(1, 1, 1);
410
- if (this.shadowWidth !== undefined) {
411
- cam.left = -this.shadowWidth / 2;
412
- cam.right = this.shadowWidth / 2;
413
- }
414
- else {
415
- const sx = this.gameObject.scale.x;
416
- cam.left *= sx;
417
- cam.right *= sx;
418
- }
419
- if (this.shadowHeight !== undefined) {
420
- cam.top = this.shadowHeight / 2;
421
- cam.bottom = -this.shadowHeight / 2;
422
- }
423
- else {
424
- const sy = this.gameObject.scale.y;
425
- cam.top *= sy;
426
- cam.bottom *= sy;
433
+ if (debug)
434
+ this.context.scene.add(new THREE.CameraHelper(cam));
427
435
  }
428
436
 
429
437
 
430
- this.light.shadow.needsUpdate = true;
431
- if (debug)
432
- this.context.scene.add(new THREE.CameraHelper(cam));
433
-
434
438
 
435
439
  if (this.isBaked) {
436
440
  this.light.removeFromParent();
@@ -457,6 +461,7 @@ export class Light extends Behaviour implements ILight {
457
461
 
458
462
  private updateShadowSoftHard() {
459
463
  if (!this.light) return;
464
+ if (!this.light.shadow) return;
460
465
  if (this.shadows === LightShadows.Soft) {
461
466
  // const radius = this.light.shadow.mapSize.width / 1024 * 5;
462
467
  // const samples = Mathf.clamp(Math.round(radius), 2, 10);
@@ -272,10 +272,10 @@ export class OrbitControls extends Behaviour implements ICameraController {
272
272
  if (!freeCam && this.lookAtConstraint?.locked) this.setFromTargetPosition(0, this.lookAtConstraint01);
273
273
 
274
274
 
275
- if (this._controls && !this.context.isInXR) {
275
+ if (this._controls) {
276
276
  if (this.debugLog)
277
277
  this._controls.domElement = this.context.renderer.domElement;
278
- this._controls.enabled = !this._shouldDisable && this._camera === this.context.mainCameraComponent;
278
+ this._controls.enabled = !this._shouldDisable && this._camera === this.context.mainCameraComponent && !this.context.isInXR;
279
279
  this._controls.enableDamping = this.enableDamping;
280
280
  this._controls.keys = this.enableKeys ? defaultKeys : disabledKeys;
281
281
  this._controls.autoRotate = this.autoRotate;
@@ -283,7 +283,8 @@ export class OrbitControls extends Behaviour implements ICameraController {
283
283
  this._controls.enableZoom = this.enableZoom;
284
284
  this._controls.dampingFactor = this.dampingFactor;
285
285
  this._controls.enablePan = this.enablePan;
286
- this._controls.update();
286
+ if (!this.context.isInXR)
287
+ this._controls.update();
287
288
  }
288
289
  }
289
290
 
@@ -69,7 +69,21 @@ export class ParticleSystemRenderer extends Behaviour {
69
69
  return res;
70
70
  }
71
71
 
72
+ private static _havePatchedQuarkShaders = false;
73
+
72
74
  getMaterial(trailEnabled: boolean = false) {
75
+
76
+ if (!ParticleSystemRenderer._havePatchedQuarkShaders) {
77
+ ParticleSystemRenderer._havePatchedQuarkShaders = true;
78
+
79
+ // HACK patch three.quarks fo three152+, see https://github.com/Alchemist0823/three.quarks/issues/56#issuecomment-1560825038
80
+ const _rebuild = TrailBatch.prototype.rebuildMaterial;
81
+ TrailBatch.prototype.rebuildMaterial = function () {
82
+ _rebuild.call(this);
83
+ this.material.defines.MAP_UV = "uv";
84
+ }
85
+ }
86
+
73
87
  const material = (trailEnabled === true && this.trailMaterial) ? this.trailMaterial : this.particleMaterial;
74
88
 
75
89
  // progressive load on start
@@ -1,5 +1,5 @@
1
1
  import { Behaviour } from "./Component";
2
- import { Box3, Color, EquirectangularReflectionMapping, LinearEncoding, LineBasicMaterial, Material, MeshStandardMaterial, Object3D, SrcAlphaFactor, sRGBEncoding, Texture, Vector3, WebGLCubeRenderTarget, WebGLRenderTarget } from "three";
2
+ import { Box3, Color, EquirectangularReflectionMapping, LinearEncoding, LineBasicMaterial, Material, MeshStandardMaterial, Object3D, SrcAlphaFactor, SRGBColorSpace, sRGBEncoding, Texture, Vector3, WebGLCubeRenderTarget, WebGLRenderTarget } from "three";
3
3
  import { serializable } from "../engine/engine_serialization";
4
4
  import { Context } from "../engine/engine_setup";
5
5
  import { getWorldPosition, getWorldScale } from "../engine/engine_three_utils";
@@ -54,7 +54,7 @@ export class ReflectionProbe extends Behaviour {
54
54
  this._texture = tex;
55
55
  if (tex) {
56
56
  tex.mapping = EquirectangularReflectionMapping;
57
- tex.encoding = sRGBEncoding;
57
+ tex.colorSpace = SRGBColorSpace;
58
58
  tex.needsUpdate = true;
59
59
  }
60
60
  }
@@ -89,7 +89,7 @@ export class ReflectionProbe extends Behaviour {
89
89
 
90
90
  if (this.texture) {
91
91
  this.texture.mapping = EquirectangularReflectionMapping;
92
- this.texture.encoding = sRGBEncoding;
92
+ this.texture.colorSpace = SRGBColorSpace;
93
93
  this.texture.needsUpdate = true;
94
94
  }
95
95
  }
@@ -20,7 +20,6 @@ export { InstancingUtil } from "../engine/engine_instancing";
20
20
 
21
21
  const debugRenderer = getParam("debugrenderer");
22
22
  const suppressInstancing = getParam("noInstancing");
23
- const debugLightmap = getParam("debuglightmaps") ? true : false;
24
23
  const debugInstancing = getParam("debuginstancing");
25
24
  const debugProgressiveLoading = getParam("debugprogressive");
26
25
  const suppressProgressiveLoading = getParam("noprogressive");
@@ -353,7 +352,7 @@ export class Renderer extends Behaviour implements IRenderer {
353
352
 
354
353
  if (this.isMultiMaterialObject(this.gameObject)) {
355
354
  for (const child of this.gameObject.children) {
356
- this.context.addBeforeRenderListener(child, this.onBeforeRenderThree.bind(this));
355
+ this.context.addBeforeRenderListener(child, this.onBeforeRenderThree);
357
356
  child.layers.mask = this.gameObject.layers.mask;
358
357
  }
359
358
 
@@ -377,14 +376,13 @@ export class Renderer extends Behaviour implements IRenderer {
377
376
  }
378
377
  // TODO: custom shader with sub materials
379
378
  else if (this.isMeshOrSkinnedMesh(this.gameObject)) {
380
-
381
- this.context.addBeforeRenderListener(this.gameObject, this.onBeforeRenderThree.bind(this));
379
+ this.context.addBeforeRenderListener(this.gameObject, this.onBeforeRenderThree);
382
380
 
383
381
  if (this.renderOrder !== undefined && this.renderOrder.length > 0)
384
382
  this.gameObject.renderOrder = this.renderOrder[0];
385
383
  }
386
384
  else {
387
- this.context.addBeforeRenderListener(this.gameObject, this.onBeforeRenderThree.bind(this));
385
+ this.context.addBeforeRenderListener(this.gameObject, this.onBeforeRenderThree);
388
386
  }
389
387
 
390
388
  this.applyLightmapping();
@@ -416,11 +414,11 @@ export class Renderer extends Behaviour implements IRenderer {
416
414
  const mat = this.gameObject["material"];
417
415
  if (!mat?.isMeshBasicMaterial) {
418
416
  if (this._lightmaps.length <= 0) {
419
- const rm = new RendererLightmap(this.gameObject, this.context);
417
+ const rm = new RendererLightmap(this.gameObject as any as Mesh, this.context);
420
418
  this._lightmaps.push(rm);
421
419
  }
422
420
  const rm = this._lightmaps[0];
423
- rm.init(this.lightmapIndex, this.lightmapScaleOffset, tex, debugLightmap);
421
+ rm.init(this.lightmapIndex, this.lightmapScaleOffset, tex);
424
422
  }
425
423
  else {
426
424
  if (mat)
@@ -435,16 +433,12 @@ export class Renderer extends Behaviour implements IRenderer {
435
433
  if (!child["material"]?.isMeshBasicMaterial) {
436
434
  let rm: RendererLightmap | undefined = undefined;
437
435
  if (i >= this._lightmaps.length) {
438
- rm = new RendererLightmap(child as GameObject, this.context);
436
+ rm = new RendererLightmap(child as Mesh, this.context);
439
437
  this._lightmaps.push(rm);
440
438
  }
441
439
  else
442
440
  rm = this._lightmaps[i];
443
- rm.init(this.lightmapIndex, this.lightmapScaleOffset, tex, debugLightmap);
444
- // onBeforeRender is not called when the renderer is on a group
445
- // this is an issue we probably also need to handle for custom shaders
446
- // and need a better solution, but for now this fixes lightmaps for multimaterial objects
447
- rm.bindOnBeforeRender();
441
+ rm.init(this.lightmapIndex, this.lightmapScaleOffset, tex);
448
442
  }
449
443
  }
450
444
  }
@@ -530,7 +524,6 @@ export class Renderer extends Behaviour implements IRenderer {
530
524
  }
531
525
 
532
526
  this.updateReflectionProbe();
533
-
534
527
  }
535
528
 
536
529
  onDisable() {
@@ -543,13 +536,22 @@ export class Renderer extends Behaviour implements IRenderer {
543
536
 
544
537
  onDestroy(): void {
545
538
  this.handles = null;
539
+
540
+ if (this.isMultiMaterialObject(this.gameObject)) {
541
+ for (const child of this.gameObject.children) {
542
+ this.context.removeBeforeRenderListener(child, this.onBeforeRenderThree);
543
+ }
544
+ }
545
+ else {
546
+ this.context.removeBeforeRenderListener(this.gameObject, this.onBeforeRenderThree);
547
+ }
548
+
546
549
  }
547
550
 
548
551
  applyStencil() {
549
552
  NEEDLE_render_objects.applyStencil(this);
550
553
  }
551
554
 
552
-
553
555
  onBeforeRender() {
554
556
  if (!this.gameObject) {
555
557
  return;
@@ -612,7 +614,9 @@ export class Renderer extends Behaviour implements IRenderer {
612
614
  }
613
615
 
614
616
  }
615
- onBeforeRenderThree(_renderer, _scene, _camera, _geometry, material, _group) {
617
+
618
+
619
+ private onBeforeRenderThree = (_renderer, _scene, _camera, _geometry, material, _group) => {
616
620
 
617
621
  this.loadProgressiveTextures(material);
618
622
 
@@ -657,7 +661,7 @@ export class Renderer extends Behaviour implements IRenderer {
657
661
 
658
662
  if (this._lightmaps) {
659
663
  for (const lm of this._lightmaps) {
660
- lm.onBeforeRenderThree(material);
664
+ lm.updateLightmapUniforms(material);
661
665
  }
662
666
  }
663
667
  }