reze-engine 0.8.0 → 0.8.1
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/engine.d.ts +24 -32
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +374 -486
- package/dist/model.d.ts +9 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +20 -24
- package/package.json +1 -1
- package/src/engine.ts +393 -592
- package/src/model.ts +28 -28
package/src/model.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Mat4, Quat, Vec3 } from "./math"
|
|
2
2
|
import { Engine } from "./engine"
|
|
3
3
|
import { PmxLoader } from "./pmx-loader"
|
|
4
|
-
import { Rigidbody, Joint
|
|
4
|
+
import { Rigidbody, Joint } from "./physics"
|
|
5
5
|
import { IKSolverSystem } from "./ik-solver"
|
|
6
6
|
import { VMDLoader } from "./vmd-loader"
|
|
7
7
|
import { BoneInterpolation, interpolateControlPoints, rawInterpolationToBoneInterpolation } from "./animation"
|
|
@@ -150,13 +150,28 @@ interface TweenState {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
export class Model {
|
|
153
|
-
|
|
154
|
-
static
|
|
153
|
+
private static _nextId = 0
|
|
154
|
+
private static nextDefaultName(): string {
|
|
155
|
+
return "model_" + Model._nextId++
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
static async loadPmx(path: string, name?: string): Promise<Model> {
|
|
155
159
|
const model = await PmxLoader.load(path)
|
|
160
|
+
model.setName(name ?? Model.nextDefaultName())
|
|
156
161
|
await Engine.getInstance().registerModel(model, path)
|
|
157
162
|
return model
|
|
158
163
|
}
|
|
159
164
|
|
|
165
|
+
private _name: string = ""
|
|
166
|
+
|
|
167
|
+
get name(): string {
|
|
168
|
+
return this._name
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
setName(value: string): void {
|
|
172
|
+
this._name = value
|
|
173
|
+
}
|
|
174
|
+
|
|
160
175
|
private vertexData: Float32Array<ArrayBuffer>
|
|
161
176
|
private baseVertexData: Float32Array<ArrayBuffer> // Original vertex data before morphing
|
|
162
177
|
private vertexCount: number
|
|
@@ -204,9 +219,6 @@ export class Model {
|
|
|
204
219
|
private boneTrackIndices: Map<string, number> = new Map()
|
|
205
220
|
private morphTrackIndices: Map<string, number> = new Map()
|
|
206
221
|
|
|
207
|
-
// Physics runtime
|
|
208
|
-
private physics: Physics | null = null
|
|
209
|
-
|
|
210
222
|
// IK and Physics enable flags
|
|
211
223
|
private ikEnabled = true
|
|
212
224
|
private physicsEnabled = true
|
|
@@ -243,11 +255,6 @@ export class Model {
|
|
|
243
255
|
this.initializeRuntimeMorph()
|
|
244
256
|
this.initializeTweenBuffers()
|
|
245
257
|
this.applyMorphs()
|
|
246
|
-
|
|
247
|
-
// Initialize physics if rigidbodies exist
|
|
248
|
-
if (rigidbodies.length > 0) {
|
|
249
|
-
this.physics = new Physics(rigidbodies, joints)
|
|
250
|
-
}
|
|
251
258
|
}
|
|
252
259
|
|
|
253
260
|
private initializeRuntimeSkeleton(): void {
|
|
@@ -656,6 +663,10 @@ export class Model {
|
|
|
656
663
|
return localTranslation
|
|
657
664
|
}
|
|
658
665
|
|
|
666
|
+
getWorldMatrices(): Mat4[] {
|
|
667
|
+
return this.runtimeSkeleton.worldMatrices
|
|
668
|
+
}
|
|
669
|
+
|
|
659
670
|
getBoneWorldMatrices(): Float32Array {
|
|
660
671
|
// Convert Mat4[] to Float32Array for WebGPU compatibility
|
|
661
672
|
const boneCount = this.skeleton.bones.length
|
|
@@ -707,7 +718,7 @@ export class Model {
|
|
|
707
718
|
this.tweenState.morphActive[idx] = 0
|
|
708
719
|
this.applyMorphs()
|
|
709
720
|
try {
|
|
710
|
-
Engine.getInstance().markVertexBufferDirty()
|
|
721
|
+
Engine.getInstance().markVertexBufferDirty(this)
|
|
711
722
|
} catch {
|
|
712
723
|
/* not registered yet */
|
|
713
724
|
}
|
|
@@ -882,10 +893,6 @@ export class Model {
|
|
|
882
893
|
this.animationTime = 0
|
|
883
894
|
this.getPoseAtTime(0)
|
|
884
895
|
|
|
885
|
-
if (this.physics) {
|
|
886
|
-
this.computeWorldMatrices()
|
|
887
|
-
this.physics.reset(this.runtimeSkeleton.worldMatrices, this.skeleton.inverseBindMatrices)
|
|
888
|
-
}
|
|
889
896
|
}
|
|
890
897
|
|
|
891
898
|
public resetAllBones(): void {
|
|
@@ -898,9 +905,6 @@ export class Model {
|
|
|
898
905
|
localTrans.set(Vec3.zeros())
|
|
899
906
|
}
|
|
900
907
|
this.computeWorldMatrices()
|
|
901
|
-
if (this.physics) {
|
|
902
|
-
this.physics.reset(this.runtimeSkeleton.worldMatrices, this.skeleton.inverseBindMatrices)
|
|
903
|
-
}
|
|
904
908
|
}
|
|
905
909
|
|
|
906
910
|
public resetAllMorphs(): void {
|
|
@@ -920,16 +924,16 @@ export class Model {
|
|
|
920
924
|
this.physicsEnabled = enabled
|
|
921
925
|
}
|
|
922
926
|
|
|
927
|
+
public getPhysicsEnabled(): boolean {
|
|
928
|
+
return this.physicsEnabled
|
|
929
|
+
}
|
|
930
|
+
|
|
923
931
|
playAnimation(): void {
|
|
924
932
|
if (!this._hasAnimation) return
|
|
925
933
|
|
|
926
934
|
this.isPaused = false
|
|
927
935
|
this.isPlaying = true
|
|
928
936
|
|
|
929
|
-
if (this.physics && this.animationTime === 0) {
|
|
930
|
-
this.computeWorldMatrices()
|
|
931
|
-
this.physics.reset(this.runtimeSkeleton.worldMatrices, this.skeleton.inverseBindMatrices)
|
|
932
|
-
}
|
|
933
937
|
}
|
|
934
938
|
|
|
935
939
|
pauseAnimation(): void {
|
|
@@ -1114,10 +1118,6 @@ export class Model {
|
|
|
1114
1118
|
this.computeWorldMatrices()
|
|
1115
1119
|
}
|
|
1116
1120
|
|
|
1117
|
-
if (this.physicsEnabled && this.physics) {
|
|
1118
|
-
this.physics.step(deltaTime, this.runtimeSkeleton.worldMatrices, this.skeleton.inverseBindMatrices)
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
1121
|
return verticesChanged
|
|
1122
1122
|
}
|
|
1123
1123
|
|
|
@@ -1260,7 +1260,7 @@ export class Model {
|
|
|
1260
1260
|
}
|
|
1261
1261
|
}
|
|
1262
1262
|
|
|
1263
|
-
|
|
1263
|
+
public computeWorldMatrices(): void {
|
|
1264
1264
|
const bones = this.skeleton.bones
|
|
1265
1265
|
const localRot = this.runtimeSkeleton.localRotations
|
|
1266
1266
|
const localTrans = this.runtimeSkeleton.localTranslations
|