{
  "version": 1,
  "description": "A workshop motor on a small cast base. Separate bakes feed the layer stack, with a local oil stain under the motor.",
  "params": {
    "wear": {"type": "float", "default": 0.5, "min": 0, "max": 1, "step": 0.05, "label": "wear", "desc": "chipped and worn paint"},
    "dirt": {"type": "float", "default": 0.5, "min": 0, "max": 1, "step": 0.05, "label": "dirt", "desc": "grime and dust"},
    "age": {"type": "float", "default": 0.5, "min": 0, "max": 1, "step": 0.05, "label": "age", "desc": "how long the surface has been exposed"},
    "resolution": {"type": "enum", "options": [256, 512, 1024], "default": 512, "label": "resolution", "desc": "pixels along each side of the maps"},
    "seed": {"type": "int", "default": 1, "min": 0, "max": 9999, "label": "seed", "desc": "changes where the marks appear"}
  },
  "vars": {"wear": 0.5, "dirt": 0.5, "age": 0.5, "resolution": 512, "seed": 1},
  "meta": {"render": {"views": ["persp"], "azimuth": 33, "elevation": 32, "size": "880x900", "shading": "pbr", "textures": true, "grid": false, "view_labels": false, "footer": false}},
  "nodes": {
    "base_plate_shape": {"type": "box", "params": {"size": [0.69, 0.08, 0.46], "center": [0, 0.04, 0]}},
    "base_plate_chamfer": {"type": "poly_bevel", "in": ["base_plate_shape"], "params": {"offset": 0.018}},
    "base_plate": {"type": "attrib_create", "in": ["base_plate_chamfer"], "params": {"name": "name", "class": "prim", "value": "base_plate"}},
    "pedestal_shape": {"type": "box", "params": {"size": [0.52, 0.064, 0.338], "center": [0.025, 0.09, -0.028]}},
    "pedestal_chamfer": {"type": "poly_bevel", "in": ["pedestal_shape"], "params": {"offset": 0.012}},
    "pedestal": {"type": "attrib_create", "in": ["pedestal_chamfer"], "params": {"name": "name", "class": "prim", "value": "pedestal"}},
    "motor_saddle_shape": {"type": "box", "params": {"size": [0.29, 0.085, 0.225], "center": [0.034, 0.145, -0.04]}},
    "motor_saddle_chamfer": {"type": "poly_bevel", "in": ["motor_saddle_shape"], "params": {"offset": 0.012}},
    "motor_saddle": {"type": "attrib_create", "in": ["motor_saddle_chamfer"], "params": {"name": "name", "class": "prim", "value": "motor_saddle"}},
    "motor_shape": {"type": "tube", "params": {"axis": "x", "radius": 0.134, "height": 0.294, "center": [0.002, 0.279, -0.05], "cols": 24}},
    "motor": {"type": "attrib_create", "in": ["motor_shape"], "params": {"name": "name", "class": "prim", "value": "motor"}},
    "motor_cap_shape": {"type": "tube", "params": {"axis": "x", "radius": 0.14, "height": 0.045, "center": [0.161, 0.279, -0.05], "cols": 24, "radius_top": 0.123}},
    "motor_cap": {"type": "attrib_create", "in": ["motor_cap_shape"], "params": {"name": "name", "class": "prim", "value": "motor_cap"}},
    "drive_housing_shape": {"type": "tube", "params": {"axis": "x", "radius": 0.109, "height": 0.091, "center": [-0.181, 0.279, -0.05], "cols": 20, "radius_top": 0.12}},
    "drive_housing": {"type": "attrib_create", "in": ["drive_housing_shape"], "params": {"name": "name", "class": "prim", "value": "drive_housing"}},
    "drive_hub_shape": {"type": "tube", "params": {"axis": "x", "radius": 0.06, "height": 0.048, "center": [-0.241, 0.279, -0.05], "cols": 20}},
    "drive_hub": {"type": "attrib_create", "in": ["drive_hub_shape"], "params": {"name": "name", "class": "prim", "value": "drive_hub"}},
    "cooling_fin_1_shape": {"type": "tube", "params": {"axis": "x", "radius": 0.145, "height": 0.012, "center": [0.11, 0.279, -0.05], "cols": 20}},
    "cooling_fin_1": {"type": "attrib_create", "in": ["cooling_fin_1_shape"], "params": {"name": "name", "class": "prim", "value": "cooling_fin_1"}},
    "cooling_fin_2_shape": {"type": "tube", "params": {"axis": "x", "radius": 0.145, "height": 0.012, "center": [0.057, 0.279, -0.05], "cols": 20}},
    "cooling_fin_2": {"type": "attrib_create", "in": ["cooling_fin_2_shape"], "params": {"name": "name", "class": "prim", "value": "cooling_fin_2"}},
    "cooling_fin_3_shape": {"type": "tube", "params": {"axis": "x", "radius": 0.145, "height": 0.012, "center": [0.004, 0.279, -0.05], "cols": 20}},
    "cooling_fin_3": {"type": "attrib_create", "in": ["cooling_fin_3_shape"], "params": {"name": "name", "class": "prim", "value": "cooling_fin_3"}},
    "cooling_fin_4_shape": {"type": "tube", "params": {"axis": "x", "radius": 0.145, "height": 0.012, "center": [-0.049, 0.279, -0.05], "cols": 20}},
    "cooling_fin_4": {"type": "attrib_create", "in": ["cooling_fin_4_shape"], "params": {"name": "name", "class": "prim", "value": "cooling_fin_4"}},
    "cooling_fin_5_shape": {"type": "tube", "params": {"axis": "x", "radius": 0.145, "height": 0.012, "center": [-0.102, 0.279, -0.05], "cols": 20}},
    "cooling_fin_5": {"type": "attrib_create", "in": ["cooling_fin_5_shape"], "params": {"name": "name", "class": "prim", "value": "cooling_fin_5"}},
    "terminal_box_shape": {"type": "box", "params": {"size": [0.158, 0.071, 0.148], "center": [-0.023, 0.426, -0.053]}},
    "terminal_box_chamfer": {"type": "poly_bevel", "in": ["terminal_box_shape"], "params": {"offset": 0.012, "divisions": 1}},
    "terminal_box": {"type": "attrib_create", "in": ["terminal_box_chamfer"], "params": {"name": "name", "class": "prim", "value": "terminal_box"}},
    "switch_box_shape": {"type": "box", "params": {"size": [0.133, 0.124, 0.065], "center": [-0.192, 0.159, 0.123]}},
    "switch_box_chamfer": {"type": "poly_bevel", "in": ["switch_box_shape"], "params": {"offset": 0.009}},
    "switch_box": {"type": "attrib_create", "in": ["switch_box_chamfer"], "params": {"name": "name", "class": "prim", "value": "switch_box"}},
    "switch_plate_shape": {"type": "box", "params": {"size": [0.097, 0.084, 0.012], "center": [-0.192, 0.166, 0.157]}},
    "switch_plate_chamfer": {"type": "poly_bevel", "in": ["switch_plate_shape"], "params": {"offset": 0.003}},
    "switch_plate": {"type": "attrib_create", "in": ["switch_plate_chamfer"], "params": {"name": "name", "class": "prim", "value": "switch_plate"}},
    "switch_shape": {"type": "tube", "params": {"axis": "z", "radius": 0.025, "height": 0.016, "center": [-0.192, 0.169, 0.169], "cols": 16}},
    "switch": {"type": "attrib_create", "in": ["switch_shape"], "params": {"name": "name", "class": "prim", "value": "switch"}},
    "lever_pivot_shape": {"type": "tube", "params": {"axis": "z", "radius": 0.035, "height": 0.024, "center": [0.195, 0.158, 0.137], "cols": 16}},
    "lever_pivot": {"type": "attrib_create", "in": ["lever_pivot_shape"], "params": {"name": "name", "class": "prim", "value": "lever_pivot"}},
    "lever_shape": {"type": "box", "params": {"size": [0.026, 0.162, 0.02], "center": [0, 0, 0]}},
    "lever_chamfer": {"type": "poly_bevel", "in": ["lever_shape"], "params": {"offset": 0.006, "divisions": 1}},
    "lever_placed": {"type": "transform", "in": ["lever_chamfer"], "params": {"rotate": [0, 0, -33], "translate": [0.233, 0.213, 0.158]}},
    "lever": {"type": "attrib_create", "in": ["lever_placed"], "params": {"name": "name", "class": "prim", "value": "lever"}},
    "lever_grip_shape": {"type": "box", "params": {"size": [0.047, 0.059, 0.032], "center": [0, 0, 0]}},
    "lever_grip_chamfer": {"type": "poly_bevel", "in": ["lever_grip_shape"], "params": {"offset": 0.008, "divisions": 1}},
    "lever_grip_placed": {"type": "transform", "in": ["lever_grip_chamfer"], "params": {"rotate": [0, 0, -33], "translate": [0.279, 0.282, 0.158]}},
    "lever_grip": {"type": "attrib_create", "in": ["lever_grip_placed"], "params": {"name": "name", "class": "prim", "value": "lever_grip"}},
    "handle_left_shape": {"type": "box", "params": {"size": [0.024, 0.058, 0.025], "center": [-0.137, 0.469, -0.048]}},
    "handle_left_chamfer": {"type": "poly_bevel", "in": ["handle_left_shape"], "params": {"offset": 0.004}},
    "handle_left": {"type": "attrib_create", "in": ["handle_left_chamfer"], "params": {"name": "name", "class": "prim", "value": "handle_left"}},
    "handle_right_shape": {"type": "box", "params": {"size": [0.024, 0.058, 0.025], "center": [0.087, 0.469, -0.048]}},
    "handle_right_chamfer": {"type": "poly_bevel", "in": ["handle_right_shape"], "params": {"offset": 0.004}},
    "handle_right": {"type": "attrib_create", "in": ["handle_right_chamfer"], "params": {"name": "name", "class": "prim", "value": "handle_right"}},
    "handle_grip_shape": {"type": "box", "params": {"size": [0.248, 0.031, 0.034], "center": [-0.025, 0.498, -0.048]}},
    "handle_grip_chamfer": {"type": "poly_bevel", "in": ["handle_grip_shape"], "params": {"offset": 0.008, "divisions": 1}},
    "handle_grip": {"type": "attrib_create", "in": ["handle_grip_chamfer"], "params": {"name": "name", "class": "prim", "value": "handle_grip"}},
    "bolt_front_left_shape": {"type": "tube", "params": {"axis": "y", "radius": 0.015, "height": 0.013, "center": [-0.292, 0.084, 0.18], "cols": 6}},
    "bolt_front_left": {"type": "attrib_create", "in": ["bolt_front_left_shape"], "params": {"name": "name", "class": "prim", "value": "bolt_front_left"}},
    "bolt_front_right_shape": {"type": "tube", "params": {"axis": "y", "radius": 0.015, "height": 0.013, "center": [0.292, 0.084, 0.18], "cols": 6}},
    "bolt_front_right": {"type": "attrib_create", "in": ["bolt_front_right_shape"], "params": {"name": "name", "class": "prim", "value": "bolt_front_right"}},
    "bolt_back_left_shape": {"type": "tube", "params": {"axis": "y", "radius": 0.015, "height": 0.013, "center": [-0.292, 0.084, -0.18], "cols": 6}},
    "bolt_back_left": {"type": "attrib_create", "in": ["bolt_back_left_shape"], "params": {"name": "name", "class": "prim", "value": "bolt_back_left"}},
    "bolt_back_right_shape": {"type": "tube", "params": {"axis": "y", "radius": 0.015, "height": 0.013, "center": [0.292, 0.084, -0.18], "cols": 6}},
    "bolt_back_right": {"type": "attrib_create", "in": ["bolt_back_right_shape"], "params": {"name": "name", "class": "prim", "value": "bolt_back_right"}},
    "prop_parts": {"type": "merge", "in": ["base_plate", "pedestal", "motor_saddle", "motor", "motor_cap", "drive_housing", "drive_hub", "cooling_fin_1", "cooling_fin_2", "cooling_fin_3", "cooling_fin_4", "cooling_fin_5", "terminal_box", "switch_box", "switch_plate", "switch", "lever_pivot", "lever", "lever_grip", "handle_left", "handle_right", "handle_grip", "bolt_front_left", "bolt_front_right", "bolt_back_left", "bolt_back_right"]},
    "enamel": {"type": "material", "in": ["prop_parts"], "params": {"name": "enamel", "base_color": "#596c58", "roughness": 0.45, "metallic": 0, "kind": "painted_metal"}},
    "controls": {"type": "material", "in": ["enamel"], "params": {"name": "controls", "group": "@name=handle* @name=lever*", "base_color": "#536958", "roughness": 0.38, "metallic": 0, "kind": "painted_metal"}},
    "trim": {"type": "material", "in": ["controls"], "params": {"name": "trim", "group": "@name=switch_plate @name=drive_hub @name=bolt_*", "base_color": "#8b9390", "roughness": 0.5, "metallic": 0.7, "kind": "stainless"}},
    "switch_material": {"type": "material", "in": ["trim"], "params": {"name": "switch_material", "group": "@name=switch", "base_color": "#632c20", "roughness": 0.55, "metallic": 0, "kind": "plastic"}},
    "handled": {"type": "group", "in": ["switch_material"], "params": {"name": "handled", "class": "prim", "pattern": "@name=handle* @name=lever @name=lever_grip"}},
    "normals": {"type": "normal", "in": ["handled"], "params": {"class": "vertex", "cusp_angle": 45}},
    "unwrap": {"type": "uv_unwrap", "in": ["normals"], "params": {"resolution": 512, "padding": 5, "iterations": 1}},
    "part_ids": {"type": "wrangle", "in": ["unwrap"], "params": {"run_over": "prims", "code": "let id = 0; for (const c of s@name) id = (id * 31 + c.charCodeAt(0)) % 997; f@wpart = id / 997;"}},
    "atlas": {"type": "uv_layout", "in": ["part_ids"], "params": {"resolution": "=resolution", "padding": 6, "iterations": 1, "visibility_weight": 1}},
    "base": {"type": "bake_material", "in": ["atlas"], "params": {"resolution": "=resolution", "padding": 3, "uv_attrib": "uv", "map_uv": "uv", "kinds": {}, "name": "base", "masks": "kinds"}},
    "measure": {"type": "bake_measure", "in": ["atlas"], "params": {
      "resolution": "=resolution",
      "padding": 3,
      "uv_attrib": "uv",
      "measures": [
        {"by": "occlusion", "name": "occ"},
        {"by": "cavity", "name": "cav", "max_distance": 0.02},
        {"by": "facing", "name": "top", "min": 0, "max": 20, "falloff": 25},
        {"by": "facing", "name": "sun", "direction": [0, 1, 0], "min": 0, "max": 45, "falloff": 90},
        {"by": "height", "name": "ht"}
      ],
      "samples": 4,
      "name": "m"
    }},
    "noise": {"type": "bake_measure", "in": ["atlas"], "params": {
      "resolution": "=resolution",
      "padding": 3,
      "uv_attrib": "uv",
      "seed": "=seed",
      "name": "n",
      "measures": [
        {"by": "noise", "name": "patch", "size": [0.12, 0.12, 0.12]},
        {"by": "noise", "name": "grain", "size": [0.0032, 0.0032, 0.0032], "octaves": 3},
        {"by": "noise", "name": "blotch", "size": [0.32, 0.32, 0.32]},
        {"by": "noise", "name": "ragged", "size": [0.024, 0.024, 0.024]}
      ]
    }},
    "wear": {"type": "bake_edge_wear", "in": ["atlas"], "params": {"resolution": "=resolution", "padding": 3, "uv_attrib": "uv", "name": "ew", "amount": "=min(1, wear * (0.5 + 1.65 * age))", "radius": 0.015, "reach": 0.024, "chip_size": 0.0048, "patch_size": 0.12, "seed": "=seed", "focus": "handled", "focus_radius": 0.048, "focus_amount": 0.95}},
    "parts": {"type": "bake_mask", "in": ["atlas"], "params": {"resolution": "=resolution", "padding": 3, "uv_attrib": "uv", "attrib": "wpart", "name": "part"}},
    "parts_kept": {"type": "tex_compact", "in": ["parts"], "params": {"keep": "C", "half": ""}},
    "wear_kept": {"type": "tex_compact", "in": ["wear"], "params": {"keep": "C chip bare concave handled", "half": "*"}},
    "noise_kept": {"type": "tex_compact", "in": ["noise"], "params": {"keep": "C patch grain blotch ragged", "half": "*"}},
    "measure_kept": {"type": "tex_compact", "in": ["measure"], "params": {"keep": "C occ cav top sun ht", "half": "*"}},
    "oil_position": {"type": "bake_position", "in": ["atlas"], "params": {"resolution": "=resolution", "padding": 0, "name": "position", "mode": "world"}},
    "mask_images": {"type": "merge", "in": ["measure_kept", "noise_kept", "wear_kept", "parts_kept", "oil_position"]},
    "stack": {"type": "tex_layers", "in": ["base", "mask_images"], "params": {
      "masks": [
        {"name": "pv", "mask": "0.8 + 0.4 * frac(part * 13.37 + seed * 0.618)", "write": false},
        {"name": "occlusion", "mask": "m_occ"},
        {"name": "cavity", "mask": "clamp(m_cav * 1.4 + ew_concave * 0.6, 0, 1)"},
        {"name": "handled", "mask": "ew_handled"},
        {"name": "edge_wear", "mask": "ew"},
        {"name": "chip", "mask": "ew_chip"},
        {"name": "bare", "mask": "ew_bare"},
        {"name": "blotch", "mask": "n_blotch"},
        {"name": "grain", "mask": "n_grain"},
        {"name": "patch_mix", "mask": "n_patch * 0.6 + n_blotch * 0.4", "write": false},
        {"name": "grime", "mask": "clamp((dirt * (0.35 + 1.3 * age)) * (cavity * 1.7 + (1 - m_occ) * 1.35) * (0.4 + 0.9 * n_blotch) * (0.7 + 0.6 * (1 - m_ht)) * pv + handled * (dirt * (0.35 + 1.3 * age)) * 0.22 * n_patch, 0, 1)"},
        {"name": "dust", "mask": "clamp((dirt * (0.35 + 1.3 * age)) * smoothstep(0.15, 0.8, m_top) * (0.4 + 1.1 * n_grain), 0, 1) * (1 - grime)"},
        {"name": "fade", "mask": "clamp((age * 0.1) * m_sun * m_occ * (0.7 + 0.6 * n_blotch), 0, 1)"},
        {"name": "oil_extent", "write": false, "mask": "sqrt(pow((position_r - 0.065) / 0.24, 2) + pow((position_b - 0.008) / 0.19, 2)) + (n_ragged - 0.5) * 0.32 + 0.06 * sin(position_r * 46 + position_b * 22)"},
        {"name": "oil", "mask": "clamp((dirt * (0.35 + 1.3 * age)) * (1.5 + n_blotch), 0, 1) * (1 - smoothstep(0.65, 0.99, oil_extent)) * smoothstep(0.095, 0.108, position_g) * (1 - smoothstep(0.118, 0.17, position_g)) * m_top"}
      ],
      "layers": [
        {"name": "painted_metal_fade", "mask": "base_kind_painted_metal * fade", "color": "#d6d2c8", "opacity": 0.55, "roughness_offset": 0.25},
        {"name": "painted_metal_primer", "mask": "base_kind_painted_metal * chip", "color": "#8e8b84", "roughness": 0.75, "metallic": 0, "height": -0.00004},
        {"name": "painted_metal_bare", "mask": "base_kind_painted_metal * bare * (0.2 + 0.8 * handled)", "color": "#d6dad5", "roughness": 0.33, "metallic": 1, "height": -0.00008},
        {"name": "stainless_smudge", "mask": "base_kind_stainless * handled * n_patch * clamp((wear * (0.5 + 1.65 * age)) * 2, 0, 1)", "roughness_offset": 0.15},
        {"name": "plastic_chalk", "mask": "base_kind_plastic * fade", "color": "#d9d6cf", "opacity": 0.4, "roughness_offset": 0.3},
        {"name": "plastic_scuff", "mask": "base_kind_plastic * chip", "color": "#ffffff", "opacity": 0.15, "roughness": 0.75},
        {"name": "film", "mask": "(1 - occlusion) * clamp((dirt * (0.35 + 1.3 * age)), 0, 1)", "color": [0.86, 0.86, 0.86], "color_mode": "multiply", "roughness_offset": 0.1},
        {"name": "grime_film", "mask": "clamp((dirt * (0.35 + 1.3 * age)) * 1.3, 0, 1) * (0.3 + 0.7 * smoothstep(0.2, 0.8, patch_mix))", "color": [0.86, 0.84, 0.81], "color_mode": "multiply", "roughness_offset": 0.06},
        {"name": "bottom", "mask": "clamp((dirt * (0.35 + 1.3 * age)) * 1.4, 0, 1) * (1 - smoothstep(0.0, 0.1 + 0.08 * n_ragged + 0.05 * n_patch, m_ht)) * (0.7 + 0.3 * n_blotch)", "color": [0.8, 0.77, 0.73], "color_mode": "multiply", "roughness_offset": 0.05},
        {"name": "soil", "mask": "clamp((dirt * (0.35 + 1.3 * age)) * (0.35 + 0.6 * blotch) * (0.6 + 0.7 * (1 - m_ht)), 0, 1)", "color": [0.84, 0.82, 0.78], "color_mode": "multiply", "roughness_offset": 0.05},
        {"name": "grime", "mask": "grime", "color": "#211610", "roughness": 0.35, "metallic": 0},
        {"name": "dust", "mask": "dust", "color": "#aaa9a0", "roughness": 0.95, "metallic": 0},
        {"name": "blotch", "mask": "(blotch * 2 - 1) * clamp((dirt * (0.35 + 1.3 * age)) + min(1, age * 1.25), 0, 1)", "signed": true, "roughness_offset": 0.07},
        {"name": "grain", "mask": "(grain * 2 - 1) * clamp((dirt * (0.35 + 1.3 * age)) + min(1, age * 1.25), 0, 1)", "signed": true, "roughness_offset": 0.05},
        {"name": "oil_stain", "mask": "oil", "color": [[0, "#302119"], [1, "#140e0a"]], "color_by": "n_blotch", "roughness": 0.35, "metallic": 0}
      ],
      "outputs": "both",
      "padding": 3,
      "name": "weathered",
      "occlusion": "occlusion"
    }},
    "one_material": {"type": "attrib_delete", "in": ["atlas"], "params": {"names": "materials", "class": "detail"}},
    "weathered": {"type": "texture_to_material", "in": ["one_material", "stack"], "params": {"material": "weathered", "base_color": "weathered_base_color", "normal": "weathered_normal", "orm": "weathered_orm"}},
    "checked_maps": {"type": "assert", "in": ["weathered"], "params": {"label": "maps", "images": "weathered_base_color weathered_normal weathered_orm", "image_size": "=resolution", "image_layers": "C", "attrib": "material", "attrib_class": "prim", "on_fail": "error"}},
    "checked_machine": {"type": "assert", "in": ["checked_maps"], "params": {"label": "uv", "uv_overlaps": 0, "on_fail": "error"}},
    "mask_image": {"type": "tex_output", "in": ["stack"], "params": {"image": "weathered_masks", "name": "weathered_masks", "keep_only": true}},
    "checked_masks": {"type": "assert", "in": ["mask_image"], "params": {"label": "masks", "images": "weathered_masks", "image_layers": "edge_wear handled cavity dust", "image_size": "=resolution", "on_fail": "error"}}
  },
  "output": "checked_machine",
  "outputs": {
    "machine": {"node": "checked_machine", "label": "Worn machine", "kind": "mesh", "tags": ["machine", "paint", "weathering"]},
    "masks": {"node": "checked_masks", "label": "Weathering masks", "kind": "textures", "tags": ["weathering", "masks", "baked"]}
  }
}
