Sorry to open this topic back up, but I finally got around to implementing my custom SDF File Format plugin and I wanted to share my approach. I also am looking for any gotchas.
I built my File Format plugin like any other except I inherited from the SdfTextFileFormat class.
class UsdSdfFileFormat : public SdfTextFileFormat {
public:
// SdfTextFileFormat overrides.
virtual bool CanRead(const std::string &file) const override;
virtual bool Read(SdfLayer* layer,
const std::string& resolvedPath,
bool metadataOnly) const override;
protected:
SDF_FILE_FORMAT_FACTORY_ACCESS;
virtual ~UsdSdfFileFormat();
UsdSdfFileFormat();
SDF_API
explicit UsdSdfFileFormat(const TfToken& formatId,
const TfToken& versionString = TfToken(),
const TfToken& target = TfToken());
private:
bool _ReadFromStream(SdfLayer *layer,
std::istream &input,
bool metadataOnly,
std::string *outErr) const;
bool _IsSdfRcsFormat(const std::string& filepath) const;
};
I removed the plugInfo.json at \lib\usd\sdf\resources from my USD build. My current plugInfo.json is:
{
"Plugins": [
{
"Info": {
"Types": {
"UsdSdfFileFormat": {
"bases": [
"SdfFileFormat"
],
"displayName": "Modified SDF Text File Format Plugin",
"extensions": [
"sdf"
],
"formatId": "sdf",
"primary": true,
"target": "usd"
}
}
},
"LibraryPath": "@PLUG_INFO_LIBRARY_PATH@",
"Name": "usdSdf",
"ResourcePath": "@PLUG_INFO_RESOURCE_PATH@",
"Root": "@PLUG_INFO_ROOT@",
"Type": "library"
}
]
}
Everything seems to be functioning correctly in my tests.
Do I need the SdfMetadata tag? The SdfFileFormat type flag?
From the default plugInfo.json:
{
"Plugins": [
{
"Info": {
"SdfMetadata": {
"payloadAssetDependencies": {
"appliesTo": "prims",
"displayGroup": "Pipeline",
"type": "asset[]"
}
},
"Types": {
"SdfFileFormat": {
"displayName": "Sdf file format base class",
"target": "sdf"
},
"SdfTextFileFormat": {
"bases": [
"SdfFileFormat"
],
"displayName": "Sdf Text File Format",
"extensions": [
"sdf"
],
"formatId": "sdf"
}
}
},
"LibraryPath": "../../usd_sdf.dll",
"Name": "sdf",
"ResourcePath": "resources",
"Root": "..",
"Type": "library"
}
]
}
Thanks,
Nick