Esempio n. 1
0
def _getFilePath(filename, folder = None):
    if not filename or not isinstance(filename, basestring):
        return filename

    # Ensure unix style path
    filename.replace('\\', '/')

    searchPaths = []

    # Search within current folder
    if folder:
        searchPaths.append(folder)

    from getpath import findFile, getPath, getSysDataPath, getSysPath, getDataPath
    searchPaths.extend([getDataPath(), getSysDataPath(), getPath(), getSysPath()])

    # Search in user / sys data, and user / sys root folders
    path = findFile(filename, searchPaths, strict=True)
    if path:
        return os.path.abspath(path)

    # Treat as absolute path or search relative to application path
    if os.path.isfile(filename):
        return os.path.abspath(filename)

    # Nothing found
    return os.path.normpath(filename)
Esempio n. 2
0
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.' % rigfile)

    import skeleton

    if not human.getBaseSkeleton():
        # TODO when starting in GUI mode, base skeleton will be loaded twice
        base_skel = skeleton.load(
            getpath.getSysDataPath('rigs/default.mhskel'), human.meshData)
        human.setBaseSkeleton(base_skel)

    referenceRig = human.getBaseSkeleton()

    # TODO update skeleton library when in gui mode
    skel = skeleton.load(rigfile, human.meshData)
    skel.autoBuildWeightReferences(referenceRig)
    vertexWeights = skel.getVertexWeights(referenceRig.getVertexWeights())
    skel.addReferencePlanes(
        referenceRig
    )  # Not strictly needed for the new way in which we determine bone normals

    human.setSkeleton(skel)
Esempio n. 3
0
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 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.' % rigfile)

    import skeleton

    if not human.getBaseSkeleton():
        # TODO when starting in GUI mode, base skeleton will be loaded twice
        base_skel = skeleton.load(getpath.getSysDataPath('rigs/default.mhskel'), human.meshData)
        human.setBaseSkeleton(base_skel)

    referenceRig = human.getBaseSkeleton()

    # TODO update skeleton library when in gui mode
    skel = skeleton.load(rigfile, human.meshData)
    skel.autoBuildWeightReferences(referenceRig)
    vertexWeights = skel.getVertexWeights(referenceRig.getVertexWeights())
    skel.addReferencePlanes(referenceRig)  # Not strictly needed for the new way in which we determine bone normals

    human.setSkeleton(skel)
    def loadHandler(self, human, values):
        if values[0] == 'status':
            return

        if values[0] == 'skinMaterial':
            path = values[1]
            if os.path.isfile(path):
                mat = material.fromFile(path)
                human.material = mat
                return
            else:
                absP = getpath.findFile(
                    path, [mh.getPath('data'),
                           mh.getSysDataPath()])
                if not os.path.isfile(absP):
                    log.warning(
                        'Could not find material %s for skinMaterial parameter.',
                        values[1])
                    return
                mat = material.fromFile(absP)
                human.material = mat
                return
        elif values[0] == 'material':
            if len(values) == 3:
                uuid = values[1]
                filepath = values[2]
                name = ""
            else:
                name = values[1]
                uuid = values[2]
                filepath = values[3]

            if human.hairProxy and human.hairProxy.getUuid() == uuid:
                proxy = human.hairProxy
                filepath = self.getMaterialPath(filepath, proxy.file)
                proxy.object.material = material.fromFile(filepath)
                return
            elif human.eyesProxy and human.eyesProxy.getUuid() == uuid:
                proxy = human.eyesProxy
                filepath = self.getMaterialPath(filepath, proxy.file)
                proxy.object.material = material.fromFile(filepath)
                return
            elif human.genitalsProxy and human.genitalsProxy.getUuid() == uuid:
                proxy = human.genitalsProxy
                filepath = self.getMaterialPath(filepath, proxy.file)
                proxy.object.material = material.fromFile(filepath)
                return
            elif not uuid in human.clothesProxies.keys():
                log.error(
                    "Could not load material for proxy with uuid %s (%s)! No such proxy."
                    % (uuid, name))
                return

            proxy = human.clothesProxies[uuid]
            proxy = human.clothesProxies[uuid]
            filepath = self.getMaterialPath(filepath, proxy.file)
            self.applyClothesMaterial(uuid, filepath)
            return
