@zylem/game-lib 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/actions.d.ts +6 -6
  2. package/dist/api/game-lib.api.json +2045 -769
  3. package/dist/api/game-lib.api.md +74 -10
  4. package/dist/api/game-lib.d.ts +193 -4
  5. package/dist/api/game-lib.typedoc.json +47249 -40214
  6. package/dist/{base-node-life-cycle-D2NuN1VB.d.ts → base-node-life-cycle-BK9xebT9.d.ts} +6 -0
  7. package/dist/chunk-3PRBSSTS.js +24 -0
  8. package/dist/chunk-47DG7I7M.js +1 -0
  9. package/dist/chunk-7QF6YTEZ.js +1 -0
  10. package/dist/chunk-CD7ZOZ35.js +1 -0
  11. package/dist/chunk-CFVRRRZZ.js +1 -0
  12. package/dist/chunk-EVYHPR3J.js +1 -0
  13. package/dist/{chunk-M3XNO56P.js → chunk-JNFFTNMH.js} +1 -1
  14. package/dist/chunk-KVSJE4XD.js +1 -0
  15. package/dist/{chunk-XNDS4YFR.js → chunk-MZZCDXFB.js} +1 -1
  16. package/dist/{chunk-RXDTAWI2.js → chunk-PCFF4LLO.js} +1 -1
  17. package/dist/chunk-UG22Z42P.js +1 -0
  18. package/dist/chunk-YAOXFYOD.js +1 -0
  19. package/dist/{collision-builder-jF-toPIl.d.ts → collision-builder-B_tm8OVy.d.ts} +13 -2
  20. package/dist/core.d.ts +15 -15
  21. package/dist/core.js +1 -1
  22. package/dist/{debug-state-BPT6jEog.d.ts → debug-state-DRoeasG2.d.ts} +1 -1
  23. package/dist/debug.d.ts +6 -6
  24. package/dist/{default-controls-0-vCnli7.d.ts → default-controls-CAKJ5zlo.d.ts} +2 -2
  25. package/dist/{entity-DZbFQ1Wg.d.ts → entity-B9yZeBm4.d.ts} +7 -1
  26. package/dist/{entity-BdSI8CL3.d.ts → entity-BGEq1yfC.d.ts} +32 -4
  27. package/dist/{entity-type-map-Bd69SpAS.d.ts → entity-type-map-CW6RHQkx.d.ts} +5 -5
  28. package/dist/entity.d.ts +12 -10
  29. package/dist/entity.js +1 -1
  30. package/dist/events.d.ts +1 -1
  31. package/dist/{game-C1FHVqXl.d.ts → game-DbqBQiFC.d.ts} +40 -11
  32. package/dist/game-default-6AZZCNST.js +1 -0
  33. package/dist/{game-interfaces-mchNYSZE.d.ts → game-interfaces-vF5sRi1n.d.ts} +7 -1
  34. package/dist/globals.d.ts +1 -1
  35. package/dist/graphics.d.ts +5 -5
  36. package/dist/input-ui.d.ts +4 -4
  37. package/dist/input-ui.js +1 -1
  38. package/dist/input.d.ts +47 -4
  39. package/dist/input.js +1 -1
  40. package/dist/{material-9vJ6SZaI.d.ts → material-DbSuZBbP.d.ts} +1 -1
  41. package/dist/public.d.ts +13 -13
  42. package/dist/public.js +1 -1
  43. package/dist/runtime.d.ts +3 -3
  44. package/dist/runtime.js +1 -1
  45. package/dist/schema/game-config.schema.json +18 -0
  46. package/dist/schema/input-config.schema.json +18 -0
  47. package/dist/schema.d.ts +12 -0
  48. package/dist/schema.js +1 -1
  49. package/dist/{vector-CiSHbivc.d.ts → vector-DN6zlPoE.d.ts} +28 -0
  50. package/dist/web-components.d.ts +12 -12
  51. package/dist/{zylem-camera-C3bn6BTI.d.ts → zylem-camera-Du2UPW9O.d.ts} +13 -1
  52. package/package.json +1 -1
  53. package/dist/chunk-7FR5JSQ2.js +0 -1
  54. package/dist/chunk-E3UBSUPX.js +0 -1
  55. package/dist/chunk-FKIKN7RP.js +0 -24
  56. package/dist/chunk-G4HONLWC.js +0 -1
  57. package/dist/chunk-IKWE2W6L.js +0 -1
  58. package/dist/chunk-JEHFHUH4.js +0 -0
  59. package/dist/chunk-JNKPTL77.js +0 -1
  60. package/dist/chunk-MSC2BEO5.js +0 -1
  61. package/dist/chunk-XNHVRFAK.js +0 -1
  62. package/dist/game-default-QHROHW2O.js +0 -1
