17 lines
1.8 KiB
Python
17 lines
1.8 KiB
Python
|
|
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/'turntable_frames';folder.mkdir(exist_ok=True)
|
||
|
|
for frame in range(72):
|
||
|
|
angle=math.tau*frame/72;cam.location=focus+Vector((math.sin(angle)*height*3,-math.cos(angle)*height*3,height*.10));cam.rotation_euler=(focus-cam.location).to_track_quat('-Z','Y').to_euler();s.render.filepath=str(folder/('%03d.png'%frame));bpy.ops.render.render(write_still=True)
|
||
|
|
print('MESHY LOCAL TURNTABLE READY',flush=True)
|