def loadPlugins(self): self.progress(0.4) # Load plugins not starting with _ self.pluginsToLoad = glob.glob(mh.getSysPath(os.path.join("plugins/",'[!_]*.py'))) # Load plugin packages (folders with a file called __init__.py) for fname in os.listdir(mh.getSysPath("plugins/")): if fname[0] != "_": folder = os.path.join("plugins", fname) if os.path.isdir(folder) and ("__init__.py" in os.listdir(folder)): self.pluginsToLoad.append(folder) self.pluginsToLoad.sort() self.pluginsToLoad.reverse() while self.pluginsToLoad: self.loadNextPlugin()
def readVertexGroupFiles(self, files): vgroups = OrderedDict() for file in files: filepath = os.path.join(mh.getSysPath("shared/armature/data"), "vgrp_"+file+".json") log.message("Loading %s" % filepath) vglist = io_json.loadJson(filepath) for key,data in vglist: try: vgroups[key] += data except KeyError: vgroups[key] = data #readVertexGroups(filepath, vgroups, vgroups) return vgroups
def __init__(self, category): guirender.RenderTaskView.__init__(self, category, 'Scene') self.filechooser = self.addRightWidget( fc.IconListFileChooser( [mh.getPath('data/scenes'), mh.getSysPath('data/scenes')], 'mhscene', ['thumb', 'png'], 'notfound.thumb', 'Scene')) #self.addLeftWidget(self.filechooser.createSortBox()) self.filechooser.enableAutoRefresh(False) @self.filechooser.mhEvent def onFileSelected(filename): G.app.currentScene.load(filename)
def loadPlugins(self): self.progress(0.4) # Load plugins not starting with _ self.pluginsToLoad = glob.glob(mh.getSysPath(os.path.join("plugins/",'[!_]*.py'))) for fname in os.listdir("plugins/"): if fname[0] != "_": folder = os.path.join("plugins", fname) if os.path.isdir(folder) and ("__init__.py" in os.listdir(folder)): self.pluginsToLoad.append(folder) self.pluginsToLoad.sort() self.pluginsToLoad.reverse() while self.pluginsToLoad: self.loadNextPlugin()
def getSysDir(self,conn,jsonCall): jsonCall.data = os.path.abspath(mh.getSysPath())
def __init__(self, app): camera = app.modelCamera #rendering properties self.camera = camera self.app = app #self.lastUndoItem = None #self.lastRotation = [0,0,0] #self.lastCameraPosition = [self.camera.eyeX, -self.camera.eyeY, self.camera.eyeZ] #self.firstTimeRendering = True self.renderResult = "" #resource paths self.renderPath = os.path.join(mh.getPath('render'), 'renderman_output') self.ribsPath = os.path.join(self.renderPath, 'ribFiles') self.usrShaderPath = os.path.join(self.ribsPath, 'shaders') #Texture paths self.usrTexturePath = os.path.join(self.ribsPath, 'textures') self.applicationPath = mh.getSysPath() self.appTexturePath = mh.getSysDataPath('textures') self.hairTexturePath = mh.getSysDataPath('hairstyles') self.skinTexturePath = os.path.join(mh.getPath(''), 'data', 'skins') #self.appObjectPath = os.path.join(self.applicationPath, 'data', '3dobjs') self.worldFileName = os.path.join(self.ribsPath,"world.rib").replace('\\', '/') self.lightsFolderPath = os.path.join(mh.getSysDataPath('lights'), 'aqsis') #mainscenefile self.sceneFileName = os.path.join(self.ribsPath, "scene.rib") #Human in the scene self.humanCharacter = RMRHuman(app.selectedHuman, "base.obj", app.selectedHuman.mesh, self.ribsPath) self.humanCharacter.materialInit() self.humanCharacter.subObjectsInit() #Rendering options #self.calcShadow = False #self.calcSSS = False ##Shadow path #self.shadowFileName = os.path.join(self.ribsPath,"shadow.rib").replace('\\', '/') ##SSS path #self.bakeFilename = os.path.join(self.ribsPath,"skinbake.rib").replace('\\', '/') #self.lightmapFileName = os.path.join(self.ribsPath,"lightmap.rib").replace('\\', '/') #self.bakeTMPTexture = os.path.join(self.usrTexturePath,"bake.bake").replace('\\', '/') #self.bakeTexture = os.path.join(self.usrTexturePath,"bake.texture").replace('\\', '/') #self.lightmapTMPTexture = os.path.join(self.usrTexturePath,"lightmap.png").replace('\\', '/') #self.lightmapTexture = os.path.join(self.usrTexturePath,"lightmap.texture").replace('\\', '/') #Lights list self.lights = [] #creating resources folders if not os.path.isdir(self.renderPath): os.makedirs(self.renderPath) if not os.path.isdir(self.ribsPath): os.makedirs(self.ribsPath) if not os.path.isdir(self.usrTexturePath): os.makedirs(self.usrTexturePath) if not os.path.isdir(self.usrShaderPath): os.makedirs(self.usrShaderPath)
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