@@ -0,0 +1 @@
1
+ import{b as V,d as ve,e as G,j as Se}from"./chunk-CM5YRNBJ.js";import{a as de,b as he}from"./chunk-YHEWKN7N.js";import{a as Q,b as Ce,c as xe}from"./chunk-EVYHPR3J.js";import{c as v,d as D,e as me,f as fe,g as ye,h as f,i as be,j as L}from"./chunk-7WRQ2UAN.js";import{p as ge}from"./chunk-XRP4JJXL.js";import{StageBodyKind as _e}from"@zylem/behaviors/core";import{Color as st,Vector2 as Oe,Vector3 as Ee}from"three";function F(i){if(!i||typeof i!="object")return!1;let e=Object.getPrototypeOf(i);return e===Object.prototype||e===null}function y(i){if(i==null||typeof i=="function"||typeof i!="object")return i;if(i instanceof st||i instanceof Oe||i instanceof Ee)return i.clone();if(i instanceof Float32Array)return new Float32Array(i);if(Array.isArray(i))return i.map(e=>y(e));if(F(i)){let e={};for(let[t,o]of Object.entries(i))t!=="_builders"&&(e[t]=y(o));return e}return i}function S(i,e){let t=y(i);if(!e)return t;if(!F(t)||!F(e))return y(e);let o=t;for(let[n,s]of Object.entries(e)){if(n==="_builders"||s===void 0)continue;let r=o[n];if(n==="shader"){o[n]=y(s);continue}if(r instanceof Oe&&me(s)){o[n]=be(s,r);continue}if(r instanceof Ee&&fe(s)){o[n]=L(s,r);continue}if(F(r)&&F(s)){o[n]=S(r,s);continue}o[n]=y(s)}return o}function Me(i){return i&&i.__kind==="collision"}function ee(i){return i.cloneComponent()}function rt(i,e){let t={kind:i?_e.Static:_e.Dynamic,position:[0,0,0],gravityScale:e.gravityScale??1,canSleep:e.canSleep??!1,ccdEnabled:e.ccdEnabled??!0},o=Q(e.lockRotations);o&&(t.lockRotation=o);let n=Q(e.lockTranslations);return n&&(t.lockTranslation=n),t}function at(i,e){if(e.offset){let t=f(e.offset,v);i.offset=[t.x,t.y,t.z]}e.sensor&&(i.sensor=!0),e.collisionType&&(i.collisionGroups=Ce(e.collisionType,e.collisionFilter))}function _(i,e,t){return at(i,e),{__kind:"collision",bodyDesc:rt(e.static??!1,e),colliderDesc:i,cloneComponent:t}}function lt(i={}){let e=f(i.size,D),t={shape:{type:"box",halfExtents:[e.x/2,e.y/2,e.z/2]}},o=y(i);return _(t,i,()=>lt(o))}function ct(i={}){let e={shape:{type:"sphere",radius:i.radius??1}},t=y(i);return _(e,i,()=>ct(t))}function ut(i={}){let e=i.radius??1,o={shape:{type:"cone",halfHeight:(i.height??2)/2,radius:e}},n=y(i);return _(o,i,()=>ut(n))}function pt(i={}){let e=i.radius??1,o={shape:{type:"cone",halfHeight:(i.height??2)/2,radius:e}},n=y(i);return _(o,i,()=>pt(n))}function dt(i={}){let e=Math.max(i.radiusTop??1,i.radiusBottom??1),o={shape:{type:"cylinder",halfHeight:(i.height??2)/2,radius:e}},n=y(i);return _(o,i,()=>dt(n))}function ht(i={}){let e=i.radius??.5,o={shape:{type:"capsule",halfHeight:(i.length??1)/2,radius:e}},n=y(i);return _(o,i,()=>ht(n))}function mt(i={}){let e=ye(i.tile,{x:10,y:10}),t=i.subdivisions??10,o=(t+1)*(t+1),n=i.heightData??new Float32Array(o),s={shape:{type:"heightfield",rows:t,cols:t,heights:n,scale:[e.x,1,e.y]}},r={...i,static:i.static??!0},a=y(r);return _(s,r,()=>mt(a))}function ft(i={}){let e=f(i.size,D),t={shape:{type:"box",halfExtents:[e.x/2,e.y/2,e.z/2]},sensor:!0},o={...i,static:i.static??!0,sensor:!0},n=y(o);return _(t,o,()=>ft(n))}import{Mesh as ze,ShaderMaterial as Et,Group as _t}from"three";var Ae=import.meta.env.VITE_DEBUG_FLAG==="true";import{nanoid as yt}from"nanoid";var C=class i{parent=null;children=[];options;uuid="";name="";markedForRemoval=!1;lifecycleCallbacks={setup:[],loaded:[],update:[],destroy:[],cleanup:[]};trackLifecycleRegistrations=!1;userLifecycleRegistrations=[];constructor(e=[]){let t=e.filter(o=>!(o instanceof i)).reduce((o,n)=>({...o,...n}),{});this.options=t,this.uuid=yt()}onSetup(...e){return this.lifecycleCallbacks.setup.push(...e),this.recordLifecycleRegistration("onSetup",e),this}onLoaded(...e){return this.lifecycleCallbacks.loaded.push(...e),this.recordLifecycleRegistration("onLoaded",e),this}onUpdate(...e){return this.lifecycleCallbacks.update.push(...e),this.recordLifecycleRegistration("onUpdate",e),this}onDestroy(...e){return this.lifecycleCallbacks.destroy.push(...e),this.recordLifecycleRegistration("onDestroy",e),this}onCleanup(...e){return this.lifecycleCallbacks.cleanup.push(...e),this.recordLifecycleRegistration("onCleanup",e),this}prependSetup(...e){return this.lifecycleCallbacks.setup.unshift(...e),this.recordLifecycleRegistration("prependSetup",e),this}prependUpdate(...e){return this.lifecycleCallbacks.update.unshift(...e),this.recordLifecycleRegistration("prependUpdate",e),this}setParent(e){this.parent=e}getParent(){return this.parent}add(e){this.children.push(e),e.setParent(this)}remove(e){let t=this.children.indexOf(e);t!==-1&&(this.children.splice(t,1),e.setParent(null))}getChildren(){return this.children}isComposite(){return this.children.length>0}enableUserLifecycleTracking(){this.trackLifecycleRegistrations=!0}replayUserLifecycleRegistrationsTo(e,t){for(let o of this.userLifecycleRegistrations){let n=t?o.callbacks.map(s=>t(s)):[...o.callbacks];switch(o.method){case"onSetup":e.onSetup(...n);break;case"onLoaded":e.onLoaded(...n);break;case"onUpdate":e.onUpdate(...n);break;case"onDestroy":e.onDestroy(...n);break;case"onCleanup":e.onCleanup(...n);break;case"prependSetup":e.prependSetup(...n);break;case"prependUpdate":e.prependUpdate(...n);break}}}cloneChildrenInto(e){for(let t of this.children)e.add(bt(t))}nodeSetup(e){this.markedForRemoval=!1,typeof this._setup=="function"&&this._setup(e);for(let t of this.lifecycleCallbacks.setup)t(e);this.children.forEach(t=>t.nodeSetup(e))}nodeUpdate(e){if(!this.markedForRemoval){typeof this._update=="function"&&this._update(e),typeof this._tickActions=="function"&&this._tickActions(e.delta);for(let t of this.lifecycleCallbacks.update)t(e);this.children.forEach(t=>t.nodeUpdate(e))}}nodeDestroy(e){if(!this.markedForRemoval){this.children.forEach(t=>t.nodeDestroy(e));for(let t of this.lifecycleCallbacks.destroy)t(e);typeof this._destroy=="function"&&this._destroy(e),this.markedForRemoval=!0;for(let t of this.lifecycleCallbacks.cleanup)t(e);typeof this._cleanup=="function"&&this._cleanup(e)}}async nodeLoaded(e){typeof this._loaded=="function"&&await this._loaded(e);for(let t of this.lifecycleCallbacks.loaded)t(e)}nodeCleanup(e){this.children.forEach(t=>t.nodeCleanup?.(e));for(let t of this.lifecycleCallbacks.cleanup)t(e);typeof this._cleanup=="function"&&this._cleanup(e)}getOptions(){return this.options}setOptions(e){this.options={...this.options,...e}}recordLifecycleRegistration(e,t){!this.trackLifecycleRegistrations||t.length===0||this.userLifecycleRegistrations.push({method:e,callbacks:[...t]})}};function bt(i){let e=i?.clone;if(typeof e!="function")throw new Error(`Cannot clone child node "${i.name||i.uuid||"unknown"}": missing clone() support.`);return e.call(i)}import{createTransformStore as Mt}from"@zylem/behaviors/core";import{makeMoveable as gt}from"@zylem/behaviors/core";function Pe(i){let e=gt(i);return ge(e)}import{clearVelocityIntent as je}from"@zylem/behaviors/core";import{Color as St,Vector3 as Ot}from"three";var we=Symbol("explicitSpawnPosition");function De(i){return i.filter(e=>!(e instanceof C)).some(e=>e!=null&&typeof e=="object"&&"position"in e)}function Be(i){i[we]=!0}function Ct(i){return i._spawnPositionExplicit?!0:i.options[we]===!0}function xt(i){return i.options.hideUntilPositioned!==!1}function Re(i){return i._spawnPlacementPending===!0}function vt(i){return i._spawnPositionExplicit===!0||i._spawnPlacementReady===!0}function U(i){let e=i.group??i.mesh;if(e){if(i.physicsAttached&&i.body)try{let t=i.body.translation();e.position.set(t.x,t.y,t.z);return}catch{}if(i.wasmStageRef&&(i.runtimeHandle??-1)>=0){let t=i.wasmStageRef.getPose(i.runtimeHandle);if(t){e.position.set(t.position[0],t.position[1],t.position[2]);return}}if(i.options.position){let t=f(i.options.position,v);e.position.set(t.x,t.y,t.z)}}}function T(i,e){i.group&&(i.group.visible=e),i.mesh&&(i.mesh.visible=e)}function Hi(i){if(i._spawnInProgress=!0,i._spawnPlacementReady=!1,!xt(i)){i._spawnPlacementPending=!1;return}i._spawnPositionExplicit=Ct(i),i._spawnPlacementPending=!0,T(i,!1)}function Yi(i){i._spawnInProgress=!1}function Fe(i){i._spawnPlacementReady=!0}function te(i){if(i._spawnPlacementPending){if(U(i),i._spawnPlacementPending=!1,i.options.visible===!1){T(i,!1);return}T(i,!0)}}function Wi(i){!Re(i)||i.options.hideUntilPositioned===!0&&!vt(i)||te(i)}function Te(i){U(i),i._spawnPlacementPending=!1,T(i,!0)}function ke(i){Re(i)&&T(i,!1)}var N={position:new Ot(0,0,0),material:{color:new St("#ffffff"),shader:V},collision:{static:!1}};function eo(i,e){let t=i.filter(n=>!(n instanceof C)),o=S(e);for(let n of t)o=S(o,n);return De(i)&&Be(o),o}function At(i){return i!=null&&typeof i=="object"}function Ie(i){return{phase:i?.phase??"stay",cooldownMs:i?.cooldownMs}}function Pt(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var P=class extends C{group;mesh;materials;bodyDesc=null;body=null;physicsAttached=!1;physicsWorldRef=null;colliderDesc;custom={};colliderDescs=[];compoundMeshes=[];debugInfo={};debugMaterial;collisionDelegate={collision:[],cooldowns:new Map,nextId:0};collisionType;packKey=null;bundleKey=null;instanceId=-1;isInstanced=!1;isBundled=!1;runtimeHandle=-1;runtimeAttached=!1;wasmStageRef=null;eventDelegate=new de;behaviorRefs=[];cloneFactory=null;trackAddedComponents=!1;trackedComponents=[];transformStore;_spawnPlacementPending=!1;_spawnPositionExplicit=!1;_spawnPlacementReady=!1;_spawnInProgress=!1;moveX;moveY;moveZ;moveXY;moveXZ;move;resetVelocity;moveForwardXY;getPosition;getVelocity;setPosition;setPositionX;setPositionY;setPositionZ;wrapAroundXY;wrapAround3D;rotateInDirection;rotateYEuler;rotateEuler;rotateX;rotateY;rotateZ;setRotationY;setRotationX;setRotationZ;setRotationDegrees;setRotationDegreesY;setRotationDegreesX;setRotationDegreesZ;setRotation;getRotation;constructor(){super(),this.transformStore=Mt(),Pe(this),this.wrapSpawnPlacementMutators()}wrapSpawnPlacementMutators(){let e=()=>{Fe(this),!this._spawnInProgress&&(U(this),te(this))},t=s=>(r,a,l)=>{!this.body&&!(this.wasmStageRef&&this.runtimeHandle>=0)||(s(r,a,l),e())},o=s=>r=>{!this.body&&!(this.wasmStageRef&&this.runtimeHandle>=0)||(s(r),e())};this.setPosition=t(this.setPosition.bind(this)),this.setPositionX=o(this.setPositionX.bind(this)),this.setPositionY=o(this.setPositionY.bind(this)),this.setPositionZ=o(this.setPositionZ.bind(this));let n=this.setPose.bind(this);this.setPose=s=>{let r=n(s);return r&&s.position!=null&&e(),r}}reveal(){this.options.visible=!0,Te(this)}getPose(){if(this.wasmStageRef&&this.runtimeHandle>=0){let n=this.wasmStageRef.getPose(this.runtimeHandle);if(n)return{position:{x:n.position[0],y:n.position[1],z:n.position[2]},rotation:{x:n.rotation[0],y:n.rotation[1],z:n.rotation[2],w:n.rotation[3]}}}let e=this.body;if(!e)return null;let t=e.translation(),o=e.rotation();return{position:{x:t.x,y:t.y,z:t.z},rotation:{x:o.x,y:o.y,z:o.z,w:o.w}}}setPose(e){if(this.wasmStageRef&&this.runtimeHandle>=0){let o=!0;if(e.position){let n=f(e.position);o=this.wasmStageRef.setPosition(this.runtimeHandle,n.x,n.y,n.z)&&o}if(e.rotation){let{x:n,y:s,z:r,w:a}=e.rotation;o=this.wasmStageRef.setRotation(this.runtimeHandle,n,s,r,a)&&o}return o}let t=this.body;if(!t)return!1;if(e.position){let o=f(e.position);t.setTranslation({x:o.x,y:o.y,z:o.z},!0)}return e.rotation&&t.setRotation(e.rotation,!0),!0}add(...e){for(let t of e)t instanceof ze?(this.addMeshComponent(t),this.trackComponent(t)):Me(t)?(this.addCollisionComponent(t),this.trackComponent(t)):super.add(t);return this}addMeshComponent(e){if(this.mesh)this.compoundMeshes.push(e),this.group||(this.group=new _t,this.group.add(this.mesh)),this.group.add(e);else if(this.mesh=e,this.materials||(this.materials=[]),e.material){let t=e.material;Array.isArray(t)?this.materials.push(...t):this.materials.push(t)}}addCollisionComponent(e){if(this.bodyDesc)this.colliderDescs.push(e.colliderDesc);else{this.bodyDesc=e.bodyDesc,this.colliderDesc=e.colliderDesc,this.colliderDescs.push(e.colliderDesc);let t=f(this.options?.position,v);this.bodyDesc.position=[t.x,t.y,t.z]}}trackComponent(e){if(this.trackAddedComponents){if(e instanceof ze){this.trackedComponents.push({kind:"mesh",component:Le(e)});return}this.trackedComponents.push({kind:"collision",component:ee(e)})}}_actions=[];runAction(e){return this._actions.push(e),e}action(e){return e.persistent=!0,this._actions.push(e),e}clearActions(){this._actions.length=0}_tickActions(e){if(this._actions.length===0)return;let t=this.transformStore;t.velocity.x=0,t.velocity.y=0,t.velocity.z=0,je(t,"actions"),t.angularVelocity.x=0,t.angularVelocity.y=0,t.angularVelocity.z=0,t.dirty.angularVelocity=!1;for(let o=this._actions.length-1;o>=0;o--){let n=this._actions[o];n.tick(this,e),n.done&&!n.persistent&&this._actions.splice(o,1)}this._actions.length===0&&(t.velocity.x=0,t.velocity.y=0,t.velocity.z=0,je(t,"actions"),t.angularVelocity.x=0,t.angularVelocity.y=0,t.angularVelocity.z=0,t.dirty.angularVelocity=!1)}create(){return this.name=this.options.name||"",this}clone(e){if(!this.cloneFactory)throw new Error(`Cannot clone ${this.constructor.name}: clone() is only supported for entities created by official factory helpers.`);let t=this.cloneFactory(S(this.options,e)),o=this.copyBehaviorRefsTo(t),n=r=>Dt(r,o);this.replayUserLifecycleRegistrationsTo(t,n);let s=this.getCollisionRegistrations();if(s.length>0)for(let r of s)t.onCollision(n(r.callback),r.options);for(let r of this.trackedComponents){if(r.kind==="mesh"){t.add(Le(r.component));continue}t.add(ee(r.component))}return this.cloneChildrenInto(t),t}finalizeCloneSupport(e){return this.cloneFactory=e,this.enableUserLifecycleTracking(),this.trackAddedComponents=!0,this}onCollision(...e){let t=[...this.collisionDelegate.collision??[]],o=this.collisionDelegate.nextId??0;if(e.length===1||e.length===2&&(e[1]==null||At(e[1]))){let n=e[0];if(!n)return this;let s=e[1];return t.push({id:o,callback:n,options:Ie(s)}),o+=1,this.collisionDelegate.collision=t,this.collisionDelegate.nextId=o,this}for(let n of e)t.push({id:o,callback:n,options:Ie()}),o+=1;return this.collisionDelegate.collision=t,this.collisionDelegate.nextId=o,this}use(e,t){let o={descriptor:e,options:{...e.defaultOptions,...t}};this.behaviorRefs.push(o);let n={getFSM:()=>o.fsm??null,getOptions:()=>o.options,ref:o},s=e.createHandle?.(o)??{};return{...n,...s}}getBehaviorRefs(){return this.behaviorRefs}getCollisionCallbacks(){return this.getCollisionRegistrations().map(e=>e.callback)}getCollisionRegistrations(){return(this.collisionDelegate.collision??[]).map(e=>({id:e.id,callback:e.callback,options:{...e.options}}))}copyBehaviorRefsTo(e){let t=new Map;for(let o of this.behaviorRefs){e.use(o.descriptor,y(o.options));let n=e.getBehaviorRefs().at(-1);n&&t.set(o,n)}return t}_setup(e){for(let t=this._actions.length-1;t>=0;t--){let o=this._actions[t];o.done&&!o.persistent?this._actions.splice(t,1):o.reset()}}async _loaded(e){}_update(e){this.updateMaterials(e)}_destroy(e){}_cleanup(e){this.disposeEvents();for(let t of this.compoundMeshes)t.geometry?.dispose(),Array.isArray(t.material)?t.material.forEach(o=>o.dispose()):t.material?.dispose();this.compoundMeshes.length=0,this.debugMaterial?.dispose(),this.debugMaterial=void 0,this.group?.removeFromParent()}_collision(e,t,o={phase:"stay",nowMs:Pt()}){if(!this.collisionDelegate.collision?.length)return;let n=this.collisionDelegate.cooldowns??new Map;this.collisionDelegate.cooldowns=n;for(let s of this.collisionDelegate.collision){if(s.options.phase!==o.phase)continue;let r=s.options.cooldownMs;if(r!=null){let a=`${s.id}:${e.uuid}`,l=n.get(a);if(l!=null&&o.nowMs-l<r)continue;n.set(a,o.nowMs)}s.callback({entity:this,other:e,globals:t})}}updateMaterials(e){if(this.materials?.length)for(let t of this.materials)t instanceof Et&&t.uniforms&&t.uniforms.iTime&&(t.uniforms.iTime.value+=e.delta)}buildInfo(){let e={};return e.name=this.name,e.uuid=this.uuid,e}dispatch(e,t){this.eventDelegate.dispatch(e,t),he.emit(e,t)}listen(e,t){return this.eventDelegate.listen(e,t)}disposeEvents(){this.eventDelegate.dispose()}};function wt(i){let e=new P;return e.options={...N,...i},ie(e,t=>wt(t??{}))}function Le(i){let e=i.clone(!0),t=[],o=[];i.traverse(n=>t.push(n)),e.traverse(n=>o.push(n));for(let n=0;n<t.length;n++){let s=t[n],r=o[n];s?.geometry?.clone&&(r.geometry=s.geometry.clone()),s?.material&&(r.material=Array.isArray(s.material)?s.material.map(a=>a.clone()):s.material.clone())}return e}function Dt(i,e){return e.size===0?i:((...t)=>{let o=Array.from(e.entries()).map(([n,s])=>({sourceRef:n,options:n.options,fsm:n.fsm,hasFSM:Object.prototype.hasOwnProperty.call(n,"fsm"),targetRef:s}));for(let n of o)n.sourceRef.options=n.targetRef.options,n.targetRef.fsm===void 0?delete n.sourceRef.fsm:n.sourceRef.fsm=n.targetRef.fsm;try{return i(...t)}finally{for(let n=o.length-1;n>=0;n--){let s=o[n];s.sourceRef.options=s.options,s.hasFSM?s.sourceRef.fsm=s.fsm:delete s.sourceRef.fsm}}})}function ie(i,e){return i.finalizeCloneSupport(e),i}function Ve(i){return typeof i?.load=="function"&&typeof i?.data=="function"}var Z=class{entityReference;constructor(e){this.entityReference=e}load(){this.entityReference.load&&this.entityReference.load()}data(){return this.entityReference.data?this.entityReference.data():null}};function Ge(i){let{args:e,defaultConfig:t,EntityClass:o,BuilderClass:n,entityType:s,MeshBuilderClass:r,CollisionBuilderClass:a,cloneFactory:l}=i,p=null,d,c=e.findIndex(b=>!(b instanceof C));c!==-1&&(d=e.splice(c,1).find(h=>!(h instanceof C)));let u=d?S(t,d):S(t);e.push(u);for(let b of e){if(b instanceof C)continue;let h=null,R=new o(b);try{if(Ve(R)){let I=new Z(R);I.load(),h=I.data()}}catch(I){console.error("Error creating entity with loader:",I)}p=new n(b,R,r?new r(h):null,a?new a(h):null),b.material&&p.withMaterial(b.material,s)}if(!p)throw new Error(`missing options for ${String(s)}, builder is not initialized.`);let m=p.build();return d!=null&&typeof d=="object"&&"position"in d&&(m._spawnPositionExplicit=!0),ie(m,b=>l(b))}import{Box3 as le,BufferAttribute as Vt,SkinnedMesh as Gt,MeshStandardMaterial as Ut,Group as Nt,Vector3 as M,Matrix4 as Ke}from"three";var B=class{async loadFile(e,t){switch(ve(e)){case"fbx":{let n=await G.loadFBX(e,t);return{object:n.object,animation:n.animations?.[0]}}case"gltf":case"glb":{let n=await G.loadGLTF(e,t);return{object:n.object,gltf:n.gltf}}case"obj":return{object:(await G.loadOBJ(e,t)).object};default:throw new Error(`Unsupported file type: ${e}`)}}};import{AnimationMixer as Bt,Bone as Ue,LoopOnce as Rt,LoopRepeat as Ft}from"three";function Tt(i){let e=i.lastIndexOf(".");return e>=0?i.slice(0,e):i}function Ne(i,e){if(!i?.name?.endsWith(".position"))return!1;let t=Tt(i.name),o=e.get(t);return o instanceof Ue?!(o.parent instanceof Ue):/hips\.position$/i.test(i.name)||/root\.position$/i.test(i.name)}function kt(i,e,t,o){for(let n of i.tracks){if(!Ne(n,e)||!n.values||n.values.length<3)continue;let s=n.values[0],r=o??n.values[1],a=n.values[2];for(let l=0;l<n.values.length;l+=3)n.values[l]=s,t&&(n.values[l+1]=r),n.values[l+2]=a}return i}function zt(i,e){for(let t of i.tracks)if(Ne(t,e)&&!(!t.values||t.values.length<3))return t.values[1];return null}var H=class{constructor(e){this.target=e}_mixer=null;_actions={};_animations=[];_currentAction=null;_pauseAtPercentage=0;_isPaused=!1;_queuedKey=null;_fadeDuration=.5;_currentKey="";_assetLoader=new B;async loadAnimations(e,t={}){if(!e.length)return;let o=t.stripRootMotionY??!1,n=t.referenceRootY,s=t.referenceAnimationPath,r=await Promise.all(e.map(c=>this._assetLoader.loadFile(c.path))),a=new Map;this.target.traverse(c=>{c.name&&a.set(c.name,c)});let l=[];if(r.forEach((c,u)=>{c.animation&&l.push({key:e[u].key||u.toString(),clip:c.animation,path:e[u].path})}),!l.length)return;let p=n;if(o&&p===void 0){let c=s?l.findIndex(m=>m.path===s):0,u=c>=0?[c,...l.map((m,g)=>g).filter(m=>m!==c)]:l.map((m,g)=>g);for(let m of u){let g=zt(l[m].clip,a);if(g!==null){p=g;break}}}let d=l.map(({key:c,clip:u})=>({key:c,clip:kt(u,a,o,p)}));this._animations=d.map(c=>c.clip),this._mixer=new Bt(this.target),d.forEach(({key:c,clip:u})=>{this._actions[c]=this._mixer.clipAction(u)}),this.playAnimation({key:d[0].key})}update(e){if(!this._mixer||!this._currentAction)return;this._mixer.update(e);let t=this._currentAction.getClip().duration*(this._pauseAtPercentage/100);if(!this._isPaused&&this._pauseAtPercentage>0&&this._currentAction.time>=t&&(this._currentAction.time=t,this._currentAction.paused=!0,this._isPaused=!0,this._queuedKey!==null)){let o=this._actions[this._queuedKey];o.reset().play(),this._currentAction.crossFadeTo(o,this._fadeDuration,!1),this._currentAction=o,this._currentKey=this._queuedKey,this._queuedKey=null}}playAnimation(e){if(!this._mixer)return;let{key:t,pauseAtPercentage:o=0,pauseAtEnd:n=!1,fadeToKey:s,fadeDuration:r=.5}=e;if(t===this._currentKey)return;let a=this._actions[t];if(!a)return;if(a===this._currentAction){this._currentKey=t;return}this._queuedKey=s||null,this._fadeDuration=r,this._pauseAtPercentage=n?100:o,this._isPaused=!1;let l=this._currentAction;this._pauseAtPercentage>0?(a.setLoop(Rt,1/0),a.clampWhenFinished=!0):(a.setLoop(Ft,1/0),a.clampWhenFinished=!1),a.reset().play(),l&&l.crossFadeTo(a,r,!1),this._currentAction=a,this._currentKey=t}dispose(){Object.values(this._actions).forEach(e=>{e.stop()}),this._mixer&&(this._mixer.stopAllAction(),this._mixer.uncacheRoot(this.target),this._mixer=null),this._actions={},this._animations=[],this._currentAction=null,this._currentKey=""}get currentAnimationKey(){return this._currentKey}get animations(){return this._animations}};import{BufferGeometry as It,Mesh as Ze,Color as Lt}from"three";import{Mesh as jt}from"three";var Y=class{_build(e,t,o){let n=new jt(t,o.at(-1));return n.position.set(0,0,0),n.castShadow=!0,n.receiveShadow=!0,n}_postBuild(){}};var W=class extends xe{},He=class extends Y{build(e){return new It}postBuild(){}},K=class{meshBuilder;collisionBuilder;materialBuilder;options;entity;constructor(e,t,o,n){this.options=e,this.entity=t,this.meshBuilder=o,this.collisionBuilder=n,this.materialBuilder=new Se;let s={meshBuilder:this.meshBuilder,collisionBuilder:this.collisionBuilder,materialBuilder:this.materialBuilder};this.options._builders=s,t&&t.options&&(t.options._builders=s)}withPosition(e){return this.options.position=e,this}withMaterial(e,t){return this.materialBuilder&&this.materialBuilder.build(e,t),this}applyMaterialToGroup(e,t){e.traverse(o=>{o instanceof Ze&&o.type==="SkinnedMesh"&&t[0]&&!o.material.map&&(o.material=t[0]),o.castShadow=!0,o.receiveShadow=!0})}build(){let e=this.entity;if(this.materialBuilder&&(e.materials=this.materialBuilder.materials),this.meshBuilder&&e.materials){let t=this.meshBuilder.build(this.options);e.mesh=this.meshBuilder._build(this.options,t,e.materials),this.meshBuilder.postBuild()}if(e.group&&e.materials&&this.applyMaterialToGroup(e.group,e.materials),this.collisionBuilder){this.collisionBuilder.withCollision(this.options?.collision||{});let[t,o]=this.collisionBuilder.build(this.options);e.bodyDesc=t,e.colliderDesc=o,e.colliderDescs.push(o);let{x:n,y:s,z:r}=f(this.options.position,v);e.bodyDesc.position=[n,s,r]}if(this.options.collisionType&&(e.collisionType=this.options.collisionType),this.options.color instanceof Lt){let t=o=>{let n=o;n&&n.color&&n.color.set&&n.color.set(this.options.color)};if(e.materials?.length)for(let o of e.materials)t(o);if(e.mesh&&e.mesh.material){let o=e.mesh.material;Array.isArray(o)?o.forEach(t):t(o)}e.group&&e.group.traverse(o=>{if(o instanceof Ze&&o.material){let n=o.material;Array.isArray(n)?n.forEach(t):t(n)}})}return e}};var Xe={...N,material:{shader:V},animations:[],models:[],collisionShape:"capsule"};function k(i){return L(i.scale,D)}var Zt=1e-4,Ht=/foot$/i,oe=new M,q=new M,Ye=new M,X=new M,We=new Ke;function Yt(i){let e=1/0,t=!1;return i.traverse(o=>{if(!o.isSkinnedMesh)return;let n=o,s=n.geometry,r=s.attributes.position,a=s.attributes.skinIndex,l=s.attributes.skinWeight,p=n.skeleton;if(!r||!a||!l||!p)return;t=!0,p.update(),n.updateMatrixWorld(!0);let d=p.boneMatrices;if(d)for(let c=0;c<r.count;c++){Ye.fromBufferAttribute(r,c).applyMatrix4(n.bindMatrix),X.set(0,0,0);for(let u=0;u<4;u++){let m=l.getComponent(c,u);if(m===0)continue;let g=a.getComponent(c,u);We.fromArray(d,g*16),X.addScaledVector(q.copy(Ye).applyMatrix4(We),m)}X.applyMatrix4(n.bindMatrixInverse).applyMatrix4(n.matrixWorld),e=Math.min(e,X.y)}}),!t||!Number.isFinite(e)?null:e}function Wt(i,e){e.updateMatrixWorld(!0);let t=e.getWorldPosition(oe).y,o=Yt(i)??1/0;if(i.traverse(n=>{!n.isBone||!Ht.test(n.name)||(n.getWorldPosition(oe),o=Math.min(o,oe.y))}),Number.isFinite(o)||i.traverse(n=>{if(!n.isSkinnedMesh)return;let s=n;if(s.computeBoundingBox(),!s.boundingBox)return;let{min:r,max:a}=s.boundingBox;for(let l of[[r.x,r.y,r.z],[r.x,r.y,a.z],[r.x,a.y,r.z],[r.x,a.y,a.z],[a.x,r.y,r.z],[a.x,r.y,a.z],[a.x,a.y,r.z],[a.x,a.y,a.z]])q.set(l[0],l[1],l[2]),q.applyMatrix4(s.matrixWorld),o=Math.min(o,q.y)}),!Number.isFinite(o)){let n=new le().setFromObject(i);if(n.isEmpty())return null;o=n.min.y}return o-t}function Kt(i,e,t){return i.stripRootMotionY!==void 0?i.stripRootMotionY:!!(e&&t.some(o=>o===e))}function j(i){let e=i.collision?.position;return e?f(e,v):null}function ne(i){return!!i.collision?.size}function Xt(i){i.hasWarnedDynamicTrimesh||(i.hasWarnedDynamicTrimesh=!0,console.warn(`Actor "${i.name||i.uuid}" requested collisionShape="trimesh" on a dynamic body; falling back to bounds.`))}function $e(i,e,t){let o=i==="model"?"bounds":i??"capsule";return o==="trimesh"&&!e?(t?.(),"bounds"):o}function qe(i,e){let t=i.x||.5,o=i.y||1,n=i.z||.5,s=Math.max(t,n)/2,r=o/2;return{shape:{type:"capsule",halfHeight:Math.max(0,r-s),radius:s},offset:[e.x,e.y,e.z],sensor:!1}}function w(i){let e=f(i.collision?.size??i.size,{x:.5,y:1,z:.5}),t=e.y||1,o=j(i);return qe({x:e.x||.5,y:t,z:e.z||.5},o??{x:0,y:t/2,z:0})}function Je(i){let e=i.collision?.size;if(!e)return null;let t=f(e,v),o=t.x/2,n=t.y/2,s=t.z/2,r=j(i);return{shape:{type:"box",halfExtents:[o,n,s]},offset:[r?.x??0,r?.y??n,r?.z??0],sensor:!1}}function Qe(i,e,t){let n=e.matrixWorld.clone().invert().multiply(i.matrixWorld);return new Ke().makeScale(t.x,t.y,t.z).multiply(n)}function se(i,e,t){i.updateMatrixWorld(!0);let o=!1,n=new le;if(i.traverse(a=>{if(!a.isMesh)return;let l=a,p=l.geometry;if(!p)return;let d=null;if(l instanceof Gt?(l.computeBoundingBox(),d=l.boundingBox?.clone()??null):(p.computeBoundingBox(),d=p.boundingBox?.clone()??null),!d)return;let c=d.applyMatrix4(Qe(l,e,t));if(!o){n.copy(c),o=!0;return}n.union(c)}),!o||n.isEmpty())return null;let s=new M,r=new M;return n.getSize(s),n.getCenter(r),{size:s,center:r}}function $t(i,e,t){i.updateMatrixWorld(!0);let o=[],n=[],s=new le,r=new M,a=!1;if(i.traverse(p=>{if(!p.isMesh)return;let d=p,c=d.geometry;if(!c)return;let u=c.getAttribute("position");if(!(u instanceof Vt))return;let m=Qe(d,e,t),g=o.length/3;for(let h=0;h<u.count;h++)r.set(u.getX(h),u.getY(h),u.getZ(h)),r.applyMatrix4(m),o.push(r.x,r.y,r.z),s.expandByPoint(r);let b=c.getIndex();if(b)for(let h=0;h<b.count;h++)n.push(g+b.getX(h));else for(let h=0;h<u.count;h++)n.push(g+h);a=!0}),!a||o.length===0||n.length===0)return null;let l=new M;return s.getCenter(l),{vertices:new Float32Array(o),indices:new Uint32Array(n),center:l}}function et(i,e,t){let o=Je(t);if(o)return o;if(!i||!e)return w(t);let n=se(i,e,k(t));if(!n)return w(t);let s=j(t);return{shape:{type:"box",halfExtents:[n.size.x/2,n.size.y/2,n.size.z/2]},offset:[s?.x??n.center.x,s?.y??n.center.y,s?.z??n.center.z],sensor:!1}}function tt(i,e,t,o,n){if(ne(n)||!i||!e)return w(n);let s=se(i,e,k(n));if(!s)return w(n);let a=j(n);if(!a){let l=t&&o?se(t,o,k(n)):null;a=l?{x:l.center.x,y:l.center.y,z:l.center.z}:{x:s.center.x,y:s.center.y,z:s.center.z}}return qe({x:s.size.x,y:s.size.y,z:s.size.z},a)}function it(i,e,t){let o=Je(t);if(o)return o;if(!i||!e)return w(t);let n=$t(i,e,k(t));if(!n)return w(t);let s=j(t);return{shape:{type:"trimesh",vertices:n.vertices,indices:n.indices},offset:s?[s.x-n.center.x,s.y-n.center.y,s.z-n.center.z]:[0,0,0],sensor:!1}}function $(i){i&&i.traverse(e=>{if(!e.isMesh)return;let t=e;t.geometry?.dispose(),Array.isArray(t.material)?t.material.forEach(o=>o.dispose()):t.material?.dispose()})}var re=class extends W{objectModel=null;collisionSource=null;collisionShape="capsule";constructor(e){super(),this.objectModel=e.objectModel,this.collisionSource=e.collisionSource??e.objectModel??null,this.collisionShape=e.collisionShape??"capsule"}collider(e){let t=$e(this.collisionShape,!!e.collision?.static);return t==="bounds"?et(this.objectModel,this.objectModel,e):t==="trimesh"?it(this.objectModel,this.objectModel,e):tt(this.collisionSource,this.collisionSource,this.objectModel,this.objectModel,e)}},ae=class extends K{createEntity(e){return new z(e)}},qt=Symbol("Actor"),z=class extends P{static type=qt;_object=null;_collisionSource=null;_animationDelegate=null;_modelFileNames=[];_assetLoader=new B;_loadGeneration=0;_loadStatus="idle";controlledRotation=!1;hasWarnedDynamicTrimesh=!1;constructor(e){super(),this.options=S(Xe,e),this.prependUpdate(this.actorUpdate.bind(this)),this.controlledRotation=!0}create(){return this._loadStatus==="idle"&&(this.options.models?.length??0)>0&&this.load(),super.create()}load(){this._loadStatus==="loading"||this._loadStatus==="loaded"||(this._modelFileNames=[...this.options.models||[]],this._modelFileNames.length!==0&&(this.disposeRuntimeState(!0),this._loadStatus="loading",this.loadModelsDeferred(++this._loadGeneration)))}data(){return{animations:this._animationDelegate?.animations,objectModel:this._object,collisionSource:this._collisionSource??this._object,collisionShape:this.options.collisionShape}}needsDeferredModelCollision(){return this.requiresLoadedCollisionSource()?!this.getRuntimeCollisionSource():!1}synchronizeRuntimeCollider(){let e=this.getResolvedCollisionShape(),t;if(e==="bounds")t=et(this._object,this.group??this._object,this.options);else if(e==="trimesh")t=it(this._object,this.group??this._object,this.options);else{let o=this.getRuntimeCollisionSource();t=tt(o,o,this._object,this._object,this.options)}this.colliderDesc=t,this.colliderDescs.length>0?this.colliderDescs[0]=t:this.colliderDescs.push(t)}actorUpdate(e){this._animationDelegate?.update(e.delta)}actorDestroy(){this._loadGeneration+=1,this._loadStatus="idle",this.disposeRuntimeState(!0),this._modelFileNames=[]}_cleanup(e){super._cleanup(e),this.actorDestroy()}playAnimation(e){this._animationDelegate?.playAnimation(e)}get object(){return this._object}get collisionSource(){return this._collisionSource??this._object}getDebugInfo(){let e={type:"Actor",models:this._modelFileNames.length>0?this._modelFileNames:"none",modelLoaded:!!this._object,scale:(()=>{let t=f(this.options.scale,D);return`${t.x}, ${t.y}, ${t.z}`})(),collisionShape:this.getResolvedCollisionShape()};if(this._animationDelegate&&(e.currentAnimation=this._animationDelegate.currentAnimationKey||"none",e.animationsCount=this.options.animations?.length||0),this._object){let t=0,o=0;this._object.traverse(n=>{if(!n.isMesh)return;t++;let s=n.geometry;s?.attributes.position&&(o+=s.attributes.position.count)}),e.meshCount=t,e.vertexCount=o}return e}getResolvedCollisionShape(){return $e(this.options.collisionShape,!!this.options.collision?.static,()=>Xt(this))}requiresLoadedCollisionSource(){let e=this.getResolvedCollisionShape();return e==="bounds"||e==="trimesh"?!ne(this.options):e==="capsule"?!ne(this.options)&&this.getCollisionSourceSelection().file!==null:!1}getRuntimeCollisionSource(){let e=this.getResolvedCollisionShape();return e==="bounds"||e==="trimesh"?this._object:this._collisionSource??this._object}getCollisionSourceSelection(){let e=this.options.models?.[0]??null,t=this.options.animations?.[0]?.path??null;return t?{file:t,reuseVisibleModel:t===e}:{file:e,reuseVisibleModel:!0}}disposeRuntimeState(e){this._animationDelegate&&(this._animationDelegate.dispose(),this._animationDelegate=null);let t=this._collisionSource;$(this._object),t&&t!==this._object&&$(t),this._object=null,this._collisionSource=null,e&&this.group&&(this.group.clear(),this.group=void 0)}loadModelsDeferred(e){this.dispatch("entity:model:loading",{entityId:this.uuid,files:this._modelFileNames});let t=this.getCollisionSourceSelection(),o=this._modelFileNames.map(s=>this._assetLoader.loadFile(s,{clone:!0})),n=t.file&&!t.reuseVisibleModel?this._assetLoader.loadFile(t.file,{clone:!0}):Promise.resolve(null);Promise.all([Promise.all(o),n]).then(([s,r])=>{if(e!==this._loadGeneration){s.forEach(l=>$(l.object??null)),r?.object&&$(r.object);return}this._object=s[0]?.object??null,this._collisionSource=t.reuseVisibleModel?this._object:r?.object??this._object,this._loadStatus=this._object?"loaded":"idle";let a=0;if(this._object){this._object.traverse(u=>{u.isMesh&&a++}),this.group=new Nt,this.group.add(this._object),this.group.scale.copy(k(this.options)),ke(this),this.applyMaterialOverrides(),this._animationDelegate=new H(this._object);let l=this.options.animations||[],p=this.options.models?.[0],d=l.map(u=>u.path),c=Kt(this.options,p,d);l.length>0?this._animationDelegate.loadAnimations(l,{stripRootMotionY:c,referenceAnimationPath:p}).then(()=>{e===this._loadGeneration&&(this.alignVisualModelToGround(),this.dispatch("entity:animation:loaded",{entityId:this.uuid,animationCount:l.length}))}):this.alignVisualModelToGround()}this.dispatch("entity:model:loaded",{entityId:this.uuid,success:!!this._object,meshCount:a})}).catch(s=>{e===this._loadGeneration&&(this._loadStatus="idle",console.error("Failed to load actor model",s),this.dispatch("entity:model:loaded",{entityId:this.uuid,success:!1,meshCount:0,errorMessage:s instanceof Error?s.message:String(s)}))})}alignVisualModelToGround(){if(!this._object||!this.group)return;this._animationDelegate?.update(0),this._object.updateMatrixWorld(!0);let e=Wt(this._object,this.group);if(e===null||Math.abs(e)<Zt)return;let t=this.group.scale.y||1;this._object.position.y-=e/t}applyMaterialOverrides(){let e=this.options.material;!e||!e.color&&!e.path&&e.opacity===void 0||this._object&&this._object.traverse(t=>{if(!t.isMesh)return;let o=t;o.material=Array.isArray(o.material)?o.material.map(n=>this.tintMaterial(n,e)):this.tintMaterial(o.material,e),e.color&&(o.castShadow=!0,o.receiveShadow=!0)})}tintMaterial(e,t){let o="color"in e,n=!!t.color,s=t.opacity!==void 0;if(!n&&!s)return e;if(n&&!o)return new Ut({color:t.color,emissiveIntensity:.5,lightMapIntensity:.5,fog:!0,opacity:t.opacity??1,transparent:s&&t.opacity<1});let r=e.clone();if(n&&"color"in r&&r.color.copy(t.color),s&&"opacity"in r&&"transparent"in r){let a=r;a.opacity=t.opacity,a.transparent=t.opacity<1}return r.needsUpdate=!0,r}};function Jt(...i){return Ge({args:i,defaultConfig:Xe,EntityClass:z,BuilderClass:ae,CollisionBuilderClass:re,entityType:z.type,cloneFactory:e=>Jt(e??{})})}import{Color as li,Fog as ci,FogExp2 as ui,Group as pi}from"three";import{Color as Qt}from"three";import{Fn as nt,fog as ei,positionWorld as ot,positionView as ti,uniform as x,float as ii,vec3 as O,clamp as ce,mix as E,max as oi,smoothstep as ni,floor as si,fract as ue,dot as ri}from"three/tsl";var J=class{values;u={time:x(0),heightEnabled:x(0),heightLevel:x(0),heightFalloff:x(0),noiseEnabled:x(0),noiseScale:x(0),noiseStrength:x(0),noiseSpeed:x(0)};attachedScene=null;constructor(e){this.values={...e},this.syncUniforms()}setValues(e){Object.assign(this.values,e),this.syncUniforms()}tick(e){this.values.time+=e,this.u.time.value=this.values.time}scan(e){if(this.attachedScene===e)return;let t=e.fog;t&&(e.fogNode=this.buildFogNode(t),this.attachedScene=e)}unpatchAll(){this.attachedScene&&(this.attachedScene.fogNode=null,this.attachedScene=null)}syncUniforms(){this.u.time.value=this.values.time,this.u.heightEnabled.value=this.values.heightEnabled,this.u.heightLevel.value=this.values.heightLevel,this.u.heightFalloff.value=this.values.heightFalloff,this.u.noiseEnabled.value=this.values.noiseEnabled,this.u.noiseScale.value=this.values.noiseScale,this.u.noiseStrength.value=this.values.noiseStrength,this.u.noiseSpeed.value=this.values.noiseSpeed}buildFogNode(e){let t=e.isFogExp2===!0,o=x(new Qt(e.color)),n=ti.z.negate(),s=t?this.exp2Factor(x(e.density),n):ni(x(e.near),x(e.far),n),r=this.u.heightLevel.sub(ot.y),a=ce(r.mul(oi(this.u.heightFalloff,0)),0,1),l=E(s,s.mul(a),this.u.heightEnabled),p=ot.mul(this.u.noiseScale).add(O(this.u.time.mul(this.u.noiseSpeed),0,this.u.time.mul(this.u.noiseSpeed).mul(.5))),c=ai(p).sub(.5).mul(2).mul(ce(this.u.noiseStrength,0,1)),u=ce(l.add(l.mul(c)),0,1),m=E(l,u,this.u.noiseEnabled);return ei(o,m)}exp2Factor(e,t){return e.mul(e).mul(t).mul(t).negate().exp().oneMinus()}},A=nt(([i])=>{let e=ue(i.mul(O(443.8975,397.2973,491.1871))),t=e.add(ri(e,e.yzx.add(19.27)));return ue(t.x.add(t.y).mul(t.z))}),ai=nt(([i])=>{let e=si(i),t=ue(i),o=t.mul(t).mul(ii(3).sub(t.mul(2))),n=A(e.add(O(0,0,0))),s=A(e.add(O(1,0,0))),r=A(e.add(O(0,1,0))),a=A(e.add(O(1,1,0))),l=A(e.add(O(0,0,1))),p=A(e.add(O(1,0,1))),d=A(e.add(O(0,1,1))),c=A(e.add(O(1,1,1))),u=E(n,s,o.x),m=E(r,a,o.x),g=E(l,p,o.x),b=E(d,c,o.x),h=E(u,m,o.y),R=E(g,b,o.y);return E(h,R,o.z)});var di=Symbol("Fog"),hi="#9aa3ad",mi=.015,fi=10,yi=250,bi=5,gi=.2,Ci=.05,xi=.15,vi=.1,pe=class extends P{static type=di;threeFog=null;attachedScene=null;patcher;patcherEnabled;constructor(e={}){super(),this.options={...e};let t=this.resolveUniformValues(this.options);this.patcher=new J(t),this.patcherEnabled=Oi(this.options)}create(){return super.create(),this.threeFog=Si(this.options),this.group=new pi,this.group.name=this.name?`Fog:${this.name}`:"Fog",this}attachToScene(e){this.threeFog&&(this.attachedScene=e,e.fog=this.threeFog,this.patcherEnabled&&this.patcher.scan(e))}_update(e){super._update(e),!(!this.attachedScene||!this.patcherEnabled)&&(this.patcher.tick(e.delta),this.patcher.scan(this.attachedScene))}_cleanup(e){this.patcher.unpatchAll(),this.attachedScene&&this.attachedScene.fog===this.threeFog&&(this.attachedScene.fog=null),this.attachedScene=null,this.threeFog=null,super._cleanup(e)}resolveUniformValues(e){let t=e.height,o=e.noise;return{time:0,heightEnabled:t?.enabled?1:0,heightLevel:t?.level??bi,heightFalloff:t?.falloff??gi,noiseEnabled:o?1:0,noiseScale:o?.scale??Ci,noiseStrength:o?.strength??xi,noiseSpeed:o?.speed??vi}}};function Si(i){let e=new li(i.color??hi);return(i.type??"linear")==="exp2"?new ui(e,i.density??mi):new ci(e,i.start??fi,i.end??yi)}function Oi(i){let e=!!i.height?.enabled,t=!!i.noise;return e||t}function _n(i={}){return new pe(i)}export{C as a,S as b,lt as c,ct as d,ut as e,pt as f,dt as g,ht as h,mt as i,ft as j,Re as k,Hi as l,Yi as m,Wi as n,ke as o,N as p,eo as q,P as r,wt as s,ie as t,Ge as u,W as v,He as w,K as x,qt as y,z,Jt as A,di as B,pe as C,_n as D};
@@ -1 +1 @@
1
- import{b as d,k as v,l as V,m as y,o as D,p as S,q as B,s as b}from"./chunk-XNHVRFAK.js";import{c as k}from"./chunk-CM5YRNBJ.js";import{c as h,d as _,h as u,i as T,j as C}from"./chunk-7WRQ2UAN.js";import{Color as $,Group as nt,Sprite as st,SpriteMaterial as rt,CanvasTexture as U,LinearFilter as E,Vector2 as ot,ClampToEdgeWrapping as H}from"three";import{MeshStandardMaterial as K,MeshBasicMaterial as tt,MeshPhongMaterial as et}from"three";function it(i){return i&&typeof i.getDebugInfo=="function"}var c=class{entity;constructor(t){this.entity=t}getPositionString(){if(this.entity.mesh){let{x:r,y:s,z:o}=this.entity.mesh.position;return`${r.toFixed(2)}, ${s.toFixed(2)}, ${o.toFixed(2)}`}let{x:t,y:e,z:n}=this.entity.options.position||{x:0,y:0,z:0};return`${t.toFixed(2)}, ${e.toFixed(2)}, ${n.toFixed(2)}`}getRotationString(){if(this.entity.mesh){let{x:s,y:o,z:a}=this.entity.mesh.rotation,p=l=>(l*180/Math.PI).toFixed(1);return`${p(s)}\xB0, ${p(o)}\xB0, ${p(a)}\xB0`}let{x:t,y:e,z:n}=this.entity.options.rotation||{x:0,y:0,z:0},r=s=>(s*180/Math.PI).toFixed(1);return`${r(t)}\xB0, ${r(e)}\xB0, ${r(n)}\xB0`}getMaterialInfo(){if(!this.entity.mesh||!this.entity.mesh.material)return{type:"none"};let t=Array.isArray(this.entity.mesh.material)?this.entity.mesh.material[0]:this.entity.mesh.material,e={type:t.type};return(t instanceof K||t instanceof tt||t instanceof et)&&(e.color=`#${t.color.getHexString()}`,e.opacity=t.opacity,e.transparent=t.transparent),"roughness"in t&&(e.roughness=t.roughness),"metalness"in t&&(e.metalness=t.metalness),e}getPhysicsInfo(){if(!this.entity.body)return null;let t={type:this.entity.body.bodyType(),mass:this.entity.body.mass(),isEnabled:this.entity.body.isEnabled(),isSleeping:this.entity.body.isSleeping()},e=this.entity.body.linvel();return t.velocity=`${e.x.toFixed(2)}, ${e.y.toFixed(2)}, ${e.z.toFixed(2)}`,t}buildDebugInfo(){let t={name:this.entity.name||this.entity.uuid,uuid:this.entity.uuid,position:this.getPositionString(),rotation:this.getRotationString(),material:this.getMaterialInfo()},e=this.getPhysicsInfo();if(e&&(t.physics=e),it(this.entity)){let n=this.entity.getDebugInfo();return{...t,...n}}return t}};var f={position:void 0,text:"",fontFamily:'Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',fontSize:18,fontColor:"#FFFFFF",backgroundColor:null,padding:4,stickToViewport:!0,screenPosition:new ot(24,24),zDistance:1},O=class extends b{createEntity(t){return new g(t)}},at=Symbol("Text"),g=class i extends y{static type=at;_sprite=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=d(f,t),this.options.screenPosition=T(this.options.screenPosition,f.screenPosition),this.prependSetup(this.textSetup.bind(this)),this.prependUpdate(this.textUpdate.bind(this)),this.onCleanup(this.textDestroy.bind(this))}create(){return this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._lastCanvasW=0,this._lastCanvasH=0,this.group=new nt,this.createSprite(),super.create()}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new U(this._canvas),this._texture.minFilter=E,this._texture.magFilter=E;let t=new rt({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new st(t),this.group?.add(this._sprite),this.redrawText(this.options.text??"")}measureAndResizeCanvas(t,e,n,r){if(!this._canvas||!this._ctx)return{sizeChanged:!1};this._ctx.font=`${e}px ${n}`;let s=this._ctx.measureText(t),o=Math.ceil(s.width),a=Math.ceil(e*1.4),p=Math.max(2,o+r*2),l=Math.max(2,a+r*2),w=p!==this._lastCanvasW||l!==this._lastCanvasH;return this._canvas.width=p,this._canvas.height=l,this._lastCanvasW=p,this._lastCanvasH=l,{sizeChanged:w}}drawCenteredText(t,e,n){!this._canvas||!this._ctx||(this._ctx.font=`${e}px ${n}`,this._ctx.textAlign="center",this._ctx.textBaseline="middle",this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this.options.backgroundColor&&(this._ctx.fillStyle=this.toCssColor(this.options.backgroundColor),this._ctx.fillRect(0,0,this._canvas.width,this._canvas.height)),this._ctx.fillStyle=this.toCssColor(this.options.fontColor??"#FFFFFF"),this._ctx.fillText(t,this._canvas.width/2,this._canvas.height/2))}updateTexture(t){!this._texture||!this._canvas||(t&&(this._texture.dispose(),this._texture=new U(this._canvas),this._texture.minFilter=E,this._texture.magFilter=E,this._texture.wrapS=H,this._texture.wrapT=H),this._texture.image=this._canvas,this._texture.needsUpdate=!0,this._sprite&&this._sprite.material&&(this._sprite.material.map=this._texture,this._sprite.material.needsUpdate=!0))}redrawText(t){if(!this._canvas||!this._ctx)return;let e=this.options.fontSize??18,n=this.options.fontFamily??f.fontFamily,r=this.options.padding??4,{sizeChanged:s}=this.measureAndResizeCanvas(t,e,n,r);this.drawCenteredText(t,e,n),this.updateTexture(!!s),this.options.stickToViewport&&this._cameraRef?this.updateStickyTransform():this.updateWorldSpriteScale()}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof $?t:new $(t)).getHexString()}`}textSetup(t){this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&(this._cameraRef.camera.add(this.group),this.updateStickyTransform())}textUpdate(t){this._sprite&&this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}getResolution(){return{width:this._cameraRef?.screenResolution.x??1,height:this._cameraRef?.screenResolution.y??1}}getScreenPixels(t,e,n){let r=t.x>=0&&t.x<=1,s=t.y>=0&&t.y<=1;return{px:r?t.x*e:t.x,py:s?t.y*n:t.y}}computeWorldExtents(t,e){let n=1,r=1;if(t.isPerspectiveCamera){let s=t,o=Math.tan(s.fov*Math.PI/180/2)*e;n=o*s.aspect,r=o}else if(t.isOrthographicCamera){let s=t;n=(s.right-s.left)/2,r=(s.top-s.bottom)/2}return{worldHalfW:n,worldHalfH:r}}updateSpriteScale(t,e){if(!this._canvas||!this._sprite)return;let r=t*2/e,s=this._canvas.height,o=Math.max(1e-4,s*r),a=this._canvas.width/this._canvas.height,p=o*a;this._sprite.scale.set(p,o,1)}updateWorldSpriteScale(){if(!this._canvas||!this._sprite)return;let t=this._canvas.width/Math.max(1,this._canvas.height),e=Math.max(1,this.options.fontSize??18),n=Math.max(.25,e/32),r=n*t;this._sprite.scale.set(r,n,1)}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:n}=this.getResolution(),r=T(this.options.screenPosition,f.screenPosition),{px:s,py:o}=this.getScreenPixels(r,e,n),a=Math.max(.001,this.options.zDistance??1),{worldHalfW:p,worldHalfH:l}=this.computeWorldExtents(t,a),w=s/e*2-1,Q=1-o/n*2,q=w*p,J=Q*l;this.group?.position.set(q,J,-a),this.updateSpriteScale(l,n)}updateText(t){this.options.text=t,this.redrawText(t),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type),text:this.options.text??"",sticky:this.options.stickToViewport}}textDestroy(){this._texture?.dispose(),this._sprite?.material&&this._sprite.material.dispose(),this._sprite&&this._sprite.removeFromParent(),this.group?.removeFromParent(),this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._cameraRef=null}};function I(...i){return S({args:i,defaultConfig:{...f},EntityClass:g,BuilderClass:O,entityType:g.type,cloneFactory:t=>I(t??{})})}import{Euler as pt,Group as lt,Quaternion as ct,Vector3 as mt}from"three";import{TextureLoader as ht,SpriteMaterial as ut,Sprite as dt,SRGBColorSpace as yt}from"three";var W={...v,size:new mt(1,1,1),images:[],animations:[]},R=class extends B{collider(t){let e=C(t.collisionSize,t.size??_);return{shape:{type:"box",halfExtents:[e.x/2,e.y/2,e.z/2]}}}},F=class extends b{createEntity(t){return new x(t)}},ft=Symbol("Sprite"),x=class i extends y{static type=ft;sprites=[];spriteMap=new Map;currentSpriteIndex=0;animations=new Map;currentAnimation=null;currentAnimationFrame="";currentAnimationIndex=0;currentAnimationTime=0;constructor(t){super(),this.options=d(W,t),this.prependSetup(this.spriteSetup.bind(this)),this.prependUpdate(this.spriteUpdate.bind(this)),this.onCleanup(this.spriteDestroy.bind(this))}create(){return this.sprites=[],this.spriteMap.clear(),this.animations.clear(),this.currentAnimation=null,this.currentAnimationFrame="",this.currentAnimationIndex=0,this.currentAnimationTime=0,this.group=void 0,this.createSpritesFromImages(this.options?.images||[]),this.createAnimations(this.options?.animations||[]),super.create()}createSpritesFromImages(t){let e=new ht,n=C(this.options.size,_);t.forEach((r,s)=>{let o=e.load(r.file);o.colorSpace=yt,o.anisotropy=k;let a=new ut({map:o,transparent:!0}),p=new dt(a);p.position.normalize(),p.scale.set(n.x,n.y,n.z),p.visible=s===0,this.sprites.push(p),this.spriteMap.set(r.name,s)}),this.group=new lt,this.group.add(...this.sprites)}createAnimations(t){t.forEach(e=>{let{name:n,frames:r,loop:s=!1,speed:o=1}=e,a={frames:r.map((p,l)=>({key:p,index:l,time:(typeof o=="number"?o:o[l])*(l+1),duration:typeof o=="number"?o:o[l]})),loop:s};this.animations.set(n,a)})}setSprite(t){let n=this.spriteMap.get(t)??0;this.currentSpriteIndex=n,this.sprites.forEach((r,s)=>{r.visible=this.currentSpriteIndex===s})}setAnimation(t,e){let n=this.animations.get(t);if(!n)return;let{loop:r,frames:s}=n,o=s[this.currentAnimationIndex];t===this.currentAnimation?(this.currentAnimationFrame=o.key,this.currentAnimationTime+=e,this.setSprite(this.currentAnimationFrame)):this.currentAnimation=t,this.currentAnimationTime>o.time&&this.currentAnimationIndex++,this.currentAnimationIndex>=s.length&&(r?(this.currentAnimationIndex=0,this.currentAnimationTime=0):this.currentAnimationTime=s[this.currentAnimationIndex].time)}getCurrentRotationQuaternion(){return this.transformStore?.dirty.rotation?this.transformStore.rotation:this.body?.rotation?.()??null}syncSpriteMaterials(){let t=this.getCurrentRotationQuaternion();this.sprites.forEach(e=>{if(e.material&&t){let r=new ct(t.x,t.y,t.z,t.w),s=new pt().setFromQuaternion(r,"XYZ");e.material.rotation=s.z}let n=C(this.options.size,_);e.scale.set(n.x,n.y,n.z)})}spriteSetup(t){this.syncSpriteMaterials()}spriteUpdate(t){this.syncSpriteMaterials()}spriteDestroy(t){this.sprites.forEach(e=>{e.removeFromParent()}),this.group?.remove(...this.sprites),this.group?.removeFromParent()}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type)}}};function P(...i){return S({args:i,defaultConfig:W,EntityClass:x,BuilderClass:F,CollisionBuilderClass:R,entityType:x.type,cloneFactory:t=>P(t??{})})}import{Color as X,Group as xt}from"three";import{Line2NodeMaterial as _t}from"three/webgpu";import{Line2 as Ct}from"three/addons/lines/webgpu/Line2.js";import{Color as N}from"three";import{LineGeometry as gt}from"three/addons/lines/LineGeometry.js";function z(i){let t=[];for(let e of i){let{x:n,y:r,z:s}=u(e,h);t.push(n,r,s)}return t}function L(i,t,e){if(!i||i.length===0)return;let n=[],r=new N(e);for(let s=0;s<t;s++){let o=i[s]??i[i.length-1]??e,a=new N(o??r);n.push(a.r,a.g,a.b)}return n}function Y(i){let t=new gt,e=z(i.points);t.setPositions(e);let n=L(i.colors,i.points.length,"#ffffff");return n&&t.setColors(n),t}var m={...v,points:[{x:0,y:0,z:0},{x:1,y:0,z:0}],linewidth:1,worldUnits:!0,alphaToCoverage:!1,opacity:1,transparent:!1,dashed:!1,dashSize:1,gapSize:1,pickThreshold:0},vt=Symbol("Line");function M(i,t){if(!i||i.length<2)throw new Error(`${t}: at least two points are required`);return i}function j(i){return i instanceof X?i.clone():new X(i??"#ffffff")}function St(i){let t=!!i.colors?.length,e=new _t({color:j(i.color).getHex(),linewidth:i.linewidth??m.linewidth,worldUnits:i.worldUnits??m.worldUnits,vertexColors:t,dashed:i.dashed??!1,dashSize:i.dashSize??m.dashSize,gapSize:i.gapSize??m.gapSize,transparent:i.transparent??!1,opacity:i.opacity??1});return e.alphaToCoverage=i.alphaToCoverage??!1,e}function bt(i){return!i.point||!i.pointOnLine||i.faceIndex==null?null:{point:i.point.clone(),pointOnLine:i.pointOnLine.clone(),faceIndex:i.faceIndex,distance:i.distance}}function Et(i,t,e={}){let n=t.getLineObject();if(!n)return null;let r=e.threshold??t.options.pickThreshold??0,s=i.params.Line2??{threshold:0};s.threshold=r,i.params.Line2=s;let a=i.intersectObject(n,!1)[0];return a?bt(a):null}var Z=class i extends y{static type=vt;_line=null;_geometry=null;_material=null;constructor(t){super();let e=d(m,t);e.points=M(e.points,"ZylemLine").map(n=>u(n,h)),this.options=e}create(){return this.disposeLineResources(),this.group=new xt,this.rebuildLine(),this.applyGroupPosition(),super.create()}setPoints(t,e){if(M(t,"setPoints"),this.options.points=t.map(r=>u(r,h)),e&&(this.options.colors=e),!this._line||!this._geometry||!this._material)return this;this._geometry.setPositions(z(this.options.points));let n=L(this.options.colors,this.options.points.length,j(this.options.color));return n&&this._geometry.setColors(n),this._material.vertexColors=!!this.options.colors?.length,this.options.dashed&&this._line.computeLineDistances(),this._geometry.computeBoundingBox(),this._geometry.computeBoundingSphere(),this}getLineObject(){return this._line}pickFromRaycaster(t,e={}){return Et(t,this,e)}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type),points:this.options.points.length,linewidth:this.options.linewidth??m.linewidth,worldUnits:this.options.worldUnits??m.worldUnits}}rebuildLine(){this._geometry=Y({points:this.options.points,colors:this.options.colors}),this._material=St(this.options),this._line=new Ct(this._geometry,this._material),this.options.dashed&&this._line.computeLineDistances(),this.group?.add(this._line)}applyGroupPosition(){if(!this.group)return;let t=u(this.options.position,h);this.group.position.set(t.x,t.y,t.z)}_cleanup(t){this.disposeLineResources(),super._cleanup(t)}disposeLineResources(){this._line?.removeFromParent(),this._geometry?.dispose(),this._material?.dispose(),this._line=null,this._geometry=null,this._material=null}};function G(...i){let t=V(i,m);M(t.points,"createLine");let e=new Z(t);return D(e,n=>G(n??{}))}var A={registry:new Map,register(i,t){this.registry.set(i,t)},createFromBlueprint(i){let t=this.registry.get(i.type);if(!t)throw new Error(`Unknown entity type: ${i.type}`);let e={...i.data,position:i.position?{x:i.position[0],y:i.position[1],z:0}:void 0,name:i.id};return t(e)}};A.register("text",i=>I(i));A.register("sprite",i=>P(i));A.register("line",i=>G(i));function Ce(i){return{template:i,generate(t){let e=[];for(let n=0;n<t;n++)e.push(i.clone());return e}}}export{c as a,at as b,g as c,I as d,ft as e,x as f,P as g,vt as h,Et as i,Z as j,G as k,A as l,Ce as m};
1
+ import{b as d,p as v,q as V,r as y,t as D,u as S,v as B,x as b}from"./chunk-KVSJE4XD.js";import{c as k}from"./chunk-CM5YRNBJ.js";import{c as h,d as _,h as u,i as T,j as C}from"./chunk-7WRQ2UAN.js";import{Color as $,Group as nt,Sprite as st,SpriteMaterial as rt,CanvasTexture as U,LinearFilter as E,Vector2 as ot,ClampToEdgeWrapping as H}from"three";import{MeshStandardMaterial as K,MeshBasicMaterial as tt,MeshPhongMaterial as et}from"three";function it(i){return i&&typeof i.getDebugInfo=="function"}var c=class{entity;constructor(t){this.entity=t}getPositionString(){if(this.entity.mesh){let{x:r,y:s,z:o}=this.entity.mesh.position;return`${r.toFixed(2)}, ${s.toFixed(2)}, ${o.toFixed(2)}`}let{x:t,y:e,z:n}=this.entity.options.position||{x:0,y:0,z:0};return`${t.toFixed(2)}, ${e.toFixed(2)}, ${n.toFixed(2)}`}getRotationString(){if(this.entity.mesh){let{x:s,y:o,z:a}=this.entity.mesh.rotation,p=l=>(l*180/Math.PI).toFixed(1);return`${p(s)}\xB0, ${p(o)}\xB0, ${p(a)}\xB0`}let{x:t,y:e,z:n}=this.entity.options.rotation||{x:0,y:0,z:0},r=s=>(s*180/Math.PI).toFixed(1);return`${r(t)}\xB0, ${r(e)}\xB0, ${r(n)}\xB0`}getMaterialInfo(){if(!this.entity.mesh||!this.entity.mesh.material)return{type:"none"};let t=Array.isArray(this.entity.mesh.material)?this.entity.mesh.material[0]:this.entity.mesh.material,e={type:t.type};return(t instanceof K||t instanceof tt||t instanceof et)&&(e.color=`#${t.color.getHexString()}`,e.opacity=t.opacity,e.transparent=t.transparent),"roughness"in t&&(e.roughness=t.roughness),"metalness"in t&&(e.metalness=t.metalness),e}getPhysicsInfo(){if(!this.entity.body)return null;let t={type:this.entity.body.bodyType(),mass:this.entity.body.mass(),isEnabled:this.entity.body.isEnabled(),isSleeping:this.entity.body.isSleeping()},e=this.entity.body.linvel();return t.velocity=`${e.x.toFixed(2)}, ${e.y.toFixed(2)}, ${e.z.toFixed(2)}`,t}buildDebugInfo(){let t={name:this.entity.name||this.entity.uuid,uuid:this.entity.uuid,position:this.getPositionString(),rotation:this.getRotationString(),material:this.getMaterialInfo()},e=this.getPhysicsInfo();if(e&&(t.physics=e),it(this.entity)){let n=this.entity.getDebugInfo();return{...t,...n}}return t}};var f={position:void 0,text:"",fontFamily:'Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',fontSize:18,fontColor:"#FFFFFF",backgroundColor:null,padding:4,stickToViewport:!0,screenPosition:new ot(24,24),zDistance:1},O=class extends b{createEntity(t){return new g(t)}},at=Symbol("Text"),g=class i extends y{static type=at;_sprite=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=d(f,t),this.options.screenPosition=T(this.options.screenPosition,f.screenPosition),this.prependSetup(this.textSetup.bind(this)),this.prependUpdate(this.textUpdate.bind(this)),this.onCleanup(this.textDestroy.bind(this))}create(){return this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._lastCanvasW=0,this._lastCanvasH=0,this.group=new nt,this.createSprite(),super.create()}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new U(this._canvas),this._texture.minFilter=E,this._texture.magFilter=E;let t=new rt({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new st(t),this.group?.add(this._sprite),this.redrawText(this.options.text??"")}measureAndResizeCanvas(t,e,n,r){if(!this._canvas||!this._ctx)return{sizeChanged:!1};this._ctx.font=`${e}px ${n}`;let s=this._ctx.measureText(t),o=Math.ceil(s.width),a=Math.ceil(e*1.4),p=Math.max(2,o+r*2),l=Math.max(2,a+r*2),w=p!==this._lastCanvasW||l!==this._lastCanvasH;return this._canvas.width=p,this._canvas.height=l,this._lastCanvasW=p,this._lastCanvasH=l,{sizeChanged:w}}drawCenteredText(t,e,n){!this._canvas||!this._ctx||(this._ctx.font=`${e}px ${n}`,this._ctx.textAlign="center",this._ctx.textBaseline="middle",this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height),this.options.backgroundColor&&(this._ctx.fillStyle=this.toCssColor(this.options.backgroundColor),this._ctx.fillRect(0,0,this._canvas.width,this._canvas.height)),this._ctx.fillStyle=this.toCssColor(this.options.fontColor??"#FFFFFF"),this._ctx.fillText(t,this._canvas.width/2,this._canvas.height/2))}updateTexture(t){!this._texture||!this._canvas||(t&&(this._texture.dispose(),this._texture=new U(this._canvas),this._texture.minFilter=E,this._texture.magFilter=E,this._texture.wrapS=H,this._texture.wrapT=H),this._texture.image=this._canvas,this._texture.needsUpdate=!0,this._sprite&&this._sprite.material&&(this._sprite.material.map=this._texture,this._sprite.material.needsUpdate=!0))}redrawText(t){if(!this._canvas||!this._ctx)return;let e=this.options.fontSize??18,n=this.options.fontFamily??f.fontFamily,r=this.options.padding??4,{sizeChanged:s}=this.measureAndResizeCanvas(t,e,n,r);this.drawCenteredText(t,e,n),this.updateTexture(!!s),this.options.stickToViewport&&this._cameraRef?this.updateStickyTransform():this.updateWorldSpriteScale()}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof $?t:new $(t)).getHexString()}`}textSetup(t){this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&(this._cameraRef.camera.add(this.group),this.updateStickyTransform())}textUpdate(t){this._sprite&&this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}getResolution(){return{width:this._cameraRef?.screenResolution.x??1,height:this._cameraRef?.screenResolution.y??1}}getScreenPixels(t,e,n){let r=t.x>=0&&t.x<=1,s=t.y>=0&&t.y<=1;return{px:r?t.x*e:t.x,py:s?t.y*n:t.y}}computeWorldExtents(t,e){let n=1,r=1;if(t.isPerspectiveCamera){let s=t,o=Math.tan(s.fov*Math.PI/180/2)*e;n=o*s.aspect,r=o}else if(t.isOrthographicCamera){let s=t;n=(s.right-s.left)/2,r=(s.top-s.bottom)/2}return{worldHalfW:n,worldHalfH:r}}updateSpriteScale(t,e){if(!this._canvas||!this._sprite)return;let r=t*2/e,s=this._canvas.height,o=Math.max(1e-4,s*r),a=this._canvas.width/this._canvas.height,p=o*a;this._sprite.scale.set(p,o,1)}updateWorldSpriteScale(){if(!this._canvas||!this._sprite)return;let t=this._canvas.width/Math.max(1,this._canvas.height),e=Math.max(1,this.options.fontSize??18),n=Math.max(.25,e/32),r=n*t;this._sprite.scale.set(r,n,1)}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:e,height:n}=this.getResolution(),r=T(this.options.screenPosition,f.screenPosition),{px:s,py:o}=this.getScreenPixels(r,e,n),a=Math.max(.001,this.options.zDistance??1),{worldHalfW:p,worldHalfH:l}=this.computeWorldExtents(t,a),w=s/e*2-1,Q=1-o/n*2,q=w*p,J=Q*l;this.group?.position.set(q,J,-a),this.updateSpriteScale(l,n)}updateText(t){this.options.text=t,this.redrawText(t),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type),text:this.options.text??"",sticky:this.options.stickToViewport}}textDestroy(){this._texture?.dispose(),this._sprite?.material&&this._sprite.material.dispose(),this._sprite&&this._sprite.removeFromParent(),this.group?.removeFromParent(),this._sprite=null,this._texture=null,this._canvas=null,this._ctx=null,this._cameraRef=null}};function I(...i){return S({args:i,defaultConfig:{...f},EntityClass:g,BuilderClass:O,entityType:g.type,cloneFactory:t=>I(t??{})})}import{Euler as pt,Group as lt,Quaternion as ct,Vector3 as mt}from"three";import{TextureLoader as ht,SpriteMaterial as ut,Sprite as dt,SRGBColorSpace as yt}from"three";var W={...v,size:new mt(1,1,1),images:[],animations:[]},R=class extends B{collider(t){let e=C(t.collisionSize,t.size??_);return{shape:{type:"box",halfExtents:[e.x/2,e.y/2,e.z/2]}}}},F=class extends b{createEntity(t){return new x(t)}},ft=Symbol("Sprite"),x=class i extends y{static type=ft;sprites=[];spriteMap=new Map;currentSpriteIndex=0;animations=new Map;currentAnimation=null;currentAnimationFrame="";currentAnimationIndex=0;currentAnimationTime=0;constructor(t){super(),this.options=d(W,t),this.prependSetup(this.spriteSetup.bind(this)),this.prependUpdate(this.spriteUpdate.bind(this)),this.onCleanup(this.spriteDestroy.bind(this))}create(){return this.sprites=[],this.spriteMap.clear(),this.animations.clear(),this.currentAnimation=null,this.currentAnimationFrame="",this.currentAnimationIndex=0,this.currentAnimationTime=0,this.group=void 0,this.createSpritesFromImages(this.options?.images||[]),this.createAnimations(this.options?.animations||[]),super.create()}createSpritesFromImages(t){let e=new ht,n=C(this.options.size,_);t.forEach((r,s)=>{let o=e.load(r.file);o.colorSpace=yt,o.anisotropy=k;let a=new ut({map:o,transparent:!0}),p=new dt(a);p.position.normalize(),p.scale.set(n.x,n.y,n.z),p.visible=s===0,this.sprites.push(p),this.spriteMap.set(r.name,s)}),this.group=new lt,this.group.add(...this.sprites)}createAnimations(t){t.forEach(e=>{let{name:n,frames:r,loop:s=!1,speed:o=1}=e,a={frames:r.map((p,l)=>({key:p,index:l,time:(typeof o=="number"?o:o[l])*(l+1),duration:typeof o=="number"?o:o[l]})),loop:s};this.animations.set(n,a)})}setSprite(t){let n=this.spriteMap.get(t)??0;this.currentSpriteIndex=n,this.sprites.forEach((r,s)=>{r.visible=this.currentSpriteIndex===s})}setAnimation(t,e){let n=this.animations.get(t);if(!n)return;let{loop:r,frames:s}=n,o=s[this.currentAnimationIndex];t===this.currentAnimation?(this.currentAnimationFrame=o.key,this.currentAnimationTime+=e,this.setSprite(this.currentAnimationFrame)):this.currentAnimation=t,this.currentAnimationTime>o.time&&this.currentAnimationIndex++,this.currentAnimationIndex>=s.length&&(r?(this.currentAnimationIndex=0,this.currentAnimationTime=0):this.currentAnimationTime=s[this.currentAnimationIndex].time)}getCurrentRotationQuaternion(){return this.transformStore?.dirty.rotation?this.transformStore.rotation:this.body?.rotation?.()??null}syncSpriteMaterials(){let t=this.getCurrentRotationQuaternion();this.sprites.forEach(e=>{if(e.material&&t){let r=new ct(t.x,t.y,t.z,t.w),s=new pt().setFromQuaternion(r,"XYZ");e.material.rotation=s.z}let n=C(this.options.size,_);e.scale.set(n.x,n.y,n.z)})}spriteSetup(t){this.syncSpriteMaterials()}spriteUpdate(t){this.syncSpriteMaterials()}spriteDestroy(t){this.sprites.forEach(e=>{e.removeFromParent()}),this.group?.remove(...this.sprites),this.group?.removeFromParent()}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type)}}};function P(...i){return S({args:i,defaultConfig:W,EntityClass:x,BuilderClass:F,CollisionBuilderClass:R,entityType:x.type,cloneFactory:t=>P(t??{})})}import{Color as X,Group as xt}from"three";import{Line2NodeMaterial as _t}from"three/webgpu";import{Line2 as Ct}from"three/addons/lines/webgpu/Line2.js";import{Color as N}from"three";import{LineGeometry as gt}from"three/addons/lines/LineGeometry.js";function z(i){let t=[];for(let e of i){let{x:n,y:r,z:s}=u(e,h);t.push(n,r,s)}return t}function L(i,t,e){if(!i||i.length===0)return;let n=[],r=new N(e);for(let s=0;s<t;s++){let o=i[s]??i[i.length-1]??e,a=new N(o??r);n.push(a.r,a.g,a.b)}return n}function Y(i){let t=new gt,e=z(i.points);t.setPositions(e);let n=L(i.colors,i.points.length,"#ffffff");return n&&t.setColors(n),t}var m={...v,points:[{x:0,y:0,z:0},{x:1,y:0,z:0}],linewidth:1,worldUnits:!0,alphaToCoverage:!1,opacity:1,transparent:!1,dashed:!1,dashSize:1,gapSize:1,pickThreshold:0},vt=Symbol("Line");function M(i,t){if(!i||i.length<2)throw new Error(`${t}: at least two points are required`);return i}function j(i){return i instanceof X?i.clone():new X(i??"#ffffff")}function St(i){let t=!!i.colors?.length,e=new _t({color:j(i.color).getHex(),linewidth:i.linewidth??m.linewidth,worldUnits:i.worldUnits??m.worldUnits,vertexColors:t,dashed:i.dashed??!1,dashSize:i.dashSize??m.dashSize,gapSize:i.gapSize??m.gapSize,transparent:i.transparent??!1,opacity:i.opacity??1});return e.alphaToCoverage=i.alphaToCoverage??!1,e}function bt(i){return!i.point||!i.pointOnLine||i.faceIndex==null?null:{point:i.point.clone(),pointOnLine:i.pointOnLine.clone(),faceIndex:i.faceIndex,distance:i.distance}}function Et(i,t,e={}){let n=t.getLineObject();if(!n)return null;let r=e.threshold??t.options.pickThreshold??0,s=i.params.Line2??{threshold:0};s.threshold=r,i.params.Line2=s;let a=i.intersectObject(n,!1)[0];return a?bt(a):null}var Z=class i extends y{static type=vt;_line=null;_geometry=null;_material=null;constructor(t){super();let e=d(m,t);e.points=M(e.points,"ZylemLine").map(n=>u(n,h)),this.options=e}create(){return this.disposeLineResources(),this.group=new xt,this.rebuildLine(),this.applyGroupPosition(),super.create()}setPoints(t,e){if(M(t,"setPoints"),this.options.points=t.map(r=>u(r,h)),e&&(this.options.colors=e),!this._line||!this._geometry||!this._material)return this;this._geometry.setPositions(z(this.options.points));let n=L(this.options.colors,this.options.points.length,j(this.options.color));return n&&this._geometry.setColors(n),this._material.vertexColors=!!this.options.colors?.length,this.options.dashed&&this._line.computeLineDistances(),this._geometry.computeBoundingBox(),this._geometry.computeBoundingSphere(),this}getLineObject(){return this._line}pickFromRaycaster(t,e={}){return Et(t,this,e)}buildInfo(){return{...new c(this).buildDebugInfo(),type:String(i.type),points:this.options.points.length,linewidth:this.options.linewidth??m.linewidth,worldUnits:this.options.worldUnits??m.worldUnits}}rebuildLine(){this._geometry=Y({points:this.options.points,colors:this.options.colors}),this._material=St(this.options),this._line=new Ct(this._geometry,this._material),this.options.dashed&&this._line.computeLineDistances(),this.group?.add(this._line)}applyGroupPosition(){if(!this.group)return;let t=u(this.options.position,h);this.group.position.set(t.x,t.y,t.z)}_cleanup(t){this.disposeLineResources(),super._cleanup(t)}disposeLineResources(){this._line?.removeFromParent(),this._geometry?.dispose(),this._material?.dispose(),this._line=null,this._geometry=null,this._material=null}};function G(...i){let t=V(i,m);M(t.points,"createLine");let e=new Z(t);return D(e,n=>G(n??{}))}var A={registry:new Map,register(i,t){this.registry.set(i,t)},createFromBlueprint(i){let t=this.registry.get(i.type);if(!t)throw new Error(`Unknown entity type: ${i.type}`);let e={...i.data,position:i.position?{x:i.position[0],y:i.position[1],z:0}:void 0,name:i.id};return t(e)}};A.register("text",i=>I(i));A.register("sprite",i=>P(i));A.register("line",i=>G(i));function Ce(i){return{template:i,generate(t){let e=[];for(let n=0;n<t;n++)e.push(i.clone());return e}}}export{c as a,at as b,g as c,I as d,ft as e,x as f,P as g,vt as h,Et as i,Z as j,G as k,A as l,Ce as m};
@@ -1,4 +1,4 @@
1
- import{j as y}from"./chunk-MSC2BEO5.js";var r={baseFill:"rgba(12,18,24,0.72)",joystickStroke:"rgba(245,247,255,0.72)",joystickInnerStroke:"rgba(255,255,255,0.18)",joystickAccentFill:"rgba(255,255,255,0.04)",joystickTabFill:"rgba(245,247,255,0.45)",thumbFill:"rgba(22,30,38,0.92)",thumbStroke:"rgba(245,247,255,0.85)",thumbInnerFill:"rgba(255,255,255,0.08)",defaultButtonAccent:"rgba(245,247,255,0.92)"},b={baseFill:"rgba(8,14,24,0.70)",joystickStroke:"rgba(207,250,254,0.85)",joystickInnerStroke:"rgba(45,212,191,0.35)",joystickAccentFill:"rgba(20,184,166,0.08)",joystickTabFill:"rgba(207,250,254,0.55)",thumbFill:"rgba(13,148,136,0.88)",thumbStroke:"rgba(240,253,250,0.95)",thumbInnerFill:"rgba(240,253,250,0.16)",defaultButtonAccent:"#67e8f9",buttonAccents:{A:"#8b5cf6",B:"#fb7185",X:"#22d3ee",Y:"#facc15"}},m={default:r,lagoon:b};function l(e){return e?typeof e=="string"?m[e]??r:e:r}function f(e,t,o){return o||(e.buttonAccents?.[t]??e.defaultButtonAccent)}function h(e){let t=l(e);return`
1
+ import{k as y}from"./chunk-UG22Z42P.js";var r={baseFill:"rgba(12,18,24,0.72)",joystickStroke:"rgba(245,247,255,0.72)",joystickInnerStroke:"rgba(255,255,255,0.18)",joystickAccentFill:"rgba(255,255,255,0.04)",joystickTabFill:"rgba(245,247,255,0.45)",thumbFill:"rgba(22,30,38,0.92)",thumbStroke:"rgba(245,247,255,0.85)",thumbInnerFill:"rgba(255,255,255,0.08)",defaultButtonAccent:"rgba(245,247,255,0.92)"},b={baseFill:"rgba(8,14,24,0.70)",joystickStroke:"rgba(207,250,254,0.85)",joystickInnerStroke:"rgba(45,212,191,0.35)",joystickAccentFill:"rgba(20,184,166,0.08)",joystickTabFill:"rgba(207,250,254,0.55)",thumbFill:"rgba(13,148,136,0.88)",thumbStroke:"rgba(240,253,250,0.95)",thumbInnerFill:"rgba(240,253,250,0.16)",defaultButtonAccent:"#67e8f9",buttonAccents:{A:"#8b5cf6",B:"#fb7185",X:"#22d3ee",Y:"#facc15"}},m={default:r,lagoon:b};function l(e){return e?typeof e=="string"?m[e]??r:e:r}function f(e,t,o){return o||(e.buttonAccents?.[t]??e.defaultButtonAccent)}function h(e){let t=l(e);return`
2
2
  <svg viewBox="0 0 140 140" width="100%" height="100%" aria-hidden="true">
3
3
  <circle cx="70" cy="70" r="62" fill="${t.baseFill}" stroke="${t.joystickStroke}" stroke-width="4" />
4
4
  <circle cx="70" cy="70" r="42" fill="${t.joystickAccentFill}" stroke="${t.joystickInnerStroke}" stroke-width="2" />
@@ -0,0 +1 @@
1
+ function r(n,e){return{[n]:{key:e}}}function V(n){return r(n,{ArrowLeft:["axes.Left"],ArrowRight:["axes.Right"],ArrowUp:["axes.Up"],ArrowDown:["axes.Down"]})}function x(n){return r(n,{ArrowLeft:["axes.SecondaryLeft"],ArrowRight:["axes.SecondaryRight"],ArrowUp:["axes.SecondaryUp"],ArrowDown:["axes.SecondaryDown"]})}function w(n){return r(n,{ArrowLeft:["directions.Left"],ArrowRight:["directions.Right"],ArrowUp:["directions.Up"],ArrowDown:["directions.Down"]})}function G(n){return r(n,{w:["directions.Up"],s:["directions.Down"],a:["directions.Left"],d:["directions.Right"]})}function A(n){return r(n,{a:["axes.Left"],d:["axes.Right"],w:["axes.Up"],s:["axes.Down"]})}function D(n){return r(n,{j:["axes.Left"],l:["axes.Right"],i:["axes.Up"],k:["axes.Down"]})}function J(n){return r(n,{j:["directions.Left"],l:["directions.Right"],i:["directions.Up"],k:["directions.Down"]})}function L(n,e){return{[n]:{mouse:{pointerLock:!0,lookMode:"delta",sensitivity:e?.sensitivity}}}}function b(n,e){return{[n]:{mouse:{pointerLock:!1,lookMode:"screenCenter",maxLookDegrees:e?.maxLookDegrees??45,lookSensitivity:e?.lookSensitivity}}}}function B(n,e){return{[n]:{mouse:{pointerLock:!1,sensitivity:e?.sensitivity}}}}function P(n,e){return{[n]:{touch:{enabled:e?.enabled??"auto",...e}}}}var h=["p1","p2","p3","p4","p5","p6","p7","p8"];function v(...n){let e={};for(let u of n)for(let o of h){let s=u[o];if(!s)continue;let t=e[o]??{},f=t.mouse||s.mouse?{...t.mouse,...s.mouse,mapping:{...t.mouse?.mapping,...s.mouse?.mapping}}:void 0,a=m(t.touch,s.touch);e[o]={key:{...t.key,...s.key},mouse:f,touch:a,includeDefaults:s.includeDefaults??t.includeDefaults}}return e}function m(n,e){if(!(!n&&!e))return n?e?{...n,...e,style:i(n.style,e.style),joysticks:T(n.joysticks,e.joysticks),buttons:k(n.buttons,e.buttons)}:d(n):d(e)}function T(n,e){if(e===void 0)return p(n);if(e===!1)return!1;let u=n||void 0;return{left:c(u?.left,e.left),right:c(u?.right,e.right)}}function c(n,e){return e===void 0?l(n):e===!1?!1:n?{...n,...e,style:i(n.style,e.style),position:i(n.position,e.position),svg:i(n.svg,e.svg)}:l(e)}function k(n,e){if(e===void 0)return y(n);if(e===!1)return!1;let u=n||void 0,o=u?C(u):{};for(let[s,t]of Object.entries(e)){let f=s,a=o[f];if(t===!1){o[f]=!1;continue}if(!a){o[f]=g(t);continue}o[f]={...a,...t,style:i(a.style,t.style),position:i(a.position,t.position)}}return o}function d(n){if(n)return{...n,style:i(void 0,n.style),joysticks:p(n.joysticks),buttons:y(n.buttons)}}function p(n){if(n!==void 0)return n===!1?!1:I(n)}function l(n){if(n!==void 0)return n===!1?!1:{...n,style:i(void 0,n.style),position:i(void 0,n.position),svg:i(void 0,n.svg)}}function y(n){if(n!==void 0)return n===!1?!1:C(n)}function g(n){return{...n,style:i(void 0,n.style),position:i(void 0,n.position)}}function I(n){return{left:l(n.left),right:l(n.right)}}function C(n){let e={};for(let[u,o]of Object.entries(n))e[u]=o===!1?!1:g(o);return e}function i(n,e){if(!(!n&&!e))return{...n??{},...e??{}}}export{V as a,x as b,w as c,G as d,A as e,D as f,J as g,L as h,b as i,B as j,P as k,v as l};
@@ -0,0 +1 @@
1
+ import{Quaternion as v}from"three";import{Quaternion as p}from"three";var h=new WeakMap,m=new p,x=new p,c=new p;function f(t){return{x:t.x,y:t.y,z:t.z}}function b(t){return{x:t.x,y:t.y,z:t.z,w:t.w}}function r(t){return{position:f(t.position),rotation:b(t.rotation)}}function u(t){return Number.isFinite(t)?Math.max(0,Math.min(1,t)):0}function l(t){return{position:f(t.translation()),rotation:b(t.rotation())}}function g(t){let e=r(t);return{previous:r(e),current:e}}function w(t){let e=l(t),o=h.get(t)??g(e);return o.previous=r(e),o.current=r(e),h.set(t,o),o}function d(t,e,o){let s=u(o);return m.set(t.rotation.x,t.rotation.y,t.rotation.z,t.rotation.w),x.set(e.rotation.x,e.rotation.y,e.rotation.z,e.rotation.w),c.slerpQuaternions(m,x,s),{position:{x:t.position.x+(e.position.x-t.position.x)*s,y:t.position.y+(e.position.y-t.position.y)*s,z:t.position.z+(e.position.z-t.position.z)*s},rotation:{x:c.x,y:c.y,z:c.z,w:c.w}}}function k(t,e){if(R(t))return t.getRenderPose(e);let o=h.get(t);if(!o)return l(t);let s=l(t);if(!H(s,o.current)){let n=w(t);return r(n.current)}return d(o.previous,o.current,e)}function R(t){return t!=null&&typeof t=="object"&&typeof t.getPoseHistory=="function"&&typeof t.getRenderPose=="function"}function H(t,e){return t.position.x===e.position.x&&t.position.y===e.position.y&&t.position.z===e.position.z&&t.rotation.x===e.rotation.x&&t.rotation.y===e.rotation.y&&t.rotation.z===e.rotation.z&&t.rotation.w===e.rotation.w}var P={x:0,y:0,z:0},a=new v,z=new v,S=class t{constructor(e,o,s){this.simulation=e;this.handle=o;this.clock=s;this.interpolationValidAfterStep=s.steps+2}poseScratch={position:[0,0,0],rotation:[0,0,0,1]};renderScratch={position:[0,0,0],rotation:[0,0,0,1],scale:1,custom:[0,0,0,0],isSleeping:!1};previousScratch={position:[0,0,0],rotation:[0,0,0,1],scale:1,custom:[0,0,0,0],isSleeping:!1};interpolationValidAfterStep;markPoseDiscontinuity(){this.interpolationValidAfterStep=this.clock.steps+2}isInterpolationStale(){return this.clock.steps<this.interpolationValidAfterStep}translation(){let e=this.simulation.getPose(this.handle,this.poseScratch);return e?{x:e.position[0],y:e.position[1],z:e.position[2]}:{...P}}rotation(){let e=this.simulation.getPose(this.handle,this.poseScratch);return e?{x:e.rotation[0],y:e.rotation[1],z:e.rotation[2],w:e.rotation[3]}:{x:0,y:0,z:0,w:1}}linvel(){let e=this.simulation.getLinearVelocity(this.handle);return e?{x:e[0],y:e[1],z:e[2]}:{...P}}angvel(){let e=this.simulation.adapter.getAngularVelocity(this.handle.slot);return e?{x:e[0],y:e[1],z:e[2]}:{...P}}setTranslation(e,o=!0){this.simulation.setPosition(this.handle,e.x,e.y,e.z),this.markPoseDiscontinuity()}setRotation(e,o=!0){this.simulation.setRotation(this.handle,e.x,e.y,e.z,e.w),this.markPoseDiscontinuity()}setLinvel(e,o=!0){this.simulation.setLinearVelocity(this.handle,e.x,e.y,e.z)}setAngvel(e,o=!0){this.simulation.setAngularVelocity(this.handle,e.x,e.y,e.z)}applyImpulse(e,o=!0){this.simulation.applyImpulse(this.handle,e.x,e.y,e.z)}lockRotations(e,o=!0){e&&this.setAngvel({x:0,y:0,z:0})}lockTranslations(e,o=!0){e&&this.setLinvel({x:0,y:0,z:0})}setLinearDamping(e){}setGravityScale(e,o=!0){}bodyInfo(){return this.simulation.getBodyInfo(this.handle)}bodyType(){return this.bodyInfo()?.bodyType??0}mass(){return this.bodyInfo()?.mass??0}isSleeping(){return this.bodyInfo()?.isSleeping??!1}isEnabled(){return this.bodyInfo()?.isEnabled??!0}livePose(){let e=this.simulation.getPose(this.handle,this.poseScratch);return e?{position:{x:e.position[0],y:e.position[1],z:e.position[2]},rotation:{x:e.rotation[0],y:e.rotation[1],z:e.rotation[2],w:e.rotation[3]}}:{position:{...P},rotation:{x:0,y:0,z:0,w:1}}}static slotToPose(e){return{position:{x:e.position[0],y:e.position[1],z:e.position[2]},rotation:{x:e.rotation[0],y:e.rotation[1],z:e.rotation[2],w:e.rotation[3]}}}getPoseHistory(){if(this.isInterpolationStale()){let i=this.livePose();return{previous:r(i),current:i}}let e=this.simulation.readRenderSlot(this.handle,this.renderScratch),o=this.simulation.readPreviousRenderSlot(this.handle,this.previousScratch),s=e?t.slotToPose(e):this.livePose();return{previous:o?t.slotToPose(o):r(s),current:s}}getRenderPose(e){let o=this.getPoseHistory();return d(o.previous,o.current,e)}isRenderSleeping(){return this.simulation.readRenderSlot(this.handle,this.renderScratch)?.isSleeping===!0}writeRenderPose(e,o,s){if(this.isInterpolationStale()){this.writeLivePose(o,s);return}let n=this.simulation.readRenderSlot(this.handle,this.renderScratch);if(!n){this.writeLivePose(o,s);return}let i=this.simulation.readPreviousRenderSlot(this.handle,this.previousScratch)??n,y=u(e);o.x=i.position[0]+(n.position[0]-i.position[0])*y,o.y=i.position[1]+(n.position[1]-i.position[1])*y,o.z=i.position[2]+(n.position[2]-i.position[2])*y,a.set(i.rotation[0],i.rotation[1],i.rotation[2],i.rotation[3]),z.set(n.rotation[0],n.rotation[1],n.rotation[2],n.rotation[3]),a.slerp(z,y),s.x=a.x,s.y=a.y,s.z=a.z,s.w=a.w}writeLivePose(e,o){let s=this.simulation.getPose(this.handle,this.poseScratch);s?(e.x=s.position[0],e.y=s.position[1],e.z=s.position[2],o.x=s.rotation[0],o.y=s.rotation[1],o.z=s.rotation[2],o.w=s.rotation[3]):(e.x=0,e.y=0,e.z=0,o.x=0,o.y=0,o.z=0,o.w=1)}};export{k as a,S as b};
@@ -1,6 +1,8 @@
1
1
  import { SimulationBodyDefinition, SimulationColliderDefinition } from '@zylem/behaviors/core';
2
- import { e as Vec3Input } from './vector-CiSHbivc.js';
2
+ import { e as Vec3Input } from './vector-DN6zlPoE.js';
3
3
 
4
+ /** Per-axis lock input: `true` locks all axes, or pass an [x, y, z] tuple. */
5
+ type LockAxesInput = boolean | readonly [boolean, boolean, boolean];
4
6
  /**
5
7
  * Options for configuring entity collision behavior.
6
8
  */
@@ -13,6 +15,12 @@ interface CollisionOptions {
13
15
  position?: Vec3Input;
14
16
  collisionType?: string;
15
17
  collisionFilter?: string[];
18
+ /** Gravity scale applied at body spawn (no live setter FFI; default 1). */
19
+ gravityScale?: number;
20
+ /** Lock rotation axes at body spawn: `true` for all, or per-axis tuple. */
21
+ lockRotations?: LockAxesInput;
22
+ /** Lock translation axes at body spawn: `true` for all, or per-axis tuple. */
23
+ lockTranslations?: LockAxesInput;
16
24
  }
17
25
  /**
18
26
  * Pack a collision type + filter into the runtime's interaction-groups u32
@@ -27,6 +35,9 @@ declare function packCollisionGroups(collisionType?: string, collisionFilter?: s
27
35
  declare class CollisionBuilder {
28
36
  static: boolean;
29
37
  sensor: boolean;
38
+ gravityScale?: number;
39
+ lockRotations?: LockAxesInput;
40
+ lockTranslations?: LockAxesInput;
30
41
  build(options: Partial<CollisionOptions>): [SimulationBodyDefinition, SimulationColliderDefinition];
31
42
  withCollision(collisionOptions: Partial<CollisionOptions>): this;
32
43
  collider(options: CollisionOptions): SimulationColliderDefinition;
@@ -35,4 +46,4 @@ declare class CollisionBuilder {
35
46
  }): SimulationBodyDefinition;
36
47
  }
37
48
 
38
- export { CollisionBuilder as C, type CollisionOptions as a, packCollisionGroups as p };
49
+ export { CollisionBuilder as C, type LockAxesInput as L, type CollisionOptions as a, packCollisionGroups as p };
package/dist/core.d.ts CHANGED
@@ -1,27 +1,27 @@
1
- import { B as Stage, E as StageStateInterface, C as CameraWrapper } from './game-C1FHVqXl.js';
2
- export { A as AspectRatio, q as AspectRatioValue, k as CameraManager, j as CameraOptions, D as DeviceProfile, p as FirstPersonOptions, l as FirstPersonPerspective, o as Fixed2DOptions, F as Fixed2DPerspective, G as Game, b as GameConfigLike, d as GameDeviceConfig, a as GameLoadingEvent, P as PerspectiveOptions, y as RenderBundleManager, z as RenderStrategyManager, R as ResolutionInput, e as ResolveGameConfigRuntime, v as RetroPreset, w as RetroPresetKey, x as RetroResolution, S as StageConfigLike, h as StageOptions, n as ThirdPersonOptions, T as ThirdPersonPerspective, i as createCamera, c as createGame, m as createPerspective, f as createStage, g as gameConfig, r as getDisplayAspect, t as getPresetResolution, u as parseResolution, s as stageConfig } from './game-C1FHVqXl.js';
3
- export { G as GameInputConfig, a as GameInputPlayerConfig, K as KeyboardMapping, M as MouseConfig, b as MouseMapping, V as VirtualTouchButtonConfig, d as VirtualTouchButtonSlot, c as VirtualTouchButtonsConfig, e as VirtualTouchConfig, f as VirtualTouchJoystickConfig, g as VirtualTouchJoysticksConfig, h as VirtualTouchPosition, i as VirtualTouchStyle, Z as ZylemGameConfig } from './game-interfaces-mchNYSZE.js';
1
+ import { B as Stage, E as StageStateInterface, C as CameraWrapper } from './game-DbqBQiFC.js';
2
+ export { A as AspectRatio, q as AspectRatioValue, k as CameraManager, j as CameraOptions, D as DeviceProfile, p as FirstPersonOptions, l as FirstPersonPerspective, o as Fixed2DOptions, F as Fixed2DPerspective, G as Game, b as GameConfigLike, d as GameDeviceConfig, a as GameLoadingEvent, P as PerspectiveOptions, y as RenderBundleManager, z as RenderStrategyManager, R as ResolutionInput, e as ResolveGameConfigRuntime, v as RetroPreset, w as RetroPresetKey, x as RetroResolution, S as StageConfigLike, h as StageOptions, n as ThirdPersonOptions, T as ThirdPersonPerspective, i as createCamera, c as createGame, m as createPerspective, f as createStage, g as gameConfig, r as getDisplayAspect, t as getPresetResolution, u as parseResolution, s as stageConfig } from './game-DbqBQiFC.js';
3
+ export { G as GameInputConfig, a as GameInputPlayerConfig, K as KeyboardMapping, M as MouseConfig, b as MouseMapping, V as VirtualTouchButtonConfig, d as VirtualTouchButtonSlot, c as VirtualTouchButtonsConfig, e as VirtualTouchConfig, f as VirtualTouchJoystickConfig, g as VirtualTouchJoysticksConfig, h as VirtualTouchPosition, i as VirtualTouchStyle, Z as ZylemGameConfig } from './game-interfaces-vF5sRi1n.js';
4
4
  import { Vector2 } from 'three';
5
- import { G as GameEntity, B as BaseNode, N as NodeInterface, a as GameEntityOptions } from './entity-BdSI8CL3.js';
5
+ import { G as GameEntity, B as BaseNode, N as NodeInterface, a as GameEntityOptions } from './entity-BGEq1yfC.js';
6
6
  import { S as StageBlueprint } from './blueprints-TbGY-h53.js';
7
- import { a as SetupContext, k as LoadedContext, U as UpdateContext, D as DestroyContext, l as CleanupContext } from './base-node-life-cycle-D2NuN1VB.js';
8
- export { L as LoadingEvent, S as StageNavigationOptions } from './base-node-life-cycle-D2NuN1VB.js';
7
+ import { a as SetupContext, k as LoadedContext, U as UpdateContext, D as DestroyContext, l as CleanupContext } from './base-node-life-cycle-BK9xebT9.js';
8
+ export { L as LoadingEvent, S as StageNavigationOptions } from './base-node-life-cycle-BK9xebT9.js';
9
9
  export { S as StageTransitionConfig, a as StageTransitionEasing, Z as ZylemTransitionShader, c as crossfadeTransitionShader } from './stage-transition-CmGpV4tc.js';
10
- import { f as CameraBehavior } from './zylem-camera-C3bn6BTI.js';
11
- export { g as CameraAction, d as CameraContext, e as CameraPerspective, j as CameraPipeline, h as CameraPipelineState, C as CameraPose, P as PerspectiveType, a as Perspectives, c as PoseDelta, T as TransformLike, V as Viewport, b as ZylemRenderer, i as isWebGPUSupported } from './zylem-camera-C3bn6BTI.js';
12
- import { e as Vec3Input, c as Vec3 } from './vector-CiSHbivc.js';
13
- export { f as VEC2_ONE, g as VEC2_ZERO, h as VEC3_ONE, i as VEC3_ZERO, V as Vec2, a as Vec2Components, b as Vec2Input, d as Vec3Components, n as normalizeVec2, j as normalizeVec3, t as toThreeVector2, k as toThreeVector3 } from './vector-CiSHbivc.js';
14
- import { S as StageEntity } from './entity-DZbFQ1Wg.js';
15
- import './entity-type-map-Bd69SpAS.js';
16
- import './material-9vJ6SZaI.js';
10
+ import { f as CameraBehavior } from './zylem-camera-Du2UPW9O.js';
11
+ export { g as CameraAction, d as CameraContext, e as CameraPerspective, j as CameraPipeline, h as CameraPipelineState, C as CameraPose, P as PerspectiveType, a as Perspectives, c as PoseDelta, T as TransformLike, V as Viewport, b as ZylemRenderer, i as isWebGPUSupported } from './zylem-camera-Du2UPW9O.js';
12
+ import { e as Vec3Input, c as Vec3 } from './vector-DN6zlPoE.js';
13
+ export { f as VEC2_ONE, g as VEC2_ZERO, h as VEC3_ONE, i as VEC3_ZERO, V as Vec2, a as Vec2Components, b as Vec2Input, d as Vec3Components, n as normalizeVec2, j as normalizeVec3, t as toThreeVector2, k as toThreeVector3 } from './vector-DN6zlPoE.js';
14
+ import { S as StageEntity } from './entity-B9yZeBm4.js';
15
+ import './entity-type-map-CW6RHQkx.js';
16
+ import './material-DbSuZBbP.js';
17
17
  import 'three/webgpu';
18
18
  import '@zylem/behaviors/core';
19
19
  import '@zylem/behaviors/particle-emitter';
20
20
  import 'three/addons/lines/webgpu/Line2.js';
21
21
  import './events.js';
22
22
  import 'mitt';
23
- import './default-controls-0-vCnli7.js';
24
- import './collision-builder-jF-toPIl.js';
23
+ import './default-controls-CAKJ5zlo.js';
24
+ import './collision-builder-B_tm8OVy.js';
25
25
  import '@sinclair/typebox';
26
26
 
27
27
  /**
package/dist/core.js CHANGED
@@ -1 +1 @@
1
- import{a as b,b as c,c as d,d as e,e as f,f as H,g as I,h as J,i as K,j as L,k as M,l as N,m as O,n as P,o as Q}from"./chunk-FKIKN7RP.js";import{a as g}from"./chunk-7GYFZKK7.js";import"./chunk-COM6HJ2L.js";import{a,c as h,d as i,e as j,f as s,g as t,h as u,i as v,k as w,l as x,m as y,n as z,o as A,p as B,q as C,r as D,s as E,t as F,v as G}from"./chunk-JNKPTL77.js";import"./chunk-VS2D4B3W.js";import"./chunk-JQKS42G4.js";import"./chunk-G4HONLWC.js";import"./chunk-XNDS4YFR.js";import"./chunk-XNHVRFAK.js";import"./chunk-CM5YRNBJ.js";import"./chunk-YHEWKN7N.js";import"./chunk-QXVH6POE.js";import"./chunk-E3UBSUPX.js";import"./chunk-D2PATZCC.js";import"./chunk-4QLJUQSJ.js";import{a as k,b as l,c as m,d as n,g as o,h as p,i as q,j as r}from"./chunk-7WRQ2UAN.js";import"./chunk-BH53MBAZ.js";import"./chunk-XRP4JJXL.js";import"./chunk-RXDTAWI2.js";import"./chunk-MSC2BEO5.js";export{b as AspectRatio,B as CameraManager,w as CameraPipeline,C as CameraWrapper,z as FirstPersonPerspective,y as Fixed2DPerspective,J as Game,v as Perspectives,s as RenderBundleManager,t as RenderStrategyManager,M as STAGE_STATE_CHANGE,I as StageManager,x as ThirdPersonPerspective,l as VEC2_ONE,k as VEC2_ZERO,n as VEC3_ONE,m as VEC3_ZERO,D as createCamera,P as createFollowTarget,K as createGame,A as createPerspective,G as createStage,g as crossfadeTransitionShader,O as dispatchStageState,L as entitySpawner,f as gameConfig,c as getDisplayAspect,d as getPresetResolution,N as initStageStateDispatcher,j as isManagedRenderEntity,a as isWebGPUSupported,o as normalizeVec2,p as normalizeVec3,e as parseResolution,h as resolveRenderCategory,Q as setCameraFeed,u as setStageFrameProfilerEnabled,E as stageConfig,H as stageState,q as toThreeVector2,r as toThreeVector3,i as usesManagedRenderPath,F as vessel};
1
+ import{a as b,b as c,c as d,d as e,e as f,f as H,g as I,h as J,i as K,j as L,k as M,l as N,m as O,n as P,o as Q}from"./chunk-3PRBSSTS.js";import{a as g}from"./chunk-7GYFZKK7.js";import"./chunk-COM6HJ2L.js";import{a,c as h,d as i,e as j,f as s,g as t,h as u,i as v,k as w,l as x,m as y,n as z,o as A,p as B,q as C,r as D,s as E,t as F,v as G}from"./chunk-CFVRRRZZ.js";import"./chunk-VS2D4B3W.js";import"./chunk-JQKS42G4.js";import"./chunk-YAOXFYOD.js";import"./chunk-MZZCDXFB.js";import"./chunk-KVSJE4XD.js";import"./chunk-CM5YRNBJ.js";import"./chunk-YHEWKN7N.js";import"./chunk-QXVH6POE.js";import"./chunk-EVYHPR3J.js";import"./chunk-D2PATZCC.js";import"./chunk-4QLJUQSJ.js";import{a as k,b as l,c as m,d as n,g as o,h as p,i as q,j as r}from"./chunk-7WRQ2UAN.js";import"./chunk-BH53MBAZ.js";import"./chunk-XRP4JJXL.js";import"./chunk-PCFF4LLO.js";import"./chunk-UG22Z42P.js";export{b as AspectRatio,B as CameraManager,w as CameraPipeline,C as CameraWrapper,z as FirstPersonPerspective,y as Fixed2DPerspective,J as Game,v as Perspectives,s as RenderBundleManager,t as RenderStrategyManager,M as STAGE_STATE_CHANGE,I as StageManager,x as ThirdPersonPerspective,l as VEC2_ONE,k as VEC2_ZERO,n as VEC3_ONE,m as VEC3_ZERO,D as createCamera,P as createFollowTarget,K as createGame,A as createPerspective,G as createStage,g as crossfadeTransitionShader,O as dispatchStageState,L as entitySpawner,f as gameConfig,c as getDisplayAspect,d as getPresetResolution,N as initStageStateDispatcher,j as isManagedRenderEntity,a as isWebGPUSupported,o as normalizeVec2,p as normalizeVec3,e as parseResolution,h as resolveRenderCategory,Q as setCameraFeed,u as setStageFrameProfilerEnabled,E as stageConfig,H as stageState,q as toThreeVector2,r as toThreeVector3,i as usesManagedRenderPath,F as vessel};
@@ -1,4 +1,4 @@
1
- import { G as GameEntity } from './entity-BdSI8CL3.js';
1
+ import { G as GameEntity } from './entity-BGEq1yfC.js';
2
2
 
3
3
  type DebugTools = 'select' | 'translate' | 'rotate' | 'scale' | 'delete' | 'none';
4
4
  interface DebugState {
package/dist/debug.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- export { D as DebugTools, d as debugState, s as setDebugTool, a as setPaused, b as setSelectedEntity } from './debug-state-BPT6jEog.js';
1
+ export { D as DebugTools, d as debugState, s as setDebugTool, a as setPaused, b as setSelectedEntity } from './debug-state-DRoeasG2.js';
2
2
  import { Object3D, Vector3 } from 'three';
3
- import { G as GameEntity } from './entity-BdSI8CL3.js';
3
+ import { G as GameEntity } from './entity-BGEq1yfC.js';
4
4
  import { WebGPURenderer } from 'three/webgpu';
5
5
  import '@zylem/behaviors/core';
6
- import './vector-CiSHbivc.js';
7
- import './material-9vJ6SZaI.js';
8
- import './collision-builder-jF-toPIl.js';
9
- import './base-node-life-cycle-D2NuN1VB.js';
6
+ import './vector-DN6zlPoE.js';
7
+ import './material-DbSuZBbP.js';
8
+ import './collision-builder-B_tm8OVy.js';
9
+ import './base-node-life-cycle-BK9xebT9.js';
10
10
  import './stage-transition-CmGpV4tc.js';
11
11
  import './events.js';
12
12
  import 'mitt';
@@ -1,5 +1,5 @@
1
- import { b as InputPlayer } from './base-node-life-cycle-D2NuN1VB.js';
2
- import { d as VirtualTouchButtonSlot, e as VirtualTouchConfig, G as GameInputConfig } from './game-interfaces-mchNYSZE.js';
1
+ import { b as InputPlayer } from './base-node-life-cycle-BK9xebT9.js';
2
+ import { d as VirtualTouchButtonSlot, e as VirtualTouchConfig, G as GameInputConfig } from './game-interfaces-vF5sRi1n.js';
3
3
 
4
4
  /**
5
5
  * Color tokens consumed by the SVG factories in `svg-assets.ts` and the
@@ -1,5 +1,5 @@
1
1
  import { Group, Mesh } from 'three';
2
- import { l as SimulationBody } from './vector-CiSHbivc.js';
2
+ import { l as SimulationBody } from './vector-DN6zlPoE.js';
3
3
 
4
4
  type LifecycleFunction<T> = (params?: any) => void;
5
5
  interface Entity<T = any> {
@@ -20,6 +20,12 @@ interface StageEntity extends Entity {
20
20
  instanceId: number;
21
21
  isInstanced?: boolean;
22
22
  isBundled?: boolean;
23
+ /**
24
+ * When true, `syncRenderPoses` leaves the entity's Three.js transform alone.
25
+ * Used for camera-parented viewmodels so physics pose sync cannot overwrite
26
+ * the local offset.
27
+ */
28
+ skipRenderPoseSync?: boolean;
23
29
  controlledRotation: boolean;
24
30
  name: string;
25
31
  markedForRemoval: boolean;
@@ -1,9 +1,9 @@
1
1
  import { BufferGeometry, Material, Mesh, Group, Vector3, Color, ShaderMaterial } from 'three';
2
2
  import { SimulationColliderDefinition, TransformState, SimulationBodyDefinition, MoveableEntity, BehaviorRuntime, Vector, BehaviorDescriptor, BehaviorHandle, BehaviorRef } from '@zylem/behaviors/core';
3
- import { c as Vec3, e as Vec3Input, b as Vec2Input, l as SimulationBody } from './vector-CiSHbivc.js';
4
- import { M as MaterialBuilder, e as MaterialOptions } from './material-9vJ6SZaI.js';
5
- import { C as CollisionBuilder, a as CollisionOptions } from './collision-builder-jF-toPIl.js';
6
- import { a as SetupContext, U as UpdateContext, D as DestroyContext, h as SetupFunction, i as LoadedFunction, g as UpdateFunction, j as DestroyFunction, C as CleanupFunction, k as LoadedContext, l as CleanupContext } from './base-node-life-cycle-D2NuN1VB.js';
3
+ import { c as Vec3, e as Vec3Input, b as Vec2Input, l as SimulationBody } from './vector-DN6zlPoE.js';
4
+ import { M as MaterialBuilder, e as MaterialOptions } from './material-DbSuZBbP.js';
5
+ import { C as CollisionBuilder, L as LockAxesInput, a as CollisionOptions } from './collision-builder-B_tm8OVy.js';
6
+ import { a as SetupContext, U as UpdateContext, D as DestroyContext, h as SetupFunction, i as LoadedFunction, g as UpdateFunction, j as DestroyFunction, C as CleanupFunction, k as LoadedContext, l as CleanupContext } from './base-node-life-cycle-BK9xebT9.js';
7
7
  import { EventEmitterDelegate, EntityEvents } from './events.js';
8
8
 
9
9
  interface NodeInterface {
@@ -252,6 +252,12 @@ interface BaseCollisionOptions {
252
252
  collisionType?: string;
253
253
  /** Allowed collision types for filtering */
254
254
  collisionFilter?: string[];
255
+ /** Gravity scale applied at body spawn (no live setter FFI; default 1). */
256
+ gravityScale?: number;
257
+ /** Lock rotation axes at body spawn: `true` for all, or per-axis tuple. */
258
+ lockRotations?: LockAxesInput;
259
+ /** Lock translation axes at body spawn: `true` for all, or per-axis tuple. */
260
+ lockTranslations?: LockAxesInput;
255
261
  }
256
262
  interface BoxCollisionOptions extends BaseCollisionOptions {
257
263
  /** Box dimensions (default: 1x1x1) */
@@ -402,6 +408,17 @@ type GameEntityOptions = {
402
408
  color?: Color;
403
409
  size?: Vec3Input;
404
410
  position?: Vec3Input;
411
+ /**
412
+ * Spawn visibility behavior:
413
+ * - `undefined` (default): hidden while `spawnEntity` runs, revealed once
414
+ * the spawn finalizes — even if no position was assigned.
415
+ * - `true` (strict): stays hidden until the first `setPosition`/`setPose`,
416
+ * for spawner patterns that place the entity frames after spawn.
417
+ * - `false`: never hidden during spawn.
418
+ */
419
+ hideUntilPositioned?: boolean;
420
+ /** Explicit render visibility. When false, entity stays hidden until {@link GameEntity.reveal}. */
421
+ visible?: boolean;
405
422
  /** Render path: `environment` (bundle), `pack` (instanced), or `none` (default). */
406
423
  category?: RenderCategory;
407
424
  runtime?: RuntimeEntityOptions;
@@ -482,6 +499,14 @@ declare class GameEntity<O extends GameEntityOptions> extends BaseNode<O> implem
482
499
  private trackAddedComponents;
483
500
  private trackedComponents;
484
501
  transformStore: TransformState;
502
+ /** Hide render target until spawn placement is confirmed. */
503
+ _spawnPlacementPending: boolean;
504
+ /** Author passed `position` in create options. */
505
+ _spawnPositionExplicit: boolean;
506
+ /** setPosition / setPose assigned a spawn placement during this spawn. */
507
+ _spawnPlacementReady: boolean;
508
+ /** True while {@link StageEntityDelegate.spawnEntity} is running for this entity. */
509
+ _spawnInProgress: boolean;
485
510
  moveX: (delta: number) => void;
486
511
  moveY: (delta: number) => void;
487
512
  moveZ: (delta: number) => void;
@@ -514,6 +539,9 @@ declare class GameEntity<O extends GameEntityOptions> extends BaseNode<O> implem
514
539
  setRotation: (x: number, y: number, z: number) => void;
515
540
  getRotation: () => any;
516
541
  constructor();
542
+ private wrapSpawnPlacementMutators;
543
+ /** Make the entity visible, clearing spawn placement pending state. */
544
+ reveal(): void;
517
545
  /**
518
546
  * Read the entity's pose from the wasm simulation. Returns `null` when
519
547
  * the entity has not been spawned into the runtime yet.
@@ -1,10 +1,10 @@
1
1
  import { Vector3, Sprite, Color, Object3D, ColorRepresentation, Light, Fog, FogExp2, Scene, Raycaster } from 'three';
2
- import { G as GameEntity, a as GameEntityOptions, B as BaseNode } from './entity-BdSI8CL3.js';
3
- import { d as Vec3Components, e as Vec3Input, b as Vec2Input } from './vector-CiSHbivc.js';
4
- import { U as UpdateContext, a as SetupContext, D as DestroyContext, l as CleanupContext } from './base-node-life-cycle-D2NuN1VB.js';
5
- import { T as TexturePath, e as MaterialOptions } from './material-9vJ6SZaI.js';
2
+ import { G as GameEntity, a as GameEntityOptions, B as BaseNode } from './entity-BGEq1yfC.js';
3
+ import { d as Vec3Components, e as Vec3Input, b as Vec2Input } from './vector-DN6zlPoE.js';
4
+ import { U as UpdateContext, a as SetupContext, D as DestroyContext, l as CleanupContext } from './base-node-life-cycle-BK9xebT9.js';
5
+ import { T as TexturePath, e as MaterialOptions } from './material-DbSuZBbP.js';
6
6
  import { Simulation } from '@zylem/behaviors/core';
7
- import { E as Entity } from './entity-DZbFQ1Wg.js';
7
+ import { E as Entity } from './entity-B9yZeBm4.js';
8
8
  import { ParticleEmitterBehaviorOptions, ParticleEffectDefinition, ParticleEmitterHandle } from '@zylem/behaviors/particle-emitter';
9
9
  import { Line2 } from 'three/addons/lines/webgpu/Line2.js';
10
10
 
package/dist/entity.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- export { A as ACTOR_TYPE, $ as AmbientLightOptions, B as BOX_TYPE, z as CONE_TYPE, J as CYLINDER_TYPE, C as CollisionShapeType, D as DISK_TYPE, a1 as DirectionalLightOptions, aj as EntityForType, ai as EntityTypeMap, a7 as FOG_TYPE, a0 as HemisphereLightOptions, Y as LIGHT_TYPE, aa as LINE_TYPE, a4 as LightShadowOptions, ad as LinePickResult, n as OnEnterParams, o as OnExitParams, O as OnHeldParams, U as PARTICLE_SYSTEM_TYPE, M as PILL_TYPE, P as PLANE_TYPE, G as PYRAMID_TYPE, a2 as PointLightOptions, R as RECT_TYPE, S as SPHERE_TYPE, f as SPRITE_TYPE, a3 as SpotLightOptions, h as SpriteAnimation, g as SpriteImage, T as TEXT_TYPE, m as ZONE_TYPE, q as ZylemActor, Z as ZylemBox, y as ZylemCone, I as ZylemCylinder, w as ZylemDisk, a6 as ZylemFog, ag as ZylemFogHeightOptions, ah as ZylemFogNoiseOptions, ae as ZylemFogOptions, af as ZylemFogType, X as ZylemLight, _ as ZylemLightOptions, a9 as ZylemLine, ac as ZylemLineOptions, Q as ZylemParticleSystem, V as ZylemParticleSystemOptions, L as ZylemPill, j as ZylemPlane, F as ZylemPyramid, u as ZylemRect, b as ZylemSphere, e as ZylemSprite, s as ZylemText, l as ZylemZone, p as createActor, c as createBox, x as createCone, H as createCylinder, v as createDisk, a5 as createFog, W as createLight, a8 as createLine, N as createParticleSystem, K as createPill, i as createPlane, E as createPyramid, t as createRect, a as createSphere, d as createSprite, r as createText, k as createZone, ab as pickZylemLine } from './entity-type-map-Bd69SpAS.js';
2
- import { G as GameEntity, a as GameEntityOptions, E as EntityBuilder, D as EntityMeshBuilder, F as EntityCollisionBuilder, B as BaseNode } from './entity-BdSI8CL3.js';
3
- export { C as CollisionComponent, b as boxCollision, d as coneCollision, c as create, e as cylinderCollision, f as pillCollision, g as planeCollision, p as pyramidCollision, s as sphereCollision, z as zoneCollision } from './entity-BdSI8CL3.js';
1
+ export { A as ACTOR_TYPE, $ as AmbientLightOptions, B as BOX_TYPE, z as CONE_TYPE, J as CYLINDER_TYPE, C as CollisionShapeType, D as DISK_TYPE, a1 as DirectionalLightOptions, aj as EntityForType, ai as EntityTypeMap, a7 as FOG_TYPE, a0 as HemisphereLightOptions, Y as LIGHT_TYPE, aa as LINE_TYPE, a4 as LightShadowOptions, ad as LinePickResult, n as OnEnterParams, o as OnExitParams, O as OnHeldParams, U as PARTICLE_SYSTEM_TYPE, M as PILL_TYPE, P as PLANE_TYPE, G as PYRAMID_TYPE, a2 as PointLightOptions, R as RECT_TYPE, S as SPHERE_TYPE, f as SPRITE_TYPE, a3 as SpotLightOptions, h as SpriteAnimation, g as SpriteImage, T as TEXT_TYPE, m as ZONE_TYPE, q as ZylemActor, Z as ZylemBox, y as ZylemCone, I as ZylemCylinder, w as ZylemDisk, a6 as ZylemFog, ag as ZylemFogHeightOptions, ah as ZylemFogNoiseOptions, ae as ZylemFogOptions, af as ZylemFogType, X as ZylemLight, _ as ZylemLightOptions, a9 as ZylemLine, ac as ZylemLineOptions, Q as ZylemParticleSystem, V as ZylemParticleSystemOptions, L as ZylemPill, j as ZylemPlane, F as ZylemPyramid, u as ZylemRect, b as ZylemSphere, e as ZylemSprite, s as ZylemText, l as ZylemZone, p as createActor, c as createBox, x as createCone, H as createCylinder, v as createDisk, a5 as createFog, W as createLight, a8 as createLine, N as createParticleSystem, K as createPill, i as createPlane, E as createPyramid, t as createRect, a as createSphere, d as createSprite, r as createText, k as createZone, ab as pickZylemLine } from './entity-type-map-CW6RHQkx.js';
2
+ import { G as GameEntity, a as GameEntityOptions, E as EntityBuilder, D as EntityMeshBuilder, F as EntityCollisionBuilder, B as BaseNode } from './entity-BGEq1yfC.js';
3
+ export { C as CollisionComponent, b as boxCollision, d as coneCollision, c as create, e as cylinderCollision, f as pillCollision, g as planeCollision, p as pyramidCollision, s as sphereCollision, z as zoneCollision } from './entity-BGEq1yfC.js';
4
4
  import { Color, Mesh } from 'three';
5
- import { b as Vec2Input, e as Vec3Input } from './vector-CiSHbivc.js';
6
- import { e as MaterialOptions } from './material-9vJ6SZaI.js';
7
- import './base-node-life-cycle-D2NuN1VB.js';
5
+ import { b as Vec2Input, e as Vec3Input } from './vector-DN6zlPoE.js';
6
+ import { e as MaterialOptions } from './material-DbSuZBbP.js';
7
+ import './base-node-life-cycle-BK9xebT9.js';
8
8
  import './stage-transition-CmGpV4tc.js';
9
9
  import '@zylem/behaviors/core';
10
- import './entity-DZbFQ1Wg.js';
10
+ import './entity-B9yZeBm4.js';
11
11
  import '@zylem/behaviors/particle-emitter';
12
12
  import 'three/addons/lines/webgpu/Line2.js';
13
- import './collision-builder-jF-toPIl.js';
13
+ import './collision-builder-B_tm8OVy.js';
14
14
  import './events.js';
15
15
  import 'mitt';
16
16
  import 'three/webgpu';
@@ -52,8 +52,10 @@ interface TemplateFactory<E extends GameEntity<O>, O extends GameEntityOptions =
52
52
  * const asteroidFactory = createEntityFactory(asteroidTemplate);
53
53
  * const asteroids = asteroidFactory.generate(10);
54
54
  *
55
- * asteroids.forEach((asteroid, i) => {
56
- * asteroid.setPosition(Math.random() * 20 - 10, Math.random() * 15 - 7.5, 0);
55
+ * asteroids.forEach((asteroid) => {
56
+ * asteroid.onSetup(({ me }) => {
57
+ * me.setPosition(Math.random() * 20 - 10, Math.random() * 15 - 7.5, 0);
58
+ * });
57
59
  * stage.add(asteroid);
58
60
  * });
59
61
  * ```
package/dist/entity.js CHANGED
@@ -1 +1 @@
1
- import{A as $,B as aa,C as ba,D as ca,E as da,F as ea,G as fa,H as ga,I as ha,J as ia,K as ja,L as ka,M as la,N as ma,O as na,P as oa,Q as pa,R as qa,a as B,b as C,c as D,d as E,e as F,f as G,g as H,h as I,i as J,j as K,k as L,l as M,m as N,n as O,o as P,p as Q,q as R,r as S,s as T,t as U,u as V,v as W,w as X,x as Y,y as Z,z as _}from"./chunk-7FR5JSQ2.js";import{b as q,c as r,d as s,e as t,f as u,g as v,h as w,i as x,j as y,k as z,m as A}from"./chunk-XNDS4YFR.js";import{c as a,d as b,e as c,f as d,g as e,h as f,i as g,j as h,n as i,p as j,t as k,u as l,v as m,w as n,x as o,y as p}from"./chunk-XNHVRFAK.js";import"./chunk-CM5YRNBJ.js";import"./chunk-YHEWKN7N.js";import"./chunk-QXVH6POE.js";import"./chunk-E3UBSUPX.js";import"./chunk-4QLJUQSJ.js";import"./chunk-7WRQ2UAN.js";import"./chunk-XRP4JJXL.js";export{k as ACTOR_TYPE,H as BOX_TYPE,Z as CONE_TYPE,da as CYLINDER_TYPE,W as DISK_TYPE,n as FOG_TYPE,ma as LIGHT_TYPE,w as LINE_TYPE,ja as PARTICLE_SYSTEM_TYPE,ga as PILL_TYPE,N as PLANE_TYPE,aa as PYRAMID_TYPE,T as RECT_TYPE,K as SPHERE_TYPE,t as SPRITE_TYPE,q as TEXT_TYPE,Q as ZONE_TYPE,l as ZylemActor,I as ZylemBox,_ as ZylemCone,ea as ZylemCylinder,X as ZylemDisk,o as ZylemFog,na as ZylemLight,y as ZylemLine,ka as ZylemParticleSystem,ha as ZylemPill,O as ZylemPlane,ba as ZylemPyramid,U as ZylemRect,L as ZylemSphere,u as ZylemSprite,r as ZylemText,R as ZylemZone,a as boxCollision,B as boxMesh,c as coneCollision,D as coneMesh,i as create,m as createActor,J as createBox,$ as createCone,pa as createCooldownIcon,fa as createCylinder,Y as createDisk,j as createEntity,A as createEntityFactory,p as createFog,oa as createLight,z as createLine,la as createParticleSystem,ia as createPill,P as createPlane,ca as createPyramid,V as createRect,M as createSphere,v as createSprite,s as createText,S as createZone,e as cylinderCollision,F as cylinderMesh,qa as destroy,x as pickZylemLine,f as pillCollision,G as pillMesh,g as planeCollision,d as pyramidCollision,E as pyramidMesh,b as sphereCollision,C as sphereMesh,h as zoneCollision};
1
+ import{A as $,B as aa,C as ba,D as ca,E as da,F as ea,G as fa,H as ga,I as ha,J as ia,K as ja,L as ka,M as la,N as ma,O as na,P as oa,Q as pa,R as qa,a as B,b as C,c as D,d as E,e as F,f as G,g as H,h as I,i as J,j as K,k as L,l as M,m as N,n as O,o as P,p as Q,q as R,r as S,s as T,t as U,u as V,v as W,w as X,x as Y,y as Z,z as _}from"./chunk-CD7ZOZ35.js";import{b as q,c as r,d as s,e as t,f as u,g as v,h as w,i as x,j as y,k as z,m as A}from"./chunk-MZZCDXFB.js";import{A as m,B as n,C as o,D as p,c as a,d as b,e as c,f as d,g as e,h as f,i as g,j as h,s as i,u as j,y as k,z as l}from"./chunk-KVSJE4XD.js";import"./chunk-CM5YRNBJ.js";import"./chunk-YHEWKN7N.js";import"./chunk-QXVH6POE.js";import"./chunk-EVYHPR3J.js";import"./chunk-4QLJUQSJ.js";import"./chunk-7WRQ2UAN.js";import"./chunk-XRP4JJXL.js";export{k as ACTOR_TYPE,H as BOX_TYPE,Z as CONE_TYPE,da as CYLINDER_TYPE,W as DISK_TYPE,n as FOG_TYPE,ma as LIGHT_TYPE,w as LINE_TYPE,ja as PARTICLE_SYSTEM_TYPE,ga as PILL_TYPE,N as PLANE_TYPE,aa as PYRAMID_TYPE,T as RECT_TYPE,K as SPHERE_TYPE,t as SPRITE_TYPE,q as TEXT_TYPE,Q as ZONE_TYPE,l as ZylemActor,I as ZylemBox,_ as ZylemCone,ea as ZylemCylinder,X as ZylemDisk,o as ZylemFog,na as ZylemLight,y as ZylemLine,ka as ZylemParticleSystem,ha as ZylemPill,O as ZylemPlane,ba as ZylemPyramid,U as ZylemRect,L as ZylemSphere,u as ZylemSprite,r as ZylemText,R as ZylemZone,a as boxCollision,B as boxMesh,c as coneCollision,D as coneMesh,i as create,m as createActor,J as createBox,$ as createCone,pa as createCooldownIcon,fa as createCylinder,Y as createDisk,j as createEntity,A as createEntityFactory,p as createFog,oa as createLight,z as createLine,la as createParticleSystem,ia as createPill,P as createPlane,ca as createPyramid,V as createRect,M as createSphere,v as createSprite,s as createText,S as createZone,e as cylinderCollision,F as cylinderMesh,qa as destroy,x as pickZylemLine,f as pillCollision,G as pillMesh,g as planeCollision,d as pyramidCollision,E as pyramidMesh,b as sphereCollision,C as sphereMesh,h as zoneCollision};
package/dist/events.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as mitt from 'mitt';
2
- import { L as LoadingEvent } from './base-node-life-cycle-D2NuN1VB.js';
2
+ import { L as LoadingEvent } from './base-node-life-cycle-BK9xebT9.js';
3
3
  import 'three';
4
4
  import './stage-transition-CmGpV4tc.js';
5
5