@hology/core 0.0.210 → 0.0.212
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/sequence/sequence-player.js +1 -1
- package/dist/effects/vfx/initializsers.d.ts +8 -1
- package/dist/effects/vfx/initializsers.js +1 -1
- package/dist/effects/vfx/vfx-collision-behaviour.js +1 -1
- package/dist/effects/vfx/vfx-defs.d.ts +10 -1
- package/dist/effects/vfx/vfx-defs.js +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/effects/vfx/vfx-renderers.d.ts +1 -0
- package/dist/effects/vfx/vfx-renderers.js +1 -1
- package/dist/gameplay/actors/actor.d.ts +23 -1
- package/dist/gameplay/actors/actor.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-animation.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-movement-like.d.ts +23 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement-like.js +4 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement-policy.d.ts +26 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement-policy.js +4 -0
- package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts +145 -55
- package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
- package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.d.ts +125 -0
- package/dist/gameplay/actors/builtin/components/character/net-character-movement-protocol.js +4 -0
- package/dist/gameplay/actors/builtin/components/character/old-character-movement.d.ts +100 -0
- package/dist/gameplay/actors/builtin/components/character/old-character-movement.js +4 -0
- package/dist/gameplay/actors/builtin/components/index.d.ts +2 -0
- package/dist/gameplay/actors/builtin/components/index.js +1 -1
- package/dist/gameplay/actors/builtin/navmesh-actor.js +1 -1
- package/dist/gameplay/actors/camera/third-person-camera-component.d.ts +3 -0
- package/dist/gameplay/actors/camera/third-person-camera-component.js +1 -1
- package/dist/gameplay/actors/component.js +1 -1
- package/dist/gameplay/actors/controller/actor-controller.d.ts +16 -0
- package/dist/gameplay/actors/controller/actor-controller.js +4 -0
- package/dist/gameplay/actors/factory.d.ts +3 -0
- package/dist/gameplay/actors/factory.js +1 -1
- package/dist/gameplay/actors/index.d.ts +4 -0
- package/dist/gameplay/actors/index.js +1 -1
- package/dist/gameplay/actors/internal/component-init.js +1 -1
- package/dist/gameplay/ai/behavior-tree/move.d.ts +2 -2
- package/dist/gameplay/index.d.ts +3 -1
- package/dist/gameplay/index.js +1 -1
- package/dist/gameplay/initiate.d.ts +4 -0
- package/dist/gameplay/initiate.js +1 -1
- package/dist/gameplay/net/browser/index.d.ts +147 -0
- package/dist/gameplay/net/browser/index.js +4 -0
- package/dist/gameplay/net/index.d.ts +7 -0
- package/dist/gameplay/net/index.js +4 -0
- package/dist/gameplay/net/net-connection.d.ts +25 -0
- package/dist/gameplay/net/net-connection.js +4 -0
- package/dist/gameplay/net/net-session.d.ts +70 -0
- package/dist/gameplay/net/net-session.js +4 -0
- package/dist/gameplay/net/service/net-actor-role.d.ts +12 -0
- package/dist/gameplay/net/service/net-actor-role.js +4 -0
- package/dist/gameplay/net/service/net-decorator.d.ts +29 -0
- package/dist/gameplay/net/service/net-decorator.js +4 -0
- package/dist/gameplay/net/service/net-serializer.d.ts +15 -0
- package/dist/gameplay/net/service/net-serializer.js +4 -0
- package/dist/gameplay/net/service/net-service.d.ts +171 -0
- package/dist/gameplay/net/service/net-service.js +4 -0
- package/dist/gameplay/net/service/net-utils.d.ts +8 -0
- package/dist/gameplay/net/service/net-utils.js +4 -0
- package/dist/gameplay/net/service/replication.d.ts +31 -0
- package/dist/gameplay/net/service/replication.js +4 -0
- package/dist/gameplay/net/service/rpc-decorator.d.ts +21 -0
- package/dist/gameplay/net/service/rpc-decorator.js +4 -0
- package/dist/gameplay/net/service/rpc.d.ts +35 -0
- package/dist/gameplay/net/service/rpc.js +4 -0
- package/dist/gameplay/services/asset-loader.d.ts +3 -2
- package/dist/gameplay/services/asset-loader.js +1 -1
- package/dist/gameplay/services/physics/abstract-physics-system.d.ts +1 -1
- package/dist/gameplay/services/physics/physics-system.d.ts +4 -2
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/gameplay/services/world.d.ts +13 -2
- package/dist/gameplay/services/world.js +1 -1
- package/dist/rendering/color-pass.js +1 -1
- package/dist/rendering.d.ts +2 -0
- package/dist/rendering.js +1 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/batched-mesh-2.d.ts +9 -0
- package/dist/scene/batched-mesh-2.js +1 -1
- package/dist/scene/bootstrap.d.ts +2 -0
- package/dist/scene/bootstrap.js +1 -1
- package/dist/scene/custom-param-runtime-types.js +1 -1
- package/dist/scene/landscape/landscape-manager.d.ts +2 -1
- package/dist/scene/landscape/landscape-manager.js +1 -1
- package/dist/scene/materializer.d.ts +50 -1
- package/dist/scene/materializer.js +1 -1
- package/dist/scene/model.d.ts +2 -0
- package/dist/scene/scatter/painted-scatter-manager.d.ts +45 -0
- package/dist/scene/scatter/painted-scatter-manager.js +4 -0
- package/dist/scene/scatter/scatter-limits.d.ts +2 -0
- package/dist/scene/scatter/scatter-limits.js +4 -0
- package/dist/scene/scatter/surface-scatter-manager.js +1 -1
- package/dist/scene/storage/storage.d.ts +1 -1
- package/dist/scene/storage/storage.js +1 -1
- package/dist/shader/builtin/standard-shader.js +1 -1
- package/dist/shader/builtin/toon-shader.js +1 -1
- package/dist/shader/builtin/unlit-shader.js +1 -1
- package/dist/shader/color-layer.js +1 -1
- package/dist/shader/graph/compiler.d.ts +7 -4
- package/dist/shader/graph/compiler.js +1 -1
- package/dist/shader/graph/model.d.ts +1 -1
- package/dist/shader/graph/model.js +1 -1
- package/dist/shader/graph/parameters.js +1 -1
- package/dist/shader/parameter.d.ts +1 -1
- package/dist/shader/parameter.js +1 -1
- package/dist/shader/sprite-shader.js +1 -1
- package/dist/shader-nodes/depth.js +1 -1
- package/dist/shader-nodes/scene-sample.js +1 -1
- package/dist/test/batched-mesh-2.test.d.ts +2 -0
- package/dist/test/batched-mesh-2.test.js +4 -0
- package/dist/test/browser-net-session.test.d.ts +2 -0
- package/dist/test/browser-net-session.test.js +4 -0
- package/dist/test/first-person-camera-component.test.js +1 -1
- package/dist/test/net-character-movement.test.d.ts +2 -0
- package/dist/test/net-character-movement.test.js +4 -0
- package/dist/test/net-property-snapshot.test.d.ts +2 -0
- package/dist/test/net-property-snapshot.test.js +4 -0
- package/dist/test/painted-scatter-manager.test.d.ts +2 -0
- package/dist/test/painted-scatter-manager.test.js +4 -0
- package/dist/test/runtime-param-type-inference.test.js +1 -1
- package/dist/test/sequence-animation-retiming.test.js +1 -1
- package/dist/test/sequence-post-process.test.js +1 -1
- package/dist/test/shader-graph.test.js +1 -1
- package/dist/test/vfx-random-color-initializer.test.d.ts +2 -0
- package/dist/test/vfx-random-color-initializer.test.js +4 -0
- package/dist/test/world-prefab-spawn.test.d.ts +2 -0
- package/dist/test/world-prefab-spawn.test.js +4 -0
- package/dist/utils/three/placeholder-texture.d.ts +3 -0
- package/dist/utils/three/placeholder-texture.js +4 -0
- package/package.json +10 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{isCollisionMesh as e}from"../collision/collision-shape-import.js";import{grassGeometryTriangleLimit as t}from"
|
|
1
|
+
import{isCollisionMesh as e}from"../collision/collision-shape-import.js";import{grassGeometryTriangleLimit as t}from"./scatter-limits.js";import{MeshSurfaceSampler as s}from"three/examples/jsm/math/MeshSurfaceSampler.js";import{Euler as r,Group as a,InstancedMesh as i,Matrix3 as n,Matrix4 as o,Mesh as c,Quaternion as l,Triangle as h,Vector3 as u}from"three";const f=30,d=Math.sqrt(3*Math.pow(15,2)),p=new h,m=new u,w=new u,S=new u,g=new u,y=new u,M=new o,A=new o,b=new o,I=(new o,new u),R=(new u,new u),x=new u,v=new l,$=new u,C=new u(0,1,0),D=new u,P=(new o).makeRotationX(Math.PI/-2),j=new o;export class SurfaceScatterManager{constructor(e,t,s,r,i){this.scene=e,this.dataProvider=t,this.view=s,this.assetManagerService=r,this.assetService=i,this.scatterRoot=new a,this.onLoopHandler=()=>this.updateVisibility(),this.refreshQueued=!1,this.refreshInProgress=!1,this.forceRefresh=!1,this.visibilityLoopRegistered=!1,this.sourceAssetCache=new Map,this.scatterRenderAssetCache=new Map,this.referencedSceneObjectIds=new Set,this.referencedSourceAssetIds=new Set,this.referencedScatterAssetIds=new Set,this.referencedPrefabAssetIds=new Set,this.scatterRoot.name="Surface Scatter",this.scatterRoot.userData.surfaceScatterGenerated=!0,this.scene.add(this.scatterRoot)}usesSourceAsset(e){return this.referencedSourceAssetIds.has(e)}referencesSceneObject(e){return this.referencedSceneObjectIds.has(e)}usesScatterAsset(e){return this.referencedScatterAssetIds.has(e)}usesPrefabAsset(e){return this.referencedPrefabAssetIds.has(e)}queueRefresh(e=!1){this.refreshQueued=!0,this.forceRefresh=this.forceRefresh||e,this.refreshInProgress||this.flushRefreshQueue()}clear(){this.clearScatterMeshes(),this.sourceAssetCache.clear(),this.scatterRenderAssetCache.clear(),this.referencedSceneObjectIds.clear(),this.referencedSourceAssetIds.clear(),this.referencedScatterAssetIds.clear(),this.referencedPrefabAssetIds.clear(),this.setVisibilityLoopRegistered(!1),this.scatterRoot.parent?.remove(this.scatterRoot)}stop(){this.setVisibilityLoopRegistered(!1)}async flushRefreshQueue(){for(this.refreshInProgress=!0;this.refreshQueued;){const e=this.forceRefresh;this.refreshQueued=!1,this.forceRefresh=!1,await this.refreshScatter(e)}this.refreshInProgress=!1}async refreshScatter(e=!1){e&&(this.sourceAssetCache.clear(),this.scatterRenderAssetCache.clear()),this.clearScatterMeshes(),this.referencedSceneObjectIds.clear(),this.referencedSourceAssetIds.clear(),this.referencedScatterAssetIds.clear(),this.referencedPrefabAssetIds.clear();const t=await this.collectSurfaceScatterSources(this.dataProvider.getObjects());if(0===t.length)return void this.setVisibilityLoopRegistered(!1);const s=new Map;for(const e of t)await this.accumulateSource(e,s);for(const e of s.values()){const t=this.scatterRenderAssetCache.get(e.renderKey);if(null==t||0===e.matrices.length)continue;const s=new i(t.geometry,t.material,e.matrices.length);s.name=e.renderKey,s.userData.surfaceScatterGenerated=!0,s.userData.viewDistance=e.viewDistance,s.userData.cellCenter=e.center.clone(),s.castShadow=t.castShadow,s.receiveShadow=t.receiveShadow,s.raycast=()=>{};for(let t=0;t<e.matrices.length;t++)s.setMatrixAt(t,e.matrices[t]);s.instanceMatrix.needsUpdate=!0,"computeBoundingBox"in s&&s.computeBoundingBox(),"computeBoundingSphere"in s&&s.computeBoundingSphere(),this.scatterRoot.add(s)}this.setVisibilityLoopRegistered(this.scatterRoot.children.length>0),this.updateVisibility()}async accumulateSource(e,t){if(null==e.source.assetId)return;this.referencedSourceAssetIds.add(e.source.assetId);const s=await this.getSourceMeshes(e.source.assetId);if(0!==s.length)for(const[r,a]of e.source.surfaceScatter?.meshes.entries()??[]){this.referencedScatterAssetIds.add(a.assetId);const i=Q(`${e.sourceKey}|${r}|${a.assetId}`);for(const e of s)z(e.sampler,i);const c=s.map(t=>{const s=(new o).multiplyMatrices(e.worldMatrix,t.localMatrix);return{sampler:t.sampler,area:O(t.geometry,s),worldMatrix:s,normalMatrix:(new n).getNormalMatrix(s)}}).filter(e=>e.area>0),l=c.reduce((e,t)=>e+t.area,0);if(l<=0)continue;const h=this.getRenderKey(a);if(null==await this.getScatterRenderAsset(a))continue;const u=Math.max(l,0)*Math.max(a.density??0,0);let f=Math.floor(u);const d=u-f;if(d>0){Q(`${e.sourceKey}|${r}|${a.assetId}|count`)()<d&&f++}if(f<=0)continue;const p=Math.cos((a.maxSlope??90)*Math.PI/180);let m=0,w=0;const S=Math.max(8*f,100);for(;m<f&&w<S;){w++;const e=B(c,l,i);if(e.sampler.sample(g,y),g.applyMatrix4(e.worldMatrix),y.applyMatrix3(e.normalMatrix).normalize(),(a.maxSlope??90)<90&&y.y<p)continue;const s=E(i,a.scaleMin??1,a.scaleMax??1);M.makeScale(s,s,s),!1!==a.randomRotation&&M.multiply(k(i)),a.alignToNormal&&(A.lookAt(D,y,C).multiply(P),M.premultiply(A)),I.copy(g),I.y+=E(i,a.offsetMin??0,a.offsetMax??0),b.makeTranslation(I.x,I.y,I.z);const r=b.clone().multiply(M),n=this.getCellKey(h,I);let o=t.get(n);null==o&&(o={renderKey:h,viewDistance:a.viewDistance,center:V(I),matrices:[]},t.set(n,o)),o.matrices.push(r),m++}}}async collectSurfaceScatterSources(e,t=(new o).identity(),s=[],r=[]){const a=[];for(const i of e??[]){const e=[...r,i.id],n=t.clone().multiply(K(i));if("asset_mesh"===i.type&&null!=i.assetId&&(i.surfaceScatter?.meshes?.length??0)>0&&(e.forEach(e=>this.referencedSceneObjectIds.add(e)),a.push({source:i,worldMatrix:n,sourceKey:e.join("/")})),null!=i.children&&a.push(...await this.collectSurfaceScatterSources(i.children,n,s,e)),"prefab"===i.type&&null!=i.assetId){if(s.includes(i.assetId)){console.warn(`Skipping circular prefab while collecting surface scatter for prefab asset ${i.assetId}`);continue}const t=await this.assetService.getAsset(i.assetId),r=t?.prefab?.objects;if(null!=r){const t=a.length;a.push(...await this.collectSurfaceScatterSources(r,n,[...s,i.assetId],e)),a.length>t&&this.referencedPrefabAssetIds.add(i.assetId)}}}return a}async getSourceMeshes(e){let t=this.sourceAssetCache.get(e);if(null!=t)return t;const r=await this.assetService.getAsset(e);if(null==r)return[];const a=await this.assetManagerService.getMesh(r);a.scene.updateMatrixWorld(!0);const i=[];return L(a.scene,a.scene,e=>{i.push({sampler:new s(e).build(),geometry:e.geometry,localMatrix:e.matrixWorld.clone()})}),this.sourceAssetCache.set(e,i),i}async getScatterRenderAsset(e){const s=this.getRenderKey(e),r=this.scatterRenderAssetCache.get(s);if(null!=r)return r;const a=await this.assetService.getAsset(e.assetId);if(null==a)return console.error(`Can not find scatter asset with id ${e.assetId}`),null;const i=await this.assetManagerService.getMesh(a,{applyMaterials:!0}),n=[];if(L(i.scene,i.scene,e=>{n.push(e)}),1!==n.length)return console.warn(`Surface scatter only works for meshes with a single visible geometry. Asset: ${a.name}`),null;const o=n[0];let c=o.geometry.clone();!0===e.normalsUp&&function(e){const t=e.getAttribute("normal");if(null==t)return;for(let e=0;e<t.count;e++)t.setXYZ(e,0,1,0);t.normalized=!0,t.needsUpdate=!0}(c),i.scene.updateMatrixWorld(!0),c.applyMatrix4(o.matrixWorld);const l=a.mesh?.rescale??1;1!==l&&c.scale(l,l,l);const h=function(e){const t=e.getIndex()??e.getAttribute("position");return null!=t?t.count/3:0}(c);if(h>t)return console.warn(`The triangle count of ${a.name} is too big ${h}. Keep it below ${t}`),null;const u=o.material;Array.isArray(u)?u.forEach(e=>{e.userData.disableAO=!0}):u.userData.disableAO=!0;const f={geometry:c,material:u,castShadow:!1,receiveShadow:!0};return this.scatterRenderAssetCache.set(s,f),f}clearScatterMeshes(){this.scatterRoot.children.slice().forEach(e=>{this.scatterRoot.remove(e)})}updateVisibility(){if(null==this.view.camera)return;const e=this.view.camera.position;this.scatterRoot.children.forEach(t=>{const s=t.userData.viewDistance,r=t.userData.cellCenter;t.visible="number"!=typeof s||null==r||e.distanceTo(r)<=s+d})}getRenderKey(e){return`${e.assetId}|n:${!0===e.normalsUp?1:0}|v:${e.viewDistance??-1}`}getCellKey(e,t){return`${e}|${Math.floor(t.x/f)}:${Math.floor(t.y/f)}:${Math.floor(t.z/f)}`}setVisibilityLoopRegistered(e){e!==this.visibilityLoopRegistered&&(this.visibilityLoopRegistered=e,e?this.view.onLoop(this.onLoopHandler):this.view.removeOnLoop(this.onLoopHandler))}}function L(t,s,r){s!==t&&null!=s.userData?.src||!0!==s.userData?.surfaceScatterGenerated&&(s instanceof c&&!e(s)&&!1!==s.visible&&r(s),s.children.forEach(e=>L(t,e,r)))}function B(e,t,s){let r=s()*t;for(const t of e)if(r-=t.area,r<=0)return t;return e[e.length-1]}function K(e){return null==e.position||null==e.rotation||null==e.scale?(new o).identity():(x.fromArray(e.position),v.setFromEuler((new r).fromArray(e.rotation)),$.fromArray(e.scale),(new o).compose(x,v,$))}function O(e,t){const s=e.getIndex(),r=e.getAttribute("position");if(null==r)return 0;let a=0;if(null!=s){for(let e=0;e<s.count;e+=3)m.fromBufferAttribute(r,s.getX(e)).applyMatrix4(t),w.fromBufferAttribute(r,s.getX(e+1)).applyMatrix4(t),S.fromBufferAttribute(r,s.getX(e+2)).applyMatrix4(t),p.set(m,w,S),a+=p.getArea();return a}for(let e=0;e<r.count;e+=3)m.fromBufferAttribute(r,e).applyMatrix4(t),w.fromBufferAttribute(r,e+1).applyMatrix4(t),S.fromBufferAttribute(r,e+2).applyMatrix4(t),p.set(m,w,S),a+=p.getArea();return a}function V(e){return R.set((Math.floor(e.x/f)+.5)*f,(Math.floor(e.y/f)+.5)*f,(Math.floor(e.z/f)+.5)*f),R.clone()}function k(e){return j.makeRotationY(e()*Math.PI*2)}function E(e,t=0,s=0){return t+e()*(s-t)}function Q(e){let t=function(e){let t=2166136261;for(let s=0;s<e.length;s++)t^=e.charCodeAt(s),t=Math.imul(t,16777619);return t>>>0}(e);return()=>{t+=1831565813;let e=t;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296}}function z(e,t){e.setRandomGenerator?.(t)}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -42,7 +42,7 @@ export declare class ObjectStorage<T extends StorageEntity> {
|
|
|
42
42
|
* @param from Relative path
|
|
43
43
|
* @param to Relative path that the given folder should be put into
|
|
44
44
|
*/
|
|
45
|
-
moveToFolder(object: T, to: string): Promise<
|
|
45
|
+
moveToFolder(object: T, to: string): Promise<T>;
|
|
46
46
|
getAbsolutePath(relativePath?: string): string;
|
|
47
47
|
getResourceAbsolutePath(relativePath?: string): string;
|
|
48
48
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{randomUUID as e}from"../../utils/uuid.js";import{pathJoin as t}from"../../utils/files.js";import{combineLatest as a,EMPTY as i,filter as n,firstValueFrom as s,from as r,map as h,mergeAll as o,mergeMap as l,Observable as c,of as d,startWith as u,Subject as p,switchMap as f,tap as w}from"rxjs";import{sleepDelay as m}from"../../utils/async.js";const y={},v={},x={},b={};null==y.read&&window.require&&(Object.assign(y,window.require("fs")),Object.assign(v,y.promises),Object.assign(x,window.require("path")),Object.assign(b,window.require("chokidar")));const j=null!=y.existsSync;let g=0,I=0;const P=[];async function F(e){await function(){if(g<32)return g++,Promise.resolve();return new Promise(e=>P.push(e))}();try{return await e()}finally{!function(){const e=P[I];if(null==e)return P.length=0,I=0,void g--;I++,I>64&&2*I>P.length&&(P.splice(0,I),I=0);e()}()}}function O(e){return F(()=>v.readFile(e))}function S(){if(j){const e="--path=",t=window.process.argv.find(t=>t.startsWith(e));return t?t.substring(e.length):""}return""}const C=/^[A-Z]:/;function A(...e){return 0===e.length?"":C.test(e[0])||j?x.join(...e):t(...e)}export class ObjectStorage{get pathResources(){return A(this.path+"-resources")}constructor(e,t,a=defaultSerializer){this.name=e,this.filePathFn=t,this.serializer=a,this.basePathUpdates=new p,this.basePath=this.basePathUpdates.pipe(h(e=>A(S(),e)),w(e=>{this.path=A(e,this.name),this.cachedIndex=null,this.loadingIndex=null,z(this.path),this.determineIfMetaFileShouldBeCreated()})),this.loaded=s(this.basePath),this.cachedIndex=null,this.loadingIndex=null,this.shouldCreateIndex=!1}setBasePath(e){this.basePathUpdates.next(e)}async determineIfMetaFileShouldBeCreated(){if(j)try{const e=["vite.renderer.config.ts","vite.config.ts"];for(const t of e){const e=A(S(),t);if(!await k(e))continue;if((await O(e)).toString().includes("hologyBuild"))return void(this.shouldCreateIndex=!1)}this.shouldCreateIndex=!0}catch(e){console.warn("Failed to read vite config to determine if meta files should be created")}}async createFolder(e,t=""){D(),await v.mkdir(x.join(this.path,t,e),{recursive:!0})}async deleteFolderForceDangerous(e){await v.rm(x.join(this.path,e),{recursive:!0,force:!0})}async moveFolder(e,t){if(D(),""==e)return void console.warn("Can not move a folder in root");const a=x.resolve(x.join(this.path,t),x.basename(e));if(await K(a)){if(a!==x.resolve(this.path,e))throw new Error("Can not move to directory as a file already exists with the same name")}else{if(function(e,t){const a=x.resolve(e),i=x.resolve(t),n=x.normalize(a)+x.sep;return(x.normalize(i)+x.sep).startsWith(n)}(x.join(this.path,e),x.join(this.path,t)))throw new Error("Can not move a folder into a folder it contains");await v.rename(x.join(this.path,e),a)}}async renameFolder(e,t){await v.rename(x.join(this.path,e),x.resolve(x.dirname(x.join(this.path,e)),t))}async moveToFolder(e,t){if(D(),e.path===t)return;await this.assertObjectFilePathAvailable({...e,path:t},e.id);const a=this.privateObjectPath({...e,path:t});await v.rename(this.privateObjectPath(e),a)}getAbsolutePath(e=""){return x.join(this.path,e)}getResourceAbsolutePath(e=""){return x.join(this.pathResources,e)}watchFolders(){return r(this.loaded).pipe(f(()=>r(z(this.path))),f(()=>this.watchDir(this.path).pipe(n(e=>!e.filename.endsWith(".json")),u(null),f(()=>r(v.readdir(this.path,{recursive:!0,withFileTypes:!0}))),h(e=>Array.from(new Set(e.filter(e=>e.isDirectory()).map(e=>x.relative(this.path,x.join(e.parentPath,e.name)).replace(/^\.$/,"")).values()))))))}watch(){D();r(this.loaded).pipe(f(()=>a([this.watchDir(this.pathResources),r(this.getAll())]).pipe(n(([e])=>null!=e),l(([e,t])=>{if("change"===e.event){const a=x.basename(e.filename),i=t.filter(e=>e.fileKey===a);if(i.length>0)return r(i).pipe(l(e=>{const t=this.privateObjectRelativePath(e);return r(this.readFileIfExists(t)).pipe(h(a=>({event:"change",object:a,path:e.path,filename:t})))}))}return i}))));return r(this.loaded).pipe(f(()=>this.watchDir(this.path)),l(e=>{const t={event:e.event,path:x.dirname(e.filename).replace(/^\.$/,""),filename:x.basename(e.filename)};return e.filename.endsWith(".json")?"unlink"!==e.event?r(this.readFileIfExists(e.filename)).pipe(w(e=>{null!=e&&(null==this.cachedIndex&&(this.cachedIndex={}),this.cachedIndex[e.id]={id:e.id,name:e.name??e.id,path:e.path},this.persistIndex())}),h(e=>({object:e,...t}))):d({object:null,...t}).pipe(w(()=>{const t=Object.keys(this.cachedIndex??{}).find(t=>this.privateObjectRelativePath(this.cachedIndex[t])===e.filename);t&&this.removeIndexEntry(t)})):"change"===e.event?r(this.reloadSubdirectory(e.filename)).pipe(o(),h(e=>({object:e,...t}))):i}))}async reloadSubdirectory(e){return(await this.getAll(e)).filter(t=>t.path.startsWith(e))}async readFileIfExists(e){const t=A(this.path,e);try{const a=await O(t);return{...JSON.parse(a.toString()),path:x.dirname(e).replace(/^\.$/,""),filename:x.basename(e)}}catch{return console.error("Could not find file at "+t),null}}async getAll(e){if(j){await this.loaded,await z(this.path);const t=await this.getObjectFilePaths(e??""),a=null==e||""===e,i=[];for(let e=0;e<t.length;e+=32){const a=Math.min(32,t.length-e),n=await Promise.all(Array.from({length:a},(a,i)=>{const n=t[e+i];return O(A(this.path,n)).then(e=>({...JSON.parse(e.toString()),path:x.dirname(n).replace(/^\.$/,""),filename:x.basename(n)}))}));i.push(...n)}return a&&(this.cachedIndex=R(i),await this.persistIndex()),i}const t=await this.loadIndex();return Promise.all(Object.keys(t).map(e=>this.get(e)))}async getObjectFilePaths(e){const t=this.path,a=x.join(t,e),i=[];return await async function e(a){const n=await v.readdir(a,{withFileTypes:!0});for(const s of n){const n=x.join(a,s.name);s.isDirectory()?await e(n):s.isFile()&&s.name.endsWith(".json")&&!/^[\._]/.test(s.name)&&i.push(x.relative(t,n))}}(a),i}async get(e){const t=await this.loadIndex(),a=t[e]??Object.values(t).find(t=>t.name===e);if(null==a)return;const i=this.privateObjectPath(a);if(!j)return(await fetch(i)).json();return await k(i)?{...JSON.parse((await O(i)).toString()),path:a.path??"",filename:x.basename(this.privateObjectRelativePath(a))}:null}async save(e){if(D(),await this.loaded,null==e.path){const t=(await this.loadIndex())[e.id];null!=t?.path&&(e={...e,path:t.path})}return await this.assertObjectFilePathAvailable(e,e.id),await v.writeFile(this.privateObjectPath(e),this.serialize(e)),await this.addOrUpdateIndexEntry(e),e}async rename(e,t){const a={...e,name:t};await this.assertObjectFilePathAvailable(a,e.id);const i=this.privateObjectPath(e),n=this.privateObjectPath(a);try{await v.rename(i,n)}catch(e){console.error(e),console.warn("Rename failed, retrying",{currentPath:i,newPath:n}),await m(400),await v.rename(i,n)}return await this.save(a),a}async delete(e){await v.unlink(this.privateObjectPath(e)),this.removeIndexEntry(e.id)}async create(t){D(),await this.loaded,t.id=e();const a=this.privateObjectPath(t);if(await this.assertObjectFilePathAvailable(t),await K(a))throw Error(`Can not create because a file already exists at ${a}`);return await v.writeFile(a,this.serialize(t)),await this.addOrUpdateIndexEntry(t),t}prepareCreate(t){return D(),t.id=e(),t}serialize(e){return this.serializer(e)}async addOrUpdateIndexEntry(e){null==this.cachedIndex&&await this.loadIndex(),this.cachedIndex[e.id]={id:e.id,name:e.name??e.id,path:e.path},await this.persistIndex()}removeIndexEntry(e){null!=this.cachedIndex&&delete this.cachedIndex[e],this.persistIndex()}async persistIndex(){j&&this.shouldCreateIndex&&null!=this.cachedIndex&&await v.writeFile(this.indexFilePath,JSON.stringify(this.cachedIndex,null,2))}get indexFilePath(){return A(this.path,"_meta.json")}async loadIndex(){if(null!=this.cachedIndex)return this.cachedIndex;this.loadingIndex??(this.loadingIndex=this.createIndex());try{return await this.loadingIndex}finally{this.loadingIndex=null}}async createIndex(){if(j){const e=await this.getAll();this.cachedIndex=R(e),await this.persistIndex()}else this.cachedIndex=await(await fetch(this.indexFilePath)).json();return this.cachedIndex}async ensureResourceDir(){await z(A(this.path+"-resources"))}async saveFile(e,t){return D(),await z(A(this.path+"-resources")),v.copyFile(t.path,A(this.path+"-resources",e.fileKey))}async saveExtraFile(e,t){return D(),await z(A(this.path+"-resources")),v.copyFile(e,A(this.path+"-resources",t))}getAssetPath(e){return window&&"function"==typeof window.require?window.require("path").join(this.path+"-resources",e.fileKey):A(this.path+"-resources",e.fileKey)}async replaceFile(e,t){if(await k(t))return v.copyFile(t,A(this.path+"-resources",e.fileKey));console.error("Failed to replace file using path "+t)}async deleteFile(e){if(null==e)return;D();const t=A(this.path+"-resources",e);return await k(t)?v.unlink(t):void 0}privateObjectPath(e){return A(this.path,this.privateObjectRelativePath(e))}privateObjectRelativePath(e){return this.filePathFn?A(e.path??"",this.filePathFn(e)):A(e.path??"",tokenizeName(e.name??e.id)+".json")}async assertObjectFilePathAvailable(e,t){const a=await this.findObjectFilePathCollision(e,t);if(null!=a)throw Error(`Can not save "${e.name??e.id}" because "${a.name}" already uses the same storage file name. Use a name that differs beyond letter casing.`)}async findObjectFilePathCollision(e,t){const a=E(this.privateObjectRelativePath(e)),i=await this.loadIndex();return Object.values(i).find(e=>e.id!==t&&E(this.privateObjectRelativePath(e))===a)??null}watchDir(e){return new c(t=>{if("win32"===process.platform&&j){const a=y.watch(e,{recursive:!0},(a,i)=>{if(i){const n=x.join(e,i);y.access(n,y.constants.F_OK,e=>{const n=e?"unlink":"rename"===a?"add":"change";t.next({event:n,filename:i})})}});return()=>a.close()}const a=b.watch(e,{cwd:e,ignoreInitial:!0,disableGlobbing:!0});return a.on("all",(e,a,i)=>{t.next({event:e,filename:a})}),a.on("error",()=>{}),()=>{a.close()}})}}export function tokenizeName(e){return e.trim().replace(/\s/g,"_").replace(/[^a-z0-9_\-\.]/gi,"")}function E(e){return e.replace(/\\/g,"/").toLowerCase()}function R(e){const t={};for(const a of e)t[a.id]={id:a.id,name:a.name??a.id,path:a.path};return t}async function z(e){j&&(await k(e)||await v.mkdir(e,{recursive:!0}))}function k(e){return!!j&&new Promise(function(t,a){y.exists(e,function(e){t(e)})})}function D(){if(!j)throw new Error("Must have direct access to filesystem")}async function K(e){try{await v.access(e,v.constants.F_OK)}catch(e){return!1}return!0}export function defaultSerializer(e){const t={...e};return delete t.path,delete t.filename,JSON.stringify(t,null,2)}/*
|
|
1
|
+
import{randomUUID as e}from"../../utils/uuid.js";import{pathJoin as t}from"../../utils/files.js";import{EMPTY as a,filter as i,firstValueFrom as n,from as s,map as r,merge as h,mergeAll as o,mergeMap as l,Observable as c,of as d,startWith as u,Subject as p,switchMap as f,tap as w}from"rxjs";import{sleepDelay as m}from"../../utils/async.js";const y={},v={},x={},b={};null==y.read&&window.require&&(Object.assign(y,window.require("fs")),Object.assign(v,y.promises),Object.assign(x,window.require("path")),Object.assign(b,window.require("chokidar")));const j=null!=y.existsSync;let g=0,I=0;const P=[];async function F(e){await function(){if(g<32)return g++,Promise.resolve();return new Promise(e=>P.push(e))}();try{return await e()}finally{!function(){const e=P[I];if(null==e)return P.length=0,I=0,void g--;I++,I>64&&2*I>P.length&&(P.splice(0,I),I=0);e()}()}}function O(e){return F(()=>v.readFile(e))}function S(){if(j){const e="--path=",t=window.process.argv.find(t=>t.startsWith(e));return t?t.substring(e.length):""}return""}const C=/^[A-Z]:/;function E(...e){return 0===e.length?"":C.test(e[0])||j?x.join(...e):t(...e)}export class ObjectStorage{get pathResources(){return E(this.path+"-resources")}constructor(e,t,a=defaultSerializer){this.name=e,this.filePathFn=t,this.serializer=a,this.basePathUpdates=new p,this.basePath=this.basePathUpdates.pipe(r(e=>E(S(),e)),w(e=>{this.path=E(e,this.name),this.cachedIndex=null,this.loadingIndex=null,k(this.path),this.determineIfMetaFileShouldBeCreated()})),this.loaded=n(this.basePath),this.cachedIndex=null,this.loadingIndex=null,this.shouldCreateIndex=!1}setBasePath(e){this.basePathUpdates.next(e)}async determineIfMetaFileShouldBeCreated(){if(j)try{const e=["vite.renderer.config.ts","vite.config.ts"];for(const t of e){const e=E(S(),t);if(!await z(e))continue;if((await O(e)).toString().includes("hologyBuild"))return void(this.shouldCreateIndex=!1)}this.shouldCreateIndex=!0}catch(e){console.warn("Failed to read vite config to determine if meta files should be created")}}async createFolder(e,t=""){D(),await v.mkdir(x.join(this.path,t,e),{recursive:!0})}async deleteFolderForceDangerous(e){await v.rm(x.join(this.path,e),{recursive:!0,force:!0})}async moveFolder(e,t){if(D(),""==e)return void console.warn("Can not move a folder in root");const a=x.resolve(x.join(this.path,t),x.basename(e));if(await U(a)){if(a!==x.resolve(this.path,e))throw new Error("Can not move to directory as a file already exists with the same name")}else{if(function(e,t){const a=x.resolve(e),i=x.resolve(t),n=x.normalize(a)+x.sep;return(x.normalize(i)+x.sep).startsWith(n)}(x.join(this.path,e),x.join(this.path,t)))throw new Error("Can not move a folder into a folder it contains");await v.rename(x.join(this.path,e),a)}}async renameFolder(e,t){await v.rename(x.join(this.path,e),x.resolve(x.dirname(x.join(this.path,e)),t))}async moveToFolder(e,t){if(D(),(e.path??"")===t)return e;const a={...e,path:t};await this.assertObjectFilePathAvailable(a,e.id);const i=this.privateObjectPath(a);return await v.rename(this.privateObjectPath(e),i),await this.addOrUpdateIndexEntry(a),a}getAbsolutePath(e=""){return x.join(this.path,e)}getResourceAbsolutePath(e=""){return x.join(this.pathResources,e)}watchFolders(){return s(this.loaded).pipe(f(()=>s(k(this.path))),f(()=>this.watchDir(this.path).pipe(i(e=>!e.filename.endsWith(".json")),u(null),f(()=>s(v.readdir(this.path,{recursive:!0,withFileTypes:!0}))),r(e=>Array.from(new Set(e.filter(e=>e.isDirectory()).map(e=>x.relative(this.path,x.join(e.parentPath,e.name)).replace(/^\.$/,"")).values()))))))}watch(){D();const e=s(this.loaded).pipe(f(()=>s(k(this.pathResources))),f(()=>this.watchDir(this.pathResources)),l(e=>{if(null==e||!["add","change","unlink"].includes(e.event))return a;const t=x.basename(e.filename);return s(this.getAll()).pipe(l(e=>{const i=e.filter(e=>e.fileKey===t);return 0===i.length?a:s(i).pipe(l(e=>{const t=this.privateObjectRelativePath(e);return s(this.readFileIfExists(t)).pipe(r(a=>({event:"change",object:a,path:e.path,filename:t})))}))}))})),t=s(this.loaded).pipe(f(()=>this.watchDir(this.path)),l(e=>{const t={event:e.event,path:x.dirname(e.filename).replace(/^\.$/,""),filename:x.basename(e.filename)};return e.filename.endsWith(".json")?"unlink"!==e.event?s(this.readFileIfExists(e.filename)).pipe(w(e=>{null!=e&&(null==this.cachedIndex&&(this.cachedIndex={}),this.cachedIndex[e.id]={id:e.id,name:e.name??e.id,path:e.path},this.persistIndex())}),r(e=>({object:e,...t}))):d({object:null,...t}).pipe(w(()=>{const t=Object.keys(this.cachedIndex??{}).find(t=>this.privateObjectRelativePath(this.cachedIndex[t])===e.filename);t&&this.removeIndexEntry(t)})):"change"===e.event?s(this.reloadSubdirectory(e.filename)).pipe(o(),r(e=>({object:e,...t}))):a}));return h(t,e)}async reloadSubdirectory(e){return(await this.getAll(e)).filter(t=>t.path.startsWith(e))}async readFileIfExists(e){const t=E(this.path,e);for(let a=0;a<3;a++)try{const a=await O(t);return{...JSON.parse(a.toString()),path:x.dirname(e).replace(/^\.$/,""),filename:x.basename(e)}}catch(e){if(2===a)return console.error("Could not read file at "+t,e),null;await m(50*(a+1))}return null}async getAll(e){if(j){await this.loaded,await k(this.path);const t=await this.getObjectFilePaths(e??""),a=null==e||""===e,i=[];for(let e=0;e<t.length;e+=32){const a=Math.min(32,t.length-e),n=await Promise.all(Array.from({length:a},(a,i)=>{const n=t[e+i];return O(E(this.path,n)).then(e=>({...JSON.parse(e.toString()),path:x.dirname(n).replace(/^\.$/,""),filename:x.basename(n)}))}));i.push(...n)}return a&&(this.cachedIndex=R(i),await this.persistIndex()),i}const t=await this.loadIndex();return Promise.all(Object.keys(t).map(e=>this.get(e)))}async getObjectFilePaths(e){const t=this.path,a=x.join(t,e),i=[];return await async function e(a){const n=await v.readdir(a,{withFileTypes:!0});for(const s of n){const n=x.join(a,s.name);s.isDirectory()?await e(n):s.isFile()&&s.name.endsWith(".json")&&!/^[\._]/.test(s.name)&&i.push(x.relative(t,n))}}(a),i}async get(e){const t=await this.loadIndex(),a=t[e]??Object.values(t).find(t=>t.name===e);if(null==a)return;const i=this.privateObjectPath(a);if(!j)return(await fetch(i)).json();return await z(i)?{...JSON.parse((await O(i)).toString()),path:a.path??"",filename:x.basename(this.privateObjectRelativePath(a))}:null}async save(e){if(D(),await this.loaded,null==e.path){const t=(await this.loadIndex())[e.id];null!=t?.path&&(e={...e,path:t.path})}return await this.assertObjectFilePathAvailable(e,e.id),await v.writeFile(this.privateObjectPath(e),this.serialize(e)),await this.addOrUpdateIndexEntry(e),e}async rename(e,t){const a={...e,name:t};await this.assertObjectFilePathAvailable(a,e.id);const i=this.privateObjectPath(e),n=this.privateObjectPath(a);try{await v.rename(i,n)}catch(e){console.error(e),console.warn("Rename failed, retrying",{currentPath:i,newPath:n}),await m(400),await v.rename(i,n)}return await this.save(a),a}async delete(e){await v.unlink(this.privateObjectPath(e)),this.removeIndexEntry(e.id)}async create(t){D(),await this.loaded,t.id=e();const a=this.privateObjectPath(t);if(await this.assertObjectFilePathAvailable(t),await U(a))throw Error(`Can not create because a file already exists at ${a}`);return await v.writeFile(a,this.serialize(t)),await this.addOrUpdateIndexEntry(t),t}prepareCreate(t){return D(),t.id=e(),t}serialize(e){return this.serializer(e)}async addOrUpdateIndexEntry(e){null==this.cachedIndex&&await this.loadIndex(),this.cachedIndex[e.id]={id:e.id,name:e.name??e.id,path:e.path},await this.persistIndex()}removeIndexEntry(e){null!=this.cachedIndex&&delete this.cachedIndex[e],this.persistIndex()}async persistIndex(){j&&this.shouldCreateIndex&&null!=this.cachedIndex&&await v.writeFile(this.indexFilePath,JSON.stringify(this.cachedIndex,null,2))}get indexFilePath(){return E(this.path,"_meta.json")}async loadIndex(){if(null!=this.cachedIndex)return this.cachedIndex;this.loadingIndex??(this.loadingIndex=this.createIndex());try{return await this.loadingIndex}finally{this.loadingIndex=null}}async createIndex(){if(j){const e=await this.getAll();this.cachedIndex=R(e),await this.persistIndex()}else this.cachedIndex=await(await fetch(this.indexFilePath)).json();return this.cachedIndex}async ensureResourceDir(){await k(E(this.path+"-resources"))}async saveFile(e,t){return D(),await k(E(this.path+"-resources")),v.copyFile(t.path,E(this.path+"-resources",e.fileKey))}async saveExtraFile(e,t){return D(),await k(E(this.path+"-resources")),v.copyFile(e,E(this.path+"-resources",t))}getAssetPath(e){return window&&"function"==typeof window.require?window.require("path").join(this.path+"-resources",e.fileKey):E(this.path+"-resources",e.fileKey)}async replaceFile(e,t){if(await z(t))return v.copyFile(t,E(this.path+"-resources",e.fileKey));console.error("Failed to replace file using path "+t)}async deleteFile(e){if(null==e)return;D();const t=E(this.path+"-resources",e);return await z(t)?v.unlink(t):void 0}privateObjectPath(e){return E(this.path,this.privateObjectRelativePath(e))}privateObjectRelativePath(e){return this.filePathFn?E(e.path??"",this.filePathFn(e)):E(e.path??"",tokenizeName(e.name??e.id)+".json")}async assertObjectFilePathAvailable(e,t){const a=await this.findObjectFilePathCollision(e,t);if(null!=a)throw Error(`Can not save "${e.name??e.id}" because "${a.name}" already uses the same storage file name. Use a name that differs beyond letter casing.`)}async findObjectFilePathCollision(e,t){const a=A(this.privateObjectRelativePath(e)),i=await this.loadIndex();return Object.values(i).find(e=>e.id!==t&&A(this.privateObjectRelativePath(e))===a)??null}watchDir(e){return new c(t=>{if("win32"===process.platform&&j){const a=y.watch(e,{recursive:!0},(a,i)=>{if(i){const n=x.join(e,i);y.access(n,y.constants.F_OK,e=>{const n=e?"unlink":"rename"===a?"add":"change";t.next({event:n,filename:i})})}});return()=>a.close()}const a=b.watch(e,{cwd:e,ignoreInitial:!0,disableGlobbing:!0});return a.on("all",(e,a,i)=>{t.next({event:e,filename:a})}),a.on("error",()=>{}),()=>{a.close()}})}}export function tokenizeName(e){return e.trim().replace(/\s/g,"_").replace(/[^a-z0-9_\-\.]/gi,"")}function A(e){return e.replace(/\\/g,"/").toLowerCase()}function R(e){const t={};for(const a of e)t[a.id]={id:a.id,name:a.name??a.id,path:a.path};return t}async function k(e){j&&(await z(e)||await v.mkdir(e,{recursive:!0}))}function z(e){return!!j&&new Promise(function(t,a){y.exists(e,function(e){t(e)})})}function D(){if(!j)throw new Error("Must have direct access to filesystem")}async function U(e){try{await v.access(e,v.constants.F_OK)}catch(e){return!1}return!0}export function defaultSerializer(e){const t={...e};return delete t.path,delete t.filename,JSON.stringify(t,null,2)}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as a}from"tslib";import{Color as t,MeshStandardMaterial as n,Texture as r,Vector2 as i}from"three";import{Shader as s}from"../shader.js";import{Parameter as o}from"../parameter.js";import*as p from"three";import{attributes as l,colorToNormal as d,NodeShaderMaterial as h,normalize as m,Sampler2DNode as v,standardMaterial as u,UniformSampler2d as c,uniformFloat as y,uniformVec2 as g,uniformVec3 as f,varying as S,varyingAttributes as M,varyingTransformed as x,vec2 as b,UniformVec3Node as C}from"three-shader-graph";import{parallaxOcclusionMapping as w}from"../../shader-nodes/pom.js";const O=new r,T=new i(1,1);export class StandardShader extends s{constructor(){super(...arguments),this.color=new t("#FFFFFF"),this.map=new c("map",O),this.opacity=1,this.alphaMap=new c("alphaMap",O),this.roughness=1,this.roughnessMap=new c("roughnessMap",O),this.metalness=0,this.metalnessMap=new c("metalnessMap",O),this.lightMap=new c("lightMap",O),this.aoMap=new c("aoMap",O),this.emissiveMap=new c("emissiveMap",O),this.normalMap=new c("normalMap",O),this.normalScale=new i(1,1),this.sheen=0,this.sheenColor=new t("#FFFFFF"),this.sheenColorMap=new c("sheenColorMap",O),this.sheenRoughness=.5,this.sheenRoughnessMap=new c("sheenRoughnessMap",O),this.anisotropyMap=new c("anisotropyMap",O),this.anisotropy=0,this.heightMap=new c("heightMap",O),this.vertexColor=!1,this.uvScale=T}build(){let e=!1;const a=g("uvScale",this.uvScale??T);let n=M.uv.multiply(a);N(this.heightMap)&&0!==(this.heightScale??.05)&&(n=w(n,this.heightMap,y("heightScale",this.heightScale??.05)));let r=y("opacity",this.opacity),s=new C("color",(new p.Vector3).setFromColor(this.color),void 0,!1).rgb;if(N(this.map)){const e=this.map.sample(n);s=s.multiply(e.rgb),r=r.multiply(e.a)}N(this.alphaMap)&&(r=r.multiply(this.alphaMap.sample(n).r)),!0===this.vertexColor&&(s=s.multiply(S(l.color.rgb)));let o=null,v=null;N(this.aoMap)&&(v=y("aoMapIntensity",this.aoMapIntensity??1),o=this.aoMap.sample(n).r);let c=y("roughness",this.roughness??1);N(this.roughnessMap)&&(c=c.multiply(this.roughnessMap.sample(n).g),e=!0);let O=y("metalness",this.metalness??0);N(this.metalnessMap)&&(O=O.multiply(this.metalnessMap.sample(n).b),e=!0);let F=null;N(this.lightMap)&&(F=this.lightMap.sample(n).rgb.multiplyScalar(y("lightMapIntensity",this.lightMapIntensity??1)));let L=f("emissive",(new p.Vector3).setFromColor(this.emissive??new t(0))).rgb;N(this.emissiveMap)&&(L=L.multiply(this.emissiveMap.sample(n).rgb));const R=y("emissiveIntensity",this.emissiveIntensity??1);let P=x.normal;if(N(this.normalMap)){const e=y("normalScale",this.normalScale?.x??1);P=d(this.normalMap.sample(n),e)}let D=null,B=null;if((this.sheen??0)>0){const e=y("sheen",this.sheen??0);D=f("sheenColor",(new p.Vector3).setFromColor(this.sheenColor??new t(16777215))).rgb.multiplyScalar(e),N(this.sheenColorMap)&&(D=D.multiply(this.sheenColorMap.sample(n).rgb)),B=y("sheenRoughness",this.sheenRoughness??.5),N(this.sheenRoughnessMap)&&(B=B.multiply(this.sheenRoughnessMap.sample(n).a))}(this.roughness<1||this.metalness>0)&&(e=!0);let _=null,I=null;if((this.anisotropy??0)>0&&(_=y("anisotropy",this.anisotropy??0),I=g("anisotropyDirection",(V=this.anisotropyRotation??0,new i(Math.cos(V),Math.sin(V)))),N(this.anisotropyMap))){const e=this.anisotropyMap.sample(n),a=m(b(e.r,e.g).multiplyScalar(2).subtract(b(1,1)));I=b(I.x.multiply(a.x).subtract(I.y.multiply(a.y)),I.y.multiply(a.x).add(I.x.multiply(a.y))),_=_.multiply(e.b)}var V;const E=new h({color:u({color:s.rgba(r),roughness:c,metalness:O,ambientOcclusion:o,ambientOcclusionIntensity:v,emissive:L,emissiveIntensity:R,normal:P,bakedLight:F,sheenColor:D,sheenRoughness:B,anisotropy:_,anisotropyDirection:I,specular:e}),opacity:r,roughness:c,normal:P,emissive:L.multiplyScalar(R),envMap:this.envMap});return null!=this.envMap&&(E.uniforms.envMapIntensity={value:this.envMapIntensity??1}),E.vertexColors=!0===this.vertexColor,E}}function N(e){return null!=e&&(!(e instanceof c)||null!=e.value&&e.value!==O)}e([o(),a("design:type",t)],StandardShader.prototype,"color",void 0),e([o({label:"Color Map"}),a("design:type",v)],StandardShader.prototype,"map",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"opacity",void 0),e([o(),a("design:type",v)],StandardShader.prototype,"alphaMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"roughness",void 0),e([o(),a("design:type",v)],StandardShader.prototype,"roughnessMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"metalness",void 0),e([o(),a("design:type",v)],StandardShader.prototype,"metalnessMap",void 0),e([o(),a("design:type",v)],StandardShader.prototype,"lightMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"lightMapIntensity",void 0),e([o(),a("design:type",v)],StandardShader.prototype,"aoMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"aoMapIntensity",void 0),e([o(),a("design:type",t)],StandardShader.prototype,"emissive",void 0),e([o({range:[0,10]}),a("design:type",Number)],StandardShader.prototype,"emissiveIntensity",void 0),e([o(),a("design:type",v)],StandardShader.prototype,"emissiveMap",void 0),e([o(),a("design:type",v)],StandardShader.prototype,"normalMap",void 0),e([o(),a("design:type",i)],StandardShader.prototype,"normalScale",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"sheen",void 0),e([o(),a("design:type",t)],StandardShader.prototype,"sheenColor",void 0),e([o(),a("design:type",v)],StandardShader.prototype,"sheenColorMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"sheenRoughness",void 0),e([o(),a("design:type",v)],StandardShader.prototype,"sheenRoughnessMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"anisotropyRotation",void 0),e([o(),a("design:type",v)],StandardShader.prototype,"anisotropyMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"anisotropy",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"envMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"envMapIntensity",void 0),e([o(),a("design:type",v)],StandardShader.prototype,"heightMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"heightScale",void 0),e([o(),a("design:type",Boolean)],StandardShader.prototype,"vertexColor",void 0),e([o(),a("design:type",i)],StandardShader.prototype,"uvScale",void 0);export var ParallaxType;!function(e){e[e.none=0]="none",e[e.offset=1]="offset",e[e.pom=2]="pom"}(ParallaxType||(ParallaxType={}));export class ParallaxStandardMaterial extends n{constructor(e={}){super(e),e.heightMap&&(this.heightMap=e.heightMap),this.heightScale=e.heightScale??.05,this.parallaxType=e.parallaxType??ParallaxType.pom,this.minLayers=e.minLayers??10,this.maxLayers=e.maxLayers??32}onBeforeCompile(e){e.uniforms.heightMap={value:this.heightMap},e.uniforms.heightScale={value:this.heightScale},e.uniforms.minLayers={value:this.minLayers},e.uniforms.maxLayers={value:this.maxLayers},e.uniforms.parallaxType={value:this.parallaxType},e.vertexTangents=!0,e.vertexShader=e.vertexShader.replace("#include <uv_pars_vertex>","\n #include <uv_pars_vertex>\n "),e.vertexShader=e.vertexShader.replace("#include <begin_vertex>","\n #include <begin_vertex>\n "),e.fragmentShader=e.fragmentShader.replace("#include <uv_pars_fragment>","\n #include <uv_pars_fragment>\n uniform sampler2D heightMap;\n uniform float heightScale;\n uniform int minLayers;\n uniform int maxLayers;\n uniform int parallaxType;\n\n vec2 parallaxOffset(vec2 uv, vec3 viewDir, vec3 normal) {\n // Compute TBN in fragment shader using screen-space derivatives\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uv);\n vec2 duv2 = dFdy(uv);\n \n vec3 dp2perp = cross(dp2, normal);\n vec3 dp1perp = cross(normal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n \n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 tbn = mat3(T * invmax, B * invmax, normal);\n vec3 viewDirTS = -viewDir * tbn;\n\n float h = texture(heightMap, uv).r;\n return uv - (viewDirTS.xy / viewDirTS.z) * (h * heightScale);\n }\n\n vec2 parallaxOcclusion2(vec2 uv, vec3 viewDir, vec3 normal) {\n // Compute TBN in fragment shader using screen-space derivatives\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uv);\n vec2 duv2 = dFdy(uv);\n \n vec3 dp2perp = cross(dp2, normal);\n vec3 dp1perp = cross(normal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n \n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 tbn = mat3(T * invmax, B * invmax, normal);\n vec3 vv = -viewDir * tbn;\n\n float parallaxLimit = -length(vv.xy) / vv.z;\n parallaxLimit *= heightScale;\n\n vec2 vOffsetDir = normalize(vv.xy);\n vec2 vMaxOffset = vOffsetDir * parallaxLimit;\n\n float factor = pow(1.0 - abs(vv.z), 2.0);\n float nNumSamples = mix(float(minLayers), float(maxLayers), factor);\n float fStepSize = 1.0 / nNumSamples;\n\n float fCurrRayHeight = 1.0;\n vec2 vCurrOffset = vec2(0.0);\n vec2 vLastOffset = vec2(0.0);\n float fLastSampledHeight = 1.0;\n float fCurrSampledHeight = 1.0;\n\n for (int nCurrSample = 0; nCurrSample < 128; nCurrSample++) {\n if (float(nCurrSample) > nNumSamples) break;\n\n fCurrSampledHeight = texture2D(heightMap, uv + vCurrOffset).r;\n if (fCurrSampledHeight > fCurrRayHeight) {\n float delta1 = fCurrSampledHeight - fCurrRayHeight;\n float delta2 = (fCurrRayHeight + fStepSize) - fLastSampledHeight;\n float ratio = delta1 / (delta1 + delta2);\n vCurrOffset = ratio * vLastOffset + (1.0 - ratio) * vCurrOffset;\n break;\n } else {\n fCurrRayHeight -= fStepSize;\n vLastOffset = vCurrOffset;\n vCurrOffset += fStepSize * vMaxOffset;\n fLastSampledHeight = fCurrSampledHeight;\n }\n }\n\n return uv + vCurrOffset;\n }\n "),e.fragmentShader=e.fragmentShader.replace("#include <map_fragment>","\n vec3 pomViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n vec2 uvPOM = vMapUv ;\n if (parallaxType == 1) {\n uvPOM = parallaxOffset(vMapUv, pomViewDir, vNormal);\n } else if (parallaxType == 2) {\n uvPOM = parallaxOcclusion2(vMapUv, pomViewDir, vNormal);\n }\n\n vec4 texelColor = texture2D(map, uvPOM);\n diffuseColor *= texelColor;\n "),e.fragmentShader=e.fragmentShader.replace("#include <normal_fragment_maps>","\n #ifdef USE_NORMALMAP\n // RE-COMPUTE TBN for normal mapping consistency\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uvPOM);\n vec2 duv2 = dFdy(uvPOM);\n vec3 dp2perp = cross(dp2, vNormal);\n vec3 dp1perp = cross(vNormal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 localTBN = mat3(T * invmax, B * invmax, vNormal);\n\n vec3 mapN = texture2D(normalMap, uvPOM).xyz * 2.0 - 1.0;\n mapN.xy *= normalScale;\n normal = normalize( localTBN * mapN );\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <roughnessmap_fragment>","\n float roughnessFactor = roughness;\n #ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, uvPOM );\n // reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n roughnessFactor *= texelRoughness.g;\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <metalnesssmap_fragment>","\n float metalnessFactor = metalness;\n #ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, uvPOM );\n // reads channel B, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n metalnessFactor *= texelMetalness.b;\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <aomap_fragment>","\n #ifdef USE_AOMAP\n\n // reads channel R, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n float ambientOcclusion = ( texture2D( aoMap, uvPOM ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n\n #if defined( USE_CLEARCOAT ) \n clearcoatSpecularIndirect *= ambientOcclusion;\n #endif\n\n #if defined( USE_SHEEN ) \n sheenSpecularIndirect *= ambientOcclusion;\n #endif\n\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n\n float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\n #endif\n\n #endif\n "),this.userData.shader=e}clone(){const e=super.clone();return e.heightMap=this.heightMap,e.heightScale=this.heightScale,e.parallaxType=this.parallaxType,e.minLayers=this.minLayers,e.maxLayers=this.maxLayers,e}}export function applyTiling(e,a){if(null==e||null==a)return e;if(1===a.x&&1===a.y)return e;const t=e.clone();return t.repeat.copy(a),t.needsUpdate=!0,t}/*
|
|
1
|
+
import{__decorate as e,__metadata as a}from"tslib";import{Color as t,MeshStandardMaterial as n,Texture as r,Vector2 as i}from"three";import{Shader as s}from"../shader.js";import{Parameter as o}from"../parameter.js";import*as p from"three";import{attributes as l,AttributeVec3Node as d,colorToNormal as h,ifDefApply as m,NodeShaderMaterial as u,normalize as v,Sampler2DNode as c,standardMaterial as y,UniformSampler2d as S,uniformFloat as g,uniformVec2 as f,uniformVec3 as M,varying as x,varyingAttributes as C,varyingTransformed as b,vec2 as w,UniformVec3Node as O,UniformFloatNode as R}from"three-shader-graph";import{parallaxOcclusionMapping as L}from"../../shader-nodes/pom.js";import{createPlaceholderTexture as T}from"../../utils/three/placeholder-texture.js";const N=T(),B=new i(1,1);export class StandardShader extends s{constructor(){super(...arguments),this.color=new t("#FFFFFF"),this.map=new S("map",N),this.opacity=1,this.alphaMap=new S("alphaMap",N),this.roughness=1,this.roughnessMap=new S("roughnessMap",N),this.metalness=0,this.metalnessMap=new S("metalnessMap",N),this.lightMap=new S("lightMap",N),this.aoMap=new S("aoMap",N),this.emissiveMap=new S("emissiveMap",N),this.normalMap=new S("normalMap",N),this.normalScale=new i(1,1),this.sheen=0,this.sheenColor=new t("#FFFFFF"),this.sheenColorMap=new S("sheenColorMap",N),this.sheenRoughness=.5,this.sheenRoughnessMap=new S("sheenRoughnessMap",N),this.anisotropyMap=new S("anisotropyMap",N),this.anisotropy=0,this.heightMap=new S("heightMap",N),this.vertexColor=!1,this.uvScale=B}build(){P(this.map,p.SRGBColorSpace),P(this.alphaMap,p.LinearSRGBColorSpace),P(this.roughnessMap,p.LinearSRGBColorSpace),P(this.metalnessMap,p.LinearSRGBColorSpace),P(this.aoMap,p.LinearSRGBColorSpace),P(this.emissiveMap,p.SRGBColorSpace),P(this.normalMap,p.LinearSRGBColorSpace),P(this.sheenColorMap,p.LinearSRGBColorSpace),P(this.sheenRoughnessMap,p.LinearSRGBColorSpace),P(this.anisotropyMap,p.LinearSRGBColorSpace);let e=!1;const a=f("uvScale",this.uvScale??B);let n=C.uv.multiply(a);F(this.heightMap)&&0!==(this.heightScale??.05)&&(n=L(n,this.heightMap,g("heightScale",this.heightScale??.05)));const r=x(new d("particleData"));let s=m("IS_PARTICLE",new R("opacity",this.opacity,void 0,!1),e=>e.multiply(r.x)),o=new O("color",(new p.Vector3).setFromColor(this.color),void 0,!1).rgb;if(F(this.map)){const e=this.map.sample(n);o=o.multiply(e.rgb),s=s.multiply(e.a)}F(this.alphaMap)&&(s=s.multiply(this.alphaMap.sample(n).r)),!0===this.vertexColor&&(o=o.multiply(x(l.color.rgb)));let c=null,S=null;F(this.aoMap)&&(S=g("aoMapIntensity",this.aoMapIntensity??1),c=this.aoMap.sample(n).r);let T=g("roughness",this.roughness??1);F(this.roughnessMap)&&(T=T.multiply(this.roughnessMap.sample(n).g),e=!0);let N=g("metalness",this.metalness??0);F(this.metalnessMap)&&(N=N.multiply(this.metalnessMap.sample(n).b),e=!0);let D=null;F(this.lightMap)&&(D=this.lightMap.sample(n).rgb.multiplyScalar(g("lightMapIntensity",this.lightMapIntensity??1)));let _=M("emissive",(new p.Vector3).setFromColor(this.emissive??new t(0))).rgb;F(this.emissiveMap)&&(_=_.multiply(this.emissiveMap.sample(n).rgb));const I=g("emissiveIntensity",this.emissiveIntensity??1);let E=b.normal;if(F(this.normalMap)){const e=g("normalScale",this.normalScale?.x??1);E=h(this.normalMap.sample(n),e)}let V=null,G=null;if((this.sheen??0)>0){const e=g("sheen",this.sheen??0);V=M("sheenColor",(new p.Vector3).setFromColor(this.sheenColor??new t(16777215))).rgb.multiplyScalar(e),F(this.sheenColorMap)&&(V=V.multiply(this.sheenColorMap.sample(n).rgb)),G=g("sheenRoughness",this.sheenRoughness??.5),F(this.sheenRoughnessMap)&&(G=G.multiply(this.sheenRoughnessMap.sample(n).a))}(this.roughness<1||this.metalness>0)&&(e=!0);let H=null,A=null;if((this.anisotropy??0)>0&&(H=g("anisotropy",this.anisotropy??0),A=f("anisotropyDirection",(U=this.anisotropyRotation??0,new i(Math.cos(U),Math.sin(U)))),F(this.anisotropyMap))){const e=this.anisotropyMap.sample(n),a=v(w(e.r,e.g).multiplyScalar(2).subtract(w(1,1)));A=w(A.x.multiply(a.x).subtract(A.y.multiply(a.y)),A.y.multiply(a.x).add(A.x.multiply(a.y))),H=H.multiply(e.b)}var U;const z=new u({color:y({color:o.rgba(s),roughness:T,metalness:N,ambientOcclusion:c,ambientOcclusionIntensity:S,emissive:_,emissiveIntensity:I,normal:E,bakedLight:D,sheenColor:V,sheenRoughness:G,anisotropy:H,anisotropyDirection:A,specular:e}),opacity:s,roughness:T,normal:E,emissive:_.multiplyScalar(I),envMap:this.envMap});return null!=this.envMap&&(z.uniforms.envMapIntensity={value:this.envMapIntensity??1}),z.vertexColors=!0===this.vertexColor,z}}function F(e){return null!=e&&(!(e instanceof S)||null!=e.value&&e.value!==N)}e([o(),a("design:type",t)],StandardShader.prototype,"color",void 0),e([o({label:"Color Map"}),a("design:type",c)],StandardShader.prototype,"map",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"opacity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"alphaMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"roughness",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"roughnessMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"metalness",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"metalnessMap",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"lightMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"lightMapIntensity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"aoMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"aoMapIntensity",void 0),e([o(),a("design:type",t)],StandardShader.prototype,"emissive",void 0),e([o({range:[0,10]}),a("design:type",Number)],StandardShader.prototype,"emissiveIntensity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"emissiveMap",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"normalMap",void 0),e([o(),a("design:type",i)],StandardShader.prototype,"normalScale",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"sheen",void 0),e([o(),a("design:type",t)],StandardShader.prototype,"sheenColor",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"sheenColorMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"sheenRoughness",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"sheenRoughnessMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"anisotropyRotation",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"anisotropyMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"anisotropy",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"envMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"envMapIntensity",void 0),e([o(),a("design:type",c)],StandardShader.prototype,"heightMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"heightScale",void 0),e([o(),a("design:type",Boolean)],StandardShader.prototype,"vertexColor",void 0),e([o(),a("design:type",i)],StandardShader.prototype,"uvScale",void 0);export var ParallaxType;!function(e){e[e.none=0]="none",e[e.offset=1]="offset",e[e.pom=2]="pom"}(ParallaxType||(ParallaxType={}));export class ParallaxStandardMaterial extends n{constructor(e={}){super(e),e.heightMap&&(this.heightMap=e.heightMap),this.heightScale=e.heightScale??.05,this.parallaxType=e.parallaxType??ParallaxType.pom,this.minLayers=e.minLayers??10,this.maxLayers=e.maxLayers??32}onBeforeCompile(e){e.uniforms.heightMap={value:this.heightMap},e.uniforms.heightScale={value:this.heightScale},e.uniforms.minLayers={value:this.minLayers},e.uniforms.maxLayers={value:this.maxLayers},e.uniforms.parallaxType={value:this.parallaxType},e.vertexTangents=!0,e.vertexShader=e.vertexShader.replace("#include <uv_pars_vertex>","\n #include <uv_pars_vertex>\n "),e.vertexShader=e.vertexShader.replace("#include <begin_vertex>","\n #include <begin_vertex>\n "),e.fragmentShader=e.fragmentShader.replace("#include <uv_pars_fragment>","\n #include <uv_pars_fragment>\n uniform sampler2D heightMap;\n uniform float heightScale;\n uniform int minLayers;\n uniform int maxLayers;\n uniform int parallaxType;\n\n vec2 parallaxOffset(vec2 uv, vec3 viewDir, vec3 normal) {\n // Compute TBN in fragment shader using screen-space derivatives\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uv);\n vec2 duv2 = dFdy(uv);\n \n vec3 dp2perp = cross(dp2, normal);\n vec3 dp1perp = cross(normal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n \n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 tbn = mat3(T * invmax, B * invmax, normal);\n vec3 viewDirTS = -viewDir * tbn;\n\n float h = texture(heightMap, uv).r;\n return uv - (viewDirTS.xy / viewDirTS.z) * (h * heightScale);\n }\n\n vec2 parallaxOcclusion2(vec2 uv, vec3 viewDir, vec3 normal) {\n // Compute TBN in fragment shader using screen-space derivatives\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uv);\n vec2 duv2 = dFdy(uv);\n \n vec3 dp2perp = cross(dp2, normal);\n vec3 dp1perp = cross(normal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n \n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 tbn = mat3(T * invmax, B * invmax, normal);\n vec3 vv = -viewDir * tbn;\n\n float parallaxLimit = -length(vv.xy) / vv.z;\n parallaxLimit *= heightScale;\n\n vec2 vOffsetDir = normalize(vv.xy);\n vec2 vMaxOffset = vOffsetDir * parallaxLimit;\n\n float factor = pow(1.0 - abs(vv.z), 2.0);\n float nNumSamples = mix(float(minLayers), float(maxLayers), factor);\n float fStepSize = 1.0 / nNumSamples;\n\n float fCurrRayHeight = 1.0;\n vec2 vCurrOffset = vec2(0.0);\n vec2 vLastOffset = vec2(0.0);\n float fLastSampledHeight = 1.0;\n float fCurrSampledHeight = 1.0;\n\n for (int nCurrSample = 0; nCurrSample < 128; nCurrSample++) {\n if (float(nCurrSample) > nNumSamples) break;\n\n fCurrSampledHeight = texture2D(heightMap, uv + vCurrOffset).r;\n if (fCurrSampledHeight > fCurrRayHeight) {\n float delta1 = fCurrSampledHeight - fCurrRayHeight;\n float delta2 = (fCurrRayHeight + fStepSize) - fLastSampledHeight;\n float ratio = delta1 / (delta1 + delta2);\n vCurrOffset = ratio * vLastOffset + (1.0 - ratio) * vCurrOffset;\n break;\n } else {\n fCurrRayHeight -= fStepSize;\n vLastOffset = vCurrOffset;\n vCurrOffset += fStepSize * vMaxOffset;\n fLastSampledHeight = fCurrSampledHeight;\n }\n }\n\n return uv + vCurrOffset;\n }\n "),e.fragmentShader=e.fragmentShader.replace("#include <map_fragment>","\n vec3 pomViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n vec2 uvPOM = vMapUv ;\n if (parallaxType == 1) {\n uvPOM = parallaxOffset(vMapUv, pomViewDir, vNormal);\n } else if (parallaxType == 2) {\n uvPOM = parallaxOcclusion2(vMapUv, pomViewDir, vNormal);\n }\n\n vec4 texelColor = texture2D(map, uvPOM);\n diffuseColor *= texelColor;\n "),e.fragmentShader=e.fragmentShader.replace("#include <normal_fragment_maps>","\n #ifdef USE_NORMALMAP\n // RE-COMPUTE TBN for normal mapping consistency\n vec3 dp1 = dFdx(-vViewPosition);\n vec3 dp2 = dFdy(-vViewPosition);\n vec2 duv1 = dFdx(uvPOM);\n vec2 duv2 = dFdy(uvPOM);\n vec3 dp2perp = cross(dp2, vNormal);\n vec3 dp1perp = cross(vNormal, dp1);\n vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;\n vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;\n float invmax = inversesqrt(max(dot(T,T), dot(B,B)));\n mat3 localTBN = mat3(T * invmax, B * invmax, vNormal);\n\n vec3 mapN = texture2D(normalMap, uvPOM).xyz * 2.0 - 1.0;\n mapN.xy *= normalScale;\n normal = normalize( localTBN * mapN );\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <roughnessmap_fragment>","\n float roughnessFactor = roughness;\n #ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, uvPOM );\n // reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n roughnessFactor *= texelRoughness.g;\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <metalnesssmap_fragment>","\n float metalnessFactor = metalness;\n #ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, uvPOM );\n // reads channel B, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n metalnessFactor *= texelMetalness.b;\n #endif\n "),e.fragmentShader=e.fragmentShader.replace("#include <aomap_fragment>","\n #ifdef USE_AOMAP\n\n // reads channel R, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n float ambientOcclusion = ( texture2D( aoMap, uvPOM ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n\n #if defined( USE_CLEARCOAT ) \n clearcoatSpecularIndirect *= ambientOcclusion;\n #endif\n\n #if defined( USE_SHEEN ) \n sheenSpecularIndirect *= ambientOcclusion;\n #endif\n\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n\n float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\n #endif\n\n #endif\n "),this.userData.shader=e}clone(){const e=super.clone();return e.heightMap=this.heightMap,e.heightScale=this.heightScale,e.parallaxType=this.parallaxType,e.minLayers=this.minLayers,e.maxLayers=this.maxLayers,e}}export function applyTiling(e,a){if(null==e||null==a)return e;if(1===a.x&&1===a.y)return e;const t=e.clone();return t.repeat.copy(a),t.needsUpdate=!0,t}function P(e,a){null!=e&&(e instanceof r?e.colorSpace=a:e instanceof S&&null!=e.value&&(e.value.colorSpace=a))}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{Color as o,DataTexture as i,RedFormat as s,
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{Color as o,DataTexture as i,RedFormat as s,Vector2 as r}from"three";import{Parameter as a}from"../parameter.js";import{Shader as p}from"../shader.js";import*as n from"three";import{attributes as l,colorToNormal as h,NodeShaderMaterial as m,Sampler2DNode as y,toonMaterial as d,UniformSampler2d as g,uniformFloat as v,uniformVec3 as c,varying as u,varyingAttributes as S,varyingTransformed as M,vec2 as b}from"three-shader-graph";import{createPlaceholderTexture as T}from"../../utils/three/placeholder-texture.js";const w=T();export class ToonShader extends p{constructor(){super(...arguments),this.color=new o("#FFFFFF"),this.opacity=1,this.intensity=1,this.map=new g("map",w),this.lightSteps=[],this.lightMap=new g("lightMap",w),this.normalMap=new g("normalMap",w),this.normalScale=new r(1,1),this.aoMap=new g("aoMap",w),this.alphaMap=new g("alphaMap",w),this.emissiveMap=new g("emissiveMap",w),this.vertexColor=!1,this.uvScale=new r(1,1)}build(){let e;if(null!=this.lightSteps&&this.lightSteps.length>0){const t=new Uint8Array(this.lightSteps.length);for(let e=0;e<t.length;e++)t[e]=255*this.lightSteps[e];e=new i(t,t.length,1,s),e.needsUpdate=!0}const t=function(e,t){if(null==t||1===t.x&&1===t.y)return e;return e.multiply(b(t))}(S.uv,this.uvScale);let r=v("opacity",this.opacity),a=c("color",(new n.Vector3).setFromColor(this.color)).rgb.multiplyScalar(v("intensity",this.intensity));if(f(this.map)){const e=this.map.sample(t);a=a.multiply(e.rgb),r=r.multiply(e.a)}f(this.alphaMap)&&(r=r.multiply(this.alphaMap.sample(t).r)),!0===this.vertexColor&&(a=a.multiply(u(l.color.rgb)));let p=null;f(this.lightMap)&&(p=this.lightMap.sample(t).rgb.multiplyScalar(v("lightMapIntensity",this.lightMapIntensity??1)));let y=M.normal;f(this.normalMap)&&(y=h(this.normalMap.sample(t),v("normalScale",this.normalScale?.x??1)));let g=null;f(this.aoMap)&&(g=this.aoMap.sample(t).r);const T=v("aoMapIntensity",this.aoMapIntensity??1);let w=c("emissive",(new n.Vector3).setFromColor(this.emissive??new o(0))).rgb;f(this.emissiveMap)&&(w=w.multiply(this.emissiveMap.sample(t).rgb));const I=v("emissiveIntensity",this.emissiveIntensity??1),x=new m({color:d({color:a.rgba(r),gradientMap:e,bakedLight:p,normal:y,ambientOcclusion:g,ambientOcclusionIntensity:T,emissive:w,emissiveIntensity:I}),opacity:r,normal:y,emissive:w.multiplyScalar(I)});return x.vertexColors=!0===this.vertexColor,x}}function f(e){return null!=e&&(!(e instanceof g)||null!=e.value&&e.value!==w)}e([a(),t("design:type",o)],ToonShader.prototype,"color",void 0),e([a({range:[0,1]}),t("design:type",Number)],ToonShader.prototype,"opacity",void 0),e([a({range:[0,10]}),t("design:type",Number)],ToonShader.prototype,"intensity",void 0),e([a(),t("design:type",y)],ToonShader.prototype,"map",void 0),e([a({type:Number,array:!0,range:[0,1]}),t("design:type",Array)],ToonShader.prototype,"lightSteps",void 0),e([a(),t("design:type",y)],ToonShader.prototype,"lightMap",void 0),e([a(),t("design:type",Number)],ToonShader.prototype,"lightMapIntensity",void 0),e([a(),t("design:type",y)],ToonShader.prototype,"normalMap",void 0),e([a(),t("design:type",r)],ToonShader.prototype,"normalScale",void 0),e([a(),t("design:type",y)],ToonShader.prototype,"aoMap",void 0),e([a(),t("design:type",Number)],ToonShader.prototype,"aoMapIntensity",void 0),e([a(),t("design:type",y)],ToonShader.prototype,"alphaMap",void 0),e([a(),t("design:type",o)],ToonShader.prototype,"emissive",void 0),e([a({range:[0,10]}),t("design:type",Number)],ToonShader.prototype,"emissiveIntensity",void 0),e([a(),t("design:type",y)],ToonShader.prototype,"emissiveMap",void 0),e([a(),t("design:type",Boolean)],ToonShader.prototype,"vertexColor",void 0),e([a(),t("design:type",r)],ToonShader.prototype,"uvScale",void 0);/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as e}from"tslib";import{Color as i,Texture as o,Vector2 as p}from"three";import{Shader as
|
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{Color as i,Texture as o,Vector2 as p}from"three";import{Shader as r}from"../shader.js";import{Parameter as a}from"../parameter.js";import{attributes as l,NodeShaderMaterial as n,rgba as s,Sampler2DNode as h,UniformSampler2d as y,uniformFloat as d,uniformVec3 as m,varying as u,varyingAttributes as c,vec2 as g}from"three-shader-graph";import*as v from"three";import{createPlaceholderTexture as M}from"../../utils/three/placeholder-texture.js";const S=M();export class UnlitShader extends r{constructor(){super(...arguments),this.color=new i("#FFFFFF"),this.opacity=1,this.intensity=1,this.map=new y("map",S),this.lightMap=new y("lightMap",S),this.aoMap=new y("aoMap",S),this.alphaMap=new y("alphaMap",S),this.vertexColor=!1,this.uvScale=new p(1,1)}build(){const t=function(t,e){if(null==e||1===e.x&&1===e.y)return t;return t.multiply(g(e))}(c.uv,this.uvScale);let e=d("opacity",this.opacity),i=m("color",(new v.Vector3).setFromColor(this.color)).rgb.multiplyScalar(d("intensity",this.intensity));if(f(this.map)){const o=this.map.sample(t);i=i.multiply(o.rgb),e=e.multiply(o.a)}if(f(this.alphaMap)&&(e=e.multiply(this.alphaMap.sample(t).r)),!0===this.vertexColor&&(i=i.multiply(u(l.color.rgb))),f(this.lightMap)&&(i=i.add(this.lightMap.sample(t).rgb.multiplyScalar(d("lightMapIntensity",this.lightMapIntensity??1)))),f(this.aoMap)){const e=this.aoMap.sample(t).r,o=d("aoMapIntensity",this.aoMapIntensity??1);i=i.multiplyScalar(e.subtract(1).multiply(o).add(1))}const o=new n({color:s(i,e),opacity:e,emissive:i,envMap:this.envMap});return o.vertexColors=!0===this.vertexColor,o}}function f(t){return null!=t&&(!(t instanceof y)||null!=t.value&&t.value!==S)}t([a(),e("design:type",i)],UnlitShader.prototype,"color",void 0),t([a({range:[0,1]}),e("design:type",Number)],UnlitShader.prototype,"opacity",void 0),t([a({range:[0,10]}),e("design:type",Number)],UnlitShader.prototype,"intensity",void 0),t([a(),e("design:type",h)],UnlitShader.prototype,"map",void 0),t([a(),e("design:type",h)],UnlitShader.prototype,"lightMap",void 0),t([a(),e("design:type",Number)],UnlitShader.prototype,"lightMapIntensity",void 0),t([a(),e("design:type",h)],UnlitShader.prototype,"aoMap",void 0),t([a(),e("design:type",Number)],UnlitShader.prototype,"aoMapIntensity",void 0),t([a(),e("design:type",h)],UnlitShader.prototype,"alphaMap",void 0),t([a(),e("design:type",o)],UnlitShader.prototype,"envMap",void 0),t([a(),e("design:type",Boolean)],UnlitShader.prototype,"vertexColor",void 0),t([a(),e("design:type",p)],UnlitShader.prototype,"uvScale",void 0);/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{Color as r,Texture as o,Vector2 as a}from"three";import{abs as s,attributes as i,float as l,FloatNode as p,max as n,min as y,mix as u,pow as d,rgba as h,SimplexNoiseNode as c,standardMaterial as g,step as L,textureSampler2d as m,varying as v,varyingAttributes as M,vec2 as x,colorToNormal as k,varyingTransformed as f,attributeVec2 as C}from"three-shader-graph";import{edgeDepthEffect as b,fresnelEffect as T,oneMinus as w,sceneColorSampler as S,screenUV as A,timeUniforms as V}from"../shader-nodes/index.js";import{SerializedParamType as F}from"../scene/model.js";import{Parameter as N}from"./parameter.js";export var ColorLayerType;!function(e){e.solid="solid",e.refraction="refraction",e.lighting="lighting",e.texture="texture",e.textureMask="textureMask",e.vertexMask="vertexMask",e.fresnelMask="fresnelMask",e.depthMask="depthMask",e.gradientMask="gradientMask"}(ColorLayerType||(ColorLayerType={}));export const defaultValueColorLayer={enabled:!0,type:ColorLayerType.solid,outputType:"rgba",opacity:1,blendMode:"normal",params:{color:{type:F.Color,value:"#FFFFFF"}}};export const defaultValueMaskLayer={enabled:!0,type:ColorLayerType.textureMask,outputType:"alpha",opacity:1,blendMode:"normal",params:{texture:{type:F.Texture,value:null},channel:{type:F.String,value:"red"}}};const z={normal:(e,t,r)=>u(e,t,r),add:(e,t,r)=>e.add(t.multiplyScalar(r)),multiply:(e,t,r)=>u(e,e.multiply(t),r),screen:(e,t,r)=>u(e,w(w(e).multiply(w(t))),r),overlay:(e,t,r)=>{const o=u(e.multiply(t).multiplyScalar(2),w(l(2).multiplyVec3(w(e)).multiply(w(t))),L(.5,e));return u(e,o.rgb,r)},difference:(e,t,r)=>u(e,s(e.subtract(t)),r),subtract:(e,t,r)=>u(e,e.subtract(t),r)};export const blendModes=Object.keys(z);const B={normal:(e,t,r)=>u(e,t,r),add:(e,t,r)=>e.add(t.multiply(r)),multiply:(e,t,r)=>u(e,e.multiply(t),r),max:(e,t,r)=>u(e,n(e,t),r),min:(e,t,r)=>u(e,y(e,t),r),difference:(e,t,r)=>u(e,s(e.subtract(t)),r),subtract:(e,t,r)=>u(e,e.subtract(t),r)};export const maskBlendModes=Object.keys(B);export class ColorLayer{constructor(){this.layers=[]}static get outputType(){return"rgba"}apply(e){const t=this.output();if(t instanceof p)return h(e.rgb,this.applyMask(e.a));{let a=t;if(null!=this.layers&&(a=this.layers.filter(e=>!1!==e.enabled).reduce((e,t)=>t.apply(e),t)),null==e)return a;const s=z[this.blendMode]??z.normal,i=a.a.multiply(this.opacity),l=s(e.rgb,a.rgb,i);let p=(r=e.a,(o=i).add(r.multiply(w(o))));return h(l,p)}var r,o}applyMask(e){const t=this.output();if(t instanceof p){let r=t;null!=this.layers&&(r=this.layers.filter(e=>!1!==e.enabled).reduce((e,t)=>t.applyMask(e),t));return(B[this.blendMode]??z.normal)(e,r,this.opacity)}return console.error("Can not use non-float layer for mask"),e}init(e,t){}static async decode(e,t){if(console.log("Decode value",e),!isColorLayerSerialized(e))return;const r=new layerTypes[e.type];return r.enabled=e.enabled,r.opacity=e.opacity??1,r.blendMode=e.blendMode,r}output(){return h("white")}}export class SolidColorLayer extends ColorLayer{constructor(){super(...arguments),this.color=new r("white"),this.layers=[]}output(){return h(this.color).multiplyScalar(1.3)}}e([N(),t("design:type",r)],SolidColorLayer.prototype,"color",void 0),e([N({type:ColorLayer,array:!0}),t("design:type",Array)],SolidColorLayer.prototype,"layers",void 0);export class TextureColorLayer extends ColorLayer{constructor(){super(...arguments),this.texture=new o,this.scale=new a(1,1),this.scroll=new a(0,0),this.layers=[]}output(){let e=M.uv;return null!=this.scroll&&this.scroll.lengthSq()>0&&(e=e.add(x(this.scroll).multiplyScalar(V.elapsed))),e=e.multiply(x(this.scale??1)),m(this.texture).sample(e)}}e([N(),t("design:type",o)],TextureColorLayer.prototype,"texture",void 0),e([N(),t("design:type",a)],TextureColorLayer.prototype,"scale",void 0),e([N(),t("design:type",a)],TextureColorLayer.prototype,"scroll",void 0),e([N({type:ColorLayer,array:!0}),t("design:type",Array)],TextureColorLayer.prototype,"layers",void 0);export class RefractionColorLayer extends ColorLayer{constructor(){super(...arguments),this.texture=new o,this.layers=[]}output(){return S.sample(A.addScalar(new c(M.uv).multiply(.2)))}}e([N(),t("design:type",o)],RefractionColorLayer.prototype,"texture",void 0),e([N({type:ColorLayer,array:!0}),t("design:type",Array)],RefractionColorLayer.prototype,"layers",void 0);export class LightingColorLayer extends ColorLayer{constructor(){super(...arguments),this.roughness=1,this.metalness=0}apply(e){const t=M.uv,r=e?.a??l(1);let o=l(this.roughness);null!=this.roughnessMap&&(o=o.multiply(m(this.roughnessMap).sample(t).g));let a=l(this.metalness);null!=this.metalnessMap&&(a=a.multiply(m(this.metalnessMap).sample(t).b));let s=f.normal;null!=this.normalMap&&(s=k(m(this.normalMap).sample(t),this.normalScale));let i=null;null!=this.aoMap&&(i=m(this.aoMap).sample(t).r);let p=null;null!=this.lightMap&&(p=m(this.lightMap).sample(t).rgb);let n=h(this.emissive??"black",r);return null!=this.emissiveMap&&(n=n.multiply(m(this.emissiveMap).sample(t))),g({color:e,emissive:n,emissiveIntensity:l(this.emissiveIntensity??1),metalness:a,roughness:o,normal:s,ambientOcclusion:i,ambientOcclusionIntensity:l(this.aoMapIntensity??1),bakedLight:p?.multiplyScalar(this.lightMapIntensity??1)})}}e([N({range:[0,1]}),t("design:type",Number)],LightingColorLayer.prototype,"roughness",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"roughnessMap",void 0),e([N({range:[0,1]}),t("design:type",Number)],LightingColorLayer.prototype,"metalness",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"metalnessMap",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"lightMap",void 0),e([N(),t("design:type",Number)],LightingColorLayer.prototype,"lightMapIntensity",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"aoMap",void 0),e([N(),t("design:type",Number)],LightingColorLayer.prototype,"aoMapIntensity",void 0),e([N(),t("design:type",r)],LightingColorLayer.prototype,"emissive",void 0),e([N({range:[0,10]}),t("design:type",Number)],LightingColorLayer.prototype,"emissiveIntensity",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"emissiveMap",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"normalMap",void 0),e([N(),t("design:type",p)],LightingColorLayer.prototype,"normalScale",void 0);export class MaskLayer extends ColorLayer{constructor(){super(...arguments),this.power=1,this.invert=!1}static get outputType(){return"float"}output(){let e=this.outputAlpha();return this.invert&&(e=w(e)),null!=this.power&&1!==this.power&&(e=d(e,this.power)),e}outputAlpha(){throw"not implemented"}}const I=["red","green","blue","alpha"];export class TextureMaskLayer extends MaskLayer{constructor(){super(...arguments),this.texture=new o,this.channel="red",this.space="uv",this.flipU=!1,this.flipV=!1,this.scale=new a(1,1),this.scroll=new a(0,0),this.offsetLayers=[],this.offset=new a(1,0),this.power=1,this.invert=!1,this.layers=[]}outputAlpha(){let e=M.uv;switch(this.space??"uv"){case"uv":e=M.uv;break;case"uv1":e=v(C("uv1"));break;case"uv2":e=v(C("uv2"));break;case"uv3":e=v(C("uv3"));break;case"world xz":e=f.worldPosition.xz}if(this.flipU&&(e=x(w(e.x),e.y)),this.flipV&&(e=x(e.x,w(e.y))),null!=this.scroll&&this.scroll.lengthSq()>0&&(e=e.add(x(this.scroll).multiplyScalar(V.elapsed))),null!=this.offsetLayers&&this.offsetLayers.length>0&&null!=this.offset&&this.offset.lengthSq()>0){const t=this.offsetLayers.reduce((e,t)=>t.applyMask(e),l(0));e=e.add(x(this.offset).multiplyScalar(t))}e=e.multiply(x(this.scale??1));return j(m(this.texture).sample(e),this.channel)}}e([N(),t("design:type",o)],TextureMaskLayer.prototype,"texture",void 0),e([N({options:I.map(e=>({name:e,value:e}))}),t("design:type",String)],TextureMaskLayer.prototype,"channel",void 0),e([N({options:["uv","uv1","uv2","uv3","world xz"].map(e=>({name:e,value:e}))}),t("design:type",String)],TextureMaskLayer.prototype,"space",void 0),e([N(),t("design:type",Boolean)],TextureMaskLayer.prototype,"flipU",void 0),e([N(),t("design:type",Boolean)],TextureMaskLayer.prototype,"flipV",void 0),e([N(),t("design:type",a)],TextureMaskLayer.prototype,"scale",void 0),e([N(),t("design:type",a)],TextureMaskLayer.prototype,"scroll",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],TextureMaskLayer.prototype,"offsetLayers",void 0),e([N(),t("design:type",a)],TextureMaskLayer.prototype,"offset",void 0),e([N(),t("design:type",Number)],TextureMaskLayer.prototype,"power",void 0),e([N(),t("design:type",Boolean)],TextureMaskLayer.prototype,"invert",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],TextureMaskLayer.prototype,"layers",void 0);export class VertexMaskLayer extends MaskLayer{constructor(){super(...arguments),this.channel="red",this.power=1,this.invert=!1,this.layers=[]}outputAlpha(){const e=i.color;return v(j(e,this.channel))}}function j(e,t){switch(t??"red"){case"red":return e.r;case"green":return e.g;case"blue":return e.b;case"alpha":return e.a}}e([N({options:I.map(e=>({name:e,value:e}))}),t("design:type",String)],VertexMaskLayer.prototype,"channel",void 0),e([N(),t("design:type",Number)],VertexMaskLayer.prototype,"power",void 0),e([N(),t("design:type",Boolean)],VertexMaskLayer.prototype,"invert",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],VertexMaskLayer.prototype,"layers",void 0);export class GradientMaskLayer extends MaskLayer{constructor(){super(...arguments),this.direction="u",this.start=0,this.end=1,this.invert=!1,this.layers=[]}outputAlpha(){return u(l(this.start),l(this.end),function(e){switch(e??"u"){case"u":return M.uv.x;case"v":return M.uv.y;case"x":return M.position.x;case"y":return M.position.y;case"z":return M.position.z}}(this.direction))}}e([N({options:["u","v","x","y","z"].map(e=>({name:e,value:e}))}),t("design:type",String)],GradientMaskLayer.prototype,"direction",void 0),e([N(),t("design:type",Number)],GradientMaskLayer.prototype,"start",void 0),e([N(),t("design:type",Number)],GradientMaskLayer.prototype,"end",void 0),e([N(),t("design:type",Boolean)],GradientMaskLayer.prototype,"invert",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],GradientMaskLayer.prototype,"layers",void 0);export class FresnelMaskLayer extends MaskLayer{constructor(){super(...arguments),this.power=1,this.invert=!1,this.layers=[]}outputAlpha(){return v(T(1))}}e([N(),t("design:type",Number)],FresnelMaskLayer.prototype,"power",void 0),e([N(),t("design:type",Boolean)],FresnelMaskLayer.prototype,"invert",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],FresnelMaskLayer.prototype,"layers",void 0);export class DepthMaskLayer extends MaskLayer{constructor(){super(...arguments),this.power=1,this.invert=!1,this.layers=[]}outputAlpha(){return b(1)}}e([N(),t("design:type",Number)],DepthMaskLayer.prototype,"power",void 0),e([N(),t("design:type",Boolean)],DepthMaskLayer.prototype,"invert",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],DepthMaskLayer.prototype,"layers",void 0);export function isColorLayerSerialized(e){return"object"==typeof e&&null!==e&&"boolean"==typeof e.enabled&&"string"==typeof e.type&&e.outputType&&("object"==typeof e.params||void 0===e.params)}export const layerTypes={[ColorLayerType.solid]:SolidColorLayer,[ColorLayerType.texture]:TextureColorLayer,[ColorLayerType.refraction]:RefractionColorLayer,[ColorLayerType.lighting]:LightingColorLayer,[ColorLayerType.textureMask]:TextureMaskLayer,[ColorLayerType.vertexMask]:VertexMaskLayer,[ColorLayerType.fresnelMask]:FresnelMaskLayer,[ColorLayerType.depthMask]:DepthMaskLayer,[ColorLayerType.gradientMask]:GradientMaskLayer};/*
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{Color as r,Texture as o,Vector2 as a}from"three";import{abs as s,attributes as i,float as l,FloatNode as p,max as y,min as n,mix as u,pow as d,rgba as h,SimplexNoiseNode as c,standardMaterial as g,step as L,textureSampler2d as m,varying as v,varyingAttributes as M,vec2 as x,colorToNormal as k,varyingTransformed as f,attributeVec2 as C}from"three-shader-graph";import{edgeDepthEffect as b,fresnelEffect as T,oneMinus as w,sceneColorSampler as S,screenUV as A,timeUniforms as V}from"../shader-nodes/index.js";import{SerializedParamType as F}from"../scene/model.js";import{Parameter as N}from"./parameter.js";import{createPlaceholderTexture as j}from"../utils/three/placeholder-texture.js";export var ColorLayerType;!function(e){e.solid="solid",e.refraction="refraction",e.lighting="lighting",e.texture="texture",e.textureMask="textureMask",e.vertexMask="vertexMask",e.fresnelMask="fresnelMask",e.depthMask="depthMask",e.gradientMask="gradientMask"}(ColorLayerType||(ColorLayerType={}));export const defaultValueColorLayer={enabled:!0,type:ColorLayerType.solid,outputType:"rgba",opacity:1,blendMode:"normal",params:{color:{type:F.Color,value:"#FFFFFF"}}};export const defaultValueMaskLayer={enabled:!0,type:ColorLayerType.textureMask,outputType:"alpha",opacity:1,blendMode:"normal",params:{texture:{type:F.Texture,value:null},channel:{type:F.String,value:"red"}}};const z={normal:(e,t,r)=>u(e,t,r),add:(e,t,r)=>e.add(t.multiplyScalar(r)),multiply:(e,t,r)=>u(e,e.multiply(t),r),screen:(e,t,r)=>u(e,w(w(e).multiply(w(t))),r),overlay:(e,t,r)=>{const o=u(e.multiply(t).multiplyScalar(2),w(l(2).multiplyVec3(w(e)).multiply(w(t))),L(.5,e));return u(e,o.rgb,r)},difference:(e,t,r)=>u(e,s(e.subtract(t)),r),subtract:(e,t,r)=>u(e,e.subtract(t),r)};export const blendModes=Object.keys(z);const B={normal:(e,t,r)=>u(e,t,r),add:(e,t,r)=>e.add(t.multiply(r)),multiply:(e,t,r)=>u(e,e.multiply(t),r),max:(e,t,r)=>u(e,y(e,t),r),min:(e,t,r)=>u(e,n(e,t),r),difference:(e,t,r)=>u(e,s(e.subtract(t)),r),subtract:(e,t,r)=>u(e,e.subtract(t),r)};export const maskBlendModes=Object.keys(B);export class ColorLayer{constructor(){this.layers=[]}static get outputType(){return"rgba"}apply(e){const t=this.output();if(t instanceof p)return h(e.rgb,this.applyMask(e.a));{let a=t;if(null!=this.layers&&(a=this.layers.filter(e=>!1!==e.enabled).reduce((e,t)=>t.apply(e),t)),null==e)return a;const s=z[this.blendMode]??z.normal,i=a.a.multiply(this.opacity),l=s(e.rgb,a.rgb,i);let p=(r=e.a,(o=i).add(r.multiply(w(o))));return h(l,p)}var r,o}applyMask(e){const t=this.output();if(t instanceof p){let r=t;null!=this.layers&&(r=this.layers.filter(e=>!1!==e.enabled).reduce((e,t)=>t.applyMask(e),t));return(B[this.blendMode]??z.normal)(e,r,this.opacity)}return console.error("Can not use non-float layer for mask"),e}init(e,t){}static async decode(e,t){if(console.log("Decode value",e),!isColorLayerSerialized(e))return;const r=new layerTypes[e.type];return r.enabled=e.enabled,r.opacity=e.opacity??1,r.blendMode=e.blendMode,r}output(){return h("white")}}export class SolidColorLayer extends ColorLayer{constructor(){super(...arguments),this.color=new r("white"),this.layers=[]}output(){return h(this.color).multiplyScalar(1.3)}}e([N(),t("design:type",r)],SolidColorLayer.prototype,"color",void 0),e([N({type:ColorLayer,array:!0}),t("design:type",Array)],SolidColorLayer.prototype,"layers",void 0);export class TextureColorLayer extends ColorLayer{constructor(){super(...arguments),this.texture=j(),this.scale=new a(1,1),this.scroll=new a(0,0),this.layers=[]}output(){let e=M.uv;return null!=this.scroll&&this.scroll.lengthSq()>0&&(e=e.add(x(this.scroll).multiplyScalar(V.elapsed))),e=e.multiply(x(this.scale??1)),m(this.texture).sample(e)}}e([N(),t("design:type",o)],TextureColorLayer.prototype,"texture",void 0),e([N(),t("design:type",a)],TextureColorLayer.prototype,"scale",void 0),e([N(),t("design:type",a)],TextureColorLayer.prototype,"scroll",void 0),e([N({type:ColorLayer,array:!0}),t("design:type",Array)],TextureColorLayer.prototype,"layers",void 0);export class RefractionColorLayer extends ColorLayer{constructor(){super(...arguments),this.texture=j(),this.layers=[]}output(){return S.sample(A.addScalar(new c(M.uv).multiply(.2)))}}e([N(),t("design:type",o)],RefractionColorLayer.prototype,"texture",void 0),e([N({type:ColorLayer,array:!0}),t("design:type",Array)],RefractionColorLayer.prototype,"layers",void 0);export class LightingColorLayer extends ColorLayer{constructor(){super(...arguments),this.roughness=1,this.metalness=0}apply(e){const t=M.uv,r=e?.a??l(1);let o=l(this.roughness);null!=this.roughnessMap&&(o=o.multiply(m(this.roughnessMap).sample(t).g));let a=l(this.metalness);null!=this.metalnessMap&&(a=a.multiply(m(this.metalnessMap).sample(t).b));let s=f.normal;null!=this.normalMap&&(s=k(m(this.normalMap).sample(t),this.normalScale));let i=null;null!=this.aoMap&&(i=m(this.aoMap).sample(t).r);let p=null;null!=this.lightMap&&(p=m(this.lightMap).sample(t).rgb);let y=h(this.emissive??"black",r);return null!=this.emissiveMap&&(y=y.multiply(m(this.emissiveMap).sample(t))),g({color:e,emissive:y,emissiveIntensity:l(this.emissiveIntensity??1),metalness:a,roughness:o,normal:s,ambientOcclusion:i,ambientOcclusionIntensity:l(this.aoMapIntensity??1),bakedLight:p?.multiplyScalar(this.lightMapIntensity??1)})}}e([N({range:[0,1]}),t("design:type",Number)],LightingColorLayer.prototype,"roughness",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"roughnessMap",void 0),e([N({range:[0,1]}),t("design:type",Number)],LightingColorLayer.prototype,"metalness",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"metalnessMap",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"lightMap",void 0),e([N(),t("design:type",Number)],LightingColorLayer.prototype,"lightMapIntensity",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"aoMap",void 0),e([N(),t("design:type",Number)],LightingColorLayer.prototype,"aoMapIntensity",void 0),e([N(),t("design:type",r)],LightingColorLayer.prototype,"emissive",void 0),e([N({range:[0,10]}),t("design:type",Number)],LightingColorLayer.prototype,"emissiveIntensity",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"emissiveMap",void 0),e([N(),t("design:type",o)],LightingColorLayer.prototype,"normalMap",void 0),e([N(),t("design:type",p)],LightingColorLayer.prototype,"normalScale",void 0);export class MaskLayer extends ColorLayer{constructor(){super(...arguments),this.power=1,this.invert=!1}static get outputType(){return"float"}output(){let e=this.outputAlpha();return this.invert&&(e=w(e)),null!=this.power&&1!==this.power&&(e=d(e,this.power)),e}outputAlpha(){throw"not implemented"}}const I=["red","green","blue","alpha"];export class TextureMaskLayer extends MaskLayer{constructor(){super(...arguments),this.texture=j(),this.channel="red",this.space="uv",this.flipU=!1,this.flipV=!1,this.scale=new a(1,1),this.scroll=new a(0,0),this.offsetLayers=[],this.offset=new a(1,0),this.power=1,this.invert=!1,this.layers=[]}outputAlpha(){let e=M.uv;switch(this.space??"uv"){case"uv":e=M.uv;break;case"uv1":e=v(C("uv1"));break;case"uv2":e=v(C("uv2"));break;case"uv3":e=v(C("uv3"));break;case"world xz":e=f.worldPosition.xz}if(this.flipU&&(e=x(w(e.x),e.y)),this.flipV&&(e=x(e.x,w(e.y))),null!=this.scroll&&this.scroll.lengthSq()>0&&(e=e.add(x(this.scroll).multiplyScalar(V.elapsed))),null!=this.offsetLayers&&this.offsetLayers.length>0&&null!=this.offset&&this.offset.lengthSq()>0){const t=this.offsetLayers.reduce((e,t)=>t.applyMask(e),l(0));e=e.add(x(this.offset).multiplyScalar(t))}e=e.multiply(x(this.scale??1));return G(m(this.texture).sample(e),this.channel)}}e([N(),t("design:type",o)],TextureMaskLayer.prototype,"texture",void 0),e([N({options:I.map(e=>({name:e,value:e}))}),t("design:type",String)],TextureMaskLayer.prototype,"channel",void 0),e([N({options:["uv","uv1","uv2","uv3","world xz"].map(e=>({name:e,value:e}))}),t("design:type",String)],TextureMaskLayer.prototype,"space",void 0),e([N(),t("design:type",Boolean)],TextureMaskLayer.prototype,"flipU",void 0),e([N(),t("design:type",Boolean)],TextureMaskLayer.prototype,"flipV",void 0),e([N(),t("design:type",a)],TextureMaskLayer.prototype,"scale",void 0),e([N(),t("design:type",a)],TextureMaskLayer.prototype,"scroll",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],TextureMaskLayer.prototype,"offsetLayers",void 0),e([N(),t("design:type",a)],TextureMaskLayer.prototype,"offset",void 0),e([N(),t("design:type",Number)],TextureMaskLayer.prototype,"power",void 0),e([N(),t("design:type",Boolean)],TextureMaskLayer.prototype,"invert",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],TextureMaskLayer.prototype,"layers",void 0);export class VertexMaskLayer extends MaskLayer{constructor(){super(...arguments),this.channel="red",this.power=1,this.invert=!1,this.layers=[]}outputAlpha(){const e=i.color;return v(G(e,this.channel))}}function G(e,t){switch(t??"red"){case"red":return e.r;case"green":return e.g;case"blue":return e.b;case"alpha":return e.a}}e([N({options:I.map(e=>({name:e,value:e}))}),t("design:type",String)],VertexMaskLayer.prototype,"channel",void 0),e([N(),t("design:type",Number)],VertexMaskLayer.prototype,"power",void 0),e([N(),t("design:type",Boolean)],VertexMaskLayer.prototype,"invert",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],VertexMaskLayer.prototype,"layers",void 0);export class GradientMaskLayer extends MaskLayer{constructor(){super(...arguments),this.direction="u",this.start=0,this.end=1,this.invert=!1,this.layers=[]}outputAlpha(){return u(l(this.start),l(this.end),function(e){switch(e??"u"){case"u":return M.uv.x;case"v":return M.uv.y;case"x":return M.position.x;case"y":return M.position.y;case"z":return M.position.z}}(this.direction))}}e([N({options:["u","v","x","y","z"].map(e=>({name:e,value:e}))}),t("design:type",String)],GradientMaskLayer.prototype,"direction",void 0),e([N(),t("design:type",Number)],GradientMaskLayer.prototype,"start",void 0),e([N(),t("design:type",Number)],GradientMaskLayer.prototype,"end",void 0),e([N(),t("design:type",Boolean)],GradientMaskLayer.prototype,"invert",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],GradientMaskLayer.prototype,"layers",void 0);export class FresnelMaskLayer extends MaskLayer{constructor(){super(...arguments),this.power=1,this.invert=!1,this.layers=[]}outputAlpha(){return v(T(1))}}e([N(),t("design:type",Number)],FresnelMaskLayer.prototype,"power",void 0),e([N(),t("design:type",Boolean)],FresnelMaskLayer.prototype,"invert",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],FresnelMaskLayer.prototype,"layers",void 0);export class DepthMaskLayer extends MaskLayer{constructor(){super(...arguments),this.power=1,this.invert=!1,this.layers=[]}outputAlpha(){return b(1)}}e([N(),t("design:type",Number)],DepthMaskLayer.prototype,"power",void 0),e([N(),t("design:type",Boolean)],DepthMaskLayer.prototype,"invert",void 0),e([N({type:MaskLayer,array:!0}),t("design:type",Array)],DepthMaskLayer.prototype,"layers",void 0);export function isColorLayerSerialized(e){return"object"==typeof e&&null!==e&&"boolean"==typeof e.enabled&&"string"==typeof e.type&&e.outputType&&("object"==typeof e.params||void 0===e.params)}export const layerTypes={[ColorLayerType.solid]:SolidColorLayer,[ColorLayerType.texture]:TextureColorLayer,[ColorLayerType.refraction]:RefractionColorLayer,[ColorLayerType.lighting]:LightingColorLayer,[ColorLayerType.textureMask]:TextureMaskLayer,[ColorLayerType.vertexMask]:VertexMaskLayer,[ColorLayerType.fresnelMask]:FresnelMaskLayer,[ColorLayerType.depthMask]:DepthMaskLayer,[ColorLayerType.gradientMask]:GradientMaskLayer};/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -10,6 +10,11 @@ export declare class ShaderGraphCompileError extends Error {
|
|
|
10
10
|
export interface ShaderGraphCompileOptions {
|
|
11
11
|
parameters?: Record<string, unknown>;
|
|
12
12
|
}
|
|
13
|
+
interface ShaderGraphMaterialBuildOptions extends ShaderGraphCompileOptions {
|
|
14
|
+
previewNodeId?: string;
|
|
15
|
+
trailBillboard?: boolean;
|
|
16
|
+
alphaTest?: number | null;
|
|
17
|
+
}
|
|
13
18
|
export interface ShaderGraphCompileResult {
|
|
14
19
|
output: ShaderGraphNodeShaderOutput;
|
|
15
20
|
nodes: Map<string, CompiledShaderGraphNode>;
|
|
@@ -76,13 +81,11 @@ export declare class ShaderGraphCompiler {
|
|
|
76
81
|
}
|
|
77
82
|
export declare function compileShaderGraph(graph: ShaderGraphDocument, options?: ShaderGraphCompileOptions): ShaderGraphCompileResult;
|
|
78
83
|
export declare function compileShaderGraphPreview(graph: ShaderGraphDocument, selectedNodeId?: string, options?: ShaderGraphCompileOptions): NodeShaderOutput;
|
|
79
|
-
export declare function buildShaderGraphMaterial(graph: ShaderGraphDocument, options?:
|
|
80
|
-
previewNodeId?: string;
|
|
81
|
-
trailBillboard?: boolean;
|
|
82
|
-
}): Material;
|
|
84
|
+
export declare function buildShaderGraphMaterial(graph: ShaderGraphDocument, options?: ShaderGraphMaterialBuildOptions): Material;
|
|
83
85
|
export declare function buildShaderGraphPostProcessMaterial(graph: ShaderGraphDocument, options?: ShaderGraphCompileOptions & {
|
|
84
86
|
previewNodeId?: string;
|
|
85
87
|
}): NodeShaderMaterial;
|
|
88
|
+
export declare function buildShaderGraphInlinePreviewMaterial(graph: ShaderGraphDocument, previewNodeId: string, options?: ShaderGraphCompileOptions): NodeShaderMaterial;
|
|
86
89
|
export declare function shaderGraphMaterialSideToThree(side: ShaderGraphMaterialSide | undefined): Side;
|
|
87
90
|
export {};
|
|
88
91
|
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{BackSide as t,Color as e,DoubleSide as a,FrontSide as r,Matrix4 as u,Texture as i,Vector2 as o,Vector3 as n,Vector4 as s}from"three";import{BooleanNode as l,FloatNode as p,Mat4Node as c,NodeShaderMaterial as h,RgbNode as v,RgbaNode as y,Sampler2DNode as m,Texture2dLookupNode as d,UniformFloatNode as f,Vec2Node as g,Vec3Node as b,Vec4Node as x,abs as w,acos as T,asin as I,attributes as S,atan as O,atan2 as M,autoVarying as C,bulge as N,bool as E,ceil as G,clamp as U,colorToNormal as B,cos as $,cross as z,degrees as V,distance as k,dot as P,exp as A,exp2 as j,float as D,floor as L,fract as q,inversesqrt as F,batchingMatrix as R,colorGradientSampler as _,curveSampler as W,ifDefApply as H,sampleNamedEasingCurve as Y,length as J,LayerMixMode as K,log as Q,log2 as X,mat4 as Z,max as tt,min as et,mix as at,mixColorsByLayer as rt,particleUniforms as ut,mod as it,normalize as ot,pow as nt,radians as st,rgba as lt,rgb as pt,saturate as ct,select as ht,sign as vt,sin as yt,smoothstep as mt,sqrt as dt,standardMaterial as ft,scaleTransform as gt,step as bt,tan as xt,textureSampler2d as wt,timeUniforms as Tt,toonMaterial as It,translate as St,transformed as Ot,triplanarMapping as Mt,twirl as Ct,uniformFloat as Nt,uniforms as Et,varyingAttributes as Gt,vec2 as Ut,vec3 as Bt,vec4 as $t,getPaintedMaterialLayerWeight as zt}from"../../shader-nodes/index.js";import{SpriteNodeShaderMaterial as Vt,getSpritePosition as kt}from"../sprite-shader.js";import{oneMinus as Pt}from"../../shader-nodes/index.js";import{vectorToRadial as At,remap as jt,hueShift as Dt,blendColor as Lt,desaturateColor as qt}from"../../shader-nodes/math.js";import{rectangleFloat as Ft,roundedRectangleFloat as Rt}from"../../shader-nodes/shapes.js";import{edgeDepthEffect as _t,fresnelEffect as Wt,depthFadeEffect as Ht}from"../../shader-nodes/effects.js";import{fragmentLinearEyeDepth as Yt,sampleSceneDepth as Jt,sampleSceneLinearEyeDepth as Kt,screenUV as Qt,nearUniformName as Xt,farUniformName as Zt}from"../../shader-nodes/depth.js";import{sampleSceneColor as te}from"../../shader-nodes/scene-sample.js";import{decalDiscard as ee,decalUV as ae}from"../../shader-nodes/decal.js";import{Trail as re,trailUV as ue}from"../../effects/vfx/trail-renderer.js";import{SimplexNoiseNode as ie,Voronoi2d as oe,rotateAxis as ne}from"../../shader-nodes/index.js";import{flipbookUv as se}from"../../shader-nodes/texture-sequence.js";import{parallaxOcclusionMapping as le}from"../../shader-nodes/pom.js";import{defaultInlineLiteralValueForPort as pe,inlineLiteralTypeForPort as ce,SHADER_GRAPH_NODE_DEFINITIONS as he}from"./registry.js";import{shaderGraphParameterTypeToValueType as ve}from"./parameters.js";import{varying as ye,reflect as me,refract as de,dFdx as fe,dFdy as ge,fwidth as be}from"three-shader-graph";import{decalNormal as xe}from"../../shader-nodes/decal.js";import{Curve2 as we}from"../../utils/curve.js";export class ShaderGraphCompileError extends Error{constructor(t,e,a){super(t),this.nodeId=e,this.port=a,this.name="ShaderGraphCompileError"}}export const shaderGraphPostProcessWeightUniformName="hology_post_process_weight";export class ShaderGraphCompiler{constructor(t,e={}){this.graph=t,this.options=e,this.compiled=new Map,this.nodesById=new Map((t.nodes??[]).map(t=>[t.id,t]))}validate(){this.compile()}compile(){if(1!==this.graph.version)throw new ShaderGraphCompileError(`Unsupported shader graph version ${this.graph.version}`);return this.validateEdges(),{output:this.compileOutput(),nodes:this.compiled}}validateEdges(){for(const t of this.graph.edges??[]){if(!this.nodesById.has(t.from.nodeId))throw new ShaderGraphCompileError(`Edge references missing source node "${t.from.nodeId}"`,t.from.nodeId,t.from.port);if(!this.nodesById.has(t.to.nodeId))throw new ShaderGraphCompileError(`Edge references missing target node "${t.to.nodeId}"`,t.to.nodeId,t.to.port)}}compileOutput(){if("postProcess"===this.graph.target)return this.compilePostProcessOutput();const t=this.graph.outputs?.color,e={color:null!=t?this.toColorOutput(this.resolveOutputBinding(t,"color")):lt("#ffffff",1),transparent:Se(this.graph)},a=this.graph.outputs?.opacity;null!=a&&(e.opacity=this.expectType(this.resolveOutputBinding(a,"opacity"),["float"],"opacity").value);const r=this.graph.outputs?.roughness;null!=r&&(e.roughness=this.expectType(this.resolveOutputBinding(r,"roughness"),["float"],"roughness").value);const u=this.graph.outputs?.metalness;null!=u&&(e.metalness=this.floatOutput(u,"metalness"));const i=this.graph.outputs?.normal;null!=i&&(e.normal=this.toVec3Output(this.resolveOutputBinding(i,"normal"),"normal"));const o=this.graph.outputs?.emissive;null!=o&&(e.emissive=this.toVec3Output(this.resolveOutputBinding(o,"emissive"),"emissive"));const n=this.graph.outputs?.ambientOcclusion;null!=n&&(e.ambientOcclusion=this.floatOutput(n,"ambientOcclusion"));const s=this.graph.outputs?.ambientOcclusionIntensity;null!=s&&(e.ambientOcclusionIntensity=this.floatOutput(s,"ambientOcclusionIntensity"));const l=this.graph.outputs?.sheenColor;null!=l&&(e.sheenColor=this.toVec3Output(this.resolveOutputBinding(l,"sheenColor"),"sheenColor"));const p=this.graph.outputs?.sheenRoughness;null!=p&&(e.sheenRoughness=this.floatOutput(p,"sheenRoughness"));const c=this.graph.outputs?.anisotropy;null!=c&&(e.anisotropy=this.floatOutput(c,"anisotropy"));const h=this.graph.outputs?.anisotropyDirection;null!=h&&(e.anisotropyDirection=this.expectType(this.resolveOutputBinding(h,"anisotropyDirection"),["vec2"],"anisotropyDirection").value);const v=this.graph.outputs?.bakedLight;null!=v&&(e.bakedLight=this.toVec3Output(this.resolveOutputBinding(v,"bakedLight"),"bakedLight"));const y=this.graph.outputs?.transform;null!=y&&"decal"!==this.graph.target&&(e.transform=this.toMat4Output(this.resolveOutputBinding(y,"transform"),"transform"));const m=this.graph.outputs?.discard;null!=m&&(e.discard=this.expectType(this.resolveOutputBinding(m,"discard"),["boolean"],"discard").value);const d=this.graph.outputs?.transparent;null!=d&&null!=d.value&&(e.transparent=Boolean(d.value));const f=this.graph.outputs?.alphaTest;return null!=f&&null!=f.value&&(e.alphaTest=Number(f.value)),this.applyShadingModel(e)}compilePostProcessOutput(){const t=this.graph.outputs?.color,e=null!=t?this.toColorOutput(this.resolveOutputBinding(t,"color")):te(Qt),a=this.graph.outputs?.opacity;return Te(e,null!=a?this.expectType(this.resolveOutputBinding(a,"opacity"),["float"],"opacity").value:void 0)}applyShadingModel(t){const e=null!=t.opacity?function(t,e){if(t instanceof p)return lt(Bt(t,t,t),e);if(t instanceof g)return lt(Bt(t.x,t.y,0),e);if(t instanceof x)return lt(t.rgb,t.w.multiply(e));return lt(t,e)}(t.color,t.opacity):t.color;switch(this.graph.shadingModel??"standard"){case"standard":{const a={color:Ne(e),roughness:t.roughness??D(.5),...null!=t.metalness?{metalness:t.metalness}:{},..."decal"===this.graph.target?{normal:ot(ye(Et.normalMatrix).multiplyVec(xe))}:{},...null!=t.normal?{normal:t.normal}:{},...null!=t.emissive?{emissive:Ee(t.emissive)}:{},...null!=t.ambientOcclusion?{ambientOcclusion:t.ambientOcclusion}:{},...null!=t.ambientOcclusionIntensity?{ambientOcclusionIntensity:t.ambientOcclusionIntensity}:{},...null!=t.sheenColor?{sheenColor:t.sheenColor.rgb}:{},...null!=t.sheenRoughness?{sheenRoughness:t.sheenRoughness}:{},...null!=t.anisotropy?{anisotropy:t.anisotropy}:{},...null!=t.anisotropyDirection?{anisotropyDirection:t.anisotropyDirection}:{},...null!=t.bakedLight?{bakedLight:t.bakedLight}:{}};return{...t,color:ft(a)}}case"toon":{const a={color:Ne(e),...null!=t.normal?{normal:t.normal}:{},...null!=t.emissive?{emissive:Ee(t.emissive)}:{},...null!=t.ambientOcclusion?{ambientOcclusion:t.ambientOcclusion}:{},...null!=t.ambientOcclusionIntensity?{ambientOcclusionIntensity:t.ambientOcclusionIntensity}:{},...null!=t.bakedLight?{bakedLight:t.bakedLight}:{}};return{...t,color:It(a)}}case"unlit":return{...t,color:e}}}compileNode(t){const e=this.compiled.get(t);if(null!=e)return e;const a=this.nodesById.get(t);if(null==a)throw new ShaderGraphCompileError(`Missing shader graph node "${t}"`,t);if(null==he[a.kind])throw new ShaderGraphCompileError(`Unsupported shader graph node "${a.kind}"`,a.id);const r=this.compileNodeInternal(a);return this.compiled.set(t,r),r}compileNodeInternal(t){switch(t.kind){case"input.parameter":return this.output(t,this.compileParameterNode(t));case"input.slider":return this.output(t,{value:{type:"float",value:D(je(Ue(t,"value",.5)))}});case"constant.boolean":return this.output(t,{value:{type:"boolean",value:E(Boolean(Ge(t,"value",!1)))}});case"constant.float":return this.output(t,{value:{type:"float",value:D(Ue(t,"value",0))}});case"constant.vec2":return this.output(t,{value:{type:"vec2",value:qe(Ge(t,"value",[0,0]))}});case"constant.vec3":return this.output(t,{value:{type:"vec3",value:Fe(Ge(t,"value",[0,0,0]))}});case"constant.rgba":return this.output(t,{value:{type:"rgba",value:Re(Ge(t,"value","#ffffff"),Ue(t,"alpha",1))}});case"builtin.uv":{const e=this.defaultUV();return this.output(t,{value:{type:"vec2",value:!0===Ge(t,"flipY",!1)?Ut(e.x,Pt(e.y)):e},u:{type:"float",value:e.x},v:{type:"float",value:e.y}})}case"builtin.screenUv":return this.output(t,{value:{type:"vec2",value:Qt}});case"builtin.color":{const e=C(S.color);return this.output(t,{value:{type:"rgba",value:e},rgb:{type:"rgb",value:e.rgb},r:{type:"float",value:e.r},g:{type:"float",value:e.g},b:{type:"float",value:e.b},a:{type:"float",value:e.a}})}case"builtin.position":{const e=C(S.position);return this.output(t,{value:{type:"vec3",value:e},x:{type:"float",value:e.x},y:{type:"float",value:e.y},z:{type:"float",value:e.z}})}case"builtin.worldPosition":{const e=C(Ot.worldPosition);return this.output(t,{value:{type:"vec3",value:e},x:{type:"float",value:e.x},y:{type:"float",value:e.y},z:{type:"float",value:e.z}})}case"builtin.objectPosition":{let e=Et.instanceMatrix.multiplyVec($t(0,0,0,1));e=H("USE_BATCHING",e,t=>R.multiplyVec(t));const a=C(Et.modelMatrix.multiplyVec(e).xyz);return this.output(t,{value:{type:"vec3",value:a},x:{type:"float",value:a.x},y:{type:"float",value:a.y},z:{type:"float",value:a.z}})}case"builtin.viewDir":{const e=C(Ot.viewDir);return this.output(t,{value:{type:"vec3",value:e},x:{type:"float",value:e.x},y:{type:"float",value:e.y},z:{type:"float",value:e.z}})}case"builtin.normal":{const e=C(S.normal);return this.output(t,{value:{type:"vec3",value:e},x:{type:"float",value:e.x},y:{type:"float",value:e.y},z:{type:"float",value:e.z}})}case"builtin.time":return this.output(t,{value:{type:"float",value:Tt.elapsed}});case"builtin.camera":{const e=Nt(Xt),a=Nt(Zt),r=Et.cameraPosition;return this.output(t,{position:{type:"vec3",value:r},x:{type:"float",value:r.x},y:{type:"float",value:r.y},z:{type:"float",value:r.z},near:{type:"float",value:e},far:{type:"float",value:a}})}case"builtin.viewMatrix":return this.output(t,{value:{type:"mat4",value:Et.viewMatrix}});case"builtin.projectionMatrix":return this.output(t,{value:{type:"mat4",value:Et.projectionMatrix}});case"builtin.modelViewMatrix":return this.output(t,{value:{type:"mat4",value:Et.modelViewMatrix}});case"builtin.particle":return this.output(t,{energy:{type:"float",value:ut.energy},color:{type:"rgb",value:ut.color},opacity:{type:"float",value:ut.opacity},time:{type:"float",value:ut.time}});case"math.add":case"math.subtract":case"math.multiply":case"math.divide":return this.output(t,{value:this.compileBinaryMath(t)});case"math.oneMinus":{const e=this.expectNumeric(this.input(t,"value"));return this.output(t,{value:{type:e.type,value:Pt(e.value)}})}case"math.abs":return this.output(t,{value:this.compileUnaryMath(t,w)});case"math.sign":return this.output(t,{value:this.compileUnaryMath(t,vt)});case"math.floor":return this.output(t,{value:this.compileUnaryMath(t,L)});case"math.ceil":return this.output(t,{value:this.compileUnaryMath(t,G)});case"math.fract":return this.output(t,{value:this.compileUnaryMath(t,q)});case"math.sin":return this.output(t,{value:this.compileUnaryMath(t,yt)});case"math.cos":return this.output(t,{value:this.compileUnaryMath(t,$)});case"math.tan":return this.output(t,{value:this.compileUnaryMath(t,xt)});case"math.asin":return this.output(t,{value:this.compileUnaryMath(t,I)});case"math.acos":return this.output(t,{value:this.compileUnaryMath(t,T)});case"math.atan":return this.output(t,{value:this.compileUnaryMath(t,O)});case"math.atan2":return this.output(t,{value:this.compileAtan2(t)});case"math.radians":return this.output(t,{value:this.compileUnaryMath(t,st)});case"math.degrees":return this.output(t,{value:this.compileUnaryMath(t,V)});case"math.sqrt":return this.output(t,{value:this.compileUnaryMath(t,dt)});case"math.inverseSqrt":return this.output(t,{value:this.compileUnaryMath(t,F)});case"math.exp":return this.output(t,{value:this.compileUnaryMath(t,A)});case"math.exp2":return this.output(t,{value:this.compileUnaryMath(t,j)});case"math.log":return this.output(t,{value:this.compileUnaryMath(t,Q)});case"math.log2":return this.output(t,{value:this.compileUnaryMath(t,X)});case"math.saturate":return this.output(t,{value:this.compileUnaryMath(t,ct)});case"math.length":{const e=this.expectNumeric(this.input(t,"value"));return this.output(t,{value:{type:"float",value:J(e.value)}})}case"math.normalize":return this.output(t,{value:this.compileUnaryMath(t,ot)});case"math.clamp":{const e=this.expectNumeric(this.input(t,"value")),a=this.expectNumeric(this.input(t,"min",{type:"float",value:D(0)})),r=this.expectNumeric(this.input(t,"max",{type:"float",value:D(1)}));return this.output(t,{value:{type:e.type,value:U(e.value,a.value,r.value)}})}case"math.min":return this.output(t,{value:this.compileBinaryFunction(t,et)});case"math.max":return this.output(t,{value:this.compileBinaryFunction(t,tt)});case"math.pow":return this.output(t,{value:this.compileBinaryFunction(t,nt)});case"math.mod":return this.output(t,{value:this.compileBinaryFunction(t,it)});case"math.step":return this.output(t,{value:this.compileBinaryFunction(t,bt,!0)});case"math.smoothstep":{const e=this.expectNumeric(this.input(t,"edge0",{type:"float",value:D(0)})),a=this.expectNumeric(this.input(t,"edge1",{type:"float",value:D(1)})),r=this.expectNumeric(this.input(t,"value"));return this.output(t,{value:{type:r.type,value:mt(e.value,a.value,r.value)}})}case"math.mix":{const e=this.expectNumeric(this.input(t,"a")),a=this.expectNumeric(this.input(t,"b")),r=this.expectNumeric(this.input(t,"t",{type:"float",value:D(.5)})),u=Ve(e.type,a.type,t.id);return this.output(t,{value:{type:u,value:at(e.value,a.value,r.value)}})}case"math.remap":{const e=this.expectType(this.input(t,"value"),["float"],t.id,"value").value,a=this.floatInput(t,"inMin",-1),r=this.floatInput(t,"inMax",1),u=this.floatInput(t,"outMin",0),i=this.floatInput(t,"outMax",1);return this.output(t,{value:{type:"float",value:jt(e,a,r,u,i)}})}case"math.select":{const e=this.boolInput(t,"condition",!1),a=this.expectNumeric(this.input(t,"a")),r=this.expectNumeric(this.input(t,"b")),u=Ve(a.type,r.type,t.id);return this.output(t,{value:{type:u,value:ht(e,a.value,r.value)}})}case"math.reflect":{const e=this.expectType(this.input(t,"incident"),["vec2","vec3","vec4","rgb","rgba"],t.id,"incident"),a=this.expectType(this.input(t,"normal"),["vec2","vec3","vec4","rgb","rgba"],t.id,"normal");return this.output(t,{value:{type:e.type,value:me(e.value,a.value)}})}case"math.refract":{const e=this.expectType(this.input(t,"incident"),["vec2","vec3","vec4","rgb","rgba"],t.id,"incident"),a=this.expectType(this.input(t,"normal"),["vec2","vec3","vec4","rgb","rgba"],t.id,"normal"),r=this.floatInput(t,"ior",1.5);return this.output(t,{value:{type:e.type,value:de(e.value,a.value,r)}})}case"math.derivative":{const e=this.expectNumeric(this.input(t,"value")),a=String(Ge(t,"mode","fwidth"));let r;return r="dFdx"===a?fe(e.value):"dFdy"===a?ge(e.value):be(e.value),this.output(t,{value:{type:e.type,value:r}})}case"layer.mixPainted":return this.output(t,{value:this.compilePaintedLayerMix(t)});case"math.dot":{const e=this.expectNumeric(this.input(t,"a")),a=this.expectNumeric(this.input(t,"b"));return Ve(e.type,a.type,t.id),this.output(t,{value:{type:"float",value:P(e.value,a.value)}})}case"math.distance":{const e=this.expectNumeric(this.input(t,"a")),a=this.expectNumeric(this.input(t,"b"));return Ve(e.type,a.type,t.id),this.output(t,{value:{type:"float",value:k(e.value,a.value)}})}case"math.cross":{const e=this.expectType(this.input(t,"a"),["vec3","rgb"],t.id,"a"),a=this.expectType(this.input(t,"b"),["vec3","rgb"],t.id,"b");return this.output(t,{value:{type:"vec3",value:z(e.value,a.value)}})}case"compare.greaterThan":case"compare.greaterThanOrEqual":case"compare.lessThan":case"compare.lessThanOrEqual":case"compare.equal":case"compare.notEqual":return this.output(t,{value:{type:"boolean",value:this.compileComparison(t)}});case"boolean.not":{const e=this.boolInput(t,"value",!1);return this.output(t,{value:{type:"boolean",value:ht(e,E(!1),E(!0))}})}case"boolean.and":return this.output(t,{value:{type:"boolean",value:this.compileBooleanBinary(t,"and")}});case"boolean.or":return this.output(t,{value:{type:"boolean",value:this.compileBooleanBinary(t,"or")}});case"compose.vec2":return this.output(t,{value:{type:"vec2",value:Ut(this.floatInput(t,"x",0),this.floatInput(t,"y",0))}});case"compose.vec3":return this.output(t,{value:{type:"vec3",value:Bt(this.floatInput(t,"x",0),this.floatInput(t,"y",0),this.floatInput(t,"z",0))}});case"compose.vec4":return this.output(t,{value:{type:"vec4",value:$t(this.floatInput(t,"x",0),this.floatInput(t,"y",0),this.floatInput(t,"z",0),this.floatInput(t,"w",0))}});case"compose.rgba":return this.output(t,{value:{type:"rgba",value:$t(this.floatInput(t,"r",1),this.floatInput(t,"g",1),this.floatInput(t,"b",1),this.floatInput(t,"a",1))}});case"decompose.component":{const e=this.expectNumeric(this.input(t,"value")),a=String(Ge(t,"component","x"));return this.output(t,{value:{type:"float",value:Pe(e,a,t.id)}})}case"decompose.split":{const e=this.expectNumeric(this.input(t,"value"));return this.output(t,function(t,e){const a={},r=(r,u)=>{a[r]={type:"float",value:Pe(t,u,e)}};switch(t.type){case"vec2":return r("x","x"),r("y","y"),r("u","x"),r("v","y"),a;case"vec3":return r("x","x"),r("y","y"),r("z","z"),a;case"rgb":return r("r","r"),r("g","g"),r("b","b"),r("x","x"),r("y","y"),r("z","z"),a;case"vec4":return r("x","x"),r("y","y"),r("z","z"),r("w","w"),a;case"rgba":return r("r","r"),r("g","g"),r("b","b"),r("a","a"),r("x","x"),r("y","y"),r("z","z"),r("w","w"),a;case"float":return a.x={type:"float",value:t.value},a}}(e,t.id))}case"color.gradient":{const e=this.expectType(this.input(t,"t",{type:"float",value:D(.5)}),["float"],t.id,"t"),a=_(function(t){const e=Ge(t,"stops",[]);if(!Array.isArray(e))return[];const a=e.map((t,a)=>{if(null==t||"object"!=typeof t||Array.isArray(t))return;const r=t,u="string"==typeof r.color?r.color:"#ffffff";return{position:De(r.position,_e(a,e.length)),color:u,alpha:De(r.alpha,1)}}).filter(t=>null!=t);return a.length>0?a:[]}(t)).sample(e.value);return this.output(t,{value:{type:"rgba",value:a}})}case"utility.curve":{const e=this.expectType(this.input(t,"t",{type:"float",value:D(.5)}),["float"],t.id,"t"),a=Ge(t,"curve","Linear"),r=Y(a,e.value)??W(we.decode(a)).sample(e.value);return this.output(t,{value:{type:"float",value:r}})}case"color.hueShift":{const e=this.expectType(this.input(t,"color"),["rgba","rgb","vec4","vec3"],t.id,"color"),a=e.value,r="rgba"===e.type||"vec4"===e.type?a.rgb??a.xyz:a,u=this.floatInput(t,"shift",0),i=Dt(r,u);return"rgba"===e.type||"vec4"===e.type?this.output(t,{value:{type:e.type,value:$t(i,a.a??a.w)}}):this.output(t,{value:{type:e.type,value:i}})}case"color.blend":{const e=this.expectType(this.input(t,"base"),["rgba","rgb","vec4","vec3"],t.id,"base"),a=this.expectType(this.input(t,"blend"),["rgba","rgb","vec4","vec3"],t.id,"blend"),r=String(Ge(t,"mode","multiply")),u=e.value,i=a.value,o="rgba"===e.type||"vec4"===e.type?u.rgb??u.xyz:u,n="rgba"===a.type||"vec4"===a.type?i.rgb??i.xyz:i;let s=Lt(o,n,r);if("rgba"===a.type||"vec4"===a.type){const t=i.a??i.w;s=at(o,s,t)}if("rgba"===e.type||"vec4"===e.type){const a=u.a??u.w;return this.output(t,{value:{type:e.type,value:$t(s,a)}})}return this.output(t,{value:{type:e.type,value:s}})}case"color.desaturate":{const e=this.expectType(this.input(t,"color"),["rgba","rgb","vec4","vec3"],t.id,"color"),a=e.value,r="rgba"===e.type||"vec4"===e.type?a.rgb??a.xyz:a,u=this.floatInput(t,"fraction",1),i=qt(r,u);return"rgba"===e.type||"vec4"===e.type?this.output(t,{value:{type:e.type,value:$t(i,a.a??a.w)}}):this.output(t,{value:{type:e.type,value:i}})}case"color.unpackNormal":{const e=this.expectType(this.input(t,"color"),["vec3","vec4","rgb","rgba"],t.id,"color"),a=this.floatInput(t,"scale",1),r=this.optionalInput(t,"normal");return this.output(t,{value:{type:"vec3",value:B(e.value,a,r?this.expectType(r,["vec3"],t.id,"normal").value:void 0)}})}case"texture.sampler2d":{const e=this.input(t,"texture");return this.output(t,{value:this.toSampler(e,t.id)})}case"texture.sample2d":{const e=this.toSampler(this.input(t,"sampler"),t.id),a=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv"),r=e.value.sample(a.value);return this.output(t,{rgba:{type:"rgba",value:r},rgb:{type:"rgb",value:r.rgb},r:{type:"float",value:r.r},g:{type:"float",value:r.g},b:{type:"float",value:r.b},a:{type:"float",value:r.a}})}case"texture.triplanarMapping":{const e=this.input(t,"sampler"),a=this.toSampler(e,t.id),r=this.expectType(this.input(t,"scale",{type:"float",value:D(1)}),["float"],t.id,"scale"),u=this.expectType(this.input(t,"normal",{type:"vec3",value:Gt.normal}),["vec3"],t.id,"normal"),i=this.expectType(this.input(t,"position",{type:"vec3",value:Gt.position}),["vec3"],t.id,"position"),o=Mt(a.value,r.value,u.value,i.value);return this.output(t,{rgba:{type:"rgba",value:o},rgb:{type:"rgb",value:o.rgb},r:{type:"float",value:o.r},g:{type:"float",value:o.g},b:{type:"float",value:o.b},a:{type:"float",value:o.a}})}case"scene.sampleColor":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:Qt}),["vec2"],t.id,"uv"),a=te(e.value);return this.output(t,{rgba:{type:"rgba",value:a},rgb:{type:"rgb",value:a.rgb},r:{type:"float",value:a.r},g:{type:"float",value:a.g},b:{type:"float",value:a.b},a:{type:"float",value:a.a}})}case"scene.sampleDepth":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:Qt}),["vec2"],t.id,"uv");return this.output(t,{depth:{type:"float",value:Jt(e.value)},linearEyeDepth:{type:"float",value:Kt(e.value)}})}case"scene.fragmentDepth":return this.output(t,{linearEyeDepth:{type:"float",value:Yt}});case"transform.translate":{const e=this.expectType(this.input(t,"offset",{type:"vec3",value:Bt(0,0,0)}),["vec3","rgb"],t.id,"offset");return this.output(t,{value:{type:"mat4",value:St(e.value)}})}case"transform.scale":{const e=this.expectType(this.input(t,"scale",{type:"vec3",value:Bt(1,1,1)}),["vec3","rgb"],t.id,"scale").value;return this.output(t,{value:{type:"mat4",value:gt(e.x,e.y,e.z)}})}case"transform.rotateAxis":{const e=this.expectType(this.input(t,"axis",{type:"vec3",value:Bt(0,1,0)}),["vec3","rgb"],t.id,"axis"),a=this.expectType(this.input(t,"angle",{type:"float",value:D(0)}),["float"],t.id,"angle");return this.output(t,{value:{type:"mat4",value:ne(e.value,a.value)}})}case"uv.rotate":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.expectType(this.input(t,"angle",{type:"float",value:D(0)}),["float"],t.id,"angle").value,r=this.expectType(this.input(t,"center",{type:"vec2",value:Ut(.5,.5)}),["vec2"],t.id,"center").value;return this.output(t,{value:{type:"vec2",value:ke(e,a,r)}})}case"uv.twirl":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.expectType(this.input(t,"strength",{type:"float",value:D(1)}),["float"],t.id,"strength").value,r=this.expectType(this.input(t,"center",{type:"vec2",value:Ut(.5,.5)}),["vec2"],t.id,"center").value,u=this.expectType(this.input(t,"offset",{type:"vec2",value:Ut(0,0)}),["vec2"],t.id,"offset").value;return this.output(t,{value:{type:"vec2",value:Ct(e,a,r,u)}})}case"uv.radial":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=At(e.subtractScalar(.5));return this.output(t,{coords:{type:"vec2",value:a.coords},radius:{type:"float",value:a.radius},angle:{type:"float",value:a.angle}})}case"uv.bulge":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.expectType(this.input(t,"center",{type:"vec2",value:Ut(.5,.5)}),["vec2"],t.id,"center").value,r=this.expectType(this.input(t,"power",{type:"float",value:D(1)}),["float"],t.id,"power").value;return this.output(t,{value:{type:"vec2",value:N(e,a,r)}})}case"uv.flipbook":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.floatInput(t,"columns",Ue(t,"columns",1)),r=this.floatInput(t,"rows",Ue(t,"rows",1)),u=this.floatInput(t,"fps",Ue(t,"fps",60)),i=this.expectType(this.input(t,"time",{type:"float",value:Tt.elapsed}),["float"],t.id,"time").value,o=String(Ge(t,"mode","clamp"));return this.output(t,{value:{type:"vec2",value:se(e,a,r,i,u,o)}})}case"uv.pom":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.input(t,"heightMap"),r=this.toSampler(a,t.id).value,u=this.floatInput(t,"heightScale",.05),i=Ue(t,"minLayers",8),o=Ue(t,"maxLayers",24);return this.output(t,{value:{type:"vec2",value:le(e,r,u,i,o)}})}case"shape.rectangle":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value;return this.output(t,{value:{type:"float",value:Ft(e,this.floatInput(t,"width",.5),this.floatInput(t,"height",.5))}})}case"shape.roundedRectangle":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value;return this.output(t,{value:{type:"float",value:Rt(e,this.floatInput(t,"width",.5),this.floatInput(t,"height",.5),this.floatInput(t,"radius",.1))}})}case"noise.simplex":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.floatInput(t,"scale",8);return this.output(t,{value:{type:"float",value:new ie(e.multiplyScalar(a))}})}case"noise.voronoi2d":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.floatInput(t,"scale",8);return this.output(t,{value:{type:"float",value:new oe(e.multiplyScalar(a))}})}case"effect.fresnel":return this.output(t,{value:{type:"float",value:C(Wt(this.floatInput(t,"power",1)))}});case"effect.edgeDepth":{const e=this.floatInput(t,"power",1);return this.output(t,{value:{type:"float",value:_t(e)}})}case"effect.depthFade":{const e=this.floatInput(t,"distance",1);return this.output(t,{value:{type:"float",value:Ht(e)}})}case"util.panner":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"coord"),a=this.expectType(this.input(t,"speed",{type:"vec2",value:Ut(0,0)}),["vec2"],t.id,"speed"),r=this.expectType(this.input(t,"tile",{type:"vec2",value:Ut(1,1)}),["vec2"],t.id,"tile"),u=this.expectType(this.input(t,"time",{type:"float",value:Tt.elapsed}),["float"],t.id,"time");return this.output(t,{value:{type:"vec2",value:e.value.multiply(r.value).add(a.value.multiplyScalar(u.value))}})}}}compileParameterNode(t){const e=String(Ge(t,"parameter","")),a=this.graph.parameters?.find(t=>t.name===e||t.id===e);if(null==a)throw new ShaderGraphCompileError(`Parameter "${e}" does not exist`,t.id);const r=ve(a.type),u={type:r,value:$e(this.options.parameters?.[a.name]??a.defaultValue,r,a.name)};if("sampler2d"!==r)return{value:u};const i=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv"),o=u.value.sample(i.value);return{value:{type:"rgba",value:o},rgb:{type:"rgb",value:o.rgb},r:{type:"float",value:o.r},g:{type:"float",value:o.g},b:{type:"float",value:o.b},a:{type:"float",value:o.a},sampler:u}}compileBinaryMath(t){const e=this.expectBinaryMathValue(this.input(t,"a")),a=this.expectBinaryMathValue(this.input(t,"b")),r=t.kind.split(".")[1];if("mat4"===e.type||"mat4"===a.type)return function(t,e,a,r){if("mat4"===t.type&&"mat4"===e.type&&"divide"!==a)return{type:"mat4",value:ze(t.value,e.value,a,r)};if("mat4"===t.type&&"float"===e.type&&("multiply"===a||"divide"===a))return{type:"mat4",value:ze(t.value,e.value,a,r)};if("float"===t.type&&"mat4"===e.type&&"multiply"===a)return{type:"mat4",value:ze(e.value,t.value,a,r)};if("mat4"===t.type&&"vec4"===e.type&&"multiply"===a)return{type:"vec4",value:t.value.multiplyVec(e.value)};throw new ShaderGraphCompileError(`Cannot ${a} ${t.type} and ${e.type}`,r)}(e,a,r,t.id);if(e.type===a.type)return{type:e.type,value:ze(e.value,a.value,r,t.id)};if("float"===e.type&&"float"!==a.type&&"multiply"===r)return{type:a.type,value:ze(a.value,e.value,r,t.id)};if("float"!==e.type&&"float"===a.type)return{type:e.type,value:ze(e.value,a.value,r,t.id)};throw new ShaderGraphCompileError(`Cannot ${r} ${e.type} and ${a.type}`,t.id)}expectBinaryMathValue(t){if(!Ae(t.type)&&"mat4"!==t.type)throw new ShaderGraphCompileError(`Expected a numeric value but got ${t.type}`);return t}compileUnaryMath(t,e){const a=this.expectNumeric(this.input(t,"value"));return{type:a.type,value:e(a.value)}}compileAtan2(t){const e=this.expectNumeric(this.input(t,"y")),a=this.expectNumeric(this.input(t,"x"));return{type:function(t,e,a){if(t===e)return t;if("rgb"===t&&"vec3"===e||"vec3"===t&&"rgb"===e)return"vec3";if("rgba"===t&&"vec4"===e||"vec4"===t&&"rgba"===e)return"vec4";throw new ShaderGraphCompileError(`Cannot mix ${t} and ${e}`,a)}(e.type,a.type,t.id),value:M(e.value,a.value)}}compileBinaryFunction(t,e,a=!1){const r=this.expectNumeric(this.input(t,"a")),u=this.expectNumeric(this.input(t,"b"));return{type:a&&"float"===u.type?r.type:Ve(r.type,u.type,t.id),value:e(r.value,u.value)}}compilePaintedLayerMix(t){const e=this.expectNumeric(this.input(t,"base")),a=[e.value],r=[zt(0)];let u=e.type;for(let e=1;e<=8;e++){const i=this.optionalInput(t,`layer${e}`);if(null==i)continue;const o=this.expectNumeric(i);u=Ve(u,o.type,t.id),a.push(o.value),r.push(zt(e))}return 1===a.length?e:{type:u,value:rt({layerColors:a,layerWeights:r,enableNoise:Boolean(Ge(t,"enableNoise",!0)),noiseScale:this.floatInput(t,"noiseScale",Ue(t,"noiseScale",.1)),noiseAmount:this.floatInput(t,"noiseAmount",Ue(t,"noiseAmount",.5)),decay:this.floatInput(t,"softness",Ue(t,"softness",.3)),mode:"hard"===String(Ge(t,"mode","soft"))?K.hard:K.soft})}}defaultUV(){return"trail"===this.graph.target?ue:"decal"===this.graph.target?ae:C(S.uv)}input(t,e,a){const r=t.inputs?.[e];if(null!=r)return this.resolveInput(r,t.id,e);const u=(this.graph.edges??[]).find(a=>a.to.nodeId===t.id&&a.to.port===e);if(null!=u)return this.resolveSocket(u.from,t.id,e);if(null!=a)return a;const i=this.inlineLiteralFallback(t,e);if(null!=i)return i;throw new ShaderGraphCompileError(`Missing input "${e}"`,t.id,e)}optionalInput(t,e){const a=t.inputs?.[e];if(null!=a)return this.resolveInput(a,t.id,e);const r=(this.graph.edges??[]).find(a=>a.to.nodeId===t.id&&a.to.port===e);return null!=r?this.resolveSocket(r.from,t.id,e):void 0}floatInput(t,e,a){return this.expectType(this.input(t,e,{type:"float",value:D(a)}),["float"],t.id,e).value}boolInput(t,e,a){return this.expectType(this.input(t,e,{type:"boolean",value:E(a)}),["boolean"],t.id,e).value}compileComparison(t){const e=this.expectType(this.input(t,"a"),["float"],t.id,"a").value,a=this.expectType(this.input(t,"b"),["float"],t.id,"b").value;switch(t.kind){case"compare.greaterThan":return e.gt(a);case"compare.greaterThanOrEqual":return e.gte(a);case"compare.lessThan":return e.lt(a);case"compare.lessThanOrEqual":return e.lte(a);case"compare.equal":return e.equals(a);case"compare.notEqual":return e.notEquals(a)}throw new ShaderGraphCompileError(`Unsupported comparison node "${t.kind}"`,t.id)}compileBooleanBinary(t,e){const a=this.boolInput(t,"a",!1),r=this.boolInput(t,"b",!1);return"and"===e?a.and(r):a.or(r)}resolveOutputBinding(t,e){if(null!=t.input)return this.resolveSocket(t.input,void 0,e);if(void 0!==t.value)return Be(t.value);throw new ShaderGraphCompileError(`Output "${e}" is missing an input or value`)}floatOutput(t,e){return this.expectType(this.resolveOutputBinding(t,e),["float"],e).value}resolveInput(t,e,a){return function(t){return null!=t.nodeId}(t)?this.resolveSocket(t,e,a):Be(t.value,t.valueType)}inlineLiteralFallback(t,e){const a=he[t.kind]?.inputs.find(t=>t.name===e);if(null==a)return;const r=ce(t.kind,a),u=pe(t.kind,a);return null!=r&&void 0!==u?Be(u,r):void 0}resolveSocket(t,e,a){const r=this.compileNode(t.nodeId).outputs[t.port];if(null==r)throw new ShaderGraphCompileError(`Node "${t.nodeId}" does not have output "${t.port}"`,e??t.nodeId,a??t.port);return r}expectType(t,e,a,r){if(!e.includes(t.type))throw new ShaderGraphCompileError(`Expected ${e.join(" or ")} but got ${t.type}`,a,r);return t}expectNumeric(t){if(!Ae(t.type))throw new ShaderGraphCompileError(`Expected a numeric value but got ${t.type}`);return t}toSampler(t,e){if("sampler2d"===t.type)return t;if("texture2d"===t.type){const a=t.value;if(null==a)throw new ShaderGraphCompileError("Texture input is empty",e);return{type:"sampler2d",value:wt(a)}}throw new ShaderGraphCompileError(`Expected texture2d or sampler2d but got ${t.type}`,e)}toColorOutput(t){switch(t.type){case"float":case"vec2":case"vec3":case"vec4":case"rgb":case"rgba":return t.value;case"boolean":{const e=ht(t.value,D(1),D(0));return lt(Bt(e,e,e),1)}case"mat4":throw new ShaderGraphCompileError("mat4 values cannot be used as color");case"texture2d":case"sampler2d":throw new ShaderGraphCompileError(`${t.type} must be sampled before it can be used as color`)}}toVec3Output(t,e){if("vec3"===t.type||"rgb"===t.type)return t.value;if("vec4"===t.type||"rgba"===t.type)return t.value.xyz;throw new ShaderGraphCompileError(`Output "${e}" expects vec3/rgb but got ${t.type}`)}toMat4Output(t,e){if("mat4"===t.type)return t.value;throw new ShaderGraphCompileError(`Output "${e}" expects mat4 but got ${t.type}`)}output(t,e){return{node:t,outputs:e}}}export function compileShaderGraph(t,e={}){return new ShaderGraphCompiler(t,e).compile()}export function compileShaderGraphPreview(t,e,a={}){if(null==e)return compileShaderGraph(t,a).output;const r=new ShaderGraphCompiler(t,a).compileNode(e),u=Object.values(r.outputs)[0];if(null==u)throw new ShaderGraphCompileError(`Node "${e}" has no previewable output`,e);return{color:Me(u),transparent:"rgba"===u.type||"vec4"===u.type}}export function buildShaderGraphMaterial(t,a={}){if("postProcess"===t.target)return buildShaderGraphPostProcessMaterial(t,a);const r=null!=a.previewNodeId?compileShaderGraphPreview(t,a.previewNodeId,a):compileShaderGraph(t,a).output;if("sprite"===t.target)return new Vt({color:r.color,discard:r.discard,transparent:r.transparent??!0,position:kt(new f("rotation",0),new f("screenSpaceSize",0)),uniforms:{color:{value:new e(16777215)}}});if("trail"===t.target){const{position:e}=re.getTrailShaderNodes(a.trailBillboard??!1),u=new h({...r,position:e});return re.applyTrailShaderParameters(u),Oe(u,t),u}if("decal"===t.target){const e=null!=r.discard?ee.or(r.discard):ee,a=new h({...r,transparent:!1,discard:e});return a.userData.isDecal=!0,Oe(a,t),a}const u=new h({transparent:!1,...r});return Oe(u,t),u}export function buildShaderGraphPostProcessMaterial(t,e={}){const a=null!=e.previewNodeId?Te(compileShaderGraphPreview(t,e.previewNodeId,e).color):compileShaderGraph(t,e).output,r=new h({color:a.color,transparent:!1,fog:!1,lights:!1,outputEncoding:!1});return r.depthWrite=!1,r.depthTest=!1,r.toneMapped=!1,r.userData.isPostProcessShaderGraph=!0,r}function Te(t,e){const a=te(Qt),r=Nt("hology_post_process_weight",1),u=ct(null!=e?r.multiply(e):r);return{color:at(a.rgb,Ie(t),u),transparent:!1,...null!=e?{opacity:e}:{}}}function Ie(t){return t instanceof p?Bt(t,t,t):t instanceof g?Bt(t.x,t.y,0):t instanceof x?t.xyz:t}export function shaderGraphMaterialSideToThree(e){switch(e){case"back":return t;case"double":return a;default:return r}}function Se(t){return"decal"!==t.target&&(t.materialOptions?.transparent??"sprite"===t.target)}function Oe(t,e){"surface"===e.target&&(t.side=shaderGraphMaterialSideToThree(e.materialOptions?.side)),null!=e.materialOptions?.transparent&&(t.transparent=e.materialOptions.transparent),null!=e.materialOptions?.alphaTest&&0===t.alphaTest&&(t.alphaTest=e.materialOptions.alphaTest),null!=e.materialOptions?.bloom&&(t.userData.hasBloom=e.materialOptions.bloom)}function Me(t){switch(t.type){case"float":return Ce(t.value);case"vec2":{const e=t.value;return lt(Bt(e.x,e.y,0),1)}case"vec3":case"rgb":return lt(t.value,1);case"vec4":case"rgba":return t.value;case"boolean":return Ce(ht(t.value,D(1),D(0)));case"mat4":throw new ShaderGraphCompileError("mat4 values cannot be previewed as color");case"texture2d":case"sampler2d":throw new ShaderGraphCompileError(`${t.type} nodes require a sampled output to preview`)}}function Ce(t){return lt(Bt(t,t,t),1)}function Ne(t){return t instanceof p?Bt(t,t,t).rgb:t instanceof g?Bt(t.x,t.y,0).rgb:t}function Ee(t){return t.rgb}function Ge(t,e,a){const r=t.params?.[e];return void 0===r?a:r}function Ue(t,e,a){const r=Ge(t,e,a);return"number"==typeof r?r:Number(r??a)}function Be(t,e){if(null!=(a=t)&&"object"==typeof a&&!Array.isArray(a)&&"value"in a)return Be(t.value,t.valueType??e);var a;const r=e??function(t){if("boolean"==typeof t)return"boolean";if("number"==typeof t)return"float";if(Array.isArray(t))return 2===t.length?"vec2":3===t.length?"vec3":16===t.length?"mat4":"vec4";return"string"==typeof t?"rgb":"float"}(t);return{type:r,value:$e(t,r,"literal")}}function $e(t,a,r){switch(a){case"boolean":return t instanceof l?t:E(Boolean(t));case"float":return t instanceof p?t:D(De(t,0));case"vec2":return t instanceof g?t:qe(t);case"vec3":return t instanceof b?t:Fe(t);case"vec4":return t instanceof x?t:function(t){const[e,a,r,u]=Le(t,4,1);return $t(e,a,r,u)}(t);case"mat4":return t instanceof c?t:function(t){if(t instanceof u)return Z(t);const e=new u;Array.isArray(t)&&16===t.length&&e.fromArray(t.map(t=>De(t,0)));return Z(e)}(t);case"rgb":return t instanceof v?t:function(t){if("string"==typeof t||"number"==typeof t||t instanceof e)return pt(t);const[a,r,u]=Le(t,3);return Bt(a,r,u).rgb}(t);case"rgba":return t instanceof y||t instanceof x?t:Re(t);case"texture2d":return t;case"sampler2d":if(function(t){const e=t;return t instanceof m||t instanceof d||"function"==typeof e?.isSampler2D||!0===e?.isSampler2D}(t))return t;if(t instanceof i)return wt(t);throw new ShaderGraphCompileError(`Parameter "${r}" needs a texture value`)}}function ze(t,e,a,r){const u=`${a}Scalar`;if(e instanceof p&&"function"==typeof t[u])return t[u](e);if("function"==typeof t[a])return t[a](e);throw new ShaderGraphCompileError(`Node does not support ${a}`,r)}function Ve(t,e,a){if(t===e)return t;if("rgb"===t&&"vec3"===e||"vec3"===t&&"rgb"===e)return"vec3";if("rgba"===t&&"vec4"===e||"vec4"===t&&"rgba"===e)return"vec4";if("float"===t&&Ae(e))return e;if("float"===e&&Ae(t))return t;throw new ShaderGraphCompileError(`Cannot mix ${t} and ${e}`,a)}function ke(t,e,a){const r=t.subtract(a),u=yt(e),i=$(e);return Ut(i.multiply(r.x).subtract(u.multiply(r.y)).add(a.x),u.multiply(r.x).add(i.multiply(r.y)).add(a.y))}function Pe(t,e,a){const r=t.value["u"===e?"x":"v"===e?"y":e];if(r instanceof p)return r;throw new ShaderGraphCompileError(`Component "${e}" is not available on ${t.type}`,a)}function Ae(t){return"float"===t||"vec2"===t||"vec3"===t||"vec4"===t||"rgb"===t||"rgba"===t}function je(t){return Number.isFinite(t)?Math.min(1,Math.max(0,t)):0}function De(t,e){if("number"==typeof t)return t;if("string"==typeof t){const a=parseFloat(t);return Number.isFinite(a)?a:e}return"boolean"==typeof t?t?1:0:e}function Le(t,a,r=0){if(Array.isArray(t))return Array.from({length:a},(e,a)=>De(t[a],r));if(t instanceof o||t instanceof n||t instanceof s)return Array.from({length:a},(e,a)=>t.toArray()[a]??r);if(t instanceof e){const e=t.toArray();return Array.from({length:a},(t,a)=>e[a]??(3===a?1:r))}if(null!=t&&"object"==typeof t){const e=t,u=["x","y","z","w"];if(u.some(t=>null!=e[t]))return Array.from({length:a},(t,a)=>De(e[u[a]],r));const i=["r","g","b","a"];if(i.some(t=>null!=e[t]))return Array.from({length:a},(t,a)=>De(e[i[a]],3===a?1:r))}return Array.from({length:a},()=>De(t,r))}function qe(t){const[e,a]=Le(t,2);return Ut(e,a)}function Fe(t){const[e,a,r]=Le(t,3);return Bt(e,a,r)}function Re(t,a=1){if("string"==typeof t||"number"==typeof t||t instanceof e)return lt(t,a);if(t instanceof b)return lt(t,a);const[r,u,i,o]=Le(t,4,a);return $t(r,u,i,o)}function _e(t,e){return e<=1?0:t/(e-1)}/*
|
|
1
|
+
import{BackSide as t,Color as e,DataTexture as a,DoubleSide as r,FrontSide as u,Matrix4 as i,RGBAFormat as o,Texture as n,Vector2 as s,Vector3 as l,Vector4 as p}from"three";import{BooleanNode as c,FloatNode as h,Mat4Node as v,NodeShaderMaterial as y,RgbNode as d,RgbaNode as m,Sampler2DNode as f,Texture2dLookupNode as g,UniformFloatNode as b,Vec2Node as x,Vec3Node as w,Vec4Node as T,abs as S,acos as I,asin as O,attributes as M,atan as C,atan2 as N,autoVarying as E,bulge as G,bool as U,ceil as B,clamp as $,colorToNormal as z,cos as k,cross as V,degrees as P,distance as A,dot as j,exp as D,exp2 as L,float as q,floor as F,fract as R,inversesqrt as _,batchingMatrix as W,colorGradientSampler as H,curveSampler as Y,ifDefApply as J,sampleNamedEasingCurve as K,length as Q,LayerMixMode as X,log as Z,log2 as tt,mat4 as et,max as at,min as rt,mix as ut,mixColorsByLayer as it,particleUniforms as ot,mod as nt,normalize as st,pow as lt,radians as pt,rgba as ct,rgb as ht,saturate as vt,select as yt,sign as dt,sin as mt,smoothstep as ft,sqrt as gt,standardMaterial as bt,scaleTransform as xt,step as wt,tan as Tt,textureSampler2d as St,timeUniforms as It,toonMaterial as Ot,translate as Mt,transformed as Ct,triplanarMapping as Nt,twirl as Et,uniformFloat as Gt,uniforms as Ut,varyingAttributes as Bt,vec2 as $t,vec3 as zt,vec4 as kt,getPaintedMaterialLayerWeight as Vt}from"../../shader-nodes/index.js";import{SpriteNodeShaderMaterial as Pt,getSpritePosition as At}from"../sprite-shader.js";import{oneMinus as jt}from"../../shader-nodes/index.js";import{vectorToRadial as Dt,remap as Lt,hueShift as qt,blendColor as Ft,desaturateColor as Rt}from"../../shader-nodes/math.js";import{rectangleFloat as _t,roundedRectangleFloat as Wt}from"../../shader-nodes/shapes.js";import{edgeDepthEffect as Ht,fresnelEffect as Yt,depthFadeEffect as Jt}from"../../shader-nodes/effects.js";import{fragmentLinearEyeDepth as Kt,sampleSceneDepth as Qt,sampleSceneLinearEyeDepth as Xt,screenUV as Zt,nearUniformName as te,farUniformName as ee}from"../../shader-nodes/depth.js";import{sampleSceneColor as ae}from"../../shader-nodes/scene-sample.js";import{decalDiscard as re,decalUV as ue}from"../../shader-nodes/decal.js";import{Trail as ie,trailUV as oe}from"../../effects/vfx/trail-renderer.js";import{SimplexNoiseNode as ne,Voronoi2d as se,rotateAxis as le}from"../../shader-nodes/index.js";import{flipbookUv as pe}from"../../shader-nodes/texture-sequence.js";import{parallaxOcclusionMapping as ce}from"../../shader-nodes/pom.js";import{defaultInlineLiteralValueForPort as he,inlineLiteralTypeForPort as ve,SHADER_GRAPH_NODE_DEFINITIONS as ye}from"./registry.js";import{shaderGraphParameterTypeToValueType as de}from"./parameters.js";import{varying as me,reflect as fe,refract as ge,dFdx as be,dFdy as xe,fwidth as we}from"three-shader-graph";import{decalNormal as Te}from"../../shader-nodes/decal.js";import{Curve2 as Se}from"../../utils/curve.js";const Ie=(()=>{const t=new a(new Uint8Array([255,255,255,255]),1,1,o);return t.name="Missing shader graph texture parameter fallback",t.needsUpdate=!0,t})(),Oe=new Set;export class ShaderGraphCompileError extends Error{constructor(t,e,a){super(t),this.nodeId=e,this.port=a,this.name="ShaderGraphCompileError"}}export const shaderGraphPostProcessWeightUniformName="hology_post_process_weight";export class ShaderGraphCompiler{constructor(t,e={}){this.graph=t,this.options=e,this.compiled=new Map,this.nodesById=new Map((t.nodes??[]).map(t=>[t.id,t]))}validate(){this.compile()}compile(){if(1!==this.graph.version)throw new ShaderGraphCompileError(`Unsupported shader graph version ${this.graph.version}`);return this.validateEdges(),{output:this.compileOutput(),nodes:this.compiled}}validateEdges(){for(const t of this.graph.edges??[]){if(!this.nodesById.has(t.from.nodeId))throw new ShaderGraphCompileError(`Edge references missing source node "${t.from.nodeId}"`,t.from.nodeId,t.from.port);if(!this.nodesById.has(t.to.nodeId))throw new ShaderGraphCompileError(`Edge references missing target node "${t.to.nodeId}"`,t.to.nodeId,t.to.port)}}compileOutput(){if("postProcess"===this.graph.target)return this.compilePostProcessOutput();const t=this.graph.outputs?.color,e={color:null!=t?this.toColorOutput(this.resolveOutputBinding(t,"color")):ct("#ffffff",1),transparent:Ne(this.graph)},a=this.graph.outputs?.opacity;null!=a&&(e.opacity=this.expectType(this.resolveOutputBinding(a,"opacity"),["float"],"opacity").value);const r=this.graph.outputs?.roughness;null!=r&&(e.roughness=this.expectType(this.resolveOutputBinding(r,"roughness"),["float"],"roughness").value);const u=this.graph.outputs?.metalness;null!=u&&(e.metalness=this.floatOutput(u,"metalness"));const i=this.graph.outputs?.normal;null!=i&&(e.normal=this.toVec3Output(this.resolveOutputBinding(i,"normal"),"normal"));const o=this.graph.outputs?.emissive;null!=o&&(e.emissive=this.toVec3Output(this.resolveOutputBinding(o,"emissive"),"emissive"));const n=this.graph.outputs?.ambientOcclusion;null!=n&&(e.ambientOcclusion=this.floatOutput(n,"ambientOcclusion"));const s=this.graph.outputs?.ambientOcclusionIntensity;null!=s&&(e.ambientOcclusionIntensity=this.floatOutput(s,"ambientOcclusionIntensity"));const l=this.graph.outputs?.sheenColor;null!=l&&(e.sheenColor=this.toVec3Output(this.resolveOutputBinding(l,"sheenColor"),"sheenColor"));const p=this.graph.outputs?.sheenRoughness;null!=p&&(e.sheenRoughness=this.floatOutput(p,"sheenRoughness"));const c=this.graph.outputs?.anisotropy;null!=c&&(e.anisotropy=this.floatOutput(c,"anisotropy"));const h=this.graph.outputs?.anisotropyDirection;null!=h&&(e.anisotropyDirection=this.expectType(this.resolveOutputBinding(h,"anisotropyDirection"),["vec2"],"anisotropyDirection").value);const v=this.graph.outputs?.bakedLight;null!=v&&(e.bakedLight=this.toVec3Output(this.resolveOutputBinding(v,"bakedLight"),"bakedLight"));const y=this.graph.outputs?.transform;null!=y&&"decal"!==this.graph.target&&(e.transform=this.toMat4Output(this.resolveOutputBinding(y,"transform"),"transform"));const d=this.graph.outputs?.discard;null!=d&&(e.discard=this.expectType(this.resolveOutputBinding(d,"discard"),["boolean"],"discard").value);const m=this.graph.outputs?.transparent;null!=m&&null!=m.value&&(e.transparent=Boolean(m.value));const f=this.graph.outputs?.alphaTest;return null!=f&&null!=f.value?e.alphaTest=Number(f.value):null!=this.graph.materialOptions?.alphaTest&&(e.alphaTest=this.graph.materialOptions.alphaTest),this.applyShadingModel(e)}compilePostProcessOutput(){const t=this.graph.outputs?.color,e=null!=t?this.toColorOutput(this.resolveOutputBinding(t,"color")):ae(Zt),a=this.graph.outputs?.opacity;return Me(e,null!=a?this.expectType(this.resolveOutputBinding(a,"opacity"),["float"],"opacity").value:void 0)}applyShadingModel(t){const e=null!=t.opacity?function(t,e){if(t instanceof h)return ct(zt(t,t,t),e);if(t instanceof x)return ct(zt(t.x,t.y,0),e);if(t instanceof T)return ct(t.rgb,t.w.multiply(e));return ct(t,e)}(t.color,t.opacity):t.color;switch(this.graph.shadingModel??"standard"){case"standard":{const a={color:Be(e),roughness:t.roughness??q(.5),...null!=t.metalness?{metalness:t.metalness}:{},..."decal"===this.graph.target?{normal:st(me(Ut.normalMatrix).multiplyVec(Te))}:{},...null!=t.normal?{normal:t.normal}:{},...null!=t.emissive?{emissive:$e(t.emissive)}:{},...null!=t.ambientOcclusion?{ambientOcclusion:t.ambientOcclusion}:{},...null!=t.ambientOcclusionIntensity?{ambientOcclusionIntensity:t.ambientOcclusionIntensity}:{},...null!=t.sheenColor?{sheenColor:t.sheenColor.rgb}:{},...null!=t.sheenRoughness?{sheenRoughness:t.sheenRoughness}:{},...null!=t.anisotropy?{anisotropy:t.anisotropy}:{},...null!=t.anisotropyDirection?{anisotropyDirection:t.anisotropyDirection}:{},...null!=t.bakedLight?{bakedLight:t.bakedLight}:{}};return{...t,color:bt(a)}}case"toon":{const a={color:Be(e),...null!=t.normal?{normal:t.normal}:{},...null!=t.emissive?{emissive:$e(t.emissive)}:{},...null!=t.ambientOcclusion?{ambientOcclusion:t.ambientOcclusion}:{},...null!=t.ambientOcclusionIntensity?{ambientOcclusionIntensity:t.ambientOcclusionIntensity}:{},...null!=t.bakedLight?{bakedLight:t.bakedLight}:{}};return{...t,color:Ot(a)}}case"unlit":return{...t,color:e}}}compileNode(t){const e=this.compiled.get(t);if(null!=e)return e;const a=this.nodesById.get(t);if(null==a)throw new ShaderGraphCompileError(`Missing shader graph node "${t}"`,t);if(null==ye[a.kind])throw new ShaderGraphCompileError(`Unsupported shader graph node "${a.kind}"`,a.id);const r=this.compileNodeInternal(a);return this.compiled.set(t,r),r}compileNodeInternal(t){switch(t.kind){case"input.parameter":return this.output(t,this.compileParameterNode(t));case"input.slider":return this.output(t,{value:{type:"float",value:q(Fe(ke(t,"value",.5)))}});case"constant.boolean":return this.output(t,{value:{type:"boolean",value:U(Boolean(ze(t,"value",!1)))}});case"constant.float":return this.output(t,{value:{type:"float",value:q(ke(t,"value",0))}});case"constant.vec2":return this.output(t,{value:{type:"vec2",value:We(ze(t,"value",[0,0]))}});case"constant.vec3":return this.output(t,{value:{type:"vec3",value:He(ze(t,"value",[0,0,0]))}});case"constant.rgba":return this.output(t,{value:{type:"rgba",value:Ye(ze(t,"value","#ffffff"),ke(t,"alpha",1))}});case"builtin.uv":{const e=this.defaultUV();return this.output(t,{value:{type:"vec2",value:!0===ze(t,"flipY",!1)?$t(e.x,jt(e.y)):e},u:{type:"float",value:e.x},v:{type:"float",value:e.y}})}case"builtin.screenUv":return this.output(t,{value:{type:"vec2",value:Zt}});case"builtin.color":{const e=E(M.color);return this.output(t,{value:{type:"rgba",value:e},rgb:{type:"rgb",value:e.rgb},r:{type:"float",value:e.r},g:{type:"float",value:e.g},b:{type:"float",value:e.b},a:{type:"float",value:e.a}})}case"builtin.position":{const e=E(M.position);return this.output(t,{value:{type:"vec3",value:e},x:{type:"float",value:e.x},y:{type:"float",value:e.y},z:{type:"float",value:e.z}})}case"builtin.worldPosition":{const e=E(Ct.worldPosition);return this.output(t,{value:{type:"vec3",value:e},x:{type:"float",value:e.x},y:{type:"float",value:e.y},z:{type:"float",value:e.z}})}case"builtin.objectPosition":{let e=Ut.instanceMatrix.multiplyVec(kt(0,0,0,1));e=J("USE_BATCHING",e,t=>W.multiplyVec(t));const a=E(Ut.modelMatrix.multiplyVec(e).xyz);return this.output(t,{value:{type:"vec3",value:a},x:{type:"float",value:a.x},y:{type:"float",value:a.y},z:{type:"float",value:a.z}})}case"builtin.viewDir":{const e=E(Ct.viewDir);return this.output(t,{value:{type:"vec3",value:e},x:{type:"float",value:e.x},y:{type:"float",value:e.y},z:{type:"float",value:e.z}})}case"builtin.normal":{const e=E(M.normal);return this.output(t,{value:{type:"vec3",value:e},x:{type:"float",value:e.x},y:{type:"float",value:e.y},z:{type:"float",value:e.z}})}case"builtin.time":return this.output(t,{value:{type:"float",value:It.elapsed}});case"builtin.camera":{const e=Gt(te),a=Gt(ee),r=Ut.cameraPosition;return this.output(t,{position:{type:"vec3",value:r},x:{type:"float",value:r.x},y:{type:"float",value:r.y},z:{type:"float",value:r.z},near:{type:"float",value:e},far:{type:"float",value:a}})}case"builtin.viewMatrix":return this.output(t,{value:{type:"mat4",value:Ut.viewMatrix}});case"builtin.projectionMatrix":return this.output(t,{value:{type:"mat4",value:Ut.projectionMatrix}});case"builtin.modelViewMatrix":return this.output(t,{value:{type:"mat4",value:Ut.modelViewMatrix}});case"builtin.particle":return this.output(t,{energy:{type:"float",value:ot.energy},color:{type:"rgb",value:ot.color},opacity:{type:"float",value:ot.opacity},time:{type:"float",value:ot.time}});case"math.add":case"math.subtract":case"math.multiply":case"math.divide":return this.output(t,{value:this.compileBinaryMath(t)});case"math.oneMinus":{const e=this.expectNumeric(this.input(t,"value"));return this.output(t,{value:{type:e.type,value:jt(e.value)}})}case"math.abs":return this.output(t,{value:this.compileUnaryMath(t,S)});case"math.sign":return this.output(t,{value:this.compileUnaryMath(t,dt)});case"math.floor":return this.output(t,{value:this.compileUnaryMath(t,F)});case"math.ceil":return this.output(t,{value:this.compileUnaryMath(t,B)});case"math.fract":return this.output(t,{value:this.compileUnaryMath(t,R)});case"math.sin":return this.output(t,{value:this.compileUnaryMath(t,mt)});case"math.cos":return this.output(t,{value:this.compileUnaryMath(t,k)});case"math.tan":return this.output(t,{value:this.compileUnaryMath(t,Tt)});case"math.asin":return this.output(t,{value:this.compileUnaryMath(t,O)});case"math.acos":return this.output(t,{value:this.compileUnaryMath(t,I)});case"math.atan":return this.output(t,{value:this.compileUnaryMath(t,C)});case"math.atan2":return this.output(t,{value:this.compileAtan2(t)});case"math.radians":return this.output(t,{value:this.compileUnaryMath(t,pt)});case"math.degrees":return this.output(t,{value:this.compileUnaryMath(t,P)});case"math.sqrt":return this.output(t,{value:this.compileUnaryMath(t,gt)});case"math.inverseSqrt":return this.output(t,{value:this.compileUnaryMath(t,_)});case"math.exp":return this.output(t,{value:this.compileUnaryMath(t,D)});case"math.exp2":return this.output(t,{value:this.compileUnaryMath(t,L)});case"math.log":return this.output(t,{value:this.compileUnaryMath(t,Z)});case"math.log2":return this.output(t,{value:this.compileUnaryMath(t,tt)});case"math.saturate":return this.output(t,{value:this.compileUnaryMath(t,vt)});case"math.length":{const e=this.expectNumeric(this.input(t,"value"));return this.output(t,{value:{type:"float",value:Q(e.value)}})}case"math.normalize":return this.output(t,{value:this.compileUnaryMath(t,st)});case"math.clamp":{const e=this.expectNumeric(this.input(t,"value")),a=this.expectNumeric(this.input(t,"min",{type:"float",value:q(0)})),r=this.expectNumeric(this.input(t,"max",{type:"float",value:q(1)}));return this.output(t,{value:{type:e.type,value:$(e.value,a.value,r.value)}})}case"math.min":return this.output(t,{value:this.compileBinaryFunction(t,rt)});case"math.max":return this.output(t,{value:this.compileBinaryFunction(t,at)});case"math.pow":return this.output(t,{value:this.compileBinaryFunction(t,lt)});case"math.mod":return this.output(t,{value:this.compileBinaryFunction(t,nt)});case"math.step":return this.output(t,{value:this.compileBinaryFunction(t,wt,!0)});case"math.smoothstep":{const e=this.expectNumeric(this.input(t,"edge0",{type:"float",value:q(0)})),a=this.expectNumeric(this.input(t,"edge1",{type:"float",value:q(1)})),r=this.expectNumeric(this.input(t,"value"));return this.output(t,{value:{type:r.type,value:ft(e.value,a.value,r.value)}})}case"math.mix":{const e=this.expectNumeric(this.input(t,"a")),a=this.expectNumeric(this.input(t,"b")),r=this.expectNumeric(this.input(t,"t",{type:"float",value:q(.5)})),u=je(e.type,a.type,t.id);return this.output(t,{value:{type:u,value:ut(e.value,a.value,r.value)}})}case"math.remap":{const e=this.expectType(this.input(t,"value"),["float"],t.id,"value").value,a=this.floatInput(t,"inMin",-1),r=this.floatInput(t,"inMax",1),u=this.floatInput(t,"outMin",0),i=this.floatInput(t,"outMax",1);return this.output(t,{value:{type:"float",value:Lt(e,a,r,u,i)}})}case"math.select":{const e=this.boolInput(t,"condition",!1),a=this.expectNumeric(this.input(t,"a")),r=this.expectNumeric(this.input(t,"b")),u=je(a.type,r.type,t.id);return this.output(t,{value:{type:u,value:yt(e,a.value,r.value)}})}case"math.reflect":{const e=this.expectType(this.input(t,"incident"),["vec2","vec3","vec4","rgb","rgba"],t.id,"incident"),a=this.expectType(this.input(t,"normal"),["vec2","vec3","vec4","rgb","rgba"],t.id,"normal");return this.output(t,{value:{type:e.type,value:fe(e.value,a.value)}})}case"math.refract":{const e=this.expectType(this.input(t,"incident"),["vec2","vec3","vec4","rgb","rgba"],t.id,"incident"),a=this.expectType(this.input(t,"normal"),["vec2","vec3","vec4","rgb","rgba"],t.id,"normal"),r=this.floatInput(t,"ior",1.5);return this.output(t,{value:{type:e.type,value:ge(e.value,a.value,r)}})}case"math.derivative":{const e=this.expectNumeric(this.input(t,"value")),a=String(ze(t,"mode","fwidth"));let r;return r="dFdx"===a?be(e.value):"dFdy"===a?xe(e.value):we(e.value),this.output(t,{value:{type:e.type,value:r}})}case"layer.mixPainted":return this.output(t,{value:this.compilePaintedLayerMix(t)});case"math.dot":{const e=this.expectNumeric(this.input(t,"a")),a=this.expectNumeric(this.input(t,"b"));return je(e.type,a.type,t.id),this.output(t,{value:{type:"float",value:j(e.value,a.value)}})}case"math.distance":{const e=this.expectNumeric(this.input(t,"a")),a=this.expectNumeric(this.input(t,"b"));return je(e.type,a.type,t.id),this.output(t,{value:{type:"float",value:A(e.value,a.value)}})}case"math.cross":{const e=this.expectType(this.input(t,"a"),["vec3","rgb"],t.id,"a"),a=this.expectType(this.input(t,"b"),["vec3","rgb"],t.id,"b");return this.output(t,{value:{type:"vec3",value:V(e.value,a.value)}})}case"compare.greaterThan":case"compare.greaterThanOrEqual":case"compare.lessThan":case"compare.lessThanOrEqual":case"compare.equal":case"compare.notEqual":return this.output(t,{value:{type:"boolean",value:this.compileComparison(t)}});case"boolean.not":{const e=this.boolInput(t,"value",!1);return this.output(t,{value:{type:"boolean",value:yt(e,U(!1),U(!0))}})}case"boolean.and":return this.output(t,{value:{type:"boolean",value:this.compileBooleanBinary(t,"and")}});case"boolean.or":return this.output(t,{value:{type:"boolean",value:this.compileBooleanBinary(t,"or")}});case"compose.vec2":return this.output(t,{value:{type:"vec2",value:$t(this.floatInput(t,"x",0),this.floatInput(t,"y",0))}});case"compose.vec3":return this.output(t,{value:{type:"vec3",value:zt(this.floatInput(t,"x",0),this.floatInput(t,"y",0),this.floatInput(t,"z",0))}});case"compose.vec4":return this.output(t,{value:{type:"vec4",value:kt(this.floatInput(t,"x",0),this.floatInput(t,"y",0),this.floatInput(t,"z",0),this.floatInput(t,"w",0))}});case"compose.rgba":return this.output(t,{value:{type:"rgba",value:kt(this.floatInput(t,"r",1),this.floatInput(t,"g",1),this.floatInput(t,"b",1),this.floatInput(t,"a",1))}});case"decompose.component":{const e=this.expectNumeric(this.input(t,"value")),a=String(ze(t,"component","x"));return this.output(t,{value:{type:"float",value:Le(e,a,t.id)}})}case"decompose.split":{const e=this.expectNumeric(this.input(t,"value"));return this.output(t,function(t,e){const a={},r=(r,u)=>{a[r]={type:"float",value:Le(t,u,e)}};switch(t.type){case"vec2":return r("x","x"),r("y","y"),r("u","x"),r("v","y"),a;case"vec3":return r("x","x"),r("y","y"),r("z","z"),a;case"rgb":return r("r","r"),r("g","g"),r("b","b"),r("x","x"),r("y","y"),r("z","z"),a;case"vec4":return r("x","x"),r("y","y"),r("z","z"),r("w","w"),a;case"rgba":return r("r","r"),r("g","g"),r("b","b"),r("a","a"),r("x","x"),r("y","y"),r("z","z"),r("w","w"),a;case"float":return a.x={type:"float",value:t.value},a}}(e,t.id))}case"color.gradient":{const e=this.expectType(this.input(t,"t",{type:"float",value:q(.5)}),["float"],t.id,"t"),a=H(function(t){const e=ze(t,"stops",[]);if(!Array.isArray(e))return[];const a=e.map((t,a)=>{if(null==t||"object"!=typeof t||Array.isArray(t))return;const r=t,u="string"==typeof r.color?r.color:"#ffffff";return{position:Re(r.position,Je(a,e.length)),color:u,alpha:Re(r.alpha,1)}}).filter(t=>null!=t);return a.length>0?a:[]}(t)).sample(e.value);return this.output(t,{value:{type:"rgba",value:a}})}case"utility.curve":{const e=this.expectType(this.input(t,"t",{type:"float",value:q(.5)}),["float"],t.id,"t"),a=ze(t,"curve","Linear"),r=K(a,e.value)??Y(Se.decode(a)).sample(e.value);return this.output(t,{value:{type:"float",value:r}})}case"color.hueShift":{const e=this.expectType(this.input(t,"color"),["rgba","rgb","vec4","vec3"],t.id,"color"),a=e.value,r="rgba"===e.type||"vec4"===e.type?a.rgb??a.xyz:a,u=this.floatInput(t,"shift",0),i=qt(r,u);return"rgba"===e.type||"vec4"===e.type?this.output(t,{value:{type:e.type,value:kt(i,a.a??a.w)}}):this.output(t,{value:{type:e.type,value:i}})}case"color.blend":{const e=this.expectType(this.input(t,"base"),["rgba","rgb","vec4","vec3"],t.id,"base"),a=this.expectType(this.input(t,"blend"),["rgba","rgb","vec4","vec3"],t.id,"blend"),r=String(ze(t,"mode","multiply")),u=e.value,i=a.value,o="rgba"===e.type||"vec4"===e.type?u.rgb??u.xyz:u,n="rgba"===a.type||"vec4"===a.type?i.rgb??i.xyz:i;let s=Ft(o,n,r);if("rgba"===a.type||"vec4"===a.type){const t=i.a??i.w;s=ut(o,s,t)}if("rgba"===e.type||"vec4"===e.type){const a=u.a??u.w;return this.output(t,{value:{type:e.type,value:kt(s,a)}})}return this.output(t,{value:{type:e.type,value:s}})}case"color.desaturate":{const e=this.expectType(this.input(t,"color"),["rgba","rgb","vec4","vec3"],t.id,"color"),a=e.value,r="rgba"===e.type||"vec4"===e.type?a.rgb??a.xyz:a,u=this.floatInput(t,"fraction",1),i=Rt(r,u);return"rgba"===e.type||"vec4"===e.type?this.output(t,{value:{type:e.type,value:kt(i,a.a??a.w)}}):this.output(t,{value:{type:e.type,value:i}})}case"color.unpackNormal":{const e=this.expectType(this.input(t,"color"),["vec3","vec4","rgb","rgba"],t.id,"color"),a=this.floatInput(t,"scale",1),r=this.optionalInput(t,"normal");return this.output(t,{value:{type:"vec3",value:z(e.value,a,r?this.expectType(r,["vec3"],t.id,"normal").value:void 0)}})}case"texture.sampler2d":{const e=this.input(t,"texture");return this.output(t,{value:this.toSampler(e,t.id)})}case"texture.sample2d":{const e=this.toSampler(this.input(t,"sampler"),t.id),a=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv"),r=e.value.sample(a.value);return this.output(t,{rgba:{type:"rgba",value:r},rgb:{type:"rgb",value:r.rgb},r:{type:"float",value:r.r},g:{type:"float",value:r.g},b:{type:"float",value:r.b},a:{type:"float",value:r.a}})}case"texture.triplanarMapping":{const e=this.input(t,"sampler"),a=this.toSampler(e,t.id),r=this.expectType(this.input(t,"scale",{type:"float",value:q(1)}),["float"],t.id,"scale"),u=this.expectType(this.input(t,"normal",{type:"vec3",value:Bt.normal}),["vec3"],t.id,"normal"),i=this.expectType(this.input(t,"position",{type:"vec3",value:Bt.position}),["vec3"],t.id,"position"),o=Nt(a.value,r.value,u.value,i.value);return this.output(t,{rgba:{type:"rgba",value:o},rgb:{type:"rgb",value:o.rgb},r:{type:"float",value:o.r},g:{type:"float",value:o.g},b:{type:"float",value:o.b},a:{type:"float",value:o.a}})}case"scene.sampleColor":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:Zt}),["vec2"],t.id,"uv"),a=ae(e.value);return this.output(t,{rgba:{type:"rgba",value:a},rgb:{type:"rgb",value:a.rgb},r:{type:"float",value:a.r},g:{type:"float",value:a.g},b:{type:"float",value:a.b},a:{type:"float",value:a.a}})}case"scene.sampleDepth":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:Zt}),["vec2"],t.id,"uv");return this.output(t,{depth:{type:"float",value:Qt(e.value)},linearEyeDepth:{type:"float",value:Xt(e.value)}})}case"scene.fragmentDepth":return this.output(t,{linearEyeDepth:{type:"float",value:Kt}});case"transform.translate":{const e=this.expectType(this.input(t,"offset",{type:"vec3",value:zt(0,0,0)}),["vec3","rgb"],t.id,"offset");return this.output(t,{value:{type:"mat4",value:Mt(e.value)}})}case"transform.scale":{const e=this.expectType(this.input(t,"scale",{type:"vec3",value:zt(1,1,1)}),["vec3","rgb"],t.id,"scale").value;return this.output(t,{value:{type:"mat4",value:xt(e.x,e.y,e.z)}})}case"transform.rotateAxis":{const e=this.expectType(this.input(t,"axis",{type:"vec3",value:zt(0,1,0)}),["vec3","rgb"],t.id,"axis"),a=this.expectType(this.input(t,"angle",{type:"float",value:q(0)}),["float"],t.id,"angle");return this.output(t,{value:{type:"mat4",value:le(e.value,a.value)}})}case"uv.rotate":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.expectType(this.input(t,"angle",{type:"float",value:q(0)}),["float"],t.id,"angle").value,r=this.expectType(this.input(t,"center",{type:"vec2",value:$t(.5,.5)}),["vec2"],t.id,"center").value;return this.output(t,{value:{type:"vec2",value:De(e,a,r)}})}case"uv.twirl":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.expectType(this.input(t,"strength",{type:"float",value:q(1)}),["float"],t.id,"strength").value,r=this.expectType(this.input(t,"center",{type:"vec2",value:$t(.5,.5)}),["vec2"],t.id,"center").value,u=this.expectType(this.input(t,"offset",{type:"vec2",value:$t(0,0)}),["vec2"],t.id,"offset").value;return this.output(t,{value:{type:"vec2",value:Et(e,a,r,u)}})}case"uv.radial":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=Dt(e.subtractScalar(.5));return this.output(t,{coords:{type:"vec2",value:a.coords},radius:{type:"float",value:a.radius},angle:{type:"float",value:a.angle}})}case"uv.bulge":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.expectType(this.input(t,"center",{type:"vec2",value:$t(.5,.5)}),["vec2"],t.id,"center").value,r=this.expectType(this.input(t,"power",{type:"float",value:q(1)}),["float"],t.id,"power").value;return this.output(t,{value:{type:"vec2",value:G(e,a,r)}})}case"uv.flipbook":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.floatInput(t,"columns",ke(t,"columns",1)),r=this.floatInput(t,"rows",ke(t,"rows",1)),u=this.floatInput(t,"fps",ke(t,"fps",60)),i=this.expectType(this.input(t,"time",{type:"float",value:It.elapsed}),["float"],t.id,"time").value,o=String(ze(t,"mode","clamp"));return this.output(t,{value:{type:"vec2",value:pe(e,a,r,i,u,o)}})}case"uv.pom":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.input(t,"heightMap"),r=this.toSampler(a,t.id).value,u=this.floatInput(t,"heightScale",.05),i=ke(t,"minLayers",8),o=ke(t,"maxLayers",24);return this.output(t,{value:{type:"vec2",value:ce(e,r,u,i,o)}})}case"shape.rectangle":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value;return this.output(t,{value:{type:"float",value:_t(e,this.floatInput(t,"width",.5),this.floatInput(t,"height",.5))}})}case"shape.roundedRectangle":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value;return this.output(t,{value:{type:"float",value:Wt(e,this.floatInput(t,"width",.5),this.floatInput(t,"height",.5),this.floatInput(t,"radius",.1))}})}case"noise.simplex":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.floatInput(t,"scale",8);return this.output(t,{value:{type:"float",value:new ne(e.multiplyScalar(a))}})}case"noise.voronoi2d":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv").value,a=this.floatInput(t,"scale",8);return this.output(t,{value:{type:"float",value:new se(e.multiplyScalar(a))}})}case"effect.fresnel":return this.output(t,{value:{type:"float",value:E(Yt(this.floatInput(t,"power",1)))}});case"effect.edgeDepth":{const e=this.floatInput(t,"power",1);return this.output(t,{value:{type:"float",value:Ht(e)}})}case"effect.depthFade":{const e=this.floatInput(t,"distance",1);return this.output(t,{value:{type:"float",value:Jt(e)}})}case"util.panner":{const e=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"coord"),a=this.expectType(this.input(t,"speed",{type:"vec2",value:$t(0,0)}),["vec2"],t.id,"speed"),r=this.expectType(this.input(t,"tile",{type:"vec2",value:$t(1,1)}),["vec2"],t.id,"tile"),u=this.expectType(this.input(t,"time",{type:"float",value:It.elapsed}),["float"],t.id,"time");return this.output(t,{value:{type:"vec2",value:e.value.multiply(r.value).add(a.value.multiplyScalar(u.value))}})}}}compileParameterNode(t){const e=String(ze(t,"parameter","")),a=this.graph.parameters?.find(t=>t.name===e||t.id===e);if(null==a)throw new ShaderGraphCompileError(`Parameter "${e}" does not exist`,t.id);const r=de(a.type),u={type:r,value:Pe(this.options.parameters?.[a.name]??a.defaultValue,r,a.name)};if("sampler2d"!==r)return{value:u};const i=this.expectType(this.input(t,"uv",{type:"vec2",value:this.defaultUV()}),["vec2"],t.id,"uv"),o=u.value.sample(i.value);return{value:{type:"rgba",value:o},rgb:{type:"rgb",value:o.rgb},r:{type:"float",value:o.r},g:{type:"float",value:o.g},b:{type:"float",value:o.b},a:{type:"float",value:o.a},sampler:u}}compileBinaryMath(t){const e=this.expectBinaryMathValue(this.input(t,"a")),a=this.expectBinaryMathValue(this.input(t,"b")),r=t.kind.split(".")[1];if("mat4"===e.type||"mat4"===a.type)return function(t,e,a,r){if("mat4"===t.type&&"mat4"===e.type&&"divide"!==a)return{type:"mat4",value:Ae(t.value,e.value,a,r)};if("mat4"===t.type&&"float"===e.type&&("multiply"===a||"divide"===a))return{type:"mat4",value:Ae(t.value,e.value,a,r)};if("float"===t.type&&"mat4"===e.type&&"multiply"===a)return{type:"mat4",value:Ae(e.value,t.value,a,r)};if("mat4"===t.type&&"vec4"===e.type&&"multiply"===a)return{type:"vec4",value:t.value.multiplyVec(e.value)};throw new ShaderGraphCompileError(`Cannot ${a} ${t.type} and ${e.type}`,r)}(e,a,r,t.id);if(e.type===a.type)return{type:e.type,value:Ae(e.value,a.value,r,t.id)};if("float"===e.type&&"float"!==a.type&&"multiply"===r)return{type:a.type,value:Ae(a.value,e.value,r,t.id)};if("float"!==e.type&&"float"===a.type)return{type:e.type,value:Ae(e.value,a.value,r,t.id)};throw new ShaderGraphCompileError(`Cannot ${r} ${e.type} and ${a.type}`,t.id)}expectBinaryMathValue(t){if(!qe(t.type)&&"mat4"!==t.type)throw new ShaderGraphCompileError(`Expected a numeric value but got ${t.type}`);return t}compileUnaryMath(t,e){const a=this.expectNumeric(this.input(t,"value"));return{type:a.type,value:e(a.value)}}compileAtan2(t){const e=this.expectNumeric(this.input(t,"y")),a=this.expectNumeric(this.input(t,"x"));return{type:function(t,e,a){if(t===e)return t;if("rgb"===t&&"vec3"===e||"vec3"===t&&"rgb"===e)return"vec3";if("rgba"===t&&"vec4"===e||"vec4"===t&&"rgba"===e)return"vec4";throw new ShaderGraphCompileError(`Cannot mix ${t} and ${e}`,a)}(e.type,a.type,t.id),value:N(e.value,a.value)}}compileBinaryFunction(t,e,a=!1){const r=this.expectNumeric(this.input(t,"a")),u=this.expectNumeric(this.input(t,"b"));return{type:a&&"float"===u.type?r.type:je(r.type,u.type,t.id),value:e(r.value,u.value)}}compilePaintedLayerMix(t){const e=this.expectNumeric(this.input(t,"base")),a=[e.value],r=[Vt(0)];let u=e.type;for(let e=1;e<=8;e++){const i=this.optionalInput(t,`layer${e}`);if(null==i)continue;const o=this.expectNumeric(i);u=je(u,o.type,t.id),a.push(o.value),r.push(Vt(e))}return 1===a.length?e:{type:u,value:it({layerColors:a,layerWeights:r,enableNoise:Boolean(ze(t,"enableNoise",!0)),noiseScale:this.floatInput(t,"noiseScale",ke(t,"noiseScale",.1)),noiseAmount:this.floatInput(t,"noiseAmount",ke(t,"noiseAmount",.5)),decay:this.floatInput(t,"softness",ke(t,"softness",.3)),mode:"hard"===String(ze(t,"mode","soft"))?X.hard:X.soft})}}defaultUV(){return"trail"===this.graph.target?oe:"decal"===this.graph.target?ue:E(M.uv)}input(t,e,a){const r=t.inputs?.[e];if(null!=r)return this.resolveInput(r,t.id,e);const u=(this.graph.edges??[]).find(a=>a.to.nodeId===t.id&&a.to.port===e);if(null!=u)return this.resolveSocket(u.from,t.id,e);if(null!=a)return a;const i=this.inlineLiteralFallback(t,e);if(null!=i)return i;throw new ShaderGraphCompileError(`Missing input "${e}"`,t.id,e)}optionalInput(t,e){const a=t.inputs?.[e];if(null!=a)return this.resolveInput(a,t.id,e);const r=(this.graph.edges??[]).find(a=>a.to.nodeId===t.id&&a.to.port===e);return null!=r?this.resolveSocket(r.from,t.id,e):void 0}floatInput(t,e,a){return this.expectType(this.input(t,e,{type:"float",value:q(a)}),["float"],t.id,e).value}boolInput(t,e,a){return this.expectType(this.input(t,e,{type:"boolean",value:U(a)}),["boolean"],t.id,e).value}compileComparison(t){const e=this.expectType(this.input(t,"a"),["float"],t.id,"a").value,a=this.expectType(this.input(t,"b"),["float"],t.id,"b").value;switch(t.kind){case"compare.greaterThan":return e.gt(a);case"compare.greaterThanOrEqual":return e.gte(a);case"compare.lessThan":return e.lt(a);case"compare.lessThanOrEqual":return e.lte(a);case"compare.equal":return e.equals(a);case"compare.notEqual":return e.notEquals(a)}throw new ShaderGraphCompileError(`Unsupported comparison node "${t.kind}"`,t.id)}compileBooleanBinary(t,e){const a=this.boolInput(t,"a",!1),r=this.boolInput(t,"b",!1);return"and"===e?a.and(r):a.or(r)}resolveOutputBinding(t,e){if(null!=t.input)return this.resolveSocket(t.input,void 0,e);if(void 0!==t.value)return Ve(t.value);throw new ShaderGraphCompileError(`Output "${e}" is missing an input or value`)}floatOutput(t,e){return this.expectType(this.resolveOutputBinding(t,e),["float"],e).value}resolveInput(t,e,a){return function(t){return null!=t.nodeId}(t)?this.resolveSocket(t,e,a):Ve(t.value,t.valueType)}inlineLiteralFallback(t,e){const a=ye[t.kind]?.inputs.find(t=>t.name===e);if(null==a)return;const r=ve(t.kind,a),u=he(t.kind,a);return null!=r&&void 0!==u?Ve(u,r):void 0}resolveSocket(t,e,a){const r=this.compileNode(t.nodeId).outputs[t.port];if(null==r)throw new ShaderGraphCompileError(`Node "${t.nodeId}" does not have output "${t.port}"`,e??t.nodeId,a??t.port);return r}expectType(t,e,a,r){if(!e.includes(t.type))throw new ShaderGraphCompileError(`Expected ${e.join(" or ")} but got ${t.type}`,a,r);return t}expectNumeric(t){if(!qe(t.type))throw new ShaderGraphCompileError(`Expected a numeric value but got ${t.type}`);return t}toSampler(t,e){if("sampler2d"===t.type)return t;if("texture2d"===t.type){const a=t.value;if(null==a)throw new ShaderGraphCompileError("Texture input is empty",e);return{type:"sampler2d",value:St(a)}}throw new ShaderGraphCompileError(`Expected texture2d or sampler2d but got ${t.type}`,e)}toColorOutput(t){switch(t.type){case"float":case"vec2":case"vec3":case"vec4":case"rgb":case"rgba":return t.value;case"boolean":{const e=yt(t.value,q(1),q(0));return ct(zt(e,e,e),1)}case"mat4":throw new ShaderGraphCompileError("mat4 values cannot be used as color");case"texture2d":case"sampler2d":throw new ShaderGraphCompileError(`${t.type} must be sampled before it can be used as color`)}}toVec3Output(t,e){if("vec3"===t.type||"rgb"===t.type)return t.value;if("vec4"===t.type||"rgba"===t.type)return t.value.xyz;throw new ShaderGraphCompileError(`Output "${e}" expects vec3/rgb but got ${t.type}`)}toMat4Output(t,e){if("mat4"===t.type)return t.value;throw new ShaderGraphCompileError(`Output "${e}" expects mat4 but got ${t.type}`)}output(t,e){return{node:t,outputs:e}}}export function compileShaderGraph(t,e={}){return new ShaderGraphCompiler(t,e).compile()}export function compileShaderGraphPreview(t,e,a={}){if(null==e)return compileShaderGraph(t,a).output;const r=new ShaderGraphCompiler(t,a).compileNode(e),u=Object.values(r.outputs)[0];if(null==u)throw new ShaderGraphCompileError(`Node "${e}" has no previewable output`,e);return{color:Ge(u),transparent:"rgba"===u.type||"vec4"===u.type}}export function buildShaderGraphMaterial(t,a={}){if("postProcess"===t.target)return buildShaderGraphPostProcessMaterial(t,a);const r=function(t,e,a){const r=a.alphaTest??t.alphaTest??e.materialOptions?.alphaTest;return null!=r?{...t,alphaTest:r}:t}(null!=a.previewNodeId?compileShaderGraphPreview(t,a.previewNodeId,a):compileShaderGraph(t,a).output,t,a);if("sprite"===t.target)return new Pt({color:r.color,discard:r.discard,alphaTest:r.alphaTest,transparent:r.transparent??!0,position:At(new b("rotation",0),new b("screenSpaceSize",0)),uniforms:{color:{value:new e(16777215)}}});if("trail"===t.target){const{position:e}=ie.getTrailShaderNodes(a.trailBillboard??!1),u=new y({...r,position:e});return ie.applyTrailShaderParameters(u),Ee(u,t),u}if("decal"===t.target){const e=null!=r.discard?re.or(r.discard):re,a=new y({...r,transparent:!1,discard:e});return a.userData.isDecal=!0,Ee(a,t),a}const u=new y({transparent:!1,...r});return Ee(u,t),u}export function buildShaderGraphPostProcessMaterial(t,e={}){const a=null!=e.previewNodeId?Me(compileShaderGraphPreview(t,e.previewNodeId,e).color):compileShaderGraph(t,e).output,r=new y({color:a.color,transparent:!1,fog:!1,lights:!1,outputEncoding:!1});return r.depthWrite=!1,r.depthTest=!1,r.toneMapped=!1,r.userData.isPostProcessShaderGraph=!0,r}export function buildShaderGraphInlinePreviewMaterial(t,e,a={}){const r=compileShaderGraphPreview({...t,target:"surface"},e,a),u=new y({color:r.color,transparent:r.transparent??!1,fog:!1,lights:!1});return u.depthWrite=!1,u.depthTest=!1,u.toneMapped=!1,u}function Me(t,e){const a=ae(Zt),r=Gt("hology_post_process_weight",1),u=vt(null!=e?r.multiply(e):r);return{color:ut(a.rgb,Ce(t),u),transparent:!1,...null!=e?{opacity:e}:{}}}function Ce(t){return t instanceof h?zt(t,t,t):t instanceof x?zt(t.x,t.y,0):t instanceof T?t.xyz:t}export function shaderGraphMaterialSideToThree(e){switch(e){case"back":return t;case"double":return r;default:return u}}function Ne(t){return"decal"!==t.target&&(t.materialOptions?.transparent??"sprite"===t.target)}function Ee(t,e){"surface"===e.target&&(t.side=shaderGraphMaterialSideToThree(e.materialOptions?.side)),null!=e.materialOptions?.transparent&&(t.transparent=e.materialOptions.transparent),null!=e.materialOptions?.bloom&&(t.userData.hasBloom=e.materialOptions.bloom)}function Ge(t){switch(t.type){case"float":return Ue(t.value);case"vec2":{const e=t.value;return ct(zt(e.x,e.y,0),1)}case"vec3":case"rgb":return ct(t.value,1);case"vec4":case"rgba":return t.value;case"boolean":return Ue(yt(t.value,q(1),q(0)));case"mat4":throw new ShaderGraphCompileError("mat4 values cannot be previewed as color");case"texture2d":case"sampler2d":throw new ShaderGraphCompileError(`${t.type} nodes require a sampled output to preview`)}}function Ue(t){return ct(zt(t,t,t),1)}function Be(t){return t instanceof h?zt(t,t,t).rgb:t instanceof x?zt(t.x,t.y,0).rgb:t}function $e(t){return t.rgb}function ze(t,e,a){const r=t.params?.[e];return void 0===r?a:r}function ke(t,e,a){const r=ze(t,e,a);return"number"==typeof r?r:Number(r??a)}function Ve(t,e){if(null!=(a=t)&&"object"==typeof a&&!Array.isArray(a)&&"value"in a)return Ve(t.value,t.valueType??e);var a;const r=e??function(t){if("boolean"==typeof t)return"boolean";if("number"==typeof t)return"float";if(Array.isArray(t))return 2===t.length?"vec2":3===t.length?"vec3":16===t.length?"mat4":"vec4";return"string"==typeof t?"rgb":"float"}(t);return{type:r,value:Pe(t,r,"literal")}}function Pe(t,a,r){switch(a){case"boolean":return t instanceof c?t:U(Boolean(t));case"float":return t instanceof h?t:q(Re(t,0));case"vec2":return t instanceof x?t:We(t);case"vec3":return t instanceof w?t:He(t);case"vec4":return t instanceof T?t:function(t){const[e,a,r,u]=_e(t,4,1);return kt(e,a,r,u)}(t);case"mat4":return t instanceof v?t:function(t){if(t instanceof i)return et(t);const e=new i;Array.isArray(t)&&16===t.length&&e.fromArray(t.map(t=>Re(t,0)));return et(e)}(t);case"rgb":return t instanceof d?t:function(t){if("string"==typeof t||"number"==typeof t||t instanceof e)return ht(t);const[a,r,u]=_e(t,3);return zt(a,r,u).rgb}(t);case"rgba":return t instanceof m||t instanceof T?t:Ye(t);case"texture2d":return t;case"sampler2d":return function(t){const e=t;return t instanceof f||t instanceof g||"function"==typeof e?.isSampler2D||!0===e?.isSampler2D}(t)?t:t instanceof n||!0===t?.isTexture?St(t):(Oe.has(r)||(Oe.add(r),console.warn(`Shader graph parameter "${r}" is missing a texture value; using a 1x1 white fallback texture.`)),St(Ie))}}function Ae(t,e,a,r){const u=`${a}Scalar`;if(e instanceof h&&"function"==typeof t[u])return t[u](e);if("function"==typeof t[a])return t[a](e);throw new ShaderGraphCompileError(`Node does not support ${a}`,r)}function je(t,e,a){if(t===e)return t;if("rgb"===t&&"vec3"===e||"vec3"===t&&"rgb"===e)return"vec3";if("rgba"===t&&"vec4"===e||"vec4"===t&&"rgba"===e)return"vec4";if("float"===t&&qe(e))return e;if("float"===e&&qe(t))return t;throw new ShaderGraphCompileError(`Cannot mix ${t} and ${e}`,a)}function De(t,e,a){const r=t.subtract(a),u=mt(e),i=k(e);return $t(i.multiply(r.x).subtract(u.multiply(r.y)).add(a.x),u.multiply(r.x).add(i.multiply(r.y)).add(a.y))}function Le(t,e,a){const r=t.value["u"===e?"x":"v"===e?"y":e];if(r instanceof h)return r;throw new ShaderGraphCompileError(`Component "${e}" is not available on ${t.type}`,a)}function qe(t){return"float"===t||"vec2"===t||"vec3"===t||"vec4"===t||"rgb"===t||"rgba"===t}function Fe(t){return Number.isFinite(t)?Math.min(1,Math.max(0,t)):0}function Re(t,e){if("number"==typeof t)return t;if("string"==typeof t){const a=parseFloat(t);return Number.isFinite(a)?a:e}return"boolean"==typeof t?t?1:0:e}function _e(t,a,r=0){if(Array.isArray(t))return Array.from({length:a},(e,a)=>Re(t[a],r));if(t instanceof s||t instanceof l||t instanceof p)return Array.from({length:a},(e,a)=>t.toArray()[a]??r);if(t instanceof e){const e=t.toArray();return Array.from({length:a},(t,a)=>e[a]??(3===a?1:r))}if(null!=t&&"object"==typeof t){const e=t,u=["x","y","z","w"];if(u.some(t=>null!=e[t]))return Array.from({length:a},(t,a)=>Re(e[u[a]],r));const i=["r","g","b","a"];if(i.some(t=>null!=e[t]))return Array.from({length:a},(t,a)=>Re(e[i[a]],3===a?1:r))}return Array.from({length:a},()=>Re(t,r))}function We(t){const[e,a]=_e(t,2);return $t(e,a)}function He(t){const[e,a,r]=_e(t,3);return zt(e,a,r)}function Ye(t,a=1){if("string"==typeof t||"number"==typeof t||t instanceof e)return ct(t,a);if(t instanceof w)return ct(t,a);const[r,u,i,o]=_e(t,4,a);return kt(r,u,i,o)}function Je(t,e){return e<=1?0:t/(e-1)}/*
|
|
2
2
|
* Copyright (©) 2026 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|