def clean(self): rigidbody_world_enabled = rigid_body.setRigidBodyWorldEnabled(False) logging.info('****************************************') logging.info(' Clean rig') logging.info('****************************************') start_time = time.time() pose_bones = [] arm = self.armature() if arm is not None: pose_bones = arm.pose.bones for i in pose_bones: if 'mmd_tools_rigid_track' in i.constraints: const = i.constraints['mmd_tools_rigid_track'] i.constraints.remove(const) rigid_track_counts = 0 for i in self.rigidBodies(): rigid_type = int(i.mmd_rigid.type) if 'mmd_tools_rigid_parent' not in i.constraints: rigid_track_counts += 1 logging.info('%3d# Create a "CHILD_OF" constraint for %s', rigid_track_counts, i.name) i.mmd_rigid.bone = i.mmd_rigid.bone relation = i.constraints['mmd_tools_rigid_parent'] relation.mute = True if rigid_type == rigid_body.MODE_STATIC: i.parent_type = 'OBJECT' i.parent = self.rigidGroupObject() elif rigid_type in [ rigid_body.MODE_DYNAMIC, rigid_body.MODE_DYNAMIC_BONE ]: arm = relation.target bone_name = relation.subtarget if arm is not None and bone_name != '': for c in arm.pose.bones[bone_name].constraints: if c.type == 'IK': c.mute = False self.__restoreTransforms(i) for i in self.joints(): self.__restoreTransforms(i) self.__removeTemporaryObjects() arm = self.armature() if arm is not None: # update armature arm.update_tag() bpy.context.scene.frame_set(bpy.context.scene.frame_current) mmd_root = self.rootObject().mmd_root if mmd_root.show_temporary_objects: mmd_root.show_temporary_objects = False logging.info(' Finished cleaning in %f seconds.', time.time() - start_time) mmd_root.is_built = False rigid_body.setRigidBodyWorldEnabled(rigidbody_world_enabled)
def build(self): rigidbody_world_enabled = rigid_body.setRigidBodyWorldEnabled(False) if self.__root.mmd_root.is_built: self.clean() self.__root.mmd_root.is_built = True logging.info('****************************************') logging.info(' Build rig') logging.info('****************************************') start_time = time.time() self.__preBuild() self.buildRigids() self.buildJoints() self.__postBuild() logging.info(' Finished building in %f seconds.', time.time() - start_time) rigid_body.setRigidBodyWorldEnabled(rigidbody_world_enabled)
def build(self): rigidbody_world_enabled = rigid_body.setRigidBodyWorldEnabled(False) if self.__root.mmd_root.is_built: self.clean() self.__root.mmd_root.is_built = True logging.info('****************************************') logging.info(' Build rig') logging.info('****************************************') start_time = time.time() self.__preBuild() self.buildRigids( bpyutils.addon_preferences('non_collision_threshold', 1.5)) self.buildJoints() self.__postBuild() logging.info(' Finished building in %f seconds.', time.time() - start_time) rigid_body.setRigidBodyWorldEnabled(rigidbody_world_enabled)
def __get_rigid_body_world_objects(): rigid_body.setRigidBodyWorldEnabled(True) rbw = bpy.context.scene.rigidbody_world if bpy.app.version < (2, 80, 0): if not rbw.group: rbw.group = bpy.data.groups.new('RigidBodyWorld') rbw.group.use_fake_user = True if not rbw.constraints: rbw.constraints = bpy.data.groups.new('RigidBodyConstraints') rbw.constraints.use_fake_user = True return rbw.group.objects, rbw.constraints.objects if not rbw.collection: rbw.collection = bpy.data.collections.new('RigidBodyWorld') rbw.collection.use_fake_user = True if not rbw.constraints: rbw.constraints = bpy.data.collections.new('RigidBodyConstraints') rbw.constraints.use_fake_user = True return rbw.collection.objects, rbw.constraints.objects
def clean(self): #FIXME rigid body cache is out of sync on Blender 2.8 # [Build] at frame 1 -> [Play] -> [Stop] at frame N -> [Clean] at frame N -> [Play] -> crash # [Build] at frame 1 -> [Play] -> [Stop] at frame N -> [Clean] at frame N -> go to frame 1 ->[Play] -> ok rigidbody_world_enabled = rigid_body.setRigidBodyWorldEnabled(False) logging.info('****************************************') logging.info(' Clean rig') logging.info('****************************************') start_time = time.time() pose_bones = [] arm = self.armature() if arm is not None: pose_bones = arm.pose.bones for i in pose_bones: if 'mmd_tools_rigid_track' in i.constraints: const = i.constraints['mmd_tools_rigid_track'] i.constraints.remove(const) if bpy.app.version < (2, 78, 0): self.__removeChildrenOfTemporaryGroupObject( ) # for speeding up only for i in self.temporaryObjects(): if i.mmd_type in [ 'NON_COLLISION_CONSTRAINT', 'SPRING_GOAL', 'SPRING_CONSTRAINT' ]: bpy.context.scene.objects.unlink(i) bpy.data.objects.remove(i) elif i.mmd_type == 'TRACK_TARGET': bpy.context.scene.objects.unlink(i) bpy.data.objects.remove(i) else: for i in self.temporaryObjects(): if i.mmd_type in [ 'NON_COLLISION_CONSTRAINT', 'SPRING_GOAL', 'SPRING_CONSTRAINT' ]: bpy.data.objects.remove(i, do_unlink=True) elif i.mmd_type == 'TRACK_TARGET': bpy.data.objects.remove(i, do_unlink=True) rigid_track_counts = 0 for i in self.rigidBodies(): rigid_type = int(i.mmd_rigid.type) if 'mmd_tools_rigid_parent' not in i.constraints: rigid_track_counts += 1 logging.info('%3d# Create a "CHILD_OF" constraint for %s', rigid_track_counts, i.name) i.mmd_rigid.bone = i.mmd_rigid.bone relation = i.constraints['mmd_tools_rigid_parent'] relation.mute = True if rigid_type == rigid_body.MODE_STATIC: i.parent_type = 'OBJECT' i.parent = self.rigidGroupObject() elif rigid_type in [ rigid_body.MODE_DYNAMIC, rigid_body.MODE_DYNAMIC_BONE ]: arm = relation.target bone_name = relation.subtarget if arm is not None and bone_name != '': for c in arm.pose.bones[bone_name].constraints: if c.type == 'IK': c.mute = False self.__restoreTransforms(i) for i in self.joints(): self.__restoreTransforms(i) arm = self.armature() if arm is not None: # update armature arm.update_tag() bpy.context.scene.frame_set(bpy.context.scene.frame_current) mmd_root = self.rootObject().mmd_root if mmd_root.show_temporary_objects: mmd_root.show_temporary_objects = False logging.info(' Finished cleaning in %f seconds.', time.time() - start_time) mmd_root.is_built = False rigid_body.setRigidBodyWorldEnabled(rigidbody_world_enabled)