reze-engine 0.68.28 → 0.68.29
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/_dbg-loader.mjs +1100 -0
- package/dist/animation.d.ts +9 -0
- package/dist/animation.d.ts.map +1 -1
- package/dist/animation.js +2 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +17 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/model.d.ts +14 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +35 -2
- package/dist/vmd-writer.d.ts.map +1 -1
- package/dist/vmd-writer.js +17 -1
- package/package.json +1 -1
- package/src/animation.ts +12 -0
- package/src/engine.ts +17 -16
- package/src/index.ts +1 -0
- package/src/model.ts +35 -2
- package/src/vmd-writer.ts +12 -1
package/dist/model.js
CHANGED
|
@@ -70,11 +70,22 @@ export class Model {
|
|
|
70
70
|
get scale() {
|
|
71
71
|
return this._scale;
|
|
72
72
|
}
|
|
73
|
-
/** Whether
|
|
74
|
-
*
|
|
73
|
+
/** Whether the HOST shows this model — what setVisible last said. A playing
|
|
74
|
+
* motion can hide her on top of this (see `drawn`), and never writes here,
|
|
75
|
+
* so the host's own switch reads back exactly as it set it. */
|
|
75
76
|
get visible() {
|
|
76
77
|
return this._visible;
|
|
77
78
|
}
|
|
79
|
+
/** Whether this model renders this frame: the host shows her and the motion
|
|
80
|
+
* has not hidden her. Hidden models skip the main, shadow and pick passes;
|
|
81
|
+
* physics keeps running so they resume consistently. */
|
|
82
|
+
get drawn() {
|
|
83
|
+
return this._visible && !this.motionHidden;
|
|
84
|
+
}
|
|
85
|
+
/** Whether the playing motion has her hidden right now (VMD's 表示 flag). */
|
|
86
|
+
get hiddenByMotion() {
|
|
87
|
+
return this.motionHidden;
|
|
88
|
+
}
|
|
78
89
|
setPosition(position) {
|
|
79
90
|
this._position.set(position);
|
|
80
91
|
this.rootMatrixDirty = true;
|
|
@@ -168,6 +179,8 @@ export class Model {
|
|
|
168
179
|
this._rotation = Quat.identity();
|
|
169
180
|
this._scale = 1;
|
|
170
181
|
this._visible = true;
|
|
182
|
+
/** The playing clip's display flag at the current frame — see `drawn`. */
|
|
183
|
+
this.motionHidden = false;
|
|
171
184
|
this.rootMatrixValues = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
172
185
|
this.rootMatrixDirty = false;
|
|
173
186
|
this.rootIsIdentity = true;
|
|
@@ -1630,6 +1643,11 @@ export class Model {
|
|
|
1630
1643
|
for (const track of ikTracks.values())
|
|
1631
1644
|
track.sort((a, b) => a.frame - b.frame);
|
|
1632
1645
|
clip.ikTracks = ikTracks;
|
|
1646
|
+
// The same records carry the model's 表示 flag. Kept only when some
|
|
1647
|
+
// record hides her: a motion that never does plays exactly as before.
|
|
1648
|
+
if (ikFrames.some((r) => !r.visible)) {
|
|
1649
|
+
clip.visibility = ikFrames.map((r) => ({ frame: r.frame, visible: r.visible }));
|
|
1650
|
+
}
|
|
1633
1651
|
}
|
|
1634
1652
|
this.animationState.loadAnimation(name, clip);
|
|
1635
1653
|
});
|
|
@@ -1893,6 +1911,8 @@ export class Model {
|
|
|
1893
1911
|
this.crossfade = null;
|
|
1894
1912
|
this.oneShot = null;
|
|
1895
1913
|
this.animationState.clear();
|
|
1914
|
+
// No clip, no motion to hide her: a cleared clip must not leave her gone.
|
|
1915
|
+
this.motionHidden = false;
|
|
1896
1916
|
}
|
|
1897
1917
|
// Seek by absolute timeline seconds, not frame index.
|
|
1898
1918
|
seek(seconds) {
|
|
@@ -1939,6 +1959,7 @@ export class Model {
|
|
|
1939
1959
|
/** Step the IK state to `frame`. VMD IK keys are steps: a state holds until
|
|
1940
1960
|
* the next one changes it, so this is a lookup, not an interpolation. */
|
|
1941
1961
|
applyIkFromClip(clip, frame) {
|
|
1962
|
+
this.applyVisibilityFromClip(clip, frame);
|
|
1942
1963
|
if (!clip.ikTracks || clip.ikTracks.size === 0) {
|
|
1943
1964
|
if (this.ikDisabled.size > 0)
|
|
1944
1965
|
this.ikDisabled.clear();
|
|
@@ -1956,6 +1977,16 @@ export class Model {
|
|
|
1956
1977
|
this.ikDisabled.add(index);
|
|
1957
1978
|
}
|
|
1958
1979
|
}
|
|
1980
|
+
/** Step the motion's display flag to `frame`. Before its first key she is
|
|
1981
|
+
* shown — MMD's own reading of a motion that starts hidden later. */
|
|
1982
|
+
applyVisibilityFromClip(clip, frame) {
|
|
1983
|
+
const keys = clip.visibility;
|
|
1984
|
+
let shown = true;
|
|
1985
|
+
if (keys)
|
|
1986
|
+
for (let i = 0; i < keys.length && keys[i].frame <= frame; i++)
|
|
1987
|
+
shown = keys[i].visible;
|
|
1988
|
+
this.motionHidden = !shown;
|
|
1989
|
+
}
|
|
1959
1990
|
/** Sample one bone track at `frame` into outRot + outVmdTrans. The translation is
|
|
1960
1991
|
* VMD-space (bind-relative), NOT yet converted to bone-local — callers convert with
|
|
1961
1992
|
* convertVMDTranslationToLocal once they know the final rotation. The cursor cache
|
|
@@ -2429,6 +2460,8 @@ export class Model {
|
|
|
2429
2460
|
}
|
|
2430
2461
|
else {
|
|
2431
2462
|
const clip = this.animationState.getCurrentClip();
|
|
2463
|
+
if (clip === null)
|
|
2464
|
+
this.motionHidden = false;
|
|
2432
2465
|
if (clip !== null) {
|
|
2433
2466
|
this.applyPoseFromClip(clip, this.animationState.getCurrentFrame());
|
|
2434
2467
|
if (evWatch !== null && evWatch === this.animationState.getCurrentAnimation()) {
|
package/dist/vmd-writer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vmd-writer.d.ts","sourceRoot":"","sources":["../src/vmd-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAmC,MAAM,aAAa,CAAA;AAC5E,OAAO,EAAgC,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAsDhF;;;;;;;;8CAQ8C;AAC9C,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAE3D,qBAAa,SAAS;IACpB,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,iBAAiB,CAAA;KAAE,GAAG,WAAW;
|
|
1
|
+
{"version":3,"file":"vmd-writer.d.ts","sourceRoot":"","sources":["../src/vmd-writer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAmC,MAAM,aAAa,CAAA;AAC5E,OAAO,EAAgC,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAsDhF;;;;;;;;8CAQ8C;AAC9C,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAE3D,qBAAa,SAAS;IACpB,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,iBAAiB,CAAA;KAAE,GAAG,WAAW;IAqJjF;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,WAAW;CAiDnD"}
|
package/dist/vmd-writer.js
CHANGED
|
@@ -82,6 +82,22 @@ export class VMDWriter {
|
|
|
82
82
|
ikByFrame.set(key.frame, [{ boneName, enabled: key.enabled }]);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
// The model's display flag rides in the same records. A moment it changes
|
|
86
|
+
// with no IK switch beside it still needs a record of its own, and every
|
|
87
|
+
// record states the flag as it stands then — one written as "shown" would
|
|
88
|
+
// bring her back mid-hide on the way in.
|
|
89
|
+
const visibility = wantBones ? clip.visibility : undefined;
|
|
90
|
+
if (visibility)
|
|
91
|
+
for (const key of visibility)
|
|
92
|
+
if (!ikByFrame.has(key.frame))
|
|
93
|
+
ikByFrame.set(key.frame, []);
|
|
94
|
+
const shownAt = (frame) => {
|
|
95
|
+
let shown = true;
|
|
96
|
+
if (visibility)
|
|
97
|
+
for (let i = 0; i < visibility.length && visibility[i].frame <= frame; i++)
|
|
98
|
+
shown = visibility[i].visible;
|
|
99
|
+
return shown;
|
|
100
|
+
};
|
|
85
101
|
const ikFrames = [...ikByFrame.entries()].sort((a, b) => a[0] - b[0]);
|
|
86
102
|
let ikSize = 0;
|
|
87
103
|
for (const [, states] of ikFrames)
|
|
@@ -168,7 +184,7 @@ export class VMDWriter {
|
|
|
168
184
|
for (const [frame, states] of ikFrames) {
|
|
169
185
|
view.setUint32(offset, frame, true);
|
|
170
186
|
offset += 4;
|
|
171
|
-
view.setUint8(offset, 1); // model visible
|
|
187
|
+
view.setUint8(offset, shownAt(frame) ? 1 : 0); // model visible
|
|
172
188
|
offset += 1;
|
|
173
189
|
view.setUint32(offset, states.length, true);
|
|
174
190
|
offset += 4;
|
package/package.json
CHANGED
package/src/animation.ts
CHANGED
|
@@ -39,9 +39,19 @@ export interface AnimationClip {
|
|
|
39
39
|
/** Per-chain IK state over time. Absent means "leave IK as the host set it" —
|
|
40
40
|
* which is what every clip built before this existed will do. */
|
|
41
41
|
ikTracks?: Map<string, IkKeyframe[]>
|
|
42
|
+
/** When the motion shows and hides the model — the 表示 flag of VMD's
|
|
43
|
+
* IK/display block, which motions use to make a character vanish for a
|
|
44
|
+
* stretch. Steps, like IK. Absent means the motion never hides her. */
|
|
45
|
+
visibility?: VisibilityKeyframe[]
|
|
42
46
|
frameCount: number // last keyframe frame index
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
/** One moment a motion shows or hides its model. Holds until the next one. */
|
|
50
|
+
export interface VisibilityKeyframe {
|
|
51
|
+
frame: number
|
|
52
|
+
visible: boolean
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
export interface AnimationPlayOptions {
|
|
46
56
|
priority?: number // Higher number = higher priority. Default: 0.
|
|
47
57
|
loop?: boolean // When true, timeline wraps at end. Default: false.
|
|
@@ -114,6 +124,7 @@ export class AnimationState {
|
|
|
114
124
|
boneTracks: clip.boneTracks,
|
|
115
125
|
morphTracks: clip.morphTracks,
|
|
116
126
|
ikTracks: clip.ikTracks,
|
|
127
|
+
visibility: clip.visibility,
|
|
117
128
|
frameCount: clip.frameCount,
|
|
118
129
|
})
|
|
119
130
|
}
|
|
@@ -139,6 +150,7 @@ export class AnimationState {
|
|
|
139
150
|
boneTracks: clip?.boneTracks ?? new Map(),
|
|
140
151
|
morphTracks,
|
|
141
152
|
ikTracks: clip?.ikTracks,
|
|
153
|
+
visibility: clip?.visibility,
|
|
142
154
|
frameCount: Math.max(clip?.frameCount ?? 0, frameCount),
|
|
143
155
|
})
|
|
144
156
|
}
|
package/src/engine.ts
CHANGED
|
@@ -4964,7 +4964,7 @@ export class Engine {
|
|
|
4964
4964
|
private writeCastSeedProps(): void {
|
|
4965
4965
|
let n = 0
|
|
4966
4966
|
this.forEachInstance((inst) => {
|
|
4967
|
-
if (inst.isProp && inst.model.
|
|
4967
|
+
if (inst.isProp && inst.model.drawn) n++
|
|
4968
4968
|
})
|
|
4969
4969
|
let data = this.castSeedPropData
|
|
4970
4970
|
let changed = data[0] !== n
|
|
@@ -4985,7 +4985,7 @@ export class Engine {
|
|
|
4985
4985
|
data[0] = n
|
|
4986
4986
|
let i = 1
|
|
4987
4987
|
this.forEachInstance((inst) => {
|
|
4988
|
-
if (!inst.isProp || !inst.model.
|
|
4988
|
+
if (!inst.isProp || !inst.model.drawn) return
|
|
4989
4989
|
if (data[i] !== inst.objectId) changed = true
|
|
4990
4990
|
data[i++] = inst.objectId
|
|
4991
4991
|
})
|
|
@@ -6761,7 +6761,7 @@ export class Engine {
|
|
|
6761
6761
|
let n = 0
|
|
6762
6762
|
for (const inst of this.modelInstances.values()) {
|
|
6763
6763
|
const m = inst.model
|
|
6764
|
-
if (!m.
|
|
6764
|
+
if (!m.drawn) continue
|
|
6765
6765
|
let byPrefix = this.pointBones.get(m)
|
|
6766
6766
|
if (!byPrefix) this.pointBones.set(m, (byPrefix = new Map()))
|
|
6767
6767
|
let bones = byPrefix.get(points.prefix)
|
|
@@ -7720,7 +7720,7 @@ export class Engine {
|
|
|
7720
7720
|
for (const inst of this.modelInstances.values()) {
|
|
7721
7721
|
// Neither a stage nor a plane is a performer, so neither is a subject an
|
|
7722
7722
|
// effect can follow.
|
|
7723
|
-
if (!inst.model.
|
|
7723
|
+
if (!inst.model.drawn || inst.isStage || inst.isPlane || inst.isProp) continue
|
|
7724
7724
|
const model = inst.model
|
|
7725
7725
|
const matrices = model.getWorldMatrices()
|
|
7726
7726
|
if (matrices.length === 0) continue
|
|
@@ -11177,7 +11177,7 @@ export class Engine {
|
|
|
11177
11177
|
const p = new Vec3(0, 0, 0)
|
|
11178
11178
|
let any = false
|
|
11179
11179
|
for (const inst of this.modelInstances.values()) {
|
|
11180
|
-
if (!inst.isStage || !inst.model.
|
|
11180
|
+
if (!inst.isStage || !inst.model.drawn) continue
|
|
11181
11181
|
const m = inst.model
|
|
11182
11182
|
for (const draw of inst.drawCalls) {
|
|
11183
11183
|
const b = draw.bounds
|
|
@@ -11417,12 +11417,12 @@ export class Engine {
|
|
|
11417
11417
|
})
|
|
11418
11418
|
pass.setStencilReference(Engine.STENCIL_EYE_VALUE)
|
|
11419
11419
|
for (const inst of this.modelInstances.values()) {
|
|
11420
|
-
if (!inst.isStage || !inst.model.
|
|
11420
|
+
if (!inst.isStage || !inst.model.drawn) continue
|
|
11421
11421
|
this.setModelDrawState(pass, inst)
|
|
11422
11422
|
this.drawMaterials(pass, inst, "opaque", view)
|
|
11423
11423
|
}
|
|
11424
11424
|
for (const inst of this.modelInstances.values()) {
|
|
11425
|
-
if (!inst.isStage || !inst.model.
|
|
11425
|
+
if (!inst.isStage || !inst.model.drawn) continue
|
|
11426
11426
|
this.setModelDrawState(pass, inst)
|
|
11427
11427
|
this.drawMaterials(pass, inst, "transparent", view)
|
|
11428
11428
|
}
|
|
@@ -11773,7 +11773,7 @@ export class Engine {
|
|
|
11773
11773
|
if (opts && stage) {
|
|
11774
11774
|
let minX = Infinity, minY = Infinity, minZ = Infinity, maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity
|
|
11775
11775
|
for (const inst of this.modelInstances.values()) {
|
|
11776
|
-
if (inst.isStage || inst.isPlane || inst.isProp || !inst.model.
|
|
11776
|
+
if (inst.isStage || inst.isPlane || inst.isProp || !inst.model.drawn) continue
|
|
11777
11777
|
const s = this.castSphereScratch
|
|
11778
11778
|
this.writeCullSphere(inst, s, 0)
|
|
11779
11779
|
if (!(s[3] < 1e6)) continue
|
|
@@ -14583,7 +14583,7 @@ export class Engine {
|
|
|
14583
14583
|
for (let i = 0; i < this.cullModels.length; i++) {
|
|
14584
14584
|
const inst = this.cullModels[i]
|
|
14585
14585
|
const o = i * Engine.CULL_MODEL_FLOATS
|
|
14586
|
-
let f = inst.model.
|
|
14586
|
+
let f = inst.model.drawn ? Engine.CULL_MODEL_VISIBLE : 0
|
|
14587
14587
|
if (inst.rigid) {
|
|
14588
14588
|
data.set(inst.rigidXform, o)
|
|
14589
14589
|
f |= Engine.CULL_MODEL_RIGID
|
|
@@ -14702,7 +14702,7 @@ export class Engine {
|
|
|
14702
14702
|
out.fill(0)
|
|
14703
14703
|
for (let i = 0; i < this.cullModels.length; i++) {
|
|
14704
14704
|
const inst = this.cullModels[i]
|
|
14705
|
-
if (!inst.model.
|
|
14705
|
+
if (!inst.model.drawn || inst.shadowDrawCalls.length === 0) continue
|
|
14706
14706
|
if (inst.rigid) {
|
|
14707
14707
|
// No sphere to read. Bail out of the whole optimisation.
|
|
14708
14708
|
out[3] = -1
|
|
@@ -14722,7 +14722,7 @@ export class Engine {
|
|
|
14722
14722
|
heads.fill(0)
|
|
14723
14723
|
for (let i = 0; i < this.cullModels.length; i++) {
|
|
14724
14724
|
const inst = this.cullModels[i]
|
|
14725
|
-
if (!inst.model.
|
|
14725
|
+
if (!inst.model.drawn || inst.rigid || inst.isStage || inst.isPlane || inst.isProp || inst.shadowDrawCalls.length === 0) continue
|
|
14726
14726
|
const o = i * Engine.CULL_MODEL_FLOATS + 16
|
|
14727
14727
|
growSphere(out, data[o], data[o + 1], data[o + 2], data[o + 3])
|
|
14728
14728
|
const m = inst.model
|
|
@@ -15293,7 +15293,7 @@ export class Engine {
|
|
|
15293
15293
|
report.models.push({
|
|
15294
15294
|
name: inst.name,
|
|
15295
15295
|
rigid: inst.rigid,
|
|
15296
|
-
visible: inst.model.
|
|
15296
|
+
visible: inst.model.drawn,
|
|
15297
15297
|
draws: inst.drawCalls.length,
|
|
15298
15298
|
cameraVisible: 0,
|
|
15299
15299
|
shadowVisible: 0,
|
|
@@ -17685,7 +17685,7 @@ export class Engine {
|
|
|
17685
17685
|
pass.setBindGroup(0, this.pickPerFrameBindGroup)
|
|
17686
17686
|
|
|
17687
17687
|
this.forEachInstance((inst) => {
|
|
17688
|
-
if (!inst.model.
|
|
17688
|
+
if (!inst.model.drawn) return // hidden models aren't pickable
|
|
17689
17689
|
pass.setVertexBuffer(0, inst.vertexBuffer)
|
|
17690
17690
|
pass.setVertexBuffer(1, inst.jointsBuffer)
|
|
17691
17691
|
pass.setVertexBuffer(2, inst.weightsBuffer)
|
|
@@ -18583,7 +18583,7 @@ export class Engine {
|
|
|
18583
18583
|
const names: string[] = []
|
|
18584
18584
|
let n = 0
|
|
18585
18585
|
this.forEachInCastOrder((inst) => {
|
|
18586
|
-
if (n >= MAX_EFFECT_SUBJECTS || inst.isStage || inst.isPlane || inst.isProp || !inst.model.
|
|
18586
|
+
if (n >= MAX_EFFECT_SUBJECTS || inst.isStage || inst.isPlane || inst.isProp || !inst.model.drawn) return
|
|
18587
18587
|
n++
|
|
18588
18588
|
if (subjects && !subjects.includes(inst.name)) return
|
|
18589
18589
|
names.push(inst.name)
|
|
@@ -19846,7 +19846,7 @@ export class Engine {
|
|
|
19846
19846
|
let n = 0
|
|
19847
19847
|
this.castSlotOf.clear()
|
|
19848
19848
|
this.forEachInCastOrder((inst) => {
|
|
19849
|
-
if (n >= MAX_EFFECT_SUBJECTS || inst.isStage || inst.isPlane || inst.isProp || !inst.model.
|
|
19849
|
+
if (n >= MAX_EFFECT_SUBJECTS || inst.isStage || inst.isPlane || inst.isProp || !inst.model.drawn) return
|
|
19850
19850
|
const m = inst.model
|
|
19851
19851
|
// WHO IS IN WHICH SLOT, recorded here because here is where it is
|
|
19852
19852
|
// decided. An effect is aimed by model name, and a name only becomes a
|
|
@@ -20263,7 +20263,8 @@ export class Engine {
|
|
|
20263
20263
|
skinMatrixBuffer: inst.skinMatrixBuffer,
|
|
20264
20264
|
indexBuffer: inst.indexBuffer,
|
|
20265
20265
|
draws,
|
|
20266
|
-
hidden
|
|
20266
|
+
// A hidden model hides every material, whoever hid it (setVisible or the motion).
|
|
20267
|
+
hidden: (m) => !inst.model.drawn || inst.hiddenMaterials.has(m) || inst.morphHiddenMaterials.has(m),
|
|
20267
20268
|
headSkin: () => (head >= 0 ? inst.model.getSkinMatrices().subarray(head * 16, head * 16 + 16) : null),
|
|
20268
20269
|
headRest,
|
|
20269
20270
|
layers: new Uint32Array(inst.objectLight.buffer)[0],
|
package/src/index.ts
CHANGED
package/src/model.ts
CHANGED
|
@@ -337,12 +337,25 @@ export class Model {
|
|
|
337
337
|
return this._scale
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
-
/** Whether
|
|
341
|
-
*
|
|
340
|
+
/** Whether the HOST shows this model — what setVisible last said. A playing
|
|
341
|
+
* motion can hide her on top of this (see `drawn`), and never writes here,
|
|
342
|
+
* so the host's own switch reads back exactly as it set it. */
|
|
342
343
|
get visible(): boolean {
|
|
343
344
|
return this._visible
|
|
344
345
|
}
|
|
345
346
|
|
|
347
|
+
/** Whether this model renders this frame: the host shows her and the motion
|
|
348
|
+
* has not hidden her. Hidden models skip the main, shadow and pick passes;
|
|
349
|
+
* physics keeps running so they resume consistently. */
|
|
350
|
+
get drawn(): boolean {
|
|
351
|
+
return this._visible && !this.motionHidden
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** Whether the playing motion has her hidden right now (VMD's 表示 flag). */
|
|
355
|
+
get hiddenByMotion(): boolean {
|
|
356
|
+
return this.motionHidden
|
|
357
|
+
}
|
|
358
|
+
|
|
346
359
|
setPosition(position: Vec3): void {
|
|
347
360
|
this._position.set(position)
|
|
348
361
|
this.rootMatrixDirty = true
|
|
@@ -459,6 +472,8 @@ export class Model {
|
|
|
459
472
|
private _rotation: Quat = Quat.identity()
|
|
460
473
|
private _scale: number = 1
|
|
461
474
|
private _visible: boolean = true
|
|
475
|
+
/** The playing clip's display flag at the current frame — see `drawn`. */
|
|
476
|
+
private motionHidden = false
|
|
462
477
|
private rootMatrixValues: Float32Array = new Float32Array([1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1])
|
|
463
478
|
private rootMatrixDirty: boolean = false
|
|
464
479
|
private rootIsIdentity: boolean = true
|
|
@@ -2041,6 +2056,11 @@ export class Model {
|
|
|
2041
2056
|
}
|
|
2042
2057
|
for (const track of ikTracks.values()) track.sort((a, b) => a.frame - b.frame)
|
|
2043
2058
|
clip.ikTracks = ikTracks
|
|
2059
|
+
// The same records carry the model's 表示 flag. Kept only when some
|
|
2060
|
+
// record hides her: a motion that never does plays exactly as before.
|
|
2061
|
+
if (ikFrames.some((r) => !r.visible)) {
|
|
2062
|
+
clip.visibility = ikFrames.map((r) => ({ frame: r.frame, visible: r.visible }))
|
|
2063
|
+
}
|
|
2044
2064
|
}
|
|
2045
2065
|
this.animationState.loadAnimation(name, clip)
|
|
2046
2066
|
})
|
|
@@ -2317,6 +2337,8 @@ export class Model {
|
|
|
2317
2337
|
this.crossfade = null
|
|
2318
2338
|
this.oneShot = null
|
|
2319
2339
|
this.animationState.clear()
|
|
2340
|
+
// No clip, no motion to hide her: a cleared clip must not leave her gone.
|
|
2341
|
+
this.motionHidden = false
|
|
2320
2342
|
}
|
|
2321
2343
|
|
|
2322
2344
|
// Seek by absolute timeline seconds, not frame index.
|
|
@@ -2376,6 +2398,7 @@ export class Model {
|
|
|
2376
2398
|
/** Step the IK state to `frame`. VMD IK keys are steps: a state holds until
|
|
2377
2399
|
* the next one changes it, so this is a lookup, not an interpolation. */
|
|
2378
2400
|
private applyIkFromClip(clip: AnimationClip, frame: number): void {
|
|
2401
|
+
this.applyVisibilityFromClip(clip, frame)
|
|
2379
2402
|
if (!clip.ikTracks || clip.ikTracks.size === 0) {
|
|
2380
2403
|
if (this.ikDisabled.size > 0) this.ikDisabled.clear()
|
|
2381
2404
|
return
|
|
@@ -2390,6 +2413,15 @@ export class Model {
|
|
|
2390
2413
|
}
|
|
2391
2414
|
}
|
|
2392
2415
|
|
|
2416
|
+
/** Step the motion's display flag to `frame`. Before its first key she is
|
|
2417
|
+
* shown — MMD's own reading of a motion that starts hidden later. */
|
|
2418
|
+
private applyVisibilityFromClip(clip: AnimationClip, frame: number): void {
|
|
2419
|
+
const keys = clip.visibility
|
|
2420
|
+
let shown = true
|
|
2421
|
+
if (keys) for (let i = 0; i < keys.length && keys[i].frame <= frame; i++) shown = keys[i].visible
|
|
2422
|
+
this.motionHidden = !shown
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2393
2425
|
/** Sample one bone track at `frame` into outRot + outVmdTrans. The translation is
|
|
2394
2426
|
* VMD-space (bind-relative), NOT yet converted to bone-local — callers convert with
|
|
2395
2427
|
* convertVMDTranslationToLocal once they know the final rotation. The cursor cache
|
|
@@ -2871,6 +2903,7 @@ export class Model {
|
|
|
2871
2903
|
this.applyCrossfade(deltaTime)
|
|
2872
2904
|
} else {
|
|
2873
2905
|
const clip = this.animationState.getCurrentClip()
|
|
2906
|
+
if (clip === null) this.motionHidden = false
|
|
2874
2907
|
if (clip !== null) {
|
|
2875
2908
|
this.applyPoseFromClip(clip, this.animationState.getCurrentFrame())
|
|
2876
2909
|
if (evWatch !== null && evWatch === this.animationState.getCurrentAnimation()) {
|
package/src/vmd-writer.ts
CHANGED
|
@@ -94,6 +94,17 @@ export class VMDWriter {
|
|
|
94
94
|
else ikByFrame.set(key.frame, [{ boneName, enabled: key.enabled }])
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
+
// The model's display flag rides in the same records. A moment it changes
|
|
98
|
+
// with no IK switch beside it still needs a record of its own, and every
|
|
99
|
+
// record states the flag as it stands then — one written as "shown" would
|
|
100
|
+
// bring her back mid-hide on the way in.
|
|
101
|
+
const visibility = wantBones ? clip.visibility : undefined
|
|
102
|
+
if (visibility) for (const key of visibility) if (!ikByFrame.has(key.frame)) ikByFrame.set(key.frame, [])
|
|
103
|
+
const shownAt = (frame: number): boolean => {
|
|
104
|
+
let shown = true
|
|
105
|
+
if (visibility) for (let i = 0; i < visibility.length && visibility[i].frame <= frame; i++) shown = visibility[i].visible
|
|
106
|
+
return shown
|
|
107
|
+
}
|
|
97
108
|
const ikFrames = [...ikByFrame.entries()].sort((a, b) => a[0] - b[0])
|
|
98
109
|
let ikSize = 0
|
|
99
110
|
for (const [, states] of ikFrames) ikSize += 4 + 1 + 4 + states.length * (IK_NAME_SIZE + 1)
|
|
@@ -188,7 +199,7 @@ export class VMDWriter {
|
|
|
188
199
|
for (const [frame, states] of ikFrames) {
|
|
189
200
|
view.setUint32(offset, frame, true)
|
|
190
201
|
offset += 4
|
|
191
|
-
view.setUint8(offset, 1) // model visible
|
|
202
|
+
view.setUint8(offset, shownAt(frame) ? 1 : 0) // model visible
|
|
192
203
|
offset += 1
|
|
193
204
|
view.setUint32(offset, states.length, true)
|
|
194
205
|
offset += 4
|