@needle-tools/engine 4.6.0 → 4.6.1-next.20d54cd

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 (114) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/generateMeshBVH.worker-BaNp_Xtp.js +25 -0
  3. package/dist/{gltf-progressive-Bm9eEfgu.min.js → gltf-progressive-Bl4okF1b.min.js} +1 -1
  4. package/dist/{gltf-progressive-GjIqwSG3.js → gltf-progressive-DSpdn0QT.js} +2 -2
  5. package/dist/{gltf-progressive-Dn6o99rH.umd.cjs → gltf-progressive-P8b8a0qY.umd.cjs} +1 -1
  6. package/dist/needle-engine.bundle-BVrLqIyi.umd.cjs +1575 -0
  7. package/dist/{needle-engine.bundle-DsrPZ9gj.js → needle-engine.bundle-BonYthMO.js} +8850 -8678
  8. package/dist/needle-engine.bundle-CokaG-YG.min.js +1575 -0
  9. package/dist/needle-engine.js +352 -351
  10. package/dist/needle-engine.min.js +1 -1
  11. package/dist/needle-engine.umd.cjs +1 -1
  12. package/dist/{postprocessing-CRQa6Qxn.umd.cjs → postprocessing-CjW23fio.umd.cjs} +18 -18
  13. package/dist/{postprocessing-D6W1EyZ-.js → postprocessing-DYLNOL3W.js} +4 -3
  14. package/dist/{postprocessing-DF8AlRgW.min.js → postprocessing-xYQWCHFu.min.js} +26 -26
  15. package/dist/{three-DMrv-4ar.umd.cjs → three-B_hneGZr.umd.cjs} +4 -4
  16. package/dist/{three-Bz6X1mrw.js → three-DrqIzZTH.js} +4198 -4198
  17. package/dist/{three-Boa-jOq-.min.js → three-DuDKwKB8.min.js} +33 -33
  18. package/dist/{three-examples-GggCDHv0.js → three-examples-B50TT3Iu.js} +5 -5
  19. package/dist/{three-examples-DuVhxqft.min.js → three-examples-DaDLBuy6.min.js} +14 -14
  20. package/dist/{three-examples-C7ryg8vN.umd.cjs → three-examples-X3OadjXB.umd.cjs} +3 -3
  21. package/dist/{three-mesh-ui-CY6Izc7C.min.js → three-mesh-ui-B3p3gyUz.min.js} +1 -1
  22. package/dist/{three-mesh-ui-CwlN0FUC.umd.cjs → three-mesh-ui-CQiIQIlA.umd.cjs} +1 -1
  23. package/dist/{three-mesh-ui-CLNOfsWn.js → three-mesh-ui-CxuWt7m-.js} +1 -1
  24. package/dist/{vendor-zxXa3Dmr.min.js → vendor-BlSxe9JJ.min.js} +3 -3
  25. package/dist/{vendor-BSD1RQIh.js → vendor-BmYIgaS1.js} +3 -3
  26. package/dist/{vendor-DHr4aqIZ.umd.cjs → vendor-Cavtu3CP.umd.cjs} +3 -3
  27. package/lib/engine/engine_assetdatabase.js +3 -1
  28. package/lib/engine/engine_assetdatabase.js.map +1 -1
  29. package/lib/engine/engine_context.d.ts +6 -3
  30. package/lib/engine/engine_context.js +20 -12
  31. package/lib/engine/engine_context.js.map +1 -1
  32. package/lib/engine/engine_three_utils.d.ts +17 -14
  33. package/lib/engine/engine_three_utils.js +106 -53
  34. package/lib/engine/engine_three_utils.js.map +1 -1
  35. package/lib/engine/engine_tonemapping.d.ts +4 -0
  36. package/lib/engine/engine_tonemapping.js +21 -18
  37. package/lib/engine/engine_tonemapping.js.map +1 -1
  38. package/lib/engine/engine_utils.js.map +1 -1
  39. package/lib/engine/engine_utils_screenshot.d.ts +1 -1
  40. package/lib/engine/engine_utils_screenshot.js +11 -2
  41. package/lib/engine/engine_utils_screenshot.js.map +1 -1
  42. package/lib/engine/webcomponents/needle-engine.d.ts +4 -1
  43. package/lib/engine/webcomponents/needle-engine.extras.js +3 -3
  44. package/lib/engine/webcomponents/needle-engine.extras.js.map +1 -1
  45. package/lib/engine/webcomponents/needle-engine.js +11 -21
  46. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  47. package/lib/engine-components/CameraUtils.js.map +1 -1
  48. package/lib/engine-components/ReflectionProbe.d.ts +2 -1
  49. package/lib/engine-components/ReflectionProbe.js +4 -1
  50. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  51. package/lib/engine-components/Renderer.js +9 -5
  52. package/lib/engine-components/Renderer.js.map +1 -1
  53. package/lib/engine-components/postprocessing/Effects/Antialiasing.js +3 -1
  54. package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -1
  55. package/lib/engine-components/postprocessing/Effects/BloomEffect.d.ts +2 -2
  56. package/lib/engine-components/postprocessing/Effects/BloomEffect.js +5 -2
  57. package/lib/engine-components/postprocessing/Effects/BloomEffect.js.map +1 -1
  58. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +8 -0
  59. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +27 -8
  60. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -1
  61. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js +1 -0
  62. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js.map +1 -1
  63. package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +1 -0
  64. package/lib/engine-components/postprocessing/Effects/Sharpening.js +4 -0
  65. package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
  66. package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +2 -9
  67. package/lib/engine-components/postprocessing/Effects/Tonemapping.js +29 -73
  68. package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
  69. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +13 -0
  70. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js +52 -0
  71. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js.map +1 -0
  72. package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +18 -0
  73. package/lib/engine-components/postprocessing/PostProcessingEffect.js +22 -3
  74. package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -1
  75. package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +21 -4
  76. package/lib/engine-components/postprocessing/PostProcessingHandler.js +237 -125
  77. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  78. package/lib/engine-components/postprocessing/Volume.d.ts +2 -1
  79. package/lib/engine-components/postprocessing/Volume.js +51 -33
  80. package/lib/engine-components/postprocessing/Volume.js.map +1 -1
  81. package/lib/engine-components/postprocessing/index.d.ts +1 -0
  82. package/lib/engine-components/postprocessing/index.js +1 -0
  83. package/lib/engine-components/postprocessing/index.js.map +1 -1
  84. package/lib/engine-components/postprocessing/utils.d.ts +43 -0
  85. package/lib/engine-components/postprocessing/utils.js +82 -0
  86. package/lib/engine-components/postprocessing/utils.js.map +1 -1
  87. package/package.json +2 -2
  88. package/plugins/vite/dependency-watcher.js +8 -2
  89. package/src/engine/engine_assetdatabase.ts +3 -1
  90. package/src/engine/engine_context.ts +27 -15
  91. package/src/engine/engine_three_utils.ts +134 -58
  92. package/src/engine/engine_tonemapping.ts +23 -24
  93. package/src/engine/engine_utils.ts +2 -2
  94. package/src/engine/engine_utils_screenshot.ts +13 -3
  95. package/src/engine/webcomponents/needle-engine.extras.ts +3 -3
  96. package/src/engine/webcomponents/needle-engine.ts +14 -25
  97. package/src/engine-components/CameraUtils.ts +3 -3
  98. package/src/engine-components/ReflectionProbe.ts +5 -1
  99. package/src/engine-components/Renderer.ts +10 -7
  100. package/src/engine-components/postprocessing/Effects/Antialiasing.ts +3 -1
  101. package/src/engine-components/postprocessing/Effects/BloomEffect.ts +6 -4
  102. package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +24 -13
  103. package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -0
  104. package/src/engine-components/postprocessing/Effects/Sharpening.ts +5 -0
  105. package/src/engine-components/postprocessing/Effects/Tonemapping.ts +29 -81
  106. package/src/engine-components/postprocessing/Effects/Tonemapping.utils.ts +60 -0
  107. package/src/engine-components/postprocessing/PostProcessingEffect.ts +23 -3
  108. package/src/engine-components/postprocessing/PostProcessingHandler.ts +268 -132
  109. package/src/engine-components/postprocessing/Volume.ts +54 -38
  110. package/src/engine-components/postprocessing/index.ts +2 -1
  111. package/src/engine-components/postprocessing/utils.ts +102 -2
  112. package/dist/generateMeshBVH.worker-Cdfpaq5W.js +0 -25
  113. package/dist/needle-engine.bundle-BDO_N7gN.min.js +0 -1559
  114. package/dist/needle-engine.bundle-CoJqbtmp.umd.cjs +0 -1559
