wireface 1.0.2 → 1.1.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.
@@ -0,0 +1,147 @@
1
+ <!DOCTYPE html>
2
+ <!--
3
+ wireface — minimal CDN playground
4
+ Repository: https://github.com/styk-tv/wireface
5
+ npm: https://www.npmjs.com/package/wireface
6
+ Copyright (c) 2026 Peter Styk
7
+ Released under the MIT License — see LICENSE in the repository root.
8
+
9
+ Self-contained, ~100 lines. Drop an mp3 onto the canvas, switch
10
+ between two preset characters, hit ▶ play. Library + Babylon both
11
+ loaded from CDN. Designed to be as close as possible to a copy-paste
12
+ for playground.babylonjs.com — see SPEC.WIREFACE.BABYLON.9.0 §6.
13
+ -->
14
+ <html lang="en">
15
+ <head>
16
+ <meta charset="utf-8">
17
+ <meta name="viewport" content="width=device-width,initial-scale=1">
18
+ <title>wireface — playground</title>
19
+ <style>
20
+ html,body { margin:0; height:100%; background:#000; color:#f4f4f0; font-family: ui-monospace, monospace; }
21
+ #app { display:grid; grid-template-rows:auto 1fr auto; height:100%; }
22
+ header { padding:12px 16px; border-bottom:1px solid rgba(255,255,255,.12); display:flex; gap:18px; align-items:center; font-size:11px; letter-spacing:.16em; text-transform:uppercase; }
23
+ header b { color:#f5e663; letter-spacing:.3em; font-weight:500; }
24
+ header .hint { color:#888; }
25
+ .canvas-wrap { position:relative; min-height:0; background:#000; }
26
+ canvas { width:100%; height:100%; display:block; outline:none; touch-action:none; }
27
+ .drop-overlay { position:absolute; inset:0; display:grid; place-items:center;
28
+ background:rgba(0,0,0,.6); border:2px dashed #f5e663; color:#f5e663;
29
+ font-size:12px; letter-spacing:.2em; text-transform:uppercase; pointer-events:none; opacity:0;
30
+ transition:opacity .15s; }
31
+ .canvas-wrap.drag-over .drop-overlay { opacity:1; }
32
+ .controls { display:flex; gap:8px; align-items:center; padding:10px 16px; border-top:1px solid rgba(255,255,255,.12); font-size:11px; }
33
+ button { font-family:inherit; font-size:10px; letter-spacing:.16em; text-transform:uppercase;
34
+ background:transparent; color:#f4f4f0; border:1px solid rgba(255,255,255,.22);
35
+ padding:8px 14px; cursor:pointer; transition:all .12s; }
36
+ button:hover:not(:disabled) { background:#f4f4f0; color:#000; border-color:#f4f4f0; }
37
+ button.on { background:#f5e663; color:#000; border-color:#f5e663; }
38
+ button:disabled { opacity:.3; cursor:not-allowed; }
39
+ .audio-name { font-size:10px; color:#888; margin-left:auto; padding-left:14px; border-left:2px solid rgba(255,255,255,.22); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:300px; }
40
+ </style>
41
+ </head>
42
+ <body>
43
+ <div id="app">
44
+ <header>
45
+ <b>WIREFACE</b>
46
+ <span class="hint">drop .mp3 onto the face · switch presets · play</span>
47
+ </header>
48
+ <div class="canvas-wrap" id="wrap">
49
+ <canvas id="cv"></canvas>
50
+ <div class="drop-overlay">drop an audio file</div>
51
+ </div>
52
+ <div class="controls">
53
+ <button data-preset="A" class="on">preset A · red wire</button>
54
+ <button data-preset="B">preset B · low-poly blue</button>
55
+ <button id="btn-play">▶ play</button>
56
+ <button id="btn-stop">■ stop</button>
57
+ <span class="audio-name" id="audio-name">no audio loaded</span>
58
+ </div>
59
+ </div>
60
+
61
+ <!-- Babylon v9 + wireface from CDN -->
62
+ <script src="https://cdn.jsdelivr.net/npm/babylonjs@9/babylon.js"></script>
63
+ <script src="https://cdn.jsdelivr.net/npm/wireface@1/dist/wireface.min.js"></script>
64
+
65
+ <script>
66
+ /* Two character presets baked-in — same shape as
67
+ examples/presets/asset-th5rha.json (red wire) and asset-ydr7de.json
68
+ (low-poly blue). Trimmed to just the renderConfig fields that
69
+ matter for the visual. The lib fills in defaults for everything
70
+ else (per-feature colors null = inherit, channelGains 1.0, etc.). */
71
+ const PRESETS = {
72
+ A: {
73
+ name: 'red wire',
74
+ renderConfig: {
75
+ meshCols: 21, meshRows: 21, fragment: true, glow: true,
76
+ mouthHole: true, mouthHoleSize: 1.15, eyeHoles: true, eyeDepth: 5,
77
+ lineThickness: 0.4, lipVertAmp: 4, lipPressForce: 3,
78
+ pupils: true, irisSize: 3.3,
79
+ lineColor: '#541717', baseColor: '#ff8585', fadeColor: '#f00000',
80
+ pupilColor: '#c4b0b0', irisColor: '#ff0000', browColor: '#616161',
81
+ depthFade: 1, mouthAnchor: true, eyeAnchor: true,
82
+ },
83
+ },
84
+ B: {
85
+ name: 'low-poly blue',
86
+ renderConfig: {
87
+ meshCols: 7, meshRows: 9, fragment: true, glow: true,
88
+ mouthHole: true, mouthHoleSize: 1.85, eyeHoles: false, eyeDepth: 1,
89
+ scaleNose: 1.15, scaleEyes: 2, scaleMouth: 2,
90
+ lineThickness: 1, lipVertAmp: 1.6,
91
+ pupils: true, irisSize: 2,
92
+ lineColor: '#181616', baseColor: '#7a86c2', fadeColor: '#f00000',
93
+ pupilColor: '#3a2727', irisColor: '#170303',
94
+ depthFade: 0.4, mouthAnchor: true,
95
+ },
96
+ },
97
+ };
98
+
99
+ /* Boot one wireface instance against the canvas. */
100
+ const wf = createWireface(document.getElementById('cv'));
101
+ wf.setLoop(true);
102
+ wf.loadPreset(PRESETS.A);
103
+
104
+ /* Preset switcher. */
105
+ for (const btn of document.querySelectorAll('[data-preset]')) {
106
+ btn.addEventListener('click', () => {
107
+ document.querySelectorAll('[data-preset]').forEach(b => b.classList.remove('on'));
108
+ btn.classList.add('on');
109
+ wf.loadPreset(PRESETS[btn.dataset.preset]);
110
+ });
111
+ }
112
+
113
+ /* Transport. */
114
+ const playBtn = document.getElementById('btn-play');
115
+ const stopBtn = document.getElementById('btn-stop');
116
+ playBtn.addEventListener('click', () => {
117
+ if (wf.isPlaying()) { wf.pause(); playBtn.textContent = '▶ play'; }
118
+ else { wf.play(); playBtn.textContent = '❚❚ pause'; }
119
+ });
120
+ stopBtn.addEventListener('click', () => { wf.stop(); playBtn.textContent = '▶ play'; });
121
+
122
+ /* Drag-drop audio onto the canvas wrap. */
123
+ const wrap = document.getElementById('wrap');
124
+ const audioLabel = document.getElementById('audio-name');
125
+ wrap.addEventListener('dragenter', e => { e.preventDefault(); wrap.classList.add('drag-over'); });
126
+ wrap.addEventListener('dragover', e => { e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; });
127
+ wrap.addEventListener('dragleave', e => {
128
+ if (e.target === wrap || !wrap.contains(e.relatedTarget)) wrap.classList.remove('drag-over');
129
+ });
130
+ wrap.addEventListener('drop', async e => {
131
+ e.preventDefault();
132
+ wrap.classList.remove('drag-over');
133
+ const file = e.dataTransfer.files && e.dataTransfer.files[0];
134
+ if (!file) return;
135
+ try {
136
+ await wf.loadAudio(file);
137
+ audioLabel.textContent = file.name;
138
+ } catch (err) {
139
+ audioLabel.textContent = 'decode failed: ' + err.message;
140
+ }
141
+ });
142
+
143
+ /* Expose for console poking. */
144
+ window.wf = wf;
145
+ </script>
146
+ </body>
147
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wireface",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "Minimal embeddable wireframe lipsync face renderer — drives expressive character profiles from voice or TTS audio in the browser.",
5
5
  "main": "wireface.js",
6
6
  "browser": "wireface.js",
package/wireface.js CHANGED
@@ -168,10 +168,25 @@
168
168
  overlayTracksMesh: true,
169
169
  moodTransitionTime: 0.6,
170
170
  lineColor: '#ffffff', pupilColor: '#ffffff',
171
+ // Per-feature minimal-line overrides. null = inherit lineColor (backward
172
+ // compat with v1.0.x presets). Each feature can be hidden individually
173
+ // even when the master `minimal` is on. Each has its own thickness
174
+ // multiplier on top of the global `lineThickness`.
175
+ mouthColor: null, eyeColor: null, noseColor: null,
176
+ minimalMouth: true, minimalEyes: true, minimalNose: true, minimalBrows: true,
177
+ mouthLineThickness: 1.0, eyeLineThickness: 1.0, noseLineThickness: 1.0, browLineThickness: 1.0,
171
178
  baseColor: '#ffffff', fadeColor: '#000000', depthFade: 0.0,
179
+ // exponent applied to the per-vertex fade weight. >1 darkens the back
180
+ // faster (so silhouette edges actually reach fadeColor in wire mode);
181
+ // <1 brightens it. 1.0 = linear, original behavior.
182
+ depthFadeCurve: 1.0,
172
183
  irisColor: '#000000', irisSize: 1.6,
173
184
  browColor: '#ffffff',
174
185
  jawExtend: 0.0, mouthGrow: 0.0,
186
+ // experimental — static z push of upper-mouth and lower-jaw regions for
187
+ // animal / crocodile-mouth distortions. Stack on top of jawExtend (which
188
+ // is jawOpen-driven). Default 0 = current behavior.
189
+ upperJawProtrude: 0.0, lowerJawProtrude: 0.0,
175
190
  cameraView: 'three-q', // initial view
176
191
  };
177
192
 
@@ -229,6 +244,17 @@
229
244
  /* ── Babylon scene ── */
230
245
  const engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: false, stencil: false, antialias: true });
231
246
  const scene = new BABYLON.Scene(engine);
247
+ // v1.1.1: right-handed coordinate system. Babylon defaults to LH where +Z
248
+ // is into the screen, so a face built with +Z=nose-forward by warpToFace
249
+ // would render facing AWAY from the default ArcRotateCamera at -Z (the
250
+ // user would see the back of the head). RH flips Z so +Z is out-of-screen,
251
+ // which means the face naturally faces the camera AND the camera view
252
+ // alphas (front=-π/2, profile=0, three-q=-π/2-0.6) map to the
253
+ // conventionally-correct sides of the face — front shows the front,
254
+ // profile shows the face's right, three-quarter is a proper portrait
255
+ // angle. Fixes the "everything is flipped so views start incorrectly"
256
+ // bug without touching warpToFace, faceRoot.rotation, or any view alpha.
257
+ scene.useRightHandedSystem = true;
232
258
  scene.clearColor = new BABYLON.Color4(0, 0, 0, 1);
233
259
  // we never pick on pointer-move; saves a per-frame ray test
234
260
  scene.skipPointerMovePicking = true;
@@ -272,15 +298,23 @@
272
298
  wireMat.alpha = 1;
273
299
  wireMat.useVertexColor = true;
274
300
 
275
- const minimalMat = new BABYLON.StandardMaterial('minimalMat', scene);
276
- minimalMat.emissiveColor = new BABYLON.Color3(1, 1, 1);
277
- minimalMat.disableLighting = true;
278
- minimalMat.specularColor = new BABYLON.Color3(0, 0, 0);
279
-
280
- const browMat = new BABYLON.StandardMaterial('browMat', scene);
281
- browMat.emissiveColor = new BABYLON.Color3(1, 1, 1);
282
- browMat.disableLighting = true;
283
- browMat.specularColor = new BABYLON.Color3(0, 0, 0);
301
+ /* one material per minimal-line feature so each can have its own color
302
+ independent of the others. lineColor is the shared fallback; if a
303
+ per-feature color (mouthColor/eyeColor/noseColor) is null the feature
304
+ inherits lineColor at apply time. */
305
+ function makeMinimalMat(name) {
306
+ const m = new BABYLON.StandardMaterial(name, scene);
307
+ m.emissiveColor = new BABYLON.Color3(1, 1, 1);
308
+ m.disableLighting = true;
309
+ m.specularColor = new BABYLON.Color3(0, 0, 0);
310
+ return m;
311
+ }
312
+ const mouthMat = makeMinimalMat('mouthMat');
313
+ const eyeMat = makeMinimalMat('eyeMat');
314
+ const noseMat = makeMinimalMat('noseMat');
315
+ const browMat = makeMinimalMat('browMat');
316
+ // legacy alias — some downstream code still references minimalMat
317
+ const minimalMat = mouthMat;
284
318
 
285
319
  const minimalGroup = new BABYLON.TransformNode('minimal', scene);
286
320
  minimalGroup.parent = faceRoot;
@@ -311,8 +345,12 @@
311
345
  let z = (1 - xRel*xRel * 0.55 - yRel*yRel * 0.55) * 0.22;
312
346
  if (z < -0.05) z = -0.05;
313
347
 
314
- // eye sockets recess (gaussian — broad and bowl-shaped)
315
- const eyeY = 0.30;
348
+ // eye sockets recess (gaussian — broad and bowl-shaped).
349
+ // Centered at yRel=0.20 → UV v=0.40 to align with the eye opening
350
+ // (eye-hole puncture, minimal-line eyelid overlay, eye_blink shapes
351
+ // are all at v=0.40). Original v011 used yRel=0.30 which placed the
352
+ // bowl above the eye opening.
353
+ const eyeY = 0.20;
316
354
  const eyeL_d = ((xRel + 0.45) / 0.30) ** 2 + ((yRel - eyeY) / 0.18) ** 2;
317
355
  const eyeR_d = ((xRel - 0.45) / 0.30) ** 2 + ((yRel - eyeY) / 0.18) ** 2;
318
356
  const eyeRecess = 0.045 * config.eyeDepth;
@@ -732,6 +770,45 @@
732
770
  }
733
771
  }
734
772
 
773
+ /* Static jaw-protrude passes — push the upper-mouth and lower-jaw
774
+ regions forward (z+) independent of jawOpen. Used together they
775
+ form the snout / animal / crocodile-mouth distortion. Each is a
776
+ smooth tent ramp in v-space:
777
+ - upper: peaks at v=0.62 (just above the mouth), tapers off by
778
+ v=0.45 (top) and v=0.72 (mouth line)
779
+ - lower: peaks at v=0.85 (chin tip), tapers off by v=0.70 (mouth)
780
+ and v=1.0 (bottom of grid)
781
+ Magnitude is `protrude * 0.18` for both — at amt=3 (slider max),
782
+ lower jaw juts forward ~0.54 z-units which is comparable to the
783
+ nose tip's z=0.22, giving a clearly elongated jaw silhouette. */
784
+ function applyUpperJawProtrude(disp) {
785
+ const amt = config.upperJawProtrude;
786
+ if (amt < 0.001) return;
787
+ const push = amt * 0.18;
788
+ for (let i = 0; i < baseUVs.length; i++) {
789
+ const v = baseUVs[i].v;
790
+ if (v < 0.45 || v > 0.72) continue;
791
+ // tent: 0 at edges, 1 at v=0.62
792
+ const w = v < 0.62 ? (v - 0.45) / 0.17 : (0.72 - v) / 0.10;
793
+ disp[i].z += push * w;
794
+ }
795
+ }
796
+ function applyLowerJawProtrude(disp) {
797
+ const amt = config.lowerJawProtrude;
798
+ if (amt < 0.001) return;
799
+ const push = amt * 0.18;
800
+ for (let i = 0; i < baseUVs.length; i++) {
801
+ const v = baseUVs[i].v;
802
+ if (v < 0.70) continue;
803
+ // tent: 0 at v=0.70, 1 at v=0.85, tapers to 0.5 at v=1.0
804
+ let w;
805
+ if (v < 0.85) w = (v - 0.70) / 0.15;
806
+ else w = 1 - (v - 0.85) / 0.30; // ramp down past chin tip
807
+ if (w < 0) w = 0;
808
+ disp[i].z += push * w;
809
+ }
810
+ }
811
+
735
812
  function applyMouthAnchors(disp) {
736
813
  if (!config.mouthAnchor) return;
737
814
  const p = computeMouthParams();
@@ -894,12 +971,18 @@
894
971
  return out;
895
972
  }
896
973
 
897
- function makeTube(name, points, radius, instance) {
898
- const r = instance ? radius : radius * config.lineThickness;
974
+ /* makeTube creates a new tube OR updates an existing one in-place.
975
+ Final radius = baseRadius * featureMul * config.lineThickness — applied
976
+ in BOTH new and instance forms. Babylon's CreateTube instance-form
977
+ applies opts.radius every call (it does not preserve the radius from
978
+ construction), so updateMinimal MUST pass the current featureMul each
979
+ frame or the tube collapses to (base × 1 × lineThickness). */
980
+ function makeTube(name, points, radius, mat, featureMul, instance) {
981
+ const r = radius * (featureMul == null ? 1 : featureMul) * config.lineThickness;
899
982
  const opts = { path: points, radius: r, tessellation: 6, updatable: true };
900
983
  if (instance) opts.instance = instance;
901
984
  const tube = BABYLON.MeshBuilder.CreateTube(name, opts, scene);
902
- if (!instance) { tube.material = minimalMat; tube.parent = minimalGroup; }
985
+ if (!instance) { tube.material = mat || mouthMat; tube.parent = minimalGroup; }
903
986
  return tube;
904
987
  }
905
988
 
@@ -992,39 +1075,44 @@
992
1075
  if (noseLeftMesh) { noseLeftMesh.dispose(); noseLeftMesh = null; }
993
1076
  if (noseRightMesh) { noseRightMesh.dispose(); noseRightMesh = null; }
994
1077
  const { upper, lower } = mouthLipPaths();
995
- mouthUpperMesh = makeTube('mouth_u', upper, 0.010);
996
- mouthLowerMesh = makeTube('mouth_l', lower, 0.010);
1078
+ mouthUpperMesh = makeTube('mouth_u', upper, 0.010, mouthMat, config.mouthLineThickness);
1079
+ mouthLowerMesh = makeTube('mouth_l', lower, 0.010, mouthMat, config.mouthLineThickness);
997
1080
  for (const eye of eyeData) {
998
- const u = makeTube('eye_' + eye.side + '_u', eyePath(eye, true), 0.0085);
999
- const l = makeTube('eye_' + eye.side + '_l', eyePath(eye, false), 0.0085);
1081
+ const u = makeTube('eye_' + eye.side + '_u', eyePath(eye, true), 0.0085, eyeMat, config.eyeLineThickness);
1082
+ const l = makeTube('eye_' + eye.side + '_l', eyePath(eye, false), 0.0085, eyeMat, config.eyeLineThickness);
1000
1083
  eyeMeshes.push({ eye, upper: u, lower: l });
1001
1084
  }
1002
1085
  for (const brow of browData) {
1003
- const m = makeTube('brow_' + brow.side, browPath(brow), 0.011);
1004
- m.material = browMat;
1086
+ const m = makeTube('brow_' + brow.side, browPath(brow), 0.011, browMat, config.browLineThickness);
1005
1087
  browMeshes.push({ brow, mesh: m });
1006
1088
  }
1007
1089
  const np = nosePaths();
1008
- noseBridgeMesh = makeTube('nose_b', np.bridge, 0.009);
1009
- noseLeftMesh = makeTube('nose_l', np.leftN, 0.0085);
1010
- noseRightMesh = makeTube('nose_r', np.rightN, 0.0085);
1090
+ noseBridgeMesh = makeTube('nose_b', np.bridge, 0.009, noseMat, config.noseLineThickness);
1091
+ noseLeftMesh = makeTube('nose_l', np.leftN, 0.0085, noseMat, config.noseLineThickness);
1092
+ noseRightMesh = makeTube('nose_r', np.rightN, 0.0085, noseMat, config.noseLineThickness);
1011
1093
  applyMinimalVisibility();
1094
+ applyMinimalSubVisibility();
1012
1095
  }
1013
1096
 
1014
1097
  function updateMinimal() {
1015
1098
  if (!mouthUpperMesh) return;
1099
+ // Babylon's CreateTube instance-form applies opts.radius EVERY call —
1100
+ // it doesn't preserve the radius from construction. So we must pass the
1101
+ // current per-feature thickness multiplier on every frame, otherwise
1102
+ // the tube collapses back to (base × 1 × lineThickness) and the
1103
+ // per-feature slider has no visible effect.
1016
1104
  const mp = mouthLipPaths();
1017
- makeTube('', mp.upper, 0.010, mouthUpperMesh);
1018
- makeTube('', mp.lower, 0.010, mouthLowerMesh);
1105
+ makeTube('', mp.upper, 0.010, null, config.mouthLineThickness, mouthUpperMesh);
1106
+ makeTube('', mp.lower, 0.010, null, config.mouthLineThickness, mouthLowerMesh);
1019
1107
  for (const em of eyeMeshes) {
1020
- makeTube('', eyePath(em.eye, true), 0.0085, em.upper);
1021
- makeTube('', eyePath(em.eye, false), 0.0085, em.lower);
1108
+ makeTube('', eyePath(em.eye, true), 0.0085, null, config.eyeLineThickness, em.upper);
1109
+ makeTube('', eyePath(em.eye, false), 0.0085, null, config.eyeLineThickness, em.lower);
1022
1110
  }
1023
- for (const bm of browMeshes) makeTube('', browPath(bm.brow), 0.011, bm.mesh);
1111
+ for (const bm of browMeshes) makeTube('', browPath(bm.brow), 0.011, null, config.browLineThickness, bm.mesh);
1024
1112
  const np = nosePaths();
1025
- makeTube('', np.bridge, 0.009, noseBridgeMesh);
1026
- makeTube('', np.leftN, 0.0085, noseLeftMesh);
1027
- makeTube('', np.rightN, 0.0085, noseRightMesh);
1113
+ makeTube('', np.bridge, 0.009, null, config.noseLineThickness, noseBridgeMesh);
1114
+ makeTube('', np.leftN, 0.0085, null, config.noseLineThickness, noseLeftMesh);
1115
+ makeTube('', np.rightN, 0.0085, null, config.noseLineThickness, noseRightMesh);
1028
1116
  }
1029
1117
 
1030
1118
  /* ── per-frame face update ── */
@@ -1045,6 +1133,8 @@
1045
1133
  applyFeatureScales(_dispBuf);
1046
1134
  applyJawExtension(_dispBuf);
1047
1135
  applyMouthGrow(_dispBuf);
1136
+ applyUpperJawProtrude(_dispBuf);
1137
+ applyLowerJawProtrude(_dispBuf);
1048
1138
  applyMouthAnchors(_dispBuf);
1049
1139
  applyEyeAnchors(_dispBuf);
1050
1140
  // write final positions
@@ -1054,12 +1144,20 @@
1054
1144
  _posBuf[3*i+2] = baseVertices[i].z + _dispBuf[i].z;
1055
1145
  }
1056
1146
  mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, _posBuf);
