Skip to content

Commit

Permalink
Support loading older USD(v0.4.0 Moana island).
Browse files Browse the repository at this point in the history
[USDC] Increase maxInts limit to support loading USD file with large int arrays.
  • Loading branch information
syoyo committed Sep 25, 2023
1 parent 492e4d6 commit b5e27fe
Show file tree
Hide file tree
Showing 6 changed files with 601 additions and 292 deletions.
201 changes: 101 additions & 100 deletions src/crate-format.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,106 @@ constexpr char kTokenVector[] = "TokenVector";
constexpr char kStringVector[] = "StringVector";
constexpr char kPathVector[] = "PathVector";

// crate data type
// id must be identitical to <pxrUSD>/pxr/usd/usd/crateDataType.h
enum class CrateDataTypeId {
CRATE_DATA_TYPE_INVALID = 0,

CRATE_DATA_TYPE_BOOL = 1,
CRATE_DATA_TYPE_UCHAR = 2,
CRATE_DATA_TYPE_INT = 3,
CRATE_DATA_TYPE_UINT = 4,
CRATE_DATA_TYPE_INT64 = 5,
CRATE_DATA_TYPE_UINT64 = 6,

CRATE_DATA_TYPE_HALF = 7,
CRATE_DATA_TYPE_FLOAT = 8,
CRATE_DATA_TYPE_DOUBLE = 9,

CRATE_DATA_TYPE_STRING = 10,
CRATE_DATA_TYPE_TOKEN = 11,
CRATE_DATA_TYPE_ASSET_PATH = 12,

CRATE_DATA_TYPE_MATRIX2D = 13,
CRATE_DATA_TYPE_MATRIX3D = 14,
CRATE_DATA_TYPE_MATRIX4D = 15,

CRATE_DATA_TYPE_QUATD = 16,
CRATE_DATA_TYPE_QUATF = 17,
CRATE_DATA_TYPE_QUATH = 18,

CRATE_DATA_TYPE_VEC2D = 19,
CRATE_DATA_TYPE_VEC2F = 20,
CRATE_DATA_TYPE_VEC2H = 21,
CRATE_DATA_TYPE_VEC2I = 22,

CRATE_DATA_TYPE_VEC3D = 23,
CRATE_DATA_TYPE_VEC3F = 24,
CRATE_DATA_TYPE_VEC3H = 25,
CRATE_DATA_TYPE_VEC3I = 26,

CRATE_DATA_TYPE_VEC4D = 27,
CRATE_DATA_TYPE_VEC4F = 28,
CRATE_DATA_TYPE_VEC4H = 29,
CRATE_DATA_TYPE_VEC4I = 30,

CRATE_DATA_TYPE_DICTIONARY = 31,
CRATE_DATA_TYPE_TOKEN_LIST_OP = 32,
CRATE_DATA_TYPE_STRING_LIST_OP = 33,
CRATE_DATA_TYPE_PATH_LIST_OP = 34,
CRATE_DATA_TYPE_REFERENCE_LIST_OP = 35,
CRATE_DATA_TYPE_INT_LIST_OP = 36,
CRATE_DATA_TYPE_INT64_LIST_OP = 37,
CRATE_DATA_TYPE_UINT_LIST_OP = 38,
CRATE_DATA_TYPE_UINT64_LIST_OP = 39,

CRATE_DATA_TYPE_PATH_VECTOR = 40,
CRATE_DATA_TYPE_TOKEN_VECTOR = 41,

CRATE_DATA_TYPE_SPECIFIER = 42,
CRATE_DATA_TYPE_PERMISSION = 43,
CRATE_DATA_TYPE_VARIABILITY = 44,

CRATE_DATA_TYPE_VARIANT_SELECTION_MAP = 45,
CRATE_DATA_TYPE_TIME_SAMPLES = 46,
CRATE_DATA_TYPE_PAYLOAD = 47,
CRATE_DATA_TYPE_DOUBLE_VECTOR = 48,
CRATE_DATA_TYPE_LAYER_OFFSET_VECTOR = 49,
CRATE_DATA_TYPE_STRING_VECTOR = 50,
CRATE_DATA_TYPE_VALUE_BLOCK = 51,
CRATE_DATA_TYPE_VALUE = 52, // Contains ValueRep
CRATE_DATA_TYPE_UNREGISTERED_VALUE = 53, // String or Dict
CRATE_DATA_TYPE_UNREGISTERED_VALUE_LIST_OP = 54,
CRATE_DATA_TYPE_PAYLOAD_LIST_OP = 55,
CRATE_DATA_TYPE_TIME_CODE = 56,

NumDataTypes // terminator
};

class CrateDataType
{
public:
CrateDataType() = default;

CrateDataType(const char *s, CrateDataTypeId did, bool a)
: name(s), dtype_id(did), supports_array(a) {
}

CrateDataType(const CrateDataType &rhs) = default;
CrateDataType &operator=(const CrateDataType&rhs) = default;

const char *name{nullptr}; // name of CrateDatatType. Constant symbol. TODO: Use string_view.
CrateDataTypeId dtype_id{CrateDataTypeId::CRATE_DATA_TYPE_INVALID};
bool supports_array{false};
};

std::string GetCrateDataTypeRepr(CrateDataType dty); // for debug cout

nonstd::expected<CrateDataType, std::string> GetCrateDataType(int32_t type_id);
std::string GetCrateDataTypeName(int32_t type_id);
std::string GetCrateDataTypeName(CrateDataTypeId type_id);



// -- from USD ----------------------------------------------------------------

