@needle-tools/engine 4.6.1 → 4.6.2-next.fb486b2
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.
- package/CHANGELOG.md +6 -0
- package/dist/generateMeshBVH.worker-BaNp_Xtp.js +25 -0
- package/dist/{gltf-progressive-Bm9eEfgu.min.js → gltf-progressive-Bl4okF1b.min.js} +1 -1
- package/dist/{gltf-progressive-GjIqwSG3.js → gltf-progressive-DSpdn0QT.js} +2 -2
- package/dist/{gltf-progressive-Dn6o99rH.umd.cjs → gltf-progressive-P8b8a0qY.umd.cjs} +1 -1
- package/dist/needle-engine.bundle-CJ4jhuta.min.js +1575 -0
- package/dist/{needle-engine.bundle-BVg46UWZ.js → needle-engine.bundle-CQzZighj.js} +9722 -9554
- package/dist/needle-engine.bundle-CdAK5p8o.umd.cjs +1575 -0
- package/dist/needle-engine.js +352 -351
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing-CRQa6Qxn.umd.cjs → postprocessing-CjW23fio.umd.cjs} +18 -18
- package/dist/{postprocessing-D6W1EyZ-.js → postprocessing-DYLNOL3W.js} +4 -3
- package/dist/{postprocessing-DF8AlRgW.min.js → postprocessing-xYQWCHFu.min.js} +26 -26
- package/dist/{three-DMrv-4ar.umd.cjs → three-B_hneGZr.umd.cjs} +4 -4
- package/dist/{three-Bz6X1mrw.js → three-DrqIzZTH.js} +4198 -4198
- package/dist/{three-Boa-jOq-.min.js → three-DuDKwKB8.min.js} +33 -33
- package/dist/{three-examples-GggCDHv0.js → three-examples-B50TT3Iu.js} +5 -5
- package/dist/{three-examples-DuVhxqft.min.js → three-examples-DaDLBuy6.min.js} +14 -14
- package/dist/{three-examples-C7ryg8vN.umd.cjs → three-examples-X3OadjXB.umd.cjs} +3 -3
- package/dist/{three-mesh-ui-CY6Izc7C.min.js → three-mesh-ui-B3p3gyUz.min.js} +1 -1
- package/dist/{three-mesh-ui-CwlN0FUC.umd.cjs → three-mesh-ui-CQiIQIlA.umd.cjs} +1 -1
- package/dist/{three-mesh-ui-CLNOfsWn.js → three-mesh-ui-CxuWt7m-.js} +1 -1
- package/dist/{vendor-zxXa3Dmr.min.js → vendor-BlSxe9JJ.min.js} +3 -3
- package/dist/{vendor-BSD1RQIh.js → vendor-BmYIgaS1.js} +3 -3
- package/dist/{vendor-DHr4aqIZ.umd.cjs → vendor-Cavtu3CP.umd.cjs} +3 -3
- package/lib/engine/engine_context.d.ts +4 -1
- package/lib/engine/engine_context.js +9 -2
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/engine_three_utils.d.ts +17 -14
- package/lib/engine/engine_three_utils.js +106 -53
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/engine_tonemapping.d.ts +4 -0
- package/lib/engine/engine_tonemapping.js +21 -18
- package/lib/engine/engine_tonemapping.js.map +1 -1
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/engine_utils_screenshot.d.ts +1 -1
- package/lib/engine/engine_utils_screenshot.js +11 -2
- package/lib/engine/engine_utils_screenshot.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.d.ts +4 -1
- package/lib/engine/webcomponents/needle-engine.extras.js +3 -3
- package/lib/engine/webcomponents/needle-engine.extras.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.js +11 -21
- package/lib/engine/webcomponents/needle-engine.js.map +1 -1
- package/lib/engine-components/CameraUtils.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js +3 -1
- package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/BloomEffect.d.ts +2 -2
- package/lib/engine-components/postprocessing/Effects/BloomEffect.js +2 -2
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +8 -0
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +27 -8
- package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js +1 -0
- package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +1 -0
- package/lib/engine-components/postprocessing/Effects/Sharpening.js +4 -0
- package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +2 -9
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js +23 -71
- package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +13 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js +52 -0
- package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js.map +1 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +18 -0
- package/lib/engine-components/postprocessing/PostProcessingEffect.js +22 -3
- package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -1
- package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +20 -4
- package/lib/engine-components/postprocessing/PostProcessingHandler.js +231 -116
- package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
- package/lib/engine-components/postprocessing/Volume.d.ts +2 -1
- package/lib/engine-components/postprocessing/Volume.js +51 -33
- package/lib/engine-components/postprocessing/Volume.js.map +1 -1
- package/lib/engine-components/postprocessing/index.d.ts +1 -0
- package/lib/engine-components/postprocessing/index.js +1 -0
- package/lib/engine-components/postprocessing/index.js.map +1 -1
- package/lib/engine-components/postprocessing/utils.d.ts +44 -0
- package/lib/engine-components/postprocessing/utils.js +82 -0
- package/lib/engine-components/postprocessing/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/engine/engine_context.ts +13 -4
- package/src/engine/engine_three_utils.ts +134 -58
- package/src/engine/engine_tonemapping.ts +23 -24
- package/src/engine/engine_utils.ts +2 -2
- package/src/engine/engine_utils_screenshot.ts +13 -3
- package/src/engine/webcomponents/needle-engine.extras.ts +3 -3
- package/src/engine/webcomponents/needle-engine.ts +14 -25
- package/src/engine-components/CameraUtils.ts +3 -3
- package/src/engine-components/postprocessing/Effects/Antialiasing.ts +3 -1
- package/src/engine-components/postprocessing/Effects/BloomEffect.ts +4 -4
- package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +24 -13
- package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -0
- package/src/engine-components/postprocessing/Effects/Sharpening.ts +5 -0
- package/src/engine-components/postprocessing/Effects/Tonemapping.ts +26 -80
- package/src/engine-components/postprocessing/Effects/Tonemapping.utils.ts +60 -0
- package/src/engine-components/postprocessing/PostProcessingEffect.ts +23 -3
- package/src/engine-components/postprocessing/PostProcessingHandler.ts +267 -122
- package/src/engine-components/postprocessing/Volume.ts +54 -38
- package/src/engine-components/postprocessing/index.ts +2 -1
- package/src/engine-components/postprocessing/utils.ts +103 -2
- package/dist/generateMeshBVH.worker-Cdfpaq5W.js +0 -25
- package/dist/needle-engine.bundle-AOXFIsYk.umd.cjs +0 -1563
- 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
|
|
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
|
|
435
|
-
private static perspectiveCam = new PerspectiveCamera();
|
|
436
|
-
private static
|
|
437
|
-
private static readonly
|
|
438
|
-
|
|
439
|
-
|
|
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 (!
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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 =
|
|
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
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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 {
|
|
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
|
|
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
|
-
//
|
|
209
|
-
|
|
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 {
|
|
14
|
-
if (!
|
|
15
|
-
|
|
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
|
|
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
|
|
525
|
-
|
|
526
|
-
|
|
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,
|
|
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 {
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
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.
|
|
51
|
+
* @default 0.7
|
|
52
52
|
*/
|
|
53
53
|
@serializable(VolumeParameter)
|
|
54
|
-
readonly scatter: VolumeParameter = new VolumeParameter(.
|
|
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,7 +91,7 @@ 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
96
|
}
|
|
97
97
|
|
|
@@ -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(
|
|
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) =>
|
|
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
|
-
|
|
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
|
}
|