Sand3D
One program per asset. A Python file that grows each part:
trunk, branches, leaves, petals and moss.
import sand3d as s3d
import numpy as np
def toy_crocus(seed=0):
corm_lift = 3
corm = s3d.at(corm_part(seed=seed + 1), z=corm_lift)
roots = s3d.at(roots_part(seed=seed + 2), on=s3d.local(corm, z=-corm_lift), anchor="-Z")
stem = s3d.at(stem_part(seed=seed + 3), on=corm.face("+Z"))
flower = s3d.at(flower_part(seed=seed + 4), on=stem.face("+Z"))
leaves = s3d.at(foliage_part(seed=seed + 5), on=corm.face("+Z").offset(-6))
return s3d.assembly("toy_crocus", corm, roots, stem, flower, leaves)
def corm_part(seed, width=29, depth=26, height=20):
with s3d.facets(6, smooth=False):
corm = s3d.loft("brown_corm",
s3d.station(0, width * .74, depth * .74),
s3d.station(height * .3, width, depth, x=-1),
s3d.station(height * .72, width * .85, depth * .86, y=1),
s3d.station(height, width * .34, depth * .34))
s3d.material(corm, "soil", color="#835432", roughness=1)
return corm
def roots_part(seed, count=6, reach=20, radius=8):
with s3d.facets(6, smooth=False):
sites = s3d.ring(count, radius, start=12).jitter(rz=13, seed=seed + 1)
lengths = s3d.vary(reach, 4, len(sites), seed=seed + 2)
roots = [s3d.at(root_part(seed=seed + 10 + i, length=length), on=frame)
for i, (frame, length) in enumerate(zip(sites, lengths))]
return s3d.group("spreading_roots", roots)
def root_part(seed, length=20, diameter=3):
root = s3d.wire("short_root", [(0, 0, 5), (length * .4, 1, 2),
(length * .78, 0, 1.1), (length, 1, 1)],
d=[(0, diameter), (.4, diameter * .75), (.8, diameter * .42), (1, 0)],
tip="sharp")
s3d.material(root, "bark", color="#a67c4e", roughness=1)
return root
def stem_part(seed, diameter=5.5, height=43):
with s3d.facets(6, smooth=False):
stem = s3d.cone("short_green_stem", diameter, height, d2=diameter * .8)
s3d.material(stem, "leaf", color="#729047", roughness=.95)
return stem
def flower_part(seed, attachment_radius=2.8, inner_rise=2):
with s3d.facets(6, smooth=False):
outer_sites = s3d.ring(3, attachment_radius, start=15).jitter(rz=3, seed=seed + 1)
inner_sites = s3d.ring(3, attachment_radius * .8, start=75).move(z=inner_rise).jitter(rz=3, seed=seed + 2)
heights = s3d.vary(57, 4.5, 3, seed=seed + 3)
inner_heights = s3d.vary(56, 3.5, 3, seed=seed + 4)
outer = [s3d.at(petal_part(seed=seed + 20 + i, height=h, width=26, spread=19), on=f)
for i, (f, h) in enumerate(zip(outer_sites, heights))]
inner = [s3d.at(petal_part(seed=seed + 30 + i, height=h, width=24, spread=17), on=f)
for i, (f, h) in enumerate(zip(inner_sites, inner_heights))]
stamens = s3d.at(stamen_part(seed=seed + 40), on=s3d.ring(3, 3.5, start=35).move(z=4),
scale=s3d.vary(1, .07, 3, seed=seed + 5))
return s3d.group("open_violet_cup", outer, inner, stamens)
def petal_part(seed, height=57, width=26, spread=19, thickness=1.7):
spread = s3d.vary(spread, spread * .08, 1, seed=seed + 1)[0]
tip_sway = s3d.vary(0, width * .13, 1, seed=seed + 2)[0]
petal = s3d.loft("angular_violet_petal",
s3d.station(0, thickness, width * .13),
s3d.station(height * .24, thickness, width * .44, x=spread * .12),
s3d.station(height * .53, thickness, width * .86, x=spread * .48, y=tip_sway * .2),
s3d.station(height * .78, thickness, width, x=spread * .86, y=tip_sway * .5),
s3d.station(height * .94, thickness * .7, width * .60, x=spread, y=tip_sway * .8),
s3d.station(height, 0, 0, x=spread * .98, y=tip_sway), tip="sharp")
def petal_color(x, y, z, n):
interior = np.array([.60, .50, .84])
exterior = np.array([.34, .15, .57])
return np.where((n[0] < -.12)[:, None], interior, exterior)
s3d.material(petal, "leaf", color=petal_color, roughness=1)
return petal
def stamen_part(seed, height=34, filament_d=1.25, anther_h=8):
filament = s3d.cone("golden_filament", filament_d, height, d2=filament_d * .72)
s3d.material(filament, "leaf", color="#f9bd35", roughness=1)
anther = s3d.at(s3d.loft("orange_anther",
s3d.station(0, 1.8, 2), s3d.station(anther_h * .22, 3.3, 2.7),
s3d.station(anther_h * .82, 2.9, 2.5), s3d.station(anther_h, 1, 1)),
on=filament.face("+Z"))
s3d.material(anther, "leaf", color="#efa021", roughness=1)
return s3d.group("stamen", filament, anther)
def foliage_part(seed, count=5, root_radius=5, height=76):
with s3d.facets(6, smooth=False):
sites = s3d.ring(count, root_radius, start=-15).jitter(rz=15, seed=seed + 1)
heights = s3d.vary(height, 13, count, seed=seed + 2)
spreads = s3d.vary(32, 7, count, seed=seed + 3)
blades = [s3d.at(striped_leaf_part(seed=seed + 10 + i, height=h, spread=spread), on=f)
for i, (f, h, spread) in enumerate(zip(sites, heights, spreads))]
return s3d.group("splayed_striped_leaves", blades)
def striped_leaf_part(seed, height=76, spread=32, width=5.2, thickness=.85, stripe_ratio=.23):
sections = [(0, 0, .43), (.22, .10, 1), (.55, .39, .93), (.84, .80, .55)]
blade = s3d.loft("green_blade",
*[s3d.station(height * z, thickness, width * w, x=spread * x) for z, x, w in sections],
s3d.station(height, 0, 0, x=spread), tip="sharp")
s3d.material(blade, "leaf", color="#356638", roughness=1)
stripes = []
for side in (-1, 1):
stripe = s3d.loft("pale_central_stripe",
*[s3d.station(height * z, .16, width * w * stripe_ratio,
x=spread * x + side * (thickness / 2 + .055)) for z, x, w in sections],
s3d.station(height, 0, 0, x=spread), tip="sharp")
s3d.material(stripe, "leaf", color="#d0ddab", roughness=1)
stripes.append(stripe)
return s3d.group("striped_leaf", blade, stripes)
import sand3d as s3d
import numpy as np
def toy_crocus(seed=0):
corm_lift = 3
corm = s3d.at(corm_part(seed=seed + 1), z=corm_lift)
roots = s3d.at(roots_part(seed=seed + 2), on=s3d.local(corm, z=-corm_lift), anchor="-Z")
stem = s3d.at(stem_part(seed=seed + 3), on=corm.face("+Z"))
flower = s3d.at(flower_part(seed=seed + 4), on=stem.face("+Z"))
leaves = s3d.at(foliage_part(seed=seed + 5), on=corm.face("+Z").offset(-6))
return s3d.assembly("toy_crocus", corm, roots, stem, flower, leaves)
def corm_part(seed, width=29, depth=26, height=20):
with s3d.facets(6, smooth=False):
corm = s3d.loft("brown_corm",
s3d.station(0, width * .74, depth * .74),
s3d.station(height * .3, width, depth, x=-1),
s3d.station(height * .72, width * .85, depth * .86, y=1),
s3d.station(height, width * .34, depth * .34))
s3d.material(corm, "soil", color="#835432", roughness=1)
return corm
def roots_part(seed, count=6, reach=20, radius=8):
with s3d.facets(6, smooth=False):
sites = s3d.ring(count, radius, start=12).jitter(rz=13, seed=seed + 1)
lengths = s3d.vary(reach, 4, len(sites), seed=seed + 2)
roots = [s3d.at(root_part(seed=seed + 10 + i, length=length), on=frame)
for i, (frame, length) in enumerate(zip(sites, lengths))]
return s3d.group("spreading_roots", roots)
def root_part(seed, length=20, diameter=3):
root = s3d.wire("short_root", [(0, 0, 5), (length * .4, 1, 2),
(length * .78, 0, 1.1), (length, 1, 1)],
d=[(0, diameter), (.4, diameter * .75), (.8, diameter * .42), (1, 0)],
tip="sharp")
s3d.material(root, "bark", color="#a67c4e", roughness=1)
return root
def stem_part(seed, diameter=5.5, height=43):
with s3d.facets(6, smooth=False):
stem = s3d.cone("short_green_stem", diameter, height, d2=diameter * .8)
s3d.material(stem, "leaf", color="#729047", roughness=.95)
return stem
def flower_part(seed, attachment_radius=2.8, inner_rise=2):
with s3d.facets(6, smooth=False):
outer_sites = s3d.ring(3, attachment_radius, start=15).jitter(rz=3, seed=seed + 1)
inner_sites = s3d.ring(3, attachment_radius * .8, start=75).move(z=inner_rise).jitter(rz=3, seed=seed + 2)
heights = s3d.vary(57, 4.5, 3, seed=seed + 3)
inner_heights = s3d.vary(56, 3.5, 3, seed=seed + 4)
outer = [s3d.at(petal_part(seed=seed + 20 + i, height=h, width=26, spread=19), on=f)
for i, (f, h) in enumerate(zip(outer_sites, heights))]
inner = [s3d.at(petal_part(seed=seed + 30 + i, height=h, width=24, spread=17), on=f)
for i, (f, h) in enumerate(zip(inner_sites, inner_heights))]
stamens = s3d.at(stamen_part(seed=seed + 40), on=s3d.ring(3, 3.5, start=35).move(z=4),
scale=s3d.vary(1, .07, 3, seed=seed + 5))
return s3d.group("open_violet_cup", outer, inner, stamens)
def petal_part(seed, height=57, width=26, spread=19, thickness=1.7):
spread = s3d.vary(spread, spread * .08, 1, seed=seed + 1)[0]
tip_sway = s3d.vary(0, width * .13, 1, seed=seed + 2)[0]
petal = s3d.loft("angular_violet_petal",
s3d.station(0, thickness, width * .13),
s3d.station(height * .24, thickness, width * .44, x=spread * .12),
s3d.station(height * .53, thickness, width * .86, x=spread * .48, y=tip_sway * .2),
s3d.station(height * .78, thickness, width, x=spread * .86, y=tip_sway * .5),
s3d.station(height * .94, thickness * .7, width * .60, x=spread, y=tip_sway * .8),
s3d.station(height, 0, 0, x=spread * .98, y=tip_sway), tip="sharp")
def petal_color(x, y, z, n):
interior = np.array([.60, .50, .84])
exterior = np.array([.34, .15, .57])
return np.where((n[0] < -.12)[:, None], interior, exterior)
s3d.material(petal, "leaf", color=petal_color, roughness=1)
return petal
def stamen_part(seed, height=34, filament_d=1.25, anther_h=8):
filament = s3d.cone("golden_filament", filament_d, height, d2=filament_d * .72)
s3d.material(filament, "leaf", color="#f9bd35", roughness=1)
anther = s3d.at(s3d.loft("orange_anther",
s3d.station(0, 1.8, 2), s3d.station(anther_h * .22, 3.3, 2.7),
s3d.station(anther_h * .82, 2.9, 2.5), s3d.station(anther_h, 1, 1)),
on=filament.face("+Z"))
s3d.material(anther, "leaf", color="#efa021", roughness=1)
return s3d.group("stamen", filament, anther)
def foliage_part(seed, count=5, root_radius=5, height=76):
with s3d.facets(6, smooth=False):
sites = s3d.ring(count, root_radius, start=-15).jitter(rz=15, seed=seed + 1)
heights = s3d.vary(height, 13, count, seed=seed + 2)
spreads = s3d.vary(32, 7, count, seed=seed + 3)
blades = [s3d.at(striped_leaf_part(seed=seed + 10 + i, height=h, spread=spread), on=f)
for i, (f, h, spread) in enumerate(zip(sites, heights, spreads))]
return s3d.group("splayed_striped_leaves", blades)
def striped_leaf_part(seed, height=76, spread=32, width=5.2, thickness=.85, stripe_ratio=.23):
sections = [(0, 0, .43), (.22, .10, 1), (.55, .39, .93), (.84, .80, .55)]
blade = s3d.loft("green_blade",
*[s3d.station(height * z, thickness, width * w, x=spread * x) for z, x, w in sections],
s3d.station(height, 0, 0, x=spread), tip="sharp")
s3d.material(blade, "leaf", color="#356638", roughness=1)
stripes = []
for side in (-1, 1):
stripe = s3d.loft("pale_central_stripe",
*[s3d.station(height * z, .16, width * w * stripe_ratio,
x=spread * x + side * (thickness / 2 + .055)) for z, x, w in sections],
s3d.station(height, 0, 0, x=spread), tip="sharp")
s3d.material(stripe, "leaf", color="#d0ddab", roughness=1)
stripes.append(stripe)
return s3d.group("striped_leaf", blade, stripes)












