예제 #1
0
    def __init__(self, scale=1.0):
        import files3d
        import getpath
        module3d.Object3D.__init__(self, 'axis', 4)
        files3d.loadMesh(getpath.getSysDataPath('3dobjs/axis.obj'),
                         maxFaces=4,
                         obj=self)

        for fg_name in self.getFaceGroups():
            if 'red' in fg_name.lower():
                self.color[self.getVerticesForGroups([fg_name
                                                      ])] = [255, 0, 0, 255]
            elif 'green' in fg_name.lower():
                self.color[self.getVerticesForGroups([fg_name
                                                      ])] = [0, 255, 0, 255]
            elif 'blue' in fg_name.lower():
                self.color[self.getVerticesForGroups([fg_name
                                                      ])] = [0, 0, 255, 255]

        self.markCoords(colr=True)
        self.sync_color()

        if scale != 1.0:
            self.coord[:] *= float(scale)
            self.markCoords(coor=True)
            self.sync_coord()
예제 #2
0
    def loadMeshAndObject(self, human):
        import files3d
        import guicommon
        import getpath
        
        import inspect  # temp code to log calling routines
        log.debug("loadMeshAndObject called by: %s", inspect.stack()[1][3])
        
        name = self.obj_file
        if isinstance(name, bytes):
            name = name.decode('utf-8')
                                  
        name = getpath.getSysPath(name)
        mesh = files3d.loadMesh(name, maxFaces = self.max_pole)
        if not mesh:
            log.error("loadMeshAndObject failed to load %s", name)
            log.error("The meshname is %s", name)

        log.debug("Now the path has been extended to %s", name)
        mesh.priority = self.z_depth           # Set render order
        mesh.setCameraProjection(0)             # Set to model camera

        obj = self.object = guicommon.Object(mesh, human.getPosition())
        obj.proxy = self
        obj.material = self.material
        obj.setRotation(human.getRotation())
        obj.setSolid(human.solid)    # Set to wireframe if human is in wireframe
        # TODO perhaps other properties should be copied from human to object, such as subdivision state. For other hints, and duplicate code, see guicommon Object.setProxy()

        # TODO why return both obj and mesh if you can access the mesh easily through obj.mesh?
        return mesh,obj
예제 #3
0
def defineGlobals():
    global theLandMarks, theBaseObjectVerts, theRefObjects

    theLandMarks = {}
    folder = "data/landmarks"
    for file in os.listdir(folder):
        (name, ext) = os.path.splitext(file)
        if ext != ".lmk":
            continue
        path = os.path.join(folder, file)
        with open(path, "r") as fp:
            landmark = []
            for line in fp:
                words = line.split()
                if len(words) > 0:
                    m = int(words[0])
                    landmark.append(m)

        theLandMarks[name] = landmark

    obj = files3d.loadMesh("data/3dobjs/base.obj")
    theBaseObjectVerts = [v.co for v in obj.verts]

    theRefObjects = {}
    for race in ["african", "asian", "neutral"]:
        for gender in ["female", "male"]:
            for age in ["child", "young", "old"]:
                path = "data/targets/macrodetails/%s-%s-%s.target" % (race, gender, age)
                theRefObjects[path] = readTarget(path)
예제 #4
0
파일: gui3d.py 프로젝트: RuliLG/makehuman
 def setProxy(self, proxy):
 
     if self.proxy:
     
         self.proxy = None
         self.__proxyMesh.clear()
         self.__proxyMesh = None
         if self.__proxySubdivisionMesh:
             self.__proxySubdivisionMesh.clear()
             self.__proxySubdivisionMesh = None
         self.mesh = self.__seedMesh
         self.mesh.setVisibility(1)
 
     if proxy:
     
         self.proxy = proxy
         
         (folder, name) = proxy.obj_file
         
         self.__proxyMesh = files3d.loadMesh(os.path.join(folder, name))
         for attr in ('x', 'y', 'z', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz',
                      'visibility', 'shadeless', 'pickable', 'cameraMode', 'texture'):
             setattr(self.__proxyMesh, attr, getattr(self.mesh, attr))
         
         self.__proxyMesh.object = self.mesh.object
         
         self.proxy.update(self.__proxyMesh, self.__seedMesh)
         
         if self.__seedMesh.object3d:
             self.attachMesh(self.__proxyMesh)
         
         self.mesh.setVisibility(0)
         self.mesh = self.__proxyMesh
         self.mesh.setVisibility(1)
예제 #5
0
    def setProxy(self, proxy):

        if self.proxy:

            self.proxy = None
            self.__proxyMesh.clear()
            self.__proxyMesh = None
            if self.__proxySubdivisionMesh:
                self.__proxySubdivisionMesh.clear()
                self.__proxySubdivisionMesh = None
            self.mesh = self.__seedMesh
            self.mesh.setVisibility(1)

        if proxy:

            self.proxy = proxy

            (folder, name) = proxy.obj_file

            self.__proxyMesh = files3d.loadMesh(os.path.join(folder, name))
            for attr in ('x', 'y', 'z', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz',
                         'visibility', 'shadeless', 'pickable', 'cameraMode',
                         'texture'):
                setattr(self.__proxyMesh, attr, getattr(self.mesh, attr))

            self.__proxyMesh.object = self.mesh.object

            self.proxy.update(self.__proxyMesh, self.__seedMesh)

            if self.__seedMesh.object3d:
                self.attachMesh(self.__proxyMesh)

            self.mesh.setVisibility(0)
            self.mesh = self.__proxyMesh
            self.mesh.setVisibility(1)