1057
- // depth fade colors
1147
+ // depth fade colors. raw t = (zMax - z) / zRange, then exponentiated by
1148
+ // depthFadeCurve. >1 darkens back faster (so silhouette edges actually
1149
+ // hit fadeColor in wire mode despite line interpolation lifting them);
1150
+ // <1 brightens back. Then scaled by depthFade.
1058
1151
  if (config.depthFade > 0.001) {
1059
- const zRange = (_zMax - _zMin) || 1, f = config.depthFade;
1152
+ const zRange = (_zMax - _zMin) || 1;
1153
+ const f = config.depthFade;
1154
+ const curve = config.depthFadeCurve > 0 ? config.depthFadeCurve : 1;
1060
1155
  for (let i = 0; i < baseVertices.length; i++) {
1061
1156
  const z = _posBuf[3*i + 2];
1062
- const t = Math.max(0, Math.min(1, (_zMax - z) / zRange)) * f;
1157
+ let t = (_zMax - z) / zRange;
1158
+ if (t < 0) t = 0; else if (t > 1) t = 1;
1159
+ if (curve !== 1) t = Math.pow(t, curve);
1160
+ t *= f;
1063
1161
  _colBuf[4*i ] = _baseRGB[0] * (1 - t) + _fadeRGB[0] * t;
1064
1162
  _colBuf[4*i+1] = _baseRGB[1] * (1 - t) + _fadeRGB[1] * t;
1065
1163
  _colBuf[4*i+2] = _baseRGB[2] * (1 - t) + _fadeRGB[2] * t;
@@ -1275,10 +1373,44 @@
1275
1373
  }
1276
1374
  }
