Skip to content

Commit aee03b4

Browse files
author
Keith Blackstone
authored
Merge pull request #25 from adobe/v1.0.4
v1.0.4
2 parents eab790a + aad5bbf commit aee03b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1508
-737
lines changed

.gitignore

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,16 @@ build-meta
4343
.vscode/*
4444
.idea
4545

46-
# Generated
46+
# Generated documentation
4747
docs
48-
Testing
4948
bin
49+
50+
# Test
51+
Testing
5052
test/__pycache__
51-
test/assets/*/*.usd
52-
test/assets/*/*/*.usd
5353
test/output
54+
test/assets/fbx/*.usd
55+
test/assets/gltf/*.usd
56+
test/assets/obj/*/*.usd
57+
test/assets/ply/*.usd
58+
test/assets/stl/*.usd

changelog.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
v1.0.4 May 31st, 2024
2+
gltf:
3+
- ability to open gltf file from within usd archive
4+
- scaling fix for normal map data and mipmap support for texture nodes
5+
ply:
6+
- clipping and axis adjusting for ply assets
7+
sbsar:
8+
- Add SbsarConfig plugin to allow to control cache size in an APP
9+
utility:
10+
- asset resolver fix for uppercase extensions
11+
- trim extensions when parsing for file format
12+
- tftoken cleanup
13+
- refactor GetConnectedSources into GetValueProducingAttributes
14+
115
v1.0.3 April 29th, 2024
216
fbx:
317
- fix for setting image filename path

fbx/src/fileFormat.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ using namespace adobe::usd;
2929
PXR_NAMESPACE_OPEN_SCOPE
3030

3131
static std::mutex mutex;
32-
const TfToken UsdFbxFileFormat::assetsPathToken("fbxAssetsPath");
33-
const TfToken UsdFbxFileFormat::phongToken("fbxPhong");
32+
const TfToken UsdFbxFileFormat::assetsPathToken("fbxAssetsPath", TfToken::Immortal);
33+
const TfToken UsdFbxFileFormat::phongToken("fbxPhong", TfToken::Immortal);
3434

3535
TF_DEFINE_PUBLIC_TOKENS(UsdFbxFileFormatTokens, USDFBX_FILE_FORMAT_TOKENS);
3636

@@ -95,6 +95,7 @@ UsdFbxFileFormat::Read(SdfLayer* layer, const std::string& resolvedPath, bool me
9595
TfStopwatch w;
9696
w.Start();
9797
TF_DEBUG_MSG(FILE_FORMAT_FBX, "Read: %s\n", resolvedPath.c_str());
98+
std::string fileType = getFileExtension(resolvedPath, DEBUG_TAG);
9899
SdfAbstractDataRefPtr layerData = InitData(layer->GetFileFormatArguments());
99100
FbxDataConstPtr data = TfDynamic_cast<const FbxDataConstPtr>(layerData);
100101
UsdData usd;
@@ -113,7 +114,7 @@ UsdFbxFileFormat::Read(SdfLayer* layer, const std::string& resolvedPath, bool me
113114
readFbx(fbx, resolvedPath, false), "Error reading FBX from %s\n", resolvedPath.c_str());
114115
GUARD(importFbx(options, fbx, usd), "Error translating FBX to USD\n");
115116
}
116-
GUARD(writeLayer(layerOptions, usd, layer, layerData, DEBUG_TAG, SdfFileFormat::_SetLayerData),
117+
GUARD(writeLayer(layerOptions, usd, layer, layerData, fileType, DEBUG_TAG, SdfFileFormat::_SetLayerData),
117118
"Error writing to the USD layer\n");
118119

119120
if (options.importImages) {

fbx/src/plugInfo.json.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"adobe::usd::FbxResolver" : {
2929
"bases": [ "ArPackageResolver" ],
30-
"extensions": [ "fbx" ]
30+
"extensions": [ "fbx", "FBX", "Fbx" ]
3131
}
3232
}
3333
},

gltf/src/fileFormat.cpp

Lines changed: 96 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ governing permissions and limitations under the License.
2424

2525
// USD
2626
#include <pxr/base/tf/pathUtils.h>
27+
#include <pxr/base/tf/stringUtils.h>
28+
#include <pxr/usd/ar/packageUtils.h>
2729
#include <pxr/usd/usd/usdaFileFormat.h>
2830

2931
PXR_NAMESPACE_OPEN_SCOPE
3032

3133
using namespace adobe::usd;
3234

33-
const TfToken UsdGltfFileFormat::assetsPathToken("gltfAssetsPath");
35+
const TfToken UsdGltfFileFormat::assetsPathToken("gltfAssetsPath", TfToken::Immortal);
3436

3537
TF_DEFINE_PUBLIC_TOKENS(UsdGltfFileFormatTokens, USDGLTF_FILE_FORMAT_TOKENS);
3638

@@ -89,32 +91,34 @@ UsdGltfFileFormat::CanRead(const std::string& filePath) const
8991
return true;
9092
}
9193

94+
/*static*/
9295
bool
93-
UsdGltfFileFormat::_ReadFromStream(SdfLayer* layer,
94-
std::istream& input,
95-
bool metadataOnly,
96-
std::string* outErr,
97-
std::istream& mtlinput) const
96+
UsdGltfFileFormat::OpenGltfAsset(const std::string& resolvedPath,
97+
std::shared_ptr<ArAsset>& asset,
98+
std::string& baseDir,
99+
bool& isAscii)
98100
{
99-
// // Read Obj data stream.
100-
// UsdGltfStream gltfStream;
101-
// if (!UsdObjReadDataFromStream(input, mtlinput, &gltfStream, outErr))
102-
// return false;
103-
104-
// // Translate obj to usd schema.
105-
// SdfLayerRefPtr objAsUsd = UsdObjTranslateObjToUsd(gltfStream);
106-
// if (!objAsUsd)
107-
// return false;
108-
109-
// // Move generated content into final layer.
110-
// layer->TransferContent(objAsUsd);
101+
asset = ArGetResolver().OpenAsset(ArResolvedPath(resolvedPath));
102+
if (!asset) {
103+
TF_WARN("Couldn't open asset %s", resolvedPath.c_str());
104+
return false;
105+
}
106+
107+
// Extract the inner most name of a potentially nest path, e.g. "archive.usdz[myAsset.gltf]"
108+
auto [packagePath, packagedPath] = ArSplitPackageRelativePathInner(resolvedPath);
109+
110+
// If we have a direct path on disk, we set the baseDir to the same folder
111+
if (packagedPath.empty()) {
112+
baseDir = TfGetPathName(packagePath);
113+
}
114+
115+
const std::string& fileName = packagedPath.empty() ? packagePath : packagedPath;
116+
std::string ext = TfStringToLower(TfGetExtension(fileName));
117+
isAscii = (ext == "gltf");
118+
111119
return true;
112120
}
113121