예제 #6
0
    def loadHuman(self):

        self.progress(0.1)
        #hairObj = hair.loadHairsFile(self.scene3d, path="./data/hairs/default", update = False)
        #self.scene3d.clear(hairObj)
        self.selectedHuman = self.addObject(
            human.Human(files3d.loadMesh("data/3dobjs/base.obj")))
예제 #7
0
    def loadHuman(self):
        self.progress(0.1)

        # Set a lower than default MAX_FACES value because we know the human has a good topology (will make it a little faster)
        # (we do not lower the global limit because that would limit the selection of meshes that MH would accept too much)
        mesh = files3d.loadMesh(mh.getSysDataPath("3dobjs/base.obj"), maxFaces = 5)
        humanModel = human.Human(mesh)
        self.selectedHuman = self.addObject(humanModel)
예제 #8
0
def getHuman():
    with mhpath:
        thuman = Human(
            files3d.loadMesh(getpath.getSysDataPath("3dobjs/base.obj"),
                             maxFaces=5))
        humanmodifier.mods_loaded = False
        modifiers = humanmodifier.loadModifiers(
            getpath.getSysDataPath('modifiers/modeling_modifiers.json'),
            thuman)
    return thuman
예제 #9
0
    def __init__(self, scale=1.0):
        import files3d
        import getpath
        module3d.Object3D.__init__(self, 'axis', 4)
        files3d.loadMesh(getpath.getSysDataPath('3dobjs/axis.obj'), maxFaces=4, obj=self)

        for fg_name in self.getFaceGroups():
            if 'red' in fg_name.lower():
                self.color[self.getVerticesForGroups([fg_name])] = [255, 0, 0, 255]
            elif 'green' in fg_name.lower():
                self.color[self.getVerticesForGroups([fg_name])] = [0, 255, 0, 255]
            elif 'blue' in fg_name.lower():
                self.color[self.getVerticesForGroups([fg_name])] = [0, 0, 255, 255]

        self.markCoords(colr=True)
        self.sync_color()

        if scale != 1.0:
            self.coord[:] *= float(scale)
            self.markCoords(coor=True)
            self.sync_coord()
예제 #10
0
 def getHuman(self):
     """Load a human model with modifiers."""
     with self.mhpath:
         # maxFaces *uint* Number of faces per vertex (pole), None for default (min 4)
         human = Human(
             files3d.loadMesh(getpath.getSysDataPath("3dobjs/base.obj"),
                              maxFaces=5))
         # load modifiers onto human
         humanmodifier.mods_loaded = False
         modifiers = humanmodifier.loadModifiers(
             getpath.getSysDataPath('modifiers/modeling_modifiers.json'),
             human)
         return human
예제 #11
0
 def createHuman(self, key, model='base.npz'):
     '''
     Creates a Human model and adds it to
     self.selected_humans[key],
     models are stored in data/3dobjs/
     '''
     model_path = './data/3dobjs/%s' % model
     h = human.Human(files3d.loadMesh(model_path,
                                      maxFaces=5))
     self.ZThumans[key] = ZThuman(h, self, key)
     self.loadMacroTargets(h)
     h.applyAllTargets()
     return self.ZThumans[key]
예제 #12
0
    def setHair(self, human, mhclo):
        self.filechooser.selectItem(mhclo)

        if human.hairObj:
            gui3d.app.removeObject(human.hairObj)
            human.hairObj = None
            human.hairProxy = None

        if os.path.basename(mhclo) == "clear.mhclo":
            return
            
        human.hairProxy = mh2proxy.readProxyFile(human.meshData, mhclo)
        human.hairProxy.type = 'Hair'
        if not human.hairProxy:
            log.error("Failed to load %s", mhclo)
            return

        obj = human.hairProxy.obj_file
        obj = os.path.join(obj[0], obj[1])
        mesh = files3d.loadMesh(obj)
        if not mesh:
            log.error("Failed to load %s", obj)
            return
        if human.hairProxy.texture:
            (folder, name) = human.hairProxy.texture
            tex = os.path.join(folder, name)
            mesh.setTexture(tex)
        else:
            tex = obj.replace('.obj', '_texture.png')
            mesh.setTexture(tex)

        human.hairObj = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
        human.hairObj.setRotation(human.getRotation())
        human.hairObj.mesh.setCameraProjection(0)
        human.hairObj.mesh.setSolid(human.mesh.solid)
        if human.hairProxy.cull:
            human.hairObj.mesh.setCull(1)
        else:
            human.hairObj.mesh.setCull(None)
        human.hairObj.mesh.setTransparentPrimitives(len(human.hairObj.mesh.fvert))
        human.hairObj.mesh.priority = 20

        hairName = human.hairObj.mesh.name.split('.')[0]

        self.adaptHairToHuman(human)
        human.hairObj.setSubdivided(human.isSubdivided())
