93 lines
3.2 KiB
Python
93 lines
3.2 KiB
Python
|
|
# Diagnose the inter-thigh residue below the crotch snap window.
|
||
|
|
# blender --background --python dbg_gusset.py -- <blend> <outdir>
|
||
|
|
import bpy, sys, math, os
|
||
|
|
import numpy as np
|
||
|
|
from mathutils import Vector, Euler
|
||
|
|
|
||
|
|
argv = sys.argv[sys.argv.index("--") + 1:]
|
||
|
|
BLEND, OUT = argv[0], argv[1]
|
||
|
|
os.makedirs(OUT, exist_ok=True)
|
||
|
|
|
||
|
|
bpy.ops.wm.open_mainfile(filepath=BLEND)
|
||
|
|
ob = max([o for o in bpy.data.objects if o.type == 'MESH'],
|
||
|
|
key=lambda o: len(o.data.vertices))
|
||
|
|
me = ob.data
|
||
|
|
n_v = len(me.vertices)
|
||
|
|
co = np.empty(n_v * 3)
|
||
|
|
me.vertices.foreach_get("co", co)
|
||
|
|
co = co.reshape(-1, 3)
|
||
|
|
|
||
|
|
# numeric: midline strip profile — for each z slice near the crotch, front-most and
|
||
|
|
# back-most y, and the x extent of geometry in the inter-thigh gap
|
||
|
|
print("== midline (|x|<0.01) y-range per z slice ==")
|
||
|
|
for z0 in np.arange(0.34, 0.50, 0.01):
|
||
|
|
m = (np.abs(co[:, 0]) < 0.01) & (co[:, 2] >= z0) & (co[:, 2] < z0 + 0.01)
|
||
|
|
if m.sum() == 0:
|
||
|
|
print(f" z {z0:.2f}: EMPTY")
|
||
|
|
continue
|
||
|
|
ys = co[m, 1]
|
||
|
|
print(f" z {z0:.2f}: n={m.sum():5d} y [{ys.min():+.4f} .. {ys.max():+.4f}]")
|
||
|
|
|
||
|
|
print("== inter-thigh occupancy: verts with |x|<0.06 per z slice ==")
|
||
|
|
for z0 in np.arange(0.30, 0.46, 0.01):
|
||
|
|
m = (np.abs(co[:, 0]) < 0.06) & (co[:, 2] >= z0) & (co[:, 2] < z0 + 0.01)
|
||
|
|
print(f" z {z0:.2f}: n={m.sum():5d}", end="")
|
||
|
|
if m.sum():
|
||
|
|
print(f" x [{co[m,0].min():+.4f}..{co[m,0].max():+.4f}]"
|
||
|
|
f" y [{co[m,1].min():+.4f}..{co[m,1].max():+.4f}]")
|
||
|
|
else:
|
||
|
|
print()
|
||
|
|
|
||
|
|
# renders: clay, shadowless, tight on the crotch — front, and from below looking up
|
||
|
|
for o in list(bpy.data.objects):
|
||
|
|
if o.type in ('LIGHT', 'CAMERA'):
|
||
|
|
bpy.data.objects.remove(o, do_unlink=True)
|
||
|
|
|
||
|
|
sc = bpy.context.scene
|
||
|
|
sc.render.engine = 'BLENDER_EEVEE'
|
||
|
|
sc.render.resolution_x = sc.render.resolution_y = 1000
|
||
|
|
sc.render.film_transparent = False
|
||
|
|
wd = bpy.data.worlds.new("w")
|
||
|
|
wd.use_nodes = True
|
||
|
|
wd.node_tree.nodes["Background"].inputs[0].default_value = (0.18, 0.18, 0.18, 1)
|
||
|
|
sc.world = wd
|
||
|
|
|
||
|
|
mat = bpy.data.materials.new("clay")
|
||
|
|
mat.use_nodes = True
|
||
|
|
b = mat.node_tree.nodes["Principled BSDF"]
|
||
|
|
b.inputs["Base Color"].default_value = (0.8, 0.8, 0.8, 1)
|
||
|
|
b.inputs["Roughness"].default_value = 0.6
|
||
|
|
ob.data.materials.clear()
|
||
|
|
ob.data.materials.append(mat)
|
||
|
|
|
||
|
|
def sun(rot, e):
|
||
|
|
ld = bpy.data.lights.new("s", 'SUN')
|
||
|
|
ld.energy = e
|
||
|
|
ld.use_shadow = False
|
||
|
|
lo = bpy.data.objects.new("s", ld)
|
||
|
|
lo.rotation_euler = rot
|
||
|
|
bpy.context.collection.objects.link(lo)
|
||
|
|
|
||
|
|
sun(Euler((math.radians(60), 0, math.radians(-30))), 3.0)
|
||
|
|
sun(Euler((math.radians(120), 0, math.radians(150))), 1.2)
|
||
|
|
|
||
|
|
cam = bpy.data.cameras.new("c")
|
||
|
|
cam.lens = 85
|
||
|
|
cob = bpy.data.objects.new("c", cam)
|
||
|
|
bpy.context.collection.objects.link(cob)
|
||
|
|
sc.camera = cob
|
||
|
|
|
||
|
|
views = [
|
||
|
|
# (name, location, rotation) — model front = -Y
|
||
|
|
("front_tight", Vector((0.0, -0.55, 0.41)), Euler((math.radians(90), 0, 0))),
|
||
|
|
("below_up", Vector((0.0, -0.30, 0.05)), Euler((math.radians(50), 0, 0))),
|
||
|
|
("side_gap", Vector((-0.45, -0.35, 0.40)), Euler((math.radians(88), 0, math.radians(-52)))),
|
||
|
|
]
|
||
|
|
for name, loc, rot in views:
|
||
|
|
cob.location = loc
|
||
|
|
cob.rotation_euler = rot
|
||
|
|
sc.render.filepath = os.path.join(OUT, f"{name}.png")
|
||
|
|
bpy.ops.render.render(write_still=True)
|
||
|
|
print(f"rendered {name}")
|
||
|
|
print("DBG_DONE")
|