@viggle/splat-engine-three 0.1.1 → 0.3.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/CHANGELOG.md +58 -0
- package/README.md +158 -20
- package/dist/chunks/chunk-2GKWT24B.js +23182 -0
- package/dist/chunks/chunk-2GKWT24B.js.map +7 -0
- package/dist/index.js +235 -3
- package/dist/types/anim/animation-conversion.d.ts +2 -2
- package/dist/types/anim/keyframe-splines.d.ts +17 -41
- package/dist/types/animation.d.ts +84 -28
- package/dist/types/armature.d.ts +280 -2
- package/dist/types/character.d.ts +120 -2
- package/dist/types/effects/index.d.ts +12 -0
- package/dist/types/effects/outlines/outline-effect.d.ts +98 -0
- package/dist/types/effects/outlines/outline-shaders.d.ts +14 -0
- package/dist/types/effects/pixelart/pixelart-effect.d.ts +152 -0
- package/dist/types/effects/pixelart/pixelart-shaders.d.ts +31 -0
- package/dist/types/effects/postfx/base-capturing-pass.d.ts +109 -0
- package/dist/types/effects/postfx/camera-frame.d.ts +103 -0
- package/dist/types/effects/postfx/frame-renderer.d.ts +32 -0
- package/dist/types/effects/postfx/frame-shaders.d.ts +19 -0
- package/dist/types/effects/postfx/mask.d.ts +44 -0
- package/dist/types/effects/postfx/postfx.d.ts +144 -0
- package/dist/types/effects/postfx/program.d.ts +74 -0
- package/dist/types/effects/postfx/uniforms.d.ts +24 -0
- package/dist/types/effects/postfx/webgl-program.d.ts +6 -0
- package/dist/types/effects/postfx/webgpu-program.d.ts +3 -0
- package/dist/types/effects/vfx/data-types.d.ts +100 -0
- package/dist/types/effects/vfx/index.d.ts +37 -0
- package/dist/types/effects/vfx/json-vfx-prefab.d.ts +94 -0
- package/dist/types/effects/vfx/layer-renderer.d.ts +118 -0
- package/dist/types/effects/vfx/layers/mesh.d.ts +124 -0
- package/dist/types/effects/vfx/layers/particle.d.ts +90 -0
- package/dist/types/effects/vfx/layers/shader.d.ts +130 -0
- package/dist/types/effects/vfx/layers/shared.d.ts +40 -0
- package/dist/types/effects/vfx/layers/sprite.d.ts +45 -0
- package/dist/types/effects/vfx/pool.d.ts +51 -0
- package/dist/types/effects/vfx/prefab.d.ts +48 -0
- package/dist/types/effects/vfx/prewarm.d.ts +17 -0
- package/dist/types/effects/vfx/stage.d.ts +115 -0
- package/dist/types/effects/vfx/webgpu-register.d.ts +2 -0
- package/dist/types/effects/webgpu-register.d.ts +2 -0
- package/dist/types/engine.d.ts +18 -0
- package/dist/types/environment.d.ts +96 -8
- package/dist/types/index.d.ts +35 -6
- package/dist/types/loader/animation/animation-glb.d.ts +4 -4
- package/dist/types/loader/character/load.d.ts +6 -1
- package/dist/types/loader/environment/lod-bundle.d.ts +123 -0
- package/dist/types/loader/environment/spz-decode.d.ts +88 -0
- package/dist/types/loader/environment/spz.d.ts +28 -0
- package/dist/types/loader/shared/asset-fetch.d.ts +11 -0
- package/dist/types/loader/shared/asset-loader.d.ts +86 -0
- package/dist/types/loader/shared/bin-cache.d.ts +41 -14
- package/dist/types/loader/shared/decode-worker.d.ts +27 -0
- package/dist/types/loader/shared/glb.d.ts +30 -0
- package/dist/types/loader/shared/inflate.d.ts +9 -0
- package/dist/types/loader/shared/pack-splats-task.d.ts +17 -0
- package/dist/types/loader/shared/sog-decode.d.ts +81 -0
- package/dist/types/loader/shared/sog.d.ts +17 -0
- package/dist/types/math.d.ts +198 -13
- package/dist/types/physics/ammo.d.ts +217 -0
- package/dist/types/physics/index.d.ts +11 -0
- package/dist/types/physics/joints.d.ts +206 -0
- package/dist/types/physics/physics-world.d.ts +194 -0
- package/dist/types/physics/rigid-body.d.ts +361 -0
- package/dist/types/presets/camera/camera-preset.d.ts +43 -0
- package/dist/types/presets/camera/third-person-camera.d.ts +63 -0
- package/dist/types/presets/character/body-shape.d.ts +109 -0
- package/dist/types/presets/character/character-reveal.d.ts +90 -0
- package/dist/types/presets/character/socket-loadout.d.ts +61 -0
- package/dist/types/presets/index.d.ts +13 -0
- package/dist/types/presets/vfx/mesh-flash.d.ts +51 -0
- package/dist/types/presets/visual/bone-overlay.d.ts +57 -0
- package/dist/types/proxy/environment-input.d.ts +30 -0
- package/dist/types/proxy/environment-source.d.ts +39 -0
- package/dist/types/proxy/proxy-debug.d.ts +106 -0
- package/dist/types/proxy/splat-source.d.ts +42 -0
- package/dist/types/proxy/voxelizer.d.ts +383 -0
- package/dist/types/relight/backend.d.ts +101 -0
- package/dist/types/relight/index.d.ts +6 -0
- package/dist/types/relight/relight-pass.d.ts +367 -0
- package/dist/types/relight/relight-placeholder.d.ts +2 -0
- package/dist/types/relight/relight-shaders.d.ts +4 -0
- package/dist/types/relight/shadow-bias.d.ts +26 -0
- package/dist/types/relight/splat-relight.d.ts +760 -0
- package/dist/types/relight/webgl-backend.d.ts +3 -0
- package/dist/types/relight/webgpu/backend.d.ts +3 -0
- package/dist/types/relight/webgpu-register.d.ts +2 -0
- package/dist/types/scene.d.ts +291 -0
- package/dist/types/skeletal/animation-player.d.ts +31 -3
- package/dist/types/skeletal/body-parts.d.ts +55 -0
- package/dist/types/skeletal/ragdoll-config.d.ts +115 -0
- package/dist/types/skeletal/ragdoll.d.ts +283 -0
- package/dist/types/skeletal/skeleton.d.ts +9 -2
- package/dist/types/splat/backend.d.ts +2 -0
- package/dist/types/splat/color-modifier.d.ts +78 -0
- package/dist/types/splat/cut-groups.d.ts +27 -0
- package/dist/types/splat/relight-binding.d.ts +39 -0
- package/dist/types/splat/reveal-bake.d.ts +43 -0
- package/dist/types/splat/reveal-look.d.ts +64 -0
- package/dist/types/splat/splat-mesh.d.ts +1 -0
- package/dist/types/splat/splat.d.ts +154 -0
- package/dist/types/splat/webgl/shaders.d.ts +5 -1
- package/dist/types/splat/webgl/splat-mesh.d.ts +4 -0
- package/dist/types/splat/webgpu/radix-sort.d.ts +3 -0
- package/dist/types/splat/webgpu/splat-mesh.d.ts +23 -0
- package/dist/types/three/splat-character.d.ts +28 -0
- package/dist/types/three/spz-loader.d.ts +35 -0
- package/dist/types/types.d.ts +6 -0
- package/dist/webgpu.js +1137 -154
- package/dist/webgpu.js.map +4 -4
- package/package.json +6 -2
- package/dist/chunks/chunk-WN5WBKM4.js +0 -8606
- package/dist/chunks/chunk-WN5WBKM4.js.map +0 -7
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { BufferGeometry, EventDispatcher, Euler, Object3D, Quaternion, Vector3 } from 'three';
|
|
2
|
+
import type { AmmoDynamicsWorld, AmmoQuat, AmmoRigidBody, AmmoTransform, AmmoVec3 } from './ammo';
|
|
3
|
+
import type { PhysicsWorld } from './physics-world';
|
|
4
|
+
/** Anything with `x`, `y`, `z`: a `THREE.Vector3`, or a plain object. @group Physics */
|
|
5
|
+
export interface XYZ {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
z: number;
|
|
9
|
+
}
|
|
10
|
+
/** Anything with `x`, `y`, `z`, `w`: a `THREE.Quaternion`, or a plain object. @group Physics */
|
|
11
|
+
export interface XYZW {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
z: number;
|
|
15
|
+
w: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* How a body moves. As in PlayCanvas: `'static'` never moves, `'dynamic'` is
|
|
19
|
+
* simulated and writes its pose to the object, `'kinematic'` follows the
|
|
20
|
+
* object and pushes dynamic bodies out of the way.
|
|
21
|
+
*
|
|
22
|
+
* @group Physics
|
|
23
|
+
*/
|
|
24
|
+
export type RigidBodyType = 'static' | 'dynamic' | 'kinematic';
|
|
25
|
+
/**
|
|
26
|
+
* Collision shape, in the same terms as PlayCanvas's `collision` component.
|
|
27
|
+
* `axis` is 0 = X, 1 = Y (default), 2 = Z. A capsule's `height` includes its
|
|
28
|
+
* two caps. Primitive shapes ignore the object's scale, as in PlayCanvas.
|
|
29
|
+
*
|
|
30
|
+
* `'mesh'` builds a static triangle mesh from every `Mesh` under `geometry`
|
|
31
|
+
* (or from the geometry itself), in the body object's frame with its world
|
|
32
|
+
* scale baked in. Bullet cannot simulate a triangle mesh as a dynamic body:
|
|
33
|
+
* pass `convexHull: true` for a moving one.
|
|
34
|
+
*
|
|
35
|
+
* @group Physics
|
|
36
|
+
*/
|
|
37
|
+
export type CollisionShape = {
|
|
38
|
+
type: 'box';
|
|
39
|
+
halfExtents: XYZ;
|
|
40
|
+
} | {
|
|
41
|
+
type: 'sphere';
|
|
42
|
+
radius: number;
|
|
43
|
+
} | {
|
|
44
|
+
type: 'capsule';
|
|
45
|
+
radius: number;
|
|
46
|
+
height: number;
|
|
47
|
+
axis?: 0 | 1 | 2;
|
|
48
|
+
} | {
|
|
49
|
+
type: 'cylinder';
|
|
50
|
+
radius: number;
|
|
51
|
+
height: number;
|
|
52
|
+
axis?: 0 | 1 | 2;
|
|
53
|
+
} | {
|
|
54
|
+
type: 'cone';
|
|
55
|
+
radius: number;
|
|
56
|
+
height: number;
|
|
57
|
+
axis?: 0 | 1 | 2;
|
|
58
|
+
} | {
|
|
59
|
+
type: 'mesh';
|
|
60
|
+
geometry: BufferGeometry | Object3D;
|
|
61
|
+
convexHull?: boolean;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Options for {@link PhysicsWorld.addBody}. Every default matches
|
|
65
|
+
* PlayCanvas's `rigidbody` component.
|
|
66
|
+
*
|
|
67
|
+
* @group Physics
|
|
68
|
+
*/
|
|
69
|
+
export interface RigidBodyOptions {
|
|
70
|
+
shape: CollisionShape;
|
|
71
|
+
/** Default `'static'`. */
|
|
72
|
+
type?: RigidBodyType;
|
|
73
|
+
/** Kilograms; only dynamic bodies have mass. Default `1`. */
|
|
74
|
+
mass?: number;
|
|
75
|
+
/** Default `0.5`. */
|
|
76
|
+
friction?: number;
|
|
77
|
+
/** Default `0`. */
|
|
78
|
+
rollingFriction?: number;
|
|
79
|
+
/** Default `0`. */
|
|
80
|
+
restitution?: number;
|
|
81
|
+
/** Default `0`. */
|
|
82
|
+
linearDamping?: number;
|
|
83
|
+
/** Default `0`. */
|
|
84
|
+
angularDamping?: number;
|
|
85
|
+
/** Per-axis multiplier on linear motion; `(1, 1, 0)` keeps a body in the XY plane. Default `(1, 1, 1)`. */
|
|
86
|
+
linearFactor?: XYZ;
|
|
87
|
+
/** Per-axis multiplier on rotation. Default `(1, 1, 1)`. */
|
|
88
|
+
angularFactor?: XYZ;
|
|
89
|
+
/** Multiplier on the world's gravity. Default `1`. */
|
|
90
|
+
gravityScale?: number;
|
|
91
|
+
/** Collision group bits. Default from {@link type}: dynamic 1, static 2, kinematic 4. */
|
|
92
|
+
group?: number;
|
|
93
|
+
/** Groups this body collides with. Default: static `BODYMASK_NOT_STATIC`, others `BODYMASK_ALL`. */
|
|
94
|
+
mask?: number;
|
|
95
|
+
/** Shape position in the object's frame (PlayCanvas `collision.linearOffset`). */
|
|
96
|
+
linearOffset?: XYZ;
|
|
97
|
+
/** Shape rotation in the object's frame (PlayCanvas `collision.angularOffset`). */
|
|
98
|
+
angularOffset?: XYZW;
|
|
99
|
+
/**
|
|
100
|
+
* A sensor: no collision response, follows the object every step and fires
|
|
101
|
+
* `triggerenter` / `triggerleave`. PlayCanvas's `collision` component
|
|
102
|
+
* without a `rigidbody`. `type`, `mass` and the material options are
|
|
103
|
+
* ignored. Default `false`.
|
|
104
|
+
*/
|
|
105
|
+
trigger?: boolean;
|
|
106
|
+
/** Whether the body starts in the simulation. Default `true`. */
|
|
107
|
+
enabled?: boolean;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* One point of contact between two bodies, seen from the body the event is
|
|
111
|
+
* dispatched on. PlayCanvas's `ContactPoint`.
|
|
112
|
+
*
|
|
113
|
+
* @group Physics
|
|
114
|
+
*/
|
|
115
|
+
export interface ContactPoint {
|
|
116
|
+
/** On this body, in its local frame. */
|
|
117
|
+
localPoint: Vector3;
|
|
118
|
+
/** On the other body, in its local frame. */
|
|
119
|
+
localPointOther: Vector3;
|
|
120
|
+
/** On this body, world space. */
|
|
121
|
+
point: Vector3;
|
|
122
|
+
/** On the other body, world space. */
|
|
123
|
+
pointOther: Vector3;
|
|
124
|
+
/** World-space contact normal, pointing from the other body toward this one. */
|
|
125
|
+
normal: Vector3;
|
|
126
|
+
/** Impulse the solver applied at this point, N·s. */
|
|
127
|
+
impulse: number;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Payload of `contact` and `collisionstart`. PlayCanvas's `ContactResult`,
|
|
131
|
+
* with `other` the other body's object.
|
|
132
|
+
*
|
|
133
|
+
* @group Physics
|
|
134
|
+
*/
|
|
135
|
+
export interface ContactResult {
|
|
136
|
+
other: Object3D;
|
|
137
|
+
otherBody: RigidBody;
|
|
138
|
+
contacts: ContactPoint[];
|
|
139
|
+
}
|
|
140
|
+
/** Payload of `collisionend`, `triggerenter` and `triggerleave`. @group Physics */
|
|
141
|
+
export interface BodyPairEvent {
|
|
142
|
+
other: Object3D;
|
|
143
|
+
otherBody: RigidBody;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Events a {@link RigidBody} dispatches, with PlayCanvas's names. They fire
|
|
147
|
+
* after the step that produced them, once every dynamic object is in place.
|
|
148
|
+
*
|
|
149
|
+
* - `contact`: every physics sub-step the bodies touch.
|
|
150
|
+
* - `collisionstart` / `collisionend`: the first and the first-not-touching sub-step.
|
|
151
|
+
* - `triggerenter` / `triggerleave`: on both a trigger and the body entering it.
|
|
152
|
+
*
|
|
153
|
+
* @group Physics
|
|
154
|
+
*/
|
|
155
|
+
export interface RigidBodyEventMap {
|
|
156
|
+
contact: ContactResult;
|
|
157
|
+
collisionstart: ContactResult;
|
|
158
|
+
collisionend: BodyPairEvent;
|
|
159
|
+
triggerenter: BodyPairEvent;
|
|
160
|
+
triggerleave: BodyPairEvent;
|
|
161
|
+
}
|
|
162
|
+
/** @group Physics */ export declare const BODYGROUP_NONE = 0;
|
|
163
|
+
/** @group Physics */ export declare const BODYGROUP_DEFAULT = 1;
|
|
164
|
+
/** @group Physics */ export declare const BODYGROUP_DYNAMIC = 1;
|
|
165
|
+
/** @group Physics */ export declare const BODYGROUP_STATIC = 2;
|
|
166
|
+
/** @group Physics */ export declare const BODYGROUP_KINEMATIC = 4;
|
|
167
|
+
/** @group Physics */ export declare const BODYGROUP_ENGINE_1 = 8;
|
|
168
|
+
/** @group Physics */ export declare const BODYGROUP_TRIGGER = 16;
|
|
169
|
+
/** @group Physics */ export declare const BODYGROUP_ENGINE_2 = 32;
|
|
170
|
+
/** @group Physics */ export declare const BODYGROUP_ENGINE_3 = 64;
|
|
171
|
+
/** @group Physics */ export declare const BODYGROUP_USER_1 = 128;
|
|
172
|
+
/** @group Physics */ export declare const BODYGROUP_USER_2 = 256;
|
|
173
|
+
/** @group Physics */ export declare const BODYGROUP_USER_3 = 512;
|
|
174
|
+
/** @group Physics */ export declare const BODYGROUP_USER_4 = 1024;
|
|
175
|
+
/** @group Physics */ export declare const BODYGROUP_USER_5 = 2048;
|
|
176
|
+
/** @group Physics */ export declare const BODYGROUP_USER_6 = 4096;
|
|
177
|
+
/** @group Physics */ export declare const BODYGROUP_USER_7 = 8192;
|
|
178
|
+
/** @group Physics */ export declare const BODYGROUP_USER_8 = 16384;
|
|
179
|
+
/** @group Physics */ export declare const BODYMASK_NONE = 0;
|
|
180
|
+
/** @group Physics */ export declare const BODYMASK_ALL = 65535;
|
|
181
|
+
/** @group Physics */ export declare const BODYMASK_STATIC = 2;
|
|
182
|
+
/** @group Physics */ export declare const BODYMASK_NOT_STATIC: number;
|
|
183
|
+
/** @group Physics */ export declare const BODYMASK_NOT_STATIC_KINEMATIC: number;
|
|
184
|
+
/**
|
|
185
|
+
* The parts of {@link PhysicsWorld} a body calls into. Kept narrow so the two
|
|
186
|
+
* classes don't reach into each other's state.
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
export interface BodyHost {
|
|
190
|
+
readonly world: PhysicsWorld;
|
|
191
|
+
readonly gravity: Vector3;
|
|
192
|
+
readonly native: AmmoDynamicsWorld;
|
|
193
|
+
readonly btVec1: AmmoVec3;
|
|
194
|
+
readonly btVec2: AmmoVec3;
|
|
195
|
+
readonly btTransform: AmmoTransform;
|
|
196
|
+
readonly btQuat: AmmoQuat;
|
|
197
|
+
simulationChanged(body: RigidBody, inWorld: boolean): void;
|
|
198
|
+
/** Run `replace`, which frees and re-creates `body`'s btRigidBody, with its joints let go meanwhile. */
|
|
199
|
+
nativeReplacing(body: RigidBody, replace: () => void): void;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* A rigid body attached to a `THREE.Object3D`: PlayCanvas's `rigidbody` and
|
|
203
|
+
* `collision` components in one object. Create one with
|
|
204
|
+
* {@link PhysicsWorld.addBody}; {@link PhysicsWorld.getBody} finds it again
|
|
205
|
+
* from the object.
|
|
206
|
+
*
|
|
207
|
+
* A dynamic body writes its pose into the object's `position` and
|
|
208
|
+
* `quaternion` after each step (converted into the parent's frame, so the
|
|
209
|
+
* object may sit anywhere in the graph; its own scale is left alone). A
|
|
210
|
+
* kinematic body or a trigger reads the object's world pose before each step.
|
|
211
|
+
* A static body reads it when created, enabled or {@link teleport}ed.
|
|
212
|
+
*
|
|
213
|
+
* Events use three.js's `addEventListener`; see {@link RigidBodyEventMap}.
|
|
214
|
+
*
|
|
215
|
+
* @group Physics
|
|
216
|
+
*/
|
|
217
|
+
export declare class RigidBody extends EventDispatcher<RigidBodyEventMap> {
|
|
218
|
+
/** The object this body moves (dynamic) or follows (kinematic, trigger). */
|
|
219
|
+
readonly object: Object3D;
|
|
220
|
+
/** The shape description the body was built from. */
|
|
221
|
+
readonly shape: CollisionShape;
|
|
222
|
+
/** True for a sensor body; see {@link RigidBodyOptions.trigger}. */
|
|
223
|
+
readonly isTrigger: boolean;
|
|
224
|
+
/** @internal Key for looking the body up from a Bullet pointer (`btRigidBody` user index). */
|
|
225
|
+
readonly _id: number;
|
|
226
|
+
private readonly _host;
|
|
227
|
+
private _ammoShape;
|
|
228
|
+
/** Native objects the shape keeps alive (triangle meshes), freed with it. */
|
|
229
|
+
private readonly _shapeParts;
|
|
230
|
+
private _body;
|
|
231
|
+
private _type;
|
|
232
|
+
private _mass;
|
|
233
|
+
private _friction;
|
|
234
|
+
private _rollingFriction;
|
|
235
|
+
private _restitution;
|
|
236
|
+
private _linearDamping;
|
|
237
|
+
private _angularDamping;
|
|
238
|
+
private readonly _linearFactor;
|
|
239
|
+
private readonly _angularFactor;
|
|
240
|
+
private _gravityScale;
|
|
241
|
+
private _group;
|
|
242
|
+
private _mask;
|
|
243
|
+
private _enabled;
|
|
244
|
+
private _inWorld;
|
|
245
|
+
private readonly _linearOffset;
|
|
246
|
+
private readonly _angularOffset;
|
|
247
|
+
private readonly _linearVelocity;
|
|
248
|
+
private readonly _angularVelocity;
|
|
249
|
+
/** @internal Use {@link PhysicsWorld.addBody}. */
|
|
250
|
+
constructor(host: BodyHost, id: number, object: Object3D, opts: RigidBodyOptions);
|
|
251
|
+
/**
|
|
252
|
+
* The Bullet `btRigidBody`, for what this wrapper does not cover: CCD
|
|
253
|
+
* (`setCcdMotionThreshold`), raw constraints on
|
|
254
|
+
* {@link PhysicsWorld.dynamicsWorld}. PlayCanvas's `rigidbody.body`.
|
|
255
|
+
* `null` once the body is removed.
|
|
256
|
+
*/
|
|
257
|
+
get ammoBody(): AmmoRigidBody | null;
|
|
258
|
+
/** The world this body belongs to. */
|
|
259
|
+
get world(): PhysicsWorld;
|
|
260
|
+
/** Whether the body is in the simulation. Disabling takes it out without destroying it. */
|
|
261
|
+
get enabled(): boolean;
|
|
262
|
+
set enabled(v: boolean);
|
|
263
|
+
/**
|
|
264
|
+
* Body type. Changing it rebuilds the body and resets {@link group} and
|
|
265
|
+
* {@link mask} to the new type's defaults, as in PlayCanvas.
|
|
266
|
+
*/
|
|
267
|
+
get type(): RigidBodyType;
|
|
268
|
+
set type(t: RigidBodyType);
|
|
269
|
+
/** Collision group bits. Setting it re-adds the body to the world. */
|
|
270
|
+
get group(): number;
|
|
271
|
+
set group(g: number);
|
|
272
|
+
/** Groups this body collides with. Setting it re-adds the body to the world. */
|
|
273
|
+
get mask(): number;
|
|
274
|
+
set mask(m: number);
|
|
275
|
+
/** Kilograms. Only dynamic bodies use it. */
|
|
276
|
+
get mass(): number;
|
|
277
|
+
set mass(m: number);
|
|
278
|
+
get friction(): number;
|
|
279
|
+
set friction(v: number);
|
|
280
|
+
get rollingFriction(): number;
|
|
281
|
+
set rollingFriction(v: number);
|
|
282
|
+
get restitution(): number;
|
|
283
|
+
set restitution(v: number);
|
|
284
|
+
get linearDamping(): number;
|
|
285
|
+
set linearDamping(v: number);
|
|
286
|
+
get angularDamping(): number;
|
|
287
|
+
set angularDamping(v: number);
|
|
288
|
+
/** Per-axis multiplier on linear motion. Assign a vector; mutating the returned one does nothing. */
|
|
289
|
+
get linearFactor(): Vector3;
|
|
290
|
+
set linearFactor(f: XYZ);
|
|
291
|
+
/** Per-axis multiplier on rotation. Assign a vector; mutating the returned one does nothing. */
|
|
292
|
+
get angularFactor(): Vector3;
|
|
293
|
+
set angularFactor(f: XYZ);
|
|
294
|
+
/** Multiplier on the world's gravity for this body. */
|
|
295
|
+
get gravityScale(): number;
|
|
296
|
+
set gravityScale(s: number);
|
|
297
|
+
/**
|
|
298
|
+
* World-space linear velocity, m/s. Dynamic bodies only. The getter returns
|
|
299
|
+
* one reused vector; clone it to keep it. Setting it wakes the body.
|
|
300
|
+
*/
|
|
301
|
+
get linearVelocity(): Vector3;
|
|
302
|
+
set linearVelocity(v: XYZ);
|
|
303
|
+
/** World-space angular velocity, rad/s. Same rules as {@link linearVelocity}. */
|
|
304
|
+
get angularVelocity(): Vector3;
|
|
305
|
+
set angularVelocity(v: XYZ);
|
|
306
|
+
/**
|
|
307
|
+
* Apply a world-space force (N) for the next step, at `relativePoint`
|
|
308
|
+
* (world-space offset from the centre of mass; default the centre).
|
|
309
|
+
*/
|
|
310
|
+
applyForce(force: XYZ, relativePoint?: XYZ): void;
|
|
311
|
+
/** Apply a world-space impulse (N·s) at `relativePoint` (as {@link applyForce}). */
|
|
312
|
+
applyImpulse(impulse: XYZ, relativePoint?: XYZ): void;
|
|
313
|
+
/** Apply a world-space torque (N·m) for the next step. */
|
|
314
|
+
applyTorque(torque: XYZ): void;
|
|
315
|
+
/** Apply a world-space angular impulse (N·m·s). */
|
|
316
|
+
applyTorqueImpulse(torque: XYZ): void;
|
|
317
|
+
/** Whether Bullet is simulating the body this step (it sleeps once it comes to rest). */
|
|
318
|
+
isActive(): boolean;
|
|
319
|
+
/** Wake the body. */
|
|
320
|
+
activate(): void;
|
|
321
|
+
/**
|
|
322
|
+
* Move the object and the body to a world-space position, and optionally a
|
|
323
|
+
* world-space rotation (a quaternion, or an Euler in radians). Velocities
|
|
324
|
+
* are kept. PlayCanvas's `rigidbody.teleport`.
|
|
325
|
+
*/
|
|
326
|
+
teleport(position: XYZ, rotation?: XYZW | Euler): void;
|
|
327
|
+
/** @internal Kinematic bodies: the object's pose becomes the motion-state target. */
|
|
328
|
+
_updateKinematic(): void;
|
|
329
|
+
/** @internal Triggers follow the object as if teleported every step. */
|
|
330
|
+
_updateTrigger(): void;
|
|
331
|
+
/**
|
|
332
|
+
* @internal Dynamic bodies: write the motion state's pose, which Bullet
|
|
333
|
+
* interpolates between fixed steps, into the object. Sleeping bodies are
|
|
334
|
+
* skipped, so an object moved by hand stays put until the body wakes.
|
|
335
|
+
*/
|
|
336
|
+
_updateDynamic(): void;
|
|
337
|
+
/** @internal Re-apply gravity to a body with its own gravity scale after the world gravity changed. */
|
|
338
|
+
_onGravityChanged(): void;
|
|
339
|
+
/** @internal Whether contacts must be gathered for this body's listeners. */
|
|
340
|
+
_wantsContacts(): boolean;
|
|
341
|
+
/** @internal Free every native object. Called by {@link PhysicsWorld.removeBody}. */
|
|
342
|
+
_destroy(): void;
|
|
343
|
+
/** The object's world pose, moved to where the shape sits (collision offsets). */
|
|
344
|
+
private _readObjectPose;
|
|
345
|
+
/** Place the body where the object is: PlayCanvas's `syncEntityToBody`. */
|
|
346
|
+
private _syncObjectToBody;
|
|
347
|
+
private _createBody;
|
|
348
|
+
private _destroyBody;
|
|
349
|
+
private _enableSimulation;
|
|
350
|
+
private _disableSimulation;
|
|
351
|
+
private _readd;
|
|
352
|
+
private _applyGravityScale;
|
|
353
|
+
private _bt;
|
|
354
|
+
private _bt2;
|
|
355
|
+
private _btXform;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Give `object` this world-space position and rotation by solving for its
|
|
359
|
+
* local transform under its parent. The object's own scale is kept.
|
|
360
|
+
*/
|
|
361
|
+
export declare function setObjectWorldPose(object: Object3D, pos: Vector3, quat: Quaternion): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Object3D } from 'three';
|
|
2
|
+
/**
|
|
3
|
+
* Host context every camera preset attaches to: the canvas it takes input
|
|
4
|
+
* from and the camera it moves. `Scene` supplies both as `scene.canvas` and
|
|
5
|
+
* `scene.camera`.
|
|
6
|
+
*
|
|
7
|
+
* @group Presets
|
|
8
|
+
*/
|
|
9
|
+
export interface CameraHost {
|
|
10
|
+
canvas: HTMLCanvasElement;
|
|
11
|
+
/** The camera (or any object) the preset positions and orients. */
|
|
12
|
+
camera: Object3D;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The shape every built-in camera conforms to: construct with config,
|
|
16
|
+
* `attach` to the host, `update` each frame, `detach` on teardown.
|
|
17
|
+
*
|
|
18
|
+
* @group Presets
|
|
19
|
+
*/
|
|
20
|
+
export interface CameraPreset {
|
|
21
|
+
attach(host: CameraHost): void;
|
|
22
|
+
update(dt: number): void;
|
|
23
|
+
detach(): void;
|
|
24
|
+
/** Exposed so controllers can use camera yaw to interpret movement input. */
|
|
25
|
+
readonly yaw: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A position as a plain `{ x, y, z }`, so a `THREE.Vector3` and an ad-hoc
|
|
29
|
+
* literal both satisfy it.
|
|
30
|
+
*
|
|
31
|
+
* @group Presets
|
|
32
|
+
*/
|
|
33
|
+
export type Vec3Like = {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
z: number;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Position supplier - what a camera follows, read every frame.
|
|
40
|
+
*
|
|
41
|
+
* @group Presets
|
|
42
|
+
*/
|
|
43
|
+
export type TargetSupplier = () => Vec3Like;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { CameraHost, CameraPreset, TargetSupplier } from './camera-preset';
|
|
2
|
+
/**
|
|
3
|
+
* Options for {@link ThirdPersonCamera}.
|
|
4
|
+
*
|
|
5
|
+
* @group Presets
|
|
6
|
+
*/
|
|
7
|
+
export interface ThirdPersonCameraOptions {
|
|
8
|
+
/** Position the camera orbits around, read each frame. */
|
|
9
|
+
target: TargetSupplier;
|
|
10
|
+
/** Default 4. */
|
|
11
|
+
distance?: number;
|
|
12
|
+
/** LookAt vertical offset above target. Default 1.2. */
|
|
13
|
+
height?: number;
|
|
14
|
+
/** Initial pitch (degrees, downward positive). Default 15. */
|
|
15
|
+
pitch?: number;
|
|
16
|
+
/** Mouse-look sensitivity in degrees per pixel. Default 0.2. */
|
|
17
|
+
mouseSensitivity?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Third-person follow camera.
|
|
21
|
+
*
|
|
22
|
+
* Orbits behind a target position at `distance` with adjustable `yaw`/`pitch`
|
|
23
|
+
* (degrees), looking at `target + (0, height, 0)`. Yaw 0 puts the camera on
|
|
24
|
+
* the target's +Z side. Mouse handling via pointer lock (click the canvas to
|
|
25
|
+
* capture, Escape to release). No smoothing.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const cam = new ThirdPersonCamera({ target: () => hero.getPosition(), distance: 5, pitch: 25 });
|
|
30
|
+
* cam.attach({ canvas: scene.canvas, camera: scene.camera });
|
|
31
|
+
* scene.on('update', (dt) => cam.update(dt));
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @group Presets
|
|
35
|
+
*/
|
|
36
|
+
export declare class ThirdPersonCamera implements CameraPreset {
|
|
37
|
+
yaw: number;
|
|
38
|
+
pitch: number;
|
|
39
|
+
distance: number;
|
|
40
|
+
height: number;
|
|
41
|
+
mouseSensitivity: number;
|
|
42
|
+
/** When false, mouse-look stops mutating yaw/pitch and the canvas no
|
|
43
|
+
* longer grabs pointer lock. The follow `update()` still runs, so a
|
|
44
|
+
* scripted camera move (e.g. a death cutscene) can drive yaw/pitch/
|
|
45
|
+
* distance/height itself without the player fighting it. Setting this
|
|
46
|
+
* false also releases an active pointer lock. */
|
|
47
|
+
get inputEnabled(): boolean;
|
|
48
|
+
set inputEnabled(v: boolean);
|
|
49
|
+
private _target;
|
|
50
|
+
private _host;
|
|
51
|
+
private _pointerLocked;
|
|
52
|
+
private _inputEnabled;
|
|
53
|
+
private _scratchPos;
|
|
54
|
+
private _scratchLook;
|
|
55
|
+
constructor(config: ThirdPersonCameraOptions);
|
|
56
|
+
attach(host: CameraHost): void;
|
|
57
|
+
detach(): void;
|
|
58
|
+
/** Place the camera for this frame. Call after the target has moved. */
|
|
59
|
+
update(_dt: number): void;
|
|
60
|
+
private _onClickToLock;
|
|
61
|
+
private _onLockChange;
|
|
62
|
+
private _onMouseMove;
|
|
63
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Character } from '../../character';
|
|
2
|
+
import type { BoneScaleInput } from '../../skeletal/bone-stretch';
|
|
3
|
+
import { ALL_BODY_PARTS, BodyPart } from '../../skeletal/body-parts';
|
|
4
|
+
/**
|
|
5
|
+
* A body-proportion preset, parameterized over the rig's humanoid bones.
|
|
6
|
+
* `along` lengthens a segment; girth (width + thickness) fattens it.
|
|
7
|
+
* Spine girth tapers linearly from `torsoGirthBase` (hips, spine_01) to
|
|
8
|
+
* `torsoGirthTop` (chest, spine_05) so the silhouette can be pyramid-shaped.
|
|
9
|
+
* Every value is a multiplier (1 = unchanged).
|
|
10
|
+
*
|
|
11
|
+
* @group Characters & Animation
|
|
12
|
+
*/
|
|
13
|
+
export interface ProportionSpec {
|
|
14
|
+
/** Uniform scale for the head bone + every FACIAL_* bone. */
|
|
15
|
+
head: number;
|
|
16
|
+
/** Lengthen the spine segments. */
|
|
17
|
+
torsoAlong: number;
|
|
18
|
+
/** Spine cross-section at the hips (spine_01). Default 1. */
|
|
19
|
+
torsoGirthBase?: number;
|
|
20
|
+
/** Spine cross-section at the chest (spine_05). Default = torsoGirthBase. */
|
|
21
|
+
torsoGirthTop?: number;
|
|
22
|
+
/** Lengthen the neck. Default = torsoAlong. */
|
|
23
|
+
neckAlong?: number;
|
|
24
|
+
/** Base length for arms + legs. */
|
|
25
|
+
limbAlong: number;
|
|
26
|
+
/** Base cross-section for arms + legs. Default 1. */
|
|
27
|
+
limbGirth?: number;
|
|
28
|
+
/** Override arm length / cross-section. Default = limb*. */
|
|
29
|
+
armAlong?: number;
|
|
30
|
+
armGirth?: number;
|
|
31
|
+
/** Override leg length / cross-section. Default = limb*. */
|
|
32
|
+
legAlong?: number;
|
|
33
|
+
legGirth?: number;
|
|
34
|
+
/** Uniform scale on hand_l/r. Default 1 (unchanged). */
|
|
35
|
+
hands?: number;
|
|
36
|
+
/** Uniform scale on foot_l/r + ball_l/r. Default 1 (unchanged). */
|
|
37
|
+
feet?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Degrees to swing the upper arms out from the torso each frame. Fattening
|
|
40
|
+
* the belly doesn't move the shoulders, so heavy builds need this to keep
|
|
41
|
+
* the arms from sinking into the gut. NOT applied by buildStretch (it's an
|
|
42
|
+
* animation-layer concern, not a bone scale); stored on the spec so presets
|
|
43
|
+
* round-trip it. Default 0.
|
|
44
|
+
*/
|
|
45
|
+
armOutDeg?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Expand a {@link ProportionSpec} into the `{ boneName: scale }` map
|
|
49
|
+
* {@link Armature.setBoneStretch} consumes. Encodes the spine-girth taper and
|
|
50
|
+
* all the per-limb defaults, so the compact spec is meaningless without it.
|
|
51
|
+
* `boneNames` = the loaded rig's actual bones (use `armature.rigBoneNames` so
|
|
52
|
+
* the 441-bone facial rig resolves correctly); optional extremities
|
|
53
|
+
* (hands/feet/FACIAL_*) are only written when present.
|
|
54
|
+
*
|
|
55
|
+
* @group Characters & Animation
|
|
56
|
+
*/
|
|
57
|
+
export declare function buildStretch(boneNames: readonly string[], spec: ProportionSpec): Record<string, BoneScaleInput>;
|
|
58
|
+
/**
|
|
59
|
+
* Stable string keys for {@link BodyPart} - the wire vocabulary of the legacy
|
|
60
|
+
* flat `{part → multiplier}` shape. Prefer {@link ProportionSpec} presets.
|
|
61
|
+
*
|
|
62
|
+
* @group Characters & Animation
|
|
63
|
+
*/
|
|
64
|
+
export declare const BODY_PART_SLUGS: readonly (readonly [string, BodyPart])[];
|
|
65
|
+
/**
|
|
66
|
+
* Body-shape preview driver for one {@link Character}: expands a
|
|
67
|
+
* {@link ProportionSpec} (or a legacy flat per-part map) and applies it via
|
|
68
|
+
* {@link Armature.setBoneStretch}. Cheap enough for live slider dragging.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const shape = BodyShapeVariant.create(character);
|
|
73
|
+
* shape.setSpec({ head: 1.6, torsoAlong: 0.7, limbAlong: 0.5, torsoGirthBase: 1.35 });
|
|
74
|
+
* shape.reset();
|
|
75
|
+
* shape.destroy();
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @group Characters & Animation
|
|
79
|
+
*/
|
|
80
|
+
export declare class BodyShapeVariant {
|
|
81
|
+
private readonly _character;
|
|
82
|
+
private readonly _boneNames;
|
|
83
|
+
/** Bone names per body part (legacy flat-map path), `[BodyPart] → names`. */
|
|
84
|
+
private readonly _partBoneNames;
|
|
85
|
+
private constructor();
|
|
86
|
+
/**
|
|
87
|
+
* Bind to the host character's rig. Synchronous - the armature must already
|
|
88
|
+
* be attached to an engine, whose skeleton library names its bones
|
|
89
|
+
* (441-bone facial rigs resolve through `armature.rigBoneNames`).
|
|
90
|
+
*/
|
|
91
|
+
static create(character: Character): BodyShapeVariant;
|
|
92
|
+
/**
|
|
93
|
+
* Apply a {@link ProportionSpec}. Takes effect on the next armature update.
|
|
94
|
+
* `armOutDeg` is carried on the spec but not previewed (animation-layer
|
|
95
|
+
* concern).
|
|
96
|
+
*/
|
|
97
|
+
setSpec(spec: ProportionSpec): void;
|
|
98
|
+
/**
|
|
99
|
+
* Legacy flat shape: uniform multiplier per body part, keyed by
|
|
100
|
+
* {@link BODY_PART_SLUGS} (`'torso'`, `'left_upper_arm'`, …). Unknown keys
|
|
101
|
+
* and non-finite values are ignored. Prefer {@link setSpec}.
|
|
102
|
+
*/
|
|
103
|
+
setScalesByName(scales: Record<string, number>): void;
|
|
104
|
+
/** Return the character to its unstretched proportions. */
|
|
105
|
+
reset(): void;
|
|
106
|
+
/** Alias of {@link reset} - detach the stretch entirely. */
|
|
107
|
+
destroy(): void;
|
|
108
|
+
}
|
|
109
|
+
export { ALL_BODY_PARTS };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Character } from '../../character';
|
|
2
|
+
import type { RevealLook } from '../../splat/reveal-look';
|
|
3
|
+
/**
|
|
4
|
+
* What {@link playReveal} drives: a splat {@link Character} or a mesh
|
|
5
|
+
* character, on either side of a handoff.
|
|
6
|
+
*
|
|
7
|
+
* @group Characters & Animation
|
|
8
|
+
*/
|
|
9
|
+
export type RevealTarget = Pick<Character, 'armature' | 'destroyed' | 'setReveal' | 'setRevealLook'>;
|
|
10
|
+
/**
|
|
11
|
+
* How {@link playReveal} animates. Times are milliseconds of wall clock, so a
|
|
12
|
+
* reveal keeps its length through dropped frames.
|
|
13
|
+
*
|
|
14
|
+
* @group Characters & Animation
|
|
15
|
+
*/
|
|
16
|
+
export interface RevealPreset {
|
|
17
|
+
/** Length of a full 0 → 1 sweep. */
|
|
18
|
+
duration: number;
|
|
19
|
+
/** Maps linear progress in [0, 1] to reveal amount in [0, 1]. */
|
|
20
|
+
ease: (t: number) => number;
|
|
21
|
+
/**
|
|
22
|
+
* While any frame takes longer than this, the sweep holds at its start - a
|
|
23
|
+
* character's first frames after loading drop several in a row, and
|
|
24
|
+
* advancing through them would spend the sweep in a few jumps.
|
|
25
|
+
*/
|
|
26
|
+
settleFrameMs: number;
|
|
27
|
+
/** Longest the sweep waits for frames to settle. 0 starts at once. */
|
|
28
|
+
settleTimeoutMs: number;
|
|
29
|
+
/** Length {@link RevealRun.speedUp} shortens a full sweep to. */
|
|
30
|
+
interruptedDuration: number;
|
|
31
|
+
/** Applied to both characters when the run starts. Unset keeps their own. */
|
|
32
|
+
look?: RevealLook;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The engine's default reveal timing.
|
|
36
|
+
*
|
|
37
|
+
* @group Characters & Animation
|
|
38
|
+
*/
|
|
39
|
+
export declare const DEFAULT_REVEAL_PRESET: Readonly<RevealPreset>;
|
|
40
|
+
/**
|
|
41
|
+
* Options for {@link playReveal}.
|
|
42
|
+
*
|
|
43
|
+
* @group Characters & Animation
|
|
44
|
+
*/
|
|
45
|
+
export interface PlayRevealOptions {
|
|
46
|
+
/** Dissolves on the same clock as the incoming character appears. */
|
|
47
|
+
outgoing?: RevealTarget | null;
|
|
48
|
+
/** Reveal amount to start from, so an interrupted sweep continues. Default 0. */
|
|
49
|
+
from?: number;
|
|
50
|
+
/** Overrides on {@link DEFAULT_REVEAL_PRESET}. */
|
|
51
|
+
preset?: Partial<RevealPreset>;
|
|
52
|
+
/** Called every frame with the incoming character's reveal amount. */
|
|
53
|
+
onProgress?: (amount: number) => void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A running {@link playReveal}.
|
|
57
|
+
*
|
|
58
|
+
* @group Characters & Animation
|
|
59
|
+
*/
|
|
60
|
+
export interface RevealRun {
|
|
61
|
+
/** Resolves true once the sweep completes, false if cancelled first. */
|
|
62
|
+
readonly finished: Promise<boolean>;
|
|
63
|
+
/** The incoming character's current reveal amount. */
|
|
64
|
+
readonly amount: number;
|
|
65
|
+
/** Finish the rest of the sweep at the pace of a `ms` full sweep. */
|
|
66
|
+
speedUp(ms?: number): void;
|
|
67
|
+
/** Stop where it is. Both characters keep their current reveal amount. */
|
|
68
|
+
cancel(): void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Reveal `incoming` - a bright front walking its skeleton from feet to head -
|
|
72
|
+
* and, given an `outgoing` character, dissolve that one on the same clock so
|
|
73
|
+
* one character hands off to the next. Runs on the engine's update loop
|
|
74
|
+
* ({@link SplatEngine.update}, which `Scene` calls every frame).
|
|
75
|
+
*
|
|
76
|
+
* The caller keeps ownership: nothing is destroyed or hidden when the run
|
|
77
|
+
* ends. Call {@link Character.prepareReveal} after loading so the first frame
|
|
78
|
+
* of the sweep does not pay the one-time setup.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* const next = await Character.load(scene, url);
|
|
83
|
+
* next.setReveal(0);
|
|
84
|
+
* const run = playReveal(next, { outgoing: current });
|
|
85
|
+
* if (await run.finished) current.destroy();
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @group Characters & Animation
|
|
89
|
+
*/
|
|
90
|
+
export declare function playReveal(incoming: RevealTarget, options?: PlayRevealOptions): RevealRun;
|