@needle-tools/engine 4.6.1 → 4.6.2

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 (103) 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-D0XWaCQs.min.js +1575 -0
  7. package/dist/{needle-engine.bundle-BVg46UWZ.js → needle-engine.bundle-DGcStTA7.js} +9715 -9555
  8. package/dist/needle-engine.bundle-DmYMLdWP.umd.cjs +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_context.d.ts +4 -1
  28. package/lib/engine/engine_context.js +9 -2
  29. package/lib/engine/engine_context.js.map +1 -1
  30. package/lib/engine/engine_three_utils.d.ts +17 -14
  31. package/lib/engine/engine_three_utils.js +106 -53
  32. package/lib/engine/engine_three_utils.js.map +1 -1
  33. package/lib/engine/engine_tonemapping.d.ts +4 -0
  34. package/lib/engine/engine_tonemapping.js +21 -18
  35. package/lib/engine/engine_tonemapping.js.map +1 -1
  36. package/lib/engine/engine_utils.js.map +1 -1
  37. package/lib/engine/engine_utils_screenshot.d.ts +1 -1
  38. package/lib/engine/engine_utils_screenshot.js +11 -2
  39. package/lib/engine/engine_utils_screenshot.js.map +1 -1
  40. package/lib/engine/webcomponents/needle-engine.d.ts +4 -1
  41. package/lib/engine/webcomponents/needle-engine.extras.js +3 -3
  42. package/lib/engine/webcomponents/needle-engine.extras.js.map +1 -1
  43. package/lib/engine/webcomponents/needle-engine.js +11 -21
  44. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  45. package/lib/engine-components/CameraUtils.js.map +1 -1
  46. package/lib/engine-components/postprocessing/Effects/Antialiasing.js +3 -1
  47. package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -1
  48. package/lib/engine-components/postprocessing/Effects/BloomEffect.d.ts +2 -2
  49. package/lib/engine-components/postprocessing/Effects/BloomEffect.js +5 -2
  50. package/lib/engine-components/postprocessing/Effects/BloomEffect.js.map +1 -1
  51. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +8 -0
  52. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +27 -8
  53. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -1
  54. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js +1 -0
  55. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js.map +1 -1
  56. package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +1 -0
  57. package/lib/engine-components/postprocessing/Effects/Sharpening.js +4 -0
  58. package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
  59. package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +2 -9
  60. package/lib/engine-components/postprocessing/Effects/Tonemapping.js +23 -71
  61. package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
  62. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +13 -0
  63. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js +52 -0
  64. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js.map +1 -0
  65. package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +18 -0
  66. package/lib/engine-components/postprocessing/PostProcessingEffect.js +22 -3
  67. package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -1
  68. package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +20 -4
  69. package/lib/engine-components/postprocessing/PostProcessingHandler.js +209 -112
  70. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  71. package/lib/engine-components/postprocessing/Volume.d.ts +2 -1
  72. package/lib/engine-components/postprocessing/Volume.js +51 -33
  73. package/lib/engine-components/postprocessing/Volume.js.map +1 -1
  74. package/lib/engine-components/postprocessing/index.d.ts +1 -0
  75. package/lib/engine-components/postprocessing/index.js +1 -0
  76. package/lib/engine-components/postprocessing/index.js.map +1 -1
  77. package/lib/engine-components/postprocessing/utils.d.ts +43 -0
  78. package/lib/engine-components/postprocessing/utils.js +82 -0
  79. package/lib/engine-components/postprocessing/utils.js.map +1 -1
  80. package/package.json +1 -1
  81. package/src/engine/engine_context.ts +13 -4
  82. package/src/engine/engine_three_utils.ts +134 -58
  83. package/src/engine/engine_tonemapping.ts +23 -24
  84. package/src/engine/engine_utils.ts +2 -2
  85. package/src/engine/engine_utils_screenshot.ts +13 -3
  86. package/src/engine/webcomponents/needle-engine.extras.ts +3 -3
  87. package/src/engine/webcomponents/needle-engine.ts +14 -25
  88. package/src/engine-components/CameraUtils.ts +3 -3
  89. package/src/engine-components/postprocessing/Effects/Antialiasing.ts +3 -1
  90. package/src/engine-components/postprocessing/Effects/BloomEffect.ts +6 -4
  91. package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +24 -13
  92. package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -0
  93. package/src/engine-components/postprocessing/Effects/Sharpening.ts +5 -0
  94. package/src/engine-components/postprocessing/Effects/Tonemapping.ts +26 -80
  95. package/src/engine-components/postprocessing/Effects/Tonemapping.utils.ts +60 -0
  96. package/src/engine-components/postprocessing/PostProcessingEffect.ts +23 -3
  97. package/src/engine-components/postprocessing/PostProcessingHandler.ts +239 -119
  98. package/src/engine-components/postprocessing/Volume.ts +54 -38
  99. package/src/engine-components/postprocessing/index.ts +2 -1
  100. package/src/engine-components/postprocessing/utils.ts +102 -2
  101. package/dist/generateMeshBVH.worker-Cdfpaq5W.js +0 -25
  102. package/dist/needle-engine.bundle-AOXFIsYk.umd.cjs +0 -1563
  103. package/dist/needle-engine.bundle-Dt52m2jf.min.js +0 -1563
