def onHumanChanged(self, event):
        if event.change == 'proxyChange':
            if event.proxy != 'clothes':
                return
            proxy = event.proxy_obj
            if not proxy:
                return
            foot_pose = proxy.special_pose.get("foot", None)
            if not foot_pose:
                return
            filename = getpath.thoroughFindFile(foot_pose, self.paths)
            if not os.path.isfile(filename):
                log.error("Could not find a file for special_pose foot %s, file does not exist.", filename)
                return
            if event.action == 'add':
                self.loadFootPose(filename)
            elif event.action == 'remove':
                if self.selectedFile and getpath.isSamePath(filename, self.selectedFile):
                    self.loadFootPose(None)

        if event.change == 'poseChange' and not self._setting_pose:
            if self.selectedPose:
                self.applyFootPose(self.selectedPose)
        if event.change == 'reset':
            # Update GUI after reset (if tab is currently visible)
            self._setting_pose = False
            self.loadFootPose(None)
Exemplo n.º 2
0
def _getFilePath(filename, folder=None, altExtensions=None):
    import getpath
    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 getpath.formatPath(path)

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

    searchPaths = []

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

    return getpath.thoroughFindFile(filename, searchPaths)
Exemplo n.º 3
0
 def loadHandler(self, human, values):
     if values[0] == "pose":
         poseFile = values[1]
         poseFile = getpath.thoroughFindFile(poseFile, self.paths)
         if not os.path.isfile(poseFile):
             log.warning("Could not load pose %s, file does not exist." % poseFile)
         else:
             self.loadPose(poseFile)
         return
Exemplo n.º 4
0
    def loadHandler(self, human, values):
        if values[0] == "skeleton":
            skelFile = values[1]

            skelFile = getpath.thoroughFindFile(skelFile, self.paths)
            if not os.path.isfile(skelFile):
                log.warning("Could not load rig %s, file does not exist." % skelFile)
            else:
                self.chooseSkeleton(skelFile)
            return
    def getMaterialPath(self, relPath, objFile = None):
        if objFile:
            objFile = os.path.abspath(objFile)
            if os.path.isfile(objFile):
                objFile = os.path.dirname(objFile)
            searchPaths = [ objFile ]
        else:
            searchPaths = []

        return getpath.thoroughFindFile(relPath, searchPaths)
    def loadHandler(self, human, values, strict):
        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.thoroughFindFile(path)
                if not os.path.isfile(absP):
                    if strict:
                        raise RuntimeError('Could not find material %s for skinMaterial parameter.' % values[1])
                    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 not uuid in human.clothesProxies.keys():
                if strict:
                    raise RuntimeError("Could not load material for proxy with uuid %s (%s)! No such proxy." % (uuid, name))
                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
Exemplo n.º 7
0
    def fromFile(self, filepath, mesh=None):
        """
        Load skeleton from json rig file.
        """
        import json
        from collections import OrderedDict
        import getpath
        import os
        self._clear()
        skelData = json.load(open(filepath, 'rb'), object_pairs_hook=OrderedDict)

        self.name = skelData.get("name", self.name)
        self.version = int(skelData.get("version", 1))
        self.copyright = skelData.get("copyright", "")
        self.description = skelData.get("description", "")
        self.plane_map_strategy = int(skelData.get("plane_map_strategy", 3))

        for joint_name, v_idxs in skelData.get("joints", dict()).items():
            if isinstance(v_idxs, list) and len(v_idxs) > 0:
                self.joint_pos_idxs[joint_name] = v_idxs

        self.planes = skelData.get("planes", dict())

        # Order bones breadth-first
        breadthfirst_bones = []
        prev_len = -1   # anti-deadlock
        while(len(breadthfirst_bones) != len(skelData["bones"]) and prev_len != len(breadthfirst_bones)):
            prev_len = len(breadthfirst_bones)
            for bone_name, bone_defs in skelData["bones"].items():
                if bone_name not in breadthfirst_bones:
                    if not bone_defs.get("parent", None):
                        breadthfirst_bones.append(bone_name)
                    elif bone_defs["parent"] in breadthfirst_bones:
                        breadthfirst_bones.append(bone_name)
        if len(breadthfirst_bones) != len(skelData["bones"]):
            missing = [bname for bname in skelData["bones"].keys() if bname not in breadthfirst_bones]
            log.warning("Some bones defined in file %s could not be added to skeleton %s, because they have an invalid parent bone (%s)", filepath, self.name, ', '.join(missing))

        for bone_name in breadthfirst_bones:
            bone_defs = skelData["bones"][bone_name]
            self.addBone(bone_name, bone_defs.get("parent", None), bone_defs["head"], bone_defs["tail"], bone_defs.get("rotation_plane", 0), bone_defs.get("reference",None), bone_defs.get("weights_reference",None))

        self.build()

        if "weights_file" in skelData and skelData["weights_file"]:
            weights_file = skelData["weights_file"]
            weights_file = getpath.thoroughFindFile(weights_file, os.path.dirname(getpath.canonicalPath(filepath)), True)

            self.vertexWeights = VertexBoneWeights.fromFile(weights_file, mesh.getVertexCount() if mesh else None, rootBone=self.roots[0].name)
    def loadHandler(self, human, values, strict):
        if values[0] == 'status':
            return

        if values[0] == 'expression' and len(values) > 1:
            if self.base_bvh is None:
                self._load_pose_units()
            poseFile = values[1]
            poseFile = getpath.thoroughFindFile(poseFile, self.paths)
            if not os.path.isfile(poseFile):
                if strict:
                    raise RuntimeError("Could not load expression pose %s, file does not exist." % poseFile)
                log.warning("Could not load expression pose %s, file does not exist.", poseFile)
            else:
                self.chooseExpression(poseFile)
            return
 def loadHandler(self, human, values):
     if values[0] == "background":
         if len(values) >= 7:
             side = values[1]
             img_filename = values[2]
             i = 0
             while img_filename and not any( [img_filename.lower().endswith(ex) for ex in self.extensions] ) and (len(values) - (i+2)) >= 5:
                 i += 1
                 img_filename = img_filename + ' ' + values[2+i]
             img_filename = getpath.thoroughFindFile(img_filename, self.backgroundsFolders)
             aspect = float(values[3+i])
             trans = (float(values[4+i]), float(values[5+i]))
             scale = float(values[6+i])
             self.filenames[side] = (img_filename, aspect)
             self.transformations[side] = [trans, scale]
         elif len(values) >= 3 and values[1] == 'enabled':
             enabled = values[2].lower() in ['true', 'yes']
             self.setBackgroundEnabled(enabled)
         else:
             log.error("Unknown background option: %s", (' '.join( values[1:]) ))
Exemplo n.º 10
0
    def loadHandler(self, human, values, strict):
        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.thoroughFindFile(path)
                if not os.path.isfile(absP):
                    if strict:
                        raise RuntimeError(
                            'Could not find material %s for skinMaterial parameter.'
                            % values[1])
                    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.eyebrowsProxy and human.eyebrowsProxy.getUuid() == uuid:
                proxy = human.eyebrowsProxy
                filepath = self.getMaterialPath(filepath, proxy.file)
                proxy.object.material = material.fromFile(filepath)
                return
            elif human.eyelashesProxy and human.eyelashesProxy.getUuid(
            ) == uuid:
                proxy = human.eyelashesProxy
                filepath = self.getMaterialPath(filepath, proxy.file)
                proxy.object.material = material.fromFile(filepath)
                return
            elif human.teethProxy and human.teethProxy.getUuid() == uuid:
                proxy = human.teethProxy
                filepath = self.getMaterialPath(filepath, proxy.file)
                proxy.object.material = material.fromFile(filepath)
                return
            elif human.tongueProxy and human.tongueProxy.getUuid() == uuid:
                proxy = human.tongueProxy
                filepath = self.getMaterialPath(filepath, proxy.file)
                proxy.object.material = material.fromFile(filepath)
                return

            elif not uuid in list(human.clothesProxies.keys()):
                if strict:
                    raise RuntimeError(
                        "Could not load material for proxy with uuid %s (%s)! No such proxy."
                        % (uuid, name))
                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
Exemplo n.º 11
0
    def fromFile(self, filepath, mesh=None):
        """
        Load skeleton from json rig file.
        """
        import json
        from collections import OrderedDict
        import getpath
        import os
        self._clear()
        skelData = json.load(open(filepath, 'rb'),
                             object_pairs_hook=OrderedDict)

        self.name = skelData.get("name", self.name)
        self.version = int(skelData.get("version", 1))
        self.copyright = skelData.get("copyright", "")
        self.description = skelData.get("description", "")

        for joint_name, v_idxs in skelData.get("joints", dict()).items():
            if isinstance(v_idxs, list) and len(v_idxs) > 0:
                self.joint_pos_idxs[joint_name] = v_idxs

        # Order bones breadth-first
        breadthfirst_bones = []
        prev_len = -1  # anti-deadlock
        while (len(breadthfirst_bones) != len(skelData["bones"])
               and prev_len != len(breadthfirst_bones)):
            prev_len = len(breadthfirst_bones)
            for bone_name, bone_defs in skelData["bones"].items():
                if bone_name not in breadthfirst_bones:
                    if not bone_defs.get("parent", None):
                        breadthfirst_bones.append(bone_name)
                    elif bone_defs["parent"] in breadthfirst_bones:
                        breadthfirst_bones.append(bone_name)
        if len(breadthfirst_bones) != len(skelData["bones"]):
            missing = [
                bname for bname in skelData["bones"].keys()
                if bname not in breadthfirst_bones
            ]
            log.warning(
                "Some bones defined in file %s could not be added to skeleton %s, because they have an invalid parent bone (%s)",
                filepath, self.name, ', '.join(missing))

        for bone_name in breadthfirst_bones:
            bone_defs = skelData["bones"][bone_name]
            self.addBone(bone_name, bone_defs.get("parent",
                                                  None), bone_defs["head"],
                         bone_defs["tail"], bone_defs["roll"],
                         bone_defs.get("reference", None),
                         bone_defs.get("weights_reference", None))

        self.build()

        if "weights_file" in skelData and skelData["weights_file"]:
            weights_file = skelData["weights_file"]
            weights_file = getpath.thoroughFindFile(
                weights_file, os.path.dirname(getpath.canonicalPath(filepath)),
                True)

            self.vertexWeights = VertexBoneWeights.fromFile(
                weights_file,
                mesh.getVertexCount() if mesh else None,
                rootBone=self.roots[0].name)