1277
1375
 
1278
- /* ── color application ── */
1376
+ /* ── color application ──
1377
+ Per-feature mouth/eye/nose materials inherit lineColor when their
1378
+ per-feature override is null. So applyLineColor pushes into all three
1379
+ inheriting materials; the per-feature setters override that. */
1279
1380
  function applyLineColor(hex) {
1280
1381
  config.lineColor = hex;
1281
- minimalMat.emissiveColor = BABYLON.Color3.FromHexString(hex);
1382
+ const c = BABYLON.Color3.FromHexString(hex);
1383
+ if (!config.mouthColor) mouthMat.emissiveColor = c;
1384
+ if (!config.eyeColor) eyeMat.emissiveColor = c;
1385
+ if (!config.noseColor) noseMat.emissiveColor = c;
1386
+ }
1387
+ function applyMouthColor(hex) {
1388
+ config.mouthColor = hex;
1389
+ mouthMat.emissiveColor = BABYLON.Color3.FromHexString(hex || config.lineColor);
1390
+ }
1391
+ function applyEyeColor(hex) {
1392
+ config.eyeColor = hex;
1393
+ eyeMat.emissiveColor = BABYLON.Color3.FromHexString(hex || config.lineColor);
1394
+ }
1395
+ function applyNoseColor(hex) {
1396
+ config.noseColor = hex;
1397
+ noseMat.emissiveColor = BABYLON.Color3.FromHexString(hex || config.lineColor);
1398
+ }
1399
+ function applyBrowColor(hex) {
1400
+ config.browColor = hex;
1401
+ browMat.emissiveColor = BABYLON.Color3.FromHexString(hex);
1402
+ }
1403
+ /* per-feature visibility — independent of master `minimal` (which still
1404
+ hides the whole minimalGroup). Each feature toggles its own meshes. */
1405
+ function applyMinimalSubVisibility() {
1406
+ const setVis = (m, v) => { if (m) m.isVisible = v; };
1407
+ setVis(mouthUpperMesh, !!config.minimalMouth);
1408
+ setVis(mouthLowerMesh, !!config.minimalMouth);
1409
+ for (const em of eyeMeshes) { setVis(em.upper, !!config.minimalEyes); setVis(em.lower, !!config.minimalEyes); }
1410
+ for (const bm of browMeshes) setVis(bm.mesh, !!config.minimalBrows);
1411
+ setVis(noseBridgeMesh, !!config.minimalNose);
1412
+ setVis(noseLeftMesh, !!config.minimalNose);
1413
+ setVis(noseRightMesh, !!config.minimalNose);
1282
1414
  }
