@hology/core 0.0.96 → 0.0.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/effects/vfx/vfx-actor.d.ts +1 -0
  2. package/dist/effects/vfx/vfx-actor.d.ts.map +1 -1
  3. package/dist/effects/vfx/vfx-actor.js +1 -1
  4. package/dist/effects/vfx/vfx-asset.d.ts +17 -4
  5. package/dist/effects/vfx/vfx-asset.d.ts.map +1 -1
  6. package/dist/effects/vfx/vfx-asset.js +1 -1
  7. package/dist/effects/vfx/vfx-materializer.d.ts +2 -8
  8. package/dist/effects/vfx/vfx-materializer.d.ts.map +1 -1
  9. package/dist/effects/vfx/vfx-materializer.js +1 -1
  10. package/dist/effects/vfx/vfx-renderers.d.ts +1 -0
  11. package/dist/effects/vfx/vfx-renderers.d.ts.map +1 -1
  12. package/dist/effects/vfx/vfx-renderers.js +1 -1
  13. package/dist/gameplay/actors/builtin/components/mesh-component.d.ts +1 -0
  14. package/dist/gameplay/actors/builtin/components/mesh-component.d.ts.map +1 -1
  15. package/dist/gameplay/actors/builtin/components/mesh-component.js +1 -1
  16. package/dist/gameplay/index.d.ts +1 -0
  17. package/dist/gameplay/index.d.ts.map +1 -1
  18. package/dist/gameplay/index.js +1 -1
  19. package/dist/gameplay/initiate.d.ts.map +1 -1
  20. package/dist/gameplay/initiate.js +1 -1
  21. package/dist/gameplay/input/input-service.d.ts +8 -0
  22. package/dist/gameplay/input/input-service.d.ts.map +1 -1
  23. package/dist/gameplay/input/input-service.js +1 -1
  24. package/dist/gameplay/services/physics/physics-system.d.ts +2 -1
  25. package/dist/gameplay/services/physics/physics-system.d.ts.map +1 -1
  26. package/dist/gameplay/services/physics/physics-system.js +1 -1
  27. package/dist/gameplay/services/shader-provider.d.ts +7 -0
  28. package/dist/gameplay/services/shader-provider.d.ts.map +1 -0
  29. package/dist/gameplay/services/shader-provider.js +4 -0
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1 -1
  33. package/dist/rendering.d.ts.map +1 -1
  34. package/dist/rendering.js +1 -1
  35. package/dist/scene/asset-resource-loader.d.ts.map +1 -1
  36. package/dist/scene/asset-resource-loader.js +1 -1
  37. package/dist/scene/collision/collision-shape.d.ts +8 -0
  38. package/dist/scene/collision/collision-shape.d.ts.map +1 -1
  39. package/dist/scene/collision/collision-shape.js +1 -1
  40. package/dist/scene/materializer.d.ts +6 -1
  41. package/dist/scene/materializer.d.ts.map +1 -1
  42. package/dist/scene/materializer.js +1 -1
  43. package/dist/shader/builtin/decal-standard-shader.d.ts.map +1 -1
  44. package/dist/shader/builtin/decal-standard-shader.js +1 -1
  45. package/dist/shader/builtin/decal-unlit-shader.d.ts +1 -0
  46. package/dist/shader/builtin/decal-unlit-shader.d.ts.map +1 -1
  47. package/dist/shader/builtin/decal-unlit-shader.js +1 -1
  48. package/dist/shader/builtin/standard-shader.d.ts.map +1 -1
  49. package/dist/shader/builtin/standard-shader.js +1 -1
  50. package/dist/shader/builtin/unlit-shader.d.ts +1 -0
  51. package/dist/shader/builtin/unlit-shader.d.ts.map +1 -1
  52. package/dist/shader/builtin/unlit-shader.js +1 -1
  53. package/dist/shader/index.d.ts +2 -0
  54. package/dist/shader/index.d.ts.map +1 -1
  55. package/dist/shader/index.js +1 -1
  56. package/dist/shader/sprite-shader.d.ts +17 -0
  57. package/dist/shader/sprite-shader.d.ts.map +1 -0
  58. package/dist/shader/sprite-shader.js +4 -0
  59. package/package.json +2 -2
  60. package/tsconfig.tsbuildinfo +1 -1