예제 #13
0
    def setEyes(self, human, mhclo):
        self.filechooser.selectItem(mhclo)

        if human.eyesObj:
            gui3d.app.removeObject(human.eyesObj)
            human.eyesObj = None
            human.eyesProxy = None

        if os.path.basename(mhclo) == "clear.mhclo":
            return

        human.eyesProxy = mh2proxy.readProxyFile(human.meshData, mhclo, type="Eyes", layer=3)
        if not human.eyesProxy:
            log.error("Failed to load %s", mhclo)
            return

        obj = human.eyesProxy.obj_file
        #obj = os.path.join(obj[0], obj[1])
        mesh = files3d.loadMesh(obj)
        if not mesh:
            log.error("Failed to load %s", obj)
            return

        mesh.material = human.eyesProxy.material

        human.eyesObj = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
        human.eyesObj.setRotation(human.getRotation())
        human.eyesObj.mesh.setCameraProjection(0)
        human.eyesObj.mesh.setSolid(human.mesh.solid)
        if human.eyesProxy.cull:
            human.eyesObj.mesh.setCull(1)
        else:
            human.eyesObj.mesh.setCull(None)
        # Enabling this causes render-que order issues so that eyes render over hair
        # Disabling it renders hi-poly eyes wrong
        if human.eyesProxy.transparent:
            human.eyesObj.mesh.setTransparentPrimitives(len(human.eyesObj.mesh.fvert))
        else:
            human.eyesObj.mesh.setTransparentPrimitives(0)
        human.eyesObj.mesh.priority = 5

        eyesName = human.eyesObj.mesh.name.split('.')[0]

        self.adaptEyesToHuman(human)
        human.eyesObj.setSubdivided(human.isSubdivided())
예제 #14
0
    def loadMeshAndObject(self, human):
        import files3d
        import guicommon

        mesh = files3d.loadMesh(self.obj_file, maxFaces=self.max_pole)
        if not mesh:
            log.error("Failed to load %s", self.obj_file)

        mesh.priority = self.z_depth  # Set render order
        mesh.setCameraProjection(0)  # Set to model camera

        obj = self.object = guicommon.Object(mesh, human.getPosition())
        obj.proxy = self
        obj.material = self.material
        obj.setRotation(human.getRotation())
        obj.setSolid(human.solid)  # Set to wireframe if human is in wireframe
        # TODO perhaps other properties should be copied from human to object, such as subdivision state. For other hints, and duplicate code, see guicommon Object.setProxy()

        # TODO why return both obj and mesh if you can access the mesh easily through obj.mesh?
        return mesh, obj
예제 #15
0
    def loadMeshAndObject(self, human):
        import files3d
        import guicommon

        mesh = files3d.loadMesh(self.obj_file, maxFaces = self.max_pole)
        if not mesh:
            log.error("Failed to load %s", self.obj_file)

        mesh.priority = self.z_depth           # Set render order
        mesh.setCameraProjection(0)             # Set to model camera

        obj = self.object = guicommon.Object(mesh, human.getPosition())
        obj.proxy = self
        obj.material = self.material
        obj.setRotation(human.getRotation())
        obj.setSolid(human.solid)    # Set to wireframe if human is in wireframe
        # TODO perhaps other properties should be copied from human to object, such as subdivision state. For other hints, and duplicate code, see guicommon Object.setProxy()

        # TODO why return both obj and mesh if you can access the mesh easily through obj.mesh?
        return mesh,obj
예제 #16
0
    def setProxy(self, proxy):
        isSubdivided = self.isSubdivided()

        if self.proxy:
            # Copy proxy mesh material settings back to original mesh
            self.__seedMesh.material = self.mesh.material
            self.proxy = None
            self.detachMesh(self.__proxyMesh)
            self.__proxyMesh.clear()
            self.__proxyMesh = None
            if self.__proxySubdivisionMesh:
                self.detachMesh(self.__proxySubdivisionMesh)
                self.__proxySubdivisionMesh.clear()
                self.__proxySubdivisionMesh = None
            self.mesh = self.__seedMesh
            self.mesh.setVisibility(1)

        if proxy:
            import files3d
            self.proxy = proxy
            self.__proxyMesh = files3d.loadMesh(proxy.obj_file)
            for attr in ('x', 'y', 'z', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz',
                         'visibility', 'shadeless', 'pickable', 'cameraMode',
                         'material'):
                setattr(self.__proxyMesh, attr, getattr(self.mesh, attr))

            self.__proxyMesh.object = self.mesh.object

            self.proxy.update(self.__proxyMesh)

            if self.__seedMesh.object3d:
                self.attachMesh(self.__proxyMesh)

            self.mesh.setVisibility(0)
            self.mesh = self.__proxyMesh
            self.mesh.setVisibility(1)
            self.__proxyMesh.setSolid(self.__seedMesh.solid)

        self.setSubdivided(isSubdivided)
