Skip to content

Commit

Permalink
Refactor GPrim Prim reconstruct.
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Nov 18, 2023
1 parent 03916f1 commit 7949cc2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 112 deletions.
11 changes: 7 additions & 4 deletions src/prim-reconstruct.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2394,25 +2394,28 @@ bool ReconstructPrim<BlendShape>(
return true;
}

#if 0
template <>
bool ReconstructPrim(
const Specifier &spec,
const PropertyMap &properties,
const ReferenceList &references,
GPrim *gprim,
std::string *warn,
std::string *err) {
std::string *err,
const PrimReconstructOptions &options) {
(void)gprim;
(void)err;

(void)references;
(void)properties;

PUSH_WARN("TODO: GPrim");
std::set<std::string> table;
if (!ReconstructGPrimProperties(spec, table, properties, gprim, warn, err, options.strict_allowedToken_check)) {
return false;
}

return true;
}
#endif

template <>
bool ReconstructPrim(
Expand Down
6 changes: 6 additions & 0 deletions src/usdGeom.hh
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,12 @@ struct GeomSubset {
return _propertyNames;
}

static bool ValidateSubsets(
const std::vector<const GeomSubset *> &subsets,
const size_t elementCount,
const FamilyType &familyType, std::string *err);


private:
std::vector<value::token> _primChildrenNames;
std::vector<value::token> _propertyNames;
Expand Down
41 changes: 24 additions & 17 deletions src/usdShade.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace tinyusdz {

constexpr auto kMaterial = "Material";
constexpr auto kShader = "Shader";
constexpr auto kNodeGraph = "NodeGraph";
constexpr auto kShaderNode = "ShaderNode";

constexpr auto kShaderInfoId = "info:id";

Expand Down Expand Up @@ -47,7 +49,7 @@ struct UsdShadePrim {
int64_t parent_id{-1};

PrimMeta meta; // TODO: move to private

const PrimMeta &metas() const { return meta; }
PrimMeta &metas() { return meta; }

Expand Down Expand Up @@ -279,40 +281,45 @@ struct Shader : UsdShadePrim {
namespace value {

// Mateiral Prim
DEFINE_TYPE_TRAIT(Material, "Material",
DEFINE_TYPE_TRAIT(Material, kMaterial,
TYPE_ID_MATERIAL, 1);

// Shader Prim
DEFINE_TYPE_TRAIT(Shader, "Shader",
DEFINE_TYPE_TRAIT(Shader, kShader,
TYPE_ID_SHADER, 1);

// NodeGraph Prim
DEFINE_TYPE_TRAIT(NodeGraph, kNodeGraph,
TYPE_ID_NODEGRAPH, 1);


// ShaderNodes
DEFINE_TYPE_TRAIT(ShaderNode, "ShaderNode",
DEFINE_TYPE_TRAIT(ShaderNode, kShaderNode,
TYPE_ID_IMAGING_SHADER_NODE, 1);
DEFINE_TYPE_TRAIT(UsdPreviewSurface, "UsdPreviewSurface",
DEFINE_TYPE_TRAIT(UsdPreviewSurface, kUsdPreviewSurface,
TYPE_ID_IMAGING_PREVIEWSURFACE, 1);
DEFINE_TYPE_TRAIT(UsdUVTexture, "UsdUVTexture", TYPE_ID_IMAGING_UVTEXTURE, 1);
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float, "UsdPrimvarReader_float",
DEFINE_TYPE_TRAIT(UsdUVTexture, kUsdUVTexture, TYPE_ID_IMAGING_UVTEXTURE, 1);
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float, kUsdPrimvarReader_float,
TYPE_ID_IMAGING_PRIMVAR_READER_FLOAT, 1);
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float2, "UsdPrimvarReader_float2",
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float2, kUsdPrimvarReader_float2,
TYPE_ID_IMAGING_PRIMVAR_READER_FLOAT2, 1);
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float3, "UsdPrimvarReader_float3",
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float3, kUsdPrimvarReader_float3,
TYPE_ID_IMAGING_PRIMVAR_READER_FLOAT3, 1);
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float4, "UsdPrimvarReader_float4",
DEFINE_TYPE_TRAIT(UsdPrimvarReader_float4, kUsdPrimvarReader_float4,
TYPE_ID_IMAGING_PRIMVAR_READER_FLOAT4, 1);
DEFINE_TYPE_TRAIT(UsdPrimvarReader_int, "UsdPrimvarReader_int",
DEFINE_TYPE_TRAIT(UsdPrimvarReader_int, kUsdPrimvarReader_int,
TYPE_ID_IMAGING_PRIMVAR_READER_INT, 1);
DEFINE_TYPE_TRAIT(UsdPrimvarReader_string, "UsdPrimvarReader_string",
DEFINE_TYPE_TRAIT(UsdPrimvarReader_string, kUsdPrimvarReader_string,
TYPE_ID_IMAGING_PRIMVAR_READER_STRING, 1);
DEFINE_TYPE_TRAIT(UsdPrimvarReader_vector, "UsdPrimvarReader_vector",
DEFINE_TYPE_TRAIT(UsdPrimvarReader_vector, kUsdPrimvarReader_vector,
TYPE_ID_IMAGING_PRIMVAR_READER_VECTOR, 1);
DEFINE_TYPE_TRAIT(UsdPrimvarReader_normal, "UsdPrimvarReader_normal",
DEFINE_TYPE_TRAIT(UsdPrimvarReader_normal, kUsdPrimvarReader_normal,
TYPE_ID_IMAGING_PRIMVAR_READER_NORMAL, 1);
DEFINE_TYPE_TRAIT(UsdPrimvarReader_point, "UsdPrimvarReader_point",
DEFINE_TYPE_TRAIT(UsdPrimvarReader_point, kUsdPrimvarReader_point,
TYPE_ID_IMAGING_PRIMVAR_READER_POINT, 1);
DEFINE_TYPE_TRAIT(UsdPrimvarReader_matrix, "UsdPrimvarReader_matrix",
DEFINE_TYPE_TRAIT(UsdPrimvarReader_matrix, kUsdPrimvarReader_matrix,
TYPE_ID_IMAGING_PRIMVAR_READER_MATRIX, 1);
DEFINE_TYPE_TRAIT(UsdTransform2d, "UsdTransform2d",
DEFINE_TYPE_TRAIT(UsdTransform2d, kUsdTransform2d,
TYPE_ID_IMAGING_TRANSFORM_2D, 1);

#undef DEFINE_TYPE_TRAIT
Expand Down
96 changes: 5 additions & 91 deletions src/usda-reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ RECONSTRUCT_PRIM_DECL(SphereLight);
RECONSTRUCT_PRIM_DECL(CylinderLight);
RECONSTRUCT_PRIM_DECL(DiskLight);
RECONSTRUCT_PRIM_DECL(DistantLight);
RECONSTRUCT_PRIM_DECL(GPrim);
RECONSTRUCT_PRIM_DECL(GeomMesh);
RECONSTRUCT_PRIM_DECL(GeomSubset);
RECONSTRUCT_PRIM_DECL(GeomSphere);
Expand All @@ -109,6 +110,7 @@ RECONSTRUCT_PRIM_DECL(GeomCamera);
RECONSTRUCT_PRIM_DECL(PointInstancer);
RECONSTRUCT_PRIM_DECL(Material);
RECONSTRUCT_PRIM_DECL(Shader);
RECONSTRUCT_PRIM_DECL(NodeGraph);

#undef RECONSTRUCT_PRIM_DECL

Expand Down Expand Up @@ -190,6 +192,7 @@ DEFINE_PRIM_TYPE(DistantLight, kDistantLight, value::TYPE_ID_LUX_DISTANT);
DEFINE_PRIM_TYPE(CylinderLight, kCylinderLight, value::TYPE_ID_LUX_CYLINDER);
DEFINE_PRIM_TYPE(Material, kMaterial, value::TYPE_ID_MATERIAL);
DEFINE_PRIM_TYPE(Shader, kShader, value::TYPE_ID_SHADER);
DEFINE_PRIM_TYPE(NodeGraph, kNodeGraph, value::TYPE_ID_NODEGRAPH);
DEFINE_PRIM_TYPE(SkelRoot, kSkelRoot, value::TYPE_ID_SKEL_ROOT);
DEFINE_PRIM_TYPE(Skeleton, kSkeleton, value::TYPE_ID_SKELETON);
DEFINE_PRIM_TYPE(SkelAnimation, kSkelAnimation, value::TYPE_ID_SKELANIMATION);
Expand Down Expand Up @@ -1498,100 +1501,10 @@ bool USDAReader::Impl::ReconstructPrim(
return true;
}

#if 0
///
/// -- RegisterReconstructCallback specializations
///
#if 0
template <>
bool USDAReader::Impl::RegisterReconstructCallback<GPrim>() {
// TODO: Move to ReconstructPrim
_parser.RegisterPrimConstructFunction(
PrimTypeTraits<GPrim>::prim_type_name,
[&](const Path &path, const PropertyMap &properties,
ReferenceList &references) {
// TODO: Implement
GPrim gprim;

//
// Resolve prepend references
//
for (const auto &ref : references) {
if (std::get<0>(ref) == tinyusdz::ListEditQual::Prepend) {
}
}

// Update props;
for (auto item : properties) {
if (item.second.is_relationship()) {
PUSH_WARN("TODO: rel");
} else {
gprim.props[item.first].attrib = item.second.get_attribute();
}
}

//
// Resolve append references
//
for (const auto &ref : references) {
if (std::get<0>(ref) == tinyusdz::ListEditQual::Prepend) {
}
}

return true;
});

return true;
}
#endif

#if 0
template <>
bool USDAReader::Impl::RegisterReconstructCallback<GeomSubset>() {
_parser.RegisterPrimConstructFunction(
"GeomSubset",
[&](const Path &full_path, const Specifier spec, const std::string &primTypeName, const Path &prim_name, const int64_t primIdx,
const int64_t parentPrimIdx,
const prim::PropertyMap &properties,
//const prim::ReferenceList &references,
const ascii::AsciiParser::PrimMetaMap &in_meta,
const ascii::AsciiParser::VariantSetList &in_variantSetList)
-> nonstd::expected<bool, std::string> {
const Path &parent = full_path.get_parent_prim_path();
if (!parent.is_valid()) {
return nonstd::make_unexpected("Invalid Prim path.");
}

(void)primTypeName;


#if 0
if (parent.IsRootPrim()) {
return nonstd::make_unexpected(
"GeomSubset must be defined as a child of GeomMesh prim.");
}
#endif

if (parentPrimIdx < 0) {
return nonstd::make_unexpected(
"GeomSubset muet be defined as a child of GeomMesh.");
}

if (_prim_nodes.size() < size_t(parentPrimIdx)) {
return nonstd::make_unexpected(
"Unexpected parentPrimIdx for GeomSubset.");
}

PrimMeta meta;
if (!ReconstructPrimMeta(in_meta, &meta)) {
return nonstd::make_unexpected("Failed to process Prim metadataum.");
}

return true;
});

return true;
}
#endif

template <>
bool USDAReader::Impl::ReconstructPrim(
Expand Down Expand Up @@ -1624,6 +1537,7 @@ bool USDAReader::Impl::ReconstructPrim<NodeGraph>(

return true;
}
#endif

// Generic Prim handler. T = Xform, GeomMesh, ...
template <typename T>
Expand Down
1 change: 1 addition & 0 deletions src/value-types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ enum TypeId {
TYPE_ID_SHADER_BEGIN = 1 << 11,
TYPE_ID_SHADER,
TYPE_ID_MATERIAL,
TYPE_ID_NODEGRAPH,
TYPE_ID_SHADER_END,

// Types for usdImaging and usdMtlx
Expand Down

0 comments on commit 7949cc2

Please sign in to comment.