def personalize(self): set_skin(self.config['base_mesh'], self.config['skin']['hue'], self.config['skin']['saturation'], self.config['skin']['value'], self.config['skin']['age'], self.config['skin']['bump']) set_eyes(self.config['base_mesh'], self.config['eye']['hue'], self.config['eye']['saturation'], self.config['eye']['value']) set_traits(self.config['base_mesh'], self.config['traits']['age'], self.config['traits']['mass'], self.config['traits']['tone']) make_unique(self.config['randomize']) finalize() # Rename get_blend_obj('MBlab_sk').name = self.config['skeleton'] get_blend_obj('MBlab_bd').name = self.config['geometry'] # Uncensor uncensor(self.config['geometry']) # Set render layers materials = [mat.name for mat in bpy.data.materials] for mat in materials: if mat.startswith('MBlab_human_skin'): render.set_render_layer(mat, self.config['skin']['render_layer']) else: render.set_render_layer(mat, self.config['misc']['render_layer']) # Generate head proxy and parent to head bone head_info = head_properties(self.config['skeleton']) head_proxy(self.config['skeleton'], head_info, self.config['head_proxy']['id'])
def uncensor(body): """set all skin geometry to skin texture (i.e. remove modesty material)""" human = get_blend_obj(body) generic_slot = get_mat_slot(human, 'MBlab_generic') skin_material = node.material('MBlab_human_skin') generic_slot.material = skin_material
def attach_to(self, geo): hair = self.config['hair'] append_item(hair['model'], 'hair', geo) render.set_render_layer('hair', hair['render_layer']) hair_color = ( hair['rgb']['r'], hair['rgb']['g'], hair['rgb']['b'], 1) retex.recolor_hair(hair_color) get_blend_obj('hair').name = hair['id'] parent_to_skeleton(bpy.data.objects[hair['id']], bpy.data.objects[self.config['skeleton']])
def head_proxy_properties(head_proxy): """Return current head proxy properties""" proxy = bpy.data.objects[head_proxy] head_center = proxy.matrix_world.to_translation() head_radius = proxy.dimensions[0] / 2 distance = get_blend_obj('Camera').location - head_center return { 'radius': head_radius, 'center': head_center, 'distance': distance.length }
def attach_to(self, geo): shirt = self.config['shirt'] append_item(shirt['model'], 'tshirt', geo) render.set_render_layer('tshirt', shirt['render_layer']) shirt_mat = node.material('tshirt') texture_file = shirt['texture'] retexture_shirt = getattr(retex, shirt['retexture_type']) retexture_shirt(shirt_mat, texture_file) get_blend_obj('tshirt').name = shirt['id'] retex.customize_clothes(shirt['id'], shirt['style']) parent_to_skeleton(bpy.data.objects[shirt['id']], bpy.data.objects[self.config['skeleton']])
def attach_to(self, geo): pants = self.config['pants'] append_item(pants['model'], 'pants', geo) render.set_render_layer('pants', pants['render_layer']) pants_mat = node.material('pants') texture_file = pants['texture'] retexture_shirt = getattr(retex, pants['retexture_type']) retexture_shirt(pants_mat, texture_file) get_blend_obj('pants').name = pants['id'] retex.customize_clothes(pants['id'], pants['style']) parent_to_skeleton(bpy.data.objects[pants['id']], bpy.data.objects[self.config['skeleton']])
def head_properties(skeleton): """Return estimated head data calculated from simulant head bone""" head = bpy.data.objects[skeleton].pose.bones['head'] length = head.length head_radius = length * (2 / 3) head_center = head.head + (head.vector * (1 / 3)) # world-space distance = get_blend_obj('Camera').location - head_center return { 'radius': head_radius, 'center': head_center, 'distance': distance.length }
def head_proxy(base_skeleton, measurements, proxy_id): """Create a head proxy sphere :param base_skeleton: skeleton to which head is attached :param measurements: radius and location information :param proxy_id: unique id for this head proxy """ bpy.ops.mesh.primitive_uv_sphere_add(size=measurements['radius'], location=measurements['center']) bpy.context.active_object.name = proxy_id head_proxy = bpy.data.objects[proxy_id] # Parent to Head Bone skeleton = get_blend_obj(base_skeleton) parent_to_skeleton(head_proxy, skeleton, bone='head') # Fix translation (move -Y two thirds as head bone's tail is now origin) center_bone_relative = mathutils.Vector( (0, -(2 / 3) * skeleton.pose.bones['head'].length, 0)) head_proxy.location = center_bone_relative
def get_bone(skeleton, bone_name): """Return bone of given name""" skeleton = get_blend_obj(skeleton) bone = skeleton.pose.bones[bone_name] return bone
def pose(body, pose_path): deselect_all() human = get_blend_obj(body) human.select = True bpy.ops.mbast.pose_load(filepath=pose_path)