@zylem/game-lib 0.8.4 → 0.8.6

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 (63) hide show
  1. package/dist/actions.d.ts +7 -5
  2. package/dist/api/game-lib.api.json +3424 -514
  3. package/dist/api/game-lib.api.md +178 -10
  4. package/dist/api/game-lib.d.ts +481 -11
  5. package/dist/api/game-lib.typedoc.json +220347 -136841
  6. package/dist/base-node-idopiSw5.d.ts +96 -0
  7. package/dist/bridge.d.ts +27 -5
  8. package/dist/bridge.js +1 -1
  9. package/dist/catalog.d.ts +77 -0
  10. package/dist/catalog.js +1 -0
  11. package/dist/{chunk-CM5YRNBJ.js → chunk-7NYP4YAG.js} +1 -1
  12. package/dist/chunk-AE3CTVHY.js +1 -0
  13. package/dist/chunk-BCFFS3FP.js +1 -0
  14. package/dist/chunk-BMRFDDMR.js +1 -0
  15. package/dist/chunk-DECK4UEC.js +1 -0
  16. package/dist/chunk-DQQA3VJH.js +1 -0
  17. package/dist/chunk-FYQNZCIP.js +1 -0
  18. package/dist/chunk-GHJQ2HKI.js +1 -0
  19. package/dist/chunk-LD4KDRYL.js +24 -0
  20. package/dist/chunk-MXO4VGDB.js +1 -0
  21. package/dist/{chunk-VIPINV7V.js → chunk-Q2YDBMVY.js} +1 -1
  22. package/dist/chunk-QDQ4QMAI.js +1 -0
  23. package/dist/{chunk-TV3AZKT4.js → chunk-QVIUZEYA.js} +1 -1
  24. package/dist/chunk-SAQA4SXW.js +1 -0
  25. package/dist/chunk-VJZMSBKP.js +1 -0
  26. package/dist/chunk-YOVE25NW.js +1 -0
  27. package/dist/{collision-builder-4TVDzXsp.d.ts → collision-builder-BckxkdmA.d.ts} +1 -1
  28. package/dist/core.d.ts +14 -11
  29. package/dist/core.js +1 -1
  30. package/dist/debug-state-B5awuDHl.d.ts +89 -0
  31. package/dist/debug.d.ts +194 -7
  32. package/dist/debug.js +1 -1
  33. package/dist/{entity-DDks47JB.d.ts → entity-BIf_a4dl.d.ts} +1 -1
  34. package/dist/{entity-BI7cSlK8.d.ts → entity-XZNGBeca.d.ts} +32 -98
  35. package/dist/{entity-type-map-COHu4fkW.d.ts → entity-type-map-CkkFMSrL.d.ts} +5 -4
  36. package/dist/entity.d.ts +9 -7
  37. package/dist/entity.js +1 -1
  38. package/dist/{game-4fsy55uN.d.ts → game-Cy8f6gJm.d.ts} +181 -17
  39. package/dist/game-default-F3KPYZ7X.js +1 -0
  40. package/dist/graphics.d.ts +6 -5
  41. package/dist/graphics.js +1 -1
  42. package/dist/{material-BKPYeBC6.d.ts → material-CxxAyJYp.d.ts} +1 -1
  43. package/dist/public.d.ts +12 -10
  44. package/dist/public.js +1 -1
  45. package/dist/runtime.d.ts +3 -3
  46. package/dist/{vector-DPbwlzgG.d.ts → simulation-body-zQw-emOr.d.ts} +1 -40
  47. package/dist/vector-D3eDzvcA.d.ts +41 -0
  48. package/dist/web-components.d.ts +12 -9
  49. package/dist/web-components.js +1 -1
  50. package/dist/{zylem-camera-B73ZNcgs.d.ts → zylem-camera-DZTpPOiD.d.ts} +12 -1
  51. package/package.json +6 -2
  52. package/dist/chunk-3I537JFL.js +0 -1
  53. package/dist/chunk-4CHZUWLF.js +0 -1
  54. package/dist/chunk-6B5JP7T5.js +0 -24
  55. package/dist/chunk-C5NEGC3S.js +0 -1
  56. package/dist/chunk-D3JO4HW2.js +0 -1
  57. package/dist/chunk-LKFF6XJC.js +0 -1
  58. package/dist/chunk-OAWK2UUY.js +0 -1
  59. package/dist/chunk-PNLNC3FA.js +0 -1
  60. package/dist/chunk-W5SXED5T.js +0 -1
  61. package/dist/debug-state-s0s-qndj.d.ts +0 -49
  62. package/dist/game-default-4PPYYGAR.js +0 -1
  63. /package/dist/{chunk-DFLI7ICU.js → chunk-MSCVL5OK.js} +0 -0
@@ -0,0 +1,96 @@
1
+ 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';
2
+
3
+ interface NodeInterface {
4
+ uuid: string;
5
+ name: string;
6
+ markedForRemoval: boolean;
7
+ nodeSetup(params: SetupContext<any>): void;
8
+ nodeUpdate(params: UpdateContext<any>): void;
9
+ nodeDestroy(params: DestroyContext<any>): void;
10
+ setParent(parent: NodeInterface | null): void;
11
+ getParent(): NodeInterface | null;
12
+ }
13
+
14
+ type BaseNodeOptions<T = any> = BaseNode | Partial<T>;
15
+ /**
16
+ * Lifecycle callback arrays - each lifecycle event can have multiple callbacks
17
+ * that execute in order.
18
+ */
19
+ interface LifecycleCallbacks<T> {
20
+ setup: Array<SetupFunction<T>>;
21
+ loaded: Array<LoadedFunction<T>>;
22
+ update: Array<UpdateFunction<T>>;
23
+ destroy: Array<DestroyFunction<T>>;
24
+ cleanup: Array<CleanupFunction<T>>;
25
+ }
26
+ declare abstract class BaseNode<Options = any, T = any> implements NodeInterface {
27
+ protected parent: NodeInterface | null;
28
+ protected children: NodeInterface[];
29
+ options: Options;
30
+ uuid: string;
31
+ name: string;
32
+ markedForRemoval: boolean;
33
+ /**
34
+ * Lifecycle callback arrays - use onSetup(), onUpdate(), etc. to add callbacks
35
+ * Uses `any` for the type parameter to avoid invariance issues when subclasses
36
+ * are assigned to BaseNode references. Type safety is enforced by the public
37
+ * onSetup/onUpdate/etc. methods which are typed with `this`.
38
+ */
39
+ protected lifecycleCallbacks: LifecycleCallbacks<any>;
40
+ private trackLifecycleRegistrations;
41
+ private userLifecycleRegistrations;
42
+ constructor(args?: BaseNodeOptions[]);
43
+ /**
44
+ * Add setup callbacks to be executed in order during nodeSetup
45
+ */
46
+ onSetup(...callbacks: Array<SetupFunction<this>>): this;
47
+ /**
48
+ * Add loaded callbacks to be executed in order during nodeLoaded
49
+ */
50
+ onLoaded(...callbacks: Array<LoadedFunction<this>>): this;
51
+ /**
52
+ * Add update callbacks to be executed in order during nodeUpdate
53
+ */
54
+ onUpdate(...callbacks: Array<UpdateFunction<this>>): this;
55
+ /**
56
+ * Add destroy callbacks to be executed in order during nodeDestroy
57
+ */
58
+ onDestroy(...callbacks: Array<DestroyFunction<this>>): this;
59
+ /**
60
+ * Add cleanup callbacks to be executed in order during nodeCleanup
61
+ */
62
+ onCleanup(...callbacks: Array<CleanupFunction<this>>): this;
63
+ /**
64
+ * Prepend setup callbacks (run before existing ones)
65
+ */
66
+ prependSetup(...callbacks: Array<SetupFunction<this>>): this;
67
+ /**
68
+ * Prepend update callbacks (run before existing ones)
69
+ */
70
+ prependUpdate(...callbacks: Array<UpdateFunction<this>>): this;
71
+ setParent(parent: NodeInterface | null): void;
72
+ getParent(): NodeInterface | null;
73
+ add(baseNode: NodeInterface): void;
74
+ remove(baseNode: NodeInterface): void;
75
+ getChildren(): NodeInterface[];
76
+ isComposite(): boolean;
77
+ enableUserLifecycleTracking(): void;
78
+ protected replayUserLifecycleRegistrationsTo(target: BaseNode<any, any>, wrap?: <T extends Function>(callback: T) => T): void;
79
+ protected cloneChildrenInto(target: BaseNode<any, any>): void;
80
+ abstract create(): T;
81
+ protected abstract _setup(params: SetupContext<this>): void;
82
+ protected abstract _loaded(params: LoadedContext<this>): Promise<void>;
83
+ protected abstract _update(params: UpdateContext<this>): void;
84
+ protected abstract _destroy(params: DestroyContext<this>): void;
85
+ protected abstract _cleanup(params: CleanupContext<this>): void;
86
+ nodeSetup(params: SetupContext<this>): void;
87
+ nodeUpdate(params: UpdateContext<this>): void;
88
+ nodeDestroy(params: DestroyContext<this>): void;
89
+ nodeLoaded(params: LoadedContext<this>): Promise<void>;
90
+ nodeCleanup(params: CleanupContext<this>): void;
91
+ getOptions(): Options;
92
+ setOptions(options: Partial<Options>): void;
93
+ private recordLifecycleRegistration;
94
+ }
95
+
96
+ export { BaseNode as B, type NodeInterface as N };
package/dist/bridge.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { GameConfigPayload, GameLoadingPayload, GameVariablePayload, GameNoticePayload, StageSnapshotPayload, EntitySummaryPayload, EntityThumbnailPayload } from '@zylem/bridge';
1
+ import { BridgePose, SceneOperationPayload, GameConfigPayload, GameLoadingPayload, GameVariablePayload, GameNoticePayload, StageSnapshotPayload, EntitySummaryPayload, EntityThumbnailPayload, EntityTypeDescriptor } from '@zylem/bridge';
2
2
  export { BRIDGE_READY_EVENT, BridgeChannel, BridgeDebugTool, BridgeHandler, GameLoadingPayload as BridgeLoadingPayload, BridgeMessageType, BridgeMessages, BridgeVec3, EditorToGameMessages, EntitySummaryPayload, EntityThumbnailPayload, GameConfigPayload, GameToEditorMessages, GameVariablePayload, StageConfigPayload, StageSnapshotPayload, ZylemBridge, announceBridgeReady, getZylemBridge } from '@zylem/bridge';
3
- import { G as GameEntity } from './entity-BI7cSlK8.js';
3
+ import { G as GameEntity } from './entity-XZNGBeca.js';
4
4
  import 'three';
5
5
  import '@zylem/behaviors/core';
6
- import './vector-DPbwlzgG.js';
7
- import './material-BKPYeBC6.js';
6
+ import './simulation-body-zQw-emOr.js';
7
+ import './vector-D3eDzvcA.js';
8
+ import './material-CxxAyJYp.js';
8
9
  import 'three/webgpu';
9
- import './collision-builder-4TVDzXsp.js';
10
+ import './collision-builder-BckxkdmA.js';
11
+ import './base-node-idopiSw5.js';
10
12
  import './base-node-life-cycle-BK9xebT9.js';
11
13
  import './stage-transition-CmGpV4tc.js';
12
14
  import './events.js';
@@ -32,6 +34,10 @@ interface GameBridgeHost {
32
34
  resolveEntity(uuid: string): GameEntity<any> | null;
33
35
  /** Write a stage variable (editor `stage:variable:set`). */
34
36
  setStageVariable?(key: string, value: unknown): void;
37
+ /** Spawn a catalog entity into the current stage (editor `entity:create`). */
38
+ createEntity?(typeId: string, props: Record<string, unknown> | undefined, pose: BridgePose | undefined): void;
39
+ /** Undo or redo a committed scene operation (`scene:operation:apply`). */
40
+ applySceneOperation?(op: SceneOperationPayload, direction: 'undo' | 'redo'): void;
35
41
  }
