Files
Diabolo/tools/model_sources/meshy_v01/painted_v02/render_details.py
T

18 lines
1.8 KiB
Python
Raw Normal View History

import bpy,math,sys
from pathlib import Path
from mathutils import Vector
p=Path(sys.argv[sys.argv.index('--')+1]).resolve();bpy.ops.wm.read_factory_settings(use_empty=True)
bpy.ops.import_scene.gltf(filepath=str(p));s=bpy.context.scene
meshes=[o for o in s.objects if o.type=='MESH'];points=[o.matrix_world@Vector(c) for o in meshes for c in o.bound_box]
lo=Vector(tuple(min(v[i] for v in points) for i in range(3)));hi=Vector(tuple(max(v[i] for v in points) for i in range(3)));height=hi.z-lo.z;focus=(hi+lo)/2
s.render.engine='BLENDER_EEVEE';s.render.resolution_x=1000;s.render.resolution_y=1000;s.render.resolution_percentage=100
s.world=bpy.data.worlds.new('Studio');s.world.use_nodes=True;bg=next(n for n in s.world.node_tree.nodes if n.type=='BACKGROUND');bg.inputs[0].default_value=(.09,.10,.12,1);bg.inputs[1].default_value=.45
for name,offset,power in [('Key',(-2,-3,3),650),('Fill',(3,-1,2),450),('Rim',(1,3,3),750)]:
d=bpy.data.lights.new(name,'AREA');d.energy=power*height**2/4;d.shape='DISK';d.size=height*1.5;o=bpy.data.objects.new(name,d);s.collection.objects.link(o);o.location=focus+Vector(offset)*height*.8;o.rotation_euler=(focus-o.location).to_track_quat('-Z','Y').to_euler()
d=bpy.data.cameras.new('Inspection camera');cam=bpy.data.objects.new('Inspection camera',d);s.collection.objects.link(cam);s.camera=cam;d.type='ORTHO';d.ortho_scale=max(height,hi.x-lo.x,hi.y-lo.y)*1.18
folder=p.parent/'detail_frames';folder.mkdir(exist_ok=True)
for label,z,scale in [('face',.88,.32),('bodice',.60,.58)]:
target=focus.copy();target.z=lo.z+height*z
cam.data.ortho_scale=height*scale;cam.location=target+Vector((0,-height*3,height*.015));cam.rotation_euler=(target-cam.location).to_track_quat('-Z','Y').to_euler();s.render.filepath=str(folder/(label+'.png'));bpy.ops.render.render(write_still=True)
print('MESHY DETAIL RENDERS READY',flush=True)