@ikijs/mcp 0.34.0 → 0.35.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/README.md +3 -3
- package/dist/{chunk-HKJT3Q6G.mjs → chunk-SNBG5VHS.mjs} +227 -54
- package/dist/chunk-SNBG5VHS.mjs.map +1 -0
- package/dist/cli.js +226 -53
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +37 -1
- package/dist/index.d.ts +37 -1
- package/dist/index.js +226 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/render-page.global.js +98 -8
- package/package.json +4 -4
- package/dist/chunk-HKJT3Q6G.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -415,6 +415,22 @@
|
|
|
415
415
|
return { worlds, grids };
|
|
416
416
|
}
|
|
417
417
|
|
|
418
|
+
// ../engine/src/occlusion.ts
|
|
419
|
+
function occlusionAmount(occlusion, value) {
|
|
420
|
+
const { stops } = occlusion;
|
|
421
|
+
const first = stops[0];
|
|
422
|
+
if (value <= first.value) return first.amount;
|
|
423
|
+
for (let i = 1; i < stops.length; i++) {
|
|
424
|
+
const hi = stops[i];
|
|
425
|
+
if (value <= hi.value) {
|
|
426
|
+
const lo = stops[i - 1];
|
|
427
|
+
const t = (value - lo.value) / (hi.value - lo.value);
|
|
428
|
+
return lo.amount * (1 - t) + hi.amount * t;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return stops[stops.length - 1].amount;
|
|
432
|
+
}
|
|
433
|
+
|
|
418
434
|
// ../engine/src/view.ts
|
|
419
435
|
function checkedView(view) {
|
|
420
436
|
const { x, y, width, height } = view;
|
|
@@ -460,7 +476,7 @@
|
|
|
460
476
|
// and composite too dark.
|
|
461
477
|
premultipliedAlpha: true,
|
|
462
478
|
// Stencil buffer backs clip masks (a part rendered only inside its masks'
|
|
463
|
-
// coverage). Granted by every modern browser; the load() guard reports if not.
|
|
479
|
+
// coverage) and occlusion (a part hidden inside its occluders'). Granted by every modern browser; the load() guard reports if not.
|
|
464
480
|
stencil: true
|
|
465
481
|
});
|
|
466
482
|
if (!gl) throw new Error("WebGL2 is not available in this browser");
|
|
@@ -495,7 +511,7 @@
|
|
|
495
511
|
uAlphaCutoff;
|
|
496
512
|
aPos;
|
|
497
513
|
aUv;
|
|
498
|
-
/** True when the context granted a stencil buffer; clipping
|
|
514
|
+
/** True when the context granted a stencil buffer; clipping and occlusion need it. */
|
|
499
515
|
stencilAvailable;
|
|
500
516
|
model;
|
|
501
517
|
view;
|
|
@@ -521,6 +537,12 @@
|
|
|
521
537
|
* → its mask part indices. A part absent from this map is unclipped.
|
|
522
538
|
*/
|
|
523
539
|
partClipGroups = /* @__PURE__ */ new Map();
|
|
540
|
+
/**
|
|
541
|
+
* Occlusion resolved once per `load()`: occluded part index → its occluders'
|
|
542
|
+
* part indices and its field. Empty for a model without the field, and then
|
|
543
|
+
* the frame loop does no per-part lookup.
|
|
544
|
+
*/
|
|
545
|
+
partOcclusions = /* @__PURE__ */ new Map();
|
|
524
546
|
/**
|
|
525
547
|
* Load a model and reset parameters to their defaults. All textures are
|
|
526
548
|
* decoded and uploaded before the model is swapped in — the swap is atomic,
|
|
@@ -707,11 +729,25 @@
|
|
|
707
729
|
const maskIndices = clip.masks.map((maskId) => indexById.get(maskId)).filter((mi) => mi !== void 0);
|
|
708
730
|
if (maskIndices.length > 0) nextClipGroups.set(i, maskIndices);
|
|
709
731
|
}
|
|
732
|
+
const nextOcclusions = /* @__PURE__ */ new Map();
|
|
733
|
+
for (let i = 0; i < nextParts.length; i++) {
|
|
734
|
+
const occlusion = nextParts[i].occlusion;
|
|
735
|
+
if (!occlusion) continue;
|
|
736
|
+
const occluders = occlusion.by.map((id) => indexById.get(id)).filter((oi) => oi !== void 0);
|
|
737
|
+
if (occluders.length > 0) {
|
|
738
|
+
nextOcclusions.set(i, { occluders, occlusion });
|
|
739
|
+
}
|
|
740
|
+
}
|
|
710
741
|
if (nextClipGroups.size > 0 && !this.stencilAvailable) {
|
|
711
742
|
console.error(
|
|
712
743
|
"Iki: model uses clip masks but this WebGL2 context has no stencil buffer; rendering unclipped"
|
|
713
744
|
);
|
|
714
745
|
}
|
|
746
|
+
if (nextOcclusions.size > 0 && !this.stencilAvailable) {
|
|
747
|
+
console.error(
|
|
748
|
+
"Iki: model uses occlusion but this WebGL2 context has no stencil buffer; rendering unhidden"
|
|
749
|
+
);
|
|
750
|
+
}
|
|
715
751
|
deletePartMeshBuffers(gl, this.partMeshes);
|
|
716
752
|
for (const texture of this.textures) {
|
|
717
753
|
if (texture) gl.deleteTexture(texture);
|
|
@@ -721,6 +757,7 @@
|
|
|
721
757
|
this.parts = nextParts;
|
|
722
758
|
this.partMeshes = nextPartMeshes;
|
|
723
759
|
this.partClipGroups = nextClipGroups;
|
|
760
|
+
this.partOcclusions = nextOcclusions;
|
|
724
761
|
this.textures = uploaded;
|
|
725
762
|
return {
|
|
726
763
|
failedTextures: uploaded.flatMap((t, i) => t === null ? [i] : []),
|
|
@@ -844,10 +881,61 @@
|
|
|
844
881
|
warpGrids
|
|
845
882
|
);
|
|
846
883
|
} else {
|
|
847
|
-
this.
|
|
884
|
+
const occlusion = this.partOcclusions.size > 0 ? this.partOcclusions.get(index) : void 0;
|
|
885
|
+
const amount = occlusion && this.stencilAvailable ? occlusionAmount(
|
|
886
|
+
occlusion.occlusion,
|
|
887
|
+
this.params.get(occlusion.occlusion.parameter)
|
|
888
|
+
) : 0;
|
|
889
|
+
if (occlusion && amount > 0) {
|
|
890
|
+
this.drawOccluded(
|
|
891
|
+
index,
|
|
892
|
+
occlusion.occluders,
|
|
893
|
+
amount,
|
|
894
|
+
project,
|
|
895
|
+
deformerWorlds,
|
|
896
|
+
warpGrids
|
|
897
|
+
);
|
|
898
|
+
} else {
|
|
899
|
+
this.drawPart(index, project, deformerWorlds, warpGrids);
|
|
900
|
+
}
|
|
848
901
|
}
|
|
849
902
|
}
|
|
850
903
|
}
|
|
904
|
+
/**
|
|
905
|
+
* Draw an occluded part: stencil the union of its occluders' coverage (as a
|
|
906
|
+
* mask's, colour-free, at the half-opaque contour), then draw the part once
|
|
907
|
+
* outside it at full strength and, when the amount is under 1, once inside
|
|
908
|
+
* it at `1 − amount`. Each sample gets exactly one copy, so there is no seam
|
|
909
|
+
* and nothing of the part shows through an occluder's translucent pixels.
|
|
910
|
+
* Restores the same state as {@link drawClipped}.
|
|
911
|
+
*/
|
|
912
|
+
drawOccluded(index, occluderIndices, amount, project, deformerWorlds, warpGrids) {
|
|
913
|
+
const { gl } = this;
|
|
914
|
+
gl.clear(gl.STENCIL_BUFFER_BIT);
|
|
915
|
+
gl.enable(gl.STENCIL_TEST);
|
|
916
|
+
gl.colorMask(false, false, false, false);
|
|
917
|
+
gl.stencilMask(255);
|
|
918
|
+
gl.stencilFunc(gl.ALWAYS, 1, 255);
|
|
919
|
+
gl.stencilOp(gl.KEEP, gl.KEEP, gl.REPLACE);
|
|
920
|
+
gl.uniform1f(this.uAlphaCutoff, MASK_ALPHA_CUTOFF);
|
|
921
|
+
for (const occluderIndex of occluderIndices) {
|
|
922
|
+
this.drawPart(occluderIndex, project, deformerWorlds, warpGrids);
|
|
923
|
+
}
|
|
924
|
+
gl.uniform1f(this.uAlphaCutoff, 0);
|
|
925
|
+
gl.colorMask(true, true, true, true);
|
|
926
|
+
gl.stencilMask(0);
|
|
927
|
+
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
|
|
928
|
+
gl.stencilFunc(gl.NOTEQUAL, 1, 255);
|
|
929
|
+
this.drawPart(index, project, deformerWorlds, warpGrids);
|
|
930
|
+
if (amount < 1) {
|
|
931
|
+
gl.stencilFunc(gl.EQUAL, 1, 255);
|
|
932
|
+
this.drawPart(index, project, deformerWorlds, warpGrids, 1 - amount);
|
|
933
|
+
}
|
|
934
|
+
gl.disable(gl.STENCIL_TEST);
|
|
935
|
+
gl.stencilMask(255);
|
|
936
|
+
gl.stencilFunc(gl.ALWAYS, 0, 255);
|
|
937
|
+
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
|
|
938
|
+
}
|
|
851
939
|
/**
|
|
852
940
|
* Draw a clipped part: stencil the union of its masks' alpha coverage, then
|
|
853
941
|
* draw the part only where the stencil was written. The mask parts also draw
|
|
@@ -880,11 +968,13 @@
|
|
|
880
968
|
}
|
|
881
969
|
/**
|
|
882
970
|
* Draw a single part with its full per-part material + geometry state. Shared
|
|
883
|
-
* by the normal pass, the stencil
|
|
884
|
-
*
|
|
885
|
-
* (the caller only sets
|
|
971
|
+
* by the normal pass, the stencil coverage-write passes (clip masks and
|
|
972
|
+
* occluders), the masked consumer draw and the occluded draws — so every path
|
|
973
|
+
* prepares the SAME complete uniform/texture/VBO state (the caller only sets
|
|
974
|
+
* stencil/colorMask/u_alphaCutoff around it). `fade` scales the part's alpha
|
|
975
|
+
* (an occluded part inside its coverage draws at `1 − amount`).
|
|
886
976
|
*/
|
|
887
|
-
drawPart(index, project, deformerWorlds, warpGrids) {
|
|
977
|
+
drawPart(index, project, deformerWorlds, warpGrids, fade = 1) {
|
|
888
978
|
const { gl } = this;
|
|
889
979
|
const part = this.parts[index];
|
|
890
980
|
const texture = part.texture ? this.textures[part.texture.index] : void 0;
|
|
@@ -911,7 +1001,7 @@
|
|
|
911
1001
|
}
|
|
912
1002
|
const [r, g, b, a] = part.color;
|
|
913
1003
|
gl.uniformMatrix3fv(this.uMatrix, false, toMat3(m));
|
|
914
|
-
gl.uniform4f(this.uColor, r, g, b, a * t.opacity);
|
|
1004
|
+
gl.uniform4f(this.uColor, r, g, b, a * t.opacity * fade);
|
|
915
1005
|
if (part.texture && texture) {
|
|
916
1006
|
const { uv } = part.texture;
|
|
917
1007
|
gl.uniform1i(this.uUseTexture, 1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikijs/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "MCP server that lets AI agents build 2D puppet characters: compose AI-drawn part images, check their geometry and auto-rig them into an open .iki model — Iki, the free Live2D alternative.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"iki",
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"!dist/metafile-*.json"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@ikijs/editor": "^0.
|
|
45
|
-
"@ikijs/format": "^0.
|
|
44
|
+
"@ikijs/editor": "^0.32.0",
|
|
45
|
+
"@ikijs/format": "^0.11.0",
|
|
46
46
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
47
47
|
"sharp": "^0.33.5",
|
|
48
48
|
"zod": "^3.25"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@ikijs/engine": "^0.
|
|
51
|
+
"@ikijs/engine": "^0.11.0",
|
|
52
52
|
"tsup": "^8.5.0",
|
|
53
53
|
"typescript": "^5.9.2"
|
|
54
54
|
},
|