Expand Down Expand Up @@ -131,7 +231,7 @@ struct ValueRep {

std::string GetStringRepr() const {
std::stringstream ss;
ss << "ty: " << static_cast<int>(GetType()) << ", isArray: " << IsArray()
ss << "ty: " << static_cast<int>(GetType()) << "(" << GetCrateDataTypeName(GetType()) << "), isArray: " << IsArray()
<< ", isInlined: " << IsInlined() << ", isCompressed: " << IsCompressed()
<< ", payload: " << GetPayload();

Expand Down Expand Up @@ -277,105 +377,6 @@ struct TableOfContents {
std::vector<Section> sections;
};

// crate data type
// id must be identitical to <pxrUSD>/pxr/usd/usd/crateDataType.h
enum class CrateDataTypeId {
CRATE_DATA_TYPE_INVALID = 0,

CRATE_DATA_TYPE_BOOL = 1,
CRATE_DATA_TYPE_UCHAR = 2,
CRATE_DATA_TYPE_INT = 3,
CRATE_DATA_TYPE_UINT = 4,
CRATE_DATA_TYPE_INT64 = 5,
CRATE_DATA_TYPE_UINT64 = 6,

CRATE_DATA_TYPE_HALF = 7,
CRATE_DATA_TYPE_FLOAT = 8,
CRATE_DATA_TYPE_DOUBLE = 9,

CRATE_DATA_TYPE_STRING = 10,
CRATE_DATA_TYPE_TOKEN = 11,
CRATE_DATA_TYPE_ASSET_PATH = 12,

CRATE_DATA_TYPE_MATRIX2D = 13,
CRATE_DATA_TYPE_MATRIX3D = 14,
CRATE_DATA_TYPE_MATRIX4D = 15,

CRATE_DATA_TYPE_QUATD = 16,
CRATE_DATA_TYPE_QUATF = 17,
CRATE_DATA_TYPE_QUATH = 18,

CRATE_DATA_TYPE_VEC2D = 19,
CRATE_DATA_TYPE_VEC2F = 20,
CRATE_DATA_TYPE_VEC2H = 21,
CRATE_DATA_TYPE_VEC2I = 22,

CRATE_DATA_TYPE_VEC3D = 23,
CRATE_DATA_TYPE_VEC3F = 24,
CRATE_DATA_TYPE_VEC3H = 25,
CRATE_DATA_TYPE_VEC3I = 26,

CRATE_DATA_TYPE_VEC4D = 27,
CRATE_DATA_TYPE_VEC4F = 28,
CRATE_DATA_TYPE_VEC4H = 29,
CRATE_DATA_TYPE_VEC4I = 30,

CRATE_DATA_TYPE_DICTIONARY = 31,
CRATE_DATA_TYPE_TOKEN_LIST_OP = 32,
CRATE_DATA_TYPE_STRING_LIST_OP = 33,
CRATE_DATA_TYPE_PATH_LIST_OP = 34,
CRATE_DATA_TYPE_REFERENCE_LIST_OP = 35,
CRATE_DATA_TYPE_INT_LIST_OP = 36,
CRATE_DATA_TYPE_INT64_LIST_OP = 37,
CRATE_DATA_TYPE_UINT_LIST_OP = 38,
CRATE_DATA_TYPE_UINT64_LIST_OP = 39,

CRATE_DATA_TYPE_PATH_VECTOR = 40,
CRATE_DATA_TYPE_TOKEN_VECTOR = 41,

CRATE_DATA_TYPE_SPECIFIER = 42,
CRATE_DATA_TYPE_PERMISSION = 43,
CRATE_DATA_TYPE_VARIABILITY = 44,

CRATE_DATA_TYPE_VARIANT_SELECTION_MAP = 45,
CRATE_DATA_TYPE_TIME_SAMPLES = 46,
CRATE_DATA_TYPE_PAYLOAD = 47,
CRATE_DATA_TYPE_DOUBLE_VECTOR = 48,
CRATE_DATA_TYPE_LAYER_OFFSET_VECTOR = 49,
CRATE_DATA_TYPE_STRING_VECTOR = 50,
CRATE_DATA_TYPE_VALUE_BLOCK = 51,
CRATE_DATA_TYPE_VALUE = 52, // Contains ValueRep
CRATE_DATA_TYPE_UNREGISTERED_VALUE = 53, // String or Dict
CRATE_DATA_TYPE_UNREGISTERED_VALUE_LIST_OP = 54,
CRATE_DATA_TYPE_PAYLOAD_LIST_OP = 55,
CRATE_DATA_TYPE_TIME_CODE = 56,

NumDataTypes // terminator
};

class CrateDataType
{
public:
CrateDataType() = default;

CrateDataType(const char *s, CrateDataTypeId did, bool a)
: name(s), dtype_id(did), supports_array(a) {
}

CrateDataType(const CrateDataType &rhs) = default;
CrateDataType &operator=(const CrateDataType&rhs) = default;

const char *name{nullptr}; // name of CrateDatatType. Constant symbol. TODO: Use string_view.
CrateDataTypeId dtype_id{CrateDataTypeId::CRATE_DATA_TYPE_INVALID};
bool supports_array{false};
};

std::string GetCrateDataTypeRepr(CrateDataType dty); // for debug cout

nonstd::expected<CrateDataType, std::string> GetCrateDataType(int32_t type_id);
std::string GetCrateDataTypeName(int32_t type_id);
std::string GetCrateDataTypeName(CrateDataTypeId type_id);

// TODO: Use PrimVar?
class CrateValue {
public:
Expand Down
Loading

0 comments on commit b5e27fe

Please sign in to comment.