@zylem/behaviors 0.2.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 +26 -0
- package/dist/behavior-system-DYbx-x_-.d.ts +307 -0
- package/dist/chunk-2C3Z5GE7.js +176 -0
- package/dist/chunk-2C3Z5GE7.js.map +1 -0
- package/dist/chunk-2CLT36VB.js +241 -0
- package/dist/chunk-2CLT36VB.js.map +1 -0
- package/dist/chunk-3PYGRHAL.js +35 -0
- package/dist/chunk-3PYGRHAL.js.map +1 -0
- package/dist/chunk-4I6E6DGV.js +212 -0
- package/dist/chunk-4I6E6DGV.js.map +1 -0
- package/dist/chunk-4URF65BR.js +44 -0
- package/dist/chunk-4URF65BR.js.map +1 -0
- package/dist/chunk-6C6NXNEW.js +38 -0
- package/dist/chunk-6C6NXNEW.js.map +1 -0
- package/dist/chunk-ARJWUNRE.js +431 -0
- package/dist/chunk-ARJWUNRE.js.map +1 -0
- package/dist/chunk-BXP4K7RF.js +1205 -0
- package/dist/chunk-BXP4K7RF.js.map +1 -0
- package/dist/chunk-DYLH6K7B.js +44 -0
- package/dist/chunk-DYLH6K7B.js.map +1 -0
- package/dist/chunk-EIWQM6U3.js +27 -0
- package/dist/chunk-EIWQM6U3.js.map +1 -0
- package/dist/chunk-EZNCCO4L.js +14 -0
- package/dist/chunk-EZNCCO4L.js.map +1 -0
- package/dist/chunk-F3KRX2V4.js +457 -0
- package/dist/chunk-F3KRX2V4.js.map +1 -0
- package/dist/chunk-FPTWVCPN.js +53 -0
- package/dist/chunk-FPTWVCPN.js.map +1 -0
- package/dist/chunk-GCNRXAKH.js +37 -0
- package/dist/chunk-GCNRXAKH.js.map +1 -0
- package/dist/chunk-GYURWCIQ.js +1985 -0
- package/dist/chunk-GYURWCIQ.js.map +1 -0
- package/dist/chunk-HZMY3TT4.js +244 -0
- package/dist/chunk-HZMY3TT4.js.map +1 -0
- package/dist/chunk-ID5QJYF5.js +50 -0
- package/dist/chunk-ID5QJYF5.js.map +1 -0
- package/dist/chunk-JAN34G6S.js +552 -0
- package/dist/chunk-JAN34G6S.js.map +1 -0
- package/dist/chunk-K3UNLQ7W.js +118 -0
- package/dist/chunk-K3UNLQ7W.js.map +1 -0
- package/dist/chunk-KDY5N6J4.js +82 -0
- package/dist/chunk-KDY5N6J4.js.map +1 -0
- package/dist/chunk-KOZUNIIE.js +413 -0
- package/dist/chunk-KOZUNIIE.js.map +1 -0
- package/dist/chunk-KS72RZHX.js +30 -0
- package/dist/chunk-KS72RZHX.js.map +1 -0
- package/dist/chunk-LD5SMIB3.js +32 -0
- package/dist/chunk-LD5SMIB3.js.map +1 -0
- package/dist/chunk-OHCPV2NT.js +86 -0
- package/dist/chunk-OHCPV2NT.js.map +1 -0
- package/dist/chunk-OYWFPIHF.js +115 -0
- package/dist/chunk-OYWFPIHF.js.map +1 -0
- package/dist/chunk-POZER3MQ.js +407 -0
- package/dist/chunk-POZER3MQ.js.map +1 -0
- package/dist/chunk-RTRVBEIB.js +56 -0
- package/dist/chunk-RTRVBEIB.js.map +1 -0
- package/dist/chunk-RTVRUNYR.js +29 -0
- package/dist/chunk-RTVRUNYR.js.map +1 -0
- package/dist/chunk-SS7ELMJ7.js +406 -0
- package/dist/chunk-SS7ELMJ7.js.map +1 -0
- package/dist/chunk-STCCNLPC.js +160 -0
- package/dist/chunk-STCCNLPC.js.map +1 -0
- package/dist/chunk-SVLNF434.js +261 -0
- package/dist/chunk-SVLNF434.js.map +1 -0
- package/dist/chunk-UYFOLI2X.js +24 -0
- package/dist/chunk-UYFOLI2X.js.map +1 -0
- package/dist/chunk-VAN4WW3F.js +67 -0
- package/dist/chunk-VAN4WW3F.js.map +1 -0
- package/dist/chunk-WOMHL23C.js +369 -0
- package/dist/chunk-WOMHL23C.js.map +1 -0
- package/dist/chunk-WWVD5DR5.js +120 -0
- package/dist/chunk-WWVD5DR5.js.map +1 -0
- package/dist/chunk-XG2YMCJW.js +201 -0
- package/dist/chunk-XG2YMCJW.js.map +1 -0
- package/dist/chunk-XIJNE67Y.js +210 -0
- package/dist/chunk-XIJNE67Y.js.map +1 -0
- package/dist/chunk-Y6UJOUE5.js +44 -0
- package/dist/chunk-Y6UJOUE5.js.map +1 -0
- package/dist/chunk-YUO6SKJD.js +348 -0
- package/dist/chunk-YUO6SKJD.js.map +1 -0
- package/dist/components--hjBMTnz.d.ts +120 -0
- package/dist/components-B29WHGQN.d.ts +39 -0
- package/dist/components-BWG1GkZA.d.ts +20 -0
- package/dist/components-XCpL6IYt.d.ts +18 -0
- package/dist/components-qWwOsvwh.d.ts +43 -0
- package/dist/cooldown.d.ts +116 -0
- package/dist/cooldown.js +20 -0
- package/dist/cooldown.js.map +1 -0
- package/dist/coordinators/boundary-ricochet-3d.d.ts +19 -0
- package/dist/coordinators/boundary-ricochet-3d.js +8 -0
- package/dist/coordinators/boundary-ricochet-3d.js.map +1 -0
- package/dist/coordinators/boundary-ricochet.d.ts +34 -0
- package/dist/coordinators/boundary-ricochet.js +8 -0
- package/dist/coordinators/boundary-ricochet.js.map +1 -0
- package/dist/coordinators/first-person-shooter.d.ts +35 -0
- package/dist/coordinators/first-person-shooter.js +9 -0
- package/dist/coordinators/first-person-shooter.js.map +1 -0
- package/dist/coordinators/multidirectional-space-shooter.d.ts +27 -0
- package/dist/coordinators/multidirectional-space-shooter.js +10 -0
- package/dist/coordinators/multidirectional-space-shooter.js.map +1 -0
- package/dist/coordinators/top-down-shooter.d.ts +27 -0
- package/dist/coordinators/top-down-shooter.js +10 -0
- package/dist/coordinators/top-down-shooter.js.map +1 -0
- package/dist/core.d.ts +25 -0
- package/dist/core.js +327 -0
- package/dist/core.js.map +1 -0
- package/dist/destructible-3d.d.ts +42 -0
- package/dist/destructible-3d.js +13 -0
- package/dist/destructible-3d.js.map +1 -0
- package/dist/destructible-prebake.d.ts +28 -0
- package/dist/destructible-prebake.js +23 -0
- package/dist/destructible-prebake.js.map +1 -0
- package/dist/entity-types-CmtQ-IBp.d.ts +15 -0
- package/dist/first-person-perspective-C9Mptl0-.d.ts +23 -0
- package/dist/first-person.d.ts +204 -0
- package/dist/first-person.js +27 -0
- package/dist/first-person.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +263 -0
- package/dist/index.js.map +1 -0
- package/dist/jumper-2d.d.ts +113 -0
- package/dist/jumper-2d.js +27 -0
- package/dist/jumper-2d.js.map +1 -0
- package/dist/jumper-3d.d.ts +164 -0
- package/dist/jumper-3d.js +29 -0
- package/dist/jumper-3d.js.map +1 -0
- package/dist/moveable-BCRpjAQb.d.ts +176 -0
- package/dist/particle-emitter/presets.d.ts +46 -0
- package/dist/particle-emitter/presets.js +15 -0
- package/dist/particle-emitter/presets.js.map +1 -0
- package/dist/particle-emitter.d.ts +78 -0
- package/dist/particle-emitter.js +15 -0
- package/dist/particle-emitter.js.map +1 -0
- package/dist/payload-BQzu-oY_.d.ts +89 -0
- package/dist/platformer-3d.d.ts +347 -0
- package/dist/platformer-3d.js +23 -0
- package/dist/platformer-3d.js.map +1 -0
- package/dist/ricochet-2d.d.ts +274 -0
- package/dist/ricochet-2d.js +16 -0
- package/dist/ricochet-2d.js.map +1 -0
- package/dist/ricochet-3d.d.ts +116 -0
- package/dist/ricochet-3d.js +16 -0
- package/dist/ricochet-3d.js.map +1 -0
- package/dist/runtime-2d.d.ts +2 -0
- package/dist/runtime-2d.js +32 -0
- package/dist/runtime-2d.js.map +1 -0
- package/dist/runtime-pong.d.ts +92 -0
- package/dist/runtime-pong.js +38 -0
- package/dist/runtime-pong.js.map +1 -0
- package/dist/screen-visibility.d.ts +74 -0
- package/dist/screen-visibility.js +10 -0
- package/dist/screen-visibility.js.map +1 -0
- package/dist/screen-wrap.d.ts +86 -0
- package/dist/screen-wrap.js +16 -0
- package/dist/screen-wrap.js.map +1 -0
- package/dist/shooter-2d.d.ts +77 -0
- package/dist/shooter-2d.js +12 -0
- package/dist/shooter-2d.js.map +1 -0
- package/dist/spark-DDlIg1nM.d.ts +148 -0
- package/dist/sync-state-machine-CZyspBpj.d.ts +16 -0
- package/dist/thruster.d.ts +132 -0
- package/dist/thruster.js +26 -0
- package/dist/thruster.js.map +1 -0
- package/dist/top-down-movement.d.ts +40 -0
- package/dist/top-down-movement.js +20 -0
- package/dist/top-down-movement.js.map +1 -0
- package/dist/use-behavior-D_82jAL3.d.ts +13 -0
- package/dist/vector-Bm65-FOG.d.ts +45 -0
- package/dist/world-boundary-2d.d.ts +141 -0
- package/dist/world-boundary-2d.js +21 -0
- package/dist/world-boundary-2d.js.map +1 -0
- package/dist/world-boundary-3d.d.ts +75 -0
- package/dist/world-boundary-3d.js +21 -0
- package/dist/world-boundary-3d.js.map +1 -0
- package/package.json +161 -0
package/dist/core.js
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPhysicsBodyComponent,
|
|
3
|
+
createTransformComponent,
|
|
4
|
+
useBehavior
|
|
5
|
+
} from "./chunk-UYFOLI2X.js";
|
|
6
|
+
import {
|
|
7
|
+
StageBodyKind,
|
|
8
|
+
StageBoundaryDim,
|
|
9
|
+
StageEventType,
|
|
10
|
+
StageRicochetDim,
|
|
11
|
+
StageRicochetReflection,
|
|
12
|
+
StageTopDownPlane
|
|
13
|
+
} from "./chunk-Y6UJOUE5.js";
|
|
14
|
+
import {
|
|
15
|
+
VEC2_ONE,
|
|
16
|
+
VEC2_ZERO,
|
|
17
|
+
VEC3_ONE,
|
|
18
|
+
VEC3_ZERO,
|
|
19
|
+
isVec2Input,
|
|
20
|
+
isVec3Input,
|
|
21
|
+
normalizeVec2,
|
|
22
|
+
normalizeVec3,
|
|
23
|
+
toRapierVector3,
|
|
24
|
+
toThreeVector2,
|
|
25
|
+
toThreeVector3
|
|
26
|
+
} from "./chunk-WWVD5DR5.js";
|
|
27
|
+
import {
|
|
28
|
+
clearVelocityIntent,
|
|
29
|
+
setVelocityIntent
|
|
30
|
+
} from "./chunk-RTVRUNYR.js";
|
|
31
|
+
import {
|
|
32
|
+
SyncStateMachine,
|
|
33
|
+
t
|
|
34
|
+
} from "./chunk-4URF65BR.js";
|
|
35
|
+
import {
|
|
36
|
+
defineBehavior
|
|
37
|
+
} from "./chunk-EZNCCO4L.js";
|
|
38
|
+
|
|
39
|
+
// src/lib/actions/capabilities/transform-store.ts
|
|
40
|
+
import { proxy } from "valtio";
|
|
41
|
+
function createTransformStore(initial) {
|
|
42
|
+
const defaultState = {
|
|
43
|
+
position: { x: 0, y: 0, z: 0 },
|
|
44
|
+
rotation: { x: 0, y: 0, z: 0, w: 1 },
|
|
45
|
+
velocity: { x: 0, y: 0, z: 0 },
|
|
46
|
+
angularVelocity: { x: 0, y: 0, z: 0 },
|
|
47
|
+
velocityChannels: {},
|
|
48
|
+
dirty: {
|
|
49
|
+
position: false,
|
|
50
|
+
rotation: false,
|
|
51
|
+
velocity: false,
|
|
52
|
+
velocityX: false,
|
|
53
|
+
velocityY: false,
|
|
54
|
+
velocityZ: false,
|
|
55
|
+
velocityChannels: false,
|
|
56
|
+
angularVelocity: false
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return proxy({
|
|
60
|
+
...defaultState,
|
|
61
|
+
...initial,
|
|
62
|
+
// Ensure dirty flags are properly initialized even if partial initial state
|
|
63
|
+
dirty: {
|
|
64
|
+
...defaultState.dirty,
|
|
65
|
+
...initial?.dirty
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function resetTransformStore(store) {
|
|
70
|
+
store.position.x = 0;
|
|
71
|
+
store.position.y = 0;
|
|
72
|
+
store.position.z = 0;
|
|
73
|
+
store.rotation.x = 0;
|
|
74
|
+
store.rotation.y = 0;
|
|
75
|
+
store.rotation.z = 0;
|
|
76
|
+
store.rotation.w = 1;
|
|
77
|
+
store.velocity.x = 0;
|
|
78
|
+
store.velocity.y = 0;
|
|
79
|
+
store.velocity.z = 0;
|
|
80
|
+
store.angularVelocity.x = 0;
|
|
81
|
+
store.angularVelocity.y = 0;
|
|
82
|
+
store.angularVelocity.z = 0;
|
|
83
|
+
for (const sourceId of Object.keys(store.velocityChannels)) {
|
|
84
|
+
delete store.velocityChannels[sourceId];
|
|
85
|
+
}
|
|
86
|
+
store.dirty.position = false;
|
|
87
|
+
store.dirty.rotation = false;
|
|
88
|
+
store.dirty.velocity = false;
|
|
89
|
+
store.dirty.velocityX = false;
|
|
90
|
+
store.dirty.velocityY = false;
|
|
91
|
+
store.dirty.velocityZ = false;
|
|
92
|
+
store.dirty.velocityChannels = false;
|
|
93
|
+
store.dirty.angularVelocity = false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/lib/actions/capabilities/moveable.ts
|
|
97
|
+
import { Vector3 } from "three";
|
|
98
|
+
function moveX(entity, delta) {
|
|
99
|
+
if (!entity.transformStore) return;
|
|
100
|
+
setVelocityIntent(entity.transformStore, "actions", { x: delta }, { mode: "replace" });
|
|
101
|
+
}
|
|
102
|
+
function moveY(entity, delta) {
|
|
103
|
+
if (!entity.transformStore) return;
|
|
104
|
+
setVelocityIntent(entity.transformStore, "actions", { y: delta }, { mode: "replace" });
|
|
105
|
+
}
|
|
106
|
+
function moveZ(entity, delta) {
|
|
107
|
+
if (!entity.transformStore) return;
|
|
108
|
+
setVelocityIntent(entity.transformStore, "actions", { z: delta }, { mode: "replace" });
|
|
109
|
+
}
|
|
110
|
+
function moveXY(entity, deltaX, deltaY) {
|
|
111
|
+
if (!entity.transformStore) return;
|
|
112
|
+
setVelocityIntent(
|
|
113
|
+
entity.transformStore,
|
|
114
|
+
"actions",
|
|
115
|
+
{ x: deltaX, y: deltaY },
|
|
116
|
+
{ mode: "replace" }
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
function moveXZ(entity, deltaX, deltaZ) {
|
|
120
|
+
if (!entity.transformStore) return;
|
|
121
|
+
setVelocityIntent(
|
|
122
|
+
entity.transformStore,
|
|
123
|
+
"actions",
|
|
124
|
+
{ x: deltaX, z: deltaZ },
|
|
125
|
+
{ mode: "replace" }
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
function move(entity, vector) {
|
|
129
|
+
if (!entity.transformStore) return;
|
|
130
|
+
setVelocityIntent(
|
|
131
|
+
entity.transformStore,
|
|
132
|
+
"actions",
|
|
133
|
+
{ x: vector.x, y: vector.y, z: vector.z },
|
|
134
|
+
{ mode: "add" }
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
function resetVelocity(entity) {
|
|
138
|
+
if (!entity.body) return;
|
|
139
|
+
entity.body.setLinvel(new Vector3(0, 0, 0), true);
|
|
140
|
+
entity.body.setLinearDamping(5);
|
|
141
|
+
}
|
|
142
|
+
function moveForwardXY(entity, delta, rotation2DAngle) {
|
|
143
|
+
const deltaX = Math.sin(-rotation2DAngle) * delta;
|
|
144
|
+
const deltaY = Math.cos(-rotation2DAngle) * delta;
|
|
145
|
+
moveXY(entity, deltaX, deltaY);
|
|
146
|
+
}
|
|
147
|
+
function getPosition(entity) {
|
|
148
|
+
if (!entity.body) return null;
|
|
149
|
+
return entity.body.translation();
|
|
150
|
+
}
|
|
151
|
+
function getVelocity(entity) {
|
|
152
|
+
if (!entity.body) return null;
|
|
153
|
+
return entity.body.linvel();
|
|
154
|
+
}
|
|
155
|
+
function setPosition(entity, x, y, z) {
|
|
156
|
+
if (!entity.body) return;
|
|
157
|
+
entity.body.setTranslation({ x, y, z }, true);
|
|
158
|
+
}
|
|
159
|
+
function setPositionX(entity, x) {
|
|
160
|
+
if (!entity.body) return;
|
|
161
|
+
const { y, z } = entity.body.translation();
|
|
162
|
+
entity.body.setTranslation({ x, y, z }, true);
|
|
163
|
+
}
|
|
164
|
+
function setPositionY(entity, y) {
|
|
165
|
+
if (!entity.body) return;
|
|
166
|
+
const { x, z } = entity.body.translation();
|
|
167
|
+
entity.body.setTranslation({ x, y, z }, true);
|
|
168
|
+
}
|
|
169
|
+
function setPositionZ(entity, z) {
|
|
170
|
+
if (!entity.body) return;
|
|
171
|
+
const { x, y } = entity.body.translation();
|
|
172
|
+
entity.body.setTranslation({ x, y, z }, true);
|
|
173
|
+
}
|
|
174
|
+
function wrapAroundXY(entity, boundsX, boundsY) {
|
|
175
|
+
const position = getPosition(entity);
|
|
176
|
+
if (!position) return;
|
|
177
|
+
const { x, y } = position;
|
|
178
|
+
const newX = x > boundsX ? -boundsX : x < -boundsX ? boundsX : x;
|
|
179
|
+
const newY = y > boundsY ? -boundsY : y < -boundsY ? boundsY : y;
|
|
180
|
+
if (newX !== x || newY !== y) {
|
|
181
|
+
setPosition(entity, newX, newY, 0);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function wrapAround3D(entity, boundsX, boundsY, boundsZ) {
|
|
185
|
+
const position = getPosition(entity);
|
|
186
|
+
if (!position) return;
|
|
187
|
+
const { x, y, z } = position;
|
|
188
|
+
const newX = x > boundsX ? -boundsX : x < -boundsX ? boundsX : x;
|
|
189
|
+
const newY = y > boundsY ? -boundsY : y < -boundsY ? boundsY : y;
|
|
190
|
+
const newZ = z > boundsZ ? -boundsZ : z < -boundsZ ? boundsZ : z;
|
|
191
|
+
if (newX !== x || newY !== y || newZ !== z) {
|
|
192
|
+
setPosition(entity, newX, newY, newZ);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function makeMoveable(entity) {
|
|
196
|
+
const moveable = entity;
|
|
197
|
+
if (!moveable.transformStore) {
|
|
198
|
+
moveable.transformStore = createTransformStore();
|
|
199
|
+
}
|
|
200
|
+
moveable.moveX = (delta) => moveX(entity, delta);
|
|
201
|
+
moveable.moveY = (delta) => moveY(entity, delta);
|
|
202
|
+
moveable.moveZ = (delta) => moveZ(entity, delta);
|
|
203
|
+
moveable.moveXY = (deltaX, deltaY) => moveXY(entity, deltaX, deltaY);
|
|
204
|
+
moveable.moveXZ = (deltaX, deltaZ) => moveXZ(entity, deltaX, deltaZ);
|
|
205
|
+
moveable.move = (vector) => move(entity, vector);
|
|
206
|
+
moveable.resetVelocity = () => resetVelocity(entity);
|
|
207
|
+
moveable.moveForwardXY = (delta, rotation2DAngle) => moveForwardXY(entity, delta, rotation2DAngle);
|
|
208
|
+
moveable.getPosition = () => getPosition(entity);
|
|
209
|
+
moveable.getVelocity = () => getVelocity(entity);
|
|
210
|
+
moveable.setPosition = (x, y, z) => setPosition(entity, x, y, z);
|
|
211
|
+
moveable.setPositionX = (x) => setPositionX(entity, x);
|
|
212
|
+
moveable.setPositionY = (y) => setPositionY(entity, y);
|
|
213
|
+
moveable.setPositionZ = (z) => setPositionZ(entity, z);
|
|
214
|
+
moveable.wrapAroundXY = (boundsX, boundsY) => wrapAroundXY(entity, boundsX, boundsY);
|
|
215
|
+
moveable.wrapAround3D = (boundsX, boundsY, boundsZ) => wrapAround3D(entity, boundsX, boundsY, boundsZ);
|
|
216
|
+
return moveable;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/lib/entities/entity.ts
|
|
220
|
+
var GameEntity = class {
|
|
221
|
+
uuid;
|
|
222
|
+
name;
|
|
223
|
+
type;
|
|
224
|
+
options;
|
|
225
|
+
group = null;
|
|
226
|
+
mesh;
|
|
227
|
+
materials;
|
|
228
|
+
body = null;
|
|
229
|
+
collider = null;
|
|
230
|
+
colliderDesc;
|
|
231
|
+
colliderDescs = [];
|
|
232
|
+
bodyDesc;
|
|
233
|
+
physicsAttached = false;
|
|
234
|
+
runtimeHandle;
|
|
235
|
+
transformStore;
|
|
236
|
+
nodeDestroy;
|
|
237
|
+
isInstanced;
|
|
238
|
+
__behaviorRefs = [];
|
|
239
|
+
create() {
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
onCleanup(callback) {
|
|
243
|
+
void callback;
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
setPosition(_x, _y, _z) {
|
|
247
|
+
}
|
|
248
|
+
setRotation(_x, _y, _z) {
|
|
249
|
+
}
|
|
250
|
+
setRotationZ(_z) {
|
|
251
|
+
}
|
|
252
|
+
setScale(_x, _y, _z) {
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Attach a behavior to this entity. The real engine entity does substantially
|
|
256
|
+
* more, but this functional stub stores the merged ref and builds the handle
|
|
257
|
+
* so descriptor/handle logic (and tests that drive behaviors directly) work
|
|
258
|
+
* without the full engine.
|
|
259
|
+
*/
|
|
260
|
+
use(descriptor, options) {
|
|
261
|
+
const mergedOptions = {
|
|
262
|
+
...descriptor.defaultOptions,
|
|
263
|
+
...options ?? {}
|
|
264
|
+
};
|
|
265
|
+
const ref = { descriptor, options: mergedOptions };
|
|
266
|
+
this.__behaviorRefs.push(ref);
|
|
267
|
+
const baseHandle = {
|
|
268
|
+
getFSM: () => ref.fsm ?? null,
|
|
269
|
+
getOptions: () => ref.options,
|
|
270
|
+
ref
|
|
271
|
+
};
|
|
272
|
+
const extra = descriptor.createHandle ? descriptor.createHandle(ref) : {};
|
|
273
|
+
return { ...baseHandle, ...extra };
|
|
274
|
+
}
|
|
275
|
+
/** Live behavior refs attached via {@link use}. */
|
|
276
|
+
getBehaviorRefs() {
|
|
277
|
+
return this.__behaviorRefs;
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
export {
|
|
281
|
+
GameEntity,
|
|
282
|
+
StageBodyKind,
|
|
283
|
+
StageBoundaryDim,
|
|
284
|
+
StageEventType,
|
|
285
|
+
StageRicochetDim,
|
|
286
|
+
StageRicochetReflection,
|
|
287
|
+
StageTopDownPlane,
|
|
288
|
+
SyncStateMachine,
|
|
289
|
+
VEC2_ONE,
|
|
290
|
+
VEC2_ZERO,
|
|
291
|
+
VEC3_ONE,
|
|
292
|
+
VEC3_ZERO,
|
|
293
|
+
clearVelocityIntent,
|
|
294
|
+
createPhysicsBodyComponent,
|
|
295
|
+
createTransformComponent,
|
|
296
|
+
createTransformStore,
|
|
297
|
+
defineBehavior,
|
|
298
|
+
getPosition,
|
|
299
|
+
getVelocity,
|
|
300
|
+
isVec2Input,
|
|
301
|
+
isVec3Input,
|
|
302
|
+
makeMoveable,
|
|
303
|
+
move,
|
|
304
|
+
moveForwardXY,
|
|
305
|
+
moveX,
|
|
306
|
+
moveXY,
|
|
307
|
+
moveXZ,
|
|
308
|
+
moveY,
|
|
309
|
+
moveZ,
|
|
310
|
+
normalizeVec2,
|
|
311
|
+
normalizeVec3,
|
|
312
|
+
resetTransformStore,
|
|
313
|
+
resetVelocity,
|
|
314
|
+
setPosition,
|
|
315
|
+
setPositionX,
|
|
316
|
+
setPositionY,
|
|
317
|
+
setPositionZ,
|
|
318
|
+
setVelocityIntent,
|
|
319
|
+
t,
|
|
320
|
+
toRapierVector3,
|
|
321
|
+
toThreeVector2,
|
|
322
|
+
toThreeVector3,
|
|
323
|
+
useBehavior,
|
|
324
|
+
wrapAround3D,
|
|
325
|
+
wrapAroundXY
|
|
326
|
+
};
|
|
327
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/actions/capabilities/transform-store.ts","../src/lib/actions/capabilities/moveable.ts","../src/lib/entities/entity.ts"],"sourcesContent":["import { proxy } from 'valtio';\n\nexport type VelocityIntentMode = 'replace' | 'add';\n\nexport interface VelocityIntent {\n\tx?: number;\n\ty?: number;\n\tz?: number;\n\tmode: VelocityIntentMode;\n\tpriority?: number;\n}\n\n/**\n * Transform state managed by Valtio for batched physics updates.\n * \n * This store accumulates transformation intents during the frame,\n * then applies them all at once after onUpdate() callbacks complete.\n * \n * Design decisions:\n * - Position: Accumulated deltas (additive)\n * - Rotation: Last value wins (replacement)\n * - Velocity: Accumulated deltas (additive)\n * - Angular velocity: Accumulated deltas (additive)\n */\nexport interface TransformState {\n\t/** Position deltas to be applied (accumulated) */\n\tposition: { x: number; y: number; z: number };\n\t\n\t/** Rotation quaternion (last value wins) */\n\trotation: { x: number; y: number; z: number; w: number };\n\t\n\t/** Linear velocity (accumulated) */\n\tvelocity: { x: number; y: number; z: number };\n\t\n\t/** Angular velocity (accumulated) */\n\tangularVelocity: { x: number; y: number; z: number };\n\n\t/** Per-source velocity intents composed once per frame */\n\tvelocityChannels: Record<string, VelocityIntent>;\n\t\n\t/** Dirty flags to track what needs to be applied */\n\tdirty: {\n\t\tposition: boolean;\n\t\trotation: boolean;\n\t\t/** @deprecated Use per-axis velocityX/Y/Z flags for new code */\n\t\tvelocity: boolean;\n\t\tvelocityX: boolean;\n\t\tvelocityY: boolean;\n\t\tvelocityZ: boolean;\n\t\tvelocityChannels: boolean;\n\t\tangularVelocity: boolean;\n\t};\n}\n\n/**\n * Create a new transform store with optional initial values.\n * The store is a Valtio proxy, making it reactive for debugging/visualization.\n * \n * @param initial Optional initial state values\n * @returns Reactive transform state\n */\nexport function createTransformStore(initial?: Partial<TransformState>): TransformState {\n\tconst defaultState: TransformState = {\n\t\tposition: { x: 0, y: 0, z: 0 },\n\t\trotation: { x: 0, y: 0, z: 0, w: 1 },\n\t\tvelocity: { x: 0, y: 0, z: 0 },\n\t\tangularVelocity: { x: 0, y: 0, z: 0 },\n\t\tvelocityChannels: {},\n\t\tdirty: {\n\t\t\tposition: false,\n\t\t\trotation: false,\n\t\t\tvelocity: false,\n\t\t\tvelocityX: false,\n\t\t\tvelocityY: false,\n\t\t\tvelocityZ: false,\n\t\t\tvelocityChannels: false,\n\t\t\tangularVelocity: false,\n\t\t},\n\t};\n\n\treturn proxy({\n\t\t...defaultState,\n\t\t...initial,\n\t\t// Ensure dirty flags are properly initialized even if partial initial state\n\t\tdirty: {\n\t\t\t...defaultState.dirty,\n\t\t\t...initial?.dirty,\n\t\t},\n\t});\n}\n\n/**\n * Reset a transform store to its initial clean state.\n * Called after applying changes to prepare for the next frame.\n * \n * @param store The transform store to reset\n */\nexport function resetTransformStore(store: TransformState): void {\n\t// Reset position deltas\n\tstore.position.x = 0;\n\tstore.position.y = 0;\n\tstore.position.z = 0;\n\n\t// Reset rotation to identity quaternion\n\tstore.rotation.x = 0;\n\tstore.rotation.y = 0;\n\tstore.rotation.z = 0;\n\tstore.rotation.w = 1;\n\n\t// Reset velocity\n\tstore.velocity.x = 0;\n\tstore.velocity.y = 0;\n\tstore.velocity.z = 0;\n\n\t// Reset angular velocity\n\tstore.angularVelocity.x = 0;\n\tstore.angularVelocity.y = 0;\n\tstore.angularVelocity.z = 0;\n\n\t// Reset per-source velocity intents\n\tfor (const sourceId of Object.keys(store.velocityChannels)) {\n\t\tdelete store.velocityChannels[sourceId];\n\t}\n\n\t// Clear all dirty flags\n\tstore.dirty.position = false;\n\tstore.dirty.rotation = false;\n\tstore.dirty.velocity = false;\n\tstore.dirty.velocityX = false;\n\tstore.dirty.velocityY = false;\n\tstore.dirty.velocityZ = false;\n\tstore.dirty.velocityChannels = false;\n\tstore.dirty.angularVelocity = false;\n}\n","import { Vector3 } from 'three';\nimport { RigidBody, Vector } from '@dimforge/rapier3d-compat';\nimport type { TransformState } from './transform-store';\nimport { createTransformStore } from './transform-store';\nimport { setVelocityIntent } from './velocity-intents';\n\nexport interface EntityWithBody {\n\tbody: RigidBody | null;\n\ttransformStore?: TransformState;\n}\n\n/**\n * Move an entity along the X axis, preserving other velocities.\n */\nexport function moveX(entity: EntityWithBody, delta: number): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(entity.transformStore, 'actions', { x: delta }, { mode: 'replace' });\n}\n\n/**\n * Move an entity along the Y axis, preserving other velocities.\n */\nexport function moveY(entity: EntityWithBody, delta: number): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(entity.transformStore, 'actions', { y: delta }, { mode: 'replace' });\n}\n\n/**\n * Move an entity along the Z axis, preserving other velocities.\n */\nexport function moveZ(entity: EntityWithBody, delta: number): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(entity.transformStore, 'actions', { z: delta }, { mode: 'replace' });\n}\n\n/**\n * Move an entity along the X and Y axis, preserving Z velocity.\n */\nexport function moveXY(entity: EntityWithBody, deltaX: number, deltaY: number): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(\n\t\tentity.transformStore,\n\t\t'actions',\n\t\t{ x: deltaX, y: deltaY },\n\t\t{ mode: 'replace' },\n\t);\n}\n\n/**\n * Move an entity along the X and Z axis, preserving Y velocity.\n */\nexport function moveXZ(entity: EntityWithBody, deltaX: number, deltaZ: number): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(\n\t\tentity.transformStore,\n\t\t'actions',\n\t\t{ x: deltaX, z: deltaZ },\n\t\t{ mode: 'replace' },\n\t);\n}\n\n/**\n * Move entity based on a vector, adding to existing velocities.\n */\nexport function move(entity: EntityWithBody, vector: Vector3): void {\n\tif (!entity.transformStore) return;\n\tsetVelocityIntent(\n\t\tentity.transformStore,\n\t\t'actions',\n\t\t{ x: vector.x, y: vector.y, z: vector.z },\n\t\t{ mode: 'add' },\n\t);\n}\n\n/**\n * Reset entity velocity\n */\nexport function resetVelocity(entity: EntityWithBody): void {\n\tif (!entity.body) return;\n\tentity.body.setLinvel(new Vector3(0, 0, 0), true);\n\tentity.body.setLinearDamping(5);\n}\n\n/**\n * Move entity forward in 2D space, preserving Z velocity\n */\nexport function moveForwardXY(entity: EntityWithBody, delta: number, rotation2DAngle: number): void {\n\tconst deltaX = Math.sin(-rotation2DAngle) * delta;\n\tconst deltaY = Math.cos(-rotation2DAngle) * delta;\n\tmoveXY(entity, deltaX, deltaY);\n}\n\n/**\n * Get entity position\n */\nexport function getPosition(entity: EntityWithBody): Vector | null {\n\tif (!entity.body) return null;\n\treturn entity.body.translation();\n}\n\n/**\n * Get entity velocity\n */\nexport function getVelocity(entity: EntityWithBody): Vector | null {\n\tif (!entity.body) return null;\n\treturn entity.body.linvel();\n}\n\n/**\n * Set entity position\n */\nexport function setPosition(entity: EntityWithBody, x: number, y: number, z: number): void {\n\tif (!entity.body) return;\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity X position\n */\nexport function setPositionX(entity: EntityWithBody, x: number): void {\n\tif (!entity.body) return;\n\tconst { y, z } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity Y position\n */\nexport function setPositionY(entity: EntityWithBody, y: number): void {\n\tif (!entity.body) return;\n\tconst { x, z } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Set entity Z position\n */\nexport function setPositionZ(entity: EntityWithBody, z: number): void {\n\tif (!entity.body) return;\n\tconst { x, y } = entity.body.translation();\n\tentity.body.setTranslation({ x, y, z }, true);\n}\n\n/**\n * Wrap entity around 2D bounds\n */\nexport function wrapAroundXY(entity: EntityWithBody, boundsX: number, boundsY: number): void {\n\tconst position = getPosition(entity);\n\tif (!position) return;\n\n\tconst { x, y } = position;\n\tconst newX = x > boundsX ? -boundsX : (x < -boundsX ? boundsX : x);\n\tconst newY = y > boundsY ? -boundsY : (y < -boundsY ? boundsY : y);\n\n\tif (newX !== x || newY !== y) {\n\t\tsetPosition(entity, newX, newY, 0);\n\t}\n}\n\n/**\n * Wrap entity around 3D bounds\n */\nexport function wrapAround3D(entity: EntityWithBody, boundsX: number, boundsY: number, boundsZ: number): void {\n\tconst position = getPosition(entity);\n\tif (!position) return;\n\n\tconst { x, y, z } = position;\n\tconst newX = x > boundsX ? -boundsX : (x < -boundsX ? boundsX : x);\n\tconst newY = y > boundsY ? -boundsY : (y < -boundsY ? boundsY : y);\n\tconst newZ = z > boundsZ ? -boundsZ : (z < -boundsZ ? boundsZ : z);\n\n\tif (newX !== x || newY !== y || newZ !== z) {\n\t\tsetPosition(entity, newX, newY, newZ);\n\t}\n}\n\n/**\n * Enhanced moveable entity with bound methods\n */\nexport interface MoveableEntity extends EntityWithBody {\n\tmoveX(delta: number): void;\n\tmoveY(delta: number): void;\n\tmoveZ(delta: number): void;\n\tmoveXY(deltaX: number, deltaY: number): void;\n\tmoveXZ(deltaX: number, deltaZ: number): void;\n\tmove(vector: Vector3): void;\n\tresetVelocity(): void;\n\tmoveForwardXY(delta: number, rotation2DAngle: number): void;\n\tgetPosition(): Vector | null;\n\tgetVelocity(): Vector | null;\n\tsetPosition(x: number, y: number, z: number): void;\n\tsetPositionX(x: number): void;\n\tsetPositionY(y: number): void;\n\tsetPositionZ(z: number): void;\n\twrapAroundXY(boundsX: number, boundsY: number): void;\n\twrapAround3D(boundsX: number, boundsY: number, boundsZ: number): void;\n}\n\n/**\n * Enhance an entity with additive movement methods.\n * Automatically creates a transform store if one doesn't exist.\n */\nexport function makeMoveable<T extends EntityWithBody>(entity: T): T & MoveableEntity {\n\tconst moveable = entity as T & MoveableEntity;\n\n\t// Create transform store if it doesn't exist\n\tif (!moveable.transformStore) {\n\t\tmoveable.transformStore = createTransformStore();\n\t}\n\n\tmoveable.moveX = (delta: number) => moveX(entity, delta);\n\tmoveable.moveY = (delta: number) => moveY(entity, delta);\n\tmoveable.moveZ = (delta: number) => moveZ(entity, delta);\n\tmoveable.moveXY = (deltaX: number, deltaY: number) => moveXY(entity, deltaX, deltaY);\n\tmoveable.moveXZ = (deltaX: number, deltaZ: number) => moveXZ(entity, deltaX, deltaZ);\n\tmoveable.move = (vector: Vector3) => move(entity, vector);\n\tmoveable.resetVelocity = () => resetVelocity(entity);\n\tmoveable.moveForwardXY = (delta: number, rotation2DAngle: number) => moveForwardXY(entity, delta, rotation2DAngle);\n\tmoveable.getPosition = () => getPosition(entity);\n\tmoveable.getVelocity = () => getVelocity(entity);\n\tmoveable.setPosition = (x: number, y: number, z: number) => setPosition(entity, x, y, z);\n\tmoveable.setPositionX = (x: number) => setPositionX(entity, x);\n\tmoveable.setPositionY = (y: number) => setPositionY(entity, y);\n\tmoveable.setPositionZ = (z: number) => setPositionZ(entity, z);\n\tmoveable.wrapAroundXY = (boundsX: number, boundsY: number) => wrapAroundXY(entity, boundsX, boundsY);\n\tmoveable.wrapAround3D = (boundsX: number, boundsY: number, boundsZ: number) => wrapAround3D(entity, boundsX, boundsY, boundsZ);\n\n\treturn moveable;\n}","import type {\n\tBehaviorDescriptor,\n\tBehaviorHandle,\n\tBehaviorRef,\n} from '../behaviors/behavior-descriptor';\n\n/**\n * Minimal, runtime-agnostic entity options contract.\n *\n * The full engine entity (in `@zylem/game-lib`) provides a richer options type,\n * but behaviors only rely on this loose shape.\n */\nexport interface GameEntityOptions {\n\t[key: string]: any;\n\tname?: string;\n}\n\n/**\n * Structural stand-in for the engine `GameEntity`.\n *\n * Behaviors annotate against this loose contract so that `@zylem/behaviors`\n * (and its `@zylem/behaviors/core` surface) never has to depend on the concrete\n * `@zylem/game-lib` entity implementation. The real engine entity is\n * structurally assignable to this type.\n */\nexport class GameEntity<TOptions = unknown> {\n\t[key: string]: any;\n\n\tuuid!: string;\n\tname!: string;\n\ttype!: string;\n\toptions?: TOptions & Record<string, unknown>;\n\tgroup: any = null;\n\tmesh?: any;\n\tmaterials?: any[];\n\tbody: any = null;\n\tcollider: any = null;\n\tcolliderDesc?: any;\n\tcolliderDescs: any[] = [];\n\tbodyDesc?: any;\n\tphysicsAttached = false;\n\truntimeHandle?: number;\n\ttransformStore?: any;\n\tnodeDestroy?: any;\n\tisInstanced?: boolean;\n\n\tprivate __behaviorRefs: BehaviorRef<any>[] = [];\n\n\tcreate(): this {\n\t\treturn this;\n\t}\n\n\tonCleanup(callback: () => void): this {\n\t\tvoid callback;\n\t\treturn this;\n\t}\n\n\tsetPosition(_x: number, _y: number, _z: number): void {}\n\tsetRotation(_x: number, _y: number, _z: number): void {}\n\tsetRotationZ(_z: number): void {}\n\tsetScale(_x: number, _y: number, _z: number): void {}\n\n\t/**\n\t * Attach a behavior to this entity. The real engine entity does substantially\n\t * more, but this functional stub stores the merged ref and builds the handle\n\t * so descriptor/handle logic (and tests that drive behaviors directly) work\n\t * without the full engine.\n\t */\n\tuse<\n\t\tO extends Record<string, any>,\n\t\tH extends Record<string, any> = Record<string, never>,\n\t>(\n\t\tdescriptor: BehaviorDescriptor<O, H>,\n\t\toptions?: Partial<O>,\n\t): BehaviorHandle<O, H> {\n\t\tconst mergedOptions = {\n\t\t\t...(descriptor.defaultOptions as O),\n\t\t\t...(options ?? {}),\n\t\t} as O;\n\t\tconst ref: BehaviorRef<O> = { descriptor, options: mergedOptions };\n\t\tthis.__behaviorRefs.push(ref as BehaviorRef<any>);\n\n\t\tconst baseHandle = {\n\t\t\tgetFSM: () => ref.fsm ?? null,\n\t\t\tgetOptions: () => ref.options,\n\t\t\tref,\n\t\t};\n\t\tconst extra = descriptor.createHandle\n\t\t\t? descriptor.createHandle(ref)\n\t\t\t: ({} as H);\n\t\treturn { ...baseHandle, ...extra } as BehaviorHandle<O, H>;\n\t}\n\n\t/** Live behavior refs attached via {@link use}. */\n\tgetBehaviorRefs(): BehaviorRef<any>[] {\n\t\treturn this.__behaviorRefs;\n\t}\n}\n\n/**\n * Factory contract injected into behavior systems via\n * {@link BehaviorSystemContext.createEntity}. The host engine supplies the real\n * entity factory at stage-construction time.\n */\nexport type CreateEntityFn = (\n\toptions?: Partial<GameEntityOptions>,\n) => GameEntity<GameEntityOptions>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AA6Df,SAAS,qBAAqB,SAAmD;AACvF,QAAM,eAA+B;AAAA,IACpC,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;AAAA,IAC7B,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;AAAA,IACnC,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;AAAA,IAC7B,iBAAiB,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;AAAA,IACpC,kBAAkB,CAAC;AAAA,IACnB,OAAO;AAAA,MACN,UAAU;AAAA,MACV,UAAU;AAAA,MACV,UAAU;AAAA,MACV,WAAW;AAAA,MACX,WAAW;AAAA,MACX,WAAW;AAAA,MACX,kBAAkB;AAAA,MAClB,iBAAiB;AAAA,IAClB;AAAA,EACD;AAEA,SAAO,MAAM;AAAA,IACZ,GAAG;AAAA,IACH,GAAG;AAAA;AAAA,IAEH,OAAO;AAAA,MACN,GAAG,aAAa;AAAA,MAChB,GAAG,SAAS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QAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA,OAAY;AAAA,EACZ,WAAgB;AAAA,EAChB;AAAA,EACA,gBAAuB,CAAC;AAAA,EACxB;AAAA,EACA,kBAAkB;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEQ,iBAAqC,CAAC;AAAA,EAE9C,SAAe;AACd,WAAO;AAAA,EACR;AAAA,EAEA,UAAU,UAA4B;AACrC,SAAK;AACL,WAAO;AAAA,EACR;AAAA,EAEA,YAAY,IAAY,IAAY,IAAkB;AAAA,EAAC;AAAA,EACvD,YAAY,IAAY,IAAY,IAAkB;AAAA,EAAC;AAAA,EACvD,aAAa,IAAkB;AAAA,EAAC;AAAA,EAChC,SAAS,IAAY,IAAY,IAAkB;AAAA,EAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQpD,IAIC,YACA,SACuB;AACvB,UAAM,gBAAgB;AAAA,MACrB,GAAI,WAAW;AAAA,MACf,GAAI,WAAW,CAAC;AAAA,IACjB;AACA,UAAM,MAAsB,EAAE,YAAY,SAAS,cAAc;AACjE,SAAK,eAAe,KAAK,GAAuB;AAEhD,UAAM,aAAa;AAAA,MAClB,QAAQ,MAAM,IAAI,OAAO;AAAA,MACzB,YAAY,MAAM,IAAI;AAAA,MACtB;AAAA,IACD;AACA,UAAM,QAAQ,WAAW,eACtB,WAAW,aAAa,GAAG,IAC1B,CAAC;AACL,WAAO,EAAE,GAAG,YAAY,GAAG,MAAM;AAAA,EAClC;AAAA;AAAA,EAGA,kBAAsC;AACrC,WAAO,KAAK;AAAA,EACb;AACD;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { a as BehaviorDescriptor } from './behavior-system-DYbx-x_-.js';
|
|
2
|
+
import { Material } from 'three';
|
|
3
|
+
import { FractureOptions, DestructibleMesh } from '@dgreenheck/three-pinata';
|
|
4
|
+
export { DestructibleMesh, FractureOptions, VoronoiOptions } from '@dgreenheck/three-pinata';
|
|
5
|
+
export { D as DestructiblePrebakeWorkerAPI, P as PlainBufferGeometryPayload, a as PlainFractureOptions, c as PrebakeWorkerRequest, d as PrebakeWorkerResponse } from './payload-BQzu-oY_.js';
|
|
6
|
+
|
|
7
|
+
type FractureOptionsInput = NonNullable<ConstructorParameters<typeof FractureOptions>[0]>;
|
|
8
|
+
type Destructible3DFragmentColliderShape = 'convexHull' | 'cuboid' | 'trimesh';
|
|
9
|
+
interface Destructible3DColliderOptions {
|
|
10
|
+
shape?: Destructible3DFragmentColliderShape;
|
|
11
|
+
sensor?: boolean;
|
|
12
|
+
collisionGroups?: number;
|
|
13
|
+
activeCollisionTypes?: number;
|
|
14
|
+
}
|
|
15
|
+
interface Destructible3DFragmentPhysicsOptions {
|
|
16
|
+
mode?: 'compound' | 'independent';
|
|
17
|
+
inheritSourceVelocity?: boolean;
|
|
18
|
+
outwardVelocity?: number;
|
|
19
|
+
angularVelocity?: number;
|
|
20
|
+
}
|
|
21
|
+
interface Destructible3DBehaviorOptions {
|
|
22
|
+
fractureOptions?: FractureOptionsInput | FractureOptions;
|
|
23
|
+
innerMaterial?: Material | null;
|
|
24
|
+
collider?: Destructible3DColliderOptions;
|
|
25
|
+
fragmentPhysics?: Destructible3DFragmentPhysicsOptions;
|
|
26
|
+
/**
|
|
27
|
+
* When set, {@link Destructible3DHandle.prebakeAsync} runs Voronoi fracture
|
|
28
|
+
* in a Web Worker (see `destructible-prebake-worker` bundle).
|
|
29
|
+
*/
|
|
30
|
+
prebakeWorkerUrl?: URL | string;
|
|
31
|
+
}
|
|
32
|
+
interface Destructible3DHandle {
|
|
33
|
+
fracture(overrideOptions?: FractureOptionsInput | FractureOptions): readonly DestructibleMesh[];
|
|
34
|
+
prebake(overrideOptions?: FractureOptionsInput | FractureOptions): void;
|
|
35
|
+
prebakeAsync(overrideOptions?: FractureOptionsInput | FractureOptions): Promise<void>;
|
|
36
|
+
repair(): void;
|
|
37
|
+
isFractured(): boolean;
|
|
38
|
+
getFragments(): readonly DestructibleMesh[];
|
|
39
|
+
}
|
|
40
|
+
declare const Destructible3DBehavior: BehaviorDescriptor<Destructible3DBehaviorOptions, Destructible3DHandle, unknown>;
|
|
41
|
+
|
|
42
|
+
export { Destructible3DBehavior, type Destructible3DBehaviorOptions, type Destructible3DColliderOptions, type Destructible3DFragmentColliderShape, type Destructible3DFragmentPhysicsOptions, type Destructible3DHandle, type FractureOptionsInput };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Destructible3DBehavior,
|
|
3
|
+
DestructibleMesh,
|
|
4
|
+
FractureOptions
|
|
5
|
+
} from "./chunk-BXP4K7RF.js";
|
|
6
|
+
import "./chunk-HZMY3TT4.js";
|
|
7
|
+
import "./chunk-EZNCCO4L.js";
|
|
8
|
+
export {
|
|
9
|
+
Destructible3DBehavior,
|
|
10
|
+
DestructibleMesh,
|
|
11
|
+
FractureOptions
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=destructible-3d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Mesh, Group, BufferGeometry } from 'three';
|
|
2
|
+
import { FractureOptions } from '@dgreenheck/three-pinata';
|
|
3
|
+
export { D as DestructiblePrebakeWorkerAPI, P as PlainBufferGeometryPayload, a as PlainFractureOptions, b as PlainWorkerFragmentPayload, c as PrebakeWorkerRequest, d as PrebakeWorkerResponse, e as bufferGeometryToPlain, f as destructibleFragmentsToPlainResponse, p as pinataFractureOptionsToPlain, g as plainFractureOptionsToPinata, h as plainToBufferGeometry, i as plainWorkerResultToTemplateParts } from './payload-BQzu-oY_.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes source mesh geometry for Voronoi prebake / fracture so runtime and
|
|
7
|
+
* CLI tooling share one code path (float attributes, non-indexed, root-relative transform).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Clones geometry with float32 attributes and expands indexed meshes to non-indexed.
|
|
12
|
+
*/
|
|
13
|
+
declare function normalizeFractureSourceGeometry(sourceGeometry: BufferGeometry): BufferGeometry;
|
|
14
|
+
/**
|
|
15
|
+
* Produces fracture-space geometry: normalized mesh vertices in root-local space.
|
|
16
|
+
*/
|
|
17
|
+
declare function buildNormalizedFractureSourceGeometry(mesh: Mesh, root: Group): BufferGeometry;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Stable JSON key for matching prebaked fragment templates to fracture options.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Serializes fracture options for prebake cache identity (mesh not included).
|
|
25
|
+
*/
|
|
26
|
+
declare function buildFractureGeometryCacheKey(options: FractureOptions): string;
|
|
27
|
+
|
|
28
|
+
export { buildFractureGeometryCacheKey, buildNormalizedFractureSourceGeometry, normalizeFractureSourceGeometry };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
bufferGeometryToPlain,
|
|
3
|
+
buildFractureGeometryCacheKey,
|
|
4
|
+
buildNormalizedFractureSourceGeometry,
|
|
5
|
+
destructibleFragmentsToPlainResponse,
|
|
6
|
+
normalizeFractureSourceGeometry,
|
|
7
|
+
pinataFractureOptionsToPlain,
|
|
8
|
+
plainFractureOptionsToPinata,
|
|
9
|
+
plainToBufferGeometry,
|
|
10
|
+
plainWorkerResultToTemplateParts
|
|
11
|
+
} from "./chunk-HZMY3TT4.js";
|
|
12
|
+
export {
|
|
13
|
+
bufferGeometryToPlain,
|
|
14
|
+
buildFractureGeometryCacheKey,
|
|
15
|
+
buildNormalizedFractureSourceGeometry,
|
|
16
|
+
destructibleFragmentsToPlainResponse,
|
|
17
|
+
normalizeFractureSourceGeometry,
|
|
18
|
+
pinataFractureOptionsToPlain,
|
|
19
|
+
plainFractureOptionsToPinata,
|
|
20
|
+
plainToBufferGeometry,
|
|
21
|
+
plainWorkerResultToTemplateParts
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=destructible-prebake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Group } from 'three';
|
|
2
|
+
import { RigidBody, Collider } from '@dimforge/rapier3d-compat';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Base entity interface - shared across modules to prevent circular dependencies
|
|
6
|
+
*/
|
|
7
|
+
interface BaseEntityInterface {
|
|
8
|
+
uuid: string;
|
|
9
|
+
name: string;
|
|
10
|
+
group: Group | null | undefined;
|
|
11
|
+
body: RigidBody | null | undefined;
|
|
12
|
+
collider: Collider | null | undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type { BaseEntityInterface as B };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Vector3 } from 'three';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Structural contract for the engine `FirstPersonPerspective`.
|
|
5
|
+
*
|
|
6
|
+
* Behaviors drive a perspective (yaw/pitch accumulation + eye position) without
|
|
7
|
+
* depending on the concrete camera implementation in `@zylem/game-lib`. The real
|
|
8
|
+
* `FirstPersonPerspective` class is structurally assignable to this interface.
|
|
9
|
+
*/
|
|
10
|
+
interface FirstPersonPerspective {
|
|
11
|
+
/** Fallback / eye position. Mutated directly by the first-person behavior. */
|
|
12
|
+
initialPosition?: Vector3;
|
|
13
|
+
/** Current yaw in radians. */
|
|
14
|
+
readonly yaw: number;
|
|
15
|
+
/** Current pitch in radians. */
|
|
16
|
+
readonly pitch: number;
|
|
17
|
+
/** Accumulate yaw and pitch deltas. */
|
|
18
|
+
look(deltaYaw: number, deltaPitch: number): void;
|
|
19
|
+
/** Set absolute yaw and pitch. */
|
|
20
|
+
setLook?(yaw: number, pitch: number): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type { FirstPersonPerspective as F };
|