Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty (gray) png results #4

Open
ben-mkiv opened this issue Apr 2, 2021 · 5 comments
Open

empty (gray) png results #4

ben-mkiv opened this issue Apr 2, 2021 · 5 comments

Comments

@ben-mkiv
Copy link

ben-mkiv commented Apr 2, 2021

Hi, for some reason my results are all 0 weighted (rgb values of 127.5)

any idea what this could be related to?

my script:

#!/bin/sh
DAZ_PATH="/home/daz/Documents/My DAZ 3D Library"
EXP="$DAZ_PATH/data/DAZ 3D/Genesis 8/Female/Morphs/DAZ 3D/Angharad 8"

./dhdm morphs-to-displacement \
displacement \
"$DAZ_PATH/data/DAZ 3D/Genesis 8/Female/Genesis8Female.dsf" \
"$DAZ_PATH/data/DAZ 3D/Genesis 8/Female/UV Sets/DAZ 3D/Base/Base Female.dsf" \
"$EXP/FHMAngharad8.dsf" \
"$EXP/FBMAngharad8.dsf"

output:

Read /home/daz/Documents/My DAZ 3D Library/data/DAZ 3D/Genesis 8/Female/Genesis8Female.dsf: 16556 vertices, 16368 faces, 18332 UVs
Applying morph '/home/daz/Documents/My DAZ 3D Library/data/DAZ 3D/Genesis 8/Female/Morphs/DAZ 3D/Angharad 8/FHMAngharad8.dsf'...
Applying morph '/home/daz/Documents/My DAZ 3D Library/data/DAZ 3D/Genesis 8/Female/Morphs/DAZ 3D/Angharad 8/FBMAngharad8.dsf'...
Subdividing to level 1...
Subdividing to level 1...
Triangulating...
Maximum displacement: 550947.2523814116
Most positive pixel component value: 140491676.85725996
Most negative pixel component value: -140091114.34485516
Rendering tile 0...
Rendering tile 1...
Rendering tile 2...
Rendering tile 3...
Rendering tile 4...
Rendering tile 5...
Rendering tile 6...
Waiting...
Writing 'displacement-0.png'...
Writing 'displacement-1.png'...
Writing 'displacement-3.png'...
Writing 'displacement-2.png'...
Writing 'displacement-4.png'...
Writing 'displacement-5.png'...
Writing 'displacement-6.png'...

on a sidenote, my compiler was complaining about the two abs() calls returning int values in diff.cc which was solved by replacing abs() with std::abs()

if (std::max(maxPos, abs(maxNeg)) > 1e-6) {

std::cerr << fmt::format("Maximum displacement: {}\n", std::max(maxDisplPos, abs(maxDisplNeg)));

@Xin-888
Copy link

Xin-888 commented Apr 2, 2021

I know what this could be. I faced a similar problem here: https://bitbucket.org/Diffeomorphic/import_daz/issues/357/it-is-possible-to-read-dhdm-files-directly (you can check the equivalent function there although that program has diverged quite a bit).

I forgot to open an issue here, but there is a small bug in the logic of the applyMorphs() function. Check the flow of it and you will notice that .dhdms extracted from .dsf files don't have their level considered, so the HD level is never detected:

dhdms.push_back({weight, Dhdm(*dhdm)});

The fix should be easy, just doing something like what is done in the other if branch (or better yet, doing it after the branches):

level = std::max(level, (unsigned int) dhdm.levels.size());

If the .dsf file you are trying to use (FBMAngharad8.dsf) doesn't have any HD information, then you are trying to bake base deformations in the textures, and the program isn't written with that in mind. In that case you will need to make more changes (again, you could check the version from the bitbucket link above).

Also, why are you using the same .dsf twice? that's the same as passing a strength of 2 (see edolstra's readme) which is weird and will give you a lot of scaling problems (scale is another thing you need to consider when dealing with large deformations like base morphs).


Also, just in case edolstra reads this, another issue I faced was that when using the program as a .dll, calling fclose() around here was necessary:

};

I think I'm not forgetting anything.

@ben-mkiv
Copy link
Author

ben-mkiv commented Apr 2, 2021

thanks for your quick reply Xin, actually i came here from your post on the diffeomorphic post

however, i've pretty much copied your code and that wasn't the root of my problem

