Exemple #1
0
    def GetRow(self, id):
        """
        Parameters
        ----------
        id : _InternalId

        Returns
        -------
        int
        """
        item = self._idToItem.get(id)
        if item is None:
            raise Tf.ErrorException("Cannot find '%d' in PrimIdTable" % id)

        parentId = self.GetParentId(id)
        path = self.GetPathFromId(id)
        if path == self._root:
            return 0

        parentItem = self._idToItem.get(parentId)
        if parentItem is None:
            raise Tf.ErrorException(
                "Cannot find parent '%d' of '%d' in PrimIdTable" %
                (parentId, id))

        return parentItem.index(path)
Exemple #2
0
    def GetParentId(self, id):
        """
        Parameters
        ----------
        id : _InternalId

        Returns
        -------
        _InternalId
        """
        item = self._idToItem.get(id)
        if item is None:
            raise Tf.ErrorException("Cannot find '%d' in PrimIdTable" % id)

        path = item.path
        if path == self._root:
            return 0

        parent = path.GetParentPath()
        parentId = self._pathToId.get(parent)
        if parentId is None:
            raise Tf.ErrorException(
                "Cannot find parent '%s' of '%s' in PrimIdTable" %
                (parent, path))

        return parentId
Exemple #3
0
    def GetChildPath(self, id, index):
        """
        Parameters
        ----------
        id : _InternalId
        index : int

        Returns
        -------
        Sdf.Path
        """
        item = self._idToItem.get(id)
        if item is None:
            raise Tf.ErrorException("Cannot find '%d' in PrimIdTable" % id)

        if index >= len(item.children):
            raise Tf.ErrorException(
                "Index '%d' exceeds number of children of '%s' in PrimIdTable"
                % (index, item.path))

        return item.children[index]
Exemple #4
0
    def GetChildCount(self, id):
        """
        Parameters
        ----------
        id : _InternalId

        Returns
        -------
        int
        """
        item = self._idToItem.get(id)
        if item is None:
            raise Tf.ErrorException("Cannot find '%d' in PrimIdTable" % id)
        return len(item.children)
Exemple #5
0
    def GetPathFromId(self, id):
        """
        Parameters
        ----------
        id : _InternalId

        Returns
        -------
        Sdf.Path
        """
        item = self._idToItem.get(id)
        if item is None:
            raise Tf.ErrorException("Cannot find '%d' in PrimIdTable" % id)
        return item.path
Exemple #6
0
    def GetIdFromPath(self, path):
        """
        Parameters
        ----------
        path : Sdf.Path

        Returns
        -------
        _InternalId
        """
        id = self._pathToId.get(path)
        if id is None:
            raise Tf.ErrorException("Cannot find '%s' in PrimIdTable" % path)
        return id
Exemple #7
0
    def RegisterChild(self, id, index):
        """
        Parameters
        ----------
        id : _InternalId
        index : int

        Returns
        -------
        bool
        """
        item = self._idToItem.get(id)
        if item is None:
            raise Tf.ErrorException("Cannot find '%d' in PrimIdTable" % id)

        if index >= len(item.children):
            raise Tf.ErrorException(
                "Index '%d' exceeds number of children of '%s' in PrimIdTable"
                % (index, item.path))

        path = item.children[index]

        if path in self._pathToId:
            # already registered.
            return True

        prim = self._stage.GetPrimAtPath(path)
        if not prim:
            raise Tf.ErrorException(
                "Expected child (%d) of id (%d) has expired.", (index, id))

        if self._nextAvailableId >= self._maxId:
            _logger.warn("out of indices.")
            return False

        self._RegisterPrim(prim)
        return True
Exemple #8
0
 def _checkMissingTemplateArg(argName, argValue):
     if not argValue:
         raise Tf.ErrorException('Error: %s must be specified '
                                 'when --templateMetadata is' % argName)