예제 #17
0
    def setProxy(self, proxy):
        isSubdivided = self.isSubdivided()

        if self.proxy:
            # Copy proxy mesh material settings back to original mesh
            self.__seedMesh.material = self.mesh.material
            self.proxy = None
            self.detachMesh(self.__proxyMesh)
            self.__proxyMesh.clear()
            self.__proxyMesh = None
            if self.__proxySubdivisionMesh:
                self.detachMesh(self.__proxySubdivisionMesh)
                self.__proxySubdivisionMesh.clear()
                self.__proxySubdivisionMesh = None
            self.mesh = self.__seedMesh
            self.mesh.setVisibility(1)

        if proxy:
            self.proxy = proxy
            self.__proxyMesh = files3d.loadMesh(proxy.obj_file)
            for attr in ('x', 'y', 'z', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz',
                         'visibility', 'shadeless', 'pickable', 'cameraMode', 'material'):
                setattr(self.__proxyMesh, attr, getattr(self.mesh, attr))

            self.__proxyMesh.object = self.mesh.object

            self.proxy.update(self.__proxyMesh)

            if self.__seedMesh.object3d:
                self.attachMesh(self.__proxyMesh)

            self.mesh.setVisibility(0)
            self.mesh = self.__proxyMesh
            self.mesh.setVisibility(1)
            self.__proxyMesh.setSolid(self.__seedMesh.solid)

        self.setSubdivided(isSubdivided)
    def setHair(self, human, obj, mhclo):

        if human.hairObj:
            gui3d.app.removeObject(human.hairObj)
            human.hairObj = None
            human.hairProxy = None

        if os.path.basename(obj) == "clear.obj":
            return
            
        mesh = files3d.loadMesh(obj)
        if mesh:
            human.hairProxy = mh2proxy.readProxyFile(human.meshData, mhclo, False)
            if human.hairProxy.texture:
                (folder, name) = human.hairProxy.texture
                tex = os.path.join(folder, name)
                mesh.setTexture(tex)
            else:
                tex = obj.replace('.obj', '_texture.png')
                mesh.setTexture(tex)

            human.hairObj = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
            human.hairObj.setRotation(human.getRotation())
            human.hairObj.mesh.setCameraProjection(0)
            human.hairObj.mesh.setSolid(human.mesh.solid)
            if human.hairProxy.cull:
                human.hairObj.mesh.setCull(1)
            else:
                human.hairObj.mesh.setCull(None)
            human.hairObj.mesh.setTransparentPrimitives(len(human.hairObj.mesh.faces))
            human.hairObj.mesh.priority = 20
                
            hairName = human.hairObj.mesh.name.split('.')[0]

            self.adaptHairToHuman(human)
            human.hairObj.setSubdivided(human.isSubdivided())
예제 #19
0
    def selectProxy(self, mhclofile):
        """
        Called when a new proxy has been selected.
        If this library selects only a single proxy, specifying None as
        mhclofile parameter will deselect the current proxy and set the selection
        to "none".
        If this library allows selecting multiple proxies, specifying None as
        mhclofile will have no effect.
        """
        if not mhclofile:
            if self.multiProxy:
                return
            else:
                self.deselectProxy(None)
                return

        log.message('Selecting proxy file "%s" from %s library.', mhclofile,
                    self.proxyName)
        human = self.human

        proxy = None
        mhcloId = getpath.canonicalPath(mhclofile)
        if mhcloId in self._proxyCache:
            proxy = self._proxyCache[mhcloId]
            if proxy.mtime < os.path.getmtime(mhclofile):
                proxy = None

        if not proxy:
            proxy = mh2proxy.readProxyFile(human.meshData,
                                           mhclofile,
                                           type=self.proxyName.capitalize())
            self._proxyCache[mhcloId] = proxy

        if proxy.uuid in [p.uuid for p in self.getSelection()]:
            log.debug(
                "Proxy with UUID %s (%s) already loaded in %s library. Skipping.",
                proxy.uuid, proxy.file, self.proxyName)
            return

        if not self.multiProxy and self.isProxySelected():
            # Deselect previously selected proxy
            self.deselectProxy(None, suppressSignal=True)

        mesh = files3d.loadMesh(proxy.obj_file, maxFaces=proxy.max_pole)
        if not mesh:
            log.error("Failed to load %s", proxy.obj_file)
            return

        self.filechooser.selectItem(mhclofile)

        mesh.material = proxy.material
        mesh.priority = proxy.z_depth  # Set render order
        mesh.setCameraProjection(0)  # Set to model camera
        mesh.setSolid(
            human.mesh.solid)  # Set to wireframe if human is in wireframe

        obj = gui3d.Object(mesh, self.human.getPosition())
        obj.setRotation(human.getRotation())
        gui3d.app.addObject(obj)

        self.adaptProxyToHuman(proxy, obj)
        obj.setSubdivided(
            human.isSubdivided())  # Copy subdivided state of human

        # Add to selection
        self.selectedProxies.append(proxy)
        self.proxyObjects.append(obj)

        self.filechooser.selectItem(mhclofile)

        self.proxySelected(proxy, obj)

        self.signalChange()
