{
  "schema": "vextor.vxl.v1",
  "id": "leaf_leaf_tray",
  "units": {"angle": "deg", "length": "mm"},
  "needs": [
    {"id": "closed", "source": "user", "text": "The leaf tray is a closed outward two-manifold mesh."},
    {"id": "one", "source": "user", "text": "The leaf tray has one connected component."},
    {"id": "bottom", "source": "user", "text": "The central bottom contact region lies on Z0 within 0.08 mm."},
    {"id": "wall", "source": "user", "text": "Material depth above the admitted bottom station is at least 2.4 mm."}
  ],
  "params": [
    {"id": "height", "domain": ["12", "18"], "type": "length", "value": "18"},
    {"id": "amplitude", "domain": ["0", "0.7"], "type": "length", "value": "0.45"},
    {"id": "level", "domain": ["0", "3"], "type": "count", "value": "2"},
    {"id": "texture", "domain": ["false", "true"], "type": "bool", "value": true},
    {"id": "chord", "domain": ["0.035", "1"], "type": "length", "value": "0.035"}
  ],
  "functions": [
    {
      "id": "fade",
      "expr": "smoothstep(0,1,t)",
      "params": [
        {"id": "t", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "leaf_width",
      "expr": "45.35*(0.15+0.85*exp(0.72*ln(max(1e-30,1-exp(1.8*ln(max(1e-30,min(1,abs(x)/75.1))))))))",
      "params": [
        {"id": "x", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "leaf_x",
      "expr": "75.1*(-1+i/4)-sign(i-4)*4*(-1+j/3)^2*floor(abs(i-4)/4)",
      "params": [
        {"id": "i", "type": "unitless"},
        {"id": "j", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "leaf_y",
      "expr": "leaf_width(leaf_x(i,j))*(-1+j/3)",
      "params": [
        {"id": "i", "type": "unitless"},
        {"id": "j", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "top_z",
      "expr": "4.8+(h-4.8)*fade(max(max(0,(abs(x)-40)/35.1),max(0,(abs(y)-31)/max(1,leaf_width(x)-31))))",
      "params": [
        {"id": "x", "type": "unitless"},
        {"id": "y", "type": "unitless"},
        {"id": "h", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "slope_x",
      "expr": "(top_z(x+0.0001,y,h)-top_z(x-0.0001,y,h))/0.0002",
      "params": [
        {"id": "x", "type": "unitless"},
        {"id": "y", "type": "unitless"},
        {"id": "h", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "slope_y",
      "expr": "(top_z(x,y+0.0001,h)-top_z(x,y-0.0001,h))/0.0002",
      "params": [
        {"id": "x", "type": "unitless"},
        {"id": "y", "type": "unitless"},
        {"id": "h", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "normal_length",
      "expr": "sqrt(slope_x(x,y,h)^2+slope_y(x,y,h)^2+1)",
      "params": [
        {"id": "x", "type": "unitless"},
        {"id": "y", "type": "unitless"},
        {"id": "h", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "skin_x",
      "expr": "x+4.8*t*slope_x(x,y,h)/normal_length(x,y,h)+2.5*t*sign(i-4)*floor(abs(i-4)/4)",
      "lets": [
        {"id": "x", "expr": "leaf_x(i,j)"},
        {"id": "y", "expr": "leaf_y(i,j)"}
      ],
      "params": [
        {"id": "i", "type": "unitless"},
        {"id": "j", "type": "unitless"},
        {"id": "t", "type": "unitless"},
        {"id": "h", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "skin_y",
      "expr": "y+4.8*t*slope_y(x,y,h)/normal_length(x,y,h)+2.5*t*sign(j-3)*floor(abs(j-3)/3)",
      "lets": [
        {"id": "x", "expr": "leaf_x(i,j)"},
        {"id": "y", "expr": "leaf_y(i,j)"}
      ],
      "params": [
        {"id": "i", "type": "unitless"},
        {"id": "j", "type": "unitless"},
        {"id": "t", "type": "unitless"},
        {"id": "h", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "skin_z",
      "expr": "top_z(x,y,h)-4.8*t/normal_length(x,y,h)",
      "lets": [
        {"id": "x", "expr": "leaf_x(i,j)"},
        {"id": "y", "expr": "leaf_y(i,j)"}
      ],
      "params": [
        {"id": "i", "type": "unitless"},
        {"id": "j", "type": "unitless"},
        {"id": "t", "type": "unitless"},
        {"id": "h", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "branch",
      "expr": "0.82*exp(-0.5*((x-a-t*dx)^2+(abs(y)-t*dy)^2)/0.58^2)",
      "lets": [
        {"id": "dx", "expr": "15*sign(a)"},
        {"id": "dy", "expr": "0.76*leaf_width(a)"},
        {"id": "t", "expr": "clamp(((x-a)*dx+abs(y)*dy)/(dx^2+dy^2),0,1)"}
      ],
      "params": [
        {"id": "x", "type": "unitless"},
        {"id": "y", "type": "unitless"},
        {"id": "a", "type": "unitless"}
      ],
      "returns": "unitless"
    },
    {
      "id": "vein_map",
      "expr": "max(mid,branches)*fade(min(75.1-abs(x),leaf_width(x)-abs(y))/4)",
      "lets": [
        {"id": "mid", "expr": "exp(-0.5*((y-1.4*sin(pi*x/150.2*180deg/pi))/0.58)^2)"},
        {"id": "branches", "expr": "max(max(max(branch(x,y,-52),branch(x,y,-36)),max(branch(x,y,-20),branch(x,y,-4))),max(max(branch(x,y,12),branch(x,y,28)),branch(x,y,44)))"}
      ],
      "params": [
        {"id": "x", "type": "unitless"},
        {"id": "y", "type": "unitless"}
      ],
      "returns": "unitless"
    }
  ],
  "variants": [
    {"id": "amplitude_0", "overrides": {"amplitude": 0.0}},
    {"id": "amplitude_0_7", "overrides": {"amplitude": 0.7}},
    {"id": "shallow_12", "overrides": {"height": 12.0}},
    {"id": "cage_level_0", "overrides": {"level": 0.0, "texture": false}},
    {"id": "cage_level_1", "overrides": {"level": 1.0, "texture": false}},
    {"id": "cage_level_2", "overrides": {"level": 2.0, "texture": false}},
    {"id": "cage_level_3", "overrides": {"level": 3.0, "texture": false}},
    {"id": "channel_readback", "overrides": {"level": 1.0, "chord": 1.0}}
  ],
  "parts": [
    {
      "id": "tray",
      "deliver": "body",
      "display_color": "#6F9D58",
      "rep": "mesh",
      "role": "deliverable",
      "steps": [
        {"id": "top", "op": "surface_grid", "rep": "mesh", "bind": "top", "channels": [{"name": "uv", "domain": "corner", "value": ["0.5+leaf_x(v,u)/200", "0.6+leaf_y(v,u)/300"], "seam": {"u": "0"}}, {"name": "mask", "domain": "corner", "value": "0.5+leaf_x(v,u)/200"}, {"name": "material_group", "domain": "corner", "value": "2"}], "creases": ["boundary"], "flip": true, "output": "cage", "poles": {"v_hi": false, "v_lo": false}, "position": ["leaf_x(v,u)*1mm", "leaf_y(v,u)*1mm", "top_z(leaf_x(v,u),leaf_y(v,u),height/1mm)*1mm"], "topology": "quad", "u": {"intervals": "6", "range": ["0", "6"]}, "v": {"intervals": "8", "range": ["0", "8"]}, "wrap": {"u": false, "v": false}},
        {"id": "bottom", "op": "surface_grid", "rep": "mesh", "bind": "bottom_${i}_${j}", "channels": [{"name": "uv", "domain": "corner", "value": ["0.25+skin_x(v,u,1,height/1mm)/400", "0.2+skin_y(v,u,1,height/1mm)/600"], "seam": {"u": "0"}}, {"name": "mask", "domain": "corner", "value": "0.5+skin_x(v,u,1,height/1mm)/200"}, {"name": "material_group", "domain": "corner", "value": "7"}], "flip": false, "output": "cage", "poles": {"v_hi": false, "v_lo": false}, "position": ["skin_x(v,u,1,height/1mm)*1mm", "skin_y(v,u,1,height/1mm)*1mm", "skin_z(v,u,1,height/1mm)*1mm"], "topology": "quad", "u": {"intervals": "4-3*(j-1)*(j-1)", "range": ["max(0,4*j-3)", "min(6,4*j+1)"]}, "v": {"intervals": "4-2*(i-1)*(i-1)", "range": ["max(0,4*i-2)", "min(8,4*i+2)"]}, "wrap": {"u": false, "v": false}, "at_each": [{"in": [["0", "0"], ["0", "1"], ["0", "2"], ["1", "0"], ["1", "2"], ["2", "0"], ["2", "1"], ["2", "2"]], "vars": ["i", "j"]}]},
        {"id": "contact", "op": "surface_grid", "rep": "mesh", "bind": "bottom_1_1", "channels": [{"name": "uv", "domain": "corner", "value": ["0.25+skin_x(v,u,1,height/1mm)/400", "0.2+skin_y(v,u,1,height/1mm)/600"], "seam": {"u": "0"}}, {"name": "mask", "domain": "corner", "value": "0.5+skin_x(v,u,1,height/1mm)/200"}, {"name": "material_group", "domain": "corner", "value": "7"}], "creases": ["boundary"], "flip": false, "output": "cage", "poles": {"v_hi": false, "v_lo": false}, "position": ["skin_x(v,u,1,height/1mm)*1mm", "skin_y(v,u,1,height/1mm)*1mm", "skin_z(v,u,1,height/1mm)*1mm"], "topology": "quad", "u": {"intervals": "4", "range": ["1", "5"]}, "v": {"intervals": "4", "range": ["2", "6"]}, "wrap": {"u": false, "v": false}},
        {"id": "wall_south", "op": "surface_grid", "rep": "mesh", "bind": "south", "channels": [{"name": "uv", "domain": "corner", "value": ["0.5+skin_x(u,0,1-v,height/1mm)/200", "0.6+skin_y(u,0,1-v,height/1mm)/300"], "seam": {"v": "0"}}, {"name": "mask", "domain": "corner", "value": "0.5+skin_x(u,0,1-v,height/1mm)/200"}, {"name": "material_group", "domain": "corner", "value": "2"}], "flip": false, "output": "cage", "poles": {"v_hi": false, "v_lo": false}, "position": ["skin_x(u,0,1-v,height/1mm)*1mm", "skin_y(u,0,1-v,height/1mm)*1mm", "skin_z(u,0,1-v,height/1mm)*1mm"], "topology": "quad", "u": {"intervals": "8", "range": ["0", "8"]}, "v": {"intervals": "1", "range": ["0", "1"]}, "wrap": {"u": false, "v": false}},
        {"id": "wall_north", "op": "surface_grid", "rep": "mesh", "bind": "north", "channels": [{"name": "uv", "domain": "corner", "value": ["0.5+skin_x(8-u,6,1-v,height/1mm)/200", "0.6+skin_y(8-u,6,1-v,height/1mm)/300"], "seam": {"v": "0"}}, {"name": "mask", "domain": "corner", "value": "0.5+skin_x(8-u,6,1-v,height/1mm)/200"}, {"name": "material_group", "domain": "corner", "value": "2"}], "flip": false, "output": "cage", "poles": {"v_hi": false, "v_lo": false}, "position": ["skin_x(8-u,6,1-v,height/1mm)*1mm", "skin_y(8-u,6,1-v,height/1mm)*1mm", "skin_z(8-u,6,1-v,height/1mm)*1mm"], "topology": "quad", "u": {"intervals": "8", "range": ["0", "8"]}, "v": {"intervals": "1", "range": ["0", "1"]}, "wrap": {"u": false, "v": false}},
        {"id": "wall_west", "op": "surface_grid", "rep": "mesh", "bind": "west", "channels": [{"name": "uv", "domain": "corner", "value": ["0.5+skin_x(0,6-u,1-v,height/1mm)/200", "0.6+skin_y(0,6-u,1-v,height/1mm)/300"], "seam": {"v": "0"}}, {"name": "mask", "domain": "corner", "value": "0.5+skin_x(0,6-u,1-v,height/1mm)/200"}, {"name": "material_group", "domain": "corner", "value": "2"}], "flip": false, "output": "cage", "poles": {"v_hi": false, "v_lo": false}, "position": ["skin_x(0,6-u,1-v,height/1mm)*1mm", "skin_y(0,6-u,1-v,height/1mm)*1mm", "skin_z(0,6-u,1-v,height/1mm)*1mm"], "topology": "quad", "u": {"intervals": "6", "range": ["0", "6"]}, "v": {"intervals": "1", "range": ["0", "1"]}, "wrap": {"u": false, "v": false}},
        {"id": "wall_east", "op": "surface_grid", "rep": "mesh", "bind": "east", "channels": [{"name": "uv", "domain": "corner", "value": ["0.5+skin_x(8,u,1-v,height/1mm)/200", "0.6+skin_y(8,u,1-v,height/1mm)/300"], "seam": {"v": "0"}}, {"name": "mask", "domain": "corner", "value": "0.5+skin_x(8,u,1-v,height/1mm)/200"}, {"name": "material_group", "domain": "corner", "value": "2"}], "flip": false, "output": "cage", "poles": {"v_hi": false, "v_lo": false}, "position": ["skin_x(8,u,1-v,height/1mm)*1mm", "skin_y(8,u,1-v,height/1mm)*1mm", "skin_z(8,u,1-v,height/1mm)*1mm"], "topology": "quad", "u": {"intervals": "6", "range": ["0", "6"]}, "v": {"intervals": "1", "range": ["0", "1"]}, "wrap": {"u": false, "v": false}},
        {"id": "join", "op": "combine_meshes", "rep": "mesh", "bind": "control", "sources": ["top", "bottom_0_0", "bottom_0_1", "bottom_0_2", "bottom_1_0", "bottom_1_1", "bottom_1_2", "bottom_2_0", "bottom_2_1", "bottom_2_2", "south", "north", "west", "east"], "closed": true, "weld": {"tolerance": "0.000001mm"}},
        {"id": "cage", "op": "cage", "rep": "mesh", "bind": "body", "source": "control", "levels": "level", "rule": "catmull_clark"},
        {"id": "veins", "op": "displace", "rep": "mesh", "bind": "body", "target": "body", "amplitude": "amplitude", "chord_error": "chord", "direction": "normal", "map": {"expr": "vein_map(x,-y)", "frame": {"origin": ["0", "0"], "size": ["150.2", "90.7"]}, "size": ["128", "96"]}, "mapping": {"frame": {"at": ["0", "0", "0"], "axis": "z", "rotate": "90"}, "kind": "planar", "seam": "shared", "size": ["150.2", "90.7"]}, "max_depth": "3", "min_edge": "0.45", "profile": {"addressing": "clamp", "color_space": "linear", "interpolation": "linear", "neutral": "0"}, "protect": [{"at": ["0", "0", "1"], "expect": ["1", "1000000"], "falloff": "constant", "kind": "halfspace", "normal": "-z"}, {"at": ["67.1", "0", "0"], "expect": ["1", "1000000"], "falloff": "constant", "kind": "halfspace", "normal": "+x"}, {"at": ["-67.1", "0", "0"], "expect": ["1", "1000000"], "falloff": "constant", "kind": "halfspace", "normal": "-x"}], "region": {"expect": ["1", "1000000"], "kind": "all", "regions": [{"angle": "75", "axis": "z", "expect": ["1", "1000000"], "falloff": "constant", "kind": "normal_cone"}, {"at": ["0", "0", "height - 0.7mm"], "expect": ["1", "1000000"], "falloff": "smoothstep", "kind": "halfspace", "normal": "-z", "width": "3"}]}, "when": "texture"}
      ]
    }
  ],
  "requirements": [
    {"id": "r_closed", "kind": "closed_delivered_mesh", "subject": "tray", "artifact": "stl", "covers": ["closed"], "required": true},
    {"id": "r_one", "kind": "component_count", "subject": "tray", "expect": "1", "covers": ["one"], "required": true},
    {"id": "r_bottom", "kind": "flat_region", "subject": "tray", "plane": {"at": ["0", "0", "0"], "normal": "-z"}, "region": {"expect": ["1", "1000000"], "falloff": "constant", "kind": "box", "max": ["30", "15", "0.001"], "min": ["-30", "-15", "-0.001"]}, "tol": "0.08", "covers": ["bottom"], "required": true},
    {"id": "r_wall", "kind": "minimum_wall", "subject": "tray", "disk": {"center": ["3", "2", "0"], "margin": "0.1", "on": {"planar": {"at": "0", "normal": "-z"}, "tol": {"direction": "1e-6", "position": "0.001"}}, "radius": "0.5"}, "min": "2.4", "tol": "0.001", "covers": ["wall"], "required": true},
    {"id": "r_global_wall", "kind": "minimum_wall_mesh", "subject": "tray", "min": "2.4", "required": true}
  ]
}
