本文整理汇总了C++中UsdGeomPrimvar::ComputeFlattened方法的典型用法代码示例。如果您正苦于以下问题:C++ UsdGeomPrimvar::ComputeFlattened方法的具体用法?C++ UsdGeomPrimvar::ComputeFlattened怎么用?C++ UsdGeomPrimvar::ComputeFlattened使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UsdGeomPrimvar
的用法示例。
在下文中一共展示了UsdGeomPrimvar::ComputeFlattened方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
UsdImagingGprimAdapter::_DiscoverPrimvars(UsdGeomGprim const& gprim,
SdfPath const& cachePath,
UsdShadeShader const& shader,
UsdTimeCode time,
UsdImagingValueCache* valueCache)
{
// TODO: It might be convenient to implicitly wire up PtexFaceOffset and
// PtexFaceIndex primvars.
TF_DEBUG(USDIMAGING_SHADERS).Msg("\t Looking for <%s> primvars at <%s>\n",
gprim.GetPrim().GetPath().GetText(),
shader.GetPrim().GetPath().GetText());
for (UsdShadeParameter const& param : shader.GetParameters()) {
UsdShadeShader source;
TfToken outputName;
if (param.GetConnectedSource(&source, &outputName)) {
UsdAttribute attr = source.GetIdAttr();
TfToken id;
if (not attr or not attr.Get(&id)) {
continue;
}
TF_DEBUG(USDIMAGING_SHADERS).Msg("\t\t Param <%s> connected <%s>(%s)\n",
param.GetAttr().GetName().GetText(),
source.GetPath().GetText(),
id.GetText());
if (id == UsdHydraTokens->HwPrimvar_1) {
TfToken t;
VtValue v;
UsdGeomPrimvar primvarAttr;
if (UsdHydraPrimvar(source).GetVarnameAttr().Get(&t,
UsdTimeCode::Default())) {
primvarAttr = gprim.GetPrimvar(t);
if (primvarAttr.ComputeFlattened(&v, time)) {
TF_DEBUG(USDIMAGING_SHADERS).Msg("Found primvar %s\n",
t.GetText());
UsdImagingValueCache::PrimvarInfo primvar;
primvar.name = t;
primvar.interpolation = primvarAttr.GetInterpolation();
valueCache->GetPrimvar(cachePath, t) = v;
_MergePrimvar(primvar, &valueCache->GetPrimvars(cachePath));
} else {
TF_DEBUG(USDIMAGING_SHADERS).Msg(
"\t\t No primvar on <%s> named %s\n",
gprim.GetPath().GetText(),
t.GetText());
}
}
} else {
// Recursively look for more primvars
_DiscoverPrimvars(gprim, cachePath, source, time, valueCache);
}
}
}
}
示例2: 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));
}
}
}
}
示例3: if
//.........这里部分代码省略.........
{
GfVec4d usdVal;
primvar.Get( &usdVal, time );
return new GT_Real64Array( usdVal.data(), 1, 4, GT_TYPE_QUATERNION );
}
else if( typeName == SdfValueTypeNames->Matrix3d )
{
GfMatrix3d usdVal;
primvar.Get( &usdVal, time );
return new GT_Real64Array( usdVal.GetArray(), 1, 9, GT_TYPE_MATRIX3 );
}
else if( typeName == SdfValueTypeNames->Matrix4d ||
typeName == SdfValueTypeNames->Frame4d )
{
GfMatrix4d usdVal;
primvar.Get( &usdVal, time );
return new GT_Real64Array( usdVal.GetArray(), 1, 16, GT_TYPE_MATRIX );
}
else if( typeName == SdfValueTypeNames->String )
{
string usdVal;
primvar.Get( &usdVal, time );
auto gtString = new GT_DAIndexedString( 1 );
gtString->setString( 0, 0, usdVal.c_str() );
return gtString;
}
else if( typeName == SdfValueTypeNames->StringArray )
{
VtArray<string> usdVal;
primvar.ComputeFlattened( &usdVal, time );
auto gtString = new GT_DAIndexedString( usdVal.size() );
for( size_t i = 0; i < usdVal.size(); ++i )
gtString->setString( i, 0, usdVal[i].c_str() );
return gtString;
}
else if( typeName == SdfValueTypeNames->IntArray )
{
VtArray<int> usdVal;
primvar.ComputeFlattened( &usdVal, time );
return new GusdGT_VtArray<int>(usdVal);
}
else if( typeName == SdfValueTypeNames->Int64Array )
{
VtArray<int64_t> usdVal;
primvar.ComputeFlattened( &usdVal, time );
return new GusdGT_VtArray<int64_t>(usdVal);
}
else if( typeName == SdfValueTypeNames->FloatArray )
{
VtArray<float> usdVal;
primvar.ComputeFlattened( &usdVal, time );
return new GusdGT_VtArray<float>(usdVal);
}
else if( typeName == SdfValueTypeNames->DoubleArray )
{
VtArray<double> usdVal;
primvar.ComputeFlattened( &usdVal, time );
return new GusdGT_VtArray<double>(usdVal);
}
else if( typeName == SdfValueTypeNames->Float2Array )
{
VtArray<GfVec2f> usdVal;
示例4: if
/* static */
GT_DataArrayHandle
GusdPrimWrapper::convertPrimvarData( const UsdGeomPrimvar& primvar, UsdTimeCode time )
{
VtValue val;
if (!primvar.ComputeFlattened(&val, time)) {
return nullptr;
}
#define _CONVERT_TUPLE(elemType, gtArray, tupleSize, gtType) \
if (val.IsHolding<elemType>()) { \
return Gusd_ConvertTupleToGt<elemType, gtArray, tupleSize>(val); \
} else if (val.IsHolding<VtArray<elemType> >()) { \
return Gusd_ConvertTupleArrayToGt<elemType, gtArray, tupleSize>( \
primvar, val); \
}
// Check for most common value types first.
_CONVERT_TUPLE(GfVec3f, GT_Real32Array, 3, GT_TYPE_NONE);
_CONVERT_TUPLE(GfVec2f, GT_Real32Array, 2, GT_TYPE_NONE);
_CONVERT_TUPLE(float, GT_Real32Array, 1, GT_TYPE_NONE);
_CONVERT_TUPLE(int, GT_Int32Array, 1, GT_TYPE_NONE);
// Scalars
_CONVERT_TUPLE(double, GT_Real64Array, 1, GT_TYPE_NONE);
_CONVERT_TUPLE(GfHalf, GT_Real16Array, 1, GT_TYPE_NONE);
_CONVERT_TUPLE(int64, GT_Int64Array, 1, GT_TYPE_NONE);
_CONVERT_TUPLE(unsigned char, GT_UInt8Array, 1, GT_TYPE_NONE);
// TODO: UInt, UInt64 (convert to int32/int64?)
// Vec2
_CONVERT_TUPLE(GfVec2d, GT_Real64Array, 2, GT_TYPE_NONE);
_CONVERT_TUPLE(GfVec2h, GT_Real16Array, 2, GT_TYPE_NONE);
_CONVERT_TUPLE(GfVec2i, GT_Int32Array, 2, GT_TYPE_NONE);
// Vec3
_CONVERT_TUPLE(GfVec3d, GT_Real64Array, 3, GT_TYPE_NONE);
_CONVERT_TUPLE(GfVec3h, GT_Real16Array, 3, GT_TYPE_NONE);
_CONVERT_TUPLE(GfVec3i, GT_Int32Array, 3, GT_TYPE_NONE);
// Vec4
_CONVERT_TUPLE(GfVec4d, GT_Real64Array, 4, GT_TYPE_NONE);
_CONVERT_TUPLE(GfVec4f, GT_Real32Array, 4, GT_TYPE_NONE);
_CONVERT_TUPLE(GfVec4h, GT_Real16Array, 4, GT_TYPE_NONE);
_CONVERT_TUPLE(GfVec4i, GT_Int32Array, 4, GT_TYPE_NONE);
// Quat
_CONVERT_TUPLE(GfQuatd, GT_Real64Array, 4, GT_TYPE_QUATERNION);
_CONVERT_TUPLE(GfQuatf, GT_Real32Array, 4, GT_TYPE_QUATERNION);
_CONVERT_TUPLE(GfQuath, GT_Real16Array, 4, GT_TYPE_QUATERNION);
// Matrices
_CONVERT_TUPLE(GfMatrix3d, GT_Real64Array, 9, GT_TYPE_MATRIX3);
_CONVERT_TUPLE(GfMatrix4d, GT_Real64Array, 16, GT_TYPE_MATRIX);
// TODO: Correct GT_Type for GfMatrix2d?
_CONVERT_TUPLE(GfMatrix2d, GT_Real64Array, 4, GT_TYPE_NONE);
#undef _CONVERT_TUPLE
#define _CONVERT_STRING(elemType) \
if (val.IsHolding<elemType>()) { \
return Gusd_ConvertStringToGt<elemType>(val); \
} else if (val.IsHolding<VtArray<elemType> >()) { \
return Gusd_ConvertStringArrayToGt<elemType>(primvar, val); \
}
_CONVERT_STRING(std::string);
_CONVERT_STRING(TfToken);
_CONVERT_STRING(SdfAssetPath);
#undef _CONVERT_STRING
return nullptr;
}