mirror of
https://github.com/lighttransport/tinyusdz.git
synced 2026-01-18 01:11:17 +01:00
Support custom kind value.
This commit is contained in:
@@ -453,7 +453,7 @@ std::string print_prim_metas(const PrimMeta &meta, const uint32_t indent) {
|
||||
}
|
||||
|
||||
if (meta.kind) {
|
||||
ss << pprint::Indent(indent) << "kind = " << quote(to_string(meta.kind.value())) << "\n";
|
||||
ss << pprint::Indent(indent) << "kind = " << quote(meta.get_kind()) << "\n";
|
||||
}
|
||||
|
||||
// TODO: UTF-8 ready pprint
|
||||
@@ -1804,6 +1804,9 @@ std::string to_string(tinyusdz::Kind v) {
|
||||
return "subcomponent";
|
||||
} else if (v == tinyusdz::Kind::SceneLibrary) {
|
||||
return "sceneLibrary";
|
||||
} else if (v == tinyusdz::Kind::UserDef) {
|
||||
// Should use PrimMeta::get_kind() to get actual Kind string value.
|
||||
return "[[InternalError. UserDefKind]]";
|
||||
} else {
|
||||
return "[[InvalidKind]]";
|
||||
}
|
||||
|
||||
@@ -622,8 +622,11 @@ nonstd::optional<Kind> KindFromString(const std::string &str) {
|
||||
} else if (str == "sceneLibrary") {
|
||||
// https://developer.apple.com/documentation/arkit/usdz_schemas_for_ar/scenelibrary
|
||||
return Kind::SceneLibrary;
|
||||
} else if (str.empty()) {
|
||||
return nonstd::nullopt;
|
||||
} else {
|
||||
return Kind::UserDef;
|
||||
}
|
||||
return nonstd::nullopt;
|
||||
}
|
||||
|
||||
bool ValidatePrimElementName(const std::string &name) {
|
||||
@@ -1313,6 +1316,7 @@ const PrimMeta &Prim::metas() const {
|
||||
return EmptyStaticMeta::GetEmptyStaticMeta();
|
||||
}
|
||||
|
||||
|
||||
bool SetCustomDataByKey(const std::string &key, const MetaVariable &var,
|
||||
CustomDataType &custom) {
|
||||
// split by namespace
|
||||
@@ -1581,6 +1585,19 @@ AssetInfo PrimMeta::get_assetInfo(bool *is_authored) const {
|
||||
return ainfo;
|
||||
}
|
||||
|
||||
const std::string PrimMeta::get_kind() const {
|
||||
|
||||
if (kind.has_value()) {
|
||||
if (kind.value() == Kind::UserDef) {
|
||||
return _kind_str;
|
||||
} else {
|
||||
return to_string(kind.value());
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
bool IsXformablePrim(const Prim &prim) {
|
||||
uint32_t tyid = prim.type_id();
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ enum class Purpose {
|
||||
// USDZ extension: sceneLibrary
|
||||
// https://developer.apple.com/documentation/arkit/usdz_schemas_for_ar/scenelibrary
|
||||
//
|
||||
|
||||
enum class Kind {
|
||||
Model,
|
||||
Group,
|
||||
@@ -97,6 +98,7 @@ enum class Kind {
|
||||
Component,
|
||||
Subcomponent,
|
||||
SceneLibrary, // USDZ extension
|
||||
UserDef, // Unknown or user defined Kind
|
||||
Invalid
|
||||
};
|
||||
|
||||
@@ -791,7 +793,9 @@ struct Payload {
|
||||
struct PrimMetas {
|
||||
nonstd::optional<bool> active; // 'active'
|
||||
nonstd::optional<bool> hidden; // 'hidden'
|
||||
nonstd::optional<Kind> kind; // 'kind'
|
||||
nonstd::optional<Kind> kind; // 'kind'. user-defined kind value is stored in _kind_str;
|
||||
std::string _kind_str;
|
||||
|
||||
nonstd::optional<Dictionary>
|
||||
assetInfo; // 'assetInfo' // TODO: Use AssetInfo?
|
||||
nonstd::optional<Dictionary> customData; // `customData`
|
||||
@@ -804,6 +808,10 @@ struct PrimMetas {
|
||||
|
||||
nonstd::optional<bool> instanceable; // 'instanceable'
|
||||
|
||||
// String representation of Kind.
|
||||
// For user-defined Kind, it returns `_kind_str`
|
||||
const std::string get_kind() const;
|
||||
|
||||
//
|
||||
// AssetInfo utility function
|
||||
//
|
||||
|
||||
@@ -942,7 +942,10 @@ class USDAReader::Impl {
|
||||
// USDZ specific: https://developer.apple.com/documentation/arkit/usdz_schemas_for_ar/scenelibrary
|
||||
out->kind = Kind::SceneLibrary;
|
||||
} else {
|
||||
PUSH_ERROR_AND_RETURN("Invalid token for `kind` metadataum.");
|
||||
// NOTE: empty token allowed.
|
||||
|
||||
out->kind = Kind::UserDef;
|
||||
out->_kind_str = tok.str();
|
||||
}
|
||||
DCOUT("Added kind: " << to_string(out->kind.value()));
|
||||
} else {
|
||||
|
||||
@@ -1825,13 +1825,26 @@ bool USDCReader::Impl::ParsePrimSpec(const crate::FieldValuePairVector &fvs,
|
||||
}
|
||||
} else if (fv.first == "kind") {
|
||||
if (auto pv = fv.second.as<value::token>()) {
|
||||
if (auto kv = KindFromString(pv->str())) {
|
||||
primMeta.kind = kv.value();
|
||||
} else {
|
||||
PUSH_ERROR_AND_RETURN_TAG(
|
||||
kTag, fmt::format("Invalid token for `kind` Prim metadata: `{}`",
|
||||
pv->str()));
|
||||
}
|
||||
|
||||
const value::token tok = (*pv);
|
||||
if (tok.str() == "subcomponent") {
|
||||
primMeta.kind = Kind::Subcomponent;
|
||||
} else if (tok.str() == "component") {
|
||||
primMeta.kind = Kind::Component;
|
||||
} else if (tok.str() == "model") {
|
||||
primMeta.kind = Kind::Model;
|
||||
} else if (tok.str() == "group") {
|
||||
primMeta.kind = Kind::Group;
|
||||
} else if (tok.str() == "assembly") {
|
||||
primMeta.kind = Kind::Assembly;
|
||||
} else if (tok.str() == "sceneLibrary") {
|
||||
// USDZ specific: https://developer.apple.com/documentation/arkit/usdz_schemas_for_ar/scenelibrary
|
||||
primMeta.kind = Kind::SceneLibrary;
|
||||
} else {
|
||||
|
||||
primMeta.kind = Kind::UserDef;
|
||||
primMeta._kind_str = tok.str();
|
||||
}
|
||||
} else {
|
||||
PUSH_ERROR_AND_RETURN_TAG(kTag,
|
||||
"`kind` must be type `token`, but got type `"
|
||||
|
||||
6
tests/usda/user-def-kind-001.usda
Normal file
6
tests/usda/user-def-kind-001.usda
Normal file
@@ -0,0 +1,6 @@
|
||||
#usda 1.0
|
||||
|
||||
def "bora" (
|
||||
kind = "muda"
|
||||
) {
|
||||
}
|
||||
BIN
tests/usdc/user-def-kind-001.usdc
Normal file
BIN
tests/usdc/user-def-kind-001.usdc
Normal file
Binary file not shown.
Reference in New Issue
Block a user