tinyusdz icon indicating copy to clipboard operation
tinyusdz copied to clipboard

API design improvement for RenderSceneConverter::ConvertMesh

Open MootoolsSoftware opened this issue 1 year ago • 3 comments

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);

MootoolsSoftware avatar Jan 10 '24 09:01 MootoolsSoftware

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...

syoyo avatar Jan 10 '24 13:01 syoyo

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

syoyo avatar Apr 15 '24 22:04 syoyo

Please take a look at rendermesh-refactor branch.

Now 'rendermesh-refactor' branch is merged into 'dev'.

syoyo avatar May 11 '24 22:05 syoyo

API has been changed. Reopen the issue if you found improvements for current API design.

syoyo avatar Jun 27 '24 20:06 syoyo