Files
aeternalis/tools/create-models.py
T

120 lines
4.0 KiB
Python

"""Rebuild original placeholder meshes: blender --background --python tools/create-models.py."""
import bpy
import math
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
OUT = ROOT / "client" / "public" / "models"
OUT.mkdir(parents=True, exist_ok=True)
def material(name, color, metallic=0):
mat = bpy.data.materials.new(name)
mat.diffuse_color = (*color, 1)
mat.use_nodes = True
node = mat.node_tree.nodes.get("Principled BSDF")
node.inputs["Base Color"].default_value = (*color, 1)
node.inputs["Roughness"].default_value = 0.85
node.inputs["Metallic"].default_value = metallic
return mat
pine = material("pine needles", (0.15, 0.34, 0.25))
tips = material("fresh needles", (0.28, 0.48, 0.3))
bark = material("bark", (0.24, 0.22, 0.2))
rock = material("stone", (0.42, 0.47, 0.48))
iron = material("iron", (0.23, 0.29, 0.3), 0.4)
cloth = material("traveler green", (0.24, 0.45, 0.41))
linen = material("linen", (0.73, 0.76, 0.71))
skin = material("skin", (0.7, 0.49, 0.34))
ember = material("ember", (0.88, 0.16, 0.16))
leaf = material("sage", (0.41, 0.64, 0.3))
flower = material("flowers", (0.89, 0.75, 0.29))
def clear():
bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete(use_global=False)
def cone(name, pos, radius, depth, mat, top=0, vertices=7):
bpy.ops.mesh.primitive_cone_add(vertices=vertices, radius1=radius, radius2=top, depth=depth, location=pos)
obj = bpy.context.object
obj.name = name
obj.data.materials.append(mat)
return obj
def cube(name, pos, scale, mat):
bpy.ops.mesh.primitive_cube_add(size=1, location=pos)
obj = bpy.context.object
obj.name = name
obj.scale = scale
obj.data.materials.append(mat)
bevel = obj.modifiers.new("worn edges", "BEVEL")
bevel.width = 0.09
bevel.segments = 1
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
return obj
def ico(name, pos, scale, mat):
bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=1, radius=1, location=pos)
obj = bpy.context.object
obj.name = name
obj.scale = scale
obj.data.materials.append(mat)
return obj
def export(name):
bpy.ops.export_scene.gltf(filepath=str(OUT / (name + ".glb")), export_format="GLB", export_yup=True)
clear()
cone("trunk", (0,0,3.7), 0.6, 7.4, bark, 0.22)
for z,r in [(5,3.8),(7.5,3),(9.5,2.2)]:
cone("canopy", (0,0,z), r, 5.2, pine if z<9 else tips)
export("tree")
clear()
ico("boulder", (0,0,1), (2.3,1.7,1.5), rock)
for x,y in [(-0.8,0.3),(0.6,-0.7),(1,0.6)]:
cone("iron vein", (x,y,1.7), 0.35, 1.8, iron, 0.1, 5)
export("ore")
clear()
for i in range(6):
a = i*math.tau/6
x,y = math.cos(a)*0.6,math.sin(a)*0.6
cone("stem",(x,y,0.6),0.09,1.2,leaf,0.04,5)
ico("leaf",(x,y,0.9),(0.6,0.3,0.2),leaf)
ico("flower",(x,y,1.4),(0.3,0.3,0.25),flower)
export("herb")
def humanoid(boss=False):
body_mat = iron if boss else cloth
cube("torso", (0,0,1.7), (0.9,0.5,1.1), body_mat)
cube("belt", (0,0,1.22), (1,0.6,0.2), bark)
ico("head", (0,0,2.55), (0.37,0.34,0.43), rock if boss else skin)
cone("hood", (0,0.05,2.83), 0.46, 0.5, body_mat, 0.18)
for sign in [-1,1]:
cube("leg", (sign*0.24,0,0.65), (0.32,0.34,1.2), iron if boss else linen)
cube("boot", (sign*0.24,-0.12,0.15), (0.37,0.58,0.3), bark)
cube("arm", (sign*0.64,0,1.67), (0.3,0.35,1), body_mat)
ico("hand", (sign*0.64,0,1.03), (0.18,0.18,0.2), rock if boss else skin)
if boss:
for sign in [-1,1]:
horn=cone("crown", (sign*0.4,0,3.2),0.2,1.2,ember,0,5)
horn.rotation_euler[1] = sign*0.4
cube("heart", (0,-0.28,1.9), (0.3,0.12,0.5),ember)
else:
cube("pack", (0,0.38,1.8), (0.72,0.4,0.85),bark)
cone("knife", (0.7,-0.05,0.75),0.13,0.6,iron,0,4)
clear()
humanoid()
export("player")
clear()
humanoid(True)
export("sentinel")
clear()
humanoid(True)
for obj in bpy.context.scene.objects:
obj.location *= 4
obj.scale *= 4
export("boss")
bpy.ops.wm.save_as_mainfile(filepath=str(ROOT / "assets" / "harbinger.blend"))