/* static */ UsdGeomXformOp::Precision UsdGeomXformOp::GetPrecisionFromValueTypeName(const SdfValueTypeName &typeName) { if (typeName == SdfValueTypeNames->Matrix4d) return PrecisionDouble; else if (typeName == SdfValueTypeNames->Double3) return PrecisionDouble; else if (typeName == SdfValueTypeNames->Float3) return PrecisionFloat; else if (typeName == SdfValueTypeNames->Half3) return PrecisionHalf; else if (typeName == SdfValueTypeNames->Double) return PrecisionDouble; else if (typeName == SdfValueTypeNames->Float) return PrecisionFloat; else if (typeName == SdfValueTypeNames->Half) return PrecisionHalf; else if (typeName == SdfValueTypeNames->Quatd) return PrecisionDouble; else if (typeName == SdfValueTypeNames->Quatf) return PrecisionFloat; else if (typeName == SdfValueTypeNames->Quath) return PrecisionHalf; TF_CODING_ERROR("Invalid typeName '%s' specified.", typeName.GetAsToken().GetText()); // Return default precision, which is double. return PrecisionDouble; }
void add(const SdfValueTypeName& scalar, const char* alias = NULL) { static const bool isShaped = true; const SdfValueTypeName array = scalar.GetArrayType(); const std::string scalarName = alias ? std::string(alias) : scalar.GetAsToken().GetString(); const std::string arrayName = alias ? std::string(alias) + "[]" : array.GetAsToken().GetString(); _ValueFactoryMap &f = *_factories; f[scalarName] = ValueFactory(scalarName, scalar.GetDimensions(), !isShaped, boost::bind(MakeScalarValueTemplate<CppType>, _1, _2, _3, _4)); f[arrayName] = ValueFactory(arrayName, array.GetDimensions(), isShaped, boost::bind(MakeShapedValueTemplate<CppType>, _1, _2, _3, _4)); }
void UsdGeomPrimvar::BlockIndices() const { // Check if the typeName is array valued here and issue a warning // if it's not. SdfValueTypeName typeName = GetTypeName(); if (!typeName.IsArray()) { TF_CODING_ERROR("Setting indices on non-array valued primvar of type " "'%s'.", typeName.GetAsToken().GetText()); return; } _GetIndicesAttr(/*create*/ true).Block(); }
bool UsdGeomPrimvar::SetIndices(const VtIntArray &indices, UsdTimeCode time) const { // Check if the typeName is array valued here and issue a warning // if it's not. SdfValueTypeName typeName = GetTypeName(); if (!typeName.IsArray()) { TF_CODING_ERROR("Setting indices on non-array valued primvar of type " "'%s'.", typeName.GetAsToken().GetText()); return false; } return _GetIndicesAttr(/*create*/ true).Set(indices, time); }
SdfAttributeSpecHandle SdfAttributeSpec::_New( const SdfSpecHandle &owner, const SdfPath& attrPath, const SdfValueTypeName& typeName, SdfVariability variability, bool custom) { if (not owner) { TF_CODING_ERROR("NULL owner"); return TfNullPtr; } if (not typeName) { TF_CODING_ERROR("Cannot create attribute spec <%s> with invalid type", attrPath.GetText()); return TfNullPtr; } SdfChangeBlock block; // AttributeSpecs are considered initially to have only required fields // only if they are not custom. bool hasOnlyRequiredFields = (not custom); if (not Sdf_ChildrenUtils<Sdf_AttributeChildPolicy>::CreateSpec( owner->GetLayer(), attrPath, SdfSpecTypeAttribute, hasOnlyRequiredFields)) { return TfNullPtr; } SdfAttributeSpecHandle spec = owner->GetLayer()->GetAttributeAtPath(attrPath); // Avoid expensive dormancy checks in the case of binary-backed data. SdfAttributeSpec *specPtr = get_pointer(spec); if (TF_VERIFY(specPtr)) { specPtr->SetField(SdfFieldKeys->Custom, custom); specPtr->SetField(SdfFieldKeys->TypeName, typeName.GetAsToken()); specPtr->SetField(SdfFieldKeys->Variability, variability); } return spec; }
SdfAttributeSpecHandle SdfAttributeSpec::_New( const SdfRelationshipSpecHandle& owner, const SdfPath& path, const std::string& name, const SdfValueTypeName& typeName, SdfVariability variability, bool custom) { if (not owner) { TF_CODING_ERROR("NULL owner"); return TfNullPtr; } if (not typeName) { TF_CODING_ERROR("Cannot create attribute spec <%s> with invalid type", owner->GetPath().AppendTarget(path). AppendProperty(TfToken(name)).GetText()); return TfNullPtr; } SdfChangeBlock block; // Determine the path of the relationship target SdfPath absPath = path.MakeAbsolutePath(owner->GetPath().GetPrimPath()); SdfPath targetPath = owner->GetPath().AppendTarget(absPath); // Check to make sure that the name is valid if (not Sdf_ChildrenUtils<Sdf_AttributeChildPolicy>::IsValidName(name)) { TF_CODING_ERROR( "Cannot create attribute on %s with invalid name: %s", targetPath.GetText(), name.c_str()); return TfNullPtr; } // Create the relationship target if it doesn't already exist. Note // that this does not automatically get added to the relationship's // target path list. SdfSpecHandle targetSpec = owner->_FindOrCreateTargetSpec(path); // AttributeSpecs are considered initially to have only required fields // only if they are not custom. bool hasOnlyRequiredFields = (not custom); // Create the relational attribute spec SdfPath attrPath = targetPath.AppendRelationalAttribute(TfToken(name)); if (not Sdf_ChildrenUtils<Sdf_AttributeChildPolicy>::CreateSpec( owner->GetLayer(), attrPath, SdfSpecTypeAttribute, hasOnlyRequiredFields)) { return TfNullPtr; } SdfAttributeSpecHandle spec = owner->GetLayer()->GetAttributeAtPath(attrPath); // Avoid expensive dormancy checks in the case of binary-backed data. SdfAttributeSpec *specPtr = get_pointer(spec); if (TF_VERIFY(specPtr)) { specPtr->SetField(SdfFieldKeys->Custom, custom); specPtr->SetField(SdfFieldKeys->TypeName, typeName.GetAsToken()); specPtr->SetField(SdfFieldKeys->Variability, variability); } return spec; }