@@ -1,4 +1,4 @@
1
- import{ConvexPolyhedronCollisionShape as e}from"@hology/core";import{Subject as t}from"rxjs";import*as a from"three";import{BoxGeometry as s,Color as r,Euler as i,Fog as n,FogExp2 as o,Group as l,Material as c,Matrix4 as h,Mesh as d,MeshLambertMaterial as m,MeshPhongMaterial as p,MeshStandardMaterial as u,Object3D as f,PointLight as y,Quaternion as g,SphereGeometry as w,Texture as v,Vector2 as S,Vector3 as A,Vector4 as b}from"three";import M,{SpriteRenderer as x}from"@hology/nebula";import{bool as j,BooleanNode as P,float as I,FloatNode as E,NodeShaderMaterial as V,rgb as D,RgbNode as N,Texture2dLookupNode as C,textureSampler2d as k,vec2 as _,Vec2Node as F,vec3 as O,Vec3Node as T,vec4 as z}from"three-shader-graph";import{VfxActor as B}from"../effects/vfx/vfx-actor.js";import{VisualEffect as W}from"../effects/vfx/vfx-param.js";import{BaseActor as $}from"../gameplay/actors/actor.js";import R from"../gameplay/actors/builtin/index.js";import{PhysicsBodyType as U,withInjectionContext as G}from"../gameplay/index.js";import{Sampler2DNode as L}from"../shader-nodes/index.js";import{LambertShader as J}from"../shader/builtin/lambert-shader.js";import{LandscapeCompositeShader as H}from"../shader/builtin/landscape-composite-shader";import{LandscapeShader as q}from"../shader/builtin/landscape-shader.js";import{StandardShader as X}from"../shader/builtin/standard-shader.js";import{UnlitShader as Y}from"../shader/builtin/unlit-shader.js";import{extractShaderParameters as Z}from"../shader/parameter.js";import{ArrayMap as Q,groupBy as K}from"../utils/collections.js";import{iterateMaterials as ee}from"../utils/materials.js";import{filterChildrenShallow as te,filterSceneShallow as ae,findFirstVisibleObject as se}from"../utils/three/traverse.js";import{AssetMeshInstance as re}from"./asset-resource-loader.js";import{isCollisionMesh as ie}from"./collision/collision-shape-import.js";import{BoxCollisionShape as ne,PhysicalShapeMesh as oe}from"./collision/collision-shape.js";import{LandscapeManager as le}from"./landscape/landscape-manager.js";import{initLandscape as ce}from"./landscape/landscape.js";import{SectionGrid as he,smoothNormalsCrossMeshes as de}from"./landscape/utils.js";import{createGrassFoliageMaterial as me}from"./materials/grass-foliage.js";import{createGrassMaterial as pe}from"./materials/grass.js";import{getMaterialAttribute as ue}from"./materials/utils/material-painting.js";import{createWaterMaterial as fe}from"./materials/water.js";import{SerializedParamType as ye}from"./model.js";import{ShapeLibrary as ge,ShapeLibraryKeys as we}from"./objects/shapes.js";import{ambientLightName as ve,createSky as Se,defaultSkyMaterial as Ae}from"./sky.js";import{Curve2 as be}from"../utils/curve.js";import{DecalUnlitShader as Me}from"../shader/builtin/decal-unlit-shader.js";import{DecalStandardShader as xe}from"../shader/builtin/decal-standard-shader.js";const je={};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 SceneMaterializer(e,this.dataProvider,this.assetsService,this.assetManagerService,t,[],[],{create:()=>null,initActor:async()=>{}})}}export class SceneMaterializer{constructor(e,s,r,i,n,o,l,c){this.scene=e,this.dataProvider=s,this.assetsService=r,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 t,this.removed$=new t,this.error$=new t,this.editorActorParamSnapshot=new Map,this.assets=new Map,this._canBeInstancedCache=new Map,this._originalMaterials=new Map,this.pmremGeneratorResults=new WeakMap,this.geometryCache=new Map,this.collisionShapeCache=new Map,this.originalFog=null,s.onCreate((e=>this.update(e))),s.onUpdate((e=>this.update(e))),s.onRemove((e=>this.remove(e))),this.createAssetSubscription=r.onCreate.subscribe((e=>{this.assets.set(e.id,e)})),this.updateSubscription=r.onUpdate.subscribe((async t=>{this.assets.set(t.id,t),"material"==t.type?e.traverse((e=>{if(e instanceof a.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=>{Te(e.userData.src.materialAssignments,t.materialAssignments).forEach((t=>{this.applyMaterial(e,t)}))})),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 A,!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=>{Oe(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===ye.Material&&s.value===a.id){t=!0;break}if(s.type===ye.Array&&"element"in s&&s.element===ye.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,null!=s?Be(e.material[s],i)||(e.material[s]=i):Be(e.material,i)||(e.material=i)}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===ye.Texture&&"string"==typeof t.value){const a=this.assets.get(t.value),s=await this.assetManagerService.getTexture(a);null!=s&&e.push(s)}}))),await Promise.all(Array.from(this.assets.values()).map((async t=>{if("texture"===t.type){const a=await this.assetManagerService.getTexture(t);e.push(a)}}))),0!==e.length){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(),Ie.clear(),await this.prefetchAssets(),await Promise.all(this.dataProvider.getObjects().map((e=>this.materialize(e)))),await this.initActorsPostInit()}initActorsPostInit(e=this.actorInstances){const t=e.map((async e=>{const t=e.object.userData.src??e.object.userData._src;if("vfx"===t.type)return Promise.resolve();const a=await this.assetsService.getAsset(t.assetId),s={...a?.actor?.params??{},...t.actor?.params??{}};for(const a of t.actor.innerParams??[])await this.applyActorComponentParams(e,a.path.slice(),a.params);const r=await Ne(s,e.constructor,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders,this.actorProvider);Object.assign(e,r);try{return await this.actorProvider.initActor(e)}catch(e){console.error(`Failed to initiate actor (name="${t.name}", id=${t.id})`,e)}}));return Promise.all(t)}addVfxChildActors(e,t=e){}async applyActorComponentParams(e,t,a){const s=t.length,r=t.shift();if(0==s){const t=await Ne(a,null,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders);for(const[a,s]of Object.entries(t))null!=s&&(e[a]=s)}else null!=e[r]&&await this.applyActorComponentParams(e[r],t,a)}canObjectBeInstanced(e){return e.physics?.type!==U.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)}))}async initWithInstancing(){await this.preInit(),await this.prefetchAssets();const t=[],s=new Q,n=new Q;for(const e of this.dataProvider.getObjects())await Oe(e,(async(e,a,i)=>{const o="asset_mesh"==e.type&&this.canObjectBeInstanced(e)&&await this.canAssetBeInstanced(e),l="shape_mesh"===e.type&&"landscape"!==e.shape&&e.physics?.type!==U.dynamic;if(o||l){if(a&&a.children?.length>0){const t=a.children.findIndex((t=>t.id===e.id));t>=0&&a.children.splice(t,1)}if(l){let t=e.shape+JSON.stringify(e.shapeParams??{})+e.castShadow+e.receiveShadow;const a=e.materialAssignments?.at(0)?.materialId,s=null!=a?this.assets.get(a):null;let o=null;if(null!=s&&"shader"!==s.material.type){if(t+=s.material.type+s.material.shader,null!=s.material.shaderParams){if(t+=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===ye.Color&&null!=e.value&&(o=new r(e.value))}}}else t+=a;n.push(t,{object:{...e,parentTransform:i},color:o})}else{const t=e.assetId+JSON.stringify(e.materialAssignments??[]);s.push(t,{...e,parentTransform:i})}}else null==a&&t.push({...e,parentTransform:i})}));for(const t of s.values()){if(0==t.length)continue;const a=await this.createFromAsset(t[0]);if(null==a)continue;const s=await this.createInstancedMesh(t,a),r=new re;r.add(s),r.userData.src=t[0],a instanceof re&&(r.collisionShapes=a.collisionShapes),r.collisionShapes.forEach((t=>{t instanceof e&&t.mesh instanceof d&&(t.mesh=t.mesh.geometry)})),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r)}for(const e of n.values()){if(0==e.length)continue;const t=e[0].object,s=await this.createFromShape(t),n=se(s,(e=>!ie(e)&&null!=e.geometry)),o=n.material.clone();null!=e[0].color&&null!=o.color&&(o.color=new r(16777215));const l=n.geometry,c=new a.InstancedMesh(l,o,e.length);for(let t=0;t<e.length;t++){const r=e[t],o=(new a.Matrix4).compose((new A).fromArray(r.object.position),(new g).setFromEuler((new i).fromArray(r.object.rotation)),(new A).fromArray(r.object.scale)),l=(new h).copy(r.object.parentTransform).multiply(o);c.setMatrixAt(t,l),null!=r.color&&c.setColorAt(t,r.color),c.castShadow=s.castShadow??!0,c.receiveShadow=n.receiveShadow??!0;const d=new re;d.add(c),d.userData.src=e[0],s instanceof oe&&(d.collisionShapes=[s.collisionShape]),d.castShadow=!1,d.receiveShadow=!1,this.scene.add(d)}}await Promise.all(t.map((e=>this.materialize(e)))),await this.initActorsPostInit()}async createInstancedMesh(e,t){const s=se(t,(e=>!ie(e)&&null!=e.geometry)),r=await this.assetsService.getAsset(e[0].assetId);await this.applyMaterials(t,Te(e[0].materialAssignments,r.materialAssignments)),s.updateMatrix();const n=s.geometry.clone(),o=new a.InstancedMesh(n,s.material,e.length);for(let t=0;t<e.length;t++){const r=(new a.Matrix4).compose((new A).fromArray(e[t].position),(new g).setFromEuler((new i).fromArray(e[t].rotation)),(new A).fromArray(e[t].scale)),n=(new h).copy(e[t].parentTransform).multiply(r).multiply(s.matrixWorld);o.setMatrixAt(t,n)}return o.castShadow=e[0].castShadow??r.castShadow??!0,o.receiveShadow=e[0].receiveShadow??r.receiveShadow??!0,s.material instanceof c&&o.castShadow&&o.receiveShadow&&(o.material.side=a.FrontSide),o}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)}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 ae(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(R));ae(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 Ie.entries())t.userData.customShaderName&&Ie.delete(e);this.landscapeManagers.forEach((t=>t.updateShaders(e))),ae(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);Te(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 r(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)}else"directional"===e.light.type?this.applyDirectionalLight(e.light.directional):"ambient"===e.light.type&&this.applyDirectionalAmbientLight(t,e.light.ambient);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 o?"density":"linear")!==e.fog.type;this.scene.fog=_e(e.fog),t&&(a=this.scene).traverse((e=>{if(e instanceof d){const t=e.material;t instanceof V&&(a.fog instanceof n?(t.uniforms.fogFar.value=a.fog.far,t.uniforms.fogNear.value=a.fog.near):a.fog instanceof o&&(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.editorActorParamSnapshot.get(e.id);null!=t&&t===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 oe&&(t.geometry=a.geometry,t.collisionShape=a.collisionShape)}("asset_mesh"===e.type||"shape_mesh"===e.type&&"landscape"!==e.shape)&&Pe(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)){console.log("materialize actor and init");const a=await this.materialize(e,t);return Oe(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:te(t,(t=>t.children?.some((t=>t.id===e.id))),(()=>!0))))[0];return null==t?this.scene:null!=t?ae(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 r(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=K(e.vertexMaterials,(e=>e.m));t.traverse((e=>{if(e instanceof d){if(null==e.geometry)return;if(We(ue(e,0,!1)),a>0){We(ue(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=ue(s,0,!0);We(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=ue(s,4,!0);We(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){let r;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=_e(e.fog),this.fixFogColor(),r=new l;break;case"sky":this.sky=Se(),this.updateSky(e),r=this.sky;break;case"world_env":this.updateWorldEnv(e),r=new l,this.worldEnvObj=r;break;case"actor":r=await this.createFromActor(e);break;case"group":r=new l;break;case"prefab":r=await this.createFromPrefabAsset(e);break;case"vfx":r=await this.createFromVfx(e);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,this.inEditor,this.inEditor){let e=null;r instanceof oe&&(e=function(e){if(e instanceof ne)return new d(new s(...e.offset.toArray()),Fe);return null}(r.collisionShape)),null!=e&&(e.layers.disable(0),e.layers.enable(18),e.scale.multiplyScalar(1.1),r.add(e))}return this.objectMap.set(r.uuid,e),this.sceneObjectMap.set(e.id,r),e.physics?.type!==U.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==U.dynamic||ke(r),this.renderingView.renderer.shadowMap.needsUpdate=!0,r}}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 s=e.worldEnv.environment;null!=s&&null!=s.textureId?this.assetManagerService.getTexture(this.assets.get(s.textureId)).then((e=>{null==this.pmremGenerator&&(this.pmremGenerator=new a.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=s.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=Ae);const t=await this.assetsService.getAsset(e.sky.materialId),s=await materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1);s.side=a.BackSide,(s instanceof u||s instanceof a.MeshBasicMaterial||s instanceof a.ShaderMaterial)&&(s.fog=!1),null!=this.sky?this.sky.material=s:console.warn("No sky has been created")}async createComponent(e,t,a,s){const r=new je[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){const t=this.actorTypes.find((t=>t.name===e.actor?.type))?.type??R[e.actor?.type];if(null==t)return null;this.inEditor&&this.editorActorParamSnapshot.set(e.id,JSON.stringify(e.actor));const a=await this.actorProvider.create(t,(new A).fromArray(e.position),(new i).fromArray(e.rotation),!0);return this.materializedActors.set(e.id,a),a?.object}async createFromVfx(e){const t=await this.assetsService.getAsset(e.assetId);null==t&&console.error("Could not find asset",e);const a=await this.actorProvider.create(B,(new A).fromArray(e.position),(new i).fromArray(e.rotation),!1);return await a.fromAsset(t),a.play(),this.materializedActors.set(e.id,a),a?.object}cleanup(){this.materializedActors.clear()}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 u({name:"Default",color:new r("#aaaaaa"),visible:this.inEditor||!e.hidden,wireframe:!!t});const i=await this.createMeshByShape(e.shape,s,e.shapeParams);i.castShadow=e.castShadow??!0,i.receiveShadow=e.castShadow??!1,e.collisionDetection||(i.collisionShape=null),i.physics=e.physics,a=i,this._originalMaterials.set(a.id,i.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 l;const a=ce(e.landscape.options);this.applyHeightMaps(a,e.landscape.heightMaps,!0);const s=new le(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 he(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((()=>de(r)),50)}async createMeshByShape(e,t,a={}){if("landscape"!==e&&we.includes(e)){const s=await prepareShapeParameters(a??{}),r=e+JSON.stringify(a);return this.geometryCache.has(r)||this.geometryCache.set(r,ge[e].geometry(s)),this.collisionShapeCache.has(r)||this.collisionShapeCache.set(r,ge[e].collision(s)),new oe(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});Te(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,Pe(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 createFromPrefabAsset(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}`);const a=new l;return t.prefab.objects.filter((e=>"global_fog"!==e.type&&"world_env"!==e.type)).forEach((e=>this.materialize(e,a,!0))),a}async createParticleSystem(e){const t=await this.assetsService.getAsset(e.assetId),s=new f;return await M.fromJSONAsync(t.particleSystem,a).then((e=>{const t=new x(s,a);e.addRenderer(t),this.renderingView.onLoop((t=>e.update()))})),s}async createLight(e){if("point"===e.light.type){const t=new y(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 w(.3,10,10),a=new u({color:new r(16771709)}),s=new d(e,a);t.add(s)}return t}return"directional"===e.light.type?(this.applyDirectionalLight(e.light.directional),new l):"ambient"===e.light.type?(this.applyDirectionalAmbientLight(null,e.light.ambient),new l):void 0}applyDirectionalAmbientLight(e,t){const a=this.scene.children.find((e=>e.name===ve));null!=a?(a.intensity=t.intensity,a.color.set(t.color),a.groundColor.set(t.color)):console.warn("Couldn't find ambient light")}applyDirectionalLight(e){for(const t of this.renderingView.csm.lights)t.intensity=e.intensity,t.color.set(e.color),t.castShadow=e.castShadow;this.renderingView.csm.lightDirection.fromArray(e.direction).normalize()}dispose(){this.updateSubscription.unsubscribe(),this.createAssetSubscription.unsubscribe(),this.materializedActors.forEach((e=>e.disposed.next(!0)))}}function Pe(e,t,a){e.castShadow=t,e.receiveShadow=a,e.traverse((e=>{e.castShadow=t,e.receiveShadow=a}))}const Ie=new Map,Ee=new Map,Ve=new m({color:16711935}),De=new Map;export async function materialFromAsset(e,t,a,s,r,i=!0){const n=JSON.stringify(e.material);return i&&Ie.has(n)?Ie.get(n):i&&Ee.has(n)?await Ee.get(n):Ee.set(n,_materialFromAsset(n,e,t,a,s,r,i)).get(n)}export async function _materialFromAsset(e,t,s,i,n,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 r(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 i.getAsset(e);null!=a&&(c.map=await n.getTexture(a))}let d;switch(t.material.type){case"phong":d=new p({...c,...h});break;case"water":d=fe(c,s);break;case"grassFoliage":d=me({color:c.color,map:c.map},s);break;case"grass":d=pe({...c,colorTwo:new r(t.material.params.colorTwo),colorThree:new r(t.material.params.colorThree)},s);break;case"standard":case"unlit":case"lambert":case"shader":case"landscape":case"landscape-composite":case"decal-unlit":case"decal-standard":const e={standard:X,lambert:J,unlit:Y,landscape:q,"landscape-composite":H,"decal-unlit":Me,"decal-standard":xe}[t.material.type]??o.find((e=>e.name==t.material.shader))?.type;if(e){try{let a=new e;const r=await Ne(t.material?.shaderParams??{},e,i,n,null,s,o);Object.assign(a,r),d=a.build()}catch(e){console.log("Shader runtime error: "+e),De.has(t.material.shader)||De.set(t.material.shader,Ve.clone()),d=De.get(t.material.shader)}d.userData.customShaderName=t.material.shader}else console.warn("Missing shader implementation with name "+t.material.shader),d=Ve;break;default:throw new Error("Unsupported material type"+t.material.type)}return s?.csm.setupMaterial(d),null!=s&&Ie.set(e,d),d.side=t.material.side??d.side??a.FrontSide,d.transparent=(t.material.transparent??c.transparent??!1)||d.transparent,d.alphaTest=t.material.alphaTest??d.alphaTest??0,t.material.bloom&&(d.userData.hasBloom=!0),d.userData.assetId=t.id,Ee.delete(e),d}async function Ne(e,t,a,s,r,i,n,o){const l={};for(const[t,c]of Object.entries(e)){const e=await Ce(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 Ce(s,null,null,null);null!=e&&(t[a]=e)}return t}async function Ce(e,t,a,s,n,o,l,c=e.value,h=e.type){if(null==e||null==c||""===c)return null;switch(h){case ye.Array:if(Array.isArray(c)&&"element"in e)return await Promise.all(c.map((r=>Ce(e,t,a,s,n,o,l,r,e.element))));break;case ye.Number:case ye.FloatNode:let h="string"==typeof c?parseFloat(c):c;return e.type===ye.FloatNode?I(h):h;case ye.Texture:return await a.getTexture(await t.getAsset(c));case ye.Sampler2DNode:return k(await a.getTexture(await t.getAsset(c)));case ye.Boolean:return c;case ye.BooleanNode:return j(c);case ye.Vector2:case ye.Vec2Node:if("object"==typeof c){const t=c instanceof Array?(new S).fromArray(c):new S(c.x,c.y);return e.type===ye.Vec2Node?_(t):t}return null;case ye.Vector3:case ye.Vec3Node:if("object"==typeof c){const t=c instanceof Array?(new A).fromArray(c):new A(c.x,c.y,c.z);return e.type===ye.Vec3Node?O(t):t}return null;case ye.Color:case ye.RgbNode:const d=new r(c);return e.type===ye.RgbNode?D(d):d;case ye.String:return c;case ye.BaseActor:const m=c;return null==s&&console.warn("Class parameters can not be prepared as actors are not passed in"),s?.get(m);case ye.Euler:const p=c;return(new i).fromArray(p);case ye.Object3D:return(await a.getMesh(await t.getAsset(c))).scene;case ye.Material:return await materialFromAsset(await t.getAsset(c),n,t,a,o);case ye.AudioBuffer:return await a.getAudio(await t.getAsset(c));case ye.VisualEffect:const u=await t.getAsset(c);if(null==l){console.error("Can not create instance of visual effect because missing actor provider");break}if("vfx"in u)return new W(l,u);console.error("Using a non-vfx asset for visual effect parameter");break;case ye.Curve:return be.decode(c)}return null}function ke(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 _e(e){return"linear"===e.type?new n(new r(e.color),e.near??100,e.far??1e3):"density"===e.type?new o(e.color,e.density):void console.warn("Invalid fog type",e)}const Fe=new u({color:4229780});async function Oe(e,t,s,r){null==r&&(r=(new h).identity()),await t(e,s,r);const n=r.clone().multiply(function(e,t){if(null==e.position||null==e.rotation||null==e.scale)return t.identity();return t.compose((new A).fromArray(e.position),(new g).setFromEuler((new i).fromArray(e.rotation)),(new A).fromArray(e.scale))}(e,new a.Matrix4));return Promise.all((e.children??[]).map((a=>Oe(a,t,e,n))))}export function toSerializedParamType(e){const t=e.constructor.prototype;return t instanceof Number||e===Number?ye.Number:t instanceof E||"function"==typeof e.prototype.isFloat?ye.FloatNode:t instanceof v||e===v||e.isTexture?ye.Texture:t instanceof L||e===C?ye.Sampler2DNode:t instanceof Boolean||e===Boolean?ye.Boolean:t instanceof P?ye.BooleanNode:t instanceof r||e==r?ye.Color:t instanceof N||"function"==typeof e.prototype.isRgb?ye.RgbNode:t instanceof S||e==S?ye.Vector2:t instanceof F||"function"==typeof e.prototype.isVec2?ye.Vec2Node:t instanceof A||e==A?ye.Vector3:t instanceof T||"function"==typeof e.prototype.isVec3?ye.Vec3Node:t instanceof String||e===String?ye.String:t instanceof $||e==$||e.prototype instanceof $||e.prototype==$?ye.BaseActor:t instanceof i||e==i?ye.Euler:t instanceof f||e==f?ye.Object3D:t instanceof c||e==c?ye.Material:t instanceof AudioBuffer||e==AudioBuffer?ye.AudioBuffer:t instanceof W||e==W?ye.VisualEffect:t instanceof be||e==be?ye.Curve: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?ye.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=Z(e);if(0===s.length)return{};let r;null!=a?G(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 A:return t instanceof A?t.toArray():void a();case b:return t instanceof b?t.toArray():void a();case r:return t instanceof r?"#"+t.getHexString():"string"==typeof t?t:"number"==typeof t?"#"+new r(t).getHexString():void a();case String:return t;case i:return t instanceof i?t.toArray():void a()}}function Te(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=>ze(e.materialId))),(t??[]).filter((e=>ze(e.materialId))),(e=>e.color+e.name))}function ze(e){return"null"!=e&&null!=e}export const customParameterDefaultValueByType=new Map([[ye.RgbNode,"#000000"],[ye.Color,"#000000"],[ye.Vector4,[0,0,0,0]],[ye.Vec4Node,[0,0,0,0]],[ye.Vector3,[0,0,0]],[ye.Vec3Node,[0,0,0]],[ye.Vector2,[0,0]],[ye.Vec2Node,[0,0]],[ye.Euler,[0,0,0,"XYZ"]],[ye.Array,[]]]);export function applyMaterial(e,t,s,i){const n=[];return e.traverse((async e=>{if(e instanceof d||e.isMesh||e instanceof a.SkinnedMesh||e.isSkinnedMesh)for(const t of ee(e.material))t.hasOwnProperty("color")&&n.push(e)})),Promise.all(n.map((async e=>{if(e.material instanceof Array)for(let a=0;a<e.material.length;a++){const n=e.material[a];if(null==n.color||!(n.color instanceof r))continue;const o="#"+n.color.getHexString(),l=n.name;if(o===t.color&&(n.name===t.name||null==t.name)||e.userData["originalColor_"+a]===t.color&&e.userData["originalMaterialName_"+a]===t.name){const r=await s(t.materialId),n=e.material[a];null!=r&&n.id!=r.id&&(e.material[a]=r,e.userData["originalColor_"+a]=e.userData["originalColor_"+a]??o,e.userData["originalMaterialName_"+a]=e.userData["originalMaterialName_"+a]??l,null!=i&&i.set(e.id+"#"+a,n))}}else if("color"in e.material){const a="#"+e.material.color.getHexString(),r=e.material.name;if(a===t.color&&(e.material.name===t.name||null==t.name)||e.userData.originalColor===t.color&&e.userData.originalName===t.name){const n=await s(t.materialId),o=e.material;null!=n&&(e.material=n,e.userData.originalColor=e.userData.originalColor??a,e.userData.originalMaterialName=e.userData.originalMaterialName??r,null!=i&&(i.has(e.id)||i.set(e.id,o)))}}})))}function Be(e,t){if(e instanceof a.ShaderMaterial&&t instanceof a.ShaderMaterial){return e.fragmentShader+e.vertexShader==t.fragmentShader+t.vertexShader&&function(e,t){if(e instanceof a.ShaderMaterial&&t instanceof a.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 We(e){if(null!=e){for(let t=0;t<e.array.length;t++)e.setX(t,0);e.needsUpdate=!0}}/*
1
+ import{ConvexPolyhedronCollisionShape as e}from"@hology/core";import{Subject as t}from"rxjs";import*as a from"three";import{BoxGeometry as s,Color as r,Euler as i,Fog as n,FogExp2 as o,Group as l,Material as c,Matrix4 as h,Mesh as d,MeshLambertMaterial as m,MeshPhongMaterial as p,MeshStandardMaterial as u,Object3D as f,PointLight as y,Quaternion as g,SphereGeometry as w,Texture as v,Vector2 as S,Vector3 as b,Vector4 as A}from"three";import M,{SpriteRenderer as x}from"@hology/nebula";import{bool as j,BooleanNode as P,float as I,FloatNode as E,NodeShaderMaterial as D,rgb as V,RgbNode as C,Texture2dLookupNode as N,textureSampler2d as k,vec2 as _,Vec2Node as F,vec3 as O,Vec3Node as T,vec4 as z}from"three-shader-graph";import{VfxActor as B}from"../effects/vfx/vfx-actor.js";import{VisualEffect as W}from"../effects/vfx/vfx-param.js";import{BaseActor as $}from"../gameplay/actors/actor.js";import R from"../gameplay/actors/builtin/index.js";import{PhysicsBodyType as U,withInjectionContext as G}from"../gameplay/index.js";import{Sampler2DNode as L}from"../shader-nodes/index.js";import{LambertShader as J}from"../shader/builtin/lambert-shader.js";import{LandscapeCompositeShader as H}from"../shader/builtin/landscape-composite-shader";import{LandscapeShader as q}from"../shader/builtin/landscape-shader.js";import{StandardShader as X}from"../shader/builtin/standard-shader.js";import{UnlitShader as Y}from"../shader/builtin/unlit-shader.js";import{extractShaderParameters as Z}from"../shader/parameter.js";import{ArrayMap as Q,groupBy as K}from"../utils/collections.js";import{iterateMaterials as ee}from"../utils/materials.js";import{filterChildrenShallow as te,filterSceneShallow as ae,findFirstVisibleObject as se}from"../utils/three/traverse.js";import{AssetMeshInstance as re}from"./asset-resource-loader.js";import{isCollisionMesh as ie}from"./collision/collision-shape-import.js";import{BoxCollisionShape as ne,PhysicalShapeMesh as oe}from"./collision/collision-shape.js";import{LandscapeManager as le}from"./landscape/landscape-manager.js";import{initLandscape as ce}from"./landscape/landscape.js";import{SectionGrid as he,smoothNormalsCrossMeshes as de}from"./landscape/utils.js";import{createGrassFoliageMaterial as me}from"./materials/grass-foliage.js";import{createGrassMaterial as pe}from"./materials/grass.js";import{getMaterialAttribute as ue}from"./materials/utils/material-painting.js";import{createWaterMaterial as fe}from"./materials/water.js";import{SerializedParamType as ye}from"./model.js";import{ShapeLibrary as ge,ShapeLibraryKeys as we}from"./objects/shapes.js";import{ambientLightName as ve,createSky as Se,defaultSkyMaterial as be}from"./sky.js";import{Curve2 as Ae}from"../utils/curve.js";import{DecalUnlitShader as Me}from"../shader/builtin/decal-unlit-shader.js";import{DecalStandardShader as xe}from"../shader/builtin/decal-standard-shader.js";const je={};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 SceneMaterializer(e,this.dataProvider,this.assetsService,this.assetManagerService,t,[],[],{create:()=>null,initActor:async()=>{}})}}export class SceneMaterializer{constructor(e,s,r,i,n,o,l,c){this.scene=e,this.dataProvider=s,this.assetsService=r,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 t,this.removed$=new t,this.error$=new t,this.editorActorParamSnapshot=new Map,this.assets=new Map,this._canBeInstancedCache=new Map,this._originalMaterials=new Map,this.pmremGeneratorResults=new WeakMap,this.geometryCache=new Map,this.collisionShapeCache=new Map,this.originalFog=null,s.onCreate((e=>this.update(e))),s.onUpdate((e=>this.update(e))),s.onRemove((e=>this.remove(e))),this.createAssetSubscription=r.onCreate.subscribe((e=>{this.assets.set(e.id,e)})),this.updateSubscription=r.onUpdate.subscribe((async t=>{this.assets.set(t.id,t),"material"==t.type?e.traverse((e=>{if(e instanceof a.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=>{Oe(e.userData.src.materialAssignments,t.materialAssignments).forEach((t=>{this.applyMaterial(e,t)}))})),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 b,!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=>{Fe(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===ye.Material&&s.value===a.id){t=!0;break}if(s.type===ye.Array&&"element"in s&&s.element===ye.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,null!=s?ze(e.material[s],i)||(e.material[s]=i):ze(e.material,i)||(e.material=i)}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===ye.Texture&&"string"==typeof t.value){const a=this.assets.get(t.value),s=await this.assetManagerService.getTexture(a);null!=s&&e.push(s)}}))),await Promise.all(Array.from(this.assets.values()).map((async t=>{if("texture"===t.type){const a=await this.assetManagerService.getTexture(t);e.push(a)}}))),0!==e.length){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(),Ie.clear(),await this.prefetchAssets(),await Promise.all(this.dataProvider.getObjects().map((e=>this.materialize(e)))),await this.initActorsPostInit()}initActorsPostInit(e=this.actorInstances){const t=e.map((async e=>{const t=e.object.userData.src??e.object.userData._src;if("vfx"===t.type)return Promise.resolve();const a=await this.assetsService.getAsset(t.assetId),s={...a?.actor?.params??{},...t.actor?.params??{}};for(const a of t.actor.innerParams??[])await this.applyActorComponentParams(e,a.path.slice(),a.params);const r=await prepareClassParameters(s,e.constructor,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders,this.actorProvider);Object.assign(e,r);try{return await this.actorProvider.initActor(e)}catch(e){console.error(`Failed to initiate actor (name="${t.name}", id=${t.id})`,e)}}));return Promise.all(t)}addVfxChildActors(e,t=e){}async applyActorComponentParams(e,t,a){const s=t.length,r=t.shift();if(0==s){const t=await prepareClassParameters(a,null,this.assetsService,this.assetManagerService,this.materializedActors,this.renderingView,this.shaders);for(const[a,s]of Object.entries(t))null!=s&&(e[a]=s)}else null!=e[r]&&await this.applyActorComponentParams(e[r],t,a)}canObjectBeInstanced(e){return e.physics?.type!==U.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)}))}async initWithInstancing(){await this.preInit(),await this.prefetchAssets();const t=[],s=new Q,n=new Q;for(const e of this.dataProvider.getObjects())await Fe(e,(async(e,a,i)=>{const o="asset_mesh"==e.type&&this.canObjectBeInstanced(e)&&await this.canAssetBeInstanced(e),l="shape_mesh"===e.type&&"landscape"!==e.shape&&e.physics?.type!==U.dynamic;if(o||l){if(a&&a.children?.length>0){const t=a.children.findIndex((t=>t.id===e.id));t>=0&&a.children.splice(t,1)}if(l){let t=e.shape+JSON.stringify(e.shapeParams??{})+e.castShadow+e.receiveShadow;const a=e.materialAssignments?.at(0)?.materialId,s=null!=a?this.assets.get(a):null;let o=null;if(null!=s&&"shader"!==s.material.type){if(t+=s.material.type+s.material.shader,null!=s.material.shaderParams){if(t+=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===ye.Color&&null!=e.value&&(o=new r(e.value))}}}else t+=a;n.push(t,{object:{...e,parentTransform:i},color:o})}else{const t=e.assetId+JSON.stringify(e.materialAssignments??[]);s.push(t,{...e,parentTransform:i})}}else null==a&&t.push({...e,parentTransform:i})}));for(const t of s.values()){if(0==t.length)continue;const a=await this.createFromAsset(t[0]);if(null==a)continue;const s=await this.createInstancedMesh(t,a),r=new re;r.add(s),r.userData.src=t[0],a instanceof re&&(r.collisionShapes=a.collisionShapes),r.collisionShapes.forEach((t=>{t instanceof e&&t.mesh instanceof d&&(t.mesh=t.mesh.geometry)})),r.castShadow=!1,r.receiveShadow=!1,this.scene.add(r)}for(const e of n.values()){if(0==e.length)continue;const t=e[0].object,s=await this.createFromShape(t),n=se(s,(e=>!ie(e)&&null!=e.geometry)),o=n.material.clone();null!=e[0].color&&null!=o.color&&(o.color=new r(16777215));const l=n.geometry,c=new a.InstancedMesh(l,o,e.length);for(let t=0;t<e.length;t++){const r=e[t],o=(new a.Matrix4).compose((new b).fromArray(r.object.position),(new g).setFromEuler((new i).fromArray(r.object.rotation)),(new b).fromArray(r.object.scale)),l=(new h).copy(r.object.parentTransform).multiply(o);c.setMatrixAt(t,l),null!=r.color&&c.setColorAt(t,r.color),c.castShadow=s.castShadow??!0,c.receiveShadow=n.receiveShadow??!0;const d=new re;d.add(c),d.userData.src=e[0],s instanceof oe&&(d.collisionShapes=[s.collisionShape]),d.castShadow=!1,d.receiveShadow=!1,this.scene.add(d)}}await Promise.all(t.map((e=>this.materialize(e)))),await this.initActorsPostInit()}async createInstancedMesh(e,t){const s=se(t,(e=>!ie(e)&&null!=e.geometry)),r=await this.assetsService.getAsset(e[0].assetId);await this.applyMaterials(t,Oe(e[0].materialAssignments,r.materialAssignments)),s.updateMatrix();const n=s.geometry.clone(),o=new a.InstancedMesh(n,s.material,e.length);for(let t=0;t<e.length;t++){const r=(new a.Matrix4).compose((new b).fromArray(e[t].position),(new g).setFromEuler((new i).fromArray(e[t].rotation)),(new b).fromArray(e[t].scale)),n=(new h).copy(e[t].parentTransform).multiply(r).multiply(s.matrixWorld);o.setMatrixAt(t,n)}return o.castShadow=e[0].castShadow??r.castShadow??!0,o.receiveShadow=e[0].receiveShadow??r.receiveShadow??!0,s.material instanceof c&&o.castShadow&&o.receiveShadow&&(o.material.side=a.FrontSide),o}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)}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 ae(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(R));ae(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 Ie.entries())t.userData.customShaderName&&Ie.delete(e);this.landscapeManagers.forEach((t=>t.updateShaders(e))),ae(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);Oe(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 r(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)}else"directional"===e.light.type?this.applyDirectionalLight(e.light.directional):"ambient"===e.light.type&&this.applyDirectionalAmbientLight(t,e.light.ambient);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 o?"density":"linear")!==e.fog.type;this.scene.fog=ke(e.fog),t&&(a=this.scene).traverse((e=>{if(e instanceof d){const t=e.material;t instanceof D&&(a.fog instanceof n?(t.uniforms.fogFar.value=a.fog.far,t.uniforms.fogNear.value=a.fog.near):a.fog instanceof o&&(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.editorActorParamSnapshot.get(e.id);null!=t&&t===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 oe&&(t.geometry=a.geometry,t.collisionShape=a.collisionShape)}("asset_mesh"===e.type||"shape_mesh"===e.type&&"landscape"!==e.shape)&&Pe(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)){console.log("materialize actor and init");const a=await this.materialize(e,t);return Fe(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:te(t,(t=>t.children?.some((t=>t.id===e.id))),(()=>!0))))[0];return null==t?this.scene:null!=t?ae(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 r(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=K(e.vertexMaterials,(e=>e.m));t.traverse((e=>{if(e instanceof d){if(null==e.geometry)return;if(Be(ue(e,0,!1)),a>0){Be(ue(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=ue(s,0,!0);Be(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=ue(s,4,!0);Be(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){let r,i;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=ke(e.fog),this.fixFogColor(),r=new l;break;case"sky":this.sky=Se(),this.updateSky(e),r=this.sky;break;case"world_env":this.updateWorldEnv(e),r=new l,this.worldEnvObj=r;break;case"actor":({object:r,actor:i}=await this.createFromActor(e));break;case"group":r=new l;break;case"prefab":r=await this.createFromPrefabAsset(e);break;case"vfx":r=await this.createFromVfx(e);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!=i&&(r.userData.actor=i),this.inEditor,this.inEditor){let e=null;r instanceof oe&&(e=function(e){if(e instanceof ne)return new d(new s(...e.offset.toArray()),_e);return null}(r.collisionShape)),null!=e&&(e.layers.disable(0),e.layers.enable(18),e.scale.multiplyScalar(1.1),r.add(e))}return this.objectMap.set(r.uuid,e),this.sceneObjectMap.set(e.id,r),e.physics?.type!==U.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==U.dynamic||Ne(r),this.renderingView.renderer.shadowMap.needsUpdate=!0,r}}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 s=e.worldEnv.environment;null!=s&&null!=s.textureId?this.assetManagerService.getTexture(this.assets.get(s.textureId)).then((e=>{null==this.pmremGenerator&&(this.pmremGenerator=new a.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=s.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=be);const t=await this.assetsService.getAsset(e.sky.materialId),s=await materialFromAsset(t,this.renderingView,this.assetsService,this.assetManagerService,this.shaders,!1);s.side=a.BackSide,(s instanceof u||s instanceof a.MeshBasicMaterial||s instanceof a.ShaderMaterial)&&(s.fog=!1),null!=this.sky?this.sky.material=s:console.warn("No sky has been created")}async createComponent(e,t,a,s){const r=new je[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){const t=this.actorTypes.find((t=>t.name===e.actor?.type))?.type??R[e.actor?.type];if(null==t)return{object:null,actor:null};this.inEditor&&this.editorActorParamSnapshot.set(e.id,JSON.stringify(e.actor));const a=await this.actorProvider.create(t,(new b).fromArray(e.position),(new i).fromArray(e.rotation),!0);return this.materializedActors.set(e.id,a),{object:a?.object,actor:a}}async createFromVfx(e){const t=await this.assetsService.getAsset(e.assetId);null==t&&console.error("Could not find asset",e);const a=await this.actorProvider.create(B,(new b).fromArray(e.position),(new i).fromArray(e.rotation),!1);return await a.fromAsset(t),a.play(),this.materializedActors.set(e.id,a),null!=a&&(a.object.userData.actor=a),a?.object}cleanup(){this.materializedActors.clear()}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 u({name:"Default",color:new r("#aaaaaa"),visible:this.inEditor||!e.hidden,wireframe:!!t});const i=await this.createMeshByShape(e.shape,s,e.shapeParams);i.castShadow=e.castShadow??!0,i.receiveShadow=e.castShadow??!1,e.collisionDetection||(i.collisionShape=null),i.physics=e.physics,a=i,this._originalMaterials.set(a.id,i.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 l;const a=ce(e.landscape.options);this.applyHeightMaps(a,e.landscape.heightMaps,!0);const s=new le(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 he(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((()=>de(r)),50)}async createMeshByShape(e,t,a={}){if("landscape"!==e&&we.includes(e)){const s=await prepareShapeParameters(a??{}),r=e+JSON.stringify(a);return this.geometryCache.has(r)||this.geometryCache.set(r,ge[e].geometry(s)),this.collisionShapeCache.has(r)||this.collisionShapeCache.set(r,ge[e].collision(s)),new oe(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});Oe(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,Pe(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 createFromPrefabAsset(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}`);const a=new l;return t.prefab.objects.filter((e=>"global_fog"!==e.type&&"world_env"!==e.type)).forEach((e=>this.materialize(e,a,!0))),a}async createParticleSystem(e){const t=await this.assetsService.getAsset(e.assetId),s=new f;return await M.fromJSONAsync(t.particleSystem,a).then((e=>{const t=new x(s,a);e.addRenderer(t),this.renderingView.onLoop((t=>e.update()))})),s}async createLight(e){if("point"===e.light.type){const t=new y(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 w(.3,10,10),a=new u({color:new r(16771709)}),s=new d(e,a);t.add(s)}return t}return"directional"===e.light.type?(this.applyDirectionalLight(e.light.directional),new l):"ambient"===e.light.type?(this.applyDirectionalAmbientLight(null,e.light.ambient),new l):void 0}applyDirectionalAmbientLight(e,t){const a=this.scene.children.find((e=>e.name===ve));null!=a?(a.intensity=t.intensity,a.color.set(t.color),a.groundColor.set(t.color)):console.warn("Couldn't find ambient light")}applyDirectionalLight(e){for(const t of this.renderingView.csm.lights)t.intensity=e.intensity,t.color.set(e.color),t.castShadow=e.castShadow;this.renderingView.csm.lightDirection.fromArray(e.direction).normalize()}dispose(){this.updateSubscription.unsubscribe(),this.createAssetSubscription.unsubscribe(),this.materializedActors.forEach((e=>e.disposed.next(!0)))}}function Pe(e,t,a){e.castShadow=t,e.receiveShadow=a,e.traverse((e=>{e.castShadow=t,e.receiveShadow=a}))}const Ie=new Map,Ee=new Map,De=new m({color:16711935}),Ve=new Map;export async function materialFromAsset(e,t,a,s,r,i=!0){const n=JSON.stringify(e.material);return i&&Ie.has(n)?Ie.get(n):i&&Ee.has(n)?await Ee.get(n):Ee.set(n,_materialFromAsset(n,e,t,a,s,r,i)).get(n)}export async function _materialFromAsset(e,t,s,i,n,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 r(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 i.getAsset(e);null!=a&&(c.map=await n.getTexture(a))}let d;switch(t.material.type){case"phong":d=new p({...c,...h});break;case"water":d=fe(c,s);break;case"grassFoliage":d=me({color:c.color,map:c.map},s);break;case"grass":d=pe({...c,colorTwo:new r(t.material.params.colorTwo),colorThree:new r(t.material.params.colorThree)},s);break;case"standard":case"unlit":case"lambert":case"shader":case"landscape":case"landscape-composite":case"decal-unlit":case"decal-standard":const e={standard:X,lambert:J,unlit:Y,landscape:q,"landscape-composite":H,"decal-unlit":Me,"decal-standard":xe}[t.material.type]??o.find((e=>e.name==t.material.shader))?.type;if(e){try{let a=new e;const r=await prepareClassParameters(t.material?.shaderParams??{},e,i,n,null,s,o);Object.assign(a,r),d=a.build()}catch(e){console.log("Shader runtime error: "+e),Ve.has(t.material.shader)||Ve.set(t.material.shader,De.clone()),d=Ve.get(t.material.shader)}d.userData.customShaderName=t.material.shader}else console.warn("Missing shader implementation with name "+t.material.shader),d=De;break;default:throw new Error("Unsupported material type"+t.material.type)}return s?.csm.setupMaterial(d),null!=s&&Ie.set(e,d),d.side=t.material.side??d.side??a.FrontSide,d.transparent=(t.material.transparent??c.transparent??!1)||d.transparent,d.alphaTest=t.material.alphaTest??d.alphaTest??0,t.material.bloom&&(d.userData.hasBloom=!0),d.userData.assetId=t.id,Ee.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 Ce(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 Ce(s,null,null,null);null!=e&&(t[a]=e)}return t}async function Ce(e,t,a,s,n,o,l,c=e.value,h=e.type){if(null==e||null==c||""===c)return null;switch(h){case ye.Array:if(Array.isArray(c)&&"element"in e)return await Promise.all(c.map((r=>Ce(e,t,a,s,n,o,l,r,e.element))));break;case ye.Number:case ye.FloatNode:let h="string"==typeof c?parseFloat(c):c;return e.type===ye.FloatNode?I(h):h;case ye.Texture:return await a.getTexture(await t.getAsset(c));case ye.Sampler2DNode:return k(await a.getTexture(await t.getAsset(c)));case ye.Boolean:return c;case ye.BooleanNode:return j(c);case ye.Vector2:case ye.Vec2Node:if("object"==typeof c){const t=c instanceof Array?(new S).fromArray(c):new S(c.x,c.y);return e.type===ye.Vec2Node?_(t):t}return null;case ye.Vector3:case ye.Vec3Node:if("object"==typeof c){const t=c instanceof Array?(new b).fromArray(c):new b(c.x,c.y,c.z);return e.type===ye.Vec3Node?O(t):t}return null;case ye.Color:case ye.RgbNode:const d=new r(c);return e.type===ye.RgbNode?V(d):d;case ye.String:return c;case ye.BaseActor:const m=c;return null==s&&console.warn("Class parameters can not be prepared as actors are not passed in"),s?.get(m);case ye.Euler:const p=c;return(new i).fromArray(p);case ye.Object3D:return(await a.getMesh(await t.getAsset(c))).scene;case ye.Material:return await materialFromAsset(await t.getAsset(c),n,t,a,o);case ye.AudioBuffer:return await a.getAudio(await t.getAsset(c));case ye.VisualEffect:const u=await t.getAsset(c);if(null==l){console.error("Can not create instance of visual effect because missing actor provider");break}if("vfx"in u)return new W(l,u);console.error("Using a non-vfx asset for visual effect parameter");break;case ye.Curve:return Ae.decode(c)}return null}function Ne(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 ke(e){return"linear"===e.type?new n(new r(e.color),e.near??100,e.far??1e3):"density"===e.type?new o(e.color,e.density):void console.warn("Invalid fog type",e)}const _e=new u({color:4229780});async function Fe(e,t,s,r){null==r&&(r=(new h).identity()),await t(e,s,r);const n=r.clone().multiply(function(e,t){if(null==e.position||null==e.rotation||null==e.scale)return t.identity();return t.compose((new b).fromArray(e.position),(new g).setFromEuler((new i).fromArray(e.rotation)),(new b).fromArray(e.scale))}(e,new a.Matrix4));return Promise.all((e.children??[]).map((a=>Fe(a,t,e,n))))}export function toSerializedParamType(e){const t=e.constructor.prototype;return t instanceof Number||e===Number?ye.Number:t instanceof E||"function"==typeof e.prototype.isFloat?ye.FloatNode:t instanceof v||e===v||e.isTexture?ye.Texture:t instanceof L||e===N?ye.Sampler2DNode:t instanceof Boolean||e===Boolean?ye.Boolean:t instanceof P?ye.BooleanNode:t instanceof r||e==r?ye.Color:t instanceof C||"function"==typeof e.prototype.isRgb?ye.RgbNode:t instanceof S||e==S?ye.Vector2:t instanceof F||"function"==typeof e.prototype.isVec2?ye.Vec2Node:t instanceof b||e==b?ye.Vector3:t instanceof T||"function"==typeof e.prototype.isVec3?ye.Vec3Node:t instanceof String||e===String?ye.String:t instanceof $||e==$||e.prototype instanceof $||e.prototype==$?ye.BaseActor:t instanceof i||e==i?ye.Euler:t instanceof f||e==f?ye.Object3D:t instanceof c||e==c?ye.Material:t instanceof AudioBuffer||e==AudioBuffer?ye.AudioBuffer:t instanceof W||e==W?ye.VisualEffect:t instanceof Ae||e==Ae?ye.Curve: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?ye.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=Z(e);if(0===s.length)return{};let r;null!=a?G(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 b:return t instanceof b?t.toArray():void a();case A:return t instanceof A?t.toArray():void a();case r:return t instanceof r?"#"+t.getHexString():"string"==typeof t?t:"number"==typeof t?"#"+new r(t).getHexString():void a();case String:return t;case i:return t instanceof i?t.toArray():void a()}}function Oe(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=>Te(e.materialId))),(t??[]).filter((e=>Te(e.materialId))),(e=>e.color+e.name))}function Te(e){return"null"!=e&&null!=e}export const customParameterDefaultValueByType=new Map([[ye.RgbNode,"#000000"],[ye.Color,"#000000"],[ye.Vector4,[0,0,0,0]],[ye.Vec4Node,[0,0,0,0]],[ye.Vector3,[0,0,0]],[ye.Vec3Node,[0,0,0]],[ye.Vector2,[0,0]],[ye.Vec2Node,[0,0]],[ye.Euler,[0,0,0,"XYZ"]],[ye.Array,[]]]);export function applyMaterial(e,t,s,i){const n=[];return e.traverse((async e=>{if(e instanceof d||e.isMesh||e instanceof a.SkinnedMesh||e.isSkinnedMesh)for(const t of ee(e.material))t.hasOwnProperty("color")&&n.push(e)})),Promise.all(n.map((async e=>{if(e.material instanceof Array)for(let a=0;a<e.material.length;a++){const n=e.material[a];if(null==n.color||!(n.color instanceof r))continue;const o="#"+n.color.getHexString(),l=n.name;if(o===t.color&&(n.name===t.name||null==t.name)||e.userData["originalColor_"+a]===t.color&&e.userData["originalMaterialName_"+a]===t.name){const r=await s(t.materialId),n=e.material[a];null!=r&&n.id!=r.id&&(e.material[a]=r,e.userData["originalColor_"+a]=e.userData["originalColor_"+a]??o,e.userData["originalMaterialName_"+a]=e.userData["originalMaterialName_"+a]??l,null!=i&&i.set(e.id+"#"+a,n))}}else if("color"in e.material){const a="#"+e.material.color.getHexString(),r=e.material.name;if(a===t.color&&(e.material.name===t.name||null==t.name)||e.userData.originalColor===t.color&&e.userData.originalName===t.name){const n=await s(t.materialId),o=e.material;null!=n&&(e.material=n,e.userData.originalColor=e.userData.originalColor??a,e.userData.originalMaterialName=e.userData.originalMaterialName??r,null!=i&&(i.has(e.id)||i.set(e.id,o)))}}})))}function ze(e,t){if(e instanceof a.ShaderMaterial&&t instanceof a.ShaderMaterial){return e.fragmentShader+e.vertexShader==t.fragmentShader+t.vertexShader&&function(e,t){if(e instanceof a.ShaderMaterial&&t instanceof a.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 Be(e){if(null!=e){for(let t=0;t<e.array.length;t++)e.setX(t,0);e.needsUpdate=!0}}/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -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;AAIhD,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;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACzC,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,WAAW,CAAC,EAAE,OAAO,CAAC;IAInC,MAAM;;;IA4DN,KAAK;CASN"}
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;AAIhD,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,CAAC;IAInC,MAAM;;;IA4DN,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 d,uniforms as n,normalize as h,varying as m}from"three-shader-graph";import{decalAlpha as y,decalNormal as c,decalUV as u}from"../../shader-nodes/decal.js";import{depthWorldPosition as S}from"../../shader-nodes/depth.js";import{DecalNodeShader as g}from"../decal-shader.js";import{Parameter as v}from"../parameter.js";export class DecalStandardShader extends g{constructor(){super(...arguments),this.color=new a("#FFFFFF"),this.opacity=1,this.roughness=1,this.metalness=0}output(){const e=u;let t=i(this.opacity);null!=this.alphaMap&&(t=t.multiply(d(this.alphaMap).sample(e).r)),t=t.multiply(y);let a=p(this.color,t);null!=this.colorMap&&(a=a.multiply(d(this.colorMap).sample(e)));let s=p(this.emissive,t);null!=this.emissiveMap&&(s=s.multiply(d(this.emissiveMap).sample(e)));let r=i(this.roughness);null!=this.roughnessMap&&(r=r.multiply(d(this.roughnessMap).sample(e).g));let g=i(this.metalness);null!=this.metalnessMap&&(g=g.multiply(d(this.metalnessMap).sample(e).b));let v=h(m(n.normalMatrix).multiplyVec(c));null!=this.normalMap&&(v=o(d(this.normalMap).sample(e),this.normalScale?.x??1,v,S,e));let M=null;return null!=this.aoMap&&(M=d(this.aoMap).sample(e).r),{color:l({color:a,emissive:s,emissiveIntensity:i(this.emissiveIntensity??1),roughness:r,metalness:g,normal:v,ambientOcclusion:M,ambientOcclusionIntensity:i(this.aoMapIntensity??1),worldPosition:S})}}build(){const e=super.build();return e.depthTest=!0,e.depthWrite=!1,e.userData.isDecal=!0,e}}e([v(),t("design:type",a)],DecalStandardShader.prototype,"color",void 0),e([v({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"opacity",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"colorMap",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"alphaMap",void 0),e([v({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"roughness",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"roughnessMap",void 0),e([v({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"metalness",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"metalnessMap",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"aoMap",void 0),e([v(),t("design:type",Number)],DecalStandardShader.prototype,"aoMapIntensity",void 0),e([v(),t("design:type",a)],DecalStandardShader.prototype,"emissive",void 0),e([v({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"emissiveIntensity",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"emissiveMap",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"normalMap",void 0),e([v(),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 d,uniforms as n,normalize as h,varying as m}from"three-shader-graph";import{decalAlpha as y,decalNormal as c,decalUV as u}from"../../shader-nodes/decal.js";import{depthWorldPosition as S}from"../../shader-nodes/depth.js";import{DecalNodeShader as g}from"../decal-shader.js";import{Parameter as v}from"../parameter.js";export class DecalStandardShader extends g{constructor(){super(...arguments),this.color=new a("#FFFFFF"),this.opacity=1,this.roughness=1,this.metalness=0}output(){const e=u;let t=i(this.opacity);null!=this.alphaMap&&(t=t.multiply(d(this.alphaMap).sample(e).r)),t=t.multiply(y);let a=p(this.color,t);null!=this.colorMap&&(a=a.multiply(d(this.colorMap).sample(e)));let s=p(this.emissive,t);null!=this.emissiveMap&&(s=s.multiply(d(this.emissiveMap).sample(e)));let r=i(this.roughness);null!=this.roughnessMap&&(r=r.multiply(d(this.roughnessMap).sample(e).g));let g=i(this.metalness);null!=this.metalnessMap&&(g=g.multiply(d(this.metalnessMap).sample(e).b));let v=h(m(n.normalMatrix).multiplyVec(c));null!=this.normalMap&&(v=o(d(this.normalMap).sample(e),this.normalScale?.x??1,v,S,e));let M=null;return null!=this.aoMap&&(M=d(this.aoMap).sample(e).r),{color:l({color:a,emissive:s,emissiveIntensity:i(this.emissiveIntensity??1),roughness:r,metalness:g,normal:v,ambientOcclusion:M,ambientOcclusionIntensity:i(this.aoMapIntensity??1),worldPosition:S})}}build(){const e=super.build();return e.depthTest=!0,e.depthWrite=!1,e.userData.isDecal=!0,e}}e([v(),t("design:type",a)],DecalStandardShader.prototype,"color",void 0),e([v({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"opacity",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"colorMap",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"alphaMap",void 0),e([v({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"roughness",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"roughnessMap",void 0),e([v({range:[0,1]}),t("design:type",Number)],DecalStandardShader.prototype,"metalness",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"metalnessMap",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"aoMap",void 0),e([v(),t("design:type",Number)],DecalStandardShader.prototype,"aoMapIntensity",void 0),e([v(),t("design:type",a)],DecalStandardShader.prototype,"emissive",void 0),e([v({range:[0,10]}),t("design:type",Number)],DecalStandardShader.prototype,"emissiveIntensity",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"emissiveMap",void 0),e([v(),t("design:type",s)],DecalStandardShader.prototype,"normalMap",void 0),e([v(),t("design:type",r)],DecalStandardShader.prototype,"normalScale",void 0);/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -3,6 +3,7 @@ import { DecalNodeShader } from '../decal-shader.js';
3
3
  export declare class DecalUnlitShader extends DecalNodeShader {
4
4
  color: Color;
5
5
  opacity: number;
6
+ intensity: number;
6
7
  colorMap?: Texture;
7
8
  alphaMap?: Texture;
8
9
  output(): {
@@ -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,EAAqE,OAAO,EAAW,MAAM,OAAO,CAAC;AAIlK,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD,qBAAa,gBAAiB,SAAQ,eAAe;IACtC,KAAK,EAAE,KAAK,CAAwB;IACtB,OAAO,EAAE,MAAM,CAAI;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEhC,MAAM;;;CAoBP"}
1
+ {"version":3,"file":"decal-unlit-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/decal-unlit-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,EAAqE,OAAO,EAAW,MAAM,OAAO,CAAC;AAIlK,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;;;CAsBP"}
@@ -1,4 +1,4 @@
1
- import{__decorate as t,__metadata as o}from"tslib";import{Color as e,Texture as r}from"three";import{Parameter as p}from"../parameter.js";import{DecalNodeShader as l}from"../decal-shader.js";import{rgba as a,textureSampler2d as i,float as s}from"three-shader-graph";import{decalAlpha as h,decalUV as c}from"../../shader-nodes/decal.js";export class DecalUnlitShader extends l{constructor(){super(...arguments),this.color=new e("#FFFFFF"),this.opacity=1}output(){const t=c;let o=s(this.opacity);null!=this.alphaMap&&(o=o.multiply(i(this.alphaMap).sample(t).r)),o=o.multiply(h);let e=a(this.color,o);return null!=this.colorMap&&(e=e.multiply(i(this.colorMap).sample(t))),{color:e}}}t([p(),o("design:type",e)],DecalUnlitShader.prototype,"color",void 0),t([p({range:[0,1]}),o("design:type",Number)],DecalUnlitShader.prototype,"opacity",void 0),t([p(),o("design:type",r)],DecalUnlitShader.prototype,"colorMap",void 0),t([p(),o("design:type",r)],DecalUnlitShader.prototype,"alphaMap",void 0);/*
1
+ import{__decorate as t,__metadata as e}from"tslib";import{Color as r,Texture as o}from"three";import{Parameter as i}from"../parameter.js";import{DecalNodeShader as p}from"../decal-shader.js";import{rgba as a,textureSampler2d as l,float as s}from"three-shader-graph";import{decalAlpha as n,decalUV as h}from"../../shader-nodes/decal.js";export class DecalUnlitShader extends p{constructor(){super(...arguments),this.color=new r("#FFFFFF"),this.opacity=1,this.intensity=1}output(){const t=h;let e=s(this.opacity);null!=this.alphaMap&&(e=e.multiply(l(this.alphaMap).sample(t).r)),e=e.multiply(n);let r=a(this.color,e);return null!=this.colorMap&&(r=r.multiply(l(this.colorMap).sample(t))),r=a(r.rgb.multiplyScalar(this.intensity),r.a),{color:r}}}t([i(),e("design:type",r)],DecalUnlitShader.prototype,"color",void 0),t([i({range:[0,1]}),e("design:type",Number)],DecalUnlitShader.prototype,"opacity",void 0),t([i({range:[0,10]}),e("design:type",Number)],DecalUnlitShader.prototype,"intensity",void 0),t([i(),e("design:type",o)],DecalUnlitShader.prototype,"colorMap",void 0),t([i(),e("design:type",o)],DecalUnlitShader.prototype,"alphaMap",void 0);/*
2
2
  * Copyright (©) 2023. 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,EAAwC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKtC,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;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACzC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IAKpD,KAAK,IAAI,QAAQ;CAkClB"}
1
+ {"version":3,"file":"standard-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/standard-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAwC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAKtC,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;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IAKpD,KAAK,IAAI,QAAQ;CAkClB"}
@@ -1,4 +1,4 @@
1
- import{__decorate as e,__metadata as t}from"tslib";import{Color as a,MeshStandardMaterial as p,Texture as i,Vector2 as d}from"three";import{Shader as r}from"../shader.js";import{Parameter as s}from"../parameter.js";import{removeObjectUndefined as o}from"../../utils/collections.js";export class StandardShader extends r{constructor(){super(...arguments),this.color=new a("#FFFFFF"),this.opacity=1,this.roughness=1,this.metalness=0}build(){return new p(o({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([s(),t("design:type",a)],StandardShader.prototype,"color",void 0),e([s({label:"Color Map"}),t("design:type",i)],StandardShader.prototype,"map",void 0),e([s({range:[0,1]}),t("design:type",Number)],StandardShader.prototype,"opacity",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"alphaMap",void 0),e([s({range:[0,1]}),t("design:type",Number)],StandardShader.prototype,"roughness",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"roughnessMap",void 0),e([s({range:[0,1]}),t("design:type",Number)],StandardShader.prototype,"metalness",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"metalnessMap",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"lightMap",void 0),e([s(),t("design:type",Number)],StandardShader.prototype,"lightMapIntensity",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"aoMap",void 0),e([s(),t("design:type",Number)],StandardShader.prototype,"aoMapIntensity",void 0),e([s(),t("design:type",a)],StandardShader.prototype,"emissive",void 0),e([s({range:[0,1]}),t("design:type",Number)],StandardShader.prototype,"emissiveIntensity",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"emissiveMap",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"bumpMap",void 0),e([s(),t("design:type",Number)],StandardShader.prototype,"bumpScale",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"normalMap",void 0),e([s(),t("design:type",d)],StandardShader.prototype,"normalScale",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"displacementMap",void 0),e([s(),t("design:type",Number)],StandardShader.prototype,"displacementScale",void 0),e([s(),t("design:type",Number)],StandardShader.prototype,"displacementBias",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"envMap",void 0),e([s({range:[0,1]}),t("design:type",Number)],StandardShader.prototype,"envMapIntensity",void 0),e([s({range:[0,1]}),t("design:type",Number)],StandardShader.prototype,"refractionRatio",void 0);/*
1
+ import{__decorate as e,__metadata as t}from"tslib";import{Color as a,MeshStandardMaterial as p,Texture as i,Vector2 as d}from"three";import{Shader as r}from"../shader.js";import{Parameter as s}from"../parameter.js";import{removeObjectUndefined as o}from"../../utils/collections.js";export class StandardShader extends r{constructor(){super(...arguments),this.color=new a("#FFFFFF"),this.opacity=1,this.roughness=1,this.metalness=0}build(){return new p(o({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([s(),t("design:type",a)],StandardShader.prototype,"color",void 0),e([s({label:"Color Map"}),t("design:type",i)],StandardShader.prototype,"map",void 0),e([s({range:[0,1]}),t("design:type",Number)],StandardShader.prototype,"opacity",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"alphaMap",void 0),e([s({range:[0,1]}),t("design:type",Number)],StandardShader.prototype,"roughness",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"roughnessMap",void 0),e([s({range:[0,1]}),t("design:type",Number)],StandardShader.prototype,"metalness",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"metalnessMap",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"lightMap",void 0),e([s(),t("design:type",Number)],StandardShader.prototype,"lightMapIntensity",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"aoMap",void 0),e([s(),t("design:type",Number)],StandardShader.prototype,"aoMapIntensity",void 0),e([s(),t("design:type",a)],StandardShader.prototype,"emissive",void 0),e([s({range:[0,10]}),t("design:type",Number)],StandardShader.prototype,"emissiveIntensity",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"emissiveMap",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"bumpMap",void 0),e([s(),t("design:type",Number)],StandardShader.prototype,"bumpScale",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"normalMap",void 0),e([s(),t("design:type",d)],StandardShader.prototype,"normalScale",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"displacementMap",void 0),e([s(),t("design:type",Number)],StandardShader.prototype,"displacementScale",void 0),e([s(),t("design:type",Number)],StandardShader.prototype,"displacementBias",void 0),e([s(),t("design:type",i)],StandardShader.prototype,"envMap",void 0),e([s({range:[0,1]}),t("design:type",Number)],StandardShader.prototype,"envMapIntensity",void 0),e([s({range:[0,1]}),t("design:type",Number)],StandardShader.prototype,"refractionRatio",void 0);/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -3,6 +3,7 @@ import { Shader } from '../shader.js';
3
3
  export declare class UnlitShader extends Shader {
4
4
  color: Color;
5
5
  opacity: number;
6
+ intensity: number;
6
7
  map?: Texture;
7
8
  lightMap?: Texture;
8
9
  lightMapIntensity?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"unlit-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/unlit-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,EAAE,QAAQ,EAA2D,OAAO,EAAW,MAAM,OAAO,CAAC;AAClK,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,qBAAa,WAAY,SAAQ,MAAM;IACxB,KAAK,EAAE,KAAK,CAAwB;IACtB,OAAO,EAAE,MAAM,CAAI;IACjC,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IAKzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACK,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGpD,KAAK,IAAI,QAAQ;CAkBlB"}
1
+ {"version":3,"file":"unlit-shader.d.ts","sourceRoot":"","sources":["../../../src/shader/builtin/unlit-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiD,KAAK,EAAE,QAAQ,EAA2D,OAAO,EAAW,MAAM,OAAO,CAAC;AAClK,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC,qBAAa,WAAY,SAAQ,MAAM;IACxB,KAAK,EAAE,KAAK,CAAwB;IACtB,OAAO,EAAE,MAAM,CAAI;IAClB,SAAS,EAAE,MAAM,CAAI;IACpC,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IAKzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACK,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGpD,KAAK,IAAI,QAAQ;CAkBlB"}
@@ -1,4 +1,4 @@
1
- import{__decorate as t,__metadata as e}from"tslib";import{AddOperation as i,MultiplyOperation as o,MixOperation as p,Color as a,MeshBasicMaterial as r,Texture as n}from"three";import{Shader as s}from"../shader.js";import{Parameter as d}from"../parameter.js";import{removeObjectUndefined as l}from"../../utils/collections.js";export class UnlitShader extends s{constructor(){super(...arguments),this.color=new a("#FFFFFF"),this.opacity=1}build(){return new r(l({color:this.color,opacity:this.opacity,map:this.map,lightMap:this.lightMap,lightMapIntensity:this.lightMapIntensity,aoMap:this.aoMap,aoMapIntensity:this.aoMapIntensity,specularMap:this.specularMap,alphaMap:this.alphaMap,envMap:this.envMap,combine:this.combine,reflectivity:this.reflectivity,refractionRatio:this.refractionRatio}))}}t([d(),e("design:type",a)],UnlitShader.prototype,"color",void 0),t([d({range:[0,1]}),e("design:type",Number)],UnlitShader.prototype,"opacity",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"map",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"lightMap",void 0),t([d(),e("design:type",Number)],UnlitShader.prototype,"lightMapIntensity",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"aoMap",void 0),t([d(),e("design:type",Number)],UnlitShader.prototype,"aoMapIntensity",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"specularMap",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"alphaMap",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"envMap",void 0),t([d({options:[{name:"Mix",value:p},{name:"Multiply",value:o},{name:"Add",value:i}]}),e("design:type",Number)],UnlitShader.prototype,"combine",void 0),t([d({range:[0,1]}),e("design:type",Number)],UnlitShader.prototype,"reflectivity",void 0),t([d({range:[0,1]}),e("design:type",Number)],UnlitShader.prototype,"refractionRatio",void 0);/*
1
+ import{__decorate as t,__metadata as e}from"tslib";import{AddOperation as i,MultiplyOperation as p,MixOperation as o,Color as a,MeshBasicMaterial as r,Texture as n}from"three";import{Shader as s}from"../shader.js";import{Parameter as d}from"../parameter.js";import{removeObjectUndefined as l}from"../../utils/collections.js";export class UnlitShader extends s{constructor(){super(...arguments),this.color=new a("#FFFFFF"),this.opacity=1,this.intensity=1}build(){return new r(l({color:this.color.multiplyScalar(this.intensity),opacity:this.opacity,map:this.map,lightMap:this.lightMap,lightMapIntensity:this.lightMapIntensity,aoMap:this.aoMap,aoMapIntensity:this.aoMapIntensity,specularMap:this.specularMap,alphaMap:this.alphaMap,envMap:this.envMap,combine:this.combine,reflectivity:this.reflectivity,refractionRatio:this.refractionRatio}))}}t([d(),e("design:type",a)],UnlitShader.prototype,"color",void 0),t([d({range:[0,1]}),e("design:type",Number)],UnlitShader.prototype,"opacity",void 0),t([d({range:[0,10]}),e("design:type",Number)],UnlitShader.prototype,"intensity",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"map",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"lightMap",void 0),t([d(),e("design:type",Number)],UnlitShader.prototype,"lightMapIntensity",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"aoMap",void 0),t([d(),e("design:type",Number)],UnlitShader.prototype,"aoMapIntensity",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"specularMap",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"alphaMap",void 0),t([d(),e("design:type",n)],UnlitShader.prototype,"envMap",void 0),t([d({options:[{name:"Mix",value:o},{name:"Multiply",value:p},{name:"Add",value:i}]}),e("design:type",Number)],UnlitShader.prototype,"combine",void 0),t([d({range:[0,1]}),e("design:type",Number)],UnlitShader.prototype,"reflectivity",void 0),t([d({range:[0,1]}),e("design:type",Number)],UnlitShader.prototype,"refractionRatio",void 0);/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -1,4 +1,6 @@
1
1
  export * from './parameter.js';
2
2
  export * from './builtin/index.js';
3
3
  export * from './shader.js';
4
+ export * from './decal-shader.js';
5
+ export * from './sprite-shader.js';
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shader/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shader/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA"}
@@ -1,4 +1,4 @@
1
- export*from"./parameter.js";export*from"./builtin/index.js";export*from"./shader.js";/*
1
+ export*from"./parameter.js";export*from"./builtin/index.js";export*from"./shader.js";export*from"./decal-shader.js";export*from"./sprite-shader.js";/*
2
2
  * Copyright (©) 2023. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -0,0 +1,17 @@
1
+ import { Material } from "three";
2
+ import { NodeShaderMaterial } from "../shader-nodes/index.js";
3
+ import { NodeShaderOutput } from "./shader.js";
4
+ import { Vec4Node, FloatNode } from 'three-shader-graph';
5
+ import * as THREE from 'three';
6
+ export declare abstract class SpriteNodeShader {
7
+ build(): Material;
8
+ abstract output(): NodeShaderOutput;
9
+ }
10
+ export declare function getSpritePosition(rotation: FloatNode): Vec4Node;
11
+ export declare class SpriteNodeShaderMaterial extends NodeShaderMaterial {
12
+ get color(): THREE.ColorRepresentation;
13
+ set color(value: THREE.ColorRepresentation);
14
+ get rotation(): number;
15
+ set rotation(value: number);
16
+ }
17
+ //# sourceMappingURL=sprite-shader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sprite-shader.d.ts","sourceRoot":"","sources":["../../src/shader/sprite-shader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAC,QAAQ,EAAyD,SAAS,EAAO,MAAM,oBAAoB,CAAC;AACpH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,8BAAsB,gBAAgB;IACpC,KAAK,IAAI,QAAQ;IAwBjB,QAAQ,CAAC,MAAM,IAAI,gBAAgB;CACpC;AAGD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,SAAS,YAoBpD;AAED,qBAAa,wBAAyB,SAAQ,kBAAkB;IAE9D,IAAI,KAAK,IAGQ,KAAK,CAAC,mBAAmB,CADzC;IACD,IAAI,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,mBAAmB,EAEzC;IACD,IAAI,QAAQ,IAGQ,MAAM,CADzB;IACD,IAAI,QAAQ,CAAC,KAAK,EAAE,MAAM,EAEzB;CACF"}
@@ -0,0 +1,4 @@
1
+ import{NodeShaderMaterial as o}from"../shader-nodes/index.js";import{Vec4Node as t,glslFunction as e,transformed as i,uniforms as r,UniformFloatNode as n}from"three-shader-graph";import*as a from"three";export class SpriteNodeShader{build(){const o=this.output(),t=getSpritePosition(new n("rotation",0));return new SpriteNodeShaderMaterial({color:o.color,discard:o.discard,transparent:o.transparent??!0,position:t,uniforms:{color:{value:new a.Color(0)}}})}}export function getSpritePosition(o){return e(t,{position:i.position,modelViewMatrix:r.modelViewMatrix,rotation:o},"\n vec2 center = vec2(0.5, 0.5);\n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n // Using scale form instance matrix instead of modelMatrix\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n \n // This times 2 on scale seem to make it appear like when using regular sprites. \n // Not sure if this is correct though.\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * (scale);\n \n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n \n mvPosition.xy += rotatedPosition;\n return projectionMatrix * mvPosition;\n ")}export class SpriteNodeShaderMaterial extends o{get color(){return this.uniforms.color.value}set color(o){this.uniforms.color.value=new a.Color(o)}get rotation(){return this.uniforms.rotation.value}set rotation(o){this.uniforms.rotation.value=o}}/*
2
+ * Copyright (©) 2023. All rights reserved.
3
+ * See the LICENSE.md file for details.
4
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hology/core",
3
- "version": "0.0.96",
3
+ "version": "0.0.98",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -168,7 +168,7 @@
168
168
  "dependencies": {
169
169
  "@babel/runtime": "^7.24.8",
170
170
  "@dimforge/rapier3d-compat": "^0.14.0",
171
- "@hology/nebula": "^0.0.96",
171
+ "@hology/nebula": "^0.0.98",
172
172
  "@plumier/reflect": "^1.1.0",
173
173
  "@recast-navigation/three": "^0.35.2",
174
174
  "recast-navigation": "^0.35.2",