Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:syoyo/tinyusdz into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Nov 2, 2023
2 parents 1fe7d2a + 8e679e0 commit d88046a
Show file tree
Hide file tree
Showing 20 changed files with 626 additions and 145 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* [x] payload(no delayed load)
* [x] inherits
* [x] variantSet
* [ ] Validate composition is correctly operated.
* [ ] Validate composition is correctly operated.
* Better usdLux support https://github.com/syoyo/tinyusdz/issues/101
* Support reading & compose some production USD scenes
* [ ] Moana island v2.1 https://github.com/syoyo/tinyusdz/issues/90
* [ ] ALAB USD production scene https://github.com/syoyo/tinyusdz/issues/91
Expand Down
3 changes: 2 additions & 1 deletion examples/openglviewer/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1482,10 +1482,11 @@ int main(int argc, char **argv) {

float highDPIscaleFactor = 1.0f;

float xscale=1.0f;
float yscale=1.0f;
#if defined(_WIN32) || defined(__linux__)
// if it's a HighDPI monitor, try to scale everything
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
float xscale, yscale;
glfwGetMonitorContentScale(monitor, &xscale, &yscale);
std::cout << "monitor xscale, yscale = " << xscale << ", " << yscale << "\n";
if (xscale > 1 || yscale > 1) {
Expand Down
99 changes: 52 additions & 47 deletions examples/tusdcat/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ int main(int argc, char **argv) {
std::string warn;

tinyusdz::AssetResolutionResolver resolver;
resolver.set_current_working_path(base_dir);
resolver.set_search_paths({base_dir});

//
Expand Down Expand Up @@ -197,14 +198,15 @@ int main(int argc, char **argv) {
}

// TODO: Find more better way to Recursively resolve references/payload/variants
bool all_resolved = true;
for (int i = 0; i < kMaxIteration; i++) {

bool has_unresolved = false;

if (comp_features.references) {
if (!src_layer.check_unresolved_references()) {
all_resolved = true;
std::cout << "# iter " << i << ": no unresolved references.\n";
} else {
all_resolved = false;
has_unresolved = true;

tinyusdz::Layer composited_layer;
if (!tinyusdz::CompositeReferences(resolver, src_layer, &composited_layer, &warn, &err)) {
Expand All @@ -225,79 +227,82 @@ int main(int argc, char **argv) {

if (comp_features.payload) {
if (!src_layer.check_unresolved_payload()) {
all_resolved = true;
std::cout << "# iter " << i << ": no unresolved payload.\n";
} else {
all_resolved = false;
}
has_unresolved = true;

tinyusdz::Layer composited_layer;
if (!tinyusdz::CompositePayload(resolver, src_layer, &composited_layer, &warn, &err)) {
std::cerr << "Failed to composite `payload`: " << err << "\n";
return -1;
}
tinyusdz::Layer composited_layer;
if (!tinyusdz::CompositePayload(resolver, src_layer, &composited_layer, &warn, &err)) {
std::cerr << "Failed to composite `payload`: " << err << "\n";
return -1;
}

if (warn.size()) {
std::cout << "WARN: " << warn << "\n";
}
if (warn.size()) {
std::cout << "WARN: " << warn << "\n";
}

std::cout << "# `payload` composited\n";
std::cout << composited_layer << "\n";
std::cout << "# `payload` composited\n";
std::cout << composited_layer << "\n";

src_layer = std::move(composited_layer);
src_layer = std::move(composited_layer);
}
}

if (comp_features.inherits) {
if (!src_layer.check_unresolved_inherits()) {
all_resolved = true;
std::cout << "# iter " << i << ": no unresolved inherits.\n";
} else {
all_resolved = false;
}
has_unresolved = true;

tinyusdz::Layer composited_layer;
if (!tinyusdz::CompositeInherits(src_layer, &composited_layer, &warn, &err)) {
std::cerr << "Failed to composite `inherits`: " << err << "\n";
return -1;
}
tinyusdz::Layer composited_layer;
if (!tinyusdz::CompositeInherits(src_layer, &composited_layer, &warn, &err)) {
std::cerr << "Failed to composite `inherits`: " << err << "\n";
return -1;
}

if (warn.size()) {
std::cout << "WARN: " << warn << "\n";
}
if (warn.size()) {
std::cout << "WARN: " << warn << "\n";
}

std::cout << "# `inherits` composited\n";
std::cout << composited_layer << "\n";
std::cout << "# `inherits` composited\n";
std::cout << composited_layer << "\n";

src_layer = std::move(composited_layer);
src_layer = std::move(composited_layer);
}
}

if (comp_features.variantSets) {
if (!src_layer.check_unresolved_variant()) {
all_resolved = true;
std::cout << "# iter " << i << ": no unresolved variant.\n";
} else {
all_resolved = false;
}
has_unresolved = true;

tinyusdz::Layer composited_layer;
if (!tinyusdz::CompositeVariant(src_layer, &composited_layer, &warn, &err)) {
std::cerr << "Failed to composite `variantSet`: " << err << "\n";
return -1;
}
tinyusdz::Layer composited_layer;
if (!tinyusdz::CompositeVariant(src_layer, &composited_layer, &warn, &err)) {
std::cerr << "Failed to composite `variantSet`: " << err << "\n";
return -1;
}

if (warn.size()) {
std::cout << "WARN: " << warn << "\n";
}
if (warn.size()) {
std::cout << "WARN: " << warn << "\n";
}

std::cout << "# `variantSet` composited\n";
std::cout << composited_layer << "\n";
std::cout << "# `variantSet` composited\n";
std::cout << composited_layer << "\n";

src_layer = std::move(composited_layer);
src_layer = std::move(composited_layer);
}
}

// TODO
// - [ ] specializes
// - [ ] `class` Prim?

if (all_resolved) {
std::cout << "# of composition resolve iteration: " << (i + 1) << "\n";
std::cout << "# has_unresolved_references: " << src_layer.check_unresolved_references() << "\n";
std::cout << "# all resolved? " << !has_unresolved << "\n";

if (!has_unresolved) {
std::cout << "# of composition iteration to resolve fully: " << (i + 1) << "\n";
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/ascii-parser-basetype.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ bool AsciiParser::SepBy1BasicType(const char sep, const char end_symbol, std::ve
}

while (!Eof()) {
if (!SkipWhitespaceAndNewline()) {
if (!SkipCommentAndWhitespaceAndNewline()) {
return false;
}

Expand All @@ -1684,7 +1684,7 @@ bool AsciiParser::SepBy1BasicType(const char sep, const char end_symbol, std::ve

if (c == sep) {
// Look next token
if (!SkipWhitespaceAndNewline()) {
if (!SkipCommentAndWhitespaceAndNewline()) {
return false;
}

Expand Down Expand Up @@ -1967,7 +1967,7 @@ bool AsciiParser::SepBy1BasicType(const char sep,

while (!Eof()) {
// sep
if (!SkipWhitespaceAndNewline()) {
if (!SkipCommentAndWhitespaceAndNewline()) {
return false;
}

Expand All @@ -1978,7 +1978,7 @@ bool AsciiParser::SepBy1BasicType(const char sep,

if (c == sep) {
// Look next token
if (!SkipWhitespaceAndNewline()) {
if (!SkipCommentAndWhitespaceAndNewline()) {
return false;
}

Expand Down
8 changes: 6 additions & 2 deletions src/ascii-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4336,6 +4336,10 @@ bool AsciiParser::ParseVariantSet(const int64_t primIdx,
Rewind(1);
}

if (!SkipCommentAndWhitespaceAndNewline()) {
return false;
}

// string
std::string variantName;
if (!ReadBasicType(&variantName)) {
Expand Down Expand Up @@ -4440,12 +4444,12 @@ bool AsciiParser::ParseVariantSet(const int64_t primIdx,
DCOUT(fmt::format("Done parse ParsePrimProps."));
}

if (!SkipWhitespaceAndNewline()) {
if (!SkipCommentAndWhitespaceAndNewline()) {
return false;
}
}

if (!SkipWhitespaceAndNewline()) {
if (!SkipCommentAndWhitespaceAndNewline()) {
return false;
}

Expand Down
24 changes: 24 additions & 0 deletions src/asset-resolution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,20 @@ bool AssetResolutionResolver::find(const std::string &assetPath) const {
}
}

if ((_current_working_path == ".") || (_current_working_path == "./")) {
std::string rpath = io::FindFile(assetPath, {});
} else {
// TODO: Only find when input path is relative.
std::string rpath = io::FindFile(assetPath, {_current_working_path});
if (rpath.size()) {
return true;
}
}

// TODO: Cache resolition.
std::string fpath = io::FindFile(assetPath, _search_paths);
return fpath.size();

}

std::string AssetResolutionResolver::resolve(
Expand Down Expand Up @@ -88,8 +99,21 @@ std::string AssetResolutionResolver::resolve(
}
}

DCOUT("cwd = " << _current_working_path);
DCOUT("search_paths = " << _search_paths);
DCOUT("assetPath = " << assetPath);

std::string rpath;
if ((_current_working_path == ".") || (_current_working_path == "./")) {
rpath = io::FindFile(assetPath, {});
} else {
rpath = io::FindFile(assetPath, {_current_working_path});
}

if (rpath.size()) {
return rpath;
}

// TODO: Cache resolition.
return io::FindFile(assetPath, _search_paths);
}
Expand Down
14 changes: 13 additions & 1 deletion src/asset-resolution.hh
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,21 @@ class AssetResolutionResolver {
_search_paths = paths;
}

void add_seartch_path(const std::string &path) {
void add_search_path(const std::string &path) {
_search_paths.push_back(path);
}

//
// Asset is first seeked from the current working path(directory) when the Asset's path is a relative path.
//
void set_current_working_path(const std::string &cwp) {
_current_working_path = cwp;
}

const std::string &current_working_path() const {
return _current_working_path;
}

const std::vector<std::string> &search_paths() const { return _search_paths; }

std::string search_paths_str() const;
Expand Down Expand Up @@ -278,6 +289,7 @@ class AssetResolutionResolver {
private:
//ResolvePathHandler _resolve_path_handler{nullptr};
void *_userdata{nullptr};
std::string _current_working_path{"./"};
std::vector<std::string> _search_paths;
mutable size_t _max_asset_bytes_in_mb{1024*1024}; // default 1 TB

Expand Down
Loading

0 comments on commit d88046a

Please sign in to comment.