Exemple #9
0
                                        'when --templateMetadata is' % argName)

        _checkMissingTemplateArg('templatePath', results.templatePath)
        _checkMissingTemplateArg('endTimeCode', results.endTimeCode)
        _checkMissingTemplateArg('startTimeCode', results.startTimeCode)
        _checkMissingTemplateArg('stride', results.stride)

        UsdUtils.StitchClipsTopology(topologyLayer, results.usdFiles)
        UsdUtils.StitchClipsTemplate(
            outLayer, topologyLayer, results.clipPath, results.templatePath,
            results.startTimeCode, results.endTimeCode, results.stride,
            results.activeOffset, results.interpolateMissingClipValues,
            results.clipSet)
    else:
        if results.templatePath:
            raise Tf.ErrorException('Error: templatePath cannot be specified '
                                    'without --templateMetadata')
        if results.activeOffset:
            raise Tf.ErrorException('Error: activeOffset cannot be specified '
                                    'without --templateMetadata')
        if results.stride:
            raise Tf.ErrorException('Error: stride cannot be specified '
                                    'without --templateMetadata')

        UsdUtils.StitchClips(outLayer, results.usdFiles, results.clipPath,
                             results.startTimeCode, results.endTimeCode,
                             results.interpolateMissingClipValues,
                             results.clipSet)

    if not results.noComment:
        outLayer.comment = 'Generated with ' + ' '.join(sys.argv)
        outLayer.Save()
Exemple #10
0
    def ResyncSubtrees(self, paths):
        """
        Parameters
        ----------
        paths : List[Sdf.Path]

        Returns
        -------
        None
        """
        # TODO: Is there a way to optimize the paths that need to be traversed
        # if there are redundancies? (say, /World/foo and /World/foo/bar)
        sortedPaths = paths[:]
        sortedPaths.sort()

        # Uniquify the list of parents.
        uniqueParents = set()  # type: Set[Sdf.Path]
        for path in sortedPaths:
            uniqueParents.add(path.GetParentPath())

        outOfSyncPaths = set()  # type: Set[Sdf.Path]

        # Update the list of children per unique parent.
        for parentPath in uniqueParents:
            _logger.debug("Updating children of parent: '%s'\n", parentPath)

            parentId = self.GetIdFromPath(parentPath)
            sortedOriginalChildren = self._idToItem[parentId].children
            sortedOriginalChildren.sort()

            newChildren = []  # type: List[Sdf.Path]

            # Look through the new children to find any paths aren't in the
            # original
            # children and not in sorted paths.  These have gotten out of sync.
            parentPrim = self._stage.GetPrimAtPath(parentPath)
            for child in parentPrim.GetFilteredChildren(self._predicate):
                inOriginalChildren = binarySearch(sortedOriginalChildren,
                                                  child.GetPath())
                inResyncPaths = binarySearch(sortedPaths, child.GetPath())

                if inOriginalChildren or inResyncPaths:
                    _logger.debug("Keeping child: '%s'", child.GetPath())
                    newChildren.append(child.GetPath())
                else:
                    _logger.debug("Out of sync new child: '%s'",
                                  child.GetPath())
                    outOfSyncPaths.add(child.GetPath())

            sortedNewChildren = newChildren[:]
            # std.sort(sortedNewChildren.begin(), sortedNewChildren.end())
            sortedNewChildren.sort()
            # Look through the original children to find any paths are missing
            # and not in sorted paths.  These have gotten out of sync, likely
            # because ResyncSubtrees has been called with an incomplete list.
            # This isn't strictly necessary other than for error checking.
            for childPath in sortedOriginalChildren:
                inNewChildren = binarySearch(sortedNewChildren, childPath)
                inResyncPaths = binarySearch(sortedPaths, childPath)
                if not inNewChildren and not inResyncPaths:
                    _logger.debug("Out of sync original child: '%s'",
                                  childPath)
                    outOfSyncPaths.add(childPath)

            # Assign the new children vector to the parent.
            self._idToItem[parentId].children[:] = newChildren
            _logger.debug("Total children count: '%d'",
                          len(self._idToItem[parentId].children))

        if outOfSyncPaths:
            raise Tf.ErrorException("Indices may have been lost during "
                                    "index resync.")
        for path in sortedPaths:
            self._InvalidateSubtree(path)