예제 #20
0
    name = os.path.basename(path)

    try:
        npzpath = os.path.splitext(path)[0] + '.mhpxy'
        try:
            proxy_ = proxy.loadTextProxy(human, path, type=None)
        except:
            print 'Could not load proxy file %s.' % path
            import traceback
            traceback.print_exc(file=sys.stdout)
            return False
        proxy.saveBinaryProxy(proxy_, npzpath)
    except:
        print 'Unable to save compiled proxy for file %s' % path
        #import traceback
        #traceback.print_exc(file=sys.stdout)
        return False
        
    return True


if __name__ == '__main__':
    human = Human(files3d.loadMesh(getSysDataPath("3dobjs/base.obj")))
    allFiles = getAllFiles('data', ['*.mhclo', '*.proxy'])
    for allProxies in allFiles:
        for (i, path) in enumerate(allProxies):
            compileProxy(path, human)
            print "[%.0f%% done] converted proxy %s" % (100*(float(i)/float(len(allProxies))), path)

    print "All done."
    def setClothes(self, human, filepath):
        if os.path.basename(filepath) == "clear.mhclo":
            for name,clo in human.clothesObjs.items():
                gui3d.app.removeObject(clo)
                del human.clothesObjs[name]
            self.clothesList = []
            human.activeClothing = None
            return

        proxy = mh2proxy.readProxyFile(human.meshData, filepath, False)
        
        if not proxy:
            return

        uuid = proxy.getUuid()
        
        # For loading costumes (sets of individual clothes)
        if proxy.clothings:
            t = 0
            dt = 1.0/len(proxy.clothings)
            for (pieceName, uuid) in proxy.clothings:
                gui3d.app.progress(t, text="Loading %s" % pieceName)
                t += dt
                mhclo = export_config.getExistingProxyFile(pieceName+".mhclo", uuid, "clothes")
                if mhclo:
                    self.setClothes(human, mhclo)
                else:
                    log.warning("Could not load clothing %s", pieceName)
            gui3d.app.progress(1, text="%s loaded" % proxy.name)
            # Load custom textures
            for (uuid, texPath) in proxy.textures:
                if not uuid in human.clothesObjs.keys():
                    log.warning("Cannot override texture for clothing piece with uuid %s!" % uuid)
                    continue
                pieceProxy = human.clothesProxies[uuid]
                if not os.path.dirname(texPath):
                    pieceProxy = human.clothesProxies[uuid]
                    clothesPath = os.path.dirname(pieceProxy.file)
                    texPath = os.path.join(clothesPath, texPath)
                log.debug("Overriding texture for clothpiece %s to %s", uuid, texPath)
                clo = human.clothesObjs[uuid]
                clo.mesh.setTexture(texPath)
            # Apply overridden transparency setting to pieces of a costume
            for (uuid, isTransparent) in proxy.transparencies.items():
                if not uuid in human.clothesProxies.keys():
                    log.warning("Could not override transparency for object with uuid %s!" % uuid)
                    continue
                clo = human.clothesObjs[uuid]
                log.debug("Overriding transparency setting for clothpiece %s to %s", uuid, bool(proxy.transparencies[uuid]))
                if proxy.transparencies[uuid]:
                    clo.mesh.setTransparentPrimitives(len(clo.mesh.faces))
                else:
                    clo.mesh.setTransparentPrimitives(0)
            return
            
        #folder = os.path.dirname(filepath)
        (folder, name) = proxy.obj_file
        obj = os.path.join(folder, name)

        try:
            clo = human.clothesObjs[uuid]
        except:
            clo = None
        if clo:
            gui3d.app.removeObject(clo)
            del human.clothesObjs[uuid]
            self.clothesList.remove(uuid)
            if human.activeClothing == uuid:
                human.activeClothing = None
            log.message("Removed clothing %s %s", proxy.name, uuid)
            return

        mesh = files3d.loadMesh(obj)
        if not mesh:
            log.error("Could not load mesh for clothing object %s", proxy.name)
            return
        if proxy.texture:
            (dir, name) = proxy.texture
            tex = os.path.join(folder, name)
            if not os.path.exists(tex):
                tex = os.path.join(self.systemClothes, "textures", name)
            mesh.setTexture(tex)
        else:
            pass
        
        clo = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
        clo.setRotation(human.getRotation())
        clo.mesh.setCameraProjection(0)
        clo.mesh.setSolid(human.mesh.solid)
        if proxy.cull:
            clo.mesh.setCull(1)
        else:
            clo.mesh.setCull(None)
        if proxy.transparent:
            clo.mesh.setTransparentPrimitives(len(clo.mesh.faces))
        else:
            clo.mesh.setTransparentPrimitives(0)
        clo.mesh.priority = 10
        human.clothesObjs[uuid] = clo        
        human.clothesProxies[uuid] = proxy
        human.activeClothing = uuid
        self.clothesList.append(uuid)
        
        for tag in proxy.tags:
            tag = tag.lower()
            if tag in KnownTags:
                try:
                    oldUuids = self.taggedClothes[tag]
                except KeyError:
                    oldUuids = []
                newUuids = []
                for oldUuid in oldUuids:
                    if oldUuid == uuid:
                        pass
                    elif True:
                        try:
                            oldClo = human.clothesObjs[oldUuid]
                        except KeyError:
                            continue
                        log.message("Removed clothing %s", oldUuid)
                        gui3d.app.removeObject(oldClo)
                        del human.clothesObjs[oldUuid]
                        self.clothesList.remove(oldUuid)
                        if human.activeClothing == oldUuid:
                            human.activeClothing = None
                    else:
                        log.message("Kept clothing %s", oldUuid)
                        newUuids.append(oldUuid)
                newUuids.append(uuid)
                self.taggedClothes[tag] = newUuids

        self.adaptClothesToHuman(human)
        clo.setSubdivided(human.isSubdivided())
