@needle-tools/engine 3.7.7-beta → 3.8.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 (76) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/needle-engine.js +472 -87019
  3. package/dist/needle-engine.light.js +472 -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/debug/debug.d.ts +1 -1
  9. package/lib/engine/engine_context.d.ts +3 -1
  10. package/lib/engine/engine_context.js +17 -12
  11. package/lib/engine/engine_context.js.map +1 -1
  12. package/lib/engine/engine_lightdata.js +6 -7
  13. package/lib/engine/engine_lightdata.js.map +1 -1
  14. package/lib/engine/engine_networking_utils.d.ts +1 -1
  15. package/lib/engine/engine_networking_utils.js.map +1 -1
  16. package/lib/engine/engine_scenelighting.js +5 -5
  17. package/lib/engine/engine_scenelighting.js.map +1 -1
  18. package/lib/engine/extensions/NEEDLE_lightmaps.js +3 -3
  19. package/lib/engine/extensions/NEEDLE_lightmaps.js.map +1 -1
  20. package/lib/engine/extensions/NEEDLE_render_objects.js +1 -1
  21. package/lib/engine/extensions/NEEDLE_render_objects.js.map +1 -1
  22. package/lib/engine/extensions/NEEDLE_techniques_webgl.js +4 -1
  23. package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
  24. package/lib/engine/extensions/extensions.js +17 -3
  25. package/lib/engine/extensions/extensions.js.map +1 -1
  26. package/lib/engine-components/Camera.js +3 -3
  27. package/lib/engine-components/Camera.js.map +1 -1
  28. package/lib/engine-components/GroundProjection.js +1 -1
  29. package/lib/engine-components/GroundProjection.js.map +1 -1
  30. package/lib/engine-components/Light.js +58 -50
  31. package/lib/engine-components/Light.js.map +1 -1
  32. package/lib/engine-components/Networking.d.ts +1 -1
  33. package/lib/engine-components/OrbitControls.js +4 -3
  34. package/lib/engine-components/OrbitControls.js.map +1 -1
  35. package/lib/engine-components/ParticleSystem.d.ts +2 -1
  36. package/lib/engine-components/ParticleSystem.js +11 -1
  37. package/lib/engine-components/ParticleSystem.js.map +1 -1
  38. package/lib/engine-components/ReflectionProbe.js +3 -3
  39. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  40. package/lib/engine-components/Renderer.js +2 -3
  41. package/lib/engine-components/Renderer.js.map +1 -1
  42. package/lib/engine-components/RendererLightmap.d.ts +2 -3
  43. package/lib/engine-components/RendererLightmap.js +16 -15
  44. package/lib/engine-components/RendererLightmap.js.map +1 -1
  45. package/lib/engine-components/export/usdz/ThreeUSDZExporter.d.ts +1 -1
  46. package/lib/engine-components/ui/BaseUIComponent.js +4 -0
  47. package/lib/engine-components/ui/BaseUIComponent.js.map +1 -1
  48. package/lib/engine-components/ui/Canvas.js +9 -1
  49. package/lib/engine-components/ui/Canvas.js.map +1 -1
  50. package/lib/engine-components/webxr/WebARCameraBackground.d.ts +1 -1
  51. package/lib/engine-components/webxr/WebARCameraBackground.js +2 -2
  52. package/lib/engine-components/webxr/WebARCameraBackground.js.map +1 -1
  53. package/lib/engine-components/webxr/WebXR.js +6 -5
  54. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  55. package/lib/engine-components/webxr/WebXRPlaneTracking.d.ts +1 -1
  56. package/package.json +5 -5
  57. package/src/engine/engine_context.ts +20 -13
  58. package/src/engine/engine_lightdata.ts +6 -8
  59. package/src/engine/engine_networking_utils.ts +1 -1
  60. package/src/engine/engine_scenelighting.ts +5 -5
  61. package/src/engine/extensions/NEEDLE_lightmaps.ts +3 -3
  62. package/src/engine/extensions/NEEDLE_render_objects.ts +10 -8
  63. package/src/engine/extensions/NEEDLE_techniques_webgl.ts +5 -1
  64. package/src/engine/extensions/extensions.ts +18 -3
  65. package/src/engine-components/Camera.ts +3 -3
  66. package/src/engine-components/GroundProjection.ts +1 -1
  67. package/src/engine-components/Light.ts +62 -57
  68. package/src/engine-components/OrbitControls.ts +4 -3
  69. package/src/engine-components/ParticleSystem.ts +14 -0
  70. package/src/engine-components/ReflectionProbe.ts +3 -3
  71. package/src/engine-components/Renderer.ts +2 -3
  72. package/src/engine-components/RendererLightmap.ts +21 -20
  73. package/src/engine-components/ui/BaseUIComponent.ts +5 -0
  74. package/src/engine-components/ui/Canvas.ts +7 -1
  75. package/src/engine-components/webxr/WebARCameraBackground.ts +3 -3
  76. package/src/engine-components/webxr/WebXR.ts +6 -6
