import bpy,json,math from mathutils import Matrix views=json.load(open('/tmp/corner-qa/scenes.json')) for v in views: bpy.ops.object.select_all(action='SELECT');bpy.ops.object.delete(use_global=False) for item in v['meshes']: p=item['positions'];ind=item['indices'];mesh=bpy.data.meshes.new(item['name']);mesh.from_pydata(list(zip(p[::3],p[1::3],p[2::3])),[],list(zip(ind[::3],ind[1::3],ind[2::3])));mesh.update();ob=bpy.data.objects.new(item['name'],mesh);bpy.context.collection.objects.link(ob) name=item['name'];color=(.67,.61,.49,1) if 'Plaster' in name or 'Shell' in name else (.3,.16,.08,1) if 'Wood' in name or 'Picture' in name else (.55,.51,.43,1) if 'Curtain' in name:color=(.88,.85,.72,1) mat=bpy.data.materials.new(name);mat.diffuse_color=color;ob.data.materials.append(mat) if 'Picture' in name and item['colors']: palette={};co=item['colors'] for poly in mesh.polygons: i=poly.vertices[0];rgb=tuple(round(x,5) for x in co[i*3:i*3+3]) if rgb not in palette: m=bpy.data.materials.new('Print');m.diffuse_color=(*rgb,1);ob.data.materials.append(m);palette[rgb]=len(ob.data.materials)-1 poly.material_index=palette[rgb] if item['colors']: attr=mesh.color_attributes.new(name='Color',type='FLOAT_COLOR',domain='POINT');co=item['colors'] for i,d in enumerate(attr.data):d.color=(*co[i*3:i*3+3],1) camera=bpy.data.cameras.new('Camera');ob=bpy.data.objects.new('Camera',camera);bpy.context.collection.objects.link(ob);a=v['matrix'];ob.matrix_world=Matrix([[a[r+c*4] for c in range(4)]for r in range(4)]);camera.type='PERSP';camera.sensor_fit='VERTICAL';camera.sensor_height=24;camera.lens=24/(2*math.tan(math.radians(v['fov'])/2));bpy.context.scene.camera=ob scene=bpy.context.scene;scene.render.engine='BLENDER_WORKBENCH';scene.display.shading.light='STUDIO';scene.display.shading.color_type='MATERIAL';scene.display.shading.show_shadows=True;scene.display.shading.show_cavity=True;scene.display.shading.cavity_type='BOTH';scene.display.shading.background_type='WORLD';scene.world.color=(.15,.15,.15) scene.render.resolution_y=750;scene.render.resolution_x=int(750*v['aspect']);scene.render.resolution_percentage=100;scene.render.image_settings.file_format='PNG';scene.render.filepath='/tmp/corner-qa/'+v['name']+'.png';bpy.ops.render.render(write_still=True)