{
  "version": 1,
  "description": "Props cut out of pictures. Three pictures (a ring with a hole, round islands and narrow strips; each a shape mask with a grain coloured through a gradient map and the mask as alpha) stand in for pictures loaded with image_file. Each is resized to fit the atlas, its normal and roughness maps come from its own brightness, and its alpha is traced into outlines (outline: how far, in pixels, an outline may stray from the edge), filled, remeshed into even triangles so the card bends smoothly, uv-mapped from the full picture canvas and bent out of flat (bend, metres). The colour, normal and roughness maps of the three are packed side by side into one atlas atlas_size pixels wide and half as tall, with padding pixels of gutter around each picture, and dilated by the same amount so colour bleeds past the shapes; the pictures are sized so that the three of them and their gutters fill the atlas width. Each card's uv is moved into its picture's place in the atlas from the packer's placement points. The cards are copied (copies, stacked and turned), named, and share one double-sided, alpha-masked material carrying the atlas.",
  "params": {
    "outline": {"type": "float", "default": 0.8, "min": 0.2, "max": 4, "step": 0.1, "label": "outline", "desc": "how far the traced outline may stray from the picture's edge, in pixels"},
    "bend": {"type": "float", "default": 0.16, "min": 0, "max": 0.5, "step": 0.01, "label": "bend", "desc": "how far each card bends out of flat, in metres"},
    "copies": {"type": "int", "default": 2, "min": 1, "max": 6, "label": "copies", "desc": "copies of each card, stacked and turned"},
    "padding": {"type": "int", "default": 8, "min": 0, "max": 16, "label": "padding", "desc": "pixels of colour bled around each shape in the atlas"},
    "atlas_size": {"type": "enum", "options": [256, 512, 1024], "default": 512, "label": "atlas size", "desc": "width of the atlas in pixels"}
  },
  "vars": {"outline": 0.8, "bend": 0.16, "copies": 2, "padding": 8, "atlas_size": 512},
  "meta": {"render": {"views": ["persp", "texture"], "texture": "cutouts_color", "textures": true, "shading": "pbr", "azimuth": 30, "elevation": 18, "size": "800x600", "grid": false}},
  "nodes": {
    "ring_mask": {"type": "tex_shape", "params": {"resolution": [256, 256], "texture_size": 1, "shape": "ring", "fill": 0.92, "inner_radius": 0.42, "falloff": 0}},
    "islands_round": {"type": "tex_shape", "params": {"resolution": [256, 256], "texture_size": 1, "shape": "disc", "fill": 0.6, "tile": [2, 2], "falloff": 0}},
    "islands_wobble": {"type": "tex_noise", "params": {"resolution": [64, 64], "feature": 0.5, "octaves": 2, "seed": 5}},
    "islands_warped": {"type": "tex_warp", "in": ["islands_round", "islands_wobble"], "params": {"mode": "slope", "distance": 0.06}},
    "islands_mask": {"type": "tex_threshold", "in": ["islands_warped"], "params": {"threshold": 0.5, "softness": 0.1}},
    "strips_bars": {"type": "tex_shape", "params": {"resolution": [128, 256], "texture_size": 0.5, "shape": "square", "fill": 0.8, "tile": [8, 1], "falloff": 0}},
    "strips_mask": {"type": "tex_threshold", "in": ["strips_bars"], "params": {"threshold": 0.5, "softness": 0.1}},
    "ring_grain": {"type": "tex_noise", "params": {"resolution": [128, 128], "feature": 0.2, "octaves": 4, "seed": 1}},
    "islands_grain": {"type": "tex_noise", "params": {"resolution": [128, 128], "feature": 0.125, "octaves": 4, "seed": 2}},
    "strips_grain": {"type": "tex_gradient", "params": {"resolution": [128, 256], "texture_size": 0.5, "angle": 90}},
    "ring_base": {"type": "tex_channel", "in": [null, null, null, "ring_mask"], "params": {"fill": [0, 0, 0, 1]}},
    "ring_paint": {"type": "tex_colorize", "in": ["ring_grain"], "params": {"ramp": [[0, "#1d4f22"], [0.45, "#357d31"], [0.8, "#62a540"], [1, "#9ccc5a"]]}},
    "ring_picture": {"type": "tex_blend", "in": ["ring_base", "ring_paint"], "params": {"mode": "normal"}},
    "ring_color": {"type": "tex_crop", "in": ["ring_picture"], "params": {"resolution": "=[2 * floor((atlas_size - 6 * padding) / 5), 2 * floor((atlas_size - 6 * padding) / 5)]"}},
    "ring_height": {"type": "tex_channel", "in": ["ring_color"], "params": {"mode": "extract", "channel": "luminance"}},
    "ring_normal": {"type": "tex_normal_from_height", "in": ["ring_height"], "params": {"depth": 0.015, "tileable": false}},
    "ring_roughness": {"type": "tex_levels", "in": ["ring_height"], "params": {"out_low": 0.8, "out_high": 0.55}},
    "islands_base": {"type": "tex_channel", "in": [null, null, null, "islands_mask"], "params": {"fill": [0, 0, 0, 1]}},
    "islands_paint": {"type": "tex_colorize", "in": ["islands_grain"], "params": {"ramp": [[0, "#5d7419"], [0.5, "#98b22c"], [1, "#d4dc68"]]}},
    "islands_picture": {"type": "tex_blend", "in": ["islands_base", "islands_paint"], "params": {"mode": "normal"}},
    "islands_color": {"type": "tex_crop", "in": ["islands_picture"], "params": {"resolution": "=[2 * floor((atlas_size - 6 * padding) / 5), 2 * floor((atlas_size - 6 * padding) / 5)]"}},
    "islands_height": {"type": "tex_channel", "in": ["islands_color"], "params": {"mode": "extract", "channel": "luminance"}},
    "islands_normal": {"type": "tex_normal_from_height", "in": ["islands_height"], "params": {"depth": 0.015, "tileable": false}},
    "islands_roughness": {"type": "tex_levels", "in": ["islands_height"], "params": {"out_low": 0.8, "out_high": 0.55}},
    "strips_base": {"type": "tex_channel", "in": [null, null, null, "strips_mask"], "params": {"fill": [0, 0, 0, 1]}},
    "strips_paint": {"type": "tex_colorize", "in": ["strips_grain"], "params": {"ramp": [[0, "#6e3510"], [0.55, "#b8692a"], [1, "#e8ad55"]]}},
    "strips_picture": {"type": "tex_blend", "in": ["strips_base", "strips_paint"], "params": {"mode": "normal"}},
    "strips_color": {"type": "tex_crop", "in": ["strips_picture"], "params": {"resolution": "=[2 * floor((atlas_size - 6 * padding) / 5) / 2, 2 * floor((atlas_size - 6 * padding) / 5)]"}},
    "strips_height": {"type": "tex_channel", "in": ["strips_color"], "params": {"mode": "extract", "channel": "luminance"}},
    "strips_normal": {"type": "tex_normal_from_height", "in": ["strips_height"], "params": {"depth": 0.015, "tileable": false}},
    "strips_roughness": {"type": "tex_levels", "in": ["strips_height"], "params": {"out_low": 0.8, "out_high": 0.55}},

    "maps": {"type": "merge", "in": ["ring_color", "ring_normal", "ring_roughness", "islands_color", "islands_normal", "islands_roughness", "strips_color", "strips_normal", "strips_roughness"]},
    "packed": {"type": "tex_pack", "in": ["maps"], "params": {"resolution": "=[atlas_size, atlas_size / 2]", "padding": "=padding", "name": "cutouts", "items": [{"name": "ring", "maps": {"color": "ring_color", "normal": "ring_normal", "roughness": "ring_roughness"}}, {"name": "islands", "maps": {"color": "islands_color", "normal": "islands_normal", "roughness": "islands_roughness"}}, {"name": "strips", "maps": {"color": "strips_color", "normal": "strips_normal", "roughness": "strips_roughness"}}]}},
    "color_padding": {"type": "tex_dilate", "in": ["packed"], "params": {"image": "cutouts_color", "name": "cutouts_color", "distance": "=padding / (2 * floor((atlas_size - 6 * padding) / 5))"}},
    "normal_padding": {"type": "tex_dilate", "in": ["color_padding", "color_padding"], "params": {"image": "cutouts_normal", "name": "cutouts_normal", "mask_image": "cutouts_color", "mask_channel": "alpha", "distance": "=padding / (2 * floor((atlas_size - 6 * padding) / 5))"}},
    "roughness_padding": {"type": "tex_dilate", "in": ["normal_padding", "normal_padding"], "params": {"image": "cutouts_roughness", "name": "cutouts_roughness", "mask_image": "cutouts_color", "mask_channel": "alpha", "distance": "=padding / (2 * floor((atlas_size - 6 * padding) / 5))"}},
    "atlas": {"type": "delete", "in": ["roughness_padding"], "params": {"class": "point", "group": "*"}},

    "ring_trace": {"type": "trace_image", "in": ["ring_color"], "params": {"tolerance": "=outline"}},
    "ring_fill": {"type": "fill", "in": ["ring_trace"], "params": {"plane": "xy"}},
    "ring_mesh": {"type": "remesh_isotropic", "in": ["ring_fill"], "params": {"target_length": 0.05, "iterations": 4, "preserve_boundary": false}},
    "ring_uv": {"type": "uv_project", "in": ["ring_mesh"], "params": {"method": "planar", "axis": "z", "scale": [1.0, 1]}},
    "ring_bent": {"type": "wrangle", "in": ["ring_uv"], "params": {"code": "const dx = @P.x / 1.0 - 0.5;\n@P.z += bend * (2.4 * dx * dx + 0.4 * @P.y * @P.y);"}},
    "ring_in_atlas": {"type": "wrangle", "in": ["ring_bent", "packed"], "params": {"run_over": "vertices", "code": "const offset = point(1, \"uv_offset\", 0);\nconst scale = point(1, \"uv_scale\", 0);\n@uv = [@uv.x * scale[0] + offset[0], @uv.y * scale[1] + offset[1], 0];"}},
    "ring_holes": {"type": "assert", "in": ["ring_in_atlas"], "params": {"label": "holes", "expr": "pieces - npoints + npolys / 2 + boundary_edges / 2 == 1"}, "note": "holes = pieces minus the Euler characteristic; on a triangle mesh edges = (3 polys + boundary edges) / 2"},
    "ring_named": {"type": "attrib_create", "in": ["ring_holes"], "params": {"name": "name", "class": "prim", "value": "ring_card"}},
    "ring_copies": {"type": "copy_xform", "in": ["ring_named"], "params": {"count": "=copies", "translate": [0, 1.25, 0], "rotate": [0, 15, 0], "pivot": [0.5, 0, 0]}},
    "ring_placed": {"type": "transform", "in": ["ring_copies"], "params": {"translate": [-1.95, 0, 0]}},
    "islands_trace": {"type": "trace_image", "in": ["islands_color"], "params": {"tolerance": "=outline"}},
    "islands_fill": {"type": "fill", "in": ["islands_trace"], "params": {"plane": "xy"}},
    "islands_mesh": {"type": "remesh_isotropic", "in": ["islands_fill"], "params": {"target_length": 0.05, "iterations": 4, "preserve_boundary": false}},
    "islands_uv": {"type": "uv_project", "in": ["islands_mesh"], "params": {"method": "planar", "axis": "z", "scale": [1.0, 1]}},
    "islands_bent": {"type": "wrangle", "in": ["islands_uv"], "params": {"code": "const dx = @P.x / 1.0 - 0.5;\n@P.z += bend * (2.4 * dx * dx + 0.4 * @P.y * @P.y);"}},
    "islands_in_atlas": {"type": "wrangle", "in": ["islands_bent", "packed"], "params": {"run_over": "vertices", "code": "const offset = point(1, \"uv_offset\", 1);\nconst scale = point(1, \"uv_scale\", 1);\n@uv = [@uv.x * scale[0] + offset[0], @uv.y * scale[1] + offset[1], 0];"}},
    "islands_holes": {"type": "assert", "in": ["islands_in_atlas"], "params": {"label": "holes", "expr": "pieces - npoints + npolys / 2 + boundary_edges / 2 == 0"}, "note": "holes = pieces minus the Euler characteristic; on a triangle mesh edges = (3 polys + boundary edges) / 2"},
    "islands_named": {"type": "attrib_create", "in": ["islands_holes"], "params": {"name": "name", "class": "prim", "value": "islands_card"}},
    "islands_copies": {"type": "copy_xform", "in": ["islands_named"], "params": {"count": "=copies", "translate": [0, 1.25, 0], "rotate": [0, 15, 0], "pivot": [0.5, 0, 0]}},
    "islands_placed": {"type": "transform", "in": ["islands_copies"], "params": {"translate": [-0.5, 0, 0]}},
    "strips_trace": {"type": "trace_image", "in": ["strips_color"], "params": {"tolerance": "=outline"}},
    "strips_fill": {"type": "fill", "in": ["strips_trace"], "params": {"plane": "xy"}},
    "strips_mesh": {"type": "remesh_isotropic", "in": ["strips_fill"], "params": {"target_length": 0.05, "iterations": 4, "preserve_boundary": false}},
    "strips_uv": {"type": "uv_project", "in": ["strips_mesh"], "params": {"method": "planar", "axis": "z", "scale": [0.5, 1]}},
    "strips_bent": {"type": "wrangle", "in": ["strips_uv"], "params": {"code": "const dx = @P.x / 0.5 - 0.5;\n@P.z += bend * (2.4 * dx * dx + 0.4 * @P.y * @P.y);"}},
    "strips_in_atlas": {"type": "wrangle", "in": ["strips_bent", "packed"], "params": {"run_over": "vertices", "code": "const offset = point(1, \"uv_offset\", 2);\nconst scale = point(1, \"uv_scale\", 2);\n@uv = [@uv.x * scale[0] + offset[0], @uv.y * scale[1] + offset[1], 0];"}},
    "strips_holes": {"type": "assert", "in": ["strips_in_atlas"], "params": {"label": "holes", "expr": "pieces - npoints + npolys / 2 + boundary_edges / 2 == 0"}, "note": "holes = pieces minus the Euler characteristic; on a triangle mesh edges = (3 polys + boundary edges) / 2"},
    "strips_named": {"type": "attrib_create", "in": ["strips_holes"], "params": {"name": "name", "class": "prim", "value": "strips_card"}},
    "strips_copies": {"type": "copy_xform", "in": ["strips_named"], "params": {"count": "=copies", "translate": [0, 1.25, 0], "rotate": [0, 15, 0], "pivot": [0.25, 0, 0]}},
    "strips_placed": {"type": "transform", "in": ["strips_copies"], "params": {"translate": [0.95, 0, 0]}},
    "all_cards": {"type": "merge", "in": ["ring_placed", "islands_placed", "strips_placed"]},
    "smooth": {"type": "normal", "in": ["all_cards"], "params": {"class": "point"}},
    "cutout_material": {"type": "material", "in": ["smooth"], "params": {"name": "cutouts", "alpha_mode": "mask", "alpha_cutoff": 0.5, "double_sided": true}},
    "textured": {"type": "texture_to_material", "in": ["cutout_material", "atlas"], "params": {"material": "cutouts", "base_color": "cutouts_color", "normal": "cutouts_normal", "roughness": "cutouts_roughness"}},
    "cards": {"type": "assert", "in": ["textured"], "params": {"label": "in_atlas", "attrib": "uv", "attrib_class": "vertex", "attrib_min": 0, "attrib_max": 1}}
  },
  "output": "cards",
  "outputs": {
    "cards": {"node": "cards", "label": "Cut-out cards", "kind": "mesh", "tags": ["cutout", "cards", "alpha-mask", "foliage", "atlas"], "description": "Flat, double-sided cards traced from three pictures, bent and copied, with uv into the shared atlas and one alpha-masked material."},
    "atlas": {"node": "atlas", "label": "Atlas", "kind": "textures", "tags": ["atlas", "textures", "packed", "cutout"], "description": "The three pictures packed side by side: colour with alpha, normal and roughness, padded against seams."}
  }
}
