@hology/core 0.0.125 → 0.0.127

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.
@@ -1 +1 @@
1
- {"version":3,"file":"navmesh-actor.d.ts","sourceRoot":"","sources":["../../../../src/gameplay/actors/builtin/navmesh-actor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAK5C,OAAO,EAAS,SAAS,EAAmE,MAAM,QAAQ,CAAC;AAe3G,wBAAsB,cAAc,4BASnC;AASD,MAAM,MAAM,aAAa,GAAG;IAO1B,IAAI,QAAE;CACP,CAAA;AAID,cACM,YAAa,SAAQ,SAAS;IAClC,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,IAAI,CAAyB;IACrC,OAAO,CAAC,KAAK,CAAgB;IAE7B,OAAO,CAAC,mBAAmB,CAA4B;IAE1C,KAAK,EAAE,OAAO,CAAO;IAElC,SAAS,EAAE,MAAM,CAAO;IAIxB,OAAO,CAAC,QAAQ,CAAa;IAIhB,aAAa,EAAE,MAAM,CAAK;IACV,kBAAkB,EAAE,MAAM,CAAK;IAI5B,QAAQ,EAAE,MAAM,CAAM;IAG/C,OAAO,EAAE,OAAO,CAAA;IACvB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,gBAAgB,CAAgB;IAGlC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IA6B7B,SAAS,IAAI,IAAI;IAIjB,OAAO,CAAC,IAAI;CAyPb;AAED,eAAe,YAAY,CAAA"}
1
+ {"version":3,"file":"navmesh-actor.d.ts","sourceRoot":"","sources":["../../../../src/gameplay/actors/builtin/navmesh-actor.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAK5C,OAAO,EAAS,SAAS,EAAmE,MAAM,QAAQ,CAAC;AAe3G,wBAAsB,cAAc,4BASnC;AASD,MAAM,MAAM,aAAa,GAAG;IAO1B,IAAI,QAAE;CACP,CAAA;AAID,cACM,YAAa,SAAQ,SAAS;IAClC,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,IAAI,CAAyB;IACrC,OAAO,CAAC,KAAK,CAAgB;IAE7B,OAAO,CAAC,mBAAmB,CAA4B;IAE1C,KAAK,EAAE,OAAO,CAAO;IAElC,SAAS,EAAE,MAAM,CAAO;IAIxB,OAAO,CAAC,QAAQ,CAAa;IAIhB,aAAa,EAAE,MAAM,CAAK;IACV,kBAAkB,EAAE,MAAM,CAAK;IAI5B,QAAQ,EAAE,MAAM,CAAM;IAG/C,OAAO,EAAE,OAAO,CAAA;IACvB,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,gBAAgB,CAAgB;IAGlC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IA6B7B,SAAS,IAAI,IAAI;IAIjB,OAAO,CAAC,IAAI;CAgQb;AAED,eAAe,YAAY,CAAA"}
@@ -1,4 +1,4 @@
1
- import{__decorate as e,__metadata as t}from"tslib";import{Ball as n,Capsule as o,Cone as s,ConvexPolyhedron as i,Cuboid as r,Cylinder as a,Heightfield as c,ShapeType as l,TriMesh as h}from"@dimforge/rapier3d-compat";import{init as p}from"@recast-navigation/core";import{DebugDrawer as u,getPositionsAndIndices as d}from"@recast-navigation/three";import{BehaviorSubject as m,Subject as f,debounceTime as w,filter as b,firstValueFrom as g,takeUntil as y}from"rxjs";import*as x from"three";import{BufferGeometryUtils as v,ConvexHull as B}from"three/examples/jsm/Addons.js";import{Actor as M,BaseActor as S,Parameter as z,PhysicsSystem as A,ViewController as C,World as j,attach as k,inject as F}from"../../";import{sleepDelay as I}from"../../../utils/async";import{hasSharedArrayBufferSupport as P,toSharedFloat32Array as V,toSharedUint32Array as G}from"../../../utils/buffer";import{DynamicTiledNavMesh as N}from"../../ai/dynamic-tiled-navmesh";import{TriggerVolumeMesh as D}from"./components/volume-editor-component";var E;!function(e){e[e.none=0]="none",e[e.starting=1]="starting",e[e.started=2]="started"}(E||(E={}));let H=E.none,R=new m(!1);export async function safeRecastInit(){return H===E.none?(H=E.starting,p().then((()=>{R.next(!0),H=E.started}))):g(R.pipe(b((e=>e))))}new x.Box3(new x.Vector3(-100,-100,-100),new x.Vector3(100,100,100));const T=navigator.hardwareConcurrency??1;let U=!1,q=class extends S{constructor(){super(...arguments),this.physics=F(A),this.view=F(C),this.world=F(j),this.editorVisualisation=k(D),this.debug=!0,this.refreshMs=4e3,this.tileSize=50,this.walkableClimb=.3,this.walkableSlopeAngle=45,this.cellSize=.2,this.bounds=new x.Box3}async onInit(){U||(await safeRecastInit(),U=!0),setTimeout((()=>{this.init()}),10),this.recreateInterval=setInterval((()=>{if("_hology_transform_group"===this.object.parent?.name)return;X.setFromCenterAndSize(this.position,this.object.scale).equals(this.bounds)||(this.disposed.next(!0),this.disposed=new f,this.init())}),2e3)}onEndPlay(){clearInterval(this.recreateInterval)}init(){this.bounds.setFromCenterAndSize(this.position,this.object.scale),console.log(this.bounds);const e=Math.min(Math.ceil(Math.min(this.bounds.max.x-this.bounds.min.x,this.bounds.max.z-this.bounds.min.z)),400),t=Math.max(this.cellSize,.01),n={tileSize:e,walkableClimb:this.walkableClimb/t,walkableSlopeAngle:this.walkableSlopeAngle,walkableRadius:2,walkableHeight:5,detailSampleDist:1,minRegionArea:6,mergeRegionArea:400,cs:t,ch:t,maxSimplificationError:1.3,maxEdgeLen:200},o=new N({navMeshBounds:this.bounds,recastConfig:n,maxTiles:1024,workers:T,cacheId:"nav"+this.object.userData?.src?.id});this.navMesh=o.navMesh;const s=this.tileSize*n.cs*2,i=performance.now(),r=new Map,a=new u;a.userData.isDebugDrawer=!0;o.navMesh;const c=this.bounds,l=()=>{const e=this.view.getCamera().getWorldPosition(new x.Vector3),t=new x.Box3((new x.Vector3).copy(e).subScalar(s),(new x.Vector3).copy(e).addScalar(s)),n=[],o=this.physics.world.bodies;if(null==o)return[];const i=new x.Box3;for(const e of o.getAll())for(let o=0,s=e.numColliders();o<s;o++){const s=e.collider(o);if(s.isSensor()||null!=s.parent().userData&&!0===s.parent().userData.ignoreForNavMesh)continue;const a=e.handle+","+o,c=r.get(a)?.mesh,l=c??O(s);if(W(s,l),null!=l){i.copy(l.geometry.boundingBox),i.min.add(l.position),i.max.add(l.position);const e=i.intersectsBox(t)||!0,o=i.intersectsBox(this.bounds);r.set(a,{pos:s.translation(),mesh:l}),e&&o&&n.push(l)}}return n},h=new x.Box3,p=new Map,m=new Map;let f=!0,b=performance.now(),g=!1;const v=function(e,t){let n=!1;return(async()=>{for(;!n;)await e(),await I(t)})(),()=>{n=!0}}((async()=>{if(g)return;const e=new x.Box3,t=l();for(const n of t){const t=p.get(n);!0!==t?.equals(n.position)&&(null!=t&&e.expandByPoint(t),e.expandByObject(n),p.set(n,n.position.clone()))}e.min.subScalar(50),e.max.addScalar(50);const n=o.getTilesForBounds(e);if(0!=n.length){const s=[];for(const n of t)h.setFromObject(n),h.intersectsBox(e)&&s.push(n);console.log("intersecting meshes",s.length);let[i,r]=d(s);r=function(e,t,n){const o=new x.Vector3,s=[];for(let i=0;i<t.length;i+=3){let r=!0;for(let s=0;s<3;s++){const a=3*t[i+s];if(o.fromArray(e,a),!n.containsPoint(o)){r=!1;break}}r&&s.push(t[i],t[i+1],t[i+2])}return new Uint32Array(s)}(i,r,c),P&&(i=V(i),r=G(r));const a=f;f=!1,await Promise.all(n.map((e=>(b=performance.now(),o.buildTile(i,r,e,a).then((()=>{const t=e[0]+","+e[1];m.set(t,(m.get(t)??0)+1),this.debug})))))).then((()=>{this.debug,g=!1}))}else g=!1}),this.refreshMs??1e4);this.disposed.subscribe((()=>v())),o.onNavMeshUpdate.pipe(y(this.disposed),w(200)).subscribe((()=>{a.clear(),a.drawNavMesh(o.navMesh)})),console.log("Create navmesh with debug",this.debug),this.debug&&(this.object.rotation.set(0,0,0),this.object.updateMatrix(),this.object.updateMatrixWorld(),this.object.parent.add(a)),this.disposed.subscribe((()=>{o?.destroy(),a.removeFromParent(),a.dispose()}));const B=performance.now()-i;B>1e3&&console.warn(`NavMesh update took ${B} ms. Consider changing tileSize or other parameter that may affect performance`)}};e([z(),t("design:type",Boolean)],q.prototype,"debug",void 0),e([z(),t("design:type",Number)],q.prototype,"walkableClimb",void 0),e([z({range:[0,89]}),t("design:type",Number)],q.prototype,"walkableSlopeAngle",void 0),e([z({range:[.01,10]}),t("design:type",Number)],q.prototype,"cellSize",void 0),q=e([M()],q);export default q;function _(e){if(e.shape instanceof c)return function(e){const t=e.shape;if(t.type!==l.HeightField)throw new Error("The provided collider is not a height field.");let n=!1;const o=t,s=o.heights,i=o.nrows,r=o.ncols,a=o.scale.x,c=o.scale.z,h=o.scale.y,p=i+1,u=new x.PlaneGeometry(c,a,r,i);u.rotateX(-Math.PI/2);const d=u.attributes.position.array;let m=0;for(let e=0;e<p;e++)for(let t=0;t<p;t++)d[m+1]=s[t*p+e]*h,m+=3,0!=d[m+1]&&(n=!0);if(!n){const e=new x.PlaneGeometry(a,c,2,2);return e.rotateX(-Math.PI/2),e}return u}(e);if(e.shape instanceof n)return new x.SphereGeometry(e.shape.radius);if(e.shape instanceof r){const t=e.shape.halfExtents;return new x.BoxGeometry(2*t.x,2*t.y,2*t.z)}if(e.shape instanceof i)return function(e){const t=[];for(let n=0;n<e.length;n+=3)t.push(new x.Vector3(e[n],e[n+1],e[n+2]));const n=(new B).setFromPoints(t),o=[];n.faces.forEach((e=>{const t=e.edge.head().point,n=e.edge.next.head().point,s=e.edge.next.next.head().point;o.push(t.x,t.y,t.z),o.push(n.x,n.y,n.z),o.push(s.x,s.y,s.z)}));const s=new x.BufferGeometry;return s.setAttribute("position",new x.Float32BufferAttribute(o,3)),s}(e.shape.vertices);if(e.shape instanceof h){const t=e.shape.vertices,n=e.shape.indices;let o=new x.BufferGeometry;return o.setAttribute("position",new x.Float32BufferAttribute(t,3)),null!=n?o.setIndex(new x.Uint16BufferAttribute(n,1)):o=v.mergeVertices(o),o.computeVertexNormals(),o}if(e.shape instanceof a){const t=e.shape.halfHeight,n=e.shape.radius;return new x.CylinderGeometry(n,n,2*t)}if(e.shape instanceof s){const t=e.shape.halfHeight,n=e.shape.radius;return new x.ConeGeometry(n,2*t)}if(e.shape instanceof o){const t=e.shape.halfHeight,n=e.shape.radius;return new x.CapsuleGeometry(n,2*t)}return console.warn("Unsupported shape",e.shape.type,e),null}function O(e){const t=_(e);if(null==t)return null;const n=L,o=new x.Mesh(t,n);return o.geometry.computeBoundingBox(),o.geometry.scale(1.01,1.01,1.01),o}function W(e,t){const n=e.translation(),o=e.rotation();t.position.set(n.x,n.y,n.z),t.quaternion.set(o.x,o.y,o.z,o.w)}const X=new x.Box3,L=new x.MeshBasicMaterial({wireframe:!1,color:16711680,side:x.FrontSide});/*
1
+ import{__decorate as e,__metadata as t}from"tslib";import{Ball as n,Capsule as o,Cone as s,ConvexPolyhedron as i,Cuboid as r,Cylinder as a,Heightfield as l,ShapeType as c,TriMesh as h}from"@dimforge/rapier3d-compat";import{init as p}from"@recast-navigation/core";import{DebugDrawer as u,getPositionsAndIndices as d}from"@recast-navigation/three";import{BehaviorSubject as m,Subject as f,debounceTime as w,filter as g,firstValueFrom as b,takeUntil as y}from"rxjs";import*as x from"three";import{BufferGeometryUtils as v,ConvexHull as M}from"three/examples/jsm/Addons.js";import{Actor as B,BaseActor as S,Parameter as z,PhysicsSystem as A,ViewController as C,World as j,attach as k,inject as F}from"../../";import{sleepDelay as I}from"../../../utils/async";import{hasSharedArrayBufferSupport as P,toSharedFloat32Array as V,toSharedUint32Array as G}from"../../../utils/buffer";import{DynamicTiledNavMesh as N}from"../../ai/dynamic-tiled-navmesh";import{TriggerVolumeMesh as D}from"./components/volume-editor-component";var E;!function(e){e[e.none=0]="none",e[e.starting=1]="starting",e[e.started=2]="started"}(E||(E={}));let T=E.none,H=new m(!1);export async function safeRecastInit(){return T===E.none?(T=E.starting,p().then((()=>{H.next(!0),T=E.started}))):b(H.pipe(g((e=>e))))}new x.Box3(new x.Vector3(-100,-100,-100),new x.Vector3(100,100,100));const R=navigator.hardwareConcurrency??1;let U=!1,q=class extends S{constructor(){super(...arguments),this.physics=F(A),this.view=F(C),this.world=F(j),this.editorVisualisation=k(D),this.debug=!0,this.refreshMs=4e3,this.tileSize=50,this.walkableClimb=.3,this.walkableSlopeAngle=45,this.cellSize=.2,this.bounds=new x.Box3}async onInit(){U||(await safeRecastInit(),U=!0),setTimeout((()=>{this.init()}),10),this.recreateInterval=setInterval((()=>{if("_hology_transform_group"===this.object.parent?.name)return;X.setFromCenterAndSize(this.position,this.object.scale).equals(this.bounds)||(this.disposed.next(!0),this.disposed=new f,this.init())}),2e3)}onEndPlay(){clearInterval(this.recreateInterval)}init(){this.bounds.setFromCenterAndSize(this.position,this.object.scale),console.log(this.bounds);const e=this.bounds.max.x-this.bounds.min.x,t=this.bounds.max.z-this.bounds.min.z,n=Math.max(1,Math.min(e,t)),o=Math.min(400,Math.max(50,Math.ceil(n/2))),s=Math.max(this.cellSize,.01),i={tileSize:Math.max(32,Math.floor(o/s)),walkableClimb:this.walkableClimb/s,walkableSlopeAngle:this.walkableSlopeAngle,walkableRadius:2,walkableHeight:5,detailSampleDist:1,minRegionArea:6,mergeRegionArea:400,cs:s,ch:s,maxSimplificationError:1.3,maxEdgeLen:200},r=new N({navMeshBounds:this.bounds,recastConfig:i,maxTiles:1024,workers:R,cacheId:"nav"+this.object.userData?.src?.id});this.navMesh=r.navMesh;const a=this.tileSize*i.cs*2,l=performance.now(),c=new Map,h=new u;h.userData.isDebugDrawer=!0;r.navMesh;const p=this.bounds,m=()=>{const e=this.view.getCamera().getWorldPosition(new x.Vector3),t=new x.Box3((new x.Vector3).copy(e).subScalar(a),(new x.Vector3).copy(e).addScalar(a)),n=[],o=this.physics.world.bodies;if(null==o)return[];const s=new x.Box3;for(const e of o.getAll())for(let o=0,i=e.numColliders();o<i;o++){const i=e.collider(o);if(i.isSensor()||null!=i.parent().userData&&!0===i.parent().userData.ignoreForNavMesh)continue;const r=e.handle+","+o,a=c.get(r)?.mesh,l=a??O(i);if(W(i,l),null!=l){s.copy(l.geometry.boundingBox),s.min.add(l.position),s.max.add(l.position);const e=s.intersectsBox(t)||!0,o=s.intersectsBox(this.bounds);c.set(r,{pos:i.translation(),mesh:l}),e&&o&&n.push(l)}}return n},f=new x.Box3,g=new Map,b=new Map;let v=!0,M=performance.now(),B=!1;const S=function(e,t){let n=!1;return(async()=>{for(;!n;)await e(),await I(t)})(),()=>{n=!0}}((async()=>{if(B)return;const e=new x.Box3,t=m();for(const n of t){const t=g.get(n);!0!==t?.equals(n.position)&&(null!=t&&e.expandByPoint(t),e.expandByObject(n),g.set(n,n.position.clone()))}e.min.subScalar(50),e.max.addScalar(50);const n=r.getTilesForBounds(e);n.length>500&&console.warn("Too many tiles to update. Consider increasing tile size");const o=n.slice(0,500);if(0!=o.length){const n=[];for(const o of t)f.setFromObject(o),f.intersectsBox(e)&&n.push(o);console.log("intersecting meshes",n.length);let[s,i]=d(n);i=function(e,t,n){const o=new x.Vector3,s=[];for(let i=0;i<t.length;i+=3){let r=!0;for(let s=0;s<3;s++){const a=3*t[i+s];if(o.fromArray(e,a),!n.containsPoint(o)){r=!1;break}}r&&s.push(t[i],t[i+1],t[i+2])}return new Uint32Array(s)}(s,i,p),P&&(s=V(s),i=G(i));const a=v;v=!1,await Promise.all(o.map((e=>(M=performance.now(),r.buildTile(s,i,e,a).then((()=>{const t=e[0]+","+e[1];b.set(t,(b.get(t)??0)+1),this.debug})))))).then((()=>{this.debug,B=!1}))}else B=!1}),this.refreshMs??1e4);this.disposed.subscribe((()=>S())),r.onNavMeshUpdate.pipe(y(this.disposed),w(200)).subscribe((()=>{h.clear(),h.drawNavMesh(r.navMesh)})),console.log("Create navmesh with debug",this.debug),this.debug&&(this.object.rotation.set(0,0,0),this.object.updateMatrix(),this.object.updateMatrixWorld(),this.object.parent.add(h)),this.disposed.subscribe((()=>{r?.destroy(),h.removeFromParent(),h.dispose()}));const z=performance.now()-l;z>1e3&&console.warn(`NavMesh update took ${z} ms. Consider changing tileSize or other parameter that may affect performance`)}};e([z(),t("design:type",Boolean)],q.prototype,"debug",void 0),e([z(),t("design:type",Number)],q.prototype,"walkableClimb",void 0),e([z({range:[0,89]}),t("design:type",Number)],q.prototype,"walkableSlopeAngle",void 0),e([z({range:[.01,10]}),t("design:type",Number)],q.prototype,"cellSize",void 0),q=e([B()],q);export default q;function _(e){if(e.shape instanceof l)return function(e){const t=e.shape;if(t.type!==c.HeightField)throw new Error("The provided collider is not a height field.");let n=!1;const o=t,s=o.heights,i=o.nrows,r=o.ncols,a=o.scale.x,l=o.scale.z,h=o.scale.y,p=i+1,u=new x.PlaneGeometry(l,a,r,i);u.rotateX(-Math.PI/2);const d=u.attributes.position.array;let m=0;for(let e=0;e<p;e++)for(let t=0;t<p;t++)d[m+1]=s[t*p+e]*h,m+=3,0!=d[m+1]&&(n=!0);if(!n){const e=new x.PlaneGeometry(a,l,2,2);return e.rotateX(-Math.PI/2),e}return u}(e);if(e.shape instanceof n)return new x.SphereGeometry(e.shape.radius);if(e.shape instanceof r){const t=e.shape.halfExtents;return new x.BoxGeometry(2*t.x,2*t.y,2*t.z)}if(e.shape instanceof i)return function(e){const t=[];for(let n=0;n<e.length;n+=3)t.push(new x.Vector3(e[n],e[n+1],e[n+2]));const n=(new M).setFromPoints(t),o=[];n.faces.forEach((e=>{const t=e.edge.head().point,n=e.edge.next.head().point,s=e.edge.next.next.head().point;o.push(t.x,t.y,t.z),o.push(n.x,n.y,n.z),o.push(s.x,s.y,s.z)}));const s=new x.BufferGeometry;return s.setAttribute("position",new x.Float32BufferAttribute(o,3)),s}(e.shape.vertices);if(e.shape instanceof h){const t=e.shape.vertices,n=e.shape.indices;let o=new x.BufferGeometry;return o.setAttribute("position",new x.Float32BufferAttribute(t,3)),null!=n?o.setIndex(new x.Uint16BufferAttribute(n,1)):o=v.mergeVertices(o),o.computeVertexNormals(),o}if(e.shape instanceof a){const t=e.shape.halfHeight,n=e.shape.radius;return new x.CylinderGeometry(n,n,2*t)}if(e.shape instanceof s){const t=e.shape.halfHeight,n=e.shape.radius;return new x.ConeGeometry(n,2*t)}if(e.shape instanceof o){const t=e.shape.halfHeight,n=e.shape.radius;return new x.CapsuleGeometry(n,2*t)}return console.warn("Unsupported shape",e.shape.type,e),null}function O(e){const t=_(e);if(null==t)return null;const n=L,o=new x.Mesh(t,n);return o.geometry.computeBoundingBox(),o.geometry.scale(1.01,1.01,1.01),o}function W(e,t){const n=e.translation(),o=e.rotation();t.position.set(n.x,n.y,n.z),t.quaternion.set(o.x,o.y,o.z,o.w)}const X=new x.Box3,L=new x.MeshBasicMaterial({wireframe:!1,color:16711680,side:x.FrontSide});/*
2
2
  * Copyright (©) 2025 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -1,4 +1,4 @@
1
- import{NavMesh as t,NavMeshParams as s,Raw as e,UnsignedCharArray as i,recastConfigDefaults as o,statusToReadableString as n}from"recast-navigation";import{buildConfig as r,buildTile as a}from"./build-tile.js";import{Subject as h}from"rxjs";import{hasWorkerBuilder as l,createWorker as d}from"../../worker/index.js";import{hasSharedArrayBufferSupport as u}from"../../utils/buffer.js";const c=[];export class DynamicTiledNavMesh{constructor(e){this.navMeshVersion=0,this.onNavMeshUpdate=new h,this.workerRoundRobin=0;const i=e.navMeshBounds.min,n=e.navMeshBounds.max,a=[i.toArray(),n.toArray()],u=e.navMeshBounds.min;this.navMeshBoundsMin=i,this.navMeshBoundsMax=n,this.navMeshBounds=a,this.navMeshOrigin=u,this.cacheId=e.cacheId;const M={...o,...e.recastConfig};this.recastConfig=M;const f=new t,{tileWidth:v,tileHeight:m,tcs:g,maxPolysPerTile:w}=r({recastConfig:M,navMeshBounds:a});this.tileWidth=v,this.tileHeight=m,this.tcs=g;const B=s.create({orig:u,tileWidth:M.tileSize*M.cs,tileHeight:M.tileSize*M.ch,maxTiles:e.maxTiles,maxPolys:w});if(f.initTiled(B),this.navMesh=f,this.workers=[],l())for(let t=0;t<e.workers;t++){let t=c.pop();void 0===t&&(t=d()),t.onmessage=t=>{this.onResult(t)},this.workers.push(t)}}onResult(t){const{tileX:s,tileY:o,navMeshData:r}=t.data,a=new i;a.copy(r),this.navMesh.removeTile(this.navMesh.getTileRefAt(s,o,0));const h=this.navMesh.addTile(a,e.Module.DT_TILE_FREE_DATA,0);e.Detour.statusFailed(h.status)&&(console.error(e.Module.RC_LOG_WARNING,`Failed to add tile to nav mesh\n\ttx: ${s}, ty: ${o},status: ${n(h.status)} (${h.status})`),a.destroy()),this.navMeshVersion++,this.onNavMeshUpdate.next([this.navMeshVersion,[s,o]])}buildTile(t,s,[e,i],o=!0){const n=u&&t.buffer instanceof window.SharedArrayBuffer,r=n?t:new Float32Array(t),h=n?s:new Uint32Array(s),l={tileX:e,tileY:i,tileBoundsMin:[this.navMeshBoundsMin.x+e*this.tcs,this.navMeshBoundsMin.y,this.navMeshBoundsMin.z+i*this.tcs],tileBoundsMax:[this.navMeshBoundsMax.x+(e+1)*this.tcs,this.navMeshBoundsMax.y,this.navMeshBoundsMax.z+(i+1)*this.tcs],recastConfig:this.recastConfig,navMeshBounds:this.navMeshBounds,keepIntermediates:!1,positions:r,indices:h};if(this.workers.length>0){this.workerRoundRobin=++this.workerRoundRobin%this.workers.length;return this.workers[this.workerRoundRobin].postMessage(l,n?void 0:[r.buffer,h.buffer]),Promise.resolve()}return new Promise((t=>{requestIdleCallback((()=>{const s=this.cacheId+JSON.stringify({tileX:l.tileX,tileY:l.tileY});if(o){const e=localStorage.getItem(s);if(null!=e){const s=f(e);return this.onResult({data:{tileX:l.tileX,tileY:l.tileY,navMeshData:s}}),void t({})}}else localStorage.removeItem(s);const e=a(l);if(!e.success||!e.data)return;const i=e.data.toTypedArray();localStorage.setItem(s,M(i)),this.onResult({data:{tileX:l.tileX,tileY:l.tileY,navMeshData:i}}),t(e)}))}))}buildAllTiles(t,s){const{tileWidth:e,tileHeight:i}=this;for(let o=0;o<i;o++)for(let i=0;i<e;i++)this.buildTile(t,s,[i,o])}getTileForWorldPosition(t){return[Math.floor((t.x-this.navMeshBoundsMin.x)/this.tcs),Math.floor((t.z-this.navMeshBoundsMin.z)/this.tcs)]}getTilesForBounds(t){const s=this.getTileForWorldPosition(t.min),e=this.getTileForWorldPosition(t.max),i=[];for(let t=s[1];t<=e[1];t++)for(let o=s[0];o<=e[0];o++)i.push([o,t]);return i}destroy(){this.navMesh.destroy(),this.onNavMeshUpdate.complete();for(const t of this.workers)t.onmessage=null,c.push(t)}}const M=function(t){return btoa(String.fromCharCode(...t))},f=function(t){if(!t)return null;const s=atob(t),e=s.length,i=new Uint8Array(e);for(let t=0;t<e;t++)i[t]=s.charCodeAt(t);return i};/*
1
+ import{NavMesh as t,NavMeshParams as s,Raw as e,UnsignedCharArray as i,recastConfigDefaults as o,statusToReadableString as n}from"recast-navigation";import{buildConfig as r,buildTile as a}from"./build-tile.js";import{Subject as h}from"rxjs";import{hasWorkerBuilder as l,createWorker as d}from"../../worker/index.js";import{hasSharedArrayBufferSupport as u}from"../../utils/buffer.js";const c=[];export class DynamicTiledNavMesh{constructor(e){this.navMeshVersion=0,this.onNavMeshUpdate=new h,this.workerRoundRobin=0;const i=e.navMeshBounds.min,n=e.navMeshBounds.max,a=[i.toArray(),n.toArray()],u=e.navMeshBounds.min;this.navMeshBoundsMin=i,this.navMeshBoundsMax=n,this.navMeshBounds=a,this.navMeshOrigin=u,this.cacheId=e.cacheId;const M={...o,...e.recastConfig};this.recastConfig=M;const f=new t,{tileWidth:v,tileHeight:m,tcs:g,maxPolysPerTile:w}=r({recastConfig:M,navMeshBounds:a});this.tileWidth=v,this.tileHeight=m,this.tcs=g;const B=s.create({orig:u,tileWidth:M.tileSize*M.cs,tileHeight:M.tileSize*M.cs,maxTiles:e.maxTiles,maxPolys:w});if(f.initTiled(B),this.navMesh=f,this.workers=[],l())for(let t=0;t<e.workers;t++){let t=c.pop();void 0===t&&(t=d()),t.onmessage=t=>{this.onResult(t)},this.workers.push(t)}}onResult(t){const{tileX:s,tileY:o,navMeshData:r}=t.data,a=new i;a.copy(r),this.navMesh.removeTile(this.navMesh.getTileRefAt(s,o,0));const h=this.navMesh.addTile(a,e.Module.DT_TILE_FREE_DATA,0);e.Detour.statusFailed(h.status)&&(console.error(e.Module.RC_LOG_WARNING,`Failed to add tile to nav mesh\n\ttx: ${s}, ty: ${o},status: ${n(h.status)} (${h.status})`),a.destroy()),this.navMeshVersion++,this.onNavMeshUpdate.next([this.navMeshVersion,[s,o]])}buildTile(t,s,[e,i],o=!0){const n=u&&t.buffer instanceof window.SharedArrayBuffer,r=n?t:new Float32Array(t),h=n?s:new Uint32Array(s),l={tileX:e,tileY:i,tileBoundsMin:[this.navMeshBoundsMin.x+e*this.tcs,this.navMeshBoundsMin.y,this.navMeshBoundsMin.z+i*this.tcs],tileBoundsMax:[this.navMeshBoundsMax.x+(e+1)*this.tcs,this.navMeshBoundsMax.y,this.navMeshBoundsMax.z+(i+1)*this.tcs],recastConfig:this.recastConfig,navMeshBounds:this.navMeshBounds,keepIntermediates:!1,positions:r,indices:h};if(this.workers.length>0){this.workerRoundRobin=++this.workerRoundRobin%this.workers.length;return this.workers[this.workerRoundRobin].postMessage(l,n?void 0:[r.buffer,h.buffer]),Promise.resolve()}return new Promise((t=>{requestIdleCallback((()=>{const s=this.cacheId+JSON.stringify({tileX:l.tileX,tileY:l.tileY});if(o){const e=localStorage.getItem(s);if(null!=e){const s=f(e);return this.onResult({data:{tileX:l.tileX,tileY:l.tileY,navMeshData:s}}),void t({})}}else localStorage.removeItem(s);const e=a(l);if(!e.success||!e.data)return;const i=e.data.toTypedArray();localStorage.setItem(s,M(i)),this.onResult({data:{tileX:l.tileX,tileY:l.tileY,navMeshData:i}}),t(e)}))}))}buildAllTiles(t,s){const{tileWidth:e,tileHeight:i}=this;for(let o=0;o<i;o++)for(let i=0;i<e;i++)this.buildTile(t,s,[i,o])}getTileForWorldPosition(t){return[Math.floor((t.x-this.navMeshBoundsMin.x)/this.tcs),Math.floor((t.z-this.navMeshBoundsMin.z)/this.tcs)]}getTilesForBounds(t){const s=this.getTileForWorldPosition(t.min),e=this.getTileForWorldPosition(t.max),i=[];for(let t=s[1];t<=e[1];t++)for(let o=s[0];o<=e[0];o++)i.push([o,t]);return i}destroy(){this.navMesh.destroy(),this.onNavMeshUpdate.complete();for(const t of this.workers)t.onmessage=null,c.push(t)}}const M=function(t){return btoa(String.fromCharCode(...t))},f=function(t){if(!t)return null;const s=atob(t),e=s.length,i=new Uint8Array(e);for(let t=0;t<e;t++)i[t]=s.charCodeAt(t);return i};/*
2
2
  * Copyright (©) 2025 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"rendering.d.ts","sourceRoot":"","sources":["../src/rendering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,MAAM,EAKN,QAAQ,EAIR,aAAa,EACb,iBAAiB,EAClB,MAAM,OAAO,CAAC;AACf,OAAO,EAA0E,UAAU,EAA6B,MAAM,cAAc,CAAC;AAM7I,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAazE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAM1H,OAAO,EAAiB,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAsCjF,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE;QACN,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,UAAU,CAAC,EAAE;QACX,OAAO,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M,KAAK,GAAG,EAAE,SAAS,UAAQ;IAoTlE,OAAO,CAAC,wBAAwB;IAkMhC,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,UAAU,CAA8B;IAChD,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,eAAe,CAAI;IAE3B,OAAO,CAAC,cAAc,CAAyB;IAE/C,OAAO,CAAC,aAAa;IAyBd,gBAAgB,CAAC,MAAM,EAAE,MAAM;IAI/B,mBAAmB;IAInB,mBAAmB,CAAC,MAAM,EAAE,MAAM;IAIzC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAQ;IAEjB,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM;IAiFhC,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,WAAW,CAAiB;IAEpC,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,gBAAgB;IAuBxB,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,qBAAqB;CAe9B;AAgBD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,QAIhD;AAiHD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,GAAG,OAAO,CAIzF"}
package/dist/rendering.js CHANGED
@@ -1,4 +1,4 @@
1
- var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as p,GammaCorrectionShader as u,LUTPass as m,RenderPass as g,ShaderPass as f,UnrealBloomPass as v,VRButton as x}from"three-stdlib";import{CSMShader as b,CSMUtil as P}from"./csm.js";import{NodeShaderMaterial as T}from"three-shader-graph";import{Reflector as y}from"three-stdlib";import{BokehPass as w,OutputPass as M}from"three/examples/jsm/Addons.js";import{CSM as R}from"three/examples/jsm/csm/CSM.js";import S from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as C}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as F}from"typedi";import{depthUniformName as D,farUniformName as I,nearUniformName as A,resolutionUniformName as E,supportsDepthTextureExtension as W}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as B}from"./shader-nodes/time.js";import{sceneMapUniformName as j}from"./shader-nodes/scene-sample.js";import{DepthPass as H}from"./utils/three/depth-pass.js";import{GPUStatsPanel as O}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as U}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as V}from"./utils/three/traverse.js";import{clamp as L}from"./utils/math.js";import{ColorPass as k}from"./rendering/color-pass.js";import{SSRPass as z}from"./rendering/ssr/SSRPass.js";import{SSRShader as _}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as N}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as G,OutlineEffectPass as q}from"./rendering/outline-effect.js";const X=document.createElement("div");X.style.position="absolute",X.style.left="50%",X.style.top="50%",X.style.color="black",X.style.zIndex="999";(new i.Layers).set(9);const Y=new i.MeshBasicMaterial({color:"black"}),Q=new i.MeshDepthMaterial;Q.depthPacking=i.RGBADepthPacking,Q.blending=i.NoBlending,Q.side=i.DoubleSide;const K=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let J=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||0!==this.container.clientWidth&&0!==this.container.clientHeight&&(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof l&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.bloomComposer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.dofPass.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.aoMaskDepthRenderTarget.dispose(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.aoPass.blendMaterial.uniforms.tDepth.value=this.aoMaskDepthRenderTarget.depthTexture,this.depthRenderTarget.dispose(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container))}addPostProcessVolume(e){if(0===this.postProcessVolumes.length)this.postProcessVolumes.push(e);else{let t=!1;for(let s=0;s<this.postProcessVolumes.length;s++)if(e.priority<this.postProcessVolumes[s].priority){this.postProcessVolumes.splice(s,0,e),t=!0;break}t||this.postProcessVolumes.push(e)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}constructor(t,s={}){this.container=t,this.options=s,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.postProcessVolumes=[],this.postProcessSettings={},this.resolutionScale=K?.5:1,this.maxPixelRatio=K?1:window.devicePixelRatio,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new S,this._showStats=!0,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),window.renderer=this.renderer=new i.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new i.Scene,this.scene.matrixWorldAutoUpdate=!1,this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(x.createButton(this.renderer));const n=new G(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=n,this.composer=new c(this.renderer);var a=(t.clientWidth||1)/(t.clientHeight||1);const o=new i.PerspectiveCamera(45,a,.5,800);o.layers.enable(19),this.setCamera(o),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,P.renderingView=this,P.patchThreeAdd(),this.isDepthTextureExtensionSupported=W(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container);const l=new g(this.scene,this.camera);this.composer.addPass(l);const h=new v(new i.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=1,h.strength=.9,h.radius=.5,this.bloomPass=h;const d=new C(this.scene,this.camera,t.clientWidth,t.clientWidth);d.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},d.blendMaterial.uniforms.tAODepth={value:d.depthTexture},d.blendMaterial.fragmentShader="\n uniform float intensity;\n uniform sampler2D tDiffuse;\n uniform sampler2D tDepth;\n uniform sampler2D tAODepth;\n varying vec2 vUv;\n\n void main() {\n vec4 texel = texture2D( tDiffuse, vUv );\n float d = textureLod(tDepth, vUv.xy, 0.0).x;\n float d2 = textureLod(tAODepth, vUv.xy, 0.0).x;\n\n float depth = 2.0 * 1.0 * 500.0 / (500.0 + 1.0 - (2.0 * d - 1.0) * (500.0 - 1.0));\n gl_FragColor = vec4(mix(vec3(1.), texel.rgb, d2 > d ? 0.0 : intensity), texel.a);\n }\n ",d.output=C.OUTPUT.Default,d.enabled=!1,this.aoPass=d,_.fragmentShader=_.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const b=!1,T=new z({renderer:this.renderer,scene:this.scene,camera:this.camera,groundReflector:null,selects:[]});T.output=z.OUTPUT.Default,T.blur=!0,T.fresnel=!1,T.distanceAttenuation=!0,T.maxDistance=50,T.selective=!0,T.bouncing=!1,T.opacity=.4,T.enabled=!1!==this.options?.reflection?.enabled||b,this.ssrPass=T,this.composer.addPass(T),!1!==this.options.ao?.enabled&&this.composer.addPass(d),this.renderer.info.autoReset=!1;const y=new c(this.renderer);y.renderToScreen=!1,y.addPass(l),y.addPass(h),this.bloomComposer=y,K||(y.renderTarget2.texture.type=i.HalfFloatType,this.composer.renderTarget1.texture.type=i.HalfFloatType);const R=new f(new i.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:y.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");R.needsSwap=!0,!1!==this.options.bloom?.enabled&&this.composer.addPass(R),this.volumetricFogPass=new N,this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new w(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const F=new k;this.colorPass=F,F.vignetteEnabled=!1,this.outlinePass=new U(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.outlinePass.enabled=!1,this.composer.addPass(this.outlinePass);const D=new f(p);D.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(D),this.fxaaPass=D,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new f(u).clear=!1,this.fixStatsStyle(),this.lutPass=new m({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const I=new M;this.composer.addPass(I)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setEnableOutlines(e){this.outlinePass.enabled=e,this.fxaaPass.enabled=e}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof g?t.camera=e:t instanceof U?t.renderCamera=e:(t instanceof H||t instanceof C)&&(t.camera=e)})),null==this.csm?(this.csm=new R({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene}),h.lights_fragment_begin=b.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof l&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){if(null==this.outlinePass)return;const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse((e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var s=!!e.extensions.get("WEBGL_depth_texture");const r=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.type=i.FloatType,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===s&&(r.depthTexture=new i.DepthTexture(128,128),r.depthTexture.type=i.UnsignedShortType,r.depthTexture.minFilter=i.NearestFilter,r.depthTexture.magFilter=i.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:i.HalfFloatType});return s.texture.minFilter=i.NearestFilter,s.texture.magFilter=i.NearestFilter,s.texture.generateMipmaps=!1,s.stencilBuffer=!1,s.depthTexture=new i.DepthTexture(128,128),s.depthTexture.type=i.UnsignedInt248Type,s.depthTexture.minFilter=i.NearestFilter,s.depthTexture.magFilter=i.NearestFilter,s}static createSceneColorRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio()*.5,t.clientHeight*e.getPixelRatio()*.5,{format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,stencilBuffer:!1});return s.texture.minFilter=i.LinearFilter,s.texture.magFilter=i.LinearFilter,s.texture.generateMipmaps=!1,s}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.depthRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren(),this.volumetricFogPass.dispose()}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){null!=this.scene.environment&&e instanceof T&&(null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1}),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment)}loop(e,t=!1){const s=this.stats,r=s.addPanel(new S.Panel("Calls","#83f","#002")),l=s.addPanel(new S.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new O(this.renderer.getContext()),s.addPanel(h)),this.showStats=t;let d=10,c=1e3;const p=()=>{const e=this.renderer.info.render.calls;e>d&&(d=e,setTimeout((()=>d=10),5e3)),r.update(e,d);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout((()=>c=1e3),5e3)),l.update(t,c)};performance.now();i.Ray.prototype.intersectTriangle;const u=[],m=[],g=[];let f=0;const v=new a,x=new a,b=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>b(t)),500);this.renderer.clear(),this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,s.begin();let a=(t*=.001)-f;if(f=t,v.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e($),t-=$;e(t)}else e(a);this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),x.copy(this.camera.matrixWorld),x.equals(v)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),u.length=0,m.length=0,g.length=0;const l=te;if(ie.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),l.setFromProjectionMatrix(ie),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof i.Sprite)&&function(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}(e,(e=>this.applyEnvMap(e))),(e instanceof o||e instanceof i.Sprite)&&this.initResolutionUniform(e.material),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[D])&&isObjectInFrustum(e,l)?(e.visible=!1,u.push(e),this.initDepthUniform(e.material),e.renderOrder=100):e instanceof y&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[j]&&isObjectInFrustum(e,l)?(e.visible=!1,g.push(e),e.material.uniforms[j].value=this.sceneColorRenderTarget.texture):(e instanceof o||e instanceof i.Sprite)&&function(e){if(e.material instanceof n)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e)&&(e.visible=!1,e.layers.enable(5),m.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[B])e.material.uniforms[B].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const s of e.material)s.uniforms&&null!=s.uniforms[B]&&(s.uniforms[B].value=t)})),u.length>0){if(this.scene.overrideMaterial=Q,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}if(g.length>0){if(this.renderer.setRenderTarget(this.sceneColorRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(!0,!0,!1);try{this.renderer.render(this.scene,this.camera)}catch(e){}}catch(e){console.warn("Error rendering scene color:",e)}this.renderer.setRenderTarget(null)}if(u.forEach((e=>e.visible=!0)),m.forEach((e=>e.visible=!0)),g.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=Q,this.camera.layers.set(5),this.renderer.setRenderTarget(this.aoMaskDepthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.camera.layers.enableAll(),this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}this.ssrPass&&(this.ssrPass.elapsedTime=t),this.volumetricFogPass&&this.volumetricFogPass.update(this.camera,this.ssrPass.beautyRenderTarget,this.csm,this.scene);try{!this.paused&&this.running&&(this.showStats&&h?.startQuery(),this.render(a),this.showStats&&h?.endQuery(),this.showStats&&p(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}s.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(b)}),1e3/this.fpsCap):requestAnimationFrame(b))};!0===this.options.enableXR?this.renderer.setAnimationLoop(b):requestAnimationFrame(b)}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return;var e;(e=this.postProcessSettings).tonemapMapping=void 0,e.tonemapExposure=1,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=new i.Color("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.lut=void 0,e.lutIntensity=0;const t=this.postProcessSettings;let s,r=!1,n=!1,a=!1;const o=this.camera?.position;if(null==o)return;let h=[];for(const e of this.postProcessVolumes){if(!ee(e.object))continue;let l=e.blendWeight??1;const d=e.distanceToPoint(o);d>e.blendRadius||(e.blendRadius>0&&(l*=L(1-d/e.blendRadius,0,1)),l>1&&(l=1),l>0&&(h.push(e),void 0!==e.settings.tonemapMapping&&(t.tonemapMapping=e.settings.tonemapMapping),void 0!==e.settings.tonemapExposure&&(t.tonemapExposure=i.MathUtils.lerp(t.tonemapExposure,e.settings.tonemapExposure,l)),void 0!==e.settings.envTexture&&(t.envTexture=e.settings.envTexture),void 0!==e.settings.envIntensity&&(t.envIntensity=i.MathUtils.lerp(t.envIntensity,e.settings.envIntensity,l)),void 0!==e.settings.vignetteIntensity&&(t.vignetteIntensity=i.MathUtils.lerp(t.vignetteIntensity,e.settings.vignetteIntensity,l),n=!0),void 0!==e.settings.colorTint&&void 0!==e.settings.colorTintIntensity&&e.settings.colorTintIntensity>0&&(t.colorTint=t.colorTint.lerp(e.settings.colorTint,l)),void 0!==e.settings.colorTintIntensity&&(t.colorTintIntensity=i.MathUtils.lerp(t.colorTintIntensity,e.settings.colorTintIntensity,l)),void 0!==e.settings.depthFocus&&(r=!0,t.depthFocus=void 0!==t.depthFocus?i.MathUtils.lerp(t.depthFocus,e.settings.depthFocus,l):e.settings.depthFocus),void 0!==e.settings.depthAperture&&(r=!0,t.depthAperture=void 0!==t.depthAperture?i.MathUtils.lerp(t.depthAperture,e.settings.depthAperture,l):e.settings.depthAperture),void 0!==e.settings.depthMaxBlur&&(r=!0,t.depthMaxBlur=void 0!==t.depthMaxBlur?i.MathUtils.lerp(t.depthMaxBlur,e.settings.depthMaxBlur,l):e.settings.depthMaxBlur),void 0!==e.settings.temperature&&(t.temperature=i.MathUtils.lerp(t.temperature,e.settings.temperature,l)),void 0!==e.settings.temperatureTint&&(t.temperatureTint=i.MathUtils.lerp(t.temperatureTint,e.settings.temperatureTint,l)),void 0!==e.settings.lut&&(s=e.settings.lut,a=!0),void 0!==e.settings.lutIntensity&&(t.lutIntensity=i.MathUtils.lerp(t.lutIntensity,e.settings.lutIntensity,l),a=!0)))}this.renderer.toneMapping=t.tonemapMapping??i.NoToneMapping,this.renderer.toneMappingExposure=t.tonemapExposure,this.scene.environment=t.envTexture,this.scene.environmentIntensity=t.envIntensity,this.colorPass.vignetteIntensity=t.vignetteIntensity,this.colorPass.vignetteEnabled=n,this.colorPass.colorTint=t.colorTint,this.colorPass.colorTintIntensity=t.colorTintIntensity,r&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==t.depthFocus&&(this.dofPass.uniforms.focus.value=t.depthFocus),void 0!==t.depthAperture&&(this.dofPass.uniforms.aperture.value=t.depthAperture),void 0!==t.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=t.depthMaxBlur)):this.dofPass.enabled=!1,this.colorPass.temperature=t.temperature,this.colorPass.temperatureTint=t.temperatureTint,this.lutPass.enabled=a,a&&(null!=s&&(s.flipY=!0,s.generateMipmaps=!1),this.lutPass.lut=s,this.lutPass.intensity=t.lutIntensity)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,s=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let i=0;i<e.length;i++)this.renderer.clearDepth(),this.renderer.setViewport(t-s/2+this.insetWidth*i+this.insetMargin*i,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[i])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){if(0===this.composer.renderTarget1.width||0===this.composer.renderTarget1.height)return;if(0===this.composer.renderTarget2.width||0===this.composer.renderTarget2.height)return;let t=!1;if(this.ssrPass.enabled&&!1!==this.options?.reflection?.enabled){const e=this.ssrPass.selects??[];e.length=0,this.scene.traverseVisible((t=>{t instanceof o&&!0===t.material.userData?.reflective&&e.push(t)})),this.ssrPass.selects=e,0==e.length&&null==this.toonOutlinePass&&!1===this.volumetricFogPass.enabled&&(this.ssrPass.enabled=!1),t=!0}else null==this.toonOutlinePass&&!1===this.volumetricFogPass.enabled&&(this.ssrPass.enabled=!1,t=!0);if(!1!==this.options.bloom?.enabled){const e=this.hasBloom();if(e||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e)));try{this.bloomComposer.render()}catch(e){Z||(console.error(e),Z=!0)}this.scene.traverse((e=>this.restoreMaterial(e))),this.bloomHidden.forEach((e=>e.visible=!0)),this.bloomHidden.length=0,this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=e}this.scene.updateWorldMatrix(!0,!0),this.composer.render(e),t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=V(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){if((e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)){if(e.material?.id===Y.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=Y:e.visible=!1}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof d&&(e.uniforms[D].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,this.camera instanceof l&&(null!=e.uniforms[A]&&(e.uniforms[A].value=this.camera.near),null!=e.uniforms[I]&&(e.uniforms[I].value=this.camera.far)))}initResolutionUniform(e){e instanceof d&&null!=e.uniforms[E]&&e.uniforms[E].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio())}};J=e=t([F(),s("design:paramtypes",[HTMLElement,Object])],J);export{J as RenderingView};let Z=!1;export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const $=.05;function ee(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}C.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse((function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls)&&(e.visible=!1),null!=e.material){let t=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0&&(t=!0);t&&(e.visible=!1)}}))};const te=new i.Frustum,se=new i.Box3,ie=new i.Matrix4;export function isObjectInFrustum(e,t){const s=se.setFromObject(e);return t.intersectsBox(s)}/*
1
+ var e;import{__decorate as t,__metadata as s}from"tslib";import*as i from"three";import{Color as r,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as l,ShaderChunk as h,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as u,GammaCorrectionShader as p,LUTPass as m,RenderPass as g,ShaderPass as f,UnrealBloomPass as v,VRButton as x}from"three-stdlib";import{CSMShader as b,CSMUtil as P}from"./csm.js";import{NodeShaderMaterial as T}from"three-shader-graph";import{Reflector as y}from"three-stdlib";import{BokehPass as w,OutputPass as M}from"three/examples/jsm/Addons.js";import{CSM as S}from"three/examples/jsm/csm/CSM.js";import R from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as C}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as F}from"typedi";import{depthUniformName as D,farUniformName as I,nearUniformName as A,resolutionUniformName as E,supportsDepthTextureExtension as O}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as U}from"./shader-nodes/time.js";import{sceneMapUniformName as W}from"./shader-nodes/scene-sample.js";import{DepthPass as B}from"./utils/three/depth-pass.js";import{GPUStatsPanel as j}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as H}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as V}from"./utils/three/traverse.js";import{clamp as L}from"./utils/math.js";import{ColorPass as k}from"./rendering/color-pass.js";import{SSRPass as z}from"./rendering/ssr/SSRPass.js";import{SSRShader as _}from"./rendering/ssr/SSRShader.js";import{VolumetricFogPass as N}from"./rendering/fog/volumetric-fog-pass.js";import{OutlineEffect as G,OutlineEffectPass as q}from"./rendering/outline-effect.js";const X=document.createElement("div");X.style.position="absolute",X.style.left="50%",X.style.top="50%",X.style.color="black",X.style.zIndex="999";(new i.Layers).set(9);const Y=new i.MeshBasicMaterial({color:"black"}),Q=new i.MeshDepthMaterial;Q.depthPacking=i.RGBADepthPacking,Q.blending=i.NoBlending,Q.side=i.DoubleSide;const K=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let J=e=class{setPaused(e){this.paused=e}resizeRender(){this.previousClientWith===this.container.clientWidth&&this.previousClientHeight===this.container.clientHeight||0!==this.container.clientWidth&&0!==this.container.clientHeight&&(this.previousClientWith=this.container.clientWidth,this.previousClientHeight=this.container.clientHeight,this.camera instanceof l&&(this.camera.aspect=this.container.clientWidth/this.container.clientHeight,this.camera.updateProjectionMatrix()),this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(this.container.clientWidth,this.container.clientHeight),this.composer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.bloomComposer.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.dofPass.setSize(this.container.clientWidth*this.resolutionScale,this.container.clientHeight*this.resolutionScale),this.aoMaskDepthRenderTarget.dispose(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.aoPass.blendMaterial.uniforms.tDepth.value=this.aoMaskDepthRenderTarget.depthTexture,this.depthRenderTarget.dispose(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget.dispose(),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container))}addPostProcessVolume(e){if(0===this.postProcessVolumes.length)this.postProcessVolumes.push(e);else{let t=!1;for(let s=0;s<this.postProcessVolumes.length;s++)if(e.priority<this.postProcessVolumes[s].priority){this.postProcessVolumes.splice(s,0,e),t=!0;break}t||this.postProcessVolumes.push(e)}}removePostProcessVolume(e){const t=this.postProcessVolumes.indexOf(e);t>-1&&this.postProcessVolumes.splice(t,1)}constructor(t,s={}){this.container=t,this.options=s,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.postProcessVolumes=[],this.postProcessSettings={},this.resolutionScale=K?.5:1,this.maxPixelRatio=K?1:window.devicePixelRatio,this.onResize=()=>{if(this.resizeRender(),!this.paused)try{this.render()}catch(e){}},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new R,this._showStats=!0,this.insetHeight=200,this.insetWidth=this.insetHeight*(16/9),this.insetOffsetY=250,this.insetMargin=10,this.maxInsetCameras=4,this.overlayCameras=new Set,this.prevClearColor=new r,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=s.maxPixelRatio&&(this.maxPixelRatio=s.maxPixelRatio),window.renderer=this.renderer=new i.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new i.Scene,this.scene.matrixWorldAutoUpdate=!0,this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(x.createButton(this.renderer));const n=new G(this.renderer,{defaultThickness:.005,defaultColor:[0,0,0],defaultAlpha:1,defaultKeepAlive:!0});this.outlineEffect=n,this.composer=new c(this.renderer);var a=(t.clientWidth||1)/(t.clientHeight||1);const o=new i.PerspectiveCamera(45,a,.5,800);o.layers.enable(19),this.setCamera(o),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,P.renderingView=this,P.patchThreeAdd(),this.isDepthTextureExtensionSupported=O(this.renderer),t.replaceChildren(this.renderer.domElement),this.setupEventListeners(),this.depthRenderTarget=e.createDepthRenderTarget(this.renderer,this.container),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.sceneColorRenderTarget=e.createSceneColorRenderTarget(this.renderer,this.container);const l=new g(this.scene,this.camera);this.composer.addPass(l);const h=new v(new i.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=1,h.strength=.9,h.radius=.5,this.bloomPass=h;const d=new C(this.scene,this.camera,t.clientWidth,t.clientWidth);d.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},d.blendMaterial.uniforms.tAODepth={value:d.depthTexture},d.blendMaterial.fragmentShader="\n uniform float intensity;\n uniform sampler2D tDiffuse;\n uniform sampler2D tDepth;\n uniform sampler2D tAODepth;\n varying vec2 vUv;\n\n void main() {\n vec4 texel = texture2D( tDiffuse, vUv );\n float d = textureLod(tDepth, vUv.xy, 0.0).x;\n float d2 = textureLod(tAODepth, vUv.xy, 0.0).x;\n\n float depth = 2.0 * 1.0 * 500.0 / (500.0 + 1.0 - (2.0 * d - 1.0) * (500.0 - 1.0));\n gl_FragColor = vec4(mix(vec3(1.), texel.rgb, d2 > d ? 0.0 : intensity), texel.a);\n }\n ",d.output=C.OUTPUT.Default,d.enabled=!1,this.aoPass=d,_.fragmentShader=_.fragmentShader.replace("if(metalness==0.) return;","if(metalness<0.1) return;");const b=!1!==this.options?.reflection?.enabled,T=new z({renderer:this.renderer,scene:this.scene,camera:this.camera,groundReflector:null,selects:[]});if(T.output=b?z.OUTPUT.SSR:z.OUTPUT.Default,T.blur=!0,T.fresnel=!1,T.distanceAttenuation=!0,T.maxDistance=50,T.selective=!0,T.bouncing=!1,T.opacity=.4,T.enabled=!1!==this.options?.reflection?.enabled||b,this.ssrPass=T,this.composer.addPass(T),b){this.toonOutlinePass=new q(this.outlineEffect,this.scene,this.camera,!0),this.composer.addPass(this.toonOutlinePass),this.toonOutlinePass.enabled=!0,this.toonOutlinePass.clear=!0,this.toonOutlinePass.renderToScreen=!1;const e=new f(new i.ShaderMaterial({uniforms:{baseTexture:{value:null},ssrTexture:{value:T.ssrRenderTarget.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }\n ",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D ssrTexture;\n uniform float ssrOpacity;\n varying vec2 vUv;\n void main() {\n vec4 base = texture2D(baseTexture, vUv);\n vec4 ssr = texture2D(ssrTexture, vUv);\n // Blend SSR on top of base using opacity\n gl_FragColor = mix(base, ssr, ssr.a);\n }\n ",defines:{}}),"baseTexture");e.needsSwap=!0,this.composer.addPass(e)}!1!==this.options.ao?.enabled&&this.composer.addPass(d),this.renderer.info.autoReset=!1;const y=new c(this.renderer);y.renderToScreen=!1,y.addPass(l),y.addPass(h),this.bloomComposer=y,K||(y.renderTarget2.texture.type=i.HalfFloatType,this.composer.renderTarget1.texture.type=i.HalfFloatType);const S=new f(new i.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:y.renderTarget2.texture}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n varying vec2 vUv;\n void main() {\n gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );\n }",defines:{}}),"baseTexture");S.needsSwap=!0,!1!==this.options.bloom?.enabled&&this.composer.addPass(S),this.volumetricFogPass=new N,this.composer.addPass(this.volumetricFogPass),this.volumetricFogPass.enabled=!0,this.dofPass=new w(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const F=new k;this.colorPass=F,F.vignetteEnabled=!1,this.outlinePass=new H(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.outlinePass.enabled=!1,this.composer.addPass(this.outlinePass);const D=new f(u);D.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(D),this.fxaaPass=D,this.fxaaPass.enabled=!1,!0===s.enableOutlines&&this.setEnableOutlines(!0),new f(p).clear=!1,this.fixStatsStyle(),this.lutPass=new m({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const I=new M;this.composer.addPass(I)}fixStatsStyle(){const e=this.stats.dom;e.style.position="absolute";const t=e.getElementsByTagName("canvas");for(let e=0;e<t.length;e++)t.item(e).style.display="inline-block"}setEnableOutlines(e){this.outlinePass.enabled=e,this.fxaaPass.enabled=e}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof g?t.camera=e:t instanceof H?t.renderCamera=e:(t instanceof B||t instanceof C)&&(t.camera=e)})),null==this.csm?(this.csm=new S({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new i.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene}),h.lights_fragment_begin=b.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof l&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){if(null==this.outlinePass)return;const t=new Map;for(const s of e)t.set(s.uuid,s);for(const s of e)s.traverse((e=>{e.uuid!==s.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var s=!!e.extensions.get("WEBGL_depth_texture");const r=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=i.NearestFilter,r.texture.magFilter=i.NearestFilter,r.texture.type=i.FloatType,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===s&&(r.depthTexture=new i.DepthTexture(128,128),r.depthTexture.type=i.UnsignedShortType,r.depthTexture.minFilter=i.NearestFilter,r.depthTexture.magFilter=i.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:i.HalfFloatType});return s.texture.minFilter=i.NearestFilter,s.texture.magFilter=i.NearestFilter,s.texture.generateMipmaps=!1,s.stencilBuffer=!1,s.depthTexture=new i.DepthTexture(128,128),s.depthTexture.type=i.UnsignedInt248Type,s.depthTexture.minFilter=i.NearestFilter,s.depthTexture.magFilter=i.NearestFilter,s}static createSceneColorRenderTarget(e,t){const s=new i.WebGLRenderTarget(t.clientWidth*e.getPixelRatio()*.5,t.clientHeight*e.getPixelRatio()*.5,{format:i.RGBAFormat,colorSpace:i.SRGBColorSpace,stencilBuffer:!1});return s.texture.minFilter=i.LinearFilter,s.texture.magFilter=i.LinearFilter,s.texture.generateMipmaps=!1,s}setupEventListeners(){window.addEventListener("resize",this.onResize),window.addEventListener("orientationchange",this.onResize),document.addEventListener("visibilitychange",this.onVisiblityChane)}stop(){this.running=!1,window.removeEventListener("resize",this.onResize),window.removeEventListener("orientationchange",this.onResize),document.removeEventListener("visibilitychange",this.onVisiblityChane),this.onLoopCallbacks=[],this.renderer.dispose(),this.depthRenderTarget.dispose(),this.aoMaskDepthRenderTarget.dispose(),this.sceneColorRenderTarget.dispose(),this.csm.dispose(),this.container.replaceChildren(),this.volumetricFogPass.dispose()}onLoop(e){this.onLoopCallbacks.push(e)}removeOnLoop(e){const t=this.onLoopCallbacks.find(e);t>=0&&this.onLoopCallbacks.splice(t,1)}set showStats(e){this._showStats=e,this._showStats&&!this.container.contains(this.stats.dom)?this.container.appendChild(this.stats.dom):!this._showStats&&this.container.contains(this.stats.dom)&&this.container.removeChild(this.stats.dom)}get showStats(){return this._showStats}applyEnvMap(e){null!=this.scene.environment&&e instanceof T&&(null==e.uniforms.envMap&&(e.uniforms.envMap={value:this.scene.environment}),null==e.uniforms.envMapIntensity&&(e.uniforms.envMapIntensity={value:1}),e.uniforms.envMap.value=this.scene.environment,e.uniforms.envMapIntensity.value=this.scene.environmentIntensity,e.envMap=this.scene.environment)}loop(e,t=!1){const s=this.stats,r=s.addPanel(new R.Panel("Calls","#83f","#002")),l=s.addPanel(new R.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new j(this.renderer.getContext()),s.addPanel(h)),this.showStats=t;let d=10,c=1e3;const u=()=>{const e=this.renderer.info.render.calls;e>d&&(d=e,setTimeout((()=>d=10),5e3)),r.update(e,d);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout((()=>c=1e3),5e3)),l.update(t,c)};performance.now();i.Ray.prototype.intersectTriangle;const p=[],m=[],g=[];let f=0;const v=new a,x=new a,b=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>b(t)),500);this.renderer.clear(),this.applyPostProcessSettings(),this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,s.begin();let a=(t*=.001)-f;if(f=t,v.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e($),t-=$;e(t)}else e(a);this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),x.copy(this.camera.matrixWorld),x.equals(v)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),p.length=0,m.length=0,g.length=0;const l=te;if(ie.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),l.setFromProjectionMatrix(ie),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof i.Sprite)&&function(e,t){if(Array.isArray(e.material))for(const s of e.material)t(s);else null!=e.material&&t(e.material)}(e,(e=>this.applyEnvMap(e))),(e instanceof o||e instanceof i.Sprite)&&this.initResolutionUniform(e.material),(e instanceof o||e instanceof i.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[D])&&isObjectInFrustum(e,l)?(e.visible=!1,p.push(e),this.initDepthUniform(e.material),e.renderOrder=100):e instanceof y&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[W]&&isObjectInFrustum(e,l)?(e.visible=!1,g.push(e),e.material.uniforms[W].value=this.sceneColorRenderTarget.texture):(e instanceof o||e instanceof i.Sprite)&&function(e){if(e.material instanceof n)return e.material.transparent||e.material.alphaTest>0;if(Array.isArray(e.material))for(const t of e.material)if(t.transparent||t.alphaTest>0)return!0}(e)&&(e.visible=!1,e.layers.enable(5),m.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[U])e.material.uniforms[U].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const s of e.material)s.uniforms&&null!=s.uniforms[U]&&(s.uniforms[U].value=t)})),p.length>0){if(this.scene.overrideMaterial=Q,this.renderer.setRenderTarget(this.depthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}if(g.length>0){if(this.renderer.setRenderTarget(this.sceneColorRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(!0,!0,!1);try{this.renderer.render(this.scene,this.camera)}catch(e){}}catch(e){console.warn("Error rendering scene color:",e)}this.renderer.setRenderTarget(null)}if(p.forEach((e=>e.visible=!0)),m.forEach((e=>e.visible=!0)),g.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=Q,this.camera.layers.set(5),this.renderer.setRenderTarget(this.aoMaskDepthRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(),this.renderer.render(this.scene,this.camera)}catch(e){console.warn(e)}this.camera.layers.enableAll(),this.renderer.setRenderTarget(null),this.scene.overrideMaterial=null}this.ssrPass&&(this.ssrPass.elapsedTime=t),this.volumetricFogPass&&this.volumetricFogPass.update(this.camera,this.ssrPass.beautyRenderTarget,this.csm,this.scene);try{!this.paused&&this.running&&(this.showStats&&h?.startQuery(),this.render(a),this.showStats&&h?.endQuery(),this.showStats&&u(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}s.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(b)}),1e3/this.fpsCap):requestAnimationFrame(b))};!0===this.options.enableXR?this.renderer.setAnimationLoop(b):requestAnimationFrame(b)}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return;var e;(e=this.postProcessSettings).tonemapMapping=void 0,e.tonemapExposure=1,e.envIntensity=1,e.envTexture=void 0,e.vignetteIntensity=0,e.colorTint=new i.Color("white"),e.colorTintIntensity=0,e.depthFocus=void 0,e.depthAperture=void 0,e.depthMaxBlur=void 0,e.temperature=6500,e.temperatureTint=0,e.lut=void 0,e.lutIntensity=0;const t=this.postProcessSettings;let s,r=!1,n=!1,a=!1;const o=this.camera?.position;if(null==o)return;let h=[];for(const e of this.postProcessVolumes){if(!ee(e.object))continue;let l=e.blendWeight??1;const d=e.distanceToPoint(o);d>e.blendRadius||(e.blendRadius>0&&(l*=L(1-d/e.blendRadius,0,1)),l>1&&(l=1),l>0&&(h.push(e),void 0!==e.settings.tonemapMapping&&(t.tonemapMapping=e.settings.tonemapMapping),void 0!==e.settings.tonemapExposure&&(t.tonemapExposure=i.MathUtils.lerp(t.tonemapExposure,e.settings.tonemapExposure,l)),void 0!==e.settings.envTexture&&(t.envTexture=e.settings.envTexture),void 0!==e.settings.envIntensity&&(t.envIntensity=i.MathUtils.lerp(t.envIntensity,e.settings.envIntensity,l)),void 0!==e.settings.vignetteIntensity&&(t.vignetteIntensity=i.MathUtils.lerp(t.vignetteIntensity,e.settings.vignetteIntensity,l),n=!0),void 0!==e.settings.colorTint&&void 0!==e.settings.colorTintIntensity&&e.settings.colorTintIntensity>0&&(t.colorTint=t.colorTint.lerp(e.settings.colorTint,l)),void 0!==e.settings.colorTintIntensity&&(t.colorTintIntensity=i.MathUtils.lerp(t.colorTintIntensity,e.settings.colorTintIntensity,l)),void 0!==e.settings.depthFocus&&(r=!0,t.depthFocus=void 0!==t.depthFocus?i.MathUtils.lerp(t.depthFocus,e.settings.depthFocus,l):e.settings.depthFocus),void 0!==e.settings.depthAperture&&(r=!0,t.depthAperture=void 0!==t.depthAperture?i.MathUtils.lerp(t.depthAperture,e.settings.depthAperture,l):e.settings.depthAperture),void 0!==e.settings.depthMaxBlur&&(r=!0,t.depthMaxBlur=void 0!==t.depthMaxBlur?i.MathUtils.lerp(t.depthMaxBlur,e.settings.depthMaxBlur,l):e.settings.depthMaxBlur),void 0!==e.settings.temperature&&(t.temperature=i.MathUtils.lerp(t.temperature,e.settings.temperature,l)),void 0!==e.settings.temperatureTint&&(t.temperatureTint=i.MathUtils.lerp(t.temperatureTint,e.settings.temperatureTint,l)),void 0!==e.settings.lut&&(s=e.settings.lut,a=!0),void 0!==e.settings.lutIntensity&&(t.lutIntensity=i.MathUtils.lerp(t.lutIntensity,e.settings.lutIntensity,l),a=!0)))}this.renderer.toneMapping=t.tonemapMapping??i.NoToneMapping,this.renderer.toneMappingExposure=t.tonemapExposure,this.scene.environment=t.envTexture,this.scene.environmentIntensity=t.envIntensity,this.colorPass.vignetteIntensity=t.vignetteIntensity,this.colorPass.vignetteEnabled=n,this.colorPass.colorTint=t.colorTint,this.colorPass.colorTintIntensity=t.colorTintIntensity,r&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==t.depthFocus&&(this.dofPass.uniforms.focus.value=t.depthFocus),void 0!==t.depthAperture&&(this.dofPass.uniforms.aperture.value=t.depthAperture),void 0!==t.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=t.depthMaxBlur)):this.dofPass.enabled=!1,this.colorPass.temperature=t.temperature,this.colorPass.temperatureTint=t.temperatureTint,this.lutPass.enabled=a,a&&(null!=s&&(s.flipY=!0,s.generateMipmaps=!1),this.lutPass.lut=s,this.lutPass.intensity=t.lutIntensity)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,s=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let i=0;i<e.length;i++)this.renderer.clearDepth(),this.renderer.setViewport(t-s/2+this.insetWidth*i+this.insetMargin*i,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[i])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){if(0===this.composer.renderTarget1.width||0===this.composer.renderTarget1.height)return;if(0===this.composer.renderTarget2.width||0===this.composer.renderTarget2.height)return;let t=!1;if(this.ssrPass.enabled&&!1!==this.options?.reflection?.enabled){const e=this.ssrPass.selects??[];e.length=0,this.scene.traverseVisible((t=>{t instanceof o&&!0===t.material.userData?.reflective&&e.push(t)})),this.ssrPass.selects=e,0==e.length&&null==this.toonOutlinePass&&!1===this.volumetricFogPass.enabled&&(this.ssrPass.enabled=!1),t=!0}else null==this.toonOutlinePass&&!1===this.volumetricFogPass.enabled&&(this.ssrPass.enabled=!1,t=!0);if(!1!==this.options.bloom?.enabled){const e=this.hasBloom();if(e||this.hadBloom){const e=this.scene.fog;this.scene.fog=null;const t=this.renderer.getClearColor(this.prevClearColor);this.renderer.setClearColor(0),this.scene.traverseVisible((e=>this.darkenNonBloomed(e)));try{this.bloomComposer.render()}catch(e){Z||(console.error(e),Z=!0)}this.scene.traverse((e=>this.restoreMaterial(e))),this.bloomHidden.forEach((e=>e.visible=!0)),this.bloomHidden.length=0,this.renderer.setClearColor(t),this.scene.fog=e}this.hadBloom=e}this.composer.render(e),t&&(this.ssrPass.enabled=!0)}hasBloom(){return null!=V(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){if((e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)){if(e.material?.id===Y.id)return;this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=Y:e.visible=!1}else"TransformControlsPlane"!==e.type&&"TransformControlsGizmo"!==e.type||(e.visible=!1,this.bloomHidden.push(e))}restoreMaterial(e){this.bloomStoredMaterials[e.uuid]&&(e.material=this.bloomStoredMaterials[e.uuid],delete this.bloomStoredMaterials[e.uuid],e.visible=!0)}initDepthUniform(e){e instanceof d&&(e.uniforms[D].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,this.camera instanceof l&&(null!=e.uniforms[A]&&(e.uniforms[A].value=this.camera.near),null!=e.uniforms[I]&&(e.uniforms[I].value=this.camera.far)))}initResolutionUniform(e){e instanceof d&&null!=e.uniforms[E]&&e.uniforms[E].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio())}};J=e=t([F(),s("design:paramtypes",[HTMLElement,Object])],J);export{J as RenderingView};let Z=!1;export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const $=.05;function ee(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}C.prototype.overrideVisibility=function(){const e=this.scene,t=this._visibilityCache;e.traverse((function(e){if(t.set(e,e.visible),(e.isPoints||e.isLine||e.isTransformControls)&&(e.visible=!1),null!=e.material){let t=!1;if(Array.isArray(e.material)){for(const s of e.material)if(null!=s.alphaTest&&s.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0&&(t=!0);t&&(e.visible=!1)}}))};const te=new i.Frustum,se=new i.Box3,ie=new i.Matrix4;export function isObjectInFrustum(e,t){const s=se.setFromObject(e);return t.intersectsBox(s)}/*
2
2
  * Copyright (©) 2025 Hology Interactive AB. All rights reserved.
3
3
  * See the LICENSE.md file for details.
4
4
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hology/core",
3
- "version": "0.0.125",
3
+ "version": "0.0.127",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -168,10 +168,10 @@
168
168
  "dependencies": {
169
169
  "@babel/runtime": "^7.24.8",
170
170
  "@dimforge/rapier3d-compat": "^0.14.0",
171
- "@hology/nebula": "^0.0.125",
171
+ "@hology/nebula": "^0.0.127",
172
172
  "@plumier/reflect": "^1.1.0",
173
- "@recast-navigation/three": "^0.35.2",
174
- "recast-navigation": "^0.35.2",
173
+ "@recast-navigation/three": "0.39.0",
174
+ "recast-navigation": "0.39.0",
175
175
  "rxjs": "7.8.1",
176
176
  "three-csm": "^4.2.1",
177
177
  "three-mesh-bvh": "^0.7.5",