@hology/core 0.0.105 → 0.0.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gameplay/actors/builtin/components/volume-editor-component.d.ts +11 -0
- package/dist/gameplay/actors/builtin/components/volume-editor-component.d.ts.map +1 -0
- package/dist/gameplay/actors/builtin/components/volume-editor-component.js +4 -0
- package/dist/gameplay/actors/builtin/index.d.ts +2 -0
- package/dist/gameplay/actors/builtin/index.d.ts.map +1 -1
- package/dist/gameplay/actors/builtin/index.js +1 -1
- package/dist/gameplay/actors/builtin/navmesh-actor.d.ts +0 -7
- package/dist/gameplay/actors/builtin/navmesh-actor.d.ts.map +1 -1
- package/dist/gameplay/actors/builtin/navmesh-actor.js +1 -1
- package/dist/gameplay/actors/builtin/post-process-volume-actor.d.ts +47 -0
- package/dist/gameplay/actors/builtin/post-process-volume-actor.d.ts.map +1 -0
- package/dist/gameplay/actors/builtin/post-process-volume-actor.js +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/rendering/color-pass.d.ts +19 -0
- package/dist/rendering/color-pass.d.ts.map +1 -0
- package/dist/rendering/color-pass.js +4 -0
- package/dist/rendering/tone-mapping.d.ts +23 -0
- package/dist/rendering/tone-mapping.d.ts.map +1 -0
- package/dist/rendering/tone-mapping.js +4 -0
- package/dist/rendering.d.ts +9 -0
- package/dist/rendering.d.ts.map +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/asset-resource-loader.d.ts +1 -0
- package/dist/scene/asset-resource-loader.d.ts.map +1 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/package.json +3 -3
- package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,11 @@
|
|
1
|
+
import { ActorComponent } from '../../../../gameplay/actors/component';
|
2
|
+
import { Color } from 'three';
|
3
|
+
export declare class TriggerVolumeMesh extends ActorComponent {
|
4
|
+
color: Color;
|
5
|
+
private dimensions;
|
6
|
+
private mesh;
|
7
|
+
onInit(): void | Promise<void>;
|
8
|
+
set visible(value: boolean);
|
9
|
+
get visible(): boolean;
|
10
|
+
}
|
11
|
+
//# sourceMappingURL=volume-editor-component.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"volume-editor-component.d.ts","sourceRoot":"","sources":["../../../../../src/gameplay/actors/builtin/components/volume-editor-component.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAa,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAuG,KAAK,EAAW,MAAM,OAAO,CAAC;AAI5I,qBACa,iBAAkB,SAAQ,cAAc;IAEtC,KAAK,EAAE,KAAK,CAAsB;IAE/C,OAAO,CAAC,UAAU,CAA8B;IAEhD,OAAO,CAAC,IAAI,CAAwB;IAEpC,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAY9B,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAEzB;IACD,IAAI,OAAO,IAHQ,OAAO,CAKzB;CACF"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import{__decorate as i,__metadata as s}from"tslib";import{Parameter as e}from"../../../../shader";import{ActorComponent as t,Component as o}from"../../../../gameplay/actors/component";import{Mesh as n,EdgesGeometry as r,LineSegments as h,LineBasicMaterial as m,Vector3 as l,BoxGeometry as c,MeshBasicMaterial as d,Group as p,Color as a}from"three";let w=class extends t{constructor(){super(...arguments),this.color=new a(16777215),this.dimensions=new l(1,1,1),this.mesh=new p}onInit(){const i=new c(this.dimensions.x,this.dimensions.y,this.dimensions.z),s=new r(i),e=new h(s,new m({color:this.color}));new n(i,new d({color:this.color,transparent:!0,opacity:.3,visible:!1}));this.mesh.add(e),this.actor.object.add(this.mesh)}set visible(i){this.mesh.visible=i}get visible(){return this.mesh.visible}};i([e(),s("design:type",a)],w.prototype,"color",void 0),w=i([o({inEditor:!0,editorOnly:!0})],w);export{w as TriggerVolumeMesh};/*
|
2
|
+
* Copyright (©) 2023. All rights reserved.
|
3
|
+
* See the LICENSE.md file for details.
|
4
|
+
*/
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { PostProcessVolume } from './post-process-volume-actor.js';
|
1
2
|
import { CameraActor } from './camera-actor.js';
|
2
3
|
import NavMeshActor from './navmesh-actor.js';
|
3
4
|
import { PositionalAudioActor } from './positional-audio-actor.js';
|
@@ -9,6 +10,7 @@ declare const _default: {
|
|
9
10
|
TriggerVolume: typeof TriggerVolume;
|
10
11
|
PositionalAudio: typeof PositionalAudioActor;
|
11
12
|
NavMesh: typeof NavMeshActor;
|
13
|
+
PostProcessVolume: typeof PostProcessVolume;
|
12
14
|
};
|
13
15
|
export default _default;
|
14
16
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/gameplay/actors/builtin/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/gameplay/actors/builtin/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;;;;;;;;;AAEpD,wBAOC"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{
|
1
|
+
import{PostProcessVolume as o}from"./post-process-volume-actor.js";import{CameraActor as r}from"./camera-actor.js";import m from"./navmesh-actor.js";import{PositionalAudioActor as t}from"./positional-audio-actor.js";import{SpawnPoint as s}from"./spawn-point.js";import{TriggerVolume as a}from"./trigger-volume.js";export default{Camera:r,SpawnPoint:s,TriggerVolume:a,PositionalAudio:t,NavMesh:m,PostProcessVolume:o};/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -1,16 +1,9 @@
|
|
1
1
|
import { NavMesh } from 'recast-navigation';
|
2
|
-
import { Color } from 'three';
|
3
2
|
import { BaseActor } from "../../";
|
4
|
-
import { ActorComponent } from '../../../gameplay';
|
5
3
|
export declare function safeRecastInit(): Promise<boolean | void>;
|
6
4
|
export type NavMeshLoader = {
|
7
5
|
save(): any;
|
8
6
|
};
|
9
|
-
export declare class TriggerVolumeMesh extends ActorComponent {
|
10
|
-
color: Color;
|
11
|
-
private dimensions;
|
12
|
-
onInit(): void | Promise<void>;
|
13
|
-
}
|
14
7
|
declare class NavMeshActor extends BaseActor {
|
15
8
|
private physics;
|
16
9
|
private view;
|
@@ -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;
|
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;AAgB3G,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,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
|
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,debounceTime as f,filter as w,firstValueFrom as b,Subject 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{DynamicTiledNavMesh as I}from"../../ai/dynamic-tiled-navmesh";import{hasSharedArrayBufferSupport as P,toSharedFloat32Array as V,toSharedUint32Array as G}from"../../../utils/buffer";import{sleepDelay as N}from"../../../utils/async";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}))):b(R.pipe(w((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 g,this.init())}),1e3)}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 I({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 w=!0,b=performance.now(),g=!1;const v=function(e,t){let n=!1;return(async()=>{for(;!n;)await e(),await N(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=w;w=!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),f(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});/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { BaseActor } from "../..";
|
2
|
+
import { Texture } from 'three';
|
3
|
+
import * as THREE from 'three';
|
4
|
+
import { ActorComponent } from "../../../gameplay";
|
5
|
+
export type PostProcessingVolumeShape = {
|
6
|
+
kind: 'box';
|
7
|
+
box: THREE.Box3;
|
8
|
+
} | {
|
9
|
+
kind: 'sphere';
|
10
|
+
sphere: THREE.Sphere;
|
11
|
+
};
|
12
|
+
export declare class PostProcessSettings extends ActorComponent {
|
13
|
+
tonemapMapping?: number;
|
14
|
+
tonemapExposure?: number;
|
15
|
+
envTexture?: Texture;
|
16
|
+
envIntensity?: number;
|
17
|
+
vignetteIntensity?: number;
|
18
|
+
colorTint?: THREE.Color;
|
19
|
+
colorTintIntensity?: number;
|
20
|
+
/** How far from the camera the scene should be in focus. Try using values like 1-20 */
|
21
|
+
depthFocus?: number;
|
22
|
+
/** Use a very small values such as 0,0002 */
|
23
|
+
depthAperture?: number;
|
24
|
+
/** Use a value like 0.01 */
|
25
|
+
depthMaxBlur?: number;
|
26
|
+
temperature?: number;
|
27
|
+
temperatureTint?: number;
|
28
|
+
lut?: Texture;
|
29
|
+
lutIntensity?: number;
|
30
|
+
resetToDefault(): void;
|
31
|
+
}
|
32
|
+
export declare class PostProcessVolume extends BaseActor {
|
33
|
+
settings: PostProcessSettings;
|
34
|
+
bounded: boolean;
|
35
|
+
priority: number;
|
36
|
+
blendWeight: number;
|
37
|
+
blendRadius: number;
|
38
|
+
private box;
|
39
|
+
private view;
|
40
|
+
private editorView;
|
41
|
+
constructor();
|
42
|
+
onInit(): Promise<void> | void;
|
43
|
+
containsPoint(point: THREE.Vector3): boolean;
|
44
|
+
distanceToPoint(point: THREE.Vector3): number;
|
45
|
+
private resetBox;
|
46
|
+
}
|
47
|
+
//# sourceMappingURL=post-process-volume-actor.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"post-process-volume-actor.d.ts","sourceRoot":"","sources":["../../../../src/gameplay/actors/builtin/post-process-volume-actor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,SAAS,EAAgC,MAAM,OAAO,CAAC;AACvF,OAAO,EAAgJ,OAAO,EAAC,MAAM,OAAO,CAAC;AAK7K,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,MAAM,MAAM,yBAAyB,GACjC;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAA;CAAE,CAAC;AAG7C,qBACa,mBAAoB,SAAQ,cAAc;IAErD,cAAc,CAAC,EAAE,MAAM,CAAA;IASvB,eAAe,CAAC,EAAE,MAAM,CAAA;IAGxB,UAAU,CAAC,EAAE,OAAO,CAAA;IAGpB,YAAY,CAAC,EAAE,MAAM,CAAA;IAMrB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAG1B,SAAS,CAAC,EAAE,KAAK,CAAC,KAAK,CAAA;IAGvB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B,uFAAuF;IAEvF,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,6CAA6C;IAE7C,aAAa,CAAC,EAAE,MAAM,CAAA;IAEtB,4BAA4B;IAE5B,YAAY,CAAC,EAAE,MAAM,CAAA;IAGrB,WAAW,CAAC,EAAE,MAAM,CAAC;IAGrB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,GAAG,CAAC,EAAE,OAAO,CAAA;IAGb,YAAY,CAAC,EAAE,MAAM,CAAA;IAkDrB,cAAc;CAmBf;AAGD,qBACa,iBAAkB,SAAQ,SAAS;IAG9C,QAAQ,EAAE,mBAAmB,CAAA;IAG7B,OAAO,EAAE,OAAO,CAAQ;IAGxB,QAAQ,EAAE,MAAM,CAAI;IAGpB,WAAW,EAAE,MAAM,CAAI;IAGvB,WAAW,EAAE,MAAM,CAAI;IAQvB,OAAO,CAAC,GAAG,CAAkD;IAE7D,OAAO,CAAC,IAAI,CAAwB;IACpC,OAAO,CAAC,UAAU,CAA4B;;IAS9C,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAK9B,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO;IASlC,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO;IASpC,OAAO,CAAC,QAAQ;CAQjB"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{Actor as o,Attach as i,attach as r,BaseActor as s,Component as n,inject as p,Parameter as d}from"../..";import{Texture as m}from"three";import{tonemapMappings as y}from"../../../rendering/tone-mapping";import{OBB as h}from"three/examples/jsm/math/OBB.js";import{Vector3 as u}from"three";import*as a from"three";import{RenderingView as v}from"../../../rendering.js";import{TriggerVolumeMesh as l}from"./components/volume-editor-component.js";import{ActorComponent as b}from"../../../gameplay";let g=class extends b{resetToDefault(){this.tonemapMapping=void 0,this.tonemapExposure=1,this.envIntensity=1,this.envTexture=void 0,this.vignetteIntensity=0,this.colorTint=new a.Color("white"),this.colorTintIntensity=0,this.depthFocus=void 0,this.depthAperture=void 0,this.depthMaxBlur=void 0,this.temperature=6500,this.temperatureTint=0,this.lut=void 0,this.lutIntensity=0}};t([d({options:y}),e("design:type",Number)],g.prototype,"tonemapMapping",void 0),t([d(),e("design:type",Number)],g.prototype,"tonemapExposure",void 0),t([d(),e("design:type",m)],g.prototype,"envTexture",void 0),t([d(),e("design:type",Number)],g.prototype,"envIntensity",void 0),t([d(),e("design:type",Number)],g.prototype,"vignetteIntensity",void 0),t([d(),e("design:type",a.Color)],g.prototype,"colorTint",void 0),t([d(),e("design:type",Number)],g.prototype,"colorTintIntensity",void 0),t([d(),e("design:type",Number)],g.prototype,"depthFocus",void 0),t([d(),e("design:type",Number)],g.prototype,"depthAperture",void 0),t([d(),e("design:type",Number)],g.prototype,"depthMaxBlur",void 0),t([d({range:[1e3,4e4],precision:.1}),e("design:type",Number)],g.prototype,"temperature",void 0),t([d({range:[-1,1]}),e("design:type",Number)],g.prototype,"temperatureTint",void 0),t([d({label:"LUT"}),e("design:type",m)],g.prototype,"lut",void 0),t([d({label:"LUT Intensity"}),e("design:type",Number)],g.prototype,"lutIntensity",void 0),g=t([n()],g);export{g as PostProcessSettings};let c=class extends s{constructor(){super(),this.bounded=!1,this.priority=0,this.blendWeight=1,this.blendRadius=0,this.box=new h(void 0,new a.Vector3(.5,.5,.5)),this.view=p(v),this.editorView=r(l),this.disposed.subscribe((()=>{this.view.removePostProcessVolume(this)}))}onInit(){this.view.addPostProcessVolume(this),this.editorView.visible=this.bounded}containsPoint(t){return!this.bounded||(this.resetBox(),this.box.containsPoint(t))}distanceToPoint(t){return this.bounded?(this.resetBox(),this.box.clampPoint(t,N),N.distanceTo(t)):0}resetBox(){const t=this.box;t.center.set(0,0,0),t.halfSize.set(.5,.5,.5),t.rotation.copy(x.rotation),t.applyMatrix4(this.object.matrixWorld)}};t([i(),e("design:type",g)],c.prototype,"settings",void 0),t([d(),e("design:type",Boolean)],c.prototype,"bounded",void 0),t([d({precision:0}),e("design:type",Number)],c.prototype,"priority",void 0),t([d({range:[0,1]}),e("design:type",Number)],c.prototype,"blendWeight",void 0),t([d(),e("design:type",Number)],c.prototype,"blendRadius",void 0),c=t([o(),e("design:paramtypes",[])],c);export{c as PostProcessVolume};const x=new h,N=new u;/*
|
2
|
+
* Copyright (©) 2023. All rights reserved.
|
3
|
+
* See the LICENSE.md file for details.
|
4
|
+
*/
|
package/dist/index.d.ts
CHANGED
@@ -4,4 +4,5 @@ export * from './scene/collision/collision-shape.js';
|
|
4
4
|
export { AssetMeshInstance } from './scene/asset-resource-loader.js';
|
5
5
|
export { registerWorker, initWorker } from './worker';
|
6
6
|
export * from './shader';
|
7
|
+
export * from './gameplay/actors/builtin/post-process-volume-actor.js';
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,cAAc,sCAAsC,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrD,cAAc,UAAU,CAAA"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,cAAc,sCAAsC,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrD,cAAc,UAAU,CAAA;AACxB,cAAc,wDAAwD,CAAA"}
|
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export{loadScene}from"./scene/bootstrap.js";export{BaseGameController}from"./controllers/base-game-controller.js";export*from"./scene/collision/collision-shape.js";export{AssetMeshInstance}from"./scene/asset-resource-loader.js";export{registerWorker,initWorker}from"./worker";export*from"./shader";/*
|
1
|
+
export{loadScene}from"./scene/bootstrap.js";export{BaseGameController}from"./controllers/base-game-controller.js";export*from"./scene/collision/collision-shape.js";export{AssetMeshInstance}from"./scene/asset-resource-loader.js";export{registerWorker,initWorker}from"./worker";export*from"./shader";export*from"./gameplay/actors/builtin/post-process-volume-actor.js";/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { ShaderPass } from 'three-stdlib';
|
2
|
+
import { Color } from 'three';
|
3
|
+
export declare class ColorPass extends ShaderPass {
|
4
|
+
private defines;
|
5
|
+
set vignetteEnabled(value: boolean);
|
6
|
+
get vignetteEnabled(): boolean;
|
7
|
+
set vignetteIntensity(value: number);
|
8
|
+
get vignetteIntensity(): number;
|
9
|
+
set colorTint(value: Color);
|
10
|
+
get colorTint(): Color;
|
11
|
+
set colorTintIntensity(value: number);
|
12
|
+
get colorTintIntensity(): number;
|
13
|
+
set temperature(value: number);
|
14
|
+
get temperature(): number;
|
15
|
+
set temperatureTint(value: number);
|
16
|
+
get temperatureTint(): number;
|
17
|
+
constructor();
|
18
|
+
}
|
19
|
+
//# sourceMappingURL=color-pass.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"color-pass.d.ts","sourceRoot":"","sources":["../../src/rendering/color-pass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,EAAE,KAAK,EAA6B,MAAM,OAAO,CAAA;AAExD,qBAAa,SAAU,SAAQ,UAAU;IAEvC,OAAO,CAAC,OAAO,CAEd;IAED,IAAI,eAAe,CAAC,KAAK,EAAE,OAAO,EAEjC;IACD,IAAI,eAAe,IAHQ,OAAO,CAKjC;IAED,IAAI,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAMlC;IACD,IAAI,iBAAiB,IAPQ,MAAM,CASlC;IAED,IAAI,SAAS,CAAC,KAAK,EAAE,KAAK,EAEzB;IACD,IAAI,SAAS,IAHQ,KAAK,CASzB;IACD,IAAI,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAEnC;IACD,IAAI,kBAAkB,IAHQ,MAAM,CAKnC;IAED,IAAI,WAAW,CAAC,KAAK,EAAE,MAAM,EAG5B;IACD,IAAI,WAAW,IAJQ,MAAM,CAM5B;IAED,IAAI,eAAe,CAAC,KAAK,EAAE,MAAM,EAGhC;IACD,IAAI,eAAe,IAJQ,MAAM,CAMhC;;CAyCF"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import{ShaderPass as t}from"three-stdlib";import{clamp as e,distance as n,float as i,ifDefApply as r,log as s,mix as u,NodeShaderMaterial as o,pow as l,select as a,smoothstep as m,uniformFloat as c,uniformSampler2d as f,uniformVec3 as p,varyingAttributes as d,vec2 as g,vec3 as v}from"../shader-nodes";import{Color as T,Texture as h,Vector3 as y}from"three";export class ColorPass extends t{set vignetteEnabled(t){this.defines.USE_VIGNETTE=!!t}get vignetteEnabled(){return!!this.defines.USE_VIGNETTE}set vignetteIntensity(t){null!=this.material.uniforms.vignetteIntensity?this.material.uniforms.vignetteIntensity={value:t}:this.material.uniforms.vignetteIntensity.value=t}get vignetteIntensity(){return this.material.uniforms.vignetteIntensity?.value}set colorTint(t){this.uniforms.colorTint.value=t}get colorTint(){const t=this.uniforms.colorTint.value;return t instanceof T?t:(new T).setFromVector3(t)}set colorTintIntensity(t){this.uniforms.colorTintIntensity.value=t}get colorTintIntensity(){return this.uniforms.colorTintIntensity?.value}set temperature(t){this.uniforms.temperature&&(this.uniforms.temperature.value=t)}get temperature(){return this.uniforms.temperature?.value}set temperatureTint(t){this.uniforms.temperatureTint&&(this.uniforms.temperatureTint.value=t)}get temperatureTint(){return this.uniforms.temperatureTint?.value}constructor(){let t=f("tDiffuse",new h).sample(d.uv);const T=p("colorTint",new y(1,1,1)),I=c("colorTintIntensity",1);t=u(t.rgb,t.rgb.multiply(T),I).rgba(1);const E=c("temperature",6500),b=c("temperatureTint",0);t=function(t,n,r){function u(t){const n=t.divide(100),r=a(n.lte(66),i(1),e(i(1.292936186062745).multiply(l(n.subtract(60),-.1332047592)),0,1)),u=a(n.lte(66),e(i(.3900815787690196).multiply(s(n)).subtract(.6318414437886275),0,1),e(i(1.1298908608952942).multiply(l(n.subtract(60),-.0755148492)),0,1)),o=a(n.gte(66),i(1),a(n.lte(19),i(0),e(i(.543206789110196).multiply(s(n.subtract(10))).subtract(1.19625408914),0,1)));return v(r,u,o)}const o=u(e(n,1e3,4e4)),m=e(r,-1,1),c=v(1,i(1).add(m.multiply(.2)),1),f=o.multiply(c),p=f.divideScalar(f.y);return e(t.divide(p),v(0,0,0),v(1,1,1))}(t.rgb,E,b).rgba(1);const S=c("vignetteIntensity",.5),U=g(.5),V=n(d.uv,U),w=t.multiplyScalar(m(.8,.2*.799,V.multiply(S.add(.2))));t=r("USE_VIGNETTE",t,(()=>w));const G=new o({fog:!1,outputEncoding:!1,color:t});console.log(G.fragmentShader),super(G),this.defines={USE_VIGNETTE:!1},G.defines=this.defines,G.needsUpdate=!0}}/*
|
2
|
+
* Copyright (©) 2023. All rights reserved.
|
3
|
+
* See the LICENSE.md file for details.
|
4
|
+
*/
|
@@ -0,0 +1,23 @@
|
|
1
|
+
export declare const tonemapMappings: ({
|
2
|
+
value: 0;
|
3
|
+
name: string;
|
4
|
+
} | {
|
5
|
+
value: 1;
|
6
|
+
name: string;
|
7
|
+
} | {
|
8
|
+
value: 2;
|
9
|
+
name: string;
|
10
|
+
} | {
|
11
|
+
value: 3;
|
12
|
+
name: string;
|
13
|
+
} | {
|
14
|
+
value: 4;
|
15
|
+
name: string;
|
16
|
+
} | {
|
17
|
+
value: 6;
|
18
|
+
name: string;
|
19
|
+
} | {
|
20
|
+
value: 7;
|
21
|
+
name: string;
|
22
|
+
})[];
|
23
|
+
//# sourceMappingURL=tone-mapping.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"tone-mapping.d.ts","sourceRoot":"","sources":["../../src/rendering/tone-mapping.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;IAQ3B,CAAA"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import{NoToneMapping as e,ACESFilmicToneMapping as a,AgXToneMapping as n,CineonToneMapping as m,LinearToneMapping as l,NeutralToneMapping as u,ReinhardToneMapping as i}from"three";export const tonemapMappings=[{value:e,name:"None"},{value:l,name:"Linear"},{value:i,name:"Reinhard"},{value:m,name:"Cineon"},{value:a,name:"ACES Filmic"},{value:n,name:"AgX"},{value:u,name:"Neutral"}];/*
|
2
|
+
* Copyright (©) 2023. All rights reserved.
|
3
|
+
* See the LICENSE.md file for details.
|
4
|
+
*/
|
package/dist/rendering.d.ts
CHANGED
@@ -2,6 +2,7 @@ import * as THREE from "three";
|
|
2
2
|
import { Camera, Object3D, WebGLRenderer, WebGLRenderTarget } from "three";
|
3
3
|
import { CSM } from "three/examples/jsm/csm/CSM.js";
|
4
4
|
import { GTAOPass } from "three/examples/jsm/postprocessing/GTAOPass.js";
|
5
|
+
import { PostProcessSettings, type PostProcessVolume } from "./gameplay/actors/builtin/post-process-volume-actor.js";
|
5
6
|
export type RenderingViewOptions = {
|
6
7
|
enableOutlines?: boolean;
|
7
8
|
enableXR?: boolean;
|
@@ -31,8 +32,13 @@ export declare class RenderingView {
|
|
31
32
|
sceneColorRenderTarget: WebGLRenderTarget;
|
32
33
|
csm: CSM | null;
|
33
34
|
fpsCap: number | null;
|
35
|
+
postProcessVolumes: PostProcessVolume[];
|
36
|
+
postProcessSettings: PostProcessSettings;
|
34
37
|
aoPass: GTAOPass;
|
35
38
|
private bloomPass;
|
39
|
+
private colorPass;
|
40
|
+
private dofPass;
|
41
|
+
private lutPass;
|
36
42
|
setPaused(value: boolean): void;
|
37
43
|
resolutionScale: number;
|
38
44
|
maxPixelRatio: number;
|
@@ -40,6 +46,8 @@ export declare class RenderingView {
|
|
40
46
|
private previousClientWith;
|
41
47
|
private previousClientHeight;
|
42
48
|
private resizeRender;
|
49
|
+
addPostProcessVolume(volume: PostProcessVolume): void;
|
50
|
+
removePostProcessVolume(volume: PostProcessVolume): void;
|
43
51
|
private onVisiblityChane;
|
44
52
|
private isDepthTextureExtensionSupported;
|
45
53
|
private outlineEffect;
|
@@ -62,6 +70,7 @@ export declare class RenderingView {
|
|
62
70
|
get showStats(): boolean;
|
63
71
|
private applyEnvMap;
|
64
72
|
loop(onFrame: (deltaTime: number) => any, showStats?: boolean): void;
|
73
|
+
private applyPostProcessSettings;
|
65
74
|
private insetHeight;
|
66
75
|
private insetWidth;
|
67
76
|
private insetOffsetY;
|
package/dist/rendering.d.ts.map
CHANGED
@@ -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;AAOf,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAGpD,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;
|
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;AAOf,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAGpD,OAAO,EAAE,QAAQ,EAAE,MAAM,+CAA+C,CAAC;AAezE,OAAO,EAAE,mBAAmB,EAAE,KAAK,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAwCrH,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,OAAO,CAAA;KACrB,CAAA;IACD,EAAE,CAAC,EAAE;QACH,OAAO,EAAE,OAAO,CAAA;KACjB,CAAA;CACF,CAAA;AAED,qBACa,aAAa;IAyJf,SAAS,EAAE,WAAW;aACb,OAAO,EAAE,oBAAoB;IAzJxC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAA;IACpB,aAAa,UAAO;IACpB,QAAQ,EAAE,aAAa,CAAA;IACvB,aAAa,EAAE,aAAa,CAAA;IACnC,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,WAAW,CAAa;IACzB,KAAK,EAAE,KAAK,CAAC,KAAK,CAAA;IAClB,OAAO,UAAO;IACd,MAAM,UAAQ;IACd,uBAAuB,EAAE,iBAAiB,CAAA;IAC1C,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,sBAAsB,EAAE,iBAAiB,CAAA;IACzC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAA;IACf,MAAM,EAAE,MAAM,GAAG,IAAI,CAAO;IAC5B,kBAAkB,EAAE,iBAAiB,EAAE,CAAK;IAC5C,mBAAmB,sBAA4B;IAE/C,MAAM,EAAE,QAAQ,CAAA;IACvB,OAAO,CAAC,SAAS,CAAiB;IAClC,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,OAAO,CAAW;IAC1B,OAAO,CAAC,OAAO,CAAS;IAGjB,SAAS,CAAC,KAAK,EAAE,OAAO;IAsBxB,eAAe,SAAqB;IAEpC,aAAa,SAA0C;IAE9D,OAAO,CAAC,QAAQ,CAKf;IAED,OAAO,CAAC,kBAAkB,CAAA;IAC1B,OAAO,CAAC,oBAAoB,CAAA;IAC5B,OAAO,CAAC,YAAY;IAwDb,oBAAoB,CAAC,MAAM,EAAE,iBAAiB;IAoB9C,uBAAuB,CAAC,MAAM,EAAE,iBAAiB;IAOxD,OAAO,CAAC,gBAAgB,CAEvB;IAED,OAAO,CAAC,gCAAgC,CAAQ;IAEhD,OAAO,CAAC,aAAa,CAAe;gBAG3B,SAAS,EAAE,WAAW,EACb,OAAO,GAAE,oBAAyB;IA0VpD,OAAO,CAAC,aAAa;IASd,SAAS,CAAC,MAAM,EAAE,MAAM;IAiDxB,kBAAkB,CAAC,GAAG,EAAE,QAAQ,EAAE;IAkBzC,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAyBtC,OAAO;IACP,OAAO,CAAC,MAAM,CAAC,6BAA6B;IAuB5C,OAAO,CAAC,MAAM,CAAC,4BAA4B;IAuB3C,OAAO,CAAC,mBAAmB;IAMpB,IAAI;IAeX,OAAO,CAAC,eAAe,CAAK;IACrB,MAAM,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,GAAG;IAG1C,YAAY,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,GAAG;IAKvD,OAAO,CAAC,KAAK,CAST;IACJ,OAAO,CAAC,UAAU,CAAO;IAEzB,IAAI,SAAS,CAAC,KAAK,EAAE,OAAO,EAO3B;IACD,IAAI,SAAS,IARQ,OAAO,CAU3B;IAED,OAAO,CAAC,WAAW;IAsBZ,IAAI,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,GAAG,EAAE,SAAS,UAAQ;IAkSlE,OAAO,CAAC,wBAAwB;IA+LhC,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;IACjB,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM;IAmChC,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,WAAW,CAAiB;IAEpC,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,gBAAgB;IAkBxB,OAAO,CAAC,qBAAqB;CAe9B;AAcD,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 i}from"tslib";import*as r from"three";import{Color as s,Material as n,Matrix4 as a,Mesh as o,PerspectiveCamera as h,ShaderChunk as l,ShaderMaterial as d}from"three";import{EffectComposer as c,FXAAShader as m,GammaCorrectionShader as u,RenderPass as p,ShaderPass as f,UnrealBloomPass as g,VRButton as v}from"three-stdlib";import{CSMShader as x,CSMUtil as w}from"./csm.js";import{NodeShaderMaterial as T}from"three-shader-graph";import{Reflector as b}from"three-stdlib";import{OutputPass as y}from"three/examples/jsm/Addons.js";import{CSM as R}from"three/examples/jsm/csm/CSM.js";import C from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as M}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as S}from"typedi";import{depthUniformName as P,farUniformName as D,nearUniformName as F,resolutionUniformName as W,supportsDepthTextureExtension as H}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as A}from"./shader-nodes/time.js";import{sceneMapUniformName as L}from"./shader-nodes/scene-sample.js";import{DepthPass as j}from"./utils/three/depth-pass.js";import{GPUStatsPanel as E}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as O}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as k}from"./utils/three/traverse.js";(new r.Layers).set(9);const B=new r.MeshBasicMaterial({color:"black"}),U=new r.MeshDepthMaterial;U.depthPacking=r.RGBADepthPacking,U.blending=r.NoBlending,U.side=r.DoubleSide;const z=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let V=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 h&&(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.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))}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=z?.5:1,this.maxPixelRatio=z?1:window.devicePixelRatio,this.onResize=()=>{this.resizeRender(),this.paused||this.render()},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new C,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 s,this.hadBloom=!1,this.bloomStoredMaterials={},this.bloomHidden=[],null!=i.maxPixelRatio&&(this.maxPixelRatio=i.maxPixelRatio),window.renderer=this.renderer=new r.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new r.Scene,this.renderer.setPixelRatio(Math.min(this.maxPixelRatio,window.devicePixelRatio)*this.resolutionScale),this.renderer.setSize(t.clientWidth,t.clientHeight),this.renderer.xr.enabled=this.options.enableXR??!1,!0===this.options.enableXR&&document.body.appendChild(v.createButton(this.renderer)),this.composer=new c(this.renderer);var n=(t.clientWidth||1)/(t.clientHeight||1);const a=new r.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=r.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=i.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=r.SRGBColorSpace,this.renderer.toneMapping=r.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,w.renderingView=this,w.patchThreeAdd(),this.isDepthTextureExtensionSupported=H(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 o=new p(this.scene,this.camera);this.composer.addPass(o);const h=new g(new r.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=1,h.strength=.9,h.radius=.5,this.bloomPass=h;const l=new M(this.scene,this.camera,t.clientWidth,t.clientWidth);l.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},l.blendMaterial.uniforms.tAODepth={value:l.depthTexture},l.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 ",l.output=M.OUTPUT.Default,l.enabled=!1,this.aoPass=l,!1!==this.options.ao?.enabled&&this.composer.addPass(l),this.renderer.info.autoReset=!1;const d=new c(this.renderer);d.renderToScreen=!1,d.addPass(o),d.addPass(h),this.bloomComposer=d,z||(d.renderTarget2.texture.type=r.HalfFloatType,this.composer.renderTarget1.texture.type=r.HalfFloatType);const x=new f(new r.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:d.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");if(x.needsSwap=!0,this.composer.addPass(x),this.outlinePass=new O(new r.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===i.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new f(m);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}new f(u).clear=!1,this.fixStatsStyle();const T=new y;this.composer.addPass(T)}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"}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof p?t.camera=e:t instanceof O?t.renderCamera=e:(t instanceof j||t instanceof M)&&(t.camera=e)})),null==this.csm?(this.csm=new R({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new r.Vector3(.5,-1,-.6).normalize(),lightIntensity:.5*Math.PI,camera:this.camera,parent:this.scene}),l.lights_fragment_begin=x.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof h&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){const t=new Map;for(const i of e)t.set(i.uuid,i);for(const i of e)i.traverse((e=>{e.uuid!==i.uuid&&t.has(e.uuid)&&t.delete(e.uuid)}));this.outlinePass.selectedObjects=Array.from(t.values())}static createDepthRenderTarget(e,t){var i=!!e.extensions.get("WEBGL_depth_texture");const s=new r.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return s.texture.minFilter=r.NearestFilter,s.texture.magFilter=r.NearestFilter,s.texture.generateMipmaps=!1,s.stencilBuffer=!1,!0===i&&(s.depthTexture=new r.DepthTexture(128,128),s.depthTexture.type=r.UnsignedShortType,s.depthTexture.minFilter=r.NearestFilter,s.depthTexture.magFilter=r.NearestFilter),s}static createAOMaskDepthRenderTarget(e,t){const i=new r.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:r.HalfFloatType});return i.texture.minFilter=r.NearestFilter,i.texture.magFilter=r.NearestFilter,i.texture.generateMipmaps=!1,i.stencilBuffer=!1,i.depthTexture=new r.DepthTexture(128,128),i.depthTexture.type=r.UnsignedInt248Type,i.depthTexture.minFilter=r.NearestFilter,i.depthTexture.magFilter=r.NearestFilter,i}static createSceneColorRenderTarget(e,t){const i=new r.WebGLRenderTarget(t.clientWidth*e.getPixelRatio()*.5,t.clientHeight*e.getPixelRatio()*.5,{format:r.RGBAFormat,colorSpace:r.SRGBColorSpace,stencilBuffer:!1});return i.texture.minFilter=r.LinearFilter,i.texture.magFilter=r.LinearFilter,i.texture.generateMipmaps=!1,i}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()}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 i=this.stats,s=i.addPanel(new C.Panel("Calls","#83f","#002")),h=i.addPanel(new C.Panel("Triangles","#c32","#002"));let l;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(l=new E(this.renderer.getContext()),i.addPanel(l)),this.showStats=t;let d=10,c=1e3;const m=()=>{const e=this.renderer.info.render.calls;e>d&&(d=e,setTimeout((()=>d=10),5e3)),s.update(e,d);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout((()=>c=1e3),5e3)),h.update(t,c)};performance.now();r.Ray.prototype.intersectTriangle;const u=[],p=[],f=[];let g=0;const v=new a,x=new a,w=t=>{const s=this.renderer.getContext();if(this.paused&&this.running&&s.drawingBufferHeight>1)return void setTimeout((()=>w(t)),500);this.renderer.autoClear=!1,this.renderer.clear(),this.renderer.setViewport(0,0,this.container.clientWidth,this.container.clientHeight),this.camera,i.begin();let a=(t*=.001)-g;if(g=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,p.length=0,f.length=0;const h=I;if(this.camera.updateMatrixWorld(),G.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),h.setFromProjectionMatrix(G),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof r.Sprite)&&function(e,t){if(Array.isArray(e.material))for(const i of e.material)t(i);else null!=e.material&&t(e.material)}(e,(e=>this.applyEnvMap(e))),(e instanceof o||e instanceof r.Sprite)&&this.initResolutionUniform(e.material),(e instanceof o||e instanceof r.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[P])&&isObjectInFrustum(e,h)?(e.visible=!1,u.push(e),this.initDepthUniform(e.material),e.renderOrder=100):e instanceof b&&(e.visible=!1,p.push(e)),(e instanceof o||e instanceof r.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[L]&&isObjectInFrustum(e,h)?(e.visible=!1,f.push(e),e.material.uniforms[L].value=this.sceneColorRenderTarget.texture):(e instanceof o||e instanceof r.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),p.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[A])e.material.uniforms[A].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const i of e.material)i.uniforms&&null!=i.uniforms[A]&&(i.uniforms[A].value=t)})),u.length>0){if(this.scene.overrideMaterial=U,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(f.length>0){if(this.renderer.setRenderTarget(this.sceneColorRenderTarget),!this.paused&&null!=this.camera)try{this.renderer.clear(!0,!0,!1),this.renderer.render(this.scene,this.camera)}catch(e){console.warn("Error rendering scene color:",e)}this.renderer.setRenderTarget(null)}if(u.forEach((e=>e.visible=!0)),p.forEach((e=>e.visible=!0)),f.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=U,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}try{!this.paused&&this.running&&(this.showStats&&l?.startQuery(),this.render(a),this.showStats&&l?.endQuery(),this.showStats&&m(),this.renderer.info.reset(),this.renderOverlay())}catch(e){console.warn(e)}i.end(),this.csm?.update(),this.running&&!0!==this.options.enableXR&&(this.fpsCap?setTimeout((()=>{requestAnimationFrame(w)}),1e3/this.fpsCap):requestAnimationFrame(w))};!0===this.options.enableXR?this.renderer.setAnimationLoop(w):requestAnimationFrame(w)}renderOverlay(){const e=Array.from(this.overlayCameras.values()).slice(0,this.maxInsetCameras),t=this.container.clientWidth/2,i=e.length*this.insetWidth+(e.length-1)*this.insetMargin;for(let r=0;r<e.length;r++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*r+this.insetMargin*r,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[r])}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;const t=this.hasBloom();if(t||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))),this.bloomComposer.render(),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=t,this.composer.render(e)}hasBloom(){return null!=k(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){(e instanceof o||e instanceof r.Sprite||e instanceof r.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)?(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=B:e.visible=!1):"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[P].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,this.camera instanceof h&&(null!=e.uniforms[F]&&(e.uniforms[F].value=this.camera.near),null!=e.uniforms[D]&&(e.uniforms[D].value=this.camera.far)))}initResolutionUniform(e){e instanceof d&&null!=e.uniforms[W]&&e.uniforms[W].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio())}};V=e=t([S(),i("design:paramtypes",[HTMLElement,Object])],V);export{V as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const _=.05;M.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 i of e.material)if(null!=i.alphaTest&&i.alphaTest>0){t=!0;break}}else null!=e.material.alphaTest&&e.material.alphaTest>0&&(t=!0);t&&(e.visible=!1)}}))};const I=new r.Frustum,N=new r.Box3,G=new r.Matrix4;export function isObjectInFrustum(e,t){const i=N.setFromObject(e);return t.intersectsBox(i)}/*
|
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 T,CSMUtil as y}from"./csm.js";import{NodeShaderMaterial as b}from"three-shader-graph";import{Reflector as P}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 C from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as S}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 W,supportsDepthTextureExtension as E}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as B}from"./shader-nodes/time.js";import{sceneMapUniformName as H}from"./shader-nodes/scene-sample.js";import{DepthPass as j}from"./utils/three/depth-pass.js";import{GPUStatsPanel as L}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{PostProcessSettings as k}from"./gameplay/actors/builtin/post-process-volume-actor.js";import{clamp as O}from"./utils/math.js";import{ColorPass as z}from"./rendering/color-pass.js";const _=document.createElement("div");_.style.position="absolute",_.style.left="50%",_.style.top="50%",_.style.color="black",_.style.zIndex="999";(new i.Layers).set(9);const N=new i.MeshBasicMaterial({color:"black"}),G=new i.MeshDepthMaterial;G.depthPacking=i.RGBADepthPacking,G.blending=i.NoBlending,G.side=i.DoubleSide;const q=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let X=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=new k,this.resolutionScale=q?.5:1,this.maxPixelRatio=q?1:window.devicePixelRatio,this.onResize=()=>{this.resizeRender(),this.paused||this.render()},this.onVisiblityChane=()=>{this.windowVisible=!document.hidden},this.isDepthTextureExtensionSupported=!1,this.onLoopCallbacks=[],this.stats=new C,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.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)),document.body.appendChild(_),this.composer=new c(this.renderer);var n=(t.clientWidth||1)/(t.clientHeight||1);const a=new i.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=i.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=s.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=i.SRGBColorSpace,this.renderer.toneMapping=i.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,y.renderingView=this,y.patchThreeAdd(),this.isDepthTextureExtensionSupported=E(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 o=new g(this.scene,this.camera);this.composer.addPass(o);const l=new v(new i.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);l.threshold=1,l.strength=.9,l.radius=.5,this.bloomPass=l;const h=new S(this.scene,this.camera,t.clientWidth,t.clientWidth);h.blendMaterial.uniforms.tDepth={value:this.aoMaskDepthRenderTarget.depthTexture},h.blendMaterial.uniforms.tAODepth={value:h.depthTexture},h.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 ",h.output=S.OUTPUT.Default,h.enabled=!1,this.aoPass=h,!1!==this.options.ao?.enabled&&this.composer.addPass(h),this.renderer.info.autoReset=!1;const d=new c(this.renderer);d.renderToScreen=!1,d.addPass(o),d.addPass(l),this.bloomComposer=d,q||(d.renderTarget2.texture.type=i.HalfFloatType,this.composer.renderTarget1.texture.type=i.HalfFloatType);const T=new f(new i.ShaderMaterial({uniforms:{baseTexture:{value:null},bloomTexture:{value:d.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");T.needsSwap=!0,this.composer.addPass(T),this.dofPass=new w(this.scene,this.camera,{focus:1,aperture:.025,maxblur:.01}),this.dofPass.enabled=!1,this.composer.addPass(this.dofPass);const b=new z;if(this.composer.addPass(b),this.colorPass=b,b.vignetteEnabled=!0,this.outlinePass=new U(new i.Vector2(t.clientWidth,t.clientHeight),this.scene,this.camera),!0===s.enableOutlines){this.outlinePass.edgeThickness=0,this.outlinePass.edgeGlow=0,this.outlinePass.edgeThickness=1.5,this.outlinePass.edgeStrength=5,this.outlinePass.clear=!1,this.composer.addPass(this.outlinePass);const e=new f(p);e.uniforms.resolution.value.set(1/t.clientWidth,1/t.clientHeight),this.composer.addPass(e)}new f(u).clear=!1,this.fixStatsStyle(),this.lutPass=new m({}),this.lutPass.enabled=!1,this.composer.addPass(this.lutPass);const P=new M;this.composer.addPass(P)}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"}setCamera(e){this.camera=e,this.composer.passes.forEach((t=>{t instanceof g?t.camera=e:t instanceof U?t.renderCamera=e:(t instanceof j||t instanceof S)&&(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=T.lights_fragment_begin):(this.csm.camera=this.camera,this.camera instanceof l&&(this.csm.maxFar=this.camera.far)),this.csm.updateFrustums()}setSelectedObjects(e){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.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()}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 b&&(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 C.Panel("Calls","#83f","#002")),l=s.addPanel(new C.Panel("Triangles","#c32","#002"));let h;navigator.userAgent.includes("Chrome")&&navigator.userAgent.includes("HologyEngine")&&(h=new L(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,T=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>T(t)),500);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(Y),t-=Y;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=J;if(this.camera.updateMatrixWorld(),Z.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),l.setFromProjectionMatrix(Z),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 P&&(e.visible=!1,m.push(e)),(e instanceof o||e instanceof i.Sprite)&&e.material?.uniforms&&null!=e.material?.uniforms[H]&&isObjectInFrustum(e,l)?(e.visible=!1,g.push(e),e.material.uniforms[H].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=G,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),this.renderer.render(this.scene,this.camera)}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=G,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}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(T)}),1e3/this.fpsCap):requestAnimationFrame(T))};!0===this.options.enableXR?this.renderer.setAnimationLoop(T):requestAnimationFrame(T)}applyPostProcessSettings(){if(0==this.postProcessVolumes.length)return;this.postProcessSettings.resetToDefault();const e=this.postProcessSettings;let t,s=!1,r=!1;const n=this.camera?.position;if(null==n)return;let a=[];for(const o of this.postProcessVolumes){if(!Q(o.object))continue;let l=o.blendWeight??1;const h=o.distanceToPoint(n);h>o.blendRadius||(o.blendRadius>0&&(l*=O(1-h/o.blendRadius,0,1)),l>1&&(l=1),l>0&&(a.push(o),void 0!==o.settings.tonemapMapping&&(e.tonemapMapping=o.settings.tonemapMapping),void 0!==o.settings.tonemapExposure&&(e.tonemapExposure=i.MathUtils.lerp(e.tonemapExposure,o.settings.tonemapExposure,l)),void 0!==o.settings.envTexture&&(e.envTexture=o.settings.envTexture),void 0!==o.settings.envIntensity&&(e.envIntensity=i.MathUtils.lerp(e.envIntensity,o.settings.envIntensity,l)),void 0!==o.settings.vignetteIntensity&&(e.vignetteIntensity=i.MathUtils.lerp(e.vignetteIntensity,o.settings.vignetteIntensity,l)),void 0!==o.settings.colorTint&&void 0!==o.settings.colorTintIntensity&&o.settings.colorTintIntensity>0&&(e.colorTint=e.colorTint.lerp(o.settings.colorTint,l)),void 0!==o.settings.colorTintIntensity&&(e.colorTintIntensity=i.MathUtils.lerp(e.colorTintIntensity,o.settings.colorTintIntensity,l)),void 0!==o.settings.depthFocus&&(s=!0,e.depthFocus=void 0!==e.depthFocus?i.MathUtils.lerp(e.depthFocus,o.settings.depthFocus,l):o.settings.depthFocus),void 0!==o.settings.depthAperture&&(s=!0,e.depthAperture=void 0!==e.depthAperture?i.MathUtils.lerp(e.depthAperture,o.settings.depthAperture,l):o.settings.depthAperture),void 0!==o.settings.depthMaxBlur&&(s=!0,e.depthMaxBlur=void 0!==e.depthMaxBlur?i.MathUtils.lerp(e.depthMaxBlur,o.settings.depthMaxBlur,l):o.settings.depthMaxBlur),void 0!==o.settings.temperature&&(e.temperature=i.MathUtils.lerp(e.temperature,o.settings.temperature,l)),void 0!==o.settings.temperatureTint&&(e.temperatureTint=i.MathUtils.lerp(e.temperatureTint,o.settings.temperatureTint,l)),void 0!==o.settings.lut&&(t=o.settings.lut,r=!0),void 0!==o.settings.lutIntensity&&(e.lutIntensity=i.MathUtils.lerp(e.lutIntensity,o.settings.lutIntensity,l),r=!0)))}this.renderer.toneMapping=e.tonemapMapping??i.NoToneMapping,this.renderer.toneMappingExposure=e.tonemapExposure,this.scene.environment=e.envTexture,this.scene.environmentIntensity=e.envIntensity,this.colorPass.vignetteIntensity=e.vignetteIntensity,this.colorPass.colorTint=e.colorTint,this.colorPass.colorTintIntensity=e.colorTintIntensity,s&&this.camera instanceof l?(this.dofPass.enabled=!0,void 0!==e.depthFocus&&(this.dofPass.uniforms.focus.value=e.depthFocus),void 0!==e.depthAperture&&(this.dofPass.uniforms.aperture.value=e.depthAperture),void 0!==e.depthMaxBlur&&(this.dofPass.uniforms.maxblur.value=e.depthMaxBlur)):this.dofPass.enabled=!1,this.colorPass.temperature=e.temperature,this.colorPass.temperatureTint=e.temperatureTint,this.lutPass.enabled=r,r&&(null!=t&&(t.flipY=!1,t.generateMipmaps=!1),this.lutPass.lut=t,this.lutPass.intensity=e.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;const t=this.hasBloom();if(t||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))),this.bloomComposer.render(),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=t,this.composer.render(e)}hasBloom(){return null!=V(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){(e instanceof o||e instanceof i.Sprite||e instanceof i.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)?(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=N:e.visible=!1):"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[W]&&e.uniforms[W].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio())}};X=e=t([F(),s("design:paramtypes",[HTMLElement,Object])],X);export{X as RenderingView};export function setRenderingPaused(e){null!=window.editor?.viewer?.renderingView&&(window.editor.viewer.renderingView.paused=e)}const Y=.05;function Q(e){let t=e;for(;t;){if(!1===t.visible)return!1;t=t.parent}return!0}S.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 J=new i.Frustum,K=new i.Box3,Z=new i.Matrix4;export function isObjectInFrustum(e,t){const s=K.setFromObject(e);return t.intersectsBox(s)}/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"asset-resource-loader.d.ts","sourceRoot":"","sources":["../../src/scene/asset-resource-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6G,QAAQ,EAAE,OAAO,EAA+B,MAAM,OAAO,CAAC;AAIlL,OAAO,EAAE,KAAK,EAAY,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAW/D,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,SAAS,CAAmE;IACpF,OAAO,CAAC,SAAS,CAAsC;IACvD,OAAO,CAAC,SAAS,CAAsC;IACvD,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,SAAS,CAA0C;IAC3D,OAAO,CAAC,UAAU,CAAsC;IACxD,OAAO,CAAC,cAAc,CAAmD;IACzE,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,eAAe,CAAQ;IAE/B,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO;IAIhC,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,KAAK,CAAiC;;IAIvC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,aAAa;IAMtC,UAAU,CAAC,IAAI,EAAE,MAAM;IAK9B,OAAO,CAAC,MAAM;IAKD,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,GAAC,IAAI,CAAC;
|
1
|
+
{"version":3,"file":"asset-resource-loader.d.ts","sourceRoot":"","sources":["../../src/scene/asset-resource-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6G,QAAQ,EAAE,OAAO,EAA+B,MAAM,OAAO,CAAC;AAIlL,OAAO,EAAE,KAAK,EAAY,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAW/D,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,SAAS,CAAmE;IACpF,OAAO,CAAC,SAAS,CAAsC;IACvD,OAAO,CAAC,SAAS,CAAsC;IACvD,OAAO,CAAC,aAAa,CAAyC;IAC9D,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,UAAU,CAAyC;IAC3D,OAAO,CAAC,SAAS,CAA0C;IAC3D,OAAO,CAAC,UAAU,CAAsC;IACxD,OAAO,CAAC,cAAc,CAAmD;IACzE,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,eAAe,CAAQ;IAE/B,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO;IAIhC,OAAO,CAAC,SAAS,CAAgB;IACjC,OAAO,CAAC,KAAK,CAAiC;;IAIvC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,aAAa;IAMtC,UAAU,CAAC,IAAI,EAAE,MAAM;IAK9B,OAAO,CAAC,MAAM;IAKD,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,GAAC,IAAI,CAAC;IA4C5D,OAAO,CAAC,iBAAiB;IAclB,UAAU,CAAC,KAAK,EAAE,KAAK;IAU9B,OAAO,CAAC,gBAAgB,CAAyC;IACpD,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAuDpE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC;IAMzD,OAAO,CAAC,mBAAmB,CAAsC;IACjE,OAAO,CAAC,sBAAsB;YAShB,QAAQ;IAyBtB,OAAO,CAAC,eAAe,CAAoB;IAC3C,OAAO,CAAC,kBAAkB;YAyEZ,WAAW;CAiC1B;AAgBD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,iBAAiB,CAAC;IACzB,UAAU,EAAE,KAAK,CAAC,aAAa,EAAE,CAAA;CAClC;AAED,qBAAa,iBAAkB,SAAQ,QAAQ;IAC7C,eAAe,CAAC,EAAE,cAAc,EAAE,CAAA;IAClC,OAAO,CAAC,EAAE,0BAA0B,CAAA;CACrC;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAInD;AAiFD,MAAM,MAAM,cAAc,GAAG;IAC3B;;;;OAIG;IACH,cAAc,EAAE,OAAO,CAAA;CACxB,CAAA"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{AudioLoader as e,BufferGeometry as t,Group as s,LoadingManager as a,Mesh as i,Object3D as r,TextureLoader as n}from"three";import{GLTFLoader as o,MTLLoader as h,OBJLoader as c,DRACOLoader as l}from"three-stdlib";import{FBXLoader as
|
1
|
+
import{AudioLoader as e,BufferGeometry as t,Group as s,LoadingManager as a,Mesh as i,Object3D as r,TextureLoader as n}from"three";import{GLTFLoader as o,MTLLoader as h,OBJLoader as c,DRACOLoader as l,LUTCubeLoader as d}from"three-stdlib";import{FBXLoader as m}from"three-stdlib";import{cloneMesh as u}from"../utils/mesh.js";import{pathJoin as p}from"../utils/files.js";import{Subject as f,firstValueFrom as g}from"rxjs";import{importCollisionShapes as w,isCollisionMesh as y}from"./collision/collision-shape-import.js";import*as x from"three";import{iterateMaterials as L}from"../utils/materials.js";import{BufferGeometryUtils as M,EXRLoader as b,KTX2Loader as A,TGALoader as C,UltraHDRLoader as S}from"three/examples/jsm/Addons.js";const v=new l;v.setDecoderConfig({type:"js"}),v.setDecoderPath("/assets/draco/");const j=["glb","gltf","fbx","obj"];export class AssetResourceLoader{onError(e){console.error(e)}constructor(){this.cache=new Map,this.textureCache=new Map,this.loadingManager=new a,this.glbLoader=new o(this.loadingManager).setDRACOLoader(v),this.fbxLoader=new m(this.loadingManager),this.objLoader=new c(this.loadingManager),this.textureLoader=new n(this.loadingManager),this.tgaLoader=new C(this.loadingManager),this.exrLoader=new b(this.loadingManager),this.cubeLoader=new d(this.loadingManager),this.hdrLoader=new S(this.loadingManager),this.ktx2Loader=new A(this.loadingManager),this._textureLoader=new x.ImageBitmapLoader(this.loadingManager),this.audioLoader=new e(this.loadingManager),this.initialisedKtx2=!1,this.makeReady=new f,this.ready=g(this.makeReady),this.asyncMeshResults=new Map,this.collisionShapeCache=new Map,this.optimizedMeshes=new Set}initKtx2(e){this.initialisedKtx2=!0,this.ktx2Loader.setTranscoderPath("/assets/basis/"),this.ktx2Loader.detectSupport(e)}setDataDir(e){this.basePath=p(e,"asset-resources"),this.makeReady.next(!0)}getUri(e){return p(this.basePath,e)+`?windowId=${getElectronArg("windowId")}`}async getTexture(e){if(null==e||null==e.fileKey)return null;if(await this.ready,!this.textureCache.has(e.id))try{await this._getTextureLoader(e.fileKey).loadAsync(this.getUri(e.fileKey)).then((t=>(t.texture&&(t=t.texture),t.wrapS=W(e.texture?.wrapS),t.wrapT=W(e.texture?.wrapT),t.flipY=e.texture?.flipY??!0,this.textureCache.set(e.id,t),t)))}catch(t){return console.warn("Failed to load texture "+e.name,t),null}return this.textureCache.get(e.id)}_getTextureLoader(e){return e?.toLowerCase().endsWith(".tga")?this.tgaLoader:e?.toLowerCase().endsWith(".ktx2")?this.ktx2Loader:e?.toLowerCase().endsWith(".exr")?this.exrLoader:e?.toLowerCase().endsWith(".cube")?this.cubeLoader:this.textureLoader}clearCache(e){"mesh"===e.type&&Array.from(this.cache.keys()).forEach((t=>{t.startsWith(e.fileKey)&&this.cache.delete(t)}))}async getMesh(e,t){if(await this.ready,null==e)return console.error("No asset was provided"),{scene:new s,animations:[]};if(!j.includes(e.fileFormat?.toLowerCase()))return console.error("Unsupported mesh file format "+e.fileFormat,e),{scene:new s,animations:[]};const a=e.fileKey+(!0===t?.mergeGeomtries?"1":"0");if(!this.cache.has(a))try{this.asyncMeshResults.has(a)||this.asyncMeshResults.set(a,this.loadMesh(e).finally((()=>this.asyncMeshResults.delete(a)))),this.cache.set(a,await this.asyncMeshResults.get(a))}catch(e){return this.onError(e),{scene:new s,animations:[]}}const r=this.cache.get(a).scene,n=this.computeCollisionShapes(e,r);!0===t?.mergeGeomtries&&this.optimizeDrawGroups(r);const o=u(r),h=this.cache.get(a).animations;o.traverse((e=>{e instanceof i&&e.material instanceof Array&&(e.material=e.material.slice())}));const c=new AssetMeshInstance;c.add(o),c.collisionShapes=n,c.animations=h;const l=e.receiveShadow??!0,d=e.castShadow??!1;return o.traverse((e=>{e.castShadow=d,e.receiveShadow=l})),{scene:c,animations:h}}async getAudio(e){return await this.ready,this.audioLoader.loadAsync(this.getUri(e.fileKey))}computeCollisionShapes(e,t){const s=e.id+e.mesh?.collisions?.shapeType;return this.collisionShapeCache.has(s)||this.collisionShapeCache.set(s,w(t,e)),this.collisionShapeCache.get(s)}async loadMesh(e){return await this.ready,await this.loadByAsset(e).then((e=>(e.scene.traverse((e=>{y(e)&&(e.visible=!1)})),e.scene=function(e,t){let s=!1;if(t.traverseVisible((e=>{k.test(e.name)&&(s=!0)})),!s)return t;const a=new x.LOD,i=[t];for(;i.length>0;){const e=i.shift(),t=e.name.match(k);if(null!=t){const s=parseInt(t[1]);0===s?a.addLevel(e,0):console.warn(`Skipping LOD level ${s} for now as LOD is not fully supported`)}else i.push(...e.children)}return a}(0,e.scene),e)))}optimizeDrawGroups(e){if(this.optimizedMeshes.has(e.uuid))return;this.optimizedMeshes.add(e.uuid);let s=!0,a=0,r=0;if(e.traverse((e=>{if(e instanceof i&&e.geometry instanceof t&&!y(e)){a++;const t=Object.keys(e.geometry.attributes).length;t!==r&&0!==r&&(s=!1),r=t}else(e instanceof x.SkinnedMesh||e instanceof x.Bone)&&(s=!1)})),a>1&&s){const s=[],a=[],r=[];e.updateWorldMatrix(!0,!0),e.traverse((e=>{e instanceof i&&e.geometry instanceof t&&!y(e)&&!Array.isArray(e.material)&&(e.updateWorldMatrix(!0,!0),s.push(e.geometry.clone().applyMatrix4(e.matrixWorld)),a.push(e.material),r.push(e))}));for(const e of r)e.removeFromParent();const n=M.mergeGeometries(s,!0),o=[];let h=0;e:for(const e of a){for(const t of o)if(t.m.id===e.id){t.indices.push(h),h++;continue e}o.push({m:e,indices:[h]}),h++}let c=0;for(const e of o){for(const t of e.indices)n.groups[t].materialIndex=c;c++}e.add(new i(n,o.map((e=>e.m))))}e.traverse((e=>{if(e instanceof i&&e.geometry instanceof t){const t=e.geometry;Array.isArray(e.material)&&t.groups.length>1&&t.groups.length>e.material.length&&M.mergeGroups(t)}}))}async loadByAsset(e){const t=this.getUri(e.fileKey);switch(e.fileFormat){case"glb":case"gltf":return this.glbLoader.loadAsync(t).then((e=>({scene:e.scene,animations:e.animations})));case"fbx":return this.fbxLoader.loadAsync(t).then((e=>({scene:e,animations:e.animations})));case"obj":if(null!=e.materialLib){const t=new h;t.materialOptions={normalizeRGB:!1};const s=await t.loadAsync(this.getUri(e.materialLib));this.objLoader.setMaterials(s)}return this.objLoader.loadAsync(t).then((e=>(R(e),e))).then((e=>({scene:e,animations:e.animations})))}}}function R(e){if(e instanceof i)for(const t of L(e.material))t instanceof x.MeshPhongMaterial&&!t.color.isLinear&&(t.color.isLinear=!0);e.children?.forEach(R)}export class AssetMeshInstance extends r{}export function getElectronArg(e){const t=`--${e}=`,s=window.process?.argv.find((e=>e.startsWith(t)));return s?.substring(t.length)}function W(e){switch(e){case"clamp":return x.ClampToEdgeWrapping;case"repeat":return x.RepeatWrapping;case"mirror":return x.MirroredRepeatWrapping}return x.RepeatWrapping}new x.Matrix4;const k=/_LOD(\d+)$/;/*
|
2
2
|
* Copyright (©) 2023. 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.
|
3
|
+
"version": "0.0.106",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"type": "module",
|
@@ -168,14 +168,14 @@
|
|
168
168
|
"dependencies": {
|
169
169
|
"@babel/runtime": "^7.24.8",
|
170
170
|
"@dimforge/rapier3d-compat": "^0.14.0",
|
171
|
-
"@hology/nebula": "^0.0.
|
171
|
+
"@hology/nebula": "^0.0.106",
|
172
172
|
"@plumier/reflect": "^1.1.0",
|
173
173
|
"@recast-navigation/three": "^0.35.2",
|
174
174
|
"recast-navigation": "^0.35.2",
|
175
175
|
"rxjs": "7.8.1",
|
176
176
|
"three-csm": "^4.2.1",
|
177
177
|
"three-mesh-bvh": "^0.7.5",
|
178
|
-
"three-shader-graph": "0.2.
|
178
|
+
"three-shader-graph": "^0.2.16",
|
179
179
|
"three-stdlib": "2.34.0",
|
180
180
|
"ts-key-enum": "^2.0.12",
|
181
181
|
"typedi": "^0.10.0"
|