예제 #22
0
파일: clmh.py 프로젝트: yshshrm/RenderMe
import os
from pandas import read_pickle
import makehuman
makehuman.set_sys_path()
import human
import files3d
import wavefront
import humanmodifier

import json
from pybetaface import api

humanoid = human.Human(files3d.loadMesh(human.getSysDataPath("3dobjs/base.obj")))

genmod = humanmodifier.MacroModifier('macrodetails','Gender')
agemod = humanmodifier.MacroModifier('macrodetails','Age')
musclemod = humanmodifier.MacroModifier('macrodetails-universal','Muscle')
weightmod = humanmodifier.MacroModifier('macrodetails-universal','Weight')
heightmod = humanmodifier.MacroModifier('macrodetails-height','Height')
body_proportionmod = humanmodifier.MacroModifier('macrodetails-proportions', 'BodyProportions')
africanmod = humanmodifier.MacroModifier('macrodetails','African')
asianmod = humanmodifier.MacroModifier('macrodetails','Asian')
caucasianmod = humanmodifier.MacroModifier('macrodetails','Caucasian')


heightmod.setHuman(humanoid)
agemod.setHuman(humanoid)
genmod.setHuman(humanoid)
weightmod.setHuman(humanoid)
musclemod.setHuman(humanoid)
body_proportionmod.setHuman(humanoid)
	log = logDummy()

	class appDummy:
		def __init__(self, human):
			self.selectedHuman = human
			self.splash = splashDummy()
			self.log_window = log_windowDummy()
			self.statusBar = None
			self.progress = None
		def addLogMessage(self, arg1, arg2):
			"Noop"
		


	buddy = human.Human(files3d.loadMesh(mh.getSysDataPath("3dobjs/base.obj"), maxFaces = 5))
	G.app = appDummy(buddy)
	base_skel = skeleton.load(mh.getSysDataPath('rigs/default.mhskel'), buddy.meshData)
	buddy.setBaseSkeleton(base_skel)

	import humanmodifier
	humanmodifier.loadModifiers("data/modifiers/modeling_modifiers.json", buddy)
	import proxy
	print os.getcwd()
	sys.stdout = stdout
	buddyProxy = proxy.loadProxy(buddy, os.path.join(os.getcwd(), 'data', 'eyes', 'low-poly', 'low-poly'), 'Eyes')
	print
	mesh, obj = buddyProxy.loadMeshAndObject(buddy)
	print
	
	buddy.setEyesProxy(buddyProxy)
예제 #24
0
    def loadHuman(self):

        self.progress(0.1)
        #hairObj = hair.loadHairsFile(self.scene3d, path="./data/hairs/default", update = False)
        #self.scene3d.clear(hairObj)
        self.selectedHuman = self.addObject(human.Human(files3d.loadMesh("data/3dobjs/base.obj")))
