From 7949cc27a4ce9c41f51b3a831d0a86aa1e8b6b89 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sat, 18 Nov 2023 23:36:34 +0900 Subject: [PATCH] Refactor GPrim Prim reconstruct. --- src/prim-reconstruct.cc | 11 +++-- src/usdGeom.hh | 6 +++ src/usdShade.hh | 41 ++++++++++-------- src/usda-reader.cc | 96 +++-------------------------------------- src/value-types.hh | 1 + 5 files changed, 43 insertions(+), 112 deletions(-) diff --git a/src/prim-reconstruct.cc b/src/prim-reconstruct.cc index 8b58d824a..4508291e7 100644 --- a/src/prim-reconstruct.cc +++ b/src/prim-reconstruct.cc @@ -2394,25 +2394,28 @@ bool ReconstructPrim( 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 table; + if (!ReconstructGPrimProperties(spec, table, properties, gprim, warn, err, options.strict_allowedToken_check)) { + return false; + } return true; } -#endif template <> bool ReconstructPrim( diff --git a/src/usdGeom.hh b/src/usdGeom.hh index 7fa99a923..70bb30221 100644 --- a/src/usdGeom.hh +++ b/src/usdGeom.hh @@ -456,6 +456,12 @@ struct GeomSubset { return _propertyNames; } + static bool ValidateSubsets( + const std::vector &subsets, + const size_t elementCount, + const FamilyType &familyType, std::string *err); + + private: std::vector _primChildrenNames; std::vector _propertyNames; diff --git a/src/usdShade.hh b/src/usdShade.hh index 8db801adf..c5303467a 100644 --- a/src/usdShade.hh +++ b/src/usdShade.hh @@ -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"; @@ -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; } @@ -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 diff --git a/src/usda-reader.cc b/src/usda-reader.cc index dcc900d28..c80c99e8f 100644 --- a/src/usda-reader.cc +++ b/src/usda-reader.cc @@ -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); @@ -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 @@ -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); @@ -1498,100 +1501,10 @@ bool USDAReader::Impl::ReconstructPrim( return true; } +#if 0 /// /// -- RegisterReconstructCallback specializations /// -#if 0 -template <> -bool USDAReader::Impl::RegisterReconstructCallback() { - // TODO: Move to ReconstructPrim - _parser.RegisterPrimConstructFunction( - PrimTypeTraits::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() { - _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 { - 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( @@ -1624,6 +1537,7 @@ bool USDAReader::Impl::ReconstructPrim( return true; } +#endif // Generic Prim handler. T = Xform, GeomMesh, ... template diff --git a/src/value-types.hh b/src/value-types.hh index a160cd1a5..9e350c509 100644 --- a/src/value-types.hh +++ b/src/value-types.hh @@ -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