@hology/core 0.0.161 → 0.0.163
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/dist/effects/vfx/behaviours.d.ts +11 -0
- package/dist/effects/vfx/behaviours.js +1 -1
- package/dist/effects/vfx/vfx-defs.d.ts +9 -0
- package/dist/effects/vfx/vfx-defs.js +1 -1
- package/dist/rendering/outline-effect.js +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/materializer.js +1 -1
- package/dist/shader/builtin/decal-unlit-shader.d.ts +1 -0
- package/dist/shader/builtin/decal-unlit-shader.js +1 -1
- package/dist/shader/builtin/unlit-shader.js +1 -1
- package/dist/shader-nodes/effects.js +1 -1
- package/package.json +3 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Vector3 } from "three";
|
|
1
2
|
import { Behaviour, Emitter, Particle } from "@hology/nebula";
|
|
2
3
|
import * as THREE from 'three';
|
|
3
4
|
export type EasingFunction = (x: number) => number;
|
|
@@ -41,6 +42,16 @@ export declare class Scale extends Behaviour {
|
|
|
41
42
|
initialize(particle: Particle): void;
|
|
42
43
|
mutate(target: Particle | Emitter, time: number, index: number): void;
|
|
43
44
|
}
|
|
45
|
+
export declare class ScaleComponents extends Behaviour {
|
|
46
|
+
private scaleA;
|
|
47
|
+
private scaleB;
|
|
48
|
+
constructor(scaleA: Vector3, scaleB: Vector3, easing: EasingFunction);
|
|
49
|
+
/**
|
|
50
|
+
* Set the behaviour's initial properties on the particle.
|
|
51
|
+
*/
|
|
52
|
+
initialize(particle: Particle): void;
|
|
53
|
+
mutate(target: Particle | Emitter, time: number, index: number): void;
|
|
54
|
+
}
|
|
44
55
|
export declare class LinearDamping extends Behaviour {
|
|
45
56
|
private factor;
|
|
46
57
|
constructor(factor: number);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Vector3 as
|
|
1
|
+
import{Vector3 as t}from"three";import{Behaviour as i,Vector3D as s,ease as e,MathUtils as o}from"@hology/nebula";import*as n from"three";export class RotatePosition extends i{constructor(t,i){super(),this.axis=t,this.angle=i,this.axis3D=new s(this.axis.x,this.axis.y,this.axis.z)}mutate(t,i,s){this.energize(t,i),null!=t.old&&0!=t.old.position.lengthSq()&&(a.copy(t.old.position),a.sub(t.parent.position),a.applyAxisAngle(this.axis3D,this.angle*i),a.add(t.parent.position),a.sub(t.old.position).divideScalar(i),t.velocity.sub(a)),a.copy(t.position),a.sub(t.parent.position),a.applyAxisAngle(this.axis3D,this.angle*i),a.add(t.parent.position),a.sub(t.position).divideScalar(i),t.velocity.add(a)}}const a=new t;export var AxisDirection;!function(t){t[t.x=0]="x",t[t.y=1]="y",t[t.z=2]="z",t[t.mx=3]="mx",t[t.my=4]="my",t[t.mz=5]="mz"}(AxisDirection||(AxisDirection={}));export class OrientAlongVelocity extends i{constructor(t){super(),this.axisDirection=t}initialize(t){t.transform.orientAlongVelocity=!0}mutate(t,i,s){t.target,n.Object3D}}export class FollowParent extends i{constructor(t){super(),this.speed=t}initialize(t){}mutate(t,i,s){const e=t.parent.parentParticle??t.parent;if(0===this.speed)return t.position.copy(e.old.position),t.acceleration.copy(e.acceleration),void t.velocity.copy(e.velocity);const o=r.copy(e.position).sub(t.position),n=(o.length(),o.normalize());l.copy(n).multiplyScalar(this.speed),t.velocity.copy(l)}}export class Scale extends i{constructor(t,i,s){super(void 0,s),this.scaleA=t,this.scaleB=i}initialize(t){t.transform.scaleA=t.scale*this.scaleA,t.transform.scaleB=t.scale*this.scaleB,t.transform.oldRadius=t.radius}mutate(t,i,s){this.energize(t,i),t.scale=o.lerp(t.transform.scaleA,t.transform.scaleB,this.energy),t.scale<5e-4&&(t.scale=0),t.radius=t.transform.oldRadius*t.scale}}export class ScaleComponents extends i{constructor(t,i,s){super(void 0,s),this.scaleA=t,this.scaleB=i}initialize(i){let s=i.transform.initialScale;s?(s=s.clone(),i.transform.initialScale=s):(s=new t(1,1,1),i.transform.initialScale=s),i.transform.scaleComponentsA=s.clone().multiply(this.scaleA),i.transform.scaleComponentsB=s.clone().multiply(this.scaleB)}mutate(t,i,s){this.energize(t,i);const e=t.transform.scaleComponentsA,o=t.transform.scaleComponentsB;t.transform.initialScale.lerpVectors(o,e,this.energy)}}export class LinearDamping extends i{constructor(t){super(),this.factor=t}mutate(t,i,s){this.energize(t,i);const e=r.copy(t.velocity).multiplyScalar(-this.factor*i);t.velocity.add(e)}}const r=new s,l=new s;export var AxisPlane;!function(t){t[t.xy=0]="xy",t[t.xz=1]="xz",t[t.yz=2]="yz",t[t.xyz=3]="xyz"}(AxisPlane||(AxisPlane={}));export class Disperse extends i{constructor(t,i,s=e.easeLinear){super(void 0,s,void 0,!0),this.distance=t,this.plane=i}initialize(t){t.transform.initialPos=t.position.clone();const i=c.copy(t.transform.initialPos).sub(t.parent.position).normalize();switch(this.plane){case AxisPlane.xy:i.setComponent(2,0);break;case AxisPlane.xz:i.setComponent(1,0);break;case AxisPlane.yz:i.setComponent(0,0)}t.transform.displacement=i.clone().multiplyScalar(this.distance),t.transform.prevEnergy=1}mutate(t,i,s){this.energize(t,i);t.transform.initialPos;const e=t.transform.displacement,o=t.transform.prevEnergy-this.energy;t.transform.prevEnergy=this.energy;t.position.x+=e.x*o,t.position.y+=e.y*o,t.position.z+=e.z*o}}export class MoveOverLife extends i{constructor(t,i,s,o=e.easeLinear){super(void 0,o,void 0,!0),this.x=t,this.y=i,this.z=s}initialize(t){t.transform.initialPos=t.position.clone()}mutate(t,i,s){this.energize(t,i);const e=t.transform.initialPos,o=1-this.energy;t.position.x=e.x+this.x*o,t.position.y=e.y+this.y*o,t.position.z=e.z+this.z*o}}const c=new s;/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -182,6 +182,14 @@ declare class ScaleDef extends BaseBevDef<ScaleDef> {
|
|
|
182
182
|
};
|
|
183
183
|
make(params?: ParamsType<this>): Behaviour;
|
|
184
184
|
}
|
|
185
|
+
declare class ScaleComponentsDef extends BaseBevDef<ScaleComponentsDef> {
|
|
186
|
+
parameters: {
|
|
187
|
+
a: ShapeParameterDef<Vector3>;
|
|
188
|
+
b: ShapeParameterDef<Vector3>;
|
|
189
|
+
ease: ShapeParameterDef<Curve2>;
|
|
190
|
+
};
|
|
191
|
+
make(params?: ParamsType<this>): Behaviour;
|
|
192
|
+
}
|
|
185
193
|
declare class RandomDriftDef extends BaseBevDef<RandomDriftDef> {
|
|
186
194
|
parameters: {
|
|
187
195
|
drift: ShapeParameterDef<Vector3>;
|
|
@@ -297,6 +305,7 @@ declare const vfxBehaviours: {
|
|
|
297
305
|
repulsion: RepulsionDef;
|
|
298
306
|
attraction: AttractionDef;
|
|
299
307
|
scale: ScaleDef;
|
|
308
|
+
scaleComponents: ScaleComponentsDef;
|
|
300
309
|
randomDrift: RandomDriftDef;
|
|
301
310
|
rotate: RotateDef;
|
|
302
311
|
rotateAdd: RotateAddDef;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{MathUtils as e,Vector2 as r,Vector3 as t}from"three";import{Alpha as s,Attraction as n,BoxZone as a,CircleZone as o,Color as i,ease as c,Force as u,Gravity as d,Life as m,LineZone as p,Mass as l,Position as w,RadialVelocity as x,RandomDrift as f,Repulsion as h,Rotate as y,Vector3D as g}from"@hology/nebula";import{AxisDirection as k,AxisPlane as
|
|
1
|
+
import{MathUtils as e,Vector2 as r,Vector3 as t}from"three";import{Alpha as s,Attraction as n,BoxZone as a,CircleZone as o,Color as i,ease as c,Force as u,Gravity as d,Life as m,LineZone as p,Mass as l,Position as w,RadialVelocity as x,RandomDrift as f,Repulsion as h,Rotate as y,Vector3D as g}from"@hology/nebula";import{AxisDirection as k,AxisPlane as b,Disperse as v,FollowParent as z,LinearDamping as R,MoveOverLife as T,OrientAlongVelocity as L,RotatePosition as V,Scale as j,ScaleComponents as D}from"./behaviours.js";import{AdditiveVelocity as C,InitialScale as B,InitialScaleComponents as I,RandomDirection as O,RandomRotation as A,randomRotationAxis as K,RandomScale as P,Rotation as S}from"./initializsers.js";import{PointZone as Y,SphereZone as M}from"./zones.js";import{WorldCollisionBehaviour as X}from"./vfx-collision-behaviour.js";import{Curve2 as Z}from"../../utils/curve.js";class q{build(e={}){const r=Q(e,this.parameters);return this.make(r)}}class E{build(e={}){const r=Q(e,this.parameters);return this.make(r)}}function F(e,r,t){return{type:"number",default:e,float:!0,min:r,max:t}}function G(e){return{type:"vec3",default:(new t).fromArray(e)}}function H(e){return{type:"color",default:e}}function J(e,r){return{type:"select",opts:e,default:r}}function N(){return{type:"curve",default:Z.linear()}}function Q(e,r){const t={};for(let s in r)null==e[s]?t[s]=r[s].default:t[s]=e[s];return t}function U(e){return r=>e.getY(r)}const W={lifetime:new class extends E{constructor(){super(...arguments),this.parameters={duration:F(1,0,1e5)}}make(e={}){return new m(e.duration)}},randomLifetime:new class extends E{constructor(){super(...arguments),this.parameters={minDuration:F(1,0,1e5),maxDuration:F(2,0,1e5)}}make(e={}){return new m(e.minDuration,e.maxDuration)}},positionPoint:new class extends E{constructor(){super(...arguments),this.parameters={position:G([0,0,0])}}make(e={}){const{x:r,y:t,z:s}=e.position;return new w(new Y(r,t,s))}},positionBox:new class extends E{constructor(){super(...arguments),this.parameters={position:G([0,0,0]),dimensions:G([0,0,0])}}make(e={}){const{x:r,y:t,z:s}=e.position,{x:n,y:o,z:i}=e.dimensions;return new w(new a(r,t,s,n,o,i))}},positionSphere:new class extends E{constructor(){super(...arguments),this.parameters={position:G([0,0,0]),radius:F(1)}}make(e={}){const{x:r,y:t,z:s}=e.position;return new w(new M(r,t,s,e.radius))}},positionLine:new class extends E{constructor(){super(...arguments),this.parameters={a:G([0,0,0]),b:G([0,0,1])}}make(e={}){const{x:r,y:t,z:s}=e.a,{x:n,y:a,z:o}=e.b;return new w(new p(r,t,s,n,a,o))}},positionCircle:new class extends E{constructor(){super(...arguments),this.parameters={position:G([0,0,0]),rotation:G([0,0,0]),radius:F(1,0,1e4)}}make(r={}){const{x:t,y:s,z:n}=r.position,{x:a,y:i,z:c}=r.rotation;return new w(new o(t,s,n,r.radius,0,e.degToRad(a),e.degToRad(i),e.degToRad(c)))}},positionRing:new class extends E{constructor(){super(...arguments),this.parameters={position:G([0,0,0]),rotation:G([0,0,0]),radius:F(1,0,1e4),thickness:F(.2,0,1e4)}}make(r={}){const{x:t,y:s,z:n}=r.position,{x:a,y:i,z:c}=r.rotation;return new w(new o(t,s,n,r.radius,Math.max(r.thickness,1e-4),e.degToRad(a),e.degToRad(i),e.degToRad(c)))}},rotation:new class extends E{constructor(){super(...arguments),this.parameters={rotation:G([0,0,0])}}make(r={}){const{x:s,y:n,z:a}=r.rotation;return new S(new t(e.degToRad(s),e.degToRad(n),e.degToRad(a)))}},randomRotation:new class extends E{constructor(){super(...arguments),this.parameters={axis:J(K,"XYZ")}}make(e={}){return new A(e.axis)}},scale:new class extends E{constructor(){super(...arguments),this.parameters={scale:F(1)}}make(e={}){return new B(e.scale)}},scaleComponents:new class extends E{constructor(){super(...arguments),this.parameters={scale:G([1,1,1])}}make(e={}){return new I(e.scale)}},randomScale:new class extends E{constructor(){super(...arguments),this.parameters={min:F(1),max:F(1)}}make(e={}){return new P(e.min,e.max)}},mass:new class extends E{constructor(){super(...arguments),this.parameters={min:F(1)}}make(e={}){return new l(e.min)}},velocity:new class extends E{constructor(){super(...arguments),this.parameters={velocity:G([0,0,0])}}make(e={}){const{x:r,y:s,z:n}=e.velocity;return new C(new t(r,s,n))}},randomVelocity:new class extends E{constructor(){super(...arguments),this.parameters={min:G([0,0,0]),max:G([0,0,0])}}make(e={}){return new C(e.min,e.max)}},radialVelocity:new class extends E{constructor(){super(...arguments),this.parameters={speed:F(1),direction:G([0,1,0]),spread:F(0)}}make(e={}){return new x(e.speed,new g(e.direction.x,e.direction.y,e.direction.z),e.spread)}},randomDirection:new class extends E{constructor(){super(...arguments),this.parameters={speed:F(1)}}make(e={}){return new O(e.speed)}}},$={force:new class extends q{constructor(){super(...arguments),this.parameters={force:G([0,0,0]),ease:N()}}make(e={}){return new u(e.force.x,e.force.y,e.force.z,void 0,U(e.ease))}},gravity:new class extends q{constructor(){super(...arguments),this.parameters={gravity:F(8),easing:N()}}make(e={}){return new d(e.gravity,void 0,U(e.easing))}},repulsion:new class extends q{constructor(){super(...arguments),this.parameters={target:G([0,0,0]),force:F(1),radius:F(1),easing:N()}}make(e={}){const r=new g(e.target.x,e.target.y,e.target.z);return new h(r,e.force,e.radius,void 0,U(e.easing))}},attraction:new class extends q{constructor(){super(...arguments),this.parameters={target:G([0,0,0]),force:F(1),radius:F(1),easing:N()}}make(e={}){const r=new g(e.target.x,e.target.y,e.target.z);return new n(r,e.force,e.radius,void 0,U(e.easing))}},scale:new class extends q{constructor(){super(...arguments),this.parameters={a:F(1),b:F(1),ease:N()}}make(e={}){return new j(e.a,e.b,U(e.ease))}},scaleComponents:new class extends q{constructor(){super(...arguments),this.parameters={a:G([1,1,1]),b:G([1,1,1]),ease:N()}}make(e={}){return new D(e.a,e.b,U(e.ease))}},randomDrift:new class extends q{constructor(){super(...arguments),this.parameters={drift:G([1,1,1]),delay:F(0),ease:N()}}make(e={}){return new f(e.drift.x,e.drift.y,e.drift.z,e.delay,void 0,U(e.ease))}},rotate:new class extends q{constructor(){super(...arguments),this.parameters={rotation:G([0,0,0]),ease:N()}}make(r={}){const{x:t,y:s,z:n}=r.rotation;return new y(e.degToRad(t),e.degToRad(s),e.degToRad(n),void 0,U(r.ease))}},rotateAdd:new class extends q{constructor(){super(...arguments),this.parameters={rotation:G([0,0,0])}}make(r={}){const{x:t,y:s,z:n}=r.rotation,a=new y(e.degToRad(t),e.degToRad(s),e.degToRad(n),void 0);return a.rotationType="add",a}},changeColor:new class extends q{constructor(){super(...arguments),this.parameters={a:H("#ffffff"),b:H("#ffffff"),ease:N()}}make(e={}){return new i(e.a,e.b,void 0,U(e.ease))}},changeOpacity:new class extends q{constructor(){super(...arguments),this.parameters={a:F(1,0,1),b:F(0,0,1),ease:N()}}make(e={}){return new s(e.a,e.b,void 0,U(e.ease))}},vortex:new class extends q{constructor(){super(...arguments),this.parameters={axis:G([0,1,0]),amount:F(1)}}make(e={}){return new V(e.axis,e.amount)}},moveTo:new class extends q{constructor(){super(...arguments),this.parameters={target:G([0,1,0]),ease:N()}}make(e={}){return new T(e.target.x,e.target.y,e.target.z,U(e.ease))}},linearDamping:new class extends q{constructor(){super(...arguments),this.parameters={factor:F(.1,0,1e3)}}make(e={}){return new R(e.factor)}},followParent:new class extends q{constructor(){super(...arguments),this.parameters={speed:F(0)}}make(e={}){return new z(e.speed)}},worldCollision:new class extends q{constructor(){super(...arguments),this.parameters={friction:F(1,0,1),bounce:F(1,0,1),lifeLoss:F(0,0)}}make(e={}){return new X(null,e.bounce,e.friction,e.lifeLoss)}}};export const VfxInitializserLibrary=W;export const VfxInitializserLibraryKeys=Object.keys(VfxInitializserLibrary);export const VfxBehaviourLibrary=$;export const VfxBehaviourLibraryKeys=Object.keys(VfxBehaviourLibrary);/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{BackSide as e,Color as t,ShaderMaterial as i,UniformsLib as n,UniformsUtils as a,Object3D as l,Mesh as
|
|
1
|
+
import{BackSide as e,Color as t,ShaderMaterial as i,UniformsLib as n,UniformsUtils as a,Object3D as l,Mesh as r,InstancedMesh as o,BatchedMesh as s,Vector3 as c}from"three";import{glslFunction as p,NodeShaderMaterial as u,Vec4Node as d,uniforms as m,transformed as v,neg as f,uniformFloat as h,uniformVec3 as _,vec3 as g,rgba as x,vec4 as k,negVec3 as A,ifDefApply as b,BooleanExpression as y,select as w,attributes as M}from"three-shader-graph";export class OutlineEffect{constructor(i,n={}){this.applied=new WeakSet,this.enabled=!0;const a=void 0!==n.defaultThickness?n.defaultThickness:.003,l=((new t).fromArray(void 0!==n.defaultColor?n.defaultColor:[0,0,0]),void 0!==n.defaultAlpha?n.defaultAlpha:1),r=void 0!==n.defaultKeepAlive&&n.defaultKeepAlive,o={},s={};["#include <common>","#include <uv_pars_vertex>","#include <displacementmap_pars_vertex>","#include <fog_pars_vertex>","#include <morphtarget_pars_vertex>","#include <skinning_pars_vertex>","#include <logdepthbuf_pars_vertex>","#include <clipping_planes_pars_vertex>","uniform float outlineThickness;","vec4 calculateOutline( vec4 pos, vec3 normal, vec4 skinned ) {","\tfloat thickness = outlineThickness;","\tconst float ratio = 1.0;","\tvec4 pos2 = projectionMatrix * modelViewMatrix * vec4( skinned.xyz + normal, 1.0 );"," float viewDistance = length((modelViewMatrix * vec4(skinned.xyz, 1.0)).xyz);"," float scale = pow(viewDistance, 0.5); // sqrt, or any exponent","\tvec4 norm = normalize( pos - pos2 );","\treturn pos + norm * thickness * scale * ratio;","}","void main() {","\t#include <uv_vertex>","\t#include <beginnormal_vertex>","\t#include <morphnormal_vertex>","\t#include <skinbase_vertex>","\t#include <skinnormal_vertex>","\t#include <begin_vertex>","\t#include <morphtarget_vertex>","\t#include <skinning_vertex>","\t#include <displacementmap_vertex>","\t#include <project_vertex>","\tvec3 outlineNormal = - objectNormal;","\tgl_Position = calculateOutline( gl_Position, outlineNormal, vec4( transformed, 1.0 ) );","\t#include <logdepthbuf_vertex>","\t#include <clipping_planes_vertex>","\t#include <fog_vertex>","}"].join("\n"),["#include <common>","#include <fog_pars_fragment>","#include <logdepthbuf_pars_fragment>","#include <clipping_planes_pars_fragment>","uniform vec3 outlineColor;","uniform float outlineAlpha;","void main() {","\t#include <clipping_planes_fragment>","\t#include <logdepthbuf_fragment>","\tgl_FragColor = vec4( outlineColor, outlineAlpha );","\t#include <tonemapping_fragment>","\t#include <colorspace_fragment>","\t#include <fog_fragment>","\t#include <premultiplied_alpha_fragment>","}"].join("\n");function f(t){Array.isArray(t)&&(t=t[0]);const i=m.projectionMatrix.multiply(m.modelViewMatrix).multiplyVec(v.position);let n=A(M.normal);n=b("DOUBLE_SIDED",n,e=>w(new y("gl_FrontFacing"),e,e.multiplyScalar(-1)));const r=h("outlineThickness",a),o=_("outlineColor",new c(0,0,0)),s=h("outlineAlpha",l),f=p(d,{pos:i,normal:n,skinned:v.position,outlineThickness:r},"\n\t\t\t\t\tfloat thickness = outlineThickness;\n\t\t\t\t\tconst float ratio = 1.0; // TODO: support outline thickness ratio for each vertex\n\t\t\t\t\tvec4 pos2 = projectionMatrix * modelViewMatrix * vec4( skinned.xyz + normal, 1.0 );\n\t\t\t\t\tfloat viewDistance = length((modelViewMatrix * vec4(skinned.xyz, 1.0)).xyz);\n\t\t\t\t\tfloat scale = pow(viewDistance, 0.5); // sqrt, or any exponent\n\t\t\t\t\t// NOTE: subtract pos2 from pos because BackSide objectNormal is negative\n\t\t\t\t\tvec4 norm = normalize( pos - pos2 );\n\t\t\t\t\treturn pos + norm * thickness * scale * ratio;\n\t\t\t"),g=x(o,s),D=[g,k(0),k(0)],T="number"==typeof t.userData.mrtOutputs&&t.userData.mrtOutputs>1,O=new u({position:f,outputs:T?D:void 0,color:T?void 0:g});return O.side=e,O.depthTest=!0,O.depthWrite=!0,O.transparent=!0,O}this.createMaterial=f,this.getOutlineMaterial=function(e){const t=function(e){let t=o[e.uuid];return void 0===t&&(t={material:f(e),used:!0,keepAlive:r,count:0},o[e.uuid]=t),t.used=!0,t.material}(e);return s[t.uuid]=e,function(e,t){Array.isArray(t)&&(t=t[0]);if("invisible"===e.name)return;const i=t.userData.outlineParameters;e.fog=t.fog,e.toneMapped=t.toneMapped,e.premultipliedAlpha=t.premultipliedAlpha,e.displacementMap=t.displacementMap,void 0!==i?(!1===t.visible?e.visible=!1:e.visible=void 0===i.visible||i.visible,e.transparent=void 0!==i.alpha&&i.alpha<1||t.transparent,void 0!==i.keepAlive&&(o[t.uuid].keepAlive=i.keepAlive)):(e.transparent=t.transparent,e.visible=t.visible);!0!==t.wireframe&&!1!==t.depthTest||(e.visible=!1);t.clippingPlanes&&(e.clipping=!0,e.clippingPlanes=t.clippingPlanes,e.clipIntersection=t.clipIntersection,e.clipShadows=t.clipShadows);e.version=t.version}(t,e),t},this.updateUniforms=function(e,t){const i=t.userData.outlineParameters;e.uniforms.outlineAlpha.value=t.opacity,void 0!==i&&(void 0!==i.thickness&&(e.uniforms.outlineThickness.value=i.thickness),void 0!==i.color&&e.uniforms.outlineColor.value.fromArray(i.color),void 0!==i.alpha&&(e.uniforms.outlineAlpha.value=i.alpha)),t.displacementMap&&(e.uniforms.displacementMap.value=t.displacementMap,e.uniforms.displacementScale.value=t.displacementScale,e.uniforms.displacementBias.value=t.displacementBias)}}apply(e){if(!(e instanceof r)||e instanceof s||e instanceof o)return;if(this.applied.has(e))return;this.applied.add(e);const t=e.onAfterRender;e.onAfterRender=(i,n,a,l,r,o)=>{t(i,n,a,l,r);let s=!1;if(Array.isArray(r)?s=r.some(e=>e&&e.userData&&e.userData.outlineParameters):r&&r.userData&&r.userData.outlineParameters&&(s=!0),!s)return;const c=e.material,p=this.getOutlineMaterial(c);e.material=p,this.updateUniforms(p,r),i.renderBufferDirect(a,n,l,p,e,o),e.material=c}}}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
package/dist/rendering.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as r,Material as a,Matrix4 as n,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as d,WebGLRenderTarget as u,Texture as c,Euler as p}from"three";import{CopyShader as m,EffectComposer as f,FXAAShader as g,GammaCorrectionShader as v,LUTPass as M,RenderPass as T,ShaderPass as b,VRButton as x}from"three-stdlib";import{CSMShader as P,CSMUtil as y}from"./csm.js";import{bool as w,colorToNormal as S,float as R,NodeShaderMaterial as C,standardMaterial as A,uniformFloat as F,uniformVec3 as U,toonMaterial as E,lambertMaterial as O,normalize as I,rgb as B,rgba as D,textureSampler2d as W,transformed as L,varying as j,varyingAttributes as V,varyingTransformed as _,vec4 as G,BooleanExpression as q,select as k,ifDefApply as N,uniformSampler2d as H,RgbaNode as z}from"three-shader-graph";import{Reflector as $}from"three-stdlib";import{BokehPass as X,OutputPass as Y}from"three/examples/jsm/Addons.js";import{CSM as Q}from"three/examples/jsm/csm/CSM.js";import K from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as J}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as Z}from"typedi";import{depthUniformName as ee,farUniformName as te,nearUniformName as se,resolutionUniformName as ie,sceneNormalUniformName as re,screenUV as ae,supportsDepthTextureExtension as ne}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as oe}from"./shader-nodes/time.js";import{aoMapUniformName as le,sceneMapUniformName as he}from"./shader-nodes/scene-sample.js";import{DepthPass as de}from"./utils/three/depth-pass.js";import{GPUStatsPanel as ue}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as ce}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as pe,traverseVisibleStop as me}from"./utils/three/traverse.js";import{clamp as fe}from"./utils/math.js";import{ColorPass as ge}from"./rendering/color-pass.js";import{SSRPass as ve}from"./rendering/ssr/SSRPass.js";import{SSRShader as Me}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as Te}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as be}from"./rendering/outline-effect.js";import{UnrealBloomPass as xe}from"./rendering/bloom/UnrealBloomPass.js";import{highPrecisionEyeDepth as Pe}from"./shader-nodes/depth";import{packDepthToRGBA as ye}from"three-shader-graph";import{FogVolumeObject as we}from"./rendering/fog/fog-volume-object";import{ParallaxStandardMaterial as Se}from"./shader/builtin/standard-shader.js";import{parallaxOcclusionMapping as Re}from"./shader-nodes/pom.js";import{FullScreenQuad as Ce}from"three-stdlib";import{edgeDepthEffect as Ae}from"./shader-nodes/effects";import{decalDiscard as Fe}from"./shader-nodes/decal.js";import{Pass as Ue}from"three/examples/jsm/Addons.js";y.patchSetupMaterial();const Ee=document.createElement("div");Ee.style.position="absolute",Ee.style.left="50%",Ee.style.top="50%",Ee.style.color="black",Ee.style.zIndex="999";(new i.Layers).set(9);const Oe=new i.MeshBasicMaterial({color:"black"}),Ie=new i.MeshDepthMaterial;var Be;Ie.depthPacking=i.RGBADepthPacking,Ie.blending=i.NoBlending,Ie.side=i.DoubleSide,function(e){e[e.opaque=0]="opaque",e[e.transparent=1]="transparent"}(Be||(Be={}));const De=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let We=e=class{setPaused(e){this.paused=e}resizeRender(){const e=this.container.clientWidth,t=this.container.clientHeight;this.previousClientWith===e&&this.previousClientHeight===t||0!==e&&0!==t&&(this.previousClientWith=e,this.previousClientHeight=t,this.camera instanceof l&&(this.camera.aspect=e/t,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(e,t),this.composer.setSize(e*this.resolutionScale,t*this.resolutionScale),this.dofPass.setSize(e*this.resolutionScale,t*this.resolutionScale),this.fxaaPass.setSize(e*this.renderer.getPixelRatio(),t*this.renderer.getPixelRatio()),this.fxaaPass.uniforms.resolution.value.set(1/(e*this.renderer.getPixelRatio()),1/(t*this.renderer.getPixelRatio())),this.createGRenderTarget(),this.phasedRenderPass.gRenderTarget=this.gRenderTarget,this.bloomPass.emissiveTexture=this.gRenderTarget.textures[1],this.ssrPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.aoPass.setSize(e*this.resolutionScale,t*this.resolutionScale),this.aoPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container),this.copyPass.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass.material.uniformsNeedUpdate=!0)}addPostProcessVolume(e){if(0===this.postProcessVolumes.length)this.postProcessVolumes.push(e);else{let t=!1;for(let s=0;s<this.postProcessVolumes.length;s++)if(e.priority<this.postProcessVolumes[s].priority){this.postProcessVolumes.splice(s,0,e),t=!0;break}t||this.postProcessVolumes.push(e)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}constructor(t,s={}){this.container=t,this.options=s,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.postProcessVolumes=[],this.postProcessSettings={},this.fquadCopy=new Ce(new d(m)),this.fquadCopyOpaque=new Ce(new C({outputs:[H("tSceneColor",new c).sample(ae),G(H("tDepthTexture",new i.DepthTexture(1,1)).sample(ae).r)]})),this.fquadBlendAO=(()=>{const e=G(1),t=new C({outputs:[H("tAO",new c).sample(ae),e,e],transparent:!0});t.depthWrite=!1,t.depthTest=!1,t.blending=i.MultiplyBlending;return new Ce(t)})(),this.resolutionScale=1,this.maxPixelRatio=De?1:window.devicePixelRatio,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!0,this.onLoopCallbacks=[],this.stats=new K,this._showStats=!0,this.gbufferMaterialCache=new Map,this.tbufferMaterialCache=new Map,this.pmremGeneratorResults=new WeakMap,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],this._customDepthMaterialCache=new WeakMap,null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),window.renderer=this.renderer=new i.WebGLRenderer({antialias:!1,powerPreference:"high-performance"});new i.MeshStandardMaterial({color:"#ccc"});this.scene=new i.Scene,this.scene.matrixWorldAutoUpdate=!0,this.scene.updateMatrixWorld=function(e){const t=this.children;for(let s=0,i=t.length;s<i;s++){t[s].updateMatrixWorld(e)}}.bind(this.scene),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(x.createButton(this.renderer));const a=new be(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=a,this.createGRenderTarget(),this.composer=new f(this.renderer);var n=(t.clientWidth||1)/(t.clientHeight||1);const o=new i.PerspectiveCamera(45,n,.5,800);o.layers.enable(19),this.setCamera(o),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,y.renderingView=this,this.isDepthTextureExtensionSupported=ne(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container);const l=new i.Vector2(t.clientWidth,t.clientHeight),h=(new T(this.scene,this.camera),new b(m,"prevtexture"));h.enabled=!0,h.needsSwap=!0,h.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass=h;const u=new xe(l,1.5,.4,.85);u.threshold=1,u.strength=.9,u.radius=.5,this.bloomPass=u;const p=new J(this.scene,this.camera,t.clientWidth,t.clientWidth,{});p.normalRenderTarget?.dispose(),p.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),p.output=J.OUTPUT.Off,p.enabled=!1,this.aoPass=p,this.fquadBlendAO.material.uniforms.tAO.value=p.pdRenderTarget.texture,Me.fragmentShader=Me.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const P=new ve({renderer:this.renderer,scene:this.scene,camera:this.camera,groundReflector:null,selects:[],normalTexture:this.gRenderTarget.textures[2],depthTexture:this.gRenderTarget.depthTexture});P.output=ve.OUTPUT.Default,P.blur=!0,P.fresnel=!1,P.distanceAttenuation=!0,P.maxDistance=50,P.selective=!0,P.bouncing=!1,P.opacity=.4,P.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=P,!1!==this.options.ao?.enabled&&this.composer.addPass(p);const w=new Ze((e,t,s,i,r)=>{this.aoPass.enabled&&(this.initResolutionUniform(this.fquadBlendAO.material),this.renderer.setRenderTarget(this.gRenderTarget),this.fquadBlendAO.render(this.renderer),this.renderer.setRenderTarget(null))});this.composer.addPass(w);const S=new Ze((e,t,s,i,r)=>{this.renderer.setRenderTarget(this.gRenderTarget),this.renderScene(Be.transparent),this.renderer.setRenderTarget(null)});this.composer.addPass(S),this.composer.addPass(h),this.composer.addPass(P),this.phasedRenderPass=new Je(this.scene,this.camera,this.gRenderTarget),this.composer.addPass(this.phasedRenderPass),this.composer.addPass(u),u.emissiveTexture=this.gRenderTarget.textures[1],this.renderer.info.autoReset=!1,this.volumetricFogPass=new Te(l),this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new X(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const R=new ge;this.composer.addPass(R),this.colorPass=R,R.vignetteEnabled=!1,this.outlinePass=new ce(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.outlinePass.enabled=!1,this.composer.addPass(this.outlinePass);const A=new b(g);A.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(A),this.fxaaPass=A,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new b(v).clear=!1,this.fixStatsStyle(),this.lutPass=new M({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const F=new b(m,"prevtexture");F.enabled=!0,F.needsSwap=!1,F.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],F.renderToScreen=!0;const U=new Y;this.composer.addPass(U)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setEnableOutlines(e){this.outlinePass.enabled=e,this.fxaaPass.enabled=e}setCamera(e){this.camera=e,this.composer.passes.forEach(t=>{t instanceof T?t.camera=e:t instanceof ce?t.renderCamera=e:(t instanceof de||t instanceof J)&&(t.camera=e)}),this.ssrPass&&(this.ssrPass.camera=e),this.aoPass&&(this.aoPass.camera=e),this.phasedRenderPass&&(this.phasedRenderPass.camera=e),null==this.csm?(this.csm=new Q({maxFar:100,lightFar:250,lightMargin:20,cascades:De?2:4,shadowMapSize:2048*(De?.5:1),lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"practical"}),this.csm&&Array.isArray(this.csm.lights),this.csm.fade=!0,h.lights_fragment_begin=P.lights_fragment_begin):(this.csm.camera=this.camera,this.camera),this.csm.updateFrustums()}setSelectedObjects(e){if(null==this.outlinePass)return;const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse(e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)});this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t,s){const r=new i.WebGLRenderTarget(t.clientWidth*s,t.clientHeight*s);return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,r.depthTexture=new i.DepthTexture(128,128),r.depthTexture.type=i.UnsignedShortType,r.depthTexture.minFilter=i.NearestFilter,r.depthTexture.magFilter=i.NearestFilter,r}static createAOMaskDepthRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:i.HalfFloatType});return s.texture.minFilter=i.NearestFilter,s.texture.magFilter=i.NearestFilter,s.texture.generateMipmaps=!1,s.stencilBuffer=!1,s.depthTexture=new i.DepthTexture(128,128),s.depthTexture.type=i.UnsignedInt248Type,s.depthTexture.minFilter=i.NearestFilter,s.depthTexture.magFilter=i.NearestFilter,s}createSceneColorRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*this.renderer.getPixelRatio(),t.clientHeight*this.renderer.getPixelRatio(),{count:2,type:i.FloatType,format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,depthBuffer:!1,stencilBuffer:!1});return s.texture.minFilter=i.LinearFilter,s.texture.magFilter=i.LinearFilter,s.texture.generateMipmaps=!1,s}createGRenderTarget(){const e=this.container;null!=this.gRenderTarget&&this.gRenderTarget.dispose(),this.gRenderTarget=new u(e.clientWidth*this.renderer.getPixelRatio(),e.clientHeight*this.renderer.getPixelRatio(),{count:3,minFilter:i.NearestFilter,magFilter:i.NearestFilter,type:i.HalfFloatType,format:i.RGBAFormat}),this.gRenderTarget.depthTexture=new i.DepthTexture(e.clientWidth,e.clientHeight),this.gRenderTarget.depthTexture.type=i.UnsignedIntType,this.gRenderTarget.depthTexture.minFilter=i.NearestFilter,this.gRenderTarget.depthTexture.magFilter=i.NearestFilter,this.gRenderTarget.texture.generateMipmaps=!1,this.gRenderTarget.stencilBuffer=!1}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.gRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren(),this.volumetricFogPass.dispose(),y.clearSceneCache(this.scene)}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){if(null!=this.scene.environment&&(e instanceof C&&(null==e.envMap||e.userData.useSceneEnv)&&(e.userData.useSceneEnv=!0,null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment},e.uniformsNeedUpdate=!0,e.uniforms.envMapRotation={value:He(this.scene.environmentRotation,this.scene.environment,new i.Matrix3)}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1},e.uniformsNeedUpdate=!0),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment),e instanceof C||e instanceof i.MeshStandardMaterial)){const t=this.gbufferMaterialCache.get(e);null==t||this.gbufferMaterialCache.has(t)||this.applyEnvMap(t)}}setupCsm(e){if(e instanceof i.Mesh||e instanceof i.SkinnedMesh)if(e.material instanceof Array)for(const t of e.material)this.csm.setupMaterial(t);else this.csm.setupMaterial(e.material)}updateUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e in s){const t=i[e],r=s[e].value;null!=t&&t.value!==r&&(t.value=r)}}updateLightUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e of et){const t=i[e],r=s[e];null!=r&&null!=t&&(t.value=r.value)}}createGBufferMaterial(e,t){const s=t===Be.opaque?this.gbufferMaterialCache:this.tbufferMaterialCache;let r=s.get(e);if(null==r){let o=V.uv;e instanceof Se&&null!=e.heightMap&&(o=Re(o,W(e.heightMap),R(e.heightScale??1)));let l=_.normal;e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial?null!=e.normalMap&&(l=S(W(e.normalMap).sample(o),e.normalScale.x??1)):e instanceof C&&null!=e.outputNormal&&(l=e.outputNormal),!0!==e.userData.disableAO&&(l=N("DOUBLE_SIDED",l,e=>k(new q("gl_FrontFacing"),e,e.multiplyScalar(-1))));let h=e.userData?.reflective?R(0):R(1);if(e instanceof i.MeshStandardMaterial){const t=F("roughness",e.roughness??1);h=null!=e.roughnessMap?W(e.roughnessMap).sample(o).g.multiply(t):t}else e instanceof C&&null!=e.outputRoughness&&(h=e.outputRoughness);let u=null;(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial)&&null!=e.lightMap&&(u=W(e.lightMap).sample(o).rgb.multiplyScalar(e.lightMapIntensity));let c,p=R(0);if(e instanceof i.MeshStandardMaterial){const t=F("metalness",e.metalness??0);p=null!=e.metalnessMap?W(e.metalnessMap).sample(o).b.multiply(t):t}else e instanceof C&&e.outputRoughness;let m=R(1);e instanceof i.MeshStandardMaterial?null!=e.aoMap&&(c=W(e.aoMap).sample(o).r,m=F("aoMapIntensity",e.aoMapIntensity)):e instanceof C&&e.outputRoughness;const f=F("opacity",e.opacity??1);let g=R(1);e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial?(null!=e.alphaMap&&(g=W(e.alphaMap).sample(o).r),g=g.multiply(f)):e instanceof C&&null!=e.outputOpacity&&(g=e.outputOpacity);let v=D(0,1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){const t=U("color",(new i.Vector3).setFromColor(e.color));null!=e.map?(v=W(e.map).sample(o).multiply(D(t,1)),g=g.multiply(v.w)):v=D(t,1)}const M=!0===e.userData.hasBloom;let T=B(0);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=U("emissive",(new i.Vector3).setFromColor(e.emissive));T=null!=e.emissiveMap?W(e.emissiveMap).sample(o).rgb.multiply(t):t,T=T.multiplyScalar(e.emissiveIntensity)}else e instanceof C&&null!=e.outputEmissive&&(T=e.outputEmissive);const b=e instanceof d&&null!=e.uniforms[ee],x=e instanceof d&&null!=e.uniforms[he],P=e instanceof d&&null!=e.uniforms[le],y=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,L=F("alphaTest",e.alphaTest);let j,H=e.alphaTest>0?g.lt(L):y&&t===Be.opaque?g.lt(.8):w(!1);!0===e.userData.isDecal&&(H=H.or(Fe)),j=y?G(0,0,0,0):(n=l,I(n).multiplyScalar(.5).addScalar(.5)).rgba(h);let z,$=e instanceof C?e.outputPosition:void 0,X=D("black",1);if(e instanceof C&&null!=e.outputColor)X=e.outputColor;else if(e instanceof i.MeshStandardMaterial)X=A({color:v,metalness:p,roughness:h,emissive:T.rgb,normal:l,ambientOcclusion:c,ambientOcclusionIntensity:m,bakedLight:u});else if(e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)X=O({color:v.rgb});else if(e instanceof i.MeshBasicMaterial){let e=v.rgb,t=u??B("white");null!=c&&(t=t.multiplyScalar(c.subtract(1).multiply(m).add(1))),e=e.multiply(t),X=e.rgba(g)}else e instanceof i.MeshToonMaterial&&(X=E({color:v,emissive:T.rgb,normal:l,ambientOcclusion:c,ambientOcclusionIntensity:m,bakedLight:u}));(e instanceof C||e instanceof i.MeshStandardMaterial)&&(z=e.envMap),r=new C({position:$,outputs:[(a=D(X.rgb,g),new FogNode(a)),T.rgba(t===Be.opaque?L:M?1:0),j],opacity:g,outputEncoding:!1,fog:!0,transparent:e.transparent,lights:!0,envMap:z,discard:H}),e instanceof i.MeshStandardMaterial&&null!=e.envMap&&null!=r.uniforms.envMapIntensity&&(r.uniforms.envMapIntensity.value=e.envMapIntensity),(e instanceof C||e instanceof i.MeshStandardMaterial)&&this.applyEnvMap(r),e instanceof C&&Object.assign(r.defines,e.defines),r.userData.mrtOutputs=3,r.forceSinglePass=e.forceSinglePass,r.side=e.side,r.blending=e.blending,y?(r.depthWrite=!e.transparent,r.depthTest=e.depthTest,r.colorWrite=t===Be.transparent):(r.depthWrite=e.depthWrite,r.depthTest=e.depthTest),r.visible=e.visible,r.alphaTest=e.alphaTest,r.alphaHash=e.alphaHash,t===Be.opaque?(r.visible&&(r.visible=!b&&!x&&!P),r.visible&&(r.visible=!y)):t===Be.transparent&&r.visible&&(r.visible=y||b||x||P),Object.assign(r.userData,e.userData),r.visible&&(this.csm.setupMaterial(r),e instanceof d&&Object.assign(r.uniforms,e.uniforms)),s.set(e,r)}var a,n;return r.visible&&e instanceof d&&this.updateUniformValues(e,r),r}loop(e,t=!1){const s=this.stats,r=s.addPanel(new K.Panel("Calls","#83f","#002")),a=s.addPanel(new K.Panel("Triangles","#c32","#002"));let l;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(l=new ue(this.renderer.getContext()),s.addPanel(l)),this.showStats=t;let h=10,d=1e3;const u=()=>{const e=this.renderer.info.render.calls;e>h&&(h=e,setTimeout(()=>h=10,5e3)),r.update(e,h);const t=this.renderer.info.render.triangles;t>d&&(d=t,setTimeout(()=>d=1e3,5e3)),a.update(t,d)};performance.now();i.Ray.prototype.intersectTriangle;this.resizeRender();const c=[],p=[],m=[];let f=0;const g=new n,v=new n;let M=0;let T=this.paused;const b=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return setTimeout(()=>b(t),500),void(T=!0);this.renderer.clear(),this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,s.begin(),this.showStats&&l?.startQuery(),this.ssrPass.gpuPanel=l;let a=(t*=.001)-f;if(f=t,T&&(a=.016,T=!1),g.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(Le),t-=Le;e(t)}else e(a);this.onLoopCallbacks.forEach(e=>e(a)),this.camera?.updateMatrixWorld(),v.copy(this.camera.matrixWorld),t-M>.08&&!v.equals(g)&&(this.renderer.shadowMap.needsUpdate=!0,M=t),this.csm.update();let n=!1;c.length=0,p.length=0,m.length=0;const h=Ve;Ge.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),h.setFromProjectionMatrix(Ge);let d=!1,x=!1,P=!1;this.scene.traverseVisible(e=>{if(this.setupCsm(e),this.outlineEffect.apply(e),e instanceof we&&(d=!0),e instanceof o&&this.initCustomDepthMaterial(e),(e instanceof o||e instanceof i.Sprite)&&(this.initResolutionUniform(e.material),this.initNormalUniform(e.material),this.initShadowUniform(e,e.material),null!=this.scene.environment&&function(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}(e,e=>this.applyEnvMap(e)),!0===e.material?.userData?.hasBloom&&(n=!0)),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[ee])&&isObjectInFrustum(e,h)?(this.initDepthUniform(e.material),x=!0):e instanceof $&&(e.visible=!1,p.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[le]&&isObjectInFrustum(e,h)&&e.material instanceof C&&this.initAoUniform(e.material),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[he]&&isObjectInFrustum(e,h)&&(m.push(e),e.material.uniforms[he].value=this.sceneColorRenderTarget.texture,P=!0),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[oe])e.material.uniforms[oe].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const s of e.material)s.uniforms&&null!=s.uniforms[oe]&&(s.uniforms[oe].value=t)}),this.bloomPass.enabled=n,this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderScene(Be.opaque),this.aoPass.output=J.OUTPUT.Off,(x||P)&&(this.fquadCopyOpaque.material.uniforms.tSceneColor.value=this.gRenderTarget.textures[0],this.fquadCopyOpaque.material.uniforms.tDepthTexture.value=this.gRenderTarget.depthTexture,this.initResolutionUniform(this.fquadCopyOpaque.material),this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.renderer.clear(),this.fquadCopyOpaque.render(this.renderer),this.renderer.setRenderTarget(this.gRenderTarget)),m.length,c.forEach(e=>e.visible=!0),p.forEach(e=>e.visible=!0),m.forEach(e=>e.visible=!0),this.aoPass.enabled,this.ssrPass&&(this.ssrPass.elapsedTime=t),this.volumetricFogPass&&d&&this.volumetricFogPass.update(this.camera,this.gRenderTarget,this.csm,this.scene);try{!this.paused&&this.running&&(this.render(a),this.showStats&&l?.endQuery(),this.showStats&&u(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}s.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout(()=>{requestAnimationFrame(b)},1e3/this.fpsCap):requestAnimationFrame(b))};!0===this.options.enableXR?this.renderer.setAnimationLoop(b):requestAnimationFrame(b)}renderScene(e){Xe.clear(),Ye.length=0;me(this.scene,t=>{if(Qe(t))return Ye.push(t),t.visible=!1,!1;if(t instanceof o){Xe.set(t,t.material);let s=!1;if(Array.isArray(t.material)){t.material=t.material.slice();for(let i=0;i<t.material.length;i++)t.material[i]=this.createGBufferMaterial(t.material[i],e),s||(s=t.material[i].visible)}else t.material=this.createGBufferMaterial(t.material,e),s||(s=t.material.visible);s?t.visible=!0:null!=t.children&&0!=t.children.length||(Ye.push(t),t.visible=!1)}});const t=this.scene.matrixWorldAutoUpdate,s=this.scene.matrixAutoUpdate,i=this.renderer.shadowMap.autoUpdate;e!==Be.opaque&&(this.renderer.shadowMap.autoUpdate=!1,this.scene.matrixWorldAutoUpdate=!1,this.scene.matrixAutoUpdate=!1);try{this.renderer.render(this.scene,this.camera)}catch(e){console.warn("Render failed",e)}e===Be.opaque&&Xe.forEach((e,t)=>{!Array.isArray(e)&&!Array.isArray(t.material)&&e instanceof d&&this.updateLightUniformValues(t.material,e)}),Xe.forEach((e,t)=>{t.material=e}),Ye.forEach((e,t)=>{e.visible=!0,e.updateMatrixWorld(!0)}),this.renderer.shadowMap.autoUpdate=i,this.scene.matrixWorldAutoUpdate=t,this.scene.matrixAutoUpdate=s}getEnvTexture(e){null==this.pmremGenerator&&(this.pmremGenerator=new i.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader());let t=this.pmremGeneratorResults.get(e);return null==t&&(t=this.pmremGenerator.fromEquirectangular(e).texture,this.pmremGeneratorResults.set(e,t)),t.colorSpace=i.SRGBColorSpace,t}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return this.lutPass.enabled=!1,void(this.colorPass.enabled=!1);var e;(e=this.postProcessSettings).tonemapMapping=void 0,e.tonemapExposure=1,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=new i.Color("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.lut=void 0,e.lutIntensity=0;const t=this.postProcessSettings;let s,r=!1,a=!1,n=!1,o=!1;if(null==this.camera)return;const h=this.camera.getWorldPosition(qe);let d=[];for(const e of this.postProcessVolumes){if(!je(e.object))continue;let l=e.blendWeight??1;const u=e.distanceToPoint(h);u>e.blendRadius||(e.blendRadius>0&&(l*=fe(1-u/e.blendRadius,0,1)),l>1&&(l=1),l>0&&(d.push(e),void 0!==e.settings.tonemapMapping&&(t.tonemapMapping=e.settings.tonemapMapping),void 0!==e.settings.tonemapExposure&&(t.tonemapExposure=i.MathUtils.lerp(t.tonemapExposure,e.settings.tonemapExposure,l)),void 0!==e.settings.envTexture&&(t.envTexture=e.settings.envTexture),void 0!==e.settings.envIntensity&&(t.envIntensity=i.MathUtils.lerp(t.envIntensity,e.settings.envIntensity,l)),void 0!==e.settings.vignetteIntensity&&(t.vignetteIntensity=i.MathUtils.lerp(t.vignetteIntensity,e.settings.vignetteIntensity,l),a=!0),void 0!==e.settings.colorTint&&void 0!==e.settings.colorTintIntensity&&e.settings.colorTintIntensity>0&&(t.colorTint=t.colorTint.lerp(e.settings.colorTint,l),o=!0),void 0!==e.settings.colorTintIntensity&&(t.colorTintIntensity=i.MathUtils.lerp(t.colorTintIntensity,e.settings.colorTintIntensity,l)),void 0!==e.settings.depthFocus&&(r=!0,t.depthFocus=void 0!==t.depthFocus?i.MathUtils.lerp(t.depthFocus,e.settings.depthFocus,l):e.settings.depthFocus),void 0!==e.settings.depthAperture&&(r=!0,t.depthAperture=void 0!==t.depthAperture?i.MathUtils.lerp(t.depthAperture,e.settings.depthAperture,l):e.settings.depthAperture),void 0!==e.settings.depthMaxBlur&&(r=!0,t.depthMaxBlur=void 0!==t.depthMaxBlur?i.MathUtils.lerp(t.depthMaxBlur,e.settings.depthMaxBlur,l):e.settings.depthMaxBlur),void 0!==e.settings.temperature&&(t.temperature=i.MathUtils.lerp(t.temperature,e.settings.temperature,l)),void 0!==e.settings.temperatureTint&&(t.temperatureTint=i.MathUtils.lerp(t.temperatureTint,e.settings.temperatureTint,l)),void 0!==e.settings.lut&&(s=e.settings.lut,n=!0),void 0!==e.settings.lutIntensity&&(t.lutIntensity=i.MathUtils.lerp(t.lutIntensity,e.settings.lutIntensity,l),n=!0)))}this.renderer.toneMapping=t.tonemapMapping??i.NoToneMapping,this.renderer.toneMappingExposure=t.tonemapExposure,null!=t.envTexture&&(this.scene.environment=this.getEnvTexture(t.envTexture)),this.scene.environmentIntensity=t.envIntensity,this.colorPass.vignetteIntensity=t.vignetteIntensity,this.colorPass.vignetteEnabled=a,this.colorPass.colorTint=t.colorTint,this.colorPass.colorTintIntensity=t.colorTintIntensity,this.colorPass.enabled=a||o,r&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==t.depthFocus&&(this.dofPass.uniforms.focus.value=t.depthFocus),void 0!==t.depthAperture&&(this.dofPass.uniforms.aperture.value=t.depthAperture),void 0!==t.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=t.depthMaxBlur)):this.dofPass.enabled=!1,this.colorPass.temperature=t.temperature,this.colorPass.temperatureTint=t.temperatureTint,this.lutPass.enabled=n,n&&(null!=s&&(s.flipY=!0,s.generateMipmaps=!1),this.lutPass.lut=s,this.lutPass.intensity=t.lutIntensity)}renderOverlay(){if(0===this.overlayCameras.size)return;const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.previousClientWith/2,s=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let i=0;i<e.length;i++)this.renderer.clearDepth(),this.renderer.setViewport(t-s/2+this.insetWidth*i+this.insetMargin*i,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[i])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){if(0===this.composer.renderTarget1.width||0===this.composer.renderTarget1.height)return;if(0===this.composer.renderTarget2.width||0===this.composer.renderTarget2.height)return;let t=!1;if(this.ssrPass.enabled&&!1!==this.options?.reflection?.enabled){const e=this.ssrPass.selects??[];e.length=0,this.scene.traverseVisible(t=>{t instanceof o&&!0===t.material.userData?.reflective&&isObjectInFrustum(t,Ve)&&e.push(t)}),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}this.options.bloom,this.composer.render(e),this.scene.matrixWorldAutoUpdate=!0,this.scene.matrixAutoUpdate=!0,t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=pe(this.scene,e=>e instanceof o&&!0===e.material?.userData?.hasBloom)}darkenNonBloomed(e){if((e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)){if(e.material?.id===Oe.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=Oe:(e.visible=!1,this.bloomHidden.push(e))}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof d&&(e.uniforms[ee].value=this.sceneColorRenderTarget.textures[1],this.camera instanceof l&&(null!=e.uniforms[se]&&(e.uniforms[se].value=this.camera.near),null!=e.uniforms[te]&&(e.uniforms[te].value=this.camera.far)))}initNormalUniform(e){e instanceof d&&null!=e.uniforms[re]&&(e.uniforms[re].value=this.gRenderTarget.textures[2])}initShadowUniform(e,t){t instanceof C&&t.uniforms.receiveShadow&&(t.uniforms.receiveShadow.value=e.receiveShadow)}initResolutionUniform(e){if(e instanceof d&&null!=e.uniforms[ie]){const t=this.previousClientWith,s=this.previousClientHeight;e.uniforms[ie].value.set(t*this.renderer.getPixelRatio(),s*this.renderer.getPixelRatio())}}initAoUniform(e){if(this.aoPass.enabled){e.uniforms[le].value=this.aoPass.pdRenderTarget.texture,null==e.defines.USE_SSAO_MAP&&(e.defines.USE_SSAO_MAP="",e.needsUpdate=!0),e.defines.USE_SSAO_MAP="";const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}else if(null!=e.defines.USE_SSAO_MAP){delete e.defines.USE_SSAO_MAP,e.needsUpdate=!0;const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}}initCustomDepthMaterial(e){if(null!=e.customDepthMaterial||!e.castShadow)return;const t=e.material;if(t instanceof C&&!t.transparent&&t.depthWrite){let s=this._customDepthMaterialCache.get(t);if(null==s){const e=ye(Pe);let i;null!=t.alphaTest&&t.alphaTest>0&&null!=t.outputOpacity&&(i=t.outputOpacity.lt(t.alphaTest)),s=new C({color:e,discard:i}),this._customDepthMaterialCache.set(t,s)}e.customDepthMaterial=s}}};We=e=t([Z(),s("design:paramtypes",[HTMLElement,Object])],We);export{We as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const Le=.05;function je(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}J.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse(function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls||e.isSprite)&&(e.visible=!1),null!=e.material){let t=!1,s=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0?t=!0:!0===e.material.userData.isDecal&&(s=!0);s&&(e.visible=!1)}})};const Ve=new i.Frustum,_e=new i.Box3,Ge=new i.Matrix4;export function isObjectInFrustum(e,t){const s=_e.setFromObject(e);return t.intersectsBox(s)}const qe=new i.Vector3;const ke=new n,Ne=new p;function He(e,t,s=new i.Matrix3){return Ne.copy(e),Ne.x*=-1,Ne.y*=-1,Ne.z*=-1,t.isCubeTexture&&!1===t.isRenderTargetTexture&&(Ne.y*=-1,Ne.z*=-1),s.setFromMatrix4(ke.makeRotationFromEuler(Ne))}const ze=new C({outputs:[G(0,0,0,0),G(0,0,0,0),D(B("white"),Ae(4))],transparent:!0}),$e=new i.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.5});ze.depthWrite=!1;new o(new i.BoxGeometry(4,4,4),$e);const Xe=new Map,Ye=[];function Qe(e){return e instanceof i.Sprite||e.isPoints||e.isLine||e.isTransformControls||e.isTransformControlsGizmo||e instanceof o&&Ke(e,e.material)}function Ke(e,t){return null==t||(Array.isArray(t)?t.some(t=>Ke(e,t)):t instanceof i.RawShaderMaterial||t instanceof i.ShaderMaterial&&!(t instanceof C))}class Je extends Ue{constructor(e,t,s){super(),this.scene=e,this.camera=t,this.gRenderTarget=s,this.needsSwap=!1}render(e,t,s,i,r){const a=e.autoClear;e.autoClear=!1;const n=this.scene.matrixWorldAutoUpdate,l=this.scene.matrixAutoUpdate,h=e.shadowMap.autoUpdate;this.scene.matrixAutoUpdate=!1,e.shadowMap.autoUpdate=!1;const d=s.depthTexture;s.depthTexture=this.gRenderTarget.depthTexture,e.setRenderTarget(s),Ye.length=0;let u=0;this.scene.traverseVisible(e=>{const t=Qe(e);e instanceof o&&!t?(Ye.push(e),e.visible=!1):t&&u++}),u>0&&e.render(this.scene,this.camera),Ye.forEach((e,t)=>{e.visible=!0}),e.setRenderTarget(null),e.autoClear=a,s.depthTexture=d,this.scene.matrixWorldAutoUpdate=n,this.scene.matrixAutoUpdate=l,e.shadowMap.autoUpdate=h}}class Ze extends Ue{constructor(e){super(),this.fn=e}render(e,t,s,i,r){this.fn(e,t,s,i,r)}}const et=["ambientLightColor","cameraNear","directionalLightShadows","directionalLights","directionalShadowMap","directionalShadowMatrix","fogColor","fogDensity","fogFar","fogNear","hemisphereLights","lightProbe","ltc_1","ltc_2","pointLightShadows","pointLights","pointShadowMap","pointShadowMatrix","rectAreaLights","shadowFar","spotLightMap","spotLightMatrix","spotLightShadows","spotLights","spotShadowMap"],tt=U("fogColor");export class FogNode extends z{constructor(e,t=tt){super(),this.source=e,this.fogColor=t}compile(e){const t=e.variable(),s=e.get(this.source.rgb),i=e.get(this.source.a),r=e.get(this.fogColor),a=e.get(F("fogFar")),n=e.get(F("fogNear")),o=e.get(F("fogDensity")),l=e.get(j(L.mvPosition.z));return{pars:"\n ",chunk:`\n #ifdef FOG_EXP2\n float fogFactor_${t} = 1.0 - exp( - ${o} * ${o} * ${l} * ${l} );\n #else\n float fogFactor_${t} = smoothstep( ${n}, ${a}, ${l} );\n #endif\n vec4 color_vec4_${t} = vec4(mix(${s}, ${r}, fogFactor_${t}), ${i});\n `,out:`color_vec4_${t}`}}}/*
|
|
1
|
+
var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as r,Material as a,Matrix4 as n,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as d,WebGLRenderTarget as u,Texture as c,Euler as p,MeshStandardMaterial as m}from"three";import{CopyShader as f,EffectComposer as g,FXAAShader as v,GammaCorrectionShader as M,LUTPass as T,RenderPass as b,ShaderPass as x,VRButton as P}from"three-stdlib";import{CSMShader as y,CSMUtil as w}from"./csm.js";import{bool as S,colorToNormal as R,float as C,NodeShaderMaterial as A,standardMaterial as F,uniformFloat as U,uniformVec3 as E,toonMaterial as O,lambertMaterial as B,normalize as I,rgb as D,rgba as W,textureSampler2d as L,transformed as j,varying as V,varyingAttributes as _,varyingTransformed as G,vec4 as q,BooleanExpression as k,select as N,ifDefApply as H,uniformSampler2d as z,RgbaNode as $}from"three-shader-graph";import{Reflector as X}from"three-stdlib";import{BokehPass as Y,OutputPass as Q}from"three/examples/jsm/Addons.js";import{CSM as K}from"three/examples/jsm/csm/CSM.js";import J from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as Z}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as ee}from"typedi";import{depthUniformName as te,farUniformName as se,nearUniformName as ie,resolutionUniformName as re,sceneNormalUniformName as ae,screenUV as ne,supportsDepthTextureExtension as oe}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as le}from"./shader-nodes/time.js";import{aoMapUniformName as he,sceneMapUniformName as de}from"./shader-nodes/scene-sample.js";import{DepthPass as ue}from"./utils/three/depth-pass.js";import{GPUStatsPanel as ce}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as pe}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as me,traverseVisibleStop as fe}from"./utils/three/traverse.js";import{clamp as ge}from"./utils/math.js";import{ColorPass as ve}from"./rendering/color-pass.js";import{SSRPass as Me}from"./rendering/ssr/SSRPass.js";import{SSRShader as Te}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as be}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as xe}from"./rendering/outline-effect.js";import{UnrealBloomPass as Pe}from"./rendering/bloom/UnrealBloomPass.js";import{highPrecisionEyeDepth as ye}from"./shader-nodes/depth";import{packDepthToRGBA as we}from"three-shader-graph";import{FogVolumeObject as Se}from"./rendering/fog/fog-volume-object";import{ParallaxStandardMaterial as Re}from"./shader/builtin/standard-shader.js";import{parallaxOcclusionMapping as Ce}from"./shader-nodes/pom.js";import{FullScreenQuad as Ae}from"three-stdlib";import{edgeDepthEffect as Fe}from"./shader-nodes/effects";import{decalDiscard as Ue}from"./shader-nodes/decal.js";import{Pass as Ee}from"three/examples/jsm/Addons.js";w.patchSetupMaterial();const Oe=document.createElement("div");Oe.style.position="absolute",Oe.style.left="50%",Oe.style.top="50%",Oe.style.color="black",Oe.style.zIndex="999";(new i.Layers).set(9);const Be=new i.MeshBasicMaterial({color:"black"}),Ie=new i.MeshDepthMaterial;var De;Ie.depthPacking=i.RGBADepthPacking,Ie.blending=i.NoBlending,Ie.side=i.DoubleSide,function(e){e[e.opaque=0]="opaque",e[e.transparent=1]="transparent"}(De||(De={}));const We=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let Le=e=class{setPaused(e){this.paused=e}resizeRender(){const e=this.container.clientWidth,t=this.container.clientHeight;this.previousClientWith===e&&this.previousClientHeight===t||0!==e&&0!==t&&(this.previousClientWith=e,this.previousClientHeight=t,this.camera instanceof l&&(this.camera.aspect=e/t,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(e,t),this.composer.setSize(e*this.resolutionScale,t*this.resolutionScale),this.dofPass.setSize(e*this.resolutionScale,t*this.resolutionScale),this.fxaaPass.setSize(e*this.renderer.getPixelRatio(),t*this.renderer.getPixelRatio()),this.fxaaPass.uniforms.resolution.value.set(1/(e*this.renderer.getPixelRatio()),1/(t*this.renderer.getPixelRatio())),this.createGRenderTarget(),this.phasedRenderPass.gRenderTarget=this.gRenderTarget,this.bloomPass.emissiveTexture=this.gRenderTarget.textures[1],this.ssrPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.aoPass.setSize(e*this.resolutionScale,t*this.resolutionScale),this.aoPass.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container),this.copyPass.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass.material.uniformsNeedUpdate=!0)}addPostProcessVolume(e){if(0===this.postProcessVolumes.length)this.postProcessVolumes.push(e);else{let t=!1;for(let s=0;s<this.postProcessVolumes.length;s++)if(e.priority<this.postProcessVolumes[s].priority){this.postProcessVolumes.splice(s,0,e),t=!0;break}t||this.postProcessVolumes.push(e)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}constructor(t,s={}){this.container=t,this.options=s,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.postProcessVolumes=[],this.postProcessSettings={},this.fquadCopy=new Ae(new d(f)),this.fquadCopyOpaque=new Ae(new A({outputs:[z("tSceneColor",new c).sample(ne),q(z("tDepthTexture",new i.DepthTexture(1,1)).sample(ne).r)]})),this.fquadBlendAO=(()=>{const e=q(1),t=new A({outputs:[z("tAO",new c).sample(ne),e,e],transparent:!0});t.depthWrite=!1,t.depthTest=!1,t.blending=i.MultiplyBlending;return new Ae(t)})(),this.resolutionScale=1,this.maxPixelRatio=We?1:window.devicePixelRatio,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!0,this.onLoopCallbacks=[],this.stats=new J,this._showStats=!0,this.gbufferMaterialCache=new Map,this.tbufferMaterialCache=new Map,this.pmremGeneratorResults=new WeakMap,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],this._customDepthMaterialCache=new WeakMap,null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),window.renderer=this.renderer=new i.WebGLRenderer({antialias:!1,powerPreference:"high-performance"});new i.MeshStandardMaterial({color:"#ccc"});this.scene=new i.Scene,this.scene.matrixWorldAutoUpdate=!0,this.scene.updateMatrixWorld=function(e){const t=this.children;for(let s=0,i=t.length;s<i;s++){t[s].updateMatrixWorld(e)}}.bind(this.scene),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(P.createButton(this.renderer));const a=new xe(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=a,this.createGRenderTarget(),this.composer=new g(this.renderer);var n=(t.clientWidth||1)/(t.clientHeight||1);const o=new i.PerspectiveCamera(45,n,.5,800);o.layers.enable(19),this.setCamera(o),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,w.renderingView=this,this.isDepthTextureExtensionSupported=oe(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=this.createSceneColorRenderTarget(this.renderer,this.container);const l=new i.Vector2(t.clientWidth,t.clientHeight),h=(new b(this.scene,this.camera),new x(f,"prevtexture"));h.enabled=!0,h.needsSwap=!0,h.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[0],this.copyPass=h;const u=new Pe(l,1.5,.4,.85);u.threshold=1,u.strength=.9,u.radius=.5,this.bloomPass=u;const p=new Z(this.scene,this.camera,t.clientWidth,t.clientWidth,{});p.normalRenderTarget?.dispose(),p.setGBuffer(this.gRenderTarget.depthTexture,this.gRenderTarget.textures[2]),p.output=Z.OUTPUT.Off,p.enabled=!1,this.aoPass=p,this.fquadBlendAO.material.uniforms.tAO.value=p.pdRenderTarget.texture,Te.fragmentShader=Te.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const m=new Me({renderer:this.renderer,scene:this.scene,camera:this.camera,groundReflector:null,selects:[],normalTexture:this.gRenderTarget.textures[2],depthTexture:this.gRenderTarget.depthTexture});m.output=Me.OUTPUT.Default,m.blur=!0,m.fresnel=!1,m.distanceAttenuation=!0,m.maxDistance=50,m.selective=!0,m.bouncing=!1,m.opacity=.4,m.enabled=!1!==this.options?.reflection?.enabled,this.ssrPass=m,!1!==this.options.ao?.enabled&&this.composer.addPass(p);const y=new et((e,t,s,i,r)=>{this.aoPass.enabled&&(this.initResolutionUniform(this.fquadBlendAO.material),this.renderer.setRenderTarget(this.gRenderTarget),this.fquadBlendAO.render(this.renderer),this.renderer.setRenderTarget(null))});this.composer.addPass(y);const S=new et((e,t,s,i,r)=>{this.renderer.setRenderTarget(this.gRenderTarget),this.renderScene(De.transparent),this.renderer.setRenderTarget(null)});this.composer.addPass(S),this.composer.addPass(h),this.composer.addPass(m),this.phasedRenderPass=new Ze(this.scene,this.camera,this.gRenderTarget),this.composer.addPass(this.phasedRenderPass),this.composer.addPass(u),u.emissiveTexture=this.gRenderTarget.textures[1],this.renderer.info.autoReset=!1,this.volumetricFogPass=new be(l),this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new Y(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const R=new ve;this.composer.addPass(R),this.colorPass=R,R.vignetteEnabled=!1,this.outlinePass=new pe(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.outlinePass.enabled=!1,this.composer.addPass(this.outlinePass);const C=new x(v);C.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(C),this.fxaaPass=C,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new x(M).clear=!1,this.fixStatsStyle(),this.lutPass=new T({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const F=new x(f,"prevtexture");F.enabled=!0,F.needsSwap=!1,F.material.uniforms.tDiffuse.value=this.gRenderTarget.textures[1],F.renderToScreen=!0;const U=new Q;this.composer.addPass(U)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setEnableOutlines(e){this.outlinePass.enabled=e,this.fxaaPass.enabled=e}setCamera(e){this.camera=e,this.composer.passes.forEach(t=>{t instanceof b?t.camera=e:t instanceof pe?t.renderCamera=e:(t instanceof ue||t instanceof Z)&&(t.camera=e)}),this.ssrPass&&(this.ssrPass.camera=e),this.aoPass&&(this.aoPass.camera=e),this.phasedRenderPass&&(this.phasedRenderPass.camera=e),null==this.csm?(this.csm=new K({maxFar:100,lightFar:250,lightMargin:20,cascades:We?2:4,shadowMapSize:2048*(We?.5:1),lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene,mode:"practical"}),this.csm&&Array.isArray(this.csm.lights),this.csm.fade=!0,h.lights_fragment_begin=y.lights_fragment_begin):(this.csm.camera=this.camera,this.camera),this.csm.updateFrustums()}setSelectedObjects(e){if(null==this.outlinePass)return;const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse(e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)});this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t,s){const r=new i.WebGLRenderTarget(t.clientWidth*s,t.clientHeight*s);return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,r.depthTexture=new i.DepthTexture(128,128),r.depthTexture.type=i.UnsignedShortType,r.depthTexture.minFilter=i.NearestFilter,r.depthTexture.magFilter=i.NearestFilter,r}static createAOMaskDepthRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:i.HalfFloatType});return s.texture.minFilter=i.NearestFilter,s.texture.magFilter=i.NearestFilter,s.texture.generateMipmaps=!1,s.stencilBuffer=!1,s.depthTexture=new i.DepthTexture(128,128),s.depthTexture.type=i.UnsignedInt248Type,s.depthTexture.minFilter=i.NearestFilter,s.depthTexture.magFilter=i.NearestFilter,s}createSceneColorRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*this.renderer.getPixelRatio(),t.clientHeight*this.renderer.getPixelRatio(),{count:2,type:i.FloatType,format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,depthBuffer:!1,stencilBuffer:!1});return s.texture.minFilter=i.LinearFilter,s.texture.magFilter=i.LinearFilter,s.texture.generateMipmaps=!1,s}createGRenderTarget(){const e=this.container;null!=this.gRenderTarget&&this.gRenderTarget.dispose(),this.gRenderTarget=new u(e.clientWidth*this.renderer.getPixelRatio(),e.clientHeight*this.renderer.getPixelRatio(),{count:3,minFilter:i.NearestFilter,magFilter:i.NearestFilter,type:i.HalfFloatType,format:i.RGBAFormat}),this.gRenderTarget.depthTexture=new i.DepthTexture(e.clientWidth,e.clientHeight),this.gRenderTarget.depthTexture.type=i.UnsignedIntType,this.gRenderTarget.depthTexture.minFilter=i.NearestFilter,this.gRenderTarget.depthTexture.magFilter=i.NearestFilter,this.gRenderTarget.texture.generateMipmaps=!1,this.gRenderTarget.stencilBuffer=!1}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.gRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren(),this.volumetricFogPass.dispose(),w.clearSceneCache(this.scene)}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){if(null!=this.scene.environment&&(e instanceof A&&(null==e.envMap||e.userData.useSceneEnv)&&(e.userData.useSceneEnv=!0,null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment},e.uniformsNeedUpdate=!0,e.uniforms.envMapRotation={value:ze(this.scene.environmentRotation,this.scene.environment,new i.Matrix3)}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1},e.uniformsNeedUpdate=!0),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment),e instanceof A||e instanceof i.MeshStandardMaterial)){const t=this.gbufferMaterialCache.get(e);null==t||this.gbufferMaterialCache.has(t)||this.applyEnvMap(t)}}setupCsm(e){if(e instanceof i.Mesh||e instanceof i.SkinnedMesh)if(e.material instanceof Array)for(const t of e.material)this.csm.setupMaterial(t);else this.csm.setupMaterial(e.material)}updateUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e in s){const t=i[e],r=s[e].value;null!=t&&t.value!==r&&(t.value=r)}}updateLightUniformValues(e,t){const s=e.uniforms,i=t.uniforms;for(const e of tt){const t=i[e],r=s[e];null!=r&&null!=t&&(t.value=r.value)}}createGBufferMaterial(e,t){const s=t===De.opaque?this.gbufferMaterialCache:this.tbufferMaterialCache;let r=s.get(e);if(null==r){let n=_.uv;e instanceof Re&&null!=e.heightMap&&(n=Ce(n,L(e.heightMap),C(e.heightScale??1)));let o=G.normal;e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial?null!=e.normalMap&&(o=R(L(e.normalMap).sample(n),e.normalScale.x??1)):e instanceof A&&null!=e.outputNormal&&(o=e.outputNormal),!0!==e.userData.disableAO&&(o=H("DOUBLE_SIDED",o,e=>N(new k("gl_FrontFacing"),e,e.multiplyScalar(-1))));let l=e.userData?.reflective?C(0):C(1);if(e instanceof i.MeshStandardMaterial){const t=U("roughness",e.roughness??1);l=null!=e.roughnessMap?L(e.roughnessMap).sample(n).g.multiply(t):t}else e instanceof A&&null!=e.outputRoughness&&(l=e.outputRoughness);let h=null;(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial)&&null!=e.lightMap&&(h=L(e.lightMap).sample(n).rgb.multiplyScalar(e.lightMapIntensity));let u,c=C(0);if(e instanceof i.MeshStandardMaterial){const t=U("metalness",e.metalness??0);c=null!=e.metalnessMap?L(e.metalnessMap).sample(n).b.multiply(t):t}else e instanceof A&&e.outputRoughness;let p=C(1);e instanceof i.MeshStandardMaterial?null!=e.aoMap&&(u=L(e.aoMap).sample(n).r,p=U("aoMapIntensity",e.aoMapIntensity)):e instanceof A&&e.outputRoughness;const f=U("opacity",e.opacity??1);let g=C(1);e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshBasicMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial?(null!=e.alphaMap&&(g=L(e.alphaMap).sample(n).r),g=g.multiply(f)):e instanceof A&&null!=e.outputOpacity&&(g=e.outputOpacity);let v=W(0,1);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial||e instanceof i.MeshBasicMaterial){const t=E("color",(new i.Vector3).setFromColor(e.color));null!=e.map?(v=L(e.map).sample(n).multiply(W(t,1)),g=g.multiply(v.w)):v=W(t,1)}const M=!0===e.userData.hasBloom;let T=D(0);if(e instanceof i.MeshStandardMaterial||e instanceof i.MeshLambertMaterial||e instanceof i.MeshToonMaterial||e instanceof i.MeshPhongMaterial){const t=E("emissive",(new i.Vector3).setFromColor(e.emissive));T=null!=e.emissiveMap?L(e.emissiveMap).sample(n).rgb.multiply(t):t,T=T.multiplyScalar(e.emissiveIntensity)}else e instanceof A&&null!=e.outputEmissive&&(T=e.outputEmissive);const b=e instanceof d&&null!=e.uniforms[te],x=e instanceof d&&null!=e.uniforms[de],P=e instanceof d&&null!=e.uniforms[he],y=e.transparent&&e.alphaTest<=.01||e.blending===i.AdditiveBlending,w=U("alphaTest",e.alphaTest);let j,V=e.alphaTest>0?g.lt(w):y&&t===De.opaque?g.lt(.8):S(!1);!0===e.userData.isDecal&&(V=V.or(Ue)),j=y?q(0,0,0,0):(a=o,I(a).multiplyScalar(.5).addScalar(.5)).rgba(l);const z=e instanceof A?e.outputPosition:void 0,$=e instanceof A?e.outputTransform:void 0;let X,Y=W("black",1);if(e instanceof A&&null!=e.outputColor)Y=e.outputColor;else if(e instanceof i.MeshStandardMaterial)Y=F({color:v,metalness:c,roughness:l,emissive:T.rgb,normal:o,ambientOcclusion:u,ambientOcclusionIntensity:p,bakedLight:h});else if(e instanceof i.MeshLambertMaterial||e instanceof i.MeshPhongMaterial)Y=B({color:v.rgb});else if(e instanceof i.MeshBasicMaterial){let e=v.rgb,t=h??D("white");null!=u&&(t=t.multiplyScalar(u.subtract(1).multiply(p).add(1))),e=e.multiply(t),Y=e.rgba(g)}else e instanceof i.MeshToonMaterial&&(Y=O({color:v,emissive:T.rgb,normal:o,ambientOcclusion:u,ambientOcclusionIntensity:p,bakedLight:h}));(e instanceof A||e instanceof i.MeshStandardMaterial)&&(X=e.envMap);let Q=!0;(e instanceof m||e instanceof i.MeshBasicMaterial||e instanceof i.ShaderMaterial)&&(Q=e.fog);let K=W(Y.rgb,g);Q&&(K=new FogNode(K)),r=new A({transform:$,position:null==$?z:void 0,outputs:[K,T.rgba(t===De.opaque?w:M?1:0),j],opacity:g,outputEncoding:!1,fog:Q,transparent:e.transparent,lights:!0,envMap:X,discard:V}),e instanceof i.MeshStandardMaterial&&null!=e.envMap&&null!=r.uniforms.envMapIntensity&&(r.uniforms.envMapIntensity.value=e.envMapIntensity),(e instanceof A||e instanceof i.MeshStandardMaterial)&&this.applyEnvMap(r),e instanceof A&&Object.assign(r.defines,e.defines),r.userData.mrtOutputs=3,r.forceSinglePass=e.forceSinglePass,r.side=e.side,r.blending=e.blending,y?(r.depthWrite=!e.transparent,r.depthTest=e.depthTest,r.colorWrite=t===De.transparent):(r.depthWrite=e.depthWrite,r.depthTest=e.depthTest),r.visible=e.visible,r.alphaTest=e.alphaTest,r.alphaHash=e.alphaHash,t===De.opaque?(r.visible&&(r.visible=!b&&!x&&!P),r.visible&&(r.visible=!y)):t===De.transparent&&r.visible&&(r.visible=y||b||x||P),Object.assign(r.userData,e.userData),r.visible&&(this.csm.setupMaterial(r),e instanceof d&&Object.assign(r.uniforms,e.uniforms)),s.set(e,r)}var a;return r.visible&&e instanceof d&&this.updateUniformValues(e,r),r}loop(e,t=!1){const s=this.stats,r=s.addPanel(new J.Panel("Calls","#83f","#002")),a=s.addPanel(new J.Panel("Triangles","#c32","#002"));let l;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(l=new ce(this.renderer.getContext()),s.addPanel(l)),this.showStats=t;let h=10,d=1e3;const u=()=>{const e=this.renderer.info.render.calls;e>h&&(h=e,setTimeout(()=>h=10,5e3)),r.update(e,h);const t=this.renderer.info.render.triangles;t>d&&(d=t,setTimeout(()=>d=1e3,5e3)),a.update(t,d)};performance.now();i.Ray.prototype.intersectTriangle;this.resizeRender();const c=[],p=[],m=[];let f=0;const g=new n,v=new n;let M=0;let T=this.paused;const b=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return setTimeout(()=>b(t),500),void(T=!0);this.renderer.clear(),this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,s.begin(),this.showStats&&l?.startQuery(),this.ssrPass.gpuPanel=l;let a=(t*=.001)-f;if(f=t,T&&(a=.016,T=!1),g.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(je),t-=je;e(t)}else e(a);this.onLoopCallbacks.forEach(e=>e(a)),this.camera?.updateMatrixWorld(),v.copy(this.camera.matrixWorld),t-M>.08&&!v.equals(g)&&(this.renderer.shadowMap.needsUpdate=!0,M=t),this.csm.update();let n=!1;c.length=0,p.length=0,m.length=0;const h=_e;qe.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),h.setFromProjectionMatrix(qe);let d=!1,x=!1,P=!1;this.scene.traverseVisible(e=>{if(this.setupCsm(e),this.outlineEffect.apply(e),e instanceof Se&&(d=!0),e instanceof o&&this.initCustomDepthMaterial(e),(e instanceof o||e instanceof i.Sprite)&&(this.initResolutionUniform(e.material),this.initNormalUniform(e.material),this.initShadowUniform(e,e.material),null!=this.scene.environment&&function(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}(e,e=>this.applyEnvMap(e)),!0===e.material?.userData?.hasBloom&&(n=!0)),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[te])&&isObjectInFrustum(e,h)?(this.initDepthUniform(e.material),x=!0):e instanceof X&&(e.visible=!1,p.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[he]&&isObjectInFrustum(e,h)&&e.material instanceof A&&this.initAoUniform(e.material),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[de]&&isObjectInFrustum(e,h)&&(m.push(e),e.material.uniforms[de].value=this.sceneColorRenderTarget.texture,P=!0),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[le])e.material.uniforms[le].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const s of e.material)s.uniforms&&null!=s.uniforms[le]&&(s.uniforms[le].value=t)}),this.bloomPass.enabled=n,this.renderer.setRenderTarget(this.gRenderTarget),this.renderer.clear(),this.renderScene(De.opaque),this.aoPass.output=Z.OUTPUT.Off,(x||P)&&(this.fquadCopyOpaque.material.uniforms.tSceneColor.value=this.gRenderTarget.textures[0],this.fquadCopyOpaque.material.uniforms.tDepthTexture.value=this.gRenderTarget.depthTexture,this.initResolutionUniform(this.fquadCopyOpaque.material),this.renderer.setRenderTarget(this.sceneColorRenderTarget),this.renderer.clear(),this.fquadCopyOpaque.render(this.renderer),this.renderer.setRenderTarget(this.gRenderTarget)),m.length,c.forEach(e=>e.visible=!0),p.forEach(e=>e.visible=!0),m.forEach(e=>e.visible=!0),this.aoPass.enabled,this.ssrPass&&(this.ssrPass.elapsedTime=t),this.volumetricFogPass&&d&&this.volumetricFogPass.update(this.camera,this.gRenderTarget,this.csm,this.scene);try{!this.paused&&this.running&&(this.render(a),this.showStats&&l?.endQuery(),this.showStats&&u(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}s.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout(()=>{requestAnimationFrame(b)},1e3/this.fpsCap):requestAnimationFrame(b))};!0===this.options.enableXR?this.renderer.setAnimationLoop(b):requestAnimationFrame(b)}renderScene(e){Ye.clear(),Qe.length=0;fe(this.scene,t=>{if(Ke(t))return Qe.push(t),t.visible=!1,!1;if(t instanceof o){Ye.set(t,t.material);let s=!1;if(Array.isArray(t.material)){t.material=t.material.slice();for(let i=0;i<t.material.length;i++)t.material[i]=this.createGBufferMaterial(t.material[i],e),s||(s=t.material[i].visible)}else t.material=this.createGBufferMaterial(t.material,e),s||(s=t.material.visible);s?t.visible=!0:null!=t.children&&0!=t.children.length||(Qe.push(t),t.visible=!1)}});const t=this.scene.matrixWorldAutoUpdate,s=this.scene.matrixAutoUpdate,i=this.renderer.shadowMap.autoUpdate;e!==De.opaque&&(this.renderer.shadowMap.autoUpdate=!1,this.scene.matrixWorldAutoUpdate=!1,this.scene.matrixAutoUpdate=!1);try{this.renderer.render(this.scene,this.camera)}catch(e){console.warn("Render failed",e)}e===De.opaque&&Ye.forEach((e,t)=>{!Array.isArray(e)&&!Array.isArray(t.material)&&e instanceof d&&this.updateLightUniformValues(t.material,e)}),Ye.forEach((e,t)=>{t.material=e}),Qe.forEach((e,t)=>{e.visible=!0,e.updateMatrixWorld(!0)}),this.renderer.shadowMap.autoUpdate=i,this.scene.matrixWorldAutoUpdate=t,this.scene.matrixAutoUpdate=s}getEnvTexture(e){null==this.pmremGenerator&&(this.pmremGenerator=new i.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader());let t=this.pmremGeneratorResults.get(e);return null==t&&(t=this.pmremGenerator.fromEquirectangular(e).texture,this.pmremGeneratorResults.set(e,t)),t.colorSpace=i.SRGBColorSpace,t}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return this.lutPass.enabled=!1,void(this.colorPass.enabled=!1);var e;(e=this.postProcessSettings).tonemapMapping=void 0,e.tonemapExposure=1,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=new i.Color("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.lut=void 0,e.lutIntensity=0;const t=this.postProcessSettings;let s,r=!1,a=!1,n=!1,o=!1;if(null==this.camera)return;const h=this.camera.getWorldPosition(ke);let d=[];for(const e of this.postProcessVolumes){if(!Ve(e.object))continue;let l=e.blendWeight??1;const u=e.distanceToPoint(h);u>e.blendRadius||(e.blendRadius>0&&(l*=ge(1-u/e.blendRadius,0,1)),l>1&&(l=1),l>0&&(d.push(e),void 0!==e.settings.tonemapMapping&&(t.tonemapMapping=e.settings.tonemapMapping),void 0!==e.settings.tonemapExposure&&(t.tonemapExposure=i.MathUtils.lerp(t.tonemapExposure,e.settings.tonemapExposure,l)),void 0!==e.settings.envTexture&&(t.envTexture=e.settings.envTexture),void 0!==e.settings.envIntensity&&(t.envIntensity=i.MathUtils.lerp(t.envIntensity,e.settings.envIntensity,l)),void 0!==e.settings.vignetteIntensity&&(t.vignetteIntensity=i.MathUtils.lerp(t.vignetteIntensity,e.settings.vignetteIntensity,l),a=!0),void 0!==e.settings.colorTint&&void 0!==e.settings.colorTintIntensity&&e.settings.colorTintIntensity>0&&(t.colorTint=t.colorTint.lerp(e.settings.colorTint,l),o=!0),void 0!==e.settings.colorTintIntensity&&(t.colorTintIntensity=i.MathUtils.lerp(t.colorTintIntensity,e.settings.colorTintIntensity,l)),void 0!==e.settings.depthFocus&&(r=!0,t.depthFocus=void 0!==t.depthFocus?i.MathUtils.lerp(t.depthFocus,e.settings.depthFocus,l):e.settings.depthFocus),void 0!==e.settings.depthAperture&&(r=!0,t.depthAperture=void 0!==t.depthAperture?i.MathUtils.lerp(t.depthAperture,e.settings.depthAperture,l):e.settings.depthAperture),void 0!==e.settings.depthMaxBlur&&(r=!0,t.depthMaxBlur=void 0!==t.depthMaxBlur?i.MathUtils.lerp(t.depthMaxBlur,e.settings.depthMaxBlur,l):e.settings.depthMaxBlur),void 0!==e.settings.temperature&&(t.temperature=i.MathUtils.lerp(t.temperature,e.settings.temperature,l)),void 0!==e.settings.temperatureTint&&(t.temperatureTint=i.MathUtils.lerp(t.temperatureTint,e.settings.temperatureTint,l)),void 0!==e.settings.lut&&(s=e.settings.lut,n=!0),void 0!==e.settings.lutIntensity&&(t.lutIntensity=i.MathUtils.lerp(t.lutIntensity,e.settings.lutIntensity,l),n=!0)))}this.renderer.toneMapping=t.tonemapMapping??i.NoToneMapping,this.renderer.toneMappingExposure=t.tonemapExposure,null!=t.envTexture&&(this.scene.environment=this.getEnvTexture(t.envTexture)),this.scene.environmentIntensity=t.envIntensity,this.colorPass.vignetteIntensity=t.vignetteIntensity,this.colorPass.vignetteEnabled=a,this.colorPass.colorTint=t.colorTint,this.colorPass.colorTintIntensity=t.colorTintIntensity,this.colorPass.enabled=a||o,r&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==t.depthFocus&&(this.dofPass.uniforms.focus.value=t.depthFocus),void 0!==t.depthAperture&&(this.dofPass.uniforms.aperture.value=t.depthAperture),void 0!==t.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=t.depthMaxBlur)):this.dofPass.enabled=!1,this.colorPass.temperature=t.temperature,this.colorPass.temperatureTint=t.temperatureTint,this.lutPass.enabled=n,n&&(null!=s&&(s.flipY=!0,s.generateMipmaps=!1),this.lutPass.lut=s,this.lutPass.intensity=t.lutIntensity)}renderOverlay(){if(0===this.overlayCameras.size)return;const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.previousClientWith/2,s=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let i=0;i<e.length;i++)this.renderer.clearDepth(),this.renderer.setViewport(t-s/2+this.insetWidth*i+this.insetMargin*i,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[i])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){if(0===this.composer.renderTarget1.width||0===this.composer.renderTarget1.height)return;if(0===this.composer.renderTarget2.width||0===this.composer.renderTarget2.height)return;let t=!1;if(this.ssrPass.enabled&&!1!==this.options?.reflection?.enabled){const e=this.ssrPass.selects??[];e.length=0,this.scene.traverseVisible(t=>{t instanceof o&&!0===t.material.userData?.reflective&&isObjectInFrustum(t,_e)&&e.push(t)}),this.ssrPass.selects=e,0==e.length&&(this.ssrPass.enabled=!1),t=!0}this.options.bloom,this.composer.render(e),this.scene.matrixWorldAutoUpdate=!0,this.scene.matrixAutoUpdate=!0,t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=me(this.scene,e=>e instanceof o&&!0===e.material?.userData?.hasBloom)}darkenNonBloomed(e){if((e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)){if(e.material?.id===Be.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=Be:(e.visible=!1,this.bloomHidden.push(e))}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof d&&(e.uniforms[te].value=this.sceneColorRenderTarget.textures[1],this.camera instanceof l&&(null!=e.uniforms[ie]&&(e.uniforms[ie].value=this.camera.near),null!=e.uniforms[se]&&(e.uniforms[se].value=this.camera.far)))}initNormalUniform(e){e instanceof d&&null!=e.uniforms[ae]&&(e.uniforms[ae].value=this.gRenderTarget.textures[2])}initShadowUniform(e,t){t instanceof A&&t.uniforms.receiveShadow&&(t.uniforms.receiveShadow.value=e.receiveShadow)}initResolutionUniform(e){if(e instanceof d&&null!=e.uniforms[re]){const t=this.previousClientWith,s=this.previousClientHeight;e.uniforms[re].value.set(t*this.renderer.getPixelRatio(),s*this.renderer.getPixelRatio())}}initAoUniform(e){if(this.aoPass.enabled){e.uniforms[he].value=this.aoPass.pdRenderTarget.texture,null==e.defines.USE_SSAO_MAP&&(e.defines.USE_SSAO_MAP="",e.needsUpdate=!0),e.defines.USE_SSAO_MAP="";const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}else if(null!=e.defines.USE_SSAO_MAP){delete e.defines.USE_SSAO_MAP,e.needsUpdate=!0;const t=this.tbufferMaterialCache.get(e);null!=t&&this.initAoUniform(t)}}initCustomDepthMaterial(e){if(null!=e.customDepthMaterial||!e.castShadow)return;const t=e.material;if(t instanceof A&&!t.transparent&&t.depthWrite){let s=this._customDepthMaterialCache.get(t);if(null==s){const e=we(ye);let i;null!=t.alphaTest&&t.alphaTest>0&&null!=t.outputOpacity&&(i=t.outputOpacity.lt(t.alphaTest)),s=new A({color:e,discard:i}),this._customDepthMaterialCache.set(t,s)}e.customDepthMaterial=s}}};Le=e=t([ee(),s("design:paramtypes",[HTMLElement,Object])],Le);export{Le as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const je=.05;function Ve(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}Z.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse(function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls||e.isSprite)&&(e.visible=!1),null!=e.material){let t=!1,s=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0?t=!0:!0===e.material.userData.isDecal&&(s=!0);s&&(e.visible=!1)}})};const _e=new i.Frustum,Ge=new i.Box3,qe=new i.Matrix4;export function isObjectInFrustum(e,t){const s=Ge.setFromObject(e);return t.intersectsBox(s)}const ke=new i.Vector3;const Ne=new n,He=new p;function ze(e,t,s=new i.Matrix3){return He.copy(e),He.x*=-1,He.y*=-1,He.z*=-1,t.isCubeTexture&&!1===t.isRenderTargetTexture&&(He.y*=-1,He.z*=-1),s.setFromMatrix4(Ne.makeRotationFromEuler(He))}const $e=new A({outputs:[q(0,0,0,0),q(0,0,0,0),W(D("white"),Fe(4))],transparent:!0}),Xe=new i.MeshBasicMaterial({color:"blue",transparent:!0,opacity:.5});$e.depthWrite=!1;new o(new i.BoxGeometry(4,4,4),Xe);const Ye=new Map,Qe=[];function Ke(e){return e instanceof i.Sprite||e.isPoints||e.isLine||e.isTransformControls||e.isTransformControlsGizmo||e instanceof o&&Je(e,e.material)}function Je(e,t){return null==t||(Array.isArray(t)?t.some(t=>Je(e,t)):t instanceof i.RawShaderMaterial||t instanceof i.ShaderMaterial&&!(t instanceof A))}class Ze extends Ee{constructor(e,t,s){super(),this.scene=e,this.camera=t,this.gRenderTarget=s,this.needsSwap=!1}render(e,t,s,i,r){const a=e.autoClear;e.autoClear=!1;const n=this.scene.matrixWorldAutoUpdate,l=this.scene.matrixAutoUpdate,h=e.shadowMap.autoUpdate;this.scene.matrixAutoUpdate=!1,e.shadowMap.autoUpdate=!1;const d=s.depthTexture;s.depthTexture=this.gRenderTarget.depthTexture,e.setRenderTarget(s),Qe.length=0;let u=0;this.scene.traverseVisible(e=>{const t=Ke(e);e instanceof o&&!t?(Qe.push(e),e.visible=!1):t&&u++}),u>0&&e.render(this.scene,this.camera),Qe.forEach((e,t)=>{e.visible=!0}),e.setRenderTarget(null),e.autoClear=a,s.depthTexture=d,this.scene.matrixWorldAutoUpdate=n,this.scene.matrixAutoUpdate=l,e.shadowMap.autoUpdate=h}}class et extends Ee{constructor(e){super(),this.fn=e}render(e,t,s,i,r){this.fn(e,t,s,i,r)}}const tt=["ambientLightColor","cameraNear","directionalLightShadows","directionalLights","directionalShadowMap","directionalShadowMatrix","fogColor","fogDensity","fogFar","fogNear","hemisphereLights","lightProbe","ltc_1","ltc_2","pointLightShadows","pointLights","pointShadowMap","pointShadowMatrix","rectAreaLights","shadowFar","spotLightMap","spotLightMatrix","spotLightShadows","spotLights","spotShadowMap"],st=E("fogColor");export class FogNode extends ${constructor(e,t=st){super(),this.source=e,this.fogColor=t}compile(e){const t=e.variable(),s=e.get(this.source.rgb),i=e.get(this.source.a),r=e.get(this.fogColor),a=e.get(U("fogFar")),n=e.get(U("fogNear")),o=e.get(U("fogDensity")),l=e.get(V(j.mvPosition.z));return{pars:"\n ",chunk:`\n #ifdef FOG_EXP2\n float fogFactor_${t} = 1.0 - exp( - ${o} * ${o} * ${l} * ${l} );\n #else\n float fogFactor_${t} = smoothstep( ${n}, ${a}, ${l} );\n #endif\n vec4 color_vec4_${t} = vec4(mix(${s}, ${r}, fogFactor_${t}), ${i});\n `,out:`color_vec4_${t}`}}}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|