36
42
  declare class GameBridge {
37
43
  private channel;
@@ -43,6 +49,11 @@ declare class GameBridge {
43
49
  * an editor command can never echo back as a game update.
44
50
  */
45
51
  private editorKnown;
52
+ /**
53
+ * True while an undo/redo is being applied, so the writes it performs are
54
+ * not themselves recorded as new operations.
55
+ */
56
+ private applyingSceneOperation;
46
57
  constructor();
47
58
  /**
48
59
  * Subscribe to editor commands and announce the game side as ready.
@@ -106,6 +117,17 @@ declare class GameBridge {
106
117
  queueEntityRemoved(uuids: string[]): void;
107
118
  /** RAF-coalesced thumbnail stream; merged by uuid per frame. */
108
119
  queueThumbnails(thumbnails: EntityThumbnailPayload[]): void;
120
+ /** Publish the placeable entity types the editor's Add palette offers. */
121
+ publishCatalog(entities: EntityTypeDescriptor[]): void;
122
+ /**
123
+ * Publish a committed, invertible change for the editor's undo stack.
124
+ *
125
+ * Sent rather than queued: coalescing merges same-type payloads within a
126
+ * frame, which would fuse two operations into one and lose an undo step.
127
+ */
128
+ publishSceneOperation(op: SceneOperationPayload): void;
129
+ /** Whether an editor is tracking scene operations for undo. */
130
+ wantsSceneOperations(): boolean;
109
131
  }
110
132
 
111
133
  export { GameBridge, type GameBridgeHost };
package/dist/bridge.js CHANGED
@@ -1 +1 @@
1
- import{a as b,b as c,c as d}from"./chunk-HNCTOJP7.js";import{c as a}from"./chunk-D3JO4HW2.js";import"./chunk-LKFF6XJC.js";import"./chunk-W5SXED5T.js";export{d as BRIDGE_READY_EVENT,a as GameBridge,c as announceBridgeReady,b as getZylemBridge};
1
+ import{a as b,b as c,c as d}from"./chunk-HNCTOJP7.js";import{f as a}from"./chunk-DQQA3VJH.js";import"./chunk-VJZMSBKP.js";import"./chunk-DECK4UEC.js";export{d as BRIDGE_READY_EVENT,a as GameBridge,c as announceBridgeReady,b as getZylemBridge};
@@ -0,0 +1,77 @@
1
+ import { EntityTypeDescriptor } from '@zylem/bridge';
2
+ export { EntityTypeDescriptor } from '@zylem/bridge';
3
+ import { B as BaseNode } from './base-node-idopiSw5.js';
4
+ import { c as Vec3 } from './vector-D3eDzvcA.js';
5
+ import './base-node-life-cycle-BK9xebT9.js';
6
+ import 'three';
7
+ import './stage-transition-CmGpV4tc.js';
8
+
9
+ /**
10
+ * Runtime registry of placeable entity types, backing the editor's Add palette.
11
+ *
12
+ * The factory stays on this side of the bridge; only a serializable descriptor
13
+ * crosses it. That is what makes the palette extensible without the editor
14
+ * depending on game-lib: a host such as Creator registers its own configured
15
+ * entities here (shaders, behaviors, whatever its swatches resolve to) and they
16
+ * show up in the palette alongside the built-in primitives.
17
+ */
18
+
19
+ /** Context handed to a factory when the user clicks to place. */
20
+ interface EntityPlacementContext {
21
+ /** Snapped world position the entity should be created at. */
22
+ position: Vec3;
23
+ /** Surface normal when placed onto geometry. */
24
+ normal?: Vec3;
25
+ /** Options merged over the descriptor's defaults. */
26
+ props: Record<string, unknown>;
27
+ }
28
+ type EntityTypeFactory = (context: EntityPlacementContext) => BaseNode | Promise<BaseNode> | null;
29
+ /** A registered entity type: what the palette shows, plus how to build it. */
30
+ interface EntityTypeRegistration extends EntityTypeDescriptor {
31
+ create: EntityTypeFactory;
32
+ }
33
+ /**
34
+ * Register a placeable entity type, replacing any existing type with the same
35
+ * id so a host can override a built-in.
36
+ *
37
+ * @returns An unregister function.
38
+ */
39
+ declare function registerEntityType(registration: EntityTypeRegistration): () => void;
40
+ /** Register several types at once, notifying listeners only after all of them. */
41
+ declare function registerEntityTypes(registrations: EntityTypeRegistration[]): () => void;
42
+ declare function getEntityType(id: string): EntityTypeRegistration | null;
43
+ /** Every registered type, in registration order. */
44
+ declare function listEntityTypes(): EntityTypeRegistration[];
45
+ /** The serializable view of the registry, as published to the editor. */
46
+ declare function buildCatalogDescriptors(): EntityTypeDescriptor[];
47
+ /**
48
+ * Observe registry changes so the catalog can be republished.
49
+ *
50
+ * @returns An unsubscribe function.
51
+ */
52
+ declare function onEntityRegistryChanged(listener: () => void): () => void;
53
+ /** Test hook: drop every registration. */
54
+ declare function clearEntityRegistry(): void;
55
+
56
+ /**
57
+ * The built-in placeable entity types offered by the editor's Add palette.
58
+ *
59
+ * Only types that can be placed with a click and no external assets are listed.
60
+ * Actors and sprites need a model or spritesheet, and fog is a global stage
61
+ * effect with no position, so none of them are meaningful to drop into a scene
62
+ * at a point. A host can still register them itself once it has the assets.
63
+ *
64
+ * Icons are inline SVG markup rather than an icon-set name. The editor and its
65
+ * hosts do not share an icon library — the editor uses lucide, Creator has its
66
+ * own hand-rolled glyph registry — so shipping the markup with the descriptor is
67
+ * what lets a Creator-registered entity look right in the palette.
68
+ */
69
+
70
+ declare const BUILT_IN_ENTITY_TYPES: EntityTypeRegistration[];
71
+ /**
72
+ * Register the built-in types. Idempotent, so a second game on the page does
73
+ * not duplicate the palette.
74
+ */
75
+ declare function registerBuiltInEntityTypes(): () => void;
76
+
77
+ export { BUILT_IN_ENTITY_TYPES, type EntityPlacementContext, type EntityTypeFactory, type EntityTypeRegistration, buildCatalogDescriptors, clearEntityRegistry, getEntityType, listEntityTypes, onEntityRegistryChanged, registerBuiltInEntityTypes, registerEntityType, registerEntityTypes };
@@ -0,0 +1 @@
1
+ import{a as o,b as s}from"./chunk-QDQ4QMAI.js";import{a as t,b as e,c as y,d as i,e as r,f as n,g as p}from"./chunk-AE3CTVHY.js";import"./chunk-BMRFDDMR.js";import"./chunk-SAQA4SXW.js";import"./chunk-7NYP4YAG.js";import"./chunk-AIQ6IVT5.js";import"./chunk-QXVH6POE.js";import"./chunk-EVYHPR3J.js";import"./chunk-4QLJUQSJ.js";import"./chunk-7WRQ2UAN.js";import"./chunk-XRP4JJXL.js";export{o as BUILT_IN_ENTITY_TYPES,r as buildCatalogDescriptors,p as clearEntityRegistry,y as getEntityType,i as listEntityTypes,n as onEntityRegistryChanged,s as registerBuiltInEntityTypes,t as registerEntityType,e as registerEntityTypes};
@@ -16,4 +16,4 @@ void main() {
16
16
 
17
17
  gl_FragColor = texel;
18
18
  }
19
- `,O={vertex:C,fragment:D};import{Color as F,RepeatWrapping as v,SRGBColorSpace as te}from"three";import{MeshBasicNodeMaterial as re,MeshStandardNodeMaterial as P}from"three/webgpu";function G(s){let e=Object.keys(s).sort().reduce((t,r)=>(t[r]=s[r],t),{});return JSON.stringify(e)}function E(s){let e=0;for(let t=0;t<s.length;t++)e=Math.imul(31,e)+s.charCodeAt(t)|0;return e.toString(36)}import{LoadingManager as ee,Cache as k}from"three";import{TextureLoader as X,RepeatWrapping as B}from"three";var b=16,L=class{loader;constructor(){this.loader=new X}isSupported(e){let t=e.split(".").pop()?.toLowerCase();return["png","jpg","jpeg","gif","webp","bmp","tga"].includes(t||"")}async load(e,t){let r=await this.loader.loadAsync(e,a=>{t?.onProgress&&a.lengthComputable&&t.onProgress(a.loaded/a.total)});return t?.repeat&&r.repeat.copy(h(t.repeat,p)),r.wrapS=t?.wrapS??B,r.wrapT=t?.wrapT??B,t?.colorSpace!==void 0&&(r.colorSpace=t.colorSpace),r.anisotropy=t?.anisotropy??b,r}clone(e){let t=e.clone();return t.anisotropy=e.anisotropy||b,t.needsUpdate=!0,t}};import{GLTFLoader as J}from"three/addons/loaders/GLTFLoader.js";import{DRACOLoader as K}from"three/addons/loaders/DRACOLoader.js";import{KTX2Loader as Z}from"three/addons/loaders/KTX2Loader.js";import{MeshoptDecoder as $}from"three/addons/libs/meshopt_decoder.module.js";import{Mesh as j}from"three";import{clone as W}from"three/addons/utils/SkeletonUtils.js";function u(s){let e=W(s),t=[],r=[];s.traverse(a=>t.push(a)),e.traverse(a=>r.push(a));for(let a=0;a<t.length;a++){let o=t[a],n=r[a];!(o instanceof j)||!(n instanceof j)||(o.geometry?.clone&&(n.geometry=o.geometry.clone()),o.material&&(n.material=Array.isArray(o.material)?o.material.map(i=>i.clone()):o.material.clone()))}return e}function I(s){let e=s.indexOf("?"),t=s.indexOf("#"),r=[e,t].filter(a=>a>=0).reduce((a,o)=>Math.min(a,o),s.length);return s.slice(0,r)}function c(s){let e=I(s),t=e.lastIndexOf("/"),r=t>=0?e.slice(t+1):e,a=r.lastIndexOf(".");return a<0||a===r.length-1?null:r.slice(a+1).toLowerCase()}var V=["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"],H="https://www.gstatic.com/draco/v1/decoders/",g=class{loader;dracoLoader;ktx2Loader=null;meshoptEnabled=!1;configuredRenderer=null;ktx2TranscoderPath=null;constructor(){this.dracoLoader=new K,this.dracoLoader.setDecoderPath(H),this.loader=new J,this.loader.setDRACOLoader(this.dracoLoader),this.setMeshoptEnabled(!0)}isSupported(e){let t=c(e);return["gltf","glb"].includes(t||"")}async configureRuntime({meshopt:e=!0,ktx2TranscoderPath:t,renderer:r=null}={}){this.setMeshoptEnabled(e!==!1);let a=this.normalizeTranscoderPath(t);if(!a){this.clearKTX2Loader();return}if(!r)throw new Error("GLTFLoaderAdapter.configureRuntime requires a renderer when ktx2TranscoderPath is provided.");(!this.ktx2Loader||this.ktx2TranscoderPath!==a)&&(this.clearKTX2Loader(),this.ktx2Loader=new Z,this.ktx2Loader.setTranscoderPath(a),this.loader.setKTX2Loader(this.ktx2Loader),this.ktx2TranscoderPath=a,this.configuredRenderer=null),!(!this.ktx2Loader||this.configuredRenderer===r)&&(this.ktx2Loader.detectSupport(r),this.configuredRenderer=r)}async load(e,t){return t?.useAsyncFetch?this.loadWithAsyncFetch(e,t):this.loadMainThread(e,t)}async loadWithAsyncFetch(e,t){try{let r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch ${e}: ${r.status} ${r.statusText}`);let a=await r.arrayBuffer(),o=await this.loader.parseAsync(a,e);return this.applyTextureAnisotropy(o.scene),{object:o.scene,animations:o.animations,gltf:o}}catch(r){return console.error(`Async fetch GLTF load failed for ${e}, falling back to loader.load():`,r),this.loadMainThread(e,t)}}async loadMainThread(e,t){return new Promise((r,a)=>{this.loader.load(e,o=>{this.applyTextureAnisotropy(o.scene),r({object:o.scene,animations:o.animations,gltf:o})},o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>a(o))})}clone(e){return{object:u(e.object),animations:e.animations?.map(t=>t.clone()),gltf:e.gltf}}applyTextureAnisotropy(e){e.traverse(t=>{let r=t.material;if(!r)return;let a=Array.isArray(r)?r:[r];for(let o of a)for(let n of V){let i=o[n];if(i&&i.isTexture){let d=i;d.anisotropy=b,d.needsUpdate=!0}}})}setMeshoptEnabled(e){if(e){if(this.meshoptEnabled)return;this.loader.setMeshoptDecoder($),this.meshoptEnabled=!0;return}this.meshoptEnabled&&(this.loader.setMeshoptDecoder(void 0),this.meshoptEnabled=!1)}clearKTX2Loader(){this.ktx2Loader&&(this.ktx2Loader.dispose(),this.ktx2Loader=null),this.loader.setKTX2Loader(void 0),this.configuredRenderer=null,this.ktx2TranscoderPath=null}normalizeTranscoderPath(e){if(!e)return null;let t=String(e);return t.endsWith("/")?t:`${t}/`}};import{FBXLoader as _}from"three/addons/loaders/FBXLoader.js";var T=class{loader;constructor(){this.loader=new _}isSupported(e){return c(e)==="fbx"}async load(e,t){return t?.useAsyncFetch?this.loadWithAsyncFetch(e,t):this.loadMainThread(e,t)}async loadWithAsyncFetch(e,t){try{let r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch ${e}: ${r.status} ${r.statusText}`);let a=await r.arrayBuffer(),o=this.loader.parse(a,e);return{object:o,animations:o.animations||[]}}catch(r){return console.error(`Async fetch FBX load failed for ${e}, falling back to loader.load():`,r),this.loadMainThread(e,t)}}async loadMainThread(e,t){return new Promise((r,a)=>{this.loader.load(e,o=>{r({object:o,animations:o.animations||[]})},o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>a(o))})}clone(e){return{object:u(e.object),animations:e.animations?.map(t=>t.clone())}}};import{OBJLoader as z}from"three/addons/loaders/OBJLoader.js";import{MTLLoader as Y}from"three/addons/loaders/MTLLoader.js";var y=class{loader;mtlLoader;constructor(){this.loader=new z,this.mtlLoader=new Y}isSupported(e){return c(e)==="obj"}async load(e,t){return t?.mtlPath&&await this.loadMTL(t.mtlPath),new Promise((r,a)=>{this.loader.load(e,o=>{r({object:o,animations:[]})},o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>a(o))})}async loadMTL(e){return new Promise((t,r)=>{this.mtlLoader.load(e,a=>{a.preload(),this.loader.setMaterials(a),t()},void 0,a=>r(a))})}clone(e){return{object:u(e.object),animations:[]}}};import{AudioLoader as q}from"three";var x=class{loader;constructor(){this.loader=new q}isSupported(e){let t=c(e);return["mp3","ogg","wav","flac","aac","m4a"].includes(t||"")}async load(e,t){return new Promise((r,a)=>{this.loader.load(e,o=>r(o),o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>a(o))})}};import{FileLoader as Q}from"three";var m=class{loader;constructor(){this.loader=new Q}isSupported(e){return!0}async load(e,t){let r=t?.responseType??"text";return this.loader.setResponseType(r),new Promise((a,o)=>{this.loader.load(e,n=>a(n),n=>{t?.onProgress&&n.lengthComputable&&t.onProgress(n.loaded/n.total)},n=>o(n))})}},M=class{fileLoader;constructor(){this.fileLoader=new m}isSupported(e){return c(e)==="json"}async load(e,t){return await this.fileLoader.load(e,{...t,responseType:"json"})}};var w=class s{static instance=null;textureCache=new Map;modelCache=new Map;audioCache=new Map;fileCache=new Map;jsonCache=new Map;pendingGLTFRuntimePath=null;pendingGLTFRuntimePromise=null;pendingGLTFRuntimeResolve=null;textureLoader;gltfLoader;fbxLoader;objLoader;audioLoader;fileLoader;jsonLoader;loadingManager;events;stats={texturesLoaded:0,modelsLoaded:0,audioLoaded:0,filesLoaded:0,cacheHits:0,cacheMisses:0};constructor(){this.textureLoader=new L,this.gltfLoader=new g,this.fbxLoader=new T,this.objLoader=new y,this.audioLoader=new x,this.fileLoader=new m,this.jsonLoader=new M,this.loadingManager=new ee,this.loadingManager.onProgress=(e,t,r)=>{this.events.emit("batch:progress",{loaded:t,total:r})},this.events=R(),k.enabled=!0}static getInstance(){return s.instance||(s.instance=new s),s.instance}static resetInstance(){s.instance&&(s.instance.clearCache(),s.instance=null)}async loadTexture(e,t){return this.loadWithCache(e,"texture",this.textureCache,()=>this.textureLoader.load(e,t),t,r=>{if(!t?.clone)return r;let a=this.textureLoader.clone(r);return t.repeat&&a.repeat.copy(h(t.repeat,p)),t.wrapS!==void 0&&(a.wrapS=t.wrapS),t.wrapT!==void 0&&(a.wrapT=t.wrapT),a})}async loadGLTF(e,t){return await this.waitForPreparedGLTFRuntime(),this.loadWithCache(e,"gltf",this.modelCache,()=>this.gltfLoader.load(e,t),t,r=>t?.clone?this.gltfLoader.clone(r):r)}prepareGLTFRuntime(e){let t=this.normalizeTranscoderPath(e?.ktx2TranscoderPath);t&&(this.pendingGLTFRuntimePath===t&&this.pendingGLTFRuntimePromise||(this.pendingGLTFRuntimePath=t,this.pendingGLTFRuntimePromise||(this.pendingGLTFRuntimePromise=new Promise(r=>{this.pendingGLTFRuntimeResolve=r}))))}async configureGLTFRuntime(e){await this.gltfLoader.configureRuntime(e);let t=this.normalizeTranscoderPath(e?.ktx2TranscoderPath);t&&e?.renderer&&this.resolvePreparedGLTFRuntime(t)}async loadFBX(e,t){return this.loadWithCache(e,"fbx",this.modelCache,()=>this.fbxLoader.load(e,t),t,r=>t?.clone?this.fbxLoader.clone(r):r)}async loadOBJ(e,t){let r=t?.mtlPath?`${e}:${t.mtlPath}`:e;return this.loadWithCache(r,"obj",this.modelCache,()=>this.objLoader.load(e,t),t,a=>t?.clone?this.objLoader.clone(a):a)}async loadModel(e,t){let r=c(e);switch(r){case"gltf":case"glb":return this.loadGLTF(e,t);case"fbx":return this.loadFBX(e,t);case"obj":return this.loadOBJ(e,t);default:throw new Error(`Unsupported model format: ${r}`)}}async loadAudio(e,t){return this.loadWithCache(e,"audio",this.audioCache,()=>this.audioLoader.load(e,t),t)}async loadFile(e,t){let r=t?.responseType?`${e}:${t.responseType}`:e;return this.loadWithCache(r,"file",this.fileCache,()=>this.fileLoader.load(e,t),t)}async loadJSON(e,t){return this.loadWithCache(e,"json",this.jsonCache,()=>this.jsonLoader.load(e,t),t)}async loadBatch(e){let t=new Map,r=e.map(async a=>{try{let o;switch(a.type){case"texture":o=await this.loadTexture(a.url,a.options);break;case"gltf":o=await this.loadGLTF(a.url,a.options);break;case"fbx":o=await this.loadFBX(a.url,a.options);break;case"obj":o=await this.loadOBJ(a.url,a.options);break;case"audio":o=await this.loadAudio(a.url,a.options);break;case"file":o=await this.loadFile(a.url,a.options);break;case"json":o=await this.loadJSON(a.url,a.options);break;default:throw new Error(`Unknown asset type: ${a.type}`)}t.set(a.url,o)}catch(o){throw this.events.emit("asset:error",{url:a.url,type:a.type,error:o}),o}});return await Promise.all(r),this.events.emit("batch:complete",{urls:e.map(a=>a.url)}),t}async preload(e){await this.loadBatch(e)}isCached(e){return this.textureCache.has(e)||this.modelCache.has(e)||this.audioCache.has(e)||this.fileCache.has(e)||this.jsonCache.has(e)}clearCache(e){e?(this.textureCache.delete(e),this.modelCache.delete(e),this.audioCache.delete(e),this.fileCache.delete(e),this.jsonCache.delete(e)):(this.textureCache.clear(),this.modelCache.clear(),this.audioCache.clear(),this.fileCache.clear(),this.jsonCache.clear(),k.clear(),this.pendingGLTFRuntimePath=null,this.pendingGLTFRuntimePromise=null,this.pendingGLTFRuntimeResolve=null)}getStats(){return{...this.stats}}on(e,t){this.events.on(e,t)}off(e,t){this.events.off(e,t)}async loadWithCache(e,t,r,a,o,n){o?.forceReload&&r.delete(e);let i=r.get(e);if(i){this.stats.cacheHits++,this.events.emit("asset:loaded",{url:e,type:t,fromCache:!0});let l=await i.promise;return n?n(l):l}this.stats.cacheMisses++,this.events.emit("asset:loading",{url:e,type:t});let d=a(),f={promise:d,loadedAt:Date.now()};r.set(e,f);try{let l=await d;return f.result=l,this.updateStats(t),this.events.emit("asset:loaded",{url:e,type:t,fromCache:!1}),n?n(l):l}catch(l){throw r.delete(e),this.events.emit("asset:error",{url:e,type:t,error:l}),l}}updateStats(e){switch(e){case"texture":this.stats.texturesLoaded++;break;case"gltf":case"fbx":case"obj":this.stats.modelsLoaded++;break;case"audio":this.stats.audioLoaded++;break;case"file":case"json":this.stats.filesLoaded++;break}}async waitForPreparedGLTFRuntime(){this.pendingGLTFRuntimePromise&&await this.pendingGLTFRuntimePromise}resolvePreparedGLTFRuntime(e){this.pendingGLTFRuntimePath&&this.pendingGLTFRuntimePath!==e||(this.pendingGLTFRuntimeResolve?.(),this.pendingGLTFRuntimeResolve=null,this.pendingGLTFRuntimePromise=null,this.pendingGLTFRuntimePath=null)}normalizeTranscoderPath(e){if(!e)return null;let t=String(e);return t.endsWith("/")?t:`${t}/`}},A=w.getInstance();import{uniform as vt,uv as Ot,time as wt,vec3 as At,vec4 as Ft,float as Pt,Fn as St}from"three/tsl";function ae(s){return"colorNode"in s}function N(s){return"fragment"in s&&"vertex"in s}function oe(s){return!!s&&N(s)&&s.vertex===O.vertex&&s.fragment===O.fragment}var U=class s{static sharedMaterialMap=new Map;static clearSharedMaterialCache(){s.sharedMaterialMap.clear()}materials=[];useTSL;constructor(e=!0){this.useTSL=e}trackSharedMaterial(e,t){let r=E(G(e)),a=s.sharedMaterialMap.get(r);if(a){let o=a.geometryMap.get(t);o?a.geometryMap.set(t,o+1):a.geometryMap.set(t,1)}else s.sharedMaterialMap.set(r,{geometryMap:new Map([[t,1]]),material:this.materials[0]})}build(e,t){let{path:r,normalMap:a,repeat:o,color:n,shader:i,opacity:d}=e,f=oe(i),l=!!i&&!f,S=!!r&&(!i||f);S?this.setTexture(r??null,o,!0,d,n):l&&i?ae(i)?this.setTSLShader(i,d):N(i)&&(console.warn("MaterialBuilder: GLSL shaders are not supported on the WebGPU renderer. Author custom shaders as TSL (ZylemTSLShader). Falling back to a default node material."),this.setColor(n??new F("#ffffff"),!0,d)):r&&this.setTexture(r,o,!0,d,n),n&&!S&&!l&&this.withColor(n,!0,d),this.materials.length===0&&this.setColor(new F("#ffffff"),!0,d),a&&this.materials.length>0&&this.setNormalMap(a,o),this.trackSharedMaterial(e,t)}withColor(e,t=!1,r){return this.setColor(e,t,r),this}withShader(e,t){return this.setShader(e,t),this}withTSLShader(e,t){return this.setTSLShader(e,t),this}applyOpacity(e,t,r=!1){t!==void 0&&(e.opacity=t),e.transparent=r||t!==void 0&&t<1,e.needsUpdate=!0}setTexture(e=null,t=p,r=!0,a,o){if(!e)return;let n=new P;o&&(n.color=o),this.applyOpacity(n,a),this.materials.push(n),A.loadTexture(e,{clone:!0,repeat:h(t,p),colorSpace:te}).then(i=>{i.wrapS=v,i.wrapT=v,n.map=i,n.needsUpdate=!0})}setNormalMap(e,t=p){let r=this.materials[this.materials.length-1];r&&A.loadTexture(e,{clone:!0,repeat:h(t,p)}).then(a=>{a.wrapS=v,a.wrapT=v,r instanceof P&&(r.normalMap=a,r.needsUpdate=!0)})}setColor(e,t=!0,r){let a=new P;a.color=e,this.applyOpacity(a,r),this.materials.push(a)}setShader(e,t){console.warn("MaterialBuilder.setShader: GLSL shaders are not supported on the WebGPU renderer. Author custom shaders as TSL (ZylemTSLShader). Falling back to a default node material."),this.setColor(new F("#ffffff"),!0,t)}setTSLShader(e,t){this.materials.push(se(e,t))}};function se(s,e){let t=new re;return t.colorNode=s.colorNode,s.positionNode&&(t.positionNode=s.positionNode),s.normalNode&&(t.normalNode=s.normalNode),s.blending!==void 0&&(t.blending=s.blending),s.side!==void 0&&(t.side=s.side),s.depthTest!==void 0&&(t.depthTest=s.depthTest),e!==void 0&&(t.opacity=e),t.transparent=!!s.transparent||e!==void 0&&e<1,t.needsUpdate=!0,t}export{C as a,O as b,b as c,c as d,A as e,G as f,E as g,ae as h,N as i,U as j,se as k,vt as l,Ot as m,wt as n,At as o,Ft as p,Pt as q,St as r};
19
+ `,O={vertex:C,fragment:D};import{Color as F,RepeatWrapping as v,SRGBColorSpace as te}from"three";import{MeshBasicNodeMaterial as re,MeshStandardNodeMaterial as P}from"three/webgpu";function G(s){let e=Object.keys(s).sort().reduce((t,r)=>(t[r]=s[r],t),{});return JSON.stringify(e)}function E(s){let e=0;for(let t=0;t<s.length;t++)e=Math.imul(31,e)+s.charCodeAt(t)|0;return e.toString(36)}import{LoadingManager as ee,Cache as k}from"three";import{TextureLoader as X,RepeatWrapping as B}from"three";var b=16,L=class{loader;constructor(){this.loader=new X}isSupported(e){let t=e.split(".").pop()?.toLowerCase();return["png","jpg","jpeg","gif","webp","bmp","tga"].includes(t||"")}async load(e,t){let r=await this.loader.loadAsync(e,a=>{t?.onProgress&&a.lengthComputable&&t.onProgress(a.loaded/a.total)});return t?.repeat&&r.repeat.copy(h(t.repeat,p)),r.wrapS=t?.wrapS??B,r.wrapT=t?.wrapT??B,t?.colorSpace!==void 0&&(r.colorSpace=t.colorSpace),r.anisotropy=t?.anisotropy??b,r}clone(e){let t=e.clone();return t.anisotropy=e.anisotropy||b,t.needsUpdate=!0,t}};import{GLTFLoader as J}from"three/addons/loaders/GLTFLoader.js";import{DRACOLoader as K}from"three/addons/loaders/DRACOLoader.js";import{KTX2Loader as Z}from"three/addons/loaders/KTX2Loader.js";import{MeshoptDecoder as $}from"three/addons/libs/meshopt_decoder.module.js";import{Mesh as j}from"three";import{clone as W}from"three/addons/utils/SkeletonUtils.js";function u(s){let e=W(s),t=[],r=[];s.traverse(a=>t.push(a)),e.traverse(a=>r.push(a));for(let a=0;a<t.length;a++){let o=t[a],n=r[a];!(o instanceof j)||!(n instanceof j)||(o.geometry?.clone&&(n.geometry=o.geometry.clone()),o.material&&(n.material=Array.isArray(o.material)?o.material.map(i=>i.clone()):o.material.clone()))}return e}function I(s){let e=s.indexOf("?"),t=s.indexOf("#"),r=[e,t].filter(a=>a>=0).reduce((a,o)=>Math.min(a,o),s.length);return s.slice(0,r)}function c(s){let e=I(s),t=e.lastIndexOf("/"),r=t>=0?e.slice(t+1):e,a=r.lastIndexOf(".");return a<0||a===r.length-1?null:r.slice(a+1).toLowerCase()}var V=["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"],H="https://www.gstatic.com/draco/v1/decoders/",g=class{loader;dracoLoader;ktx2Loader=null;meshoptEnabled=!1;configuredRenderer=null;ktx2TranscoderPath=null;constructor(){this.dracoLoader=new K,this.dracoLoader.setDecoderPath(H),this.loader=new J,this.loader.setDRACOLoader(this.dracoLoader),this.setMeshoptEnabled(!0)}isSupported(e){let t=c(e);return["gltf","glb"].includes(t||"")}async configureRuntime({meshopt:e=!0,ktx2TranscoderPath:t,renderer:r=null}={}){this.setMeshoptEnabled(e!==!1);let a=this.normalizeTranscoderPath(t);if(!a){this.clearKTX2Loader();return}if(!r)throw new Error("GLTFLoaderAdapter.configureRuntime requires a renderer when ktx2TranscoderPath is provided.");(!this.ktx2Loader||this.ktx2TranscoderPath!==a)&&(this.clearKTX2Loader(),this.ktx2Loader=new Z,this.ktx2Loader.setTranscoderPath(a),this.loader.setKTX2Loader(this.ktx2Loader),this.ktx2TranscoderPath=a,this.configuredRenderer=null),!(!this.ktx2Loader||this.configuredRenderer===r)&&(this.ktx2Loader.detectSupport(r),this.configuredRenderer=r)}async load(e,t){return t?.useAsyncFetch?this.loadWithAsyncFetch(e,t):this.loadMainThread(e,t)}async loadWithAsyncFetch(e,t){try{let r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch ${e}: ${r.status} ${r.statusText}`);let a=await r.arrayBuffer(),o=await this.loader.parseAsync(a,e);return this.applyTextureAnisotropy(o.scene),{object:o.scene,animations:o.animations,gltf:o}}catch(r){return console.error(`Async fetch GLTF load failed for ${e}, falling back to loader.load():`,r),this.loadMainThread(e,t)}}async loadMainThread(e,t){return new Promise((r,a)=>{this.loader.load(e,o=>{this.applyTextureAnisotropy(o.scene),r({object:o.scene,animations:o.animations,gltf:o})},o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>a(o))})}clone(e){return{object:u(e.object),animations:e.animations?.map(t=>t.clone()),gltf:e.gltf}}applyTextureAnisotropy(e){e.traverse(t=>{let r=t.material;if(!r)return;let a=Array.isArray(r)?r:[r];for(let o of a)for(let n of V){let i=o[n];if(i&&i.isTexture){let d=i;d.anisotropy=b,d.needsUpdate=!0}}})}setMeshoptEnabled(e){if(e){if(this.meshoptEnabled)return;this.loader.setMeshoptDecoder($),this.meshoptEnabled=!0;return}this.meshoptEnabled&&(this.loader.setMeshoptDecoder(void 0),this.meshoptEnabled=!1)}clearKTX2Loader(){this.ktx2Loader&&(this.ktx2Loader.dispose(),this.ktx2Loader=null),this.loader.setKTX2Loader(void 0),this.configuredRenderer=null,this.ktx2TranscoderPath=null}normalizeTranscoderPath(e){if(!e)return null;let t=String(e);return t.endsWith("/")?t:`${t}/`}};import{FBXLoader as _}from"three/addons/loaders/FBXLoader.js";var T=class{loader;constructor(){this.loader=new _}isSupported(e){return c(e)==="fbx"}async load(e,t){return t?.useAsyncFetch?this.loadWithAsyncFetch(e,t):this.loadMainThread(e,t)}async loadWithAsyncFetch(e,t){try{let r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch ${e}: ${r.status} ${r.statusText}`);let a=await r.arrayBuffer(),o=this.loader.parse(a,e);return{object:o,animations:o.animations||[]}}catch(r){return console.error(`Async fetch FBX load failed for ${e}, falling back to loader.load():`,r),this.loadMainThread(e,t)}}async loadMainThread(e,t){return new Promise((r,a)=>{this.loader.load(e,o=>{r({object:o,animations:o.animations||[]})},o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>a(o))})}clone(e){return{object:u(e.object),animations:e.animations?.map(t=>t.clone())}}};import{OBJLoader as z}from"three/addons/loaders/OBJLoader.js";import{MTLLoader as Y}from"three/addons/loaders/MTLLoader.js";var y=class{loader;mtlLoader;constructor(){this.loader=new z,this.mtlLoader=new Y}isSupported(e){return c(e)==="obj"}async load(e,t){return t?.mtlPath&&await this.loadMTL(t.mtlPath),new Promise((r,a)=>{this.loader.load(e,o=>{r({object:o,animations:[]})},o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>a(o))})}async loadMTL(e){return new Promise((t,r)=>{this.mtlLoader.load(e,a=>{a.preload(),this.loader.setMaterials(a),t()},void 0,a=>r(a))})}clone(e){return{object:u(e.object),animations:[]}}};import{AudioLoader as q}from"three";var x=class{loader;constructor(){this.loader=new q}isSupported(e){let t=c(e);return["mp3","ogg","wav","flac","aac","m4a"].includes(t||"")}async load(e,t){return new Promise((r,a)=>{this.loader.load(e,o=>r(o),o=>{t?.onProgress&&o.lengthComputable&&t.onProgress(o.loaded/o.total)},o=>a(o))})}};import{FileLoader as Q}from"three";var m=class{loader;constructor(){this.loader=new Q}isSupported(e){return!0}async load(e,t){let r=t?.responseType??"text";return this.loader.setResponseType(r),new Promise((a,o)=>{this.loader.load(e,n=>a(n),n=>{t?.onProgress&&n.lengthComputable&&t.onProgress(n.loaded/n.total)},n=>o(n))})}},M=class{fileLoader;constructor(){this.fileLoader=new m}isSupported(e){return c(e)==="json"}async load(e,t){return await this.fileLoader.load(e,{...t,responseType:"json"})}};var w=class s{static instance=null;textureCache=new Map;modelCache=new Map;audioCache=new Map;fileCache=new Map;jsonCache=new Map;pendingGLTFRuntimePath=null;pendingGLTFRuntimePromise=null;pendingGLTFRuntimeResolve=null;textureLoader;gltfLoader;fbxLoader;objLoader;audioLoader;fileLoader;jsonLoader;loadingManager;events;stats={texturesLoaded:0,modelsLoaded:0,audioLoaded:0,filesLoaded:0,cacheHits:0,cacheMisses:0};constructor(){this.textureLoader=new L,this.gltfLoader=new g,this.fbxLoader=new T,this.objLoader=new y,this.audioLoader=new x,this.fileLoader=new m,this.jsonLoader=new M,this.loadingManager=new ee,this.loadingManager.onProgress=(e,t,r)=>{this.events.emit("batch:progress",{loaded:t,total:r})},this.events=R(),k.enabled=!0}static getInstance(){return s.instance||(s.instance=new s),s.instance}static resetInstance(){s.instance&&(s.instance.clearCache(),s.instance=null)}async loadTexture(e,t){return this.loadWithCache(e,"texture",this.textureCache,()=>this.textureLoader.load(e,t),t,r=>{if(!t?.clone)return r;let a=this.textureLoader.clone(r);return t.repeat&&a.repeat.copy(h(t.repeat,p)),t.wrapS!==void 0&&(a.wrapS=t.wrapS),t.wrapT!==void 0&&(a.wrapT=t.wrapT),a})}async loadGLTF(e,t){return await this.waitForPreparedGLTFRuntime(),this.loadWithCache(e,"gltf",this.modelCache,()=>this.gltfLoader.load(e,t),t,r=>t?.clone?this.gltfLoader.clone(r):r)}prepareGLTFRuntime(e){let t=this.normalizeTranscoderPath(e?.ktx2TranscoderPath);t&&(this.pendingGLTFRuntimePath===t&&this.pendingGLTFRuntimePromise||(this.pendingGLTFRuntimePath=t,this.pendingGLTFRuntimePromise||(this.pendingGLTFRuntimePromise=new Promise(r=>{this.pendingGLTFRuntimeResolve=r}))))}async configureGLTFRuntime(e){await this.gltfLoader.configureRuntime(e);let t=this.normalizeTranscoderPath(e?.ktx2TranscoderPath);t&&e?.renderer&&this.resolvePreparedGLTFRuntime(t)}async loadFBX(e,t){return this.loadWithCache(e,"fbx",this.modelCache,()=>this.fbxLoader.load(e,t),t,r=>t?.clone?this.fbxLoader.clone(r):r)}async loadOBJ(e,t){let r=t?.mtlPath?`${e}:${t.mtlPath}`:e;return this.loadWithCache(r,"obj",this.modelCache,()=>this.objLoader.load(e,t),t,a=>t?.clone?this.objLoader.clone(a):a)}async loadModel(e,t){let r=c(e);switch(r){case"gltf":case"glb":return this.loadGLTF(e,t);case"fbx":return this.loadFBX(e,t);case"obj":return this.loadOBJ(e,t);default:throw new Error(`Unsupported model format: ${r}`)}}async loadAudio(e,t){return this.loadWithCache(e,"audio",this.audioCache,()=>this.audioLoader.load(e,t),t)}async loadFile(e,t){let r=t?.responseType?`${e}:${t.responseType}`:e;return this.loadWithCache(r,"file",this.fileCache,()=>this.fileLoader.load(e,t),t)}async loadJSON(e,t){return this.loadWithCache(e,"json",this.jsonCache,()=>this.jsonLoader.load(e,t),t)}async loadBatch(e){let t=new Map,r=e.map(async a=>{try{let o;switch(a.type){case"texture":o=await this.loadTexture(a.url,a.options);break;case"gltf":o=await this.loadGLTF(a.url,a.options);break;case"fbx":o=await this.loadFBX(a.url,a.options);break;case"obj":o=await this.loadOBJ(a.url,a.options);break;case"audio":o=await this.loadAudio(a.url,a.options);break;case"file":o=await this.loadFile(a.url,a.options);break;case"json":o=await this.loadJSON(a.url,a.options);break;default:throw new Error(`Unknown asset type: ${a.type}`)}t.set(a.url,o)}catch(o){throw this.events.emit("asset:error",{url:a.url,type:a.type,error:o}),o}});return await Promise.all(r),this.events.emit("batch:complete",{urls:e.map(a=>a.url)}),t}async preload(e){await this.loadBatch(e)}isCached(e){return this.textureCache.has(e)||this.modelCache.has(e)||this.audioCache.has(e)||this.fileCache.has(e)||this.jsonCache.has(e)}clearCache(e){e?(this.textureCache.delete(e),this.modelCache.delete(e),this.audioCache.delete(e),this.fileCache.delete(e),this.jsonCache.delete(e)):(this.textureCache.clear(),this.modelCache.clear(),this.audioCache.clear(),this.fileCache.clear(),this.jsonCache.clear(),k.clear(),this.pendingGLTFRuntimePath=null,this.pendingGLTFRuntimePromise=null,this.pendingGLTFRuntimeResolve=null)}getStats(){return{...this.stats}}on(e,t){this.events.on(e,t)}off(e,t){this.events.off(e,t)}async loadWithCache(e,t,r,a,o,n){o?.forceReload&&r.delete(e);let i=r.get(e);if(i){this.stats.cacheHits++,this.events.emit("asset:loaded",{url:e,type:t,fromCache:!0});let l=await i.promise;return n?n(l):l}this.stats.cacheMisses++,this.events.emit("asset:loading",{url:e,type:t});let d=a(),f={promise:d,loadedAt:Date.now()};r.set(e,f);try{let l=await d;return f.result=l,this.updateStats(t),this.events.emit("asset:loaded",{url:e,type:t,fromCache:!1}),n?n(l):l}catch(l){throw r.delete(e),this.events.emit("asset:error",{url:e,type:t,error:l}),l}}updateStats(e){switch(e){case"texture":this.stats.texturesLoaded++;break;case"gltf":case"fbx":case"obj":this.stats.modelsLoaded++;break;case"audio":this.stats.audioLoaded++;break;case"file":case"json":this.stats.filesLoaded++;break}}async waitForPreparedGLTFRuntime(){this.pendingGLTFRuntimePromise&&await this.pendingGLTFRuntimePromise}resolvePreparedGLTFRuntime(e){this.pendingGLTFRuntimePath&&this.pendingGLTFRuntimePath!==e||(this.pendingGLTFRuntimeResolve?.(),this.pendingGLTFRuntimeResolve=null,this.pendingGLTFRuntimePromise=null,this.pendingGLTFRuntimePath=null)}normalizeTranscoderPath(e){if(!e)return null;let t=String(e);return t.endsWith("/")?t:`${t}/`}},A=w.getInstance();import{uniform as vt,uv as Ot,time as wt,vec3 as At,vec4 as Ft,float as Pt,Fn as St}from"three/tsl";function ae(s){return"colorNode"in s}function N(s){return"fragment"in s&&"vertex"in s}function oe(s){return!!s&&N(s)&&s.vertex===O.vertex&&s.fragment===O.fragment}var U=class s{static sharedMaterialMap=new Map;static clearSharedMaterialCache(){s.sharedMaterialMap.clear()}materials=[];useTSL;constructor(e=!0){this.useTSL=e}trackSharedMaterial(e,t){let r=E(G(e)),a=s.sharedMaterialMap.get(r);if(a){let o=a.geometryMap.get(t);o?a.geometryMap.set(t,o+1):a.geometryMap.set(t,1)}else s.sharedMaterialMap.set(r,{geometryMap:new Map([[t,1]]),material:this.materials[0]})}build(e,t){let{path:r,normalMap:a,repeat:o,color:n,shader:i,opacity:d}=e,f=oe(i),l=!!i&&!f,S=!!r&&(!i||f);S?this.setTexture(r??null,o,!0,d,n):l&&i?ae(i)?this.setTSLShader(i,d):N(i)&&(console.warn("MaterialBuilder: GLSL shaders are not supported on the WebGPU renderer. Author custom shaders as TSL (ZylemTSLShader). Falling back to a default node material."),this.setColor(n??new F("#ffffff"),!0,d)):r&&this.setTexture(r,o,!0,d,n),n&&!S&&!l&&this.withColor(n,!0,d),this.materials.length===0&&this.setColor(new F("#ffffff"),!0,d),a&&this.materials.length>0&&this.setNormalMap(a,o),this.trackSharedMaterial(e,t)}withColor(e,t=!1,r){return this.setColor(e,t,r),this}withShader(e,t){return this.setShader(e,t),this}withTSLShader(e,t){return this.setTSLShader(e,t),this}applyOpacity(e,t,r=!1){t!==void 0&&(e.opacity=t),e.transparent=r||t!==void 0&&t<1,e.needsUpdate=!0}setTexture(e=null,t=p,r=!0,a,o){if(!e)return;let n=new P;o&&(n.color=o),this.applyOpacity(n,a),this.materials.push(n),A.loadTexture(e,{clone:!0,repeat:h(t,p),colorSpace:te}).then(i=>{i.wrapS=v,i.wrapT=v,n.map=i,n.needsUpdate=!0})}setNormalMap(e,t=p){let r=this.materials[this.materials.length-1];r&&A.loadTexture(e,{clone:!0,repeat:h(t,p)}).then(a=>{a.wrapS=v,a.wrapT=v,r instanceof P&&(r.normalMap=a,r.needsUpdate=!0)})}setColor(e,t=!0,r){let a=new P;a.color=e,this.applyOpacity(a,r),this.materials.push(a)}setShader(e,t){console.warn("MaterialBuilder.setShader: GLSL shaders are not supported on the WebGPU renderer. Author custom shaders as TSL (ZylemTSLShader). Falling back to a default node material."),this.setColor(new F("#ffffff"),!0,t)}setTSLShader(e,t){this.materials.push(se(e,t))}};function se(s,e){let t=new re;return t.colorNode=s.colorNode,s.positionNode&&(t.positionNode=s.positionNode),s.normalNode&&(t.normalNode=s.normalNode),s.blending!==void 0&&(t.blending=s.blending),s.side!==void 0&&(t.side=s.side),s.depthTest!==void 0&&(t.depthTest=s.depthTest),e!==void 0&&(t.opacity=e),t.transparent=!!s.transparent||e!==void 0&&e<1,t.needsUpdate=!0,t}export{C as a,O as b,G as c,E as d,b as e,c as f,A as g,ae as h,N as i,U as j,se as k,vt as l,Ot as m,wt as n,At as o,Ft as p,Pt as q,St as r};
@@ -0,0 +1 @@
1
+ var n=new Map,i=new Set;function r(){for(let t of i)try{t()}catch(e){console.error("[zylem] entity registry listener failed",e)}}function y(t){return n.set(t.id,t),r(),()=>{n.get(t.id)===t&&(n.delete(t.id),r())}}function p(t){for(let e of t)n.set(e.id,e);return r(),()=>{for(let e of t)n.get(e.id)===e&&n.delete(e.id);r()}}function c(t){return n.get(t)??null}function o(){return[...n.values()]}function s(){return o().map(({create:t,...e})=>e)}function a(t){return i.add(t),()=>i.delete(t)}function d(){n.clear(),r()}export{y as a,p as b,c,o as d,s as e,a as f,d as g};
@@ -0,0 +1 @@
1
+ import{GridHelper as O,Group as X}from"three";var R=3094855,V=4871528,q=20,_=class{group=new X;scene=null;fine=null;coarse=null;increment=0;constructor(){this.group.name="__zylem_construction_grid__",this.group.renderOrder=-1,this.group.visible=!1}addTo(t){this.scene!==t&&(this.scene=t,t.add(this.group))}setIncrement(t){t<=0||t===this.increment||(this.increment=t,this.rebuild())}setVisible(t){this.group.visible=t}get visible(){return this.group.visible}dispose(){this.clearHelpers(),this.scene?.remove(this.group),this.scene=null}rebuild(){this.clearHelpers();let t=q*2,i=Math.round(t/this.increment);i>0&&i<=400&&(this.fine=new O(t,i,R,R),this.fine.material.transparent=!0,this.fine.material.opacity=.35,this.fine.material.depthWrite=!1,this.group.add(this.fine)),this.coarse=new O(t,t,V,V),this.coarse.material.transparent=!0,this.coarse.material.opacity=.6,this.coarse.material.depthWrite=!1,this.group.add(this.coarse)}clearHelpers(){for(let t of[this.fine,this.coarse])t&&(this.group.remove(t),t.geometry.dispose(),t.material.dispose());this.fine=null,this.coarse=null}};import{BoxGeometry as y,ConeGeometry as W,CylinderGeometry as f,Group as d,Mesh as m,MeshBasicMaterial as D,PlaneGeometry as C,Quaternion as Q,Raycaster as Z,TorusGeometry as S,Vector3 as l}from"three";var H={x:16726867,y:5036364,z:3900150,xy:3900150,yz:16726867,xz:5036364,xyz:14540253},J=16765499,I=.16,h={x:new l(1,0,0),y:new l(0,1,0),z:new l(0,0,1)},z={xy:new l(0,0,1),yz:new l(1,0,0),xz:new l(0,1,0)},A=12,K=Math.sqrt(1-1/A),w=1/A;function U(n,t){return Math.abs(n.dot(t))>K}function M(n,t,i){let e=k.copy(n.origin).sub(t),s=n.direction.dot(i),o=1-s*s;return o<1/A?null:(e.dot(i)-s*e.dot(n.direction))/o}function x(n,t,i,e){let s=i.dot(n.direction);if(Math.abs(s)<w)return null;let o=k.copy(t).sub(n.origin).dot(i)/s;return o<0?null:e.copy(n.direction).multiplyScalar(o).add(n.origin)}var k=new l,G=new l,Y=new l,j=new l,T=new Q,B=class{root=new d;scene=null;modeGroups={translate:new d,rotate:new d,scale:new d};handles={translate:[],rotate:[],scale:[]};materials=[];geometries=[];mode="translate";highlighted=null;drag=null;raycaster=new Z;constructor(){this.root.name="__zylem_transform_gizmo__",this.root.renderOrder=1e3,this.root.visible=!1,this.buildTranslate(),this.buildRotate(),this.buildScale();for(let t of Object.keys(this.modeGroups))this.root.add(this.modeGroups[t]);this.applyModeVisibility()}addTo(t){this.scene!==t&&(this.scene=t,t.add(this.root))}removeFromScene(){this.scene&&(this.scene.remove(this.root),this.scene=null)}dispose(){this.removeFromScene();for(let t of this.geometries)t.dispose();for(let t of this.materials)t.dispose();this.geometries=[],this.materials=[]}setMode(t){this.mode!==t&&(this.mode=t,this.applyModeVisibility())}getMode(){return this.mode}show(t){this.root.position.copy(t),this.root.visible=!0}hide(){this.root.visible=!1,this.setHighlight(null)}get visible(){return this.root.visible}get pivot(){return this.root.position}update(t){if(!this.root.visible)return;let i;if(t.isPerspectiveCamera){let e=t;j.setFromMatrixPosition(e.matrixWorld),i=2*j.distanceTo(this.root.position)*Math.tan(e.fov*Math.PI/360)*I}else if(t.isOrthographicCamera){let e=t;i=(e.top-e.bottom)/(e.zoom||1)*I}else i=1;this.root.scale.setScalar(Math.max(i,1e-4))}pick(t){if(!this.root.visible)return null;this.raycaster.set(t.origin,t.direction);let i=this.handles[this.mode].filter(s=>this.isHandleDraggable(s.axis,t)).map(s=>s.picker),e=this.raycaster.intersectObjects(i,!1);return e.length?e[0].object.userData.gizmoAxis??null:null}isHandleDraggable(t,i){if(t==="xyz")return!0;if(this.isPlaneAxis(t))return Math.abs(i.direction.dot(z[t]))>=w;let e=h[t];return this.mode==="rotate"?Math.abs(i.direction.dot(e))>=w:!U(i.direction,e)}setHighlight(t){if(this.highlighted!==t){this.highlighted=t;for(let i of Object.keys(this.handles))for(let e of this.handles[i]){let s=e.axis===t?J:H[e.axis];for(let o of e.visuals)o.material.color.setHex(s)}}}beginDrag(t,i,e){let s=this.root.position.clone(),o={axis:t,mode:this.mode,pivot:s,startAxisValue:0,startPoint:new l,startAngle:0,startRadius:0};if(t==="xyz"){let r=this.cameraPlaneRadius(i,s,e);if(r===null||r<1e-4)return!1;o.startRadius=r}else if(this.isPlaneAxis(t)){let r=z[t];if(!x(i,s,r,o.startPoint))return!1}else if(this.mode==="rotate"){let r=h[t],a=this.angleOnPlane(i,s,r);if(a===null)return!1;o.startAngle=a}else{let r=M(i,s,h[t]);if(r===null||(o.startAxisValue=r,this.mode==="scale"&&Math.abs(r)<1e-4))return!1}return this.drag=o,this.setHighlight(t),!0}updateDrag(t,i){let e=this.drag;if(!e)return null;if(e.mode==="rotate"){let r=h[e.axis]??h.y,a=this.angleOnPlane(t,e.pivot,r);return a===null?null:{kind:"rotate",axis:r.clone(),angle:a-e.startAngle}}if(e.mode==="scale"){if(e.axis==="xyz"){let u=this.cameraPlaneRadius(t,e.pivot,i);if(u===null)return null;let p=u/e.startRadius;return{kind:"scale",factor:new l(p,p,p)}}let r=M(t,e.pivot,h[e.axis]);if(r===null)return null;let a=r/e.startAxisValue,c=new l(1,1,1);return c[e.axis]=a,{kind:"scale",factor:c}}if(this.isPlaneAxis(e.axis)){let r=z[e.axis],a=x(t,e.pivot,r,G);return a?{kind:"translate",offset:a.clone().sub(e.startPoint)}:null}let s=h[e.axis],o=M(t,e.pivot,s);return o===null?null:{kind:"translate",offset:s.clone().multiplyScalar(o-e.startAxisValue)}}endDrag(){this.drag=null,this.setHighlight(null)}get isDragging(){return this.drag!==null}get draggingAxis(){return this.drag?.axis??null}isPlaneAxis(t){return t==="xy"||t==="yz"||t==="xz"}angleOnPlane(t,i,e){let s=x(t,i,e,G);if(!s)return null;let o=Y.copy(s).sub(i);if(o.lengthSq()<1e-8)return null;let r=Math.abs(e.y)>.9?h.x:h.y,a=k.copy(r).cross(e).normalize(),c=new l().copy(e).cross(a);return Math.atan2(o.dot(c),o.dot(a))}cameraPlaneRadius(t,i,e){T.setFromRotationMatrix(e.matrixWorld);let s=new l(0,0,1).applyQuaternion(T),o=x(t,i,s,G);return o?o.distanceTo(i):null}applyModeVisibility(){for(let t of Object.keys(this.modeGroups))this.modeGroups[t].visible=t===this.mode}makeMaterial(t,i){let e=new D({color:H[t],transparent:!0,opacity:i,depthTest:!1,depthWrite:!1,toneMapped:!1});return this.materials.push(e),e}track(t){return this.geometries.push(t),t}makePicker(t,i,e){let s=new D({visible:!1});this.materials.push(s);let o=new m(this.track(i),s);return o.visible=!1,o.userData.gizmoAxis=t,e(o),o}orientAlongAxis(t,i){i==="x"&&(t.rotation.z=-Math.PI/2),i==="z"&&(t.rotation.x=Math.PI/2)}buildTranslate(){let t=this.modeGroups.translate;for(let i of["x","y","z"]){let e=this.makeMaterial(i,1),s=new m(this.track(new f(.012,.012,.7,8)),e);s.position.y=.35;let o=new m(this.track(new W(.045,.16,12)),e);o.position.y=.78;let r=new d;r.add(s,o),this.orientAlongAxis(r,i);let a=this.makePicker(i,new f(.1,.1,.9,6),u=>{u.position.y=.45}),c=new d;c.add(a),this.orientAlongAxis(c,i),t.add(r,c),this.handles.translate.push({axis:i,visuals:[s,o],picker:a})}for(let i of["xy","yz","xz"]){let e=this.makeMaterial(i,.35),s=new m(this.track(new C(.22,.22)),e);this.positionPlaneHandle(s,i);let o=this.makePicker(i,new C(.22,.22),r=>{this.positionPlaneHandle(r,i)});t.add(s,o),this.handles.translate.push({axis:i,visuals:[s],picker:o})}}positionPlaneHandle(t,i){i==="xy"?t.position.set(.28,.28,0):i==="yz"?(t.position.set(0,.28,.28),t.rotation.y=Math.PI/2):(t.position.set(.28,0,.28),t.rotation.x=-Math.PI/2)}buildRotate(){let t=this.modeGroups.rotate;for(let i of["x","y","z"]){let e=this.makeMaterial(i,1),s=new m(this.track(new S(.68,.01,6,64)),e);this.orientRing(s,i);let o=this.makePicker(i,new S(.68,.08,4,24),r=>this.orientRing(r,i));t.add(s,o),this.handles.rotate.push({axis:i,visuals:[s],picker:o})}}orientRing(t,i){i==="x"&&(t.rotation.y=Math.PI/2),i==="y"&&(t.rotation.x=Math.PI/2)}buildScale(){let t=this.modeGroups.scale;for(let o of["x","y","z"]){let r=this.makeMaterial(o,1),a=new m(this.track(new f(.012,.012,.7,8)),r);a.position.y=.35;let c=new m(this.track(new y(.09,.09,.09)),r);c.position.y=.74;let u=new d;u.add(a,c),this.orientAlongAxis(u,o);let p=this.makePicker(o,new f(.1,.1,.85,6),F=>{F.position.y=.43}),b=new d;b.add(p),this.orientAlongAxis(b,o),t.add(u,b),this.handles.scale.push({axis:o,visuals:[a,c],picker:p})}let i=this.makeMaterial("xyz",.9),e=new m(this.track(new y(.13,.13,.13)),i),s=this.makePicker("xyz",new y(.22,.22,.22),()=>{});t.add(e,s),this.handles.scale.push({axis:"xyz",visuals:[e],picker:s})}};import{Box3 as $,PerspectiveCamera as tt,Vector3 as v}from"three";var P=new $,g=new v,E=new v,et=new v;function N(n){P.setFromObject(n),P.getSize(g),P.getCenter(E);let t=Math.max(g.x,1e-4),i=Math.max(g.y,1e-4),e=Math.max(g.z,1e-4),s=Math.max(t,i,e);return{width:t,height:i,depth:e,center:E.clone(),maxDim:s}}function L(n,t,i=1.35){let e=t.fov*(Math.PI/180),s=n/(2*Math.tan(e/2))*i;return Math.max(s,.5)}function ct(n,t,i=1.35){let e=N(n),s=L(e.maxDim,t,i);return t.position.copy(e.center).add(new v(s,s,s)),t.lookAt(e.center),t.near=Math.max(s/100,.01),t.far=Math.max(s*20,100),t.updateProjectionMatrix(),e}function ht(n,t,i,e=1.5){let s=N(n),o=et.copy(i);o.lengthSq()<1e-8&&o.set(1,1,1),o.normalize();let r=s.maxDim*e;return t instanceof tt&&(r=L(s.maxDim,t,e),t.near=Math.max(r/100,.01),t.far=Math.max(r*20,100),t.updateProjectionMatrix()),t.position.copy(s.center).addScaledVector(o,r),t.lookAt(s.center),s}export{ct as a,ht as b,_ as c,M as d,x as e,B as f};
@@ -0,0 +1 @@
1
+ import{b as R,c as gt,d as ft,e as bt,f as xt,g as Ot,h as wt,j as St,r as p,s as f,t as c,v as b,w as N,x as $,y as D,z as T}from"./chunk-SAQA4SXW.js";import{j as vt}from"./chunk-7NYP4YAG.js";import{d as V}from"./chunk-4QLJUQSJ.js";import{b as j,c as dt,d as yt,h as q,i as E}from"./chunk-7WRQ2UAN.js";import{BoxGeometry as qt,CapsuleGeometry as Jt,ConeGeometry as Ct,CylinderGeometry as Kt,Mesh as z,MeshStandardMaterial as Qt,SphereGeometry as te}from"three";function B(e,t=Symbol("mesh")){if(e.material||e.color){let i=new vt;if(i.build({...e.material,color:e.color??e.material?.color},t),i.materials.length>0)return i.materials}return[new Qt]}function L(e,t){if(t.position){let i=q(t.position,dt);e.position.set(i.x,i.y,i.z)}return e.castShadow=!0,e.receiveShadow=!0,e}function Mt(e={}){let t=q(e.size,yt),i=new qt(t.x,t.y,t.z),o=B(e);return L(new z(i,o.at(-1)),e)}function Pt(e={}){let t=new te(e.radius??1),i=B(e);return L(new z(t,i.at(-1)),e)}function Zt(e={}){let t=new Ct(e.radius??1,e.height??2,e.radialSegments??32),i=B(e);return L(new z(t,i.at(-1)),e)}function Et(e={}){let t=new Ct(e.radius??1,e.height??2,4),i=B(e);return L(new z(t,i.at(-1)),e)}function _t(e={}){let t=new Kt(e.radiusTop??1,e.radiusBottom??1,e.height??2,e.radialSegments??32),i=B(e);return L(new z(t,i.at(-1)),e)}function Rt(e={}){let t=new Jt(e.radius??.5,e.length??1,e.capSegments??10,e.radialSegments??20),i=B(e);return L(new z(t,i.at(-1)),e)}import{Vector3 as se}from"three";import{MeshStandardMaterial as ee,MeshBasicMaterial as ie,MeshPhongMaterial as oe}from"three";function ne(e){return e&&typeof e.getDebugInfo=="function"}var u=class{entity;constructor(t){this.entity=t}getPositionString(){if(this.entity.mesh){let{x:n,y:s,z:l}=this.entity.mesh.position;return`${n.toFixed(2)}, ${s.toFixed(2)}, ${l.toFixed(2)}`}let{x:t,y:i,z:o}=this.entity.options.position||{x:0,y:0,z:0};return`${t.toFixed(2)}, ${i.toFixed(2)}, ${o.toFixed(2)}`}getRotationString(){if(this.entity.mesh){let{x:s,y:l,z:r}=this.entity.mesh.rotation,a=m=>(m*180/Math.PI).toFixed(1);return`${a(s)}\xB0, ${a(l)}\xB0, ${a(r)}\xB0`}let{x:t,y:i,z:o}=this.entity.options.rotation||{x:0,y:0,z:0},n=s=>(s*180/Math.PI).toFixed(1);return`${n(t)}\xB0, ${n(i)}\xB0, ${n(o)}\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,i={type:t.type};return(t instanceof ee||t instanceof ie||t instanceof oe)&&(i.color=`#${t.color.getHexString()}`,i.opacity=t.opacity,i.transparent=t.transparent),"roughness"in t&&(i.roughness=t.roughness),"metalness"in t&&(i.metalness=t.metalness),i}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()},i=this.entity.body.linvel();return t.velocity=`${i.x.toFixed(2)}, ${i.y.toFixed(2)}, ${i.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()},i=this.getPhysicsInfo();if(i&&(t.physics=i),ne(this.entity)){let o=this.entity.getDebugInfo();return{...t,...o}}return t}};var Dt={...p,size:new se(1,1,1)},re=Symbol("Box"),J=class e extends c{static type=re;constructor(t){super(),this.options={...Dt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),{x:o,y:n,z:s}=this.options.size??{x:1,y:1,z:1};return{...i,type:String(e.type),size:`${o}, ${n}, ${s}`}}};function ae(...e){let t=f(e,Dt),i=new J(t);return i.add(Mt({size:t.size,material:t.material,color:t.color}),gt({size:t.size,static:t.collision?.static,sensor:t.collision?.sensor,canSleep:t.collision?.canSleep,ccdEnabled:t.collision?.ccdEnabled,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>ae(o??{}))}var Tt={...p,radius:1},le=Symbol("Sphere"),K=class e extends c{static type=le;constructor(t){super(),this.options={...Tt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.radius??1;return{...i,type:String(e.type),radius:o.toFixed(2)}}};function ce(...e){let t=f(e,Tt),i=new K(t);return i.add(Pt({radius:t.radius,material:t.material,color:t.color}),ft({radius:t.radius,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>ce(o??{}))}var zt={...p,radius:1,height:2,radialSegments:32},he=Symbol("Cone"),Q=class e extends c{static type=he;constructor(t){super(),this.options={...zt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.radius??1,n=this.options.height??2;return{...i,type:String(e.type),radius:o.toFixed(2),height:n.toFixed(2)}}};function me(...e){let t=f(e,zt),i=new Q(t);return i.add(Zt({radius:t.radius,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),bt({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>me(o??{}))}var Bt={...p,radius:1,height:2},pe=Symbol("Pyramid"),tt=class e extends c{static type=pe;constructor(t){super(),this.options={...Bt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.radius??1,n=this.options.height??2;return{...i,type:String(e.type),radius:o.toFixed(2),height:n.toFixed(2)}}};function ue(...e){let t=f(e,Bt),i=new tt(t);return i.add(Et({radius:t.radius,height:t.height,material:t.material,color:t.color}),xt({radius:t.radius,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>ue(o??{}))}var Lt={...p,radiusTop:1,radiusBottom:1,height:2,radialSegments:32},de=Symbol("Cylinder"),et=class e extends c{static type=de;constructor(t){super(),this.options={...Lt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.radiusTop??1,n=this.options.radiusBottom??1,s=this.options.height??2;return{...i,type:String(e.type),radiusTop:o.toFixed(2),radiusBottom:n.toFixed(2),height:s.toFixed(2)}}};function ye(...e){let t=f(e,Lt),i=new et(t);return i.add(_t({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,radialSegments:t.radialSegments,material:t.material,color:t.color}),Ot({radiusTop:t.radiusTop,radiusBottom:t.radiusBottom,height:t.height,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>ye(o??{}))}var It={...p,radius:.5,length:1,capSegments:10,radialSegments:20},ge=Symbol("Pill"),it=class e extends c{static type=ge;constructor(t){super(),this.options={...It,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.radius??.5,n=this.options.length??1;return{...i,type:String(e.type),radius:o.toFixed(2),length:n.toFixed(2)}}};function fe(...e){let t=f(e,It),i=new it(t);return i.add(Rt({radius:t.radius,length:t.length,capSegments:t.capSegments,radialSegments:t.radialSegments,material:t.material,color:t.color}),wt({radius:t.radius,length:t.length,static:t.collision?.static,sensor:t.collision?.sensor,gravityScale:t.collision?.gravityScale,lockRotations:t.collision?.lockRotations,lockTranslations:t.collision?.lockTranslations,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>fe(o??{}))}import{Group as be,RingGeometry as xe}from"three";var kt={...p,innerRadius:0,outerRadius:1,thetaSegments:32},ot=class extends N{collider(t){let i=t.outerRadius??1;return{shape:{type:"cylinder",halfHeight:.1/2,radius:i}}}},nt=class extends ${build(t){let i=t.innerRadius??0,o=t.outerRadius??1,n=t.thetaSegments??32,s=new xe(i,o,n);return s.rotateX(-Math.PI/2),s}},st=class extends D{createEntity(t){return new F(t)}build(){let t=super.build();return t.mesh&&!t.group&&(t.group=new be,t.group.add(t.mesh)),t}},Oe=Symbol("Disk"),F=class e extends c{static type=Oe;constructor(t){super(),this.options={...kt,...t}}buildInfo(){let i=new u(this).buildDebugInfo(),o=this.options.innerRadius??0,n=this.options.outerRadius??1;return{...i,type:String(e.type),innerRadius:o.toFixed(2),outerRadius:n.toFixed(2)}}};function we(...e){return T({args:e,defaultConfig:kt,EntityClass:F,BuilderClass:st,MeshBuilderClass:nt,CollisionBuilderClass:ot,entityType:F.type,cloneFactory:t=>we(t??{})})}import{PlaneGeometry as ve,Vector2 as Ft,Vector3 as Gt}from"three";import{BufferGeometry as Se,Float32BufferAttribute as rt}from"three";var X=class e extends Se{constructor(t=1,i=1,o=1,n=1){super(),this.type="XZPlaneGeometry",this.parameters={width:t,height:i,widthSegments:o,heightSegments:n};let s=t/2,l=i/2,r=Math.floor(o),a=Math.floor(n),m=r+1,C=a+1,M=t/r,x=i/a,O=[],w=[],d=[],P=[];for(let y=0;y<C;y++){let h=y*x-l;for(let S=0;S<m;S++){let Z=S*M-s;w.push(Z,0,h),d.push(0,1,0),P.push(S/r),P.push(1-y/a)}}for(let y=0;y<a;y++)for(let h=0;h<r;h++){let S=h+m*y,Z=h+m*(y+1),g=h+1+m*(y+1),v=h+1+m*y;O.push(S,Z,v),O.push(Z,g,v)}this.setIndex(O),this.setAttribute("position",new rt(w,3)),this.setAttribute("normal",new rt(d,3)),this.setAttribute("uv",new rt(P,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new e(t.width,t.height,t.widthSegments,t.heightSegments)}};var Y=4,Ht={...p,tile:new Ft(10,10),repeat:new Ft(1,1),collision:{static:!0},subdivisions:Y,randomizeHeight:!1,heightScale:1};function At(e){let t=e.subdivisions??Y,i=e.heightMap2D,o=e.heightMap,n=e.subdivisionsX??t,s=e.subdivisionsZ??t;return i&&i.length>0&&i[0]?.length>0?(s=i.length-1,n=i[0].length-1):o&&o.length>0&&(n=o.length-1),{subdivisionsX:n,subdivisionsZ:s}}var at=class extends N{collider(t){let i=E(t.tile,j),{subdivisionsX:o,subdivisionsZ:n}=At(t),s=new Gt(i.x,1,i.y),l=t._builders?.meshBuilder?.heightData??new Float32Array((o+1)*(n+1));return{shape:{type:"heightfield",rows:o,cols:n,heights:l,scale:[s.x,1,s.z]}}}},lt=class extends ${heightData=new Float32Array;columnsRows=new Map;subdivisionsX=Y;subdivisionsZ=Y;build(t){let i=E(t.tile,j),{subdivisionsX:o,subdivisionsZ:n}=At(t);this.subdivisionsX=o,this.subdivisionsZ=n;let s=new Gt(i.x,1,i.y),l=t.heightScale??1,r=new X(s.x,s.z,o,n),a=new ve(s.x,s.z,o,n),m=o>0?s.x/o:1,C=n>0?s.z/n:1,M=r.attributes.position.array,x=a.attributes.position.array,O=new Map,w=t.heightMap2D,d=t.heightMap,P=t.randomizeHeight??!1,y=(h,S)=>h<0?0:h>S?S:h;for(let h=0;h<x.length;h+=3){let S=x[h],Z=x[h+1],g=y(Math.round((S+s.x/2)/m),o),v=y(Math.round((s.z/2-Z)/C),n),_=0;if(w){let ut=w[v];ut&&(_=ut[g]??0)}else d&&d.length>0?_=d[g]??0:P&&(_=Math.random()*4);let k=_*l;x[h+2]=k,M[h+1]=k,O.get(v)||O.set(v,new Map),O.get(v).set(g,k)}return this.columnsRows=O,r}postBuild(){let t=[];for(let i=0;i<=this.subdivisionsX;++i)for(let o=0;o<=this.subdivisionsZ;++o){let n=this.columnsRows.get(o);t.push(n?.get(i)??0)}this.heightData=new Float32Array(t)}},ct=class extends D{createEntity(t){return new G(t)}},Ce=Symbol("Plane"),G=class extends c{static type=Ce;constructor(t){super(),this.options=R(Ht,t)}};function Me(...e){return T({args:e,defaultConfig:Ht,EntityClass:G,BuilderClass:ct,MeshBuilderClass:lt,CollisionBuilderClass:at,entityType:G.type,cloneFactory:t=>Me(t??{})})}import{Vector3 as Pe}from"three";var Vt={...p,size:new Pe(1,1,1),collision:{static:!0}},Ze=Symbol("Zone"),ht=class extends c{static type=Ze;_enteredZone=new Map;_exitedZone=new Map;_zoneEntities=new Map;constructor(t){super(),this.options=R(Vt,t)}handlePostCollision({delta:t}){return this._enteredZone.forEach((i,o)=>{this.exited(t,o)}),this._enteredZone.size>0}handleIntersectionEvent({other:t,delta:i}){this._enteredZone.get(t.uuid)?this.held(i,t):(this.entered(t),this._zoneEntities.set(t.uuid,t))}onEnter(t){return this.options.onEnter=t,this}onHeld(t){return this.options.onHeld=t,this}onExit(t){return this.options.onExit=t,this}entered(t){this._enteredZone.set(t.uuid,1),this.options.onEnter&&this.options.onEnter({self:this,visitor:t,globals:V.globals})}exited(t,i){let o=this._exitedZone.get(i);if(o&&o>1+t){this._exitedZone.delete(i),this._enteredZone.delete(i);let n=this._zoneEntities.get(i);this.options.onExit&&this.options.onExit({self:this,visitor:n,globals:V.globals});return}this._exitedZone.set(i,1+t)}held(t,i){let o=this._enteredZone.get(i.uuid)??0;this._enteredZone.set(i.uuid,o+t),this._exitedZone.set(i.uuid,1),this.options.onHeld&&this.options.onHeld({delta:t,self:this,visitor:i,globals:V.globals,heldTime:o})}};function Ee(...e){let t=f(e,Vt),i=new ht(t);return i.add(St({size:t.size,static:t.collision?.static??!0,collisionType:t.collisionType,collisionFilter:t.collisionFilter})),b(i,o=>Ee(o??{}))}import{Color as Nt,Group as _e,Sprite as Re,SpriteMaterial as De,CanvasTexture as $t,LinearFilter as W,Vector2 as U,ClampToEdgeWrapping as Xt,ShaderMaterial as Yt,Mesh as Te,PlaneGeometry as ze,Vector3 as Wt}from"three";var I={position:void 0,width:120,height:48,fillColor:"#FFFFFF",strokeColor:null,strokeWidth:0,radius:0,padding:0,stickToViewport:!0,screenPosition:new U(24,24),zDistance:1,anchor:new U(0,0)},mt=class extends D{createEntity(t){return new H(t)}},Be=Symbol("Rect"),H=class e extends c{static type=Be;_sprite=null;_mesh=null;_texture=null;_canvas=null;_ctx=null;_cameraRef=null;_lastCanvasW=0;_lastCanvasH=0;constructor(t){super(),this.options=R(I,t),this.options.screenPosition=E(this.options.screenPosition,I.screenPosition),this.options.anchor=E(this.options.anchor,I.anchor),this.group=new _e,this.createSprite(),this.prependSetup(this.rectSetup.bind(this)),this.prependUpdate(this.rectUpdate.bind(this))}createSprite(){this._canvas=document.createElement("canvas"),this._ctx=this._canvas.getContext("2d"),this._texture=new $t(this._canvas),this._texture.minFilter=W,this._texture.magFilter=W;let t=new De({map:this._texture,transparent:!0,depthTest:!1,depthWrite:!1,alphaTest:.5});this._sprite=new Re(t),this.group?.add(this._sprite),this.redrawRect()}redrawRect(){if(!this._canvas||!this._ctx)return;let t=Math.max(2,Math.floor(this.options.width??120)),i=Math.max(2,Math.floor(this.options.height??48)),o=this.options.padding??0,n=this.options.strokeWidth??0,s=t+o*2+n,l=i+o*2+n,r=Math.max(2,s),a=Math.max(2,l),m=r!==this._lastCanvasW||a!==this._lastCanvasH;this._canvas.width=r,this._canvas.height=a,this._lastCanvasW=r,this._lastCanvasH=a,this._ctx.clearRect(0,0,this._canvas.width,this._canvas.height);let C=Math.max(0,this.options.radius??0),M=Math.floor(o+n/2),x=Math.floor(o+n/2),O=Math.floor(t),w=Math.floor(i);if(this._ctx.beginPath(),C>0?this.roundedRectPath(this._ctx,M,x,O,w,C):this._ctx.rect(M,x,O,w),this.options.fillColor&&(this._ctx.fillStyle=this.toCssColor(this.options.fillColor),this._ctx.fill()),this.options.strokeColor&&n>0&&(this._ctx.lineWidth=n,this._ctx.strokeStyle=this.toCssColor(this.options.strokeColor),this._ctx.stroke()),this._texture){if(m&&(this._texture.dispose(),this._texture=new $t(this._canvas),this._texture.minFilter=W,this._texture.magFilter=W,this._texture.wrapS=Xt,this._texture.wrapT=Xt,this._sprite&&this._sprite.material instanceof Yt)){let d=this._sprite.material;d.uniforms?.tDiffuse&&(d.uniforms.tDiffuse.value=this._texture),d.uniforms?.iResolution&&d.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)}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)}}getWidth(){return this.options.width??0}getHeight(){return this.options.height??0}roundedRectPath(t,i,o,n,s,l){let r=Math.min(l,Math.floor(Math.min(n,s)/2));t.moveTo(i+r,o),t.lineTo(i+n-r,o),t.quadraticCurveTo(i+n,o,i+n,o+r),t.lineTo(i+n,o+s-r),t.quadraticCurveTo(i+n,o+s,i+n-r,o+s),t.lineTo(i+r,o+s),t.quadraticCurveTo(i,o+s,i,o+s-r),t.lineTo(i,o+r),t.quadraticCurveTo(i,o,i+r,o)}toCssColor(t){return typeof t=="string"?t:`#${(t instanceof Nt?t:new Nt(t)).getHexString()}`}getResolution(){try{let t=this._cameraRef?.renderer?.domElement;if(t)return{width:t.clientWidth||1,height:t.clientHeight||1}}catch{}return{width:this._cameraRef?.screenResolution?.x??1,height:this._cameraRef?.screenResolution?.y??1}}rectSetup(t){if(this._cameraRef=t.camera,this.options.stickToViewport&&this._cameraRef&&this._cameraRef.camera.add(this.group),this.materials?.length&&this._sprite){let i=this.materials[0];i instanceof Yt&&(i.transparent=!0,i.depthTest=!1,i.depthWrite=!1,this._texture&&(i.uniforms?.tDiffuse&&(i.uniforms.tDiffuse.value=this._texture),i.uniforms?.iResolution&&this._canvas&&i.uniforms.iResolution.value.set(this._canvas.width,this._canvas.height,1)),this._mesh=new Te(new ze(1,1),i),this.group?.add(this._mesh),this._sprite.visible=!1)}}rectUpdate(t){if(this._sprite){if(this._cameraRef&&this.options.bounds){let i=this.computeScreenBoundsFromOptions(this.options.bounds);if(i){let{x:o,y:n,width:s,height:l}=i,r=Math.max(2,Math.floor(s)),a=Math.max(2,Math.floor(l)),m=r!==(this.options.width??0)||a!==(this.options.height??0);this.options.screenPosition=new U(Math.floor(o),Math.floor(n)),this.options.width=r,this.options.height=a,this.options.anchor=new U(0,0),m&&this.redrawRect()}}this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}}updateStickyTransform(){if(!this._sprite||!this._cameraRef)return;let t=this._cameraRef.camera,{width:i,height:o}=this.getResolution(),n=E(this.options.screenPosition,I.screenPosition),s=n.x,l=n.y,r=Math.max(.001,this.options.zDistance??1),a=1,m=1;if(t.isPerspectiveCamera){let g=t,v=Math.tan(g.fov*Math.PI/180/2)*r;a=v*g.aspect,m=v}else if(t.isOrthographicCamera){let g=t;a=(g.right-g.left)/2,m=(g.top-g.bottom)/2}let C=s/i*2-1,M=1-l/o*2,x=C*a,O=M*m,w=1,d=1;if(this._canvas){let v=m*2/o,_=this._canvas.height;d=Math.max(1e-4,_*v);let k=this._canvas.width/this._canvas.height;w=d*k,this._sprite.scale.set(w,d,1),this._mesh&&this._mesh.scale.set(w,d,1)}let P=E(this.options.anchor,I.anchor),y=Math.min(100,Math.max(0,P.x))/100,h=Math.min(100,Math.max(0,P.y))/100,S=(.5-y)*w,Z=(h-.5)*d;this.group?.position.set(x+S,O+Z,-r)}worldToScreen(t){if(!this._cameraRef)return{x:0,y:0};let i=this._cameraRef.camera,{width:o,height:n}=this.getResolution(),s=t.clone().project(i),l=(s.x+1)/2*o,r=(1-s.y)/2*n;return{x:l,y:r}}computeScreenBoundsFromOptions(t){if(!this._cameraRef)return null;if(t.screen)return{...t.screen};if(t.world){let{left:i,right:o,top:n,bottom:s,z:l=0}=t.world,r=this.worldToScreen(new Wt(i,n,l)),a=this.worldToScreen(new Wt(o,s,l)),m=Math.min(r.x,a.x),C=Math.min(r.y,a.y),M=Math.abs(a.x-r.x),x=Math.abs(a.y-r.y);return{x:m,y:C,width:M,height:x}}return null}updateRect(t){this.options={...this.options,...t},this.redrawRect(),this.options.stickToViewport&&this._cameraRef&&this.updateStickyTransform()}buildInfo(){return{...new u(this).buildDebugInfo(),type:String(e.type),width:this.options.width??0,height:this.options.height??0,sticky:this.options.stickToViewport}}};function Le(...e){return T({args:e,defaultConfig:{...I},EntityClass:H,BuilderClass:mt,entityType:H.type,cloneFactory:t=>Le(t??{})})}import{AmbientLight as Ie,DirectionalLight as ke,Group as Fe,HemisphereLight as Ge,Object3D as He,PointLight as Ae,SpotLight as Ve}from"three";var Ne=Symbol("Light"),$e={x:0,y:0,z:0},A=16777215,Xe={mapSize:2048,near:.1,far:500,bias:0,radius:1,left:-100,right:100,top:100,bottom:-100},Ye={mapSize:1024,near:.1,far:500,bias:0,radius:1},pt=class extends c{static type=Ne;light=null;lightTarget=null;constructor(t){super(),this.options={...t}}create(){super.create();let t=new Fe,{light:i,target:o}=We(this.options);return t.add(i),o&&t.add(o),this.group=t,this.light=i,this.lightTarget=o,this}_cleanup(t){this.light?.shadow?.map?.dispose?.(),this.light=null,this.lightTarget=null,super._cleanup(t)}};function We(e){switch(e.type){case"ambient":return{light:Ue(e),target:null};case"hemisphere":return{light:je(e),target:null};case"directional":return qe(e);case"point":return{light:Je(e),target:null};case"spot":return Ke(e)}}function Ue(e){let t=new Ie(e.color??A,e.intensity??1);return e.name&&(t.name=e.name),t}function je(e){let t=e.skyColor??e.color??A,i=e.groundColor??0,o=new Ge(t,i,e.intensity??1);return e.name&&(o.name=e.name),o}function qe(e){let t=new ke(e.color??A,e.intensity??1);e.name&&(t.name=e.name),Qe(t,e.castShadow??!1,e.shadow);let i=Ut(e.position,e.target);return i&&(t.target=i),{light:t,target:i}}function Je(e){let t=new Ae(e.color??A,e.intensity??1,e.distance,e.decay);return e.name&&(t.name=e.name),jt(t,e.castShadow??!1,e.shadow),t}function Ke(e){let t=new Ve(e.color??A,e.intensity??1,e.distance,e.angle,e.penumbra,e.decay);e.name&&(t.name=e.name),jt(t,e.castShadow??!1,e.shadow);let i=Ut(e.position,e.target);return i&&(t.target=i),{light:t,target:i}}function Ut(e,t){if(!t)return null;let i=e??$e,o=new He;return o.position.set(t.x-i.x,t.y-i.y,t.z-i.z),o}function Qe(e,t,i){if(!t){e.castShadow=!1;return}e.castShadow=!0;let o={...Xe,...i??{}};e.shadow.mapSize.set(o.mapSize,o.mapSize),e.shadow.camera.near=o.near,e.shadow.camera.far=o.far,e.shadow.camera.left=o.left,e.shadow.camera.right=o.right,e.shadow.camera.top=o.top,e.shadow.camera.bottom=o.bottom,e.shadow.bias=o.bias,e.shadow.radius=o.radius,e.shadow.camera.updateProjectionMatrix()}function jt(e,t,i){if(!t){e.castShadow=!1;return}e.castShadow=!0;let o={...Ye,...i??{}};e.shadow.mapSize.set(o.mapSize,o.mapSize),e.shadow.camera.near=o.near,e.shadow.camera.far=o.far,e.shadow.bias=o.bias,e.shadow.radius=o.radius,e.shadow.camera.updateProjectionMatrix()}function No(e){return new pt(e)}export{u as a,Mt as b,Pt as c,Zt as d,Et as e,_t as f,Rt as g,re as h,J as i,ae as j,le as k,K as l,ce as m,he as n,Q as o,me as p,pe as q,tt as r,ue as s,de as t,et as u,ye as v,ge as w,it as x,fe as y,Oe as z,F as A,we as B,Ce as C,G as D,Me as E,Ze as F,ht as G,Ee as H,Be as I,H as J,Le as K,Ne as L,pt as M,No as N};
@@ -0,0 +1 @@
1
+ import{proxy as u}from"valtio/vanilla";var a=["translate","rotate","scale"];function f(t){return a.includes(t)}var y={enabled:!0,translate:.25,rotate:Math.PI/12,scale:.1},e=u({enabled:!1,paused:!1,tool:"none",selectedEntityId:null,selectedEntityIds:[],hoveredEntityId:null,snap:{...y},gridVisible:!1,addTypeId:null,addTypeProps:null,flags:new Set}),i=null;function E(t){return i=t,()=>{i===t&&(i=null)}}function d(t){return!t||!i?null:i(t)}function r(t,n){if(t==null)return null;if(typeof t=="string")return t;let l=t.uuid;if(typeof l=="string")return console.warn(`${n}: received a live entity. Pass the UUID instead \u2014 storing entities in debugState makes valtio deep-proxy the scene graph.`),l;throw new TypeError(`${n} expects an entity UUID string or null, received ${typeof t}.`)}function b(){return e.paused}function x(t){e.paused=t}function I(){return e.tool}function S(t){e.tool=t}function v(){return e.enabled||e.tool!=="none"}function T(){return e.selectedEntityId}function c(t){let n=r(t,"setSelectedEntityId");e.selectedEntityId!==n&&(e.selectedEntityId=n,e.selectedEntityIds=n?[n]:[])}function m(){return[...e.selectedEntityIds]}function D(t){let n=t.map((o,s)=>r(o,`setSelectedEntityIds[${s}]`)).filter(o=>o!==null);n.length===e.selectedEntityIds.length&&n.every((o,s)=>e.selectedEntityIds[s]===o)||(e.selectedEntityIds=n,e.selectedEntityId=n[0]??null)}function h(){return{...e.snap}}function R(t){Object.assign(e.snap,t)}function G(t){e.gridVisible=t}function P(t,n){e.addTypeId=t,e.addTypeProps=t?n??null:null}function w(){return e.hoveredEntityId}function p(t){let n=r(t,"setHoveredEntityId");e.hoveredEntityId!==n&&(e.hoveredEntityId=n)}function H(){p(null)}function O(){return d(e.selectedEntityId)}function A(){return d(e.hoveredEntityId)}function k(t){c(r(t,"setSelectedEntity"))}export{a,f as b,y as c,e as d,E as e,d as f,b as g,x as h,I as i,S as j,v as k,T as l,c as m,m as n,D as o,h as p,R as q,G as r,P as s,w as t,p as u,H as v,O as w,A as x,k as y};
@@ -0,0 +1 @@
1
+ import{b as S,c as v,d as x}from"./chunk-VJZMSBKP.js";import{d as a,h,j as y,m as b,q as f,r as g,s as m}from"./chunk-DECK4UEC.js";import{subscribe as k}from"valtio/vanilla";import{announceBridgeReady as q,getZylemBridge as l}from"@zylem/bridge";function c(n,e){return[n[0]*e.x,n[1]*e.y,n[2]*e.z]}function E(n,e){let i=new Float32Array(n.length);for(let t=0;t<n.length;t+=3)i[t]=n[t]*e.x,i[t+1]=n[t+1]*e.y,i[t+2]=n[t+2]*e.z;return i}function z(n,e){let{shape:i}=n,t=n.offset?c(n.offset,e):n.offset,o;switch(i.type){case"box":o={type:"box",halfExtents:c(i.halfExtents,e)};break;case"sphere":o={type:"sphere",radius:i.radius*Math.max(e.x,e.y,e.z)};break;case"capsule":case"cylinder":case"cone":o={type:i.type,halfHeight:i.halfHeight*e.y,radius:i.radius*Math.max(e.x,e.z)};break;case"convexHull":o={type:"convexHull",vertices:E(i.vertices,e)};break;case"trimesh":o={type:"trimesh",vertices:E(i.vertices,e),indices:i.indices};break;case"heightfield":o={...i,scale:c(i.scale,e)};break;default:o=i;break}return{...n,shape:o,offset:t}}function V(n){if(!n.colliderBaseline){let e=n.colliderDescs.length?n.colliderDescs:n.colliderDesc?[n.colliderDesc]:[];n.colliderBaseline=e.map(i=>({...i}))}return n.colliderBaseline}function P(n){if(!n.colliderScaleDirty)return!1;n.colliderScaleDirty=!1;let e=V(n);if(!e.length)return!1;let i=n.getScale(),t=e.map(d=>z(d,i));n.colliderDescs=t,n.colliderDesc=t[0];let o=n.physicsWorldRef;if(!o)return!0;let r=n.getPose();return o.destroyEntity(n),r&&n.bodyDesc&&(n.bodyDesc.position=[r.position.x,r.position.y,r.position.z],n.bodyDesc.rotation=[r.rotation.x,r.rotation.y,r.rotation.z,r.rotation.w]),o.addEntity(n),!0}function D(n){return(n?.group??n?.mesh)?.scale}function G(n){let i=(typeof n?.getScale=="function"?n.getScale():void 0)??n?.scale??D(n)??{};return{x:i.x??1,y:i.y??1,z:i.z??1}}function L(n){let e=typeof n?.getPose=="function"?n.getPose():null;if(!e?.rotation)return;let{x:i,y:t,z:o,w:r}=e.rotation;return{x:i,y:t,z:o,w:r}}function u(n){let e=typeof n?.getPose=="function"?n.getPose():null,i=e?.position??{x:0,y:0,z:0},t=e?.rotation??{x:0,y:0,z:0,w:1};return{position:{x:i.x,y:i.y,z:i.z},rotation:x(t),quaternion:{x:t.x,y:t.y,z:t.z,w:t.w},scale:G(n)}}function T(n,e){if(typeof n?.setScale=="function"){n.setScale(e.x,e.y,e.z);return}D(n)?.set?.(e.x,e.y,e.z)}function O(n){!n||typeof n.getScale!="function"||P(n)}function U(n,e){if(!n)return!1;let i=e.quaternion??(e.rotation?v(e.rotation):void 0),t=!1;return(e.position||i)&&typeof n.setPose=="function"&&(t=n.setPose({position:e.position,rotation:i})),e.scale&&(T(n,e.scale),t=!0),t}function K(n){let e=n?.constructor?.type;return e?String(e).replace("Symbol(","").replace(")",""):"Unknown"}function I(n){let e=n;if(!e?.uuid)return;let i=l().channel;if(!i.hasSubscribers("entity:upsert"))return;let t=u(n);i.queue("entity:upsert",[{uuid:e.uuid,name:e.name||"Unnamed",type:K(n),position:t.position,rotation:t.rotation,scale:t.scale,quaternion:t.quaternion}])}function $(n,e){l().channel.send("game:notice",{level:n,message:e})}var w=class{channel;unsubscribes=[];host=null;editorKnown={};applyingSceneOperation=!1;constructor(){this.channel=l().channel}connect(e,i){this.disconnect(),this.host=e,this.unsubscribes.push(this.channel.on("debug:set",({enabled:t})=>{this.editorKnown.debug=t,a.enabled=t}),this.channel.on("tool:set",({tool:t})=>{y(t)}),this.channel.on("playback:set",({paused:t})=>{this.editorKnown.paused=t,h(t)}),this.channel.on("entity:select",({uuid:t})=>{this.editorKnown.selectedUuid=t,b(t)}),this.channel.on("entity:focus",({uuid:t})=>{S(t)}),this.channel.on("entity:transform",({uuid:t,position:o,rotation:r,quaternion:d,scale:p})=>{let s=this.host?.resolveEntity(t);if(!s)return;let C=u(s);if(U(s,{position:o,rotation:r,quaternion:d,scale:p}),p&&O(s),I(s),this.applyingSceneOperation)return;let B=u(s);this.channel.send("scene:operation",{opId:`tx-${t}-${Date.now().toString(36)}`,kind:"transform",label:`Set ${s.name||"entity"} transform`,entries:[{uuid:t,before:C,after:B}]})}),this.channel.on("entity:create",({typeId:t,props:o,pose:r})=>{this.host?.createEntity?.(t,o,r)}),this.channel.on("scene:operation:apply",({op:t,direction:o})=>{this.applyingSceneOperation=!0;try{this.host?.applySceneOperation?.(t,o)}finally{this.applyingSceneOperation=!1}}),this.channel.on("add:type:set",({typeId:t,props:o})=>{m(t,o??null)}),this.channel.on("snap:set",t=>{f(t)}),this.channel.on("grid:set",({visible:t})=>{g(t)}),this.channel.on("stage:variable:set",({key:t,value:o})=>{this.host?.setStageVariable?.(t,o)}),k(a,()=>this.publishDebugStateChanges())),this.publishDebugStateChanges(),q(i)}disconnect(){for(let e of this.unsubscribes)e();this.unsubscribes=[],this.host=null,this.editorKnown={}}publishDebugStateChanges(){let e={};a.paused!==this.editorKnown.paused&&(this.editorKnown.paused=a.paused,e.paused=a.paused),a.enabled!==this.editorKnown.debug&&(this.editorKnown.debug=a.enabled,e.debug=a.enabled),(e.paused!==void 0||e.debug!==void 0)&&this.publishStatus(e),(a.selectedEntityId!==this.editorKnown.selectedUuid||a.hoveredEntityId!==this.editorKnown.hoveredUuid)&&(this.editorKnown.selectedUuid=a.selectedEntityId,this.editorKnown.hoveredUuid=a.hoveredEntityId,this.channel.queue("entity:selection",{selectedUuid:a.selectedEntityId,hoveredUuid:a.hoveredEntityId,selectedUuids:[...a.selectedEntityIds]}))}wantsEntityUpdates(){return this.channel.hasSubscribers("entity:upsert")||this.channel.hasSubscribers("stage:snapshot")}wantsThumbnails(){return this.channel.hasSubscribers("entity:thumbnail")}onEditorAttached(e){return this.channel.onSubscriberAdded(i=>{if(i!=="entity:upsert"&&i!=="entity:thumbnail")return;let t=i==="entity:upsert"?"entity:thumbnail":"entity:upsert";this.channel.subscriberCount(t)>0||e()})}publishConfig(e){this.channel.send("game:config",e)}publishLoading(e){this.channel.send("game:loading",e)}publishStatus(e){this.channel.queue("game:status",e)}publishVariable(e){this.channel.send("game:variable",e)}publishNotice(e,i){this.channel.send("game:notice",{level:e,message:i})}publishStageSnapshot(e){this.channel.send("stage:snapshot",e)}queueEntityUpsert(e){e.length&&this.channel.queue("entity:upsert",e)}queueEntityRemoved(e){e.length&&this.channel.queue("entity:removed",{uuids:e})}queueThumbnails(e){e.length&&this.channel.queue("entity:thumbnail",e)}publishCatalog(e){this.channel.send("catalog:snapshot",{entities:e})}publishSceneOperation(e){this.channel.send("scene:operation",e)}wantsSceneOperations(){return this.channel.hasSubscribers("scene:operation")}};function j(n){l().channel.send("scene:operation",n)}export{P as a,G as b,L as c,K as d,$ as e,w as f,j as g};