Esempio n. 1
0
def loadProxy(human, path, type="Clothes"):
    try:
        npzpath = os.path.splitext(path)[0] + '.mhpxy'
        try:
            if not os.path.isfile(npzpath):
                log.message('compiled proxy file missing: %s', npzpath)
                raise RuntimeError('compiled proxy file missing: %s', npzpath)
            if os.path.isfile(path) and os.path.getmtime(path) > os.path.getmtime(npzpath):
                log.message('compiled proxy file out of date: %s', npzpath)
                raise RuntimeError('compiled file out of date: %s', npzpath)
            proxy = loadBinaryProxy(npzpath, human, type)
        except Exception as e:
            showTrace = not isinstance(e, RuntimeError)
            log.warning("Problem loading binary proxy: %s", e, exc_info=showTrace)
            proxy = loadTextProxy(human, path, type)    # TODO perhaps proxy type should be stored in .mhclo file too
            if getpath.isSubPath(npzpath, getpath.getPath()):
                # Only write compiled binary proxies to user data path
                try:
                    saveBinaryProxy(proxy, npzpath)
                except StandardError:
                    log.notice('unable to save compiled proxy: %s', npzpath, exc_info=True)
            else:
                log.debug('Not writing compiled proxies to system paths (%s).', npzpath)
    except:
        log.error('Unable to load proxy file: %s', path, exc_info=True)
        return None

    return proxy
Esempio n. 2
0
    def getMaterialPaths(self, objType, proxy = None):
        if objType == 'skin':
            objType = 'skins'
        elif objType not in [t.lower() for t in SimpleProxyTypes]:
            objType = 'clothes'
        objType = objType.lower()

        if proxy and objType != 'skins':
            subPath = None
        else:
            subPath = objType

        # General paths
        if subPath:
            paths = [mh.getPath(os.path.join('data', subPath)), mh.getSysDataPath(subPath)]
            for p in paths:
                if getpath.isSubPath(p, mh.getPath()) and not os.path.exists(p):
                    os.makedirs(p)
        else:
            paths = []

        # Global material paths
        for p in [mh.getPath(os.path.join('data', objType, 'materials')), mh.getSysDataPath(os.path.join(objType, 'materials'))]:
            if os.path.isdir(p):
                paths.append(p)

        # Path where proxy file is located
        if proxy:
            paths = [os.path.dirname(proxy.file)] + paths

        return paths
    def getMaterialPaths(self, objType, proxy = None):
        if objType == 'skin':
            objType = 'skins'
        elif objType not in [t.lower() for t in SimpleProxyTypes]:
            objType = 'clothes'
        objType = objType.lower()

        if proxy and objType != 'skins':
            subPath = None
        else:
            subPath = objType

        # General paths
        if subPath:
            paths = [mh.getPath(os.path.join('data', subPath)), mh.getSysDataPath(subPath)]
            for p in paths:
                if getpath.isSubPath(p, mh.getPath()) and not os.path.exists(p):
                    os.makedirs(p)
        else:
            paths = []

        # Global material paths
        for p in [mh.getPath(os.path.join('data', objType, 'materials')), mh.getSysDataPath(os.path.join(objType, 'materials'))]:
            if os.path.isdir(p):
                paths.append(p)

        # Path where proxy file is located
        if proxy:
            paths = [os.path.dirname(proxy.file)] + paths

        return paths
Esempio n. 4
0
def loadMesh(path, locX=0, locY=0, locZ=0, loadColors=1):
    """
    This function loads the specified mesh object into internal MakeHuman data 
    structures, and returns it. The loaded file should be in Wavefront OBJ 
    format.
    
    Parameters:
    -----------
   
    path:     
      *String*.  The file system path to the file containing the object to load.

    locX:
      *float* X location of loaded obj, default = 0

    locY:
      *float* Y location of loaded obj, default = 0

    locZ:
      *float* Z location of loaded obj, default = 0
    """
    name = os.path.basename(path)
    obj = module3d.Object3D(name)

    obj.path = path
    obj.x = locX
    obj.y = locY
    obj.z = locZ

    try:
        npzpath = os.path.splitext(path)[0] + '.npz'
        try:
            if not os.path.isfile(npzpath):
                log.message('compiled file missing: %s', npzpath)
                raise RuntimeError()
            if os.path.isfile(path) and os.path.getmtime(path) > os.path.getmtime(npzpath):
                log.message('compiled file out of date: %s', npzpath)
                raise RuntimeError()
            loadBinaryMesh(obj, npzpath)
        except:
            loadTextMesh(obj, path)
            if isSubPath(npzpath, getPath('')):
                # Only write compiled binary meshes to user data path
                try:
                    saveBinaryMesh(obj, npzpath)
                except Exception:
                    log.notice('unable to save compiled mesh: %s', npzpath)
            else:
                log.debug('Not writing compiled meshes to system paths (%s).', npzpath)
    except:
        log.error('Unable to load obj file: %s', path, exc_info=True)
        return False

    obj.updateIndexBuffer()
    obj.calcNormals()
        
    return obj
