A clean start for the shared repository: the Unity project (Assets, Packages, ProjectSettings), ArtSource, Docs and Tools as they stood at f3666f0 in the old local repository, with its generated prefabs and scene brought up to date. Images, audio, models and binaries go through Git LFS (.gitattributes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2299 lines
107 KiB
Python
2299 lines
107 KiB
Python
"""GRASS CUTTER - rig decor + environment set dressing.
|
|
|
|
Run from project root:
|
|
blender -b --factory-startup --python ArtSource/Blender/scripts/os_decor.py -- [AssetName ...]
|
|
|
|
Conventions (Docs/DESIGN.md): meters, Z-up, front = -Y, transforms applied, origin = pivot at the
|
|
bottom centre (deck / seabed, z=0) unless noted. Buoy origin = waterline.
|
|
New materials live in ArtSource/materials_decor.json.
|
|
"""
|
|
import sys, os, zlib
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from common import *
|
|
import common
|
|
from mathutils import noise
|
|
from mathutils.bvhtree import BVHTree
|
|
|
|
TAU = 2 * math.pi
|
|
DEBUG = os.environ.get("OSD_DEBUG") == "1"
|
|
_join = join
|
|
|
|
|
|
def join(objs, name):
|
|
if DEBUG:
|
|
objs = [o for o in objs if o is not None]
|
|
agg = {}
|
|
for o in objs:
|
|
k = o.name.split(".")[0]
|
|
agg[k] = agg.get(k, 0) + sum(len(p.vertices) - 2 for p in o.data.polygons)
|
|
top = sorted(agg.items(), key=lambda kv: -kv[1])[:8]
|
|
print(f" JOIN {name}: " + ", ".join(f"{k}={v}" for k, v in top))
|
|
return _join(objs, name)
|
|
|
|
|
|
# =============================================================================== helpers
|
|
|
|
def add_mats(o, *names):
|
|
"""Append materials without clearing (clearing wipes per-face material indices)."""
|
|
for n in names:
|
|
o.data.materials.append(mat(n))
|
|
return o
|
|
|
|
|
|
def bx(x0, x1, y0, y1, z0, z1, m, bevel=0.02, segs=2, name="b"):
|
|
size = (x1 - x0, y1 - y0, z1 - z0)
|
|
loc = ((x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2)
|
|
if bevel > 0:
|
|
return rbox(name, size, loc, bevel=bevel, segs=segs, m=m)
|
|
return cube(name, size, loc, m)
|
|
|
|
|
|
def cy(r, z0, z1, m, x=0.0, y=0.0, verts=24, bevel=0.0, segs=2, r2=None, name="c"):
|
|
return cyl(name, r, z1 - z0, loc=(x, y, (z0 + z1) / 2), verts=verts, bevel=bevel, segs=segs, m=m, r2=r2)
|
|
|
|
|
|
def xf(o, loc=(0, 0, 0), rot=(0, 0, 0), scale=(1, 1, 1)):
|
|
"""Set transform (degrees) and apply it."""
|
|
o.scale = scale
|
|
o.rotation_euler = [math.radians(a) for a in rot]
|
|
o.location = loc
|
|
return apply_xform(o)
|
|
|
|
|
|
def rod(p0, p1, r, m, verts=10, bevel=0.0, r2=None, name="rod"):
|
|
p0, p1 = Vector(p0), Vector(p1)
|
|
d = p1 - p0
|
|
o = cyl(name, r, d.length, verts=verts, m=m, bevel=bevel, r2=r2)
|
|
o.rotation_euler = d.to_track_quat("Z", "Y").to_euler()
|
|
o.location = (p0 + p1) / 2
|
|
return apply_xform(o)
|
|
|
|
|
|
def ptube(name, pts, r, m, cyclic=False, rs=1, caps=True):
|
|
"""Tube along a POLY path (points used as-is). rs = bevel resolution (profile verts = 4 + 2*rs)."""
|
|
cu = bpy.data.curves.new(name, "CURVE")
|
|
cu.dimensions = "3D"
|
|
cu.bevel_depth = r
|
|
cu.bevel_resolution = rs
|
|
cu.use_fill_caps = caps and not cyclic
|
|
sp = cu.splines.new("POLY")
|
|
sp.points.add(len(pts) - 1)
|
|
for i, p in enumerate(pts):
|
|
sp.points[i].co = (p[0], p[1], p[2], 1)
|
|
sp.use_cyclic_u = cyclic
|
|
o = link(bpy.data.objects.new(name, cu))
|
|
o2 = to_mesh(o)
|
|
set_mats(o2, m)
|
|
return o2
|
|
|
|
|
|
def bez(pts, n):
|
|
"""Catmull-Rom resample of control points -> n points (passes through the controls)."""
|
|
P = [Vector(p) for p in pts]
|
|
P = [P[0] * 2 - P[1]] + P + [P[-1] * 2 - P[-2]]
|
|
out = []
|
|
segs = len(P) - 3
|
|
for k in range(n):
|
|
t = k / (n - 1) * segs
|
|
i = min(int(t), segs - 1)
|
|
u = t - i
|
|
p0, p1, p2, p3 = P[i], P[i + 1], P[i + 2], P[i + 3]
|
|
out.append(0.5 * ((2 * p1) + (-p0 + p2) * u + (2 * p0 - 5 * p1 + 4 * p2 - p3) * u * u + (-p0 + 3 * p1 - 3 * p2 + p3) * u * u * u))
|
|
return [tuple(p) for p in out]
|
|
|
|
|
|
def rev(name, profile, mats, segs=24, close_top=True, close_bottom=False, loc=(0, 0, 0), phase=0.0):
|
|
"""Revolve (r, z) profile; mats = one name or a name per profile segment (bands)."""
|
|
if isinstance(mats, str):
|
|
mats = [mats] * (len(profile) - 1)
|
|
slots = []
|
|
for n in mats:
|
|
if n not in slots:
|
|
slots.append(n)
|
|
bm = bmesh.new()
|
|
rings = []
|
|
for (r, z) in profile:
|
|
if r <= 1e-6:
|
|
rings.append([bm.verts.new((0, 0, z))])
|
|
else:
|
|
rings.append([bm.verts.new((r * math.cos(TAU * i / segs + phase), r * math.sin(TAU * i / segs + phase), z)) for i in range(segs)])
|
|
for k, (a, b) in enumerate(zip(rings, rings[1:])):
|
|
mi = slots.index(mats[k])
|
|
fs = []
|
|
if len(a) == 1 and len(b) == 1:
|
|
continue
|
|
if len(a) == 1:
|
|
fs = [bm.faces.new((a[0], b[i], b[(i + 1) % segs])) for i in range(segs)]
|
|
elif len(b) == 1:
|
|
fs = [bm.faces.new((a[i], a[(i + 1) % segs], b[0])) for i in range(segs)]
|
|
else:
|
|
fs = [bm.faces.new((a[i], a[(i + 1) % segs], b[(i + 1) % segs], b[i])) for i in range(segs)]
|
|
for f in fs:
|
|
f.material_index = mi
|
|
if close_top and len(rings[-1]) > 1:
|
|
bm.faces.new(rings[-1]).material_index = slots.index(mats[-1])
|
|
if close_bottom and len(rings[0]) > 1:
|
|
bm.faces.new(list(reversed(rings[0]))).material_index = slots.index(mats[0])
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
bmesh.ops.translate(bm, vec=Vector(loc), verts=bm.verts)
|
|
o = mesh_obj(name, bm)
|
|
add_mats(o, *slots)
|
|
return o
|
|
|
|
|
|
def softbox(name, size, loc=(0, 0, 0), r=0.05, m=None, bulge=(0, 0, 0), na=2, nf=3):
|
|
"""Rounded box with real arc corners + optional pillow bulge per axis."""
|
|
hx, hy, hz = [s / 2 for s in size]
|
|
r = min(r, hx * 0.98, hy * 0.98, hz * 0.98)
|
|
|
|
def coords(h):
|
|
inner = h - r
|
|
flat = [(-inner + 2 * inner * i / (nf - 1)) for i in range(nf)] if inner > 1e-5 else [0.0]
|
|
arc = [inner + r * math.sin(i / na * math.pi / 2) for i in range(1, na + 1)]
|
|
return [-a for a in reversed(arc)] + flat + arc
|
|
|
|
cx, cyy, cz = coords(hx), coords(hy), coords(hz)
|
|
bm = bmesh.new()
|
|
|
|
def grid(us, vs, f):
|
|
V = [[bm.verts.new(f(u, v)) for v in vs] for u in us]
|
|
for i in range(len(us) - 1):
|
|
for j in range(len(vs) - 1):
|
|
bm.faces.new((V[i][j], V[i + 1][j], V[i + 1][j + 1], V[i][j + 1]))
|
|
|
|
grid(cx, cyy, lambda u, v: (u, v, hz)); grid(cx, cyy, lambda u, v: (u, v, -hz))
|
|
grid(cx, cz, lambda u, v: (u, hy, v)); grid(cx, cz, lambda u, v: (u, -hy, v))
|
|
grid(cyy, cz, lambda u, v: (hx, u, v)); grid(cyy, cz, lambda u, v: (-hx, u, v))
|
|
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=1e-6)
|
|
inner = Vector((hx - r, hy - r, hz - r))
|
|
for v in bm.verts:
|
|
p = v.co.copy()
|
|
q = Vector([max(-inner[i], min(inner[i], p[i])) for i in range(3)])
|
|
d = p - q
|
|
p2 = q + d.normalized() * r if d.length > 1e-9 else p
|
|
fx = max(0.0, 1 - (p.x / hx) ** 2)
|
|
fy = max(0.0, 1 - (p.y / hy) ** 2)
|
|
fz = max(0.0, 1 - (p.z / hz) ** 2)
|
|
p2.x += math.copysign(bulge[0] * fy * fz, p.x)
|
|
p2.y += math.copysign(bulge[1] * fx * fz, p.y)
|
|
p2.z += math.copysign(bulge[2] * fx * fy, p.z)
|
|
v.co = p2
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
bmesh.ops.translate(bm, vec=Vector(loc), verts=bm.verts)
|
|
o = mesh_obj(name, bm)
|
|
if m:
|
|
set_mats(o, m)
|
|
return o
|
|
|
|
|
|
def fillet2d(pts, r, n=3):
|
|
out = []
|
|
N = len(pts)
|
|
for i in range(N):
|
|
p0, p1, p2 = Vector(pts[i - 1]), Vector(pts[i]), Vector(pts[(i + 1) % N])
|
|
rr = r[i] if isinstance(r, (list, tuple)) else r
|
|
a, b = p0 - p1, p2 - p1
|
|
la, lb = a.length, b.length
|
|
a.normalize(); b.normalize()
|
|
ang = math.acos(max(-1.0, min(1.0, a.dot(b))))
|
|
if rr <= 0 or ang > math.pi - 1e-3:
|
|
out.append(p1)
|
|
continue
|
|
t = min(rr / math.tan(ang / 2), la * 0.48, lb * 0.48)
|
|
s, e = p1 + a * t, p1 + b * t
|
|
for k in range(n + 1):
|
|
u = k / n
|
|
out.append(s * (1 - u) ** 2 + p1 * 2 * u * (1 - u) + e * u * u)
|
|
return [(p.x, p.y) for p in out]
|
|
|
|
|
|
def slab(name, pts, t0, t1, m, plane="YZ", bevel=0.015, segs=2):
|
|
"""Extrude a 2D polygon (a,b) along the remaining axis between t0..t1, bevel the cap edges."""
|
|
bm = bmesh.new()
|
|
|
|
def P(a, b, t):
|
|
if plane == "YZ":
|
|
return (t, a, b)
|
|
if plane == "XZ":
|
|
return (a, t, b)
|
|
return (a, b, t)
|
|
|
|
bot = [bm.verts.new(P(a, b, t0)) for a, b in pts]
|
|
top = [bm.verts.new(P(a, b, t1)) for a, b in pts]
|
|
bm.faces.new(bot); bm.faces.new(top)
|
|
for i in range(len(pts)):
|
|
j = (i + 1) % len(pts)
|
|
bm.faces.new((bot[i], bot[j], top[j], top[i]))
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
o = mesh_obj(name, bm)
|
|
set_mats(o, m)
|
|
if bevel > 0:
|
|
bv = o.modifiers.new("bev", "BEVEL")
|
|
bv.width = bevel
|
|
bv.segments = segs
|
|
bv.limit_method = "ANGLE"
|
|
bv.angle_limit = math.radians(40)
|
|
bake(o)
|
|
return o
|
|
|
|
|
|
def decal(name, center, w, h, facing, m):
|
|
"""Quad with 0..1 UVs facing a direction (u = viewer right, v = up)."""
|
|
n = Vector(facing).normalized()
|
|
up = Vector((0, 0, 1)) if abs(n.z) < 0.9 else Vector((0, 1, 0))
|
|
rt = up.cross(n).normalized()
|
|
up = n.cross(rt).normalized()
|
|
c = Vector(center)
|
|
bm = bmesh.new()
|
|
uvl = bm.loops.layers.uv.verify()
|
|
corners = [(-1, -1), (1, -1), (1, 1), (-1, 1)]
|
|
vs = [bm.verts.new(c + rt * (a * w / 2) + up * (b * h / 2)) for a, b in corners]
|
|
f = bm.faces.new(vs)
|
|
f.normal_update()
|
|
if f.normal.dot(n) < 0:
|
|
f.normal_flip()
|
|
for l in f.loops:
|
|
d = l.vert.co - c
|
|
l[uvl].uv = (d.dot(rt) / w + 0.5, d.dot(up) / h + 0.5)
|
|
o = mesh_obj(name, bm)
|
|
set_mats(o, m)
|
|
return o
|
|
|
|
|
|
def paint(o, fn, names):
|
|
"""Assign materials per face: fn(center, normal, index) -> index into names."""
|
|
o.data.materials.clear()
|
|
for n in names:
|
|
o.data.materials.append(mat(n))
|
|
for p in o.data.polygons:
|
|
p.material_index = fn(Vector(p.center), Vector(p.normal), p.index)
|
|
return o
|
|
|
|
|
|
def wobble(o, amp, freq, seed=0.0, axis_w=(1, 1, 1)):
|
|
off = Vector((seed * 17.31, seed * 5.13, seed * 9.71))
|
|
me = o.data
|
|
me.update()
|
|
for v in me.vertices:
|
|
n = noise.noise(v.co * freq + off)
|
|
d = v.normal * n * amp
|
|
v.co += Vector((d.x * axis_w[0], d.y * axis_w[1], d.z * axis_w[2]))
|
|
return o
|
|
|
|
|
|
def sweep_rings(name, path, radii, m, verts=12, close_ends=True, phase=0.0):
|
|
"""Generalised cylinder along path points with per-point radius (scalar or (rx, ry))."""
|
|
bm = bmesh.new()
|
|
path = [Vector(p) for p in path]
|
|
rings = []
|
|
prev_n = None
|
|
for i, p in enumerate(path):
|
|
t = (path[min(i + 1, len(path) - 1)] - path[max(i - 1, 0)]).normalized()
|
|
if prev_n is None:
|
|
ref = Vector((0, 0, 1)) if abs(t.z) < 0.9 else Vector((1, 0, 0))
|
|
nx = ref.cross(t).normalized()
|
|
else:
|
|
nx = (prev_n - t * prev_n.dot(t)).normalized()
|
|
prev_n = nx
|
|
ny = t.cross(nx)
|
|
rr = radii[i]
|
|
rx, ry = (rr, rr) if not isinstance(rr, (tuple, list)) else rr
|
|
ring = []
|
|
for k in range(verts):
|
|
a = TAU * k / verts + phase
|
|
ring.append(bm.verts.new(p + nx * math.cos(a) * rx + ny * math.sin(a) * ry))
|
|
rings.append(ring)
|
|
for a, b in zip(rings, rings[1:]):
|
|
for k in range(verts):
|
|
bm.faces.new((a[k], a[(k + 1) % verts], b[(k + 1) % verts], b[k]))
|
|
if close_ends:
|
|
bm.faces.new(rings[0]); bm.faces.new(rings[-1])
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
o = mesh_obj(name, bm)
|
|
set_mats(o, m)
|
|
return o
|
|
|
|
|
|
def dbl(o, off=0.004):
|
|
"""Make a thin sheet double-sided: duplicate faces, flip, push back slightly."""
|
|
bm = bmesh.new()
|
|
bm.from_mesh(o.data)
|
|
bm.normal_update()
|
|
orig = list(bm.faces)
|
|
ret = bmesh.ops.duplicate(bm, geom=orig)
|
|
newf = [g for g in ret["geom"] if isinstance(g, bmesh.types.BMFace)]
|
|
newv = [g for g in ret["geom"] if isinstance(g, bmesh.types.BMVert)]
|
|
bmesh.ops.reverse_faces(bm, faces=newf)
|
|
bm.normal_update()
|
|
for v in newv:
|
|
v.co -= v.normal * off
|
|
bm.to_mesh(o.data)
|
|
bm.free()
|
|
return o
|
|
|
|
|
|
def tri_ngons(o):
|
|
bm = bmesh.new()
|
|
bm.from_mesh(o.data)
|
|
ng = [f for f in bm.faces if len(f.verts) > 4]
|
|
if ng:
|
|
bmesh.ops.triangulate(bm, faces=ng, quad_method="BEAUTY", ngon_method="BEAUTY")
|
|
bm.to_mesh(o.data)
|
|
bm.free()
|
|
|
|
|
|
def ntris(o):
|
|
return sum(len(p.vertices) - 2 for p in o.data.polygons)
|
|
|
|
|
|
DECAL_MATS = ("M_Label", "M_Logo")
|
|
|
|
|
|
def uv_keep(o, scale=1.0):
|
|
"""uv_box, but keep the 0..1 UVs of decal faces (M_Label / M_Logo)."""
|
|
me = o.data
|
|
keep = {}
|
|
idx = [i for i, m_ in enumerate(me.materials) if m_ and m_.name in DECAL_MATS]
|
|
if idx and me.uv_layers:
|
|
uvl = me.uv_layers.active.data
|
|
for p in me.polygons:
|
|
if p.material_index in idx:
|
|
keep[p.index] = [tuple(uvl[li].uv) for li in p.loop_indices]
|
|
uv_box(o, scale)
|
|
if keep:
|
|
uvl = me.uv_layers.active.data
|
|
for p in me.polygons:
|
|
if p.index in keep:
|
|
for li, uv in zip(p.loop_indices, keep[p.index]):
|
|
uvl[li].uv = uv
|
|
return o
|
|
|
|
|
|
def finalize(o, uv=1.0, ang=40):
|
|
uv_keep(o, uv)
|
|
smooth(o, ang)
|
|
return o
|
|
|
|
|
|
def hexbolt(x, y, z, r=0.02, h=0.02, m="M_Steel", axis="Z"):
|
|
o = cyl("bolt", r, h, verts=6, m=m, bevel=0.004, segs=1, axis=axis)
|
|
o.location = (x, y, z)
|
|
return apply_xform(o)
|
|
|
|
|
|
def bvh_of(o):
|
|
bm = bmesh.new()
|
|
bm.from_mesh(o.data)
|
|
bm.transform(o.matrix_world)
|
|
t = BVHTree.FromBMesh(bm)
|
|
bm.free()
|
|
return t
|
|
|
|
|
|
# =============================================================================== DECOR
|
|
|
|
def decor_lamp():
|
|
P = []
|
|
P.append(rev("foot", [(0, 0), (0.3, 0), (0.33, 0.015), (0.335, 0.05), (0.32, 0.075), (0.22, 0.1), (0.14, 0.14), (0.11, 0.2), (0.105, 0.24)],
|
|
["M_PaintWhite"] * 4 + ["M_PaintOrange"] * 4, segs=24))
|
|
P.append(torus("bump", 0.315, 0.03, loc=(0, 0, 0.035), seg=24, rseg=6, m="M_Rubber"))
|
|
for k in range(6):
|
|
a = TAU * k / 6 + 0.3
|
|
P.append(hexbolt(math.cos(a) * 0.255, math.sin(a) * 0.255, 0.09, r=0.02, h=0.03))
|
|
P.append(rev("post", [(0.1, 0.2), (0.094, 1.2), (0.088, 2.06)], "M_PaintWhite", segs=20, close_top=False))
|
|
col = [(0.09, 0), (0.106, 0.008), (0.112, 0.03), (0.112, 0.13), (0.106, 0.152), (0.09, 0.16)]
|
|
P.append(rev("band", [(r, z + 0.45) for r, z in col], "M_PaintOrange", segs=20, close_top=False))
|
|
P.append(rev("band2", [(r * 0.97, z * 0.55 + 1.8) for r, z in col], "M_Teal", segs=20, close_top=False))
|
|
# little hanging name tag + hook
|
|
P.append(rod((0.0, -0.08, 1.5), (0.0, -0.17, 1.5), 0.013, "M_Steel", verts=8))
|
|
tag = slab("tag", fillet2d([(-0.1, -0.22), (0.1, -0.22), (0.1, 0.0), (-0.1, 0.0)], 0.035), -0.012, 0.012, "M_PaintOrange", plane="XZ", bevel=0.006)
|
|
xf(tag, loc=(0, -0.18, 1.48))
|
|
P.append(tag)
|
|
P.append(decal("tagd", (0, -0.1935, 1.37), 0.16, 0.16, (0, -1, 0), "M_Logo"))
|
|
# head: cup, cage, cap
|
|
P.append(rev("cup", [(0.088, 2.05), (0.095, 2.09), (0.16, 2.14), (0.19, 2.16), (0.193, 2.19), (0.16, 2.205), (0.12, 2.2)],
|
|
["M_PaintWhite"] * 3 + ["M_PaintOrange"] * 3, segs=24))
|
|
for k in range(4):
|
|
a = TAU * k / 4 + math.pi / 4
|
|
pts = [(math.cos(a) * r, math.sin(a) * r, z) for r, z in ((0.17, 2.19), (0.225, 2.27), (0.235, 2.37), (0.215, 2.47), (0.17, 2.54))]
|
|
P.append(tube("cage", pts, 0.013, m="M_DarkGrey", res=4, segs=4))
|
|
P.append(torus("cring", 0.232, 0.012, loc=(0, 0, 2.37), seg=24, rseg=4, m="M_DarkGrey"))
|
|
P.append(rev("cap", [(0.0, 2.52), (0.16, 2.535), (0.255, 2.545), (0.268, 2.575), (0.25, 2.61), (0.19, 2.66), (0.1, 2.7), (0.0, 2.71)],
|
|
["M_PaintWhite"] + ["M_PaintOrange"] * 6, segs=24))
|
|
P.append(sphere("knob", 0.04, (0, 0, 2.74), seg=12, rings=8, m="M_PaintWhite"))
|
|
body = join(P, "Body")
|
|
finalize(body)
|
|
bulb = sphere("Bulb", 0.2, (0, 0, 2.37), seg=20, rings=12, m="M_Emissive", scale=(1, 1, 1.02))
|
|
smooth(bulb, 80)
|
|
uv_box(bulb, 1)
|
|
return dict(elev=12)
|
|
|
|
|
|
def frond(length, width, yaw, pitch, base, droop=0.9, n=12, m="M_Plant"):
|
|
bm = bmesh.new()
|
|
L, R, C = [], [], []
|
|
for i in range(n + 1):
|
|
t = i / n
|
|
u = length * t
|
|
z = length * (math.tan(pitch) * t * 0.8 - droop * t * t)
|
|
w = width * (math.sin(math.pi * min(1.0, t * 1.06)) ** 0.6) * (1.0 - 0.2 * t)
|
|
fwd = 0.0
|
|
if i % 2 == 1:
|
|
w *= 0.5
|
|
else:
|
|
fwd = 0.035 * length
|
|
fold = w * 0.32
|
|
C.append(bm.verts.new((u, 0, z)))
|
|
L.append(bm.verts.new((u + fwd, w, z - fold)))
|
|
R.append(bm.verts.new((u + fwd, -w, z - fold)))
|
|
for i in range(n):
|
|
bm.faces.new((L[i], C[i], C[i + 1], L[i + 1]))
|
|
bm.faces.new((C[i], R[i], R[i + 1], C[i + 1]))
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
for f in bm.faces:
|
|
f.normal_update()
|
|
if sum(f.normal.z for f in bm.faces) < 0:
|
|
for f in bm.faces:
|
|
f.normal_flip()
|
|
o = mesh_obj("frond", bm)
|
|
set_mats(o, m)
|
|
dbl(o, 0.008)
|
|
o.rotation_euler = (0, 0, yaw)
|
|
o.location = base
|
|
return apply_xform(o)
|
|
|
|
|
|
def decor_palm():
|
|
P = []
|
|
pot_prof = [(0, 0), (0.25, 0), (0.275, 0.02), (0.31, 0.2), (0.34, 0.4), (0.345, 0.42), (0.38, 0.43), (0.39, 0.46), (0.39, 0.53), (0.37, 0.55), (0.34, 0.545), (0.33, 0.5)]
|
|
mats = ["M_Teal", "M_Teal", "M_Teal", "M_PaintOrange", "M_Teal", "M_PaintWhite", "M_PaintWhite", "M_PaintWhite", "M_PaintWhite", "M_PaintWhite", "M_PaintWhite"]
|
|
P.append(rev("pot", pot_prof, mats, segs=24, close_top=False))
|
|
P.append(cy(0.335, 0.44, 0.5, "M_Bark", verts=24, name="soil"))
|
|
rnd = random.Random(7)
|
|
for k in range(7):
|
|
a = rnd.uniform(0, TAU); rr = rnd.uniform(0.14, 0.27)
|
|
s = sphere("pebble", rnd.uniform(0.035, 0.05), (math.cos(a) * rr, math.sin(a) * rr, 0.5), seg=6, rings=4,
|
|
m=rnd.choice(["M_PaintWhite", "M_PaintWhite", "M_Teal"]), scale=(1, 0.8, 0.55))
|
|
P.append(s)
|
|
# segmented curved trunk
|
|
ctrl = [(0, 0, 0.48), (0.03, 0.0, 1.0), (0.12, 0.04, 1.5), (0.26, 0.08, 2.0)]
|
|
path = bez(ctrl, 9)
|
|
for i in range(len(path) - 1):
|
|
p0, p1 = Vector(path[i]), Vector(path[i + 1])
|
|
d = p1 - p0
|
|
L = d.length
|
|
t = i / (len(path) - 1)
|
|
r0 = 0.11 - 0.035 * t
|
|
seg = rev("tr", [(r0 * 0.8, 0), (r0, L * 0.3), (r0 * 1.14, L * 0.82), (r0 * 1.2, L * 0.94), (r0 * 0.9, L * 1.04)], "M_Bark", segs=10, close_top=True)
|
|
seg.rotation_euler = d.to_track_quat("Z", "Y").to_euler()
|
|
seg.location = p0
|
|
apply_xform(seg)
|
|
P.append(seg)
|
|
top = Vector(path[-1]) + Vector((0, 0, 0.06))
|
|
P.append(sphere("crown", 0.12, top, seg=10, rings=7, m="M_Bark", scale=(1, 1, 0.8)))
|
|
for k in range(3):
|
|
a = TAU * k / 3 + 0.4
|
|
P.append(sphere("coco", 0.075, top + Vector((math.cos(a) * 0.1, math.sin(a) * 0.1, -0.09)), seg=8, rings=6, m="M_Patty"))
|
|
n = 10
|
|
for k in range(n):
|
|
yaw = TAU * k / n + rnd.uniform(-0.12, 0.12)
|
|
P.append(frond(rnd.uniform(1.0, 1.2), rnd.uniform(0.25, 0.29), yaw, math.radians(rnd.uniform(28, 50)), top,
|
|
droop=rnd.uniform(0.8, 1.05), m="M_Plant" if k % 2 == 0 else "M_LeavesDark"))
|
|
for k in range(3): # young upright fronds
|
|
yaw = TAU * k / 3 + 0.9
|
|
P.append(frond(0.65, 0.17, yaw, math.radians(68), top + Vector((0, 0, 0.04)), droop=0.65, n=10, m="M_Leaves"))
|
|
o = join(P, "SM_Decor_Palm")
|
|
finalize(o, ang=55)
|
|
return dict(elev=18)
|
|
|
|
|
|
def decor_bench():
|
|
P = []
|
|
side = fillet2d([(-0.3, 0.0), (-0.17, 0.0), (-0.13, 0.26), (0.11, 0.26), (0.15, 0.0), (0.3, 0.0), (0.3, 0.06),
|
|
(0.25, 0.4), (0.33, 0.9), (0.21, 0.92), (0.12, 0.47), (-0.3, 0.47)],
|
|
[0.04, 0.03, 0.06, 0.06, 0.03, 0.04, 0.05, 0.06, 0.04, 0.04, 0.06, 0.05], n=2)
|
|
for sx in (-1, 1):
|
|
x = sx * 0.82
|
|
P.append(slab("side", side, x - 0.05, x + 0.05, "M_PaintWhite", plane="YZ", bevel=0.02, segs=1))
|
|
for (yy, zz) in ((-0.22, 0.43), (0.06, 0.43), (0.21, 0.6), (0.255, 0.78)):
|
|
P.append(hexbolt(x + sx * 0.055, yy, zz, r=0.018, h=0.014, axis="X"))
|
|
for yy in (-0.235, 0.225):
|
|
P.append(bx(x - 0.07, x + 0.07, yy - 0.07, yy + 0.07, -0.0, 0.025, "M_Rubber", bevel=0.01, name="foot"))
|
|
# armrest cap
|
|
P.append(softbox("arm", (0.16, 0.36, 0.06), (x, -0.12, 0.64), r=0.03, m="M_Teal", na=2, nf=2))
|
|
P.append(rod((x, -0.05, 0.47), (x, -0.05, 0.61), 0.022, "M_Steel", verts=10))
|
|
P.append(rod((x, -0.24, 0.47), (x, -0.24, 0.61), 0.022, "M_Steel", verts=10))
|
|
for yy in (-0.21, -0.04, 0.13):
|
|
P.append(softbox("slat", (1.86, 0.15, 0.055), (0, yy, 0.5), r=0.025, m="M_PaintOrange", na=2, nf=2))
|
|
for k, (yy, zz) in enumerate(((0.23, 0.66), (0.28, 0.84))):
|
|
s = softbox("bslat", (1.86, 0.055, 0.15), (0, 0, 0), r=0.025, m="M_PaintOrange", na=2, nf=2)
|
|
xf(s, loc=(0, yy, zz), rot=(-12, 0, 0))
|
|
P.append(s)
|
|
P.append(bx(-0.78, 0.78, -0.05, 0.03, 0.38, 0.47, "M_PaintWhite", bevel=0.02, name="stringer"))
|
|
o = join(P, "Body")
|
|
finalize(o)
|
|
o.name = "SM_Decor_Bench"
|
|
pl = decal("plaque", (0.0, 0.252, 0.83), 0.24, 0.12, (0, -0.97, 0.22), "M_Label")
|
|
xf(pl, loc=(0, -0.01, 0))
|
|
o = join([o, pl], "SM_Decor_Bench")
|
|
return dict(elev=22)
|
|
|
|
|
|
def decor_umbrella():
|
|
P = []
|
|
P.append(rev("base", [(0, 0), (0.36, 0), (0.39, 0.02), (0.4, 0.07), (0.38, 0.12), (0.3, 0.16), (0.16, 0.19), (0.08, 0.2), (0.06, 0.3), (0.05, 0.34)],
|
|
["M_PaintWhite", "M_PaintWhite", "M_PaintOrange", "M_PaintOrange", "M_PaintWhite", "M_PaintWhite", "M_PaintWhite", "M_Teal", "M_Teal"], segs=24))
|
|
P.append(torus("bump", 0.39, 0.025, loc=(0, 0, 0.03), seg=24, rseg=5, m="M_Rubber"))
|
|
P.append(cy(0.05, 0.16, 0.2, "M_DarkGrey", x=0.24, verts=12, bevel=0.01, name="cap")) # fill cap
|
|
P.append(rod((0, 0, 0.3), (0, 0, 2.3), 0.026, "M_Steel", verts=12))
|
|
P.append(cy(0.04, 1.2, 1.28, "M_DarkGrey", verts=12, bevel=0.01, name="crankhub"))
|
|
P.append(rod((0, 0, 1.24), (0.0, -0.13, 1.24), 0.012, "M_DarkGrey", verts=8))
|
|
P.append(cy(0.02, 1.24 - 0.04, 1.24 + 0.05, "M_Teal", y=-0.13, verts=10, name="crank"))
|
|
# drink tray clipped to the pole
|
|
P.append(cy(0.045, 1.0, 1.04, "M_DarkGrey", verts=12, name="clamp"))
|
|
P.append(bx(0.03, 0.2, -0.015, 0.015, 1.0, 1.03, "M_DarkGrey", bevel=0.008, name="arm"))
|
|
P.append(cy(0.09, 0.995, 1.025, "M_PaintWhite", x=0.22, verts=20, bevel=0.008, name="tray"))
|
|
P.append(rev("cup", [(0.0, 1.025), (0.04, 1.025), (0.055, 1.15), (0.058, 1.16)], "M_Teal", segs=16, loc=(0.22, 0, 0)))
|
|
P.append(cy(0.052, 1.14, 1.145, "M_PaintOrange", x=0.22, verts=16, name="juice"))
|
|
P.append(rod((0.22, 0, 1.08), (0.25, -0.03, 1.25), 0.006, "M_PaintRed", verts=6))
|
|
sl = cy(0.035, -0.004, 0.004, "M_PaintYellow", verts=12, name="slice")
|
|
xf(sl, loc=(0.275, 0.0, 1.16), rot=(0, 70, 0))
|
|
P.append(sl)
|
|
# canopy
|
|
Pn, sub, nr = 8, 4, 6
|
|
R, top = 1.05, 2.28
|
|
na = Pn * sub
|
|
bm = bmesh.new()
|
|
grid = []
|
|
for i in range(nr + 1):
|
|
row = []
|
|
for j in range(na):
|
|
th = TAU * j / na
|
|
frac = (j % sub) / sub
|
|
rr = 0.06 + (R - 0.06) * i / nr
|
|
rr *= 1.0 - 0.07 * math.sin(math.pi * frac) * (i / nr)
|
|
z = top - 0.45 * (rr / R) ** 1.5 - 0.07 * (rr / R) * math.sin(math.pi * frac)
|
|
row.append(bm.verts.new((math.cos(th) * rr, math.sin(th) * rr, z)))
|
|
grid.append(row)
|
|
val = []
|
|
for j in range(na):
|
|
frac = (j % sub) / sub
|
|
v = grid[nr][j].co
|
|
val.append(bm.verts.new((v.x * 1.01, v.y * 1.01, v.z - 0.08 - 0.06 * math.sin(math.pi * frac))))
|
|
for i in range(nr):
|
|
for j in range(na):
|
|
f = bm.faces.new((grid[i][j], grid[i][(j + 1) % na], grid[i + 1][(j + 1) % na], grid[i + 1][j]))
|
|
f.material_index = (j // sub) % 2
|
|
for j in range(na):
|
|
f = bm.faces.new((grid[nr][j], grid[nr][(j + 1) % na], val[(j + 1) % na], val[j]))
|
|
f.material_index = 1 - (j // sub) % 2
|
|
top_ring = [grid[0][j] for j in range(na)]
|
|
cap = bm.faces.new(top_ring)
|
|
cap.material_index = 1
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
can = mesh_obj("canopy", bm)
|
|
add_mats(can, "M_PaintOrange", "M_PaintWhite")
|
|
bm2 = bmesh.new(); bm2.from_mesh(can.data)
|
|
for f in bm2.faces:
|
|
if f.normal.z < -0.2:
|
|
f.normal_flip()
|
|
bm2.to_mesh(can.data); bm2.free()
|
|
mod(can, "SOLIDIFY", thickness=0.014, offset=-1)
|
|
bake(can)
|
|
P.append(can)
|
|
# ribs + stretchers
|
|
for k in range(Pn):
|
|
th = TAU * k / Pn
|
|
pts = []
|
|
for i in range(7):
|
|
rr = 0.05 + (R - 0.05) * i / 6
|
|
z = top - 0.45 * (rr / R) ** 1.5 - 0.025
|
|
pts.append((math.cos(th) * rr, math.sin(th) * rr, z))
|
|
P.append(ptube("rib", pts, 0.01, "M_PaintWhite", rs=0))
|
|
P.append(sphere("tip", 0.022, (math.cos(th) * (R + 0.01), math.sin(th) * (R + 0.01), top - 0.45), seg=6, rings=4, m="M_PaintWhite"))
|
|
rr = R * 0.5
|
|
P.append(rod((0, 0, top - 0.42), (math.cos(th) * rr, math.sin(th) * rr, top - 0.42 * 0.5 ** 1.6 - 0.03), 0.007, "M_Steel", verts=6))
|
|
P.append(cy(0.04, top - 0.46, top - 0.38, "M_PaintWhite", verts=12, bevel=0.01, name="runner"))
|
|
P.append(cy(0.05, top - 0.02, top + 0.06, "M_PaintWhite", verts=12, bevel=0.015, name="hub"))
|
|
P.append(sphere("finial", 0.045, (0, 0, top + 0.1), seg=12, rings=8, m="M_PaintOrange"))
|
|
o = join(P, "SM_Decor_Umbrella")
|
|
finalize(o, ang=45)
|
|
return dict(elev=22)
|
|
|
|
|
|
def decor_flag():
|
|
P = []
|
|
P.append(rev("base", [(0, 0), (0.22, 0), (0.24, 0.015), (0.24, 0.06), (0.22, 0.08), (0.12, 0.11), (0.07, 0.15), (0.06, 0.24)],
|
|
["M_PaintWhite", "M_PaintWhite", "M_PaintOrange", "M_PaintWhite", "M_PaintWhite", "M_PaintWhite", "M_Teal"], segs=28))
|
|
P.append(torus("bump", 0.225, 0.02, loc=(0, 0, 0.025), seg=28, rseg=6, m="M_Rubber"))
|
|
for k in range(5):
|
|
a = TAU * k / 5
|
|
P.append(hexbolt(math.cos(a) * 0.17, math.sin(a) * 0.17, 0.095, r=0.015, h=0.025))
|
|
P.append(rev("pole", [(0.04, 0.2), (0.036, 2.0), (0.03, 4.3)], "M_PaintWhite", segs=14, close_top=True))
|
|
for z0, mm in ((0.6, "M_PaintOrange"), (0.7, "M_PaintWhite"), (0.8, "M_PaintOrange")):
|
|
P.append(cy(0.043, z0, z0 + 0.1, mm, verts=14, name="band"))
|
|
P.append(sphere("finial", 0.065, (0, 0, 4.36), seg=14, rings=10, m="M_Gold"))
|
|
P.append(cy(0.045, 4.27, 4.3, "M_DarkGrey", verts=14, name="truck"))
|
|
# halyard + cleat
|
|
P.append(ptube("halyard", [(-0.045, 0.0, 4.28), (-0.05, 0.0, 2.5), (-0.055, 0.0, 1.16)], 0.006, "M_Rope", rs=0))
|
|
P.append(bx(-0.08, -0.04, -0.07, 0.07, 1.1, 1.13, "M_Steel", bevel=0.01, name="cleat"))
|
|
P.append(bx(-0.06, -0.035, -0.02, 0.02, 1.07, 1.12, "M_Steel", bevel=0.006, name="cleatpost"))
|
|
for k in range(4):
|
|
P.append(torus("coil", 0.04 - k * 0.002, 0.007, loc=(-0.075, 0.0, 1.06 - k * 0.012), axis="X", seg=12, rseg=4, m="M_Rope"))
|
|
for z in (4.18, 3.18):
|
|
P.append(torus("ring", 0.045, 0.008, loc=(0.0, 0, z), seg=12, rseg=4, m="M_Steel"))
|
|
body = join(P, "Body")
|
|
finalize(body)
|
|
# cloth: 1.5 x 1.0, hoist at x=0.05, flies toward +X (Unity -X)
|
|
W, H, nu, nv = 1.5, 1.0, 24, 12
|
|
top = 4.2
|
|
bm = bmesh.new()
|
|
uvl = bm.loops.layers.uv.verify()
|
|
G = []
|
|
for i in range(nu + 1):
|
|
u = i / nu
|
|
col = []
|
|
for j in range(nv + 1):
|
|
v = j / nv
|
|
x = 0.05 + W * u
|
|
y = 0.09 * math.sin(u * 7.0 + v * 0.8) * u ** 0.8
|
|
z = top - H + H * v - 0.06 * u * u
|
|
col.append(bm.verts.new((x, y, z)))
|
|
G.append(col)
|
|
for i in range(nu):
|
|
for j in range(nv):
|
|
f = bm.faces.new((G[i][j], G[i + 1][j], G[i + 1][j + 1], G[i][j + 1]))
|
|
uc, vc = (i + 0.5) / nu, (j + 0.5) / nv
|
|
if 1 / nu <= uc <= 9 / nu and 3 / nv <= vc <= 9 / nv:
|
|
mi = 3
|
|
elif uc < 10 / nu:
|
|
mi = 1
|
|
elif vc < 3 / nv:
|
|
mi = 2
|
|
elif 7 / nv <= vc <= 8 / nv:
|
|
mi = 1
|
|
else:
|
|
mi = 0
|
|
f.material_index = mi
|
|
for l, (ii, jj) in zip(f.loops, ((i, j), (i + 1, j), (i + 1, j + 1), (i, j + 1))):
|
|
if mi == 3:
|
|
l[uvl].uv = ((ii - 1) / 8, (jj - 3) / 6)
|
|
else:
|
|
l[uvl].uv = (ii / nu * 1.5, jj / nv)
|
|
cloth = mesh_obj("Cloth", bm)
|
|
add_mats(cloth, "M_Teal", "M_PaintWhite", "M_PaintOrange", "M_Logo")
|
|
mod(cloth, "SOLIDIFY", thickness=0.01, offset=0)
|
|
bake(cloth)
|
|
smooth(cloth, 80)
|
|
set_origin(cloth, (0, 0, top - H / 2))
|
|
return dict(elev=12, azim=-25)
|
|
|
|
|
|
def decor_dish():
|
|
P = []
|
|
hub = Vector((0, 0, 1.0))
|
|
for k in range(3):
|
|
a = TAU * k / 3 + math.pi / 2
|
|
foot = Vector((math.cos(a) * 0.72, math.sin(a) * 0.72, 0.06))
|
|
P.append(rod(foot, hub + Vector((math.cos(a) * 0.08, math.sin(a) * 0.08, 0)), 0.034, "M_PaintWhite", verts=10))
|
|
pad = rev("pad", [(0, 0), (0.11, 0), (0.12, 0.02), (0.1, 0.05), (0.05, 0.07), (0.04, 0.09)], ["M_Rubber", "M_Rubber", "M_PaintOrange", "M_PaintOrange", "M_PaintOrange"], segs=12)
|
|
xf(pad, loc=(foot.x, foot.y, 0))
|
|
P.append(pad)
|
|
P.append(hexbolt(foot.x + 0.07 * math.cos(a), foot.y + 0.07 * math.sin(a), 0.035, r=0.014, h=0.02))
|
|
b = TAU * (k + 1) / 3 + math.pi / 2
|
|
pa = Vector((math.cos(a) * 0.43, math.sin(a) * 0.43, 0.45))
|
|
pb = Vector((math.cos(b) * 0.43, math.sin(b) * 0.43, 0.45))
|
|
P.append(rod(pa, pb, 0.016, "M_Steel", verts=8))
|
|
P.append(rev("hub", [(0, 0.9), (0.1, 0.9), (0.12, 0.93), (0.12, 1.06), (0.09, 1.1), (0.065, 1.12)], ["M_DarkGrey", "M_PaintOrange", "M_PaintOrange", "M_DarkGrey", "M_DarkGrey"], segs=20))
|
|
P.append(cy(0.06, 1.1, 1.45, "M_PaintWhite", verts=16, name="mast"))
|
|
P.append(cy(0.085, 1.42, 1.5, "M_DarkGrey", verts=16, bevel=0.012, segs=1, name="bearing"))
|
|
# junction box + cable
|
|
jb = bx(-0.09, 0.09, -0.06, 0.06, -0.12, 0.12, "M_Teal", bevel=0.02, name="jbox")
|
|
xf(jb, loc=(0, 0.11, 1.25))
|
|
P.append(jb)
|
|
P.append(decal("jl", (0, 0.172, 1.25), 0.1, 0.1, (0, 1, 0), "M_Logo"))
|
|
P.append(tube("cable", [(0, 0.12, 1.12), (0.05, 0.25, 0.8), (0.12, 0.3, 0.3), (0.2, 0.32, 0.03), (0.4, 0.4, 0.02)], 0.014, m="M_Rubber", res=6, segs=4))
|
|
body = join(P, "Body")
|
|
finalize(body)
|
|
# ---------------------------------------------------------- Dish (rotates about Z, pivot on the bearing)
|
|
D = []
|
|
piv = Vector((0, 0, 1.5))
|
|
D.append(cy(0.1, 1.5, 1.56, "M_PaintWhite", verts=20, bevel=0.01, name="turn"))
|
|
yoke = fillet2d([(-0.1, 0.0), (0.1, 0.0), (0.07, 0.3), (-0.07, 0.3)], [0.01, 0.01, 0.05, 0.05])
|
|
for sx in (-1, 1):
|
|
y = slab("yoke", yoke, -0.02, 0.02, "M_PaintOrange", plane="YZ", bevel=0.008)
|
|
xf(y, loc=(sx * 0.17, 0, 1.55))
|
|
D.append(y)
|
|
D.append(bx(-0.19, 0.19, -0.08, 0.08, 1.54, 1.58, "M_PaintOrange", bevel=0.015, name="yokebase"))
|
|
D.append(rod((-0.2, 0, 1.8), (0.2, 0, 1.8), 0.03, "M_DarkGrey", verts=12))
|
|
for sx in (-1, 1):
|
|
D.append(hexbolt(sx * 0.205, 0, 1.8, r=0.03, h=0.02, axis="X"))
|
|
# reflector (+Z built, then aimed -Y and up 35 deg)
|
|
Rd, depth = 0.72, 0.2
|
|
f = Rd * Rd / (4 * depth)
|
|
prof = [(Rd * (i / 5) ** 0.85, (Rd * (i / 5) ** 0.85) ** 2 / (4 * f)) for i in range(6)]
|
|
refl = rev("refl", [(0, 0)] + prof[1:], "M_PaintWhite", segs=24, close_top=False)
|
|
refl.data.materials.append(mat("M_HullWhite"))
|
|
mod(refl, "SOLIDIFY", thickness=0.025, offset=-1, material_offset=1, material_offset_rim=0)
|
|
bake(refl)
|
|
parts = [refl]
|
|
parts.append(torus("rim", Rd, 0.024, loc=(0, 0, depth), seg=24, rseg=6, m="M_PaintOrange"))
|
|
parts.append(rev("back", [(0, -0.12), (0.14, -0.12), (0.2, -0.05), (0.24, 0.0)], "M_DarkGrey", segs=16, close_top=False))
|
|
for k in range(4):
|
|
a = TAU * k / 4 + math.pi / 4
|
|
parts.append(ptube("rib", [(math.cos(a) * 0.15, math.sin(a) * 0.15, -0.08), (math.cos(a) * 0.4, math.sin(a) * 0.4, 0.0), (math.cos(a) * 0.65, math.sin(a) * 0.65, 0.12)], 0.014, "M_DarkGrey", rs=0))
|
|
feed = Vector((0, 0, f))
|
|
for k in range(3):
|
|
a = TAU * k / 3 + math.pi / 2
|
|
rim = Vector((math.cos(a) * Rd * 0.96, math.sin(a) * Rd * 0.96, depth))
|
|
parts.append(rod(rim, feed - Vector((0, 0, 0.04)), 0.011, "M_Steel", verts=6))
|
|
parts.append(rev("feed", [(0, f - 0.06), (0.05, f - 0.06), (0.06, f + 0.03), (0.035, f + 0.06), (0, f + 0.065)], ["M_PaintOrange", "M_PaintOrange", "M_DarkGrey", "M_DarkGrey"], segs=14))
|
|
dsh = join(parts, "refl")
|
|
xf(dsh, loc=(0, 0, 0), rot=(55, 0, 0))
|
|
xf(dsh, loc=(0, -0.08, 1.8))
|
|
D.append(dsh)
|
|
cw = bx(-0.08, 0.08, 0.12, 0.3, 1.66, 1.82, "M_DarkGrey", bevel=0.03, name="cw")
|
|
D.append(cw)
|
|
D.append(rod((0, 0.05, 1.75), (0, 0.13, 1.74), 0.025, "M_Steel", verts=8))
|
|
dish = join(D, "Dish")
|
|
finalize(dish)
|
|
set_origin(dish, piv)
|
|
return dict(elev=22, azim=-40)
|
|
|
|
|
|
def crate(w, d, h, body_m, lid_m, clip_m="M_PaintWhite"):
|
|
P = []
|
|
b = bx(-w / 2, w / 2, -d / 2, d / 2, 0, h - 0.02, body_m, bevel=0.035, segs=2, name="crate")
|
|
for v in b.data.vertices:
|
|
t = v.co.z / h
|
|
s = 0.9 + 0.1 * t
|
|
v.co.x *= s
|
|
v.co.y *= s
|
|
P.append(b)
|
|
P.append(bx(-w / 2 - 0.012, w / 2 + 0.012, -d / 2 - 0.012, d / 2 + 0.012, h - 0.075, h - 0.03, body_m, bevel=0.015, segs=1, name="lip"))
|
|
for sy in (-1, 1):
|
|
for k in range(2):
|
|
x = (-0.22 + 0.44 * k) * w
|
|
P.append(bx(x - 0.018, x + 0.018, sy * d / 2 * 0.95 - 0.016, sy * d / 2 * 0.95 + 0.016, 0.03, h - 0.08, body_m, bevel=0.012, segs=1, name="rib"))
|
|
for sx in (-1, 1):
|
|
P.append(bx(sx * w / 2 * 0.955 - 0.012, sx * w / 2 * 0.955 + 0.012, -d * 0.3, d * 0.3, h - 0.17, h - 0.11, "M_DarkGrey", bevel=0.01, segs=1, name="handle"))
|
|
P.append(bx(sx * w / 2 * 0.955 - 0.018, sx * w / 2 * 0.955 + 0.018, -d * 0.33, d * 0.33, h - 0.11, h - 0.085, body_m, bevel=0.01, segs=1, name="grip"))
|
|
P.append(bx(-w / 2 - 0.02, w / 2 + 0.02, -d / 2 - 0.02, d / 2 + 0.02, h - 0.03, h + 0.025, lid_m, bevel=0.02, segs=2, name="lid"))
|
|
P.append(bx(-w / 2 + 0.06, w / 2 - 0.06, -d / 2 + 0.06, d / 2 - 0.06, h + 0.02, h + 0.045, lid_m, bevel=0.012, segs=1, name="lidp"))
|
|
for sy in (-1, 1):
|
|
for x in (-w * 0.28, w * 0.28):
|
|
P.append(bx(x - 0.04, x + 0.04, sy * (d / 2 + 0.025) - 0.012, sy * (d / 2 + 0.025) + 0.012, h - 0.07, h + 0.02, clip_m, bevel=0.008, segs=1, name="clip"))
|
|
P.append(decal("label", (0, -d / 2 * 0.955 - 0.0175, h * 0.42), w * 0.36, w * 0.18, (0, -1, 0), "M_Label"))
|
|
return join(P, "crate")
|
|
|
|
|
|
def decor_crates():
|
|
P = []
|
|
c = crate(0.8, 0.55, 0.42, "M_Teal", "M_PaintWhite"); xf(c, loc=(-0.42, -0.25, 0), rot=(0, 0, 2)); P.append(c)
|
|
c = crate(0.8, 0.55, 0.42, "M_PaintOrange", "M_PaintWhite"); xf(c, loc=(0.44, -0.18, 0), rot=(0, 0, -4)); P.append(c)
|
|
c = crate(0.8, 0.55, 0.42, "M_PaintWhite", "M_Teal", clip_m="M_PaintOrange"); xf(c, loc=(-0.05, 0.42, 0), rot=(0, 0, 88)); P.append(c)
|
|
c = crate(0.62, 0.44, 0.34, "M_PaintWhite", "M_PaintOrange", clip_m="M_Teal"); xf(c, loc=(0.0, -0.2, 0.47), rot=(0, 0, 9)); P.append(c)
|
|
# water jug on top
|
|
jug = rev("jug", [(0, 0), (0.1, 0), (0.115, 0.02), (0.12, 0.26), (0.1, 0.31), (0.04, 0.35), (0.035, 0.39), (0.04, 0.4)], "M_Bottle", segs=16)
|
|
jug2 = cy(0.045, 0.38, 0.42, "M_Teal", verts=16, bevel=0.008, name="jugcap")
|
|
jw = rev("jugw", [(0, 0.01), (0.105, 0.01), (0.11, 0.2)], "M_WaterFill", segs=16)
|
|
j = join([jug, jug2, jw], "jug")
|
|
xf(j, loc=(0.12, -0.25, 0.86))
|
|
P.append(j)
|
|
o = join(P, "SM_Decor_Crates")
|
|
finalize(o)
|
|
return dict(elev=24)
|
|
|
|
|
|
def decor_lifebuoy():
|
|
P = []
|
|
P.append(bx(-0.2, 0.2, -0.2, 0.2, 0, 0.05, "M_PaintWhite", bevel=0.02, name="plate"))
|
|
for sx in (-1, 1):
|
|
for sy in (-1, 1):
|
|
P.append(hexbolt(sx * 0.15, sy * 0.15, 0.055, r=0.016, h=0.02))
|
|
P.append(softbox("post", (0.13, 0.13, 1.55), (0, 0.04, 0.8), r=0.03, m="M_PaintWhite", na=2, nf=2))
|
|
P.append(softbox("cap", (0.17, 0.17, 0.08), (0, 0.04, 1.6), r=0.035, m="M_PaintOrange", na=2, nf=2, bulge=(0, 0, 0.02)))
|
|
for z in (0.2, 0.28):
|
|
P.append(bx(-0.07, 0.07, -0.03, 0.11, z, z + 0.05, "M_PaintOrange", bevel=0.01, name="stripe"))
|
|
# hook
|
|
P.append(ptube("hook", bez([(0, -0.02, 1.4), (0, -0.12, 1.4), (0, -0.16, 1.43), (0, -0.16, 1.48)], 8), 0.014, "M_Steel", rs=1))
|
|
# sign plate
|
|
P.append(bx(-0.125, 0.125, -0.04, -0.025, 0.98, 1.12, "M_PaintOrange", bevel=0.008, name="sign"))
|
|
# ring
|
|
Rr, rt = 0.3, 0.07
|
|
ctr = Vector((0, -0.12, 1.43 - Rr - rt + 0.02))
|
|
ring = torus("ring", Rr, rt, loc=(0, 0, 0), axis="Y", seg=32, rseg=10)
|
|
paint(ring, lambda c, n, i: (int(((math.atan2(c.z, c.x) + TAU) % TAU) / (TAU / 8) + 0.5)) % 2, ["M_PaintOrange", "M_PaintWhite"])
|
|
xf(ring, loc=tuple(ctr))
|
|
P.append(ring)
|
|
# grab line with 4 straps
|
|
pts = []
|
|
for k in range(64):
|
|
a = TAU * k / 64
|
|
frac = (a / (TAU / 4) + 0.5) % 1
|
|
sag = 0.03 * math.sin(math.pi * frac)
|
|
rr = Rr + rt + 0.006 + sag
|
|
pts.append((ctr.x + math.cos(a) * rr, ctr.y, ctr.z + math.sin(a) * rr - sag * 0.4))
|
|
P.append(ptube("grab", pts, 0.011, "M_Rope", cyclic=True, rs=1))
|
|
for k in range(4):
|
|
a = TAU * k / 4 + TAU / 8
|
|
st = torus("strap", rt + 0.006, 0.014, loc=(0, 0, 0), axis="X", seg=10, rseg=4, m="M_Rope")
|
|
xf(st, rot=(0, 90 - math.degrees(a), 0))
|
|
xf(st, loc=(ctr.x + math.cos(a) * Rr, ctr.y, ctr.z + math.sin(a) * Rr))
|
|
P.append(st)
|
|
# coiled throw line on a lower peg
|
|
P.append(rod((0.06, 0.04, 0.6), (0.17, 0.04, 0.6), 0.016, "M_Steel", verts=8))
|
|
for k in range(5):
|
|
c = torus("coil", 0.12 + 0.004 * k, 0.014, loc=(0, 0, 0), axis="X", seg=14, rseg=5, m="M_Rope")
|
|
xf(c, rot=(9 * k - 18, 0, 0), scale=(1, 0.85, 1.0))
|
|
xf(c, loc=(0.085 + 0.016 * k, 0.04, 0.6 - 0.11))
|
|
P.append(c)
|
|
P.append(ptube("tail", bez([(0.13, 0.0, 0.4), (0.16, -0.05, 0.25), (0.15, -0.1, 0.1), (0.2, -0.18, 0.03), (0.32, -0.2, 0.02)], 10), 0.013, "M_Rope", rs=1))
|
|
o = join(P, "SM_Decor_Lifebuoy")
|
|
finalize(o)
|
|
lb = decal("lbl", (0, -0.0415, 1.05), 0.21, 0.105, (0, -1, 0), "M_Label")
|
|
o = join([o, lb], "SM_Decor_Lifebuoy")
|
|
return dict(elev=14)
|
|
|
|
|
|
def decor_grill():
|
|
P = []
|
|
zr = 0.86
|
|
bowl = rev("bowl", [(0, 0.54), (0.12, 0.545), (0.23, 0.58), (0.31, 0.65), (0.345, 0.75), (0.35, zr - 0.01), (0.355, zr + 0.005), (0.345, zr + 0.012),
|
|
(0.335, zr), (0.325, 0.76), (0.29, 0.67), (0.22, 0.61), (0.11, 0.58), (0, 0.575)],
|
|
["M_PaintRed"] * 6 + ["M_Steel"] * 2 + ["M_Charcoal"] * 5, segs=24)
|
|
P.append(bowl)
|
|
# coals
|
|
rnd = random.Random(11)
|
|
P.append(cy(0.24, 0.6, 0.64, "M_Charcoal", verts=20, name="bed"))
|
|
for k in range(9):
|
|
a = rnd.uniform(0, TAU); rr = rnd.uniform(0, 0.2)
|
|
lump = sphere("lump", rnd.uniform(0.035, 0.05), (math.cos(a) * rr, math.sin(a) * rr, 0.65), seg=6, rings=4,
|
|
m="M_Ember" if k % 3 else "M_Charcoal", scale=(1, 1, 0.7))
|
|
P.append(lump)
|
|
# grate
|
|
P.append(torus("grate", 0.315, 0.008, loc=(0, 0, 0.79), seg=24, rseg=4, m="M_Steel"))
|
|
for k in range(-5, 6):
|
|
x = k * 0.055
|
|
hw = math.sqrt(max(0.0, 0.315 ** 2 - x * x))
|
|
P.append(rod((x, -hw, 0.79), (x, hw, 0.79), 0.006, "M_Steel", verts=4))
|
|
# food
|
|
for k, (x, y) in enumerate(((-0.12, -0.12), (-0.04, -0.14), (0.04, -0.13))):
|
|
s = ptube("sausage", [(x, y - 0.08, 0.815), (x + 0.01, y, 0.818), (x, y + 0.08, 0.815)], 0.026, "M_Sausage", rs=2)
|
|
P.append(s)
|
|
for (x, y) in ((0.1, 0.1), (-0.1, 0.12)):
|
|
P.append(cy(0.07, 0.8, 0.83, "M_Patty", x=x, y=y, verts=12, bevel=0.01, segs=1, name="patty"))
|
|
P.append(cy(0.072, 0.83, 0.838, "M_PaintYellow", x=x, y=y, verts=4, name="cheese"))
|
|
# handles on bowl
|
|
for sx in (-1, 1):
|
|
P.append(bx(sx * 0.37 - 0.03, sx * 0.37 + 0.03, -0.09, 0.09, 0.79, 0.82, "M_DarkGrey", bevel=0.012, segs=1, name="h"))
|
|
P.append(bx(sx * 0.4 - 0.02, sx * 0.4 + 0.02, -0.09, 0.09, 0.8, 0.83, "M_DarkGrey", bevel=0.012, segs=1, name="h2"))
|
|
# lid: hinged up at the back
|
|
lid = rev("lid", [(0.0, 0.25), (0.14, 0.235), (0.26, 0.16), (0.33, 0.06), (0.355, 0.0), (0.345, -0.01), (0.29, 0.07), (0.18, 0.18), (0, 0.215)],
|
|
["M_PaintRed"] * 4 + ["M_Steel"] * 1 + ["M_DarkGrey"] * 3, segs=24)
|
|
lp = [lid]
|
|
lp.append(bx(-0.09, 0.09, -0.025, 0.025, 0.26, 0.29, "M_DarkGrey", bevel=0.012, name="lh"))
|
|
for sx in (-1, 1):
|
|
lp.append(bx(sx * 0.07 - 0.012, sx * 0.07 + 0.012, -0.012, 0.012, 0.24, 0.27, "M_Steel", bevel=0.004, name="lhp"))
|
|
lp.append(rev("therm", [(0, 0), (0.04, 0), (0.04, 0.02), (0, 0.025)], ["M_Steel", "M_PaintWhite", "M_PaintWhite"], segs=14))
|
|
xf(lp[-1], loc=(0, 0, 0), rot=(-38, 0, 0))
|
|
xf(lp[-1], loc=(0, -0.13, 0.21))
|
|
lid = join(lp, "lid")
|
|
xf(lid, loc=(0, -0.355, 0), rot=(0, 0, 0))
|
|
xf(lid, rot=(-100, 0, 0))
|
|
xf(lid, loc=(0, 0.36, zr + 0.01))
|
|
P.append(lid)
|
|
P.append(rod((-0.1, 0.36, zr - 0.02), (0.1, 0.36, zr - 0.02), 0.012, "M_Steel", verts=8))
|
|
# legs, wheels, shelf, ash pan
|
|
feet = []
|
|
for k in range(3):
|
|
a = TAU * k / 3 - math.pi / 2
|
|
top = Vector((math.cos(a) * 0.24, math.sin(a) * 0.24, 0.6))
|
|
foot = Vector((math.cos(a) * 0.36, math.sin(a) * 0.36, 0.06 if k else 0.0))
|
|
P.append(rod(foot, top, 0.022, "M_DarkGrey", verts=10, r2=0.018))
|
|
feet.append(foot)
|
|
if k:
|
|
w = cyl("wheel", 0.07, 0.04, verts=14, m="M_Rubber", bevel=0.012, segs=1, axis="X")
|
|
xf(w, loc=(foot.x + math.copysign(0.03, foot.x), foot.y, 0.07))
|
|
P.append(w)
|
|
P.append(hexbolt(foot.x + math.copysign(0.052, foot.x), foot.y, 0.07, r=0.025, h=0.008, m="M_PaintWhite", axis="X"))
|
|
else:
|
|
P.append(cy(0.035, 0.0, 0.025, "M_Rubber", x=foot.x, y=foot.y, verts=12, bevel=0.008, name="foot"))
|
|
tri = [(math.cos(TAU * k / 3 - math.pi / 2) * 0.3, math.sin(TAU * k / 3 - math.pi / 2) * 0.3) for k in range(3)]
|
|
P.append(slab("shelf", fillet2d(tri, 0.06, n=2), 0.24, 0.265, "M_DarkGrey", plane="XY", bevel=0.008, segs=1))
|
|
P.append(rev("ash", [(0, 0.4), (0.13, 0.4), (0.15, 0.44), (0.15, 0.47), (0.13, 0.47), (0.12, 0.45)], ["M_Steel"] * 5, segs=20))
|
|
# tool bar + tools hanging on the right side
|
|
bar_x = 0.4
|
|
P.append(rod((bar_x, -0.1, 0.72), (bar_x, 0.1, 0.72), 0.01, "M_Steel", verts=8))
|
|
for yy in (-0.1, 0.1):
|
|
P.append(rod((bar_x - 0.04, yy, 0.74), (bar_x, yy, 0.72), 0.008, "M_Steel", verts=6))
|
|
# spatula
|
|
sp = [rod((0, 0, 0), (0, 0, -0.22), 0.007, "M_Steel", verts=6)]
|
|
sp.append(bx(-0.012, 0.012, -0.016, 0.016, 0.0, 0.1, "M_Teal", bevel=0.008, segs=1, name="sh"))
|
|
sp.append(bx(-0.004, 0.004, -0.045, 0.045, -0.33, -0.22, "M_Steel", bevel=0.003, segs=1, name="blade"))
|
|
spat = join(sp, "spat"); xf(spat, loc=(bar_x + 0.015, -0.05, 0.62), rot=(0, 4, 0)); P.append(spat)
|
|
tg = [bx(-0.012, 0.012, -0.016, 0.016, 0.0, 0.08, "M_PaintOrange", bevel=0.008, segs=1, name="th")]
|
|
for s in (-1, 1):
|
|
tg.append(rod((0, 0, 0.0), (0, s * 0.03, -0.26), 0.006, "M_Steel", verts=6))
|
|
tongs = join(tg, "tongs"); xf(tongs, loc=(bar_x + 0.015, 0.06, 0.64), rot=(0, -3, 0)); P.append(tongs)
|
|
o = join(P, "SM_Decor_Grill")
|
|
finalize(o)
|
|
return dict(elev=30, azim=-30)
|
|
|
|
|
|
def decor_hammock():
|
|
P = []
|
|
span = 1.6
|
|
for sx in (-1, 1):
|
|
x = sx * span
|
|
P.append(bx(x - 0.26, x + 0.26, -0.26, 0.26, 0, 0.07, "M_PaintWhite", bevel=0.025, name="foot"))
|
|
P.append(bx(x - 0.27, x + 0.27, -0.27, 0.27, 0.0, 0.02, "M_Rubber", bevel=0.008, name="pad"))
|
|
for by_ in (-1, 1):
|
|
P.append(hexbolt(x + sx * 0.19, by_ * 0.19, 0.075, r=0.016, h=0.02))
|
|
P.append(bx(x - 0.075, x + 0.075, -0.075, 0.075, 0.05, 1.6, "M_PaintWhite", bevel=0.035, segs=2, name="post"))
|
|
P.append(bx(x - 0.095, x + 0.095, -0.095, 0.095, 1.57, 1.68, "M_PaintOrange", bevel=0.04, segs=2, name="cap"))
|
|
P.append(bx(x - 0.08, x + 0.08, -0.08, 0.08, 0.3, 0.38, "M_PaintOrange", bevel=0.012, name="stripe"))
|
|
P.append(rod((x - sx * 0.07, 0, 0.6), (x - sx * 0.24, 0, 0.07), 0.026, "M_PaintWhite", verts=10))
|
|
eye = torus("eye", 0.045, 0.012, loc=(0, 0, 0), axis="Y", seg=12, rseg=4, m="M_Steel")
|
|
xf(eye, loc=(x - sx * 0.11, 0, 1.38))
|
|
P.append(eye)
|
|
# spreader bars + ropes
|
|
sb_x = 1.08
|
|
W = 0.86
|
|
for sx in (-1, 1):
|
|
x = sx * sb_x
|
|
P.append(rod((x, -W / 2 - 0.05, 0.95), (x, W / 2 + 0.05, 0.95), 0.022, "M_Wood", verts=10))
|
|
for yy in (-W / 2 - 0.05, W / 2 + 0.05):
|
|
P.append(sphere("knob", 0.03, (x, yy, 0.95), seg=6, rings=4, m="M_Wood"))
|
|
ring = Vector((sx * (span - 0.11 - 0.05), 0, 1.36))
|
|
for k in range(5):
|
|
yy = -W / 2 + W * k / 4
|
|
P.append(rod(ring, (x, yy, 0.97), 0.006, "M_Rope", verts=5))
|
|
P.append(torus("ring", 0.04, 0.01, loc=tuple(ring), axis="Y", seg=10, rseg=4, m="M_Steel"))
|
|
# fabric bed
|
|
nu, nv = 24, 9
|
|
bm = bmesh.new()
|
|
G = []
|
|
for i in range(nu + 1):
|
|
u = -1 + 2 * i / nu
|
|
col = []
|
|
for j in range(nv + 1):
|
|
v = -1 + 2 * j / nv
|
|
x = sb_x * u
|
|
w = W / 2 * (1 - 0.12 * (1 - u * u))
|
|
y = v * w
|
|
z = 0.95 - 0.42 * (1 - u * u) + 0.13 * v * v * (1 - 0.3 * u * u)
|
|
col.append(bm.verts.new((x, y, z)))
|
|
G.append(col)
|
|
stripes = [0, 1, 0, 2, 2, 2, 0, 1, 0]
|
|
for i in range(nu):
|
|
for j in range(nv):
|
|
f = bm.faces.new((G[i][j], G[i + 1][j], G[i + 1][j + 1], G[i][j + 1]))
|
|
f.material_index = stripes[j]
|
|
bed = mesh_obj("bed", bm)
|
|
add_mats(bed, "M_Teal", "M_PaintWhite", "M_CushionOrange")
|
|
bm2 = bmesh.new(); bm2.from_mesh(bed.data)
|
|
for f in bm2.faces:
|
|
f.normal_update()
|
|
if sum(f.normal.z for f in bm2.faces) < 0:
|
|
for f in bm2.faces:
|
|
f.normal_flip()
|
|
bm2.to_mesh(bed.data); bm2.free()
|
|
dbl(bed, 0.012)
|
|
P.append(bed)
|
|
pil = softbox("pillow", (0.3, 0.5, 0.12), (0, 0, 0), r=0.05, m="M_Canvas", bulge=(0, 0, 0.03))
|
|
xf(pil, loc=(-0.78, 0, 0.73), rot=(0, -28, 0))
|
|
P.append(pil)
|
|
book = bx(-0.09, 0.09, -0.065, 0.065, 0, 0.025, "M_PaintRed", bevel=0.006, name="book")
|
|
xf(book, loc=(0.25, 0.06, 0.54), rot=(0, 4, 25))
|
|
P.append(book)
|
|
o = join(P, "SM_Decor_Hammock")
|
|
finalize(o, ang=50)
|
|
return dict(elev=24, azim=-28)
|
|
|
|
|
|
def decor_beacon():
|
|
P = []
|
|
P.append(rev("plinth", [(0, 0), (0.62, 0), (0.65, 0.02), (0.65, 0.16), (0.6, 0.2), (0.52, 0.22), (0.5, 0.26)],
|
|
["M_DarkGrey", "M_DarkGrey", "M_PaintWhite", "M_PaintWhite", "M_PaintWhite", "M_PaintWhite"], segs=8, phase=math.pi / 8))
|
|
for k in range(8):
|
|
a = TAU * k / 8 + TAU / 16
|
|
b = cyl("bolt", 0.025, 0.03, verts=6, m="M_Steel")
|
|
xf(b, loc=(math.cos(a) * 0.56, math.sin(a) * 0.56, 0.215))
|
|
P.append(b)
|
|
# banded tapered tower
|
|
zb, zt, rb, rt = 0.24, 2.0, 0.46, 0.31
|
|
prof, mats = [], []
|
|
nb = 5
|
|
for k in range(nb):
|
|
z0 = zb + (zt - zb) * k / nb
|
|
z1 = zb + (zt - zb) * (k + 1) / nb
|
|
for t in (0.0, 0.5):
|
|
z = z0 + (z1 - z0) * t
|
|
prof.append((rb + (rt - rb) * (z - zb) / (zt - zb), z))
|
|
mats.append("M_PaintRed" if k % 2 == 0 else "M_PaintWhite")
|
|
prof.append((rt, zt))
|
|
P.append(rev("tower", prof, mats, segs=28, close_top=False))
|
|
# door
|
|
door = slab("door", fillet2d([(-0.17, 0.0), (0.17, 0.0), (0.17, 0.42), (0.0, 0.56), (-0.17, 0.42)], [0.02, 0.02, 0.1, 0.1, 0.1], n=2), -0.04, 0.04, "M_PaintWhite", plane="XZ", bevel=0.012, segs=1)
|
|
xf(door, loc=(0, -0.43, 0.26))
|
|
P.append(door)
|
|
dpan = slab("dpan", fillet2d([(-0.13, 0.0), (0.13, 0.0), (0.13, 0.39), (0.0, 0.5), (-0.13, 0.39)], [0.01, 0.01, 0.09, 0.09, 0.09], n=2), -0.03, 0.03, "M_Teal", plane="XZ", bevel=0.01, segs=1)
|
|
xf(dpan, loc=(0, -0.45, 0.27))
|
|
P.append(dpan)
|
|
P.append(sphere("knob", 0.022, (0.08, -0.48, 0.5), seg=8, rings=6, m="M_Brass"))
|
|
# portholes
|
|
for z, a in ((1.15, -90), (1.65, -30)):
|
|
rr = rb + (rt - rb) * (z - zb) / (zt - zb)
|
|
d = Vector((math.cos(math.radians(a)), math.sin(math.radians(a)), 0))
|
|
c = d * (rr - 0.005) + Vector((0, 0, z))
|
|
ring = torus("port", 0.085, 0.02, axis="Y", seg=14, rseg=4, m="M_Brass")
|
|
gl = cyl("glass", 0.08, 0.02, axis="Y", verts=14, m="M_Navy")
|
|
pr = join([ring, gl], "porthole")
|
|
xf(pr, rot=(0, 0, a + 90))
|
|
xf(pr, loc=tuple(c))
|
|
P.append(pr)
|
|
# ladder rungs on the back
|
|
for k in range(6):
|
|
z = 0.5 + k * 0.24
|
|
rr = rb + (rt - rb) * (z - zb) / (zt - zb)
|
|
P.append(ptube("rung", [(-0.12, rr - 0.01, z), (-0.12, rr + 0.07, z), (0.12, rr + 0.07, z), (0.12, rr - 0.01, z)], 0.012, "M_Steel", rs=0))
|
|
# gallery
|
|
P.append(rev("gallery", [(0, 1.98), (0.5, 1.98), (0.52, 2.0), (0.52, 2.06), (0.5, 2.08), (0, 2.08)], ["M_PaintWhite", "M_PaintWhite", "M_PaintOrange", "M_PaintWhite", "M_PaintWhite"], segs=28))
|
|
for k in range(10):
|
|
a = TAU * k / 10
|
|
P.append(rod((math.cos(a) * 0.48, math.sin(a) * 0.48, 2.08), (math.cos(a) * 0.48, math.sin(a) * 0.48, 2.36), 0.012, "M_PaintWhite", verts=6))
|
|
P.append(torus("rail", 0.48, 0.018, loc=(0, 0, 2.37), seg=28, rseg=5, m="M_PaintRed"))
|
|
P.append(torus("rail2", 0.48, 0.01, loc=(0, 0, 2.22), seg=28, rseg=4, m="M_PaintWhite"))
|
|
# lantern room
|
|
P.append(cy(0.27, 2.08, 2.14, "M_PaintWhite", verts=16, bevel=0.01, name="lbase"))
|
|
P.append(cy(0.25, 2.14, 2.52, "M_Glass", verts=12, name="glass"))
|
|
for k in range(6):
|
|
a = TAU * k / 6
|
|
P.append(rod((math.cos(a) * 0.255, math.sin(a) * 0.255, 2.14), (math.cos(a) * 0.255, math.sin(a) * 0.255, 2.52), 0.016, "M_PaintWhite", verts=6))
|
|
P.append(rev("roof", [(0, 2.5), (0.33, 2.5), (0.34, 2.53), (0.3, 2.58), (0.2, 2.7), (0.08, 2.82), (0.05, 2.86)],
|
|
["M_PaintRed"] * 6, segs=24))
|
|
P.append(sphere("vent", 0.07, (0, 0, 2.9), seg=12, rings=8, m="M_PaintRed"))
|
|
P.append(cy(0.05, 2.92, 2.96, "M_PaintWhite", verts=12, name="ventcap"))
|
|
P.append(rod((0, 0, 2.95), (0, 0, 3.12), 0.008, "M_Brass", verts=6))
|
|
P.append(sphere("tip", 0.018, (0, 0, 3.13), seg=8, rings=5, m="M_Brass"))
|
|
body = join(P, "Body")
|
|
finalize(body)
|
|
# Light: fresnel lens
|
|
lprof = [(0, 2.16), (0.07, 2.16), (0.11, 2.19), (0.13, 2.24), (0.135, 2.3), (0.13, 2.36), (0.11, 2.41), (0.07, 2.44), (0, 2.44)]
|
|
light = rev("Light", lprof, "M_LightRed", segs=12)
|
|
light = join([light] + [torus("fr", 0.137, 0.009, loc=(0, 0, 2.24 + 0.06 * k), seg=12, rseg=4, m="M_LightRed") for k in range(3)], "Light")
|
|
smooth(light, 50)
|
|
uv_box(light, 1)
|
|
set_origin(light, (0, 0, 2.3))
|
|
return dict(elev=14)
|
|
|
|
|
|
def decor_sofa():
|
|
P = []
|
|
P.append(softbox("base", (1.86, 0.84, 0.24), (0, 0.02, 0.22), r=0.07, m="M_CushionTeal", na=2, nf=2))
|
|
P.append(softbox("back", (1.86, 0.24, 0.56), (0, 0.32, 0.58), r=0.1, m="M_CushionTeal", na=2, nf=2))
|
|
for sx in (-1, 1):
|
|
a = softbox("arm", (0.22, 0.86, 0.48), (sx * 0.82, 0.02, 0.45), r=0.1, m="M_CushionTeal", na=2, nf=2, bulge=(0.015, 0, 0.02))
|
|
P.append(a)
|
|
for sy in (-1, 1):
|
|
leg = rev("leg", [(0.03, 0.0), (0.045, 0.1), (0.05, 0.11)], ["M_Wood", "M_Wood"], segs=10, close_bottom=True)
|
|
xf(leg, loc=(sx * 0.82, sy * 0.33 + 0.02, 0))
|
|
P.append(leg)
|
|
P.append(cy(0.032, 0.0, 0.012, "M_Rubber", x=sx * 0.82, y=sy * 0.33 + 0.02, verts=10, name="cap"))
|
|
for sx in (-1, 1):
|
|
s = softbox("seat", (0.72, 0.62, 0.17), (sx * 0.36, -0.08, 0.42), r=0.07, m="M_CushionOrange", na=2, nf=3, bulge=(0, 0.01, 0.03))
|
|
P.append(s)
|
|
b = softbox("bcush", (0.72, 0.2, 0.44), (0, 0, 0), r=0.09, m="M_CushionOrange", na=2, nf=3, bulge=(0, 0.035, 0.01))
|
|
xf(b, loc=(sx * 0.36, 0.17, 0.74), rot=(-12, 0, 0))
|
|
P.append(b)
|
|
pil = softbox("pillow", (0.38, 0.13, 0.36), (0, 0, 0), r=0.06, m="M_Canvas", na=2, nf=3, bulge=(0, 0.04, 0))
|
|
xf(pil, loc=(-0.58, 0.02, 0.68), rot=(-18, 6, 22))
|
|
P.append(pil)
|
|
o = join(P, "SM_Decor_Sofa")
|
|
finalize(o, ang=50)
|
|
return dict(elev=20)
|
|
|
|
|
|
def decor_vending():
|
|
def B(*a, **k):
|
|
k.setdefault("segs", 1)
|
|
return bx(*a, **k)
|
|
|
|
P = []
|
|
W, D, H = 1.0, 0.78, 1.95
|
|
P.append(B(-W / 2, W / 2, -D / 2, D / 2, 0.06, H, "M_HullWhite", bevel=0.07, segs=2, name="body"))
|
|
P.append(B(-W / 2 - 0.012, W / 2 + 0.012, -D / 2 - 0.012, D / 2 + 0.012, 0.14, 0.24, "M_PaintOrange", bevel=0.03, segs=2, name="stripe"))
|
|
P.append(B(-W / 2 + 0.03, W / 2 - 0.03, -D / 2 + 0.03, D / 2 - 0.03, 0.0, 0.08, "M_DarkGrey", bevel=0.02, name="plinth"))
|
|
# header sign
|
|
P.append(B(-W / 2 + 0.02, W / 2 - 0.02, -D / 2 - 0.03, -D / 2 + 0.05, 1.68, 1.92, "M_Teal", bevel=0.03, name="hdr"))
|
|
P.append(B(-W / 2 + 0.06, W / 2 - 0.06, -D / 2 - 0.035, -D / 2, 1.71, 1.89, "M_LightBlue", bevel=0.01, name="hdrglow"))
|
|
P.append(decal("hdrlabel", (0.0, -D / 2 - 0.0365, 1.8), 0.34, 0.17, (0, -1, 0), "M_Label"))
|
|
# display window
|
|
x0, x1, z0, z1 = -0.44, 0.17, 0.5, 1.62
|
|
yb = -D / 2 + 0.12
|
|
P.append(B(x0, x1, yb, yb + 0.02, z0, z1, "M_LightBlue", bevel=0.0, name="glowback"))
|
|
for sx0, sx1, sz0, sz1 in ((x0 - 0.04, x0, z0 - 0.04, z1 + 0.04), (x1, x1 + 0.04, z0 - 0.04, z1 + 0.04), (x0, x1, z0 - 0.04, z0), (x0, x1, z1, z1 + 0.04)):
|
|
P.append(B(sx0, sx1, -D / 2 - 0.025, yb + 0.01, sz0, sz1, "M_DarkGrey", bevel=0.012, name="frame"))
|
|
for side in (-1, 1):
|
|
xx = x0 if side < 0 else x1
|
|
P.append(B(xx - 0.005, xx + 0.005, -D / 2 - 0.01, yb, z0, z1, "M_DarkGrey", bevel=0.0, name="reveal"))
|
|
bottle = rev("bottle", [(0, 0), (0.05, 0.0), (0.052, 0.045), (0.054, 0.05), (0.054, 0.11), (0.052, 0.115), (0.05, 0.135), (0.022, 0.18), (0.024, 0.185), (0.024, 0.225), (0, 0.228)],
|
|
["M_Bottle", "M_Bottle", "M_PaintWhite", "M_PaintWhite", "M_PaintWhite", "M_Bottle", "M_Bottle", "M_Teal", "M_Teal", "M_Teal"], segs=8)
|
|
for r, zs in enumerate((0.56, 0.93, 1.3)):
|
|
P.append(B(x0, x1, yb - 0.24, yb, zs - 0.03, zs, "M_PaintWhite", bevel=0.006, name="shelf"))
|
|
P.append(B(x0, x1, yb - 0.25, yb - 0.23, zs - 0.06, zs, "M_PaintOrange", bevel=0.006, name="shelflip"))
|
|
for k in range(3):
|
|
b = bottle.copy(); b.data = bottle.data.copy(); link(b)
|
|
xf(b, loc=(x0 + 0.11 + k * 0.195, yb - 0.1, zs))
|
|
P.append(b)
|
|
bpy.data.objects.remove(bottle)
|
|
P.append(B(x0, x1, -D / 2 - 0.02, -D / 2 - 0.005, z0, z1, "M_Glass", bevel=0.0, name="glass"))
|
|
# control column
|
|
cx0, cx1 = 0.24, 0.44
|
|
P.append(B(cx0, cx1, -D / 2 - 0.025, -D / 2 + 0.02, 0.62, 1.58, "M_DarkGrey", bevel=0.02, name="panel"))
|
|
P.append(B(cx0 + 0.025, cx1 - 0.025, -D / 2 - 0.035, -D / 2 - 0.02, 1.38, 1.52, "M_Screen", bevel=0.008, name="screen"))
|
|
for k in range(6):
|
|
r_, c_ = divmod(k, 2)
|
|
bt = cyl("btn", 0.026, 0.03, axis="Y", verts=12, m="M_PaintOrange" if k % 3 else "M_Teal", bevel=0.008, segs=1)
|
|
xf(bt, loc=(cx0 + 0.055 + c_ * 0.09, -D / 2 - 0.035, 1.27 - r_ * 0.085))
|
|
P.append(bt)
|
|
P.append(B(cx0 + 0.07, cx1 - 0.07, -D / 2 - 0.035, -D / 2 - 0.02, 0.95, 1.0, "M_Steel", bevel=0.008, name="coin"))
|
|
P.append(B(cx0 + 0.088, cx1 - 0.088, -D / 2 - 0.04, -D / 2 - 0.03, 0.965, 0.985, "M_Rubber", bevel=0.0, name="slot"))
|
|
P.append(B(cx0 + 0.04, cx1 - 0.04, -D / 2 - 0.04, -D / 2 - 0.02, 0.72, 0.84, "M_Steel", bevel=0.012, name="card"))
|
|
# dispenser bay
|
|
P.append(B(-0.4, 0.4, -D / 2 - 0.03, -D / 2 + 0.03, 0.27, 0.44, "M_DarkGrey", bevel=0.03, name="bay"))
|
|
P.append(B(-0.36, 0.36, -D / 2 - 0.045, -D / 2 - 0.02, 0.3, 0.41, "M_Navy", bevel=0.015, name="flap"))
|
|
P.append(B(-0.1, 0.1, -D / 2 - 0.06, -D / 2 - 0.035, 0.385, 0.405, "M_Steel", bevel=0.008, name="pull"))
|
|
# side vents + cup dispenser
|
|
for k in range(4):
|
|
z = 1.25 + k * 0.07
|
|
P.append(B(W / 2 - 0.01, W / 2 + 0.012, -0.2, 0.2, z, z + 0.03, "M_DarkGrey", bevel=0.01, name="vent"))
|
|
P.append(decal("sidelogo", (W / 2 + 0.002, 0.0, 0.85), 0.42, 0.42, (1, 0, 0), "M_Logo"))
|
|
P.append(B(-W / 2 - 0.05, -W / 2 + 0.01, -0.06, 0.06, 0.95, 1.0, "M_Steel", bevel=0.01, name="bracket"))
|
|
tubeo = rev("cuptube", [(0.0, 0.92), (0.055, 0.92), (0.055, 1.42), (0.05, 1.42)], ["M_Bottle"] * 3, segs=14, close_top=False)
|
|
xf(tubeo, loc=(-W / 2 - 0.08, 0, 0))
|
|
P.append(tubeo)
|
|
for k in range(3):
|
|
c = rev("cup", [(0.032, 0.0), (0.05, 0.09), (0.052, 0.095)], ["M_PaintWhite"] * 2, segs=12, close_top=False, close_bottom=True)
|
|
xf(c, loc=(-W / 2 - 0.08, 0, 0.92 + k * 0.05))
|
|
P.append(c)
|
|
P.append(cy(0.06, 0.9, 0.93, "M_Teal", x=-W / 2 - 0.08, verts=14, bevel=0.008, name="cupcap"))
|
|
for sx in (-1, 1):
|
|
for sy in (-1, 1):
|
|
P.append(cy(0.05, 0.0, 0.03, "M_Rubber", x=sx * 0.38, y=sy * 0.28, verts=10, name="pad"))
|
|
o = join(P, "SM_Decor_Vending")
|
|
finalize(o)
|
|
return dict(elev=12, azim=-30)
|
|
|
|
|
|
def duck(scale=1.0):
|
|
P = []
|
|
P.append(sphere("dbody", 0.1, (0, 0.01, 0.06), seg=12, rings=8, m="M_PaintYellow", scale=(0.85, 1.15, 0.7)))
|
|
P.append(sphere("dtail", 0.04, (0, 0.11, 0.1), seg=8, rings=6, m="M_PaintYellow", scale=(0.8, 1.0, 1.0)))
|
|
P.append(sphere("dhead", 0.065, (0, -0.07, 0.16), seg=10, rings=7, m="M_PaintYellow"))
|
|
P.append(sphere("beak", 0.035, (0, -0.135, 0.15), seg=8, rings=6, m="M_PaintOrange", scale=(1.1, 0.9, 0.45)))
|
|
for sx in (-1, 1):
|
|
P.append(sphere("eye", 0.012, (sx * 0.035, -0.115, 0.18), seg=6, rings=4, m="M_Pupil"))
|
|
d = join(P, "duck")
|
|
xf(d, scale=(scale, scale, scale))
|
|
return d
|
|
|
|
|
|
def decor_pool():
|
|
P = []
|
|
R, r = 0.82, 0.135
|
|
P.append(cy(0.9, 0.0, 0.04, "M_Inflatable", verts=32, bevel=0.015, segs=1, name="floor"))
|
|
for k, (z, mm) in enumerate(((0.15, "M_Inflatable"), (0.39, "M_PaintWhite"), (0.63, "M_Inflatable"))):
|
|
t = torus("ring", R, r, loc=(0, 0, 0), seg=32, rseg=8, m=mm)
|
|
xf(t, loc=(0, 0, z), scale=(1, 1, 0.9))
|
|
P.append(t)
|
|
P.append(torus("seam", R + r * 0.99, 0.008, loc=(0, 0, z), seg=32, rseg=3, m="M_PaintWhite" if mm != "M_PaintWhite" else "M_Inflatable"))
|
|
for a in (0.6, 2.3):
|
|
v = cyl("valve", 0.03, 0.04, axis="X", verts=10, m="M_PaintWhite", bevel=0.008)
|
|
xf(v, rot=(0, 0, math.degrees(a)))
|
|
xf(v, loc=(math.cos(a) * (R + r + 0.005), math.sin(a) * (R + r + 0.005), 0.63))
|
|
P.append(v)
|
|
# dots print on the white ring
|
|
for k in range(10):
|
|
a = TAU * k / 10 + 0.2
|
|
dot = cyl("dot", 0.045, 0.01, axis="X", verts=8, m="M_PaintOrange" if k % 2 else "M_Teal")
|
|
xf(dot, rot=(0, 0, math.degrees(a)))
|
|
xf(dot, loc=(math.cos(a) * (R + r * 0.9 + 0.003), math.sin(a) * (R + r * 0.9 + 0.003), 0.39))
|
|
P.append(dot)
|
|
d = duck(1.2)
|
|
xf(d, loc=(0.25, -0.15, 0.56), rot=(0, 0, 30))
|
|
P.append(d)
|
|
ball = sphere("ball", 0.16, (0, 0, 0), seg=12, rings=8)
|
|
paint(ball, lambda c, n, i: 3 if abs(c.z) > 0.15 else int(((math.atan2(c.y, c.x) + TAU) % TAU) / (TAU / 6)) % 3,
|
|
["M_PaintRed", "M_PaintWhite", "M_PaintYellow", "M_PaintWhite"])
|
|
xf(ball, loc=(-0.32, 0.25, 0.62), rot=(20, 10, 0))
|
|
P.append(ball)
|
|
o = join(P, "Body")
|
|
finalize(o, ang=60)
|
|
water = cy(R - 0.02, 0.03, 0.6, "M_WaterFill", verts=40, name="Water")
|
|
smooth(water, 30)
|
|
uv_box(water, 1)
|
|
return dict(elev=35)
|
|
|
|
|
|
def decor_gnome():
|
|
P = []
|
|
P.append(rev("base", [(0, 0), (0.2, 0), (0.215, 0.012), (0.215, 0.03), (0.2, 0.045), (0, 0.045)], "M_PaintGreen", segs=24))
|
|
# boots
|
|
for sx in (-1, 1):
|
|
P.append(sphere("boot", 0.06, (sx * 0.06, -0.04, 0.075), seg=10, rings=6, m="M_Rubber", scale=(0.85, 1.35, 0.7)))
|
|
# coat / vest body
|
|
coat = rev("coat", [(0.0, 0.06), (0.11, 0.06), (0.135, 0.1), (0.14, 0.16), (0.128, 0.24), (0.1, 0.3), (0.07, 0.33), (0.0, 0.34)],
|
|
["M_Teal", "M_CrewVest", "M_CrewVest", "M_CrewVest", "M_CrewVest", "M_CrewVest", "M_CrewVest"], segs=20)
|
|
P.append(coat)
|
|
P.append(rev("refl", [(0.142, 0.17), (0.145, 0.175), (0.144, 0.2), (0.14, 0.205)], "M_Reflective", segs=20, close_top=False))
|
|
P.append(rev("belt", [(0.137, 0.115), (0.14, 0.12), (0.14, 0.14), (0.136, 0.145)], "M_DarkGrey", segs=20, close_top=False))
|
|
P.append(bx(-0.025, 0.025, -0.15, -0.13, 0.115, 0.145, "M_Gold", bevel=0.006, name="buckle"))
|
|
# head
|
|
hz = 0.39
|
|
P.append(sphere("head", 0.085, (0, -0.01, hz), seg=16, rings=10, m="M_Skin"))
|
|
for sx in (-1, 1):
|
|
P.append(sphere("ear", 0.022, (sx * 0.083, 0.0, hz), seg=8, rings=6, m="M_Skin", scale=(0.6, 1, 1.2)))
|
|
P.append(sphere("cheek", 0.025, (sx * 0.045, -0.075, hz - 0.012), seg=8, rings=6, m="M_PaintRed", scale=(1, 0.5, 0.8)))
|
|
P.append(sphere("eye", 0.014, (sx * 0.032, -0.084, hz + 0.018), seg=8, rings=6, m="M_Pupil", scale=(1, 1, 1.25)))
|
|
br = sphere("brow", 0.022, (sx * 0.036, -0.08, hz + 0.042), seg=8, rings=5, m="M_Beard", scale=(1.3, 0.6, 0.45))
|
|
P.append(br)
|
|
P.append(sphere("nose", 0.034, (0, -0.105, hz - 0.008), seg=10, rings=8, m="M_Skin"))
|
|
# beard: sculpted lumpy wedge
|
|
beard = sphere("beard", 0.1, (0, 0, 0), seg=16, rings=12, m="M_Beard")
|
|
for v in beard.data.vertices:
|
|
p = v.co
|
|
t = (p.z + 0.1) / 0.2
|
|
p.x *= 0.95 + 0.25 * (1 - t)
|
|
p.y *= 0.62
|
|
p.z *= 1.05
|
|
if p.z < -0.05:
|
|
p.y -= (p.z + 0.05) * 0.6
|
|
wobble(beard, 0.01, 22.0, seed=3)
|
|
xf(beard, loc=(0, -0.07, hz - 0.11))
|
|
P.append(beard)
|
|
P.append(sphere("mous", 0.03, (0, -0.11, hz - 0.035), seg=10, rings=6, m="M_Beard", scale=(1.8, 0.7, 0.6)))
|
|
# pointy hard-hat hat with a bent tip
|
|
path = bez([(0, 0, hz + 0.05), (0, 0.0, hz + 0.15), (0, 0.03, hz + 0.26), (0, 0.1, hz + 0.32)], 9)
|
|
radii = [0.098, 0.088, 0.075, 0.06, 0.047, 0.035, 0.024, 0.014, 0.004]
|
|
hat = sweep_rings("hat", path, radii, "M_PaintWhite", verts=16)
|
|
paint(hat, lambda c, n, i: 1 if hz + 0.1 < c.z < hz + 0.135 else 0, ["M_PaintWhite", "M_PaintOrange"])
|
|
P.append(hat)
|
|
P.append(torus("brim", 0.1, 0.018, loc=(0, 0, hz + 0.055), seg=20, rseg=5, m="M_PaintWhite"))
|
|
lamp = cyl("lamp", 0.022, 0.03, axis="Y", verts=12, m="M_Emissive")
|
|
lh = cyl("lamph", 0.028, 0.025, axis="Y", verts=12, m="M_DarkGrey")
|
|
xf(lh, loc=(0, 0.012, 0))
|
|
lp = join([lamp, lh], "lampj")
|
|
xf(lp, loc=(0, -0.095, hz + 0.105), rot=(-12, 0, 0))
|
|
P.append(lp)
|
|
# arms
|
|
sh = Vector((0.11, -0.01, 0.29))
|
|
for sx in (-1, 1):
|
|
s = Vector((sx * sh.x, sh.y, sh.z))
|
|
if sx < 0: # left arm forward holding the bucket
|
|
hand = Vector((-0.15, -0.12, 0.2))
|
|
P.append(sweep_rings("arm", bez([s, (-0.16, -0.05, 0.26), hand], 6), [0.035, 0.034, 0.032, 0.031, 0.03, 0.028], "M_CrewVest", verts=10))
|
|
else: # right hand thumbs-up-ish on the belly
|
|
hand = Vector((0.08, -0.13, 0.18))
|
|
P.append(sweep_rings("arm", bez([s, (0.15, -0.06, 0.22), hand], 6), [0.035, 0.034, 0.032, 0.031, 0.03, 0.028], "M_CrewVest", verts=10))
|
|
P.append(sphere("hand", 0.034, tuple(hand), seg=10, rings=8, m="M_GloveOrange"))
|
|
P.append(sphere("thumb", 0.014, (0.08, -0.155, 0.215), seg=6, rings=5, m="M_GloveOrange", scale=(1, 1, 1.6)))
|
|
# tiny bucket
|
|
bk = [rev("bucket", [(0, 0), (0.045, 0), (0.06, 0.09), (0.064, 0.095), (0.056, 0.095), (0.05, 0.03), (0, 0.03)],
|
|
["M_Teal", "M_Teal", "M_PaintWhite", "M_PaintWhite", "M_Teal", "M_Teal"], segs=16)]
|
|
bk.append(cy(0.055, 0.075, 0.08, "M_WaterFill", verts=16, name="bw"))
|
|
hpts = [(math.cos(a) * 0.062, 0.0, 0.095 + math.sin(a) * 0.07) for a in [math.pi * k / 10 for k in range(11)]]
|
|
bk.append(ptube("handle", hpts, 0.005, "M_Steel", rs=0))
|
|
b = join(bk, "bucket")
|
|
xf(b, loc=(-0.15, -0.12, 0.2 - 0.165 + 0.05 - 0.03))
|
|
P.append(b)
|
|
o = join(P, "SM_Decor_Gnome")
|
|
finalize(o, ang=60)
|
|
return dict(elev=12, azim=-25)
|
|
|
|
|
|
DECOR = {
|
|
"SM_Decor_Lamp": decor_lamp,
|
|
"SM_Decor_Palm": decor_palm,
|
|
"SM_Decor_Bench": decor_bench,
|
|
"SM_Decor_Umbrella": decor_umbrella,
|
|
"SM_Decor_Flag": decor_flag,
|
|
"SM_Decor_Dish": decor_dish,
|
|
"SM_Decor_Crates": decor_crates,
|
|
"SM_Decor_Lifebuoy": decor_lifebuoy,
|
|
"SM_Decor_Grill": decor_grill,
|
|
"SM_Decor_Hammock": decor_hammock,
|
|
"SM_Decor_Beacon": decor_beacon,
|
|
"SM_Decor_Sofa": decor_sofa,
|
|
"SM_Decor_Vending": decor_vending,
|
|
"SM_Decor_Pool": decor_pool,
|
|
"SM_Decor_Gnome": decor_gnome,
|
|
}
|
|
|
|
# =============================================================================== ENVIRONMENT
|
|
|
|
def smoothstep(a, b, x):
|
|
t = max(0.0, min(1.0, (x - a) / (b - a)))
|
|
return t * t * (3 - 2 * t)
|
|
|
|
|
|
def rock_column(name, H, rfun, seed, nseg=36, ring_h=0.6, cap_h=2.0, lean=(0, 0), notches=(), chunk=0.35, chunk_amp=0.5,
|
|
layer_rng=(2.2, 4.2), wet_z=6.0, z_bottom=-1.2, offset=(0, 0), fiss=0.35, crown=(1.0, 1.2, 0.0)):
|
|
"""Eroded sea stack: radial profile + lobes + strata ledges + wave-cut notches + voronoi chunks."""
|
|
rnd = random.Random(seed)
|
|
# strata
|
|
bounds = [z_bottom]
|
|
while bounds[-1] < H + 5:
|
|
bounds.append(bounds[-1] + rnd.uniform(*layer_rng))
|
|
lay = []
|
|
for i in range(len(bounds)):
|
|
lay.append(dict(ledge=rnd.uniform(0.05, 0.15), scale=rnd.uniform(0.9, 1.08),
|
|
mat=rnd.choices(["M_Rock", "M_RockBand", "M_RockLilac"], weights=[5, 3, 2])[0]))
|
|
|
|
def layer_at(z):
|
|
for i in range(len(bounds) - 1):
|
|
if z < bounds[i + 1]:
|
|
return i, (z - bounds[i]) / (bounds[i + 1] - bounds[i])
|
|
return len(bounds) - 1, 0.0
|
|
|
|
def center(z):
|
|
t = max(0.0, z / H)
|
|
return Vector((offset[0] + lean[0] * t * t, offset[1] + lean[1] * t * t, 0))
|
|
|
|
so = Vector((seed * 13.7, seed * 7.3, seed * 3.1))
|
|
zs = []
|
|
z = z_bottom
|
|
while z < H - cap_h:
|
|
zs.append(z)
|
|
z += ring_h
|
|
ncap = max(3, int(cap_h / ring_h * 1.6))
|
|
for k in range(ncap):
|
|
a = (k / ncap) * math.pi / 2
|
|
zs.append(H - cap_h + cap_h * math.sin(a))
|
|
bm = bmesh.new()
|
|
rings = []
|
|
for z in zs:
|
|
t = max(0.0, z / H)
|
|
base = rfun(t)
|
|
u = 0.0
|
|
if z > H - cap_h:
|
|
u = (z - (H - cap_h)) / cap_h
|
|
base *= 1 - 0.5 * u ** 1.6
|
|
if z < 1.5:
|
|
base *= 1 + 0.32 * smoothstep(1.5, -1.2, z)
|
|
li, f = layer_at(z)
|
|
L = lay[li]
|
|
c = center(z)
|
|
ring = []
|
|
for j in range(nseg):
|
|
th = TAU * j / nseg
|
|
ca, sa = math.cos(th), math.sin(th)
|
|
lobes = 1 + 0.2 * noise.noise(Vector((ca * 1.1, sa * 1.1, z * 0.03)) + so) + 0.09 * noise.noise(Vector((ca * 2.4, sa * 2.4, z * 0.07)) + so * 2)
|
|
r = base * lobes * L["scale"]
|
|
led = L["ledge"] * (0.55 + 0.45 * noise.noise(Vector((ca * 1.7, sa * 1.7, li * 3.1)) + so))
|
|
r *= 1 + led * smoothstep(0.55, 1.0, f) - 0.5 * led * smoothstep(0.25, 0.0, f)
|
|
for (zn, dn, wn) in notches:
|
|
r *= 1 - dn * math.exp(-((z - zn) / wn) ** 2) * (0.75 + 0.25 * noise.noise(Vector((ca * 2, sa * 2, zn)) + so))
|
|
p = Vector((ca * r, sa * r, z))
|
|
q = Vector((p.x * chunk, p.y * chunk, p.z * chunk * 0.55)) + so
|
|
d, pts = noise.voronoi(q, distance_metric="DISTANCE")
|
|
cv = noise.cell(pts[0])
|
|
r += chunk_amp * cv * (1.0 if z > -0.5 else 0.5)
|
|
r -= chunk_amp * 0.3 * smoothstep(0.16, 0.0, d[1] - d[0])
|
|
fz = noise.noise(Vector((ca * 2.6, sa * 2.6, z * 0.035)) + so * 3)
|
|
r -= fiss * max(0.0, 1 - abs(fz) * 5) ** 2
|
|
r += 0.08 * noise.noise(p * 0.8 + so)
|
|
r = max(r, 0.05)
|
|
zz = z
|
|
uc = smoothstep(H - cap_h * 2.2, H, z)
|
|
if uc > 0:
|
|
tilt, crag, phi = crown
|
|
cn = noise.noise(Vector((ca * 2.2, sa * 2.2, 7.7)) + so)
|
|
spike = max(0.0, cn) ** 1.3 * crag + 0.35 * crag * max(0.0, noise.noise(Vector((ca * 5.0, sa * 5.0, 3.3)) + so))
|
|
zz = z + uc * (tilt * math.cos(th - phi) + spike)
|
|
ring.append(bm.verts.new((c.x + ca * r, c.y + sa * r, zz)))
|
|
rings.append(ring)
|
|
top = bm.verts.new(tuple(center(H) + Vector((0, 0, H - cap_h * 0.15))))
|
|
faces = []
|
|
for a, b in zip(rings, rings[1:]):
|
|
for j in range(nseg):
|
|
faces.append(bm.faces.new((a[j], a[(j + 1) % nseg], b[(j + 1) % nseg], b[j])))
|
|
for j in range(nseg):
|
|
faces.append(bm.faces.new((rings[-1][j], rings[-1][(j + 1) % nseg], top)))
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
slots = ["M_RockWet", "M_Rock", "M_RockBand", "M_RockLilac"]
|
|
for fc in bm.faces:
|
|
cc = fc.calc_center_median()
|
|
th = math.atan2(cc.y, cc.x)
|
|
wz = wet_z + 1.1 * noise.noise(Vector((math.cos(th) * 1.5, math.sin(th) * 1.5, 0.0)) + so)
|
|
if cc.z < wz:
|
|
fc.material_index = 0
|
|
elif cc.z > H - cap_h * 0.6:
|
|
fc.material_index = 1
|
|
else:
|
|
fc.material_index = slots.index(lay[layer_at(cc.z)[0]]["mat"])
|
|
o = mesh_obj(name, bm)
|
|
add_mats(o, *slots)
|
|
return o, center
|
|
|
|
|
|
def boulder(r, loc, seed, sc=(1, 1, 0.7), m="M_RockWet", sub=1):
|
|
"""Chunky faceted boulder: low icosphere, per-vertex jitter, flat-ish base."""
|
|
bm = bmesh.new()
|
|
bmesh.ops.create_icosphere(bm, subdivisions=sub, radius=r)
|
|
rr = random.Random(seed)
|
|
so = Vector((seed * 3.3, seed * 1.7, seed * 5.9))
|
|
for v in bm.verts:
|
|
p = v.co.copy()
|
|
k = 1 + 0.22 * noise.noise(p / r * 0.9 + so) + rr.uniform(-0.08, 0.08)
|
|
q = Vector((p.x * sc[0], p.y * sc[1], p.z * sc[2])) * k
|
|
if q.z < -0.15 * r:
|
|
q.z = -0.15 * r + (q.z + 0.15 * r) * 0.3
|
|
v.co = q
|
|
if sub >= 2:
|
|
bmesh.ops.dissolve_limit(bm, angle_limit=math.radians(8), verts=bm.verts, edges=bm.edges)
|
|
bmesh.ops.translate(bm, vec=Vector(loc), verts=bm.verts)
|
|
o = mesh_obj("boulder", bm)
|
|
set_mats(o, m)
|
|
return o
|
|
|
|
|
|
def surf_hit(bvh, center_fn, th, z):
|
|
d = Vector((math.cos(th), math.sin(th), 0))
|
|
c = center_fn(z) + Vector((0, 0, z))
|
|
hit = bvh.ray_cast(c + d * 80, -d)
|
|
if hit[0] is None:
|
|
return None, None
|
|
return hit[0], hit[1]
|
|
|
|
|
|
def orient(o, loc, nrm, spin=0.0, sink=0.0):
|
|
q = Vector(nrm).to_track_quat("Z", "Y")
|
|
o.rotation_euler = (q @ Quaternion_z(spin)).to_euler() if spin else q.to_euler()
|
|
o.location = Vector(loc) - Vector(nrm) * sink
|
|
return apply_xform(o)
|
|
|
|
|
|
def Quaternion_z(a):
|
|
from mathutils import Quaternion
|
|
return Quaternion((0, 0, 1), a)
|
|
|
|
|
|
def barnacle(r, h, m="M_Barnacle"):
|
|
return rev("barn", [(r, 0), (r * 0.8, h * 0.6), (r * 0.48, h), (r * 0.3, h * 0.7)], m, segs=6, close_top=True)
|
|
|
|
|
|
def barnacle_clusters(bvh, center_fn, rnd, n_clusters, z_lo, z_hi, scale=1.0, per=(3, 6)):
|
|
out = []
|
|
for _ in range(n_clusters):
|
|
th = rnd.uniform(0, TAU)
|
|
z = rnd.uniform(z_lo, z_hi)
|
|
loc, nrm = surf_hit(bvh, center_fn, th, z)
|
|
if loc is None:
|
|
continue
|
|
nrm = Vector(nrm)
|
|
tx = nrm.cross(Vector((0, 0, 1))).normalized()
|
|
ty = nrm.cross(tx).normalized()
|
|
for k in range(rnd.randint(*per)):
|
|
off = tx * rnd.uniform(-0.8, 0.8) * scale + ty * rnd.uniform(-0.55, 0.55) * scale
|
|
p = loc + off + nrm * 1.5
|
|
hit = bvh.ray_cast(p, -nrm, 4.0)
|
|
if hit[0] is None:
|
|
continue
|
|
r = rnd.uniform(0.13, 0.3) * scale
|
|
b = barnacle(r, r * rnd.uniform(0.9, 1.3))
|
|
orient(b, hit[0], hit[1], spin=rnd.uniform(0, TAU), sink=r * 0.15)
|
|
out.append(b)
|
|
return out
|
|
|
|
|
|
def seaweed(bvh, center_fn, rnd, th, z, length, width=0.2, steps=8, m="M_Seaweed"):
|
|
bm = bmesh.new()
|
|
L, R = [], []
|
|
phase = rnd.uniform(0, TAU)
|
|
for i in range(steps + 1):
|
|
t = i / steps
|
|
zz = z - length * t
|
|
thh = th + 0.06 * math.sin(phase + t * 5)
|
|
loc, nrm = surf_hit(bvh, center_fn, thh, zz)
|
|
if loc is None:
|
|
break
|
|
nrm = Vector(nrm)
|
|
nrm.z = 0
|
|
if nrm.length < 1e-4:
|
|
nrm = Vector((math.cos(thh), math.sin(thh), 0))
|
|
nrm.normalize()
|
|
tan = Vector((0, 0, 1)).cross(nrm).normalized()
|
|
w = width * (1 - 0.65 * t) * (0.8 + 0.3 * math.sin(phase * 2 + t * 9))
|
|
ctr = loc + nrm * (0.06 + 0.05 * t) + tan * 0.18 * math.sin(phase + t * 6)
|
|
L.append(bm.verts.new(ctr - tan * w / 2))
|
|
R.append(bm.verts.new(ctr + tan * w / 2 + nrm * 0.02))
|
|
if len(L) < 3:
|
|
bm.free()
|
|
return None
|
|
for i in range(len(L) - 1):
|
|
bm.faces.new((L[i], R[i], R[i + 1], L[i + 1]))
|
|
o = mesh_obj("weed", bm)
|
|
set_mats(o, m)
|
|
dbl(o, 0.01)
|
|
return o
|
|
|
|
|
|
def coral_cluster(loc, nrm, rnd, scale=1.0):
|
|
P = []
|
|
nrm = Vector(nrm)
|
|
up = (nrm * 0.5 + Vector((0, 0, 1))).normalized()
|
|
tx = up.cross(Vector((1, 0, 0)) if abs(up.x) < 0.9 else Vector((0, 1, 0))).normalized()
|
|
ty = up.cross(tx)
|
|
for k in range(rnd.randint(4, 6)):
|
|
a = TAU * k / 5 + rnd.uniform(-0.3, 0.3)
|
|
spread = rnd.uniform(0.25, 0.6)
|
|
d = (up + (tx * math.cos(a) + ty * math.sin(a)) * spread).normalized()
|
|
Lb = rnd.uniform(0.5, 0.9) * scale
|
|
p0 = Vector(loc) - up * 0.1
|
|
p1 = p0 + d * Lb * 0.5
|
|
p2 = p1 + (d + up * 0.6).normalized() * Lb * 0.5
|
|
rb = 0.07 * scale
|
|
P.append(sweep_rings("br", [p0, p1, p2], [rb * 1.2, rb, rb * 0.8], "M_Coral", verts=6, close_ends=False))
|
|
P.append(sphere("tip", rb * 1.15, tuple(p2), seg=6, rings=3, m="M_Coral"))
|
|
if k % 2 == 0:
|
|
q = p1 + (d - up * 0.2 + tx * 0.3).normalized() * Lb * 0.3
|
|
P.append(sweep_rings("tw", [p1, q], [rb * 0.8, rb * 0.6], "M_Coral", verts=5, close_ends=False))
|
|
P.append(sphere("tip", rb * 0.8, tuple(q), seg=5, rings=3, m="M_Coral"))
|
|
return P
|
|
|
|
|
|
def brain_coral(loc, r, seed):
|
|
o = sphere("brain", r, (0, 0, 0), seg=10, rings=6, m="M_Coral", scale=(1, 1, 0.6))
|
|
wobble(o, r * 0.12, 6.0 / r, seed=seed)
|
|
xf(o, loc=loc)
|
|
return o
|
|
|
|
|
|
def spire(name, H, rfun, seed, nseg, ring_h, cap_h, lean, notches, wet_frac, twin=None, boulders=5, n_barn=10, n_weed=10, n_coral=3, chunk=0.35, chunk_amp=0.5,
|
|
rock_tris=6000, fiss=0.35, crown=(1.0, 1.2, 0.0)):
|
|
rnd = random.Random(seed)
|
|
wet_z = H * wet_frac
|
|
main, cfn = rock_column("rock", H, rfun, seed, nseg=nseg, ring_h=ring_h, cap_h=cap_h, lean=lean, notches=notches,
|
|
wet_z=wet_z, chunk=chunk, chunk_amp=chunk_amp, fiss=fiss, crown=crown)
|
|
parts = [main]
|
|
cfns = [(cfn, H, main)]
|
|
if twin:
|
|
t2, cfn2 = rock_column("rock2", twin["H"], twin["rfun"], seed + 11, nseg=twin.get("nseg", 28), ring_h=ring_h, cap_h=twin["cap_h"],
|
|
lean=twin["lean"], notches=notches, wet_z=wet_z, offset=twin["offset"], chunk=chunk, chunk_amp=chunk_amp, fiss=fiss,
|
|
crown=twin.get("crown", crown))
|
|
parts.append(t2)
|
|
cfns.append((cfn2, twin["H"], t2))
|
|
R0 = rfun(0.0)
|
|
for k in range(boulders):
|
|
a = TAU * k / boulders + rnd.uniform(-0.4, 0.4)
|
|
rr = rnd.uniform(1.1, 1.45) * R0
|
|
br = rnd.uniform(0.9, 1.8) * (R0 / 4.5)
|
|
bo = boulder(br, (0, 0, 0), seed * 10 + k, sc=(rnd.uniform(1.0, 1.5), 1.0, rnd.uniform(0.55, 0.8)), sub=2)
|
|
xf(bo, loc=(math.cos(a) * rr, math.sin(a) * rr, br * 0.1), rot=(rnd.uniform(-10, 10), rnd.uniform(-10, 10), rnd.uniform(0, 360)))
|
|
parts.append(bo)
|
|
rock = join(parts, "rock")
|
|
cur = ntris(rock)
|
|
if cur > rock_tris:
|
|
mod(rock, "DECIMATE", decimate_type="COLLAPSE", ratio=rock_tris / cur)
|
|
bake(rock)
|
|
uv_box(rock, 0.25)
|
|
bvh = bvh_of(rock)
|
|
deco = []
|
|
for (cf, hh, _) in cfns:
|
|
frac = 1.0 if cf is cfns[0][0] else 0.6
|
|
deco += barnacle_clusters(bvh, cf, rnd, int(n_barn * frac), 0.2, min(wet_z + 0.5, hh * 0.9), scale=max(1.0, H / 22))
|
|
for k in range(int(n_weed * frac)):
|
|
th = rnd.uniform(0, TAU)
|
|
zz = rnd.uniform(wet_z * 0.35, wet_z * 0.95)
|
|
for s in range(rnd.randint(2, 4)):
|
|
w = seaweed(bvh, cf, rnd, th + s * 0.05, zz + rnd.uniform(-0.3, 0.3), rnd.uniform(1.6, 3.2) * max(1.0, H / 25),
|
|
width=rnd.uniform(0.28, 0.45) * max(1.0, H / 30), m="M_Seaweed")
|
|
if w:
|
|
deco.append(w)
|
|
for k in range(n_coral):
|
|
th = rnd.uniform(0, TAU)
|
|
loc, nrm = surf_hit(bvh, cfn, th, rnd.uniform(0.3, 1.5))
|
|
if loc is not None:
|
|
deco += coral_cluster(loc, nrm, rnd, scale=1.6 * max(1.0, H / 25))
|
|
loc2, nrm2 = surf_hit(bvh, cfn, th + 0.25, 0.4)
|
|
if loc2 is not None:
|
|
deco.append(brain_coral(tuple(loc2), rnd.uniform(0.5, 0.8) * max(1.0, H / 25), seed + k))
|
|
for d in deco:
|
|
uv_box(d, 1)
|
|
deco_o = join(deco, "deco")
|
|
smooth(deco_o, 60)
|
|
smooth(rock, 38)
|
|
o = join([rock, deco_o], name)
|
|
return o
|
|
|
|
|
|
def env_spire_a():
|
|
H = 15.0
|
|
def rf(t):
|
|
return 4.2 * (1.08 - 0.32 * t + 0.08 * math.exp(-((t - 0.72) / 0.12) ** 2) - 0.1 * math.exp(-((t - 0.4) / 0.08) ** 2))
|
|
def rf2(t):
|
|
return 1.9 * (1.1 - 0.55 * t)
|
|
spire("SM_Spire_A", H, rf, 3, nseg=72, ring_h=0.22, cap_h=1.4, lean=(0.8, 0.3), notches=[(5.2, 0.16, 0.55)], wet_frac=0.5,
|
|
twin=dict(H=7.0, rfun=rf2, cap_h=1.0, lean=(1.2, -0.6), offset=(4.4, -2.2), nseg=40, crown=(0.7, 0.9, 2.0)),
|
|
boulders=5, n_barn=10, n_weed=8, n_coral=3, chunk=0.45, chunk_amp=0.55, rock_tris=5000, fiss=0.4, crown=(1.6, 1.5, 0.6))
|
|
return dict(elev=12, azim=-30)
|
|
|
|
|
|
def env_spire_b():
|
|
H = 25.0
|
|
def rf(t):
|
|
return 4.4 * (1.15 - 0.6 * t + 0.3 * math.exp(-((t - 0.72) / 0.12) ** 2))
|
|
def rf2(t):
|
|
return 2.2 * (1.12 - 0.6 * t)
|
|
spire("SM_Spire_B", H, rf, 7, nseg=72, ring_h=0.3, cap_h=2.2, lean=(2.8, -1.2), notches=[(7.6, 0.2, 0.7), (12.5, 0.12, 0.6)], wet_frac=0.42,
|
|
twin=dict(H=10.0, rfun=rf2, cap_h=1.2, lean=(-1.0, 0.8), offset=(-4.2, 3.0), nseg=40, crown=(0.8, 1.0, 4.0)),
|
|
boulders=5, n_barn=10, n_weed=8, n_coral=3, chunk=0.38, chunk_amp=0.7, rock_tris=5400, fiss=0.5, crown=(2.6, 2.4, -0.5))
|
|
return dict(elev=10, azim=-30)
|
|
|
|
|
|
def env_spire_c():
|
|
H = 40.0
|
|
def rf(t):
|
|
return 5.6 * (1.22 - 0.78 * t ** 0.85 + 0.16 * math.exp(-((t - 0.52) / 0.07) ** 2))
|
|
def rf2(t):
|
|
return 3.4 * (1.15 - 0.75 * t ** 0.9)
|
|
spire("SM_Spire_C", H, rf, 13, nseg=64, ring_h=0.4, cap_h=3.0, lean=(-2.4, 1.6), notches=[(9.0, 0.16, 0.8), (16.0, 0.14, 0.7), (24.5, 0.1, 0.7)],
|
|
wet_frac=0.38, twin=dict(H=21.0, rfun=rf2, cap_h=2.0, lean=(1.8, 0.8), offset=(4.6, 1.8), nseg=48, crown=(1.4, 1.8, 0.4)),
|
|
boulders=6, n_barn=11, n_weed=9, n_coral=3, chunk=0.3, chunk_amp=0.85, rock_tris=5800, fiss=0.6, crown=(2.0, 3.2, 2.2))
|
|
return dict(elev=8, azim=-30)
|
|
|
|
|
|
# ------------------------------------------------------------------------------- wreck ship
|
|
|
|
SHIP_L, SHIP_B, SHIP_D = 30.0, 7.0, 4.4
|
|
|
|
|
|
def hull_frame(y):
|
|
"""Return (half-beam, keel z, deck z, shape exponent) at y (bow at -Y)."""
|
|
t = min(1.0, max(0.0, (y + SHIP_L / 2) / SHIP_L))
|
|
if t < 0.32:
|
|
w = SHIP_B / 2 * max(0.04, math.sin(math.pi / 2 * t / 0.32) ** 0.85)
|
|
elif t > 0.86:
|
|
w = SHIP_B / 2 * (1 - 0.3 * ((t - 0.86) / 0.14) ** 2)
|
|
else:
|
|
w = SHIP_B / 2
|
|
k = 1.8 * max(0.0, (0.16 - t) / 0.16) ** 2 + 1.7 * max(0.0, (t - 0.86) / 0.14) ** 1.6
|
|
d = SHIP_D + 0.9 * max(0.0, (0.3 - t) / 0.3) ** 2 + 0.25 * max(0.0, (t - 0.8) / 0.2)
|
|
n = 2.0 + 4.0 * smoothstep(0.0, 0.35, t) - 1.8 * smoothstep(0.85, 1.0, t)
|
|
return w, k, d, n
|
|
|
|
|
|
def hull_ring(y):
|
|
w, k, d, n = hull_frame(y)
|
|
hb = k + (d - k) * 0.42
|
|
half = [(0.0, k)]
|
|
for i in range(1, 7):
|
|
phi = math.pi / 2 * (1 - i / 6)
|
|
x = w * math.cos(phi) ** (2 / n)
|
|
z = hb - (hb - k) * math.sin(phi) ** (2 / n)
|
|
half.append((x, z))
|
|
half += [(w * 1.02, hb + (d - hb) * 0.5), (w * 1.04, d), (w * 1.05, d + 0.55), (w * 0.97, d + 0.6), (w * 0.94, d + 0.05), (w * 0.5, d + 0.12), (0.0, d + 0.16)]
|
|
ring = half + [(-x, z) for (x, z) in reversed(half[1:-1])]
|
|
return ring
|
|
|
|
|
|
def hull_piece(y0, y1, n, break_at, rnd, cap_end):
|
|
"""Loft hull rings from y0..y1. break_at: 'start' or 'end' gets a jagged torn edge."""
|
|
bm = bmesh.new()
|
|
rings = []
|
|
ys = [y0 + (y1 - y0) * i / n for i in range(n + 1)]
|
|
for i, y in enumerate(ys):
|
|
ring = hull_ring(y)
|
|
jag = 0.0
|
|
if (break_at == "end" and i >= n - 1) or (break_at == "start" and i <= 1):
|
|
jag = 1.0 if (i == n or i == 0) else 0.45
|
|
vs = []
|
|
for j, (x, z) in enumerate(ring):
|
|
yy = y
|
|
xx, zz = x, z
|
|
if jag:
|
|
yy += jag * (0.9 * noise.noise(Vector((j * 0.7, y, 1.3))) + rnd.uniform(-0.25, 0.25)) * (1 if break_at == "end" else -1)
|
|
xx *= 1 - jag * 0.05 * rnd.random()
|
|
zz -= jag * 0.25 * rnd.random() * (1 if z > 3 else 0)
|
|
vs.append(bm.verts.new((xx, yy, zz)))
|
|
rings.append(vs)
|
|
m = len(rings[0])
|
|
for a, b in zip(rings, rings[1:]):
|
|
for j in range(m):
|
|
bm.faces.new((a[j], a[(j + 1) % m], b[(j + 1) % m], b[j]))
|
|
if cap_end == "start":
|
|
bm.faces.new(rings[0])
|
|
elif cap_end == "end":
|
|
bm.faces.new(rings[-1])
|
|
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)
|
|
o = mesh_obj("hull", bm)
|
|
# paint: navy topsides, red bottom, white rail, rust deck + rust patches
|
|
add_mats(o, "M_PaintRed", "M_Navy", "M_Rust", "M_PaintWhite")
|
|
me = o.data
|
|
for p in me.polygons:
|
|
c = Vector(p.center)
|
|
w, k, d, nn = hull_frame(c.y)
|
|
if c.z > d + 0.45:
|
|
mi = 3
|
|
elif p.normal.z > 0.6 and c.z > d - 0.2:
|
|
mi = 2
|
|
elif c.z < k + (d - k) * 0.42 + 0.02:
|
|
mi = 0
|
|
else:
|
|
mi = 2
|
|
p.material_index = mi
|
|
me.update()
|
|
o.data.materials.append(mat("M_Rust"))
|
|
mod(o, "SOLIDIFY", thickness=0.16, offset=-1, material_offset=4, material_offset_rim=4)
|
|
# material_offset maps inner shell index i -> i+4 : pad slots so they all exist and are rusty
|
|
for _ in range(3):
|
|
o.data.materials.append(mat("M_Rust"))
|
|
bake(o)
|
|
return o
|
|
|
|
|
|
def strakes(y0, y1, n=24):
|
|
"""White boot-top line at the bilge + rubbing strake under the deck edge, both sides."""
|
|
P = []
|
|
for side in (-1, 1):
|
|
boot, rub = [], []
|
|
for i in range(n + 1):
|
|
y = y0 + (y1 - y0) * i / n
|
|
ring = hull_ring(y)
|
|
bx_, bz = ring[6]
|
|
rx0, rz0 = ring[7]
|
|
rx1, rz1 = ring[8]
|
|
boot.append((side * (bx_ + 0.03), y, bz))
|
|
rub.append((side * ((rx0 + rx1) / 2 + 0.06), y, (rz0 + rz1) / 2 + 0.25))
|
|
P.append(ptube("boot", boot, 0.09, "M_PaintWhite", rs=1))
|
|
P.append(ptube("rub", rub, 0.12, "M_Rust", rs=1))
|
|
return P
|
|
|
|
|
|
def torn_ribs(y, rnd, dirn):
|
|
"""Bent frame ribs sticking out of the torn hull section."""
|
|
P = []
|
|
ring = hull_ring(y)
|
|
half = ring[:9]
|
|
for k in range(5):
|
|
side = -1 if k % 2 else 1
|
|
cut = rnd.randint(4, 8)
|
|
yy = y + dirn * rnd.uniform(0.3, 1.1)
|
|
pts = []
|
|
for j, (x, z) in enumerate(half[1:cut + 1]):
|
|
bend = (j / max(1, cut)) ** 2 * rnd.uniform(0.3, 0.9) * dirn
|
|
pts.append((side * (x - 0.12), yy + bend, z + 0.05))
|
|
if len(pts) >= 2:
|
|
P.append(ptube("rib", pts, 0.08, "M_Rust", rs=0))
|
|
for k in range(3):
|
|
x = rnd.uniform(-2.5, 2.5)
|
|
d = hull_frame(y)[2]
|
|
pl = bx(-0.5, 0.5, 0, 1.4, -0.05, 0.05, "M_Rust", bevel=0.02, segs=1, name="plate")
|
|
xf(pl, rot=(dirn * rnd.uniform(-35, -10), rnd.uniform(-15, 15), 0))
|
|
xf(pl, loc=(x, y - (0.2 if dirn > 0 else 1.2), d + 0.1))
|
|
P.append(pl)
|
|
return P
|
|
|
|
|
|
def porthole(loc, facing, r=0.16):
|
|
ring = torus("ph", r, 0.035, axis="Y", seg=10, rseg=4, m="M_Steel")
|
|
gl = cyl("phg", r * 0.95, 0.03, axis="Y", verts=10, m="M_Navy")
|
|
o = join([ring, gl], "porthole")
|
|
o.rotation_euler = Vector(facing).to_track_quat("Y", "Z").to_euler()
|
|
o.location = loc
|
|
return apply_xform(o)
|
|
|
|
|
|
def rail_run(pts, h=1.0, m="M_PaintWhite"):
|
|
P = []
|
|
for p in pts:
|
|
P.append(rod(p, (p[0], p[1], p[2] + h), 0.03, m, verts=5))
|
|
P.append(ptube("rail", [(p[0], p[1], p[2] + h) for p in pts], 0.035, m, rs=0))
|
|
P.append(ptube("rail", [(p[0], p[1], p[2] + h * 0.5) for p in pts], 0.025, m, rs=0))
|
|
return P
|
|
|
|
|
|
def container(L, m, rnd):
|
|
P = [bx(-1.2, 1.2, -L / 2, L / 2, 0, 2.5, m, bevel=0.06, segs=1, name="cbox")]
|
|
for k in range(int(L / 0.7)):
|
|
y = -L / 2 + 0.35 + k * 0.7
|
|
for sx in (-1, 1):
|
|
P.append(bx(sx * 1.2 - 0.05, sx * 1.2 + 0.05, y - 0.12, y + 0.12, 0.15, 2.35, m, bevel=0.03, segs=1, name="corr"))
|
|
for sy in (-1, 1):
|
|
P.append(bx(-1.25, 1.25, sy * L / 2 - 0.08, sy * L / 2 + 0.08, -0.02, 2.52, "M_Rust", bevel=0.04, segs=1, name="endframe"))
|
|
for x in (-0.4, 0.4):
|
|
P.append(rod((x, -L / 2 - 0.1, 0.3), (x, -L / 2 - 0.1, 2.2), 0.04, "M_Steel", verts=5))
|
|
return join(P, "container")
|
|
|
|
|
|
def env_wreck_ship():
|
|
rnd = random.Random(42)
|
|
yb = 1.5 # break line
|
|
# ---------------------------------------------------------- bow half
|
|
B = [hull_piece(-SHIP_L / 2, yb, 22, "end", rnd, "start")]
|
|
B += strakes(-SHIP_L / 2 + 1.2, yb - 0.9) + torn_ribs(yb - 0.5, rnd, +1)
|
|
dz = lambda y: hull_frame(y)[2]
|
|
# forecastle gear
|
|
B.append(cy(0.5, dz(-12) + 0.1, dz(-12) + 0.7, "M_Rust", x=-1.0, y=-11.5, verts=12, bevel=0.05, segs=1, name="windlass"))
|
|
B.append(cy(0.5, dz(-12) + 0.1, dz(-12) + 0.7, "M_Rust", x=1.0, y=-11.5, verts=12, bevel=0.05, segs=1, name="windlass"))
|
|
w = rod((-1.4, -11.5, dz(-12) + 0.5), (1.4, -11.5, dz(-12) + 0.5), 0.18, "M_DarkGrey", verts=10)
|
|
B.append(w)
|
|
for y in (-9.0, -4.0):
|
|
for sx in (-1, 1):
|
|
B.append(cy(0.2, dz(y) + 0.1, dz(y) + 0.7, "M_DarkGrey", x=sx * 2.6, y=y, verts=10, bevel=0.04, segs=1, name="bollard"))
|
|
B.append(cy(0.28, dz(y) + 0.6, dz(y) + 0.72, "M_DarkGrey", x=sx * 2.6, y=y, verts=10, name="bollardcap"))
|
|
# cargo hatches
|
|
for (y0, y1) in ((-7.5, -3.2), (-2.4, 0.8)):
|
|
B.append(bx(-2.4, 2.4, y0, y1, dz(y1) - 0.1, dz(y1) + 0.6, "M_Rust", bevel=0.08, segs=1, name="coaming"))
|
|
for k in range(3):
|
|
yy0 = y0 + (y1 - y0) * k / 3
|
|
yy1 = y0 + (y1 - y0) * (k + 1) / 3 - 0.08
|
|
lid = bx(-2.3, 2.3, yy0, yy1, dz(y1) + 0.6, dz(y1) + 0.85, "M_PaintRed" if k != 1 else "M_Rust", bevel=0.06, segs=1, name="hlid")
|
|
if y0 > -3 and k == 2:
|
|
xf(lid, rot=(-25, 6, 0))
|
|
xf(lid, loc=(0.4, 0.6, -0.4))
|
|
B.append(lid)
|
|
# foremast with bent boom
|
|
B.append(rod((0, -8.2, dz(-8)), (0, -8.2, dz(-8) + 7.5), 0.22, "M_PaintWhite", verts=10, r2=0.16))
|
|
B.append(cy(0.35, dz(-8) + 7.5, dz(-8) + 7.8, "M_DarkGrey", y=-8.2, verts=10, name="masttop"))
|
|
B.append(sphere("mlight", 0.15, (0, -8.2, dz(-8) + 7.95), seg=8, rings=5, m="M_LightRed"))
|
|
B.append(ptube("boom", bez([(0, -8.0, dz(-8) + 1.0), (1.2, -5.5, dz(-8) + 2.8), (2.6, -3.4, dz(-8) + 3.2), (3.6, -2.6, dz(-8) + 2.2)], 8), 0.14, "M_PaintOrange", rs=1))
|
|
B.append(ptube("stay", [(0, -8.2, dz(-8) + 7.4), (3.6, -2.6, dz(-8) + 2.2)], 0.03, "M_DarkGrey", rs=0))
|
|
B.append(ptube("stay", [(0, -8.2, dz(-8) + 7.4), (0, -14.4, dz(-14.5) + 0.6)], 0.03, "M_DarkGrey", rs=0))
|
|
# anchor + chain at the hawse
|
|
hz = dz(-12.5) - 1.0
|
|
w0, _, _, _ = hull_frame(-12.5)
|
|
an = []
|
|
an.append(rod((0, 0, 0), (0, 0, -1.6), 0.09, "M_DarkGrey", verts=8))
|
|
an.append(ptube("arms", bez([(-0.8, 0, -1.0), (-0.6, 0, -1.55), (0, 0, -1.75), (0.6, 0, -1.55), (0.8, 0, -1.0)], 9), 0.09, "M_DarkGrey", rs=1))
|
|
for sx in (-1, 1):
|
|
f = bx(-0.15, 0.15, -0.05, 0.05, -0.15, 0.15, "M_DarkGrey", bevel=0.03, segs=1, name="fluke")
|
|
xf(f, loc=(sx * 0.8, 0, -0.95), rot=(0, sx * 35, 0))
|
|
an.append(f)
|
|
an.append(torus("shackle", 0.15, 0.04, axis="Y", seg=10, rseg=4, m="M_DarkGrey"))
|
|
anc = join(an, "anchor")
|
|
xf(anc, loc=(w0 + 0.15, -12.5, hz), rot=(0, 0, 90))
|
|
B.append(anc)
|
|
for k in range(10):
|
|
lk = torus("link", 0.14, 0.04, axis="Y" if k % 2 else "X", seg=8, rseg=4, m="M_DarkGrey")
|
|
xf(lk, scale=(1, 1, 1.5))
|
|
xf(lk, loc=(w0 + 0.25 + k * 0.06, -12.6 + k * 0.18, hz - 0.3 - k * 0.32))
|
|
B.append(lk)
|
|
bow = join(B, "bow")
|
|
# ---------------------------------------------------------- stern half
|
|
S = [hull_piece(yb + 0.4, SHIP_L / 2, 20, "start", rnd, "end")]
|
|
S += strakes(yb + 1.3, SHIP_L / 2 - 0.3) + torn_ribs(yb + 0.9, rnd, -1)
|
|
ds = dz(10)
|
|
blocks = [((-3.1, 3.1, 7.6, 13.4), ds + 0.1, ds + 2.3), ((-2.7, 2.7, 8.2, 12.9), ds + 2.3, ds + 4.3), ((-3.4, 3.4, 8.4, 10.6), ds + 4.3, ds + 5.9)]
|
|
for (x0, x1, y0, y1), z0, z1 in blocks:
|
|
S.append(bx(x0, x1, y0, y1, z0, z1, "M_PaintWhite", bevel=0.12, segs=2, name="house"))
|
|
S.append(bx(x0 - 0.1, x1 + 0.1, y0 - 0.1, y1 + 0.1, z1 - 0.12, z1 + 0.06, "M_Rust", bevel=0.04, segs=1, name="eave"))
|
|
# bridge windows (front) + side portholes + rust streaks
|
|
for k in range(6):
|
|
x = -2.6 + k * 1.04
|
|
S.append(bx(x - 0.4, x + 0.4, 8.32, 8.42, ds + 4.75, ds + 5.55, "M_Navy", bevel=0.05, segs=1, name="win"))
|
|
for sx in (-1, 1):
|
|
for lvl, (yy0, yy1, zz) in enumerate(((8.4, 13.0, ds + 1.3), (8.9, 12.5, ds + 3.3))):
|
|
xw = (3.1 if lvl == 0 else 2.7) * sx
|
|
for k in range(4):
|
|
y = yy0 + 0.6 + k * (yy1 - yy0 - 1.2) / 3
|
|
S.append(porthole((xw + sx * 0.02, y, zz), (sx, 0, 0), r=0.2))
|
|
if (k + lvl) % 2 == 0:
|
|
S.append(bx(xw + sx * 0.0 - 0.02, xw + sx * 0.03 + 0.02, y - 0.06, y + 0.06, zz - 1.0, zz - 0.25, "M_Rust", bevel=0.0, name="streak"))
|
|
for k in range(3):
|
|
S.append(porthole((-1.4 + k * 1.4, 7.58, ds + 1.3), (0, -1, 0), r=0.2))
|
|
# door
|
|
S.append(bx(-0.5, 0.5, 7.52, 7.62, ds + 0.2, ds + 2.0, "M_Rust", bevel=0.06, segs=1, name="door"))
|
|
# funnel
|
|
fun = rev("funnel", [(0, 0), (1.15, 0), (1.12, 1.6), (1.15, 1.7), (1.15, 2.3), (1.1, 2.4), (1.0, 3.2), (0.9, 3.25)],
|
|
["M_PaintWhite", "M_PaintWhite", "M_PaintRed", "M_PaintRed", "M_PaintRed", "M_Rust", "M_DarkGrey"], segs=16)
|
|
xf(fun, loc=(0, 12.0, ds + 4.2), scale=(0.8, 1.15, 1), rot=(-8, 0, 0))
|
|
S.append(fun)
|
|
# radar mast on the bridge roof
|
|
S.append(rod((0, 9.5, ds + 5.9), (0, 9.5, ds + 8.4), 0.12, "M_PaintWhite", verts=8))
|
|
S.append(bx(-1.1, 1.1, 9.4, 9.6, ds + 7.4, ds + 7.55, "M_PaintWhite", bevel=0.03, segs=1, name="yard"))
|
|
rad = bx(-0.9, 0.9, -0.08, 0.08, -0.1, 0.1, "M_DarkGrey", bevel=0.05, segs=1, name="radar")
|
|
xf(rad, loc=(0, 9.5, ds + 8.5), rot=(0, 18, 25))
|
|
S.append(rad)
|
|
S.append(sphere("mlight", 0.13, (1.1, 9.5, ds + 7.7), seg=8, rings=5, m="M_LightRed"))
|
|
# bridge wings rails
|
|
for sx in (-1, 1):
|
|
S += rail_run([(sx * 3.4, 8.45 + k * 0.53, ds + 5.9) for k in range(5)], h=0.9)
|
|
# empty lifeboat davits, one bent
|
|
for k, sx in enumerate((-1, 1)):
|
|
for y in (9.2, 11.4):
|
|
pts = [(sx * 3.0, y, ds + 2.3), (sx * 3.4, y, ds + 3.3), (sx * 3.9, y, ds + 3.5)] if k == 0 else [(sx * 3.0, y, ds + 2.3), (sx * 3.5, y + 0.2, ds + 2.9), (sx * 3.8, y + 0.6, ds + 2.4)]
|
|
S.append(ptube("davit", bez(pts, 6), 0.09, "M_PaintOrange", rs=1))
|
|
# aft deck rails
|
|
S += rail_run([(-3.0 + 6.0 * k / 6, 14.1, ds + 0.3) for k in range(7)], h=0.9)
|
|
for sx in (-1, 1):
|
|
S += rail_run([(sx * 3.2, 4.0 + k * 1.2, ds + 0.6) for k in range(3)], h=0.9)
|
|
# container still on the stern deck near the break
|
|
c1 = container(5.8, "M_PaintTeal", rnd)
|
|
xf(c1, loc=(0.0, 4.6, ds + 0.65), rot=(0, 4, 88))
|
|
S.append(c1)
|
|
stern = join(S, "stern")
|
|
# ---------------------------------------------------------- place halves on the seabed
|
|
xf(bow, rot=(-5, -16, -3))
|
|
xf(bow, loc=(0.6, -1.0, -1.25))
|
|
xf(stern, rot=(3, 20, 5))
|
|
xf(stern, loc=(-0.5, 1.6, -1.7))
|
|
# spilled containers + debris on the seabed
|
|
deb = []
|
|
c2 = container(5.8, "M_PaintYellow", rnd)
|
|
xf(c2, rot=(0, 78, 0))
|
|
xf(c2, loc=(6.2, -0.4, 1.05), rot=(0, 0, 18))
|
|
deb.append(c2)
|
|
c3 = container(5.8, "M_PaintOrange", rnd)
|
|
xf(c3, rot=(0, -8, 0))
|
|
xf(c3, loc=(-6.6, 2.6, -0.3), rot=(0, 0, -64))
|
|
deb.append(c3)
|
|
for k in range(5):
|
|
a = rnd.uniform(0, TAU)
|
|
rr = rnd.uniform(5.5, 9.0)
|
|
pl = bx(-0.6, 0.6, -0.4, 0.4, -0.04, 0.04, "M_Rust", bevel=0.02, segs=1, name="plate")
|
|
for v in pl.data.vertices:
|
|
v.co.z += 0.15 * math.sin(v.co.x * 4)
|
|
xf(pl, loc=(math.cos(a) * rr, math.sin(a) * rr, 0.1), rot=(rnd.uniform(-20, 20), rnd.uniform(-20, 20), rnd.uniform(0, 360)))
|
|
deb.append(pl)
|
|
debris = join(deb, "debris")
|
|
for o in (bow, stern, debris):
|
|
uv_box(o, 0.5)
|
|
ship = join([bow, stern, debris], "SM_Wreck_Ship")
|
|
# barnacles + hanging seaweed on the hull (rays from the sides)
|
|
bvh = bvh_of(ship)
|
|
deco = []
|
|
for k in range(70):
|
|
side = rnd.choice((-1, 1))
|
|
y = rnd.uniform(-13, 13.5)
|
|
z = rnd.uniform(0.2, 2.6)
|
|
hit = bvh.ray_cast(Vector((side * 30, y, z)), Vector((-side, 0, 0)))
|
|
if hit[0] is None:
|
|
continue
|
|
r = rnd.uniform(0.12, 0.3)
|
|
b = barnacle(r, r * rnd.uniform(1.0, 1.5))
|
|
orient(b, hit[0], hit[1], spin=rnd.uniform(0, TAU), sink=r * 0.15)
|
|
deco.append(b)
|
|
for k in range(22):
|
|
side = rnd.choice((-1, 1))
|
|
y = rnd.uniform(-12, 13)
|
|
hit = bvh.ray_cast(Vector((side * 30, y, 6.2)), Vector((-side, 0, -0.08)).normalized())
|
|
if hit[0] is None:
|
|
continue
|
|
top = hit[0] + Vector((side * 0.1, 0, 0))
|
|
bm = bmesh.new()
|
|
Lv, Rv = [], []
|
|
ln = rnd.uniform(1.2, 2.8)
|
|
ph = rnd.uniform(0, TAU)
|
|
for i in range(7):
|
|
t = i / 6
|
|
p = top + Vector((side * (0.15 + 0.1 * t), 0.2 * math.sin(ph + t * 5), -ln * t))
|
|
hw = 0.14 * (1 - 0.6 * t)
|
|
Lv.append(bm.verts.new(p - Vector((0, hw, 0))))
|
|
Rv.append(bm.verts.new(p + Vector((0, hw, 0))))
|
|
for i in range(6):
|
|
bm.faces.new((Lv[i], Rv[i], Rv[i + 1], Lv[i + 1]))
|
|
wd = mesh_obj("weed", bm)
|
|
set_mats(wd, "M_Seaweed")
|
|
dbl(wd, 0.01)
|
|
deco.append(wd)
|
|
for d in deco:
|
|
uv_box(d, 1)
|
|
ship = join([ship] + deco, "SM_Wreck_Ship")
|
|
smooth(ship, 40)
|
|
return dict(elev=24, azim=-55, dist_mul=0.8, extra=[dict(elev=18, azim=125, dist_mul=0.8)])
|
|
|
|
|
|
# ------------------------------------------------------------------------------- probe
|
|
|
|
def env_wreck_probe():
|
|
rnd = random.Random(5)
|
|
P = []
|
|
# octagonal body
|
|
body = rev("body", [(0, 0.0), (0.95, 0.0), (1.05, 0.08), (1.05, 0.62), (1.07, 0.64), (1.07, 0.78), (1.05, 0.8), (1.05, 1.05), (0.95, 1.15), (0.6, 1.55), (0.52, 1.62), (0, 1.64)],
|
|
["M_HullWhite", "M_HullWhite", "M_HullWhite", "M_PaintOrange", "M_PaintOrange", "M_PaintOrange", "M_HullWhite", "M_HullWhite", "M_HullWhite", "M_PaintOrange", "M_PaintOrange"], segs=8, phase=math.pi / 8)
|
|
bv = body.modifiers.new("bev", "BEVEL"); bv.width = 0.035; bv.segments = 2; bv.limit_method = "ANGLE"; bv.angle_limit = math.radians(30)
|
|
bake(body)
|
|
P.append(body)
|
|
# gold foil lower module (crinkled)
|
|
foil = rev("foil", [(0, -0.75), (0.7, -0.75), (0.82, -0.6), (0.85, -0.1), (0.8, 0.0), (0, 0.0)], "M_Gold", segs=16, phase=math.pi / 16)
|
|
subsurf(foil, 1)
|
|
wobble(foil, 0.035, 7.0, seed=2)
|
|
P.append(foil)
|
|
# engine bell + RCS
|
|
P.append(rev("bell", [(0.18, -0.75), (0.2, -0.85), (0.32, -1.05), (0.42, -1.18), (0.4, -1.2), (0.3, -1.08), (0.17, -0.88)], ["M_DarkGrey", "M_Steel", "M_Steel", "M_Steel", "M_DarkGrey", "M_DarkGrey"], segs=16, close_top=False))
|
|
for k in range(4):
|
|
a = TAU * k / 4 + TAU / 8
|
|
n = rev("rcs", [(0.04, 0), (0.06, -0.05), (0.1, -0.16), (0.09, -0.17)], "M_DarkGrey", segs=8, close_top=False)
|
|
xf(n, rot=(0, 90, math.degrees(a)))
|
|
xf(n, loc=(math.cos(a) * 1.02, math.sin(a) * 1.02, 0.9))
|
|
P.append(n)
|
|
# hatch with window on the front face (-Y)
|
|
hatch = slab("hatch", fillet2d([(-0.32, 0.0), (0.32, 0.0), (0.32, 0.62), (-0.32, 0.62)], 0.12, n=2), -0.05, 0.05, "M_PaintWhite", plane="XZ", bevel=0.015, segs=1)
|
|
xf(hatch, loc=(0, -0.99, 0.15))
|
|
P.append(hatch)
|
|
P.append(porthole((0, -1.05, 0.62), (0, -1, 0), r=0.13))
|
|
P.append(bx(0.18, 0.24, -1.09, -1.04, 0.3, 0.48, "M_DarkGrey", bevel=0.015, segs=1, name="handle"))
|
|
P.append(decal("lbl", (-0.62, -0.985, 0.92), 0.42, 0.2, (math.sin(math.radians(-22.5)), -math.cos(math.radians(-22.5)), 0), "M_Label"))
|
|
# legs: 4, one buckled
|
|
for k in range(4):
|
|
a = TAU * k / 4 + TAU / 8
|
|
ca, sa = math.cos(a), math.sin(a)
|
|
hip = Vector((ca * 0.98, sa * 0.98, 0.15))
|
|
if k == 2:
|
|
knee = Vector((ca * 1.6, sa * 1.6, -0.45))
|
|
foot = Vector((ca * 1.75, sa * 1.75, -0.2))
|
|
else:
|
|
knee = Vector((ca * 1.55, sa * 1.55, -0.5))
|
|
foot = Vector((ca * 1.95, sa * 1.95, -1.15))
|
|
P.append(rod(hip, knee, 0.075, "M_Steel", verts=8))
|
|
P.append(rod(knee, foot, 0.06, "M_PaintOrange", verts=8))
|
|
P.append(sphere("knee", 0.1, tuple(knee), seg=8, rings=6, m="M_DarkGrey"))
|
|
P.append(rod(Vector((ca * 0.8, sa * 0.8, -0.6)), knee, 0.045, "M_Steel", verts=6))
|
|
pad = rev("pad", [(0, -0.02), (0.28, -0.02), (0.3, 0.02), (0.2, 0.09), (0.08, 0.12)], ["M_PaintWhite", "M_PaintWhite", "M_PaintWhite", "M_DarkGrey"], segs=12)
|
|
if k == 2:
|
|
xf(pad, rot=(50, 0, math.degrees(a) + 90))
|
|
xf(pad, loc=tuple(foot - Vector((0, 0, 0.08))))
|
|
P.append(pad)
|
|
# solar wings: one deployed, one snapped and hanging
|
|
def wing():
|
|
W = [bx(0.0, 2.2, -0.04, 0.04, -0.55, 0.55, "M_PaintWhite", bevel=0.03, segs=1, name="frame")]
|
|
for i in range(4):
|
|
x0 = 0.08 + i * 0.53
|
|
W.append(bx(x0, x0 + 0.48, -0.055, 0.055, -0.5, 0.5, "M_SolarPanel", bevel=0.01, segs=1, name="cells"))
|
|
W.append(rod((-0.35, 0, 0), (0.05, 0, 0), 0.05, "M_Steel", verts=8))
|
|
return join(W, "wing")
|
|
w1 = wing()
|
|
xf(w1, rot=(0, -8, 0))
|
|
xf(w1, loc=(1.38, 0.2, 0.95), rot=(0, 0, 12))
|
|
P.append(w1)
|
|
w2 = wing()
|
|
xf(w2, rot=(70, -55, 0))
|
|
xf(w2, loc=(-1.35, 0.3, 0.8), rot=(0, 0, 180 + 15))
|
|
P.append(w2)
|
|
P.append(rod((-1.02, 0.25, 0.95), (-1.32, 0.3, 0.86), 0.05, "M_Steel", verts=8))
|
|
# dish antenna on a bent mast
|
|
P.append(ptube("mast", bez([(0.2, 0.1, 1.6), (0.25, 0.15, 2.1), (0.5, 0.25, 2.4)], 6), 0.06, "M_Steel", rs=1))
|
|
dish = rev("dish", [(0, 0), (0.18, 0.02), (0.36, 0.08), (0.5, 0.17)], "M_PaintWhite", segs=16, close_top=False)
|
|
dish.data.materials.append(mat("M_PaintOrange"))
|
|
mod(dish, "SOLIDIFY", thickness=0.03, offset=-1, material_offset=1)
|
|
bake(dish)
|
|
dsh = join([dish, rev("feed", [(0, 0.0), (0.04, 0.0), (0.03, 0.32), (0.06, 0.34), (0, 0.38)], "M_DarkGrey", segs=8)], "dish")
|
|
xf(dsh, rot=(30, 70, 15))
|
|
xf(dsh, loc=(0.55, 0.27, 2.42))
|
|
P.append(dsh)
|
|
# bent whip antenna + beacon
|
|
P.append(ptube("whip", bez([(-0.35, -0.2, 1.6), (-0.4, -0.25, 2.3), (-0.6, -0.3, 2.7), (-1.0, -0.35, 2.75)], 10), 0.022, "M_Steel", rs=1))
|
|
P.append(sphere("tip", 0.05, (-1.0, -0.35, 2.75), seg=8, rings=5, m="M_PaintOrange"))
|
|
P.append(rev("beacon", [(0, 1.62), (0.11, 1.62), (0.11, 1.68), (0.09, 1.74), (0.05, 1.79), (0, 1.8)], ["M_DarkGrey", "M_LightRed", "M_LightRed", "M_LightRed", "M_LightRed"], segs=12))
|
|
probe = join([p for p in P if p is not None], "probe")
|
|
# crashed pose: tilted, half-buried in the seabed
|
|
xf(probe, rot=(14, -9, 22))
|
|
xf(probe, loc=(0, 0, 0.95))
|
|
# sand / sediment pile + scattered debris + growth
|
|
deco = []
|
|
mound = rev("mound", [(0, 0.55), (0.9, 0.5), (1.7, 0.32), (2.4, 0.12), (2.9, 0.0), (3.1, -0.1)], "M_Sand", segs=24, close_top=False)
|
|
mound = join([mound], "mound")
|
|
for v in mound.data.vertices:
|
|
rr = Vector((v.co.x, v.co.y)).length
|
|
v.co.z += 0.18 * noise.noise(Vector((v.co.x * 0.6, v.co.y * 0.6, 1.0))) * min(1.0, rr)
|
|
v.co.x *= 1.15
|
|
deco.append(mound)
|
|
deco.append(boulder(0.45, (2.3, -1.2, 0.1), 9, sc=(1.3, 1.0, 0.6), m="M_RockWet", sub=1))
|
|
deco.append(boulder(0.3, (-2.2, 1.4, 0.05), 10, sc=(1.2, 1.0, 0.6), m="M_RockWet", sub=1))
|
|
bvh = bvh_of(probe)
|
|
for k in range(26):
|
|
a = rnd.uniform(0, TAU)
|
|
z = rnd.uniform(0.4, 1.4)
|
|
hit = bvh.ray_cast(Vector((math.cos(a) * 10, math.sin(a) * 10, z)), Vector((-math.cos(a), -math.sin(a), 0)))
|
|
if hit[0] is None or hit[0].z > 1.6:
|
|
continue
|
|
r = rnd.uniform(0.04, 0.09)
|
|
b = barnacle(r, r * 1.3)
|
|
orient(b, hit[0], hit[1], spin=rnd.uniform(0, TAU), sink=r * 0.15)
|
|
deco.append(b)
|
|
for k in range(6):
|
|
a = rnd.uniform(0, TAU)
|
|
hit = bvh.ray_cast(Vector((math.cos(a) * 10, math.sin(a) * 10, 1.9)), Vector((-math.cos(a), -math.sin(a), 0)))
|
|
if hit[0] is None:
|
|
continue
|
|
top = hit[0] + Vector(hit[1]) * 0.04
|
|
bm = bmesh.new()
|
|
Lv, Rv = [], []
|
|
ph = rnd.uniform(0, TAU)
|
|
out = Vector((math.cos(a), math.sin(a), 0))
|
|
side = Vector((0, 0, 1)).cross(out)
|
|
for i in range(6):
|
|
t = i / 5
|
|
p = top + out * (0.05 + 0.15 * t) + side * 0.08 * math.sin(ph + t * 6) - Vector((0, 0, 1.1 * t))
|
|
hw = 0.07 * (1 - 0.5 * t)
|
|
Lv.append(bm.verts.new(p - side * hw)); Rv.append(bm.verts.new(p + side * hw))
|
|
for i in range(5):
|
|
bm.faces.new((Lv[i], Rv[i], Rv[i + 1], Lv[i + 1]))
|
|
wd = mesh_obj("weed", bm); set_mats(wd, "M_Seaweed"); dbl(wd, 0.006)
|
|
deco.append(wd)
|
|
for k in range(2):
|
|
a = rnd.uniform(0, TAU)
|
|
deco += coral_cluster((math.cos(a) * 2.3, math.sin(a) * 2.3, 0.0), (0, 0, 1), rnd, scale=0.6)
|
|
for d in deco:
|
|
uv_box(d, 1)
|
|
uv_keep(probe, 1)
|
|
o = join([probe] + deco, "SM_Wreck_Probe")
|
|
smooth(o, 40)
|
|
return dict(elev=22, azim=-30, dist_mul=0.85)
|
|
|
|
|
|
# ------------------------------------------------------------------------------- buoy
|
|
|
|
def env_buoy():
|
|
P = []
|
|
# float (waterline at z=0)
|
|
P.append(rev("float", [(0, -0.62), (0.3, -0.64), (0.58, -0.52), (0.72, -0.3), (0.78, -0.08), (0.79, 0.0), (0.79, 0.16), (0.76, 0.26), (0.62, 0.32), (0.3, 0.35), (0, 0.36)],
|
|
["M_DarkGrey", "M_DarkGrey", "M_PaintRed", "M_PaintRed", "M_PaintRed", "M_PaintWhite", "M_PaintWhite", "M_PaintRed", "M_PaintRed", "M_PaintRed"], segs=28))
|
|
P.append(torus("fender", 0.8, 0.075, loc=(0, 0, 0.2), seg=28, rseg=6, m="M_Rubber"))
|
|
for k in range(4):
|
|
a = TAU * k / 4
|
|
e = torus("eye", 0.07, 0.022, axis="X", seg=8, rseg=4, m="M_Steel")
|
|
xf(e, rot=(0, 0, math.degrees(a)))
|
|
xf(e, loc=(math.cos(a) * 0.55, math.sin(a) * 0.55, 0.38))
|
|
P.append(e)
|
|
# counterweight tail
|
|
P.append(rod((0, 0, -0.6), (0, 0, -1.25), 0.07, "M_DarkGrey", verts=10))
|
|
P.append(rev("weight", [(0, -1.45), (0.16, -1.45), (0.2, -1.38), (0.2, -1.25), (0.14, -1.2), (0.07, -1.18)], "M_DarkGrey", segs=12))
|
|
P.append(torus("moor", 0.09, 0.025, loc=(0, 0, -1.55), axis="X", seg=10, rseg=4, m="M_Steel"))
|
|
# lattice tower
|
|
base_r, top_r, z0, z1 = 0.42, 0.2, 0.34, 1.85
|
|
corners = []
|
|
for k in range(4):
|
|
a = TAU * k / 4 + TAU / 8
|
|
b_ = Vector((math.cos(a) * base_r, math.sin(a) * base_r, z0))
|
|
t_ = Vector((math.cos(a) * top_r, math.sin(a) * top_r, z1))
|
|
corners.append((b_, t_))
|
|
P.append(rod(b_, t_, 0.04, "M_PaintWhite", verts=8))
|
|
for k in range(4):
|
|
(b0, t0), (b1, t1) = corners[k], corners[(k + 1) % 4]
|
|
for (ta, tb) in ((0.15, 0.5), (0.5, 0.85)):
|
|
pa = b0.lerp(t0, ta); pb = b1.lerp(t1, tb)
|
|
P.append(rod(pa, pb, 0.022, "M_PaintWhite", verts=6))
|
|
# daymark panel (red with white stripe) between front/back legs
|
|
if k in (0, 2):
|
|
pts = [b0.lerp(t0, 0.25), b1.lerp(t1, 0.25), b1.lerp(t1, 0.8), b0.lerp(t0, 0.8)]
|
|
bm = bmesh.new()
|
|
vs = [bm.verts.new(p) for p in pts]
|
|
bm.faces.new(vs)
|
|
pan = mesh_obj("panel", bm)
|
|
set_mats(pan, "M_PaintRed")
|
|
mod(pan, "SOLIDIFY", thickness=0.04, offset=0)
|
|
bake(pan)
|
|
P.append(pan)
|
|
st = [b0.lerp(t0, 0.47), b1.lerp(t1, 0.47), b1.lerp(t1, 0.58), b0.lerp(t0, 0.58)]
|
|
bm = bmesh.new()
|
|
vs = [bm.verts.new(p) for p in st]
|
|
bm.faces.new(vs)
|
|
sp = mesh_obj("stripe", bm)
|
|
set_mats(sp, "M_PaintWhite")
|
|
mod(sp, "SOLIDIFY", thickness=0.06, offset=0)
|
|
bake(sp)
|
|
P.append(sp)
|
|
# platform, cage, solar, radar reflector
|
|
P.append(rev("plat", [(0, 1.84), (0.3, 1.84), (0.32, 1.87), (0.32, 1.9), (0.3, 1.92), (0, 1.92)], ["M_DarkGrey", "M_PaintRed", "M_PaintRed", "M_PaintRed", "M_PaintRed"], segs=16))
|
|
for k in range(6):
|
|
a = TAU * k / 6
|
|
P.append(rod((math.cos(a) * 0.27, math.sin(a) * 0.27, 1.92), (math.cos(a) * 0.27, math.sin(a) * 0.27, 2.15), 0.012, "M_PaintWhite", verts=5))
|
|
P.append(torus("cage", 0.27, 0.016, loc=(0, 0, 2.15), seg=16, rseg=4, m="M_PaintWhite"))
|
|
for sx in (-1, 1):
|
|
sp = bx(-0.13, 0.13, -0.02, 0.02, -0.11, 0.11, "M_SolarPanel", bevel=0.01, segs=1, name="solar")
|
|
xf(sp, rot=(-35 * sx, 0, 0))
|
|
xf(sp, loc=(0, sx * 0.38, 1.78))
|
|
P.append(sp)
|
|
P.append(rod((0, sx * 0.25, 1.82), (0, sx * 0.36, 1.8), 0.012, "M_Steel", verts=5))
|
|
P.append(cy(0.05, 2.15, 2.4, "M_DarkGrey", verts=8, name="rstem"))
|
|
for (rx, ry, rz) in ((0, 0, 0), (90, 0, 0), (0, 90, 0)):
|
|
pl = bx(-0.16, 0.16, -0.16, 0.16, -0.006, 0.006, "M_Steel", bevel=0.0, name="refl")
|
|
xf(pl, rot=(rx, ry, 45))
|
|
xf(pl, loc=(0, 0, 2.55))
|
|
P.append(pl)
|
|
body = join(P, "Body")
|
|
finalize(body)
|
|
light = rev("Light", [(0, 1.92), (0.09, 1.92), (0.11, 1.96), (0.12, 2.02), (0.11, 2.08), (0.07, 2.12), (0, 2.13)], "M_LightRed", segs=12)
|
|
smooth(light, 50)
|
|
uv_box(light, 1)
|
|
set_origin(light, (0, 0, 2.02))
|
|
return dict(elev=12)
|
|
|
|
|
|
ENV = {
|
|
"SM_Spire_A": env_spire_a,
|
|
"SM_Spire_B": env_spire_b,
|
|
"SM_Spire_C": env_spire_c,
|
|
"SM_Wreck_Ship": env_wreck_ship,
|
|
"SM_Wreck_Probe": env_wreck_probe,
|
|
"SM_Buoy": env_buoy,
|
|
}
|
|
|
|
# =============================================================================== runner
|
|
|
|
BUDGET = {"SM_Spire_A": 12000, "SM_Spire_B": 12000, "SM_Spire_C": 12000, "SM_Wreck_Ship": 25000, "SM_Wreck_Probe": 10000, "SM_Buoy": 4000}
|
|
|
|
# preview-only tints for textured materials whose texture file is not generated yet
|
|
FALLBACK = {"M_Rock": "#B4A79E", "M_RockWet": "#59626B", "M_RockBand": "#D9B994", "M_RockLilac": "#A898C8", "M_Rust": "#8E4D2E",
|
|
"M_Label": "#EEF1F2", "M_Logo": "#FFFFFF", "M_Fabric": "#F2EEE6", "M_Sand": "#E3CFA3", "M_HullWhite": "#F4F6F8"}
|
|
|
|
|
|
def preview_tints():
|
|
for m_ in bpy.data.materials:
|
|
d = common.MATDEFS.get(m_.name)
|
|
if not d or not d.get("texture") or os.path.exists(os.path.join(TEXTURES, d["texture"])):
|
|
continue
|
|
col = FALLBACK.get(m_.name)
|
|
if col and m_.node_tree:
|
|
b = next((n for n in m_.node_tree.nodes if n.type == "BSDF_PRINCIPLED"), None)
|
|
if b:
|
|
b.inputs["Base Color"].default_value = hex2rgb(col) + [1.0]
|
|
|
|
|
|
def main(builders):
|
|
args = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else []
|
|
names = args or list(builders.keys())
|
|
for n in names:
|
|
reset()
|
|
random.seed(zlib.crc32(n.encode()))
|
|
res = builders[n]() or {}
|
|
extra = res.pop("extra", [])
|
|
meshes = [o for o in bpy.context.scene.objects if o.type == "MESH"]
|
|
total = 0
|
|
for o in meshes:
|
|
tri_ngons(o)
|
|
total += ntris(o)
|
|
budget = BUDGET.get(n, 4000)
|
|
info = ", ".join(f"{o.name}:{ntris(o)}" for o in meshes)
|
|
print(f"[{n}] tris={total} budget={budget} {'OK' if total <= budget else 'OVER'} | {info}")
|
|
export(n)
|
|
save_blend(n)
|
|
preview_tints()
|
|
if os.environ.get("OSD_CLAY") == "1":
|
|
for m_ in bpy.data.materials:
|
|
if m_.node_tree:
|
|
b = next((x for x in m_.node_tree.nodes if x.type == "BSDF_PRINCIPLED"), None)
|
|
for l in list(m_.node_tree.links):
|
|
if l.to_node == b and l.to_socket.name == "Base Color":
|
|
m_.node_tree.links.remove(l)
|
|
if b and not m_.name.startswith(("M_Light", "M_Emissive", "M_Ember")):
|
|
c = {"M_RockWet": (0.18, 0.2, 0.22), "M_RockBand": (0.5, 0.4, 0.3), "M_RockLilac": (0.4, 0.35, 0.5)}.get(m_.name, (0.55, 0.55, 0.55))
|
|
if m_.name in ("M_Barnacle", "M_Coral", "M_Seaweed", "M_PaintRed", "M_Navy", "M_PaintOrange", "M_PaintTeal", "M_PaintYellow"):
|
|
continue
|
|
b.inputs["Base Color"].default_value = (*c, 1)
|
|
n = n + "_clay"
|
|
preview(n, **res)
|
|
for k, pv in enumerate(extra):
|
|
preview(f"{n}_{k + 1}", **pv)
|
|
print(f"[{n}] done")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
ALL = dict(DECOR)
|
|
ALL.update(globals().get("ENV", {}))
|
|
main(ALL)
|