Esempio n. 6
0
def addProxy(human, mhclofile, type):
    # TODO if eyes proxy is loaded, the one loaded by default should be removed

    if not os.path.isfile(mhclofile):
        mhclofile = getpath.findFile(mhclofile,
                                     searchPaths=[
                                         getpath.getDataPath(),
                                         getpath.getSysDataPath(),
                                         getpath.getPath(),
                                         getpath.getSysPath()
                                     ])
        if not os.path.isfile(mhclofile):
            #log.error("Proxy file %s does not exist (%s).", mhclofile, type)
            #return
            raise RuntimeError('Proxy file "%s" does not exist (%s).' %
                               (mhclofile, type))

    import proxy
    pxy = proxy.loadProxy(human, mhclofile, type=type.capitalize())
    mesh, obj = pxy.loadMeshAndObject(human)

    if type == "proxymeshes":
        human.setProxy(pxy)
        return

    mesh, obj = pxy.loadMeshAndObject(human)

    if not mesh:
        raise RuntimeError('Failed to load proxy mesh "%s"', pxy.obj_file)

    def _adaptProxyToHuman(pxy, obj):
        mesh = obj.getSeedMesh()
        pxy.update(mesh)
        mesh.update()
        # Update subdivided mesh if smoothing is enabled
        if obj.isSubdivided():
            obj.getSubdivisionMesh()

    _adaptProxyToHuman(pxy, obj)
    obj.setSubdivided(human.isSubdivided())

    if type == "hair":
        human.hairProxy = pxy
    elif type == "eyes":
        human.eyesProxy = pxy
    elif type == "eyebrows":
        human.eyebrowsProxy = pxy
    elif type == "eyelashes":
        human.eyelashesProxy = pxy
    elif type == "teeth":
        human.teethProxy = pxy
    elif type == "tongue":
        human.tongueProxy = pxy
    elif type == "clothes":
        human.addClothesProxy(pxy)
    else:
        raise RuntimeError("Unknown proxy type: %s" % type)
    def getMaterialPath(self, relPath, objFile=None):
        if objFile:
            objFile = os.path.abspath(objFile)
            if os.path.isdir(objFile):
                objFile = os.path.split(objFile)[0]
            searchPaths = [objFile] + self.searchPaths
        else:
            searchPaths = self.searchPaths

        return getpath.findFile(relPath, searchPaths)
    def getMaterialPath(self, relPath, objFile = None):
        if objFile:
            objFile = os.path.abspath(objFile)
            if os.path.isdir(objFile):
                objFile = os.path.split(objFile)[0]
            searchPaths = [ objFile ] + self.searchPaths
        else:
            searchPaths = self.searchPaths

        return getpath.findFile(relPath, searchPaths)
def addProxy(human, mhclofile, type):
    # TODO if eyes proxy is loaded, the one loaded by default should be removed

    if not os.path.isfile(mhclofile):
        mhclofile = getpath.findFile(mhclofile, 
                                     searchPaths = [getpath.getDataPath(), 
                                                    getpath.getSysDataPath(),
                                                    getpath.getPath(),
                                                    getpath.getSysPath()])
        if not os.path.isfile(mhclofile):
            #log.error("Proxy file %s does not exist (%s).", mhclofile, type)
            #return
            raise RuntimeError('Proxy file "%s" does not exist (%s).' % (mhclofile, type))

    import proxy
    pxy = proxy.loadProxy(human, mhclofile, type=type.capitalize())
    mesh,obj = pxy.loadMeshAndObject(human)

    if type == "proxymeshes":
        human.setProxy(pxy)
        return

    mesh,obj = pxy.loadMeshAndObject(human)

    if not mesh:
        raise RuntimeError('Failed to load proxy mesh "%s"', pxy.obj_file)

    def _adaptProxyToHuman(pxy, obj):
        mesh = obj.getSeedMesh()
        pxy.update(mesh)
        mesh.update()
        # Update subdivided mesh if smoothing is enabled
        if obj.isSubdivided():
            obj.getSubdivisionMesh()

    _adaptProxyToHuman(pxy, obj)
    obj.setSubdivided(human.isSubdivided())

    if type == "hair":
        human.hairProxy = pxy
    elif type == "eyes":
        human.eyesProxy = pxy
    elif type == "eyebrows":
        human.eyebrowsProxy = pxy
    elif type == "eyelashes":
        human.eyelashesProxy = pxy
    elif type == "teeth":
        human.teethProxy = pxy
    elif type == "tongue":
        human.tongueProxy = pxy
    elif type == "clothes":
        human.addClothesProxy(pxy)
    else:
        raise RuntimeError("Unknown proxy type: %s" % type)
Esempio n. 10
0
    def loadScene(self):

        self.progress(0.18)

        userSceneDir = mh.getDataPath("scenes")
        if not os.path.exists(userSceneDir):
            os.makedirs(userSceneDir)

        from scene import Scene
        from getpath import findFile
        self.setScene(Scene(findFile("scenes/default.mhscene")))
