480 lines
20 KiB
Python
480 lines
20 KiB
Python
# tools/blender/build_enemies.py
|
|
# FBC: NIGHT SHIFT - low-poly actor library.
|
|
#
|
|
# Run inside Blender 5.x:
|
|
# exec(open("/home/dandovlatov/Documents/cntrl/tools/blender/build_enemies.py").read())
|
|
#
|
|
# Builds five game-ready actors (guard, hiss staff, mold spore, hiss brute,
|
|
# resonance shard), exports each as a GLB with its origin at the feet and facing
|
|
# -Y (glTF Y-up turns that into +Z, the game camera direction), saves the source
|
|
# .blend and renders a lineup sheet. No external assets.
|
|
|
|
import math
|
|
import os
|
|
|
|
import bpy
|
|
import mathutils
|
|
|
|
REPO = "/home/dandovlatov/Documents/cntrl"
|
|
MODEL_DIR = os.path.join(REPO, "assets", "models")
|
|
BLEND_DIR = os.path.join(REPO, "assets", "blender")
|
|
CONCEPT_DIR = os.path.join(REPO, "docs", "concept")
|
|
for d in (MODEL_DIR, BLEND_DIR, CONCEPT_DIR):
|
|
os.makedirs(d, exist_ok=True)
|
|
|
|
# --------------------------------------------------------------- scene reset
|
|
bpy.ops.object.select_all(action="SELECT")
|
|
bpy.ops.object.delete(use_global=False)
|
|
for datablocks in (bpy.data.meshes, bpy.data.materials, bpy.data.curves,
|
|
bpy.data.cameras, bpy.data.lights, bpy.data.collections):
|
|
for block in list(datablocks):
|
|
if block.users == 0:
|
|
datablocks.remove(block)
|
|
|
|
|
|
# ------------------------------------------------------------------ palette
|
|
def srgb_to_linear(c):
|
|
return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4
|
|
|
|
|
|
def rgb(hexstr):
|
|
h = hexstr.lstrip("#")
|
|
return tuple(srgb_to_linear(int(h[i:i + 2], 16) / 255.0) for i in (0, 2, 4))
|
|
|
|
|
|
P = {
|
|
"concrete": "#2b2b2f", "paper": "#e8e4d8", "redaction": "#26272c",
|
|
"hiss": "#c1121f", "hiss_hot": "#ff3b46", "board": "#f5c518",
|
|
"teal": "#4ec9b0", "navy": "#3b4a5e", "navy_lt": "#5c7086",
|
|
"tan": "#c8b99b", "skin": "#e0cdb0", "steel": "#8a96a1",
|
|
"mold": "#7fae55", "mold_dk": "#527a38", "mold_glow": "#a6e86e",
|
|
}
|
|
|
|
|
|
def material(name, color, rough=0.7, metal=0.0, emit=None, emit_strength=0.0):
|
|
m = bpy.data.materials.new(name)
|
|
m.use_nodes = True
|
|
b = next(n for n in m.node_tree.nodes if n.type == "BSDF_PRINCIPLED")
|
|
b.inputs["Base Color"].default_value = (*rgb(P.get(color, color)), 1.0)
|
|
b.inputs["Roughness"].default_value = rough
|
|
b.inputs["Metallic"].default_value = metal
|
|
if emit is not None:
|
|
b.inputs["Emission Color"].default_value = (*rgb(P.get(emit, emit)), 1.0)
|
|
b.inputs["Emission Strength"].default_value = emit_strength
|
|
return m
|
|
|
|
|
|
M = {
|
|
"concrete": material("concrete", "concrete", 0.92),
|
|
"paper": material("paper", "paper", 0.85),
|
|
"redaction": material("redaction", "redaction", 0.6),
|
|
"navy": material("navy", "navy", 0.82),
|
|
"navy_lt": material("navy_lt", "navy_lt", 0.78),
|
|
"tan": material("tan", "tan", 0.9),
|
|
"skin": material("skin", "skin", 0.88),
|
|
"steel": material("steel", "steel", 0.38, 0.55),
|
|
"hiss": material("hiss", "hiss", 0.45, 0.15, "hiss_hot", 1.6),
|
|
"hiss_dull": material("hiss_dull", "hiss", 0.85),
|
|
"hiss_hot": material("hiss_hot", "hiss_hot", 0.3, 0.0, "hiss_hot", 2.4),
|
|
"board": material("board", "board", 0.35, 0.1, "board", 1.6),
|
|
"teal": material("teal", "teal", 0.4, 0.0, "teal", 1.4),
|
|
"mold": material("mold", "mold", 0.95),
|
|
"mold_dk": material("mold_dk", "mold_dk", 0.98),
|
|
"mold_glow": material("mold_glow", "mold_glow", 0.5, 0.0, "mold_glow", 1.8),
|
|
"actor": material("actor", "#ffffff", 0.8),
|
|
}
|
|
|
|
# The exporter only writes COLOR_0 when the node graph actually uses it.
|
|
actor_nodes = M["actor"].node_tree
|
|
attr_node = actor_nodes.nodes.new("ShaderNodeAttribute")
|
|
attr_node.attribute_name = "Color"
|
|
actor_nodes.links.new(attr_node.outputs["Color"],
|
|
next(n for n in actor_nodes.nodes
|
|
if n.type == "BSDF_PRINCIPLED").inputs["Base Color"])
|
|
|
|
|
|
# ------------------------------------------------------------------ geometry
|
|
def part(root, name, shape, loc, scale, mat, rot=(0.0, 0.0, 0.0),
|
|
bevel=0.012, verts=6):
|
|
"""One low-poly primitive, rooted under `root`, with a chamfered silhouette."""
|
|
if shape == "box":
|
|
bpy.ops.mesh.primitive_cube_add(size=1.0, location=loc)
|
|
elif shape == "ico":
|
|
bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=1, radius=0.5,
|
|
location=loc)
|
|
elif shape == "oct":
|
|
bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=0, radius=0.5,
|
|
location=loc)
|
|
elif shape == "cone":
|
|
bpy.ops.mesh.primitive_cone_add(vertices=verts, radius1=0.5,
|
|
radius2=0.0, depth=1.0, location=loc)
|
|
elif shape == "cyl":
|
|
bpy.ops.mesh.primitive_cylinder_add(vertices=verts, radius=0.5,
|
|
depth=1.0, location=loc)
|
|
elif shape == "torus":
|
|
bpy.ops.mesh.primitive_torus_add(major_segments=12, minor_segments=4,
|
|
major_radius=0.5, minor_radius=0.06,
|
|
location=loc)
|
|
else:
|
|
raise ValueError(shape)
|
|
|
|
obj = bpy.context.object
|
|
obj.name = name
|
|
obj.scale = scale
|
|
obj.rotation_euler = rot
|
|
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
|
|
if bevel > 0.0 and min(scale) > 0.05 and shape in ("box", "cyl"):
|
|
mod = obj.modifiers.new("Chamfer", "BEVEL")
|
|
mod.width = bevel
|
|
mod.segments = 1
|
|
mod.limit_method = "ANGLE"
|
|
try:
|
|
bpy.ops.object.modifier_apply(modifier=mod.name)
|
|
except Exception:
|
|
pass
|
|
# Bake the palette into COLOR_0 so the whole actor can share one material:
|
|
# raylib then draws it in a single call instead of one call per part.
|
|
src = M[mat] if isinstance(mat, str) else mat
|
|
linear = next(n for n in src.node_tree.nodes
|
|
if n.type == "BSDF_PRINCIPLED").inputs["Base Color"].default_value
|
|
attr = obj.data.color_attributes.new(name="Color", type="FLOAT_COLOR",
|
|
domain="POINT")
|
|
for i in range(len(obj.data.vertices)):
|
|
attr.data[i].color = (linear[0], linear[1], linear[2], 1.0)
|
|
obj.data.materials.append(M["actor"])
|
|
for poly in obj.data.polygons:
|
|
poly.use_smooth = False
|
|
obj.parent = root
|
|
return obj
|
|
|
|
|
|
def merge_actor(root, name):
|
|
"""Collapse all parts into one mesh so the GLB has a single primitive."""
|
|
meshes = [o for o in root.children if o.type == "MESH"]
|
|
if len(meshes) < 2:
|
|
return
|
|
bpy.ops.object.select_all(action="DESELECT")
|
|
for o in meshes:
|
|
o.select_set(True)
|
|
bpy.context.view_layer.objects.active = meshes[0]
|
|
bpy.ops.object.join()
|
|
joined = bpy.context.object
|
|
joined.name = name + "_mesh"
|
|
joined.parent = root
|
|
|
|
|
|
def root_for(name):
|
|
root = bpy.data.objects.new(name, None)
|
|
bpy.context.scene.collection.objects.link(root)
|
|
return root
|
|
|
|
|
|
def base(root, radius, mat="redaction", glow=None):
|
|
part(root, "base", "cyl", (0, 0, 0.035), (radius, radius, 0.07), mat,
|
|
bevel=0.01, verts=12)
|
|
if glow is not None:
|
|
part(root, "base_glow", "torus", (0, 0, 0.075),
|
|
(radius * 1.85, radius * 1.85, radius * 1.85), glow,
|
|
rot=(0, 0, 0), bevel=0)
|
|
|
|
|
|
# ------------------------------------------------------------------- actors
|
|
def build_guard():
|
|
r = root_for("Guard")
|
|
for side in (-1, 1):
|
|
x = side * 0.17
|
|
part(r, "leg_%d" % side, "box", (x, 0, 0.44), (0.22, 0.26, 0.86), "navy")
|
|
part(r, "boot_%d" % side, "box", (x, -0.05, 0.09), (0.27, 0.38, 0.18),
|
|
"redaction")
|
|
part(r, "knee_%d" % side, "box", (x, -0.14, 0.5), (0.2, 0.05, 0.16),
|
|
"steel")
|
|
part(r, "torso", "box", (0, 0, 1.16), (0.66, 0.38, 0.72), "navy_lt")
|
|
part(r, "vest", "box", (0, -0.19, 1.16), (0.54, 0.07, 0.6), "navy")
|
|
part(r, "belt", "box", (0, 0, 0.83), (0.7, 0.42, 0.1), "redaction")
|
|
for side in (-1, 1):
|
|
part(r, "pouch_%d" % side, "box", (side * 0.25, -0.13, 0.83),
|
|
(0.16, 0.14, 0.14), "tan")
|
|
part(r, "collar_%d" % side, "box", (side * 0.11, -0.2, 1.46),
|
|
(0.19, 0.05, 0.14), "paper", rot=(0, 0, side * 0.25))
|
|
part(r, "arm_%d" % side, "box", (side * 0.44, 0, 1.16),
|
|
(0.2, 0.26, 0.62), "tan")
|
|
part(r, "hand_%d" % side, "ico", (side * 0.45, -0.02, 0.82),
|
|
(0.17, 0.18, 0.2), "skin")
|
|
part(r, "badge", "box", (0.17, -0.235, 1.3), (0.19, 0.02, 0.14), "paper")
|
|
part(r, "badge_bar", "box", (0.17, -0.247, 1.31), (0.14, 0.01, 0.04), "hiss_dull")
|
|
part(r, "security_strip", "box", (0, -0.235, 1.45), (0.4, 0.02, 0.06), "board")
|
|
part(r, "head", "ico", (0, 0, 1.68), (0.35, 0.33, 0.38), "skin")
|
|
part(r, "cap", "box", (0, 0, 1.86), (0.4, 0.38, 0.14), "navy")
|
|
part(r, "brim", "box", (0, -0.25, 1.82), (0.4, 0.26, 0.045), "redaction")
|
|
for side in (-1, 1):
|
|
part(r, "eye_%d" % side, "box", (side * 0.08, -0.17, 1.68),
|
|
(0.05, 0.02, 0.025), "redaction", bevel=0)
|
|
part(r, "radio", "box", (0.31, 0.11, 1.44), (0.12, 0.12, 0.18), "redaction")
|
|
part(r, "antenna", "cyl", (0.31, 0.11, 1.62), (0.018, 0.018, 0.22), "steel",
|
|
bevel=0, verts=6)
|
|
part(r, "service_weapon", "box", (0.49, -0.16, 0.88), (0.1, 0.3, 0.1),
|
|
"redaction", rot=(0.35, 0, 0))
|
|
part(r, "muzzle", "cyl", (0.49, -0.33, 0.94), (0.035, 0.035, 0.12), "steel",
|
|
rot=(math.pi / 2, 0, 0), bevel=0, verts=6)
|
|
base(r, 0.52, "redaction", "board")
|
|
return r
|
|
|
|
|
|
def build_hiss_staff():
|
|
r = root_for("HissStaff")
|
|
part(r, "shroud", "cone", (0, 0, 0.62), (0.92, 0.8, 1.25), "navy",
|
|
rot=(math.pi, 0, 0), verts=8, bevel=0)
|
|
part(r, "torso", "box", (0, 0, 1.22), (0.64, 0.4, 0.68), "navy_lt")
|
|
part(r, "coat_l", "box", (-0.2, 0.02, 0.7), (0.22, 0.34, 0.7), "navy",
|
|
rot=(0, 0, -0.12))
|
|
part(r, "coat_r", "box", (0.2, 0.02, 0.7), (0.22, 0.34, 0.7), "navy",
|
|
rot=(0, 0, 0.12))
|
|
for side in (-1, 1):
|
|
part(r, "lapel_%d" % side, "box", (side * 0.13, -0.225, 1.41),
|
|
(0.18, 0.05, 0.32), "paper", rot=(0, 0, side * 0.32))
|
|
part(r, "shoulder_%d" % side, "box", (side * 0.42, 0, 1.48),
|
|
(0.22, 0.42, 0.16), "redaction")
|
|
part(r, "tie", "box", (0, -0.235, 1.2), (0.09, 0.03, 0.36), "hiss_dull")
|
|
part(r, "badge", "box", (0.18, -0.235, 1.34), (0.17, 0.02, 0.12), "paper")
|
|
part(r, "badge_bar", "box", (0.18, -0.248, 1.35), (0.12, 0.01, 0.035),
|
|
"hiss_dull")
|
|
# Left arm hangs, right arm reaches toward the camera with a Hiss growth.
|
|
part(r, "arm_l", "box", (-0.44, 0, 1.12), (0.18, 0.24, 0.6), "navy_lt")
|
|
part(r, "hand_l", "ico", (-0.45, -0.02, 0.79), (0.16, 0.18, 0.19), "skin")
|
|
part(r, "arm_r_upper", "box", (0.44, -0.18, 1.32), (0.17, 0.44, 0.18),
|
|
"navy_lt", rot=(-0.75, 0, 0))
|
|
part(r, "arm_r_fore", "box", (0.46, -0.52, 1.15), (0.15, 0.42, 0.16),
|
|
"navy_lt", rot=(-0.15, 0, 0))
|
|
part(r, "hand_r", "ico", (0.46, -0.75, 1.1), (0.18, 0.2, 0.2), "skin")
|
|
for i in range(4):
|
|
a = 2.0 * math.pi * i / 4
|
|
part(r, "clang_%d" % i, "cone",
|
|
(0.46 + math.cos(a) * 0.12, -0.85, 1.1 + math.sin(a) * 0.12),
|
|
(0.09, 0.09, 0.34), "hiss",
|
|
rot=(math.pi / 2 + math.sin(a) * 0.5, 0, math.cos(a) * 0.5),
|
|
bevel=0, verts=5)
|
|
part(r, "head", "ico", (0, 0, 1.7), (0.33, 0.31, 0.36), "skin")
|
|
part(r, "hair", "box", (0, 0.04, 1.85), (0.36, 0.32, 0.12), "redaction")
|
|
part(r, "eye_hot", "box", (-0.09, -0.16, 1.71), (0.07, 0.035, 0.07),
|
|
"hiss_hot", bevel=0)
|
|
part(r, "eye_dead", "box", (0.09, -0.16, 1.71), (0.07, 0.03, 0.045),
|
|
"redaction", bevel=0)
|
|
part(r, "jaw", "box", (0, -0.12, 1.53), (0.22, 0.2, 0.1), "redaction")
|
|
# Red resonance cracks crawling up the torso and shroud.
|
|
for i, (x, y, z, ang) in enumerate([
|
|
(-0.28, -0.05, 0.55, 0.5), (0.25, -0.1, 0.78, -0.4),
|
|
(-0.1, -0.22, 1.05, 0.8), (0.2, -0.22, 1.35, -0.7),
|
|
]):
|
|
part(r, "crack_%d" % i, "box", (x, y, z), (0.035, 0.03, 0.34), "hiss",
|
|
rot=(0, 0, ang), bevel=0)
|
|
base(r, 0.56, "redaction", "hiss_dull")
|
|
return r
|
|
|
|
|
|
def build_mold_spore():
|
|
r = root_for("MoldSpore")
|
|
part(r, "core", "ico", (0, 0, 0.45), (0.94, 0.86, 0.66), "mold_dk")
|
|
lobes = [
|
|
(-0.36, 0.1, 0.38, 0.55), (0.38, -0.05, 0.36, 0.5),
|
|
(0.05, 0.36, 0.42, 0.48), (-0.08, -0.4, 0.3, 0.44),
|
|
(0.42, 0.32, 0.5, 0.36), (-0.45, -0.3, 0.55, 0.3),
|
|
]
|
|
for i, (x, y, z, s) in enumerate(lobes):
|
|
part(r, "lobe_%d" % i, "ico", (x, y, z), (s, s * 0.9, s * 0.8), "mold")
|
|
for i, (x, y, z, s) in enumerate([
|
|
(-0.25, -0.1, 0.78, 0.24), (0.22, 0.08, 0.83, 0.28),
|
|
(0.0, -0.28, 0.74, 0.2), (0.4, -0.22, 0.66, 0.18),
|
|
]):
|
|
part(r, "sac_%d" % i, "ico", (x, y, z), (s, s, s * 0.8), "mold_glow")
|
|
part(r, "pustule_%d" % i, "oct", (x, y, z + s * 0.6),
|
|
(s * 0.5, s * 0.5, s * 0.5), "mold_glow", bevel=0)
|
|
for i in range(6):
|
|
a = 2.0 * math.pi * i / 6 + 0.2
|
|
part(r, "tendril_%d" % i, "cone",
|
|
(math.cos(a) * 0.52, math.sin(a) * 0.52, 0.16),
|
|
(0.16, 0.16, 0.55), "mold_dk",
|
|
rot=(math.sin(a) * 1.25, -math.cos(a) * 1.25, 0), bevel=0,
|
|
verts=5)
|
|
for i in range(3):
|
|
a = 2.0 * math.pi * i / 3 + 0.6
|
|
x, y = math.cos(a) * 0.3, math.sin(a) * 0.3
|
|
part(r, "stalk_%d" % i, "cyl", (x, y, 0.85), (0.08, 0.08, 0.42),
|
|
"mold_dk", bevel=0, verts=6)
|
|
part(r, "cap_%d" % i, "cone", (x, y, 1.09), (0.26, 0.26, 0.18),
|
|
"mold_glow", bevel=0, verts=7)
|
|
for i in range(4):
|
|
a = 2.0 * math.pi * i / 4 + 0.4
|
|
part(r, "spore_%d" % i, "oct",
|
|
(math.cos(a) * 0.55, math.sin(a) * 0.55, 1.3 + (i % 2) * 0.24),
|
|
(0.1, 0.1, 0.14), "mold_glow", bevel=0)
|
|
base(r, 0.62, "mold_dk", "mold_glow")
|
|
return r
|
|
|
|
|
|
def build_hiss_brute():
|
|
r = root_for("HissBrute")
|
|
for side in (-1, 1):
|
|
x = side * 0.4
|
|
part(r, "leg_%d" % side, "box", (x, 0, 0.54), (0.46, 0.54, 1.08),
|
|
"redaction")
|
|
part(r, "greave_%d" % side, "box", (x, -0.04, 0.45), (0.48, 0.56, 0.5),
|
|
"steel")
|
|
part(r, "foot_%d" % side, "box", (x, -0.16, 0.1), (0.52, 0.72, 0.2),
|
|
"redaction")
|
|
part(r, "torso", "box", (0, 0, 1.7), (1.5, 0.86, 1.3), "navy")
|
|
part(r, "pec_l", "box", (-0.38, -0.45, 1.92), (0.62, 0.12, 0.5), "steel",
|
|
rot=(0, 0, -0.15))
|
|
part(r, "pec_r", "box", (0.38, -0.45, 1.92), (0.62, 0.12, 0.5), "steel",
|
|
rot=(0, 0, 0.15))
|
|
part(r, "core", "oct", (0, -0.48, 1.7), (0.38, 0.2, 0.4), "hiss_hot",
|
|
bevel=0)
|
|
part(r, "core_ring", "torus", (0, -0.5, 1.7), (1.0, 1.0, 1.0), "hiss",
|
|
bevel=0)
|
|
for side in (-1, 1):
|
|
part(r, "pauldron_%d" % side, "box", (side * 0.9, 0.02, 2.1),
|
|
(0.6, 0.78, 0.52), "steel", rot=(0, 0, side * 0.18))
|
|
part(r, "pauldron_band_%d" % side, "box", (side * 0.92, -0.02, 2.26),
|
|
(0.62, 0.8, 0.1), "hiss_dull")
|
|
part(r, "upperarm_%d" % side, "box", (side * 1.02, -0.04, 1.62),
|
|
(0.44, 0.5, 0.82), "redaction")
|
|
part(r, "forearm_%d" % side, "box", (side * 1.08, -0.16, 0.98),
|
|
(0.48, 0.56, 0.76), "steel")
|
|
part(r, "fist_%d" % side, "ico", (side * 1.1, -0.22, 0.55),
|
|
(0.4, 0.42, 0.38), "redaction")
|
|
for i in range(4):
|
|
part(r, "gauntlet_%d" % i, "cone",
|
|
(1.08 + (i - 1.5) * 0.12, -0.48, 0.98 + (i % 2) * 0.16),
|
|
(0.1, 0.1, 0.4), "hiss", rot=(math.pi / 2, 0, 0), bevel=0,
|
|
verts=5)
|
|
part(r, "neck", "cyl", (0, 0, 2.38), (0.3, 0.3, 0.24), "redaction", bevel=0)
|
|
part(r, "head", "box", (0, -0.02, 2.56), (0.54, 0.54, 0.46), "redaction")
|
|
part(r, "visor", "box", (0, -0.29, 2.58), (0.46, 0.05, 0.11), "hiss_hot",
|
|
bevel=0)
|
|
part(r, "jaw_grille", "box", (0, -0.29, 2.41), (0.34, 0.05, 0.1), "steel",
|
|
bevel=0)
|
|
for i, (x, y, z, rx, ry) in enumerate([
|
|
(-0.6, 0.1, 2.35, 0.3, -0.6), (0.6, 0.12, 2.4, 0.2, 0.7),
|
|
(-0.3, 0.35, 2.7, -0.2, -0.3), (0.35, 0.38, 2.78, -0.3, 0.4),
|
|
(0.0, 0.45, 2.55, 0.1, 0.0),
|
|
]):
|
|
part(r, "spine_%d" % i, "cone", (x, y, z), (0.18, 0.18, 0.66), "hiss",
|
|
rot=(rx, ry, 0), bevel=0, verts=5)
|
|
base(r, 0.95, "redaction", "hiss_dull")
|
|
return r
|
|
|
|
|
|
def build_shard():
|
|
r = root_for("Shard")
|
|
part(r, "crystal", "oct", (0, 0, 0.34), (0.34, 0.34, 0.52), "board",
|
|
bevel=0)
|
|
part(r, "core", "oct", (0, 0, 0.34), (0.16, 0.16, 0.26), "paper", bevel=0)
|
|
part(r, "halo", "torus", (0, 0, 0.24), (0.62, 0.62, 0.62), "board",
|
|
bevel=0)
|
|
return r
|
|
|
|
|
|
# ------------------------------------------------------------------ exports
|
|
BUILDERS = [
|
|
("guard", build_guard),
|
|
("hiss_staff", build_hiss_staff),
|
|
("mold_spore", build_mold_spore),
|
|
("hiss_brute", build_hiss_brute),
|
|
("shard", build_shard),
|
|
]
|
|
|
|
exported = []
|
|
for name, builder in BUILDERS:
|
|
root = builder()
|
|
merge_actor(root, name)
|
|
bpy.ops.object.select_all(action="DESELECT")
|
|
root.select_set(True)
|
|
for child in root.children_recursive:
|
|
child.select_set(True)
|
|
bpy.context.view_layer.objects.active = root
|
|
out = os.path.join(MODEL_DIR, name + ".glb")
|
|
bpy.ops.export_scene.gltf(
|
|
filepath=out,
|
|
export_format="GLB",
|
|
use_selection=True,
|
|
export_apply=True,
|
|
export_yup=True,
|
|
export_materials="EXPORT",
|
|
export_cameras=False,
|
|
export_lights=False,
|
|
export_extras=False,
|
|
)
|
|
tris = sum(len(p.vertices) - 2 for o in root.children_recursive
|
|
if o.type == "MESH" for p in o.data.polygons)
|
|
exported.append((name, tris, os.path.getsize(out)))
|
|
print("[export] %-12s %4d tris %7d bytes -> %s" % (name, tris,
|
|
os.path.getsize(out), out))
|
|
|
|
|
|
# ------------------------------------------------------------ lineup render
|
|
SLOTS = {"Guard": -6.5, "HissStaff": -2.5, "MoldSpore": 1.3,
|
|
"HissBrute": 5.6, "Shard": 9.0}
|
|
for obj in bpy.data.objects:
|
|
if obj.name in SLOTS:
|
|
obj.location.x = SLOTS[obj.name]
|
|
if obj.name == "Shard":
|
|
obj.scale = (3.0, 3.0, 3.0)
|
|
|
|
world = bpy.data.worlds.new("ShowroomWorld") if not bpy.data.worlds else bpy.data.worlds[0]
|
|
bpy.context.scene.world = world
|
|
world.use_nodes = True
|
|
bg = next(n for n in world.node_tree.nodes if n.type == "BACKGROUND")
|
|
bg.inputs["Color"].default_value = (*rgb("#0d0f12"), 1.0)
|
|
bg.inputs["Strength"].default_value = 0.8
|
|
|
|
|
|
def area(name, loc, color, power, size):
|
|
data = bpy.data.lights.new(name, "AREA")
|
|
data.energy = power
|
|
data.shape = "DISK"
|
|
data.size = size
|
|
data.color = rgb(color)
|
|
obj = bpy.data.objects.new(name, data)
|
|
bpy.context.scene.collection.objects.link(obj)
|
|
obj.location = loc
|
|
direction = (0 - obj.location.x, 0 - obj.location.y, 1.2 - obj.location.z)
|
|
obj.rotation_euler = (0, 0, 0)
|
|
obj.rotation_euler = mathutils.Vector(direction).to_track_quat("-Z", "Y").to_euler()
|
|
return obj
|
|
|
|
|
|
area("Key", (-3, -7, 10), "#eef2ff", 2600, 8)
|
|
area("HissFill", (9, -2, 5), "#ff3b46", 1300, 6)
|
|
area("PolarisRim", (0, 7, 7), "#4ec9b0", 1500, 7)
|
|
|
|
cam_data = bpy.data.cameras.new("ActorCam")
|
|
cam = bpy.data.objects.new("ActorCam", cam_data)
|
|
bpy.context.scene.collection.objects.link(cam)
|
|
cam.location = (1.0, -19.0, 7.5)
|
|
cam.rotation_euler = mathutils.Vector((1.0 - 1.0, 0 - -19.0, 1.25 - 7.5)).to_track_quat("-Z", "Y").to_euler()
|
|
cam_data.lens = 40
|
|
bpy.context.scene.camera = cam
|
|
|
|
scene = bpy.context.scene
|
|
engines = [i.identifier for i in bpy.types.RenderSettings.bl_rna.properties["engine"].enum_items]
|
|
scene.render.engine = "BLENDER_EEVEE_NEXT" if "BLENDER_EEVEE_NEXT" in engines else engines[0]
|
|
scene.render.resolution_x = 1100
|
|
scene.render.resolution_y = 520
|
|
scene.render.resolution_percentage = 100
|
|
scene.render.image_settings.file_format = "PNG"
|
|
scene.render.filepath = os.path.join(CONCEPT_DIR, "enemy_lineup.png")
|
|
try:
|
|
scene.eevee.taa_render_samples = 64
|
|
except Exception:
|
|
pass
|
|
bpy.ops.render.render(write_still=True)
|
|
print("[render] lineup ->", scene.render.filepath)
|
|
|
|
scene.render.filepath = os.path.join(CONCEPT_DIR, "enemy_detail.png")
|
|
cam.location = (-0.6, -7.5, 3.4)
|
|
cam.rotation_euler = mathutils.Vector((0.0 - -0.6, 0 - -7.5, 1.2 - 3.4)).to_track_quat("-Z", "Y").to_euler()
|
|
cam_data.lens = 42
|
|
bpy.ops.render.render(write_still=True)
|
|
print("[render] detail ->", scene.render.filepath)
|
|
|
|
bpy.ops.wm.save_as_mainfile(filepath=os.path.join(BLEND_DIR, "fbc_enemies.blend"))
|
|
print("[done] actors:", ", ".join("%s(%d tris)" % (n, t) for n, t, _ in exported))
|