rendering materials to mesh objects

import bpy FILE_PATH = "/home/user/test/" def deleteDefaultCube(): bpy.data.objects['Cube'].select = True bpy.ops.object.delete() def linkMeshObject(): fname = FILE_PATH + "remote.blend" with bpy.data.libraries.load(fname, link=True) as (src, dst): # src has many properties, each of which is a list of name strings. # dst is how we specify what we want to link from the library file. dst.objects = src.objects scene = bpy.context.scene for ob in dst.objects: if ob.type == 'MESH': scene.objects.link(ob) bpy.context.scene.objects.active = ob break return bpy.context.object def linkMaterial(obj): fname = FILE_PATH + "material1.blend" with bpy.data.libraries.load(fname, link=True) as (src, dst): # src has many properties, each of which is a list of name strings. # dst is how we specify what we want to link from the library file. dst.materials = src.materials for material in dst.materials: if obj.data.materials: # assign to 1st material slot obj.data.materials[0] = material else: # no slots obj.data.materials.append(material) def renderAsPng(): bpy.context.scene.cycles.film_transparent = True bpy.context.scene.render.engine = 'CYCLES' bpy.data.scenes['Scene'].render.filepath = FILE_PATH + 'test.png' bpy.ops.render.render(write_still=True) deleteDefaultCube() mesh_ob = linkMeshObject() linkMaterial(mesh_ob) renderAsPng()

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.