reze-engine 0.3.4 → 0.3.6
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/dist/ammo-loader.d.ts +0 -1
- package/dist/ammo-loader.d.ts.map +1 -1
- package/dist/ammo-loader.js +0 -3
- package/dist/engine.d.ts +2 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +44 -100
- package/dist/ik-solver.d.ts +7 -2
- package/dist/ik-solver.d.ts.map +1 -1
- package/dist/ik-solver.js +110 -137
- package/dist/math.d.ts +10 -6
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +36 -62
- package/dist/model.d.ts +1 -19
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +24 -93
- package/dist/player.d.ts +6 -20
- package/dist/player.d.ts.map +1 -1
- package/dist/player.js +89 -193
- package/package.json +1 -1
- package/src/ammo-loader.ts +0 -4
- package/src/engine.ts +54 -101
- package/src/ik-solver.ts +121 -178
- package/src/math.ts +43 -82
- package/src/model.ts +26 -101
- package/src/player.ts +116 -212
- package/src/bezier-interpolate.ts +0 -47
- package/src/ik.ts +0 -449
package/dist/math.d.ts
CHANGED
|
@@ -7,12 +7,10 @@ export declare class Vec3 {
|
|
|
7
7
|
add(other: Vec3): Vec3;
|
|
8
8
|
subtract(other: Vec3): Vec3;
|
|
9
9
|
length(): number;
|
|
10
|
-
lengthSquared(): number;
|
|
11
10
|
normalize(): Vec3;
|
|
12
11
|
cross(other: Vec3): Vec3;
|
|
13
12
|
dot(other: Vec3): number;
|
|
14
13
|
scale(scalar: number): Vec3;
|
|
15
|
-
clone(): Vec3;
|
|
16
14
|
}
|
|
17
15
|
export declare class Quat {
|
|
18
16
|
x: number;
|
|
@@ -26,14 +24,10 @@ export declare class Quat {
|
|
|
26
24
|
conjugate(): Quat;
|
|
27
25
|
length(): number;
|
|
28
26
|
normalize(): Quat;
|
|
29
|
-
rotateVec(v: Vec3): Vec3;
|
|
30
|
-
rotate(v: Vec3): Vec3;
|
|
31
|
-
static fromTo(from: Vec3, to: Vec3): Quat;
|
|
32
27
|
static fromAxisAngle(axis: Vec3, angle: number): Quat;
|
|
33
28
|
toArray(): [number, number, number, number];
|
|
34
29
|
static slerp(a: Quat, b: Quat, t: number): Quat;
|
|
35
30
|
static fromEuler(rotX: number, rotY: number, rotZ: number): Quat;
|
|
36
|
-
toEuler(): Vec3;
|
|
37
31
|
}
|
|
38
32
|
export declare class Mat4 {
|
|
39
33
|
values: Float32Array;
|
|
@@ -53,4 +47,14 @@ export declare class Mat4 {
|
|
|
53
47
|
translateInPlace(tx: number, ty: number, tz: number): this;
|
|
54
48
|
inverse(): Mat4;
|
|
55
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Bezier interpolation function
|
|
52
|
+
* @param x1 First control point X (0-127, normalized to 0-1)
|
|
53
|
+
* @param x2 Second control point X (0-127, normalized to 0-1)
|
|
54
|
+
* @param y1 First control point Y (0-127, normalized to 0-1)
|
|
55
|
+
* @param y2 Second control point Y (0-127, normalized to 0-1)
|
|
56
|
+
* @param t Interpolation parameter (0-1)
|
|
57
|
+
* @returns Interpolated value (0-1)
|
|
58
|
+
*/
|
|
59
|
+
export declare function bezierInterpolate(x1: number, x2: number, y1: number, y2: number, t: number): number;
|
|
56
60
|
//# sourceMappingURL=math.d.ts.map
|
package/dist/math.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../src/math.ts"],"names":[],"mappings":"AACA,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,qBAAa,IAAI;IACf,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;gBAEG,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;IAM3C,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI;IAItB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,GAAG,IAAI;IA6C7D,WAAW,IAAI,IAAI;IAqBnB,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI;IAY1D,OAAO,IAAI,IAAI;CA8DhB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAgCnG"}
|
package/dist/math.js
CHANGED
|
@@ -17,9 +17,6 @@ export class Vec3 {
|
|
|
17
17
|
length() {
|
|
18
18
|
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
|
19
19
|
}
|
|
20
|
-
lengthSquared() {
|
|
21
|
-
return this.x * this.x + this.y * this.y + this.z * this.z;
|
|
22
|
-
}
|
|
23
20
|
normalize() {
|
|
24
21
|
const len = this.length();
|
|
25
22
|
if (len === 0)
|
|
@@ -35,9 +32,6 @@ export class Vec3 {
|
|
|
35
32
|
scale(scalar) {
|
|
36
33
|
return new Vec3(this.x * scalar, this.y * scalar, this.z * scalar);
|
|
37
34
|
}
|
|
38
|
-
clone() {
|
|
39
|
-
return new Vec3(this.x, this.y, this.z);
|
|
40
|
-
}
|
|
41
35
|
}
|
|
42
36
|
export class Quat {
|
|
43
37
|
constructor(x, y, z, w) {
|
|
@@ -69,42 +63,6 @@ export class Quat {
|
|
|
69
63
|
return new Quat(0, 0, 0, 1);
|
|
70
64
|
return new Quat(this.x / len, this.y / len, this.z / len, this.w / len);
|
|
71
65
|
}
|
|
72
|
-
// Rotate a vector by this quaternion: result = q * v * q^-1
|
|
73
|
-
rotateVec(v) {
|
|
74
|
-
// Treat v as pure quaternion (x, y, z, 0)
|
|
75
|
-
const qx = this.x, qy = this.y, qz = this.z, qw = this.w;
|
|
76
|
-
const vx = v.x, vy = v.y, vz = v.z;
|
|
77
|
-
// t = 2 * cross(q.xyz, v)
|
|
78
|
-
const tx = 2 * (qy * vz - qz * vy);
|
|
79
|
-
const ty = 2 * (qz * vx - qx * vz);
|
|
80
|
-
const tz = 2 * (qx * vy - qy * vx);
|
|
81
|
-
// result = v + q.w * t + cross(q.xyz, t)
|
|
82
|
-
return new Vec3(vx + qw * tx + (qy * tz - qz * ty), vy + qw * ty + (qz * tx - qx * tz), vz + qw * tz + (qx * ty - qy * tx));
|
|
83
|
-
}
|
|
84
|
-
// Rotate a vector by this quaternion (Babylon.js style naming)
|
|
85
|
-
rotate(v) {
|
|
86
|
-
const qv = new Vec3(this.x, this.y, this.z);
|
|
87
|
-
const uv = qv.cross(v);
|
|
88
|
-
const uuv = qv.cross(uv);
|
|
89
|
-
return v.add(uv.scale(2 * this.w)).add(uuv.scale(2));
|
|
90
|
-
}
|
|
91
|
-
// Static method: create quaternion that rotates from one direction to another
|
|
92
|
-
static fromTo(from, to) {
|
|
93
|
-
const dot = from.dot(to);
|
|
94
|
-
if (dot > 0.999999)
|
|
95
|
-
return new Quat(0, 0, 0, 1); // Already aligned
|
|
96
|
-
if (dot < -0.999999) {
|
|
97
|
-
// 180 degrees
|
|
98
|
-
let axis = from.cross(new Vec3(1, 0, 0));
|
|
99
|
-
if (axis.length() < 0.001)
|
|
100
|
-
axis = from.cross(new Vec3(0, 1, 0));
|
|
101
|
-
return new Quat(axis.x, axis.y, axis.z, 0).normalize();
|
|
102
|
-
}
|
|
103
|
-
const axis = from.cross(to);
|
|
104
|
-
const w = Math.sqrt((1 + dot) * 2);
|
|
105
|
-
const invW = 1 / w;
|
|
106
|
-
return new Quat(axis.x * invW, axis.y * invW, axis.z * invW, w * 0.5).normalize();
|
|
107
|
-
}
|
|
108
66
|
// Static method: create quaternion from rotation axis and angle
|
|
109
67
|
static fromAxisAngle(axis, angle) {
|
|
110
68
|
const normalizedAxis = axis.normalize();
|
|
@@ -159,26 +117,6 @@ export class Quat {
|
|
|
159
117
|
const z = cy * cx * sz - sy * sx * cz;
|
|
160
118
|
return new Quat(x, y, z, w).normalize();
|
|
161
119
|
}
|
|
162
|
-
// Convert quaternion to Euler angles (ZXY order, inverse of fromEuler)
|
|
163
|
-
toEuler() {
|
|
164
|
-
const qx = this.x;
|
|
165
|
-
const qy = this.y;
|
|
166
|
-
const qz = this.z;
|
|
167
|
-
const qw = this.w;
|
|
168
|
-
// ZXY order (left-handed)
|
|
169
|
-
// Roll (X): rotation around X axis
|
|
170
|
-
const sinr_cosp = 2 * (qw * qx + qy * qz);
|
|
171
|
-
const cosr_cosp = 1 - 2 * (qx * qx + qy * qy);
|
|
172
|
-
const rotX = Math.atan2(sinr_cosp, cosr_cosp);
|
|
173
|
-
// Pitch (Y): rotation around Y axis
|
|
174
|
-
const sinp = 2 * (qw * qy - qz * qx);
|
|
175
|
-
const rotY = Math.abs(sinp) >= 1 ? (sinp >= 0 ? Math.PI / 2 : -Math.PI / 2) : Math.asin(sinp);
|
|
176
|
-
// Yaw (Z): rotation around Z axis
|
|
177
|
-
const siny_cosp = 2 * (qw * qz + qx * qy);
|
|
178
|
-
const cosy_cosp = 1 - 2 * (qy * qy + qz * qz);
|
|
179
|
-
const rotZ = Math.atan2(siny_cosp, cosy_cosp);
|
|
180
|
-
return new Vec3(rotX, rotY, rotZ);
|
|
181
|
-
}
|
|
182
120
|
}
|
|
183
121
|
export class Mat4 {
|
|
184
122
|
constructor(values) {
|
|
@@ -431,3 +369,39 @@ export class Mat4 {
|
|
|
431
369
|
return new Mat4(out);
|
|
432
370
|
}
|
|
433
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* Bezier interpolation function
|
|
374
|
+
* @param x1 First control point X (0-127, normalized to 0-1)
|
|
375
|
+
* @param x2 Second control point X (0-127, normalized to 0-1)
|
|
376
|
+
* @param y1 First control point Y (0-127, normalized to 0-1)
|
|
377
|
+
* @param y2 Second control point Y (0-127, normalized to 0-1)
|
|
378
|
+
* @param t Interpolation parameter (0-1)
|
|
379
|
+
* @returns Interpolated value (0-1)
|
|
380
|
+
*/
|
|
381
|
+
export function bezierInterpolate(x1, x2, y1, y2, t) {
|
|
382
|
+
// Clamp t to [0, 1]
|
|
383
|
+
t = Math.max(0, Math.min(1, t));
|
|
384
|
+
// Binary search for the t value that gives us the desired x
|
|
385
|
+
// We're solving for t in the Bezier curve: x(t) = 3*(1-t)^2*t*x1 + 3*(1-t)*t^2*x2 + t^3
|
|
386
|
+
let start = 0;
|
|
387
|
+
let end = 1;
|
|
388
|
+
let mid = 0.5;
|
|
389
|
+
// Iterate until we find the t value that gives us the desired x
|
|
390
|
+
for (let i = 0; i < 15; i++) {
|
|
391
|
+
// Evaluate Bezier curve at mid point
|
|
392
|
+
const x = 3 * (1 - mid) * (1 - mid) * mid * x1 + 3 * (1 - mid) * mid * mid * x2 + mid * mid * mid;
|
|
393
|
+
if (Math.abs(x - t) < 0.0001) {
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
if (x < t) {
|
|
397
|
+
start = mid;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
end = mid;
|
|
401
|
+
}
|
|
402
|
+
mid = (start + end) / 2;
|
|
403
|
+
}
|
|
404
|
+
// Now evaluate the y value at this t
|
|
405
|
+
const y = 3 * (1 - mid) * (1 - mid) * mid * y1 + 3 * (1 - mid) * mid * mid * y2 + mid * mid * mid;
|
|
406
|
+
return y;
|
|
407
|
+
}
|
package/dist/model.d.ts
CHANGED
|
@@ -42,20 +42,6 @@ export interface IKLink {
|
|
|
42
42
|
hasLimit: boolean;
|
|
43
43
|
minAngle?: Vec3;
|
|
44
44
|
maxAngle?: Vec3;
|
|
45
|
-
rotationOrder?: EulerRotationOrder;
|
|
46
|
-
solveAxis?: SolveAxis;
|
|
47
|
-
}
|
|
48
|
-
export declare enum EulerRotationOrder {
|
|
49
|
-
YXZ = 0,
|
|
50
|
-
ZYX = 1,
|
|
51
|
-
XZY = 2
|
|
52
|
-
}
|
|
53
|
-
export declare enum SolveAxis {
|
|
54
|
-
None = 0,
|
|
55
|
-
Fixed = 1,
|
|
56
|
-
X = 2,
|
|
57
|
-
Y = 3,
|
|
58
|
-
Z = 4
|
|
59
45
|
}
|
|
60
46
|
export interface IKSolver {
|
|
61
47
|
index: number;
|
|
@@ -64,7 +50,6 @@ export interface IKSolver {
|
|
|
64
50
|
iterationCount: number;
|
|
65
51
|
limitAngle: number;
|
|
66
52
|
links: IKLink[];
|
|
67
|
-
canSkipWhenPhysicsEnabled: boolean;
|
|
68
53
|
}
|
|
69
54
|
export interface IKChainInfo {
|
|
70
55
|
ikRotation: Quat;
|
|
@@ -101,7 +86,6 @@ export interface SkeletonRuntime {
|
|
|
101
86
|
localRotations: Float32Array;
|
|
102
87
|
localTranslations: Float32Array;
|
|
103
88
|
worldMatrices: Float32Array;
|
|
104
|
-
computedBones: boolean[];
|
|
105
89
|
ikChainInfo?: IKChainInfo[];
|
|
106
90
|
ikSolvers?: IKSolver[];
|
|
107
91
|
}
|
|
@@ -134,6 +118,7 @@ export declare class Model {
|
|
|
134
118
|
private initializeRotTweenBuffers;
|
|
135
119
|
private initializeTransTweenBuffers;
|
|
136
120
|
private initializeMorphTweenBuffers;
|
|
121
|
+
private createTweenState;
|
|
137
122
|
private initializeRuntimeMorph;
|
|
138
123
|
private updateRotationTweens;
|
|
139
124
|
private updateTranslationTweens;
|
|
@@ -141,7 +126,6 @@ export declare class Model {
|
|
|
141
126
|
getVertices(): Float32Array<ArrayBuffer>;
|
|
142
127
|
getTextures(): Texture[];
|
|
143
128
|
getMaterials(): Material[];
|
|
144
|
-
getVertexCount(): number;
|
|
145
129
|
getIndices(): Uint32Array<ArrayBuffer>;
|
|
146
130
|
getSkeleton(): Skeleton;
|
|
147
131
|
getSkinning(): Skinning;
|
|
@@ -149,12 +133,10 @@ export declare class Model {
|
|
|
149
133
|
getJoints(): Joint[];
|
|
150
134
|
getMorphing(): Morphing;
|
|
151
135
|
getMorphWeights(): Float32Array;
|
|
152
|
-
getBoneNames(): string[];
|
|
153
136
|
rotateBones(names: string[], quats: Quat[], durationMs?: number): void;
|
|
154
137
|
moveBones(names: string[], relativeTranslations: Vec3[], durationMs?: number): void;
|
|
155
138
|
getBoneWorldMatrices(): Float32Array;
|
|
156
139
|
getBoneInverseBindMatrices(): Float32Array;
|
|
157
|
-
getMorphNames(): string[];
|
|
158
140
|
setMorphWeight(name: string, weight: number, durationMs?: number): void;
|
|
159
141
|
private applyMorphs;
|
|
160
142
|
evaluatePose(): boolean;
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,IAAI,EAAE,IAAI,EAAa,MAAM,QAAQ,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAK5C,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,kBAAkB,EAAE,MAAM,CAAA;IAC1B,kBAAkB,EAAE,MAAM,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3C,QAAQ,EAAE,MAAM,CAAA;IAChB,WAA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C,sBAAsB;IAW9B,OAAO,CAAC,oBAAoB;IAsC5B,OAAO,CAAC,uBAAuB;IAuB/B,OAAO,CAAC,uBAAuB;IA2B/B,WAAW,IAAI,YAAY,CAAC,WAAW,CAAC;IAIxC,WAAW,IAAI,OAAO,EAAE;IAIxB,YAAY,IAAI,QAAQ,EAAE;IAI1B,UAAU,IAAI,WAAW,CAAC,WAAW,CAAC;IAItC,WAAW,IAAI,QAAQ;IAIvB,WAAW,IAAI,QAAQ;IAIvB,cAAc,IAAI,SAAS,EAAE;IAI7B,SAAS,IAAI,KAAK,EAAE;IAIpB,WAAW,IAAI,QAAQ;IAIvB,eAAe,IAAI,YAAY;IAM/B,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAqEtE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAoGnF,oBAAoB,IAAI,YAAY;IAIpC,0BAA0B,IAAI,YAAY;IAI1C,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAwCvE,OAAO,CAAC,WAAW;IAiEnB,YAAY,IAAI,OAAO;IAoBvB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,oBAAoB;CA4F7B"}
|
package/dist/model.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
import { Mat4, Quat, Vec3, easeInOut } from "./math";
|
|
2
2
|
import { IKSolverSystem } from "./ik-solver";
|
|
3
3
|
const VERTEX_STRIDE = 8;
|
|
4
|
-
// Euler rotation order for angle constraints
|
|
5
|
-
export var EulerRotationOrder;
|
|
6
|
-
(function (EulerRotationOrder) {
|
|
7
|
-
EulerRotationOrder[EulerRotationOrder["YXZ"] = 0] = "YXZ";
|
|
8
|
-
EulerRotationOrder[EulerRotationOrder["ZYX"] = 1] = "ZYX";
|
|
9
|
-
EulerRotationOrder[EulerRotationOrder["XZY"] = 2] = "XZY";
|
|
10
|
-
})(EulerRotationOrder || (EulerRotationOrder = {}));
|
|
11
|
-
// Solve axis optimization
|
|
12
|
-
export var SolveAxis;
|
|
13
|
-
(function (SolveAxis) {
|
|
14
|
-
SolveAxis[SolveAxis["None"] = 0] = "None";
|
|
15
|
-
SolveAxis[SolveAxis["Fixed"] = 1] = "Fixed";
|
|
16
|
-
SolveAxis[SolveAxis["X"] = 2] = "X";
|
|
17
|
-
SolveAxis[SolveAxis["Y"] = 3] = "Y";
|
|
18
|
-
SolveAxis[SolveAxis["Z"] = 4] = "Z";
|
|
19
|
-
})(SolveAxis || (SolveAxis = {}));
|
|
20
4
|
export class Model {
|
|
21
5
|
constructor(vertexData, indexData, textures, materials, skeleton, skinning, morphing, rigidbodies = [], joints = []) {
|
|
22
6
|
this.textures = [];
|
|
@@ -59,7 +43,6 @@ export class Model {
|
|
|
59
43
|
acc[bone.name] = index;
|
|
60
44
|
return acc;
|
|
61
45
|
}, {}),
|
|
62
|
-
computedBones: new Array(boneCount).fill(false),
|
|
63
46
|
};
|
|
64
47
|
const rotations = this.runtimeSkeleton.localRotations;
|
|
65
48
|
for (let i = 0; i < this.skeleton.bones.length; i++) {
|
|
@@ -91,17 +74,6 @@ export class Model {
|
|
|
91
74
|
for (let i = 0; i < boneCount; i++) {
|
|
92
75
|
const bone = bones[i];
|
|
93
76
|
if (bone.ikTargetIndex !== undefined && bone.ikLinks && bone.ikLinks.length > 0) {
|
|
94
|
-
// Check if all links are affected by physics (for optimization)
|
|
95
|
-
let canSkipWhenPhysicsEnabled = true;
|
|
96
|
-
for (const link of bone.ikLinks) {
|
|
97
|
-
// For now, assume no bones are physics-controlled (can be enhanced later)
|
|
98
|
-
// If a bone has a rigidbody attached, it's physics-controlled
|
|
99
|
-
const hasPhysics = this.rigidbodies.some((rb) => rb.boneIndex === link.boneIndex);
|
|
100
|
-
if (!hasPhysics) {
|
|
101
|
-
canSkipWhenPhysicsEnabled = false;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
77
|
const solver = {
|
|
106
78
|
index: solverIndex++,
|
|
107
79
|
ikBoneIndex: i,
|
|
@@ -109,7 +81,6 @@ export class Model {
|
|
|
109
81
|
iterationCount: bone.ikIteration ?? 1,
|
|
110
82
|
limitAngle: bone.ikLimitAngle ?? Math.PI,
|
|
111
83
|
links: bone.ikLinks,
|
|
112
|
-
canSkipWhenPhysicsEnabled,
|
|
113
84
|
};
|
|
114
85
|
ikSolvers.push(solver);
|
|
115
86
|
}
|
|
@@ -118,33 +89,21 @@ export class Model {
|
|
|
118
89
|
this.runtimeSkeleton.ikSolvers = ikSolvers;
|
|
119
90
|
}
|
|
120
91
|
initializeRotTweenBuffers() {
|
|
121
|
-
|
|
122
|
-
this.rotTweenState = {
|
|
123
|
-
active: new Uint8Array(n),
|
|
124
|
-
startQuat: new Float32Array(n * 4),
|
|
125
|
-
targetQuat: new Float32Array(n * 4),
|
|
126
|
-
startTimeMs: new Float32Array(n),
|
|
127
|
-
durationMs: new Float32Array(n),
|
|
128
|
-
};
|
|
92
|
+
this.rotTweenState = this.createTweenState(this.skeleton.bones.length, 4, 4);
|
|
129
93
|
}
|
|
130
94
|
initializeTransTweenBuffers() {
|
|
131
|
-
|
|
132
|
-
this.transTweenState = {
|
|
133
|
-
active: new Uint8Array(n),
|
|
134
|
-
startVec: new Float32Array(n * 3),
|
|
135
|
-
targetVec: new Float32Array(n * 3),
|
|
136
|
-
startTimeMs: new Float32Array(n),
|
|
137
|
-
durationMs: new Float32Array(n),
|
|
138
|
-
};
|
|
95
|
+
this.transTweenState = this.createTweenState(this.skeleton.bones.length, 3, 3);
|
|
139
96
|
}
|
|
140
97
|
initializeMorphTweenBuffers() {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
98
|
+
this.morphTweenState = this.createTweenState(this.morphing.morphs.length, 1, 1);
|
|
99
|
+
}
|
|
100
|
+
createTweenState(count, startSize, targetSize) {
|
|
101
|
+
return {
|
|
102
|
+
active: new Uint8Array(count),
|
|
103
|
+
startQuat: new Float32Array(count * startSize),
|
|
104
|
+
targetQuat: new Float32Array(count * targetSize),
|
|
105
|
+
startTimeMs: new Float32Array(count),
|
|
106
|
+
durationMs: new Float32Array(count),
|
|
148
107
|
};
|
|
149
108
|
}
|
|
150
109
|
initializeRuntimeMorph() {
|
|
@@ -223,42 +182,30 @@ export class Model {
|
|
|
223
182
|
}
|
|
224
183
|
return hasActiveTweens;
|
|
225
184
|
}
|
|
226
|
-
// Get interleaved vertex data for GPU upload
|
|
227
|
-
// Format: [x,y,z, nx,ny,nz, u,v, x,y,z, nx,ny,nz, u,v, ...]
|
|
228
185
|
getVertices() {
|
|
229
186
|
return this.vertexData;
|
|
230
187
|
}
|
|
231
|
-
// Get texture information
|
|
232
188
|
getTextures() {
|
|
233
189
|
return this.textures;
|
|
234
190
|
}
|
|
235
|
-
// Get material information
|
|
236
191
|
getMaterials() {
|
|
237
192
|
return this.materials;
|
|
238
193
|
}
|
|
239
|
-
// Get vertex count
|
|
240
|
-
getVertexCount() {
|
|
241
|
-
return this.vertexCount;
|
|
242
|
-
}
|
|
243
|
-
// Get index data for GPU upload
|
|
244
194
|
getIndices() {
|
|
245
195
|
return this.indexData;
|
|
246
196
|
}
|
|
247
|
-
// Accessors for skeleton/skinning
|
|
248
197
|
getSkeleton() {
|
|
249
198
|
return this.skeleton;
|
|
250
199
|
}
|
|
251
200
|
getSkinning() {
|
|
252
201
|
return this.skinning;
|
|
253
202
|
}
|
|
254
|
-
// Accessors for physics data
|
|
255
203
|
getRigidbodies() {
|
|
256
204
|
return this.rigidbodies;
|
|
257
205
|
}
|
|
258
206
|
getJoints() {
|
|
259
207
|
return this.joints;
|
|
260
208
|
}
|
|
261
|
-
// Accessors for morphing
|
|
262
209
|
getMorphing() {
|
|
263
210
|
return this.morphing;
|
|
264
211
|
}
|
|
@@ -266,9 +213,6 @@ export class Model {
|
|
|
266
213
|
return this.runtimeMorph.weights;
|
|
267
214
|
}
|
|
268
215
|
// ------- Bone helpers (public API) -------
|
|
269
|
-
getBoneNames() {
|
|
270
|
-
return this.skeleton.bones.map((b) => b.name);
|
|
271
|
-
}
|
|
272
216
|
rotateBones(names, quats, durationMs) {
|
|
273
217
|
const state = this.rotTweenState;
|
|
274
218
|
const normalized = quats.map((q) => q.normalize());
|
|
@@ -302,14 +246,10 @@ export class Model {
|
|
|
302
246
|
const startQuat = new Quat(state.startQuat[qi], state.startQuat[qi + 1], state.startQuat[qi + 2], state.startQuat[qi + 3]);
|
|
303
247
|
const targetQuat = new Quat(state.targetQuat[qi], state.targetQuat[qi + 1], state.targetQuat[qi + 2], state.targetQuat[qi + 3]);
|
|
304
248
|
const result = Quat.slerp(startQuat, targetQuat, e);
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
sx = cx;
|
|
310
|
-
sy = cy;
|
|
311
|
-
sz = cz;
|
|
312
|
-
sw = cw;
|
|
249
|
+
sx = result.x;
|
|
250
|
+
sy = result.y;
|
|
251
|
+
sz = result.z;
|
|
252
|
+
sw = result.w;
|
|
313
253
|
}
|
|
314
254
|
state.startQuat[qi] = sx;
|
|
315
255
|
state.startQuat[qi + 1] = sy;
|
|
@@ -415,9 +355,6 @@ export class Model {
|
|
|
415
355
|
getBoneInverseBindMatrices() {
|
|
416
356
|
return this.skeleton.inverseBindMatrices;
|
|
417
357
|
}
|
|
418
|
-
getMorphNames() {
|
|
419
|
-
return this.morphing.morphs.map((m) => m.name);
|
|
420
|
-
}
|
|
421
358
|
setMorphWeight(name, weight, durationMs) {
|
|
422
359
|
const idx = this.runtimeMorph.nameIndex[name] ?? -1;
|
|
423
360
|
if (idx < 0 || idx >= this.runtimeMorph.weights.length)
|
|
@@ -434,9 +371,8 @@ export class Model {
|
|
|
434
371
|
// Animated change
|
|
435
372
|
const state = this.morphTweenState;
|
|
436
373
|
const now = performance.now();
|
|
437
|
-
const currentWeight = this.runtimeMorph.weights[idx];
|
|
438
374
|
// If already tweening, start from current interpolated value
|
|
439
|
-
let startWeight =
|
|
375
|
+
let startWeight = this.runtimeMorph.weights[idx];
|
|
440
376
|
if (state.active[idx] === 1) {
|
|
441
377
|
const startMs = state.startTimeMs[idx];
|
|
442
378
|
const prevDur = Math.max(1, state.durationMs[idx]);
|
|
@@ -517,11 +453,11 @@ export class Model {
|
|
|
517
453
|
if (hasActiveMorphTweens) {
|
|
518
454
|
this.applyMorphs();
|
|
519
455
|
}
|
|
520
|
-
// Compute initial world matrices (needed for IK solving)
|
|
456
|
+
// Compute initial world matrices (needed for IK solving to read bone positions)
|
|
521
457
|
this.computeWorldMatrices();
|
|
522
|
-
// Solve IK chains (modifies localRotations)
|
|
458
|
+
// Solve IK chains (modifies localRotations with final IK rotations)
|
|
523
459
|
this.solveIKChains();
|
|
524
|
-
// Recompute world matrices with IK rotations applied
|
|
460
|
+
// Recompute world matrices with final IK rotations applied to localRotations
|
|
525
461
|
this.computeWorldMatrices();
|
|
526
462
|
return hasActiveMorphTweens;
|
|
527
463
|
}
|
|
@@ -532,18 +468,18 @@ export class Model {
|
|
|
532
468
|
const ikChainInfo = this.runtimeSkeleton.ikChainInfo;
|
|
533
469
|
if (!ikChainInfo)
|
|
534
470
|
return;
|
|
535
|
-
IKSolverSystem.solve(ikSolvers, this.skeleton.bones, this.runtimeSkeleton.localRotations, this.runtimeSkeleton.localTranslations, this.runtimeSkeleton.worldMatrices, ikChainInfo
|
|
536
|
-
);
|
|
471
|
+
IKSolverSystem.solve(ikSolvers, this.skeleton.bones, this.runtimeSkeleton.localRotations, this.runtimeSkeleton.localTranslations, this.runtimeSkeleton.worldMatrices, ikChainInfo);
|
|
537
472
|
}
|
|
538
473
|
computeWorldMatrices() {
|
|
539
474
|
const bones = this.skeleton.bones;
|
|
540
475
|
const localRot = this.runtimeSkeleton.localRotations;
|
|
541
476
|
const localTrans = this.runtimeSkeleton.localTranslations;
|
|
542
477
|
const worldBuf = this.runtimeSkeleton.worldMatrices;
|
|
543
|
-
const computed = this.runtimeSkeleton.computedBones.fill(false);
|
|
544
478
|
const boneCount = bones.length;
|
|
545
479
|
if (boneCount === 0)
|
|
546
480
|
return;
|
|
481
|
+
// Local computed array (avoids instance field overhead)
|
|
482
|
+
const computed = new Array(boneCount).fill(false);
|
|
547
483
|
const computeWorld = (i) => {
|
|
548
484
|
if (computed[i])
|
|
549
485
|
return;
|
|
@@ -574,14 +510,9 @@ export class Model {
|
|
|
574
510
|
ay = -ay;
|
|
575
511
|
az = -az;
|
|
576
512
|
}
|
|
577
|
-
const identityQuat = new Quat(0, 0, 0, 1);
|
|
578
513
|
const appendQuat = new Quat(ax, ay, az, aw);
|
|
579
|
-
const result = Quat.slerp(
|
|
580
|
-
|
|
581
|
-
const ry = result.y;
|
|
582
|
-
const rz = result.z;
|
|
583
|
-
const rw = result.w;
|
|
584
|
-
rotateM = Mat4.fromQuat(rx, ry, rz, rw).multiply(rotateM);
|
|
514
|
+
const result = Quat.slerp(new Quat(0, 0, 0, 1), appendQuat, absRatio);
|
|
515
|
+
rotateM = Mat4.fromQuat(result.x, result.y, result.z, result.w).multiply(rotateM);
|
|
585
516
|
}
|
|
586
517
|
if (b.appendMove) {
|
|
587
518
|
const appendRatio = b.appendRatio ?? 1;
|
package/dist/player.d.ts
CHANGED
|
@@ -13,13 +13,11 @@ export declare class Player {
|
|
|
13
13
|
private frames;
|
|
14
14
|
private boneTracks;
|
|
15
15
|
private morphTracks;
|
|
16
|
-
private
|
|
16
|
+
private _duration;
|
|
17
17
|
private isPlaying;
|
|
18
18
|
private isPaused;
|
|
19
|
-
private
|
|
19
|
+
private _currentTime;
|
|
20
20
|
private startTime;
|
|
21
|
-
private pausedTime;
|
|
22
|
-
private pauseStartTime;
|
|
23
21
|
/**
|
|
24
22
|
* Load VMD animation file
|
|
25
23
|
*/
|
|
@@ -58,21 +56,9 @@ export declare class Player {
|
|
|
58
56
|
* Get current playback progress
|
|
59
57
|
*/
|
|
60
58
|
getProgress(): AnimationProgress;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Get animation duration
|
|
67
|
-
*/
|
|
68
|
-
getDuration(): number;
|
|
69
|
-
/**
|
|
70
|
-
* Check if playing
|
|
71
|
-
*/
|
|
72
|
-
isPlayingState(): boolean;
|
|
73
|
-
/**
|
|
74
|
-
* Check if paused
|
|
75
|
-
*/
|
|
76
|
-
isPausedState(): boolean;
|
|
59
|
+
get currentTime(): number;
|
|
60
|
+
get duration(): number;
|
|
61
|
+
get isPlayingState(): boolean;
|
|
62
|
+
get isPausedState(): boolean;
|
|
77
63
|
}
|
|
78
64
|
//# sourceMappingURL=player.d.ts.map
|
package/dist/player.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../src/player.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../src/player.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAqB,MAAM,QAAQ,CAAA;AAGtD,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAChC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IACnC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,qBAAa,MAAM;IAEjB,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,UAA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