@viggle/splat-engine-three 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +290 -2
- package/dist/chunks/chunk-MM6DJU6S.js +7801 -0
- package/dist/chunks/chunk-MM6DJU6S.js.map +7 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +7 -0
- package/dist/types/anim/animation-conversion.d.ts +25 -0
- package/dist/types/anim/bind-pose.d.ts +15 -0
- package/dist/types/anim/keyframe-splines.d.ts +59 -0
- package/dist/types/anim/rest-relative.d.ts +32 -0
- package/dist/types/anim/spline.d.ts +14 -0
- package/dist/types/animation.d.ts +216 -0
- package/dist/types/armature.d.ts +524 -0
- package/dist/types/character.d.ts +540 -0
- package/dist/types/engine.d.ts +166 -0
- package/dist/types/environment.d.ts +53 -0
- package/dist/types/index.d.ts +37 -0
- package/dist/types/lighting/color.d.ts +13 -0
- package/dist/types/lighting/point-light.d.ts +33 -0
- package/dist/types/lighting/sky-light.d.ts +22 -0
- package/dist/types/lighting/sun-light.d.ts +34 -0
- package/dist/types/loader/animation/animation-glb.d.ts +117 -0
- package/dist/types/loader/character/index.d.ts +33 -0
- package/dist/types/loader/character/legacy/index.d.ts +34 -0
- package/dist/types/loader/character/legacy/interleaved-splat.d.ts +101 -0
- package/dist/types/loader/character/legacy/planar-splat.d.ts +139 -0
- package/dist/types/loader/character/load.d.ts +33 -0
- package/dist/types/loader/character/types.d.ts +129 -0
- package/dist/types/loader/character/v1/decode.d.ts +32 -0
- package/dist/types/loader/environment/ply.d.ts +16 -0
- package/dist/types/loader/shared/bin-cache.d.ts +19 -0
- package/dist/types/loader/skeleton/index.d.ts +19 -0
- package/dist/types/loader/skeleton/skeleton-data-441.d.ts +5 -0
- package/dist/types/loader/skeleton/skeleton-data.d.ts +6 -0
- package/dist/types/math.d.ts +82 -0
- package/dist/types/skeletal/animation-player.d.ts +185 -0
- package/dist/types/skeletal/bone-mask.d.ts +27 -0
- package/dist/types/skeletal/bone-stretch.d.ts +65 -0
- package/dist/types/skeletal/pose.d.ts +27 -0
- package/dist/types/skeletal/skeleton.d.ts +57 -0
- package/dist/types/skeletal/splat-skinning.d.ts +69 -0
- package/dist/types/splat/backend.d.ts +57 -0
- package/dist/types/splat/bone-binding.d.ts +38 -0
- package/dist/types/splat/depth-sort.d.ts +58 -0
- package/dist/types/splat/packed-splats.d.ts +36 -0
- package/dist/types/splat/splat-mesh.d.ts +71 -0
- package/dist/types/splat/splat.d.ts +186 -0
- package/dist/types/splat/transform-palette.d.ts +42 -0
- package/dist/types/splat/webgl/backend.d.ts +17 -0
- package/dist/types/splat/webgl/shaders.d.ts +2 -0
- package/dist/types/splat/webgl/splat-mesh.d.ts +52 -0
- package/dist/types/splat/webgpu/backend.d.ts +25 -0
- package/dist/types/splat/webgpu/lighting.d.ts +34 -0
- package/dist/types/splat/webgpu/radix-sort.d.ts +46 -0
- package/dist/types/splat/webgpu/splat-mesh.d.ts +71 -0
- package/dist/types/three/loaders.d.ts +77 -0
- package/dist/types/three/splat-character.d.ts +192 -0
- package/dist/types/types.d.ts +30 -0
- package/dist/types/webgpu.d.ts +5 -0
- package/dist/webgpu.js +813 -0
- package/dist/webgpu.js.map +7 -0
- package/package.json +46 -4
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { Matrix4, Object3D, Vector3 } from 'three';
|
|
2
|
+
import type { ColorRepresentation, Object3DEventMap } from 'three';
|
|
3
|
+
import type { Animation } from '../animation';
|
|
4
|
+
import type { Armature } from '../armature';
|
|
5
|
+
import { Character } from '../character';
|
|
6
|
+
import type { SplatEngine } from '../engine';
|
|
7
|
+
import type { CharacterBundle } from '../loader/character/load';
|
|
8
|
+
import type { BodyRegion, BoneMask } from '../skeletal/bone-mask';
|
|
9
|
+
import type { Splat } from '../splat/splat';
|
|
10
|
+
/**
|
|
11
|
+
* What a clip's horizontal travel does to the character.
|
|
12
|
+
*
|
|
13
|
+
* - `'off'` - the clip plays in place.
|
|
14
|
+
* - `'apply'` - the character's body moves with the clip, beneath
|
|
15
|
+
* {@link SplatCharacter.position}, which stays where you put it.
|
|
16
|
+
* - `'extract'` - the clip plays in place and its travel is handed to you by
|
|
17
|
+
* {@link SplatCharacter.consumeRootMotion}, to feed a controller or physics.
|
|
18
|
+
*
|
|
19
|
+
* @group Characters & Animation
|
|
20
|
+
*/
|
|
21
|
+
export type SplatRootMotion = 'off' | 'apply' | 'extract';
|
|
22
|
+
/** @group Characters & Animation */
|
|
23
|
+
export interface SplatPlayOptions {
|
|
24
|
+
/** Repeat when the clip ends. Default `true`. */
|
|
25
|
+
loop?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/** @group Characters & Animation */
|
|
28
|
+
export interface SplatCrossFadeOptions extends SplatPlayOptions {
|
|
29
|
+
/** Start the new clip at the same fraction of its length the old one had reached. Default `false`. */
|
|
30
|
+
preserveTime?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** @group Characters & Animation */
|
|
33
|
+
export interface SplatLayerOptions {
|
|
34
|
+
/** The bones the layer drives, as a named region. Give this or `mask`. */
|
|
35
|
+
region?: BodyRegion;
|
|
36
|
+
/** The bones the layer drives, as an explicit mask. Give this or `region`. */
|
|
37
|
+
mask?: BoneMask;
|
|
38
|
+
/** Repeat when the clip ends. Default `true`. */
|
|
39
|
+
loop?: boolean;
|
|
40
|
+
/** Seconds to blend the layer in. Default `0`. */
|
|
41
|
+
fadeDuration?: number;
|
|
42
|
+
/** How strongly the layer overrides the base pose, 0..1. Default `1`. */
|
|
43
|
+
weight?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Events a {@link SplatCharacter} dispatches, alongside the usual `Object3D` ones.
|
|
47
|
+
* @group Characters & Animation
|
|
48
|
+
*/
|
|
49
|
+
export interface SplatCharacterEventMap extends Object3DEventMap {
|
|
50
|
+
/** A non-looping clip reached its last frame. */
|
|
51
|
+
finished: {
|
|
52
|
+
clip: Animation;
|
|
53
|
+
};
|
|
54
|
+
/** A looping clip wrapped around to its start. */
|
|
55
|
+
loop: {
|
|
56
|
+
clip: Animation;
|
|
57
|
+
};
|
|
58
|
+
/** An event authored into the clip was crossed. */
|
|
59
|
+
clipevent: {
|
|
60
|
+
clip: Animation | null;
|
|
61
|
+
name: string;
|
|
62
|
+
frame: number;
|
|
63
|
+
payload?: unknown;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A gaussian-splat character, as a three.js object.
|
|
68
|
+
*
|
|
69
|
+
* Add it to a scene, move it with `position` / `rotation` / `scale`, and call
|
|
70
|
+
* {@link SplatCharacter.update} once per frame - the role `AnimationMixer.update`
|
|
71
|
+
* plays for a skinned mesh. Create one with {@link VSplatLoader}.
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* const character = await new VSplatLoader().loadAsync('/assets/hero.vsplat');
|
|
75
|
+
* scene.add(character);
|
|
76
|
+
* character.position.set(1, 0, 0);
|
|
77
|
+
*
|
|
78
|
+
* const run = await new SplatClipLoader().loadAsync('/assets/run.glb');
|
|
79
|
+
* character.play(run);
|
|
80
|
+
*
|
|
81
|
+
* renderer.setAnimationLoop(() => {
|
|
82
|
+
* character.update(clock.getDelta());
|
|
83
|
+
* renderer.render(scene, camera);
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* `position` is the model origin. A character in its rest pose stands on it;
|
|
88
|
+
* how closely a clip keeps the feet on it depends on the clip.
|
|
89
|
+
*
|
|
90
|
+
* Animation is driven by this class rather than by `AnimationMixer`: a splat
|
|
91
|
+
* character has no `Bone` hierarchy for a mixer to write to. Clips are
|
|
92
|
+
* {@link Animation} objects from {@link SplatClipLoader}.
|
|
93
|
+
*
|
|
94
|
+
* @group Characters & Animation
|
|
95
|
+
*/
|
|
96
|
+
export declare class SplatCharacter extends Object3D<SplatCharacterEventMap> {
|
|
97
|
+
/** Type flag, in the three.js manner. */
|
|
98
|
+
readonly isSplatCharacter = true;
|
|
99
|
+
readonly type: string;
|
|
100
|
+
/**
|
|
101
|
+
* The engine-level character this object wraps. Everything not surfaced
|
|
102
|
+
* here - multi-level LOD, variant splats, animation LOD - is reachable
|
|
103
|
+
* through it.
|
|
104
|
+
*/
|
|
105
|
+
readonly character: Character;
|
|
106
|
+
private readonly _engine;
|
|
107
|
+
private readonly _bundles;
|
|
108
|
+
private _clip;
|
|
109
|
+
private _loop;
|
|
110
|
+
private _finishedSent;
|
|
111
|
+
private _rootMotion;
|
|
112
|
+
private _disposed;
|
|
113
|
+
/**
|
|
114
|
+
* @param bundles - Decoded character bundles, finest level of detail first.
|
|
115
|
+
* They are read, never modified, so clones share them.
|
|
116
|
+
* @internal Use {@link VSplatLoader}.
|
|
117
|
+
*/
|
|
118
|
+
constructor(engine: SplatEngine, bundles: CharacterBundle[], name?: string);
|
|
119
|
+
/** The rig: bone names, bone matrices, bone-length scaling. */
|
|
120
|
+
get armature(): Armature;
|
|
121
|
+
/** The splats that draw this character, one per level of detail. */
|
|
122
|
+
get splats(): readonly Splat[];
|
|
123
|
+
/**
|
|
124
|
+
* Advance the animation by `delta` seconds and pose the splats. Call once
|
|
125
|
+
* per frame, before rendering.
|
|
126
|
+
*/
|
|
127
|
+
update(delta: number): void;
|
|
128
|
+
/** Start `clip` from its first frame, cutting from whatever was playing. */
|
|
129
|
+
play(clip: Animation, options?: SplatPlayOptions): this;
|
|
130
|
+
/** Blend from the current pose into `clip` over `duration` seconds. */
|
|
131
|
+
crossFadeTo(clip: Animation, duration?: number, options?: SplatCrossFadeOptions): this;
|
|
132
|
+
/** Stop playback and return to the rest pose, blending over `fadeDuration` seconds. */
|
|
133
|
+
stop(fadeDuration?: number): this;
|
|
134
|
+
/**
|
|
135
|
+
* Play `clip` on a named layer that overrides part of the body - an upper
|
|
136
|
+
* body wave over a full-body run, say. Calling it again with the same layer
|
|
137
|
+
* name replaces what that layer plays.
|
|
138
|
+
*/
|
|
139
|
+
playLayer(layer: string, clip: Animation, options: SplatLayerOptions): this;
|
|
140
|
+
setLayerWeight(layer: string, weight: number): this;
|
|
141
|
+
stopLayer(layer: string, fadeDuration?: number): this;
|
|
142
|
+
/** The clip the base track is playing, or `null`. */
|
|
143
|
+
get clip(): Animation | null;
|
|
144
|
+
get isPlaying(): boolean;
|
|
145
|
+
get paused(): boolean;
|
|
146
|
+
set paused(value: boolean);
|
|
147
|
+
/** Playback speed multiplier. `1` is the authored speed. */
|
|
148
|
+
get timeScale(): number;
|
|
149
|
+
set timeScale(value: number);
|
|
150
|
+
/** Position in the current clip, in seconds. */
|
|
151
|
+
get time(): number;
|
|
152
|
+
set time(seconds: number);
|
|
153
|
+
/** Length of the current clip in seconds, or `0` when nothing is playing. */
|
|
154
|
+
get duration(): number;
|
|
155
|
+
/** See {@link SplatRootMotion}. Applies to the current clip and every later one. */
|
|
156
|
+
get rootMotion(): SplatRootMotion;
|
|
157
|
+
set rootMotion(mode: SplatRootMotion);
|
|
158
|
+
/**
|
|
159
|
+
* The clip's horizontal travel since the last call, in this object's local
|
|
160
|
+
* space. Non-zero only in `'extract'` mode. `y` is always `0`.
|
|
161
|
+
*/
|
|
162
|
+
consumeRootMotion(target?: Vector3): Vector3;
|
|
163
|
+
/**
|
|
164
|
+
* Blend the character's colour toward `color` by `amount` (0..1) - a hit
|
|
165
|
+
* flash, a selection highlight. `amount = 0` restores the authored colour.
|
|
166
|
+
*/
|
|
167
|
+
setTint(color: ColorRepresentation, amount?: number): this;
|
|
168
|
+
/** Contrast and saturation multipliers for the character's colour. `(1, 1)` is unchanged. */
|
|
169
|
+
setGrade(contrast: number, saturation: number): this;
|
|
170
|
+
/** Bone names, in rig order. */
|
|
171
|
+
get boneNames(): readonly string[];
|
|
172
|
+
/**
|
|
173
|
+
* World matrix of a bone as of the last {@link SplatCharacter.update} - for
|
|
174
|
+
* attaching a prop to a hand, or aiming a camera at a head.
|
|
175
|
+
*
|
|
176
|
+
* @returns `target`, or `null` when the rig has no bone of that name.
|
|
177
|
+
*/
|
|
178
|
+
getBoneWorldMatrix(name: string, target?: Matrix4): Matrix4 | null;
|
|
179
|
+
/**
|
|
180
|
+
* A second character from the same decoded data, at the same transform. The
|
|
181
|
+
* copy starts in the rest pose with nothing playing; it does not share this
|
|
182
|
+
* one's animation state.
|
|
183
|
+
*/
|
|
184
|
+
clone(): this;
|
|
185
|
+
/**
|
|
186
|
+
* Release every GPU resource the character holds. The object stays in the
|
|
187
|
+
* scene graph, empty; remove it yourself if you no longer want it there.
|
|
188
|
+
*/
|
|
189
|
+
dispose(): void;
|
|
190
|
+
private _keyFor;
|
|
191
|
+
private _started;
|
|
192
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared data shapes used across the loader, skeletal and splat layers.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Rig description handed to {@link Armature}.
|
|
6
|
+
*
|
|
7
|
+
* The `stdMale*` field names are inherited from the skeleton library and mean
|
|
8
|
+
* "the rest pose this armature binds to", whichever rig that is.
|
|
9
|
+
*/
|
|
10
|
+
export interface ArmatureData {
|
|
11
|
+
numBones: number;
|
|
12
|
+
/** Flat `[x,y,z] * numBones` rest translations carried by the character bundle. */
|
|
13
|
+
joints?: Float32Array;
|
|
14
|
+
/** Whether the bundle's geometric corrections are baked into its splats and joints. */
|
|
15
|
+
corrected?: boolean;
|
|
16
|
+
/** Whether `joints` is this character's own vetted rest pose. */
|
|
17
|
+
restIsPerCharacter?: boolean;
|
|
18
|
+
skeleton?: Int32Array;
|
|
19
|
+
stdMaleRestTranslations?: Float32Array;
|
|
20
|
+
stdMaleRestRotations?: Float32Array;
|
|
21
|
+
stdMaleParents?: Int32Array;
|
|
22
|
+
}
|
|
23
|
+
/** Per-splat skinning influences, `K` slots per splat. */
|
|
24
|
+
export interface SplatWeights {
|
|
25
|
+
/** `numSplats * K` rig bone indices. */
|
|
26
|
+
indices: Uint16Array;
|
|
27
|
+
/** `numSplats * K` weights, matching `indices`. */
|
|
28
|
+
weights: Float32Array;
|
|
29
|
+
}
|
|
30
|
+
export type { SkeletonLibrary } from './loader/skeleton';
|