thats my code now:

unsigned int applyMorphs(Mesh & mesh, size_t nrPaths, char * paths[])
{
    std::vector<std::pair<double, Dhdm>> dhdms;
    unsigned int level = 1;

    for (size_t i = 0; i < nrPaths; ++i) {
        std::string fn = paths[i];
        double weight = 1.0;
        auto c = fn.find('=');
        if (c != fn.npos) {
            weight = stod(fn.substr(c + 1));
            fn = std::string(fn, 0, c);
        }

        std::string dhdm_path = "";

        if (fn.size() >= 4 && std::string(fn, fn.size() - 4) == ".dsf") {
            if (auto dhdm_path_2 = mesh.applyMorph(weight, fn))
                dhdm_path = *dhdm_path_2;
        } 
        else {
			dhdm_path = fn;
		}
        
        if(dhdm_path.size() > 0){
            auto dhdm = Dhdm(dhdm_path);
            level = std::max(level, (unsigned int) dhdm.levels.size());
            dhdms.push_back({weight, std::move(dhdm)});
        }
    }

    mesh.subdivide(level, dhdms);

    return level;
}

If the .dsf file you are trying to use (FBMAngharad8.dsf) doesn't have any HD information, then you are trying to bake base
deformations in the textures, and the program isn't written with that in mind. In that case you will need to make more changes
(again, you could check the version from the bitbucket link above).

it's the Angharad8 with HD Addon, so there should be HD morphs in there?!

Also, why are you using the same .dsf twice? that's the same as passing a strength of 2 (see edolstra's readme) which is weird
and will give you a lot of scaling problems (scale is another thing you need to consider when dealing with large deformations like base morphs).

one is FHM (head) the other FBM (body)

maybe i'll wait a few days for your fork to finish and then i'll give it a try to make it a command line tool again ;)

also another question about your fork: where is the normal baking done? In the dhdm parser or in blender?

@Xin-888
Copy link

Xin-888 commented Apr 2, 2021

Unless I'm misunderstanding what you are trying to do, the "Angharad 8" file you are using I believe is the base mesh morph, that's why you are getting those large scaling issues:

Maximum displacement: 550947.2523814116
Most positive pixel component value: 140491676.85725996
Most negative pixel component value: -140091114.34485516

You want to use the morph files for the HD details (.dhdm files).

If you really want to bake base deformations in the textures, you need to change the scaling to accommodate such large deformations (or you could try including EXR support from from the bitbucket version, which doesn't have scaling limits). Look into changing the first parameter here:

auto diff = MeshDiff::create(1.0, baseMesh, {{1.0, std::move(finalMesh)}});

And then make sure that the console output stays between 0.0 and 255.0 instead of these very large values:

Most positive pixel component value: 140491676.85725996
Most negative pixel component value: -140091114.34485516

Ok, just read your edit. Then yes, your problem seems to be that you are passing the wrong .dsf file. You want to pass .dhdm files. You can find those in the same directory I believe. It's likely there will be a .dhdm for the head and one for the body.

@ben-mkiv
Copy link
Author

ben-mkiv commented Apr 2, 2021

thank you, you are correct those files didn't refer to the HD Morphs, i'm now getting visible results with FBMAngharad8HD_div4.dsf as input file, however stuff like Head/PHMCrowsFeetHDL.dsf still result in gray output

Maximum displacement: 1.0413897439175781e+108
Most positive pixel component value: 2.6555438469898242e+110
Most negative pixel component value: -2.655543756651406e+110

edit: my actual goal is to get displacement/normal maps from the morphs for use outside of blender, maybe my whole approach with this tool is wrong and i should go with your blender solution (which sadly is only available for windows at the moment of writing)

@Xin-888
Copy link

Xin-888 commented Apr 2, 2021

I don't know what that dsf file contains, but as a tip, you can check the .dhdm file associated with a .dsf file by opening the .dsf file with a text editor (you might need to gzip decompress the file first) and searching for the following keyword: "hd_url". It will point to the .dhdm file. You should be using that one to avoid scaling issues.


The normals baking depends on Blender. But since you are already compiling the program, you shouldn't need to do much to compile it for linux. Just look into creating a shared library instead of a dll and changing a few things if necessary on the python handling of the dll.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants