Ejemplo n.º 1
0
 def loadMacroTargets(self):
     keys = ('macrodetails', 'universal', 'stature')
     import targets
     for i in xrange(3):
         key = keys[:i + 1]
         for target in targets.getTargets().groups[key]:
             algos3d.getTarget(self.selectedHuman.meshData, target.path)
Ejemplo n.º 2
0
 def loadMacroTargets(self):
     keys = ('macrodetails', 'universal', 'stature')
     import targets
     for i in xrange(3):
         key = keys[:i+1]
         for target in targets.getTargets().groups[key]:
             algos3d.getTarget(self.selectedHuman.meshData, target.path)
Ejemplo n.º 3
0
 def loadMacroTargets(self):
     """
     Preload all target files belonging to group macrodetails and its child
     groups.
     """
     import targets
     #import getpath
     for target in targets.getTargets().findTargets('macrodetails'):
         #log.debug('Preloading target %s', getpath.getRelativePath(target.path))
         algos3d.getTarget(self.selectedHuman.meshData, target.path)
Ejemplo n.º 4
0
 def stripTargets(self, obj, action=-1):
     for targetName in universalBaseTargets:
         filename = os.path.join(gp.getSysDataPath('targets/macrodetails'), targetName)
         target = algos3d.getTarget(obj, filename)
         if target:
             target.apply(obj, action * 1.0 / len(universalBaseTargets))
     for targetName in baseTargets:
         filename = os.path.join(gp.getSysDataPath('targets/macrodetails'), targetName)
         target = algos3d.getTarget(obj, filename)
         if target:
             target.apply(obj, action * 1.0 / len(baseTargets))
Ejemplo n.º 5
0
 def loadMacroTargets(self, human):
     '''
     Preload all target files belonging to group macrodetails and its child
     groups.
     '''
     import targets
     #import getpath
     print('Loading macroTargets :')
     i = 0
     for target in targets.getTargets().findTargets('macrodetails'):
         print('\t%s' % target.path)
         #log.debug('Preloading target %s', getpath.getRelativePath(target.path))
         algos3d.getTarget(human.meshData, target.path)
         i = i +1
     print('Properly loaded %d macroTargets' % i)
Ejemplo n.º 6
0
 def onClicked(dummy):
     human = gui3d.app.selectedHuman
     targets = []
     for name in human.targetsDetailStack.keys():
         if isinstance(algos3d.getTarget(human, name), EditTarget):
             targets.append(name)
     gui3d.app.do(EditAction(human, targets, 0.0))
Ejemplo n.º 7
0
 def updateValue(self, human, value, updateNormals=1):
     
     # Collect vertex and face indices if we didn't yet
     if not (self.verts or self.faces):
         # Collect verts
         self.verts = []
         for target in self.targets:
             t = algos3d.getTarget(human.meshData, target[0])
             self.verts.extend(t.verts)
         self.verts = list(set(self.verts))
         
         # collect faces
         self.faces = []
         for vindex in self.verts:
             self.faces += [face.idx for face in human.meshData.verts[vindex].sharedFaces]
         self.faces = list(set(self.faces))
     
     # Remove old targets
     for target in self.targets:
         algos3d.loadTranslationTarget(human.meshData, target[0], -human.getDetail(target[0]), None, 0, 0)
     
     # Update detail state
     self.setValue(human, value)
     
     # Add new targets
     for target in self.targets:
         algos3d.loadTranslationTarget(human.meshData, target[0], human.getDetail(target[0]), None, 0, 0)
         
     # Update vertices
     faces = [human.meshData.faces[i] for i in self.faces]
     vertices = [human.meshData.verts[i] for i in self.verts]
     if updateNormals:
         human.meshData.calcNormals(1, 1, vertices, faces)
     human.meshData.update(vertices, updateNormals)
 def onClicked(dummy):
     human = gui3d.app.selectedHuman
     targets = []
     for name in human.targetsDetailStack.keys():
         if isinstance(algos3d.getTarget(human, name), EditTarget):
             targets.append(name)
     gui3d.app.do(EditAction(human, targets, 0.0))
Ejemplo n.º 9
0
 def onClicked(path):
     if path:
         if not os.path.isfile(self.metaFile):
             error_msg = 'No Base Model defined.\nPress "Set Base"'
             dialog = gui.Dialog()
             dialog.prompt(title='Error',
                           text=error_msg,
                           button1Label='OK')
             log.warning(error_msg)
         else:
             if not path.lower().endswith('.target'):
                 error_msg = 'Cannot save diff target to file: {0:s}\nExpected a path to a .target file'.format(
                     path)
                 dialog = gui.Dialog()
                 dialog.prompt(title='Error',
                               text=error_msg,
                               button1Label='OK')
                 return
             else:
                 human = G.app.selectedHuman
                 target = algos3d.getTarget(human.meshData,
                                            self.metaFile)
                 target.apply(human.meshData, -1)
                 self.saveTargets(path, False)
                 target.apply(human.meshData, 1)
                 self.diffFileName = os.path.basename(path)
                 self.diffDirName = os.path.dirname(path)
                 self.diffNameEdit.setText(self.diffFileName)
                 self.saveDiffAsButton.path = path
                 G.app.statusPersist(
                     'Saving Target Directory: ' + self.dirName +
                     '   Saving Diff Targets Directory: ' +
                     self.diffDirName)
Ejemplo n.º 10
0
        def onClicked(event):
            if not os.path.isfile(self.metaFile):
                error_msg = 'No Base Model defined.\nPress "Set Base"'
                dialog = gui.Dialog()
                dialog.prompt(title='Error', text=error_msg, button1Label='OK')
                log.warning(error_msg)
            else:
                path = os.path.join(self.diffDirName, self.diffFileName)
                overwrite = True
                dialog = gui.Dialog()

                if not path.lower().endswith('.target'):
                    error_msg = 'Cannot save target to file: {0:s}\nExpected a path to a .target file'.format(path)
                    dialog.prompt(title='Error', text=error_msg, button1Label='OK')
                    log.error('Cannot save targets to %s. Not a .target file.', path)
                    return
                else:
                    if os.path.exists(path):
                        msg = 'File {0:s} already exists. Overwrite?'.format(path)
                        overwrite = dialog.prompt(title='Warning', text=msg, button1Label='YES', button2Label='NO')
                        if overwrite:
                            log.message('Overwriting %s ...', path)
                    if overwrite:
                        human = G.app.selectedHuman
                        target = algos3d.getTarget(human.meshData, self.metaFile)
                        target.apply(human.meshData, -1)
                        self.saveTargets(path, False)
                        target.apply(human.meshData, 1)
Ejemplo n.º 11
0
def clearPoseDetails(human):
    for path in human.targetsDetailStack.keys():
        try:
            target = algos3d.getTarget(human.meshData, path)
        except KeyError:
            continue
        if (isinstance(target, warpmodifier.WarpTarget) and
            isinstance(target.modifier, PoseModifier)):
            target.modifier.updateValue(0.0)
            human.setDetail(path, 0)
    human.applyAllTargets()
Ejemplo n.º 12
0
    def buildLists(self):
        # Collect vertex and face indices if we didn't yet
        if self.verts is None and self.faces is None:
            # Collect verts
            vmask = np.zeros(self.human.meshData.getVertexCount(), dtype=bool)
            for target in self.targets:
                t = algos3d.getTarget(self.human.meshData, target[0])
                vmask[t.verts] = True
            self.verts = np.argwhere(vmask)[..., 0]
            del vmask

            # collect faces
            self.faces = self.human.meshData.getFacesForVertices(self.verts)
Ejemplo n.º 13
0
    def buildLists(self):
        # Collect vertex and face indices if we didn't yet
        if self.verts is None and self.faces is None:
            # Collect verts
            vmask = np.zeros(self.human.meshData.getVertexCount(), dtype=bool)
            for target in self.targets:
                t = algos3d.getTarget(self.human.meshData, target[0])
                vmask[t.verts] = True
            self.verts = np.argwhere(vmask)[...,0]
            del vmask

            # collect faces
            self.faces = self.human.meshData.getFacesForVertices(self.verts)
Ejemplo n.º 14
0
 def showTarget(self, path):
     mesh = G.app.selectedHuman.meshData
     target = algos3d.getTarget(mesh, path)
     sizes = np.sqrt(np.sum(target.data ** 2, axis = -1))
     sizes /= np.amax(sizes)
     val = sizes * 2 - 1
     del sizes
     red = np.maximum(val, 0)
     blue = np.maximum(-val, 0)
     green = 1.0 - red - blue
     del val
     color = np.array([red,green,blue,np.ones_like(red)]).T
     color = (color * 255.99).astype(np.uint8)
     mesh.color[target.verts,:] = color
     mesh.markCoords(target.verts, colr = True)
     mesh.sync_all()
Ejemplo n.º 15
0
 def showTarget(self, path):
     mesh = G.app.selectedHuman.meshData
     target = algos3d.getTarget(mesh, path)
     sizes = np.sqrt(np.sum(target.data**2, axis=-1))
     sizes /= np.amax(sizes)
     val = sizes * 2 - 1
     del sizes
     red = np.maximum(val, 0)
     blue = np.maximum(-val, 0)
     green = 1.0 - red - blue
     del val
     color = np.array([red, green, blue, np.ones_like(red)]).T
     color = (color * 255.99).astype(np.uint8)
     mesh.color[target.verts, :] = color
     mesh.markCoords(target.verts, colr=True)
     mesh.sync_all()
Ejemplo n.º 16
0
def readTarget(filepath):
    target = algos3d.getTarget(G.app.selectedHuman.meshData, filepath)
    if target is None:
        raise IOError("Can't find target %s" % filepath)

    return target