예제 #25
0
    def setClothes(self, human, filepath):
        if os.path.basename(filepath) == "clear.mhclo":
            for name,clo in human.clothesObjs.items():
                gui3d.app.removeObject(clo)
                del human.clothesObjs[name]
            human.clothesProxies = {}
            self.clothesList = []
            human.activeClothing = None
            self.updateFaceMasks(self.faceHidingTggl.selected)
            return

        if filepath not in self.cache:
            proxy = mh2proxy.readProxyFile(human.meshData, filepath)
            proxy.type = 'Clothes'
            self.cache[filepath] = proxy
            proxy.toggleEnabled = False
        else:
            proxy = self.cache[filepath]

        if not proxy:
            return

        uuid = proxy.getUuid()

        # TODO costumes should go in a separate library
        '''
        # For loading costumes (sets of individual clothes)
        if proxy.clothings:
            t = 0
            dt = 1.0/len(proxy.clothings)
            folder = os.path.dirname(filepath)
            for (pieceName, uuid) in proxy.clothings:
                gui3d.app.progress(t, text="Loading %s" % pieceName)
                t += dt
                piecePath = os.path.join(folder, pieceName+".mhclo")
                mhclo = exportutils.config.getExistingProxyFile(piecePath, uuid, "clothes")
                if mhclo:
                    self.setClothes(human, mhclo)
                else:
                    log.warning("Could not load clothing %s", pieceName)
            gui3d.app.progress(1, text="%s loaded" % proxy.name)
            # Load custom textures
            for (uuid, texPath) in proxy.textures:
                if not uuid in human.clothesObjs.keys():
                    log.warning("Cannot override texture for clothing piece with uuid %s!" % uuid)
                    continue
                pieceProxy = human.clothesProxies[uuid]
                if not os.path.dirname(texPath):
                    pieceProxy = human.clothesProxies[uuid]
                    clothesPath = os.path.dirname(pieceProxy.file)
                    texPath = os.path.join(clothesPath, texPath)
                log.debug("Overriding texture for clothpiece %s to %s", uuid, texPath)
                clo = human.clothesObjs[uuid]
                clo.mesh.setTexture(texPath)
            # Apply overridden transparency setting to pieces of a costume
            for (uuid, isTransparent) in proxy.transparencies.items():
                if not uuid in human.clothesProxies.keys():
                    log.warning("Could not override transparency for object with uuid %s!" % uuid)
                    continue
                clo = human.clothesObjs[uuid]
                log.debug("Overriding transparency setting for clothpiece %s to %s", uuid, bool(proxy.transparencies[uuid]))
                if proxy.transparencies[uuid]:
                    clo.mesh.setTransparentPrimitives(len(clo.mesh.fvert))
                else:
                    clo.mesh.setTransparentPrimitives(0)
            return
        '''

        #folder = os.path.dirname(filepath)
        (folder, name) = proxy.obj_file
        obj = os.path.join(folder, name)

        try:
            clo = human.clothesObjs[uuid]
        except:
            clo = None
        if clo:
            gui3d.app.removeObject(clo)
            del human.clothesObjs[uuid]
            self.clothesList.remove(uuid)
            if human.activeClothing == uuid:
                human.activeClothing = None
            proxy = human.clothesProxies[uuid]
            del human.clothesProxies[uuid]
            self.updateFaceMasks(self.faceHidingTggl.selected)
            self.filechooser.deselectItem(proxy.file)
            log.message("Removed clothing %s %s", proxy.name, uuid)
            return

        if obj not in self.meshCache:
            mesh = files3d.loadMesh(obj)
            self.meshCache[obj] = mesh
        else:
            mesh = self.meshCache[obj]
        if not mesh:
            log.error("Could not load mesh for clothing object %s", proxy.name)
            return
        if proxy.texture:
            (dir, name) = proxy.texture
            tex = os.path.join(folder, name)
            if not os.path.exists(tex):
                tex = os.path.join(self.systemClothes, "textures", name)
            mesh.setTexture(tex)
        
        clo = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
        clo.setRotation(human.getRotation())
        clo.mesh.setCameraProjection(0)
        clo.mesh.setSolid(human.mesh.solid)
        if proxy.cull:
            clo.mesh.setCull(1)
        else:
            clo.mesh.setCull(None)
        if proxy.transparent:
            clo.mesh.setTransparentPrimitives(len(clo.mesh.fvert))
        else:
            clo.mesh.setTransparentPrimitives(0)
        clo.mesh.priority = 10
        human.clothesObjs[uuid] = clo        
        human.clothesProxies[uuid] = proxy
        human.activeClothing = uuid
        self.clothesList.append(uuid)

        # TODO Disabled until conflict with new filechooser is sorted out
        '''
        for tag in proxy.tags:
            tag = tag.lower()
            # Allow only one piece of clothing per known tag
            if tag in KnownTags:
                try:
                    oldUuids = self.taggedClothes[tag]
                except KeyError:
                    oldUuids = []
                newUuids = []
                for oldUuid in oldUuids:
                    if oldUuid == uuid:
                        pass
                    elif True:  # TODO use parameter here
                        try:
                            oldClo = human.clothesObjs[oldUuid]
                        except KeyError:
                            continue
                        gui3d.app.removeObject(oldClo)
                        del human.clothesObjs[oldUuid]
                        self.clothesList.remove(oldUuid)
                        if human.activeClothing == oldUuid:
                            human.activeClothing = None
                        log.message("Removed clothing %s with known tag %s", oldUuid, tag)
                    else:
                        log.message("Kept clothing %s with known tag %s", oldUuid, tag)
                        newUuids.append(oldUuid)
                newUuids.append(uuid)
                self.taggedClothes[tag] = newUuids
        '''

        self.adaptClothesToHuman(human)
        clo.setSubdivided(human.isSubdivided())
        
        #self.clothesButton.setTexture(obj.replace('.obj', '.png'))
        self.orderRenderQueue()
        self.updateFaceMasks(self.faceHidingTggl.selected)
