"""Wedge supercar body + wheel for an SL RC car: original design in the spirit of a mid-70s Italian wedge (sharply raked screen, trapezoid side glass, NACA side scoops, air boxes, louvred deck). No badges. "C:/Program Files/Blender Foundation/Blender 5.2/blender.exe" -b -P gen_car.py -- [--scale 0.17] [--out DIR] [--render] [--color red|white|yellow|green] [--checks] Modelled at real scale (length 4.14, width 1.89, height 1.07, wheelbase 2.45 m; x forward, y left, z up, ground z=0, origin mid-wheelbase), exported Z-up (export_yup=False) scaled by --scale, centred on the bbox (SL centres a mesh on its bbox anyway). body.glb one mesh. Faces: 0 paint, 1 glass, 2 black trim/vents/wheel wells, 3 front lamps, 4 tail lamps. Material names carry the face number ("0_paint"...): SL orders faces alphabetically by material name. The shell is a loft: one ring of 26 points per station (14 per half, mirrored), so UVs are a smooth function of position (u along the car, v = arc length from the roof centre line, folded at y=0): no seams. Small add-ons (mirrors, lamps, slats, pipes) are separate closed boxes with planar UVs. wheel.glb one wheel + tyre, axle along Y, outer face +Y, centred on the axle. Faces: 0 tyre, 1 rim, 2 dark ("0_tyre"...). --checks: extra orthographic side/top/front/rear renders (for proportions). Claude Opus 5.5 (subagent for Tessel), 2026-10-11; nose cap, tail, air-boxes, lamps, material names 2026-10-12. """ import math import os import sys import bpy from mathutils import Euler, Matrix, Vector argv = sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [] def arg(name, default, conv=str): return conv(argv[argv.index(name) + 1]) if name in argv else default HERE = os.path.dirname(os.path.abspath(__file__)) OUT = arg("--out", HERE) SCALE = arg("--scale", 0.17, float) COLOR = arg("--color", "red") RENDER, CHECKS = "--render" in argv, "--checks" in argv PAINT, GLASS, BLACK, LAMP, TAIL = range(5) # ------------------------------------------------------------------ dimensions (real metres) XN, XT = 2.205, -1.935 # nose tip, tail (length 4.14) FA, RA = 1.225, -1.225 # axles (wheelbase 2.45) TF, TR = 1.52, 1.58 # track front / rear (to tyre centres) R_TYRE, W_TYRE = 0.315, 0.22 # wheel.glb: radius, width (front) REAR_WIDE = 1.36 # rear tyres: scale wheel.glb along Y by this XC, XR1, XR2 = 0.78, 0.20, -0.38 # cowl (screen base), roof front, roof rear XCP, XRW = -0.60, -0.66 # C-pillar foot / air-box intake face, rear glass bottom + air-box start XAB1, XAB2 = -1.30, -1.48 # air-box top ends, air-box back meets the deck XD1, XD2, XD3 = 0.15, -0.55, -0.57 # NACA scoop: tip, opening, flank resumes LV1, LV2 = -0.74, -1.40 # louvre panel on the deck ZTOP_N, ZCHIN = 0.525, 0.225 # nose: leading edge, chin ORDER = ["B0", "B1", "W1", "W2", "C1", "N1o", "N1i", "N2i", "N2o", "S", "G0", "G1", "G2", "T"] # Profile lines (x, y, z), interpolated linearly in x. B0 floor centre, B1 floor edge, W1/W2 wheel-well # inner/outer edge (the sill outside the arches), C1 main side crease, S shoulder, G0 glass base / hood edge / # air-box outer top, G1 roof edge / A-pillar / air-box inner top, G2 roof / screen edge / deck edge, T centre line. LINES = { "B0": [(XN, 0, ZCHIN), (FA, 0, 0.14), (RA, 0, 0.14), (XT, 0, 0.245)], "B1": [(XN, 0.55, ZCHIN), (FA, 0.58, 0.145), (RA, 0.58, 0.145), (XT, 0.58, 0.245)], "W1": [(XN, 0.62, ZCHIN + 0.003), (FA, 0.62, 0.15), (RA, 0.62, 0.15), (XT, 0.62, 0.247)], "W2": [(XN, 0.74, 0.235), (1.90, 0.82, 0.19), (FA, 0.85, 0.16), (RA, 0.88, 0.165), (XT, 0.86, 0.25)], "C1": [(XN, 0.80, 0.43), (1.90, 0.885, 0.55), (FA + 0.27, 0.92, 0.675), (FA - 0.27, 0.925, 0.675), (0.40, 0.935, 0.665), (RA + 0.30, 0.945, 0.71), (RA - 0.30, 0.945, 0.71), (XT, 0.94, 0.70)], "S": [(XN, 0.78, 0.505), (1.90, 0.875, 0.58), (FA, 0.915, 0.71), (XC, 0.91, 0.80), (XR1, 0.905, 0.815), (XCP, 0.92, 0.835), (RA, 0.94, 0.85), (XT, 0.935, 0.86)], "G0": [(XN, 0.72, 0.518), (XC, 0.86, 0.815), (XR1, 0.84, 0.83), (XR2, 0.84, 0.835), (XCP, 0.865, 0.85), (XRW, 0.90, 0.99), (XAB1, 0.905, 0.965), (XAB2, 0.905, 0.893), (XT + 0.12, 0.88, 0.872), (XT, 0.88, 0.89)], "G1": [(XN, 0.62, 0.521), (XC, 0.78, 0.822), (XR1, 0.64, 1.045), (XR2, 0.64, 1.045), (XCP, 0.65, 0.95), (XRW, 0.62, 0.99), (XAB1, 0.62, 0.965), (XAB2, 0.64, 0.898), (XT + 0.12, 0.67, 0.876), (XT, 0.68, 0.895)], "G2": [(XN, 0.50, 0.523), (XC, 0.70, 0.826), (XR1, 0.55, 1.062), (XR2, 0.55, 1.062), (XRW, 0.52, 0.93), (XAB1, 0.52, 0.915), (XAB2, 0.54, 0.904), (XT + 0.12, 0.555, 0.877), (XT, 0.56, 0.897)], "T": [(XN, 0, ZTOP_N), (XC, 0, 0.83), (XR1, 0, 1.07), (XR2, 0, 1.07), (XRW, 0, 0.935), (-1.55, 0, 0.905), (XT + 0.12, 0, 0.878), (XT, 0, 0.90)], } # wheel arches: centre, half-length at the sill, half-length of the flat top, top height (trapezoids) ARCHES = [(FA, 0.52, 0.27, 0.655), (RA, 0.55, 0.30, 0.69)] def interp(keys, x): ks = sorted(keys) if x <= ks[0][0]: return ks[0][1:] for a, b in zip(ks, ks[1:]): if x <= b[0]: t = (x - a[0]) / (b[0] - a[0]) return tuple(p + (q - p) * t for p, q in zip(a[1:], b[1:])) return ks[-1][1:] def arch(x): for c, ro, ri, zt in ARCHES: d = abs(x - c) if d < ro: return (1.0 if d <= ri else (ro - d) / (ro - ri)), zt return 0.0, 0.0 def section(x): """Half section at station x: list of (y, z) in ORDER.""" P = {n: interp(k, x) for n, k in LINES.items()} a, zt = arch(x) if a > 0: for n, yt in (("W1", 0.60), ("W2", P["C1"][0] - 0.01)): y, z = P[n] P[n] = (y + (yt - y) * a, z + (zt - z) * a) P["C1"] = (P["C1"][0], max(P["C1"][1], P["W2"][1] + 0.02)) (yc, zc), (ys, zs) = P["C1"], P["S"] if XD2 <= x <= XD1 or abs(x - XD3) < 1e-6: # NACA scoop: a recessed triangle widening rearward t = 1.0 if x <= XD2 else (XD1 - x) / (XD1 - XD2) hh = 0.03 + 0.38 * t s = [0.5 - hh, 0.5 - hh * 0.7, 0.5 + hh * 0.7, 0.5 + hh] depth = 0.0 if x < XD2 else 0.055 * t else: s, depth = [0.2, 0.4, 0.6, 0.8], 0.0 for n, sv, dd in zip(("N1o", "N1i", "N2i", "N2o"), s, (0, depth, depth, 0)): P[n] = (yc + (ys - yc) * sv - dd, zc + (zs - zc) * sv) return [P[n] for n in ORDER] def stations(): xs = {XN, XT, XD1, XD2, XD3, LV1, LV2} for keys in LINES.values(): xs.update(k[0] for k in keys) for c, ro, ri, _ in ARCHES: xs.update((c - ro, c - ri, c + ri, c + ro)) out = [] for x in sorted(xs, reverse=True): if not out or out[-1] - x > 0.008: out.append(x) return out def nose_x(y, z): """The nose ring is raked (chin set back) and chamfered at the corners in plan.""" return XN - 0.12 * (ZTOP_N - z) / (ZTOP_N - ZCHIN) - max(0.0, abs(y) - 0.55) * 0.6 def tail_x(y): return XT + max(0.0, abs(y) - 0.80) * 0.5 # ------------------------------------------------------------------ mesh building class Part: def __init__(self, name): self.name, self.V, self.UV, self.F, self.M = name, [], [], [], [] def v(self, p, uv=None): p = Vector(p) self.V.append(p) self.UV.append(uv if uv is not None else ((p.x - XT) / 4.2, 0.5 + (1.1 - p.z + abs(p.y) * 0.3) / 2.6)) return len(self.V) - 1 def f(self, idx, m): self.F.append(tuple(idx)) self.M.append(m) def box8(self, c, m): """c: 8 corners, bottom ring then top ring, same winding.""" i = [self.v(p) for p in c] for q in ((0, 3, 2, 1), (4, 5, 6, 7), (0, 1, 5, 4), (1, 2, 6, 5), (2, 3, 7, 6), (3, 0, 4, 7)): self.f([i[k] for k in q], m) def box(self, lo, hi, m): (x0, y0, z0), (x1, y1, z1) = lo, hi self.box8([(x0, y0, z0), (x1, y0, z0), (x1, y1, z0), (x0, y1, z0), (x0, y0, z1), (x1, y0, z1), (x1, y1, z1), (x0, y1, z1)], m) def beam(self, a, b, w, h, m): a, b = Vector(a), Vector(b) d = (b - a).normalized() sd = d.cross(Vector((0, 0, 1))).normalized() * (w / 2) up = sd.cross(d).normalized() * (h / 2) self.box8([a - sd - up, a + sd - up, b + sd - up, b - sd - up, a - sd + up, a + sd + up, b + sd + up, b - sd + up], m) def tube_x(self, x0, x1, y, z, r, n, m, cap_m): ring0 = [self.v((x0, y + r * math.cos(2 * math.pi * k / n), z + r * math.sin(2 * math.pi * k / n))) for k in range(n)] ring1 = [self.v((x1, y + r * math.cos(2 * math.pi * k / n), z + r * math.sin(2 * math.pi * k / n))) for k in range(n)] for k in range(n): self.f((ring0[k], ring0[(k + 1) % n], ring1[(k + 1) % n], ring1[k]), m) self.f(ring0[::-1], m) self.f(ring1, cap_m) def tris(self): return sum(len(f) - 2 for f in self.F) def build_body(): p = Part("body") xs = stations() rings, half_n = [], len(ORDER) for i, x in enumerate(xs): half = section(x) arc = [0.0] * half_n # arc length from the centre line T, going down for j in range(half_n - 2, -1, -1): arc[j] = arc[j + 1] + math.dist(half[j], half[j + 1]) idx = {} for j in list(range(half_n)) + list(range(half_n - 2, 0, -1)): for sgn in ((1,) if j in (0, half_n - 1) else (1, -1)): if (j, sgn) in idx: continue y, z = half[j] y *= sgn xx = nose_x(y, z) if i == 0 else tail_x(y) if i == len(xs) - 1 else x idx[(j, sgn)] = p.v((xx, y, z), ((xx - XT) / 4.2, arc[j] / 2.6)) ring = [idx[(j, 1)] for j in range(half_n)] + [idx[(j, -1)] for j in range(half_n - 2, 0, -1)] rings.append((x, ring)) def ri(j, sgn): # ring position of half point j on side sgn return j if (sgn > 0 or j in (0, half_n - 1)) else 2 * (half_n - 1) - j def strip_mat(k, xm): if k in (0, 1, 2): return BLACK # floor and wheel wells if k in (5, 6, 7) and XD3 < xm < XD1: return BLACK # NACA scoop if k == 10: if XR2 < xm < XC: return GLASS # side glass if XRW < xm < XCP: return BLACK # air-box intake face if k == 12: if XR1 < xm < XC or XRW < xm < XR2: return GLASS # windscreen, rear glass if LV2 < xm < LV1: return BLACK # louvre panel return PAINT for (xa, ra), (xb, rb) in zip(rings, rings[1:]): xm = (xa + xb) / 2 for k in range(half_n - 1): m = strip_mat(k, xm) for sgn in (1, -1): a0, a1 = ra[ri(k, sgn)], ra[ri(k + 1, sgn)] b0, b1 = rb[ri(k, sgn)], rb[ri(k + 1, sgn)] if k == 10 and XCP < xm < XR2: # the side glass's raked rear edge runs diagonally across this quad p.f((a0, a1, b0), GLASS) p.f((a1, b1, b0), PAINT) continue d0 = (p.V[a0] - p.V[b1]).length d1 = (p.V[a1] - p.V[b0]).length if d0 <= d1: p.f((a0, a1, b1), m) p.f((a0, b1, b0), m) else: p.f((a0, a1, b0), m) p.f((a1, b1, b0), m) def cap(ring, m): """End cap as columns between the top chain (T..G0) and the bottom chain (B0..W2), plus a fan over each side corner (G0 S N.. C1 W2): no centre vertex, so smooth shading stays clean.""" for sgn in (1, -1): r = lambda j: ring[ri(j, sgn)] for top, bot in (((13, 12), (0, 1)), ((12, 11), (1, 2)), ((11, 10), (2, 3))): p.f((r(top[0]), r(top[1]), r(bot[1]), r(bot[0])), m) for j in range(10, 4, -1): p.f((r(3), r(j), r(j - 1)), m) cap(rings[0][1], PAINT) # tail: body-colour lip round a recessed panel; a black band carries the lamps rl = rings[-1][1] cz = sum(p.V[i].z for i in rl) / len(rl) zs = [p.V[i].z for i in rl] ymax = max(p.V[i].y for i in rl) sy, sz = (ymax - 0.045) / ymax, (max(zs) - min(zs) - 0.09) / (max(zs) - min(zs)) inner = [] for i in rl: q = p.V[i] inner.append(p.v((q.x + 0.035, q.y * sy, cz + (q.z - cz) * sz), (p.UV[i][0] + 0.008, p.UV[i][1]))) n = len(rl) for k in range(n): p.f((rl[k], rl[(k + 1) % n], inner[(k + 1) % n], inner[k]), PAINT) cap(inner, PAINT) panel_x = XT + 0.035 p.box((panel_x - 0.022, -0.86, 0.555), (panel_x + 0.03, 0.86, 0.785), BLACK) for sgn in (1, -1): # front lamps: wide slots under the leading edge, wrapping the chamfered corners # (split at y=0.55, where nose_x's corner chamfer starts, so no lamp face cuts through the kink) ys, zs2 = (0.30, 0.47, 0.55, 0.64), (0.385, 0.455) nl = len(ys) pts = [] for z in zs2: for y in ys: pts.append((nose_x(y, z) + 0.008, sgn * y, z)) for a in range(nl - 1): b = a + 1 lo = [Vector(pts[a]), Vector(pts[b]), Vector(pts[b + nl]), Vector(pts[a + nl])] back = [q - Vector((0.05, 0, 0)) for q in lo] p.box8(back + lo, LAMP) if sgn > 0 else p.box8(back[::-1] + lo[::-1], LAMP) # tail lamps: a pair of blocks each side, standing proud of the black band for y0, y1 in ((0.50, 0.66), (0.68, 0.84)): p.box((panel_x - 0.034, sgn * y0, 0.615), (panel_x, sgn * y1, 0.725), TAIL) # mirrors: a stalk off the door top and a small wedge head p.beam((0.70, sgn * 0.86, 0.815), (0.665, sgn * 0.94, 0.87), 0.025, 0.02, PAINT) p.box((0.635, sgn * 0.925, 0.85), (0.695, sgn * 1.025, 0.91), PAINT) # exhausts: two pipes each side of centre under the tail panel for y in (0.09, 0.19): p.tube_x(panel_x + 0.05, XT - 0.045, sgn * y, 0.33, 0.034, 8, BLACK, BLACK) # louvres: body-colour slats across the black deck panel for j in range(7): x = LV1 - 0.05 - j * 0.09 zt = interp(LINES["T"], x)[1] p.box((x - 0.012, -0.47, zt - 0.02), (x + 0.012, 0.47, zt + 0.022), PAINT) return p def build_wheel(): p = Part("wheel") n = 16 # profile (r, y) from the back centre round the tyre to the front centre; y + is the outer face prof = [(0.0, -0.06), (0.19, -0.10), (0.29, -0.11), (R_TYRE, -0.09), (R_TYRE, 0.09), (0.29, 0.11), (0.195, 0.10), (0.165, 0.07), (0.05, 0.075), (0.0, 0.085)] band_m = [2, 0, 0, 0, 0, 0, 1, 1, 1] # wheel faces: 0 tyre, 1 rim, 2 dark rings = [] for j, (r, y) in enumerate(prof): if r == 0: rings.append([p.v((0, y, 0), (0.5, 0.5))] * n) continue rings.append([p.v((r * math.cos(2 * math.pi * k / n), y, r * math.sin(2 * math.pi * k / n)), (0.5 + 0.5 * r / R_TYRE * math.cos(2 * math.pi * k / n), 0.5 + 0.5 * r / R_TYRE * math.sin(2 * math.pi * k / n))) for k in range(n)]) for j in range(len(prof) - 1): a, b = rings[j], rings[j + 1] for k in range(n): k1 = (k + 1) % n q = [a[k], a[k1], b[k1], b[k]] q = [v for i_, v in enumerate(q) if v not in q[:i_]] p.f(q, band_m[j]) # telephone-dial holes: five dark discs just proud of the dish for h in range(5): a = 2 * math.pi * h / 5 + math.pi / 2 cx, cz = 0.108 * math.cos(a), 0.108 * math.sin(a) disc = [p.v((cx + 0.036 * math.cos(2 * math.pi * k / 8), 0.0795, cz + 0.036 * math.sin(2 * math.pi * k / 8))) for k in range(8)] p.f(disc, 2) # oriented to face +y in to_object return p # ------------------------------------------------------------------ blender objects def srgb_lin(c): return tuple(((v + 0.055) / 1.055) ** 2.4 if v > 0.04045 else v / 12.92 for v in c) def hexc(h): h = h.lstrip("#") return tuple(int(h[i:i + 2], 16) / 255 for i in (0, 2, 4)) def material(name, hexcol, rough=0.5, metal=0.0, emit=0.0): m = bpy.data.materials.new(name) m.use_nodes = True b = m.node_tree.nodes["Principled BSDF"] b.inputs["Base Color"].default_value = (*srgb_lin(hexc(hexcol)), 1) b.inputs["Roughness"].default_value = rough b.inputs["Metallic"].default_value = metal if emit: b.inputs["Emission Color"].default_value = (*srgb_lin(hexc(hexcol)), 1) b.inputs["Emission Strength"].default_value = emit return m PAINTS = {"red": "#c8100c", "white": "#ece9e0", "yellow": "#f0c010", "green": "#2f7a3a"} for o in list(bpy.data.objects): bpy.data.objects.remove(o) BODY_MATS = [material("0_paint", PAINTS.get(COLOR, COLOR), 0.25), material("1_glass", "#1b2026", 0.08), material("2_trim", "#161616", 0.7), material("3_lamp", "#f2e6c8", 0.2, emit=0.4), material("4_tail", "#b0140c", 0.2, emit=0.3)] WHEEL_MATS = [material("0_tyre", "#1c1c1c", 0.85), material("1_rim", "#b8b8b4", 0.3, 0.8), material("2_rim_dark", "#2a2a2a", 0.6)] def to_object(part, mats, sharp_deg): me = bpy.data.meshes.new(part.name) me.from_pydata([tuple(v) for v in part.V], [], part.F) me.update() me.polygons.foreach_set("material_index", part.M) uv = me.uv_layers.new(name="UVMap") for loop in me.loops: uv.data[loop.index].uv = part.UV[loop.vertex_index] for m in mats: me.materials.append(m) import bmesh bm = bmesh.new() bm.from_mesh(me) bmesh.ops.recalc_face_normals(bm, faces=bm.faces) if part.name == "wheel": # open discs: recalc can't orient them; they face the outer side (+y) for f in bm.faces: if len(f.verts) == 8 and f.normal.y < 0: f.normal_flip() bm.to_mesh(me) bm.free() me.shade_smooth() me.set_sharp_from_angle(angle=math.radians(sharp_deg)) me.update() ob = bpy.data.objects.new(part.name, me) bpy.context.scene.collection.objects.link(ob) return ob def signed_volume(ob): me = ob.data v = 0.0 for poly in me.polygons: ps = [me.vertices[i].co for i in poly.vertices] for k in range(1, len(ps) - 1): v += ps[0].dot(ps[k].cross(ps[k + 1])) / 6 return v def bbox(ob): xs = [v.co for v in ob.data.vertices] lo = Vector((min(c.x for c in xs), min(c.y for c in xs), min(c.z for c in xs))) hi = Vector((max(c.x for c in xs), max(c.y for c in xs), max(c.z for c in xs))) return lo, hi def export(ob, path, centre): me = ob.data.copy() me.transform(Matrix.Scale(SCALE, 4) @ Matrix.Translation(-centre)) tmp = bpy.data.objects.new(ob.name + "_x", me) bpy.context.scene.collection.objects.link(tmp) for o in bpy.context.scene.objects: o.select_set(o == tmp) bpy.context.view_layer.objects.active = tmp bpy.ops.export_scene.gltf(filepath=path, export_format="GLB", use_selection=True, export_yup=False, export_apply=True) bpy.data.objects.remove(tmp) bpy.data.meshes.remove(me) body_p, wheel_p = build_body(), build_wheel() body = to_object(body_p, BODY_MATS, 28) wheel = to_object(wheel_p, WHEEL_MATS, 40) blo, bhi = bbox(body) bc = (blo + bhi) / 2 os.makedirs(OUT, exist_ok=True) export(body, os.path.join(OUT, "body.glb"), bc) export(wheel, os.path.join(OUT, "wheel.glb"), Vector((0, 0, 0))) counts = [0] * 5 for f, m in zip(body_p.F, body_p.M): counts[m] += len(f) - 2 print(f"body tris {body_p.tris()} (paint {counts[0]}, glass {counts[1]}, trim {counts[2]}, lamps {counts[3]}, " f"tail {counts[4]}), verts {len(body_p.V)}, stations {len(stations())}, volume {signed_volume(body):.3f}") print(f"wheel tris {wheel_p.tris()}") size = bhi - blo print(f"body bbox real {size.x:.3f} x {size.y:.3f} x {size.z:.3f}; centre {tuple(round(c, 3) for c in bc)}") print(f"export scale {SCALE}: body {size.x * SCALE:.3f} x {size.y * SCALE:.3f} x {size.z * SCALE:.3f}, " f"wheel dia {2 * R_TYRE * SCALE:.4f} width {W_TYRE * SCALE:.4f} (rear x{REAR_WIDE} in Y)") WHEELS = {"FL": (FA, TF / 2), "FR": (FA, -TF / 2), "RL": (RA, TR / 2), "RR": (RA, -TR / 2)} for k, (x, y) in WHEELS.items(): o = (Vector((x, y, R_TYRE)) - bc) * SCALE print(f" wheel {k}: <{o.x:.4f}, {o.y:.4f}, {o.z:.4f}>") if not RENDER: sys.exit(0) # ------------------------------------------------------------------ previews scene = bpy.context.scene scene.render.engine = "BLENDER_EEVEE" scene.eevee.taa_render_samples = 24 scene.view_settings.view_transform = "Standard" scene.world = bpy.data.worlds.new("w") scene.world.use_nodes = True scene.world.node_tree.nodes["Background"].inputs["Color"].default_value = (*srgb_lin(hexc("#b4c2d0")), 1) scene.world.node_tree.nodes["Background"].inputs["Strength"].default_value = 0.8 bpy.ops.mesh.primitive_plane_add(size=60, location=(0, 0, 0)) bpy.context.active_object.data.materials.append(material("ground", "#8e8c86", 0.9)) sun = bpy.data.objects.new("sun", bpy.data.lights.new("sun", "SUN")) sun.data.energy = 3.0 sun.data.angle = math.radians(4) sun.rotation_euler = Euler((math.radians(40), 0, math.radians(-35))) scene.collection.objects.link(sun) fill = bpy.data.objects.new("fill", bpy.data.lights.new("fill", "SUN")) fill.data.energy = 0.8 fill.rotation_euler = Euler((math.radians(65), 0, math.radians(150))) scene.collection.objects.link(fill) for k, (x, y) in WHEELS.items(): w = bpy.data.objects.new("w" + k, wheel.data) w.location = (x, y, R_TYRE) w.rotation_euler = (0, 0, 0 if y > 0 else math.pi) w.scale = (1, REAR_WIDE if k[0] == "R" else 1, 1) scene.collection.objects.link(w) wheel.hide_render = True def shot(fname, target, az, el, dist, lens=50, res=(960, 600), ortho=None): scene.render.resolution_x, scene.render.resolution_y = res cam = bpy.data.objects.new("cam", bpy.data.cameras.new("cam")) scene.collection.objects.link(cam) cam.data.lens = lens if ortho: cam.data.type = "ORTHO" cam.data.ortho_scale = ortho t = Vector(target) d = Vector((math.cos(math.radians(el)) * math.cos(math.radians(az)), math.cos(math.radians(el)) * math.sin(math.radians(az)), math.sin(math.radians(el)))) cam.location = t + d * dist cam.rotation_euler = (-d).to_track_quat("-Z", "Y").to_euler() scene.camera = cam scene.render.filepath = os.path.join(OUT, fname) bpy.ops.render.render(write_still=True) bpy.data.objects.remove(cam) print("rendered", fname) shot("preview_front.png", (0.15, 0, 0.5), 35, 14, 9.5, lens=55) shot("preview_rear.png", (-0.1, 0, 0.5), 215, 16, 9.5, lens=55) if CHECKS: shot("check_side.png", (0.135, 0, 0.55), 90, 0, 10, res=(1000, 360), ortho=4.6) shot("check_top.png", (0.135, 0, 0.5), 90, 89.9, 10, res=(1000, 500), ortho=4.6) shot("check_front.png", (0, 0, 0.55), 0, 0, 10, res=(700, 420), ortho=2.3) shot("check_rear.png", (0, 0, 0.55), 180, 0, 10, res=(700, 420), ortho=2.3)