Skip to content

Commit

Permalink
Add some support of converting BlendShapes
Browse files Browse the repository at this point in the history
  • Loading branch information
syoyo committed Apr 17, 2024
1 parent 269901d commit 82f22b8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
32 changes: 30 additions & 2 deletions src/tydra/render-data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3448,7 +3448,7 @@ bool RenderSceneConverter::ConvertMesh(
//
if (mesh.has_primvar("skel:jointIndices") &&
mesh.has_primvar("skel:jointWeights")) {
DCOUT("Convertg skin weights");
DCOUT("Convert skin weights");
GeomPrimvar jointIndices;
GeomPrimvar jointWeights;

Expand Down Expand Up @@ -3678,6 +3678,7 @@ bool RenderSceneConverter::ConvertMesh(

// TODO: key duplicate check
dst.targets[bs->name] = shapeTarget;
DCOUT("Converted blendshape target: " << bs->name);
}

//
Expand Down Expand Up @@ -5063,8 +5064,18 @@ bool MeshVisitor(const tinyusdz::Path &abs_path, const tinyusdz::Prim &prim,
}
}

// TODO: BlendShapes
// BlendShapes
std::vector<std::pair<std::string, const BlendShape *>> blendshapes;
{
std::string local_err;
blendshapes = GetBlendShapes(visitorEnv->env->stage, prim, &local_err);
if (local_err.size()) {
if (err) {
(*err) += fmt::format("Failed to get BlendShapes prims. err = {}", local_err);
}
}
}
DCOUT("# of blendshapes : " << blendshapes.size());

RenderMesh rmesh;

Expand Down Expand Up @@ -6003,6 +6014,23 @@ std::string DumpMesh(const RenderMesh &mesh, uint32_t indent) {
<< "\n";
ss << pprint::Indent(indent + 1) << "}\n";
}
if (mesh.targets.size()) {
ss << pprint::Indent(indent + 1) << "shapeTargets {\n";

for (const auto &target : mesh.targets) {
ss << pprint::Indent(indent + 2) << target.first << " {\n";
ss << pprint::Indent(indent + 3) << "prim_name " << quote(target.second.prim_name) << "\n";
ss << pprint::Indent(indent + 3) << "abs_path " << quote(target.second.abs_path) << "\n";
ss << pprint::Indent(indent + 3) << "display_name " << quote(target.second.display_name) << "\n";
ss << pprint::Indent(indent + 3) << "pointIndices " << quote(value::print_array_snipped(target.second.pointIndices)) << "\n";
ss << pprint::Indent(indent + 3) << "pointOffsets " << quote(value::print_array_snipped(target.second.pointOffsets)) << "\n";
ss << pprint::Indent(indent + 3) << "normalOffsets " << quote(value::print_array_snipped(target.second.normalOffsets)) << "\n";
ss << pprint::Indent(indent + 2) << "}\n";
}

ss << pprint::Indent(indent + 1) << "}\n";

}
if (mesh.material_subsetMap.size()) {
ss << pprint::Indent(indent + 1) << "material_subsets {\n";
for (const auto &msubset : mesh.material_subsetMap) {
Expand Down
2 changes: 1 addition & 1 deletion src/tydra/scene-access.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,7 @@ bool IsPathIncluded(const CollectionMembershipQuery &query, const Stage &stage,
}

std::vector<std::pair<std::string, const tinyusdz::BlendShape *>>
GetBlenedShapes(
GetBlendShapes(
const tinyusdz::Stage &stage,
const tinyusdz::Prim &prim, std::string *err) {

Expand Down
2 changes: 1 addition & 1 deletion src/tydra/scene-access.hh
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ std::vector<const GeomSubset *> GetGeomSubsetChildren(
// (`skel:blendShapes`, `skel:blendShapeTargets`)
//
std::vector<std::pair<std::string, const tinyusdz::BlendShape *>>
GetBlenedShapes(const tinyusdz::Stage &stage, const tinyusdz::Prim &prim,
GetBlendShapes(const tinyusdz::Stage &stage, const tinyusdz::Prim &prim,
std::string *err = nullptr);

#if 0 // TODO
Expand Down

0 comments on commit 82f22b8

Please sign in to comment.