Esempio n. 5
0
def loadMesh(path, loadColors=1, maxFaces=None, obj=None):
    """
    This function loads the specified mesh object into internal MakeHuman data 
    structures, and returns it. The loaded file should be in Wavefront OBJ 
    format.
    
    Parameters:
    -----------
   
    path:     
      *String*.  The file system path to the file containing the object to load.

    Note: loadColors is currently unused

    maxFaces:
      *uint* Number of faces per vertex (pole), None for default (min 4)
    """
    name = os.path.basename(path)
    if obj is None:
        obj = module3d.Object3D(name)
    if maxFaces:
        obj.MAX_FACES = maxFaces

    obj.path = path

    try:
        npzpath = os.path.splitext(path)[0] + '.npz'
        try:
            if not os.path.isfile(npzpath):
                log.message('compiled file missing: %s', npzpath)
                raise RuntimeError('compiled file missing: %s', npzpath)
            if os.path.isfile(path) and os.path.getmtime(
                    path) > os.path.getmtime(npzpath):
                log.message('compiled file out of date: %s', npzpath)
                raise RuntimeError('compiled file out of date: %s', npzpath)
            loadBinaryMesh(obj, npzpath)
        except Exception as e:
            showTrace = not isinstance(e, RuntimeError)
            log.warning("Problem loading binary mesh: %s",
                        e,
                        exc_info=showTrace)
            loadTextMesh(obj, path)
            if isSubPath(npzpath, getPath('')):
                # Only write compiled binary meshes to user data path
                try:
                    saveBinaryMesh(obj, npzpath)
                except StandardError:
                    log.notice('unable to save compiled mesh: %s', npzpath)
            else:
                log.debug('Not writing compiled meshes to system paths (%s).',
                          npzpath)
    except:
        log.error('Unable to load obj file: %s', path, exc_info=True)
        return False

    return obj
Esempio n. 6
0
def loadMesh(path, loadColors=1, maxFaces=None, obj=None):
    """
    This function loads the specified mesh object into internal MakeHuman data 
    structures, and returns it. The loaded file should be in Wavefront OBJ 
    format.
    
    Parameters:
    -----------
   
    path:     
      *String*.  The file system path to the file containing the object to load.

    Note: loadColors is currently unused

    maxFaces:
      *uint* Number of faces per vertex (pole), None for default (min 4)
    """
    name = os.path.basename(path)
    if obj is None:
        obj = module3d.Object3D(name)
    if maxFaces:
        obj.MAX_FACES = maxFaces

    obj.path = path

    try:
        npzpath = os.path.splitext(path)[0] + '.npz'
        try:
            if not os.path.isfile(npzpath):
                log.message('compiled file missing: %s', npzpath)
                raise RuntimeError('compiled file missing: %s', npzpath)
            if os.path.isfile(path) and os.path.getmtime(path) > os.path.getmtime(npzpath):
                log.message('compiled file out of date: %s', npzpath)
                raise RuntimeError('compiled file out of date: %s', npzpath)
            loadBinaryMesh(obj, npzpath)
        except Exception as e:
            showTrace = not isinstance(e, RuntimeError)
            log.warning("Problem loading binary mesh: %s", e, exc_info=showTrace)
            loadTextMesh(obj, path)
            if isSubPath(npzpath, getPath('')):
                # Only write compiled binary meshes to user data path
                try:
                    saveBinaryMesh(obj, npzpath)
                except StandardError:
                    log.notice('unable to save compiled mesh: %s', npzpath)
            else:
                log.debug('Not writing compiled meshes to system paths (%s).', npzpath)
    except:
        log.error('Unable to load obj file: %s', path, exc_info=True)
        return False

    return obj
