def setUpMesh(): """ Imports the mesh and connects it to the armature. """ print 'Setting up mesh...' t1= Blender.sys.time() # A little hack because import_obj.py doesnt provide the names of the imported objects objectsBefore = [ob for ob in scene.objects] import_obj.load_obj(MESHString) names = [ob.name for ob in scene.objects if ob not in objectsBefore] global mesh_name # The mesh created in makehuman is split up in parts, and these need to be # joined together before connecting it to the armature. Uses 'body' as the # main mesh part and connects all other parts to this. mesh_name = [s for s in names if 'body' in s][0] restmesh_name = [s for s in names if s is not mesh_name] armature = [ob for ob in scene.objects if ob.name == armature_name][0] armature.RotX = math.pi/2 bodymesh = [ob for ob in scene.objects if ob.name == mesh_name][0] restmesh = [ob for ob in scene.objects if ob.name in restmesh_name] bodymesh.join(restmesh) for ob in restmesh: scene.objects.unlink(ob) print 'done moving armature and joining mesh parts, it took %.4fs' % (Blender.sys.time()-t1) t2 = Blender.sys.time() editmode = Window.EditMode() # are we in edit mode? If so ... if editmode: Window.EditMode(0) # leave edit mode # Actual code for connection to armature. We still need to fix the remaining # verts though. This is done in fixVerts() armature.makeParent([bodymesh]) bodymesh.addVertexGroupsFromArmature(armature) mods = bodymesh.modifiers mod = mods.append(Modifier.Types.ARMATURE) mod[Modifier.Settings.OBJECT] = armature mod[Modifier.Settings.VGROUPS] = True mod[Modifier.Settings.ENVELOPES] = True print 'done adding mesh using bone heat, it took %.4fs' % (Blender.sys.time()-t2) if editmode: Window.EditMode(1) # optional, just being nice print 'Setting up mesh took %.4fs' % (Blender.sys.time()-t1)
def import_obj(filename): load_obj(filename) sculptify_scene()
""" if __name__ == "__main__": filename = os.getenv("filename") if filename is None: print HELP else: scene = Blender.Scene.GetCurrent() # Blender's default view has a cube. This script cannot be run in batch # (-b) mode because Blender cannot join objects there. print "Removing default cube..." scene.objects.unlink((o for o in scene.objects if o.name == "Cube").next()) print "Importing model..." if filename.endswith(".obj"): # Import model from OBJ file. import_obj.load_obj(filename) elif filename.endswith(".off"): # Import model from OFF file. off_import.read(filename) # Join objects. print "Joining objects..." other_objects = [scene.objects[i] for i in range(1, len(scene.objects))] scene.objects[0].join(other_objects) for o in other_objects: scene.objects.unlink(o) scene.objects.active = scene.objects[0] # Export to MiniLight. print "Exporting model..." minilight_export.write(filename + ".ml.txt") Blender.Quit()
# I'm importing an .obj file. Applying a material and a texture and then exporting again. # I've come to importing the file and creating a new material etc but now I need to apply it to the # imported object. But how do I access the object functions for the imported object? import Blender from Blender import Scene, Object, Material import import_obj ob = import_obj.load_obj('/home/arnaud/Documents/z25/bodycount/scans/Arnaud/scan_faceFrnt_scl8_tst02.obj',CLAMP_SIZE=10.0) print(ob) mat = Material.New('gezichtMat') mat.rgbCol = [0.8, 0.2, 0.2] ob.setMaterials(mat) Blender.Redraw() # import_obj dosnt return 1 object. make a new scene for each import, then loop on its objects. # also, set the materials for the mesh, not the object # ob.getData(mesh=1).materials = [mymat]