114-
// void function(TfDebug::FILE_FORMAT_GLTF a) {
115-
// TF_DEBUG_MSG(a, "Experiment debug cdoe\n");
116-
// }
117-
118122
bool
119123
UsdGltfFileFormat::Read(PXR_NS::SdfLayer* layer,
120124
const std::string& resolvedPath,
@@ -123,44 +127,99 @@ UsdGltfFileFormat::Read(PXR_NS::SdfLayer* layer,
123127
TfStopwatch w;
124128
w.Start();
125129
TF_DEBUG_MSG(FILE_FORMAT_GLTF, "Read: %s\n", resolvedPath.c_str());
126-
SdfAbstractDataRefPtr layerData = InitData(layer->GetFileFormatArguments());
127-
GltfDataConstPtr data = TfDynamic_cast<const GltfDataConstPtr>(layerData);
128-
UsdData usd;
130+
131+
std::shared_ptr<ArAsset> asset;
132+
std::string baseDir;
133+
bool isAscii = false;
134+
if (!OpenGltfAsset(resolvedPath, asset, baseDir, isAscii)) {
135+
return false;
136+
}
137+
138+
std::shared_ptr<const char> buffer = asset->GetBuffer();
139+
size_t bufferSize = asset->GetSize();
140+
TF_DEBUG_MSG(FILE_FORMAT_GLTF,
141+
"Type: %s, Base path: '%s', Size: %zu KB\n",
142+
isAscii ? "GLTF" : "GLB",
143+
baseDir.c_str(),
144+
bufferSize >> 10);
145+
129146
tinygltf::Model gltf;
147+
GUARD(readGltfFromMemory(gltf, baseDir, isAscii, &*buffer, bufferSize),
148+
"Error reading glTF file\n");
149+
150+
UsdData usd;
130151
ImportGltfOptions options;
131152
options.importGeometry = true;
132153
options.importMaterials = true;
133154
options.importImages = true;
155+
GUARD(importGltf(options, gltf, usd, resolvedPath), "Error translating glTF to USD\n");
156+
157+
SdfAbstractDataRefPtr layerData = InitData(layer->GetFileFormatArguments());
158+
GltfDataConstPtr data = TfDynamic_cast<const GltfDataConstPtr>(layerData);
134159
WriteLayerOptions layerOptions;
135160
layerOptions.writeMaterialX = data->writeMaterialX;
136161
layerOptions.pruneJoints = false;
137162
layerOptions.assetsPath = data->assetsPath;
138-
GUARD(readGltf(gltf, resolvedPath), "Error reading glTF file\n");
139-
GUARD(importGltf(options, gltf, usd, resolvedPath), "Error translating glTF to USD\n");
140-
GUARD(writeLayer(layerOptions, usd, layer, layerData, DEBUG_TAG, SdfFileFormat::_SetLayerData),
141-
"Error writing to the USD layer\n");
163+
std::string ext = isAscii ? "GLTF" : "GLB";
164+
GUARD(
165+
writeLayer(layerOptions, usd, layer, layerData, ext, DEBUG_TAG, SdfFileFormat::_SetLayerData),
166+
"Error writing to the USD layer\n");
142167

168+
// Populate the GLTF resolver with the images we just parsed from the asset, so that we don't
169+
// have to open the asset again.
143170
if (options.importImages) {
144171
Resolver::populateCache(resolvedPath, std::move(usd.images));
145172
} else {
146173
Resolver::clearCache(resolvedPath);
147174
}
148175

149176
w.Stop();
150-
TF_DEBUG_MSG(FILE_FORMAT_GLTF, "Total time: %ld ms\n", static_cast<long int>(w.GetMilliseconds()));
177+
TF_DEBUG_MSG(
178+
FILE_FORMAT_GLTF, "Total time: %ld ms\n", static_cast<long int>(w.GetMilliseconds()));
179+
151180
return true;
152181
}
153182

154183
bool
155184
UsdGltfFileFormat::ReadFromString(SdfLayer* layer, const std::string& str) const
156185
{
157-
std::string error;
158-
std::stringstream ss(str);
159-
std::stringstream ssmtl("");
160-
if (!_ReadFromStream(layer, ss, /*metadataOnly=*/false, &error, ssmtl)) {
161-
TF_RUNTIME_ERROR("Failed to read GLTF data from string: %s", error.c_str());
162-
return false;
163-
}
186+
TfStopwatch w;
187+
w.Start();
188+
TF_DEBUG_MSG(FILE_FORMAT_GLTF, "ReadFromString: %zu KB\n", str.size() >> 10);
189+
190+
// We don't have a base directory for external references. So only complete GLTF files will work
191+
// with this path
192+
std::string baseDir;
193+
bool isAscii = true;
194+
195+
tinygltf::Model gltf;
196+
GUARD(readGltfFromMemory(gltf, baseDir, isAscii, &str[0], str.size()),
197+
"Error reading glTF from string\n");
198+
199+
UsdData usd;
200+
ImportGltfOptions options;
201+
options.importGeometry = true;
202+
options.importMaterials = true;
203+
options.importImages = true;
204+
GUARD(importGltf(options, gltf, usd, ""), "Error translating glTF to USD\n");
205+
206+
SdfAbstractDataRefPtr layerData = InitData(layer->GetFileFormatArguments());
207+
GltfDataConstPtr data = TfDynamic_cast<const GltfDataConstPtr>(layerData);
208+
WriteLayerOptions layerOptions;
209+
layerOptions.writeMaterialX = data->writeMaterialX;
210+
layerOptions.pruneJoints = false;
211+
layerOptions.assetsPath = data->assetsPath;
212+
std::string ext = isAscii ? "GLTF" : "GLB";
213+
GUARD(
214+
writeLayer(layerOptions, usd, layer, layerData, ext, DEBUG_TAG, SdfFileFormat::_SetLayerData),
215+
"Error writing to the USD layer\n");
216+
217+
// Note, we can't populate the path resolver since we don't have an associated file
218+
219+
w.Stop();
220+
TF_DEBUG_MSG(
221+
FILE_FORMAT_GLTF, "Total time: %ld ms\n", static_cast<long int>(w.GetMilliseconds()));
222+
164223
return true;
165224
}
166225

gltf/src/fileFormat.h

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,32 @@ governing permissions and limitations under the License.
1111
*/
1212
#pragma once
1313
#include "api.h"
14-
#include <iosfwd>
14+
#include <version.h>
15+
16+
#include <sdfUtils.h>
17+
1518
#include <pxr/base/tf/staticTokens.h>
1619
#include <pxr/pxr.h>
1720
#include <pxr/usd/pcp/dynamicFileFormatInterface.h>
18-
#include <sdfUtils.h>
21+
22+
#include <iosfwd>
1923
#include <string>
20-
#include <version.h>
2124

2225
PXR_NAMESPACE_OPEN_SCOPE
2326

24-
#define USDGLTF_FILE_FORMAT_TOKENS ((Id, "gltf"))((Version, FILE_FORMATS_VERSION))((Target, "usd"))
27+
// clang-format off
28+
#define USDGLTF_FILE_FORMAT_TOKENS \
29+
((Id, "gltf")) \
30+
((Version, FILE_FORMATS_VERSION)) \
31+
((Target, "usd"))
32+
// clang-format on
2533

2634
TF_DECLARE_PUBLIC_TOKENS(UsdGltfFileFormatTokens, USDGLTF_FILE_FORMAT_TOKENS);
2735
TF_DECLARE_WEAK_AND_REF_PTRS(GltfData);
2836
TF_DECLARE_WEAK_AND_REF_PTRS(UsdGltfFileFormat);
2937

38+
class ArAsset;
39+
3040
/// \ingroup usdgltf
3141
/// \brief SdfData specialization for working with glTF files.
3242
class GltfData : public FileFormatDataBase
@@ -45,6 +55,13 @@ class USDGLTF_API UsdGltfFileFormat
4555
public:
4656
friend class GltfData;
4757

58+
// If successful, returns true and fills in the assetPtr, baseDir and the isAscii flag
59+
// baseDir can be used to resolve external assets
60+
static bool OpenGltfAsset(const std::string& resolvedPath,
61+
std::shared_ptr<ArAsset>& assetPtr,
62+
std::string& baseDir,
63+
bool& isAscii);
64+
4865
virtual SdfAbstractDataRefPtr InitData(const FileFormatArguments& args) const override;
4966

5067
virtual void ComposeFieldsForFileFormatArguments(const std::string& assetPath,
@@ -61,8 +78,8 @@ class USDGLTF_API UsdGltfFileFormat
6178
virtual bool CanRead(const std::string& file) const override;
6279

6380
virtual bool Read(SdfLayer* layer,
64-
const std::string& resolved_path,
65-
bool metadata_only) const override;
81+
const std::string& resolvedPath,
82+
bool metadataOnly) const override;
6683

6784
virtual bool ReadFromString(SdfLayer* layer, const std::string& str) const override;
6885

@@ -88,13 +105,6 @@ class USDGLTF_API UsdGltfFileFormat
88105
virtual ~UsdGltfFileFormat();
89106

90107
UsdGltfFileFormat();
91-
92-
private:
93-
bool _ReadFromStream(SdfLayer* layer,
94-
std::istream& input,
95-
bool metadataOnly,
96-
std::string* outErr,
97-
std::istream& mtlinput) const;
98108
};
99109

100110
PXR_NAMESPACE_CLOSE_SCOPE

0 commit comments

Comments
 (0)