def createJointPool(self, counts): if counts < 1: return [] obj = bpyutils.createObject(name='Joint', object_data=None) obj.parent = self.jointGroupObject() obj.mmd_type = 'JOINT' obj.rotation_mode = 'YXZ' obj.empty_draw_type = 'ARROWS' obj.empty_draw_size = 0.1 * self.__root.empty_draw_size obj.hide_render = True if bpy.ops.rigidbody.world_add.poll(): bpy.ops.rigidbody.world_add() bpy.ops.rigidbody.constraint_add(type='GENERIC_SPRING') rbc = obj.rigid_body_constraint rbc.disable_collisions = False rbc.use_limit_ang_x = True rbc.use_limit_ang_y = True rbc.use_limit_ang_z = True rbc.use_limit_lin_x = True rbc.use_limit_lin_y = True rbc.use_limit_lin_z = True rbc.use_spring_x = True rbc.use_spring_y = True rbc.use_spring_z = True if hasattr(rbc, 'use_spring_ang_x'): rbc.use_spring_ang_x = True rbc.use_spring_ang_y = True rbc.use_spring_ang_z = True if counts == 1: return [obj] return bpyutils.duplicateObject(obj, counts)
def __createNonCollisionConstraint(self, nonCollisionJointTable): total_len = len(nonCollisionJointTable) if total_len < 1: return start_time = time.time() logging.debug('-' * 60) logging.debug(' creating ncc, counts: %d', total_len) ncc_obj = bpyutils.createObject(name='ncc', object_data=None) ncc_obj.location = [0, 0, 0] ncc_obj.empty_draw_size = 0.5 * self.__root.empty_draw_size ncc_obj.empty_draw_type = 'ARROWS' ncc_obj.mmd_type = 'NON_COLLISION_CONSTRAINT' ncc_obj.hide_render = True ncc_obj.parent = self.temporaryGroupObject() bpy.ops.rigidbody.constraint_add(type='GENERIC') rb = ncc_obj.rigid_body_constraint rb.disable_collisions = True ncc_objs = bpyutils.duplicateObject(ncc_obj, total_len) logging.debug(' created %d ncc.', len(ncc_objs)) for ncc_obj, pair in zip(ncc_objs, nonCollisionJointTable): rbc = ncc_obj.rigid_body_constraint rbc.object1, rbc.object2 = pair ncc_obj.hide = ncc_obj.hide_select = True logging.debug(' finish in %f seconds.', time.time() - start_time) logging.debug('-' * 60)
def createRigidBodyPool(self, counts): if counts < 1: return [] obj = bpyutils.createObject( name='Rigidbody', object_data=bpy.data.meshes.new(name='Rigidbody')) obj.parent = self.rigidGroupObject() obj.mmd_type = 'RIGID_BODY' obj.rotation_mode = 'YXZ' obj.draw_type = 'SOLID' #obj.show_wire = True obj.show_transparent = True obj.hide_render = True if hasattr(obj, 'display'): obj.display.show_shadows = False if hasattr(obj, 'cycles_visibility'): for attr_name in ('camera', 'diffuse', 'glossy', 'scatter', 'shadow', 'transmission'): if hasattr(obj.cycles_visibility, attr_name): setattr(obj.cycles_visibility, attr_name, False) if bpy.app.version < (2, 71, 0): obj.mmd_rigid.shape = 'BOX' obj.mmd_rigid.size = (1, 1, 1) bpy.ops.rigidbody.object_add(type='ACTIVE') if counts == 1: return [obj] return bpyutils.duplicateObject(obj, counts)