示例#1
0
文件: simple.cpp 项目: 400dama/USD
/* static */
UsdSchemaExamplesSimple
UsdSchemaExamplesSimple::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (not stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdSchemaExamplesSimple();
    }
    return UsdSchemaExamplesSimple(stage->GetPrimAtPath(path));
}
示例#2
0
文件: primvar.cpp 项目: 400dama/USD
/* static */
UsdHydraPrimvar
UsdHydraPrimvar::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (not stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdHydraPrimvar();
    }
    return UsdHydraPrimvar(stage->GetPrimAtPath(path));
}
示例#3
0
文件: shader.cpp 项目: JT-a/USD
/* static */
UsdShadeShader
UsdShadeShader::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdShadeShader();
    }
    return UsdShadeShader(stage->GetPrimAtPath(path));
}
示例#4
0
/* static */
UsdUISceneGraphPrimAPI
UsdUISceneGraphPrimAPI::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdUISceneGraphPrimAPI();
    }
    return UsdUISceneGraphPrimAPI(stage->GetPrimAtPath(path));
}
/* static */
UsdContrivedEmptyMultipleApplyAPI
UsdContrivedEmptyMultipleApplyAPI::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdContrivedEmptyMultipleApplyAPI();
    }
    return UsdContrivedEmptyMultipleApplyAPI(stage->GetPrimAtPath(path));
}
示例#6
0
文件: sphere.cpp 项目: JT-a/USD
/* static */
UsdGeomSphere
UsdGeomSphere::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdGeomSphere();
    }
    return UsdGeomSphere(stage->GetPrimAtPath(path));
}
示例#7
0
/* static */
UsdRiLightPortalAPI
UsdRiLightPortalAPI::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdRiLightPortalAPI();
    }
    return UsdRiLightPortalAPI(stage->GetPrimAtPath(path));
}
示例#8
0
文件: ns_derived.cpp 项目: JT-a/USD
/* static */
UsdContrivedDerived
UsdContrivedDerived::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdContrivedDerived();
    }
    return UsdContrivedDerived(stage->GetPrimAtPath(path));
}
示例#9
0
/* static */
UsdGeomNurbsCurves
UsdGeomNurbsCurves::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdGeomNurbsCurves();
    }
    return UsdGeomNurbsCurves(stage->GetPrimAtPath(path));
}
示例#10
0
文件: root.cpp 项目: lvxejay/USD
/* static */
UsdSkelRoot
UsdSkelRoot::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdSkelRoot();
    }
    return UsdSkelRoot(stage->GetPrimAtPath(path));
}
示例#11
0
/* static */
UsdGeomPointBased
UsdGeomPointBased::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (not stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdGeomPointBased();
    }
    return UsdGeomPointBased(stage->GetPrimAtPath(path));
}
示例#12
0
/* static */
UsdGeomXformable
UsdGeomXformable::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (not stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdGeomXformable();
    }
    return UsdGeomXformable(stage->GetPrimAtPath(path));
}
示例#13
0
UsdEditContext::UsdEditContext(const UsdStagePtr &stage,
                               const UsdEditTarget &editTarget)
    : _stage(stage)
    , _originalEditTarget(stage->GetEditTarget())
{
    // Do not check validity of EditTarget: stage will do that and
    // issue an error if invalid.  We DO NOT want people authoring
    // into places they did not expect to be authoring.
    _stage->SetEditTarget(editTarget);
}
示例#14
0
void
GusdPrimWrapper::addLeadingBookend( double curFrame, double startFrame )
{
    if( curFrame != startFrame ) {
        double bookendFrame = curFrame - TIME_SAMPLE_DELTA;

        // Ensure the stage start frame <= bookendFrame
        UsdStagePtr stage = getUsdPrimForWrite().GetPrim().GetStage();
        if(stage) {
            double startFrame = stage->GetStartTimeCode();
            if( startFrame > bookendFrame) {
                stage->SetStartTimeCode(bookendFrame);
            }
        }

        getUsdPrimForWrite().GetVisibilityAttr().Set(UsdGeomTokens->invisible,
                                       UsdTimeCode(bookendFrame));
        getUsdPrimForWrite().GetVisibilityAttr().Set(UsdGeomTokens->inherited,
                                       UsdTimeCode(curFrame));   
    }
}
示例#15
0
文件: cylinder.cpp 项目: 400dama/USD
/* static */
UsdGeomCylinder
UsdGeomCylinder::Define(
    const UsdStagePtr &stage, const SdfPath &path)
{
    static TfToken usdPrimTypeName("Cylinder");
    if (not stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdGeomCylinder();
    }
    return UsdGeomCylinder(
        stage->DefinePrim(path, usdPrimTypeName));
}
示例#16
0
文件: ns_derived.cpp 项目: JT-a/USD
/* static */
UsdContrivedDerived
UsdContrivedDerived::Define(
    const UsdStagePtr &stage, const SdfPath &path)
{
    static TfToken usdPrimTypeName("Derived");
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdContrivedDerived();
    }
    return UsdContrivedDerived(
        stage->DefinePrim(path, usdPrimTypeName));
}
示例#17
0
/* static */
UsdGeomNurbsCurves
UsdGeomNurbsCurves::Define(
    const UsdStagePtr &stage, const SdfPath &path)
{
    static TfToken usdPrimTypeName("NurbsCurves");
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdGeomNurbsCurves();
    }
    return UsdGeomNurbsCurves(
        stage->DefinePrim(path, usdPrimTypeName));
}
示例#18
0
文件: sphere.cpp 项目: JT-a/USD
/* static */
UsdGeomSphere
UsdGeomSphere::Define(
    const UsdStagePtr &stage, const SdfPath &path)
{
    static TfToken usdPrimTypeName("Sphere");
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdGeomSphere();
    }
    return UsdGeomSphere(
        stage->DefinePrim(path, usdPrimTypeName));
}
示例#19
0
文件: root.cpp 项目: lvxejay/USD
/* static */
UsdSkelRoot
UsdSkelRoot::Define(
    const UsdStagePtr &stage, const SdfPath &path)
{
    static TfToken usdPrimTypeName("SkelRoot");
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdSkelRoot();
    }
    return UsdSkelRoot(
        stage->DefinePrim(path, usdPrimTypeName));
}
示例#20
0
/* static */
UsdGeomXformCommonAPI
UsdGeomXformCommonAPI::Get(const UsdStagePtr &stage, const SdfPath &path)
{
    if (!stage) {
        TF_CODING_ERROR("Invalid stage");
        return UsdGeomXformCommonAPI();
    }

    UsdGeomXformable xformable(stage->GetPrimAtPath(path));

    return UsdGeomXformCommonAPI(xformable);
}
/// Finds the rootmost ancestor of the prim at \p path that is an Xform
/// or SkelRoot type prim. The result may be the prim itself.
static UsdPrim
_FindRootmostXformOrSkelRoot(const UsdStagePtr& stage, const SdfPath& path)
{
    UsdPrim currentPrim = stage->GetPrimAtPath(path);
    UsdPrim rootmost;
    while (currentPrim) {
        if (currentPrim.IsA<UsdGeomXform>()) {
            rootmost = currentPrim;
        } else if (currentPrim.IsA<UsdSkelRoot>()) {
            rootmost = currentPrim;
        }
        currentPrim = currentPrim.GetParent();
    }

    return rootmost;
}
示例#22
0
    AlembicChaser(
            UsdStagePtr stage,
            const UsdMayaChaserRegistry::FactoryContext::DagToUsdMap& dagToUsd,
            const std::map<std::string, std::string>& attrPrefixes,
            const std::map<std::string, std::string>& primvarPrefixes)
    : _stage(stage)
    , _dagToUsd(dagToUsd)
    {
        for (const auto& p: dagToUsd) {
            const MDagPath& dag = p.first;
            const SdfPath& usdPrimPath = p.second;

            UsdPrim usdPrim = stage->GetPrimAtPath(usdPrimPath);
            if (!dag.isValid() || !usdPrim) {
                continue;
            }

            _primEntries.push_back(_PrimEntry(dag, usdPrim));
            _GatherPrefixedAttrs(attrPrefixes, primvarPrefixes, dag,
                    &(_primEntries.back().attrs));
        }
    }
