@hology/core 0.0.92 → 0.0.95
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/csm.d.ts.map +1 -1
- package/dist/effects/vfx/initializsers.d.ts +4 -1
- package/dist/effects/vfx/initializsers.d.ts.map +1 -1
- package/dist/effects/vfx/initializsers.js +1 -1
- package/dist/effects/vfx/rates.d.ts +8 -0
- package/dist/effects/vfx/rates.d.ts.map +1 -1
- package/dist/effects/vfx/rates.js +1 -1
- package/dist/effects/vfx/vfx-actor.d.ts +2 -1
- package/dist/effects/vfx/vfx-actor.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-actor.js +1 -1
- package/dist/effects/vfx/vfx-asset.d.ts +3 -0
- package/dist/effects/vfx/vfx-asset.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-asset.js +1 -1
- package/dist/effects/vfx/vfx-collision-behaviour.d.ts +19 -0
- package/dist/effects/vfx/vfx-collision-behaviour.d.ts.map +1 -0
- package/dist/effects/vfx/vfx-collision-behaviour.js +4 -0
- package/dist/effects/vfx/vfx-defs.d.ts +27 -15
- package/dist/effects/vfx/vfx-defs.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-defs.js +1 -1
- package/dist/effects/vfx/vfx-materializer.d.ts +3 -4
- package/dist/effects/vfx/vfx-materializer.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-materializer.js +1 -1
- package/dist/effects/vfx/vfx-renderers.d.ts +1 -0
- package/dist/effects/vfx/vfx-renderers.d.ts.map +1 -1
- package/dist/effects/vfx/vfx-renderers.js +1 -1
- package/dist/gameplay/actors/actor.d.ts.map +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-movement.d.ts.map +1 -1
- package/dist/gameplay/actors/builtin/components/character/character-movement.js +1 -1
- package/dist/gameplay/actors/builtin/components/mesh-component.d.ts.map +1 -1
- package/dist/gameplay/actors/builtin/components/mesh-component.js +1 -1
- package/dist/gameplay/actors/builtin/navmesh-actor.d.ts +11 -0
- 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/camera/third-person-camera-component.d.ts.map +1 -1
- package/dist/gameplay/actors/camera/third-person-camera-component.js +1 -1
- package/dist/gameplay/actors/component.d.ts.map +1 -1
- package/dist/gameplay/ai/build-tile.d.ts +1 -1
- package/dist/gameplay/ai/build-tile.d.ts.map +1 -1
- package/dist/gameplay/ai/dynamic-tiled-navmesh.d.ts.map +1 -1
- package/dist/gameplay/ai/dynamic-tiled-navmesh.js +1 -1
- package/dist/gameplay/input/input.d.ts.map +1 -1
- package/dist/gameplay/services/physics/physics-system.d.ts.map +1 -1
- package/dist/gameplay/services/physics/physics-system.js +1 -1
- package/dist/gameplay/services/pointer-events.d.ts.map +1 -1
- package/dist/rendering.d.ts.map +1 -1
- package/dist/rendering.js +1 -1
- package/dist/scene/asset-resource-loader.js +1 -1
- package/dist/scene/collision/collision-shape-import.d.ts.map +1 -1
- package/dist/scene/collision/collision-shape-import.js +1 -1
- package/dist/scene/materializer.d.ts +11 -2
- package/dist/scene/materializer.d.ts.map +1 -1
- package/dist/scene/materializer.js +1 -1
- package/dist/scene/model.d.ts +4 -3
- package/dist/scene/model.d.ts.map +1 -1
- package/dist/scene/model.js +1 -1
- package/dist/scene/objects/prefab.d.ts +8 -0
- package/dist/scene/objects/prefab.d.ts.map +1 -0
- package/dist/scene/objects/prefab.js +4 -0
- package/dist/scene/objects/shapes.d.ts +1 -1
- package/dist/scene/objects/shapes.d.ts.map +1 -1
- package/dist/scene/scene-data-service.d.ts +17 -7
- package/dist/scene/scene-data-service.d.ts.map +1 -1
- package/dist/scene/scene-data-service.js +1 -1
- package/dist/scene/storage/storage.d.ts +9 -8
- package/dist/scene/storage/storage.d.ts.map +1 -1
- package/dist/scene/storage/storage.js +1 -1
- package/dist/shader/parameter.d.ts +2 -1
- package/dist/shader/parameter.d.ts.map +1 -1
- package/dist/shader-nodes/particle.d.ts +4 -2
- package/dist/shader-nodes/particle.d.ts.map +1 -1
- package/dist/shader-nodes/particle.js +1 -1
- package/dist/utils/curve.d.ts +12 -0
- package/dist/utils/curve.d.ts.map +1 -0
- package/dist/utils/curve.js +4 -0
- package/dist/utils/math.js +1 -1
- package/dist/utils/voxel-bitset.d.ts +14 -0
- package/dist/utils/voxel-bitset.d.ts.map +1 -0
- package/dist/utils/voxel-bitset.js +4 -0
- package/package.json +198 -122
- package/tsconfig.tsbuildinfo +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"character-movement.d.ts","sourceRoot":"","sources":["../../../../../../src/gameplay/actors/builtin/components/character/character-movement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAC/F,OAAO,EAAE,aAAa,EAAiB,MAAM,4DAA4D,CAAC;AAC1G,OAAO,EAAoB,OAAO,EAAwB,eAAe,EAAE,MAAM,OAAO,CAAC;AACzF,OAAO,EAAE,cAAc,EAAa,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAkBnD,qBACa,0BAA2B,SAAQ,cAAc;IA0D9C,OAAO,CAAC,aAAa;IAvDjC,QAAQ,CAAC,cAAc,YAAkB;IACzC,QAAQ,CAAC,SAAS,cAAoB;IACtC,QAAQ,CAAC,WAAW,cAAoB;IACxC,QAAQ,CAAC,aAAa,gBAAsB;IAGrC,eAAe,SAAI;IAGnB,QAAQ,SAAI;IACZ,iBAAiB,SAAI;IACrB,cAAc,SAAK;IACnB,YAAY,SAAI;IAChB,sBAAsB,SAAK;IAC3B,oBAAoB,UAAQ;IAC5B,eAAe,EAAE,MAAM,CAAO;IAC9B,cAAc,EAAE,MAAM,CAAI;IAC1B,cAAc,EAAE,MAAM,CAAK;IAC3B,SAAS,UAAQ;IACjB,IAAI,SAAK;IACT,YAAY,UAAO;IACnB,kBAAkB,SAAyB;IAC3C,kBAAkB,SAAyB;IAC3C,4BAA4B,UAAO;IAC1C,oCAAoC;IAC7B,kBAAkB,UAAQ;IACjC,IAAW,gBAAgB,IACW,MAAM,CADuB;IACnE,IAAW,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAA4G;IACxJ,IAAW,sBAAsB,IAAI,OAAO,CAAmD;IAC/F,IAAW,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAA8F;IAChJ,IAAW,iBAAiB,IACY,MAAM,CADuB;IACrE,IAAW,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAA4G;IAC1J,IAAW,YAAY,IACW,MAAM,CAD2B;IACnE,IAAW,YAAY,CAAC,QAAQ,EAAE,MAAM,EAA0C;IAClF,IAAW,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAiC;IACnE,IAAW,MAAM,IADW,MAAM,CACa;IAC/C,IAAW,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAA0C;IACrF,IAAW,iBAAiB,IADS,MAAM,CAC0B;IAErE;;;;OAIG;IACI,OAAO,UAAO;IAGrB,QAAQ,CAAC,QAAQ,UAAgB;IACjC,IAAI,wBAAgC;IACpC,WAAW,UAAQ;IACnB,WAAW,UAAQ;IAEnB,OAAO,CAAC,EAAE,CAAqC;IAC/C,OAAO,CAAC,aAAa,CAAsB;gBAEvB,aAAa,EAAE,aAAa;IAOhD,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,qBAAqB,CAAwB;IAErD;;;OAGG;IACI,yBAAyB,UAAQ;IAExC,mEAAmE;IAC5D,cAAc,UAAO;IAE5B,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;
|
1
|
+
{"version":3,"file":"character-movement.d.ts","sourceRoot":"","sources":["../../../../../../src/gameplay/actors/builtin/components/character/character-movement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAC/F,OAAO,EA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,CACa;IAC/C,IAAW,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAA0C;IACrF,IAAW,iBAAiB,IADS,MAAM,CAC0B;IAErE;;;;OAIG;IACI,OAAO,UAAO;IAGrB,QAAQ,CAAC,QAAQ,UAAgB;IACjC,IAAI,wBAAgC;IACpC,WAAW,UAAQ;IACnB,WAAW,UAAQ;IAEnB,OAAO,CAAC,EAAE,CAAqC;IAC/C,OAAO,CAAC,aAAa,CAAsB;gBAEvB,aAAa,EAAE,aAAa;IAOhD,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,qBAAqB,CAAwB;IAErD;;;OAGG;IACI,yBAAyB,UAAQ;IAExC,mEAAmE;IAC5D,cAAc,UAAO;IAE5B,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAiT9B,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,gBAAgB,CAAiB;IAClC,mBAAmB,CAAC,MAAM,EAAE,eAAe;IAUlD,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,MAAM;IAKP,mBAAmB;IAI1B,OAAO,CAAC,aAAa;IAkBrB,IAAW,UAAU,YAEpB;IAED,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,IAAI;IA8BZ,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,WAAW;CAQtB"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as t,__metadata as
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{ActionInput as i,AxisInput as o,RotationInput as s}from"../../../../../gameplay/input/index.js";import{PhysicsSystem as n,RayTestResult as r}from"../../../../../gameplay/services/physics/physics-system.js";import{MathUtils as a,Vector3 as c,ArrowHelper as l}from"three";import{ActorComponent as h,Component as p}from"../../../component.js";import{CharacterMovementMode as m}from"./modes.js";import{CapsuleCollisionShape as d}from"../../../../../scene/collision/collision-shape.js";import{takeUntil as u}from"rxjs";import{PhysicsBodyType as y}from"../../../../services/physics/physics-system.js";import g from"@dimforge/rapier3d-compat";import{RootMotionClip as f}from"../../../../../gameplay/animation/root-motion.js";import*as S from"three";import{clamp as w}from"../../../../../utils/math.js";const v=new c,M=new c,A=1/30,x=-131071;let T=class extends h{get autoStepMinWidth(){return this.cc.autostepMinWidth()}set autoStepMinWidth(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),t,this.cc.autostepIncludesDynamicBodies())}get autoStepDynamicObjects(){return this.cc.autostepIncludesDynamicBodies()}set autoStepDynamicObjects(t){this.cc.enableAutostep(this.cc.autostepMaxHeight(),this.cc.autostepMinWidth(),t)}get autoStepMaxHeight(){return this.cc.autostepMaxHeight()}set autoStepMaxHeight(t){this.cc.enableAutostep(t,this.cc.autostepMinWidth(),this.cc.autostepIncludesDynamicBodies())}get snapToGround(){return this.cc.snapToGroundDistance()}set snapToGround(t){this.cc.enableSnapToGround(t)}set offset(t){this.cc.setOffset(t)}get offset(){return this.cc.offset()}set normalNudgeFactor(t){this.cc.setNormalNudgeFactor(t)}get normalNudgeFactor(){return this.cc.normalNudgeFactor()}constructor(t){super(),this.physicsSystem=t,this.directionInput=new o,this.jumpInput=new i,this.sprintInput=new i,this.rotationInput=new s,this.horizontalSpeed=0,this.maxSpeed=8,this.maxSpeedBackwards=8,this.maxSpeedSprint=12,this.jumpVelocity=7,this.fallingMovementControl=.5,this.fallingReorientation=!1,this.gravityOverride=null,this.colliderHeight=2,this.colliderRadius=.5,this.jumpInAir=!1,this.mass=50,this.allowSliding=!0,this.minSlopeSlideAngle=a.degToRad(70),this.maxSlopeClimbAngle=a.degToRad(70),this.applyImpulsesToDynamicBodies=!0,this.characterCollision=!1,this.enabled=!0,this.velocity=new c,this.mode=m.walking,this.isSprinting=!1,this.pressedJump=!1,this.rayTestResult=new r,this.resetRootMotion=!1,this.rotateToMovementDirection=!1,this.smoothRotation=!0;const e=this.cc=this.physicsSystem.getCharacterController(.1);e.enableSnapToGround(.1),e.enableAutostep(0,.1,!1)}onInit(){const t=this.cc;t.setApplyImpulsesToDynamicBodies(this.applyImpulsesToDynamicBodies),t.setMinSlopeSlideAngle(this.minSlopeSlideAngle),t.setMaxSlopeClimbAngle(this.maxSlopeClimbAngle),t.setCharacterMass(this.mass),t.setSlideEnabled(this.allowSliding),this.physicsSystem.addActor(this.actor,[this.createCollisionShape()],{mass:0,type:y.kinematic,continousCollisionDetection:!1,friction:0,restitution:.5,ignoreForNavMesh:!0}),this.rotationInput.rotation.copy(this.actor.rotation);let e=this.rotationInput.rotation.y;const i=new c,o=new c,s=new c,n=new c(0,0,1),r=new c,l=new c,h=new c;let p=0,d=null;const g=new c,T=new c,C=new c,j=new c,R=new c,G=this.characterCollision?null:x;this.physicsSystem.beforeStep.pipe(u(this.disposed)).subscribe((u=>{if(this.checkGrounded(u),!this.enabled)return;if(null!=this.rootMotionAction){if(this.rootMotionAction.getClip()instanceof f){const t=this.rootMotionInterpolant;this.resetRootMotion&&(g.fromArray(t.evaluate(0)),this.resetRootMotion=!1),j.fromArray(t.evaluate(this.rootMotionAction.time)),T.subVectors(j,g),g.copy(j),this.rootMotionAction.getRoot().getWorldScale(C),T.multiply(C)}}u>A&&(u=A);const y=null!=this.rootMotionAction&&this.rootMotionAction.enabled&&0!=T.length();this.pressedJump=this.jumpInput.activated,this.isSprinting=this.sprintInput.activated;let x=this.rotationInput.rotation.y-e;s.copy(this.actor.position),r.set(-this.directionInput.vector.x,0,this.directionInput.vector.y).normalize();const V=!this.rotateToMovementDirection&&r.z<0?this.maxSpeedBackwards:this.isSprinting?this.maxSpeedSprint:this.maxSpeed;if(h.set(0,0,0),this.rotateToMovementDirection){if(r.lengthSq()>0){z.setFromUnitVectors(n.clone().normalize(),r.clone().normalize()),n.copy(r);const t=(x%(2*Math.PI)+3*Math.PI)%(2*Math.PI)-Math.PI,i=Math.abs(t),o=this.smoothRotation?w(10*u*t,-i,i):t;H.setFromEuler(k.set(0,o,0)),z.multiply(H),this.actor.object.applyQuaternion(z),h.copy(this.actor.object.getWorldDirection(F).normalize()),e+=o}}else h.copy(r).applyAxisAngle(I,this.rotationInput.rotation.y),e=this.rotationInput.rotation.y,this.actor.rotation.y+=x;if(R.set(0,0,0),this.rayTestResult.hasHit&&null!=this.rayTestResult.actor&&this.physicsSystem.getLinearVelocity(this.rayTestResult.actor,R),this.mode===m.walking?(0!==h.length()?(p=Math.min(V,p),p=a.lerp(p,V,4*u)):p=0,l.copy(h).multiplyScalar(p),this.pressedJump&&(this.mode=m.falling,this.velocity.copy(l),this.velocity.y=this.jumpVelocity),l.y=.016*this.getEffectiveGravity(),l.add(R)):this.mode===m.falling&&(this.pressedJump&&this.jumpInAir&&(this.mode=m.falling,this.velocity.copy(l),this.velocity.y=this.jumpVelocity),this.velocity.y+=u*this.getEffectiveGravity(),l.copy(this.velocity),l.addScaledVector(h,this.fallingMovementControl),this.fallingReorientation&&l.applyAxisAngle(new c(0,1,0),x)),o.copy(l).normalize(),i.copy(l),l.length(),y?(T.applyAxisAngle(I,this.actor.rotation.y),T.y+=u*this.getEffectiveGravity(),v.copy(T)):v.copy(l).multiplyScalar(u),this.isGrounded&&this.mode===m.walking&&(this.rayTestResult.distance>t.offset()||(v.y=Math.max(0,R.y*u)),this.physicsSystem.getActorComputedMovement(this.actor,t,v,G),t.computedCollision(0,D),null!=D&&null!=D.normal1)){const e=(new S.Vector3).copy(D.normal1);Math.acos(e.dot(I))>t.maxSlopeClimbAngle()&&(v.y=.016*this.getEffectiveGravity()*.5)}M.copy(this.physicsSystem.getActorComputedMovement(this.actor,t,v,G)),this.physicsSystem.setNextKinematicTranslation(this.actor,M);let E=function(t){if(t.numComputedCollisions()>0){const e=t.computedCollision(0);b.x=e.normal2.x,b.y=e.normal2.y,b.z=e.normal2.z;const i=b.angleTo(I);b.x=e.normal1.x,b.y=e.normal1.y,b.z=e.normal1.z;const o=b.angleTo(I);return!(i<100)&&o>t.minSlopeSlideAngle()}return!1}(t);y||this.isGrounded&&!E||this.mode!==m.falling&&(null==d?d=performance.now():performance.now()-d>100&&(this.mode=m.falling,this.velocity.copy(i))),this.isGrounded&&this.velocity.y<=0&&(this.mode,m.falling,this.mode=m.walking,this.velocity.y=0,d=null),this.mode,m.walking,this.horizontalSpeed=p}))}debugDirection(){const t=new l(v,this.actor.position,1,65280);this.actor.object.parent.add(t),setTimeout((()=>{t.removeFromParent()}),30);const e=new l(M,this.actor.position,1,16711680);this.actor.object.parent.add(e),setTimeout((()=>{e.removeFromParent()}),30)}setRootMotionAction(t){const e=t?.getClip();if(e instanceof f){this.rootMotionAction=t,this.resetRootMotion=!0;const i=[];this.rootMotionInterpolant=e.motionTrack.InterpolantFactoryMethodSmooth(i)}}getWallDirection(t,e){const i=t.clone().negate().cross(I);return i.dot(e)<0?i.negate():i}moveTo(t){this.actor.position.copy(t),this.physicsSystem.updateActorTransform(this.actor)}getEffectiveGravity(){return this.gravityOverride??this.physicsSystem.getGravity().y}checkGrounded(t){this.colliderHeight,this.colliderRadius;G.y=-.05,this.physicsSystem.rayTest(C.addVectors(this.actor.position,R.set(0,this.offset,0)),j.addVectors(this.actor.position,G),this.rayTestResult,{excludeActor:this.actor,excludeTriggers:!0})}get isGrounded(){return this.rayTestResult.hasHit||this.cc.computedGrounded()}createCollisionShape(){const t=new d(this.colliderHeight,this.colliderRadius);return t.offset.y=this.colliderRadius+this.colliderHeight/2+this.offset,t.collisionGroup=x,t}step(t){}performMovement(t){}arrowHelper(t,e,i){const o=new l(t,e,1,i);this.actor.object.parent.add(o),setTimeout((()=>{o.removeFromParent()}),30)}};T=t([p({inEditor:!1}),e("design:paramtypes",[n])],T);export{T as CharacterMovementComponent};const I=new c(0,1,0),b=new c;const C=new c,j=new c,R=new c(0,1,0),G=new c(0,-.1,0),D=(new c(0,-1,0),new g.CharacterCollision),z=new S.Quaternion,H=new S.Quaternion,k=new S.Euler,F=new S.Vector3;/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mesh-component.d.ts","sourceRoot":"","sources":["../../../../../src/gameplay/actors/builtin/components/mesh-component.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,EACd,MAAM,yDAAyD,CAAA;AAIhE,OAAO,EAAE,KAAK,EAAQ,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACtD,OAAO,EAAE,cAAc,EAAa,MAAM,oBAAoB,CAAA;AAU9D,qBACa,aAAa,CAAC,IAAI,SAAS,QAAQ,GAAG,QAAQ,CAAE,SAAQ,cAAc;
|
1
|
+
{"version":3,"file":"mesh-component.d.ts","sourceRoot":"","sources":["../../../../../src/gameplay/actors/builtin/components/mesh-component.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,aAAa,EACd,MAAM,yDAAyD,CAAA;AAIhE,OAAO,EAAE,KAAK,EAAQ,QAAQ,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACtD,OAAO,EAAE,cAAc,EAAa,MAAM,oBAAoB,CAAA;AAU9D,qBACa,aAAa,CAAC,IAAI,SAAS,QAAQ,GAAG,QAAQ,CAAE,SAAQ,cAAc;IAmCrE,OAAO,CAAC,aAAa;IA/BjC,MAAM,EAAE,IAAI,CAAA;IAGZ,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAgB;IAG1C,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAc;IAGtC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAqB;IAG5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAA6B;IAGlD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAiC;IAO1D,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAyB;IAG3D,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAQ;IAEnC,QAAQ,CAAC,2BAA2B,EAAE,OAAO,CAAoD;IAEjG,OAAO,CAAC,WAAW,CAAM;gBAEL,aAAa,EAAE,aAAa;IAIhD,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAUvB,SAAS,CAAC,WAAW,EAAE,IAAI;IAQlC,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,kBAAkB;CAc3B"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as t,__metadata as s}from"tslib";import{PhysicsBodyType as i,PhysicsSystem as e}from"../../../../gameplay/services/physics/physics-system.js";import{AssetMeshInstance as o}from"../../../../scene/asset-resource-loader.js";import{PhysicalShapeMesh as r}from"../../../../index.js";import{Parameter as n}from"../../../../shader/parameter.js";import{Euler as c,Object3D as h,Vector3 as p}from"three";import{ActorComponent as a,Component as l}from"../../component.js";import{firstValueFrom as
|
1
|
+
import{__decorate as t,__metadata as s}from"tslib";import{PhysicsBodyType as i,PhysicsSystem as e}from"../../../../gameplay/services/physics/physics-system.js";import{AssetMeshInstance as o}from"../../../../scene/asset-resource-loader.js";import{PhysicalShapeMesh as r}from"../../../../index.js";import{Parameter as n}from"../../../../shader/parameter.js";import{Euler as c,Object3D as h,Vector3 as p}from"three";import{ActorComponent as a,Component as l}from"../../component.js";import{firstValueFrom as m}from"rxjs";const y={friction:.1,mass:0,bodyType:i.static,continousCollisionDetection:!1};let d=class extends a{constructor(t){super(),this.physicsSystem=t,this.position=new p,this.rotation=new c,this.scale=new p(1,1,1),this.mass=y.mass,this.friction=y.friction,this.bodyType=i.static,this.isTrigger=!1,this.continousCollisionDetection=y.continousCollisionDetection}onInit(){null!=this.object&&(this.currentMesh=this.object,this.updateMesh()),m(this.disposed).then((()=>{this.physicsSystem.removeActor(this.actor)}))}setObject(t){null!=this.currentMesh&&this.actor.object.remove(this.currentMesh),this.object=this.currentMesh=t,this.updateMesh()}updateMesh(){this.currentMesh.position.copy(this.position),this.currentMesh.rotation.copy(this.rotation),this.currentMesh.scale.copy(this.scale);const t=this.getCollisionShapes();t.length>0&&this.physicsSystem.addActor(this.actor,t,{...y,isTrigger:this.isTrigger??!1,mass:this.mass,friction:this.friction,type:this.bodyType,continousCollisionDetection:this.continousCollisionDetection}),this.actor.object.add(this.currentMesh)}getCollisionShapes(){return this.currentMesh instanceof o?this.currentMesh.collisionShapes:this.currentMesh instanceof r?[this.currentMesh.collisionShape]:"collisionShape"in this.currentMesh?(console.error("Could not understand wehre to get collision shapes from. This is likely due to an import issue"),[this.currentMesh.collisionShape]):[]}};t([n({type:h}),s("design:type",Object)],d.prototype,"object",void 0),t([n(),s("design:type",p)],d.prototype,"position",void 0),t([n(),s("design:type",c)],d.prototype,"rotation",void 0),t([n(),s("design:type",p)],d.prototype,"scale",void 0),t([n(),s("design:type",Number)],d.prototype,"mass",void 0),t([n(),s("design:type",Number)],d.prototype,"friction",void 0),t([n({options:[{name:"Static",value:i.static},{name:"Kinematic",value:i.kinematic},{name:"Dynamic",value:i.dynamic}]}),s("design:type",Number)],d.prototype,"bodyType",void 0),t([n(),s("design:type",Boolean)],d.prototype,"isTrigger",void 0),d=t([l({inEditor:!0}),s("design:paramtypes",[e])],d);export{d as MeshComponent};/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -1,13 +1,21 @@
|
|
1
1
|
import { NavMesh } from 'recast-navigation';
|
2
|
+
import { Color } from 'three';
|
2
3
|
import { BaseActor } from "../../";
|
4
|
+
import { ActorComponent } from '../../../gameplay';
|
3
5
|
export declare function safeRecastInit(): Promise<boolean | void>;
|
4
6
|
export type NavMeshLoader = {
|
5
7
|
save(): any;
|
6
8
|
};
|
9
|
+
export declare class TriggerVolumeMesh extends ActorComponent {
|
10
|
+
color: Color;
|
11
|
+
private dimensions;
|
12
|
+
onInit(): void | Promise<void>;
|
13
|
+
}
|
7
14
|
declare class NavMeshActor extends BaseActor {
|
8
15
|
private physics;
|
9
16
|
private view;
|
10
17
|
private world;
|
18
|
+
private editorVisualisation;
|
11
19
|
debug: boolean;
|
12
20
|
refreshMs: number;
|
13
21
|
private tileSize;
|
@@ -15,7 +23,10 @@ declare class NavMeshActor extends BaseActor {
|
|
15
23
|
walkableSlopeAngle: number;
|
16
24
|
cellSize: number;
|
17
25
|
navMesh: NavMesh;
|
26
|
+
private bounds;
|
27
|
+
private recreateInterval;
|
18
28
|
onInit(): Promise<void>;
|
29
|
+
onEndPlay(): void;
|
19
30
|
private init;
|
20
31
|
}
|
21
32
|
export default NavMeshActor;
|
@@ -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;AAG5C,OAAO,EAAuG,KAAK,EAAC,MAAM,OAAO,CAAC;AAElI,OAAO,EAAS,SAAS,EAAmE,MAAM,QAAQ,CAAC;AAI3G,OAAO,EAAY,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAW5D,wBAAsB,cAAc,4BASnC;AASD,MAAM,MAAM,aAAa,GAAG;IAO1B,IAAI,QAAE;CACP,CAAA;AAED,qBACa,iBAAkB,SAAQ,cAAc;IAEtC,KAAK,EAAE,KAAK,CAAsB;IAE/C,OAAO,CAAC,UAAU,CAA8B;IAEhD,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAY/B;AAGD,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,CAAc;IAIjB,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;CAmPb;AAED,eAAe,YAAY,CAAA"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import{Ball 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 d,getPositionsAndIndices as u}from"@recast-navigation/three";import{BehaviorSubject as m,debounceTime as f,filter as w,firstValueFrom as g,Subject as b,takeUntil as y}from"rxjs";import*as x from"three";import{Mesh as v,EdgesGeometry as B,LineSegments as M,LineBasicMaterial as S,Vector3 as z,BoxGeometry as A,MeshBasicMaterial as C,Group as j,Color as k}from"three";import{BufferGeometryUtils as I,ConvexHull as F}from"three/examples/jsm/Addons.js";import{Actor as P,BaseActor as V,Parameter as G,PhysicsSystem as N,ViewController as D,World as E,attach as H,inject as R}from"../../";import{DynamicTiledNavMesh as T}from"../../ai/dynamic-tiled-navmesh";import{hasSharedArrayBufferSupport as U,toSharedFloat32Array as q,toSharedUint32Array as O}from"../../../utils/buffer";import{sleepDelay as _}from"../../../utils/async";import{Component as W,ActorComponent as X}from"../../../gameplay";var L;!function(e){e[e.none=0]="none",e[e.starting=1]="starting",e[e.started=2]="started"}(L||(L={}));let $=L.none,J=new m(!1);export async function safeRecastInit(){return $===L.none?($=L.starting,p().then((()=>{J.next(!0),$=L.started}))):g(J.pipe(w((e=>e))))}new x.Box3(new x.Vector3(-100,-100,-100),new x.Vector3(100,100,100));const K=navigator.hardwareConcurrency??1;let Q=class extends X{constructor(){super(...arguments),this.color=new k(16777215),this.dimensions=new z(1,1,1)}onInit(){const e=new A(this.dimensions.x,this.dimensions.y,this.dimensions.z),t=new B(e),n=new M(t,new S({color:this.color})),o=(new v(e,new C({color:this.color,transparent:!0,opacity:.3,visible:!1})),new j);o.add(n),this.actor.object.add(o)}};e([G(),t("design:type",k)],Q.prototype,"color",void 0),Q=e([W({inEditor:!0,editorOnly:!0})],Q);export{Q as TriggerVolumeMesh};let Y=!1,Z=class extends V{constructor(){super(...arguments),this.physics=R(N),this.view=R(D),this.world=R(E),this.editorVisualisation=H(Q),this.debug=!0,this.refreshMs=4e3,this.tileSize=400,this.walkableClimb=.3,this.walkableSlopeAngle=45,this.cellSize=.2,this.bounds=new x.Box3}async onInit(){Y||(await safeRecastInit(),Y=!0),setTimeout((()=>{this.init()}),10),this.recreateInterval=setInterval((()=>{if("_hology_transform_group"===this.object.parent?.name)return;oe.setFromCenterAndSize(this.position,this.object.scale).equals(this.bounds)||(this.disposed.next(!0),this.disposed=new b,this.init())}),1e3)}onEndPlay(){clearInterval(this.recreateInterval)}init(){const e=Math.max(this.cellSize,.01),t={tileSize:400,walkableClimb:this.walkableClimb/e,walkableSlopeAngle:this.walkableSlopeAngle,walkableRadius:2,walkableHeight:5,detailSampleDist:1,minRegionArea:6,mergeRegionArea:400,cs:e,ch:e,maxSimplificationError:1.3,maxEdgeLen:200};this.bounds.setFromCenterAndSize(this.position,this.object.scale);const n=new T({navMeshBounds:this.bounds,recastConfig:t,maxTiles:1024,workers:K,cacheId:"nav"+this.object.userData?.src?.id});this.navMesh=n.navMesh;const o=this.tileSize*t.cs*2,s=performance.now(),i=new Map,r=new d;r.userData.isDebugDrawer=!0;n.navMesh;const a=this.bounds,c=()=>{const e=this.view.getCamera().getWorldPosition(new x.Vector3),t=new x.Box3((new x.Vector3).copy(e).subScalar(o),(new x.Vector3).copy(e).addScalar(o)),n=[],s=this.physics.world.bodies;if(null==s)return[];const r=new x.Box3;for(const e of s.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=i.get(a)?.mesh,l=c??te(s);if(ne(s,l),null!=l){r.copy(l.geometry.boundingBox),r.min.add(l.position),r.max.add(l.position);const e=r.intersectsBox(t)||!0,o=r.intersectsBox(this.bounds);i.set(a,{pos:s.translation(),mesh:l}),e&&o&&n.push(l)}}return n},l=new x.Box3,h=new Map,p=new Map;let m=!0,w=performance.now(),g=!1;const b=function(e,t){let n=!1;return(async()=>{for(;!n;)await e(),await _(t)})(),()=>{n=!0}}((async()=>{if(g)return;const e=new x.Box3,t=c();for(const n of t){const t=h.get(n);!0!==t?.equals(n.position)&&(null!=t&&e.expandByPoint(t),e.expandByObject(n),h.set(n,n.position.clone()))}e.min.subScalar(50),e.max.addScalar(50);const o=n.getTilesForBounds(e);if(0!=o.length){const s=[];for(const n of t)l.setFromObject(n),l.intersectsBox(e)&&s.push(n);console.log("intersecting meshes",s.length);let[i,r]=u(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,a),U&&(i=q(i),r=O(r));const c=m;m=!1,await Promise.all(o.map((e=>(w=performance.now(),n.buildTile(i,r,e,c).then((()=>{const t=e[0]+","+e[1];p.set(t,(p.get(t)??0)+1),this.debug})))))).then((()=>{this.debug,g=!1}))}else g=!1}),this.refreshMs??1e4);this.disposed.subscribe((()=>b())),n.onNavMeshUpdate.pipe(y(this.disposed),f(200)).subscribe((()=>{r.clear(),r.drawNavMesh(n.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(r)),this.disposed.subscribe((()=>{n?.destroy(),r.removeFromParent(),r.dispose()}));const v=performance.now()-s;v>1e3&&console.warn(`NavMesh update took ${v} ms. Consider changing tileSize or other parameter that may affect performance`)}};e([G(),t("design:type",Boolean)],Z.prototype,"debug",void 0),e([G(),t("design:type",Number)],Z.prototype,"walkableClimb",void 0),e([G({range:[0,89]}),t("design:type",Number)],Z.prototype,"walkableSlopeAngle",void 0),e([G({range:[.01,10]}),t("design:type",Number)],Z.prototype,"cellSize",void 0),Z=e([P()],Z);export default Z;function ee(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,d=new x.PlaneGeometry(c,a,r,i);d.rotateX(-Math.PI/2);const u=d.attributes.position.array;let m=0;for(let e=0;e<p;e++)for(let t=0;t<p;t++)u[m+1]=s[t*p+e]*h,m+=3,0!=u[m+1]&&(n=!0);if(!n){const e=new x.PlaneGeometry(a,c,2,2);return e.rotateX(-Math.PI/2),e}return d}(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 F).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=I.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 te(e){const t=ee(e);if(null==t)return null;const n=se,o=new x.Mesh(t,n);return o.geometry.computeBoundingBox(),o.geometry.scale(1.01,1.01,1.01),o}function ne(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 oe=new x.Box3,se=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
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"third-person-camera-component.d.ts","sourceRoot":"","sources":["../../../../src/gameplay/actors/camera/third-person-camera-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA6B,MAAM,iBAAiB,CAAC;AAE5E,OAAO,EAAqB,iBAAiB,EAAC,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAiB,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAiB,MAAM,0CAA0C,CAAC;AAUxF;;;GAGG;AACH,qBACa,0BAA2B,SAAQ,cAAc;IA+BhD,OAAO,CAAC,cAAc;IAAkB,OAAO,CAAC,aAAa;IA7BzE,OAAO,CAAC,MAAM,CAA6F;IACvF,IAAI,EAAE,MAAM,CAAc;IAC1B,GAAG,EAAE,MAAM,CAAa;IACxB,SAAS,EAAE,MAAM,CAAqB;IACnD,MAAM,EAAE,iBAAiB,CAA0E;IAEnG,QAAQ,EAAE,MAAM,CAAI;IACpB,WAAW,EAAE,MAAM,CAAM;IACzB,WAAW,SAAgB;IAC3B,MAAM,SAAI;IACV,OAAO,SAAK;IACZ,OAAO,SAAM;IACb,YAAY,EAAE,OAAO,CAAO;IAC5B,eAAe,SAAI;IAE1B,OAAO,CAAC,oBAAoB,CAAK;IACjC,OAAO,CAAC,kBAAkB,CAA4C;IAEtE,SAAgB,aAAa,0BAAwD;IACrF,SAAgB,SAAS,eAA4B;IAErD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IAEvC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA2C;IAEjE,WAAW,UAAO;IAEzB,OAAO,CAAC,KAAK,CAAgB;gBAET,cAAc,EAAE,cAAc,EAAU,aAAa,EAAE,aAAa;IAEjF,aAAa,UAAQ;IACtB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAYtB,QAAQ;IAuBR,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAI5C,OAAO,KAAK,OAAO,GAElB;IAED,OAAO,CAAC,MAAM,CAAqB;IAC5B,UAAU;IAkBjB,OAAO,CAAC,wBAAwB,CAAO;IAEhC,UAAU;IAOjB,OAAO,CAAC,WAAW,CAIlB;IAED,OAAO,CAAC,SAAS,CAIhB;IAED,OAAO,CAAC,mBAAmB,CAK1B;IAED,OAAO,CAAC,eAAe;IAkBvB,OAAO,CAAC,iBAAiB;IA0CzB,OAAO,CAAC,iBAAiB;IAWzB,OAAO,CAAC,oBAAoB;
|
1
|
+
{"version":3,"file":"third-person-camera-component.d.ts","sourceRoot":"","sources":["../../../../src/gameplay/actors/camera/third-person-camera-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA6B,MAAM,iBAAiB,CAAC;AAE5E,OAAO,EAAqB,iBAAiB,EAAC,MAAM,OAAO,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA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AED,OAAO,CAAC,eAAe;IAkBvB,OAAO,CAAC,iBAAiB;IA0CzB,OAAO,CAAC,iBAAiB;IAWzB,OAAO,CAAC,oBAAoB;CAoB7B;AAcD,8EAA8E;AAC9E,qBAAa,yBAA0B,SAAQ,0BAA0B;CAAG"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as t,__metadata as e}from"tslib";import{ActorComponent as i,Component as s}from"../component.js";import{Vector3 as o,MathUtils as n,PerspectiveCamera as a}from"three";import{ViewController as r}from"../../services/render.js";import{DecimalInput as h,RestrictedRotationInput as c}from"../../input/index.js";import{PhysicsSystem as d,RayTestResult as m}from"../../services/physics/physics-system.js";import{Parameter as l}from"../../../shader/parameter.js";import{World as p}from"../../services/world.js";import{inject as u}from"../../inject.js";const f=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let w=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.5,this.far=500,this.viewAngle=f?30:45,this.camera=new a(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=5,this.collisionCheckRadius=.5,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new c(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new h(1,0,1),this.offset=new o,this.lookAtOffset=new o(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(p),this.isMouseLocked=!1,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||"mouse"!==t.pointerType||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{null!=document.pointerLockElement||null!=document.mozPointerLockElement||this.showCursor()}}async onInit(){this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.activate()}activate(){this.viewController.setCamera(this.camera);const t=this.element;null!=document.body.requestPointerLock&&(t.addEventListener("pointerdown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.disposed.subscribe((()=>{t.removeEventListener("pointerdown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1)})))}onLateUpdate(t){this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor(){null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||(this.element.style.cursor="none",null==this.canvas&&(this.canvas=this.element.getElementsByTagName("canvas")[0]),this.canvas&&(this.canvas.requestPointerLock(),this.isMouseLocked=!0))}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.checkForCollision(t);const e=n.clamp(Math.min(this.restrictedDistance,this.distance),Math.min(this.minDistance,this.restrictedDistance),Math.max(this.distance*this.zoomInput.value,this.minDistance)),i=Math.cos(this.rotationInput.rotation.x)*e,s=this.fixedBehind?0:this.rotationInput.rotation.y;this.offset.x=Math.sin(-s)*i,this.offset.y=Math.sin(this.rotationInput.rotation.x)*e+2,this.offset.z=Math.cos(-s)*-i,this.offset.add(this.lookAtOffset),this.updateCameraPosition()}checkForCollision(t){const e=this.getLookAtPosition(),i=y;let s=!1,o=this.distance;const a=new m,r=this.camera.getWorldPosition(g);for(let t=-1;t<=1;t++){const n=k.subVectors(r,e);i.copy(r).add(n.multiplyScalar(1.2)),i.x+=t*this.collisionCheckRadius,this.physicsSystem.rayTest(e,i,a,{debugLifetime:0,excludeActor:this.actor,excludeTriggers:!0}),a.hasHit&&a.distance<this.distance&&(o=Math.min(a.distance,o),s||(s=a.hasHit))}s||(this.restrictedDistance=n.lerp(this.restrictedDistance,this.distance,n.clamp(this.bounceBackSpeed*t,0,1)))}getLookAtPosition(){const t=v;return t.set(0,0,0),t.y=this.height,t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t}updateCameraPosition(){this.fixedBehind?(this.
|
1
|
+
import{__decorate as t,__metadata as e}from"tslib";import{ActorComponent as i,Component as s}from"../component.js";import{Vector3 as o,MathUtils as n,PerspectiveCamera as a}from"three";import{ViewController as r}from"../../services/render.js";import{DecimalInput as h,RestrictedRotationInput as c}from"../../input/index.js";import{PhysicsSystem as d,RayTestResult as m}from"../../services/physics/physics-system.js";import{Parameter as l}from"../../../shader/parameter.js";import{World as p}from"../../services/world.js";import{inject as u}from"../../inject.js";const f=void 0!==window&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);let w=class extends i{constructor(t,e){super(),this.viewController=t,this.physicsSystem=e,this.aspect=this.viewController.htmlElement.clientWidth/this.viewController.htmlElement.clientHeight,this.near=.5,this.far=500,this.viewAngle=f?30:45,this.camera=new a(this.viewAngle,this.aspect,this.near,this.far),this.distance=9,this.minDistance=1.5,this.maxDistance=this.distance,this.height=3,this.offsetX=-1,this.offsetZ=1.5,this.autoActivate=!0,this.bounceBackSpeed=5,this.collisionCheckRadius=.5,this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.rotationInput=new c(-Math.PI/4,Math.PI/2-.7),this.zoomInput=new h(1,0,1),this.offset=new o,this.lookAtOffset=new o(this.offsetX,0,this.offsetZ),this.fixedBehind=!0,this.world=u(p),this.isMouseLocked=!1,this.canvas=null,this.pointerLockInactivatedAt=null,this.onMouseDown=t=>{this.isMouseLocked||"mouse"!==t.pointerType||this.hideCursor()},this.onKeyDown=t=>{"Escape"===t.key&&this.showCursor()},this.onPointerLockChange=()=>{null!=document.pointerLockElement||null!=document.mozPointerLockElement||this.showCursor()}}async onInit(){this.world.scene.add(this.camera),this.rotationInput.rotation.copy(this.actor.rotation),this.restrictedDistance=Math.max(this.distance,this.maxDistance),this.lookAtOffset.set(this.offsetX,0,this.offsetZ),this.autoActivate&&this.activate()}activate(){this.viewController.setCamera(this.camera);const t=this.element;null!=document.body.requestPointerLock&&(t.addEventListener("pointerdown",this.onMouseDown),t.addEventListener("keydown",this.onKeyDown),document.addEventListener("pointerlockchange",this.onPointerLockChange,!1),this.disposed.subscribe((()=>{t.removeEventListener("pointerdown",this.onMouseDown),t.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("pointerlockchange",this.onPointerLockChange,!1)})))}onLateUpdate(t){this.setFromRotation(t)}get element(){return this.viewController.htmlElement}hideCursor(){null!=this.pointerLockInactivatedAt&&performance.now()-this.pointerLockInactivatedAt<1600||(this.element.style.cursor="none",null==this.canvas&&(this.canvas=this.element.getElementsByTagName("canvas")[0]),this.canvas&&(this.canvas.requestPointerLock(),this.isMouseLocked=!0))}showCursor(){this.pointerLockInactivatedAt=performance.now(),this.element.style.cursor="default",window.document.exitPointerLock(),this.isMouseLocked=!1}setFromRotation(t){this.checkForCollision(t);const e=n.clamp(Math.min(this.restrictedDistance,this.distance),Math.min(this.minDistance,this.restrictedDistance),Math.max(this.distance*this.zoomInput.value,this.minDistance)),i=Math.cos(this.rotationInput.rotation.x)*e,s=this.fixedBehind?0:this.rotationInput.rotation.y;this.offset.x=Math.sin(-s)*i,this.offset.y=Math.sin(this.rotationInput.rotation.x)*e+2,this.offset.z=Math.cos(-s)*-i,this.offset.add(this.lookAtOffset),this.updateCameraPosition()}checkForCollision(t){const e=this.getLookAtPosition(),i=y;let s=!1,o=this.distance;const a=new m,r=this.camera.getWorldPosition(g);for(let t=-1;t<=1;t++){const n=k.subVectors(r,e);i.copy(r).add(n.multiplyScalar(1.2)),i.x+=t*this.collisionCheckRadius,this.physicsSystem.rayTest(e,i,a,{debugLifetime:0,excludeActor:this.actor,excludeTriggers:!0}),a.hasHit&&a.distance<this.distance&&(o=Math.min(a.distance,o),s||(s=a.hasHit))}s||(this.restrictedDistance=n.lerp(this.restrictedDistance,this.distance,n.clamp(this.bounceBackSpeed*t,0,1)))}getLookAtPosition(){const t=v;return t.set(0,0,0),t.y=this.height,t.add(this.lookAtOffset),t.applyMatrix4(this.actor.object.matrixWorld),t}updateCameraPosition(){this.fixedBehind?(this.camera.position.set(this.offset.x,this.offset.y,this.offset.z),this.camera.rotation.set(0,0,0),this.camera.scale.set(1,1,1),this.camera.applyMatrix4(this.actor.object.matrix)):this.camera.position.copy(this.actor.position).add(this.offset);const t=this.getLookAtPosition();this.camera.lookAt(t)}};t([l(),e("design:type",Number)],w.prototype,"near",void 0),t([l(),e("design:type",Number)],w.prototype,"far",void 0),t([l(),e("design:type",Number)],w.prototype,"viewAngle",void 0),w=t([s(),e("design:paramtypes",[r,d])],w);export{w as ThirdPersonCameraComponent};const v=new o,y=new o,k=(new o,new o),g=new o;export class ThirdPartyCameraComponent extends w{}/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/gameplay/actors/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,aAAa,EAAqB,MAAM,QAAQ,CAAC;AACtF,OAAO,EAAE,SAAS,EAAkC,MAAM,YAAY,CAAA;AAItE,8BAAsB,cAAc,CAAC,SAAS,SAAS,SAAS,GAAG,SAAS;IACnE,KAAK,EAAE,SAAS,CAAA;;IAMvB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,GAAC,IAAI;IAC5B,WAAW,IAAI,IAAI;IACnB,SAAS,IAAI,IAAI;IACjB;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IACjC;;;;OAIG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAErC,IAAI,QAAQ,iCAEX;IAED,SAAS,CAAC,MAAM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AED,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,EAAE,MAAM,cAAc,CAAC,CAAC,CAAA;AAGnG,wBAAgB,MAAM,CAAC,CAAC,SAAS,cAAc,EAAE,KAAK,GAAE,oBAAoB,CAAC,CAAC,CAAM,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,IAC1F,QAAQ,MAAM,EAAE,cAAc,MAAM,GAAG,MAAM,EAAE,QAAQ,MAAM,KAAG,IAAI,CAetF;AAGD,wBAAgB,MAAM,CAAC,CAAC,SAAS,cAAc,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,CAY3G"}
|
@@ -4,7 +4,7 @@ type BuildConfigProps = {
|
|
4
4
|
navMeshBounds: [min: Vector3Tuple, max: Vector3Tuple];
|
5
5
|
};
|
6
6
|
export declare const buildConfig: ({ recastConfig, navMeshBounds: [navMeshBoundsMin, navMeshBoundsMax] }: BuildConfigProps) => {
|
7
|
-
config: import("
|
7
|
+
config: import("recast-navigation").RawModule.rcConfig;
|
8
8
|
orig: {
|
9
9
|
x: number;
|
10
10
|
y: number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"build-tile.d.ts","sourceRoot":"","sources":["../../../src/gameplay/ai/build-tile.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,wBAAwB,EACxB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EAGjB,iBAAiB,EACjB,YAAY,EA4Bb,MAAM,yBAAyB,CAAA;AA+BhC,KAAK,gBAAgB,GAAG;IACtB,YAAY,EAAE,YAAY,CAAA;IAC1B,aAAa,EAAE,CAAC,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,CAAC,CAAA;CACtD,CA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AAE,CACpC,GAAG;IACF,iBAAiB,CAAC,EAAE,iBAAiB,CAAA;IACrC,YAAY,EAAE,kBAAkB,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,qHAUvB,kBAAkB,KAAG,mBA6SvB,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"dynamic-tiled-navmesh.d.ts","sourceRoot":"","sources":["../../../src/gameplay/ai/dynamic-tiled-navmesh.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EAGP,YAAY,EAEZ,YAAY,EAGf,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAI9B,MAAM,MAAM,wBAAwB,GAAG;IACnC,aAAa,EAAE,KAAK,CAAC,IAAI,CAAA;IACzB,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;IACnC,QAAQ,EAAE,MAAM,CAAA;IAEhB,OAAO,EAAE,MAAM,CAAA;IAEf,OAAO,EAAE,MAAM,CAAA;CAClB,CAAA;
|
1
|
+
{"version":3,"file":"dynamic-tiled-navmesh.d.ts","sourceRoot":"","sources":["../../../src/gameplay/ai/dynamic-tiled-navmesh.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,OAAO,EAGP,YAAY,EAEZ,YAAY,EAGf,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAI9B,MAAM,MAAM,wBAAwB,GAAG;IACnC,aAAa,EAAE,KAAK,CAAC,IAAI,CAAA;IACzB,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;IACnC,QAAQ,EAAE,MAAM,CAAA;IAEhB,OAAO,EAAE,MAAM,CAAA;IAEf,OAAO,EAAE,MAAM,CAAA;CAClB,CAAA;AAID,qBAAa,mBAAmB;IAC5B,OAAO,EAAE,OAAO,CAAA;IAChB,cAAc,SAAI;IAClB,eAAe,2DAAiE;IAEhF,aAAa,EAAE,CAAC,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,YAAY,CAAC,CAAA;IACrD,gBAAgB,EAAE,KAAK,CAAC,OAAO,CAAA;IAC/B,gBAAgB,EAAE,KAAK,CAAC,OAAO,CAAA;IAC/B,aAAa,EAAE,KAAK,CAAC,OAAO,CAAA;IAE5B,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;IAEX,YAAY,EAAE,YAAY,CAAA;IAE1B,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,EAAE,CAAA;IAC5B,gBAAgB,SAAI;IAEpB,OAAO,CAAC,OAAO,CAAQ;gBAEX,KAAK,EAAE,wBAAwB;IAqD3C,OAAO,CAAC,QAAQ;IA+BhB,SAAS,CAAC,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,YAAY,GAAE,OAAc;IAuE7H,aAAa,CAAC,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW;IAU3D,uBAAuB,CAAC,aAAa,EAAE,KAAK,CAAC,OAAO,GAI/B,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC;IAG3C,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI;IAepC,OAAO;CASV"}
|
@@ -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";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
|
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};/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../src/gameplay/input/input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAW,MAAM,OAAO,CAAC;AAMhD,qBAAa,SAAS;IAClB,QAAQ,CAAC,MAAM,UAAgB;IAC/B,IAAI,UAAU,WAEb;IACD,IAAI,QAAQ,WAEX;IACD,SAAgB,eAAe,
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../src/gameplay/input/input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAW,MAAM,OAAO,CAAC;AAMhD,qBAAa,SAAS;IAClB,QAAQ,CAAC,MAAM,UAAgB;IAC/B,IAAI,UAAU,WAEb;IACD,IAAI,QAAQ,WAEX;IACD,SAAgB,eAAe,GAAI,QAAQ,OAAO,UAEjD;IACD,SAAgB,eAAe,GAAI,QAAQ,OAAO,UAEjD;IACD,SAAgB,eAAe,GAAI,QAAQ,OAAO,UAEjD;IACD,SAAgB,eAAe,GAAI,QAAQ,OAAO,UAEjD;CACJ;AAGD,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAA;AAW1B,qBAAa,WAAW;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;IAE5D,SAAS,UAAQ;IACjB,SAAgB,MAAM,GAAI,QAAQ,OAAO,UAOxC;IACM,OAAO,CAAC,EAAE,EAAE,QAAQ;IAGpB,KAAK,CAAC,EAAE,EAAE,QAAQ;CAG5B;AAGD,qBAAa,aAAa;IACtB,QAAQ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S,EACtE,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,GACzB,UAAU,CAAC,CAAC,CAAC;IAIhB;;;OAGG;IACI,oBAAoB,CAAC,KAAK,EAAE,SAAS;IAS5C;;;OAGG;IACH,OAAO,CAAC,UAAU;IAKlB;;;;;OAKG;IACI,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,GAAG;QAC7D,EAAE,EAAE,OAAO,CAAC;QACZ,EAAE,EAAE,OAAO,CAAC;QACZ,EAAE,EAAE,OAAO,CAAA;KACZ,EAAE;IA8BH;;OAEG;IACI,IAAI;IAMX;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;IA2BxB;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ;IAwBhB;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;IA6EnB;;;OAGG;IACI,wBAAwB,IAAI,MAAM,CAAC,kBAAkB;CAG7D"}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{__decorate as e,__metadata as t}from"tslib";import*as i from"@dimforge/rapier3d-compat";import{QueryFilterFlags as s}from"@dimforge/rapier3d-compat";import{BehaviorSubject as o,distinctUntilChanged as r,filter as n,map as a,Subject as c,takeUntil as l}from"rxjs";import*as d from"three";import{ArrowHelper as h,BufferAttribute as u,BufferGeometry as y,Group as p,LineSegments as g,Matrix4 as m,Object3D as f,Quaternion as w,Raycaster as v,Scene as x,Vector3 as B}from"three";import{Service as b}from"typedi";import{AssetMeshInstance as A}from"../../../scene/asset-resource-loader.js";import{BoxCollisionShape as C,CapsuleCollisionShape as D,ConeCollisionShape as z,ConvexPolyhedronCollisionShape as R,CylinderCollisionShape as S,PhysicalShapeMesh as T,PlaneCollisionShape as M,SphereCollisionShape as E,TrimeshCollisionShape as W}from"../../../index.js";import{LandscapeGroup as F}from"../../../scene/landscape/landscape.js";import{ViewController as V}from"../render.js";import{World as _}from"../world.js";import*as I from"three/examples/jsm/utils/BufferGeometryUtils.js";import{calculateEffectiveScale as j}from"../../../utils/three/traverse.js";import{AbstractPhysicsSystem as L}from"./abstract-physics-system.js";export class RayTestResult{constructor(){this.hasHit=!1,this.hitPoint=new B,this.hitNormal=new B}}export var PhysicsBodyType;!function(e){e[e.dynamic=1]="dynamic",e[e.static=2]="static",e[e.kinematic=4]="kinematic",e[e.kinematicVelocityBased=8]="kinematicVelocityBased"}(PhysicsBodyType||(PhysicsBodyType={}));let P=class extends L{set showDebug(e){this.shouldRenderDebug=e,this.debugMesh&&(this.debugMesh.visible=e)}get showDebug(){return this.shouldRenderDebug}constructor(e,t){super(),this.viewController=e,this.gameWorld=t,this.staticMeshes=new Map,this.staticBodies=new Map,this.actorBodies=new Map,this.bodyActors=new Map,this.collisionEvents=new c,this.beforeStep=new c,this.afterStep=new c,this.shouldRenderDebug=!1,this._raycaster=new v,this._reusableResult=new RayTestResult,this._raytestDiff=new B,this._raytestDirection=new B,this.controlledActors=new Set,this.ready=this.setup()}createDebugMesh(){return new g(new y,new d.LineBasicMaterial({color:255}))}async start(){return await this.ready,this.handleTick(),this.ready}renderDebug(){null==this.debugMesh&&(this.debugMesh=this.createDebugMesh(),this.debugMesh.visible=this.shouldRenderDebug,this.debugMesh.raycast=function(){},this.gameWorld.scene.add(this.debugMesh));const e=this.world.debugRender();this.debugMesh.geometry.setAttribute("position",new u(e.vertices,3))}async setup(){if(null!=this.rapier)throw new Error("Rapier is already estup");this.rapier=await X(),this.eventQueue=new i.EventQueue(!0),this.setupWorld()}handleTick(){this.fixedupdateSub=this.viewController.onUpdate().subscribe((e=>{e=Math.min(.1,e),this.beforeStep.next(e),this.updatePhysics(e),this.afterStep.next(e),this.showDebug&&this.renderDebug(),this.world.bodies.forEach((e=>{if(e.isFixed())return;const t=this.staticMeshes.get(e)??this.bodyActors.get(e)?.object;var i,s;null!=t&&(t.parent instanceof x&&(Y(t.position,e.translation()),(e.isDynamic()||e.isKinematic()&&!this.controlledActors.has(this.bodyActors.get(e)?.id))&&(i=t.quaternion,s=e.rotation(),i.x=s.x,i.y=s.y,i.z=s.z,i.w=s.w)))}))}))}_updateWorld(){this.world.timestep=0,this.world.step()}updatePhysics(e){this.world.timestep=e,this.world.step(this.eventQueue),this.eventQueue.drainCollisionEvents(((e,t,i)=>{this.collisionEvents.next({handle1:e,handle2:t,started:i}),this.collisionEvents.next({handle1:t,handle2:e,started:i})}))}rayTestFromCamera(e,t,i){this._raycaster.setFromCamera(H,this.viewController.getCamera());const s=this._raycaster.ray.origin,o=this._raycaster.ray.direction.multiplyScalar(e).add(s);return this.rayTest(s,o,t,i)}rayTest(e,t,s,o){null==s&&(s=this._reusableResult);const r=this._raytestDiff,n=this._raytestDirection;if(r.subVectors(t,e),n.copy(r).normalize(),0===n.length())return console.warn("Ray test called with to and from being equal"),s;const a=new i.Ray(e,n),c=r.length(),l=this.world.castRayAndGetNormal(a,c,!1,void 0,void 0,void 0,null!=o?.excludeActor?this.actorBodies.get(o.excludeActor.id):void 0,o?.excludeTriggers?e=>!e.isSensor():void 0);if(s.hasHit=null!=l,s.hasHit){const t=a.pointAt(l.timeOfImpact);s._internal=l,Y(s.hitNormal,l.normal),Y(s.hitPoint,t),s.distance=J.subVectors(s.hitPoint,e).length();const i=this.world.bodies.getAll().find((e=>function(e,t){for(let i=0,s=e.numColliders();i<s;i++){const s=e.collider(i);if(t(s))return s}}(e,(e=>e===l.collider))));s.actor=null!=i?this.bodyActors.get(i):null}if(this.showDebug){const t=new h(n,e,c,o?.debugColor??255);this.gameWorld.scene.add(t),setTimeout((()=>this.gameWorld.scene.remove(t)),o?.debugLifetime??200)}return this._reusableResult}setGravity(e,t,i){this.world.gravity.x=e,this.world.gravity.y=t,this.world.gravity.z=i}getGravity(){return G.set(this.world.gravity.x,this.world.gravity.y,this.world.gravity.z)}addFromScene(e){this.addRecursively(e);for(const e of this.staticBodies.values())Z(e,(e=>e.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)))}addRecursively(e){if(this.removeSceneObject(e),!function(e){if(null!=e.userData?.src){const t=e.userData?.src;return"actor"===t.type}return!1}(e))if(e instanceof T&&null!=e.collisionShape){const t=this.createStaticBody(e,[e.collisionShape],e.physics);this.staticMeshes.set(t,e),this.staticBodies.set(e,t)}else if(e instanceof A&&!1!==e.userData?.src?.collisionDetection)if(e.children[0]&&e.children[0].instanceMatrix)this.createForInstancedMesh(e.children[0],e.collisionShapes);else{const t=this.createStaticBody(e,e.collisionShapes,e.physics);this.staticMeshes.set(t,e),this.staticBodies.set(e,t)}else e instanceof F?this.addLandscapeGroup(e):(e instanceof p||e instanceof x)&&e.children.forEach((e=>this.addRecursively(e)))}createForInstancedMesh(e,t){const i=new m;for(let s=0;s<e.count;s++){const o=new f;o.matrix.identity(),i.fromArray(e.instanceMatrix.array,16*s),o.applyMatrix4(i);this.createStaticBody(o,t)}}getCharacterController(e){return this.world?.createCharacterController(e)}getActorComputedMovement(e,t,i,o=null){const r=this.actorBodies.get(e.id);this.controlledActors.add(e.id);const n=r.collider(0);t.computeColliderMovement(n,i,s.EXCLUDE_SENSORS,o,ee);const a=t.computedMovement();return Y($,a),$}setNextKinematicTranslation(e,t){const i=this.actorBodies.get(e.id),s=i.translation();s.x+=t.x,s.y+=t.y,s.z+=t.z,i?.setNextKinematicTranslation(s)}setAngularVelocity(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.setAngvel(q,!0)}setLinearVelocity(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.setLinvel(q,!0)}getLinearVelocity(e,t){const i=this.actorBodies.get(e.id).linvel();return t.x=i.x,t.y=i.y,t.z=i.z,t}getAngularVelocity(e,t){const i=this.actorBodies.get(e.id).angvel();return t.x=i.x,t.y=i.y,t.z=i.z,t}setLinearDamping(e,t){const i=this.actorBodies.get(e.id);i?.setLinearDamping(t)}setAngularDamping(e,t){const i=this.actorBodies.get(e.id);i?.setAngularDamping(t)}addLandscapeGroup(e){const t=e.userData.src,s=t.landscape.heightMaps;for(const r of e.sections){this.staticBodies.has(r)&&this.world.removeRigidBody(this.staticBodies.get(r));var o=r.getWorldPosition(new B);if(t.landscape.holes&&t.landscape.holes.some((e=>e.m===r.name&&0!==e.w[0]))){const e=r.geometry.clone(),s=r.scale,n=r.geometry.getAttribute("hole"),a=new Float32Array(e.getAttribute("position").array);for(let e=0;e<a.length;e+=3)a[e]*=s.x,a[e+1]*=s.y,a[e+2]*=s.z;const c=e.index;for(let e=0;e<c.count;e+=3){const t=n.getX(c.getX(e)),i=n.getX(c.getY(e)),s=n.getX(c.getZ(e));(t>.5||i>.5||s>.5)&&(c.setX(e,0),c.setY(e,0),c.setZ(e,0))}const l=i.ColliderDesc.trimesh(a,new Uint32Array(e.getIndex().array));if(!1!==t.collisionDetection){const e=this.world.createRigidBody(i.RigidBodyDesc.fixed()),t=new i.Vector3(0,0,0);K(t,o),e.setTranslation(t,!1),this.world.createCollider(l,e),this.staticBodies.set(r,e)}continue}const e=t.landscape.options.density+1,n=t.landscape.options.sectionSize,a=new Array(e);for(let t=0;t<e;t++)a[t]=new Array(e).fill(0);const c=s.find((e=>e.x===r.x&&e.y==r.y));if(null!=c)for(const t of c.points){if(null==a[t.i%e])continue;const i=e-1-Math.floor(t.i/e);i in a[t.i%e]?a[t.i%e][i]=t.y/n:console.warn("wrong index",{points:a,point:t,i:t.i%e,k:i,heightMap:c})}const l=t.landscape.options.density,d=a.flatMap((e=>e.reverse())),h=i.ColliderDesc.heightfield(l,l,new Float32Array(d),new i.Vector3(n,n,n));if(!1!==t.collisionDetection){const e=this.world.createRigidBody(i.RigidBodyDesc.fixed()),t=new i.Vector3(0,0,0);K(t,o),e.setTranslation(t,!1),this.world.createCollider(h,e),this.staticBodies.set(r,e)}}}addActor(e,t,s={}){if(0==t.length)return void console.error("No collision shapes were defined when adding actor to the physics system.");this.removeActor(e);const o=e.object;let r;switch(s.type??PhysicsBodyType.static){case PhysicsBodyType.dynamic:r=i.RigidBodyDesc.dynamic(),r.mass=s.mass??1;break;case PhysicsBodyType.kinematic:r=i.RigidBodyDesc.kinematicPositionBased();break;case PhysicsBodyType.kinematicVelocityBased:r=i.RigidBodyDesc.kinematicVelocityBased();break;default:r=s.isTrigger?i.RigidBodyDesc.kinematicVelocityBased():i.RigidBodyDesc.fixed()}const n=this.world.createRigidBody(r);n.enableCcd(1==s.continousCollisionDetection);for(const e of t)this.addShape(n,e,o);Z(n,(e=>{null!=s.isTrigger&&(e.setSensor(s.isTrigger),e.setActiveCollisionTypes(i.ActiveCollisionTypes.ALL),e.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)),null!=s.friction&&e.setFriction(s.friction),null!=s.density&&e.setDensity(s.density),null!=s.mass&&e.setMass(s.mass),null!=s.restitution&&e.setRestitution(s.restitution)})),N(n,o),!0===s.ignoreForNavMesh&&(n.userData={ignoreForNavMesh:!0}),this.actorBodies.set(e.id,n),this.bodyActors.set(n,e)}applyTorque(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.addTorque(q,!0)}applyTorqueImpulse(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.applyTorqueImpulse(q,!0)}resetForces(e){const t=this.actorBodies.get(e.id);t?.resetForces(!1)}resetTorques(e){const t=this.actorBodies.get(e.id);t?.resetTorques(!1)}applyForce(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.addForce(q,!0)}applyImpulse(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.applyImpulse(q,!0)}applyLocalForce(e,t,i){const s=this.actorBodies.get(e.id);K(q,t),null==i?s?.addForce(q,!0):(K(Q,i),s?.addForceAtPoint(q,Q,!0))}applyLocalImpulse(e,t,i){const s=this.actorBodies.get(e.id);K(q,t),null==i?s.applyImpulse(q,!0):(K(Q,i),s.applyImpulseAtPoint(q,Q,!0))}applyRadiusImpulse(e,t,s){this.world.bodies.forEach((o=>{if(o.collider(0)?.isSensor())return;if(o.bodyType()!==i.RigidBodyType.Dynamic)return;const r=U;Y(r,o.translation());const n=r.clone().sub(e);if(n.length()>t)return;const a=n.clone().normalize().multiplyScalar(s);q.x=a.x,q.y=a.y,q.z=a.z,o.applyImpulse(q,!0)}))}removeActor(e){if(null==e)return;this.controlledActors.delete(e.id);const t=this.actorBodies.get(e.id);null!=t&&(this.bodyActors.delete(t),this.world.removeRigidBody(t)),this.actorBodies.delete(e.id)}removeRemoved(e){const t=new Set;e.traverse((e=>{t.add(e.uuid)}));for(const[e,i]of this.staticBodies.entries())!t.has(e.uuid)&&this.world.getRigidBody(i.handle)&&(this.staticBodies.delete(e),this.world.removeRigidBody(i))}removeSceneObject(e){if(e instanceof F){for(const t of e.sections)this.removeSceneObject(t);return}let t=this.staticBodies.get(e);null!=t&&this.world.getRigidBody(t.handle)&&this.world.removeRigidBody(t),this.staticBodies.delete(e)}activateActorEvents(e){this.actorBodies.get(e.id)}_onCollisionWithActorEvent(e,t,i){return this.activateActorEvents(e),this.collisionEvents.pipe(l(e.disposed),n((({started:e})=>e===i)),a((({handle1:e,handle2:t,started:i})=>({a1:this.bodyActors.get(this.world.getCollider(e)?.parent()),a2:this.bodyActors.get(this.world.getCollider(t)?.parent()),started:i}))),n((({a1:i,a2:s})=>null!=i&&null!=s&&i.id===e.id&&t(i,s))),a((({a2:e})=>e)))}onBeginContact(e){return this.activateActorEvents(e),this.collisionEvents.pipe(l(e.disposed),n((e=>e.started)),n((({handle1:t})=>{const i=this.bodyActors.get(this.world.getCollider(t)?.parent());return null!=i&&i.id===e.id})),a((e=>e.handle2)))}onEndContact(e){return this.activateActorEvents(e),this.collisionEvents.pipe(l(e.disposed),n((e=>!e.started)),n((({handle1:t})=>{const i=this.bodyActors.get(this.world.getCollider(t)?.parent());return null!=i&&i.id===e.id})),a((e=>e.handle2)))}onHasContactChanged(e){const t=new Set,i=new o(!1);return this.onBeginContact(e).subscribe((e=>{t.add(e),i.next(t.size>0)})),this.onEndContact(e).subscribe((e=>{t.delete(e),i.next(t.size>0)})),i.pipe(r())}onBeginOverlapWithActorType(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>i instanceof t),!0)}onEndOverlapWithActorType(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>i instanceof t),!1)}onBeginOverlapWithActor(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>t.id===i.id),!0)}onEndOverlapWithActor(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>t.id===i.id),!1)}onCollisionWithActor(e,t){return this.onBeginOverlapWithActor(e,t)}onCollisionWithActorType(e,t){return this.onBeginOverlapWithActorType(e,t)}updateActorTransform(e){const t=this.actorBodies.get(e.id);null!=t?N(t,e.object):console.warn("Actor has not been added to physics world",e)}setupWorld(){const e=new i.World({x:0,y:-9.81,z:0});this.world=e}getActorContacts(e,t){const s=this.actorBodies.get(e.id);if(s&&s.numColliders()>0){const o=s.collider(0);let r=o.shape,n=o.translation(),a=o.rotation(),c=t,l=.3;const d=this.world.castShape(n,a,c,r,.1,l,!0,null,null,null,this.actorBodies.get(e.id),(e=>e.shape.type!=i.ShapeType.HeightField));if(null!=d){const e=new B,t=new B,i=new B;return Y(e,d.witness2),Y(t,d.witness1),Y(i,d.normal1),i.negate(),[{ri:e,rj:t,ni:i}]}return[]}return console.warn("Actor is not added to the physics system"),[]}stop(){this.world?.bodies.forEach((e=>this.world.removeRigidBody(e))),this.world?.free(),this.fixedupdateSub?.unsubscribe()}createStaticBody(e,t,s){const o=s?.type===PhysicsBodyType.dynamic?i.RigidBodyDesc.dynamic():i.RigidBodyDesc.fixed(),r=this.world.createRigidBody(o);for(const i of t){if(null==i){console.warn("Collision shape is missing for object",e);continue}const o=this.addShape(r,i,e);null!=s?.friction&&o.setFriction(s.friction),null!=s?.density&&o.setDensity(s.density),null!=s?.mass&&o.setMass(s.mass/t.length),null!=s?.restitution&&o.setRestitution(s.restitution)}return N(r,e),r.userData=e.uuid,r}addShape(e,t,i){const s=i.getWorldScale(te),o=this.createShape(t,s);null!=t.collisionGroup&&o.setCollisionGroups(t.collisionGroup),o.friction=.1;const r=t.offset.clone().multiply(s);var n,a;K(o.translation,r),n=o.rotation,a=(new w).setFromEuler(t.rotation),n.x=a.x,n.y=a.y,n.z=a.z,n.w=a.w;return this.world.createCollider(o,e)}createShape(e,t){if(e instanceof C)return i.ColliderDesc.cuboid(e.dimensions.x*t.x/2,e.dimensions.y*t.y/2,e.dimensions.z*t.z/2);if(e instanceof D){return i.ColliderDesc.capsule(e.length/2*t.y,e.radius*Math.max(t.z,t.x))}if(e instanceof W){const s=null!=e.geometry.getIndex()?e.geometry:I.mergeVertices(e.geometry),o=new Float32Array(s.getAttribute("position").array);for(let e=0;e<o.length;e+=3)o[e]*=t.x,o[e+1]*=t.y,o[e+2]*=t.z;return i.ColliderDesc.trimesh(o,new Uint32Array(s.getIndex().array))}if(e instanceof R){let s;e.mesh instanceof d.Mesh?s=e.mesh.geometry:e.mesh instanceof d.BufferGeometry?s=e.mesh:console.log("Unknownd shape",{shapeInfo:e});const o=new Float32Array(s.getAttribute("position").array);if(e.mesh instanceof d.Mesh){const t=j(e.mesh);for(let e=0;e<o.length;e+=3)o[e]*=t.x,o[e+1]*=t.y,o[e+2]*=t.z}for(let e=0;e<o.length;e+=3)o[e]*=t.x,o[e+1]*=t.y,o[e+2]*=t.z;const r=o;return i.ColliderDesc.convexHull(r)}if(e instanceof E){const s=2*t.x-t.y-t.z;return Math.abs(s)>.01?this.createShape(new R(new d.SphereGeometry(e.radius).scale(t.x,t.y,t.z)),new B(1,1,1)):i.ColliderDesc.ball(e.radius*Math.max(t.x,t.y,t.z))}return e instanceof S?i.ColliderDesc.cylinder(e.height/2*t.y,e.radiusTop*Math.max(t.z,t.x)):e instanceof z?i.ColliderDesc.cone(e.height*t.y,e.radiusBottom/2*Math.max(t.z,t.x)):e instanceof M?i.ColliderDesc.cuboid(e.width/2*t.x,e.height/2*t.y,.01):(console.error("Unsupported shape",e),i.ColliderDesc.cuboid(1,1,1))}createCharacterCollision(){return new i.CharacterCollision}};P=e([b(),t("design:paramtypes",[V,_])],P);export{P as PhysicsSystem};const k=new B,O=new d.Quaternion;function N(e,t){const s=t.getWorldPosition(k),o=t.getWorldQuaternion(O);e.setTranslation(new i.Vector3(s.x,s.y,s.z),!1),e.setRotation(new i.Quaternion(o.x,o.y,o.z,o.w),!1)}const G=new B,q=new i.Vector3(0,0,0),Q=new i.Vector3(0,0,0),U=new B,H=new d.Vector2,X=async()=>{let e=await import("@dimforge/rapier3d-compat");return await e.init(),e};function K(e,t){e.x=t.x,e.y=t.y,e.z=t.z}function Y(e,t){e.x=t.x,e.y=t.y,e.z=t.z}function Z(e,t){for(let i=0,s=e.numColliders();i<s;i++){t(e.collider(i))}}const J=new B,$=new B,ee=e=>!e.isSensor(),te=new B;/*
|
1
|
+
import{__decorate as e,__metadata as t}from"tslib";import*as i from"@dimforge/rapier3d-compat";import{QueryFilterFlags as s}from"@dimforge/rapier3d-compat";import{BehaviorSubject as o,distinctUntilChanged as n,filter as r,map as a,Subject as c,takeUntil as l}from"rxjs";import*as d from"three";import{ArrowHelper as h,BufferAttribute as u,BufferGeometry as y,Group as p,LineSegments as g,Matrix4 as m,Object3D as f,Quaternion as w,Raycaster as v,Scene as x,Vector3 as B}from"three";import{Service as b}from"typedi";import{AssetMeshInstance as A}from"../../../scene/asset-resource-loader.js";import{BoxCollisionShape as C,CapsuleCollisionShape as D,ConeCollisionShape as z,ConvexPolyhedronCollisionShape as M,CylinderCollisionShape as R,PhysicalShapeMesh as S,PlaneCollisionShape as T,SphereCollisionShape as E,TrimeshCollisionShape as W}from"../../../index.js";import{LandscapeGroup as F}from"../../../scene/landscape/landscape.js";import{ViewController as V}from"../render.js";import{World as _}from"../world.js";import*as I from"three/examples/jsm/utils/BufferGeometryUtils.js";import{calculateEffectiveScale as j}from"../../../utils/three/traverse.js";import{AbstractPhysicsSystem as L}from"./abstract-physics-system.js";export class RayTestResult{constructor(){this.hasHit=!1,this.hitPoint=new B,this.hitNormal=new B}}export var PhysicsBodyType;!function(e){e[e.dynamic=1]="dynamic",e[e.static=2]="static",e[e.kinematic=4]="kinematic",e[e.kinematicVelocityBased=8]="kinematicVelocityBased"}(PhysicsBodyType||(PhysicsBodyType={}));let P=class extends L{set showDebug(e){this.shouldRenderDebug=e,this.debugMesh&&(this.debugMesh.visible=e)}get showDebug(){return this.shouldRenderDebug}constructor(e,t){super(),this.viewController=e,this.gameWorld=t,this.staticMeshes=new Map,this.staticBodies=new Map,this.actorBodies=new Map,this.bodyActors=new Map,this.collisionEvents=new c,this.beforeStep=new c,this.afterStep=new c,this.shouldRenderDebug=!1,this._raycaster=new v,this._reusableResult=new RayTestResult,this._raytestDiff=new B,this._raytestDirection=new B,this.controlledActors=new Set,this.ready=this.setup()}createDebugMesh(){return new g(new y,new d.LineBasicMaterial({color:255}))}async start(){return await this.ready,this.handleTick(),this.ready}renderDebug(){null==this.debugMesh&&(this.debugMesh=this.createDebugMesh(),this.debugMesh.visible=this.shouldRenderDebug,this.debugMesh.raycast=function(){},this.gameWorld.scene.add(this.debugMesh));const e=this.world.debugRender();this.debugMesh.geometry.setAttribute("position",new u(e.vertices,3))}async setup(){if(null!=this.rapier)throw new Error("Rapier is already estup");this.rapier=await X(),this.eventQueue=new i.EventQueue(!0),this.setupWorld()}handleTick(){this.fixedupdateSub=this.viewController.onUpdate().subscribe((e=>{e=Math.min(.1,e),this.beforeStep.next(e),this.updatePhysics(e),this.showDebug&&this.renderDebug(),this.world.bodies.forEach((e=>{if(e.isFixed())return;const t=this.staticMeshes.get(e)??this.bodyActors.get(e)?.object;var i,s;null!=t&&(t.parent instanceof x&&(Y(t.position,e.translation()),(e.isDynamic()||e.isKinematic()&&!this.controlledActors.has(this.bodyActors.get(e)?.id))&&(i=t.quaternion,s=e.rotation(),i.x=s.x,i.y=s.y,i.z=s.z,i.w=s.w),t.updateMatrix(),t.updateWorldMatrix(!1,!1)))})),this.afterStep.next(e)}))}_updateWorld(){this.world.timestep=0,this.world.step()}updatePhysics(e){this.world.timestep=e,this.world.step(this.eventQueue),this.eventQueue.drainCollisionEvents(((e,t,i)=>{this.collisionEvents.next({handle1:e,handle2:t,started:i}),this.collisionEvents.next({handle1:t,handle2:e,started:i})}))}rayTestFromCamera(e,t,i){this._raycaster.setFromCamera(H,this.viewController.getCamera());const s=this._raycaster.ray.origin,o=this._raycaster.ray.direction.multiplyScalar(e).add(s);return this.rayTest(s,o,t,i)}rayTest(e,t,i,s){null==i&&(i=this._reusableResult);const o=this._raytestDiff,n=this._raytestDirection;if(o.subVectors(t,e),n.copy(o).normalize(),0===n.length())return console.warn("Ray test called with to and from being equal"),i;K(ie.origin,e),K(ie.dir,n);const r=o.length(),a=this.world.castRayAndGetNormal(ie,r,!1,void 0,void 0,void 0,null!=s?.excludeActor?this.actorBodies.get(s.excludeActor.id):void 0,s?.excludeTriggers?e=>!e.isSensor():void 0);if(i.hasHit=null!=a,i.hasHit){const t=ie.pointAt(a.timeOfImpact);i._internal=a,Y(i.hitNormal,a.normal),Y(i.hitPoint,t),i.distance=J.subVectors(i.hitPoint,e).length();const s=this.world.bodies.getAll().find((e=>function(e,t){for(let i=0,s=e.numColliders();i<s;i++){const s=e.collider(i);if(t(s))return s}}(e,(e=>e===a.collider))));i.actor=null!=s?this.bodyActors.get(s):null}if(this.showDebug){const t=new h(n,e,r,s?.debugColor??255);this.gameWorld.scene.add(t),setTimeout((()=>this.gameWorld.scene.remove(t)),s?.debugLifetime??200)}return this._reusableResult}setGravity(e,t,i){this.world.gravity.x=e,this.world.gravity.y=t,this.world.gravity.z=i}getGravity(){return G.set(this.world.gravity.x,this.world.gravity.y,this.world.gravity.z)}addFromScene(e){this.addRecursively(e);for(const e of this.staticBodies.values())Z(e,(e=>e.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)))}addRecursively(e){if(this.removeSceneObject(e),!function(e){if(null!=e.userData?.src){const t=e.userData?.src;return"actor"===t.type}return!1}(e))if(e instanceof S&&null!=e.collisionShape){const t=this.createStaticBody(e,[e.collisionShape],e.physics);this.staticMeshes.set(t,e),this.staticBodies.set(e,t)}else if(e instanceof A&&!1!==e.userData?.src?.collisionDetection)if(e.children[0]&&e.children[0].instanceMatrix)this.createForInstancedMesh(e.children[0],e.collisionShapes);else{const t=this.createStaticBody(e,e.collisionShapes,e.physics);this.staticMeshes.set(t,e),this.staticBodies.set(e,t)}else e instanceof F?this.addLandscapeGroup(e):(e instanceof p||e instanceof x)&&e.children.forEach((e=>this.addRecursively(e)))}createForInstancedMesh(e,t){const i=new m;for(let s=0;s<e.count;s++){const o=new f;o.matrix.identity(),i.fromArray(e.instanceMatrix.array,16*s),o.applyMatrix4(i);this.createStaticBody(o,t)}}getCharacterController(e){return this.world?.createCharacterController(e)}getActorComputedMovement(e,t,i,o=null){const n=this.actorBodies.get(e.id);this.controlledActors.add(e.id);const r=n.collider(0);t.computeColliderMovement(r,i,s.EXCLUDE_SENSORS,o,ee);const a=t.computedMovement();return Y($,a),$}setNextKinematicTranslation(e,t){const i=this.actorBodies.get(e.id),s=i.translation();s.x+=t.x,s.y+=t.y,s.z+=t.z,i?.setNextKinematicTranslation(s)}setAngularVelocity(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.setAngvel(q,!0)}setLinearVelocity(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.setLinvel(q,!0)}getLinearVelocity(e,t=new B){const i=this.actorBodies.get(e.id).linvel();return t.x=i.x,t.y=i.y,t.z=i.z,t}getAngularVelocity(e,t=new B){const i=this.actorBodies.get(e.id).angvel();return t.x=i.x,t.y=i.y,t.z=i.z,t}setLinearDamping(e,t){const i=this.actorBodies.get(e.id);i?.setLinearDamping(t)}setAngularDamping(e,t){const i=this.actorBodies.get(e.id);i?.setAngularDamping(t)}addLandscapeGroup(e){const t=e.userData.src,s=t.landscape.heightMaps;for(const n of e.sections){this.staticBodies.has(n)&&this.world.removeRigidBody(this.staticBodies.get(n));var o=n.getWorldPosition(new B);if(t.landscape.holes&&t.landscape.holes.some((e=>e.m===n.name&&0!==e.w[0]))){const e=n.geometry.clone(),s=n.scale,r=n.geometry.getAttribute("hole"),a=new Float32Array(e.getAttribute("position").array);for(let e=0;e<a.length;e+=3)a[e]*=s.x,a[e+1]*=s.y,a[e+2]*=s.z;const c=e.index;for(let e=0;e<c.count;e+=3){const t=r.getX(c.getX(e)),i=r.getX(c.getY(e)),s=r.getX(c.getZ(e));(t>.5||i>.5||s>.5)&&(c.setX(e,0),c.setY(e,0),c.setZ(e,0))}const l=i.ColliderDesc.trimesh(a,new Uint32Array(e.getIndex().array));if(!1!==t.collisionDetection){const e=this.world.createRigidBody(i.RigidBodyDesc.fixed()),t=new i.Vector3(0,0,0);K(t,o),e.setTranslation(t,!1),this.world.createCollider(l,e),this.staticBodies.set(n,e)}continue}const e=t.landscape.options.density+1,r=t.landscape.options.sectionSize,a=new Array(e);for(let t=0;t<e;t++)a[t]=new Array(e).fill(0);const c=s.find((e=>e.x===n.x&&e.y==n.y));if(null!=c)for(const t of c.points){if(null==a[t.i%e])continue;const i=e-1-Math.floor(t.i/e);i in a[t.i%e]?a[t.i%e][i]=t.y/r:console.warn("wrong index",{points:a,point:t,i:t.i%e,k:i,heightMap:c})}const l=t.landscape.options.density,d=a.flatMap((e=>e.reverse())),h=i.ColliderDesc.heightfield(l,l,new Float32Array(d),new i.Vector3(r,r,r));if(!1!==t.collisionDetection){const e=this.world.createRigidBody(i.RigidBodyDesc.fixed()),t=new i.Vector3(0,0,0);K(t,o),e.setTranslation(t,!1),this.world.createCollider(h,e),this.staticBodies.set(n,e)}}}addActor(e,t,s={}){if(0==t.length)return void console.error("No collision shapes were defined when adding actor to the physics system.");this.removeActor(e);const o=e.object;let n;switch(s.type??PhysicsBodyType.static){case PhysicsBodyType.dynamic:n=i.RigidBodyDesc.dynamic(),n.mass=s.mass??1;break;case PhysicsBodyType.kinematic:n=i.RigidBodyDesc.kinematicPositionBased();break;case PhysicsBodyType.kinematicVelocityBased:n=i.RigidBodyDesc.kinematicVelocityBased();break;default:n=s.isTrigger?i.RigidBodyDesc.kinematicVelocityBased():i.RigidBodyDesc.fixed()}const r=this.world.createRigidBody(n);r.enableCcd(1==s.continousCollisionDetection);for(const e of t)this.addShape(r,e,o);Z(r,(e=>{null!=s.isTrigger&&(e.setSensor(s.isTrigger),e.setActiveCollisionTypes(i.ActiveCollisionTypes.ALL),e.setActiveEvents(i.ActiveEvents.COLLISION_EVENTS)),null!=s.friction&&e.setFriction(s.friction),null!=s.density&&e.setDensity(s.density),null!=s.mass&&e.setMass(s.mass),null!=s.restitution&&e.setRestitution(s.restitution)})),N(r,o),!0===s.ignoreForNavMesh&&(r.userData={ignoreForNavMesh:!0}),this.actorBodies.set(e.id,r),this.bodyActors.set(r,e)}applyTorque(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.addTorque(q,!0)}applyTorqueImpulse(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.applyTorqueImpulse(q,!0)}resetForces(e){const t=this.actorBodies.get(e.id);t?.resetForces(!1)}resetTorques(e){const t=this.actorBodies.get(e.id);t?.resetTorques(!1)}applyForce(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.addForce(q,!0)}applyImpulse(e,t){const i=this.actorBodies.get(e.id);q.x=t.x,q.y=t.y,q.z=t.z,i?.applyImpulse(q,!0)}applyLocalForce(e,t,i){const s=this.actorBodies.get(e.id);K(q,t),null==i?s?.addForce(q,!0):(K(Q,i),s?.addForceAtPoint(q,Q,!0))}applyLocalImpulse(e,t,i){const s=this.actorBodies.get(e.id);K(q,t),null==i?s.applyImpulse(q,!0):(K(Q,i),s.applyImpulseAtPoint(q,Q,!0))}applyRadiusImpulse(e,t,s){this.world.bodies.forEach((o=>{if(o.collider(0)?.isSensor())return;if(o.bodyType()!==i.RigidBodyType.Dynamic)return;const n=U;Y(n,o.translation());const r=n.clone().sub(e);if(r.length()>t)return;const a=r.clone().normalize().multiplyScalar(s);q.x=a.x,q.y=a.y,q.z=a.z,o.applyImpulse(q,!0)}))}removeActor(e){if(null==e)return;this.controlledActors.delete(e.id);const t=this.actorBodies.get(e.id);null!=t&&(this.bodyActors.delete(t),this.world.removeRigidBody(t)),this.actorBodies.delete(e.id)}removeRemoved(e){const t=new Set;e.traverse((e=>{t.add(e.uuid)}));for(const[e,i]of this.staticBodies.entries())!t.has(e.uuid)&&this.world.getRigidBody(i.handle)&&(this.staticBodies.delete(e),this.world.removeRigidBody(i))}removeSceneObject(e){if(e instanceof F){for(const t of e.sections)this.removeSceneObject(t);return}let t=this.staticBodies.get(e);null!=t&&this.world.getRigidBody(t.handle)&&this.world.removeRigidBody(t),this.staticBodies.delete(e)}activateActorEvents(e){this.actorBodies.get(e.id)}_onCollisionWithActorEvent(e,t,i){return this.activateActorEvents(e),this.collisionEvents.pipe(l(e.disposed),r((({started:e})=>e===i)),a((({handle1:e,handle2:t,started:i})=>({a1:this.bodyActors.get(this.world.getCollider(e)?.parent()),a2:this.bodyActors.get(this.world.getCollider(t)?.parent()),started:i}))),r((({a1:i,a2:s})=>null!=i&&null!=s&&i.id===e.id&&t(i,s))),a((({a2:e})=>e)))}onBeginContact(e){return this.activateActorEvents(e),this.collisionEvents.pipe(l(e.disposed),r((e=>e.started)),r((({handle1:t})=>{const i=this.bodyActors.get(this.world.getCollider(t)?.parent());return null!=i&&i.id===e.id})),a((e=>e.handle2)))}onEndContact(e){return this.activateActorEvents(e),this.collisionEvents.pipe(l(e.disposed),r((e=>!e.started)),r((({handle1:t})=>{const i=this.bodyActors.get(this.world.getCollider(t)?.parent());return null!=i&&i.id===e.id})),a((e=>e.handle2)))}onHasContactChanged(e){const t=new Set,i=new o(!1);return this.onBeginContact(e).subscribe((e=>{t.add(e),i.next(t.size>0)})),this.onEndContact(e).subscribe((e=>{t.delete(e),i.next(t.size>0)})),i.pipe(n())}onBeginOverlapWithActorType(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>i instanceof t),!0)}onEndOverlapWithActorType(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>i instanceof t),!1)}onBeginOverlapWithActor(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>t.id===i.id),!0)}onEndOverlapWithActor(e,t){return this._onCollisionWithActorEvent(e,((e,i)=>t.id===i.id),!1)}onCollisionWithActor(e,t){return this.onBeginOverlapWithActor(e,t)}onCollisionWithActorType(e,t){return this.onBeginOverlapWithActorType(e,t)}updateActorTransform(e){const t=this.actorBodies.get(e.id);null!=t?N(t,e.object):console.warn("Actor has not been added to physics world",e)}setupWorld(){const e=new i.World({x:0,y:-9.81,z:0});this.world=e}getActorContacts(e,t){const s=this.actorBodies.get(e.id);if(s&&s.numColliders()>0){const o=s.collider(0);let n=o.shape,r=o.translation(),a=o.rotation(),c=t,l=.3;const d=this.world.castShape(r,a,c,n,.1,l,!0,null,null,null,this.actorBodies.get(e.id),(e=>e.shape.type!=i.ShapeType.HeightField));if(null!=d){const e=new B,t=new B,i=new B;return Y(e,d.witness2),Y(t,d.witness1),Y(i,d.normal1),i.negate(),[{ri:e,rj:t,ni:i}]}return[]}return console.warn("Actor is not added to the physics system"),[]}stop(){this.world?.bodies.forEach((e=>this.world.removeRigidBody(e))),this.world?.free(),this.fixedupdateSub?.unsubscribe()}createStaticBody(e,t,s){const o=s?.type===PhysicsBodyType.dynamic?i.RigidBodyDesc.dynamic():i.RigidBodyDesc.fixed(),n=this.world.createRigidBody(o);for(const i of t){if(null==i){console.warn("Collision shape is missing for object",e);continue}const o=this.addShape(n,i,e);null!=s?.friction&&o.setFriction(s.friction),null!=s?.density&&o.setDensity(s.density),null!=s?.mass&&o.setMass(s.mass/t.length),null!=s?.restitution&&o.setRestitution(s.restitution)}return N(n,e),n.userData=e.uuid,n}addShape(e,t,i){const s=i.getWorldScale(te),o=this.createShape(t,s);null!=t.collisionGroup&&o.setCollisionGroups(t.collisionGroup),o.friction=.1;const n=t.offset.clone().multiply(s);K(o.translation,n);const r=(new w).setFromEuler(t.rotation);var a,c;t instanceof M&&t.mesh instanceof d.Mesh&&r.multiply(t.mesh.getWorldQuaternion(O)),a=o.rotation,c=r,a.x=c.x,a.y=c.y,a.z=c.z,a.w=c.w;return this.world.createCollider(o,e)}createShape(e,t){if(e instanceof C)return i.ColliderDesc.cuboid(e.dimensions.x*t.x/2,e.dimensions.y*t.y/2,e.dimensions.z*t.z/2);if(e instanceof D){return i.ColliderDesc.capsule(e.length/2*t.y,e.radius*Math.max(t.z,t.x))}if(e instanceof W){const s=null!=e.geometry.getIndex()?e.geometry:I.mergeVertices(e.geometry),o=new Float32Array(s.getAttribute("position").array);for(let e=0;e<o.length;e+=3)o[e]*=t.x,o[e+1]*=t.y,o[e+2]*=t.z;return i.ColliderDesc.trimesh(o,new Uint32Array(s.getIndex().array))}if(e instanceof M){let s;e.mesh instanceof d.Mesh?s=e.mesh.geometry:e.mesh instanceof d.BufferGeometry?s=e.mesh:console.log("Unknownd shape",{shapeInfo:e});const o=new Float32Array(s.getAttribute("position").array);if(e.mesh instanceof d.Mesh){const t=j(e.mesh);for(let e=0;e<o.length;e+=3)o[e]*=t.x,o[e+1]*=t.y,o[e+2]*=t.z}for(let e=0;e<o.length;e+=3)o[e]*=t.x,o[e+1]*=t.y,o[e+2]*=t.z;const n=o;return i.ColliderDesc.convexHull(n)}if(e instanceof E){const s=2*t.x-t.y-t.z;return Math.abs(s)>.01?this.createShape(new M(new d.SphereGeometry(e.radius).scale(t.x,t.y,t.z)),new B(1,1,1)):i.ColliderDesc.ball(e.radius*Math.max(t.x,t.y,t.z))}return e instanceof R?i.ColliderDesc.cylinder(e.height/2*t.y,e.radiusTop*Math.max(t.z,t.x)):e instanceof z?i.ColliderDesc.cone(e.height*t.y,e.radiusBottom/2*Math.max(t.z,t.x)):e instanceof T?i.ColliderDesc.cuboid(e.width/2*t.x,e.height/2*t.y,.001):(console.error("Unsupported shape",e),i.ColliderDesc.cuboid(1,1,1))}createCharacterCollision(){return new i.CharacterCollision}};P=e([b(),t("design:paramtypes",[V,_])],P);export{P as PhysicsSystem};const k=new B,O=new d.Quaternion;function N(e,t){const s=t.getWorldPosition(k),o=t.getWorldQuaternion(O);e.setTranslation(new i.Vector3(s.x,s.y,s.z),!1),e.setRotation(new i.Quaternion(o.x,o.y,o.z,o.w),!1)}const G=new B,q=new i.Vector3(0,0,0),Q=new i.Vector3(0,0,0),U=new B,H=new d.Vector2,X=async()=>{let e=await import("@dimforge/rapier3d-compat");return await e.init(),e};function K(e,t){e.x=t.x,e.y=t.y,e.z=t.z}function Y(e,t){e.x=t.x,e.y=t.y,e.z=t.z}function Z(e,t){for(let i=0,s=e.numColliders();i<s;i++){t(e.collider(i))}}const J=new B,$=new B,ee=e=>!e.isSensor(),te=new B;const ie=new i.Ray(new i.Vector3(0,0,0),new i.Vector3(0,1,0));/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pointer-events.d.ts","sourceRoot":"","sources":["../../../src/gameplay/services/pointer-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAsB,MAAM,OAAO,CAAA;AAKlE,OAAO,EAAE,UAAU,EAAyG,MAAM,MAAM,CAAA;AACxI,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAGvC,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,QAAQ,CAAA;IAChB,YAAY,EAAE,YAAY,CAAA;CAC3B,CAAA;AAED,KAAK,iBAAiB,CAAC,CAAC,SAAS,SAAS,IAAI;IAC5C,KAAK,EAAE,CAAC,CAAA;IACR,YAAY,EAAE,YAAY,CAAA;CAC3B,CAAA;AAED,qBACa,aAAa;IACxB,OAAO,CAAC,IAAI,CAA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,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;IA4BhC,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;CAwBzB;AAcD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,QAIhD;AAuGD;;;;;;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 s from"three";import{Color as r,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 p,RenderPass as u,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 b}from"three-shader-graph";import{Reflector as T}from"three-stdlib";import{OutputPass as y}from"three/examples/jsm/Addons.js";import{CSM as M}from"three/examples/jsm/csm/CSM.js";import C from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as P}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as R}from"typedi";import{depthUniformName as S,farUniformName as D,nearUniformName as F,resolutionUniformName as W,supportsDepthTextureExtension as A}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as H}from"./shader-nodes/time.js";import{DepthPass as L}from"./utils/three/depth-pass.js";import{GPUStatsPanel as k}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as O}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as j}from"./utils/three/traverse.js";(new s.Layers).set(9);const E=new s.MeshBasicMaterial({color:"black"}),B=new s.MeshDepthMaterial;B.depthPacking=s.RGBADepthPacking,B.blending=s.NoBlending,B.side=s.DoubleSide;const U=/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||(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.aoMaskDepthRenderTarget.dispose(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.aoPass.blendMaterial.uniforms.tDepth.value=this.aoMaskDepthRenderTarget.depthTexture)}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=U?.5:1,this.maxPixelRatio=U?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!=i.maxPixelRatio&&(this.maxPixelRatio=i.maxPixelRatio),window.renderer=this.renderer=new s.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new s.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/t.clientHeight;const a=new s.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=s.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=i.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=s.SRGBColorSpace,this.renderer.toneMapping=s.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,w.renderingView=this,w.patchThreeAdd(),this.isDepthTextureExtensionSupported=A(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);const o=new u(this.scene,this.camera);this.composer.addPass(o);const h=new g(new s.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=0,h.strength=.9,h.radius=1;const l=new P(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=P.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;const x=new f(new s.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 s.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(p).clear=!1,this.fixStatsStyle();const b=new y;this.composer.addPass(b)}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 u?t.camera=e:t instanceof O?t.renderCamera=e:(t instanceof L||t instanceof P)&&(t.camera=e)})),null==this.csm?(this.csm=new M({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new s.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 r=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=s.NearestFilter,r.texture.magFilter=s.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===i&&(r.depthTexture=new s.DepthTexture(128,128),r.depthTexture.type=s.UnsignedShortType,r.depthTexture.minFilter=s.NearestFilter,r.depthTexture.magFilter=s.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const i=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:s.HalfFloatType});return i.texture.minFilter=s.NearestFilter,i.texture.magFilter=s.NearestFilter,i.texture.generateMipmaps=!1,i.stencilBuffer=!1,i.depthTexture=new s.DepthTexture(128,128),i.depthTexture.type=s.UnsignedInt248Type,i.depthTexture.minFilter=s.NearestFilter,i.depthTexture.magFilter=s.NearestFilter,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.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 i=this.stats,r=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 k(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)),r.update(e,d);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout((()=>c=1e3),5e3)),h.update(t,c)};performance.now();s.Ray.prototype.intersectTriangle;const p=[],u=[];let f=0;const g=new a,v=new a,x=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>x(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)-f;if(f=t,g.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(z),t-=z;e(t)}else e(a);this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),v.copy(this.camera.matrixWorld),v.equals(g)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),p.length=0,u.length=0;const h=_;if(this.camera.updateMatrixWorld(),N.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),h.setFromProjectionMatrix(N),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof s.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 s.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[S])&&isObjectInFrustum(e,h)?(e.visible=!1,p.push(e),this.initDepthUniform(e.material),e.renderOrder=100):(e instanceof T||(e instanceof o||e instanceof s.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,u.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[H])e.material.uniforms[H].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const i of e.material)i.uniforms&&null!=i.uniforms[H]&&(i.uniforms[H].value=t)})),p.length>0){if(this.scene.overrideMaterial=B,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(p.forEach((e=>e.visible=!0)),u.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=B,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.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(x)}),1e3/this.fpsCap):requestAnimationFrame(x))};!0===this.options.enableXR?this.renderer.setAnimationLoop(x):requestAnimationFrame(x)}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 s=0;s<e.length;s++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*s+this.insetMargin*s,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[s])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){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!=j(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){(e instanceof o||e instanceof s.Sprite||e instanceof s.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)?(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=E: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[S].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,null!=e.uniforms[W]&&e.uniforms[W].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio()),this.camera instanceof h&&(e.uniforms[F].value=this.camera.near,e.uniforms[D].value=this.camera.far))}};V=e=t([R(),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 z=.05;P.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 _=new s.Frustum,I=new s.Box3,N=new s.Matrix4;export function isObjectInFrustum(e,t){const i=I.setFromObject(e);return t.intersectsBox(i)}/*
|
1
|
+
var e;import{__decorate as t,__metadata as i}from"tslib";import*as s from"three";import{Color as r,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 p,RenderPass as u,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 b}from"three-shader-graph";import{Reflector as y}from"three-stdlib";import{OutputPass as T}from"three/examples/jsm/Addons.js";import{CSM as M}from"three/examples/jsm/csm/CSM.js";import C from"three/examples/jsm/libs/stats.module.js";import{GTAOPass as P}from"three/examples/jsm/postprocessing/GTAOPass.js";import{Service as R}from"typedi";import{depthUniformName as S,farUniformName as D,nearUniformName as F,resolutionUniformName as W,supportsDepthTextureExtension as A}from"./shader-nodes/depth.js";import{elapsedTimeUniformName as H}from"./shader-nodes/time.js";import{DepthPass as L}from"./utils/three/depth-pass.js";import{GPUStatsPanel as k}from"./utils/three/gpu-stats-panel.js";import{OutlinePass as O}from"./utils/three/outline-pass.js";import{findFirstVisibleObject as j}from"./utils/three/traverse.js";(new s.Layers).set(9);const E=new s.MeshBasicMaterial({color:"black"}),B=new s.MeshDepthMaterial;B.depthPacking=s.RGBADepthPacking,B.blending=s.NoBlending,B.side=s.DoubleSide;const U=/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||(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.aoMaskDepthRenderTarget.dispose(),this.aoMaskDepthRenderTarget=e.createAOMaskDepthRenderTarget(this.renderer,this.container),this.aoPass.blendMaterial.uniforms.tDepth.value=this.aoMaskDepthRenderTarget.depthTexture)}constructor(t,i={}){this.container=t,this.options=i,this.windowVisible=!0,this.running=!0,this.paused=!1,this.fpsCap=null,this.resolutionScale=U?.5:1,this.maxPixelRatio=U?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!=i.maxPixelRatio&&(this.maxPixelRatio=i.maxPixelRatio),window.renderer=this.renderer=new s.WebGLRenderer({antialias:!0,powerPreference:"high-performance"}),this.scene=new s.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/t.clientHeight;const a=new s.PerspectiveCamera(45,n,.5,800);a.layers.enable(19),this.setCamera(a),this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=s.PCFSoftShadowMap,this.renderer.shadowMap.autoUpdate=i.shadows?.autoUpdate??!1,this.renderer.outputColorSpace=s.SRGBColorSpace,this.renderer.toneMapping=s.NoToneMapping,this.renderer.toneMappingExposure=1,this.renderer.gammaFactor=1.4,w.renderingView=this,w.patchThreeAdd(),this.isDepthTextureExtensionSupported=A(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);const o=new u(this.scene,this.camera);this.composer.addPass(o);const h=new g(new s.Vector2(t.clientWidth,t.clientHeight),1.5,.4,.85);h.threshold=0,h.strength=.9,h.radius=1;const l=new P(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=P.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;const x=new f(new s.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 s.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(p).clear=!1,this.fixStatsStyle();const b=new T;this.composer.addPass(b)}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 u?t.camera=e:t instanceof O?t.renderCamera=e:(t instanceof L||t instanceof P)&&(t.camera=e)})),null==this.csm?(this.csm=new M({maxFar:500,lightFar:250,lightMargin:20,cascades:4,shadowMapSize:2048,lightDirection:new s.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 r=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio());return r.texture.minFilter=s.NearestFilter,r.texture.magFilter=s.NearestFilter,r.texture.generateMipmaps=!1,r.stencilBuffer=!1,!0===i&&(r.depthTexture=new s.DepthTexture(128,128),r.depthTexture.type=s.UnsignedShortType,r.depthTexture.minFilter=s.NearestFilter,r.depthTexture.magFilter=s.NearestFilter),r}static createAOMaskDepthRenderTarget(e,t){const i=new s.WebGLRenderTarget(t.clientWidth*e.getPixelRatio(),t.clientHeight*e.getPixelRatio(),{type:s.HalfFloatType});return i.texture.minFilter=s.NearestFilter,i.texture.magFilter=s.NearestFilter,i.texture.generateMipmaps=!1,i.stencilBuffer=!1,i.depthTexture=new s.DepthTexture(128,128),i.depthTexture.type=s.UnsignedInt248Type,i.depthTexture.minFilter=s.NearestFilter,i.depthTexture.magFilter=s.NearestFilter,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.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 i=this.stats,r=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 k(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)),r.update(e,d);const t=this.renderer.info.render.triangles;t>c&&(c=t,setTimeout((()=>c=1e3),5e3)),h.update(t,c)};performance.now();s.Ray.prototype.intersectTriangle;const p=[],u=[];let f=0;const g=new a,v=new a,x=t=>{const r=this.renderer.getContext();if(this.paused&&this.running&&r.drawingBufferHeight>1)return void setTimeout((()=>x(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)-f;if(f=t,g.copy(this.camera.matrixWorld),a>1){let t=a;for(;t>.05;)e(z),t-=z;e(t)}else e(a);this.onLoopCallbacks.forEach((e=>e(a))),this.camera?.updateMatrixWorld(),v.copy(this.camera.matrixWorld),v.equals(g)||(this.renderer.shadowMap.needsUpdate=!0),this.resizeRender(),p.length=0,u.length=0;const h=_;if(this.camera.updateMatrixWorld(),N.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),h.setFromProjectionMatrix(N),this.scene.traverseVisible((e=>{if(null!=this.scene.environment&&(e instanceof o||e instanceof s.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 s.Sprite)&&e.visible&&(e.material?.userData?.water||e.material?.uniforms&&null!=e.material?.uniforms[S])&&isObjectInFrustum(e,h)?(e.visible=!1,p.push(e),this.initDepthUniform(e.material),e.renderOrder=100):e instanceof y?(e.visible=!1,u.push(e)):(e instanceof o||e instanceof s.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),u.push(e)),e instanceof o&&e.material?.uniforms&&null!=e.material?.uniforms[H])e.material.uniforms[H].value=t;else if(e instanceof o&&Array.isArray(e.material))for(const i of e.material)i.uniforms&&null!=i.uniforms[H]&&(i.uniforms[H].value=t)})),p.length>0){if(this.scene.overrideMaterial=B,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(p.forEach((e=>e.visible=!0)),u.forEach((e=>e.visible=!0)),this.aoPass.enabled){if(this.scene.overrideMaterial=B,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(x)}),1e3/this.fpsCap):requestAnimationFrame(x))};!0===this.options.enableXR?this.renderer.setAnimationLoop(x):requestAnimationFrame(x)}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 s=0;s<e.length;s++)this.renderer.clearDepth(),this.renderer.setViewport(t-i/2+this.insetWidth*s+this.insetMargin*s,this.insetOffsetY,this.insetWidth,this.insetHeight),this.renderer.render(this.scene,e[s])}addOverlayCamera(e){this.overlayCameras.add(e)}clearOverlayCameras(){this.overlayCameras.clear()}removeOverlayCamera(e){this.overlayCameras.delete(e)}render(e){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!=j(this.scene,(e=>e instanceof o&&!0===e.material?.userData?.hasBloom))}darkenNonBloomed(e){(e instanceof o||e instanceof s.Sprite||e instanceof s.Line)&&e.visible&&(null==e.material.userData||!0!==e.material.userData.hasBloom)?(this.bloomStoredMaterials[e.uuid]=e.material,!0!==e.material.transparent?e.material=E: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[S].value=this.isDepthTextureExtensionSupported?this.depthRenderTarget.depthTexture:this.depthRenderTarget.texture,null!=e.uniforms[W]&&e.uniforms[W].value.set(this.container.clientWidth*this.renderer.getPixelRatio(),this.container.clientHeight*this.renderer.getPixelRatio()),this.camera instanceof h&&(e.uniforms[F].value=this.camera.near,e.uniforms[D].value=this.camera.far))}};V=e=t([R(),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 z=.05;P.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 _=new s.Frustum,I=new s.Box3,N=new s.Matrix4;export function isObjectInFrustum(e,t){const i=I.setFromObject(e);return t.intersectsBox(i)}/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|
@@ -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}from"three-stdlib";import{FBXLoader as l}from"three-stdlib";import{cloneMesh as d}from"../utils/mesh.js";import{pathJoin as m}from"../utils/files.js";import{Subject as p,firstValueFrom as u}from"rxjs";import{importCollisionShapes as g,isCollisionMesh as f}from"./collision/collision-shape-import.js";import*as w from"three";import{iterateMaterials as y}from"../utils/materials.js";import{BufferGeometryUtils as x,EXRLoader as L,KTX2Loader as M,TGALoader as b,UltraHDRLoader as A}from"three/examples/jsm/Addons.js";const S=["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),this.fbxLoader=new l(this.loadingManager),this.objLoader=new c(this.loadingManager),this.textureLoader=new n(this.loadingManager),this.tgaLoader=new b(this.loadingManager),this.exrLoader=new L(this.loadingManager),this.hdrLoader=new A(this.loadingManager),this.ktx2Loader=new M(this.loadingManager),this._textureLoader=new w.ImageBitmapLoader(this.loadingManager),this.audioLoader=new e(this.loadingManager),this.initialisedKtx2=!1,this.makeReady=new p,this.ready=u(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=m(e,"asset-resources"),this.makeReady.next(!0)}getUri(e){return m(this.basePath,e)+`?windowId=${getElectronArg("windowId")}`}async getTexture(e){return null==e||null==e.fileKey?null:(await this.ready,this.textureCache.has(e.id)||await this._getTextureLoader(e.fileKey).loadAsync(this.getUri(e.fileKey)).then((t=>(t.wrapS=j(e.texture?.wrapS),t.wrapT=j(e.texture?.wrapT),t.flipY=e.texture?.flipY??!0,this.textureCache.set(e.id,t),t))),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:this.textureLoader}async getMesh(e,t){if(await this.ready,null==e)return console.error("No asset was provided"),{scene:new s,animations:[]};if(!S.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=d(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,m=e.castShadow??!1;return o.traverse((e=>{e.castShadow=m,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,g(t,e)),this.collisionShapeCache.get(s)}async loadMesh(e){return await this.ready,await this.loadByAsset(e).then((e=>(e.scene=function(e,t){let s=!1;if(t.traverseVisible((e=>{v.test(e.name)&&(s=!0)})),!s)return t;const a=new w.LOD,i=[t];for(;i.length>0;){const e=i.shift(),t=e.name.match(v);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&&!f(e)){a++;const t=Object.keys(e.geometry.attributes).length;t!==r&&0!==r&&(s=!1),r=t}else(e instanceof w.SkinnedMesh||e instanceof w.Bone)&&(s=!1)})),a>1&&s){const s=[],a=[],r=[];e.updateWorldMatrix(!0,!0),e.traverse((e=>{e instanceof i&&e.geometry instanceof t&&!f(e)&&!Array.isArray(e.material)&&(e.updateWorldMatrix(!0,!0),e.geometry.
|
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}from"three-stdlib";import{FBXLoader as l}from"three-stdlib";import{cloneMesh as d}from"../utils/mesh.js";import{pathJoin as m}from"../utils/files.js";import{Subject as p,firstValueFrom as u}from"rxjs";import{importCollisionShapes as g,isCollisionMesh as f}from"./collision/collision-shape-import.js";import*as w from"three";import{iterateMaterials as y}from"../utils/materials.js";import{BufferGeometryUtils as x,EXRLoader as L,KTX2Loader as M,TGALoader as b,UltraHDRLoader as A}from"three/examples/jsm/Addons.js";const S=["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),this.fbxLoader=new l(this.loadingManager),this.objLoader=new c(this.loadingManager),this.textureLoader=new n(this.loadingManager),this.tgaLoader=new b(this.loadingManager),this.exrLoader=new L(this.loadingManager),this.hdrLoader=new A(this.loadingManager),this.ktx2Loader=new M(this.loadingManager),this._textureLoader=new w.ImageBitmapLoader(this.loadingManager),this.audioLoader=new e(this.loadingManager),this.initialisedKtx2=!1,this.makeReady=new p,this.ready=u(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=m(e,"asset-resources"),this.makeReady.next(!0)}getUri(e){return m(this.basePath,e)+`?windowId=${getElectronArg("windowId")}`}async getTexture(e){return null==e||null==e.fileKey?null:(await this.ready,this.textureCache.has(e.id)||await this._getTextureLoader(e.fileKey).loadAsync(this.getUri(e.fileKey)).then((t=>(t.wrapS=j(e.texture?.wrapS),t.wrapT=j(e.texture?.wrapT),t.flipY=e.texture?.flipY??!0,this.textureCache.set(e.id,t),t))),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:this.textureLoader}async getMesh(e,t){if(await this.ready,null==e)return console.error("No asset was provided"),{scene:new s,animations:[]};if(!S.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=d(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,m=e.castShadow??!1;return o.traverse((e=>{e.castShadow=m,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,g(t,e)),this.collisionShapeCache.get(s)}async loadMesh(e){return await this.ready,await this.loadByAsset(e).then((e=>(e.scene=function(e,t){let s=!1;if(t.traverseVisible((e=>{v.test(e.name)&&(s=!0)})),!s)return t;const a=new w.LOD,i=[t];for(;i.length>0;){const e=i.shift(),t=e.name.match(v);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&&!f(e)){a++;const t=Object.keys(e.geometry.attributes).length;t!==r&&0!==r&&(s=!1),r=t}else(e instanceof w.SkinnedMesh||e instanceof w.Bone)&&(s=!1)})),a>1&&s){const s=[],a=[],r=[];e.updateWorldMatrix(!0,!0),e.traverse((e=>{e instanceof i&&e.geometry instanceof t&&!f(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=x.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&&x.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=>(C(e),e))).then((e=>({scene:e,animations:e.animations})))}}}function C(e){if(e instanceof i)for(const t of y(e.material))t instanceof w.MeshPhongMaterial&&!t.color.isLinear&&(t.color.isLinear=!0);e.children?.forEach(C)}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 j(e){switch(e){case"clamp":return w.ClampToEdgeWrapping;case"repeat":return w.RepeatWrapping;case"mirror":return w.MirroredRepeatWrapping}return w.RepeatWrapping}const v=/_LOD(\d+)$/;/*
|
2
2
|
* Copyright (©) 2023. All rights reserved.
|
3
3
|
* See the LICENSE.md file for details.
|
4
4
|
*/
|