@hology/core 0.0.153 → 0.0.155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/effects/vfx/vfx-materializer.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/gameplay/services/physics/physics-system.d.ts +1 -0
- package/dist/gameplay/services/physics/physics-system.d.ts.map +1 -1
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/rendering/bloom/LuminosityHighPassShader.d.ts +28 -0
- package/dist/rendering/bloom/LuminosityHighPassShader.d.ts.map +1 -0
- package/dist/rendering/bloom/LuminosityHighPassShader.js +4 -0
- package/dist/rendering/bloom/UnrealBloomPass.d.ts +89 -0
- package/dist/rendering/bloom/UnrealBloomPass.d.ts.map +1 -0
- package/dist/rendering/bloom/UnrealBloomPass.js +4 -0
- package/dist/rendering/bloom/types.d.ts +14 -0
- package/dist/rendering/bloom/types.d.ts.map +1 -0
- package/dist/rendering/bloom/types.js +4 -0
- package/dist/rendering/outline-effect.js +1 -1
- package/dist/rendering/ssr/SSRPass.d.ts +9 -2
- package/dist/rendering/ssr/SSRPass.d.ts.map +1 -1
- package/dist/rendering/ssr/SSRPass.js +1 -1
- package/dist/rendering/ssr/SSRShader.d.ts.map +1 -1
- package/dist/rendering/ssr/SSRShader.js +1 -1
- package/dist/rendering.d.ts +4 -0
- package/dist/rendering.d.ts.map +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/asset-resource-loader.d.ts.map +1 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/batched-mesh-2.d.ts +10 -0
- package/dist/scene/batched-mesh-2.d.ts.map +1 -0
- package/dist/scene/batched-mesh-2.js +4 -0
- package/dist/scene/landscape/landscape-manager.d.ts.map +1 -1
- package/dist/scene/landscape/landscape-manager.js +1 -1
- package/dist/scene/materializer.d.ts +5 -0
- package/dist/scene/materializer.d.ts.map +1 -1
- package/dist/scene/materializer.js +1 -1
- package/dist/shader/builtin/decal-standard-shader.d.ts +2 -0
- package/dist/shader/builtin/decal-standard-shader.d.ts.map +1 -1
- package/dist/shader/builtin/decal-standard-shader.js +1 -1
- package/dist/shader/builtin/decal-unlit-shader.d.ts +2 -1
- package/dist/shader/builtin/decal-unlit-shader.d.ts.map +1 -1
- package/dist/shader/builtin/decal-unlit-shader.js +1 -1
- package/dist/shader/builtin/lambert-shader.d.ts +3 -1
- package/dist/shader/builtin/lambert-shader.d.ts.map +1 -1
- package/dist/shader/builtin/lambert-shader.js +1 -1
- package/dist/shader/builtin/landscape-composite-shader.d.ts.map +1 -1
- package/dist/shader/builtin/landscape-composite-shader.js +1 -1
- package/dist/shader/builtin/standard-shader.d.ts.map +1 -1
- package/dist/shader/builtin/standard-shader.js +1 -1
- package/dist/shader/shader.d.ts +1 -0
- package/dist/shader/shader.d.ts.map +1 -1
- package/dist/shader-nodes/curve-sample.d.ts +11 -0
- package/dist/shader-nodes/curve-sample.d.ts.map +1 -0
- package/dist/shader-nodes/curve-sample.js +4 -0
- package/dist/shader-nodes/depth.d.ts +3 -0
- package/dist/shader-nodes/depth.d.ts.map +1 -1
- package/dist/shader-nodes/depth.js +1 -1
- package/dist/shader-nodes/index.d.ts +1 -0
- package/dist/shader-nodes/index.d.ts.map +1 -1
- package/dist/shader-nodes/index.js +1 -1
- package/dist/shader-nodes/pom.d.ts +7 -0
- package/dist/shader-nodes/pom.d.ts.map +1 -0
- package/dist/shader-nodes/pom.js +4 -0
- package/dist/utils/three/traverse.d.ts +2 -1
- package/dist/utils/three/traverse.d.ts.map +1 -1
- package/dist/utils/three/traverse.js +1 -1
- package/package.json +3 -3
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{ConvexPolyhedronCollisionShape as a}from"@hology/core";import{Subject as s}from"rxjs";import*as r from"three";import{BoxGeometry as i,Color as n,Euler as o,Fog as l,FogExp2 as c,Group as h,Material as d,Matrix4 as m,Mesh as p,MeshLambertMaterial as u,MeshPhongMaterial as f,MeshStandardMaterial as g,Object3D as y,PointLight as w,Quaternion as v,Scene as b,Texture as A,Vector2 as S,Vector3 as M,Vector4 as j}from"three";import x,{SpriteRenderer as P}from"@hology/nebula";import{bool as I,BooleanNode as D,float as C,FloatNode as E,NodeShaderMaterial as V,rgb as O,RgbNode as k,Texture2dLookupNode as N,textureSampler2d as F,vec2 as T,Vec2Node as z,vec3 as B,Vec3Node as _,vec4 as L}from"three-shader-graph";import{Service as W}from"typedi";import{VfxActor as $}from"../effects/vfx/vfx-actor.js";import{VisualEffect as R}from"../effects/vfx/vfx-param.js";import{BaseActor as G}from"../gameplay/actors/actor.js";import U from"../gameplay/actors/builtin/index.js";import{PhysicsBodyType as H,ThreeBlendingMode as J,withInjectionContext as q}from"../gameplay/index.js";import{RenderingView as X}from"../rendering.js";import{Sampler2DNode as Y}from"../shader-nodes/index.js";import{LambertShader as Z}from"../shader/builtin/lambert-shader.js";import{LandscapeCompositeShader as K}from"../shader/builtin/landscape-composite-shader";import{LandscapeShader as Q}from"../shader/builtin/landscape-shader.js";import{StandardShader as ee}from"../shader/builtin/standard-shader.js";import{UnlitShader as te}from"../shader/builtin/unlit-shader.js";import{extractShaderParameters as ae}from"../shader/parameter.js";import{ArrayMap as se,groupBy as re}from"../utils/collections.js";import{iterateMaterials as ie}from"../utils/materials.js";import{filterChildrenShallow as ne,filterSceneShallow as oe,findFirstVisibleObject as le}from"../utils/three/traverse.js";import{AssetMeshInstance as ce,AssetResourceLoader as he}from"./asset-resource-loader.js";import{isCollisionMesh as de}from"./collision/collision-shape-import.js";import{BoxCollisionShape as me,PhysicalShapeMesh as pe}from"./collision/collision-shape.js";import{LandscapeManager as ue}from"./landscape/landscape-manager.js";import{initLandscape as fe}from"./landscape/landscape.js";import{SectionGrid as ge,smoothNormalsCrossMeshes as ye}from"./landscape/utils.js";import{createGrassFoliageMaterial as we}from"./materials/grass-foliage.js";import{createGrassMaterial as ve}from"./materials/grass.js";import{getMaterialAttribute as be}from"./materials/utils/material-painting.js";import{createWaterMaterial as Ae}from"./materials/water.js";import{SerializedParamType as Se}from"./model.js";import{ShapeLibrary as Me,ShapeLibraryKeys as je}from"./objects/shapes.js";import{ambientLightName as xe,createSky as Pe,defaultSkyMaterial as Ie}from"./sky.js";import{Curve2 as De}from"../utils/curve.js";import{DecalUnlitShader as Ce}from"../shader/builtin/decal-unlit-shader.js";import{DecalStandardShader as Ee}from"../shader/builtin/decal-standard-shader.js";import{ColorLayer as Ve,defaultValueColorLayer as Oe,defaultValueMaskLayer as ke,MaskLayer as Ne}from"../shader/color-layer.js";import{LayeredShader as Fe}from"../shader/builtin/layered-shader";import{isColorLayerSerialized as Te}from"../shader/color-layer";import{FogVolume as ze}from"../rendering/fog/fog-volume-actor.js";import{UnscaledSprite as Be}from"../utils/three/unscaled-sprite.js";import{ToonShader as _e}from"../shader/builtin/toon-shader.js";const Le={},We=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),$e=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||(navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPad"))&&!!navigator.userAgent.match(/AppleWebKit/)&&!navigator.userAgent.match(/CriOS/);export const shapeDefaultColor="#aaaaaa";export class SceneMaterializerLoader{constructor(e,t,a){this.dataProvider=e,this.assetsService=t,this.assetManagerService=a}get(e,t){return new Re(e,this.dataProvider,this.assetsService,this.assetManagerService,t,[],[],{create:()=>null,initActor:async()=>{}})}}let Re=class{constructor(e,t,a,i,n,o,l,c){this.scene=e,this.dataProvider=t,this.assetsService=a,this.assetManagerService=i,this.renderingView=n,this.shaders=o,this.actorTypes=l,this.actorProvider=c,this.objectMap=new Map,this.sceneObjectMap=new Map,this.components=[],this.landscapeManagers=[],this.materializedActors=new Map,this.inEditor=!0,this.updated$=new s,this.removed$=new s,this.error$=new s,this.editorActorParamSnapshot=new Map,this.assets=new Map,this._canBeInstancedCache=new Map,this._originalMaterials=new Map,this.pmremGeneratorResults=new WeakMap,this.prefabInstanceChain=[],this.geometryCache=new Map,this.collisionShapeCache=new Map,this.originalFog=null,t.onCreate(e=>this.update(e)),t.onUpdate(e=>this.update(e)),t.onRemove(e=>this.remove(e)),this.createAssetSubscription=a.onCreate.subscribe(e=>{this.assets.set(e.id,e)}),this.updateSubscription=a.onUpdate.subscribe(async t=>{this.assets.set(t.id,t),"material"==t.type?e.traverse(e=>{if(e instanceof r.Mesh)if(Array.isArray(e.material))for(let a=0;a<e.material.length;a++)this.refreshMaterial(e,e.material[a],t,a);else this.refreshMaterial(e,e.material,t)}):"mesh"==t.type?(this.findByAssetId(t.id).forEach(e=>{this.remove(e.userData.src),this.materializeAndInitActor(e.userData.src)}),this.landscapeManagers.forEach(e=>{const a=e.source?.grass?.layers?.some(e=>e.meshes.some(e=>e.assetId===t.id));a&&e.queueRefreshScatter(this.renderingView?.camera.position??new M,!0)})):"prefab"===t.type?this.findByAssetId(t.id).forEach(e=>{const t=e.userData.src;this.remove(t),this.materializeAndInitActor(t)}):"vfx"===t.type&&this.dataProvider.getObjects().forEach(e=>{Qe(e,(e,a)=>{"vfx"===e.type&&e.assetId===t.id&&(this.remove(e),this.materializeAndInitActor(e))})})})}async refreshMaterial(e,t,a,s){const r=t?.userData?.assetId;if(r!==a.id){const e=this.assets.get(r);let t=!1;if(null!=e)for(const s of Object.values(e.material.shaderParams)){if(s.type===Se.Material&&s.value===a.id){t=!0;break}if(s.type===Se.Array&&"element"in s&&s.element===Se.Material&&s.value.includes(a.id)){t=!0;break}}if(!t)return}const i=await materialFromAsset(this.assets.get(r),this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1),n=i.userData;i.userData=t.userData,i.userData.hasBloom=n.hasBloom,i.userData.reflective=n.reflective,i.userData.outlineParameters=n.outlineParameters,null!=s?at(e.material[s],i)||(e.material[s]=i):at(e.material,i)||(e.material=i,e===this.sky&&this.applySkySettings(e.material))}getTopLevelActors(){return Array.from(this.materializedActors.entries()).filter(([e,t])=>!e.includes("/")).map(([,e])=>e)}get actorInstances(){return Array.from(this.materializedActors.values())}async initTextures(){const e=[];if(await Promise.all(this.dataProvider.getObjects().filter(e=>"shape_mesh"===e.type||"asset_mesh"===e.type).filter(e=>null!=e.materialAssignments).flatMap(e=>e.materialAssignments).map(async t=>{const a=this.assets.get(t.materialId);if(null!=a)for(const t of Object.values(a.material.shaderParams))if(t.type===Se.Texture&&"string"==typeof t.value){const a=this.assets.get(t.value),s=await this.assetManagerService.getTexture(a);null!=s&&e.push(s)}})),0!==e.length&&this.renderingView){console.log(`Initializing ${e.length} textures`),console.time("Init textures");for(const t of e)this.renderingView.renderer.initTexture(t);console.timeEnd("Init textures")}}async prefetchAssets(){const e=Array.from(new Set(this.dataProvider.getObjects().filter(e=>null!=e.assetId&&"asset_mesh"==e.type).filter(e=>e.assetId)));await Promise.all(e.map(e=>this.assetsService.getAsset(e.assetId).then(e=>{if(null!=e)return this.assetManagerService.getMesh(e)}))),this.initTextures()}async init(){await this.preInit(),Ue.clear(),He.clear(),await this.prefetchAssets(),await Promise.all(this.dataProvider.getObjects().map(e=>this.materialize(e))),await this.initActorsPostInit()}initActorsPostInit(e=this.getTopLevelActors(),t){const a=e.map(async e=>{const a=e.object.userData.src??e.object.userData._src;if("vfx"===a.type)return Promise.resolve();const s=await this.assetsService.getAsset(a.assetId),r={...s?.actor?.params??{},...a.actor?.params??{}},i=null!=t?new Map(Array.from(this.materializedActors.entries()).filter(([e,a])=>e.startsWith(t.sceneObjectChain.join("/"))&&e.split("/").length-1===t.sceneObjectChain.length).map(([e,t])=>[e.split("/").pop(),t])):this.materializedActors;for(const t of a.actor.innerParams??[])await this.applyActorComponentParams(e,t.path.slice(),t.params,i);const n=await prepareClassParameters(r,e.constructor,this.assetsService,this.assetManagerService,i,this.renderingView,this.shaders,this.actorProvider);Object.assign(e,n);try{return await this.actorProvider.initActor(e)}catch(e){console.error(`Failed to initiate actor (name="${a.name}", id=${a.id})`,e)}});return Promise.all(a)}addVfxChildActors(e,t=e){}async applyActorComponentParams(e,t,a,s){const r=t.length,i=t.shift();if(0==r){const t=await prepareClassParameters(a,null,this.assetsService,this.assetManagerService,s,this.renderingView,this.shaders,this.actorProvider);for(const[a,s]of Object.entries(t))null!=s&&(e[a]=s)}else null!=e[i]&&await this.applyActorComponentParams(e[i],t,a,s)}canObjectBeInstanced(e){return e.physics?.type!==H.dynamic&&"sky"!==e.type&&"global_fog"!==e.type&&"world_env"!==e.type}async canAssetBeInstanced(e){if(!this._canBeInstancedCache.has(e.assetId)){const t=await this.createFromAsset(e);if(null==t)return!1;const a=[];t.traverse(e=>{!de(e)&&e.isMesh&&a.push(e)});const s=1==a.length&&0==a[0].children.length,r=a[0]instanceof p&&null!=a[0].geometry.morphAttributes&&Object.keys(a[0].geometry.morphAttributes).length>0,i=!0;this._canBeInstancedCache.set(e.assetId,s&&i&&!r)}return this._canBeInstancedCache.get(e.assetId)}async preInit(){this.renderingView?.onLoop(()=>{null!=this.sky&&this.renderingView.camera.getWorldPosition(this.sky.position)}),this.assetsService.getAssets().then(e=>{for(const t of e)this.assets.set(t.id,t)})}shouldBeMaterialized(e){if(null!=this.detailTier&&"asset_mesh"===e.type&&null!=e.assetId){const t=this.assets.get(e.assetId);if(null!=t){const e=t.mesh?.detailTier;if(null!=e)return e<=this.detailTier}}return!0}async initWithInstancing(){await this.preInit(),await this.prefetchAssets(),Ue.clear(),He.clear();const e=[],t=new se,s=new se;for(const a of this.dataProvider.getObjects())await Qe(a,async(a,r,i)=>{if(!this.shouldBeMaterialized(a))return;const o="asset_mesh"==a.type&&this.canObjectBeInstanced(a)&&await this.canAssetBeInstanced(a),l="shape_mesh"===a.type&&"landscape"!==a.shape&&a.physics?.type!==H.dynamic;if(o||l){if(r&&r.children?.length>0){const e=r.children.findIndex(e=>e.id===a.id);e>=0&&r.children.splice(e,1)}if(l){let e=a.shape+JSON.stringify(a.shapeParams??{})+a.castShadow+a.receiveShadow;const t=a.materialAssignments?.at(0)?.materialId,r=null!=t?this.assets.get(t):null;let o=null;if(null!=r&&"shader"!==r.material.type){if(e+=r.material.type+r.material.shader,null!=r.material.shaderParams){if(e+=Object.entries(r.material.shaderParams).filter(([e,t])=>"color"!=e).map(e=>JSON.stringify(e)).join(),null!=r.material.shaderParams.color){const e=r.material.shaderParams.color;e.type===Se.Color&&null!=e.value&&(o=new n(e.value))}}}else e+=t;s.push(e,{object:{...a,parentTransform:i},color:o})}else{const e=a.assetId+JSON.stringify(a.materialAssignments??[]);t.push(e,{...a,parentTransform:i})}}else null==r&&e.push({...a,parentTransform:i})});for(const e of t.values()){if(0==e.length)continue;const t=await this.createFromAsset(e[0]);if(null==t)continue;const s=await this.createInstancedMesh(e,t),r=new ce;r.add(s),r.userData.src=e[0],t instanceof ce&&(r.collisionShapes=t.collisionShapes),r.collisionShapes.forEach(e=>{e instanceof a&&e.mesh instanceof p&&(e.mesh=e.mesh.geometry)}),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r)}for(const e of s.values()){if(0==e.length)continue;const t=e[0].object,a=await this.createFromShape(t),s=le(a,e=>!de(e)&&null!=e.geometry),i=s.material.clone();null!=e[0].color&&null!=i.color&&(i.color=new n(16777215));const l=s.geometry;let c,h;!($e||i instanceof V||null==l.index)?(c=new r.BatchedMesh(e.length,l.getAttribute("position").count,l.index.count,i),c.perObjectFrustumCulled=!0,h=c.addGeometry(l)):c=new r.InstancedMesh(l,i,e.length),c.castShadow=a.castShadow??!0,c.receiveShadow=s.receiveShadow??!0;for(let t=0;t<e.length;t++){const a=e[t],s=(new r.Matrix4).compose((new M).fromArray(a.object.position),(new v).setFromEuler((new o).fromArray(a.object.rotation)),(new M).fromArray(a.object.scale)),i=(new m).copy(a.object.parentTransform).multiply(s);let n;n=c instanceof r.BatchedMesh?c.addInstance(h):t,c.setMatrixAt(n,i),null!=a.color&&c.setColorAt(n,a.color)}for(let t=0;t<e.length;t++){const s=e[t],r=new ce;r.userData.src=e[0],a instanceof pe&&(r.collisionShapes=[a.collisionShape]),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r),r.add(c),null==c.userData.hasCollision&&(c.userData.hasCollision=[]),c.userData.hasCollision[t]=!!s.object.collisionDetection}}await Promise.all(e.map(e=>this.materialize(e))),await this.initActorsPostInit()}async createInstancedMesh(e,t){const a=le(t,e=>!de(e)&&null!=e.geometry),s=await this.assetsService.getAsset(e[0].assetId);await this.applyMaterials(t,et(e[0].materialAssignments,s.materialAssignments)),a.updateMatrix();const i=a.geometry.clone(),n=a.material;let l,c;if(!($e||n instanceof V||!(i.groups.length<2)||Array.isArray(n)&&1!=n.length)){const t=Array.isArray(n)?n[0]:n,a=i.getAttribute("position").count;l=new r.BatchedMesh(e.length,a,null!=i.index?i.index.count:a,t),l.perObjectFrustumCulled=!0,c=l.addGeometry(i)}else l=new r.InstancedMesh(i,n,e.length);for(let t=0;t<e.length;t++){let s=t;l instanceof r.BatchedMesh&&(s=l.addInstance(c));const i=(new r.Matrix4).compose((new M).fromArray(e[t].position),(new v).setFromEuler((new o).fromArray(e[t].rotation)),(new M).fromArray(e[t].scale)),n=(new m).copy(e[t].parentTransform).multiply(i).multiply(a.matrixWorld);l.setMatrixAt(s,n),null==l.userData.hasCollision&&(l.userData.hasCollision=[]),l.userData.hasCollision[t]=!!e[t].collisionDetection}if(l.castShadow=e[0].castShadow??s.castShadow??!0,l.receiveShadow=e[0].receiveShadow??s.receiveShadow??!0,a.material instanceof d&&l.castShadow&&l.receiveShadow)if(Array.isArray(n))for(const e of n)e.side=r.FrontSide;else n.side=r.FrontSide;return l}remove(e){if(console.log("Remove scene object",e),"global_fog"==e.type)return void(this.scene.fog=this.originalFog);if("world_env"===e.type)this.resetWorldEnv(),this.worldEnvObj=null;else if("actor"==e.type||"vfx"===e.type){const t=this.materializedActors.get(e.id);null!=t?(t.disposed.next(!0),t.onEndPlay()):console.warn("Failed to remove actor",e)}else"prefab"===e.type&&this.materializedActors.forEach((t,a)=>{a.startsWith(e.id)&&(t.disposed.next(!0),t.onEndPlay()),this.materializedActors.delete(a)});const t=this.sceneObjectMap.get(e.id);t?.parent.remove(t),this.sceneObjectMap.delete(e.id),this.components.filter(t=>t.object.userData.src?.id===e.id).forEach(e=>this.components.splice(this.components.indexOf(e,1))),this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(e=>{e.clear(),e.stop(),this.landscapeManagers.splice(this.landscapeManagers.indexOf(e,1))}),this.removed$.next({object:t,source:e})}deleteSceneObject(e){const t=this.sceneObjectMap.get(e.id);if(this.scene.remove(t),"landscape"==e.type){const t=this.landscapeManagers.findIndex(t=>t.source.id===e.id);if(t>-1){const e=this.landscapeManagers.splice(t,1)[0];e.clear(),e.stop()}}}findByAssetId(e){return oe(this.scene,t=>t.userData.src?.assetId==e,e=>null!=e.userData.src)}applyMaterials(e,t){return null==t?Promise.resolve([]):Promise.all(t.filter(e=>"null"!==e.materialId).map(t=>this.applyMaterial(e,t)))}async applyMaterial(e,t){await applyMaterial(e,t,e=>{const t=this.assets.get(e);if(null!=t)try{return materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders)}catch(e){console.error("Failed to apply material",e)}},this._originalMaterials)}unapplyMaterials(e){e.traverse(async e=>{if(e instanceof p)if(e.material instanceof Array)for(let t=0;t<e.material.length;t++)e.material[t]=this._originalMaterials.get(e.id+"#"+t)??e.material[t];else e.material=this._originalMaterials.get(e.id)??e.material})}updateActors(e){console.log("update actors"),this.actorTypes=e;const t=new Set(Object.values(U));oe(this.scene,e=>e.userData.src?.id&&"actor"===e.userData.src.type&&this.materializedActors.has(e.userData.src?.id)&&!t.has(e.userData.src.actor.type)).forEach(async e=>{this.remove(e.userData.src),await this.materializeAndInitActor(e.userData.src)})}updateShaders(e){this.shaders=e;for(const[e,t]of Ue.entries())t.userData.customShaderName&&Ue.delete(e);this.landscapeManagers.forEach(t=>t.updateShaders(e)),oe(this.scene,e=>!0).forEach(e=>{e.traverse(async e=>{if(e instanceof p)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++){const a=e.material[t].userData?.customShaderName;if(null!=a){const a=this.assets.get(e.material[t].userData.assetId);this.refreshMaterial(e,e.material[t],a,t)}}else{const t=e.material.userData?.customShaderName;if(null!=t){const t=this.assets.get(e.material.userData.assetId);this.refreshMaterial(e,e.material,t)}}})})}async update(e){if("sky"===e.type&&null!=this.sky&&null!=this.sky.parent)return void this.updateSky(e);if("world_env"===e.type&&null!=this.worldEnvObj)return void this.updateWorldEnv(e);const t=this.sceneObjectMap.get(e.id);if(t){let s=!1;if(t.traverseAncestors(e=>{"_hology_transform_group"===e.name&&(s=!0)}),!s){const a=this.findParent(e);null!=a&&a.uuid!=t.uuid?a.attach(t):console.error("Parent is wrong")}if("prefab"!==e.type&&"group"!==e.type){this.unapplyMaterials(t);this.inEditor&&e.hidden&&!1?t.traverse(e=>{e instanceof p&&(e.material.wireframe=!0)}):t.traverse(e=>{e instanceof p&&(e.material.wireframe=!1)})}if("asset_mesh"===e.type){const a=this.assets.get(e.assetId);et(e.materialAssignments,a.materialAssignments).forEach(e=>this.applyMaterial(t,e))}else"shape_mesh"===e.type&&this.applyMaterials(t,e.materialAssignments);if(s||(null!=e.position&&t.position.fromArray(e.position),null!=e.scale&&t.scale.fromArray(e.scale),null!=e.rotation&&t.rotation.fromArray(e.rotation)),this.applyVertexMaterials(e,t),"light"==e.type)if("point"==e.light.type){const a=t;a.color=new n(e.light.point.color),a.intensity=e.light.point.intensity,a.decay=e.light.point.decay,a.castShadow=e.light.point.castShadow,a.distance=Math.max(e.light.point.distance,0),a.userData.volumetricIntensity=e.light.point.volumetricIntensity}else if("spot"==e.light.type){const a=t;a.color=new n(e.light.spot.color),a.intensity=e.light.spot.intensity,a.decay=e.light.spot.decay,a.angle=e.light.spot.angle,a.penumbra=e.light.spot.penumbra,a.castShadow=e.light.spot.castShadow,a.distance=Math.max(e.light.spot.distance,0),a.userData.volumetricIntensity=e.light.spot.volumetricIntensity}else"directional"===e.light.type?this.applyDirectionalLight(e.light.directional,e):"ambient"===e.light.type&&this.applyDirectionalAmbientLight(t,e.light.ambient,e);else if("landscape"===e.shape){const a=this.landscapeManagers.find(t=>t.source.id===e.id).source.landscape.options.density!==e.landscape.options.density;if(this.inEditor&&a){this.remove(e);const t=await this.materializeAndInitActor(e);return void this.updated$.next({object:t,source:e})}this.applyHeightMaps(t,e.landscape.heightMaps),this.inEditor&&this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(t=>{t.updateSource(e),t.queueRefreshScatter(this.renderingView.camera.position,!0,e=>!0)})}else if("global_fog"===e.type){const t=(this.scene.fog instanceof c?"density":"linear")!==e.fog.type;this.scene.fog=Ze(e.fog),t&&(a=this.scene).traverse(e=>{if(e instanceof p){const t=e.material;t instanceof V&&(a.fog instanceof l?(t.uniforms.fogFar.value=a.fog.far,t.uniforms.fogNear.value=a.fog.near):a.fog instanceof c&&(t.uniforms.density={value:a.fog.density}),t.needsUpdate=!0,t.uniformsNeedUpdate=!0)}}),this.fixFogColor()}else if("actor"===e.type){if(this.materializedActors.has(e.id)){const t=this.materializedActors.get(e.id);if(t instanceof ze){const a=await prepareClassParameters(e.actor.params,null,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,[],this.actorProvider);return void Object.assign(t,a)}const a=this.editorActorParamSnapshot.get(e.id);null!=a&&a===JSON.stringify(e.actor)||s||(this.remove(e),await this.materializeAndInitActor(e))}}else if("shape_mesh"===e.type){const a=await this.createMeshByShape(e.shape,t.material,e.shapeParams);t instanceof pe&&(t.geometry=a.geometry,t.collisionShape=a.collisionShape)}("asset_mesh"===e.type||"shape_mesh"===e.type&&"landscape"!==e.shape)&&Ge(t,e.castShadow,e.receiveShadow),e.name&&e.name.length>0&&(t.name=e.name),this.updated$.next({object:t,source:e})}else{const t=await this.materializeAndInitActor(e);this.updated$.next({object:t,source:e})}var a;this.renderingView.renderer.shadowMap.needsUpdate=!0}async materializeAndInitActor(e,t=this.findParent(e)){const a=await this.materialize(e,t);return Qe(e,async e=>{if("actor"===e.type){const t=this.materializedActors.get(e.id);null!=t?await this.initActorsPostInit([t]):console.error(`Something went wrong when creating actor ${e.id}`)}}),a}findParent(e){const t=this.dataProvider.getObjects().flatMap(t=>t.id===e.id?null:ne(t,t=>t.children?.some(t=>t.id===e.id),()=>!0))[0];return null==t?this.scene:null!=t?oe(this.scene,e=>e.userData?.src?.id===t.id,e=>null!=e.userData?.src)[0]:void 0}fixFogColor(){!0===this.renderingView.options.enableOutlines&&(this.scene.fog.color=new n(this.scene.fog.color))}findMeshWithGeometry(e){let t;return e.traverse(e=>{e instanceof p&&e.geometry&&(t=e)}),t}applyVertexMaterials(e,t){if(null==e.vertexMaterials||0===e.vertexMaterials.length)return;let a=1;for(const t of e.vertexMaterials)a=Math.max(t.w.length,a);const s=re(e.vertexMaterials,e=>e.m);t.traverse(e=>{if(e instanceof p){if(null==e.geometry)return;if(st(be(e,0,!1)),a>0){st(be(e,0,!1))}}});const r=new Set;for(const[e,i]of s.entries()){const s=null!=e?t.getObjectByName(e):this.findMeshWithGeometry(t);let n=!1;if(null==s||null==s.geometry)return void console.warn(`Failed to apply vertex materials on mesh with name "${e}"`);const o=be(s,0,!0);st(o);for(const e of i)o.setX(e.i,e.w[0]??0),o.setY(e.i,e.w[1]??0),o.setZ(e.i,e.w[2]??0),o.setW(e.i,e.w[3]??0),n=!0;if(a>0){const e=be(s,4,!0);st(e);for(const t of i)e.setX(t.i,t.w[4]??0),e.setY(t.i,t.w[5]??0),e.setZ(t.i,t.w[6]??0),e.setW(t.i,t.w[7]??0),e.needsUpdate=!0,n=!0}n&&r.add(e)}this.inEditor&&this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(e=>e.queueRefreshScatter(this.renderingView.camera.position,!0,e=>r.has(e.name)))}async materialize(e,t,a=!1,s){if(!this.shouldBeMaterialized(e))return;let r,n;switch(e.type){case"asset_mesh":r=await this.createFromAsset(e);break;case"shape_mesh":r=await this.createFromShape(e);break;case"light":r=await this.createLight(e);break;case"particles":r=await this.createParticleSystem(e),e.collisionDetection=!1;break;case"global_fog":this.scene.fog=Ze(e.fog),this.fixFogColor(),r=new h;break;case"sky":this.sky=Pe(),this.updateSky(e),r=this.sky;break;case"world_env":this.updateWorldEnv(e),r=new h,this.worldEnvObj=r;break;case"actor":({object:r,actor:n}=await this.createFromActor(e,s));break;case"group":r=new h;break;case"prefab":r=await this.createFromPrefab(e,s);break;case"vfx":r=await this.createFromVfx(e,s);break;default:if(this.inEditor)throw new Error("unknown type "+e.type);console.warn(`Failed to materialize object. Unknown type '${e.type}'. This might be because the hology/core library is not compatible with the editor version.`)}if(null!=r){if(e.name&&e.name.length>0&&(r.name=e.name),null!=e.position&&r.position.fromArray(e.position),null!=e.scale&&r.scale.fromArray(e.scale),null!=e.rotation&&r.rotation.fromArray(e.rotation),a?r.userData._src=e:r.userData.src=e,null!=n&&(r.userData.actor=n),this.inEditor,this.inEditor){let e=null;r instanceof pe&&(e=function(e){if(e instanceof me)return new p(new i(...e.offset.toArray()),Ke);return null}(r.collisionShape)),null!=e&&(e.layers.disable(0),e.layers.enable(18),e.scale.multiplyScalar(1.1),r.add(e))}if(this.objectMap.set(r.uuid,e),this.sceneObjectMap.set(e.id,r),e.physics?.type!==H.dynamic||null==t||this.inEditor?null==t?this.scene.add(r):t?.add(r):(t.add(r),r.getWorldPosition(r.position),r.getWorldQuaternion(r.quaternion),r.getWorldScale(r.scale),this.scene?.attach(r)),null!=e.children&&await Promise.all(e.children?.map(e=>this.materialize(e,r,a))),this.inEditor||"asset_mesh"!=e.type&&"shape_mesh"!==e.type||"landscape"===e.shape||null!=e.physics?.type&&e.physics.type==H.dynamic||Ye(r),null!=this.renderingView)return this.renderingView.renderer.shadowMap.needsUpdate=!0,r;console.warn("RenderingView not found in materializer. No idea what called this")}}updateWorldEnv(e){this.renderingView.aoPass.enabled=e.worldEnv.ao.enabled,this.renderingView.aoPass.blendIntensity=e.worldEnv.ao.blendIntensity,this.renderingView.aoPass.updateGtaoMaterial(e.worldEnv.ao),this.renderingView.aoPass.output=!0===e.worldEnv.ao.onlyAO?5:0;const t=e.worldEnv.toneMapping;null!=t&&(this.renderingView.renderer.toneMapping=t.mapping??0,this.renderingView.renderer.toneMappingExposure=t.exposure??1);const a=e.worldEnv.environment;null!=a&&null!=a.textureId?this.assetManagerService.getTexture(this.assets.get(a.textureId)).then(e=>{null==this.pmremGenerator&&(this.pmremGenerator=new r.PMREMGenerator(this.renderingView.renderer),this.pmremGenerator.compileEquirectangularShader()),this.pmremGeneratorResults.has(e)||this.pmremGeneratorResults.set(e,this.pmremGenerator.fromEquirectangular(e).texture);const t=this.pmremGeneratorResults.get(e);this.renderingView.scene.environment=t,this.renderingView.scene.environmentIntensity=a.intensity??1}):this.renderingView.scene.environment=null}resetWorldEnv(){this.renderingView.aoPass.enabled=!1,this.renderingView.aoPass.blendIntensity=1,this.renderingView.aoPass.output=0,this.renderingView.renderer.toneMapping=0,this.renderingView.renderer.toneMappingExposure=1}async updateSky(e){if(null==e?.sky?.materialId)return void(this.sky.material=Ie);const t=await this.assetsService.getAsset(e.sky.materialId),a=await materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1);this.applySkySettings(a),null!=this.sky?this.sky.material=a:console.warn("No sky has been created")}applySkySettings(e){e.side=r.BackSide,(e instanceof g||e instanceof r.MeshBasicMaterial||e instanceof r.ShaderMaterial)&&(e.fog=!1)}async createComponent(e,t,a,s){const r=new Le[a.path+"/"+a.className],i=t.id+s;r.id=i,r.object=e;for(const e of a.params)null!=e.value&&(r[e.name]=e.value);return this.components.push(r),i}async createFromActor(e,t){const a=this.actorTypes.find(t=>t.name===e.actor?.type)?.type??U[e.actor?.type];if(null==a)return{object:null,actor:null};this.inEditor&&this.editorActorParamSnapshot.set(e.id,JSON.stringify(e.actor));const s=await this.actorProvider.create(a,(new M).fromArray(e.position),(new o).fromArray(e.rotation),!0);return this.materializedActors.set(this.getNestedActorId(e.id,t),s),{object:s?.object,actor:s}}getNestedActorId(e,t){return null!=t?t.sceneObjectChain.join("/")+"/"+e:e}async createFromVfx(e,t){const a=await this.assetsService.getAsset(e.assetId);null==a&&console.error("Could not find asset",e);const s=await this.actorProvider.create($,(new M).fromArray(e.position),(new o).fromArray(e.rotation),!1);try{await s.fromAsset(a)}catch(e){return console.error("Failed to create VFX asset",e),null}return s.play(),this.materializedActors.set(this.getNestedActorId(e.id,t),s),null!=s&&(s.object.userData.actor=s),s?.object}async createFromShape(e){const t=this.inEditor&&e.hidden;let a;if("landscape"==e.shape)a=this.createLandscape(e),a.traverse(e=>{e instanceof p&&this._originalMaterials.set(e.id,e.material)});else{let s=new g({name:"Default",color:new n("#aaaaaa"),visible:this.inEditor||!e.hidden,wireframe:!!t});const r=await this.createMeshByShape(e.shape,s,e.shapeParams);r.castShadow=e.castShadow??!0,r.receiveShadow=e.castShadow??!1,e.collisionDetection||(r.collisionShape=null),r.physics=e.physics,a=r,this._originalMaterials.set(a.id,r.material),a.traverse(e=>{})}return t||(await Promise.all((e.materialAssignments??[]).filter(e=>null!=e.materialId).map(e=>this.applyMaterial(a,e))),this.applyVertexMaterials(e,a)),a}createLandscape(e){const t=e.landscape?.options;if(null==t)return console.error(`No landscape options exist on scene object ${e.id} ${e.name}`),new h;const a=fe(e.landscape.options);this.applyHeightMaps(a,e.landscape.heightMaps,!0);const s=new ue(e,this.renderingView,a,this.assetManagerService,this.assetsService,this.shaders,t=>{(e.materialAssignments??[]).filter(e=>null!=e.materialId).forEach(e=>this.applyMaterial(t,e))});return this.landscapeManagers.push(s),s.refreshGeometry(),a}applyHeightMaps(e,t,a=!1){const s=new ge(e.sections);for(const e of t??[]){const t=s.find(e.x,e.y);if(!t)return;const a=t.geometry.getAttribute("position");for(const t of e.points)a.setY(t.i,t.y);a.needsUpdate=!0}const r=e.sections;r.forEach(e=>{e.geometry.computeBoundsTree(),e.geometry.computeVertexNormals()}),this.inEditor&&!a||setTimeout(()=>ye(r),50)}async createMeshByShape(e,t,a={}){if("landscape"!==e&&je.includes(e)){const s=await prepareShapeParameters(a??{}),r=e+JSON.stringify(a);if(!this.geometryCache.has(r)){const t=Me[e].geometry(s);t.computeTangents(),this.geometryCache.set(r,t)}this.collisionShapeCache.has(r)||this.collisionShapeCache.set(r,Me[e].collision(s));return new pe(this.geometryCache.get(r),t,this.collisionShapeCache.get(r))}if(this.inEditor)throw new Error(`Unsupported shape '${e}'`);console.warn(`Failed to create shape. Unsupported shape '${e}'. This might be because the hology/core library is not compatible with the editor version.`)}async createFromAsset(e){const t=await this.assetsService.getAsset(e.assetId);if(null==t)return void console.warn(`Can not find asset with id ${e.assetId} and name ${e.name}`);let{scene:a}=await this.assetManagerService.getMesh(t,{mergeGeomtries:!0});et(e.materialAssignments,t.materialAssignments).forEach(e=>this.applyMaterial(a,e));const s=e.receiveShadow??!!t.receiveShadow??!0,r=e.castShadow??!!t.castShadow??!1;return a.receiveShadow=s,Ge(a,r,s),e.collisionDetection||(a.collisionShapes=[]),null!=e.physics&&!0!==this.inEditor&&(a.physics=e.physics),this.applyVertexMaterials(e,a),a.traverse(e=>{e instanceof p&&"computeBoundsTree"in e.geometry&&null==e.geometry.boundsTree&&e.geometry.computeBoundsTree()}),a}async createFromPrefab(e,t){const a=await this.assetsService.getAsset(e.assetId);if(null==a)return void console.warn(`Can not find asset with id ${e.assetId} and name ${e.name}`);null==t&&(t={sceneObjectChain:[]}),t.sceneObjectChain.push(e.id);const{object:s}=await this.createFromPrefabAsset(a,t);return t.sceneObjectChain.pop(),s}async createFromPrefabAsset(e,t){const a=new h;await Promise.all(e.prefab.objects.filter(e=>"global_fog"!==e.type&&"world_env"!==e.type).map(e=>this.materialize(e,a,!0,structuredClone(t))));const s=t.sceneObjectChain.join("/"),r=Array.from(this.materializedActors.entries()).filter(([e,a])=>e.startsWith(s)&&e.split("/").length-1===t.sceneObjectChain.length).map(([,e])=>e);r.forEach(e=>{a.add(e.object)}),this.initActorsPostInit(r,structuredClone(t));const i=Array.from(this.materializedActors.entries()).filter(([e,t])=>e.startsWith(s)).map(([,e])=>e);return{object:a,actors:i}}async createParticleSystem(e){const t=await this.assetsService.getAsset(e.assetId),a=new y;return await x.fromJSONAsync(t.particleSystem,r).then(e=>{const t=new P(a,r);e.addRenderer(t),this.renderingView.onLoop(t=>e.update())}),a}async createLight(e){if("point"===e.light.type){const t=new w(e.light.point.color,e.light.point.intensity,e.light.point.distance,e.light.point.decay);if(t.castShadow=e.light.point.castShadow??!0,this.inEditor){const e=(new r.TextureLoader).load("assets/light-bulb-icon.webp"),a=new r.SpriteMaterial({map:e,alphaTest:.5}),s=new Be(a);s.scale.multiplyScalar(.6),t.add(s)}return t}if("spot"===e.light.type){const t=new r.SpotLight(e.light.spot.color,e.light.spot.intensity,e.light.spot.distance,e.light.spot.angle,e.light.spot.penumbra,e.light.spot.decay);if(t.castShadow=e.light.spot.castShadow??!0,t.target=new y,t.target.position.set(0,-1,0),t.add(t.target),this.inEditor){const e=(new r.TextureLoader).load("assets/light-bulb-icon.webp"),a=new r.SpriteMaterial({map:e,alphaTest:.5}),s=new Be(a);s.scale.multiplyScalar(.6),t.add(s),t.add(new r.SpotLightHelper(t))}return t}return"directional"===e.light.type?(this.applyDirectionalLight(e.light.directional,e),new h):"ambient"===e.light.type?(this.applyDirectionalAmbientLight(null,e.light.ambient,e),new h):void 0}applyDirectionalAmbientLight(e,t,a){const s=this.scene.children.find(e=>e.name===xe);null!=s?(s.intensity=t.intensity,s.color.set(t.color),s.groundColor.set(t.color),s.userData.src=a,s.userData.volumetricIntensity=t.volumetricIntensity):console.warn("Couldn't find ambient light")}applyDirectionalLight(e,t){for(const a of this.renderingView.csm.lights)a.intensity=e.intensity,a.color.set(e.color),a.castShadow=e.castShadow,a.userData.src=t,a.userData.volumetricIntensity=e.volumetricIntensity;this.renderingView.csm.lightDirection.fromArray(e.direction).normalize()}dispose(){this.updateSubscription.unsubscribe(),this.createAssetSubscription.unsubscribe(),this.materializedActors.forEach(e=>e.disposed.next(!0)),this.materializedActors.clear()}};Re=e([W(),t("design:paramtypes",[b,Object,Object,he,X,Array,Array,Object])],Re);export{Re as SceneMaterializer};function Ge(e,t,a){e.castShadow=t,e.receiveShadow=a,e.traverse(e=>{e.castShadow=t,e.receiveShadow=a})}const Ue=new Map,He=new Map,Je=new u({color:16711935}),qe=new Map;export async function materialFromAsset(e,t,a,s,r,i=!0){const n=JSON.stringify(e.material);return i&&Ue.has(n)?Ue.get(n):i&&He.has(n)?await He.get(n):He.set(n,_materialFromAsset(n,e,t,a,s,r,i)).get(n)}export async function _materialFromAsset(e,t,a,s,i,o,l=!0){const c={opacity:t.material.params.opacity,map:null,emissive:t.material.params.emissive??null,metalness:t.material.params.metalness??0,flatShading:t.material.params.flatShading??!1,color:new n(t.material.params.color),transparent:null!=t.material.params.opacity&&t.material.params.opacity<1},h={};if(null!=t.material.params.map){const e=t.material.params.map,a=await s.getAsset(e);null!=a&&(c.map=await i.getTexture(a))}let d;switch(t.material.type){case"phong":d=new f({...c,...h});break;case"water":d=Ae(c,a);break;case"grassFoliage":d=we({color:c.color,map:c.map},a);break;case"grass":d=ve({...c,colorTwo:new n(t.material.params.colorTwo),colorThree:new n(t.material.params.colorThree)},a);break;case"standard":case"unlit":case"toon":case"layered":case"lambert":case"shader":case"landscape":case"landscape-composite":case"decal-unlit":case"decal-standard":const e={standard:We?Z:ee,lambert:Z,unlit:te,toon:_e,layered:Fe,landscape:Q,"landscape-composite":K,"decal-unlit":Ce,"decal-standard":Ee}[t.material.type]??o.find(e=>e.name==t.material.shader)?.type;if(e){try{let r=new e;const n=await prepareClassParameters(t.material?.shaderParams??{},e,s,i,null,a,o);Object.assign(r,n),d=r.build()}catch(e){console.log("Shader runtime error: "+e),qe.has(t.material.shader)||qe.set(t.material.shader,Je.clone()),d=qe.get(t.material.shader)}d.userData.customShaderName=t.material.shader}else console.warn("Missing shader implementation with name "+t.material.shader),d=Je;break;default:throw new Error("Unsupported material type"+t.material.type)}return a?.csm.setupMaterial(d),null!=a&&Ue.set(e,d),d.side=t.material.side??d.side??r.FrontSide,d.transparent=(t.material.transparent??c.transparent??!1)||d.transparent,d.alphaTest=t.material.alphaTest??d.alphaTest??0,null!=t.material.blending&&(d.blending=J[t.material.blending]??r.NormalBlending),t.material.bloom&&(d.userData.hasBloom=!0),t.material.reflective&&(d.userData.reflective=!0),!0===t.material.outlines&&(d.userData.outlineParameters={},null!=t.material.outlineParams&&(null!=t.material.outlineParams.color&&(d.userData.outlineParameters.color=new n(t.material.outlineParams.color).toArray()),null!=t.material.outlineParams.thickness&&(d.userData.outlineParameters.thickness=t.material.outlineParams.thickness))),d.userData.assetId=t.id,He.delete(e),d}export async function prepareClassParameters(e,t,a,s,r,i,n,o){const l={};for(const[t,c]of Object.entries(e)){const e=await Xe(t,c,a,s,r,i,n,o);null!=e&&(l[t]=e)}return l}export async function prepareShapeParameters(e){const t={};for(const[a,s]of Object.entries(e)){const e=await Xe(a,s,null,null,null);null!=e&&(t[a]=e)}return t}async function Xe(e,t,a,s,r,i,l,c,h=t.value,d=t.type){if(null==t||null==h||""===h)return null;switch(d){case Se.Array:if(Array.isArray(h)&&"element"in t)return await Promise.all(h.map(n=>Xe(e,t,a,s,r,i,l,c,n,t.element)));break;case Se.Number:case Se.FloatNode:let d="string"==typeof h?parseFloat(h):h;return t.type===Se.FloatNode?C(d):d;case Se.Texture:let m=await s.getTexture(await a.getAsset(h));return"envmap"===e.toLowerCase()&&null!=i&&(m=i.getEnvTexture(m)),m;case Se.Sampler2DNode:return F(await s.getTexture(await a.getAsset(h)));case Se.Boolean:return h;case Se.BooleanNode:return I(h);case Se.Vector2:case Se.Vec2Node:if("object"==typeof h){const e=h instanceof Array?(new S).fromArray(h):new S(h.x,h.y);return t.type===Se.Vec2Node?T(e):e}return null;case Se.Vector3:case Se.Vec3Node:if("object"==typeof h){const e=h instanceof Array?(new M).fromArray(h):new M(h.x,h.y,h.z);return t.type===Se.Vec3Node?B(e):e}return null;case Se.Color:case Se.RgbNode:const p=new n(h);return t.type===Se.RgbNode?O(p):p;case Se.String:return h;case Se.BaseActor:const u=h;return null==r&&console.warn("Class parameters can not be prepared as actors are not passed in"),r?.get(u);case Se.Euler:const f=h;return(new o).fromArray(f);case Se.Object3D:return(await s.getMesh(await a.getAsset(h))).scene;case Se.Material:return await materialFromAsset(await a.getAsset(h),i,a,s,l);case Se.AudioBuffer:return await s.getAudio(await a.getAsset(h));case Se.VisualEffect:const g=await a.getAsset(h);if(null==c){console.error("Can not create instance of visual effect because missing actor provider");break}if("vfx"in g)return new R(c,g);console.error("Using a non-vfx asset for visual effect parameter");break;case Se.Curve:return De.decode(h);case Se.ColorLayer:case Se.MaskLayer:if(Te(h)){const e=await Ve.decode(h,async e=>await s.getTexture(await a.getAsset(e))),t=await prepareClassParameters(h.params,null,a,s);return Object.assign(e,t),e}return console.warn("Expecting color layer but got",h),null}return null}function Ye(e){e.updateWorldMatrix(!0,!0),e.updateMatrix(),e.traverse(e=>{e.matrixAutoUpdate=!1,e.matrixWorldNeedsUpdate=!1});const t=e.updateMatrixWorld;e.updateMatrixWorld=function(){t.apply(e),e.updateMatrixWorld=function(){}}}function Ze(e){return"linear"===e.type?new l(new n(e.color),e.near??100,e.far??1e3):"density"===e.type?new c(e.color,e.density):void console.warn("Invalid fog type",e)}const Ke=new g({color:4229780});async function Qe(e,t,a,s){null==s&&(s=(new m).identity()),await t(e,a,s);const i=s.clone().multiply(function(e,t){if(null==e.position||null==e.rotation||null==e.scale)return t.identity();return t.compose((new M).fromArray(e.position),(new v).setFromEuler((new o).fromArray(e.rotation)),(new M).fromArray(e.scale))}(e,new r.Matrix4));return Promise.all((e.children??[]).map(a=>Qe(a,t,e,i)))}export function toSerializedParamType(e){const t=e.constructor.prototype;return t instanceof Number||e===Number?Se.Number:t instanceof E||"function"==typeof e.prototype.isFloat?Se.FloatNode:t instanceof A||e===A||e.isTexture?Se.Texture:t instanceof Y||e===N?Se.Sampler2DNode:t instanceof Boolean||e===Boolean?Se.Boolean:t instanceof D?Se.BooleanNode:t instanceof n||e==n?Se.Color:t instanceof k||"function"==typeof e.prototype.isRgb?Se.RgbNode:t instanceof S||e==S?Se.Vector2:t instanceof z||"function"==typeof e.prototype.isVec2?Se.Vec2Node:t instanceof M||e==M?Se.Vector3:t instanceof _||"function"==typeof e.prototype.isVec3?Se.Vec3Node:t instanceof String||e===String?Se.String:t instanceof G||e==G||e.prototype instanceof G||e.prototype==G?Se.BaseActor:t instanceof o||e==o?Se.Euler:t instanceof y||e==y?Se.Object3D:t instanceof d||e==d?Se.Material:t instanceof AudioBuffer||e==AudioBuffer?Se.AudioBuffer:t instanceof R||e==R?Se.VisualEffect:t instanceof De||e==De?Se.Curve:t instanceof Ve||e==Ve?Se.ColorLayer:t instanceof Ne||e==Ne?Se.MaskLayer:void console.warn("Failed to map parameter type to serialized version",{type:e})}export function prepareCustomParams(e,t,a={}){return Object.fromEntries(e.map(e=>[e.name,{type:e.options.array?Se.Array:toSerializedParamType(e.type),...e.options.array?{element:toSerializedParamType(e.type)}:{},value:t[e.name]?.value??(!0!==e.options.array?a[e.name]??customParameterDefaultValueByType.get(toSerializedParamType(e.type)):[])}]))}export function prepareCustomParamsFromType(e,t,a=null){const s=ae(e);if(0===s.length)return{};let r;null!=a?q(a,()=>{r=a.get(e)}):r=new e;const i={};for(const e of s){const t=r[e.name];if(null!=t&&!0!==e.options.array){const a=serializeCustomParameter(e.type,t);null!=a&&(i[e.name]=a)}}return prepareCustomParams(s,t,i)}export function serializeCustomParameter(e,t){function a(){console.error("Failed to serialize value",{type:e,value:t})}switch(e){case Number:case Boolean:return t;case S:return t instanceof S?t.toArray():void a();case M:return t instanceof M?t.toArray():void a();case j:return t instanceof j?t.toArray():void a();case n:return t instanceof n?"#"+t.getHexString():"string"==typeof t?t:"number"==typeof t?"#"+new n(t).getHexString():void a();case String:return t;case o:return t instanceof o?t.toArray():void a()}}function et(e,t){return function(e,t,a){const s=[],r=new Set;for(const i of[...e??[],...t??[]]){const e=a(i);r.has(e)||(r.add(e),s.push(i))}return s}((e??[]).filter(e=>tt(e.materialId)),(t??[]).filter(e=>tt(e.materialId)),e=>e.color+e.name)}function tt(e){return"null"!=e&&null!=e}export const customParameterDefaultValueByType=new Map([[Se.RgbNode,"#000000"],[Se.Color,"#000000"],[Se.Vector4,[0,0,0,0]],[Se.Vec4Node,[0,0,0,0]],[Se.Vector3,[0,0,0]],[Se.Vec3Node,[0,0,0]],[Se.Vector2,[0,0]],[Se.Vec2Node,[0,0]],[Se.Euler,[0,0,0,"XYZ"]],[Se.Array,[]],[Se.ColorLayer,Oe],[Se.MaskLayer,ke]]);export function applyMaterial(e,t,a,s){const i=[];return e.traverse(async e=>{if(e instanceof p||e.isMesh||e instanceof r.SkinnedMesh||e.isSkinnedMesh)for(const t of ie(e.material))t.hasOwnProperty("color")&&i.push(e)}),Promise.all(i.map(async e=>{if(e.material instanceof Array)for(let r=0;r<e.material.length;r++){const i=e.material[r];if(null==i.color||!(i.color instanceof n))continue;const o="#"+i.color.getHexString(),l=i.name;if(o===t.color&&(i.name===t.name||null==t.name)||e.userData["originalColor_"+r]===t.color&&e.userData["originalMaterialName_"+r]===t.name){const i=await a(t.materialId),n=e.material[r];null!=i&&n.id!=i.id&&(e.material[r]=i,e.userData["originalColor_"+r]=e.userData["originalColor_"+r]??o,e.userData["originalMaterialName_"+r]=e.userData["originalMaterialName_"+r]??l,null!=s&&s.set(e.id+"#"+r,n))}}else if("color"in e.material){const r="#"+e.material.color.getHexString(),i=e.material.name;if(r===t.color&&(e.material.name===t.name||null==t.name)||e.userData.originalColor===t.color&&e.userData.originalName===t.name){const n=await a(t.materialId),o=e.material;null!=n&&(e.material=n,e.userData.originalColor=e.userData.originalColor??r,e.userData.originalMaterialName=e.userData.originalMaterialName??i,null!=s&&(s.has(e.id)||s.set(e.id,o)))}}}))}function at(e,t){if(e instanceof r.ShaderMaterial&&t instanceof r.ShaderMaterial){return e.fragmentShader+e.vertexShader==t.fragmentShader+t.vertexShader&&function(e,t){if(e instanceof r.ShaderMaterial&&t instanceof r.ShaderMaterial){for(const a in e.uniforms){if(null==t.uniforms[a])return!1;if(t.uniforms[a].value!==e.uniforms[a].value)return!1}return!0}return!1}(e,t)}return!1}function st(e){if(null!=e){for(let t=0;t<e.array.length;t++)e.setX(t,0);e.needsUpdate=!0}}/*
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{ConvexPolyhedronCollisionShape as a}from"@hology/core";import{Subject as s}from"rxjs";import*as r from"three";import{BoxGeometry as i,Color as n,Euler as o,Fog as l,FogExp2 as c,Group as h,Material as p,Matrix4 as m,Mesh as d,MeshLambertMaterial as u,MeshPhongMaterial as f,MeshStandardMaterial as g,Object3D as y,PointLight as w,Quaternion as M,Scene as v,Texture as b,Vector2 as A,Vector3 as S,Vector4 as x}from"three";import j,{SpriteRenderer as I}from"@hology/nebula";import{batchingUniformFloat as P,batchingUniformVec2 as D,batchingUniformVec3 as C,batchingUniformVec4 as E,bool as T,BooleanExpression as V,BooleanNode as O,colorToNormal as k,float as B,FloatNode as F,ifDefApply as N,NodeShaderMaterial as z,rgb as _,rgba as W,RgbNode as L,select as $,standardMaterial as R,Texture2dLookupNode as U,textureSampler2d as G,textureSampler2dArray as H,varyingAttributes as J,varyingTransformed as q,vec2 as X,Vec2Node as Y,vec3 as Z,Vec3Node as K,vec4 as Q,Vec4Node as ee}from"three-shader-graph";import{Service as te}from"typedi";import{VfxActor as ae}from"../effects/vfx/vfx-actor.js";import{VisualEffect as se}from"../effects/vfx/vfx-param.js";import{BaseActor as re}from"../gameplay/actors/actor.js";import ie from"../gameplay/actors/builtin/index.js";import{PhysicsBodyType as ne,ThreeBlendingMode as oe,withInjectionContext as le}from"../gameplay/index.js";import{RenderingView as ce}from"../rendering.js";import{Sampler2DNode as he}from"../shader-nodes/index.js";import{LambertShader as pe}from"../shader/builtin/lambert-shader.js";import{LandscapeCompositeShader as me}from"../shader/builtin/landscape-composite-shader";import{LandscapeShader as de}from"../shader/builtin/landscape-shader.js";import{StandardShader as ue}from"../shader/builtin/standard-shader.js";import{UnlitShader as fe}from"../shader/builtin/unlit-shader.js";import{extractShaderParameters as ge}from"../shader/parameter.js";import{ArrayMap as ye,groupBy as we}from"../utils/collections.js";import{iterateMaterials as Me}from"../utils/materials.js";import{filterChildrenShallow as ve,filterSceneShallow as be,findFirstVisibleMesh as Ae,findFirstVisibleObject as Se}from"../utils/three/traverse.js";import{AssetMeshInstance as xe,AssetResourceLoader as je}from"./asset-resource-loader.js";import{isCollisionMesh as Ie}from"./collision/collision-shape-import.js";import{BoxCollisionShape as Pe,PhysicalShapeMesh as De}from"./collision/collision-shape.js";import{LandscapeManager as Ce}from"./landscape/landscape-manager.js";import{initLandscape as Ee}from"./landscape/landscape.js";import{SectionGrid as Te,smoothNormalsCrossMeshes as Ve}from"./landscape/utils.js";import{createGrassFoliageMaterial as Oe}from"./materials/grass-foliage.js";import{createGrassMaterial as ke}from"./materials/grass.js";import{getMaterialAttribute as Be}from"./materials/utils/material-painting.js";import{createWaterMaterial as Fe}from"./materials/water.js";import{SerializedParamType as Ne}from"./model.js";import{ShapeLibrary as ze,ShapeLibraryKeys as _e}from"./objects/shapes.js";import{ambientLightName as We,createSky as Le,defaultSkyMaterial as $e}from"./sky.js";import{Curve2 as Re}from"../utils/curve.js";import{DecalUnlitShader as Ue}from"../shader/builtin/decal-unlit-shader.js";import{DecalStandardShader as Ge}from"../shader/builtin/decal-standard-shader.js";import{ColorLayer as He,defaultValueColorLayer as Je,defaultValueMaskLayer as qe,MaskLayer as Xe}from"../shader/color-layer.js";import{LayeredShader as Ye}from"../shader/builtin/layered-shader";import{isColorLayerSerialized as Ze}from"../shader/color-layer";import{FogVolume as Ke}from"../rendering/fog/fog-volume-actor.js";import{UnscaledSprite as Qe}from"../utils/three/unscaled-sprite.js";import{ToonShader as et}from"../shader/builtin/toon-shader.js";import{BatchedMesh2 as tt}from"./batched-mesh-2.js";import{ParallaxStandardMaterial as at}from"../shader/builtin/standard-shader";import{parallaxOcclusionMapping as st}from"../shader-nodes/pom.js";const rt={},it=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),nt=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||(navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPad"))&&!!navigator.userAgent.match(/AppleWebKit/)&&!navigator.userAgent.match(/CriOS/);export const shapeDefaultColor="#aaaaaa";export class SceneMaterializerLoader{constructor(e,t,a){this.dataProvider=e,this.assetsService=t,this.assetManagerService=a}get(e,t){return new ot(e,this.dataProvider,this.assetsService,this.assetManagerService,t,[],[],{create:()=>null,initActor:async()=>{}})}}let ot=class{constructor(e,t,a,i,n,o,l,c){this.scene=e,this.dataProvider=t,this.assetsService=a,this.assetManagerService=i,this.renderingView=n,this.shaders=o,this.actorTypes=l,this.actorProvider=c,this.objectMap=new Map,this.sceneObjectMap=new Map,this.components=[],this.landscapeManagers=[],this.materializedActors=new Map,this.inEditor=!0,this.updated$=new s,this.removed$=new s,this.error$=new s,this.editorActorParamSnapshot=new Map,this.assets=new Map,this._canBeInstancedCache=new Map,this._originalMaterials=new Map,this.pmremGeneratorResults=new WeakMap,this.prefabInstanceChain=[],this.geometryCache=new Map,this.collisionShapeCache=new Map,this.originalFog=null,t.onCreate(e=>this.update(e)),t.onUpdate(e=>this.update(e)),t.onRemove(e=>this.remove(e)),this.createAssetSubscription=a.onCreate.subscribe(e=>{this.assets.set(e.id,e)}),this.updateSubscription=a.onUpdate.subscribe(async t=>{this.assets.set(t.id,t),"material"==t.type?e.traverse(e=>{if(e instanceof r.Mesh)if(Array.isArray(e.material))for(let a=0;a<e.material.length;a++)this.refreshMaterial(e,e.material[a],t,a);else this.refreshMaterial(e,e.material,t)}):"mesh"==t.type?(this.findByAssetId(t.id).forEach(e=>{this.remove(e.userData.src),this.materializeAndInitActor(e.userData.src)}),this.landscapeManagers.forEach(e=>{const a=e.source?.grass?.layers?.some(e=>e.meshes.some(e=>e.assetId===t.id));a&&e.queueRefreshScatter(this.renderingView?.camera.position??new S,!0)})):"prefab"===t.type?this.findByAssetId(t.id).forEach(e=>{const t=e.userData.src;this.remove(t),this.materializeAndInitActor(t)}):"vfx"===t.type&&this.dataProvider.getObjects().forEach(e=>{yt(e,(e,a)=>{"vfx"===e.type&&e.assetId===t.id&&(this.remove(e),this.materializeAndInitActor(e))})})})}async refreshMaterial(e,t,a,s){const r=t?.userData?.assetId;if(r!==a.id){const e=this.assets.get(r);let t=!1;if(null!=e)for(const s of Object.values(e.material.shaderParams)){if(s.type===Ne.Material&&s.value===a.id){t=!0;break}if(s.type===Ne.Array&&"element"in s&&s.element===Ne.Material&&s.value.includes(a.id)){t=!0;break}}if(!t)return}const i=await materialFromAsset(this.assets.get(r),this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1),n=i.userData;i.userData=t.userData,i.userData.hasBloom=n.hasBloom,i.userData.reflective=n.reflective,i.userData.outlineParameters=n.outlineParameters,null!=s?vt(e.material[s],i)||(e.material[s]=i):vt(e.material,i)||(e.material=i,e===this.sky&&this.applySkySettings(e.material))}getTopLevelActors(){return Array.from(this.materializedActors.entries()).filter(([e,t])=>!e.includes("/")).map(([,e])=>e)}get actorInstances(){return Array.from(this.materializedActors.values())}async initTextures(){const e=[];if(await Promise.all(this.dataProvider.getObjects().filter(e=>"shape_mesh"===e.type||"asset_mesh"===e.type).filter(e=>null!=e.materialAssignments).flatMap(e=>e.materialAssignments).map(async t=>{const a=this.assets.get(t.materialId);if(null!=a)for(const t of Object.values(a.material.shaderParams))if(t.type===Ne.Texture&&"string"==typeof t.value){const a=this.assets.get(t.value),s=await this.assetManagerService.getTexture(a);null!=s&&e.push(s)}})),0!==e.length&&this.renderingView){console.log(`Initializing ${e.length} textures`),console.time("Init textures");for(const t of e)this.renderingView.renderer.initTexture(t);console.timeEnd("Init textures")}}async prefetchAssets(){const e=Array.from(new Set(this.dataProvider.getObjects().filter(e=>null!=e.assetId&&"asset_mesh"==e.type).filter(e=>e.assetId)));await Promise.all(e.map(e=>this.assetsService.getAsset(e.assetId).then(e=>{if(null!=e)return this.assetManagerService.getMesh(e)}))),this.initTextures()}async init(){await this.preInit(),ct.clear(),ht.clear(),await this.prefetchAssets(),await Promise.all(this.dataProvider.getObjects().map(e=>this.materialize(e))),await this.initActorsPostInit()}initActorsPostInit(e=this.getTopLevelActors(),t){const a=e.map(async e=>{const a=e.object.userData.src??e.object.userData._src;if("vfx"===a.type)return Promise.resolve();const s=await this.assetsService.getAsset(a.assetId),r={...s?.actor?.params??{},...a.actor?.params??{}},i=null!=t?new Map(Array.from(this.materializedActors.entries()).filter(([e,a])=>e.startsWith(t.sceneObjectChain.join("/"))&&e.split("/").length-1===t.sceneObjectChain.length).map(([e,t])=>[e.split("/").pop(),t])):this.materializedActors;for(const t of a.actor.innerParams??[])await this.applyActorComponentParams(e,t.path.slice(),t.params,i);const n=await prepareClassParameters(r,e.constructor,this.assetsService,this.assetManagerService,i,this.renderingView,this.shaders,this.actorProvider);Object.assign(e,n);try{return await this.actorProvider.initActor(e)}catch(e){console.error(`Failed to initiate actor (name="${a.name}", id=${a.id})`,e)}});return Promise.all(a)}addVfxChildActors(e,t=e){}async applyActorComponentParams(e,t,a,s){const r=t.length,i=t.shift();if(0==r){const t=await prepareClassParameters(a,null,this.assetsService,this.assetManagerService,s,this.renderingView,this.shaders,this.actorProvider);for(const[a,s]of Object.entries(t))null!=s&&(e[a]=s)}else null!=e[i]&&await this.applyActorComponentParams(e[i],t,a,s)}canObjectBeInstanced(e){return e.physics?.type!==ne.dynamic&&"sky"!==e.type&&"global_fog"!==e.type&&"world_env"!==e.type}async canAssetBeInstanced(e){if(!this._canBeInstancedCache.has(e.assetId)){const t=await this.createFromAsset(e);if(null==t)return!1;const a=[];t.traverse(e=>{!Ie(e)&&e.isMesh&&a.push(e)});const s=1==a.length&&0==a[0].children.length,r=a[0]instanceof d&&null!=a[0].geometry.morphAttributes&&Object.keys(a[0].geometry.morphAttributes).length>0,i=!0;this._canBeInstancedCache.set(e.assetId,s&&i&&!r)}return this._canBeInstancedCache.get(e.assetId)}async preInit(){this.renderingView?.onLoop(()=>{null!=this.sky&&this.renderingView.camera.getWorldPosition(this.sky.position)}),this.assetsService.getAssets().then(e=>{for(const t of e)this.assets.set(t.id,t)})}shouldBeMaterialized(e){if(null!=this.detailTier&&"asset_mesh"===e.type&&null!=e.assetId){const t=this.assets.get(e.assetId);if(null!=t){const e=t.mesh?.detailTier;if(null!=e)return e<=this.detailTier}}return!0}async initWithInstancing(){await this.preInit(),await this.prefetchAssets(),ct.clear(),ht.clear();const e=[],t=new ye,a=new ye;let s=0,i=0;const l=new Map,c=new Map;for(const r of this.dataProvider.getObjects())await yt(r,async(r,o,h)=>{if(!this.shouldBeMaterialized(r))return;const p="asset_mesh"==r.type&&this.canObjectBeInstanced(r)&&await this.canAssetBeInstanced(r),m="shape_mesh"===r.type&&"landscape"!==r.shape&&r.physics?.type!==ne.dynamic;if(p||m){if(o&&o.children?.length>0){const e=o.children.findIndex(e=>e.id===r.id);e>=0&&o.children.splice(e,1)}if(m){let e=r.shape+JSON.stringify(r.shapeParams??{})+r.castShadow+r.receiveShadow;const t=r.materialAssignments?.at(0)?.materialId,s=null!=t?this.assets.get(t):null;let o=null;if(null!=s&&"shader"!==s.material.type){if(e+=s.material.type+s.material.shader,null!=s.material.shaderParams){if(e+=Object.entries(s.material.shaderParams).filter(([e,t])=>"color"!=e).map(e=>JSON.stringify(e)).join(),null!=s.material.shaderParams.color){const e=s.material.shaderParams.color;e.type===Ne.Color&&null!=e.value&&(o=new n(e.value))}}}else e+=t;a.push(e,{object:{...r,parentTransform:h},color:o}),i++}else{const e=this.assets.get(r.assetId);wt(e.materialAssignments,r.materialAssignments);let a=l.get(r.assetId);if(null==a){const e=await this.createFromAsset(r),t=Ae(e);a={useBatchedMesh:null!=t&&this.testCanBatch(t.material,t.geometry),assetMesh:e},l.set(r.assetId,a)}if(a.useBatchedMesh){const s=wt(r.materialAssignments,e.materialAssignments),i=s[0]?.materialId;let n;if(i){const e=this.assets.get(i);n=await materialFromAsset(e,this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!0)}if(null==n)if(null==a.defaultMaterial){const e=Ae(a.assetMesh);null!=e&&(n=Array.isArray(e.material)?e.material[0]:e.material,a.defaultMaterial=n)}else n=a.defaultMaterial;if(null!=n){c.set(r.id,n);let e=jt(n);e+=St(a.assetMesh),t.push(e,{...r,parentTransform:h})}else console.warn("Can not materialize mesh because missing material",r)}else{const e=r.assetId+JSON.stringify(r.materialAssignments??[]);t.push(e,{...r,parentTransform:h})}s++}}else null==o&&e.push({...r,parentTransform:h})});console.log(`Scene init stats: \n Assets: ${t.size} batch groups containing in total ${s} objects.\n Shapes: ${a.size} batch groups containing in total ${i} objects. \n ${e.length} objects can not be batched. \n `);for(const e of l.values())this.prepareCollisionShapesForInstanced(e.assetMesh);console.time("materialize batches");for(const e of t.values()){if(0==e.length)continue;const t=await this.createFromAsset(e[0]);if(null==t)continue;let a;if(l.get(e[0].assetId).useBatchedMesh){a=this.createBatchedMesh(e,c,l)}else a=await this.createInstancedMesh(e,t);const s=this.assets.get(e[0].assetId);a.castShadow=e[0].castShadow??s.castShadow??!0,a.receiveShadow=e[0].receiveShadow??s.receiveShadow??!0;const r=new xe;r.add(a),r.userData.src=e[0],t instanceof xe&&(r.collisionShapes=t.collisionShapes),this.prepareCollisionShapesForInstanced(r),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r)}console.timeEnd("materialize batches");for(const e of a.values()){if(0==e.length)continue;const t=e[0].object,a=await this.createFromShape(t),s=Se(a,e=>!Ie(e)&&null!=e.geometry),i=s.material.clone();null!=e[0].color&&null!=i.color&&(i.color=new n(16777215));const l=s.geometry;let c,h;!(nt||i instanceof z||null==l.index)?(c=new r.BatchedMesh(e.length,l.getAttribute("position").count,l.index.count,i),c.perObjectFrustumCulled=!0,h=c.addGeometry(l)):c=new r.InstancedMesh(l,i,e.length),c.castShadow=a.castShadow??!0,c.receiveShadow=s.receiveShadow??!0;for(let t=0;t<e.length;t++){const a=e[t],s=(new r.Matrix4).compose((new S).fromArray(a.object.position),(new M).setFromEuler((new o).fromArray(a.object.rotation)),(new S).fromArray(a.object.scale)),i=(new m).copy(a.object.parentTransform).multiply(s);let n;n=c instanceof r.BatchedMesh?c.addInstance(h):t,c.setMatrixAt(n,i),null!=a.color&&c.setColorAt(n,a.color)}for(let t=0;t<e.length;t++){const s=e[t],r=new xe;r.userData.src=e[0],a instanceof De&&(r.collisionShapes=[a.collisionShape]),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r),r.add(c),null==c.userData.hasCollision&&(c.userData.hasCollision=[]),c.userData.hasCollision[t]=!!s.object.collisionDetection}}await Promise.all(e.map(e=>this.materialize(e))),await this.initActorsPostInit()}prepareCollisionShapesForInstanced(e){e instanceof xe&&e.collisionShapes.forEach(e=>{e instanceof a&&e.mesh instanceof d&&(e.mesh=e.mesh.geometry)})}testCanBatch(e,t){return!nt&&!(e instanceof z)&&t.groups.length<2&&(!Array.isArray(e)||1==e.length)&&this.testCanBatchMaterial(e)}testCanBatchMaterial(e){const t=Array.isArray(e)?e[0]:e;return null!=t&&(t instanceof g&&(null==t.bumpMap&&null==t.lightMap&&null==t.displacementMap))}createBatchedMesh(e,t,a){const s=new ye;for(const t of e)s.push(t.assetId,t);let i=0,o=0,l=0;const c=new Map;for(const[e,t]of s.entries()){const s=a.get(e);if(null==s){console.warn("Missing batching info for asset id "+e);continue}const r=Ae(s.assetMesh);if(null==r){console.warn("Missing mesh in batched asset");continue}c.set(e,r);const n=r.geometry.getAttribute("position");null==n&&console.warn("Missing position attribute for batched mesh"),i+=r.geometry.index.count*t.length,o+=n.count*t.length,l+=t.length}const h=["color","map","roughness","roughnessMap","metalness","metalnessMap","opacity","alphaMap","aoMap","aoMapIntensity","normalMap","normalScale","emissive","emissiveIntensity","emissiveMap"];let p=new Map,m=new r.MeshStandardMaterial({color:"white"});const d=t.get(e[0].id);if(d instanceof g){const a=new Set,s=new Map;for(const i of e){const e=t.get(i.id);for(const t of h){let i=e[t];i instanceof r.CompressedArrayTexture&&null!=i.userData.index&&(i=i.userData.index);const n=s.get(t);void 0!==n&&i!==n?a.add(t):s.set(t,i)}}for(const e of a){let t;const a=d[e];if("number"==typeof a)t=P(e);else if(a instanceof x)t=E(e);else if(a instanceof S||a instanceof n)t=C(e);else if(a instanceof A)t=D(e);else if(a instanceof r.CompressedArrayTexture)t=P(e+"_i");else if(a instanceof b)continue;p.set(e,t)}let i=J.uv;d instanceof at&&null!=d.heightMap&&(i=st(i,G(d.heightMap),B(d.heightScale)));let o=It(p.get("opacity"),F)??B(d.opacity??1);if(null!=d.alphaMap){let e;if(d.alphaMap instanceof r.CompressedArrayTexture){const t=H(d.alphaMap),a=It(p.get("alphaMap"),F)??B(d.alphaMap.userData.index??0);e=t.sample(Z(i.x,i.y,a))}else e=G(d.alphaMap).sample(i);o=o.multiply(e.r)}let l=W(It(p.get("color"),K)??d.color,o);if(null!=d.map){let e;if(d.map instanceof r.CompressedArrayTexture){const t=H(d.map),a=It(p.get("map"),F)??B(d.map.userData.index??0);e=t.sample(Z(i.x,i.y,a))}else e=G(d.map).sample(i);l=l.multiply(e)}let c=W(It(p.get("emissive"),K)??d.emissive,o);if(null!=d.emissiveMap){let e;if(d.emissiveMap instanceof r.CompressedArrayTexture){const t=H(d.emissiveMap),a=It(p.get("emissiveMap"),F)??B(d.emissiveMap.userData.index??0);e=t.sample(Z(i.x,i.y,a))}else e=G(d.emissiveMap).sample(i);c=c.multiply(e)}const f=It(p.get("emissiveIntensity"),F)??B(d.emissiveIntensity??1),g=It(p.get("normalScale"),Y)??X(d.normalScale??new A(1,1));let y=q.normal;if(null!=d.normalMap){let e;if(d.normalMap instanceof r.CompressedArrayTexture){const t=H(d.normalMap),a=It(p.get("normalMap"),F)??B(d.normalMap.userData.index??0);e=t.sample(Z(i.x,i.y,a))}else e=G(d.normalMap).sample(i);y=k(e.rgb,g.x)}let w=It(p.get("roughness"),F)??B(d.roughness??1);if(null!=d.roughnessMap){let e;if(d.roughnessMap instanceof r.CompressedArrayTexture){const t=H(d.roughnessMap),a=It(p.get("roughnessMap"),F)??B(d.roughnessMap.userData.index??0);e=t.sample(Z(i.x,i.y,a))}else e=G(d.roughnessMap).sample(i);w=w.multiply(e.g)}let M=It(p.get("metalness"),F)??B(d.metalness??0);if(null!=d.metalnessMap){let e;if(d.metalnessMap instanceof r.CompressedArrayTexture){const t=H(d.metalnessMap),a=It(p.get("metalnessMap"),F)??B(d.metalnessMap.userData.index??0);e=t.sample(Z(i.x,i.y,a))}else e=G(d.metalnessMap).sample(i);M=M.multiply(e.b)}let v=B(1);if(null!=d.aoMap){let e;if(d.aoMap instanceof r.CompressedArrayTexture){const t=H(d.aoMap),a=It(p.get("aoMap"),F)??B(d.aoMap.userData.index??0);e=t.sample(Z(i.x,i.y,a))}else e=G(d.aoMap).sample(i);v=v.multiply(e.r)}const j=It(p.get("aoMapIntensity"),F)??B(d.aoMapIntensity??0);let I=y;!0!==d.userData.disableAO&&(I=N("DOUBLE_SIDED",I,e=>$(new V("gl_FrontFacing"),e,e.multiplyScalar(-1))));const T=new z({color:R({color:l,roughness:w,metalness:M,ambientOcclusion:v,ambientOcclusionIntensity:j,emissive:c,emissiveIntensity:f,normal:I}),normal:y,roughness:w,opacity:o,emissive:c.rgb,transparent:d.transparent,alphaTest:d.alphaTest,envMap:d.envMap});null!=d.envMap&&(T.uniforms.envMapIntensity={value:d.envMapIntensity},T.uniforms.envMapRotation={value:(u=d.envMapRotation,(new r.Matrix3).setFromMatrix4(Pt.makeRotationFromEuler(u)))}),m=T}var u;const f=new tt(l,o,i,m);for(const[e,t]of p.entries()){let a=1;t instanceof ee||t instanceof K?a=4:t instanceof Y&&(a=2),f.initUniform(e,a,0)}for(const[e,i]of s.entries()){const s=c.get(e),o=f.addGeometry(s.geometry),l=a.get(e);if(null==l){console.warn("Missing batching info when configuring for asset id "+e);continue}let h=l.assetMesh instanceof xe?l.assetMesh.collisionShapes:void 0;const m=this.configureBatchedInstancedMesh(i,f,s,o,h);for(let e=0;e<m.length;e++){const a=i[e],s=m[e],o=t.get(a.id);for(let e of p.keys()){let t=o[e];if(t instanceof n&&(t=new S(t.r,t.g,t.b)),t instanceof r.CompressedArrayTexture)t=t.userData.index??0,e+="_i";else if(t instanceof b||null==t)continue;f.setUniformAt(e,s,t)}}}return f}async createInstancedMesh(e,t){const a=Se(t,e=>!Ie(e)&&null!=e.geometry),s=await this.assetsService.getAsset(e[0].assetId);await this.applyMaterials(t,wt(e[0].materialAssignments,s.materialAssignments)),a.updateMatrix();const i=a.geometry.clone(),n=a.material;let o,l;if(this.testCanBatch(n,i)){const t=Array.isArray(n)?n[0]:n,a=i.getAttribute("position").count;o=new r.BatchedMesh(e.length,a,null!=i.index?i.index.count:a,t),o.perObjectFrustumCulled=!0,l=o.addGeometry(i)}else o=new r.InstancedMesh(i,n,e.length);if(this.configureBatchedInstancedMesh(e,o,a),a.material instanceof p&&o.castShadow&&o.receiveShadow&&Array.isArray(n))for(const e of n);return o}configureBatchedInstancedMesh(e,t,a,s,i){const n=[];for(let l=0;l<e.length;l++){let c=l;t instanceof r.BatchedMesh&&(c=t.addInstance(s)),n.push(c);const h=(new r.Matrix4).compose((new S).fromArray(e[l].position),(new M).setFromEuler((new o).fromArray(e[l].rotation)),(new S).fromArray(e[l].scale)),p=(new m).copy(e[l].parentTransform).multiply(h).multiply(a.matrixWorld);t.setMatrixAt(c,p),null==t.userData.hasCollision&&(t.userData.hasCollision=[]),t.userData.hasCollision[c]=!!e[l].collisionDetection,null!=i&&(null==t.userData.collisionShapes&&(t.userData.collisionShapes=[]),t.userData.collisionShapes[c]=i)}return n}remove(e){if(console.log("Remove scene object",e),"global_fog"==e.type)return void(this.scene.fog=this.originalFog);if("world_env"===e.type)this.resetWorldEnv(),this.worldEnvObj=null;else if("actor"==e.type||"vfx"===e.type){const t=this.materializedActors.get(e.id);null!=t?(t.disposed.next(!0),t.onEndPlay()):console.warn("Failed to remove actor",e)}else"prefab"===e.type&&this.materializedActors.forEach((t,a)=>{a.startsWith(e.id)&&(t.disposed.next(!0),t.onEndPlay()),this.materializedActors.delete(a)});const t=this.sceneObjectMap.get(e.id);t?.parent.remove(t),this.sceneObjectMap.delete(e.id),this.components.filter(t=>t.object.userData.src?.id===e.id).forEach(e=>this.components.splice(this.components.indexOf(e,1))),this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(e=>{e.clear(),e.stop(),this.landscapeManagers.splice(this.landscapeManagers.indexOf(e,1))}),this.removed$.next({object:t,source:e})}deleteSceneObject(e){const t=this.sceneObjectMap.get(e.id);if(this.scene.remove(t),"landscape"==e.type){const t=this.landscapeManagers.findIndex(t=>t.source.id===e.id);if(t>-1){const e=this.landscapeManagers.splice(t,1)[0];e.clear(),e.stop()}}}findByAssetId(e){return be(this.scene,t=>t.userData.src?.assetId==e,e=>null!=e.userData.src)}applyMaterials(e,t){return null==t?Promise.resolve([]):Promise.all(t.filter(e=>"null"!==e.materialId).map(t=>this.applyMaterial(e,t)))}async applyMaterial(e,t){await applyMaterial(e,t,e=>{const t=this.assets.get(e);if(null!=t)try{return materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders)}catch(e){console.error("Failed to apply material",e)}},this._originalMaterials)}unapplyMaterials(e){e.traverse(async e=>{if(e instanceof d)if(e.material instanceof Array)for(let t=0;t<e.material.length;t++)e.material[t]=this._originalMaterials.get(e.id+"#"+t)??e.material[t];else e.material=this._originalMaterials.get(e.id)??e.material})}updateActors(e){console.log("update actors"),this.actorTypes=e;const t=new Set(Object.values(ie));be(this.scene,e=>e.userData.src?.id&&"actor"===e.userData.src.type&&this.materializedActors.has(e.userData.src?.id)&&!t.has(e.userData.src.actor.type)).forEach(async e=>{this.remove(e.userData.src),await this.materializeAndInitActor(e.userData.src)})}updateShaders(e){this.shaders=e;for(const[e,t]of ct.entries())t.userData.customShaderName&&ct.delete(e);this.landscapeManagers.forEach(t=>t.updateShaders(e)),be(this.scene,e=>!0).forEach(e=>{e.traverse(async e=>{if(e instanceof d)if(Array.isArray(e.material))for(let t=0;t<e.material.length;t++){const a=e.material[t].userData?.customShaderName;if(null!=a){const a=this.assets.get(e.material[t].userData.assetId);this.refreshMaterial(e,e.material[t],a,t)}}else{const t=e.material.userData?.customShaderName;if(null!=t){const t=this.assets.get(e.material.userData.assetId);this.refreshMaterial(e,e.material,t)}}})})}async update(e){if("sky"===e.type&&null!=this.sky&&null!=this.sky.parent)return void this.updateSky(e);if("world_env"===e.type&&null!=this.worldEnvObj)return void this.updateWorldEnv(e);const t=this.sceneObjectMap.get(e.id);if(t){let s=!1;if(t.traverseAncestors(e=>{"_hology_transform_group"===e.name&&(s=!0)}),!s){const a=this.findParent(e);null!=a&&a.uuid!=t.uuid?a.attach(t):console.error("Parent is wrong")}if("prefab"!==e.type&&"group"!==e.type){this.unapplyMaterials(t);this.inEditor&&e.hidden&&!1?t.traverse(e=>{e instanceof d&&(e.material.wireframe=!0)}):t.traverse(e=>{e instanceof d&&(e.material.wireframe=!1)})}if("asset_mesh"===e.type){const a=this.assets.get(e.assetId);wt(e.materialAssignments,a.materialAssignments).forEach(e=>this.applyMaterial(t,e))}else"shape_mesh"===e.type&&this.applyMaterials(t,e.materialAssignments);if(s||(null!=e.position&&t.position.fromArray(e.position),null!=e.scale&&t.scale.fromArray(e.scale),null!=e.rotation&&t.rotation.fromArray(e.rotation)),this.applyVertexMaterials(e,t),"light"==e.type)if("point"==e.light.type){const a=t;a.color=new n(e.light.point.color),a.intensity=e.light.point.intensity,a.decay=e.light.point.decay,a.castShadow=e.light.point.castShadow,a.distance=Math.max(e.light.point.distance,0),a.userData.volumetricIntensity=e.light.point.volumetricIntensity}else if("spot"==e.light.type){const a=t;a.color=new n(e.light.spot.color),a.intensity=e.light.spot.intensity,a.decay=e.light.spot.decay,a.angle=e.light.spot.angle,a.penumbra=e.light.spot.penumbra,a.castShadow=e.light.spot.castShadow,a.distance=Math.max(e.light.spot.distance,0),a.userData.volumetricIntensity=e.light.spot.volumetricIntensity}else"directional"===e.light.type?this.applyDirectionalLight(e.light.directional,e):"ambient"===e.light.type&&this.applyDirectionalAmbientLight(t,e.light.ambient,e);else if("landscape"===e.shape){const a=this.landscapeManagers.find(t=>t.source.id===e.id).source.landscape.options.density!==e.landscape.options.density;if(this.inEditor&&a){this.remove(e);const t=await this.materializeAndInitActor(e);return void this.updated$.next({object:t,source:e})}this.applyHeightMaps(t,e.landscape.heightMaps),this.inEditor&&this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(t=>{t.updateSource(e),t.queueRefreshScatter(this.renderingView.camera.position,!0,e=>!0)})}else if("global_fog"===e.type){const t=(this.scene.fog instanceof c?"density":"linear")!==e.fog.type;this.scene.fog=ft(e.fog),t&&(a=this.scene).traverse(e=>{if(e instanceof d){const t=e.material;t instanceof z&&(a.fog instanceof l?(t.uniforms.fogFar.value=a.fog.far,t.uniforms.fogNear.value=a.fog.near):a.fog instanceof c&&(t.uniforms.density={value:a.fog.density}),t.needsUpdate=!0,t.uniformsNeedUpdate=!0)}}),this.fixFogColor()}else if("actor"===e.type){if(this.materializedActors.has(e.id)){const t=this.materializedActors.get(e.id);if(t instanceof Ke){const a=await prepareClassParameters(e.actor.params,null,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,[],this.actorProvider);return void Object.assign(t,a)}const a=this.editorActorParamSnapshot.get(e.id);null!=a&&a===JSON.stringify(e.actor)||s||(this.remove(e),await this.materializeAndInitActor(e))}}else if("shape_mesh"===e.type){const a=await this.createMeshByShape(e.shape,t.material,e.shapeParams);t instanceof De&&(t.geometry=a.geometry,t.collisionShape=a.collisionShape)}("asset_mesh"===e.type||"shape_mesh"===e.type&&"landscape"!==e.shape)&<(t,e.castShadow,e.receiveShadow),e.name&&e.name.length>0&&(t.name=e.name),this.updated$.next({object:t,source:e})}else{const t=await this.materializeAndInitActor(e);this.updated$.next({object:t,source:e})}var a;this.renderingView.renderer.shadowMap.needsUpdate=!0}async materializeAndInitActor(e,t=this.findParent(e)){const a=await this.materialize(e,t);return yt(e,async e=>{if("actor"===e.type){const t=this.materializedActors.get(e.id);null!=t?await this.initActorsPostInit([t]):console.error(`Something went wrong when creating actor ${e.id}`)}}),a}findParent(e){const t=this.dataProvider.getObjects().flatMap(t=>t.id===e.id?null:ve(t,t=>t.children?.some(t=>t.id===e.id),()=>!0))[0];return null==t?this.scene:null!=t?be(this.scene,e=>e.userData?.src?.id===t.id,e=>null!=e.userData?.src)[0]:void 0}fixFogColor(){!0===this.renderingView.options.enableOutlines&&(this.scene.fog.color=new n(this.scene.fog.color))}findMeshWithGeometry(e){let t;return e.traverse(e=>{e instanceof d&&e.geometry&&(t=e)}),t}applyVertexMaterials(e,t){if(null==e.vertexMaterials||0===e.vertexMaterials.length)return;let a=1;for(const t of e.vertexMaterials)a=Math.max(t.w.length,a);const s=we(e.vertexMaterials,e=>e.m);t.traverse(e=>{if(e instanceof d){if(null==e.geometry)return;if(bt(Be(e,0,!1)),a>0){bt(Be(e,0,!1))}}});const r=new Set;for(const[e,i]of s.entries()){const s=null!=e?t.getObjectByName(e):this.findMeshWithGeometry(t);let n=!1;if(null==s||null==s.geometry)return void console.warn(`Failed to apply vertex materials on mesh with name "${e}"`);const o=Be(s,0,!0);bt(o);for(const e of i)o.setX(e.i,e.w[0]??0),o.setY(e.i,e.w[1]??0),o.setZ(e.i,e.w[2]??0),o.setW(e.i,e.w[3]??0),n=!0;if(a>0){const e=Be(s,4,!0);bt(e);for(const t of i)e.setX(t.i,t.w[4]??0),e.setY(t.i,t.w[5]??0),e.setZ(t.i,t.w[6]??0),e.setW(t.i,t.w[7]??0),e.needsUpdate=!0,n=!0}n&&r.add(e)}this.inEditor&&this.landscapeManagers.filter(t=>t.source.id===e.id).forEach(e=>e.queueRefreshScatter(this.renderingView.camera.position,!0,e=>r.has(e.name)))}async materialize(e,t,a=!1,s){if(!this.shouldBeMaterialized(e))return;let r,n;switch(e.type){case"asset_mesh":r=await this.createFromAsset(e);break;case"shape_mesh":r=await this.createFromShape(e);break;case"light":r=await this.createLight(e);break;case"particles":r=await this.createParticleSystem(e),e.collisionDetection=!1;break;case"global_fog":this.scene.fog=ft(e.fog),this.fixFogColor(),r=new h;break;case"sky":this.sky=Le(),this.updateSky(e),r=this.sky;break;case"world_env":this.updateWorldEnv(e),r=new h,this.worldEnvObj=r;break;case"actor":({object:r,actor:n}=await this.createFromActor(e,s));break;case"group":r=new h;break;case"prefab":r=await this.createFromPrefab(e,s);break;case"vfx":r=await this.createFromVfx(e,s);break;default:if(this.inEditor)throw new Error("unknown type "+e.type);console.warn(`Failed to materialize object. Unknown type '${e.type}'. This might be because the hology/core library is not compatible with the editor version.`)}if(null!=r){if(e.name&&e.name.length>0&&(r.name=e.name),null!=e.position&&r.position.fromArray(e.position),null!=e.scale&&r.scale.fromArray(e.scale),null!=e.rotation&&r.rotation.fromArray(e.rotation),a?r.userData._src=e:r.userData.src=e,null!=n&&(r.userData.actor=n),this.inEditor,this.inEditor){let e=null;r instanceof De&&(e=function(e){if(e instanceof Pe)return new d(new i(...e.offset.toArray()),gt);return null}(r.collisionShape)),null!=e&&(e.layers.disable(0),e.layers.enable(18),e.scale.multiplyScalar(1.1),r.add(e))}if(this.objectMap.set(r.uuid,e),this.sceneObjectMap.set(e.id,r),e.physics?.type!==ne.dynamic||null==t||this.inEditor?null==t?this.scene.add(r):t?.add(r):(t.add(r),r.getWorldPosition(r.position),r.getWorldQuaternion(r.quaternion),r.getWorldScale(r.scale),this.scene?.attach(r)),null!=e.children&&await Promise.all(e.children?.map(e=>this.materialize(e,r,a))),this.inEditor||"asset_mesh"!=e.type&&"shape_mesh"!==e.type||"landscape"===e.shape||null!=e.physics?.type&&e.physics.type==ne.dynamic||ut(r),null!=this.renderingView)return this.renderingView.renderer.shadowMap.needsUpdate=!0,r;console.warn("RenderingView not found in materializer. No idea what called this")}}updateWorldEnv(e){this.renderingView.aoPass.enabled=e.worldEnv.ao.enabled,this.renderingView.aoPass.blendIntensity=e.worldEnv.ao.blendIntensity,this.renderingView.aoPass.updateGtaoMaterial(e.worldEnv.ao),this.renderingView.aoPass.output=!0===e.worldEnv.ao.onlyAO?5:0;const t=e.worldEnv.toneMapping;null!=t&&(this.renderingView.renderer.toneMapping=t.mapping??0,this.renderingView.renderer.toneMappingExposure=t.exposure??1);const a=e.worldEnv.environment;null!=a&&null!=a.textureId?this.assetManagerService.getTexture(this.assets.get(a.textureId)).then(e=>{null==this.pmremGenerator&&(this.pmremGenerator=new r.PMREMGenerator(this.renderingView.renderer),this.pmremGenerator.compileEquirectangularShader()),this.pmremGeneratorResults.has(e)||this.pmremGeneratorResults.set(e,this.pmremGenerator.fromEquirectangular(e).texture);const t=this.pmremGeneratorResults.get(e);this.renderingView.scene.environment=t,this.renderingView.scene.environmentIntensity=a.intensity??1}):this.renderingView.scene.environment=null}resetWorldEnv(){this.renderingView.aoPass.enabled=!1,this.renderingView.aoPass.blendIntensity=1,this.renderingView.aoPass.output=0,this.renderingView.renderer.toneMapping=0,this.renderingView.renderer.toneMappingExposure=1}async updateSky(e){if(null==e?.sky?.materialId)return void(this.sky.material=$e);const t=await this.assetsService.getAsset(e.sky.materialId),a=await materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1);this.applySkySettings(a),null!=this.sky?this.sky.material=a:console.warn("No sky has been created")}applySkySettings(e){e.side=r.BackSide,(e instanceof g||e instanceof r.MeshBasicMaterial||e instanceof r.ShaderMaterial)&&(e.fog=!1),e.depthTest=!1}async createComponent(e,t,a,s){const r=new rt[a.path+"/"+a.className],i=t.id+s;r.id=i,r.object=e;for(const e of a.params)null!=e.value&&(r[e.name]=e.value);return this.components.push(r),i}async createFromActor(e,t){const a=this.actorTypes.find(t=>t.name===e.actor?.type)?.type??ie[e.actor?.type];if(null==a)return{object:null,actor:null};this.inEditor&&this.editorActorParamSnapshot.set(e.id,JSON.stringify(e.actor));const s=await this.actorProvider.create(a,(new S).fromArray(e.position),(new o).fromArray(e.rotation),!0);return this.materializedActors.set(this.getNestedActorId(e.id,t),s),{object:s?.object,actor:s}}getNestedActorId(e,t){return null!=t?t.sceneObjectChain.join("/")+"/"+e:e}async createFromVfx(e,t){const a=await this.assetsService.getAsset(e.assetId);null==a&&console.error("Could not find asset",e);const s=await this.actorProvider.create(ae,(new S).fromArray(e.position),(new o).fromArray(e.rotation),!1);try{await s.fromAsset(a)}catch(e){return console.error("Failed to create VFX asset",e),null}return s.play(),this.materializedActors.set(this.getNestedActorId(e.id,t),s),null!=s&&(s.object.userData.actor=s),s?.object}async createFromShape(e){const t=this.inEditor&&e.hidden;let a;if("landscape"==e.shape)a=this.createLandscape(e),a.traverse(e=>{e instanceof d&&this._originalMaterials.set(e.id,e.material)});else{let s=new g({name:"Default",color:new n("#aaaaaa"),visible:this.inEditor||!e.hidden,wireframe:!!t});const r=await this.createMeshByShape(e.shape,s,e.shapeParams);r.castShadow=e.castShadow??!0,r.receiveShadow=e.castShadow??!1,e.collisionDetection||(r.collisionShape=null),r.physics=e.physics,a=r,this._originalMaterials.set(a.id,r.material),a.traverse(e=>{})}return t||(await Promise.all((e.materialAssignments??[]).filter(e=>null!=e.materialId).map(e=>this.applyMaterial(a,e))),this.applyVertexMaterials(e,a)),a}createLandscape(e){const t=e.landscape?.options;if(null==t)return console.error(`No landscape options exist on scene object ${e.id} ${e.name}`),new h;const a=Ee(e.landscape.options);this.applyHeightMaps(a,e.landscape.heightMaps,!0);const s=new Ce(e,this.renderingView,a,this.assetManagerService,this.assetsService,this.shaders,t=>{(e.materialAssignments??[]).filter(e=>null!=e.materialId).forEach(e=>this.applyMaterial(t,e))});return this.landscapeManagers.push(s),s.refreshGeometry(),a}applyHeightMaps(e,t,a=!1){const s=new Te(e.sections);for(const e of t??[]){const t=s.find(e.x,e.y);if(!t)return;const a=t.geometry.getAttribute("position");for(const t of e.points)a.setY(t.i,t.y);a.needsUpdate=!0}const r=e.sections;r.forEach(e=>{e.geometry.computeBoundsTree(),e.geometry.computeVertexNormals()}),this.inEditor&&!a||setTimeout(()=>Ve(r),50)}async createMeshByShape(e,t,a={}){if("landscape"!==e&&_e.includes(e)){const s=await prepareShapeParameters(a??{}),r=e+JSON.stringify(a);if(!this.geometryCache.has(r)){const t=ze[e].geometry(s);t.computeTangents(),this.geometryCache.set(r,t)}this.collisionShapeCache.has(r)||this.collisionShapeCache.set(r,ze[e].collision(s));return new De(this.geometryCache.get(r),t,this.collisionShapeCache.get(r))}if(this.inEditor)throw new Error(`Unsupported shape '${e}'`);console.warn(`Failed to create shape. Unsupported shape '${e}'. This might be because the hology/core library is not compatible with the editor version.`)}async createFromAsset(e){const t=await this.assetsService.getAsset(e.assetId);if(null==t)return void console.warn(`Can not find asset with id ${e.assetId} and name ${e.name}`);let{scene:a}=await this.assetManagerService.getMesh(t,{mergeGeomtries:!0});try{await Promise.all(wt(e.materialAssignments,t.materialAssignments).map(e=>this.applyMaterial(a,e)))}catch(t){console.error("Failed to apply material"+t,e)}const s=e.receiveShadow??!!t.receiveShadow??!0,r=e.castShadow??!!t.castShadow??!1;return a.receiveShadow=s,lt(a,r,s),e.collisionDetection||(a.collisionShapes=[]),null!=e.physics&&!0!==this.inEditor&&(a.physics=e.physics),this.applyVertexMaterials(e,a),a.traverse(e=>{e instanceof d&&"computeBoundsTree"in e.geometry&&null==e.geometry.boundsTree&&e.geometry.computeBoundsTree()}),a}async createFromPrefab(e,t){const a=await this.assetsService.getAsset(e.assetId);if(null==a)return void console.warn(`Can not find asset with id ${e.assetId} and name ${e.name}`);null==t&&(t={sceneObjectChain:[]}),t.sceneObjectChain.push(e.id);const{object:s}=await this.createFromPrefabAsset(a,t);return t.sceneObjectChain.pop(),s}async createFromPrefabAsset(e,t){const a=new h;await Promise.all(e.prefab.objects.filter(e=>"global_fog"!==e.type&&"world_env"!==e.type).map(e=>this.materialize(e,a,!0,structuredClone(t))));const s=t.sceneObjectChain.join("/"),r=Array.from(this.materializedActors.entries()).filter(([e,a])=>e.startsWith(s)&&e.split("/").length-1===t.sceneObjectChain.length).map(([,e])=>e);r.forEach(e=>{a.add(e.object)}),this.initActorsPostInit(r,structuredClone(t));const i=Array.from(this.materializedActors.entries()).filter(([e,t])=>e.startsWith(s)).map(([,e])=>e);return{object:a,actors:i}}async createParticleSystem(e){const t=await this.assetsService.getAsset(e.assetId),a=new y;return await j.fromJSONAsync(t.particleSystem,r).then(e=>{const t=new I(a,r);e.addRenderer(t),this.renderingView.onLoop(t=>e.update())}),a}async createLight(e){if("point"===e.light.type){const t=new w(e.light.point.color,e.light.point.intensity,e.light.point.distance,e.light.point.decay);if(t.castShadow=e.light.point.castShadow??!0,this.inEditor){const e=(new r.TextureLoader).load("assets/light-bulb-icon.webp"),a=new r.SpriteMaterial({map:e,alphaTest:.5}),s=new Qe(a);s.scale.multiplyScalar(.6),t.add(s)}return t}if("spot"===e.light.type){const t=new r.SpotLight(e.light.spot.color,e.light.spot.intensity,e.light.spot.distance,e.light.spot.angle,e.light.spot.penumbra,e.light.spot.decay);if(t.castShadow=e.light.spot.castShadow??!0,t.target=new y,t.target.position.set(0,-1,0),t.add(t.target),this.inEditor){const e=(new r.TextureLoader).load("assets/light-bulb-icon.webp"),a=new r.SpriteMaterial({map:e,alphaTest:.5}),s=new Qe(a);s.scale.multiplyScalar(.6),t.add(s),t.add(new r.SpotLightHelper(t))}return t}return"directional"===e.light.type?(this.applyDirectionalLight(e.light.directional,e),new h):"ambient"===e.light.type?(this.applyDirectionalAmbientLight(null,e.light.ambient,e),new h):void 0}applyDirectionalAmbientLight(e,t,a){const s=this.scene.children.find(e=>e.name===We);null!=s?(s.intensity=t.intensity,s.color.set(t.color),s.groundColor.set(t.color),s.userData.src=a,s.userData.volumetricIntensity=t.volumetricIntensity):console.warn("Couldn't find ambient light")}applyDirectionalLight(e,t){for(const a of this.renderingView.csm.lights)a.intensity=e.intensity,a.color.set(e.color),a.castShadow=e.castShadow,a.userData.src=t,a.userData.volumetricIntensity=e.volumetricIntensity;this.renderingView.csm.lightDirection.fromArray(e.direction).normalize()}dispose(){this.updateSubscription.unsubscribe(),this.createAssetSubscription.unsubscribe(),this.materializedActors.forEach(e=>e.disposed.next(!0)),this.materializedActors.clear()}};ot=e([te(),t("design:paramtypes",[v,Object,Object,je,ce,Array,Array,Object])],ot);export{ot as SceneMaterializer};function lt(e,t,a){e.castShadow=t,e.receiveShadow=a,e.traverse(e=>{e.castShadow=t,e.receiveShadow=a})}const ct=new Map,ht=new Map,pt=new u({color:16711935}),mt=new Map;export async function materialFromAsset(e,t,a,s,r,i=!0){const n=JSON.stringify(e.material);return i&&ct.has(n)?ct.get(n):i&&ht.has(n)?await ht.get(n):ht.set(n,_materialFromAsset(n,e,t,a,s,r,i)).get(n)}export async function _materialFromAsset(e,t,a,s,i,o,l=!0){const c={opacity:t.material.params.opacity,map:null,emissive:t.material.params.emissive??null,metalness:t.material.params.metalness??0,flatShading:t.material.params.flatShading??!1,color:new n(t.material.params.color),transparent:null!=t.material.params.opacity&&t.material.params.opacity<1},h={};if(null!=t.material.params.map){const e=t.material.params.map,a=await s.getAsset(e);null!=a&&(c.map=await i.getTexture(a))}let p;switch(t.material.type){case"phong":p=new f({...c,...h});break;case"water":p=Fe(c,a);break;case"grassFoliage":p=Oe({color:c.color,map:c.map},a);break;case"grass":p=ke({...c,colorTwo:new n(t.material.params.colorTwo),colorThree:new n(t.material.params.colorThree)},a);break;case"standard":case"unlit":case"toon":case"layered":case"lambert":case"shader":case"landscape":case"landscape-composite":case"decal-unlit":case"decal-standard":const e={standard:it?pe:ue,lambert:pe,unlit:fe,toon:et,layered:Ye,landscape:de,"landscape-composite":me,"decal-unlit":Ue,"decal-standard":Ge}[t.material.type]??o.find(e=>e.name==t.material.shader)?.type;if(e){try{let r=new e;const n=await prepareClassParameters(t.material?.shaderParams??{},e,s,i,null,a,o);Object.assign(r,n),p=r.build()}catch(e){console.log("Shader runtime error: "+e),mt.has(t.material.shader)||mt.set(t.material.shader,pt.clone()),p=mt.get(t.material.shader)}p.userData.customShaderName=t.material.shader}else console.warn("Missing shader implementation with name "+t.material.shader),p=pt;break;default:throw new Error("Unsupported material type"+t.material.type)}return a?.csm.setupMaterial(p),null!=a&&ct.set(e,p),p.side=t.material.side??p.side??r.FrontSide,p.transparent=(t.material.transparent??c.transparent??!1)||p.transparent,p.alphaTest=t.material.alphaTest??p.alphaTest??0,null!=t.material.blending&&(p.blending=oe[t.material.blending]??r.NormalBlending),t.material.bloom&&(p.userData.hasBloom=!0),t.material.reflective&&(p.userData.reflective=!0),!0===t.material.outlines&&(p.userData.outlineParameters={},null!=t.material.outlineParams&&(null!=t.material.outlineParams.color&&(p.userData.outlineParameters.color=new n(t.material.outlineParams.color).toArray()),null!=t.material.outlineParams.thickness&&(p.userData.outlineParameters.thickness=t.material.outlineParams.thickness))),p.userData.assetId=t.id,ht.delete(e),p}export async function prepareClassParameters(e,t,a,s,r,i,n,o){const l={};for(const[t,c]of Object.entries(e)){const e=await dt(t,c,a,s,r,i,n,o);null!=e&&(l[t]=e)}return l}export async function prepareShapeParameters(e){const t={};for(const[a,s]of Object.entries(e)){const e=await dt(a,s,null,null,null);null!=e&&(t[a]=e)}return t}async function dt(e,t,a,s,r,i,l,c,h=t.value,p=t.type){if(null==t||null==h||""===h)return null;switch(p){case Ne.Array:if(Array.isArray(h)&&"element"in t)return await Promise.all(h.map(n=>dt(e,t,a,s,r,i,l,c,n,t.element)));break;case Ne.Number:case Ne.FloatNode:let p="string"==typeof h?parseFloat(h):h;return t.type===Ne.FloatNode?B(p):p;case Ne.Texture:let m=await s.getTexture(await a.getAsset(h));return"envmap"===e.toLowerCase()&&null!=i&&(m=i.getEnvTexture(m)),m;case Ne.Sampler2DNode:return G(await s.getTexture(await a.getAsset(h)));case Ne.Boolean:return h;case Ne.BooleanNode:return T(h);case Ne.Vector2:case Ne.Vec2Node:if("object"==typeof h){const e=h instanceof Array?(new A).fromArray(h):new A(h.x,h.y);return t.type===Ne.Vec2Node?X(e):e}return null;case Ne.Vector3:case Ne.Vec3Node:if("object"==typeof h){const e=h instanceof Array?(new S).fromArray(h):new S(h.x,h.y,h.z);return t.type===Ne.Vec3Node?Z(e):e}return null;case Ne.Color:case Ne.RgbNode:const d=new n(h);return t.type===Ne.RgbNode?_(d):d;case Ne.String:return h;case Ne.BaseActor:const u=h;return null==r&&console.warn("Class parameters can not be prepared as actors are not passed in"),r?.get(u);case Ne.Euler:const f=h;return(new o).fromArray(f);case Ne.Object3D:return(await s.getMesh(await a.getAsset(h))).scene;case Ne.Material:return await materialFromAsset(await a.getAsset(h),i,a,s,l);case Ne.AudioBuffer:return await s.getAudio(await a.getAsset(h));case Ne.VisualEffect:const g=await a.getAsset(h);if(null==c){console.error("Can not create instance of visual effect because missing actor provider");break}if("vfx"in g)return new se(c,g);console.error("Using a non-vfx asset for visual effect parameter");break;case Ne.Curve:return Re.decode(h);case Ne.ColorLayer:case Ne.MaskLayer:if(Ze(h)){const e=await He.decode(h,async e=>await s.getTexture(await a.getAsset(e))),t=await prepareClassParameters(h.params,null,a,s);return Object.assign(e,t),e}return console.warn("Expecting color layer but got",h),null}return null}function ut(e){e.updateWorldMatrix(!0,!0),e.updateMatrix(),e.traverse(e=>{e.matrixAutoUpdate=!1,e.matrixWorldNeedsUpdate=!1});const t=e.updateMatrixWorld;e.updateMatrixWorld=function(){t.apply(e),e.updateMatrixWorld=function(){}}}function ft(e){return"linear"===e.type?new l(new n(e.color),e.near??100,e.far??1e3):"density"===e.type?new c(e.color,e.density):void console.warn("Invalid fog type",e)}const gt=new g({color:4229780});async function yt(e,t,a,s){null==s&&(s=(new m).identity()),await t(e,a,s);const i=s.clone().multiply(function(e,t){if(null==e.position||null==e.rotation||null==e.scale)return t.identity();return t.compose((new S).fromArray(e.position),(new M).setFromEuler((new o).fromArray(e.rotation)),(new S).fromArray(e.scale))}(e,new r.Matrix4));return Promise.all((e.children??[]).map(a=>yt(a,t,e,i)))}export function toSerializedParamType(e){const t=e.constructor.prototype;return t instanceof Number||e===Number?Ne.Number:t instanceof F||"function"==typeof e.prototype.isFloat?Ne.FloatNode:t instanceof b||e===b||e.isTexture?Ne.Texture:t instanceof he||e===U?Ne.Sampler2DNode:t instanceof Boolean||e===Boolean?Ne.Boolean:t instanceof O?Ne.BooleanNode:t instanceof n||e==n?Ne.Color:t instanceof L||"function"==typeof e.prototype.isRgb?Ne.RgbNode:t instanceof A||e==A?Ne.Vector2:t instanceof Y||"function"==typeof e.prototype.isVec2?Ne.Vec2Node:t instanceof S||e==S?Ne.Vector3:t instanceof K||"function"==typeof e.prototype.isVec3?Ne.Vec3Node:t instanceof String||e===String?Ne.String:t instanceof re||e==re||e.prototype instanceof re||e.prototype==re?Ne.BaseActor:t instanceof o||e==o?Ne.Euler:t instanceof y||e==y?Ne.Object3D:t instanceof p||e==p?Ne.Material:t instanceof AudioBuffer||e==AudioBuffer?Ne.AudioBuffer:t instanceof se||e==se?Ne.VisualEffect:t instanceof Re||e==Re?Ne.Curve:t instanceof He||e==He?Ne.ColorLayer:t instanceof Xe||e==Xe?Ne.MaskLayer:void console.warn("Failed to map parameter type to serialized version",{type:e})}export function prepareCustomParams(e,t,a={}){return Object.fromEntries(e.map(e=>[e.name,{type:e.options.array?Ne.Array:toSerializedParamType(e.type),...e.options.array?{element:toSerializedParamType(e.type)}:{},value:t[e.name]?.value??(!0!==e.options.array?a[e.name]??customParameterDefaultValueByType.get(toSerializedParamType(e.type)):[])}]))}export function prepareCustomParamsFromType(e,t,a=null){const s=ge(e);if(0===s.length)return{};let r;null!=a?le(a,()=>{r=a.get(e)}):r=new e;const i={};for(const e of s){const t=r[e.name];if(null!=t&&!0!==e.options.array){const a=serializeCustomParameter(e.type,t);null!=a&&(i[e.name]=a)}}return prepareCustomParams(s,t,i)}export function serializeCustomParameter(e,t){function a(){console.error("Failed to serialize value",{type:e,value:t})}switch(e){case Number:case Boolean:return t;case A:return t instanceof A?t.toArray():void a();case S:return t instanceof S?t.toArray():void a();case x:return t instanceof x?t.toArray():void a();case n:return t instanceof n?"#"+t.getHexString():"string"==typeof t?t:"number"==typeof t?"#"+new n(t).getHexString():void a();case String:return t;case o:return t instanceof o?t.toArray():void a()}}function wt(e,t){return function(e,t,a){const s=[],r=new Set;for(const i of[...e??[],...t??[]]){const e=a(i);r.has(e)||(r.add(e),s.push(i))}return s}((e??[]).filter(e=>Mt(e.materialId)),(t??[]).filter(e=>Mt(e.materialId)),e=>e.color+e.name)}function Mt(e){return"null"!=e&&null!=e}export const customParameterDefaultValueByType=new Map([[Ne.RgbNode,"#000000"],[Ne.Color,"#000000"],[Ne.Vector4,[0,0,0,0]],[Ne.Vec4Node,[0,0,0,0]],[Ne.Vector3,[0,0,0]],[Ne.Vec3Node,[0,0,0]],[Ne.Vector2,[0,0]],[Ne.Vec2Node,[0,0]],[Ne.Euler,[0,0,0,"XYZ"]],[Ne.Array,[]],[Ne.ColorLayer,Je],[Ne.MaskLayer,qe]]);export function applyMaterial(e,t,a,s){const i=[];return e.traverse(async e=>{if(e instanceof d||e.isMesh||e instanceof r.SkinnedMesh||e.isSkinnedMesh)for(const t of Me(e.material))t.hasOwnProperty("color")&&i.push(e)}),Promise.all(i.map(async e=>{if(e.material instanceof Array)for(let r=0;r<e.material.length;r++){const i=e.material[r];if(null==i.color||!(i.color instanceof n))continue;const o="#"+i.color.getHexString(),l=i.name;if(o===t.color&&(i.name===t.name||null==t.name)||e.userData["originalColor_"+r]===t.color&&e.userData["originalMaterialName_"+r]===t.name){const i=await a(t.materialId),n=e.material[r];null!=i&&n.id!=i.id&&(e.material[r]=i,e.userData["originalColor_"+r]=e.userData["originalColor_"+r]??o,e.userData["originalMaterialName_"+r]=e.userData["originalMaterialName_"+r]??l,null!=s&&s.set(e.id+"#"+r,n))}}else if("color"in e.material){const r="#"+e.material.color.getHexString(),i=e.material.name;if(r===t.color&&(e.material.name===t.name||null==t.name)||e.userData.originalColor===t.color&&e.userData.originalName===t.name){const n=await a(t.materialId),o=e.material;null!=n&&(e.material=n,e.userData.originalColor=e.userData.originalColor??r,e.userData.originalMaterialName=e.userData.originalMaterialName??i,null!=s&&(s.has(e.id)||s.set(e.id,o)))}}}))}function vt(e,t){if(e instanceof r.ShaderMaterial&&t instanceof r.ShaderMaterial){return e.fragmentShader+e.vertexShader==t.fragmentShader+t.vertexShader&&function(e,t){if(e instanceof r.ShaderMaterial&&t instanceof r.ShaderMaterial){for(const a in e.uniforms){if(null==t.uniforms[a])return!1;if(t.uniforms[a].value!==e.uniforms[a].value)return!1}return!0}return!1}(e,t)}return!1}function bt(e){if(null!=e){for(let t=0;t<e.array.length;t++)e.setX(t,0);e.needsUpdate=!0}}const At=new WeakMap;function St(e){let t=At.get(e);return null==t&&(t=function(e){const t=Ae(e);if(null==t)return"";return Object.keys(t.geometry.attributes).sort().join(",")}(e),At.set(e,t)),t}const xt=new WeakMap;function jt(e){let t=xt.get(e);return null==t&&(t=function(e){let t=e.type;e instanceof r.MeshToonMaterial&&(t+=e.id);(e instanceof r.MeshBasicMaterial||e instanceof r.MeshLambertMaterial||e instanceof g||e instanceof f)&&(null!=e.map&&(t+="c"+e.map?.id),null!=e.aoMap&&(t+="o"+e.aoMap?.id),null!=e.lightMap&&(t+="l"+e.lightMap?.id),null!=e.envMap&&(t+="v"+e.envMap?.id),null!=e.alphaMap&&(t+="a"+e.alphaMap?.id));e instanceof g&&(null!=e.normalMap&&(t+="n"+e.normalMap?.id),null!=e.roughnessMap&&(t+="r"+e.roughnessMap?.id),null!=e.metalnessMap&&(t+="m"+e.metalnessMap?.id),null!=e.emissiveMap&&(t+="e"+e.emissiveMap?.id));(e instanceof u||e instanceof f)&&null!=e.specularMap&&(t+="s"+e.specularMap?.id);e instanceof r.MeshToonMaterial&&(null!=e.map&&(t+="c"+e.map?.id),null!=e.aoMap&&(t+="o"+e.aoMap?.id),null!=e.lightMap&&(t+="l"+e.lightMap?.id),null!=e.alphaMap&&(t+="a"+e.alphaMap?.id));e instanceof at&&null!=e.heightMap&&(t+="h"+e.heightMap?.id);if(e instanceof r.ShaderMaterial){t+=e.vertexShader,t+=e.fragmentShader;for(const a in e.uniforms){const s=e.uniforms[a];s&&s.value&&s.value.isTexture&&null!=s.value.id&&(t+="t:"+a+":"+s.value.id)}}null!=e.userData.outlineParameters&&(t+=e.userData.outlineParameters.color,t+=e.userData.outlineParameters.thickness);return t+=e.side,t+=e.transparent?"t":"",t+=e.depthWrite?"dw":"",t+=e.depthTest?"dt":"",t+=e.alphaTest,t}(e),xt.set(e,t)),t}function It(e,t){if(null==e)return null;if(!(e instanceof t))throw new Error(`Value is not an instance of ${t.name}`);return e}const Pt=new m;/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Color, Texture, Vector2 } from 'three';
|
|
2
|
+
import { Vec3Node } from 'three-shader-graph';
|
|
2
3
|
import { DecalNodeShader } from '../decal-shader.js';
|
|
3
4
|
export declare class DecalStandardShader extends DecalNodeShader {
|
|
4
5
|
color: Color;
|
|
@@ -18,6 +19,7 @@ export declare class DecalStandardShader extends DecalNodeShader {
|
|
|
18
19
|
normalScale?: Vector2;
|
|
19
20
|
output(): {
|
|
20
21
|
color: import("three-shader-graph").RgbaNode;
|
|
22
|
+
normal: Vec3Node;
|
|
21
23
|
};
|
|
22
24
|
build(): import("three").Material;
|
|
23
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decal-standard-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/decal-standard-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"decal-standard-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/decal-standard-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAA4L,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAGvO,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,qBAAa,mBAAoB,SAAQ,eAAe;IACzC,KAAK,EAAE,KAAK,CAAwB;IACtB,OAAO,EAAE,MAAM,CAAI;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEL,SAAS,CAAC,EAAE,MAAM,CAAK;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IAET,SAAS,CAAC,EAAE,MAAM,CAAK;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,EAAE,KAAK,CAAC;IACF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,WAAW,CAAC,EAAE,OAAO,CAAmB;IAIrD,MAAM;;;;IAgEN,KAAK;CASN"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{Color as a,Texture as s,Vector2 as r}from"three";import{colorToNormal as o,float as i,rgba as p,standardMaterial as l,textureSampler2d as n,uniforms as d,normalize as h,varying as m,rgb as c,AttributeVec3Node as y,ifDefApply as u,Vec3ExpressionNode as S}from"three-shader-graph";import{decalAlpha as g,decalNormal as v,decalUV as M}from"../../shader-nodes/decal.js";import{depthWorldPosition as D}from"../../shader-nodes/depth.js";import{DecalNodeShader as b}from"../decal-shader.js";import{Parameter as I}from"../parameter.js";export class DecalStandardShader extends b{constructor(){super(...arguments),this.color=new a("#FFFFFF"),this.opacity=1,this.roughness=1,this.metalness=0,this.normalScale=new r(1,1)}output(){const e=M,t=m(new y("particleData"));let a=u("IS_PARTICLE",i(this.opacity),()=>t.x);null!=this.alphaMap&&(a=a.multiply(n(this.alphaMap).sample(e).r)),a=a.multiply(g);const s=m(u("IS_PARTICLE",c(this.color),()=>new S("instanceColor")));let r=u("IS_PARTICLE",c(this.color),()=>s.rgb),b=p(r,a);null!=this.colorMap&&(b=b.multiply(n(this.colorMap).sample(e)));let I=p(this.emissive,a);null!=this.emissiveMap&&(I=I.multiply(n(this.emissiveMap).sample(e)));let f=i(this.roughness);null!=this.roughnessMap&&(f=f.multiply(n(this.roughnessMap).sample(e).g));let F=i(this.metalness);null!=this.metalnessMap&&(F=F.multiply(n(this.metalnessMap).sample(e).b));let w=h(m(d.normalMatrix).multiplyVec(v));null!=this.normalMap&&(w=o(n(this.normalMap).sample(e),this.normalScale?.x??1,w,D,e));let x=null;return null!=this.aoMap&&(x=n(this.aoMap).sample(e).r),{color:l({color:b,emissive:I,emissiveIntensity:i(this.emissiveIntensity??1),roughness:f,metalness:F,normal:w,ambientOcclusion:x,ambientOcclusionIntensity:i(this.aoMapIntensity??1),worldPosition:D})}}build(){const e=super.build();return e.depthTest=!0,e.depthWrite=!1,e.userData.isDecal=!0,e}}e([I(),t("design:type",a)],DecalStandardShader.prototype,"color",void 0),e([I({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"opacity",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"colorMap",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"alphaMap",void 0),e([I({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"roughness",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"roughnessMap",void 0),e([I({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"metalness",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"metalnessMap",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"aoMap",void 0),e([I(),t("design:type",Number)],DecalStandardShader.prototype,"aoMapIntensity",void 0),e([I(),t("design:type",a)],DecalStandardShader.prototype,"emissive",void 0),e([I({range:[0,10]}),t("design:type",Number)],DecalStandardShader.prototype,"emissiveIntensity",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"emissiveMap",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"normalMap",void 0),e([I(),t("design:type",r)],DecalStandardShader.prototype,"normalScale",void 0);/*
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{Color as a,Texture as s,Vector2 as r}from"three";import{colorToNormal as o,float as i,rgba as p,standardMaterial as l,textureSampler2d as n,uniforms as d,normalize as h,varying as m,rgb as c,AttributeVec3Node as y,ifDefApply as u,Vec3ExpressionNode as S}from"three-shader-graph";import{decalAlpha as g,decalNormal as v,decalUV as M}from"../../shader-nodes/decal.js";import{depthWorldPosition as D}from"../../shader-nodes/depth.js";import{DecalNodeShader as b}from"../decal-shader.js";import{Parameter as I}from"../parameter.js";export class DecalStandardShader extends b{constructor(){super(...arguments),this.color=new a("#FFFFFF"),this.opacity=1,this.roughness=1,this.metalness=0,this.normalScale=new r(1,1)}output(){const e=M,t=m(new y("particleData"));let a=u("IS_PARTICLE",i(this.opacity),()=>t.x);null!=this.alphaMap&&(a=a.multiply(n(this.alphaMap).sample(e).r)),a=a.multiply(g);const s=m(u("IS_PARTICLE",c(this.color),()=>new S("instanceColor")));let r=u("IS_PARTICLE",c(this.color),()=>s.rgb),b=p(r,a);null!=this.colorMap&&(b=b.multiply(n(this.colorMap).sample(e)));let I=p(this.emissive,a);null!=this.emissiveMap&&(I=I.multiply(n(this.emissiveMap).sample(e)));let f=i(this.roughness);null!=this.roughnessMap&&(f=f.multiply(n(this.roughnessMap).sample(e).g));let F=i(this.metalness);null!=this.metalnessMap&&(F=F.multiply(n(this.metalnessMap).sample(e).b));let w=h(m(d.normalMatrix).multiplyVec(v));null!=this.normalMap&&(w=o(n(this.normalMap).sample(e),this.normalScale?.x??1,w,D,e));let x=null;return null!=this.aoMap&&(x=n(this.aoMap).sample(e).r),{color:l({color:b,emissive:I,emissiveIntensity:i(this.emissiveIntensity??1),roughness:f,metalness:F,normal:w,ambientOcclusion:x,ambientOcclusionIntensity:i(this.aoMapIntensity??1),worldPosition:D}),normal:w}}build(){const e=super.build();return e.depthTest=!0,e.depthWrite=!1,e.userData.isDecal=!0,e}}e([I(),t("design:type",a)],DecalStandardShader.prototype,"color",void 0),e([I({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"opacity",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"colorMap",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"alphaMap",void 0),e([I({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"roughness",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"roughnessMap",void 0),e([I({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"metalness",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"metalnessMap",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"aoMap",void 0),e([I(),t("design:type",Number)],DecalStandardShader.prototype,"aoMapIntensity",void 0),e([I(),t("design:type",a)],DecalStandardShader.prototype,"emissive",void 0),e([I({range:[0,10]}),t("design:type",Number)],DecalStandardShader.prototype,"emissiveIntensity",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"emissiveMap",void 0),e([I(),t("design:type",s)],DecalStandardShader.prototype,"normalMap",void 0),e([I(),t("design:type",r)],DecalStandardShader.prototype,"normalScale",void 0);/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, Texture } from 'three';
|
|
1
|
+
import { Color, Material, Texture } from 'three';
|
|
2
2
|
import { DecalNodeShader } from '../decal-shader.js';
|
|
3
3
|
export declare class DecalUnlitShader extends DecalNodeShader {
|
|
4
4
|
color: Color;
|
|
@@ -9,5 +9,6 @@ export declare class DecalUnlitShader extends DecalNodeShader {
|
|
|
9
9
|
output(): {
|
|
10
10
|
color: import("three-shader-graph").RgbaNode;
|
|
11
11
|
};
|
|
12
|
+
build(): Material;
|
|
12
13
|
}
|
|
13
14
|
//# sourceMappingURL=decal-unlit-shader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decal-unlit-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/decal-unlit-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,
|
|
1
|
+
{"version":3,"file":"decal-unlit-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/decal-unlit-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,EAAE,QAAQ,EAA2D,OAAO,EAAqB,MAAM,OAAO,CAAC;AAI5K,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD,qBAAa,gBAAiB,SAAQ,eAAe;IACtC,KAAK,EAAE,KAAK,CAAwB;IACtB,OAAO,EAAE,MAAM,CAAI;IAClB,SAAS,EAAE,MAAM,CAAI;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEhC,MAAM;;;IA4BN,KAAK;CAUN"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t,__metadata as e}from"tslib";import{Color as
|
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{Color as r,Texture as o,BackSide as i}from"three";import{Parameter as a}from"../parameter.js";import{DecalNodeShader as l}from"../decal-shader.js";import{rgb as p,rgba as s,textureSampler2d as n,float as c,AttributeVec3Node as d,varying as h,ifDefApply as m,Vec3ExpressionNode as y}from"three-shader-graph";import{decalAlpha as u,decalUV as g}from"../../shader-nodes/decal.js";export class DecalUnlitShader extends l{constructor(){super(...arguments),this.color=new r("#FFFFFF"),this.opacity=1,this.intensity=1}output(){const t=g,e=h(new d("particleData"));let r=m("IS_PARTICLE",c(this.opacity),()=>e.x);null!=this.alphaMap&&(r=r.multiply(n(this.alphaMap).sample(t).r)),r=r.multiply(u);const o=h(m("IS_PARTICLE",p(this.color),()=>new y("instanceColor")));let i=m("IS_PARTICLE",p(this.color),()=>o.rgb),a=s(i,r);return null!=this.colorMap&&(a=a.multiply(n(this.colorMap).sample(t))),a=s(a.rgb.multiplyScalar(this.intensity),a.a),{color:a}}build(){const t=super.build();return t.depthTest=!0,t.depthWrite=!1,t.userData.isDecal=!0,t.side=i,t}}t([a(),e("design:type",r)],DecalUnlitShader.prototype,"color",void 0),t([a({range:[0,1]}),e("design:type",Number)],DecalUnlitShader.prototype,"opacity",void 0),t([a({range:[0,10]}),e("design:type",Number)],DecalUnlitShader.prototype,"intensity",void 0),t([a(),e("design:type",o)],DecalUnlitShader.prototype,"colorMap",void 0),t([a(),e("design:type",o)],DecalUnlitShader.prototype,"alphaMap",void 0);/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, Material, Texture } from 'three';
|
|
1
|
+
import { Color, Material, Texture, Vector2 } from 'three';
|
|
2
2
|
import { Shader } from '../shader.js';
|
|
3
3
|
export declare class LambertShader extends Shader {
|
|
4
4
|
color: Color;
|
|
@@ -12,6 +12,8 @@ export declare class LambertShader extends Shader {
|
|
|
12
12
|
lightMapIntensity?: number;
|
|
13
13
|
aoMap?: Texture;
|
|
14
14
|
aoMapIntensity?: number;
|
|
15
|
+
normalMap?: Texture;
|
|
16
|
+
normalScale?: Vector2;
|
|
15
17
|
specularMap?: Texture;
|
|
16
18
|
envMap?: Texture;
|
|
17
19
|
reflectivity?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambert-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/lambert-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAwC,OAAO,
|
|
1
|
+
{"version":3,"file":"lambert-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/lambert-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAwC,OAAO,EAAE,OAAO,EAAuB,MAAM,OAAO,CAAC;AACrH,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKtC,qBAAa,aAAc,SAAQ,MAAM;IAC1B,KAAK,EAAE,KAAK,CAAwB;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,CAAI;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,KAAK,CAAC;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACzC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,WAAW,CAAC,EAAE,OAAO,CAAoB;IACzC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,OAAO,CAAC;IAEH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGpD,KAAK,IAAI,QAAQ;CAuBlB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{Color as
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{Color as a,Texture as i,Vector2 as r,MeshLambertMaterial as p}from"three";import{Shader as o}from"../shader.js";import{Parameter as s}from"../parameter.js";import{removeObjectUndefined as n}from"../../utils/collections.js";export class LambertShader extends o{constructor(){super(...arguments),this.color=new a("#FFFFFF"),this.opacity=1,this.normalScale=new r(1,1)}build(){return new p(n({color:this.color,opacity:this.opacity,emissive:this.emissive,emissiveIntensity:this.emissiveIntensity,emissiveMap:this.emissiveMap,map:this.map,lightMap:this.lightMap,lightMapIntensity:this.lightMapIntensity,aoMap:this.aoMap,aoMapIntensity:this.aoMapIntensity,normalMap:this.normalMap,normalScale:this.normalScale,specularMap:this.specularMap,alphaMap:this.alphaMap,envMap:this.envMap,reflectivity:this.reflectivity,refractionRatio:this.refractionRatio}))}}e([s(),t("design:type",a)],LambertShader.prototype,"color",void 0),e([s({label:"Color Map"}),t("design:type",i)],LambertShader.prototype,"map",void 0),e([s({range:[0,1]}),t("design:type",Number)],LambertShader.prototype,"opacity",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"alphaMap",void 0),e([s(),t("design:type",a)],LambertShader.prototype,"emissive",void 0),e([s({range:[0,1]}),t("design:type",Number)],LambertShader.prototype,"emissiveIntensity",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"emissiveMap",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"lightMap",void 0),e([s(),t("design:type",Number)],LambertShader.prototype,"lightMapIntensity",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"aoMap",void 0),e([s(),t("design:type",Number)],LambertShader.prototype,"aoMapIntensity",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"normalMap",void 0),e([s(),t("design:type",r)],LambertShader.prototype,"normalScale",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"specularMap",void 0),e([s(),t("design:type",i)],LambertShader.prototype,"envMap",void 0),e([s({range:[0,1]}),t("design:type",Number)],LambertShader.prototype,"reflectivity",void 0),e([s({range:[0,1]}),t("design:type",Number)],LambertShader.prototype,"refractionRatio",void 0);/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"landscape-composite-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/landscape-composite-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,QAAQ,EAAoF,MAAM,OAAO,CAAC;AAE1H,OAAO,EAAE,YAAY,EAAoB,MAAM,8BAA8B,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"landscape-composite-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/landscape-composite-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,QAAQ,EAAoF,MAAM,OAAO,CAAC;AAE1H,OAAO,EAAE,YAAY,EAAoB,MAAM,8BAA8B,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAO5D,qBAAa,wBAAyB,SAAQ,UAAU;IACzB,MAAM,EAAE,QAAQ,EAAE,CAAK;IAEvC,OAAO,EAAE,MAAM,CAAI;IAE4E,UAAU,EAAE,YAAY,CAAoB;IAC3I,UAAU,EAAE,MAAM,CAAI;IACtB,WAAW,EAAE,MAAM,CAAK;IACxB,QAAQ,EAAE,MAAM,CAAK;IAErB,WAAW,EAAE,OAAO,CAAQ;IAC5B,aAAa,EAAE,QAAQ,CAAA;IACvB,UAAU,EAAE,MAAM,CAAK;IAEpC,MAAM,IAAI,gBAAgB;CA2I3B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{Material as s,MathUtils as a,MeshBasicMaterial as o,MeshLambertMaterial as l,MeshStandardMaterial as i}from"three";import{cos as n,float as r,mix as p,standardMaterial as m,step as h,varyingAttributes as u,SimplexNoiseNode as c,varying as d,uniforms as y,vec4 as g,attributes as M,smoothstep as
|
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import{Material as s,MathUtils as a,MeshBasicMaterial as o,MeshLambertMaterial as l,MeshStandardMaterial as i}from"three";import{cos as n,float as r,mix as p,standardMaterial as m,step as h,varyingAttributes as u,SimplexNoiseNode as c,varying as d,uniforms as y,vec4 as g,attributes as M,smoothstep as f,textureSampler2d as S,rgba as v,varyingTransformed as b,colorToNormal as C}from"three-shader-graph";import{LayerMixMode as L,mixColorsByLayer as A}from"../../shader-nodes/layers.js";import{Parameter as x}from"../parameter.js";import{NodeShader as N}from"../shader.js";import{ParallaxStandardMaterial as j}from"./standard-shader.js";import{parallaxOcclusionMapping as w}from"../../shader-nodes/pom.js";const z=d(y.modelMatrix.multiplyVec(g(M.position,1)).xz);export class LandscapeCompositeShader extends N{constructor(){super(...arguments),this.layers=[],this.uvScale=1,this.transition=L.soft,this.noiseScale=1,this.noiseAmount=.2,this.softness=.3,this.enableSlope=!1,this.slopeAngle=35}output(){const e=new Map,t=new B,s=u.uv.multiplyScalar(this.uvScale??1);function d(t,s){let a=s;if(t instanceof j&&null!=t.heightMap){let o=e.get(t);null==o&&(o=w(s,S(t.heightMap),r(t.heightScale??1)),e.set(t,o)),a=o}return a}const y=this.layers.map(e=>{if(e instanceof i||e instanceof l||e instanceof o){let t=v(e.color,1);return null!=e.map&&(t=t.multiply(S(e.map).sample(d(e,s)))),t}return v("white")}),g=this.layers.map(e=>(e instanceof i||e instanceof l)&&null!=e.normalMap?C(S(e.normalMap).sample(d(e,s)),e.normalScale?.x??1):b.normal),M=this.layers.map(e=>{let a=r(1);return e instanceof i&&(a=r(e.roughness??1),null!=e.roughnessMap&&(a=a.multiply(t.get(e.roughnessMap,d(e,s)).g))),a}),x=this.layers.map(e=>{let a=r(0);return e instanceof i&&(a=r(e.metalness??0),null!=e.metalnessMap&&(a=a.multiply(t.get(e.metalnessMap,d(e,s)).b))),a});let N,H,R,T;if(this.enableSlope&&null!=this.slopeMaterial&&this.slopeMaterial instanceof i){const e=d(this.slopeMaterial,s);N=v(this.slopeMaterial.color,1),null!=this.slopeMaterial.map&&(N=N.multiply(t.get(this.slopeMaterial.map,e))),H=b.normal,null!=this.slopeMaterial.normalMap&&(H=C(t.get(this.slopeMaterial.normalMap,e),this.slopeMaterial.normalScale?.x??1)),R=r(this.slopeMaterial.roughness??1),null!=this.slopeMaterial.roughnessMap&&(R=R.multiply(t.get(this.slopeMaterial.roughnessMap,e).g)),T=r(this.slopeMaterial.metalness??0),null!=this.slopeMaterial.roughnessMap&&(T=T.multiply(t.get(this.slopeMaterial.metalnessMap,e).b))}const V=(e,t)=>{const s=A({layerColors:e.slice(0,8),noiseScale:this.noiseScale,noiseAmount:this.noiseAmount,mode:this.transition,decay:this.softness}),o=r(this.noiseAmount).multiply(r(.1)),l=r(this.noiseScale),i=new c(z.multiplyScalar(l)).multiply(r(2)).subtract(r(1)).multiply(o),m=r(a.degToRad(this.slopeAngle)).add(i.multiply(r(.1)));let d=p(s,t,h(m,n(u.normal.y)));if(this.transition==L.soft){const e=m,a=r(this.softness).divide(r(2)),o=e.subtract(a),l=e.add(a);d=p(s,t,f(o,l,n(u.normal.y)))}return this.enableSlope&&null!=t?d:s},k=V(y,N),q=V(g,H),D=V(M,R),E=V(x,T);return{color:m({color:k,normal:q,roughness:D,metalness:E}),landscape:!0}}}e([x({type:s}),t("design:type",Array)],LandscapeCompositeShader.prototype,"layers",void 0),e([x(),t("design:type",Number)],LandscapeCompositeShader.prototype,"uvScale",void 0),e([x({options:[{value:L.hard,name:"Hard"},{value:L.soft,name:"Soft"}]}),t("design:type",Number)],LandscapeCompositeShader.prototype,"transition",void 0),e([x(),t("design:type",Number)],LandscapeCompositeShader.prototype,"noiseScale",void 0),e([x(),t("design:type",Number)],LandscapeCompositeShader.prototype,"noiseAmount",void 0),e([x(),t("design:type",Number)],LandscapeCompositeShader.prototype,"softness",void 0),e([x(),t("design:type",Boolean)],LandscapeCompositeShader.prototype,"enableSlope",void 0),e([x(),t("design:type",s)],LandscapeCompositeShader.prototype,"slopeMaterial",void 0),e([x(),t("design:type",Number)],LandscapeCompositeShader.prototype,"slopeAngle",void 0);class B{constructor(){this.cache=new Map}get(e,t){return this.cache.has(e)||this.cache.set(e,S(e).sample(t)),this.cache.get(e)}}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/standard-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,8BAA8B,EAAkB,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChI,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAOtC,qBAAa,cAAe,SAAQ,MAAM;IAE3B,KAAK,EAAE,KAAK,CAAwB;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,CAAI;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACL,SAAS,CAAC,EAAE,MAAM,CAAK;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IACT,SAAS,CAAC,EAAE,MAAM,CAAK;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,KAAK,CAAC;IACF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"standard-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/standard-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,8BAA8B,EAAkB,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChI,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAOtC,qBAAa,cAAe,SAAQ,MAAM;IAE3B,KAAK,EAAE,KAAK,CAAwB;IAChB,GAAG,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,CAAI;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACL,SAAS,CAAC,EAAE,MAAM,CAAK;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IACT,SAAS,CAAC,EAAE,MAAM,CAAK;IACrC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,KAAK,CAAC;IACF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,WAAW,CAAC,EAAE,OAAO,CAAoB;IAEzC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAG1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGvC,SAAS,CAAC,EAAE,OAAO,CAAiB;IACpC,WAAW,CAAC,EAAE,MAAM,CAAA;IAGjC,KAAK,IAAI,QAAQ;CAgDlB;AAGD,oBAAY,YAAY;IACtB,IAAI,IAAA;IACJ,MAAM,IAAA;IACN,GAAG,IAAA;CACJ;AAED,qBAAa,wBAAyB,SAAQ,oBAAoB;IACzD,SAAS,EAAE,OAAO,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;gBAEZ,MAAM,GAAE,OAAO,CAAC;QAC1B,SAAS,EAAE,OAAO,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,YAAY,CAAC;QAC3B,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAA;KAClB,GAAG,8BAA8B,CAAM;IAYxC,eAAe,CAAC,MAAM,KAAA;IAuLtB,KAAK,IAAI,IAAI;CAUd"}
|
|
@@ -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{removeObjectUndefined as p}from"../../utils/collections.js";const l=new r;export class StandardShader extends s{constructor(){super(...arguments),this.color=new t("#FFFFFF"),this.opacity=1,this.roughness=1,this.metalness=0,this.normalScale=new i(1,1),this.heightMap=l}build(){const e=null!=this.
|
|
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{removeObjectUndefined as p}from"../../utils/collections.js";const l=new r;export class StandardShader extends s{constructor(){super(...arguments),this.color=new t("#FFFFFF"),this.opacity=1,this.roughness=1,this.metalness=0,this.normalScale=new i(1,1),this.heightMap=l}build(){const e=(null!=this.map||null!=this.normalMap)&&null!=this.heightMap&&this.heightMap!=l&&0!==this.heightScale;return new(e?ParallaxStandardMaterial:n)(p({color:this.color,opacity:this.opacity,roughness:this.roughness,metalness:this.metalness,map:this.map,lightMap:this.lightMap,lightMapIntensity:this.lightMapIntensity,aoMap:this.aoMap,aoMapIntensity:this.aoMapIntensity,emissive:this.emissive,emissiveIntensity:this.emissiveIntensity,emissiveMap:this.emissiveMap,bumpMap:this.bumpMap,bumpScale:this.bumpScale,normalMap:this.normalMap,normalScale:this.normalScale,displacementMap:this.displacementMap,displacementScale:this.displacementScale,displacementBias:this.displacementBias,roughnessMap:this.roughnessMap,metalnessMap:this.metalnessMap,alphaMap:this.alphaMap,envMap:this.envMap,envMapIntensity:this.envMapIntensity,refractionRatio:this.refractionRatio,...e?{heightMap:this.heightMap,heightScale:this.heightScale}:{}}))}}e([o(),a("design:type",t)],StandardShader.prototype,"color",void 0),e([o({label:"Color Map"}),a("design:type",r)],StandardShader.prototype,"map",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"opacity",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"alphaMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"roughness",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"roughnessMap",void 0),e([o({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"metalness",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"metalnessMap",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"lightMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"lightMapIntensity",void 0),e([o(),a("design:type",r)],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",r)],StandardShader.prototype,"emissiveMap",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"bumpMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"bumpScale",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"normalMap",void 0),e([o(),a("design:type",i)],StandardShader.prototype,"normalScale",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"displacementMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"displacementScale",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"displacementBias",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({range:[0,1]}),a("design:type",Number)],StandardShader.prototype,"refractionRatio",void 0),e([o(),a("design:type",r)],StandardShader.prototype,"heightMap",void 0),e([o(),a("design:type",Number)],StandardShader.prototype,"heightScale",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 varying vec3 vViewDirTS;\n varying mat3 vTBN;\n "),e.vertexShader=e.vertexShader.replace("#include <begin_vertex>","\n #include <begin_vertex>\n vec3 N = normalize(normalMatrix * normal);\n vec3 T = normalize(normalMatrix * tangent.xyz);\n vec3 B = cross(N, T) * tangent.w;\n vTBN = mat3(T, B, N);\n\n vec3 viewDir = cameraPosition - (modelMatrix * vec4(transformed, 1.0)).xyz;\n vViewDirTS = normalize(vTBN * viewDir);\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 varying vec3 vViewDirTS;\n varying mat3 vTBN;\n\n vec2 parallaxOffset(vec2 uv, vec3 viewDirTS) {\n float h = texture(heightMap, uv).r;\n return uv - (viewDirTS.xy / viewDirTS.z) * (h * heightScale);\n }\n\n vec2 parallaxOcclusion2(vec2 uv, vec3 viewDirTS) {\n vec3 viewDir = normalize(vViewPosition);\n vec3 vv = -viewDir * vTBN;\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 // Probably should use actual normal but it might not matter\n vec3 nNormal = vec3(0.0, 0.0, 1.0);\n float nNumSamples = mix(float(maxLayers), float(minLayers), dot(viewDir, nNormal));\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 < 50; 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 vec2 uvPOM = vMapUv ;\n if (parallaxType == 1) {\n uvPOM = parallaxOffset(vMapUv , vViewDirTS);\n } else if (parallaxType == 2) {\n uvPOM = parallaxOcclusion2(vMapUv , vViewDirTS);\n }\n\n\n vec4 texelColor = texture2D(map, uvPOM);\n //texelColor = mapTexelToLinear(texelColor);\n diffuseColor *= texelColor;\n "),e.fragmentShader=e.fragmentShader.replace("#include <normal_fragment_maps>","\n #ifdef USE_NORMALMAP\n vec3 mapN = texture2D(normalMap, uvPOM).xyz * 2.0 - 1.0;\n mapN.xy *= normalScale;\n normal = normalize( tbn * 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}}/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
package/dist/shader/shader.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../src/shader/shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAgC,QAAQ,EAAE,WAAW,EAAkB,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACxJ,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,cAAc,gBAAgB,CAAA;AAE9B,8BAAsB,MAAM;IAC1B,QAAQ,CAAC,KAAK,IAAI,QAAQ;CAC3B;AAED,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;AAErC,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;AAEvC,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;CACd,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAA;AAE5C,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAE1C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,QAAQ,GAAC,QAAQ,GAAC,QAAQ,GAAC,SAAS,CAAC;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE,SAAS,CAAA;CACpB,CAAA;AAID,8BAAsB,UAAU;IAC9B,KAAK,IAAI,QAAQ;IAajB,QAAQ,CAAC,MAAM,IAAI,gBAAgB;CACpC"}
|
|
1
|
+
{"version":3,"file":"shader.d.ts","sourceRoot":"","sources":["../../src/shader/shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAgC,QAAQ,EAAE,WAAW,EAAkB,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACxJ,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,cAAc,gBAAgB,CAAA;AAE9B,8BAAsB,MAAM;IAC1B,QAAQ,CAAC,KAAK,IAAI,QAAQ;CAC3B;AAED,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;AAErC,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,CAAA;AAEvC,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;CACd,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,CAAA;AAE5C,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAE1C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,QAAQ,GAAC,QAAQ,GAAC,QAAQ,GAAC,SAAS,CAAC;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,QAAQ,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB,CAAA;AAID,8BAAsB,UAAU;IAC9B,KAAK,IAAI,QAAQ;IAajB,QAAQ,CAAC,MAAM,IAAI,gBAAgB;CACpC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FloatNode, Sampler2DNode } from "three-shader-graph";
|
|
2
|
+
import { Curve2 } from "../utils/curve";
|
|
3
|
+
export declare function sampleCurve(curve: Curve2, t: FloatNode): FloatNode;
|
|
4
|
+
export declare function curveSampler(curve: Curve2, resolution?: number): CurveSampler;
|
|
5
|
+
declare class CurveSampler {
|
|
6
|
+
private sampler;
|
|
7
|
+
constructor(sampler: Sampler2DNode);
|
|
8
|
+
sample(t: FloatNode): FloatNode;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=curve-sample.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curve-sample.d.ts","sourceRoot":"","sources":["../../src/shader-nodes/curve-sample.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,aAAa,EAA0B,MAAM,oBAAoB,CAAC;AACtF,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,aAEtD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW,gBAalE;AAED,cAAM,YAAY;IACJ,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,aAAa;IAC1C,MAAM,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS;CAGhC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{DataTexture as e,LinearFilter as r,RedFormat as t,UnsignedByteType as n}from"three";import{textureSampler2d as s,vec2 as o}from"three-shader-graph";export function sampleCurve(e,r){return curveSampler(e).sample(r)}export function curveSampler(o,m=64){const p=new Uint8Array(m);for(let e=0;e<m;e++){const r=e/m;p[e]=255*o.getY(r)}const l=new e(p,m,1);l.format=t,l.type=n,l.minFilter=l.magFilter=r,l.needsUpdate=!0;const c=s(l);return new a(c)}class a{constructor(e){this.sampler=e}sample(e){return this.sampler.sample(o(e,0)).r}}/*
|
|
2
|
+
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
|
+
* See the LICENSE.md file for details.
|
|
4
|
+
*/
|
|
@@ -5,6 +5,7 @@ export declare const depthUniformName = "hology_depth_map";
|
|
|
5
5
|
export declare const resolutionUniformName = "hology_resolution";
|
|
6
6
|
export declare const nearUniformName = "hology_camera_near";
|
|
7
7
|
export declare const farUniformName = "hology_camera_far";
|
|
8
|
+
export declare const sceneNormalUniformName = "hology_scene_normal_map";
|
|
8
9
|
export declare const depthSampler: import("three-shader-graph").UniformSampler2d;
|
|
9
10
|
export declare const fragmentLinearEyeDepth: FloatNode;
|
|
10
11
|
export declare const resolution: import("three-shader-graph").UniformVec2Node;
|
|
@@ -18,4 +19,6 @@ export declare const depthWorldPosition: import("three-shader-graph").Vec3Node;
|
|
|
18
19
|
* An approximated normal created by taking multiple samples using a depth texture
|
|
19
20
|
*/
|
|
20
21
|
export declare const depthNormal: import("three-shader-graph").Vec3Node;
|
|
22
|
+
export declare const sceneNormalSampler: import("three-shader-graph").UniformSampler2d;
|
|
23
|
+
export declare const sceneNormal: import("three-shader-graph").Vec3Node;
|
|
21
24
|
//# sourceMappingURL=depth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"depth.d.ts","sourceRoot":"","sources":["../../src/shader-nodes/depth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"depth.d.ts","sourceRoot":"","sources":["../../src/shader-nodes/depth.ts"],"names":[],"mappings":"AACA,OAAO,EAAW,aAAa,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAA0C,SAAS,EAA8I,QAAQ,EAAkB,MAAM,oBAAoB,CAAC;AAI7P,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,aAAa,WAGpE;AAID,eAAO,MAAM,gBAAgB,qBAAqB,CAAA;AAClD,eAAO,MAAM,qBAAqB,sBAAsB,CAAA;AACxD,eAAO,MAAM,eAAe,uBAAuB,CAAA;AACnD,eAAO,MAAM,cAAc,sBAAsB,CAAA;AACjD,eAAO,MAAM,sBAAsB,4BAA4B,CAAA;AAE/D,eAAO,MAAM,YAAY,+CAAkE,CAAA;AA6G3F,eAAO,MAAM,sBAAsB,WAAkB,CAAA;AAGrD,eAAO,MAAM,UAAU,8CAA4D,CAAA;AAEnF,eAAO,MAAM,QAAQ,UAA+D,CAAA;AAEpF,eAAO,MAAM,cAAc,WAA+B,CAAA;AAgB1D;;GAEG;AACH,eAAO,MAAM,kBAAkB,uCAAkC,CAAA;AASjE;;GAEG;AACH,eAAO,MAAM,WAAW,uCAAyF,CAAA;AAEjH,eAAO,MAAM,kBAAkB,+CAAgE,CAAA;AAC/F,eAAO,MAAM,WAAW,uCAA6D,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Vector2 as t}from"three";import{
|
|
1
|
+
import*as e from"three";import{Vector2 as t}from"three";import{cross as o,dot as r,float as n,FloatExpressionNode as s,FloatNode as c,inverse as a,normalize as i,texture2d as p,uniformFloat as l,uniforms as m,uniformSampler2d as h,uniformVec2 as u,unpackRGBToNormal as d,varying as x,vec2 as f,Vec2ExpressionNode as _,vec4 as U,Vec4Node as g}from"three-shader-graph";export function supportsDepthTextureExtension(e){return!0}export const depthUniformName="hology_depth_map";export const resolutionUniformName="hology_resolution";export const nearUniformName="hology_camera_near";export const farUniformName="hology_camera_far";export const sceneNormalUniformName="hology_scene_normal_map";export const depthSampler=h(depthUniformName,new e.DepthTexture(1,1));const y=l(nearUniformName,.5),k=l(farUniformName,500);class $ extends c{compile(e){const t=e.variable();var o=e.get(y),r=e.get(k);return{chunk:`\n float depth_${t} = 2.0 * ${o} * ${r} / (${r} + ${o} - (2.0 * ${e.get(this.depth)} - 1.0) * (${r} - ${o}));\n `,out:`depth_${t}`}}constructor(e){super(),this.depth=e}}function N(e){return new $(e)}new class extends g{constructor(){super(...arguments),this.k="31u50"}compile(e){return{pars:`\n const float UnpackDownscale_${this.k} = 255. / 256.; // 0..1 -> fraction (excluding 1)\n const vec4 PackFactors_${this.k} = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\n const vec4 UnpackFactors_${this.k} = vec4( UnpackDownscale_${this.k} / PackFactors_${this.k}.rgb, 1.0 / PackFactors_${this.k}.a );\n `,out:`UnpackFactors_${this.k}`}}};function v(e){return p(depthSampler,e).r}const w=new s("gl_FragCoord.z");export const fragmentLinearEyeDepth=N(w);export const resolution=u("hology_resolution",new t(250,1e3));export const screenUV=new _("gl_FragCoord.xy").divide(resolution);export const linearEyeDepth=N(v(screenUV));const V=x(a(m.projectionMatrix)),b=x(a(m.viewMatrix));function F(e=screenUV){const t=v(e).multiply(2).subtract(1),o=e.multiplyScalar(2).subtractScalar(1),r=U(o.x,o.y,t,1),n=V.multiplyVec(r),s=n.xyz.divideScalar(n.w);return b.multiplyVec(U(s,1)).xyz}export const depthWorldPosition=F(screenUV);const S=n(1).divide(resolution.x),D=n(1).divide(resolution.y),P=F(screenUV.add(f(S,n(0)))),z=F(screenUV.add(f(n(0),D)));export const depthNormal=i(o(P.subtract(depthWorldPosition),z.subtract(depthWorldPosition)));export const sceneNormalSampler=h(sceneNormalUniformName,new e.Texture);export const sceneNormal=d(sceneNormalSampler.sample(screenUV).rgb);/*
|
|
2
2
|
* Copyright (©) 2025 Hology Interactive AB. All rights reserved.
|
|
3
3
|
* See the LICENSE.md file for details.
|
|
4
4
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shader-nodes/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC3H,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shader-nodes/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAC3H,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,uBAAuB,CAAA;AACrC,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA"}
|