/// Finds the existing SkelRoot which is shared by all \p paths.
/// If no SkelRoot is found, and \p config is "auto", then attempts to
/// find a common ancestor of \p paths which can be converted to SkelRoot.
/// \p outMadeSkelRoot must be non-null; it will be set to indicate whether
/// any auto-typename change actually occurred (true) or whether there was
/// already a SkelRoot, so no renaming was necessary (false).
/// If an existing, common SkelRoot cannot be found for all paths, and if
/// it's not possible to create one, returns an empty SdfPath.
static SdfPath
_VerifyOrMakeSkelRoot(const UsdStagePtr& stage,
                      const SdfPath& path,
                      const TfToken& config)
{
    if (config != UsdMayaJobExportArgsTokens->auto_ &&
        config != UsdMayaJobExportArgsTokens->explicit_) {
        return SdfPath();
    }

    // Only try to auto-rename to SkelRoot if we're not already a
    // descendant of one. Otherwise, verify that the user tagged it in a sane
    // way.

    if (UsdSkelRoot root = UsdSkelRoot::Find(stage->GetPrimAtPath(path))) {

        // Verify that the SkelRoot isn't nested in another SkelRoot.
        // This is necessary because UsdSkel doesn't handle nested skel roots
        // very well currently; this restriction may be loosened in the future.
        if (UsdSkelRoot root2 = UsdSkelRoot::Find(root.GetPrim().GetParent())) {
            TF_RUNTIME_ERROR("The SkelRoot <%s> is nested inside another "
                    "SkelRoot <%s>. This might cause unexpected behavior.",
                    root.GetPath().GetText(), root2.GetPath().GetText());
            return SdfPath();
        }
        else {
            return root.GetPath();
        }
    } else if(config == UsdMayaJobExportArgsTokens->auto_) {
        // If auto-generating the SkelRoot, find the rootmost
        // UsdGeomXform and turn it into a SkelRoot.
        // XXX: It might be good to also consider model hierarchy here, and not
        // go past our ancestor component when trying to generate the SkelRoot.
        // (Example: in a scene with /World, /World/Char_1, /World/Char_2, we
        // might want SkelRoots to stop at Char_1 and Char_2.) Unfortunately,
        // the current structure precludes us from accessing model hierarchy
        // here.
        if (UsdPrim root = _FindRootmostXformOrSkelRoot(stage, path)) {
            UsdSkelRoot::Define(stage, root.GetPath());
            return root.GetPath();
        }
        else {
            if (path.IsRootPrimPath()) {
                // This is the most common problem when we can't obtain a
                // SkelRoot.
                // Show a nice error with useful information about root prims.
                TF_RUNTIME_ERROR("The prim <%s> is a root prim, so it has no "
                        "ancestors that can be converted to a SkelRoot. (USD "
                        "requires that skinned meshes and skeletons be "
                        "encapsulated under a SkelRoot.) Try grouping this "
                        "prim under a parent group.",
                        path.GetText());
            }
            else {
                // Show generic error as a last resort if we don't know exactly
                // what went wrong.
                TF_RUNTIME_ERROR("Could not find an ancestor of the prim <%s> "
                        "that can be converted to a SkelRoot. (USD requires "
                        "that skinned meshes and skeletons be encapsulated "
                        "under a SkelRoot.)",
                        path.GetText());
            }
            return SdfPath();
        }
    }
    return SdfPath();
}
示例#24
0
static
bool 
_SetOrMergeOverOp(std::vector<int64_t> const &items, SdfListOpType op,
                  UsdPrim const &prim)
{
    SdfInt64ListOp  proposed, current;
    UsdStagePtr stage = prim.GetStage();
    UsdEditTarget editTarget = stage->GetEditTarget();
    SdfPrimSpecHandle  primSpec = 
        editTarget.GetPrimSpecForScenePath(prim.GetPath());
    
    if (primSpec){
        VtValue  existingOp = primSpec->GetInfo(UsdGeomTokens->inactiveIds);
        if (existingOp.IsHolding<SdfInt64ListOp>()){
            current = existingOp.UncheckedGet<SdfInt64ListOp>();
        }
    }

    proposed.SetItems(items, op);
    if (current.IsExplicit()){
        std::vector<int64_t> explicitItems = current.GetExplicitItems();
        proposed.ApplyOperations(&explicitItems);
        current.SetExplicitItems(explicitItems);
    }
    else {
        // We can't use ApplyOperations on an extant, non-explicit listOp
        // because the result is always flat and explicit.
        current.ComposeOperations(proposed, op);
        // ComposeOperations() is too narrow in functionality - it does not
        // consider that if we "remove over" an existing set of added items,
        // we need to additionally ensure the removed items get removed
        // from the added in current, since when applying ops, we first
        // remove, then add.  Bug #139215 filed to track; when it gets fixed
        // we can remove this code!
        if (op == SdfListOpTypeDeleted){
            std::vector<int64_t> addedItems = current.GetAddedItems();
            if (!addedItems.empty()){
                std::set<int64_t> toRemove(items.begin(), items.end());
                std::vector<int64_t> newAdded;
                newAdded.reserve(addedItems.size());
                for (auto elt : addedItems){
                    if (!toRemove.count(elt))
                        newAdded.push_back(elt);
                }
                if (newAdded.size() != addedItems.size())
                    current.SetAddedItems(newAdded);
            }
        }
        else if (op == SdfListOpTypeAdded){
            std::vector<int64_t> deletedItems = current.GetDeletedItems();
            if (!deletedItems.empty()){
                std::set<int64_t> toAdd(items.begin(), items.end());
                std::vector<int64_t> newDeleted;
                newDeleted.reserve(deletedItems.size());
                for (auto elt : deletedItems){
                    if (!toAdd.count(elt))
                        newDeleted.push_back(elt);
                }
                if (newDeleted.size() != deletedItems.size())
                    current.SetDeletedItems(newDeleted);
            }
        }
    }
    return prim.SetMetadata(UsdGeomTokens->inactiveIds, current);
}
示例#25
0
void
GusdPrimWrapper::updateTransformFromGTPrim( const GfMatrix4d &xform, 
                                            UsdTimeCode time, bool force )
{
    UsdGeomImageable usdGeom = getUsdPrimForWrite();
    UsdGeomXformable prim( usdGeom );

    // Determine if we need to clear previous transformations from a stronger
    // opinion on the stage before authoring ours.
    UsdStagePtr stage = usdGeom.GetPrim().GetStage();
    UsdEditTarget currEditTarget = stage->GetEditTarget();

    // If the edit target does no mapping, it is most likely the session
    // layer which means it is in the local layer stack and can overlay
    // any xformOps.
    if ( !currEditTarget.GetMapFunction().IsNull() && 
         !currEditTarget.GetMapFunction().IsIdentity() ) {
        bool reset;
        std::vector<UsdGeomXformOp> xformVec = prim.GetOrderedXformOps(&reset);

        // The xformOps attribute is static so we only check if we haven't
        // changed anything yet. In addition nothing needs to be cleared if it
        // was previously empty.
        if (m_lastXformSet.IsDefault() && (int)xformVec.size() > 0) {
            // Load the root layer for temp, stronger opinion changes.
            stage->GetRootLayer()->SetPermissionToSave(false);
            stage->SetEditTarget(stage->GetRootLayer());
            UsdGeomXformable stagePrim( getUsdPrimForWrite() );

            // Clear the xformOps on the stronger layer, so our weaker edit
            // target (with mapping across a reference) can write out clean,
            // new transforms.
            stagePrim.ClearXformOpOrder();
            stage->SetEditTarget(currEditTarget);
        }
    }

    if( !prim )
        return;

    // Try to avoid setting the transform when we can.
    // If force it true, always write the transform (used when writting per frame)
    bool setKnot = true;
    if( !force ) {
        
        // Has the transform has been set at least once
        if( !m_lastXformSet.IsDefault() ) {

            // Is the transform at this frame the same as the last frame
            if( isClose(xform,m_xformCache) ) {
                setKnot = false;
                m_lastXformCompared = time;
            }
            else {
                // If the transform has been held for more than one frame, 
                // set a knot on the last frame
                if( m_lastXformCompared != m_lastXformSet ) {
                    prim.MakeMatrixXform().Set( m_xformCache, m_lastXformCompared );
                }
            }
        }
        else {
            // If the transform is an identity, don't set it
            if( isClose(xform,GfMatrix4d( 1.0 ))) {

                setKnot = false;
                m_lastXformCompared = time;
            }
            else {

                // If the transform was identity and now isn't, set a knot on the last frame
                if( !m_lastXformCompared.IsDefault() ) {
                    prim.MakeMatrixXform().Set( GfMatrix4d(1.0), m_lastXformCompared );
                }
            }
        }
    }

    if( setKnot ) {
        prim.MakeMatrixXform().Set( xform, time );
        m_xformCache = xform;
        m_lastXformSet = time;
        m_lastXformCompared = time;
    }
}
示例#26
0
UsdEditContext::UsdEditContext(const UsdStagePtr &stage)
    : _stage(stage)
    , _originalEditTarget(stage->GetEditTarget())
{
}