@vgai/engine 0.4.1 → 0.5.0-canary.20260719.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 +48 -15
- package/package.json +11 -25
- package/schemas/engine-capabilities.json +10 -10
- package/schemas/entity2d.schema.json +468 -0
- package/schemas/mat.schema.json +2 -33
- package/schemas/prefab.schema.json +16 -172
- package/schemas/scn2d.schema.json +42 -23
- package/schemas/vgai-game.schema.json +34 -0
- package/schemas/vscn.schema.json +16 -172
- package/src/adapter/authoring.ts +152 -2
- package/src/adapter/colyseus-networking-adapter.ts +35 -1
- package/src/adapter/first-party-systems.ts +7 -1
- package/src/adapter/game-adapter.ts +13 -0
- package/src/adapter/index.ts +25 -0
- package/src/adapter/rapier-physics-adapter.ts +55 -2
- package/src/adapter/system-adapter.ts +249 -2
- package/src/adapter/vgai-scene-game-adapter.ts +149 -25
- package/src/ai/navigation.ts +28 -0
- package/src/animation/clip-map.ts +1 -8
- package/src/animation/theatre-director.ts +50 -0
- package/src/animation/xstate-animation-binding.ts +6 -0
- package/src/audio/audio-introspection.ts +290 -0
- package/src/audio/tone-context.ts +46 -0
- package/src/dev/chrome-trace.ts +153 -0
- package/src/dev/performance-profiler.ts +93 -6
- package/src/dev/render-debug-adapter.ts +199 -0
- package/src/dev/render-memory.ts +243 -0
- package/src/dev/webgl-frame-capture.ts +424 -0
- package/src/ecs/component-manager.ts +43 -10
- package/src/ecs/game-component.ts +39 -10
- package/src/input/input-manager.ts +24 -19
- package/src/input/input-types.ts +1 -1
- package/src/loader.ts +7 -0
- package/src/manifest/load.ts +14 -0
- package/src/manifest/schema.ts +65 -0
- package/src/react/game-state.tsx +1 -1
- package/src/render/render-batch-system.ts +26 -12
- package/src/render/spark-renderer-lifecycle.ts +64 -0
- package/src/runtime/create-runtime.ts +33 -5
- package/src/runtime/debug-bridge.ts +5 -5
- package/src/runtime/game.ts +102 -20
- package/src/runtime/mount-manifest.ts +1 -1
- package/src/runtime/render-control.ts +121 -0
- package/src/runtime/types.ts +1 -1
- package/src/scene/asset-loaders.ts +77 -3
- package/src/scene/instance-mesh.ts +25 -0
- package/src/scene/material-factory.ts +4 -15
- package/src/scene/mesh-shadow.ts +18 -0
- package/src/scene/particles-factory.ts +59 -0
- package/src/scene/scene-loader.ts +41 -16
- package/src/scene/schema/instances.ts +1 -2
- package/src/scene/schema/material.ts +83 -94
- package/src/scene/schema/mesh.ts +76 -90
- package/src/scene/schema/scene-file.ts +1 -2
- package/src/scene/user-data.ts +30 -14
- package/src/setup/setup-renderer.ts +6 -1
- package/src/world2d/asset-paths2d.ts +44 -0
- package/src/world2d/collision-2d.ts +7 -14
- package/src/world2d/entity2d-asset.ts +22 -0
- package/src/world2d/index.ts +27 -2
- package/src/world2d/physics2d-transform.ts +173 -0
- package/src/world2d/physics2d-units.ts +10 -0
- package/src/world2d/pixi-game-adapter.ts +148 -36
- package/src/world2d/scene2d-identity.ts +49 -0
- package/src/world2d/scene2d-loader.ts +243 -119
- package/src/world2d/schema/entity2d.ts +51 -33
- package/src/world2d/schema/physics2d.ts +14 -3
- package/src/world2d/schema/sprite.ts +32 -4
- package/src/world2d/schema/tilemap.ts +26 -9
- package/src/world2d/transform-writer-2d.ts +29 -11
- package/src/world2d/types.ts +21 -8
- package/src/world3d-react/behavior.tsx +138 -0
- package/src/world3d-react/engine-bridge.ts +48 -0
- package/src/world3d-react/index.ts +44 -0
- package/src/world3d-react/r3f-adapter.tsx +303 -0
- package/src/world3d-react/world-context.ts +294 -0
- package/vendor/realism-effects/LICENSE.md +21 -0
- package/vendor/realism-effects/UPSTREAM.md +19 -0
- package/vendor/realism-effects/dist/index.cjs +3447 -0
- package/vendor/realism-effects/dist/index.d.ts +59 -0
- package/vendor/realism-effects/dist/index.js +3434 -0
- package/vendor/realism-effects/package.json +23 -0
- package/src/character/cloth-sim.ts +0 -533
- package/src/character/spring-chain.ts +0 -307
- package/src/humanoid/body.ts +0 -663
- package/src/humanoid/clips.ts +0 -149
- package/src/humanoid/compose.ts +0 -209
- package/src/humanoid/generate.ts +0 -189
- package/src/humanoid/index.ts +0 -36
- package/src/humanoid/schema.ts +0 -108
- package/src/humanoid/skeleton.ts +0 -345
- package/src/react/humanoid-bake.document.tsx +0 -337
- package/src/scene/geometries/index.ts +0 -7
- package/src/scene/geometries/terrain.ts +0 -42
- package/src/scene/geometry-registry.ts +0 -42
- package/src/scene/instance-registry.ts +0 -84
- package/src/scene/instancers/grid.ts +0 -38
- package/src/scene/instancers/index.ts +0 -7
- package/src/scene/material-registry.ts +0 -73
- package/src/scene/materials/index.ts +0 -7
- package/src/scene/materials/water.ts +0 -56
- package/src/world2d/components-2d.ts +0 -86
- package/tools/humanoid-bake.tool.ts +0 -274
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Character primitive — spring-bone chains (hair, ponytails, cloth strips)
|
|
3
|
-
* on top of `@pixiv/three-vrm-springbone`'s raw API.
|
|
4
|
-
*
|
|
5
|
-
* This is a THIN COMPOSITION HELPER, not a wrapper (CLAUDE.md "use libraries
|
|
6
|
-
* directly"): every export here is a small function that assembles the
|
|
7
|
-
* library's own objects (`THREE.Bone`, `VRMSpringBoneJoint`,
|
|
8
|
-
* `VRMSpringBoneCollider`, `VRMSpringBoneManager`) — nothing from the
|
|
9
|
-
* library is re-exported, and callers still import `@pixiv/three-vrm-
|
|
10
|
-
* springbone` types directly for anything beyond what's here. Kept
|
|
11
|
-
* deliberately bare: composing a specific character (a caped viking, a
|
|
12
|
-
* ponytailed ranger) is ordinary calling code on top of these pieces, not a
|
|
13
|
-
* costume/preset system in the engine.
|
|
14
|
-
*
|
|
15
|
-
* Sharp edge this module exists partly to contain (see the mission brief /
|
|
16
|
-
* `cloth-hair-bench/spring-rig.ts`'s header for the full discovery):
|
|
17
|
-
* `VRMSpringBoneCollider` overrides `updateWorldMatrix` (the ON-DEMAND,
|
|
18
|
-
* manually-invoked method), NOT `updateMatrixWorld` (the one the renderer
|
|
19
|
-
* calls automatically) — `SpringColliderRig.reposition()` below calls
|
|
20
|
-
* `collider.updateWorldMatrix(true, false)` itself every tick so callers
|
|
21
|
-
* can't forget it.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
VRMSpringBoneCollider,
|
|
26
|
-
type VRMSpringBoneColliderGroup,
|
|
27
|
-
VRMSpringBoneColliderShapeCapsule,
|
|
28
|
-
VRMSpringBoneColliderShapeSphere,
|
|
29
|
-
VRMSpringBoneJoint,
|
|
30
|
-
VRMSpringBoneManager,
|
|
31
|
-
} from '@pixiv/three-vrm-springbone';
|
|
32
|
-
import * as THREE from 'three';
|
|
33
|
-
|
|
34
|
-
const DEFAULT_GRAVITY_DIR = new THREE.Vector3(0, -1, 0);
|
|
35
|
-
|
|
36
|
-
// ---------------------------------------------------------------------------
|
|
37
|
-
// Bone chains
|
|
38
|
-
// ---------------------------------------------------------------------------
|
|
39
|
-
|
|
40
|
-
export interface BoneChain {
|
|
41
|
-
/** Swinging bones, root (nearest the anchor) first. */
|
|
42
|
-
bones: THREE.Bone[];
|
|
43
|
-
/** A non-simulated leaf `Object3D` past the last bone — the spring joint
|
|
44
|
-
* "tail" target for the last bone in the chain. */
|
|
45
|
-
tip: THREE.Object3D;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** World-space offset from `parent`'s CURRENT world position -> the local
|
|
49
|
-
* position a new direct child of `parent` must have to sit there. Requires
|
|
50
|
-
* `parent.matrixWorld` to be current. Sidesteps ever reasoning about a
|
|
51
|
-
* bone's local rest-axis convention (arbitrary per-bone on an imported
|
|
52
|
-
* rig) — the caller only ever thinks in world-space directions. */
|
|
53
|
-
export function worldOffsetToLocalPos(
|
|
54
|
-
parent: THREE.Object3D,
|
|
55
|
-
worldDir: THREE.Vector3,
|
|
56
|
-
length: number,
|
|
57
|
-
): THREE.Vector3 {
|
|
58
|
-
const parentWorld = new THREE.Vector3();
|
|
59
|
-
parent.getWorldPosition(parentWorld);
|
|
60
|
-
const targetWorld = parentWorld.clone().addScaledVector(worldDir, length);
|
|
61
|
-
return parent.worldToLocal(targetWorld.clone());
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Build a straight chain of `count` new `THREE.Bone`s under `parent`, each
|
|
65
|
-
* offset `segmentLength` further along the WORLD-space unit vector
|
|
66
|
-
* `worldDir` — the natural rest shape for hair/cloth hanging under gravity.
|
|
67
|
-
* Ends with a `tip` `Object3D` (one more segment past the last bone) so
|
|
68
|
-
* every bone has an explicit spring-joint child target. Can be anchored to
|
|
69
|
-
* either an existing rig bone (hair off a head) or any plain `Object3D`. */
|
|
70
|
-
export function buildBoneChain(
|
|
71
|
-
parent: THREE.Object3D,
|
|
72
|
-
namePrefix: string,
|
|
73
|
-
count: number,
|
|
74
|
-
segmentLength: number,
|
|
75
|
-
worldDir: THREE.Vector3,
|
|
76
|
-
): BoneChain {
|
|
77
|
-
const bones: THREE.Bone[] = [];
|
|
78
|
-
let cur: THREE.Object3D = parent;
|
|
79
|
-
cur.updateWorldMatrix(true, false);
|
|
80
|
-
for (let i = 0; i < count; i++) {
|
|
81
|
-
const localPos = worldOffsetToLocalPos(cur, worldDir, segmentLength);
|
|
82
|
-
const bone = new THREE.Bone();
|
|
83
|
-
bone.name = `${namePrefix}${i}`;
|
|
84
|
-
bone.position.copy(localPos);
|
|
85
|
-
cur.add(bone);
|
|
86
|
-
bone.updateWorldMatrix(true, false);
|
|
87
|
-
bones.push(bone);
|
|
88
|
-
cur = bone;
|
|
89
|
-
}
|
|
90
|
-
const tip = new THREE.Object3D();
|
|
91
|
-
tip.name = `${namePrefix}Tip`;
|
|
92
|
-
tip.position.copy(worldOffsetToLocalPos(cur, worldDir, segmentLength));
|
|
93
|
-
cur.add(tip);
|
|
94
|
-
return { bones, tip };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// ---------------------------------------------------------------------------
|
|
98
|
-
// Spring joints
|
|
99
|
-
// ---------------------------------------------------------------------------
|
|
100
|
-
|
|
101
|
-
export interface ChainJointSettings {
|
|
102
|
-
stiffness?: number;
|
|
103
|
-
gravityPower?: number;
|
|
104
|
-
gravityDir?: THREE.Vector3;
|
|
105
|
-
dragForce?: number;
|
|
106
|
-
hitRadius?: number;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface ChainJointHandle {
|
|
110
|
-
joints: VRMSpringBoneJoint[];
|
|
111
|
-
/** Deregisters every joint this chain added from `manager`. Does NOT
|
|
112
|
-
* detach the bones from the scene graph (the caller owns that). */
|
|
113
|
-
dispose(): void;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Register one `VRMSpringBoneJoint` per bone in `chain` on `manager` (each
|
|
117
|
-
* targeting the next bone, the last targeting `chain.tip`). Does not call
|
|
118
|
-
* `manager.setInitState()` — batch that once after all chains for a
|
|
119
|
-
* manager are registered and the scene's world matrices are current (sharp
|
|
120
|
-
* edge: `VRMSpringBoneJoint` sets `bone.matrixAutoUpdate = false`, so
|
|
121
|
-
* `setInitState()` must run AFTER `scene.updateMatrixWorld(true)`). */
|
|
122
|
-
export function registerChainJoints(
|
|
123
|
-
manager: VRMSpringBoneManager,
|
|
124
|
-
chain: BoneChain,
|
|
125
|
-
colliderGroups: VRMSpringBoneColliderGroup[],
|
|
126
|
-
settings: ChainJointSettings = {},
|
|
127
|
-
): ChainJointHandle {
|
|
128
|
-
const joints: VRMSpringBoneJoint[] = [];
|
|
129
|
-
for (let i = 0; i < chain.bones.length; i++) {
|
|
130
|
-
const bone = chain.bones[i]!;
|
|
131
|
-
const child = chain.bones[i + 1] ?? chain.tip;
|
|
132
|
-
const joint = new VRMSpringBoneJoint(
|
|
133
|
-
bone,
|
|
134
|
-
child,
|
|
135
|
-
{
|
|
136
|
-
stiffness: settings.stiffness ?? 1.2,
|
|
137
|
-
gravityPower: settings.gravityPower ?? 0.9,
|
|
138
|
-
gravityDir: settings.gravityDir ?? DEFAULT_GRAVITY_DIR,
|
|
139
|
-
dragForce: settings.dragForce ?? 0.35,
|
|
140
|
-
hitRadius: settings.hitRadius ?? 0.02,
|
|
141
|
-
},
|
|
142
|
-
colliderGroups,
|
|
143
|
-
);
|
|
144
|
-
manager.addJoint(joint);
|
|
145
|
-
joints.push(joint);
|
|
146
|
-
}
|
|
147
|
-
return {
|
|
148
|
-
joints,
|
|
149
|
-
dispose(): void {
|
|
150
|
-
for (const joint of joints) manager.deleteJoint(joint);
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// ---------------------------------------------------------------------------
|
|
156
|
-
// Colliders
|
|
157
|
-
// ---------------------------------------------------------------------------
|
|
158
|
-
|
|
159
|
-
export interface SphereColliderDef {
|
|
160
|
-
shape: 'sphere';
|
|
161
|
-
name: string;
|
|
162
|
-
/** The collider tracks this object's world position every `reposition()`. */
|
|
163
|
-
followBone: THREE.Object3D;
|
|
164
|
-
radius: number;
|
|
165
|
-
/** Extra WORLD-space offset added after sampling `followBone`'s position
|
|
166
|
-
* (e.g. nudging a head collider up from the neck joint). */
|
|
167
|
-
worldOffset?: THREE.Vector3;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export interface CapsuleColliderDef {
|
|
171
|
-
shape: 'capsule';
|
|
172
|
-
name: string;
|
|
173
|
-
followBone: THREE.Object3D;
|
|
174
|
-
radius: number;
|
|
175
|
-
/** Capsule tail, in the collider's own local space (world-axis-aligned —
|
|
176
|
-
* colliders are parented directly to the scene, see `buildSpringColliderRig`). */
|
|
177
|
-
tail: THREE.Vector3;
|
|
178
|
-
worldOffset?: THREE.Vector3;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export type ColliderDef = SphereColliderDef | CapsuleColliderDef;
|
|
182
|
-
|
|
183
|
-
export interface SpringColliderRig {
|
|
184
|
-
group: VRMSpringBoneColliderGroup;
|
|
185
|
-
colliders: Map<string, VRMSpringBoneCollider>;
|
|
186
|
-
/** Reposition every collider from its `followBone`'s CURRENT world
|
|
187
|
-
* transform and refresh its `colliderMatrix` (see module header). Call
|
|
188
|
-
* once per tick, BEFORE `manager.update(dt)`. */
|
|
189
|
-
reposition(): void;
|
|
190
|
-
dispose(): void;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/** Build sphere/capsule colliders parented directly to `scene` (world
|
|
194
|
-
* space) — sidesteps reasoning about any bone's local rest-axis convention
|
|
195
|
-
* for the collider shape's offset/tail vectors. */
|
|
196
|
-
export function buildSpringColliderRig(scene: THREE.Scene, defs: ColliderDef[]): SpringColliderRig {
|
|
197
|
-
const colliders = new Map<string, VRMSpringBoneCollider>();
|
|
198
|
-
const followers: Array<{ def: ColliderDef; collider: VRMSpringBoneCollider }> = [];
|
|
199
|
-
|
|
200
|
-
for (const def of defs) {
|
|
201
|
-
const collider =
|
|
202
|
-
def.shape === 'sphere'
|
|
203
|
-
? new VRMSpringBoneCollider(new VRMSpringBoneColliderShapeSphere({ radius: def.radius }))
|
|
204
|
-
: new VRMSpringBoneCollider(
|
|
205
|
-
new VRMSpringBoneColliderShapeCapsule({
|
|
206
|
-
radius: def.radius,
|
|
207
|
-
offset: new THREE.Vector3(0, 0, 0),
|
|
208
|
-
tail: def.tail,
|
|
209
|
-
}),
|
|
210
|
-
);
|
|
211
|
-
scene.add(collider);
|
|
212
|
-
colliders.set(def.name, collider);
|
|
213
|
-
followers.push({ def, collider });
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const group: VRMSpringBoneColliderGroup = {
|
|
217
|
-
name: 'body',
|
|
218
|
-
colliders: [...colliders.values()],
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const worldTmp = new THREE.Vector3();
|
|
222
|
-
return {
|
|
223
|
-
group,
|
|
224
|
-
colliders,
|
|
225
|
-
reposition(): void {
|
|
226
|
-
for (const { def, collider } of followers) {
|
|
227
|
-
def.followBone.getWorldPosition(worldTmp);
|
|
228
|
-
collider.position.copy(worldTmp);
|
|
229
|
-
if (def.worldOffset) collider.position.add(def.worldOffset);
|
|
230
|
-
collider.updateWorldMatrix(true, false);
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
dispose(): void {
|
|
234
|
-
for (const collider of colliders.values()) scene.remove(collider);
|
|
235
|
-
colliders.clear();
|
|
236
|
-
},
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// ---------------------------------------------------------------------------
|
|
241
|
-
// Composed chain rig (the common case: one chain, its own manager)
|
|
242
|
-
// ---------------------------------------------------------------------------
|
|
243
|
-
|
|
244
|
-
export interface SpringChainRigOptions {
|
|
245
|
-
parent: THREE.Object3D;
|
|
246
|
-
namePrefix: string;
|
|
247
|
-
count: number;
|
|
248
|
-
segmentLength: number;
|
|
249
|
-
worldDir: THREE.Vector3;
|
|
250
|
-
/** Colliders this chain collides against. Omit for a chain with no
|
|
251
|
-
* collision (e.g. a side strand tucked away from the body). */
|
|
252
|
-
colliderRig?: SpringColliderRig;
|
|
253
|
-
settings?: ChainJointSettings;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export interface SpringChainRig {
|
|
257
|
-
bones: THREE.Bone[];
|
|
258
|
-
tip: THREE.Object3D;
|
|
259
|
-
/** The manager owning this chain's joints — a "manager-compatible handle"
|
|
260
|
-
* a caller can also register additional joints on directly. */
|
|
261
|
-
manager: VRMSpringBoneManager;
|
|
262
|
-
/** Repositions `colliderRig` (if given) and steps the spring simulation.
|
|
263
|
-
* Handles the collider `updateWorldMatrix` footgun internally — callers
|
|
264
|
-
* never need to call `collider.updateWorldMatrix` themselves. */
|
|
265
|
-
tick(dt: number): void;
|
|
266
|
-
dispose(): void;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/** Compose `buildBoneChain` + `registerChainJoints` behind one call for the
|
|
270
|
-
* common single-chain case: builds the chain, gives it its OWN
|
|
271
|
-
* `VRMSpringBoneManager` (managers are cheap — one per independent chain
|
|
272
|
-
* keeps `dispose()`/`tick()` fully self-contained), registers its joints,
|
|
273
|
-
* and calls `setInitState()` once construction is complete.
|
|
274
|
-
*
|
|
275
|
-
* For MULTIPLE chains sharing one collider rig (e.g. a ponytail + two side
|
|
276
|
-
* strands all colliding against the same head), build each chain with its
|
|
277
|
-
* own `buildSpringChainRig` call (same `colliderRig` passed to each) and
|
|
278
|
-
* tick all of them — `colliderRig.reposition()` is idempotent per frame, so
|
|
279
|
-
* calling it once per chain tick is correct, just slightly redundant work
|
|
280
|
-
* (cheap: it only touches a handful of colliders). */
|
|
281
|
-
export function buildSpringChainRig(options: SpringChainRigOptions): SpringChainRig {
|
|
282
|
-
const chain = buildBoneChain(
|
|
283
|
-
options.parent,
|
|
284
|
-
options.namePrefix,
|
|
285
|
-
options.count,
|
|
286
|
-
options.segmentLength,
|
|
287
|
-
options.worldDir,
|
|
288
|
-
);
|
|
289
|
-
const manager = new VRMSpringBoneManager();
|
|
290
|
-
const colliderGroups = options.colliderRig ? [options.colliderRig.group] : [];
|
|
291
|
-
const jointHandle = registerChainJoints(manager, chain, colliderGroups, options.settings);
|
|
292
|
-
manager.setInitState();
|
|
293
|
-
|
|
294
|
-
return {
|
|
295
|
-
bones: chain.bones,
|
|
296
|
-
tip: chain.tip,
|
|
297
|
-
manager,
|
|
298
|
-
tick(dt: number): void {
|
|
299
|
-
options.colliderRig?.reposition();
|
|
300
|
-
manager.update(dt);
|
|
301
|
-
},
|
|
302
|
-
dispose(): void {
|
|
303
|
-
jointHandle.dispose();
|
|
304
|
-
chain.bones[0]?.removeFromParent();
|
|
305
|
-
},
|
|
306
|
-
};
|
|
307
|
-
}
|