@ikijs/editor 0.3.1 → 0.4.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/dist/index.mjs CHANGED
@@ -1841,8 +1841,58 @@ var HAIR_FRONT_DEPTH = 0.1;
1841
1841
  var HAIR_BACK_DEPTH = -0.08;
1842
1842
  var NOD_TRAVEL = 30;
1843
1843
  var NOD_BEND = 0.5;
1844
- var HAIR_BACK_NOD_DEPTH = -0.07;
1844
+ var HAIR_BACK_NOD_DEPTH = -0.135;
1845
+ function headNodParallaxUnit(gridHalfHeight) {
1846
+ return gridHalfHeight * HEAD_CYLINDER_RADIUS_FACTOR * Math.sin(HEAD_TURN_MAX_DEG * NOD_BEND * (Math.PI / 180));
1847
+ }
1848
+ var FEATURE_DEPTH = {
1849
+ eye: 0.04,
1850
+ iris: 0.04,
1851
+ pupil: 0.04,
1852
+ highlight: 0.04,
1853
+ lash: 0.04,
1854
+ brow: 0.04,
1855
+ blush: 0.04,
1856
+ mouth: 0.04,
1857
+ mouth_open: 0.04,
1858
+ nose: 0.08
1859
+ };
1860
+ var HAIR_FRONT_NOD_DEPTH = FEATURE_DEPTH.brow;
1861
+ function roleFamily(role) {
1862
+ return role.replace(/_[LR]$/, "");
1863
+ }
1864
+ function featureParallaxBindings(role, options) {
1865
+ if (!options.hasNose) return [];
1866
+ const depth = FEATURE_DEPTH[roleFamily(role)];
1867
+ if (depth === void 0) return [];
1868
+ const bindings = [];
1869
+ const shiftX = depth * (options.parallaxUnit ?? 0);
1870
+ if (shiftX !== 0) {
1871
+ bindings.push({
1872
+ parameter: StandardParameter.AngleX,
1873
+ channel: "translateX",
1874
+ from: -shiftX,
1875
+ to: shiftX
1876
+ });
1877
+ }
1878
+ const shiftY = depth * (options.parallaxUnitY ?? 0);
1879
+ if (shiftY !== 0) {
1880
+ bindings.push({
1881
+ parameter: StandardParameter.AngleY,
1882
+ channel: "translateY",
1883
+ from: -shiftY,
1884
+ to: shiftY
1885
+ });
1886
+ }
1887
+ return bindings;
1888
+ }
1845
1889
  function bindingsForRole(spec, role, cropW, cropH, options = {}) {
1890
+ return [
1891
+ ...roleOwnBindings(spec, role, cropW, cropH, options),
1892
+ ...featureParallaxBindings(role, options)
1893
+ ];
1894
+ }
1895
+ function roleOwnBindings(spec, role, cropW, cropH, options) {
1846
1896
  const isEyeStack = EYE_STACK_PREFIXES.some((p) => role.startsWith(p));
1847
1897
  if (isEyeStack && spec.eyeSide !== void 0) {
1848
1898
  const isGazeRole = role.startsWith("iris_") || role.startsWith("pupil_") || role.startsWith("highlight_");
@@ -1956,7 +2006,8 @@ function bindingsForRole(spec, role, cropW, cropH, options = {}) {
1956
2006
  });
1957
2007
  }
1958
2008
  }
1959
- const shiftY = (isFront ? 0 : HAIR_BACK_NOD_DEPTH) * (options.parallaxUnitY ?? 0);
2009
+ const frontDepth = options.hasNose ? HAIR_FRONT_NOD_DEPTH : 0;
2010
+ const shiftY = (isFront ? frontDepth : HAIR_BACK_NOD_DEPTH) * (options.parallaxUnitY ?? 0);
1960
2011
  if (shiftY !== 0) {
1961
2012
  parallax.push({
1962
2013
  parameter: StandardParameter.AngleY,
@@ -2052,6 +2103,7 @@ function generateIkiFromLayerSet(layers, canvas) {
2052
2103
  validateLayerInputs(layers, canvas);
2053
2104
  const hasHair = layers.some((l) => l.role === "hair_front");
2054
2105
  const hasMouthOpen = layers.some((l) => l.role === "mouth_open");
2106
+ const hasNose = layers.some((l) => l.role === "nose");
2055
2107
  const bodyLayer = layers.find((l) => l.role === "body");
2056
2108
  const parameters = [
2057
2109
  {
@@ -2230,7 +2282,7 @@ function generateIkiFromLayerSet(layers, canvas) {
2230
2282
  const faceCenterY = faceTransform.y;
2231
2283
  const halfH = Math.max(faceCenterY - unionMinY, unionMaxY - faceCenterY);
2232
2284
  const parallaxUnit = headTurnParallaxUnit(halfW);
2233
- const parallaxUnitY = headTurnParallaxUnit(halfH);
2285
+ const parallaxUnitY = headNodParallaxUnit(halfH);
2234
2286
  const faceBottom = faceTransform.y - faceCropH / 2;
2235
2287
  const neckPivot = {
2236
2288
  x: faceCenterX,
@@ -2351,7 +2403,8 @@ function generateIkiFromLayerSet(layers, canvas) {
2351
2403
  const roleBindings = bindingsForRole(spec, role, cropW, cropH, {
2352
2404
  hasMouthOpen,
2353
2405
  parallaxUnit,
2354
- parallaxUnitY
2406
+ parallaxUnitY,
2407
+ hasNose
2355
2408
  });
2356
2409
  const deformerId = spec.deformer === "none" ? void 0 : spec.deformer;
2357
2410
  if (spec.mesh) {