Esempio n. 7
0
def loadProxy(human, path, type="Clothes"):
    try:
        npzpath = os.path.splitext(path)[0] + '.mhpxy'
        asciipath = os.path.splitext(path)[0] + getAsciiFileExtension(type)
        try:
            if not os.path.isfile(npzpath):
                log.message('compiled proxy file missing: %s', npzpath)
                raise RuntimeError('compiled proxy file missing: %s', npzpath)
            if os.path.isfile(asciipath) and os.path.getmtime(
                    asciipath) > os.path.getmtime(npzpath):
                log.message('compiled proxy file out of date: %s', npzpath)
                raise RuntimeError('compiled file out of date: %s', npzpath)
            proxy = loadBinaryProxy(npzpath, human, type)
        except Exception as e:
            showTrace = not isinstance(e, RuntimeError)
            log.warning("Problem loading binary proxy: %s",
                        e,
                        exc_info=showTrace)
            proxy = loadTextProxy(
                human, asciipath, type
            )  # TODO perhaps proxy type should be stored in .mhclo file too
            if getpath.isSubPath(npzpath, getpath.getPath()):
                # Only write compiled binary proxies to user data path
                try:
                    log.message('Compiling binary proxy file %s', npzpath)
                    saveBinaryProxy(proxy, npzpath)
                except Exception:
                    log.notice('unable to save compiled proxy: %s',
                               npzpath,
                               exc_info=True)
                    if os.path.isfile(npzpath):
                        # Remove file again, in case an empty file is left
                        try:
                            os.remove(npzpath)
                        except Exception as e:
                            log.warning(
                                "Could not remove empty file %s that was left behind (%s).",
                                npzpath, e)
            else:
                log.debug('Not writing compiled proxies to system paths (%s).',
                          npzpath)
    except:
        log.error('Unable to load proxy file: %s', path, exc_info=True)
        return None

    return proxy
    def getMaterialPaths(self, objType, proxy=None):
        if objType == 'skin':
            objType = 'skins'
        elif objType not in [t.lower() for t in SimpleProxyTypes]:
            objType = 'clothes'
        objType = objType.lower()

        if proxy and objType != 'skins':
            subPath = None
        else:
            subPath = objType

        # General paths
        if subPath:
            paths = [
                mh.getPath(os.path.join('data', subPath)),
                mh.getSysDataPath(subPath)
            ]
            for p in paths:
                if getpath.isSubPath(p,
                                     mh.getPath()) and not os.path.exists(p):
                    os.makedirs(p)
        else:
            paths = []

        # Global material paths
        for p in [
                mh.getPath(os.path.join('data', objType, 'materials')),
                mh.getSysDataPath(os.path.join(objType, 'materials'))
        ]:
            if os.path.isdir(p):
                paths.append(p)

        # Path where proxy file is located
        if proxy:
            dirname = os.path.abspath(os.path.dirname(proxy.file))
            parent = os.path.abspath(os.path.join(dirname, '..'))
            asset_basename = os.path.basename(dirname)
            asset_parentbase = os.path.basename(parent)
            user_parent_base = getpath.getDataPath(asset_parentbase)
            user_asset_final = os.path.abspath(
                os.path.join(user_parent_base, asset_basename))
            paths = [dirname, user_asset_final] + paths

        return paths
Esempio n. 9
0
        print("All done.")
        sys.exit()

    # Get contents from FTP
    newContents = getFTPContents(ftp)

    destinationFolder = getSysDataPath()
    toDownload = getNewFiles(oldContents, newContents, destinationFolder)
    toRemove = getRemovedFiles(oldContents, newContents, destinationFolder)

    # Remove files removed on FTP
    for filePath in toRemove:
        filename = os.path.join(destinationFolder, filePath.lstrip('/'))

        if not isSubPath(filename, destinationFolder):
            raise RuntimeError(
                "ERROR: File destinations are jailed inside the sys data path (%s), destination path (%s) tries to escape!"
                % (destinationFolder, filename))

        if DONTREMOVE:
            newFile = filename + '.removedasset'
            i = 0
            while os.path.isfile(newFile):
                newFile = filename + '.' + str(i) + '.removedasset'
                i = i + 1
            shutil.move(filename, newFile)
            print("Moved removed file to %s (removed from FTP)" % newFile)
        else:
            print("Removing file %s (removed from FTP)" % filename)
            os.remove(filename)
 def isSubPath(self, subpath, path):
     """
     Determines whether subpath is a sub-path of path, returns True if it is.
     """
     import getpath
     return getpath.isSubPath(subpath, path)