예제 #26
0
 def __init__(self):
     self.selectedHuman = Human(files3d.loadMesh(getpath.getSysDataPath("3dobjs/base.obj"), maxFaces = 5))
     self.log_window = None
     self.splash = None
     self.statusBar = None
    log = logDummy()

    class appDummy:
        def __init__(self, human):
            self.selectedHuman = human
            self.splash = splashDummy()
            self.log_window = log_windowDummy()
            self.statusBar = None
            self.progress = None

        def addLogMessage(self, arg1, arg2):
            "Noop"

    buddy = human.Human(
        files3d.loadMesh(mh.getSysDataPath("3dobjs/base.obj"), maxFaces=5))
    G.app = appDummy(buddy)
    base_skel = skeleton.load(mh.getSysDataPath('rigs/default.mhskel'),
                              buddy.meshData)
    buddy.setBaseSkeleton(base_skel)

    import humanmodifier
    humanmodifier.loadModifiers("data/modifiers/modeling_modifiers.json",
                                buddy)
    import proxy
    print os.getcwd()
    sys.stdout = stdout
    buddyProxy = proxy.loadProxy(
        buddy, os.path.join(os.getcwd(), 'data', 'eyes', 'low-poly',
                            'low-poly'), 'Eyes')
    print
예제 #28
0
            print(('Could not load proxy file {}.'.format(path)))
            import traceback
            traceback.print_exc(file=sys.stdout)
            return False
        proxy.saveBinaryProxy(proxy_, npzpath)
    except:
        print(('Unable to save compiled proxy for file {}'.format(path)))
        import traceback
        traceback.print_exc(file=sys.stdout)
        if os.path.isfile(npzpath):
            # Remove file again, in case an empty file is left
            try:
                os.remove(npzpath)
            except:
                pass
        return False

    return True


if __name__ == '__main__':
    human = Human(files3d.loadMesh(getSysDataPath("3dobjs/base.obj")))
    allFiles = getAllFiles('data', ['*.mhclo', '*.proxy'])
    for allProxies in allFiles:
        for (i, path) in enumerate(allProxies):
            compileProxy(path, human)
            print("{:.1f}% done converted proxy {}".format(
                100 * (float(i) / float(len(allProxies))), path))

    print("All done.")
    def setClothes(self, human, mhclo):
    
        if os.path.basename(mhclo) == "clear.mhclo":
            for name,clo in human.clothesObjs.items():
                gui3d.app.removeObject(clo)
                del human.clothesObjs[name]
            self.clothesList = []
            return

        proxy = mh2proxy.readProxyFile(human.meshData, mhclo, False)
        
        if not proxy:
            return

        uuid = proxy.getUuid()
        
        if proxy.clothings:
            folder = os.path.dirname(mhclo)
            for piece in proxy.clothings:
                piecefile = os.path.join(folder, piece, piece+".mhclo")
                self.setClothes(human, piecefile)
            return
            
        #folder = os.path.dirname(mhclo)
        (folder, name) = proxy.obj_file
        obj = os.path.join(folder, name)

        try:
            clo = human.clothesObjs[uuid]
        except:
            clo = None
        if clo:
            gui3d.app.removeObject(clo)
            del human.clothesObjs[uuid]
            self.clothesList.remove(uuid)
            print "Removed clothing 1", proxy.name, uuid
            return

        mesh = files3d.loadMesh(obj)
        if proxy.texture:
            (dir, name) = proxy.texture
            tif = os.path.join(folder, name)
            mesh.setTexture(tif)
        else:
            pass
        
        clo = gui3d.app.addObject(gui3d.Object(human.getPosition(), mesh))
        clo.setRotation(human.getRotation())
        clo.mesh.setCameraProjection(0)
        clo.mesh.setSolid(human.mesh.solid)
        clo.mesh.setTransparentPrimitives(len(clo.mesh.faces))
        clo.mesh.originalClothesVerts = [v.co[:] for v in clo.mesh.verts]
        human.clothesObjs[uuid] = clo        
        human.clothesProxies[uuid] = proxy
        self.clothesList.append(uuid)
        
        for tag in proxy.tags:
            tag = tag.lower()
            if tag in KnownTags:
                try:
                    oldUuids = self.taggedClothes[tag]
                except KeyError:
                    oldUuids = []
                newUuids = []
                for oldUuid in oldUuids:
                    if oldUuid == uuid:
                        pass
                    elif True:
                        try:
                            oldClo = human.clothesObjs[oldUuid]
                        except KeyError:
                            continue
                        print "OVERRIDE: do not remove clothing 2", oldUuid
                        #gui3d.app.removeObject(oldClo)
                        #del human.clothesObjs[oldUuid]
                        #self.clothesList.remove(oldUuid)
                    else:
                        print "Kept clothing", oldUuid
                        newUuids.append(oldUuid)
                newUuids.append(uuid)
                self.taggedClothes[tag] = newUuids

        self.adaptClothesToHuman(human)
        clo.setSubdivided(human.isSubdivided())