@@ -1,4 +1,4 @@
1
- import { AnimationAction, Box3, Box3Helper, Camera, Color, Euler, GridHelper, Layers, Material, Mesh, MeshStandardMaterial, Object3D, PerspectiveCamera, PlaneGeometry, Quaternion, Scene, ShadowMaterial, Texture, Uniform, Vector2Like, Vector3 } from "three";
1
+ import { AnimationAction, Box3, Box3Helper, Camera, Color, DepthTexture, Euler, GridHelper, Layers, Material, Mesh, MeshStandardMaterial, Object3D, OrthographicCamera, PerspectiveCamera, PlaneGeometry, Quaternion, Scene, ShadowMaterial, Texture, Uniform, Vector2Like, Vector3, WebGLRenderTarget } from "three";
2
2
  import { ShaderMaterial, WebGLRenderer } from "three";
3
3
  import { GroundedSkybox } from "three/examples/jsm/objects/GroundedSkybox.js";
4
4
 
@@ -95,7 +95,7 @@ export function lookAtObject(object: Object3D, target: Object3D, keepUpDirection
95
95
  * });
96
96
  * ```
97
97
  */
98
- export function lookAtScreenPoint(object: Object3D, target: Vector2Like, camera: Camera, factor : number = 1): Vector3 | null {
98
+ export function lookAtScreenPoint(object: Object3D, target: Vector2Like, camera: Camera, factor: number = 1): Vector3 | null {
99
99
 
100
100
  if (camera) {
101
101
  const pos = getTempVector(0, 0, 0);
@@ -426,42 +426,69 @@ export function isAnimationAction(obj: object) {
426
426
 
427
427
 
428
428
 
429
+ class BlitMaterial extends ShaderMaterial {
430
+ static vertex = `
431
+ varying vec2 vUv;
432
+ void main(){
433
+ vUv = uv;
434
+ gl_Position = vec4(position.xy, 0., 1.0);
435
+ }`;
436
+
437
+ constructor() {
438
+ super({
439
+ vertexShader: BlitMaterial.vertex,
440
+ uniforms: {
441
+ map: new Uniform(null),
442
+ flipY: new Uniform(true),
443
+ writeDepth: new Uniform(false),
444
+ depthTexture: new Uniform(null)
445
+ },
446
+ fragmentShader: `
447
+ uniform sampler2D map;
448
+ uniform bool flipY;
449
+ uniform bool writeDepth;
450
+ uniform sampler2D depthTexture;
451
+
452
+ varying vec2 vUv;
453
+
454
+ void main(){
455
+ vec2 uv = vUv;
456
+ if (flipY) uv.y = 1.0 - uv.y;
457
+ gl_FragColor = texture2D(map, uv);
458
+
459
+ if (writeDepth) {
460
+ float depth = texture2D(depthTexture, uv).r;
461
+ gl_FragDepth = depth;
462
+
463
+ // float linearDepth = (depth - 0.99) * 100.0; // Enhance near 1.0 values
464
+ // gl_FragColor = vec4(linearDepth, linearDepth, linearDepth, 1.0);
465
+ }
466
+ }`
467
+ });
468
+ }
469
+
470
+ reset() {
471
+ this.uniforms.map.value = null;
472
+ this.uniforms.flipY.value = true;
473
+ this.uniforms.writeDepth.value = false;
474
+ this.uniforms.depthTexture.value = null;
475
+ this.needsUpdate = true;
476
+ this.uniformsNeedUpdate = true;
477
+ }
478
+ }
479
+
429
480
  /**
430
481
  * Utility class to perform various graphics operations like copying textures to canvas
431
482
  */
432
483
  export class Graphics {
433
- private static planeGeometry = new PlaneGeometry(2, 2, 1, 1);
434
- private static renderer: WebGLRenderer | undefined = undefined;
435
- private static perspectiveCam = new PerspectiveCamera();
436
- private static scene = new Scene();
437
- private static readonly vertex = `
438
- varying vec2 vUv;
439
- void main(){
440
- vUv = uv;
441
- gl_Position = vec4(position.xy * 1.0,0.,.999999);
442
- }`;
443
- private static readonly fragment = `
444
- uniform sampler2D map;
445
- varying vec2 vUv;
446
- void main(){
447
- vec2 uv = vUv;
448
- uv.y = 1.0 - uv.y;
449
- gl_FragColor = texture2D( map, uv);
450
- // gl_FragColor = vec4(uv.xy, 0, 1);
451
- }`;
452
- private static blitMaterial: ShaderMaterial | undefined = undefined;
484
+ private static readonly planeGeometry = new PlaneGeometry(2, 2, 1, 1);
485
+ private static readonly renderer: WebGLRenderer = new WebGLRenderer({ antialias: false, alpha: true });
486
+ private static readonly perspectiveCam = new PerspectiveCamera();
487
+ private static readonly orthographicCam = new OrthographicCamera();
488
+ private static readonly scene = new Scene();
489
+ private static readonly blitMaterial: BlitMaterial = new BlitMaterial();
490
+ private static readonly mesh: Mesh = new Mesh(Graphics.planeGeometry, Graphics.blitMaterial);
453
491
 
454
- /**
455
- * Create a blit material for copying textures
456
- */
457
- static createBlitMaterial(fragment: string): ShaderMaterial {
458
- return new ShaderMaterial({
459
- uniforms: { map: new Uniform(null) },
460
- vertexShader: this.vertex,
461
- fragmentShader: fragment
462
- });
463
- }
464
- private static mesh: Mesh | undefined = undefined;
465
492
 
466
493
  /**
467
494
  * Copy a texture to a new texture
@@ -470,17 +497,16 @@ export class Graphics {
470
497
  * @returns the newly created, copied texture
471
498
  */
472
499
  static copyTexture(texture: Texture, blitMaterial?: ShaderMaterial): Texture {
500
+
473
501
  // ensure that a blit material exists
474
- if (!this.blitMaterial) {
475
- this.blitMaterial = new ShaderMaterial({
476
- uniforms: { map: new Uniform(null) },
477
- vertexShader: this.vertex,
478
- fragmentShader: this.fragment
479
- });
480
- }
502
+ if (!blitMaterial) {
503
+ blitMaterial = this.blitMaterial;
504
+ };
505
+ this.blitMaterial.reset();
481
506
 
482
507
  const material = blitMaterial || this.blitMaterial;
483
508
 
509
+ // TODO: reset the uniforms...
484
510
  material.uniforms.map.value = texture;
485
511
  material.needsUpdate = true;
486
512
  material.uniformsNeedUpdate = true;
@@ -488,17 +514,13 @@ export class Graphics {
488
514
 
489
515
  // ensure that the blit material has the correct vertex shader
490
516
  const origVertexShader = material.vertexShader;
491
- material.vertexShader = this.vertex;
517
+ material.vertexShader = BlitMaterial.vertex;
492
518
 
493
- if (!this.mesh)
494
- this.mesh = new Mesh(this.planeGeometry, this.blitMaterial);
495
519
  const mesh = this.mesh;
496
520
  mesh.material = material;
497
521
  mesh.frustumCulled = false;
498
522
  this.scene.children.length = 0;
499
523
  this.scene.add(mesh);
500
- if (!this.renderer)
501
- this.renderer = new WebGLRenderer({ antialias: false });
502
524
  this.renderer.setSize(texture.image.width, texture.image.height);
503
525
  this.renderer.clear();
504
526
  this.renderer.render(this.scene, this.perspectiveCam);
@@ -512,19 +534,73 @@ export class Graphics {
512
534
  return tex;
513
535
  }
514
536
 
515
- // static blit(src: Texture, target: Texture, blitMaterial?: ShaderMaterial) {
516
- // let material = blitMaterial ?? this.blipMaterial;
517
- // material.uniforms.map.value = src;
518
- // this.mesh.material = material;
519
- // this.mesh.frustumCulled = false;
520
- // this.mesh.matrix.identity();
521
- // this.scene.children.length = 0;
522
- // this.scene.add(this.mesh);
523
- // this.renderer.setSize(src.image.width, src.image.height);
524
- // this.renderer.clear();
525
- // this.renderer.render(this.scene, this.perspectiveCam);
526
- // return new Texture(this.renderer.domElement);
527
- // }
537
+ static blit(src: Texture, target: WebGLRenderTarget, options?: {
538
+ renderer?: WebGLRenderer,
539
+ blitMaterial?: ShaderMaterial,
540
+ flipY?: boolean,
541
+ depthTexture?: DepthTexture | null,
542
+ depthTest?: boolean,
543
+ depthWrite?: boolean,
544
+ }) {
545
+ const {
546
+ renderer = this.renderer,
547
+ blitMaterial = this.blitMaterial,
548
+ flipY = false,
549
+ depthTexture = null,
550
+ depthTest = true,
551
+ depthWrite = true,
552
+ } = options || {};
553
+
554
+ this.blitMaterial.reset();
555
+
556
+ if (blitMaterial.uniforms.map) blitMaterial.uniforms.map.value = src;
557
+ if (blitMaterial.uniforms.flipY) blitMaterial.uniforms.flipY.value = flipY;
558
+
559
+ if (depthTexture) {
560
+ blitMaterial.uniforms.writeDepth = new Uniform(true);
561
+ blitMaterial.uniforms.depthTexture.value = depthTexture;
562
+ }
563
+ else {
564
+ blitMaterial.uniforms.writeDepth = new Uniform(false);
565
+ blitMaterial.uniforms.depthTexture.value = null;
566
+ }
567
+ blitMaterial.needsUpdate = true;
568
+ blitMaterial.uniformsNeedUpdate = true;
569
+
570
+ const mesh = this.mesh;
571
+ mesh.material = blitMaterial;
572
+ mesh.frustumCulled = false;
573
+ this.scene.children.length = 0;
574
+ this.scene.add(mesh);
575
+
576
+ // Save state
577
+ const renderTarget = renderer.getRenderTarget();
578
+ const gl = renderer.getContext();
579
+ const depthTestEnabled = gl.getParameter(gl.DEPTH_TEST);
580
+ const depthWriteMask = gl.getParameter(gl.DEPTH_WRITEMASK);
581
+ const depthFunc = gl.getParameter(gl.DEPTH_FUNC);
582
+
583
+
584
+ // Set state
585
+ if (depthTest) renderer.getContext().enable(renderer.getContext().DEPTH_TEST);
586
+ else renderer.getContext().disable(renderer.getContext().DEPTH_TEST);
587
+ renderer.state.buffers.depth.setMask(depthWrite);
588
+
589
+ renderer.setClearColor(new Color(0, 0, 0), 0);
590
+ // renderer.setSize(target.width, target.height);
591
+ renderer.setPixelRatio(window.devicePixelRatio);
592
+ renderer.setRenderTarget(target);
593
+ renderer.clear();
594
+ renderer.render(this.scene, this.perspectiveCam);
595
+
596
+
597
+ // Restore state
598
+ renderer.setRenderTarget(renderTarget); // reset render target
599
+ const depthBuffer = renderer.state.buffers.depth;
600
+ depthBuffer.setTest(depthTestEnabled);
601
+ depthBuffer.setMask(depthWriteMask);
602
+ depthBuffer.setFunc(depthFunc);
603
+ }
528
604
 
529
605
  /**
530
606
  * Copy a texture to a HTMLCanvasElement
@@ -1,4 +1,4 @@
1
- import { ShaderChunk } from "three";
1
+ import { ACESFilmicToneMapping, AgXToneMapping, NeutralToneMapping, NoToneMapping, ShaderChunk, ToneMapping } from "three";
2
2
 
3
3
  import { isDevEnvironment } from "./debug/index.js";
4
4
  import type { Context } from "./engine_setup";
@@ -185,26 +185,25 @@ vec3 AgXToneMapping( vec3 color ) {
185
185
  }
186
186
 
187
187
 
188
-
189
-
190
-
191
-
192
-
193
-
194
- // function resetShaders(ctx: Context) {
195
- // const scene = ctx.scene;
196
- // const gl = ctx.renderer;
197
- // scene.traverse(object => {
198
- // if ((object as Mesh).isMesh) {
199
- // const mesh = object as Mesh;
200
- // if (Array.isArray(mesh.material)) {
201
- // mesh.material.forEach(mat => gl.properties.remove(mat));
202
- // }
203
- // else {
204
- // gl.properties.remove(mesh.material);
205
- // }
206
- // }
207
- // })
208
- // if (gl.info?.programs)
209
- // gl.info.programs.length = 0;
210
- // }
188
+ type TonemappingName = "none" | "neutral" | "aces" | "agx" | "khronos_neutral";
189
+
190
+ export function nameToThreeTonemapping(str: null | undefined | TonemappingName | ({} & string)): undefined | ToneMapping {
191
+ if (typeof str !== "string")
192
+ return undefined;
193
+ str = str.toLowerCase();
194
+ switch (str) {
195
+ case "none":
196
+ return NoToneMapping;
197
+ case "neutral":
198
+ return NeutralToneMapping;
199
+ case "aces":
200
+ return ACESFilmicToneMapping;
201
+ case "agx":
202
+ return AgXToneMapping;
203
+ case "khronos_neutral":
204
+ return NeutralToneMapping;
205
+ default:
206
+ console.warn("[PostProcessing] Unknown tone mapping mode", str);
207
+ return undefined;
208
+ }
209
+ }
@@ -7,7 +7,7 @@ import { needleLogoOnlySVG } from "./assets/index.js";
7
7
  import type { Context } from "./engine_context.js";
8
8
  import { ContextRegistry } from "./engine_context_registry.js";
9
9
  import { type SourceIdentifier } from "./engine_types.js";
10
- import type { NeedleEngineHTMLElement } from "./webcomponents/needle-engine.js";
10
+ import type { NeedleEngineWebComponent } from "./webcomponents/needle-engine.js";
11
11
 
12
12
  // https://schneidenbach.gitbooks.io/typescript-cookbook/content/nameof-operator.html
13
13
  /** @internal */
@@ -1008,7 +1008,7 @@ async function addOverlays(canvas: HTMLCanvasElement, args: { showLogo?: boolean
1008
1008
 
1009
1009
  // Draw the website's icon in the center of the QR code
1010
1010
  const faviconImage = new Image();
1011
- const element = document.querySelector("needle-engine") as NeedleEngineHTMLElement;
1011
+ const element = document.querySelector("needle-engine") as NeedleEngineWebComponent;
1012
1012
  const logoSrc = element?.getAttribute("loading-logo-src") || needleLogoOnlySVG;
1013
1013
  if (!logoSrc) return;
1014
1014
 
@@ -45,7 +45,7 @@ export declare type ScreenshotOptions = {
45
45
  /**
46
46
  * The context to take the screenshot from. If not provided, the current context will be used.
47
47
  */
48
- context?: Pick<Context, "scene" | "renderer" | "mainCamera" | "renderNow" | "updateAspect" | "updateSize" | "currentFrameEvent">,
48
+ context?: Pick<Context, "scene" | "renderer" | "mainCamera" | "renderNow" | "updateAspect" | "updateSize" | "currentFrameEvent" | "devicePixelRatio">,
49
49
  /**
50
50
  * The width of the screenshot - if not provided, the width of the current renderer will be used.
51
51
  */
@@ -205,11 +205,21 @@ export function screenshot2(opts: ScreenshotOptionsDataUrl | ScreenshotOptionsTe
205
205
  const renderWidth = width;
206
206
  const renderHeight = height;
207
207
 
208
- // apply page zoom
209
- const zoomLevel = window.devicePixelRatio || 1;
208
+ // Apply page zoom
209
+ let zoomLevel = (window.devicePixelRatio || 1);
210
+ let contextZoomLevel = 1;
211
+ // Apply context zoom level
212
+ if (context.devicePixelRatio === 'auto' || context.devicePixelRatio === 'manual')
213
+ contextZoomLevel = 1;
214
+ else
215
+ contextZoomLevel = context.devicePixelRatio / window.devicePixelRatio;
216
+ zoomLevel *= contextZoomLevel;
210
217
  width /= zoomLevel;
211
218
  height /= zoomLevel;
212
219
 
220
+ width = Math.floor(width);
221
+ height = Math.floor(height);
222
+
213
223
  // save XR state and reset it for screenshot
214
224
  const xrframe = renderer.xr.isPresenting && renderer.xr.getFrame();
215
225
  const previousXRState = renderer.xr.enabled;
@@ -10,7 +10,7 @@ DO NOT IMPORT ENGINE_ELEMENT FROM HERE
10
10
  * Use the addAttributeChangeCallback utility methods to register callback events
11
11
  */
12
12
  export async function registerObservableAttribute(name: string) {
13
- const { NeedleEngineHTMLElement } = await import("./needle-engine.js");
14
- if (!NeedleEngineHTMLElement.observedAttributes.includes(name))
15
- NeedleEngineHTMLElement.observedAttributes.push(name);
13
+ const { NeedleEngineWebComponent } = await import("./needle-engine.js");
14
+ if (!NeedleEngineWebComponent.observedAttributes.includes(name))
15
+ NeedleEngineWebComponent.observedAttributes.push(name);
16
16
  }
@@ -1,5 +1,3 @@
1
- import { AgXToneMapping, Color, LinearToneMapping, NeutralToneMapping, NoToneMapping } from "three";
2
-
3
1
  import { isDevEnvironment, showBalloonWarning } from "../debug/index.js";
4
2
  import { PUBLIC_KEY, VERSION } from "../engine_constants.js";
5
3
  import { registerLoader } from "../engine_gltf.js";
@@ -7,6 +5,7 @@ import { hasCommercialLicense } from "../engine_license.js";
7
5
  import { setDracoDecoderPath, setDracoDecoderType, setKtx2TranscoderPath } from "../engine_loaders.gltf.js";
8
6
  import { NeedleLoader } from "../engine_loaders.js";
9
7
  import { Context, ContextCreateArgs } from "../engine_setup.js";
8
+ import { nameToThreeTonemapping } from "../engine_tonemapping.js";
10
9
  import { type INeedleEngineComponent, type LoadedModel } from "../engine_types.js";
11
10
  import { getParam } from "../engine_utils.js";
12
11
  import { RGBAColor } from "../js-extensions/RGBAColor.js";
@@ -30,7 +29,7 @@ const desktopSessionActiveClassName = "desktop-session-active";
30
29
  const observedAttributes = [
31
30
  "public-key",
32
31
  "version",
33
-
32
+
34
33
  "hash",
35
34
  "src",
36
35
  "camera-controls",
@@ -60,7 +59,7 @@ const observedAttributes = [
60
59
  * @example
61
60
  * <needle-engine src="https://example.com/scene.glb" camera-controls="false"></needle-engine>
62
61
  */
63
- export class NeedleEngineHTMLElement extends HTMLElement implements INeedleEngineComponent {
62
+ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngineComponent {
64
63
 
65
64
  static get observedAttributes() {
66
65
  return observedAttributes
@@ -352,6 +351,12 @@ export class NeedleEngineHTMLElement extends HTMLElement implements INeedleEngin
352
351
  }
353
352
  }
354
353
 
354
+ /** The tonemapping setting configured as an attribute on the <needle-engine> component */
355
+ get toneMapping(): TonemappingAttributeOptions | null | undefined {
356
+ const attribute = (this.getAttribute("tonemapping") || this.getAttribute("tone-mapping")) as TonemappingAttributeOptions | null | undefined;
357
+ return attribute;
358
+ }
359
+
355
360
  private _loadId: number = 0;
356
361
  private _abortController: AbortController | null = null;
357
362
  private _lastSourceFiles: Array<string> | null = null;
@@ -521,26 +526,10 @@ export class NeedleEngineHTMLElement extends HTMLElement implements INeedleEngin
521
526
  private applyAttributes() {
522
527
  // set tonemapping if configured
523
528
  if (this._context?.renderer) {
524
- const attribute = this.getAttribute("tonemapping") || this.getAttribute("tone-mapping") as TonemappingAttributeOptions | null | undefined;
525
- switch (attribute?.toLowerCase()) {
526
- case "none":
527
- this._context.renderer.toneMapping = NoToneMapping;
528
- break;
529
- case "linear":
530
- this._context.renderer.toneMapping = LinearToneMapping;
531
- break;
532
- case "neutral":
533
- this._context.renderer.toneMapping = NeutralToneMapping;
534
- break;
535
- case "agx":
536
- this._context.renderer.toneMapping = AgXToneMapping;
537
- break;
538
- default:
539
- if (attribute !== null && attribute !== undefined) {
540
- console.warn("Invalid tone-mapping attribute: " + attribute);
541
- }
529
+ const threeTonemapping = nameToThreeTonemapping(this.toneMapping);
530
+ if (threeTonemapping !== undefined) {
531
+ this._context.renderer.toneMapping = threeTonemapping;
542
532
  }
543
-
544
533
  const exposure = this.getAttribute("tone-mapping-exposure");
545
534
  if (exposure !== null && exposure !== undefined) {
546
535
  const value = parseFloat(exposure);
@@ -561,7 +550,7 @@ export class NeedleEngineHTMLElement extends HTMLElement implements INeedleEngin
561
550
  if (this._context?.renderer) {
562
551
  if (typeof backgroundColor === "string" && backgroundColor.length > 0) {
563
552
  const rgbaColor = RGBAColor.fromColorRepresentation(backgroundColor);
564
- if(debug) console.debug("<needle-engine> background-color changed, str:", backgroundColor, "→", rgbaColor)
553
+ if (debug) console.debug("<needle-engine> background-color changed, str:", backgroundColor, "→", rgbaColor)
565
554
  this._context.renderer.setClearColor(rgbaColor, rgbaColor.alpha);
566
555
  this.context.scene.background = null;
567
556
  }
@@ -803,7 +792,7 @@ export class NeedleEngineHTMLElement extends HTMLElement implements INeedleEngin
803
792
  }
804
793
 
805
794
  if (typeof window !== "undefined" && !window.customElements.get(htmlTagName))
806
- window.customElements.define(htmlTagName, NeedleEngineHTMLElement);
795
+ window.customElements.define(htmlTagName, NeedleEngineWebComponent);
807
796
 
808
797
 
809
798
 
@@ -6,7 +6,7 @@ import { Context } from "../engine/engine_context.js";
6
6
  import { ContextEvent, ContextRegistry } from "../engine/engine_context_registry.js";
7
7
  import type { ICamera, IContext } from "../engine/engine_types.js";
8
8
  import { getParam } from "../engine/engine_utils.js";
9
- import { NeedleEngineHTMLElement } from "../engine/webcomponents/needle-engine.js";
9
+ import { NeedleEngineWebComponent } from "../engine/webcomponents/needle-engine.js";
10
10
  import { Camera, ClearFlags } from "./Camera.js";
11
11
  import { OrbitControls } from "./OrbitControls.js";
12
12
  import { EnvironmentScene } from "./utils/EnvironmentScene.js";
@@ -69,7 +69,7 @@ ContextRegistry.registerCallback(ContextEvent.MissingCamera, (evt) => {
69
69
  cameraObject.position.y = 1;
70
70
  cameraObject.position.z = 2;
71
71
 
72
- const engineElement = evt.context.domElement as NeedleEngineHTMLElement
72
+ const engineElement = evt.context.domElement as NeedleEngineWebComponent
73
73
  // If the camera is missing and the <needle-engine controls> is not set to false, create default camera controls
74
74
  // That way we still create controls if the attribute is not added to <needle-engine> at all
75
75
  if (engineElement?.cameraControls != false) {
@@ -92,7 +92,7 @@ ContextRegistry.registerCallback(ContextEvent.ContextCreated, (evt) => {
92
92
  }
93
93
 
94
94
  // check if <needle-engine camera-controls> attribute is present or enabled
95
- const engineElement = evt.context.domElement as NeedleEngineHTMLElement
95
+ const engineElement = evt.context.domElement as NeedleEngineWebComponent
96
96
  if (engineElement?.cameraControls == true) {
97
97
 
98
98
  // Check if something else already acts as a camera controller
@@ -22,6 +22,10 @@ export class ReflectionProbe extends Behaviour {
22
22
 
23
23
  private static _probes: Map<Context, ReflectionProbe[]> = new Map();
24
24
 
25
+ static isUsingReflectionProbe(material: Material) {
26
+ return !!(material[$reflectionProbeKey] || material[$originalMaterial]?.[$reflectionProbeKey]);
27
+ }
28
+
25
29
  public static get(object: Object3D | null | undefined, context: Context, isAnchor: boolean, anchor?: Object3D): ReflectionProbe | null {
26
30
  if (!object || object.isObject3D !== true) return null;
27
31
  if (disable) return null;
@@ -29,7 +33,7 @@ export class ReflectionProbe extends Behaviour {
29
33
  if (probes) {
30
34
  for (const probe of probes) {
31
35
  if (!probe.__didAwake) probe.__internalAwake();
32
- if (probe.enabled) {
36
+ if (probe.activeAndEnabled) {
33
37
  if (anchor) {
34
38
  // test if anchor is reflection probe object
35
39
  if (probe.gameObject === anchor) {
@@ -708,7 +708,15 @@ export class Renderer extends Behaviour implements IRenderer {
708
708
  if (this.reflectionProbeUsage !== ReflectionProbeUsage.Off && this._reflectionProbe) {
709
709
  this._reflectionProbe.onSet(this);
710
710
  }
711
-
711
+ // since three 163 we need to set the envMap to the scene envMap if it is not set
712
+ // otherwise the envmapIntensity has no effect: https://github.com/mrdoob/three.js/pull/27903
713
+ // internal issue: https://linear.app/needle/issue/NE-6363
714
+ for (const mat of this._sharedMaterials) {
715
+ // If the material has a envMap and is NOT using a reflection probe we set the envMap to the scene environment
716
+ if (mat && "envMap" in mat && "envMapIntensity" in mat && !ReflectionProbe.isUsingReflectionProbe(mat)) {
717
+ mat.envMap = this.context.scene.environment;
718
+ }
719
+ }
712
720
  }
713
721
 
714
722
  private onBeforeRenderThree = (_renderer, _scene, _camera, _geometry, material, _group) => {
@@ -716,11 +724,6 @@ export class Renderer extends Behaviour implements IRenderer {
716
724
  const factor = this.hasLightmap ? Math.PI : 1;
717
725
  const environmentIntensity = this.context.mainCameraComponent?.environmentIntensity ?? 1;
718
726
  material.envMapIntensity = Math.max(0, environmentIntensity * this.context.sceneLighting.environmentIntensity / factor);
719
-
720
- // since three 163 we need to set the envMap to the scene envMap if it is not set
721
- // otherwise the envmapIntensity has no effect: https://github.com/mrdoob/three.js/pull/27903
722
- // internal issue: https://linear.app/needle/issue/NE-6363
723
- if (!material.envMap) material.envMap = this.context.scene.environment;
724
727
  }
725
728
 
726
729
  if (this._lightmaps) {
@@ -856,7 +859,7 @@ export class SkinnedMeshRenderer extends MeshRenderer {
856
859
  mesh.computeBoundingSphere();
857
860
  mesh.geometry = geometry;
858
861
  }
859
- catch(err) {
862
+ catch (err) {
860
863
  console.error(`Error updating bounding sphere for ${mesh.name}`, err);
861
864
  }
862
865
  }
@@ -33,7 +33,9 @@ export class Antialiasing extends PostProcessingEffect {
33
33
  onCreateEffect(): EffectProviderResult {
34
34
  const effect = new MODULES.POSTPROCESSING.MODULE.SMAAEffect({
35
35
  preset: MODULES.POSTPROCESSING.MODULE.SMAAPreset.HIGH,
36
- edgeDetectionMode: MODULES.POSTPROCESSING.MODULE.EdgeDetectionMode.DEPTH
36
+ edgeDetectionMode: MODULES.POSTPROCESSING.MODULE.EdgeDetectionMode.LUMA,
37
+ // Keep predication mode disabled (default) since it looks better
38
+ // predicationMode: MODULES.POSTPROCESSING.MODULE.PredicationMode.DEPTH,
37
39
  });
38
40
 
39
41
  this.preset.onValueChanged = (newValue) => {
@@ -1,4 +1,4 @@
1
- import type { BloomEffect as _BloomEffect } from "postprocessing";
1
+ import { BloomEffect as _BloomEffect, EffectAttribute } from "postprocessing";
2
2
  import { MathUtils } from "three";
3
3
 
4
4
  import { MODULES } from "../../../engine/engine_modules.js";
@@ -48,10 +48,10 @@ export class BloomEffect extends PostProcessingEffect {
48
48
 
49
49
  /**
50
50
  * Scatter value. The higher the value, the more the bloom will scatter.
51
- * @default 0.3
51
+ * @default 0.7
52
52
  */
53
53
  @serializable(VolumeParameter)
54
- readonly scatter: VolumeParameter = new VolumeParameter(.3);
54
+ readonly scatter: VolumeParameter = new VolumeParameter(.7);
55
55
 
56
56
  /**
57
57
  * Set to true to use selective bloom when the effect gets created.
@@ -91,8 +91,10 @@ export class BloomEffect extends PostProcessingEffect {
91
91
  luminanceThreshold: this.threshold.value,
92
92
  luminanceSmoothing: this.scatter.value,
93
93
  radius: 0.85, // default value
94
- intensity: this.intensity.value,
94
+ intensity: this.intensity.value,
95
95
  });
96
+ // @ts-ignore Well... it's protected but bloom needs this :(
97
+ bloom.setAttributes(EffectAttribute.CONVOLUTION);
96
98
  }
97
99
 
98
100
  this.intensity.onValueChanged = newValue => {