Ejemplo n.º 17
0
    def getReferences(self):
        """
        Building source and target characters from scratch.
        The source character is the sum of reference characters.
        The target character is the sum of all non-warp targets.
        Cannot use human.getSeedMesh() which returns sum of all targets.
        """
        srcCharCoord = self.human.meshData.orig_coord.copy()
        trgCharCoord = srcCharCoord.copy()
        srcTargetCoord = np.zeros(srcCharCoord.shape, dtype=np.float32)

        keypoints = self.getKeypoints()
        trgPoints = np.zeros(6, float)
        srcPoints = np.zeros(6, float)


        # Traverse targets on stack
        for charpath,value in self.human.targetsDetailStack.items():
            if 'expression' in charpath:
                # TODO remove this stupid hack
                continue

            # The original target
            try:
                trgChar = algos3d.getTarget(self.human.meshData, charpath)
            except KeyError:
                continue    # Warp target? - ignore
            if isinstance(trgChar, WarpTarget):
                continue

            # TODO This is very wasteful, because we only need trgCharCoord and
            # srcCharCoord at the six keypoints

            srcVerts = np.s_[...]
            dstVerts = trgChar.verts[srcVerts]
            trgCharCoord[dstVerts] += value * trgChar.data[srcVerts]    # TODO replace with getting whole stack
        del charpath
        del value


        # The reference target (from reference variables)
        factors = self.getFactors(1.0)  # Calculate the fully applied warp target (weight = 1.0)
        factors = self.toReferenceFactors(factors)

        refTargets = self.referenceTargets
        tWeights = humanmodifier.getTargetWeights(refTargets, factors, ignoreNotfound = True)
        for tpath, tweight in tWeights.items():
            srcChar = algos3d.getTarget(self.human.meshData, tpath)
            dstVerts = srcChar.verts[srcVerts]
            srcCharCoord[dstVerts] += tweight * srcChar.data[srcVerts]


        # The warp target
        warpTargets = self.targets
        tWeights = humanmodifier.getTargetWeights(warpTargets, factors, ignoreNotfound = True)
        for tpath, tweight in tWeights.items():
            srcTrg = readTarget(tpath)
            addTargetVerts(srcTargetCoord, tweight, srcTrg)

        # Aggregate the keypoints differences
        trgPoints = trgCharCoord[keypoints]
        srcPoints = srcCharCoord[keypoints]
        return srcTargetCoord, srcPoints, trgPoints
Ejemplo n.º 18
0
def readTarget(filepath):
    target = algos3d.getTarget(G.app.selectedHuman.meshData, filepath)
    if target is None:
        raise IOError("Can't find target %s" % filepath)

    return target
Ejemplo n.º 19
0
    def getReferences(self):
        """
        Building source and target characters from scratch.
        The source character is the sum of reference characters.
        The target character is the sum of all non-warp targets.
        Cannot use human.getSeedMesh() which returns sum of all targets.
        """
        srcCharCoord = self.human.meshData.orig_coord.copy()
        trgCharCoord = srcCharCoord.copy()
        srcTargetCoord = np.zeros(srcCharCoord.shape, dtype=np.float32)

        keypoints = self.getKeypoints()
        trgPoints = np.zeros(6, float)
        srcPoints = np.zeros(6, float)

        # Traverse targets on stack
        for charpath, value in self.human.targetsDetailStack.items():
            if 'expression' in charpath:
                # TODO remove this stupid hack
                continue

            # The original target
            try:
                trgChar = algos3d.getTarget(self.human.meshData, charpath)
            except KeyError:
                continue  # Warp target? - ignore
            if isinstance(trgChar, WarpTarget):
                continue

            # TODO This is very wasteful, because we only need trgCharCoord and
            # srcCharCoord at the six keypoints

            srcVerts = np.s_[...]
            dstVerts = trgChar.verts[srcVerts]
            trgCharCoord[dstVerts] += value * trgChar.data[
                srcVerts]  # TODO replace with getting whole stack
        del charpath
        del value

        # The reference target (from reference variables)
        factors = self.getFactors(
            1.0)  # Calculate the fully applied warp target (weight = 1.0)
        factors = self.toReferenceFactors(factors)

        refTargets = self.referenceTargets
        tWeights = humanmodifier.getTargetWeights(refTargets,
                                                  factors,
                                                  ignoreNotfound=True)
        for tpath, tweight in tWeights.items():
            srcChar = algos3d.getTarget(self.human.meshData, tpath)
            dstVerts = srcChar.verts[srcVerts]
            srcCharCoord[dstVerts] += tweight * srcChar.data[srcVerts]

        # The warp target
        warpTargets = self.targets
        tWeights = humanmodifier.getTargetWeights(warpTargets,
                                                  factors,
                                                  ignoreNotfound=True)
        for tpath, tweight in tWeights.items():
            srcTrg = readTarget(tpath)
            addTargetVerts(srcTargetCoord, tweight, srcTrg)

        # Aggregate the keypoints differences
        trgPoints = trgCharCoord[keypoints]
        srcPoints = srcCharCoord[keypoints]
        return srcTargetCoord, srcPoints, trgPoints