@@ -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");
@@ -420,7 +419,7 @@ export class Renderer extends Behaviour implements IRenderer {
420
419
  this._lightmaps.push(rm);
421
420
  }
422
421
  const rm = this._lightmaps[0];
423
- rm.init(this.lightmapIndex, this.lightmapScaleOffset, tex, debugLightmap);
422
+ rm.init(this.lightmapIndex, this.lightmapScaleOffset, tex);
424
423
  }
425
424
  else {
426
425
  if (mat)
@@ -440,7 +439,7 @@ export class Renderer extends Behaviour implements IRenderer {
440
439
  }
441
440
  else
442
441
  rm = this._lightmaps[i];
443
- rm.init(this.lightmapIndex, this.lightmapScaleOffset, tex, debugLightmap);
442
+ rm.init(this.lightmapIndex, this.lightmapScaleOffset, tex);
444
443
  // onBeforeRender is not called when the renderer is on a group
445
444
  // this is an issue we probably also need to handle for custom shaders
446
445
  // and need a better solution, but for now this fixes lightmaps for multimaterial objects
@@ -1,7 +1,9 @@
1
1
  import { Behaviour, GameObject } from "./Component";
2
- import * as THREE from "three";
3
- import { Texture } from "three";
2
+ import { Material, Mesh, ShaderMaterial, Texture, Vector4 } from "three";
4
3
  import { Context, OnRenderCallback } from "../engine/engine_setup";
4
+ import { getParam } from "../engine/engine_utils";
5
+
6
+ const debug = getParam("debuglightmaps");
5
7
 
6
8
  // this component is automatically added by the Renderer if the object has lightmap uvs AND we have a lightmap
7
9
  // for multimaterial objects GLTF exports a "Group" with the renderer component
@@ -19,20 +21,20 @@ export class RendererLightmap {
19
21
  }
20
22
 
21
23
  lightmapIndex: number = -1;
22
- lightmapScaleOffset: THREE.Vector4 = new THREE.Vector4(1, 1, 0, 0);
24
+ lightmapScaleOffset: THREE.Vector4 = new Vector4(1, 1, 0, 0);
23
25
 
24
26
  private context: Context;
25
27
  private gameObject: GameObject;
26
- private lightmapTexture: THREE.Texture | null = null;
27
- private lightmapScaleOffsetUniform = { value: new THREE.Vector4(1, 1, 0, 0) };
28
- private lightmapUniform: { value: THREE.Texture | null } = { value: null };
28
+ private lightmapTexture: Texture | null = null;
29
+ private lightmapScaleOffsetUniform = { value: new Vector4(1, 1, 0, 0) };
30
+ private lightmapUniform: { value: Texture | null } = { value: null };
29
31
 
30
32
  constructor(gameObject: GameObject, context: Context) {
31
33
  this.gameObject = gameObject;
32
34
  this.context = context;
33
35
  }
34
36
 
35
- init(lightmapIndex: number, lightmapScaleOffset: THREE.Vector4, lightmapTexture: THREE.Texture, debug: boolean = false) {
37
+ init(lightmapIndex: number, lightmapScaleOffset: Vector4, lightmapTexture: Texture) {
36
38
  console.assert(this.gameObject !== undefined && this.gameObject !== null, "Missing gameobject", this);
37
39
 
38
40
  this.lightmapIndex = lightmapIndex;
@@ -40,8 +42,7 @@ export class RendererLightmap {
40
42
  this.lightmapScaleOffset = lightmapScaleOffset;
41
43
  this.lightmapTexture = lightmapTexture;
42
44
 
43
- const debugLightmaps = debug;
44
- if (debugLightmaps) this.setLightmapDebugMaterial();
45
+ if (debug) this.setLightmapDebugMaterial();
45
46
  this.applyLightmap();
46
47
  }
47
48
 
@@ -68,15 +69,16 @@ export class RendererLightmap {
68
69
 
69
70
  console.assert(this.gameObject.type === "Mesh", "Lightmap only works on meshes", this);
70
71
 
71
- const mesh = this.gameObject as unknown as THREE.Mesh;
72
+ const mesh = this.gameObject as unknown as Mesh;
72
73
  // TODO: ensure uv2 exists
73
- if (!mesh.geometry.getAttribute("uv2"))
74
- mesh.geometry.setAttribute("uv2", mesh.geometry.getAttribute("uv"));
74
+ if (!mesh.geometry.getAttribute("uv1"))
75
+ mesh.geometry.setAttribute("uv1", mesh.geometry.getAttribute("uv"));
75
76
 
76
- const mat = this.gameObject["material"].clone();
77
+ const mat: Material = this.gameObject["material"].clone();
77
78
  this.gameObject["material"] = mat;
78
79
 
79
80
  this.gameObject["material"].onBeforeCompile = (shader, _) => {
81
+ shader.lightMapUv = "uv1";
80
82
  shader.uniforms.lightmap = this.lightmapUniform;
81
83
  shader.uniforms.lightmapScaleOffset = this.lightmapScaleOffsetUniform;
82
84
  };
@@ -107,13 +109,12 @@ export class RendererLightmap {
107
109
  private setLightmapDebugMaterial() {
108
110
 
109
111
  // debug lightmaps
110
- this.gameObject["material"] = new THREE.ShaderMaterial({
112
+ this.gameObject["material"] = new ShaderMaterial({
111
113
  vertexShader: `
112
- attribute vec2 uv2;
113
- varying vec2 vUv2;
114
+ varying vec2 vUv1;
114
115
  void main()
115
116
  {
116
- vUv2 = uv2;
117
+ vUv1 = uv1;
117
118
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
118
119
  }
119
120
  `,
@@ -121,7 +122,7 @@ export class RendererLightmap {
121
122
  uniform sampler2D lightmap;
122
123
  uniform float lightMapIntensity;
123
124
  uniform vec4 lightmapScaleOffset;
124
- varying vec2 vUv2;
125
+ varying vec2 vUv1;
125
126
 
126
127
  // took from threejs 05fc79cd52b79e8c3e8dec1e7dca72c5c39983a4
127
128
  vec4 conv_sRGBToLinear( in vec4 value ) {
@@ -129,7 +130,7 @@ export class RendererLightmap {
129
130
  }
130
131
 
131
132
  void main() {
132
- vec2 lUv = vUv2.xy * lightmapScaleOffset.xy + vec2(lightmapScaleOffset.z, (1. - (lightmapScaleOffset.y + lightmapScaleOffset.w)));
133
+ vec2 lUv = vUv1.xy * lightmapScaleOffset.xy + vec2(lightmapScaleOffset.z, (1. - (lightmapScaleOffset.y + lightmapScaleOffset.w)));
133
134
 
134
135
  vec4 lightMapTexel = texture2D( lightmap, lUv);
135
136
  // The range of RGBM lightmaps goes from 0 to 34.49 (5^2.2) in linear space, and from 0 to 5 in gamma space.
@@ -138,7 +139,7 @@ export class RendererLightmap {
138
139
  //lightMapTexel = conv_sRGBToLinear(lightMapTexel);
139
140
  // lightMapTexel.rgb = vec3(1.);
140
141
 
141
- // gl_FragColor = vec4(vUv2.xy, 0, 1);
142
+ // gl_FragColor = vec4(vUv1.xy, 0, 1);
142
143
  gl_FragColor = lightMapTexel;
143
144
  }
144
145
  `,
@@ -6,8 +6,11 @@ import { showGizmos } from '../../engine/engine_default_parameters';
6
6
  import { AxesHelper, Object3D } from 'three';
7
7
  import { ICanvas, IGraphic } from './Interfaces';
8
8
  import { ShadowCastingMode } from '../Renderer';
9
+ import { getParam } from '../../engine/engine_utils';
9
10
  export const includesDir = "./include";
10
11
 
12
+ const debug = getParam("debugshadowcomponents");
13
+
11
14
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
12
15
 
13
16
 
@@ -128,6 +131,8 @@ export class BaseUIComponent extends Behaviour {
128
131
  // otherwise it will fail when object are enabled at runtime
129
132
  if (needsUpdate)
130
133
  ThreeMeshUI.update();
134
+
135
+ if(debug) console.log(this.shadowComponent)
131
136
  }
132
137
 
133
138
 
@@ -190,6 +190,7 @@ export class Canvas extends UIRootComponent implements ICanvas {
190
190
  }
191
191
 
192
192
  onBeforeRenderRoutine = () => {
193
+ if(this.context.isInVR) return;
193
194
  this.previousParent = this.gameObject.parent;
194
195
  // console.log(this.previousParent?.name + "/" + this.gameObject.name);
195
196
 
@@ -208,6 +209,7 @@ export class Canvas extends UIRootComponent implements ICanvas {
208
209
  }
209
210
 
210
211
  onAfterRenderRoutine = () => {
212
+ if(this.context.isInVR) return;
211
213
  if ((this.screenspace || this.renderOnTop) && this.previousParent && this.context.mainCamera) {
212
214
  if (this.screenspace) {
213
215
  const camObj = this.context.mainCamera;
@@ -215,7 +217,10 @@ export class Canvas extends UIRootComponent implements ICanvas {
215
217
  } else {
216
218
  this.previousParent.add(this.gameObject);
217
219
  }
220
+ const prevAutoClearDepth = this.context.renderer.autoClear;
221
+ const prevAutoClearColor = this.context.renderer.autoClearColor;
218
222
  this.context.renderer.autoClear = false;
223
+ this.context.renderer.autoClearColor = false;
219
224
  this.context.renderer.clearDepth();
220
225
  this.onUpdateRenderMode(true);
221
226
  this.handleLayoutUpdates();
@@ -223,7 +228,8 @@ export class Canvas extends UIRootComponent implements ICanvas {
223
228
  // this.handleLayoutUpdates();
224
229
  EventSystem.ensureUpdateMeshUI(ThreeMeshUI, this.context);
225
230
  this.context.renderer.render(this.gameObject, this.context.mainCamera);
226
- this.context.renderer.autoClear = true;
231
+ this.context.renderer.autoClear = prevAutoClearDepth;
232
+ this.context.renderer.autoClearColor = prevAutoClearColor;
227
233
  this.previousParent.add(this.gameObject);
228
234
  }
229
235
  this._lastMatrixWorld?.copy(this.gameObject.matrixWorld);
@@ -3,7 +3,6 @@ import { serializable } from "../../engine/engine_serialization_decorator";
3
3
  import { RGBAColor } from "../js-extensions/RGBAColor"
4
4
  import { WebXR } from "./WebXR";
5
5
  import {
6
- Camera as ThreeCamera,
7
6
  Scene,
8
7
  Texture,
9
8
  Mesh, MeshBasicMaterial,
@@ -11,7 +10,8 @@ import {
11
10
  PlaneGeometry,
12
11
  ShaderLib,
13
12
  ShaderMaterial,
14
- DoubleSide
13
+ DoubleSide,
14
+ PerspectiveCamera
15
15
  } from "three";
16
16
 
17
17
  export class WebARCameraBackground extends Behaviour {
@@ -53,7 +53,7 @@ export class WebARCameraBackground extends Behaviour {
53
53
  const geometry = new PlaneGeometry();
54
54
  const scene = new Scene();
55
55
  scene.add(new Mesh(geometry, material));
56
- const camera = new ThreeCamera();
56
+ const camera = new PerspectiveCamera();
57
57
 
58
58
  return function forceTextureInitialization(renderer, texture) {
59
59
  material.map = texture;
@@ -1,4 +1,4 @@
1
- import { ArrayCamera, Color, Euler, EventDispatcher, Group, Matrix4, Mesh, MeshBasicMaterial, Object3D, Quaternion, RingGeometry, Texture, Vector3 } from 'three';
1
+ import { ArrayCamera, Color, Euler, EventDispatcher, Group, Matrix4, Mesh, MeshBasicMaterial, Object3D, Quaternion, RingGeometry, Texture, Vector3, WebXRArrayCamera } from 'three';
2
2
  import { ARButton } from '../../include/three/ARButton.js';
3
3
  import { VRButton } from '../../include/three/VRButton.js';
4
4
 
@@ -393,7 +393,7 @@ export class WebXR extends Behaviour {
393
393
  private _originalXRRigRotation: Quaternion = new Quaternion();
394
394
 
395
395
  private onEnterXR(session: XRSession, frame: XRFrame) {
396
- console.log("[XR] session begin", session);
396
+ console.log("[XR] session begin", session, frame);
397
397
  WebXR._isInXr = true;
398
398
 
399
399
  this.ensureRig();
@@ -414,16 +414,16 @@ export class WebXR extends Behaviour {
414
414
  // we set layers to sync raycasting and have a similar behaviour to unity
415
415
  const xr = this.context.renderer.xr;
416
416
  if (this.context.mainCamera) {
417
- //@ts-ignore
418
- const cam = xr.getCamera(this.context.mainCamera) as ArrayCamera;
417
+ const cam = xr.getCamera() as WebXRArrayCamera;
418
+ if(debugWebXR) console.log("WebXRCamera", cam);
419
419
  const cull = this.context.mainCameraComponent?.cullingMask;
420
- if(cull !== undefined){
420
+ if(cam && cull !== undefined){
421
421
  for (const c of cam.cameras) {
422
422
  c.layers.mask = cull;
423
423
  }
424
424
  cam.layers.mask = cull;
425
425
  }
426
- else {
426
+ else if (cam) {
427
427
  for (const c of cam.cameras) {
428
428
  c.layers.enableAll();
429
429
  }