@zylem/game-lib 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/actions.d.ts +255 -8
- package/dist/actions.js +1 -936
- package/dist/audio.d.ts +13 -0
- package/dist/audio.js +1 -0
- package/dist/base-node-life-cycle-CnJ-7zX-.d.ts +143 -0
- package/dist/behavior.d.ts +3 -0
- package/dist/behavior.js +1 -0
- package/dist/chunk-4QLJUQSJ.js +1 -0
- package/dist/chunk-73VZQZUL.js +1 -0
- package/dist/chunk-A34ZG3L4.js +1 -0
- package/dist/chunk-CDPY4VOQ.js +1 -0
- package/dist/chunk-DR6XXZE7.js +19 -0
- package/dist/chunk-FM5TBEPO.js +1 -0
- package/dist/chunk-G2IIMSUH.js +1 -0
- package/dist/chunk-MSC2BEO5.js +1 -0
- package/dist/chunk-NIH5CONO.js +1 -0
- package/dist/chunk-ONWXGBWB.js +1 -0
- package/dist/chunk-QEDQDR27.js +1 -0
- package/dist/chunk-QXVH6POE.js +1 -0
- package/dist/chunk-RXDTAWI2.js +29 -0
- package/dist/chunk-WKHW2QO2.js +1 -0
- package/dist/chunk-XRP4JJXL.js +1 -0
- package/dist/chunk-YHEWKN7N.js +1 -0
- package/dist/chunk-YHKXQ2ZN.js +1 -0
- package/dist/core.d.ts +206 -14
- package/dist/core.js +24 -12424
- package/dist/debug.d.ts +24 -0
- package/dist/debug.js +1 -0
- package/dist/default-controls-BGc61yYl.d.ts +111 -0
- package/dist/{entity-vj-HTjzU.d.ts → entity-DNkYKfdp.d.ts} +452 -578
- package/dist/entity-type-map-C94h2TDW.d.ts +781 -0
- package/dist/entity.d.ts +265 -0
- package/dist/entity.js +1 -0
- package/dist/events.d.ts +172 -0
- package/dist/events.js +1 -0
- package/dist/game-Cuj5gy7U.d.ts +1590 -0
- package/dist/game-default-PZLLHYL7.js +1 -0
- package/dist/game-interfaces-tfpM5NBk.d.ts +90 -0
- package/dist/globals.d.ts +104 -0
- package/dist/globals.js +1 -0
- package/dist/graphics.d.ts +83 -0
- package/dist/graphics.js +1 -0
- package/dist/input-ui.d.ts +34 -0
- package/dist/input-ui.js +1 -0
- package/dist/input.d.ts +72 -0
- package/dist/input.js +1 -0
- package/dist/material-Wz83vTTp.d.ts +151 -0
- package/dist/runtime.d.ts +433 -0
- package/dist/runtime.js +1 -0
- package/dist/web-components.d.ts +67 -0
- package/dist/web-components.js +9 -0
- package/dist/world-C9zdyl5d.d.ts +103 -0
- package/dist/{camera-4XO5gbQH.d.ts → zylem-stage-runtime-Cs-UDEVU.d.ts} +201 -329
- package/package.json +52 -63
- package/dist/actions.js.map +0 -1
- package/dist/behavior/jumper-2d.d.ts +0 -114
- package/dist/behavior/jumper-2d.js +0 -711
- package/dist/behavior/jumper-2d.js.map +0 -1
- package/dist/behavior/platformer-3d.d.ts +0 -296
- package/dist/behavior/platformer-3d.js +0 -761
- package/dist/behavior/platformer-3d.js.map +0 -1
- package/dist/behavior/ricochet-2d.d.ts +0 -275
- package/dist/behavior/ricochet-2d.js +0 -425
- package/dist/behavior/ricochet-2d.js.map +0 -1
- package/dist/behavior/ricochet-3d.d.ts +0 -117
- package/dist/behavior/ricochet-3d.js +0 -443
- package/dist/behavior/ricochet-3d.js.map +0 -1
- package/dist/behavior/screen-visibility.d.ts +0 -79
- package/dist/behavior/screen-visibility.js +0 -358
- package/dist/behavior/screen-visibility.js.map +0 -1
- package/dist/behavior/screen-wrap.d.ts +0 -87
- package/dist/behavior/screen-wrap.js +0 -246
- package/dist/behavior/screen-wrap.js.map +0 -1
- package/dist/behavior/shooter-2d.d.ts +0 -79
- package/dist/behavior/shooter-2d.js +0 -180
- package/dist/behavior/shooter-2d.js.map +0 -1
- package/dist/behavior/thruster.d.ts +0 -11
- package/dist/behavior/thruster.js +0 -292
- package/dist/behavior/thruster.js.map +0 -1
- package/dist/behavior/top-down-movement.d.ts +0 -56
- package/dist/behavior/top-down-movement.js +0 -125
- package/dist/behavior/top-down-movement.js.map +0 -1
- package/dist/behavior/world-boundary-2d.d.ts +0 -142
- package/dist/behavior/world-boundary-2d.js +0 -235
- package/dist/behavior/world-boundary-2d.js.map +0 -1
- package/dist/behavior/world-boundary-3d.d.ts +0 -76
- package/dist/behavior/world-boundary-3d.js +0 -274
- package/dist/behavior/world-boundary-3d.js.map +0 -1
- package/dist/behavior-descriptor-BXnVR8Ki.d.ts +0 -159
- package/dist/blueprints-DmbK2dki.d.ts +0 -26
- package/dist/camera.d.ts +0 -6
- package/dist/camera.js +0 -1993
- package/dist/camera.js.map +0 -1
- package/dist/composition-BASvMKrW.d.ts +0 -218
- package/dist/core-CARRaS55.d.ts +0 -541
- package/dist/core.js.map +0 -1
- package/dist/entities-ChFirVL9.d.ts +0 -410
- package/dist/entities.d.ts +0 -9
- package/dist/entities.js +0 -4986
- package/dist/entities.js.map +0 -1
- package/dist/entity-Bq_eNEDI.d.ts +0 -28
- package/dist/entity-types-DAu8sGJH.d.ts +0 -26
- package/dist/global-change-2JvMaz44.d.ts +0 -25
- package/dist/main.d.ts +0 -1353
- package/dist/main.js +0 -19525
- package/dist/main.js.map +0 -1
- package/dist/physics-pose-DCc4oE44.d.ts +0 -25
- package/dist/physics-protocol-BDD3P5W2.d.ts +0 -200
- package/dist/physics-worker.d.ts +0 -21
- package/dist/physics-worker.js +0 -306
- package/dist/physics-worker.js.map +0 -1
- package/dist/physics.d.ts +0 -205
- package/dist/physics.js +0 -577
- package/dist/physics.js.map +0 -1
- package/dist/stage-types-C19IhuzA.d.ts +0 -731
- package/dist/stage.d.ts +0 -52
- package/dist/stage.js +0 -8479
- package/dist/stage.js.map +0 -1
- package/dist/sync-state-machine-CZyspBpj.d.ts +0 -16
- package/dist/thruster-23lzoPZd.d.ts +0 -180
- package/dist/world-DfgxoNMt.d.ts +0 -105
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{p as e}from"./chunk-QEDQDR27.js";import"./chunk-A34ZG3L4.js";import"./chunk-CDPY4VOQ.js";import"./chunk-ONWXGBWB.js";import"./chunk-DR6XXZE7.js";import"./chunk-YHEWKN7N.js";import"./chunk-QXVH6POE.js";import"./chunk-73VZQZUL.js";import"./chunk-YHKXQ2ZN.js";import"./chunk-WKHW2QO2.js";import"./chunk-4QLJUQSJ.js";import"./chunk-G2IIMSUH.js";import"./chunk-FM5TBEPO.js";import"./chunk-XRP4JJXL.js";import"./chunk-MSC2BEO5.js";import{proxy as t}from"valtio/vanilla";var s=()=>({id:"zylem",globals:{},stages:[e()],debug:!1,time:0,input:void 0}),a=t({...s()});function o(){return{id:a.id??"zylem",globals:a.globals??{},stages:a.stages??[e()],debug:a.debug,time:a.time,input:a.input}}export{o as getGameDefaultConfig};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { U as UpdateFunction } from './base-node-life-cycle-CnJ-7zX-.js';
|
|
2
|
+
|
|
3
|
+
type BasicTypes = number | string | boolean;
|
|
4
|
+
type BaseGlobals = Record<string, BasicTypes>;
|
|
5
|
+
type KeyboardMapping = Record<string, string[]>;
|
|
6
|
+
type MouseMapping = Record<string, string[]>;
|
|
7
|
+
type VirtualTouchStyle = Partial<Record<string, string | number>>;
|
|
8
|
+
interface VirtualTouchPosition {
|
|
9
|
+
top?: string | number;
|
|
10
|
+
right?: string | number;
|
|
11
|
+
bottom?: string | number;
|
|
12
|
+
left?: string | number;
|
|
13
|
+
transform?: string;
|
|
14
|
+
}
|
|
15
|
+
interface VirtualTouchButtonConfig {
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
className?: string;
|
|
18
|
+
style?: VirtualTouchStyle;
|
|
19
|
+
position?: VirtualTouchPosition;
|
|
20
|
+
size?: number;
|
|
21
|
+
label?: string;
|
|
22
|
+
/** Trusted SVG markup injected into the control. */
|
|
23
|
+
svg?: string;
|
|
24
|
+
}
|
|
25
|
+
interface VirtualTouchJoystickConfig {
|
|
26
|
+
enabled?: boolean;
|
|
27
|
+
className?: string;
|
|
28
|
+
style?: VirtualTouchStyle;
|
|
29
|
+
position?: VirtualTouchPosition;
|
|
30
|
+
size?: number;
|
|
31
|
+
thumbSize?: number;
|
|
32
|
+
maxDistance?: number;
|
|
33
|
+
deadzone?: number;
|
|
34
|
+
directionThreshold?: number;
|
|
35
|
+
horizontalAxis?: 'Horizontal' | 'SecondaryHorizontal';
|
|
36
|
+
verticalAxis?: 'Vertical' | 'SecondaryVertical';
|
|
37
|
+
emitDirections?: boolean;
|
|
38
|
+
svg?: {
|
|
39
|
+
base?: string;
|
|
40
|
+
thumb?: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
type VirtualTouchButtonSlot = 'A' | 'B' | 'X' | 'Y' | 'Start' | 'Select' | 'L' | 'R' | 'LTrigger' | 'RTrigger' | 'Up' | 'Down' | 'Left' | 'Right';
|
|
44
|
+
type VirtualTouchButtonsConfig = Partial<Record<VirtualTouchButtonSlot, VirtualTouchButtonConfig | false>>;
|
|
45
|
+
interface VirtualTouchJoysticksConfig {
|
|
46
|
+
left?: VirtualTouchJoystickConfig | false;
|
|
47
|
+
right?: VirtualTouchJoystickConfig | false;
|
|
48
|
+
}
|
|
49
|
+
interface VirtualTouchConfig {
|
|
50
|
+
enabled?: boolean | 'auto';
|
|
51
|
+
className?: string;
|
|
52
|
+
style?: VirtualTouchStyle;
|
|
53
|
+
joysticks?: VirtualTouchJoysticksConfig | false;
|
|
54
|
+
buttons?: VirtualTouchButtonsConfig | false;
|
|
55
|
+
}
|
|
56
|
+
interface MouseConfig {
|
|
57
|
+
/** Custom mapping from mouse actions to input properties. */
|
|
58
|
+
mapping?: MouseMapping;
|
|
59
|
+
/** Whether to capture the cursor via Pointer Lock API. */
|
|
60
|
+
pointerLock?: boolean;
|
|
61
|
+
/** Sensitivity multiplier for mouse movement (default 0.002). */
|
|
62
|
+
sensitivity?: number;
|
|
63
|
+
}
|
|
64
|
+
interface GameInputPlayerConfig {
|
|
65
|
+
key?: KeyboardMapping;
|
|
66
|
+
mouse?: MouseConfig;
|
|
67
|
+
touch?: VirtualTouchConfig;
|
|
68
|
+
includeDefaults?: boolean;
|
|
69
|
+
}
|
|
70
|
+
interface GameInputConfig {
|
|
71
|
+
p1?: GameInputPlayerConfig;
|
|
72
|
+
p2?: GameInputPlayerConfig;
|
|
73
|
+
p3?: GameInputPlayerConfig;
|
|
74
|
+
p4?: GameInputPlayerConfig;
|
|
75
|
+
p5?: GameInputPlayerConfig;
|
|
76
|
+
p6?: GameInputPlayerConfig;
|
|
77
|
+
p7?: GameInputPlayerConfig;
|
|
78
|
+
p8?: GameInputPlayerConfig;
|
|
79
|
+
}
|
|
80
|
+
interface ZylemGameConfig<StageInterface, GameInterface, TGlobals extends BaseGlobals> {
|
|
81
|
+
id: string;
|
|
82
|
+
globals?: TGlobals;
|
|
83
|
+
stages?: StageInterface[];
|
|
84
|
+
update?: UpdateFunction<GameInterface>;
|
|
85
|
+
debug?: boolean;
|
|
86
|
+
time?: number;
|
|
87
|
+
input?: GameInputConfig;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type { BaseGlobals as B, GameInputConfig as G, KeyboardMapping as K, MouseConfig as M, VirtualTouchConfig as V, ZylemGameConfig as Z, VirtualTouchButtonSlot as a, GameInputPlayerConfig as b, MouseMapping as c, VirtualTouchButtonConfig as d, VirtualTouchButtonsConfig as e, VirtualTouchJoystickConfig as f, VirtualTouchJoysticksConfig as g, VirtualTouchPosition as h, VirtualTouchStyle as i };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { f as UpdateContext } from './base-node-life-cycle-CnJ-7zX-.js';
|
|
2
|
+
import 'three';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Set a global value by path.
|
|
6
|
+
* Emits a 'game:state:updated' event when the value changes.
|
|
7
|
+
* @example setGlobal('score', 100)
|
|
8
|
+
* @example setGlobal('player.health', 50)
|
|
9
|
+
*/
|
|
10
|
+
declare function setGlobal(path: string, value: unknown): void;
|
|
11
|
+
/**
|
|
12
|
+
* Create/initialize a global with a default value.
|
|
13
|
+
* Only sets the value if it doesn't already exist.
|
|
14
|
+
* Use this to ensure globals have initial values before game starts.
|
|
15
|
+
* @example createGlobal('score', 0)
|
|
16
|
+
* @example createGlobal('player.health', 100)
|
|
17
|
+
*/
|
|
18
|
+
declare function createGlobal<T>(path: string, defaultValue: T): T;
|
|
19
|
+
/**
|
|
20
|
+
* Get a global value by path.
|
|
21
|
+
* @example getGlobal('score') // 100
|
|
22
|
+
* @example getGlobal<number>('player.health') // 50
|
|
23
|
+
*/
|
|
24
|
+
declare function getGlobal<T = unknown>(path: string): T | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Subscribe to changes on a global value at a specific path.
|
|
27
|
+
* Returns an unsubscribe function. Subscriptions are automatically
|
|
28
|
+
* cleaned up when the game is disposed.
|
|
29
|
+
* @example const unsub = onGlobalChange('score', (val) => console.log(val));
|
|
30
|
+
*/
|
|
31
|
+
declare function onGlobalChange<T = unknown>(path: string, callback: (value: T) => void): () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Subscribe to changes on multiple global paths.
|
|
34
|
+
* Callback fires when any of the paths change, receiving all current values.
|
|
35
|
+
* Subscriptions are automatically cleaned up when the game is disposed.
|
|
36
|
+
* @example const unsub = onGlobalChanges(['score', 'lives'], ([score, lives]) => console.log(score, lives));
|
|
37
|
+
*/
|
|
38
|
+
declare function onGlobalChanges<T extends unknown[] = unknown[]>(paths: string[], callback: (values: T) => void): () => void;
|
|
39
|
+
/**
|
|
40
|
+
* Get the entire globals object (read-only snapshot).
|
|
41
|
+
*/
|
|
42
|
+
declare function getGlobals<T = Record<string, unknown>>(): T;
|
|
43
|
+
/**
|
|
44
|
+
* Unsubscribe all active global subscriptions.
|
|
45
|
+
* Used internally on game dispose to prevent old callbacks from firing.
|
|
46
|
+
*/
|
|
47
|
+
declare function clearGlobalSubscriptions(): void;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Set a variable on an object by path.
|
|
51
|
+
* @example setVariable(stage1, 'totalAngle', 0.5)
|
|
52
|
+
* @example setVariable(entity, 'enemy.count', 10)
|
|
53
|
+
*/
|
|
54
|
+
declare function setVariable(target: object, path: string, value: unknown): void;
|
|
55
|
+
/**
|
|
56
|
+
* Create/initialize a variable with a default value on a target object.
|
|
57
|
+
* Only sets the value if it doesn't already exist.
|
|
58
|
+
* @example createVariable(stage1, 'totalAngle', 0)
|
|
59
|
+
* @example createVariable(entity, 'enemy.count', 10)
|
|
60
|
+
*/
|
|
61
|
+
declare function createVariable<T>(target: object, path: string, defaultValue: T): T;
|
|
62
|
+
/**
|
|
63
|
+
* Get a variable from an object by path.
|
|
64
|
+
* @example getVariable(stage1, 'totalAngle') // 0.5
|
|
65
|
+
* @example getVariable<number>(entity, 'enemy.count') // 10
|
|
66
|
+
*/
|
|
67
|
+
declare function getVariable<T = unknown>(target: object, path: string): T | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Subscribe to changes on a variable at a specific path for a target object.
|
|
70
|
+
* Returns an unsubscribe function.
|
|
71
|
+
* @example const unsub = onVariableChange(stage1, 'score', (val) => console.log(val));
|
|
72
|
+
*/
|
|
73
|
+
declare function onVariableChange<T = unknown>(target: object, path: string, callback: (value: T) => void): () => void;
|
|
74
|
+
/**
|
|
75
|
+
* Subscribe to changes on multiple variable paths for a target object.
|
|
76
|
+
* Callback fires when any of the paths change, receiving all current values.
|
|
77
|
+
* Returns an unsubscribe function.
|
|
78
|
+
* @example const unsub = onVariableChanges(stage1, ['count', 'total'], ([count, total]) => console.log(count, total));
|
|
79
|
+
*/
|
|
80
|
+
declare function onVariableChanges<T extends unknown[] = unknown[]>(target: object, paths: string[], callback: (values: T) => void): () => void;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Listen for a single global key change inside an onUpdate pipeline.
|
|
84
|
+
* Usage: onUpdate(globalChange('p1Score', (value) => { ... }))
|
|
85
|
+
*/
|
|
86
|
+
declare function globalChange<T = any>(key: string, callback: (value: T, ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
|
|
87
|
+
/**
|
|
88
|
+
* Listen for multiple global key changes inside an onUpdate pipeline.
|
|
89
|
+
* Calls back when any of the provided keys changes.
|
|
90
|
+
* Usage: onUpdate(globalChanges(['p1Score','p2Score'], ([p1,p2]) => { ... }))
|
|
91
|
+
*/
|
|
92
|
+
declare function globalChanges<T = any>(keys: string[], callback: (values: T[], ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Listen for a single stage variable change inside an onUpdate pipeline.
|
|
95
|
+
* Usage: onUpdate(variableChange('score', (value, ctx) => { ... }))
|
|
96
|
+
*/
|
|
97
|
+
declare function variableChange<T = any>(key: string, callback: (value: T, ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
|
|
98
|
+
/**
|
|
99
|
+
* Listen for multiple stage variable changes; fires when any changes.
|
|
100
|
+
* Usage: onUpdate(variableChanges(['a','b'], ([a,b], ctx) => { ... }))
|
|
101
|
+
*/
|
|
102
|
+
declare function variableChanges<T = any>(keys: string[], callback: (values: T[], ctx: UpdateContext<any>) => void): (ctx: UpdateContext<any>) => void;
|
|
103
|
+
|
|
104
|
+
export { clearGlobalSubscriptions, createGlobal, createVariable, getGlobal, getGlobals, getVariable, globalChange, globalChanges, onGlobalChange, onGlobalChanges, onVariableChange, onVariableChanges, setGlobal, setVariable, variableChange, variableChanges };
|
package/dist/globals.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{h,i as v,j as y,k as T,l as x}from"./chunk-WKHW2QO2.js";import{e as u,f,g,h as C,i as b,j as p,m as c}from"./chunk-4QLJUQSJ.js";import"./chunk-G2IIMSUH.js";function V(t,r){let n;return a=>{let e=a.globals?.[t];n!==e&&(n===void 0&&e===void 0||r(e,a),n=e)}}function U(t,r){let n=new Array(t.length).fill(void 0);return a=>{let e=t.map(i=>a.globals?.[i]);if(e.some((i,l)=>n[l]!==i)){let i=n.every(o=>o===void 0),l=e.every(o=>o===void 0);i&&l||r(e,a),n=e}}}function m(t,r){let n;return a=>{let e=a.stage?.getVariable?.(t)??void 0;n!==e&&(n===void 0&&e===void 0||r(e,a),n=e)}}function G(t,r){let n=new Array(t.length).fill(void 0);return a=>{let e=l=>a.stage?.getVariable?.(l),d=t.map(e);if(d.some((l,o)=>n[o]!==l)){let l=n.every(s=>s===void 0),o=d.every(s=>s===void 0);l&&o||r(d,a),n=d}}}export{c as clearGlobalSubscriptions,f as createGlobal,v as createVariable,g as getGlobal,p as getGlobals,y as getVariable,V as globalChange,U as globalChanges,C as onGlobalChange,b as onGlobalChanges,T as onVariableChange,x as onVariableChanges,u as setGlobal,h as setVariable,m as variableChange,G as variableChanges};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Z as ZylemTSLShader } from './material-Wz83vTTp.js';
|
|
2
|
+
export { o as ZylemShader, m as ZylemShaderObject, r as createNodeMaterialFromTSL, q as isGLSLShader, p as isTSLShader } from './material-Wz83vTTp.js';
|
|
3
|
+
export { Fn, abs, asin, atan, clamp, cos, dot, exp, float, floor, fract, length, max, min, mix, mod, normalize, positionWorld, pow, sin, smoothstep, step, time, uniform, uv, vec2, vec3, vec4 } from 'three/tsl';
|
|
4
|
+
import 'three';
|
|
5
|
+
import 'three/webgpu';
|
|
6
|
+
import '@dimforge/rapier3d-compat';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* TSL fire shader for WebGPU.
|
|
10
|
+
*/
|
|
11
|
+
declare const fireTSL: ZylemTSLShader;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* TSL star shader for WebGPU.
|
|
15
|
+
*/
|
|
16
|
+
declare const starTSL: ZylemTSLShader;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* TSL debug wireframe shader for WebGPU.
|
|
20
|
+
*/
|
|
21
|
+
declare const debugTSL: ZylemTSLShader;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Create a gradient sky shader with custom colors.
|
|
25
|
+
*
|
|
26
|
+
* @param groundColor Color below the horizon (default: dark ground)
|
|
27
|
+
* @param horizonColor Color at the horizon line (default: warm orange)
|
|
28
|
+
* @param zenithColor Color directly above (default: deep blue/black)
|
|
29
|
+
*/
|
|
30
|
+
declare function createGradientSky(groundColor?: [number, number, number], horizonColor?: [number, number, number], zenithColor?: [number, number, number]): ZylemTSLShader;
|
|
31
|
+
/**
|
|
32
|
+
* Default gradient sky: dark space above, warm horizon glow, dark ground below.
|
|
33
|
+
* Suitable as a general-purpose game skybox.
|
|
34
|
+
*/
|
|
35
|
+
declare const gradientSkyTSL: ZylemTSLShader;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* TSL starfield skybox shader for WebGPU.
|
|
39
|
+
* Uses world-space position for proper 3D skybox rendering.
|
|
40
|
+
*/
|
|
41
|
+
declare const starfieldSkyTSL: ZylemTSLShader;
|
|
42
|
+
|
|
43
|
+
declare const standardShader: {
|
|
44
|
+
vertex: string;
|
|
45
|
+
fragment: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
declare const objectVertexShader = "\nuniform vec2 uvScale;\nvarying vec2 vUv;\n\nvoid main() {\n\tvUv = uv;\n\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\tgl_Position = projectionMatrix * mvPosition;\n}\n";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Convenience factory for creating background (skybox) shaders.
|
|
52
|
+
*
|
|
53
|
+
* Wraps a TSL color node into a {@link ZylemTSLShader} object suitable for
|
|
54
|
+
* passing to `stageConfig({ backgroundShader: ... })`.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { createBackgroundShader, Fn, positionWorld, normalize, vec4 } from '@zylem/game-lib/graphics';
|
|
59
|
+
*
|
|
60
|
+
* const myShader = createBackgroundShader(
|
|
61
|
+
* Fn(() => {
|
|
62
|
+
* const dir = normalize(positionWorld);
|
|
63
|
+
* return vec4(dir.x, dir.y, dir.z, 1.0);
|
|
64
|
+
* })()
|
|
65
|
+
* );
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Create a background shader from a TSL color node.
|
|
71
|
+
*
|
|
72
|
+
* The color node receives the skybox mesh geometry and should produce a
|
|
73
|
+
* `vec4` color output. For proper skybox rendering, use `positionWorld`
|
|
74
|
+
* (from `three/tsl`) to derive a view direction and compute colors in
|
|
75
|
+
* spherical coordinates.
|
|
76
|
+
*
|
|
77
|
+
* @param colorNode - A TSL node expression that evaluates to a vec4 color
|
|
78
|
+
* @param transparent - Whether the background should be transparent (default: false)
|
|
79
|
+
* @returns A ZylemTSLShader that can be used as `backgroundShader` in stage config
|
|
80
|
+
*/
|
|
81
|
+
declare function createBackgroundShader(colorNode: any, transparent?: boolean): ZylemTSLShader;
|
|
82
|
+
|
|
83
|
+
export { ZylemTSLShader, createBackgroundShader, createGradientSky, debugTSL, fireTSL, gradientSkyTSL, objectVertexShader, standardShader, starTSL, starfieldSkyTSL };
|
package/dist/graphics.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as tt,b as ot,f as et,g as rt,i as at,j as st,k as nt,l as mt,m as lt,n as dt,o as ct,p as ut}from"./chunk-DR6XXZE7.js";import"./chunk-QXVH6POE.js";import"./chunk-YHKXQ2ZN.js";import"./chunk-G2IIMSUH.js";import{Fn as R,uv as it,time as W,vec3 as h,vec4 as U,float as b,floor as A,fract as Z,sin as B,atan as pt,length as G,mix as p,mod as I,max as ft,pow as j}from"three/tsl";var yt=R(([e,t])=>{let a=h(1,100,1e3),s=e.mul(t),o=A(I(s,t)).mul(a),r=A(I(s.add(h(1,1,1)),t)).mul(a),n=Z(s),l=n.mul(n).mul(b(3).sub(n.mul(2))),c=U(o.x.add(o.y).add(o.z),r.x.add(o.y).add(o.z),o.x.add(r.y).add(o.z),r.x.add(r.y).add(o.z)),d=Z(B(c.mul(.1)).mul(1e3)),i=p(p(d.x,d.y,l.x),p(d.z,d.w,l.x),l.y),u=Z(B(c.add(r.z).sub(o.z).mul(.1)).mul(1e3)),f=p(p(u.x,u.y,l.x),p(u.z,u.w,l.x),l.y);return p(i,f,l.z).mul(2).sub(1)}),St=R(()=>{let e=it().sub(.5),t=b(3).sub(G(e.mul(2)).mul(3)),a=h(pt(e.x,e.y).div(6.2832).add(.5),G(e).mul(.4),.5),s=h(0,W.mul(-.05),W.mul(.01));for(let r=1;r<=7;r++){let n=Math.pow(2,r);t=t.add(b(1.5/n).mul(yt(a.add(s),b(n*16))))}let o=ft(t,0);return U(t,j(o,2).mul(.4),j(o,3).mul(.15),1)})(),xt={colorNode:St,transparent:!1};import{Fn as E,uv as bt,time as V,vec3 as S,vec4 as ht,float as Tt,fract as vt,length as q,exp as Lt,sin as gt,cos as Zt,abs as kt,pow as wt}from"three/tsl";var Nt=E(([e])=>{let t=S(.5,.5,.5),a=S(.5,.5,.5),s=S(1,1,1),o=S(.263,.416,.557);return t.add(a.mul(Zt(s.mul(e).add(o).mul(6.28318))))}),Ft=E(()=>{let e=bt().mul(2).sub(1),t=q(e),a=e,s=S(0,0,0);for(let o=0;o<4;o++){a=vt(a.mul(1.5)).sub(.5);let r=q(a).mul(Lt(t.negate())),n=Nt(t.add(o*.4).add(V.mul(.4)));r=gt(r.mul(5).add(V)).div(5),r=kt(r),r=wt(Tt(.01).div(r),1.2),s=s.add(n.mul(r))}return ht(s,1)})(),zt={colorNode:Ft,transparent:!1};import{Fn as Ct,uv as Pt,vec3 as H,vec4 as Mt,float as k,min as w,mix as Wt,smoothstep as At,fwidth as Bt}from"three/tsl";var Gt=H(.2,.2,.25),It=H(.6,.9,1),jt=1,Rt=Ct(()=>{let e=Pt(),t=w(w(e.x,k(1).sub(e.x)),w(e.y,k(1).sub(e.y))),a=Bt(t).mul(jt).max(1e-5),s=At(k(0),a,t),o=Wt(It,Gt,s);return Mt(o,1)})(),Ut={colorNode:Rt,transparent:!1};import{Fn as Vt,positionWorld as qt,vec3 as T,vec4 as Et,float as v,normalize as Ht,smoothstep as O,mix as X,clamp as N,pow as Y,asin as Ot}from"three/tsl";var Xt=Math.PI*.5;function _(e=[.15,.1,.08],t=[.45,.25,.15],a=[.02,.02,.08]){return{colorNode:Vt(()=>{let o=Ht(qt),r=Ot(N(o.y,-1,1)).div(Xt),n=O(0,1,N(r,0,1)),l=X(T(t[0],t[1],t[2]),T(a[0],a[1],a[2]),Y(n,v(1.5))),c=O(0,1,N(r.negate(),0,1)),d=X(T(t[0],t[1],t[2]),T(e[0],e[1],e[2]),Y(c,v(.8))),i=r.greaterThanEqual(v(0)).select(l,d);return Et(i,v(1))})(),transparent:!1}}var Yt=_();import{Fn as P,time as _t,positionWorld as Dt,vec2 as M,vec3 as y,vec4 as Jt,float as m,floor as D,fract as J,sin as g,dot as Kt,length as Qt,mix as C,max as F,normalize as $t,atan as to,asin as oo,clamp as eo}from"three/tsl";var ro=6.28318530718,ao=3.14159265359,so=y(1,.9,.7),no=y(.7,.85,1),mo=y(1,1,1),lo=y(.01,.01,.03),L=P(([e])=>{let t=Kt(e,M(127.1,311.7));return J(g(t).mul(43758.5453))}),z=P(([e,t,a])=>{let s=e.mul(t),o=D(s),r=J(s).sub(.5),n=L(o),l=F(m(0),n.sub(.85).mul(6.666)),c=L(o.add(1.3)).sub(.5),d=L(o.add(2.1)).sub(.5),i=M(c,d),u=r.sub(i),f=Qt(u),x=C(m(.015),m(.03),n),K=F(m(0),m(1).sub(f.div(x))),Q=F(m(0),m(1).sub(f.div(x.mul(4)))).mul(.15),$=m(.6).add(g(a.mul(m(.6).add(n)).add(n.mul(6.28))).mul(.4));return K.add(Q).mul($).mul(l)}),co=P(()=>{let e=$t(Dt),t=_t,a=to(e.z,e.x),s=oo(eo(e.y,-1,1)),o=M(a.div(ro).add(.5),s.div(ao).add(.5)),r=y(lo),n=g(o.x.mul(2).add(t.mul(.02))).mul(g(o.y.mul(1.5).sub(t.mul(.01)))).mul(.5).add(.5);r=r.add(y(.01,.005,.02).mul(n));let l=z(o,m(60),t),c=z(o.add(.37),m(120),t.mul(.8)),d=z(o.add(.71),m(240),t.mul(.6)),i=l.add(c.mul(.6)).add(d.mul(.35)),u=L(D(o.mul(60))),f=C(so,no,u),x=C(f,mo,m(.5));return r=r.add(x.mul(i)),Jt(r,m(1))})(),uo={colorNode:co,transparent:!1};import{positionWorld as Bo,normalize as Go,mix as Io,smoothstep as jo,clamp as Ro,sin as Uo,cos as Vo,atan as qo,asin as Eo,abs as Ho,exp as Oo,pow as Xo,step as Yo,max as _o,min as Do,floor as Jo,fract as Ko,dot as Qo,length as $o,vec2 as te,mod as oe}from"three/tsl";function io(e,t=!1){return{colorNode:e,transparent:t}}export{ut as Fn,Ho as abs,Eo as asin,qo as atan,Ro as clamp,Vo as cos,io as createBackgroundShader,_ as createGradientSky,at as createNodeMaterialFromTSL,Ut as debugTSL,Qo as dot,Oo as exp,xt as fireTSL,ct as float,Jo as floor,Ko as fract,Yt as gradientSkyTSL,rt as isGLSLShader,et as isTSLShader,$o as length,_o as max,Do as min,Io as mix,oe as mod,Go as normalize,tt as objectVertexShader,Bo as positionWorld,Xo as pow,Uo as sin,jo as smoothstep,ot as standardShader,zt as starTSL,uo as starfieldSkyTSL,Yo as step,mt as time,st as uniform,nt as uv,te as vec2,lt as vec3,dt as vec4};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { T as TouchTheme, a as TouchThemeName } from './default-controls-BGc61yYl.js';
|
|
2
|
+
export { D as DefaultTouchControlsOptions, J as JoystickSelection, d as defaultTouchControls, b as resolveButtonAccent, r as resolveTouchTheme, t as touchThemes } from './default-controls-BGc61yYl.js';
|
|
3
|
+
import './base-node-life-cycle-CnJ-7zX-.js';
|
|
4
|
+
import 'three';
|
|
5
|
+
import './game-interfaces-tfpM5NBk.js';
|
|
6
|
+
|
|
7
|
+
type TouchThemeInput = TouchTheme | TouchThemeName;
|
|
8
|
+
interface TouchButtonSvgOptions {
|
|
9
|
+
/** Stroke + text accent color. Overrides any theme-resolved accent. */
|
|
10
|
+
accent?: string;
|
|
11
|
+
/** Theme name or full theme object (defaults to `'default'`). */
|
|
12
|
+
theme?: TouchThemeInput;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Stylized joystick base SVG: outer ring, subtle inner ring, and four
|
|
16
|
+
* directional tabs. Designed to scale to any size; consumes only theme
|
|
17
|
+
* color tokens so a single `theme` argument re-skins the whole control.
|
|
18
|
+
*/
|
|
19
|
+
declare function joystickBaseSvg(theme?: TouchThemeInput): string;
|
|
20
|
+
/**
|
|
21
|
+
* Stylized joystick thumb SVG: filled disc with a subtle inner highlight ring.
|
|
22
|
+
*/
|
|
23
|
+
declare function joystickThumbSvg(theme?: TouchThemeInput): string;
|
|
24
|
+
/**
|
|
25
|
+
* Stylized button SVG with a centered label. The accent color drives the
|
|
26
|
+
* outer stroke, the inner translucent fill, and the label text color, so
|
|
27
|
+
* each button can have its own visual identity within a shared theme.
|
|
28
|
+
*
|
|
29
|
+
* @param label Display text (length affects font size, like the engine default).
|
|
30
|
+
* @param options `accent` overrides the theme accent; `theme` selects the palette.
|
|
31
|
+
*/
|
|
32
|
+
declare function touchButtonSvg(label: string, options?: TouchButtonSvgOptions): string;
|
|
33
|
+
|
|
34
|
+
export { type TouchButtonSvgOptions, TouchTheme, type TouchThemeInput, TouchThemeName, joystickBaseSvg, joystickThumbSvg, touchButtonSvg };
|
package/dist/input-ui.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as o,b as e,c as t,d as u,e as c,f as h,g as T}from"./chunk-RXDTAWI2.js";import"./chunk-MSC2BEO5.js";export{T as defaultTouchControls,u as joystickBaseSvg,c as joystickThumbSvg,t as resolveButtonAccent,e as resolveTouchTheme,h as touchButtonSvg,o as touchThemes};
|
package/dist/input.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { I as InputPlayer } from './base-node-life-cycle-CnJ-7zX-.js';
|
|
2
|
+
export { A as AnalogState, c as ButtonName, B as ButtonState, b as InputGamepad, d as InputPlayerNumber, e as InputProvider, a as Inputs } from './base-node-life-cycle-CnJ-7zX-.js';
|
|
3
|
+
import { G as GameInputConfig, V as VirtualTouchConfig } from './game-interfaces-tfpM5NBk.js';
|
|
4
|
+
import 'three';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Maps arrow keys to axes (Horizontal/Vertical) for the given player.
|
|
8
|
+
* @example stage.setInputConfiguration(useArrowsForAxes('p1'));
|
|
9
|
+
*/
|
|
10
|
+
declare function useArrowsForAxes(player: InputPlayer): GameInputConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Maps arrow keys to secondary axes for the given player.
|
|
13
|
+
* @example stage.setInputConfiguration(useArrowsForSecondaryAxes('p1'));
|
|
14
|
+
*/
|
|
15
|
+
declare function useArrowsForSecondaryAxes(player: InputPlayer): GameInputConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Maps arrow keys to directions (Up/Down/Left/Right) for the given player.
|
|
18
|
+
* Useful when `includeDefaults` is false and you still want arrow-key directions.
|
|
19
|
+
* @example stage.setInputConfiguration(useArrowsForDirections('p1'));
|
|
20
|
+
*/
|
|
21
|
+
declare function useArrowsForDirections(player: InputPlayer): GameInputConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Maps W/A/S/D keys to directions (Up/Down/Left/Right) for the given player.
|
|
24
|
+
* @example stage.setInputConfiguration(useWASDForDirections('p1'));
|
|
25
|
+
*/
|
|
26
|
+
declare function useWASDForDirections(player: InputPlayer): GameInputConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Maps W/A/S/D keys to axes (Horizontal/Vertical) for the given player.
|
|
29
|
+
* @example stage.setInputConfiguration(useWASDForAxes('p1'));
|
|
30
|
+
*/
|
|
31
|
+
declare function useWASDForAxes(player: InputPlayer): GameInputConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Maps I/J/K/L keys to axes (Horizontal/Vertical) for the given player.
|
|
34
|
+
* @example stage.setInputConfiguration(useIJKLForAxes('p1'));
|
|
35
|
+
*/
|
|
36
|
+
declare function useIJKLForAxes(player: InputPlayer): GameInputConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Maps I/J/K/L keys to directions (Up/Down/Left/Right) for the given player.
|
|
39
|
+
* @example stage.setInputConfiguration(useIJKLForDirections('p1'));
|
|
40
|
+
*/
|
|
41
|
+
declare function useIJKLForDirections(player: InputPlayer): GameInputConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Enables mouse-look with pointer lock for the given player.
|
|
44
|
+
* Mouse movement maps to SecondaryHorizontal/SecondaryVertical axes;
|
|
45
|
+
* left click maps to LTrigger, right click to RTrigger.
|
|
46
|
+
* @example stage.setInputConfiguration(useMouseLook('p1'));
|
|
47
|
+
*/
|
|
48
|
+
declare function useMouseLook(player: InputPlayer, options?: {
|
|
49
|
+
sensitivity?: number;
|
|
50
|
+
}): GameInputConfig;
|
|
51
|
+
/**
|
|
52
|
+
* Enables basic mouse input (no pointer lock) for the given player.
|
|
53
|
+
* @example stage.setInputConfiguration(useMouse('p1'));
|
|
54
|
+
*/
|
|
55
|
+
declare function useMouse(player: InputPlayer, options?: {
|
|
56
|
+
sensitivity?: number;
|
|
57
|
+
}): GameInputConfig;
|
|
58
|
+
/**
|
|
59
|
+
* Enables virtual touch controls for the given player.
|
|
60
|
+
* By default the provider auto-enables itself on mobile/touch devices.
|
|
61
|
+
* @example stage.setInputConfiguration(useVirtualControls('p1'));
|
|
62
|
+
*/
|
|
63
|
+
declare function useVirtualControls(player: InputPlayer, options?: VirtualTouchConfig): GameInputConfig;
|
|
64
|
+
/**
|
|
65
|
+
* Deep-merges multiple GameInputConfig objects into one.
|
|
66
|
+
* At the player level, configs are merged (both apply).
|
|
67
|
+
* At the key level, later configs win on conflict.
|
|
68
|
+
* @example mergeInputConfigs(useArrowsForAxes('p1'), useWASDForDirections('p1'));
|
|
69
|
+
*/
|
|
70
|
+
declare function mergeInputConfigs(...configs: GameInputConfig[]): GameInputConfig;
|
|
71
|
+
|
|
72
|
+
export { InputPlayer, mergeInputConfigs, useArrowsForAxes, useArrowsForDirections, useArrowsForSecondaryAxes, useIJKLForAxes, useIJKLForDirections, useMouse, useMouseLook, useVirtualControls, useWASDForAxes, useWASDForDirections };
|
package/dist/input.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,b as o,c as r,d as s,e as t,f as u,g as n,h as i,i as p,j as a,k as A}from"./chunk-MSC2BEO5.js";export{A as mergeInputConfigs,e as useArrowsForAxes,r as useArrowsForDirections,o as useArrowsForSecondaryAxes,u as useIJKLForAxes,n as useIJKLForDirections,p as useMouse,i as useMouseLook,a as useVirtualControls,t as useWASDForAxes,s as useWASDForDirections};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { Vector3, Vector2, Color, Material } from 'three';
|
|
2
|
+
import { MeshBasicNodeMaterial } from 'three/webgpu';
|
|
3
|
+
import { Vector3 as Vector3$1 } from '@dimforge/rapier3d-compat';
|
|
4
|
+
|
|
5
|
+
type Vec2 = Vector2;
|
|
6
|
+
type Vec3 = Vector3 | Vector3$1;
|
|
7
|
+
type Vec2Components = {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
11
|
+
type Vec3Components = {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
z: number;
|
|
15
|
+
};
|
|
16
|
+
type Vec2Tuple = readonly [number?, number?] & {
|
|
17
|
+
x?: number;
|
|
18
|
+
y?: number;
|
|
19
|
+
};
|
|
20
|
+
type Vec3Tuple = readonly [number?, number?, number?] & {
|
|
21
|
+
x?: number;
|
|
22
|
+
y?: number;
|
|
23
|
+
z?: number;
|
|
24
|
+
};
|
|
25
|
+
type Vec2Input = Vec2 | {
|
|
26
|
+
x?: number;
|
|
27
|
+
y?: number;
|
|
28
|
+
} | Vec2Tuple;
|
|
29
|
+
type Vec3Input = Vec3 | {
|
|
30
|
+
x?: number;
|
|
31
|
+
y?: number;
|
|
32
|
+
z?: number;
|
|
33
|
+
} | Vec3Tuple;
|
|
34
|
+
declare const VEC2_ZERO: Readonly<Vec2Components>;
|
|
35
|
+
declare const VEC2_ONE: Readonly<Vec2Components>;
|
|
36
|
+
declare const VEC3_ZERO: Readonly<Vec3Components>;
|
|
37
|
+
declare const VEC3_ONE: Readonly<Vec3Components>;
|
|
38
|
+
declare function normalizeVec2(input?: Vec2Input | null, defaults?: Vec2Input | Partial<Vec2Components>): Vec2Components;
|
|
39
|
+
declare function normalizeVec3(input?: Vec3Input | null, defaults?: Vec3Input | Partial<Vec3Components>): Vec3Components;
|
|
40
|
+
declare function toThreeVector2(input?: Vec2Input | null, defaults?: Vec2Input | Partial<Vec2Components>): Vector2;
|
|
41
|
+
declare function toThreeVector3(input?: Vec3Input | null, defaults?: Vec3Input | Partial<Vec3Components>): Vector3;
|
|
42
|
+
declare function toRapierVector3(input?: Vec3Input | null, defaults?: Vec3Input | Partial<Vec3Components>): Vector3$1;
|
|
43
|
+
|
|
44
|
+
declare function shortHash(objString: string): string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* GLSL shader object (traditional WebGL approach).
|
|
48
|
+
*
|
|
49
|
+
* @deprecated game-lib renders with WebGPU, which cannot compile raw GLSL
|
|
50
|
+
* `ShaderMaterial`. Author custom shaders as {@link ZylemTSLShader} (TSL)
|
|
51
|
+
* instead. A GLSL shader passed to a material now logs a warning and renders
|
|
52
|
+
* with a default node material.
|
|
53
|
+
*/
|
|
54
|
+
type ZylemShaderObject = {
|
|
55
|
+
fragment: string;
|
|
56
|
+
vertex: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* TSL shader type (for WebGPU)
|
|
60
|
+
* colorNode should be a TSL node that returns the fragment color
|
|
61
|
+
*/
|
|
62
|
+
type ZylemTSLShader = {
|
|
63
|
+
colorNode: any;
|
|
64
|
+
transparent?: boolean;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Combined shader type supporting both GLSL and TSL
|
|
68
|
+
*/
|
|
69
|
+
type ZylemShader = ZylemShaderObject | ZylemTSLShader;
|
|
70
|
+
/**
|
|
71
|
+
* Check if a shader is a TSL shader
|
|
72
|
+
*/
|
|
73
|
+
declare function isTSLShader(shader: ZylemShader): shader is ZylemTSLShader;
|
|
74
|
+
/**
|
|
75
|
+
* Check if a shader is a GLSL shader
|
|
76
|
+
*/
|
|
77
|
+
declare function isGLSLShader(shader: ZylemShader): shader is ZylemShaderObject;
|
|
78
|
+
interface MaterialOptions {
|
|
79
|
+
path?: string;
|
|
80
|
+
normalMap?: string;
|
|
81
|
+
repeat?: Vec2Input;
|
|
82
|
+
shader?: ZylemShader;
|
|
83
|
+
color?: Color;
|
|
84
|
+
/** Opacity from 0 (fully transparent) to 1 (fully opaque). */
|
|
85
|
+
opacity?: number;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated game-lib is WebGPU-only and always builds TSL node materials.
|
|
88
|
+
* This flag is ignored.
|
|
89
|
+
*/
|
|
90
|
+
useTSL?: boolean;
|
|
91
|
+
}
|
|
92
|
+
type BatchGeometryMap = Map<symbol, number>;
|
|
93
|
+
interface BatchMaterialMapObject {
|
|
94
|
+
geometryMap: BatchGeometryMap;
|
|
95
|
+
material: Material;
|
|
96
|
+
}
|
|
97
|
+
type BatchKey = ReturnType<typeof shortHash>;
|
|
98
|
+
type TexturePath = string | null;
|
|
99
|
+
declare class MaterialBuilder {
|
|
100
|
+
static batchMaterialMap: Map<BatchKey, BatchMaterialMapObject>;
|
|
101
|
+
/**
|
|
102
|
+
* Clear the static batch material cache.
|
|
103
|
+
* Should be called during game disposal to prevent stale material references
|
|
104
|
+
* from persisting across demo/stage switches.
|
|
105
|
+
*/
|
|
106
|
+
static clearBatchCache(): void;
|
|
107
|
+
materials: Material[];
|
|
108
|
+
/**
|
|
109
|
+
* Retained for backward compatibility. game-lib is WebGPU-only and always
|
|
110
|
+
* builds TSL node materials, so this no longer changes behavior.
|
|
111
|
+
*
|
|
112
|
+
* @deprecated
|
|
113
|
+
*/
|
|
114
|
+
private useTSL;
|
|
115
|
+
constructor(useTSL?: boolean);
|
|
116
|
+
batchMaterial(options: Partial<MaterialOptions>, entityType: symbol): void;
|
|
117
|
+
build(options: Partial<MaterialOptions>, entityType: symbol): void;
|
|
118
|
+
withColor(color: Color, useTSL?: boolean, opacity?: number): this;
|
|
119
|
+
withShader(shader: ZylemShaderObject, opacity?: number): this;
|
|
120
|
+
withTSLShader(shader: ZylemTSLShader, opacity?: number): this;
|
|
121
|
+
private applyOpacity;
|
|
122
|
+
/**
|
|
123
|
+
* Set texture - loads in background (deferred).
|
|
124
|
+
* Material is created immediately with null map, texture applies when loaded.
|
|
125
|
+
*/
|
|
126
|
+
setTexture(texturePath?: TexturePath, repeat?: Vec2Input, _useTSL?: boolean, opacity?: number, color?: Color): void;
|
|
127
|
+
/**
|
|
128
|
+
* Set normal map for the current material
|
|
129
|
+
*/
|
|
130
|
+
setNormalMap(normalMapPath: string, repeat?: Vec2Input): void;
|
|
131
|
+
setColor(color: Color, _useTSL?: boolean, opacity?: number): void;
|
|
132
|
+
/**
|
|
133
|
+
* @deprecated GLSL shaders cannot compile on the WebGPU renderer. This now
|
|
134
|
+
* logs a warning and creates a default node material so the entity still
|
|
135
|
+
* renders. Author custom shaders as {@link ZylemTSLShader} (TSL) and use
|
|
136
|
+
* {@link withTSLShader} / `material.shader` instead.
|
|
137
|
+
*/
|
|
138
|
+
setShader(_customShader: ZylemShaderObject, opacity?: number): void;
|
|
139
|
+
/**
|
|
140
|
+
* Set TSL shader (WebGPU compatible)
|
|
141
|
+
*/
|
|
142
|
+
setTSLShader(tslShader: ZylemTSLShader, opacity?: number): void;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Build a standalone WebGPU node material ({@link MeshBasicNodeMaterial}) from
|
|
146
|
+
* a {@link ZylemTSLShader}. Useful for runtime material swapping outside the
|
|
147
|
+
* entity material pipeline (e.g. demos that toggle shader "looks").
|
|
148
|
+
*/
|
|
149
|
+
declare function createNodeMaterialFromTSL(tslShader: ZylemTSLShader, opacity?: number): MeshBasicNodeMaterial;
|
|
150
|
+
|
|
151
|
+
export { type MaterialOptions as M, type TexturePath as T, type Vec3Components as V, type ZylemTSLShader as Z, type Vec3Input as a, type Vec2Input as b, type Vec3 as c, type Vec2 as d, type Vec2Components as e, VEC2_ONE as f, VEC2_ZERO as g, VEC3_ONE as h, VEC3_ZERO as i, normalizeVec3 as j, toThreeVector2 as k, toThreeVector3 as l, type ZylemShaderObject as m, normalizeVec2 as n, type ZylemShader as o, isTSLShader as p, isGLSLShader as q, createNodeMaterialFromTSL as r, MaterialBuilder as s, toRapierVector3 as t };
|