add usd-21-05-win64_py37
This commit is contained in:
1 parent
41d23e71ba
commit
66bc054336
15675 files changed
+3061008
No files matched your search
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_API_H
|
||||
#define PXR_USD_USD_UTILS_API_H
|
||||
|
||||
#include "pxr/base/arch/export.h"
|
||||
|
||||
#if defined(PXR_STATIC)
|
||||
# define USDUTILS_API
|
||||
# define USDUTILS_API_TEMPLATE_CLASS(...)
|
||||
# define USDUTILS_API_TEMPLATE_STRUCT(...)
|
||||
# define USDUTILS_LOCAL
|
||||
#else
|
||||
# if defined(USDUTILS_EXPORTS)
|
||||
# define USDUTILS_API ARCH_EXPORT
|
||||
# define USDUTILS_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define USDUTILS_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# else
|
||||
# define USDUTILS_API ARCH_IMPORT
|
||||
# define USDUTILS_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
|
||||
# define USDUTILS_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
|
||||
# endif
|
||||
# define USDUTILS_LOCAL ARCH_HIDDEN
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,201 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_AUTHORING_H
|
||||
#define PXR_USD_USD_UTILS_AUTHORING_H
|
||||
|
||||
/// \file usdUtils/authoring.h
|
||||
///
|
||||
/// A collection of utilities for higher-level authoring and copying scene
|
||||
/// description than provided by the core Usd and Sdf API's
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
|
||||
#include "pxr/base/tf/hashset.h"
|
||||
|
||||
#include "pxr/usd/usd/collectionAPI.h"
|
||||
#include "pxr/usd/usd/stage.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
/// Given two layers \p source and \p destination, copy the authored metadata
|
||||
/// from one to the other. By default, copy **all** authored metadata;
|
||||
/// however, you can skip certain classes of metadata with the parameter
|
||||
/// \p skipSublayers, which will prevent copying subLayers or subLayerOffsets
|
||||
///
|
||||
/// Makes no attempt to clear metadata that may already be authored in
|
||||
/// \p destination, but any fields that are already in \p destination but also
|
||||
/// in \p source will be replaced.
|
||||
///
|
||||
/// Certain bits of layer metadata (eg. colorConfiguration and
|
||||
/// colorManagementSystem) can have their fallback values specified in the
|
||||
/// plugInfo.json files of plugins. When such metadata is unauthored in the
|
||||
/// source layer, if \p bakeUnauthoredFallbacks is set to true, then the
|
||||
/// fallback values are baked into the destination layer.
|
||||
///
|
||||
/// \return \c true on success, \c false on error.
|
||||
USDUTILS_API
|
||||
bool UsdUtilsCopyLayerMetadata(const SdfLayerHandle &source,
|
||||
const SdfLayerHandle &destination,
|
||||
bool skipSublayers = false,
|
||||
bool bakeUnauthoredFallbacks = false);
|
||||
|
||||
using UsdUtilsPathHashSet = TfHashSet<SdfPath, SdfPath::Hash>;
|
||||
|
||||
/// \anchor UsdUtilsAuthoring_Collections
|
||||
/// \name API for computing and authoring collections
|
||||
/// @{
|
||||
|
||||
/// Computes the optimal set of paths to include and the set of paths to
|
||||
/// exclude below includes paths, in order to encode an "expandPrims"
|
||||
/// collection that contains the subtrees of prims rooted at
|
||||
/// \p includedRootPaths.
|
||||
///
|
||||
/// The algorithm used to determine a compact representation is driven
|
||||
/// by the following three parameters: \p minInclusionRatio,
|
||||
/// \p maxNumExcludesBelowInclude and \p minIncludeExcludeCollectionSize.
|
||||
/// See below for their descriptions.
|
||||
///
|
||||
/// \p usdStage is the USD stage to which the paths in \p includedRootPaths
|
||||
/// belong.
|
||||
/// \p pathsToInclude is populated with the set of paths to include. Any
|
||||
/// existing paths in the set are cleared before adding paths to it.
|
||||
/// \p pathsToExclude is populated with the set of paths to exclude. Any
|
||||
/// existing paths in the set are cleared before adding paths to it.
|
||||
/// \p minInclusionRatio is the minimum value of the ratio between the number
|
||||
/// of included paths and the sum of the number of included and excluded paths
|
||||
/// below an ancestor path, at or above which the ancestor path is included in
|
||||
/// the collection. For example, if an ancestor prim has four children and
|
||||
/// three out of the four are included in the collection, the inclusion ratio
|
||||
/// at the ancestor is 0.75. This value should be in the range (0,1), if not,
|
||||
/// it's clamped to the range.
|
||||
/// \p maxNumExcludesBelowInclude is the maximum number of paths that we exclude
|
||||
/// below any ancestor path that we include in a collection. This parameter only
|
||||
/// affects paths that have already passed the min-inclusion-ratio test.
|
||||
/// Setting this to 0 will cause all collections to have includes only (and no
|
||||
/// excludes). Setting it to a higher number will cause ancestor paths that are
|
||||
/// higher up in the namespace hierarchy to be included in collections.
|
||||
/// \p minIncludeExcludeCollectionSize is the minimum size of a collection
|
||||
/// (i.e. the number of subtree-root paths included in it), at or
|
||||
/// above which the algorithm chooses to make a collection with both included
|
||||
/// and excluded paths, instead of creating a collection with only includes
|
||||
/// (containing the specified set of paths). \ref UsdCollectionAPI
|
||||
/// \p pathsToIgnore is the list of paths to be ignored by the algorithm used
|
||||
/// to determine the included and excluded paths for each collection. If
|
||||
/// non-empty, the paths in the hash set don't contribute towards the counts and
|
||||
/// ratios computed by the algorithm.
|
||||
///
|
||||
/// Returns false if paths in \p includedRootPaths (or their common ancestor)
|
||||
/// can't be found on the given \p usdStage.
|
||||
/// parameters has an invalid value.
|
||||
///
|
||||
/// The python version of this function returns a tuple containing the
|
||||
/// two lists (pathsToInclude, pathsToExclude).
|
||||
USDUTILS_API
|
||||
bool UsdUtilsComputeCollectionIncludesAndExcludes(
|
||||
const SdfPathSet &includedRootPaths,
|
||||
const UsdStageWeakPtr &usdStage,
|
||||
SdfPathVector *pathsToInclude,
|
||||
SdfPathVector *pathsToExclude,
|
||||
double minInclusionRatio=0.75,
|
||||
const unsigned int maxNumExcludesBelowInclude=5u,
|
||||
const unsigned int minIncludeExcludeCollectionSize=3u,
|
||||
const UsdUtilsPathHashSet &pathsToIgnore=UsdUtilsPathHashSet());
|
||||
|
||||
/// Authors a collection named \p collectionName on the given prim,
|
||||
/// \p usdPrim with the given set of included paths (\p pathsToInclude)
|
||||
/// and excluded paths (\p pathsToExclude).
|
||||
///
|
||||
/// If a collection with the specified name already exists on \p usdPrim,
|
||||
/// its data is appended to. The resulting collection will contain
|
||||
/// both the old paths and the newly included paths.
|
||||
USDUTILS_API
|
||||
UsdCollectionAPI UsdUtilsAuthorCollection(
|
||||
const TfToken &collectionName,
|
||||
const UsdPrim &usdPrim,
|
||||
const SdfPathVector &pathsToInclude,
|
||||
const SdfPathVector &pathsToExclude=SdfPathVector());
|
||||
|
||||
/// Given a vector of (collection-name, path-set) pairs, \p assignments,
|
||||
/// creates and returns a vector of collections that include subtrees of prims
|
||||
/// rooted at the included paths. The collections are created on the given prim,
|
||||
/// \p usdPrim.
|
||||
///
|
||||
/// Based on the paths included in the various collections, this function
|
||||
/// computes a compact representation for each collection in parallel
|
||||
/// using UsdUtilsGetCollectionIncludesExcludes(). So, it takes the
|
||||
/// same set of parameters as that function: \p minInclusionRatio,
|
||||
/// \p maxNumExcludesBelowInclude and \p minIncludeExcludeCollectionSize.
|
||||
///
|
||||
/// \note It is valid for the paths or subtrees specified in \p assignments
|
||||
/// to have overlapping subtrees. In this case the overlapping bits will belong
|
||||
/// to multiple collections.
|
||||
///
|
||||
/// \p assignments is a vector of pairs representing collection names and paths
|
||||
/// to be included in the collection in each collection.
|
||||
/// \p usdPrim is the prim on which the collections are created.
|
||||
/// \p minInclusionRatio is the minimum value of the ratio between the number
|
||||
/// of included paths and the sum of the number of included and excluded paths
|
||||
/// below an ancestor path, at or above which the ancestor path is included in
|
||||
/// the collection. For example, if an ancestor prim has four children and
|
||||
/// three out of the four are included in the collection, the inclusion ratio
|
||||
/// at the ancestor is 0.75. This value should be in the range (0,1), if not,
|
||||
/// it's clamped to the range.
|
||||
/// \p maxNumExcludesBelowInclude is the maximum number of paths that we exclude
|
||||
/// below any ancestor path that we include in a collection. This parameter only
|
||||
/// affects paths that have already passed the min-inclusion-ratio test.
|
||||
/// Setting this to 0 will cause all collections to have includes only (and no
|
||||
/// excludes). Setting it to a higher number will cause ancestor paths that are
|
||||
/// higher up in the namespace hierarchy to be included in collections.
|
||||
/// \p minIncludeExcludeCollectionSize is the minimum size of a collection
|
||||
/// (i.e. the number of subtree-root paths included in it), at or
|
||||
/// above which the algorithm chooses to make a collection with both included
|
||||
/// and excluded paths, instead of creating a collection with only includes
|
||||
/// (containing the specified set of paths). \ref UsdCollectionAPI
|
||||
///
|
||||
/// Returns the vector of UsdCollectionAPI objects that were created.
|
||||
/// If a collection is empty (i.e. includes no paths), then an empty collection
|
||||
/// is created for it with the default expansionRule. Hence, the size of the
|
||||
/// returned vector should match the size of \p assignments.
|
||||
USDUTILS_API
|
||||
std::vector<UsdCollectionAPI> UsdUtilsCreateCollections(
|
||||
const std::vector<std::pair<TfToken, SdfPathSet>> &assignments,
|
||||
const UsdPrim &usdPrim,
|
||||
const double minInclusionRatio=0.75,
|
||||
const unsigned int maxNumExcludesBelowInclude=5u,
|
||||
const unsigned int minIncludeExcludeCollectionSize=3u);
|
||||
|
||||
/// @}
|
||||
|
||||
/// Retrieve a list of all dirty layers from the stage's UsedLayers.
|
||||
USDUTILS_API
|
||||
SdfLayerHandleVector UsdUtilsGetDirtyLayers(UsdStagePtr stage,
|
||||
bool includeClipLayers = true);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif /* PXR_USD_USD_UTILS_AUTHORING_H */
|
||||
@@ -0,0 +1,135 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_COALESCING_DIAGNOSTIC_DELEGATE_H
|
||||
#define PXR_USD_USD_UTILS_COALESCING_DIAGNOSTIC_DELEGATE_H
|
||||
|
||||
/// \file usdUtils/coalescingDiagnosticDelegate.h
|
||||
///
|
||||
/// A class which provides aggregation of warnings and statuses
|
||||
/// emitted from Tf's diagnostic management system. These diagnostic
|
||||
/// notifications can be coalesced by invocation point,
|
||||
/// currently defined as the source file, line number and function name,
|
||||
/// to recieve a more concise output.
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
#include "pxr/base/tf/diagnosticMgr.h"
|
||||
|
||||
#include <ostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <tbb/concurrent_queue.h>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// The shared component in a coalesced result
|
||||
/// This type can be thought of as the key by which we
|
||||
/// coalesce our diagnostics.
|
||||
struct UsdUtilsCoalescingDiagnosticDelegateSharedItem {
|
||||
size_t sourceLineNumber;
|
||||
std::string sourceFunction;
|
||||
std::string sourceFileName;
|
||||
};
|
||||
|
||||
/// The unshared component in a coalesced result
|
||||
struct UsdUtilsCoalescingDiagnosticDelegateUnsharedItem {
|
||||
TfCallContext context;
|
||||
std::string commentary;
|
||||
};
|
||||
|
||||
/// An item used in coalesced results, containing a shared component:
|
||||
/// the file/function/line number, and a set of unshared components: the
|
||||
/// call context and commentary.
|
||||
struct UsdUtilsCoalescingDiagnosticDelegateItem {
|
||||
UsdUtilsCoalescingDiagnosticDelegateSharedItem sharedItem;
|
||||
std::vector<UsdUtilsCoalescingDiagnosticDelegateUnsharedItem> unsharedItems;
|
||||
};
|
||||
|
||||
/// A vector of coalesced results, each containing a shared component,
|
||||
/// the file/function/line number, and a set of unshared components, the
|
||||
/// call context and commentary.
|
||||
typedef std::vector<UsdUtilsCoalescingDiagnosticDelegateItem>
|
||||
UsdUtilsCoalescingDiagnosticDelegateVector;
|
||||
|
||||
/// A class which collects warnings and statuses from the
|
||||
/// Tf diagnostic manager system in a thread safe manner.
|
||||
///
|
||||
/// This class allows clients to get both the unfiltered
|
||||
/// results, as well as a compressed view which deduplicates
|
||||
/// diagnostic events by their source line number, function and file
|
||||
/// from which they occurred.
|
||||
class UsdUtilsCoalescingDiagnosticDelegate : public TfDiagnosticMgr::Delegate {
|
||||
public:
|
||||
USDUTILS_API
|
||||
UsdUtilsCoalescingDiagnosticDelegate();
|
||||
|
||||
USDUTILS_API
|
||||
virtual ~UsdUtilsCoalescingDiagnosticDelegate();
|
||||
|
||||
/// Methods that implement the interface provided in TfDiagnosticMgr::Delegate
|
||||
|
||||
USDUTILS_API
|
||||
virtual void IssueError(const TfError&) override;
|
||||
|
||||
USDUTILS_API
|
||||
virtual void IssueStatus(const TfStatus&) override;
|
||||
|
||||
USDUTILS_API
|
||||
virtual void IssueWarning(const TfWarning&) override;
|
||||
|
||||
USDUTILS_API
|
||||
virtual void IssueFatalError(const TfCallContext&, const std::string &) override;
|
||||
|
||||
// Methods that provide collection of diagnostics as well as sending
|
||||
// them to a stream(stderr, stdout, a file, etc).
|
||||
|
||||
/// Print all pending diagnostics in a coalesced form to \p ostr
|
||||
/// \note This method clears the pending diagnostics.
|
||||
USDUTILS_API
|
||||
void DumpCoalescedDiagnostics(std::ostream& ostr);
|
||||
|
||||
/// Print all pending diagnostics without any coalescing to \p ostr
|
||||
/// \note This method clears the pending diagnostics.
|
||||
USDUTILS_API
|
||||
void DumpUncoalescedDiagnostics(std::ostream& ostr);
|
||||
|
||||
/// Get all pending diagnostics in a coalesced form.
|
||||
/// \note This method clears the pending diagnostics.
|
||||
USDUTILS_API
|
||||
UsdUtilsCoalescingDiagnosticDelegateVector TakeCoalescedDiagnostics();
|
||||
|
||||
/// Get all pending diagnostics without any coalescing.
|
||||
/// \note This method clears the pending diagnostics.
|
||||
USDUTILS_API
|
||||
std::vector<std::unique_ptr<TfDiagnosticBase>> TakeUncoalescedDiagnostics();
|
||||
|
||||
private:
|
||||
tbb::concurrent_queue<TfDiagnosticBase*> _diagnostics;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_USD_UTILS_COALESCING_DIAGNOSTIC_DELEGATE_H
|
||||
@@ -0,0 +1,149 @@
|
||||
//
|
||||
// Copyright 2020 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_CONDITIONAL_ABORT_DIAGNOSTIC_DELEGATE_H
|
||||
#define PXR_USD_USD_UTILS_CONDITIONAL_ABORT_DIAGNOSTIC_DELEGATE_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
#include "pxr/base/tf/diagnosticMgr.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class TfPatternMatcher;
|
||||
|
||||
/// A class which represents the inclusion exclusion filters on which errors
|
||||
/// will be matched
|
||||
/// stringFilters: matching and filtering will be done on explicit string
|
||||
/// of the error/warning
|
||||
/// codePathFilters: matching and filtering will be done on errors/warnings
|
||||
/// coming from a specific usd code path
|
||||
class UsdUtilsConditionalAbortDiagnosticDelegateErrorFilters
|
||||
{
|
||||
public:
|
||||
UsdUtilsConditionalAbortDiagnosticDelegateErrorFilters() {}
|
||||
USDUTILS_API
|
||||
UsdUtilsConditionalAbortDiagnosticDelegateErrorFilters(
|
||||
const std::vector<std::string>& stringFilters,
|
||||
const std::vector<std::string>& codePathFilters);
|
||||
|
||||
const std::vector<std::string>& GetStringFilters() const {
|
||||
return _stringFilters;
|
||||
};
|
||||
|
||||
const std::vector<std::string>& GetCodePathFilters() const {
|
||||
return _codePathFilters;
|
||||
}
|
||||
|
||||
USDUTILS_API
|
||||
void SetStringFilters(const std::vector<std::string>& stringFilters);
|
||||
USDUTILS_API
|
||||
void SetCodePathFilters(const std::vector<std::string>& codePathFilters);
|
||||
private:
|
||||
std::vector<std::string> _stringFilters;
|
||||
std::vector<std::string> _codePathFilters;
|
||||
};
|
||||
|
||||
/// A class that allows client application to instantiate a diagnostic delegate
|
||||
/// that can be used to abort operations for a non fatal USD error or warning
|
||||
/// based on immutable include exclude rules defined for this instance.
|
||||
///
|
||||
/// These rules are regex strings where case sensitive matching is done on
|
||||
/// error/warning text or the location of the code path where the error/warning
|
||||
/// occured.
|
||||
/// Note that these rules will be respected only during the lifetime of the
|
||||
/// delegate.
|
||||
/// Include Rules determine what errors or warnings will cause a fatal abort.
|
||||
/// Exclude Rules determine what errors or warnings matched from the Include
|
||||
/// Rules should not cause the fatal abort.
|
||||
/// Example: to abort on all errors and warnings coming from "*pxr*" codepath
|
||||
/// but not from "*ConditionalAbortDiagnosticDelegate*", a client can create the
|
||||
/// following delegate:
|
||||
///
|
||||
/// \code
|
||||
/// UsdUtilsConditionalAbortDiagnosticDelegateErrorFilters includeFilters;
|
||||
/// UsdUtilsConditionalAbortDiagnosticDelegateErrorFilters excludeFilters;
|
||||
/// includeFilters.SetCodePathFilters({"*pxr*"});
|
||||
/// excludeFilters.SetCodePathFilters({"*ConditionalAbortDiagnosticDelegate*"});
|
||||
/// UsdUtilsConditionalAbortDiagnosticDelegate delegate =
|
||||
/// UsdUtilsConditionalAbortDiagnosticDelegate(includeFilters,
|
||||
/// excludeFilters);
|
||||
/// \endcode
|
||||
///
|
||||
class UsdUtilsConditionalAbortDiagnosticDelegate :
|
||||
public TfDiagnosticMgr::Delegate
|
||||
{
|
||||
public:
|
||||
|
||||
/// Constructor to initialize conditionalAbortDiagnosticDelegate.
|
||||
/// Responsible for adding this delegate instance to TfDiagnosticMgr and
|
||||
/// also sets the \p includeFilters and \p excludeFilters
|
||||
/// \note The _includeFilters and _excludeFilters are immutable
|
||||
USDUTILS_API
|
||||
UsdUtilsConditionalAbortDiagnosticDelegate(
|
||||
const UsdUtilsConditionalAbortDiagnosticDelegateErrorFilters&
|
||||
includeFilters,
|
||||
const UsdUtilsConditionalAbortDiagnosticDelegateErrorFilters&
|
||||
excludeFilters);
|
||||
|
||||
/// Handles the removal of this delegate from TfDiagnosticMgr.
|
||||
USDUTILS_API
|
||||
virtual ~UsdUtilsConditionalAbortDiagnosticDelegate();
|
||||
|
||||
UsdUtilsConditionalAbortDiagnosticDelegate() = delete;
|
||||
UsdUtilsConditionalAbortDiagnosticDelegate(
|
||||
const UsdUtilsConditionalAbortDiagnosticDelegate& delegate) = delete;
|
||||
UsdUtilsConditionalAbortDiagnosticDelegate& operator=(
|
||||
const UsdUtilsConditionalAbortDiagnosticDelegate& delegate) = delete;
|
||||
|
||||
// Interface overrides
|
||||
void IssueError(const TfError& err) override;
|
||||
void IssueWarning(const TfWarning& warning) override;
|
||||
void IssueFatalError(const TfCallContext &ctx,
|
||||
const std::string &msg) override;
|
||||
// Following will be no-ops for our purposes - prints same message as
|
||||
// DiagnosticMgr
|
||||
void IssueStatus(const TfStatus& status) override;
|
||||
|
||||
private:
|
||||
|
||||
const std::vector<TfPatternMatcher> _includePatternStringFilters;
|
||||
const std::vector<TfPatternMatcher> _includePatternCodePathFilters;
|
||||
const std::vector<TfPatternMatcher> _excludePatternStringFilters;
|
||||
const std::vector<TfPatternMatcher> _excludePatternCodePathFilters;
|
||||
|
||||
protected:
|
||||
/// Helper to match \p err against a given set of \p errorFilters
|
||||
/// A client can override this to affect the behavior of the rule matcher.
|
||||
virtual bool _RuleMatcher(const TfDiagnosticBase& err,
|
||||
const std::vector<TfPatternMatcher>& stringPatternFilters,
|
||||
const std::vector<TfPatternMatcher>& codePathPatternFilters);
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_DEBUG_CODES_H
|
||||
#define PXR_USD_USD_UTILS_DEBUG_CODES_H
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/base/tf/debug.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
TF_DEBUG_CODES(
|
||||
USDUTILS_CREATE_USDZ_PACKAGE
|
||||
);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_USD_UTILS_DEBUG_CODES_H
|
||||
@@ -0,0 +1,183 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_DEPENDENCIES_H
|
||||
#define PXR_USD_USD_UTILS_DEPENDENCIES_H
|
||||
|
||||
/// \file usdUtils/dependencies.h
|
||||
///
|
||||
/// Utilities for the following tasks that require consideration of a USD
|
||||
/// asset's external dependencies:
|
||||
/// * extracting asset dependencies from a USD file.
|
||||
/// * creating a USDZ package containing a given asset and all of its external
|
||||
/// dependencies.
|
||||
/// * some time in the future, localize a given asset and all of its
|
||||
/// dependencies into a specified directory.
|
||||
///
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/sdf/layer.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
class SdfAssetPath;
|
||||
|
||||
/// Parses the file at \p filePath, identifying external references, and
|
||||
/// sorting them into separate type-based buckets. Sublayers are returned in
|
||||
/// the \p sublayers vector, references, whether prim references, value clip
|
||||
/// references or values from asset path attributes, are returned in the
|
||||
/// \p references vector. Payload paths are returned in \p payloads.
|
||||
///
|
||||
/// \note No recursive chasing of dependencies is performed; that is the
|
||||
/// client's responsibility, if desired.
|
||||
///
|
||||
/// \note Not all returned references are actually authored explicitly in the
|
||||
/// layer. For example, templated clip asset paths are resolved and expanded
|
||||
/// to include all available clip files that match the specified pattern.
|
||||
USDUTILS_API
|
||||
void UsdUtilsExtractExternalReferences(
|
||||
const std::string& filePath,
|
||||
std::vector<std::string>* subLayers,
|
||||
std::vector<std::string>* references,
|
||||
std::vector<std::string>* payloads);
|
||||
|
||||
/// Creates a USDZ package containing the specified asset, identified by its
|
||||
/// \p assetPath. The created package will include a localized version of the
|
||||
/// asset itself and all of its external dependencies. Due to localization, the
|
||||
/// packaged layers might be modified to have different asset paths.
|
||||
///
|
||||
/// You can optionally specify a different package-internal name for the first
|
||||
/// layer of the asset by specifying \p firstLayerName. By default,
|
||||
/// \p firstLayerName is empty, meaning that the original name is preserved.
|
||||
///
|
||||
/// Returns true if the package was created successfully.
|
||||
///
|
||||
/// \note Clients of this function must take care of configuring the asset
|
||||
/// resolver context before invoking the function. To create a default
|
||||
/// resolver context, use \ref CreateDefaultContextForAsset() with the
|
||||
/// asset path.
|
||||
///
|
||||
/// \note If the given asset has a dependency on a directory (i.e. an external
|
||||
/// reference to a directory path), the dependency is ignored and the contents
|
||||
/// of the directory are not included in the created package.
|
||||
///
|
||||
/// \note This function modifies the layers referenced by \p assetPath
|
||||
/// (including the root layer and all transitive layer dependencies) in-place.
|
||||
/// However, it does not save the layers before copying them into the package
|
||||
/// that is created. It also does not revert the changes it makes to the
|
||||
/// layers. Therefore, it is strongly recommended that you run this function in
|
||||
/// isolation after any source UsdStages have been closed. If you have UsdStages
|
||||
/// open during the function call that reference the layers being modified, you
|
||||
/// may receive warnings or composition errors which may not affect the
|
||||
/// resulting package adversely.
|
||||
///
|
||||
/// \sa UsdUtilsCreateNewARKitUsdzPackage()
|
||||
USDUTILS_API
|
||||
bool
|
||||
UsdUtilsCreateNewUsdzPackage(
|
||||
const SdfAssetPath& assetPath,
|
||||
const std::string& usdzFilePath,
|
||||
const std::string& firstLayerName=std::string());
|
||||
|
||||
/// Similar to UsdUtilsCreateNewUsdzPackage, this function packages all of the
|
||||
/// dependencies of the given asset. Assets targeted at the initial usdz
|
||||
/// implementation in ARKit operate under greater constraints than usdz files
|
||||
/// for more general 'in house' uses, and this option attempts to ensure that
|
||||
/// these constraints are honored; this may involve more transformations to the
|
||||
/// data, which may cause loss of features such as VariantSets.
|
||||
///
|
||||
/// If \p firstLayerName is specified, it is modified to have the ".usdc"
|
||||
/// extension, as required by the initial usdz implementation in ARKit.
|
||||
///
|
||||
/// Returns true if the package was created successfully.
|
||||
///
|
||||
/// \note Clients of this function must take care of configuring the asset
|
||||
/// resolver context before invoking the function. To create a default
|
||||
/// resolver context, use \ref CreateDefaultContextForAsset() with the
|
||||
/// asset path.
|
||||
///
|
||||
/// \note If the given asset has a dependency on a directory (i.e. an external
|
||||
/// reference to a directory path), the dependency is ignored and the contents
|
||||
/// of the directory are not included in the created package.
|
||||
///
|
||||
/// \note This function modifies the layers referenced by \p assetPath
|
||||
/// (including the root layer and all transitive layer dependencies) in-place.
|
||||
/// However, it does not save the layers before copying them into the package
|
||||
/// that is created. It also does not revert the changes it makes to the
|
||||
/// layers. Therefore, it is strongly recommended that you run this function in
|
||||
/// isolation after any source UsdStages have been closed. If you have UsdStages
|
||||
/// open during the function call that reference the layers being modified, you
|
||||
/// may receive warnings or composition errors which may not affect the
|
||||
/// resulting package adversely.
|
||||
///
|
||||
/// \sa UsdUtilsCreateNewUsdzPackage()
|
||||
USDUTILS_API
|
||||
bool
|
||||
UsdUtilsCreateNewARKitUsdzPackage(
|
||||
const SdfAssetPath &assetPath,
|
||||
const std::string &usdzFilePath,
|
||||
const std::string &firstLayerName=std::string());
|
||||
|
||||
/// Recursively computes all the dependencies of the given asset and populates
|
||||
/// \p layers with all the dependencies that can be opened as an SdfLayer.
|
||||
/// All of the resolved non-layer dependencies are populated in \p assets.
|
||||
/// Any unresolved (layer and non-layer) asset paths are populated in
|
||||
/// \p unresolvedPaths.
|
||||
///
|
||||
/// The input vectors to be populated with the results are are *cleared* before
|
||||
/// any results are added to them.
|
||||
///
|
||||
/// Returns true if the given asset was resolved correctly.
|
||||
USDUTILS_API
|
||||
bool
|
||||
UsdUtilsComputeAllDependencies(const SdfAssetPath &assetPath,
|
||||
std::vector<SdfLayerRefPtr> *layers,
|
||||
std::vector<std::string> *assets,
|
||||
std::vector<std::string> *unresolvedPaths);
|
||||
|
||||
/// Callback that is used to modify asset paths in a layer. The \c assetPath
|
||||
/// will contain the string value that's authored. The returned value is the
|
||||
/// new value that should be authored in the layer.
|
||||
using UsdUtilsModifyAssetPathFn = std::function<std::string(
|
||||
const std::string& assetPath)>;
|
||||
|
||||
/// Helper function that visits every asset path in \c layer, calls \c modifyFn
|
||||
/// and replaces the value with the return value of \c modifyFn. This modifies
|
||||
/// \c layer in place.
|
||||
///
|
||||
/// This can be useful in preparing a layer for consumption in contexts that do
|
||||
/// not have access to the ArResolver for which the layer's asset paths were
|
||||
/// authored: we can replace all paths with their fully resolved equivalents,
|
||||
/// for example.
|
||||
USDUTILS_API
|
||||
void UsdUtilsModifyAssetPaths(
|
||||
const SdfLayerHandle& layer,
|
||||
const UsdUtilsModifyAssetPathFn& modifyFn);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif // PXR_USD_USD_UTILS_DEPENDENCIES_H
|
||||
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// Copyright 2017 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_FLATTEN_LAYER_STACK_H
|
||||
#define PXR_USD_USD_UTILS_FLATTEN_LAYER_STACK_H
|
||||
|
||||
/// \file usdUtils/flattenLayerStack.h
|
||||
///
|
||||
/// Utilities for flattening layer stacks into a single layer.
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/usd/stage.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/pcp/layerStackIdentifier.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
/// Flatten the root layer stack of the given \p stage into a single layer
|
||||
/// with the given optional \p tag.
|
||||
///
|
||||
/// The result layer can be substituted for the original layer stack
|
||||
/// while producing the same composed UsdStage.
|
||||
///
|
||||
/// Unlike UsdStage::Export(), this function does not flatten
|
||||
/// composition arcs, such as references, payloads, inherits,
|
||||
/// specializes, or variants.
|
||||
///
|
||||
/// Sublayer time offsets on the sublayers will be applied to remap
|
||||
/// any time-keyed scene description, such as timeSamples and clips.
|
||||
///
|
||||
/// Asset paths will be resolved to absolute form, to ensure that
|
||||
/// they continue to identify the same asset from the output layer.
|
||||
/// \sa UsdUtilsFlattenLayerStackResolveAssetPath
|
||||
///
|
||||
/// A few historical scene description features cannot be flattened
|
||||
/// into a single opinion because they unfortunately encode
|
||||
/// operations that are not closed under composition. Specifically,
|
||||
/// the SdfListOp operations "add" and "reorder" cannot be flattened.
|
||||
/// Instead, "add" will be converted to "append", and "reorder"
|
||||
/// will be discarded.
|
||||
///
|
||||
USDUTILS_API
|
||||
SdfLayerRefPtr
|
||||
UsdUtilsFlattenLayerStack(const UsdStagePtr &stage,
|
||||
const std::string& tag = std::string());
|
||||
|
||||
/// Callback function for overloaded version of \c UsdUtilsFlattenLayerStack.
|
||||
///
|
||||
/// The callback is given the \c sourceLayer and the \c assetPath authored in
|
||||
/// that layer. It should return the \c std::string that should be authored in
|
||||
/// the flattened layer.
|
||||
///
|
||||
/// \sa UsdUtilsFlattenLayerStackResolveAssetPath
|
||||
using UsdUtilsResolveAssetPathFn = std::function<std::string(
|
||||
const SdfLayerHandle& sourceLayer,
|
||||
const std::string& assetPath)>;
|
||||
|
||||
/// Flatten the root layer stack of the given \p stage into a single layer with
|
||||
/// the given optional \p tag and using the \p resolveAssetPathFn to resolve
|
||||
/// asset paths that are encountered.
|
||||
///
|
||||
/// This is an advanced version of the above function.
|
||||
///
|
||||
///
|
||||
/// One use case for this version of the function is to flatten a layer stack
|
||||
/// that contains relative asset paths that we want to preserve as relative
|
||||
/// paths. For example:
|
||||
///
|
||||
/// \code
|
||||
/// /source/root.usd # sublayers a.usd and b.usd
|
||||
/// /source/a.usd # contains reference to ./subdir/layer.usd
|
||||
/// /source/b.usd
|
||||
/// /source/subdir/layer.usd
|
||||
/// \endcode
|
||||
///
|
||||
/// We may want to generate \c "/dest/root.flat.usd" knowing that we will
|
||||
/// (by some other means) also be copying \c "/source/subdir" into \c
|
||||
/// "/dest/subdir". It's useful then to preserve the relative paths.
|
||||
///
|
||||
/// Note, only the caller knows the ultimate destination of the flattened layer.
|
||||
/// So to accomplish this, we can provide a \c resolveAssetPathFn callback that
|
||||
/// captures the outputDir, tests if the authored path is relative, and if so,
|
||||
/// computes a new relative path (based on where it will eventually be
|
||||
/// exported).
|
||||
USDUTILS_API
|
||||
SdfLayerRefPtr
|
||||
UsdUtilsFlattenLayerStack(const UsdStagePtr &stage,
|
||||
const UsdUtilsResolveAssetPathFn& resolveAssetPathFn,
|
||||
const std::string& tag = std::string());
|
||||
|
||||
/// The default \c UsdUtilsResolvePathFn used by \c UsdUtilsFlattenLayerStack.
|
||||
/// For paths that the current ArResolver identifies as searchpaths or absolute
|
||||
/// paths, we return the unmodified path. However, any "Layer relative path"
|
||||
/// (see SdfComputeAssetPathRelativeToLayer) will be absolutized, because we do
|
||||
/// not know if the flattened layer's containing directory will be the same as
|
||||
/// any given source layer's in the incoming layerStack.
|
||||
USDUTILS_API
|
||||
std::string
|
||||
UsdUtilsFlattenLayerStackResolveAssetPath(
|
||||
const SdfLayerHandle& sourceLayer,
|
||||
const std::string& assetPath);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif /* PXR_USD_USD_UTILS_FLATTEN_LAYER_STACK_H */
|
||||
@@ -0,0 +1,127 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_INTROSPECTION_H
|
||||
#define PXR_USD_USD_UTILS_INTROSPECTION_H
|
||||
|
||||
/// \file usdUtils/introspection.h
|
||||
///
|
||||
/// Collection of module-scoped utilities for introspecting a given USD stage.
|
||||
/// Future additions might include full-on dependency extraction, queries like
|
||||
/// "Does this stage contain this asset?", "usd grep" functionality, etc.
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include "pxr/usd/usd/stage.h"
|
||||
|
||||
#include "pxr/base/tf/envSetting.h"
|
||||
#include "pxr/base/vt/dictionary.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
#define USDUTILS_USDSTAGE_STATS \
|
||||
(approxMemoryInMb) \
|
||||
(totalPrimCount) \
|
||||
(modelCount) \
|
||||
(instancedModelCount) \
|
||||
(assetCount) \
|
||||
(prototypeCount) \
|
||||
(totalInstanceCount) \
|
||||
(usedLayerCount) \
|
||||
(primary) \
|
||||
(prototypes) \
|
||||
(primCounts) \
|
||||
/*(totalPrimCount)*/ \
|
||||
(activePrimCount) \
|
||||
(inactivePrimCount) \
|
||||
(pureOverCount) \
|
||||
(instanceCount) \
|
||||
(primCountsByType) \
|
||||
(untyped)
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(UsdUtilsUsdStageStatsKeys,
|
||||
USDUTILS_API, USDUTILS_USDSTAGE_STATS);
|
||||
|
||||
/// Opens the given layer on a USD stage and collects various stats.
|
||||
/// The stats are populated in the dictionary-valued output param \p stats.
|
||||
///
|
||||
/// The set of stats include:
|
||||
/// * approxMemoryInMb - approximate memory allocated when opening the stage
|
||||
/// with all the models loaded.
|
||||
/// * totalPrimCount - total number of prims
|
||||
/// * modelCount - number of models
|
||||
/// * instancedModelCount - number of instanced models
|
||||
/// * assetCount - number of assets
|
||||
/// * prototypeCount - number of prototypes
|
||||
/// * totalInstanceCount - total number of instances (including nested instances)
|
||||
/// * two sub-dictionaries, 'primary' and 'prototypes' for the "primary" prim tree
|
||||
/// and for all the prototype subtrees respectively, containing the following
|
||||
/// stats:
|
||||
/// * primCounts - a sub-dictionary containing the following
|
||||
/// * totalPrimCount - number of prims
|
||||
/// * activePrimCount - number of active prims
|
||||
/// * inactivePrimCount - number of inactive prims
|
||||
/// * pureOverCount - number of pure overs
|
||||
/// * instanceCount - number of instances
|
||||
/// * primCountsByType - a sub-dictionary containing prim counts keyed by the
|
||||
/// prim type.
|
||||
///
|
||||
/// Returns the stage that was opened.
|
||||
///
|
||||
/// The "prototypes" subdictionary is populated only if the stage has one or more
|
||||
/// instanced models.
|
||||
///
|
||||
/// \note The approximate memory allocated when opening the stage is computed
|
||||
/// and reported *only* if the TfMallocTag system has already been initialized
|
||||
/// by the client, and the number will represent only *additional* consumed
|
||||
/// memory, so if some of the layers the stage uses are already open, the true
|
||||
/// memory consumption for the stage may be higher than reported.
|
||||
/// \sa TfMallocTag::IsInitialized()
|
||||
///
|
||||
/// \note Only component models are included in 'modelCount' and
|
||||
/// 'instancedModelCount'.
|
||||
///
|
||||
USDUTILS_API
|
||||
UsdStageRefPtr UsdUtilsComputeUsdStageStats(const std::string &rootLayerPath,
|
||||
VtDictionary *stats);
|
||||
|
||||
/// \overload
|
||||
/// Computes stats on an already opened USD stage.
|
||||
///
|
||||
/// Returns the total number of prims on the stage, including active, inactive.
|
||||
/// pure overs, prims inside prototypes etc.
|
||||
///
|
||||
USDUTILS_API
|
||||
size_t UsdUtilsComputeUsdStageStats(const UsdStageWeakPtr &stage,
|
||||
VtDictionary *stats);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif /* PXR_USD_USD_UTILS_INTROSPECTION_H */
|
||||
@@ -0,0 +1,159 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_PIPELINE_H
|
||||
#define PXR_USD_USD_UTILS_PIPELINE_H
|
||||
|
||||
/// \file usdUtils/pipeline.h
|
||||
///
|
||||
/// Collection of module-scoped utilities for establishing pipeline
|
||||
/// conventions for things not currently suitable or possible to canonize in
|
||||
/// USD's schema modules.
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
#include "pxr/usd/usdUtils/registeredVariantSet.h"
|
||||
|
||||
#include "pxr/base/tf/envSetting.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
#include "pxr/usd/usd/common.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
USDUTILS_API
|
||||
extern TfEnvSetting<bool> USD_FORCE_DEFAULT_MATERIALS_SCOPE_NAME;
|
||||
|
||||
/// Define the shading pipeline's convention for naming a companion
|
||||
/// alpha/opacity attribute and primvarnames given the full name of a
|
||||
/// color-valued attribute
|
||||
USDUTILS_API
|
||||
TfToken UsdUtilsGetAlphaAttributeNameForColor(TfToken const &colorAttrName);
|
||||
|
||||
/// Returns the model name associated with a given root layer. In order,
|
||||
/// it looks for defaultPrim metadata, a prim matching the filename,
|
||||
/// and then the first concrete root prim.
|
||||
USDUTILS_API
|
||||
TfToken UsdUtilsGetModelNameFromRootLayer(const SdfLayerHandle& rootLayer);
|
||||
|
||||
/// Certain variant sets can be registered with the system.
|
||||
/// \sa UsdUtilsRegisteredVariantSet
|
||||
///
|
||||
|
||||
/// Returns the set of UsdUtilsRegisteredVariantSet objects that are registered
|
||||
/// with the pipeline.
|
||||
///
|
||||
/// This list will be empty until one or more plugInfo.json files
|
||||
/// discoverable by your USD installation contain an entry in the
|
||||
/// UsdUtilsPipeline group like the following:
|
||||
/// \code{json}
|
||||
/// "UsdUtilsPipeline": {
|
||||
/// "RegisteredVariantSets": [
|
||||
/// "modelingVariant": {
|
||||
/// "selectionExportPolicy": {
|
||||
/// "always"
|
||||
/// }
|
||||
/// },
|
||||
/// "standin": {
|
||||
/// "selectionExportPolicy": {
|
||||
/// "never"
|
||||
/// }
|
||||
/// }
|
||||
/// ]
|
||||
/// }
|
||||
/// \endcode
|
||||
USDUTILS_API
|
||||
const std::set<UsdUtilsRegisteredVariantSet>& UsdUtilsGetRegisteredVariantSets();
|
||||
|
||||
/// If a valid UsdPrim already exists at \p path on the USD stage \p stage,
|
||||
/// returns it. It not, it checks to see if the path belongs to a prim
|
||||
/// underneath an instance and returns the corresponding prototype prim.
|
||||
///
|
||||
/// This returns an invalid UsdPrim if no corresponding prototype prim can be
|
||||
/// found and if no prim exists at the path.
|
||||
///
|
||||
/// This method is similar to UsdStage::GetPrimAtPath(), in that it will never
|
||||
/// author scene description, and therefore is safe to use as a "reader" in the
|
||||
/// Usd multi-threading model.
|
||||
USDUTILS_API
|
||||
UsdPrim UsdUtilsGetPrimAtPathWithForwarding(const UsdStagePtr &stage,
|
||||
const SdfPath &path);
|
||||
|
||||
/// Given a path, uninstances all the instanced prims in the namespace chain and
|
||||
/// returns the resulting prim at the requested path. Returns a NULL prim if the
|
||||
/// given path doesn't exist and does not correspond to a valid prim inside a
|
||||
/// prototype.
|
||||
USDUTILS_API
|
||||
UsdPrim UsdUtilsUninstancePrimAtPath(const UsdStagePtr &stage,
|
||||
const SdfPath &path);
|
||||
|
||||
/// Returns the name of the primary UV set used on meshes and nurbs.
|
||||
/// By default the name is "st".
|
||||
USDUTILS_API
|
||||
const TfToken& UsdUtilsGetPrimaryUVSetName();
|
||||
|
||||
/// Returns the name of the reference position used on meshes and nurbs.
|
||||
/// By default the name is "pref".
|
||||
USDUTILS_API
|
||||
const TfToken& UsdUtilsGetPrefName();
|
||||
|
||||
/// Get the name of the USD prim under which materials are expected to be
|
||||
/// authored.
|
||||
///
|
||||
/// The scope name can be configured in the metadata of a plugInfo.json file
|
||||
/// like so:
|
||||
/// \code{json}
|
||||
/// "UsdUtilsPipeline": {
|
||||
/// "MaterialsScopeName": "SomeScopeName"
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// If \p forceDefault is true, any value specified in a plugInfo.json will be
|
||||
/// ignored and the built-in default will be returned. This is primarily used
|
||||
/// for unit testing purposes as a way to ignore any site-based configuration.
|
||||
USDUTILS_API
|
||||
TfToken UsdUtilsGetMaterialsScopeName(const bool forceDefault = false);
|
||||
|
||||
/// Get the name of the USD prim representing the primary camera.
|
||||
/// By default the name is "main_cam".
|
||||
///
|
||||
/// The camera name can be configured in the metadata of a plugInfo.json file
|
||||
/// like so:
|
||||
/// \code{json}
|
||||
/// "UsdUtilsPipeline": {
|
||||
/// "PrimaryCameraName": "SomeCameraName"
|
||||
/// }
|
||||
/// \endcode
|
||||
///
|
||||
/// If \p forceDefault is true, any value specified in a plugInfo.json will be
|
||||
/// ignored and the built-in default will be returned. This is primarily used
|
||||
/// for unit testing purposes as a way to ignore any site-based configuration.
|
||||
USDUTILS_API
|
||||
TfToken UsdUtilsGetPrimaryCameraName(const bool forceDefault = false);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_REGISTERED_VARIANT_SET_H
|
||||
#define PXR_USD_USD_UTILS_REGISTERED_VARIANT_SET_H
|
||||
|
||||
/// \file usdUtils/registeredVariantSet.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
/// \class UsdUtilsRegisteredVariantSet
|
||||
///
|
||||
/// Class that holds information about variantSets that are registered with
|
||||
/// the pipeline.
|
||||
///
|
||||
/// Registered variantSets are known variantSets in a pipeline that may need to
|
||||
/// be reasoned about by apps during import/export.
|
||||
///
|
||||
/// \sa UsdUtilsGetRegisteredVariantSets
|
||||
struct UsdUtilsRegisteredVariantSet
|
||||
{
|
||||
public:
|
||||
/// The name of the variantSet.
|
||||
const std::string name;
|
||||
|
||||
/// This specifies how the variantSet should be treated during export.
|
||||
///
|
||||
/// Note, in the plugInfo.json, the values for these enum's are
|
||||
/// lowerCamelCase.
|
||||
enum class SelectionExportPolicy {
|
||||
/// Never
|
||||
///
|
||||
/// This variantSet selection is meant to remain entirely within an
|
||||
/// application. This typically represents a "session" variantSelection
|
||||
/// that should not be transmitted down the pipeline.
|
||||
Never,
|
||||
|
||||
/// IfAuthored
|
||||
///
|
||||
/// This variantSet selection should be exported if there is an authored
|
||||
/// opinion in the application. This is only relevant if the
|
||||
/// application is able to distinguish between "default" and "set"
|
||||
/// opinions.
|
||||
IfAuthored,
|
||||
|
||||
/// Authored
|
||||
///
|
||||
/// This variantSet selection should always be exported.
|
||||
Always,
|
||||
};
|
||||
|
||||
/// Specifies how to export a variant selection.
|
||||
const SelectionExportPolicy selectionExportPolicy;
|
||||
|
||||
UsdUtilsRegisteredVariantSet(
|
||||
const std::string& name,
|
||||
const SelectionExportPolicy& selectionExportPolicy) :
|
||||
name(name),
|
||||
selectionExportPolicy(selectionExportPolicy)
|
||||
{
|
||||
}
|
||||
|
||||
// provided so this can be stored in a std::set.
|
||||
bool operator<(const UsdUtilsRegisteredVariantSet&
|
||||
other) const {
|
||||
return this->name < other.name;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif /* PXR_USD_USD_UTILS_REGISTERED_VARIANT_SET_H */
|
||||
@@ -0,0 +1,295 @@
|
||||
//
|
||||
// Copyright 2018 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_SPARSE_VALUE_WRITER_H
|
||||
#define PXR_USD_USD_UTILS_SPARSE_VALUE_WRITER_H
|
||||
|
||||
/// \file usdUtils/sparseValueWriter.h
|
||||
///
|
||||
/// A collection of utilities for authoring time-varying attribute values with
|
||||
/// basic run-length encoding.
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
|
||||
#include "pxr/base/vt/value.h"
|
||||
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
#include "pxr/usd/usd/attribute.h"
|
||||
#include "pxr/usd/usd/timeCode.h"
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
/// \class UsdUtilsSparseAttrValueWriter
|
||||
///
|
||||
/// A utility class for authoring time-varying attribute values with
|
||||
/// simple run-length encoding, by skipping any redundant time-samples.
|
||||
/// Time-samples that are close enough to each other, with relative difference
|
||||
/// smaller than a fixed epsilon value are considered to be equivalent. This is
|
||||
/// to avoid unnecessary authoring of time-samples caused by numerical fuzz in
|
||||
/// certain computations.
|
||||
///
|
||||
/// For vectors, matrices, and other composite types (like quaternions and
|
||||
/// arrays), each component is compared with the corresponding component for
|
||||
/// closeness. The chosen epsilon value for double precision floating point
|
||||
/// numbers is 1e-12. For single-precision, it is 1e-6 and for half-precision,
|
||||
/// it is 1e-2.
|
||||
///
|
||||
/// Example c++ usage:
|
||||
/// \code
|
||||
/// UsdGeomSphere sphere = UsdGeomSphere::Define(stage, SdfPath("/Sphere"));
|
||||
/// UsdAttribute radius = sphere.CreateRadiusAttr();
|
||||
/// UsdUtilsSparseAttrValueWriter attrValueWriter(radius,
|
||||
/// /*defaultValue*/ VtValue(1.0));
|
||||
/// attrValueWriter.SetTimeSample(VtValue(10.0), UsdTimeCode(1.0));
|
||||
/// attrValueWriter.SetTimeSample(VtValue(10.0), UsdTimeCode(2.0));
|
||||
/// attrValueWriter.SetTimeSample(VtValue(10.0), UsdTimeCode(3.0));
|
||||
/// attrValueWriter.SetTimeSample(VtValue(20.0), UsdTimeCode(4.0));
|
||||
/// \endcode
|
||||
///
|
||||
/// Equivalent python example:
|
||||
/// \code
|
||||
/// sphere = UsdGeom.Sphere.Define(stage, Sdf.Path("/Sphere"))
|
||||
/// radius = sphere.CreateRadiusAttr()
|
||||
/// attrValueWriter = UsdUtils.SparseAttrValueWriter(radius, defaultValue=1.0)
|
||||
/// attrValueWriter.SetTimeSample(10.0, 1.0)
|
||||
/// attrValueWriter.SetTimeSample(10.0, 2.0)
|
||||
/// attrValueWriter.SetTimeSample(10.0, 3.0)
|
||||
/// attrValueWriter.SetTimeSample(20.0, 4.0)
|
||||
/// \endcode
|
||||
///
|
||||
/// In the above examples, the specified default value of radius (1.0) will not
|
||||
/// be authored into scene description since it matches the fallback value.
|
||||
/// Additionally, the time-sample authored at time=2.0 will be skipped since
|
||||
/// it is redundant. Also note that for correct behavior, the calls to
|
||||
/// SetTimeSample() must be made with sequentially increasing time
|
||||
/// values. If not, a coding error is issued and the authored animation may be
|
||||
/// incorrect.
|
||||
///
|
||||
class UsdUtilsSparseAttrValueWriter {
|
||||
public:
|
||||
/// The constructor initializes the data required for run-length encoding of
|
||||
/// time-samples. It also sets the default value of \p attr to
|
||||
/// \p defaultValue, if \p defaultValue is non-empty and different from the
|
||||
/// existing default value of \p attr.
|
||||
///
|
||||
/// \p defaultValue can be unspecified (or left empty) if you don't
|
||||
/// care about authoring a default value. In this case, the sparse authoring
|
||||
/// logic is initialized with the existing authored default value or
|
||||
/// the fallback value, if \p attr has one.
|
||||
USDUTILS_API
|
||||
UsdUtilsSparseAttrValueWriter(const UsdAttribute &attr,
|
||||
const VtValue &defaultValue=VtValue());
|
||||
|
||||
/// The constructor initializes the data required for run-length encoding of
|
||||
/// time-samples. It also sets the default value of \p attr to
|
||||
/// \p defaultValue, if \p defaultValue is non-empty and different from
|
||||
/// the existing default value of \p attr.
|
||||
///
|
||||
/// It \p defaultValue is null or points to an empty VtValue, the sparse
|
||||
/// authoring logic is intialized with the existing authored default value
|
||||
/// or the fallback value, if \p attr has one.
|
||||
///
|
||||
/// For efficiency, this function swaps out the given \p defaultValue,
|
||||
/// leaving it empty.
|
||||
USDUTILS_API
|
||||
UsdUtilsSparseAttrValueWriter(const UsdAttribute &attr, VtValue *defaultValue);
|
||||
|
||||
/// Sets a new time-sample on the attribute with given \p value at the
|
||||
/// given \p time. The time-sample is only authored if it's different
|
||||
/// from the previously set time-sample, in which case the previous
|
||||
/// time-sample is also authored, in order to to end the previous run
|
||||
/// of contiguous identical values and start a new run.
|
||||
///
|
||||
/// This incurs a copy of \p value. Also, the value will be held in
|
||||
/// memory at least until the next time-sample is written or until the
|
||||
/// SparseAttrValueWriter instance is destroyed.
|
||||
USDUTILS_API
|
||||
bool SetTimeSample(const VtValue &value, const UsdTimeCode time);
|
||||
|
||||
/// \overload
|
||||
///
|
||||
/// For efficiency, this function swaps out the given \p value, leaving
|
||||
/// it empty. The value will be held in memory at least until the next
|
||||
/// time-sample is written or until the SparseAttrValueWriter instance is
|
||||
/// destroyed.
|
||||
USDUTILS_API
|
||||
bool SetTimeSample(VtValue *value, const UsdTimeCode time);
|
||||
|
||||
/// Returns the attribute that's held in the sparse value writer.
|
||||
const UsdAttribute & GetAttr() const {
|
||||
return _attr;
|
||||
}
|
||||
|
||||
private:
|
||||
// Helper method to initialize the sparse authoring scheme.
|
||||
void _InitializeSparseAuthoring(VtValue *defaultValue);
|
||||
|
||||
// The attribute whose time-samples will be authored via public API.
|
||||
const UsdAttribute _attr;
|
||||
|
||||
// The time at which previous time-sample was authored.
|
||||
UsdTimeCode _prevTime = UsdTimeCode::Default();
|
||||
|
||||
// The value at previously authored time-sample.
|
||||
VtValue _prevValue;
|
||||
|
||||
// Whether a time-sample was written at _prevTime (with value=_prevValue).
|
||||
bool _didWritePrevValue=true;
|
||||
};
|
||||
|
||||
/// \class UsdUtilsSparseValueWriter
|
||||
///
|
||||
/// Utility class that manages sparse authoring of a set of UsdAttributes.
|
||||
/// It does this by maintaining a map of UsdAttributes to their corresponding
|
||||
/// UsdUtilsSparseAttrValueWriter objects.
|
||||
///
|
||||
/// To use this class, simply instantiate an instance of it and invoke
|
||||
/// the SetAttribute() method with various attributes and their associated
|
||||
/// time-samples.
|
||||
///
|
||||
/// \note If the attribute has a default value, SetAttribute() must be
|
||||
/// called with time=Default first (multiple times, if necessary), followed by
|
||||
/// calls to author time-samples in sequentially increasing time order.
|
||||
///
|
||||
/// \note This class is not threadsafe.
|
||||
/// In general, authoring to a single USD layer from multiple threads isn't
|
||||
/// threadsafe. Hence, there is little value in making this class threadsafe.
|
||||
///
|
||||
///
|
||||
/// Example c++ usage:
|
||||
/// \code
|
||||
/// UsdGeomCylinder cylinder = UsdGeomCylinder::Define(stage, SdfPath("/Cylinder"));
|
||||
/// UsdAttribute radius = cylinder.CreateRadiusAttr();
|
||||
/// UsdAttribute height = cylinder.CreateHeightAttr();
|
||||
/// UsdUtilsSparseValueWriter valueWriter;
|
||||
/// valueWriter.SetAttribute(radius, 2.0, UsdTimeCode::Default());
|
||||
/// valueWriter.SetAttribute(height, 2.0, UsdTimeCode::Default());
|
||||
///
|
||||
/// valueWriter.SetAttribute(radius, 10.0, UsdTimeCode(1.0));
|
||||
/// valueWriter.SetAttribute(radius, 20.0, UsdTimeCode(2.0));
|
||||
/// valueWriter.SetAttribute(radius, 20.0, UsdTimeCode(3.0));
|
||||
/// valueWriter.SetAttribute(radius, 20.0, UsdTimeCode(4.0));
|
||||
///
|
||||
/// valueWriter.SetAttribute(height, 2.0, UsdTimeCode(1.0));
|
||||
/// valueWriter.SetAttribute(height, 2.0, UsdTimeCode(2.0));
|
||||
/// valueWriter.SetAttribute(height, 3.0, UsdTimeCode(3.0));
|
||||
/// valueWriter.SetAttribute(height, 3.0, UsdTimeCode(4.0));
|
||||
/// \endcode
|
||||
///
|
||||
/// Equivalent python code:
|
||||
/// \code{.py}
|
||||
/// cylinder = UsdGeom.Cylinder.Define(stage, Sdf.Path("/Cylinder"))
|
||||
/// radius = cylinder.CreateRadiusAttr()
|
||||
/// height = cylinder.CreateHeightAttr()
|
||||
/// valueWriter = UsdUtils.SparseValueWriter()
|
||||
/// valueWriter.SetAttribute(radius, 2.0, Usd.TimeCode.Default())
|
||||
/// valueWriter.SetAttribute(height, 2.0, Usd.TimeCode.Default())
|
||||
///
|
||||
/// valueWriter.SetAttribute(radius, 10.0, 1.0)
|
||||
/// valueWriter.SetAttribute(radius, 20.0, 2.0)
|
||||
/// valueWriter.SetAttribute(radius, 20.0, 3.0)
|
||||
/// valueWriter.SetAttribute(radius, 20.0, 4.0)
|
||||
///
|
||||
/// valueWriter.SetAttribute(height, 2.0, 1.0)
|
||||
/// valueWriter.SetAttribute(height, 2.0, 2.0)
|
||||
/// valueWriter.SetAttribute(height, 3.0, 3.0)
|
||||
/// valueWriter.SetAttribute(height, 3.0, 4.0)
|
||||
/// \endcode
|
||||
///
|
||||
/// In the above example,
|
||||
/// <ul><li>The default value of the "height" attribute is not authored into scene
|
||||
/// description since it matches the fallback value.</li>
|
||||
/// <li>Time-samples at time=3.0 and time=4.0 will be skipped for the radius
|
||||
/// attribute.</li>
|
||||
/// <li>For the "height" attribute, the first timesample at time=1.0 will be
|
||||
/// skipped since it matches the default value.</li>
|
||||
/// <li>The last time-sample at time=4.0 will also be skipped for "height"
|
||||
/// since it matches the previously written value at time=3.0.</li>
|
||||
/// </ul>
|
||||
class UsdUtilsSparseValueWriter {
|
||||
public:
|
||||
/// Sets the value of \p attr to \p value at time \p time. The value
|
||||
/// is written sparsely, i.e., the default value is authored only if
|
||||
/// it is different from the fallback value or the existing default value,
|
||||
/// and any redundant time-samples are skipped when the attribute value does
|
||||
/// not change significantly between consecutive time-samples.
|
||||
USDUTILS_API
|
||||
bool SetAttribute(const UsdAttribute &attr,
|
||||
const VtValue &value,
|
||||
const UsdTimeCode time=UsdTimeCode::Default());
|
||||
|
||||
/// \overload
|
||||
/// For efficiency, this function swaps out the given \p value, leaving
|
||||
/// it empty. The value will be held in memory at least until the next
|
||||
/// time-sample is written or until the SparseAttrValueWriter instance is
|
||||
/// destroyed.
|
||||
USDUTILS_API
|
||||
bool SetAttribute(const UsdAttribute &attr,
|
||||
VtValue *value,
|
||||
const UsdTimeCode time=UsdTimeCode::Default());
|
||||
|
||||
/// \overload
|
||||
template<typename T>
|
||||
bool SetAttribute(const UsdAttribute &attr,
|
||||
T &value,
|
||||
const UsdTimeCode time=UsdTimeCode::Default())
|
||||
{
|
||||
VtValue val = VtValue::Take(value);
|
||||
return SetAttribute(attr, &val, time);
|
||||
}
|
||||
|
||||
/// Clears the internal map, thereby releasing all the memory used by
|
||||
/// the sparse value-writers.
|
||||
USDUTILS_API
|
||||
void Clear() {
|
||||
_attrValueWriterMap.clear();
|
||||
}
|
||||
|
||||
/// Returns a new vector of UsdUtilsSparseAttrValueWriter populated
|
||||
/// from the attrValueWriter map.
|
||||
USDUTILS_API
|
||||
std::vector<UsdUtilsSparseAttrValueWriter>
|
||||
GetSparseAttrValueWriters() const;
|
||||
|
||||
private:
|
||||
// Templated helper method used by the two public SetAttribute() methods.
|
||||
template <typename T>
|
||||
bool _SetAttributeImpl(const UsdAttribute &attr,
|
||||
T &value,
|
||||
const UsdTimeCode time);
|
||||
|
||||
struct _AttrHash {
|
||||
inline size_t operator() (const UsdAttribute &attr) const {
|
||||
return hash_value(attr);
|
||||
}
|
||||
};
|
||||
|
||||
using _AttrValueWriterMap = std::unordered_map<UsdAttribute,
|
||||
UsdUtilsSparseAttrValueWriter,
|
||||
_AttrHash>;
|
||||
_AttrValueWriterMap _attrValueWriterMap;
|
||||
};
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_STAGE_CACHE_H
|
||||
#define PXR_USD_USD_UTILS_STAGE_CACHE_H
|
||||
|
||||
/// \file usdUtils/stageCache.h
|
||||
/// A simple interface for handling a singleton usd stage cache.
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
#include "pxr/usd/usd/stageCache.h"
|
||||
|
||||
#include "pxr/base/tf/declarePtrs.h"
|
||||
#include "pxr/base/tf/token.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
TF_DECLARE_WEAK_AND_REF_PTRS(SdfLayer);
|
||||
|
||||
/// \class UsdUtilsStageCache
|
||||
///
|
||||
/// The UsdUtilsStageCache class provides a simple interface for handling a
|
||||
/// singleton usd stage cache for use by all USD clients. This way code from
|
||||
/// any location can make use of the same cache to maximize stage reuse.
|
||||
///
|
||||
class UsdUtilsStageCache {
|
||||
public:
|
||||
|
||||
/// Returns the singleton stage cache.
|
||||
USDUTILS_API
|
||||
static UsdStageCache &Get();
|
||||
|
||||
/// Given variant selections as a vector of pairs (vector in case order
|
||||
/// matters to the client), constructs a session layer with overs on the
|
||||
/// given root modelName with the variant selections, or returns a cached
|
||||
/// session layer with those opinions.
|
||||
USDUTILS_API
|
||||
static SdfLayerRefPtr GetSessionLayerForVariantSelections(
|
||||
const TfToken& modelName,
|
||||
const std::vector<std::pair<std::string, std::string> > &variantSelections);
|
||||
};
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif /* PXR_USD_USD_UTILS_STAGE_CACHE_H */
|
||||
@@ -0,0 +1,137 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_STITCH_H
|
||||
#define PXR_USD_USD_UTILS_STITCH_H
|
||||
|
||||
/// \file usdUtils/stitch.h
|
||||
///
|
||||
/// Collection of module-scoped utilities for combining layers.
|
||||
/// These utilize the convention of a strong and a weak layer. The strong
|
||||
/// layer will be the first parameter to the function and will always have
|
||||
/// precedence in conflicts during the merge.
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/spec.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
/// Merge all scene description in \p weakLayer into \p strongLayer.
|
||||
///
|
||||
/// Prims and properties in \p weakLayer that do not exist in \p strongLayer
|
||||
/// will be copied into \p strongLayer. Prims and properties that do
|
||||
/// exist in \p strongLayer will be merged with the existing scene
|
||||
/// description.
|
||||
///
|
||||
/// Merging prims and properties is done on a field-by-field basis.
|
||||
/// In general, if a field has a value in \p strongLayer, the value from
|
||||
/// \p weakLayer will be ignored. However, certain fields have special
|
||||
/// rules for merging values together:
|
||||
///
|
||||
/// - For map and dictionary-valued fields (including time samples),
|
||||
/// a dictionary merge is performed; values in the weaker dictionary
|
||||
/// are copied into the stronger dictionary only if the key does not
|
||||
/// already exist.
|
||||
///
|
||||
/// - For listOp-valued fields, the listOps will be combined into a
|
||||
/// single listOp. The historical "add" and "reorder" list op operations
|
||||
/// cannot be combined in this way; "add" will be converted to "append",
|
||||
/// and "reorder" will be discarded.
|
||||
///
|
||||
/// - The minimum startTimeCode value and maximum endTimeCode value will
|
||||
/// be used.
|
||||
USDUTILS_API
|
||||
void UsdUtilsStitchLayers(
|
||||
const SdfLayerHandle& strongLayer,
|
||||
const SdfLayerHandle& weakLayer);
|
||||
|
||||
/// Merge the scene description for \p weakObj into \p strongObj.
|
||||
///
|
||||
/// See documentation on UsdUtilsStitchLayers for a description of
|
||||
/// the merging behavior.
|
||||
USDUTILS_API
|
||||
void UsdUtilsStitchInfo(
|
||||
const SdfSpecHandle& strongObj,
|
||||
const SdfSpecHandle& weakObj);
|
||||
|
||||
/// \name Advanced Stitching API
|
||||
/// @{
|
||||
|
||||
/// Status enum returned by UsdUtilsStitchValueFn describing the
|
||||
/// desired value stitching behavior.
|
||||
enum class UsdUtilsStitchValueStatus
|
||||
{
|
||||
NoStitchedValue, ///< Don't stitch values for this field.
|
||||
UseDefaultValue, ///< Use the default stitching behavior for this field.
|
||||
UseSuppliedValue ///< Use the value supplied in stitchedValue.
|
||||
};
|
||||
|
||||
/// Callback for customizing how values are stitched together.
|
||||
///
|
||||
/// This callback will be invoked for each field being stitched from the
|
||||
/// source spec at \p path in \p weakLayer to the destination spec at
|
||||
/// \p path in \p strongLayer. \p fieldInStrongLayer and \p fieldInWeakLayer
|
||||
/// indicates whether the field has values in either layer.
|
||||
///
|
||||
/// The callback should return a UsdUtilsStitchValueStatus to indicate the
|
||||
/// desired behavior. Note that if the callback returns UseSuppliedValue and
|
||||
/// supplies an empty VtValue in \p stitchedValue, the field will be removed
|
||||
/// from the destination spec.
|
||||
using UsdUtilsStitchValueFn = std::function<
|
||||
UsdUtilsStitchValueStatus(
|
||||
const TfToken& field, const SdfPath& path,
|
||||
const SdfLayerHandle& strongLayer, bool fieldInStrongLayer,
|
||||
const SdfLayerHandle& weakLayer, bool fieldInWeakLayer,
|
||||
VtValue* stitchedValue)>;
|
||||
|
||||
/// Advanced version of UsdUtilsStitchLayers that accepts a \p stitchValueFn
|
||||
/// callback to customize how fields in \p strongLayer and \p weakLayer are
|
||||
/// stitched together. See documentation on UsdUtilsStitchValueFn for more
|
||||
/// details.
|
||||
USDUTILS_API
|
||||
void UsdUtilsStitchLayers(
|
||||
const SdfLayerHandle& strongLayer,
|
||||
const SdfLayerHandle& weakLayer,
|
||||
const UsdUtilsStitchValueFn& stitchValueFn);
|
||||
|
||||
/// Advanced version of UsdUtilsStitchInfo that accepts a \p stitchValueFn
|
||||
/// callback to customize how fields in \p strongObj and \p weakObj are
|
||||
/// stitched together. See documentation on UsdUtilsStitchValueFn for more
|
||||
/// details.
|
||||
USDUTILS_API
|
||||
void UsdUtilsStitchInfo(
|
||||
const SdfSpecHandle& strongObj,
|
||||
const SdfSpecHandle& weakObj,
|
||||
const UsdUtilsStitchValueFn& stitchValueFn);
|
||||
|
||||
/// @}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif /* PXR_USD_USD_UTILS_STITCH_H */
|
||||
@@ -0,0 +1,264 @@
|
||||
//
|
||||
// Copyright 2016 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_STITCH_CLIPS_H
|
||||
#define PXR_USD_USD_UTILS_STITCH_CLIPS_H
|
||||
|
||||
/// \file usdUtils/stitchClips.h
|
||||
///
|
||||
/// Collection of utilities for sequencing multiple layers each holding
|
||||
/// sequential time-varying data into
|
||||
/// \ref Usd_Page_ValueClips "USD Value Clips".
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
#include "pxr/usd/usd/clipsAPI.h"
|
||||
#include "pxr/usd/sdf/declareHandles.h"
|
||||
#include "pxr/usd/sdf/path.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
SDF_DECLARE_HANDLES(SdfLayer);
|
||||
|
||||
/// A function that creates layers that use
|
||||
/// \ref Usd_Page_ValueClips "USD Value Clips"
|
||||
/// to effectively merge the time samples in the given \p clipLayers under \p
|
||||
/// clipPath without copying the samples into a separate layer.
|
||||
///
|
||||
/// \p resultLayer The layer to which clip metadata and frame data
|
||||
/// will be written. The layer representing the static
|
||||
/// scene topology will be authored as a sublayer on
|
||||
/// this layer as well; it will be authored as the
|
||||
/// first sublayer in the list(strongest).
|
||||
///
|
||||
/// \p clipLayerFiles The files containing the time varying data.
|
||||
///
|
||||
/// \p clipPath The path at which we will put the clip metadata.
|
||||
///
|
||||
/// \p startTimeCode The first time coordinate for the rootLayer
|
||||
/// to point to. If none is provided, it will be
|
||||
/// the lowest startTimeCode available from
|
||||
/// the \p clipLayers.
|
||||
///
|
||||
/// \p endTimeCode The last time coordinate for the rootLayer to
|
||||
/// point to. If none is provided, it will be the
|
||||
/// highest endTimeCode authored from the
|
||||
/// \p clipLayers.
|
||||
///
|
||||
/// \p interpolateMissingClipValues
|
||||
/// Whether values for clips without samples are
|
||||
/// interpolated from surrounding clips. See
|
||||
/// UsdClipsAPI::GetInterpolateMissingClipValues
|
||||
/// for more details.
|
||||
///
|
||||
/// \p clipSet The name of the clipSet in which the
|
||||
/// aforementioned metadata will be authored.
|
||||
/// \note If this parameter is omitted, the default
|
||||
/// clipSet name will be authored.
|
||||
///
|
||||
/// Details on how this is accomplished can be found below:
|
||||
///
|
||||
/// Pre-existing opinions will be wiped away upon success. Upon failure, the
|
||||
/// original topology and manifest layers, if pre-existing, will be preserved.
|
||||
/// These layers will be named/looked up via the following scheme:
|
||||
///
|
||||
/// topologyLayerName = <resultIdWithoutExt>.topology.<resultExt>
|
||||
/// manifestLayerName = <resultIdWithoutExt>.manifest.<resultExt>
|
||||
///
|
||||
/// For example: if the resultLayerFile's name is foo.usd the expected topology
|
||||
/// layer will be foo.topology.usd and the expected manifest layer will be
|
||||
/// foo.manifest.usd.
|
||||
///
|
||||
/// The topology layer contains the aggregated topology of the set of
|
||||
/// \p clipLayers. This process will merge prims and properties, save for time
|
||||
/// varying properties, those will be accessed from the original
|
||||
/// clip files.
|
||||
///
|
||||
/// The aggregation of topology works by merging a clipLayer at a time with
|
||||
/// the topologyLayer. If a prim already exists in the topologyLayer, its
|
||||
/// attributes will be merged.
|
||||
///
|
||||
/// For example, if we have a layer, clipA with attributes /World/fx/foo.bar
|
||||
/// and a second layer with /World/fx/foo.baz. Our aggregate topology layer
|
||||
/// will contain both /World/fx/foo.bar, /World/fx/foo.baz.
|
||||
///
|
||||
/// The manifest layer contains declarations for all attributes that exist
|
||||
/// under \p clipPath and descendants in the clip layers with authored time
|
||||
/// samples. Any default values authored into the topology layer for these
|
||||
/// time sampled attributes will also be authored into the manifest.
|
||||
///
|
||||
/// The \p resultLayer will contain clip metadata at the specified \p clipPath.
|
||||
/// The resultLayer will also have timeCode range data, such as start and end
|
||||
/// timeCodes written to it, with the starting position being provided by
|
||||
/// \p startTimeCode and the ending provided by \p endTimeCode.
|
||||
///
|
||||
/// Note: an invalid clip path(because the prim doesn't exist in
|
||||
/// the aggregate topologyLayer) will result in a TF_CODING_ERROR.
|
||||
///
|
||||
USDUTILS_API
|
||||
bool
|
||||
UsdUtilsStitchClips(const SdfLayerHandle& resultLayer,
|
||||
const std::vector<std::string>& clipLayerFiles,
|
||||
const SdfPath& clipPath,
|
||||
const double startTimeCode
|
||||
= std::numeric_limits<double>::max(),
|
||||
const double endTimeCode
|
||||
= std::numeric_limits<double>::max(),
|
||||
const bool interpolateMissingClipValues
|
||||
= false,
|
||||
const TfToken& clipSet
|
||||
= UsdClipsAPISetNames->default_);
|
||||
|
||||
/// A function which aggregates the topology of a set of \p clipLayerFiles
|
||||
/// for use in USD's Value Clips system. This aggregated scene topology
|
||||
/// will only include non-time-varying data, as it is for use in conjunction
|
||||
/// with the value clip metadata in a manifest layer.
|
||||
///
|
||||
/// \p topologyLayer The layer in which topology of the
|
||||
/// \p clipLayerFiles will be aggregated and inserted.
|
||||
///
|
||||
/// \p clipLayerFiles The files containing the time varying data.
|
||||
///
|
||||
USDUTILS_API
|
||||
bool
|
||||
UsdUtilsStitchClipsTopology(const SdfLayerHandle& topologyLayer,
|
||||
const std::vector<std::string>& clipLayerFiles);
|
||||
|
||||
/// A function which creates a clip manifest from the set of \p clipLayerFiles
|
||||
/// for use in USD's Value Clips system. This manifest will contain
|
||||
/// declarations for attributes with authored time samples in the clip layers.
|
||||
/// If a time sampled attribute has a default value authored in the given
|
||||
/// \p topologyLayer, that value will also be authored as its default in the
|
||||
/// manifest.
|
||||
///
|
||||
/// \p manifestLayer The layer where manifest data will be inserted.
|
||||
///
|
||||
/// \p topologyLayer The topology layer for \p clipLayerFiles.
|
||||
///
|
||||
/// \p clipLayerFiles The files containing the time varying data.
|
||||
///
|
||||
/// \p clipPrimPath The manifest will contain attributes from this
|
||||
/// prim and its descendants in \p clipLayerFiles.
|
||||
USDUTILS_API
|
||||
bool
|
||||
UsdUtilsStitchClipsManifest(const SdfLayerHandle& manifestLayer,
|
||||
const SdfLayerHandle& topologyLayer,
|
||||
const std::vector<std::string>& clipLayerFiles,
|
||||
const SdfPath& clipPath);
|
||||
|
||||
/// A function which authors clip template metadata on a particular prim in a
|
||||
/// result layer, as well as adding the topologyLayer to the list of subLayers
|
||||
/// on the \p resultLayer. It will clear the \p resultLayer and create
|
||||
/// a prim at \p clipPath. Specifically, this will author clipPrimPath,
|
||||
/// clipTemplateAssetPath, clipTemplateStride, clipTemplateStartTime,
|
||||
/// clipTemplateEndTime, and clipManifestAssetPath.
|
||||
///
|
||||
/// \p resultLayer The layer in which we will author the metadata.
|
||||
///
|
||||
/// \p topologyLayer The layer containing the aggregate topology of
|
||||
/// the clipLayers which the metadata refers to.
|
||||
///
|
||||
/// \p manifestLayer The layer containing manifest for the attributes
|
||||
/// in the clipLayers.
|
||||
///
|
||||
/// \p clipPath The path at which to author the metadata in
|
||||
/// \p resultLayer
|
||||
///
|
||||
/// \p templatePath The template string to be authored at the
|
||||
/// clipTemplateAssetPath metadata key.
|
||||
///
|
||||
/// \p startTime The start time to be authored at the
|
||||
/// clipTemplateStartTime metadata key.
|
||||
///
|
||||
/// \p endTime The end time to be authored at the
|
||||
/// clipTemplateEndTime metadata key.
|
||||
///
|
||||
/// \p stride The stride to be authored at the
|
||||
/// clipTemplateStride metadata key.
|
||||
///
|
||||
/// \p activeOffset The offset to be authored at the
|
||||
/// clipTemplateActiveOffset metadata key.
|
||||
/// \note If this parameter is omitted, no value
|
||||
/// will be authored as the metadata is optional.
|
||||
///
|
||||
/// \p interpolateMissingClipValues
|
||||
/// Whether values for clips without samples are
|
||||
/// interpolated from surrounding clips. See
|
||||
/// UsdClipsAPI::GetInterpolateMissingClipValues
|
||||
/// for more details.
|
||||
///
|
||||
/// \p clipSet The name of the clipSet in which the
|
||||
/// aforementioned metadata will be authored.
|
||||
/// \note If this parameter is omitted, the default
|
||||
/// clipSet name("default") will be authored.
|
||||
///
|
||||
/// For further information on these metadatum, see \ref Usd_Page_AdvancedFeatures
|
||||
///
|
||||
USDUTILS_API
|
||||
bool
|
||||
UsdUtilsStitchClipsTemplate(const SdfLayerHandle& resultLayer,
|
||||
const SdfLayerHandle& topologyLayer,
|
||||
const SdfLayerHandle& manifestLayer,
|
||||
const SdfPath& clipPath,
|
||||
const std::string& templatePath,
|
||||
const double startTime,
|
||||
const double endTime,
|
||||
const double stride,
|
||||
const double activeOffset
|
||||
= std::numeric_limits<double>::max(),
|
||||
const bool interpolateMissingClipValues
|
||||
= false,
|
||||
const TfToken& clipSet
|
||||
= UsdClipsAPISetNames->default_);
|
||||
|
||||
/// Generates a topology file name based on an input file name
|
||||
///
|
||||
/// For example, if given 'foo.usd', it generates 'foo.topology.usd'
|
||||
///
|
||||
/// Note: this will not strip preceding paths off of a file name
|
||||
/// so /bar/baz/foo.usd will produce /bar/baz/foo.topology.usd
|
||||
///
|
||||
/// \p rootLayerName The filepath used as a basis for generating
|
||||
/// our topology layer name.
|
||||
USDUTILS_API
|
||||
std::string
|
||||
UsdUtilsGenerateClipTopologyName(const std::string& rootLayerName);
|
||||
|
||||
/// Generates a manifest file name based on an input file name
|
||||
///
|
||||
/// For example, if given 'foo.usd', it generates 'foo.manifest.usd'
|
||||
///
|
||||
/// Note: this will not strip preceding paths off of a file name
|
||||
/// so /bar/baz/foo.usd will produce /bar/baz/foo.manifest.usd
|
||||
///
|
||||
/// \p rootLayerName The filepath used as a basis for generating
|
||||
/// our manifest layer name.
|
||||
USDUTILS_API
|
||||
std::string
|
||||
UsdUtilsGenerateClipManifestName(const std::string& rootLayerName);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
#endif /* PXR_USD_USD_UTILS_STITCH_CLIPS_H */
|
||||
@@ -0,0 +1,409 @@
|
||||
//
|
||||
// Copyright 2019 Pixar
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
||||
// with the following modification; you may not use this file except in
|
||||
// compliance with the Apache License and the following modification to it:
|
||||
// Section 6. Trademarks. is deleted and replaced with:
|
||||
//
|
||||
// 6. Trademarks. This License does not grant permission to use the trade
|
||||
// names, trademarks, service marks, or product names of the Licensor
|
||||
// and its affiliates, except as required to comply with Section 4(c) of
|
||||
// the License and to reproduce the content of the NOTICE file.
|
||||
//
|
||||
// You may obtain a copy of the Apache License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the Apache License with the above modification is
|
||||
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the Apache License for the specific
|
||||
// language governing permissions and limitations under the Apache License.
|
||||
//
|
||||
#ifndef PXR_USD_USD_UTILS_TIME_CODE_RANGE_H
|
||||
#define PXR_USD_USD_UTILS_TIME_CODE_RANGE_H
|
||||
|
||||
/// \file usdUtils/timeCodeRange.h
|
||||
|
||||
#include "pxr/pxr.h"
|
||||
#include "pxr/usd/usdUtils/api.h"
|
||||
|
||||
#include "pxr/base/gf/math.h"
|
||||
#include "pxr/base/tf/diagnostic.h"
|
||||
#include "pxr/base/tf/staticTokens.h"
|
||||
#include "pxr/usd/usd/timeCode.h"
|
||||
|
||||
#include <iosfwd>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
|
||||
#define USDUTILS_TIME_CODE_RANGE_TOKENS \
|
||||
((EmptyTimeCodeRange, "NONE")) \
|
||||
((RangeSeparator, ":")) \
|
||||
((StrideSeparator, "x"))
|
||||
|
||||
TF_DECLARE_PUBLIC_TOKENS(
|
||||
UsdUtilsTimeCodeRangeTokens,
|
||||
USDUTILS_API,
|
||||
USDUTILS_TIME_CODE_RANGE_TOKENS);
|
||||
|
||||
|
||||
/// \class UsdUtilsTimeCodeRange
|
||||
///
|
||||
/// Represents a range of UsdTimeCode values as start and end time codes and a
|
||||
/// stride value.
|
||||
///
|
||||
/// A UsdUtilsTimeCodeRange can be iterated to retrieve all time code values in
|
||||
/// the range. The range may be empty, it may contain a single time code, or it
|
||||
/// may represent multiple time codes from start to end. The interval defined
|
||||
/// by the start and end time codes is closed on both ends.
|
||||
///
|
||||
/// Note that when constructing a UsdUtilsTimeCodeRange,
|
||||
/// UsdTimeCode::EarliestTime() and UsdTimeCode::Default() cannot be used as
|
||||
/// the start or end time codes. Also, the end time code cannot be less than
|
||||
/// the start time code for positive stride values, and the end time code
|
||||
/// cannot be greater than the start time code for negative stride values.
|
||||
/// Finally, the stride value cannot be zero. If any of these conditions are
|
||||
/// not satisfied, then an invalid empty range will be returned.
|
||||
class UsdUtilsTimeCodeRange
|
||||
{
|
||||
public:
|
||||
|
||||
/// \class const_iterator
|
||||
///
|
||||
/// A forward iterator into a UsdUtilsTimeCodeRange.
|
||||
class const_iterator
|
||||
{
|
||||
public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using value_type = UsdTimeCode;
|
||||
using reference = const UsdTimeCode&;
|
||||
using pointer = const UsdTimeCode*;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
|
||||
/// Returns the UsdTimeCode referenced by this iterator.
|
||||
reference operator*() {
|
||||
return _currTimeCode;
|
||||
}
|
||||
|
||||
/// Returns a pointer to the UsdTimeCode referenced by this iterator.
|
||||
pointer operator->() {
|
||||
return &_currTimeCode;
|
||||
}
|
||||
|
||||
/// Pre-increment operator. Advances this iterator to the next
|
||||
/// UsdTimeCode in the range.
|
||||
///
|
||||
/// This iterator is returned.
|
||||
const_iterator& operator++() {
|
||||
if (_timeCodeRange) {
|
||||
++_currStep;
|
||||
_currTimeCode =
|
||||
UsdTimeCode(
|
||||
_timeCodeRange->_startTimeCode.GetValue() +
|
||||
_timeCodeRange->_stride * _currStep);
|
||||
}
|
||||
_InvalidateIfExhausted();
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// Post-increment operator. Advances this iterator to the next
|
||||
/// UsdTimeCode in the range.
|
||||
///
|
||||
/// A copy of this iterator prior to the increment is returned.
|
||||
const_iterator operator++(int) {
|
||||
const_iterator preAdvanceIter = *this;
|
||||
++(*this);
|
||||
return preAdvanceIter;
|
||||
}
|
||||
|
||||
/// Return true if this iterator is equivalent to \p other.
|
||||
bool operator ==(const const_iterator& other) const {
|
||||
return _timeCodeRange == other._timeCodeRange &&
|
||||
_currStep == other._currStep;
|
||||
}
|
||||
|
||||
/// Return true if this iterator is not equivalent to \p other.
|
||||
bool operator !=(const const_iterator& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class UsdUtilsTimeCodeRange;
|
||||
|
||||
const_iterator(const UsdUtilsTimeCodeRange* timeCodeRange) :
|
||||
_timeCodeRange(timeCodeRange),
|
||||
_currStep(0u),
|
||||
_maxSteps(0u),
|
||||
_currTimeCode()
|
||||
{
|
||||
if (_timeCodeRange) {
|
||||
const double startVal = _timeCodeRange->_startTimeCode.GetValue();
|
||||
const double endVal = _timeCodeRange->_endTimeCode.GetValue();
|
||||
const double stride = _timeCodeRange->_stride;
|
||||
|
||||
_maxSteps = static_cast<size_t>(
|
||||
GfFloor((endVal - startVal + stride) / stride));
|
||||
_currTimeCode = _timeCodeRange->_startTimeCode;
|
||||
}
|
||||
|
||||
_InvalidateIfExhausted();
|
||||
}
|
||||
|
||||
void _InvalidateIfExhausted() {
|
||||
bool finished = false;
|
||||
if (!_timeCodeRange) {
|
||||
finished = true;
|
||||
} else if (_currStep >= _maxSteps) {
|
||||
finished = true;
|
||||
}
|
||||
|
||||
if (finished) {
|
||||
_timeCodeRange = nullptr;
|
||||
_currStep = 0u;
|
||||
_maxSteps = 0u;
|
||||
_currTimeCode = UsdTimeCode();
|
||||
}
|
||||
}
|
||||
|
||||
const UsdUtilsTimeCodeRange* _timeCodeRange;
|
||||
size_t _currStep;
|
||||
size_t _maxSteps;
|
||||
UsdTimeCode _currTimeCode;
|
||||
};
|
||||
|
||||
using iterator = const_iterator;
|
||||
|
||||
/// Create a time code range from \p frameSpec.
|
||||
///
|
||||
/// A FrameSpec is a compact string representation of a time code range.
|
||||
/// A FrameSpec may contain up to three floating point values for the start
|
||||
/// time code, end time code, and stride values of a time code range.
|
||||
///
|
||||
/// A FrameSpec containing just a single floating point value represents
|
||||
/// a time code range containing only that time code.
|
||||
///
|
||||
/// A FrameSpec containing two floating point values separated by the range
|
||||
/// separator (':') represents a time code range from the first value as
|
||||
/// the start time code to the second values as the end time code.
|
||||
///
|
||||
/// A FrameSpec that specifies both a start and end time code value may
|
||||
/// also optionally specify a third floating point value as the stride,
|
||||
/// separating it from the first two values using the stride separator
|
||||
/// ('x').
|
||||
///
|
||||
/// The following are examples of valid FrameSpecs:
|
||||
/// 123
|
||||
/// 101:105
|
||||
/// 105:101
|
||||
/// 101:109x2
|
||||
/// 101:110x2
|
||||
/// 101:104x0.5
|
||||
///
|
||||
/// An empty string corresponds to an invalid empty time code range.
|
||||
///
|
||||
/// A coding error will be issued if the given string is malformed.
|
||||
USDUTILS_API
|
||||
static UsdUtilsTimeCodeRange CreateFromFrameSpec(
|
||||
const std::string& frameSpec);
|
||||
|
||||
/// Construct an invalid empty range.
|
||||
///
|
||||
/// The start time code will be initialized to zero, and any iteration of
|
||||
/// the range will yield no time codes.
|
||||
UsdUtilsTimeCodeRange()
|
||||
{
|
||||
_Invalidate();
|
||||
}
|
||||
|
||||
/// Construct a range containing only the given \p timeCode.
|
||||
///
|
||||
/// An iteration of the range will yield only that time code.
|
||||
UsdUtilsTimeCodeRange(const UsdTimeCode timeCode) :
|
||||
UsdUtilsTimeCodeRange(timeCode, timeCode)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a range containing the time codes from \p startTimeCode to
|
||||
/// \p endTimeCode.
|
||||
///
|
||||
/// If \p endTimeCode is greater than or equal to \p startTimeCode, then
|
||||
/// the stride will be 1.0. Otherwise, the stride will be -1.0.
|
||||
UsdUtilsTimeCodeRange(
|
||||
const UsdTimeCode startTimeCode,
|
||||
const UsdTimeCode endTimeCode) :
|
||||
UsdUtilsTimeCodeRange(
|
||||
startTimeCode,
|
||||
endTimeCode,
|
||||
(endTimeCode >= startTimeCode) ? 1.0 : -1.0)
|
||||
{
|
||||
}
|
||||
|
||||
/// Construct a range containing the time codes from \p startTimeCode to
|
||||
/// \p endTimeCode using the stride value \p stride.
|
||||
///
|
||||
/// UsdTimeCode::EarliestTime() and UsdTimeCode::Default() cannot be used
|
||||
/// as \p startTimeCode or \p endTimeCode. If \p stride is a positive
|
||||
/// value, then \p endTimeCode cannot be less than \p startTimeCode. If
|
||||
/// \p stride is a negative value, then \p endTimeCode cannot be greater
|
||||
/// than \p startTimeCode. Finally, the stride value cannot be zero. If any
|
||||
/// of these conditions are not satisfied, then a coding error will be
|
||||
/// issued and an invalid empty range will be returned.
|
||||
UsdUtilsTimeCodeRange(
|
||||
const UsdTimeCode startTimeCode,
|
||||
const UsdTimeCode endTimeCode,
|
||||
const double stride) :
|
||||
_startTimeCode(startTimeCode),
|
||||
_endTimeCode(endTimeCode),
|
||||
_stride(stride)
|
||||
{
|
||||
if (_startTimeCode.IsEarliestTime()) {
|
||||
TF_CODING_ERROR(
|
||||
"startTimeCode cannot be UsdTimeCode::EarliestTime()");
|
||||
_Invalidate();
|
||||
return;
|
||||
}
|
||||
if (_startTimeCode.IsDefault()) {
|
||||
TF_CODING_ERROR(
|
||||
"startTimeCode cannot be UsdTimeCode::Default()");
|
||||
_Invalidate();
|
||||
return;
|
||||
}
|
||||
if (_endTimeCode.IsEarliestTime()) {
|
||||
TF_CODING_ERROR(
|
||||
"endTimeCode cannot be UsdTimeCode::EarliestTime()");
|
||||
_Invalidate();
|
||||
return;
|
||||
}
|
||||
if (_endTimeCode.IsDefault()) {
|
||||
TF_CODING_ERROR(
|
||||
"endTimeCode cannot be UsdTimeCode::Default()");
|
||||
_Invalidate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_stride > 0.0) {
|
||||
if (_endTimeCode < _startTimeCode) {
|
||||
TF_CODING_ERROR(
|
||||
"endTimeCode cannot be less than startTimeCode with "
|
||||
"positive stride");
|
||||
_Invalidate();
|
||||
return;
|
||||
}
|
||||
} else if (_stride < 0.0) {
|
||||
if (_endTimeCode > _startTimeCode) {
|
||||
TF_CODING_ERROR(
|
||||
"endTimeCode cannot be greater than startTimeCode with "
|
||||
"negative stride");
|
||||
_Invalidate();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
TF_CODING_ERROR("stride cannot be zero");
|
||||
_Invalidate();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the start time code of this range.
|
||||
UsdTimeCode GetStartTimeCode() const {
|
||||
return _startTimeCode;
|
||||
}
|
||||
|
||||
/// Return the end time code of this range.
|
||||
UsdTimeCode GetEndTimeCode() const {
|
||||
return _endTimeCode;
|
||||
}
|
||||
|
||||
/// Return the stride value of this range.
|
||||
double GetStride() const {
|
||||
return _stride;
|
||||
}
|
||||
|
||||
/// Return an iterator to the start of this range.
|
||||
iterator begin() const {
|
||||
return iterator(this);
|
||||
}
|
||||
|
||||
/// Return a const_iterator to the start of this range.
|
||||
const_iterator cbegin() const {
|
||||
return const_iterator(this);
|
||||
}
|
||||
|
||||
/// Return the past-the-end iterator for this range.
|
||||
iterator end() const {
|
||||
return iterator(nullptr);
|
||||
}
|
||||
|
||||
/// Return the past-the-end const_iterator for this range.
|
||||
const_iterator cend() const {
|
||||
return const_iterator(nullptr);
|
||||
}
|
||||
|
||||
/// Return true if this range contains no time codes, or false otherwise.
|
||||
bool empty() const {
|
||||
return begin() == end();
|
||||
}
|
||||
|
||||
/// Return true if this range contains one or more time codes, or false
|
||||
/// otherwise.
|
||||
bool IsValid() const {
|
||||
return !empty();
|
||||
}
|
||||
|
||||
/// Return true if this range contains one or more time codes, or false
|
||||
/// otherwise.
|
||||
explicit operator bool() const {
|
||||
return IsValid();
|
||||
}
|
||||
|
||||
/// Return true if this range is equivalent to \p other.
|
||||
bool operator ==(const UsdUtilsTimeCodeRange& other) const {
|
||||
return _startTimeCode == other._startTimeCode &&
|
||||
_endTimeCode == other._endTimeCode &&
|
||||
_stride == other._stride;
|
||||
}
|
||||
|
||||
/// Return true if this range is not equivalent to \p other.
|
||||
bool operator !=(const UsdUtilsTimeCodeRange& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/// Sets the range such that it yields no time codes.
|
||||
void _Invalidate() {
|
||||
_startTimeCode = UsdTimeCode(0.0);
|
||||
_endTimeCode = UsdTimeCode(-1.0);
|
||||
_stride = 1.0;
|
||||
}
|
||||
|
||||
UsdTimeCode _startTimeCode;
|
||||
UsdTimeCode _endTimeCode;
|
||||
double _stride;
|
||||
};
|
||||
|
||||
// Stream I/O operators.
|
||||
|
||||
/// Stream insertion operator.
|
||||
USDUTILS_API
|
||||
std::ostream& operator<<(
|
||||
std::ostream& os,
|
||||
const UsdUtilsTimeCodeRange& timeCodeRange);
|
||||
|
||||
/// Stream extraction operator.
|
||||
USDUTILS_API
|
||||
std::istream& operator>>(
|
||||
std::istream& is,
|
||||
UsdUtilsTimeCodeRange& timeCodeRange);
|
||||
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user