def addRig(human, rigfile): if not os.path.isfile(rigfile): rigfile = getpath.findFile( rigfile, searchPaths=[getpath.getSysDataPath(), getpath.getSysPath()]) if not os.path.isfile(rigfile): #log.error("Rig file %s does not exist.", mhclofile) #return raise RuntimeError('Rig file "%s" does not exist.' % mhclofile) import skeleton from armature.options import ArmatureOptions armature_options = ArmatureOptions() descr = armature_options.loadPreset( rigfile, None) # TODO update skeleton library when in gui mode # Load skeleton definition from options human._skeleton, boneWeights = skeleton.loadRig(armature_options, human.meshData) human._skeleton.options = armature_options # TODO this should be resolved in the future def skeleton_getter(): return human._skeleton human.getSkeleton = skeleton_getter
def chooseSkeleton(self, filename): """ Load skeleton from rig definition in a .rig file. """ log.debug("Loading skeleton from rig file %s", filename) try: self.removeBoneHighlights() except: pass if not filename or os.path.basename(filename) == 'clear.rig': # Unload current skeleton self.human._skeleton = None self.human.animated = None if self.skelObj: # Remove old skeleton mesh gui3d.app.removeObject(self.skelObj) self.skelObj = None self.skelMesh = None self.filechooser.deselectAll() self.selectedBone = None self.reloadBoneExplorer() self.boneCountLbl.setText("Bones: ") self.descrLbl.setText("Description: ") self.filechooser.selectItem( os.path.join(self.rigPaths[0], 'clear.rig')) return # Load skeleton definition from .rig file self.human._skeleton, boneWeights = skeleton.loadRig( filename, self.human.meshData) # Store a reference to the currently loaded rig self.human._skeleton.file = filename self.human._skeleton.dirty = False # Flag used for deferred updating self.human._skeleton._library = self # Temporary member, used for rebuilding skeleton self.filechooser.selectItem(filename) # Created an AnimatedMesh object to manage the skeletal animation on the # human mesh and optionally additional meshes. # The animation manager object is accessible by other plugins via # gui3d.app.currentHuman.animated. self.human.animated = animation.AnimatedMesh(self.human.getSkeleton(), self.human.meshData, boneWeights) # (Re-)draw the skeleton self.drawSkeleton(self.human.getSkeleton()) self.reloadBoneExplorer() self.boneCountLbl.setText("Bones: %s" % self.human.getSkeleton().getBoneCount()) if self.human.getSkeleton().name in self.rigDescriptions.keys(): descr = self.rigDescriptions[self.human.getSkeleton().name] else: descr = "None available" self.descrLbl.setText("Description: %s" % descr)
def chooseSkeleton(self, filename): """ Load skeleton from rig definition in a .rig file. """ log.debug("Loading skeleton from rig file %s", filename) try: self.removeBoneHighlights() except: pass if not filename or os.path.basename(filename) == 'clear.rig': # Unload current skeleton self.human._skeleton = None self.human.animated = None if self.skelObj: # Remove old skeleton mesh gui3d.app.removeObject(self.skelObj) self.skelObj = None self.skelMesh = None self.filechooser.deselectAll() self.selectedBone = None self.reloadBoneExplorer() self.boneCountLbl.setText("Bones: ") self.descrLbl.setText("Description: ") self.filechooser.selectItem(os.path.join(self.rigPaths[0], 'clear.rig')) return # Load skeleton definition from .rig file self.human._skeleton, boneWeights = skeleton.loadRig(filename, self.human.meshData) # Store a reference to the currently loaded rig self.human._skeleton.file = filename self.human._skeleton.dirty = False # Flag used for deferred updating self.human._skeleton._library = self # Temporary member, used for rebuilding skeleton self.filechooser.selectItem(filename) # Created an AnimatedMesh object to manage the skeletal animation on the # human mesh and optionally additional meshes. # The animation manager object is accessible by other plugins via # gui3d.app.currentHuman.animated. self.human.animated = animation.AnimatedMesh(self.human.getSkeleton(), self.human.meshData, boneWeights) # (Re-)draw the skeleton self.drawSkeleton(self.human.getSkeleton()) self.reloadBoneExplorer() self.boneCountLbl.setText("Bones: %s" % self.human.getSkeleton().getBoneCount()) if self.human.getSkeleton().name in self.rigDescriptions.keys(): descr = self.rigDescriptions[self.human.getSkeleton().name] else: descr = "None available" self.descrLbl.setText("Description: %s" % descr)
def loadRig(self): if self.animated: # Set human mesh back to rest pose before removing the animatedMesh self.animated.setToRestPose() rigtype = "soft1" filename = os.path.join("data", "rigs", rigtype+".rig") self.skel, boneWeights = skeleton.loadRig(filename, self.human.meshData) self.animated = animation.AnimatedMesh(self.skel, self.human.meshData, boneWeights) # (Re-)draw the skeleton self.drawSkeleton(self.skel)
def chooseSkeleton(self, options): """ Load skeleton from an options set. """ log.debug("Loading skeleton with options %s", options) self.removeBoneHighlights() if not options: # Unload current skeleton self.human._skeleton = None self.human.animated = None if self.skelObj: # Remove old skeleton mesh gui3d.app.removeObject(self.skelObj) self.skelObj = None self.skelMesh = None self.boneCountLbl.setText("Bones: ") #self.selectedBone = None if self.debugLib: self.debugLib.reloadBoneExplorer() return # Load skeleton definition from options self.human._skeleton, boneWeights = skeleton.loadRig( options, self.human.meshData) # Store a reference to the currently loaded rig self.human._skeleton.options = options self.human._skeleton.dirty = False # Flag used for deferred updating self.human._skeleton._library = self # Temporary member, used for rebuilding skeleton #self.filechooser.selectItem(options) # Created an AnimatedMesh object to manage the skeletal animation on the # human mesh and optionally additional meshes. # The animation manager object is accessible by other plugins via # gui3d.app.currentHuman.animated. self.human.animated = animation.AnimatedMesh(self.human.getSkeleton(), self.human.meshData, boneWeights) # (Re-)draw the skeleton skel = self.human.getSkeleton() self.drawSkeleton(skel) if self.debugLib: self.debugLib.reloadBoneExplorer() self.boneCountLbl.setText("Bones: %s" % self.human.getSkeleton().getBoneCount())
def chooseSkeleton(self, options): """ Load skeleton from an options set. """ log.debug("Loading skeleton with options %s", options) try: self.removeBoneHighlights() except: pass if not options: # Unload current skeleton self.human._skeleton = None self.human.animated = None if self.skelObj: # Remove old skeleton mesh gui3d.app.removeObject(self.skelObj) self.skelObj = None self.skelMesh = None ''' self.filechooser.deselectAll() self.selectedBone = None self.reloadBoneExplorer() self.boneCountLbl.setText("Bones: ") self.descrLbl.setText("Description: ") self.filechooser.selectItem(os.path.join(self.rigPaths[0], 'clear.rig')) ''' return # Load skeleton definition from options self.human._skeleton, boneWeights = skeleton.loadRig(options, self.human.meshData) # Store a reference to the currently loaded rig self.human._skeleton.options = options self.human._skeleton.dirty = False # Flag used for deferred updating self.human._skeleton._library = self # Temporary member, used for rebuilding skeleton #self.filechooser.selectItem(options) # Created an AnimatedMesh object to manage the skeletal animation on the # human mesh and optionally additional meshes. # The animation manager object is accessible by other plugins via # gui3d.app.currentHuman.animated. self.human.animated = animation.AnimatedMesh(self.human.getSkeleton(), self.human.meshData, boneWeights) # (Re-)draw the skeleton self.drawSkeleton(self.human.getSkeleton()) '''
def addRig(human, rigfile): if not os.path.isfile(rigfile): rigfile = getpath.findFile(rigfile, searchPaths = [getpath.getSysDataPath(), getpath.getSysPath()]) if not os.path.isfile(rigfile): #log.error("Rig file %s does not exist.", mhclofile) #return raise RuntimeError('Rig file "%s" does not exist.' % mhclofile) import skeleton from armature.options import ArmatureOptions armature_options = ArmatureOptions() descr = armature_options.loadPreset(rigfile, None) # TODO update skeleton library when in gui mode # Load skeleton definition from options human._skeleton, boneWeights = skeleton.loadRig(armature_options, human.meshData) human._skeleton.options = armature_options # TODO this should be resolved in the future def skeleton_getter(): return human._skeleton human.getSkeleton = skeleton_getter
def loadAnimationTrack(anim): """ Load animation from a BVH file specified by anim. """ global _jointMappingCache if "z_is_up" in anim.options: swapYZ = True else: swapYZ = False human = gui3d.app.selectedHuman log.debug("Loading BVH %s", anim.getPath()) # Load BVH data bvhRig = bvh.load(anim.getPath(), swapYZ) if anim.collection.scale != 1.0: # Scale rig bvhRig.scale(anim.collection.scale) # Scale is only useful when using the joint locations of the BVH rig # or when drawing the BVH rig. if human.getSkeleton().name == anim.collection.rig: # Skeleton and joint rig in BVH match, do a straight mapping of the # motion: # Load animation data from BVH file and add it to AnimatedMesh # This is a list that references a joint name in the BVH for each # bone in the skeleton (breadth-first order): jointToBoneMap = [bone.name for bone in human.getSkeleton().getBones()] animTrack = bvhRig.createAnimationTrack(jointToBoneMap, anim.getAnimationTrackName()) gui3d.app.statusPersist("") else: # Skeleton and joint rig in BVH are not the same, retarget/remap # the motion data: if not os.path.isfile( mh.getSysPath( "tools/blender26x/mh_mocap_tool/target_rigs/%s.trg") % human.getSkeleton().name): gui3d.app.statusPersist( "Cannot apply motion on the selected skeleton %s because there is no target mapping file for it.", human.getSkeleton().name) return None # Load source skeleton of animation for remapping cacheName = anim.collection.rig + "_" + human.getSkeleton().name if cacheName in _jointMappingCache: # Load from cache jointToBoneMap = _jointMappingCache[cacheName] else: # Create and cache mapping srcSkel, _ = skeleton.loadRig( os.path.join(mh.getSysDataPath('rigs'), '%s.rig' % anim.collection.rig), human.meshData) tgtSkel = human.getSkeleton() # Load mapping from reference rig to target rig # TODO this only works if anim.collection.rig == soft1! We cannot do reverse target mappings jointToBoneMap = skeleton.getRetargetMapping( None, human.getSkeleton().name, human.getSkeleton()) # We dont use the compensation angles from the retarget map, instead we calculate the difference between reference and target rig ourselves excludeFromCompensation = ["Root", "Spine1", "Spine2", "Spine3"] jointToBoneMap = skeleton.getRestPoseCompensation( srcSkel, tgtSkel, jointToBoneMap, excludeFromCompensation) _jointMappingCache[cacheName] = jointToBoneMap animTrack = bvhRig.createAnimationTrack(jointToBoneMap, anim.getAnimationTrackName()) gui3d.app.statusPersist("") log.debug("Created animation track for %s rig.", human.getSkeleton().name) log.debug("Frames: %s", animTrack.nFrames) log.debug("Playtime: %s", animTrack.getPlaytime()) return animTrack
def loadAnimationTrack(anim): """ Load animation from a BVH file specified by anim. """ global _jointMappingCache if "z_is_up" in anim.options: swapYZ = True else: swapYZ = False human = gui3d.app.selectedHuman log.debug("Loading BVH %s", anim.getPath()) # Load BVH data bvhRig = bvh.load(anim.getPath(), swapYZ) if anim.collection.scale != 1.0: # Scale rig bvhRig.scale(scale) # Scale is only useful when using the joint locations of the BVH rig # or when drawing the BVH rig. if human.getSkeleton().name == anim.collection.rig: # Skeleton and joint rig in BVH match, do a straight mapping of the # motion: # Load animation data from BVH file and add it to AnimatedMesh # This is a list that references a joint name in the BVH for each # bone in the skeleton (breadth-first order): jointToBoneMap = [bone.name for bone in human.getSkeleton().getBones()] animTrack = bvhRig.createAnimationTrack(jointToBoneMap, anim.getAnimationTrackName()) gui3d.app.statusPersist("") else: # Skeleton and joint rig in BVH are not the same, retarget/remap # the motion data: if not os.path.isfile(mh.getSysPath("tools/blender26x/mh_mocap_tool/target_rigs/%s.trg") % human.getSkeleton().name): gui3d.app.statusPersist("Cannot apply motion on the selected skeleton %s because there is no target mapping file for it.", human.getSkeleton().name) return None # Load source skeleton of animation for remapping cacheName = anim.collection.rig + "_" + human.getSkeleton().name if cacheName in _jointMappingCache: # Load from cache jointToBoneMap = _jointMappingCache[cacheName] else: # Create and cache mapping srcSkel, _ = skeleton.loadRig(os.path.join(mh.getSysDataPath('rigs'), '%s.rig' % anim.collection.rig), human.meshData) tgtSkel = human.getSkeleton() # Load mapping from reference rig to target rig # TODO this only works if anim.collection.rig == soft1! We cannot do reverse target mappings jointToBoneMap = skeleton.getRetargetMapping(None, human.getSkeleton().name, human.getSkeleton()) # We dont use the compensation angles from the retarget map, instead we calculate the difference between reference and target rig ourselves excludeFromCompensation = ["Root", "Spine1", "Spine2", "Spine3"] jointToBoneMap = skeleton.getRestPoseCompensation(srcSkel, tgtSkel, jointToBoneMap, excludeFromCompensation) _jointMappingCache[cacheName] = jointToBoneMap animTrack = bvhRig.createAnimationTrack(jointToBoneMap, anim.getAnimationTrackName()) gui3d.app.statusPersist("") log.debug("Created animation track for %s rig.", human.getSkeleton().name) log.debug("Frames: %s", animTrack.nFrames) log.debug("Playtime: %s", animTrack.getPlaytime()) return animTrack