本文整理汇总了C++中UsdPrim::GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ UsdPrim::GetAttribute方法的具体用法?C++ UsdPrim::GetAttribute怎么用?C++ UsdPrim::GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UsdPrim
的用法示例。
在下文中一共展示了UsdPrim::GetAttribute方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UsdGeomPrimvar
UsdGeomPrimvar
UsdGeomPrimvarsAPI::FindPrimvarWithInheritance(const TfToken &name) const
{
TRACE_FUNCTION();
const TfToken attrName = UsdGeomPrimvar::_MakeNamespaced(name);
UsdPrim prim = GetPrim();
if (!prim) {
TF_CODING_ERROR("FindPrimvarWithInheritance called on invalid prim: %s",
UsdDescribe(prim).c_str());
return UsdGeomPrimvar();
}
UsdGeomPrimvar localPv = GetPrimvar(name);
if (localPv.HasAuthoredValue()){
return localPv;
}
for (prim = prim.GetParent(); prim && !prim.IsPseudoRoot();
prim = prim.GetParent()) {
UsdAttribute attr = prim.GetAttribute(attrName);
if (attr.HasAuthoredValue()) {
if (UsdGeomPrimvar pv = UsdGeomPrimvar(attr)) {
// Only constant primvars can be inherited.
if (pv.GetInterpolation() == UsdGeomTokens->constant) {
return pv;
} else {
// Non-constant interpolation blocks inheritance.
return UsdGeomPrimvar();
}
}
}
}
return localPv;
}
示例2: attrObj
UsdAttribute
PxrUsdMayaWriteUtil::GetOrCreateUsdAttr(
const MPlug& plg,
const UsdPrim& usdPrim,
const std::string &attrName,
bool custom)
{
MObject attrObj(plg.attribute());
TfToken usdAttrName(attrName);
if (usdAttrName.IsEmpty()) {
printf("Invalid attrName '%s' for %s\n",
attrName.c_str(),
plg.name().asChar());
return UsdAttribute();
}
// See if usdAttr already exists. If so, return.
UsdAttribute usdAttr = usdPrim.GetAttribute(usdAttrName);
if (usdAttr) {
return usdAttr;
}
SdfValueTypeName attrType = PxrUsdMayaWriteUtil::GetUsdTypeName(plg);
// ---------------------
// CreateAttribute on USD Prim if specified above
if (attrType) {
usdAttr = usdPrim.CreateAttribute(usdAttrName, attrType, custom);
}
else {
// Skipping. Unsupported type.
}
return usdAttr;
}
示例3: riStatements
static bool
_GatherRibAttributes(
const UsdPrim &prim,
double currentTime,
FnKat::GroupBuilder& attrsBuilder)
{
bool hasAttrs = false;
// USD SHADING STYLE ATTRIBUTES
UsdRiStatements riStatements(prim);
if (riStatements) {
const std::vector<UsdProperty> props =
riStatements.GetRiAttributes();
std::string attrName;
TF_FOR_ALL(propItr, props) {
UsdProperty prop = *propItr;
if (!prop) continue;
std::string nameSpace =
riStatements.GetRiAttributeNameSpace(prop).GetString();
nameSpace = TfStringReplace(nameSpace, ":", ".") + ".";
attrName = nameSpace +
riStatements.GetRiAttributeName(prop).GetString();
VtValue vtValue;
UsdAttribute usdAttr = prim.GetAttribute(prop.GetName());
if (usdAttr) {
if (not usdAttr.Get(&vtValue, currentTime))
continue;
// XXX asShaderParam really means:
// "For arrays, as a single attr vs a type/value pair group"
// The type/value pair group is meaningful for attrs who don't
// have a formal type definition -- like a "user" RiAttribute.
//
// However, other array values (such as two-element shadingrate)
// are not expecting the type/value pair form and will not
// generate rib correctly. As such, we'll handle the "user"
// attribute as a special case.
bool asShaderParam = true;
if (nameSpace == "user.")
{
asShaderParam = false;
}
attrsBuilder.set(attrName, PxrUsdKatanaUtils::ConvertVtValueToKatAttr(vtValue,
asShaderParam) );
}
else {
UsdRelationship usdRel = prim.GetRelationship(prop.GetName());
attrsBuilder.set(attrName, PxrUsdKatanaUtils::ConvertRelTargetsToKatAttr(usdRel,
/* asShaderParam */ false) );
}
hasAttrs = true;
}
}
示例4:
void
UsdImagingPointsAdapter::_GetPoints(UsdPrim const& prim,
VtValue* value,
UsdTimeCode time)
{
HD_TRACE_FUNCTION();
if (!prim.GetAttribute(UsdGeomTokens->points).Get(value, time)) {
*value = VtVec3fArray();
}
}
示例5:
UsdShadeParameter::UsdShadeParameter(
UsdPrim prim,
TfToken const &name,
SdfValueTypeName const &typeName)
{
// XXX what do we do if the type name doesn't match and it exists already?
_attr = prim.GetAttribute(name);
if (!_attr) {
_attr = prim.CreateAttribute(name, typeName, /* custom = */ false);
}
}
示例6:
UsdShadeInterfaceAttribute::UsdShadeInterfaceAttribute(
const UsdPrim& prim,
TfToken const& interfaceAttrName,
SdfValueTypeName const& typeName)
: _name(interfaceAttrName)
{
TfToken attrName = _GetName(interfaceAttrName);
_attr = prim.GetAttribute(attrName);
if (not _attr) {
_attr = prim.CreateAttribute(attrName, typeName, /* custom = */ false);
}
}
示例7:
UsdShadeOutput::UsdShadeOutput(
UsdPrim prim,
TfToken const &name,
SdfValueTypeName const &typeName)
{
// XXX what do we do if the type name doesn't match and it exists already?
TfToken attrName = _GetOutputAttrName(name);
_prop = prim.GetAttribute(attrName);
if (!_prop) {
_prop = prim.CreateAttribute(attrName, typeName, /* custom = */ false);
}
}
示例8: GetOrCreateUsdRiAttribute
/* static */
UsdAttribute PxrUsdMayaWriteUtil::GetOrCreateUsdRiAttribute(
const MPlug& attrPlug,
const UsdPrim& usdPrim,
const std::string& attrName,
const std::string& nameSpace,
const bool translateMayaDoubleToUsdSinglePrecision)
{
UsdAttribute usdAttr;
if (!usdPrim) {
return usdAttr;
}
MObject attrObj(attrPlug.attribute());
TfToken riAttrNameToken(attrName);
if (riAttrNameToken.IsEmpty()) {
MGlobal::displayError(
TfStringPrintf("Invalid UsdRi attribute name '%s' for Maya plug '%s'",
attrName.c_str(),
attrPlug.name().asChar()).c_str());
return usdAttr;
}
UsdRiStatements riStatements(usdPrim);
if (!riStatements) {
return usdAttr;
}
// See if a UsdRi attribute with this name already exists. If so, return it.
// XXX: There isn't currently API for looking for a specific UsdRi attribute
// by name, so we have to get them all and then see if one matches.
const std::vector<UsdProperty>& riAttrs = riStatements.GetRiAttributes(nameSpace);
TF_FOR_ALL(iter, riAttrs) {
if (iter->GetBaseName() == riAttrNameToken) {
// Re-get the attribute from the prim so we can return it as a
// UsdAttribute rather than a UsdProperty.
return usdPrim.GetAttribute(iter->GetName());
}
}
const SdfValueTypeName& typeName =
PxrUsdMayaWriteUtil::GetUsdTypeName(attrPlug,
translateMayaDoubleToUsdSinglePrecision);
if (typeName) {
usdAttr = riStatements.CreateRiAttribute(riAttrNameToken,
typeName.GetType(),
nameSpace);
}
return usdAttr;
}
示例9: TfToken
/* static */
UsdAttribute
UsdGeomXformOp::_GetXformOpAttr(UsdPrim const& prim, const TfToken &opName,
bool *isInverseOp)
{
*isInverseOp = _IsInverseOp(opName);
// Is it is an inverse operation, strip off the "invert:" at the beginning
// of opName to get the associated attribute's name.
const TfToken &xformOpAttrName = *isInverseOp
? TfToken(opName.GetString().substr(
_tokens->invertPrefix.GetString().size()))
: opName;
return prim.GetAttribute(xformOpAttrName);
}
示例10: attrObj
/* static */
UsdAttribute
PxrUsdMayaWriteUtil::GetOrCreateUsdAttr(
const MPlug& attrPlug,
const UsdPrim& usdPrim,
const std::string& attrName,
const bool custom,
const bool translateMayaDoubleToUsdSinglePrecision)
{
UsdAttribute usdAttr;
if (!usdPrim) {
return usdAttr;
}
MObject attrObj(attrPlug.attribute());
TfToken usdAttrNameToken(attrName);
if (usdAttrNameToken.IsEmpty()) {
MGlobal::displayError(
TfStringPrintf("Invalid USD attribute name '%s' for Maya plug '%s'",
attrName.c_str(),
attrPlug.name().asChar()).c_str());
return usdAttr;
}
// See if the USD attribute already exists. If so, return it.
usdAttr = usdPrim.GetAttribute(usdAttrNameToken);
if (usdAttr) {
return usdAttr;
}
const SdfValueTypeName& typeName =
PxrUsdMayaWriteUtil::GetUsdTypeName(attrPlug,
translateMayaDoubleToUsdSinglePrecision);
if (typeName) {
usdAttr = usdPrim.CreateAttribute(usdAttrNameToken, typeName, custom);
}
return usdAttr;
}
示例11: TfToken
void
UsdImagingGprimAdapter::_DiscoverPrimvarsDeprecated(UsdGeomGprim const& gprim,
SdfPath const& cachePath,
UsdPrim const& shaderPrim,
UsdTimeCode time,
UsdImagingValueCache* valueCache)
{
UsdImagingValueCache::PrimvarInfo primvar;
std::vector<UsdProperty> const& props
= shaderPrim.GetProperties();
TF_FOR_ALL(propIt, props) {
UsdAttribute attr = propIt->As<UsdAttribute>();
if (not attr) {
continue;
}
if (attr.GetPath().IsNamespacedPropertyPath()) {
continue;
}
// Ok this is a parameter, check source input.
if (UsdAttribute texAttr = shaderPrim.GetAttribute(
TfToken(attr.GetPath().GetName()
+ ":texture"))) {
TfToken t;
SdfAssetPath ap;
VtValue v;
UsdGeomPrimvar primvarAttr;
texAttr.Get(&ap, UsdTimeCode::Default());
bool isPtex = GlfPtexTexture::IsPtexTexture(TfToken(ap.GetAssetPath()));
if (isPtex) {
t = UsdImagingTokens->ptexFaceIndex;
// Allow the client to override this name
texAttr.GetMetadata(UsdImagingTokens->faceIndexPrimvar, &t);
primvarAttr = gprim.GetPrimvar(t);
if (primvarAttr) {
if (primvarAttr.ComputeFlattened(&v, time)) {
primvar.name = t;
primvar.interpolation = primvarAttr.GetInterpolation();
valueCache->GetPrimvar(cachePath, t) = v;
_MergePrimvar(primvar, &valueCache->GetPrimvars(cachePath));
}
}
t = UsdImagingTokens->ptexFaceOffset;
// Allow the client to override this name
texAttr.GetMetadata(UsdImagingTokens->faceOffsetPrimvar, &t);
primvarAttr = gprim.GetPrimvar(t);
if (primvarAttr) {
primvar.name = t;
primvar.interpolation = primvarAttr.GetInterpolation();
if (primvarAttr.ComputeFlattened(&v, time)) {
valueCache->GetPrimvar(cachePath, t) = v;
_MergePrimvar(primvar, &valueCache->GetPrimvars(cachePath));
}
}
} else {
texAttr.GetMetadata(UsdImagingTokens->uvPrimvar, &t);
primvarAttr = gprim.GetPrimvar(t);
if (TF_VERIFY(primvarAttr, "%s\n", t.GetText())) {
if (TF_VERIFY(primvarAttr.ComputeFlattened(&v, time))) {
primvar.name = t; // does not include primvars:
primvar.interpolation = primvarAttr.GetInterpolation();
// Convert double to float, we don't need double precision.
if (v.IsHolding<VtVec2dArray>()) {
v = VtValue::Cast<VtVec2fArray>(v);
}
valueCache->GetPrimvar(cachePath, t) = v;
_MergePrimvar(primvar, &valueCache->GetPrimvars(cachePath));
}
}
}
} else if (UsdAttribute pvAttr = shaderPrim.GetAttribute(
TfToken(attr.GetPath().GetName()
+ ":primvar"))) {
TfToken t;
VtValue v;
UsdGeomPrimvar primvarAttr;
if (TF_VERIFY(pvAttr.Get(&t, UsdTimeCode::Default()))) {
primvarAttr = gprim.GetPrimvar(t);
if (TF_VERIFY(primvarAttr.ComputeFlattened(&v, time))) {
primvar.name = t; // does not include primvars:
primvar.interpolation = primvarAttr.GetInterpolation();
valueCache->GetPrimvar(cachePath, t) = v;
_MergePrimvar(primvar, &valueCache->GetPrimvars(cachePath));
}
}
}
}