tinyusdz
tinyusdz copied to clipboard
API design improvement for RenderSceneConverter::ConvertMesh
Our usage of the library is the following, reading material and mesh in a step by step approach:
using MeshMap = std::map<std::string, const tinyusdz::GeomMesh*>;
MeshMap meshmap;
tinyusdz::tydra::ListPrims(stage, meshmap);
for (const auto& item : meshmap)
{
// FindBoundMaterial seaches bound material for parent GPrim.
tinyusdz::Path matPath;
const tinyusdz::Material* material{ nullptr };
std::string err;
bool ret = tinyusdz::tydra::FindBoundMaterial(stage, tinyusdz::Path(item.first, ""), "", &matPath, &material, &err);
if (ret)
{
if (material)
{
// Convert Material
tinyusdz::tydra::RenderMaterial rmat;
ret = converter.ConvertMaterial(matPath, *material, &rmat);
XASSERT(ret);
// Convert Mesh
tinyusdz::tydra::RenderMesh rmesh;
ret = converter.ConvertMesh(-1 / which index to use here ??? /, *item.second, &rmesh);
XASSERT(ret);
}
}
else
{
// Mesh without Material, is it possible ??
tinyusdz::tydra::RenderMesh rmesh;
ret = converter.ConvertMesh(-1, *item.second, &rmesh);
XASSERT(ret);
}
In the following approach the call to RenderSceneConverter::ConvertMesh is not possible as we don't have the material index need for the first parameter.
bool ConvertMesh(const int64_t rmaterial_d, const tinyusdz::GeomMesh &mesh, RenderMesh *dst);
Would it be possible to add a new version of ConvertMesh?
bool ConvertMesh(const RenderMaterial& rmaterial, const tinyusdz::GeomMesh &mesh, RenderMesh *dst);
As commented here
https://github.com/syoyo/tinyusdz/issues/109#issuecomment-1876952311
We need to consider per-face material binding with GeomSubset, so ConvertMesh API will be changed accordingly, and I'm working on RenderScene converter refactoring with GeomSubset and proper FindBindMaterial implementation(e.g. consider BindStrength) in mind. Stay tuned...
Finished refactoring of RenderScene converter.
Please take a look at rendermesh-refactor
branch. Now ConvertMesh takes material assignment infos.
Exampe of gathering Materials(including GeomSubset materials) bound to GeomMesh can be found at
https://github.com/syoyo/tinyusdz/blob/e86a0a5697f7070c0ed9cf577c54ef23172b463c/src/tydra/render-data.cc#L4786
Please take a look at rendermesh-refactor branch.
Now 'rendermesh-refactor' branch is merged into 'dev'.
API has been changed. Reopen the issue if you found improvements for current API design.