Esempio n. 11
0
 def isSubPath(self, subpath, path):
     """
     Determines whether subpath is a sub-path of path, returns True if it is.
     """
     import getpath
     return getpath.isSubPath(subpath, path)
Esempio n. 12
0
        print "All done."
        sys.exit()

    # Get contents from FTP
    newContents = getFTPContents(ftp)

    destinationFolder = getSysDataPath()
    toDownload = getNewFiles(oldContents, newContents, destinationFolder)
    toRemove = getRemovedFiles(oldContents, newContents, destinationFolder)

    # Remove files removed on FTP
    for filePath in toRemove:
        filename = os.path.join(destinationFolder, filePath.lstrip('/'))

        if not isSubPath(filename, destinationFolder):
            raise RuntimeError("ERROR: File destinations are jailed inside the sys data path (%s), destination path (%s) tries to escape!" % (destinationFolder, filename))

        if DONTREMOVE:
            newFile = filename + '.removedasset'
            i = 0
            while os.path.isfile(newFile):
                newFile = filename + '.' + str(i) + '.removedasset'
                i = i+1
            shutil.move(filename, newFile)
            print "Moved removed file to %s (removed from FTP)" % newFile
        else:
            print "Removing file %s (removed from FTP)" % filename
            os.remove(filename)

    TOTAL_FILES = len(toDownload)
Esempio n. 13
0
def loadMesh(path, loadColors=1, maxFaces=None, obj=None):
    """
    This function loads the specified mesh object into internal MakeHuman data 
    structures, and returns it. The loaded file should be in Wavefront OBJ 
    format.
    
    Parameters:
    -----------
   
    path:     
      *String*.  The file system path to the file containing the object to load.

    Note: loadColors is currently unused

    maxFaces:
      *uint* Number of faces per vertex (pole), None for default (min 4)
    """
    if type(path) is bytes:
        path = path.decode('utf-8')
    log.debug("loadMesh in files3d received a raw path of %s", path)
    name = os.path.basename(path)
    if isinstance(name, bytes):
        name.decode('utf-8')
    log.debug("os.path.basename produce a name of: %s", name)
    log.debug("files3d loadMesh basename is %s", name)
    if obj is None:
        obj = module3d.Object3D(os.path.splitext(path)[0])
        log.message("obj name changed from None to %s",
                    module3d.Object3D(name))
    if maxFaces:
        obj.MAX_FACES = maxFaces

    obj.path = path

    try:
        import getpath
        path = getpath.getSysPath(path)
        log.message("Expanded path is found to be %s", path)
        npzpath = os.path.splitext(path)[0] + '.npz'

        log.debug("files3d loadMesh will attempt to load %s", npzpath)

        if not os.path.isfile(npzpath):
            log.message('compiled file missing: %s', npzpath)
            raise RuntimeError('compiled file missing: %s', npzpath)
        if os.path.isfile(
                path) and os.path.getmtime(path) > os.path.getmtime(npzpath):
            log.message('compiled file out of date: %s', npzpath)
            raise RuntimeError('compiled file out of date: %s', npzpath)
        loadBinaryMesh(obj, npzpath)

        log.message("files3d loadMesh attempting to load %s", npzpath)
        loadTextMesh(obj, path)
        if isSubPath(npzpath, getPath('')):
            # Only write compiled binary meshes to user data path
            saveBinaryMesh(obj, npzpath)
            log.debug('files3d just saved compiled mesh: %s', npzpath)
        else:
            log.debug("files3d using getpath('') could not find (%s).",
                      npzpath)
    except:
        log.error('Unable to load obj file: %s', path, exc_info=True)
        return False

    return obj