HdStGLSLProgramSharedPtr HdStGLSLProgram::GetComputeProgram( TfToken const &shaderToken, HdStResourceRegistry *resourceRegistry) { // Find the program from registry HdInstance<HdStGLSLProgram::ID, HdStGLSLProgramSharedPtr> programInstance; std::unique_lock<std::mutex> regLock = resourceRegistry->RegisterGLSLProgram( HdStGLSLProgram::ComputeHash(shaderToken), &programInstance); if (programInstance.IsFirstInstance()) { // if not exists, create new one HdStGLSLProgramSharedPtr newProgram( new HdStGLSLProgram(HdTokens->computeShader)); GlfGLSLFX glslfx(HdStPackageComputeShader()); std::string version = "#version 430\n"; if (!newProgram->CompileShader( GL_COMPUTE_SHADER, version + glslfx.GetSource(shaderToken))) { TF_CODING_ERROR("Fail to compile " + shaderToken.GetString()); return HdStGLSLProgramSharedPtr(); } if (!newProgram->Link()) { TF_CODING_ERROR("Fail to link " + shaderToken.GetString()); return HdStGLSLProgramSharedPtr(); } programInstance.SetValue(newProgram); } return programInstance.GetValue(); }
/* static */ TfToken UsdGeomXformOp::GetOpName( const Type opType, const TfToken &opSuffix, bool isInverseOp) { TfToken opName = _MakeNamespaced(GetOpTypeToken(opType)); if (!opSuffix.IsEmpty()) opName = TfToken(opName.GetString() + ":" + opSuffix.GetString()); if (isInverseOp) opName = TfToken(_tokens->invertPrefix.GetString() + opName.GetString()); return opName; }
static TfToken _MakeNamespaced(const TfToken& name) { return _IsNamespaced(name) ? name : TfToken(_tokens->xformOpPrefix.GetString() + name.GetString()); }
TfToken UsdGeomCollectionAPI::_GetCollectionPropertyName( const TfToken &baseName /* =TfToken() */) const { return TfToken(UsdGeomTokens->collection.GetString() + ":" + _name.GetString() + (baseName.IsEmpty() ? "" : (":" + baseName.GetString()))); }
PXR_NAMESPACE_OPEN_SCOPE static std::string _GetMayaAttrNameForMetadataKey(const TfToken& key) { return TfStringPrintf("USD_%s", TfMakeValidIdentifier(key.GetString()).c_str()); }
/* static */ HdStGLSLProgram::ID HdStGLSLProgram::ComputeHash(TfToken const &sourceFile) { HD_TRACE_FUNCTION(); uint32_t hash = 0; std::string const &filename = sourceFile.GetString(); hash = ArchHash(filename.c_str(), filename.size(), hash); return hash; }
TfToken UsdVolVolume::_MakeNamespaced(const TfToken& name) { TfToken result; if (TfStringStartsWith(name, _tokens->fieldPrefix)) { result = name; } else { result = TfToken(_tokens->fieldPrefix.GetString() + name.GetString()); } return result; }
UsdAttribute UsdRiStatementsAPI::GetRiAttribute( const TfToken &name, const std::string &nameSpace) { TfToken fullName = _MakeRiAttrNamespace(nameSpace, name.GetString()); if (UsdGeomPrimvar p = UsdGeomPrimvarsAPI(GetPrim()).GetPrimvar(fullName)) { return p; } if (TfGetEnvSetting(USDRI_STATEMENTS_READ_OLD_ATTR_ENCODING)) { return GetPrim().GetAttribute(fullName); } return UsdAttribute(); }
/* 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); }
SdfPath SdfPath::AppendProperty(TfToken const &propName) const { if (!IsValidNamespacedIdentifier(propName.GetString())) { //TF_WARN("Invalid property name."); return EmptyPath(); } if (!IsPrimVariantSelectionPath() && !IsPrimPath() && (_pathNode != Sdf_PathNode::GetRelativeRootNode())) { TF_WARN("Can only append a property '%s' to a prim path (%s)", propName.GetText(), GetText()); return EmptyPath(); } return SdfPath(Sdf_PathNode::FindOrCreatePrimProperty(_pathNode, propName)); }
SdfFileFormat::SdfFileFormat( const TfToken& formatId, const TfToken& versionString, const TfToken& target, const std::string& extension) : _formatId(formatId) , _target(target) , _cookie("#" + formatId.GetString()) , _versionString(versionString) , _extensions(1, extension) , _isPrimaryFormat( _FileFormatRegistry ->GetPrimaryFormatForExtension(extension) == formatId) { // Do Nothing. }
std::string UsdRiStatementsAPI::MakeRiAttributePropertyName(const std::string &attrName) { std::vector<string> names = TfStringTokenize(attrName, ":"); // If this is an already-encoded name, return it unchanged. if (TfGetEnvSetting(USDRI_STATEMENTS_WRITE_NEW_ATTR_ENCODING)) { if (names.size() == 5 && TfStringStartsWith(attrName, _tokens->primvarAttrNamespace)) { return attrName; } } if (names.size() == 4 && TfStringStartsWith(attrName, _tokens->fullAttributeNamespace)) { return attrName; } // Attempt to parse namespaces in different forms. if (names.size() == 1) { names = TfStringTokenize(attrName, "."); } if (names.size() == 1) { names = TfStringTokenize(attrName, "_"); } // Fallback to user namespace if no other exists. if (names.size() == 1) { names.insert(names.begin(), "user"); } TfToken prefix = TfGetEnvSetting(USDRI_STATEMENTS_WRITE_NEW_ATTR_ENCODING) ? _tokens->primvarAttrNamespace : _tokens->fullAttributeNamespace; string fullName = prefix.GetString() + names[0] + ":" + ( names.size() > 2 ? TfStringJoin(names.begin() + 1, names.end(), "_") : names[1]); return SdfPath::IsValidNamespacedIdentifier(fullName) ? fullName : string(); }
SdfFileFormat::SdfFileFormat( const TfToken& formatId, const TfToken& versionString, const TfToken& target, const std::vector<std::string>& extensions) : _formatId(formatId) , _target(target) , _cookie("#" + formatId.GetString()) , _versionString(versionString) , _extensions(extensions) // If a file format is marked as primary, then it must be the // primary format for all of the extensions it supports. So, // it's sufficient to just check the first extension in the list. , _isPrimaryFormat( _FileFormatRegistry ->GetPrimaryFormatForExtension(extensions[0]) == formatId) { // Do Nothing. }
UsdAttribute UsdRiStatementsAPI::CreateRiAttribute( const TfToken &name, const TfType &tfType, const string &nameSpace) { TfToken fullName = _MakeRiAttrNamespace(nameSpace, name.GetString()); SdfValueTypeName usdType = SdfSchema::GetInstance().FindType(tfType); if (TfGetEnvSetting(USDRI_STATEMENTS_WRITE_NEW_ATTR_ENCODING)) { return UsdGeomPrimvarsAPI(GetPrim()) .CreatePrimvar(fullName, usdType).GetAttr(); } else { UsdAttribute attr = GetPrim().CreateAttribute(fullName, usdType, /* custom = */ false); if (!TF_VERIFY(attr)) { return UsdAttribute(); } return attr; } }
void KindRegistry::_Register(const TfToken& kind, const TfToken& baseKind) { if (not TfIsValidIdentifier(kind.GetString())) { TF_CODING_ERROR("Invalid kind: '%s'", kind.GetText()); return; } _KindMap::const_iterator it = _kindMap.find(kind); if (it != _kindMap.end()) { TF_CODING_ERROR("Kind '%s' has already been registered", kind.GetText()); return; } _KindData data; data.baseKind = baseKind; _kindMap[kind] = data; }
/* static */ TfToken UsdSkelInbetweenShape::_MakeNamespaced(const TfToken& name, bool quiet) { TfToken result; if(_IsNamespaced(name)){ result = name; } else { result = TfToken(_tokens->inbetweensPrefix.GetString() + name.GetString()); } // XXX: All properly namespaced attributes are legal inbetweens. // However, if we extend the schema to include any special attributes // -- such as a namespaced pointIndices attr on each shape -- then // we must validate that the name does not conflict with those. if(!_IsValidInbetweenName(result, quiet)) { result = TfToken(); } return result; }
/* static */ TfToken UsdGeomPrimvar::_MakeNamespaced(const TfToken& name, bool quiet) { TfToken result; if (_IsNamespaced(name)){ result = name; } else { result = TfToken(_tokens->primvarsPrefix.GetString() + name.GetString()); } if (_ContainsExtraNamespaces(result)){ result = TfToken(); if (!quiet){ TF_CODING_ERROR("%s is not a valid name for a Primvar, because" " it contains namespaces.", name.GetText()); } } return result; }
SdfPath SdfPath::AppendElementToken(const TfToken &elementTok) const { std::string const &element = elementTok.GetString(); if (ARCH_UNLIKELY((!_pathNode) || element.empty())){ if (!_pathNode){ TF_CODING_ERROR("Cannot append element \'%s\' to the EmptyPath.", element.c_str()); } else { TF_CODING_ERROR("Cannot append EmptyPath as a path element."); } return EmptyPath(); } /* This is a somewhat unfortunate replication of a subset of the * logic contained in the full-path-parser. We can't invoke the * parser on just a single element out of context (and probably * wouldn't want to for cost reasons if we could). Can't think of * a more elegant way to do this. 1/13 */ char const *txt = element.c_str(); // No static tokens for variant chars... if (txt[0] == '{') { vector<string> tokens = TfStringTokenize(element, "{=}"); TfToken variantSel; if (tokens.size() == 2){ variantSel = TfToken(tokens[1]); } else if (tokens.size() != 1){ return EmptyPath(); } return AppendVariantSelection(TfToken(tokens[0]), variantSel); } else if (txt[0] == SdfPathTokens->relationshipTargetStart.GetString()[0]) { SdfPath target(element.substr(1, element.length()-2)); return AppendTarget(target); } else if (txt[0] == SdfPathTokens->propertyDelimiter.GetString()[0]) { // This is the ambiguous one. First check for the special symbols, // and if it looks like a "plain old property", consult parent type // to determine what the property sub-type should be. static string mapperStr = SdfPathTokens->propertyDelimiter.GetString() + SdfPathTokens->mapperIndicator.GetString() + SdfPathTokens->relationshipTargetStart.GetString(); static string expressionStr = SdfPathTokens->propertyDelimiter.GetString() + SdfPathTokens->expressionIndicator.GetString(); if ( element == expressionStr ){ return IsPropertyPath() ? AppendExpression() : AppendProperty(SdfPathTokens->expressionIndicator); } else if (TfStringStartsWith(element, mapperStr)){ const size_t prefixSz(mapperStr.length()); SdfPath target(element.substr(prefixSz, element.length()-(prefixSz+1))); return AppendMapper(target); } else { TfToken property(element.substr(1)); if (IsMapperPath()){ return AppendMapperArg(property); } else if (IsTargetPath()){ return AppendRelationalAttribute(property); } else { return AppendProperty(property); } } } else { return AppendChild(elementTok); } }
// Assumes that name is prefixed with the primvars namespace inline static bool _ContainsExtraNamespaces(const TfToken &name) { static const size_t prefixSize = _tokens->primvarsPrefix.GetString().size(); return (name.GetString().find(':', prefixSize) != std::string::npos); }
static inline bool _IsValidIdentifier(TfToken const &name) { return TfIsValidIdentifier(name.GetString()); }
TfToken SdfPath::StripNamespace(const TfToken &name) { return TfToken(StripNamespace(name.GetString())); }
bool GlfUVTexture::IsSupportedImageFile(TfToken const &imageFilePath) { return IsSupportedImageFile(imageFilePath.GetString()); }
static TfToken _GetOutputAttrName(const TfToken outputName) { return TfToken(UsdShadeTokens->outputs.GetString() + outputName.GetString()); }
std::string SdfPath::JoinIdentifier(const TfToken &lhs, const TfToken &rhs) { return JoinIdentifier(lhs.GetString(), rhs.GetString()); }
static TfToken _GetConnectionRelName(const TfToken &attrName) { return TfToken(UsdShadeTokens->connectedSourceFor.GetString() + attrName.GetString()); }
static std::string _GetMayaAttrNameForAttrName(const TfToken& attrName) { return TfStringPrintf("USD_ATTR_%s", TfMakeValidIdentifier(attrName.GetString()).c_str()); }