def applyMaterial(matFile, obj):
    if not os.path.isfile(matFile):
        matFile = getpath.findFile(matFile, 
                                   searchPaths = [getpath.getDataPath(), 
                                                  getpath.getSysDataPath(),
                                                  getpath.getPath(),
                                                  getpath.getSysPath()])
    if not os.path.isfile(matFile):
        raise RuntimeError('Material file "%s" does not exist.', matFile)
    else:
        import material
        obj.material = material.fromFile( matFile )
    def loadHandler(self, human, values):
        if values[0] == 'status':
            return

        if values[0] == 'skinMaterial':
            path = values[1]
            if os.path.isfile(path):
                mat = material.fromFile(path)
                human.material = mat
                return
            else:
                absP = getpath.findFile(path, [mh.getPath('data'), mh.getSysDataPath()])
                if not os.path.isfile(absP):
                    log.warning('Could not find material %s for skinMaterial parameter.', values[1])
                    return
                mat = material.fromFile(absP)
                human.material = mat
                return
        elif values[0] == 'material':
            if len(values) == 3:
                uuid = values[1]
                filepath = values[2]
                name = ""
            else:
                name = values[1]
                uuid = values[2]
                filepath = values[3]

            if human.hairProxy and human.hairProxy.getUuid() == uuid:
                proxy = human.hairProxy
                filepath = self.getMaterialPath(filepath, proxy.file)
                proxy.object.material = material.fromFile(filepath)
                return
            elif human.eyesProxy and human.eyesProxy.getUuid() == uuid:
                proxy = human.eyesProxy
                filepath = self.getMaterialPath(filepath, proxy.file)
                proxy.object.material = material.fromFile(filepath)
                return
            elif human.genitalsProxy and human.genitalsProxy.getUuid() == uuid:
                proxy = human.genitalsProxy
                filepath = self.getMaterialPath(filepath, proxy.file)
                proxy.object.material = material.fromFile(filepath)
                return
            elif not uuid in human.clothesProxies.keys():
                log.error("Could not load material for proxy with uuid %s (%s)! No such proxy." % (uuid, name))
                return

            proxy = human.clothesProxies[uuid]
            proxy = human.clothesProxies[uuid]
            filepath = self.getMaterialPath(filepath, proxy.file)
            self.applyClothesMaterial(uuid, filepath)
            return
Esempio n. 13
0
    def loadHandler(self, human, values):
        if values[0] == "skeleton":
            skelFile = values[1]

            skelFile = getpath.findFile(skelFile, self.paths)
            if not os.path.isfile(skelFile):
                log.warning("Could not load rig %s, file does not exist." % skelFile)
            else:
                self.rigPresetFileSelected(skelFile, True)
            return

        # Make sure no skeleton is drawn
        if self.skelObj:
            self.skelObj.hide()
Esempio n. 14
0
def applyMaterial(matFile, obj):
    if not os.path.isfile(matFile):
        matFile = getpath.findFile(matFile,
                                   searchPaths=[
                                       getpath.getDataPath(),
                                       getpath.getSysDataPath(),
                                       getpath.getPath(),
                                       getpath.getSysPath()
                                   ])
    if not os.path.isfile(matFile):
        raise RuntimeError('Material file "%s" does not exist.', matFile)
    else:
        import material
        obj.material = material.fromFile(matFile)
Esempio n. 15
0
    def loadHandler(self, human, values):
        if values[0] == "skeleton":
            skelFile = values[1]

            skelFile = getpath.findFile(skelFile, self.paths)
            if not os.path.isfile(skelFile):
                log.warning("Could not load rig %s, file does not exist." %
                            skelFile)
            else:
                self.rigPresetFileSelected(skelFile, True)
            return

        # Make sure no skeleton is drawn
        if self.skelObj:
            self.skelObj.hide()
Esempio n. 16
0
def _getFilePath(filename, folder = None, altExtensions=None):
    if altExtensions is not None:
        # Search for existing path with alternative file extension
        for aExt in altExtensions:
            if aExt.startswith('.'):
                aExt = aExt[1:]
            aFile = os.path.splitext(filename)[0]+'.'+aExt
            aPath = _getFilePath(aFile, folder, altExtensions=None)
            if os.path.isfile(aPath):
                # Path found, return result with original extension
                orgExt = os.path.splitext(filename)[1]
                path = os.path.splitext(aPath)[0]+orgExt
                return os.path.normpath(path)

    if not filename or not isinstance(filename, basestring):
        return filename

    # Ensure unix style path
    filename.replace('\\', '/')

    searchPaths = []

    # Search within current folder
    if folder:
        searchPaths.append(folder)

    from getpath import findFile, getPath, getSysDataPath, getSysPath, getDataPath
    searchPaths.extend([getDataPath(), getSysDataPath(), getPath(), getSysPath()])

    # Search in user / sys data, and user / sys root folders
    path = findFile(filename, searchPaths, strict=True)
    if path:
        return os.path.abspath(path)

    # Treat as absolute path or search relative to application path
    if os.path.isfile(filename):
        return os.path.abspath(filename)

    # Nothing found
    return os.path.normpath(filename)
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