Unexpected png renders
Hi @edolstra,
Thanks for this great utility, I'm trying to debug it now but everything seems to work except the render to png (Applied morphs obj look like they should):

Do you have a clue?
I'm on macOS with:
- OpenSubdiv 3.4.4
- libPNG 1.4.12
- ZLib 1.2.11
- Boost 1.75.0
- GLEW 2.2.0
And this is the working version (same inputs) with morphs-to-obj

That's very likely a failure to zero-initialize glm vectors (see #2). You can either hard code the zero-initialization, or set the flag GLM_FORCE_CTOR_INIT.
As a side note, I have been expanding this program here (for windows but compiled with MinGW so it only requires tiny changes for other platforms): https://bitbucket.org/Diffeomorphic/import_daz/issues/357/it-is-possible-to-read-dhdm-files-directly . It's still not well organized since I was trying different things, but feel free to take stuff from there too, like EXR support, support for base meshes with triangles (like genesis 2 ones), auto-scaling option, interfacing with Blender directly, etc.
That's very likely a failure to zero-initialize glm vectors (see #2). You can either hard code the zero-initialization, or set the flag GLM_FORCE_CTOR_INIT.
As a side note, I have been expanding this program here (for windows but compiled with MinGW so it only requires tiny changes for other platforms): https://bitbucket.org/Diffeomorphic/import_daz/issues/357/it-is-possible-to-read-dhdm-files-directly . It's still not well organized since I was trying different things, but feel free to take stuff from there too, like EXR support, support for base meshes with triangles (like genesis 2 ones), auto-scaling option, interfacing with Blender directly, etc.
Thanks a lot, I'm trying those right now! I'll definitely check your fork! I see you are adapting it to blender, I'm trying to adapt it to Unity (EXR is on my todo list so that's interesting), I'm reworking the official DAZ addon, and until recently tried to keep it PRable (https://github.com/melMass/DazToUnity), I'm now completely diverging from it as the codebase is full of dead functions, half done stuff etc etc... The idea would be to integrate dhdm in the process, automating most of it!
set the flag GLM_FORCE_CTOR_INIT.
Thanks !! that was it. In CMake:
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGLM_FORCE_CTOR_INIT")

@Xin-888 I'm trying to implement your modifications, can you explain the code required to generate the meshdiff in your version?
Here is what I've tried but it returns black exrs:
...
auto baseMesh = Mesh::fromDSF(baseMeshPath, uvMapPath);
std::string baseObj = "displacement_base.obj";
baseMesh.writeObj(baseObj); // I'm using a second function with the same name to save to file
auto finalMesh = baseMesh;
auto level = finalMesh.applyMorphs(morphPaths);
baseMesh.subdivide(level, {}, -1);
fmt::print(fg(fmt::color::green_yellow), "Triangulating...");
baseMesh.triangulate();
finalMesh.triangulate();
const char* baseName = "myBaseName";
MeshDiff::renderContextInit('X', 4096); // use 'P' for png
MeshDiff diff('T', baseMesh, finalMesh ,baseName,true ,1.0,0.5,1.0);
const std::set<unsigned short> selectedTiles {1001,1002,1003,1004,1005,1006};
std::vector<std::future<void>> asyncs;
diff.writeToImage("out",selectedTiles,asyncs);
MeshDiff::renderContextFinish();
std::cout << "Async Waiting...\n";
for (auto & async : asyncs)
async.get();
Small note:
const std::string outFilePrefix( fmt::format("{}\\{}", outputDirpath, texture_prefix));
Should be (to be cross platform):
const std::string outFilePrefix( fmt::format("{}/{}", outputDirpath, texture_prefix) );
Yay !! Dumb me, they are 32bits.
but aren't they a bit too crunched?

I have to double check, but it's skipping tiles:

Tiles are still being filtered out if the maximum displacement in that tile is small (just like the version here does). The tile set filtering added later is done after that to exclude tiles which have non-negligible displacement but which you don't care about.
Also, thanks for that slashes thing, I will change that.
Thanks I did not know about this optimization very useful!