@@ -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
@@ -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 => {
@@ -17,9 +17,18 @@ export class ColorAdjustments extends PostProcessingEffect {
17
17
  return "ColorAdjustments";
18
18
  }
19
19
 
20
+ /**
21
+ * Whether values for contrast, hueshift or saturation are remapped to a different range.
22
+ */
23
+ remap = true;
24
+
20
25
  @serializable(VolumeParameter)
21
- readonly postExposure: VolumeParameter = new VolumeParameter(0);
26
+ readonly postExposure: VolumeParameter = new VolumeParameter(1);
22
27
 
28
+ /**
29
+ * Range -1 to 1, where 0 is the default value, -1 is the lowest contrast and 1 is the highest contrast.
30
+ * @default 0
31
+ */
23
32
  @serializable(VolumeParameter)
24
33
  readonly contrast: VolumeParameter = new VolumeParameter(0);
25
34
 
@@ -31,11 +40,12 @@ export class ColorAdjustments extends PostProcessingEffect {
31
40
 
32
41
  init() {
33
42
  this.postExposure!.valueProcessor = v => {
43
+ if(!this.remap) return v;
34
44
  v = Math.pow(2.0, v);
35
45
  return v;
36
46
  }
37
-
38
47
  this.contrast.valueProcessor = (v: number) => {
48
+ if(!this.remap) return v;
39
49
  let divisor = 1;
40
50
  if (v > 0) divisor = 200;
41
51
  else if (v < 0) divisor = 100;
@@ -45,10 +55,14 @@ export class ColorAdjustments extends PostProcessingEffect {
45
55
  };
46
56
  this.contrast.defaultValue = 0;
47
57
 
48
- this.hueShift.valueProcessor = (v: number) => Math.PI * v / 180;
58
+ this.hueShift.valueProcessor = (v: number) => {
59
+ if(!this.remap) return v;
60
+ return Math.PI * v / 180;
61
+ }
49
62
  this.hueShift.defaultValue = 0;
50
63
 
51
64
  this.saturation.valueProcessor = (v: number) => {
65
+ if(!this.remap) return v;
52
66
  if (v < 0) return (v / 100);
53
67
  const sat = (v / (100 * Math.PI));
54
68
  return sat;
@@ -60,36 +74,33 @@ export class ColorAdjustments extends PostProcessingEffect {
60
74
  const effects: EffectProviderResult = [];
61
75
 
62
76
  // TODO: do we still need this?
63
- if (this.context.renderer.toneMapping !== NoToneMapping && this.postExposure.overrideState)
64
- this.context.renderer.toneMapping = NoToneMapping;
65
-
66
-
77
+ // if (this.context.renderer.toneMapping !== NoToneMapping && this.postExposure.overrideState)
78
+ // this.context.renderer.toneMapping = NoToneMapping;
67
79
  // find the ToneMapping effect because we need it to apply post exposure
68
80
  let tonemappingEffect = this.postprocessingContext?.components.find(c => c instanceof ToneMappingEffect) as ToneMappingEffect;
69
81
  if (!tonemappingEffect) {
70
82
  tonemappingEffect = new ToneMappingEffect();
71
83
  this.postprocessingContext?.components.push(tonemappingEffect);
72
84
  }
73
-
74
85
  // We need this effect if someone uses ACES or AgX tonemapping;
75
86
  // problem is that we CAN'T use this effect for the "Linear" case, the package expects that in this case you remove the effect
76
87
  this.postExposure!.onValueChanged = (v) => {
77
- if (this.postExposure.overrideState) {
88
+ if (this.postExposure.overrideState && tonemappingEffect) {
78
89
  tonemappingEffect.exposure.value = v;
79
90
  }
91
+ else console.warn("[PostProcessing] PostExposure is set to override but no ToneMappingEffect found in the postprocessing stack. Please add a ToneMappingEffect to your postprocessing stack to use PostExposure.");
80
92
  };
81
93
 
82
94
  const brightnesscontrast = new MODULES.POSTPROCESSING.MODULE.BrightnessContrastEffect();
83
95
  this.contrast!.onValueChanged = v => brightnesscontrast.contrast = v;
84
96
 
85
97
  const hueSaturationEffect = new MODULES.POSTPROCESSING.MODULE.HueSaturationEffect();
86
-
87
- effects.push(brightnesscontrast);
88
- effects.push(hueSaturationEffect);
89
-
90
98
  this.hueShift!.onValueChanged = v => hueSaturationEffect.hue = v;
91
99
  this.saturation!.onValueChanged = v => hueSaturationEffect.saturation = v;
92
100
 
101
+
102
+ effects.push(brightnesscontrast);
103
+ effects.push(hueSaturationEffect);
93
104
  return effects;
94
105
  }
95
106
  }
@@ -124,6 +124,7 @@ export class ScreenSpaceAmbientOcclusionN8 extends PostProcessingEffect {
124
124
  cam,
125
125
  width, height
126
126
  ) as N8AOPostPass;
127
+ ssao.name = "SSAO N8";
127
128
 
128
129
  const mode = ScreenSpaceAmbientOcclusionN8QualityMode[this.quality];
129
130
  ssao.setQualityMode(mode);
@@ -1,8 +1,10 @@
1
+ import { EffectAttribute } from "postprocessing";
1
2
  import { Uniform } from "three";
2
3
 
3
4
  import { MODULES } from "../../../engine/engine_modules.js";
4
5
  import { serializable } from "../../../engine/engine_serialization.js";
5
6
  import { PostProcessingEffect } from "../PostProcessingEffect.js";
7
+ import { PostProcessingEffectOrder } from "../utils.js";
6
8
  // import type { createSharpeningEffectType } from "./Sharpening.effect";
7
9
 
8
10
  // let __SHARPENING_MODULE: typeof import("./Sharpening.effect");
@@ -21,6 +23,8 @@ export class SharpeningEffect extends PostProcessingEffect {
21
23
  return "Sharpening";
22
24
  }
23
25
 
26
+ order: number | undefined = PostProcessingEffectOrder.Sharpening;
27
+
24
28
  private _effect?: any;
25
29
 
26
30
  onCreateEffect() {
@@ -130,6 +134,7 @@ function createSharpeningEffectType() {
130
134
  ["radius", new Uniform(1)],
131
135
  // ["threshold", new Uniform(0)],
132
136
  ]),
137
+ attributes: EffectAttribute.CONVOLUTION
133
138
  });
134
139
  }
135
140
  }