1283
1415
  function applyPupilColor(hex) {
1284
1416
  config.pupilColor = hex;
@@ -1300,10 +1432,6 @@
1300
1432
  config.irisColor = hex;
1301
1433
  if (irisMat) irisMat.emissiveColor = BABYLON.Color3.FromHexString(hex);
1302
1434
  }
1303
- function applyBrowColor(hex) {
1304
- config.browColor = hex;
1305
- browMat.emissiveColor = BABYLON.Color3.FromHexString(hex);
1306
- }
1307
1435
 
1308
1436
  /* ── views ── */
1309
1437
  const VIEWS = {
@@ -1335,8 +1463,12 @@
1335
1463
  applyFadeColor(config.fadeColor);
1336
1464
  applyLineColor(config.lineColor);
1337
1465
  applyBrowColor(config.browColor);
1466
+ if (config.mouthColor) applyMouthColor(config.mouthColor);
1467
+ if (config.eyeColor) applyEyeColor(config.eyeColor);
1468
+ if (config.noseColor) applyNoseColor(config.noseColor);
1338
1469
  applyPupilColor(config.pupilColor);
1339
1470
  applyIrisColor(config.irisColor);
1471
+ applyMinimalSubVisibility();
1340
1472
  applyGlow();
1341
1473
  setView(config.cameraView);
1342
1474
 
@@ -1373,6 +1505,15 @@
1373
1505
  if (rc.eyeHoleSize !== undefined && rc.eyeHoleSize !== config.eyeHoleSize) needRebuild = true;
1374
1506
  if (rc.eyeDepth !== undefined && rc.eyeDepth !== config.eyeDepth) needRebuild = true;
1375
1507
 
1508
+ // any per-feature thickness change requires rebuilding the affected
1509
+ // tubes (CreateTube radius is fixed at construction)
1510
+ const featureThicknessChanged =
1511
+ rc.lineThickness !== undefined ||
1512
+ rc.mouthLineThickness !== undefined ||
1513
+ rc.eyeLineThickness !== undefined ||
1514
+ rc.noseLineThickness !== undefined ||
1515
+ rc.browLineThickness !== undefined;
1516
+
1376
1517
  Object.assign(config, rc);
1377
1518
  if (p.lineColor) applyLineColor(p.lineColor);
1378
1519
  if (p.pupilColor) applyPupilColor(p.pupilColor);
@@ -1382,6 +1523,9 @@
1382
1523
  if (rc.pupilColor) applyPupilColor(rc.pupilColor);
1383
1524
  if (rc.irisColor) applyIrisColor(rc.irisColor);
1384
1525
  if (rc.browColor) applyBrowColor(rc.browColor);
1526
+ if (rc.mouthColor !== undefined) applyMouthColor(rc.mouthColor);
1527
+ if (rc.eyeColor !== undefined) applyEyeColor(rc.eyeColor);
1528
+ if (rc.noseColor !== undefined) applyNoseColor(rc.noseColor);
1385
1529
 
1386
1530
  if (needRebuild) {
1387
1531
  rebuildMesh();
@@ -1393,10 +1537,15 @@
1393
1537
  applyFaceFlip();
1394
1538
  applyMeshVisibility();
1395
1539
  applyMinimalVisibility();
1396
- if (rc.lineThickness !== undefined) rebuildMinimalLines();
1540
+ if (featureThicknessChanged) rebuildMinimalLines();
1397
1541
  if (rc.irisSize !== undefined || rc.pupils !== undefined) rebuildPupils();
1398
1542
  if (rc.lipVertAmp !== undefined || rc.lipPressForce !== undefined) identifyAnchorRings();
1399
1543
  }
1544
+ // per-feature visibility toggles always apply (cheap; no rebuild)
1545
+ if (rc.minimalMouth !== undefined || rc.minimalEyes !== undefined ||
1546
+ rc.minimalNose !== undefined || rc.minimalBrows !== undefined) {
1547
+ applyMinimalSubVisibility();
1548
+ }
1400
1549
  if (rc.glow !== undefined) applyGlow();
1401
1550
  // channel gains
1402
1551
  if (p.channelGains) {