@doki-land/live2d-renderer 0.0.22 → 0.0.24
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/index.d.ts +3 -0
- package/dist/index.js +11 -1
- package/package.json +2 -2
- package/src/moc/moc3.ts +21 -1
- package/src/runtime/model-runtime.ts +6 -0
package/dist/index.d.ts
CHANGED
|
@@ -285,6 +285,8 @@ interface ModelBackend {
|
|
|
285
285
|
*/
|
|
286
286
|
resolveParameter?(model: InternalModel, id: string): number | undefined;
|
|
287
287
|
listParameters?(model: InternalModel): readonly ParameterBinding[];
|
|
288
|
+
/** Drawable index → MOC art-mesh id (program order), when known. */
|
|
289
|
+
getDrawableArtMeshId?(model: InternalModel, drawableIndex: number): string | undefined;
|
|
288
290
|
}
|
|
289
291
|
declare function selectModelBackend(backends: ModelBackend[], json: unknown): ModelBackend;
|
|
290
292
|
|
|
@@ -318,6 +320,7 @@ declare class Moc3Backend implements ModelBackend {
|
|
|
318
320
|
setPartOpacity(model: InternalModel, id: string, value: number): void;
|
|
319
321
|
resolveParameter(model: InternalModel, id: string): number | undefined;
|
|
320
322
|
listParameters(model: InternalModel): readonly ParameterBinding[];
|
|
323
|
+
getDrawableArtMeshId(model: InternalModel, drawableIndex: number): string | undefined;
|
|
321
324
|
hitTest(_model: InternalModel, _x: number, _y: number): string | null;
|
|
322
325
|
destroyModel(model: InternalModel): void;
|
|
323
326
|
getResidentInstance(model: InternalModel): ModelInstance | null;
|
package/dist/index.js
CHANGED
|
@@ -5963,12 +5963,15 @@ var Moc3Backend = class {
|
|
|
5963
5963
|
const instance = createModelInstance(program);
|
|
5964
5964
|
const meshes = allocateMeshesFromProgram2(program);
|
|
5965
5965
|
const byArtMesh = /* @__PURE__ */ new Map();
|
|
5966
|
+
const drawableArtMeshIds = [];
|
|
5966
5967
|
if (doc) {
|
|
5968
|
+
const artMeshIds = moc3SectionStrings(doc, "art_mesh.ids");
|
|
5967
5969
|
const artOrder = moc3ArtMeshIndicesInProgramOrder(doc);
|
|
5968
5970
|
for (let i = 0; i < artOrder.length; i++) {
|
|
5969
5971
|
const art = artOrder[i];
|
|
5970
5972
|
const mesh = meshes[i];
|
|
5971
5973
|
if (mesh) byArtMesh.set(art, mesh);
|
|
5974
|
+
drawableArtMeshIds.push(artMeshIds[art] ?? "");
|
|
5972
5975
|
}
|
|
5973
5976
|
}
|
|
5974
5977
|
const poseOpacity = new Float32Array(meshes.length);
|
|
@@ -5989,7 +5992,8 @@ var Moc3Backend = class {
|
|
|
5989
5992
|
poseDirty: true,
|
|
5990
5993
|
partOpacity: /* @__PURE__ */ new Map(),
|
|
5991
5994
|
bindings,
|
|
5992
|
-
paramIndexById
|
|
5995
|
+
paramIndexById,
|
|
5996
|
+
drawableArtMeshIds
|
|
5993
5997
|
};
|
|
5994
5998
|
bakePose2(state);
|
|
5995
5999
|
applyPartOpacity(state);
|
|
@@ -6048,6 +6052,12 @@ var Moc3Backend = class {
|
|
|
6048
6052
|
syncBindingValues2(state);
|
|
6049
6053
|
return state.bindings;
|
|
6050
6054
|
}
|
|
6055
|
+
getDrawableArtMeshId(model, drawableIndex) {
|
|
6056
|
+
const state = stateByModel2.get(model);
|
|
6057
|
+
if (!state) return void 0;
|
|
6058
|
+
const id = state.drawableArtMeshIds[drawableIndex];
|
|
6059
|
+
return id || void 0;
|
|
6060
|
+
}
|
|
6051
6061
|
hitTest(_model, _x, _y) {
|
|
6052
6062
|
return null;
|
|
6053
6063
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doki-land/live2d-renderer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "Live2D rendering — moc2/moc3 decode + WebGPU, WebGL2, Canvas2D backends for live2d.ts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"test": "vitest run"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@doki-land/live2d-core": "0.0.
|
|
48
|
+
"@doki-land/live2d-core": "0.0.24"
|
|
49
49
|
},
|
|
50
50
|
"sideEffects": false
|
|
51
51
|
}
|
package/src/moc/moc3.ts
CHANGED
|
@@ -20,7 +20,11 @@ import type {
|
|
|
20
20
|
} from "../runtime/model-runtime.js";
|
|
21
21
|
import type { BlendMode, DrawableMesh } from "../types.js";
|
|
22
22
|
import { cascadedPartOpacity, readMoc3PartTables } from "./moc3-parts.js";
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
type Moc3Document,
|
|
25
|
+
moc3SectionStrings,
|
|
26
|
+
parseMoc3Document,
|
|
27
|
+
} from "./moc3-reader.js";
|
|
24
28
|
import {
|
|
25
29
|
evaluateMoc3PoseInto,
|
|
26
30
|
moc3ArtMeshIndicesInProgramOrder,
|
|
@@ -40,6 +44,8 @@ interface Moc3State {
|
|
|
40
44
|
partOpacity: Map<string, number>;
|
|
41
45
|
bindings: ParameterBinding[];
|
|
42
46
|
paramIndexById: Map<string, number>;
|
|
47
|
+
/** Program-order art-mesh ids for HitArea resolution. */
|
|
48
|
+
drawableArtMeshIds: readonly string[];
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
const stateByModel = new WeakMap<InternalModel, Moc3State>();
|
|
@@ -191,12 +197,15 @@ export class Moc3Backend implements ModelBackend {
|
|
|
191
197
|
const instance = createModelInstance(program);
|
|
192
198
|
const meshes = allocateMeshesFromProgram(program);
|
|
193
199
|
const byArtMesh = new Map<number, DrawableMesh>();
|
|
200
|
+
const drawableArtMeshIds: string[] = [];
|
|
194
201
|
if (doc) {
|
|
202
|
+
const artMeshIds = moc3SectionStrings(doc, "art_mesh.ids");
|
|
195
203
|
const artOrder = moc3ArtMeshIndicesInProgramOrder(doc);
|
|
196
204
|
for (let i = 0; i < artOrder.length; i++) {
|
|
197
205
|
const art = artOrder[i]!;
|
|
198
206
|
const mesh = meshes[i];
|
|
199
207
|
if (mesh) byArtMesh.set(art, mesh);
|
|
208
|
+
drawableArtMeshIds.push(artMeshIds[art] ?? "");
|
|
200
209
|
}
|
|
201
210
|
}
|
|
202
211
|
const poseOpacity = new Float32Array(meshes.length);
|
|
@@ -218,6 +227,7 @@ export class Moc3Backend implements ModelBackend {
|
|
|
218
227
|
partOpacity: new Map(),
|
|
219
228
|
bindings,
|
|
220
229
|
paramIndexById,
|
|
230
|
+
drawableArtMeshIds,
|
|
221
231
|
};
|
|
222
232
|
bakePose(state);
|
|
223
233
|
applyPartOpacity(state);
|
|
@@ -286,6 +296,16 @@ export class Moc3Backend implements ModelBackend {
|
|
|
286
296
|
return state.bindings;
|
|
287
297
|
}
|
|
288
298
|
|
|
299
|
+
getDrawableArtMeshId(
|
|
300
|
+
model: InternalModel,
|
|
301
|
+
drawableIndex: number,
|
|
302
|
+
): string | undefined {
|
|
303
|
+
const state = stateByModel.get(model);
|
|
304
|
+
if (!state) return undefined;
|
|
305
|
+
const id = state.drawableArtMeshIds[drawableIndex];
|
|
306
|
+
return id || undefined;
|
|
307
|
+
}
|
|
308
|
+
|
|
289
309
|
hitTest(_model: InternalModel, _x: number, _y: number): string | null {
|
|
290
310
|
return null;
|
|
291
311
|
}
|
|
@@ -76,6 +76,12 @@ export interface ModelBackend {
|
|
|
76
76
|
resolveParameter?(model: InternalModel, id: string): number | undefined;
|
|
77
77
|
|
|
78
78
|
listParameters?(model: InternalModel): readonly ParameterBinding[];
|
|
79
|
+
|
|
80
|
+
/** Drawable index → MOC art-mesh id (program order), when known. */
|
|
81
|
+
getDrawableArtMeshId?(
|
|
82
|
+
model: InternalModel,
|
|
83
|
+
drawableIndex: number,
|
|
84
|
+
): string | undefined;
|
|
79
85
|
}
|
|
80
86
|
|
|
81
87
|
export function selectModelBackend(
|