BabylonJS / Exporters

Exporters for Babylon.js and gltf file formats
Other
613 stars 313 forks source link

Support hair & fur export #51

Closed kutomer closed 6 years ago

kutomer commented 6 years ago

Hello :) I think it will be very useful if we will be able to export 3dsmax hair & fur modifer as Babylon.FurMaterial

in the meantime do we have any other way to export fur & hair from 3dsmax to Babylon.js?

Thanks!

deltakosh commented 6 years ago

This is a good idea. So far the only way would be to do it at load time in JS :(

kutomer commented 6 years ago

Thanks a lot for the quick reply! Do you think that it's something can be added to a backlog or something? Would love to help to develop this feature but guidance is needed.

deltakosh commented 6 years ago

Obviously :) You can perhaps familiarize yourself with the C# code of the exporter. Then we can discuss where in the json file we can export it (it is not a big deal as we can export all kind of materials)

kutomer commented 6 years ago

Do you have any documentation for the exporter which I can begin with?

deltakosh commented 6 years ago

I would say tags just loadibg the VS project should be a good start Project is pretty straightforward

kutomer commented 6 years ago

Thanks,

  1. I couldn't find a way to debug the plugin (read that I need to be a certified Autodesk developer), the way I'm doing it now is with RaiseMessage and for that, I need to rebuild and relaunch 3dsmax what makes the development process much slower.
  2. I guess I'm doing something wrong but meshMode.IGameObject.NumModifiers.ToString() returns 0 for me, have any idea?
noalak commented 6 years ago

Hi kutomer,

1) Doing the same 2) Hair and Fur modifier is a World Space Modifier. Don't really know much about it but find attached the code you are probably looking for. Add it to the BabylonExporter.Mesh.cs file, for example before morph targets code (line 360).

With that you get all parameters from Hair and Fur modifier. Seems like there is no interface provided by the API, so you need to retreive each parameter by id. You need to adapt the getter method (GetFloat, GetInt, GetColor...) to the parameter type of each parameter, otherwise it would return the default value (0 for a float).

Be aware that an object might have several WSMs. To retreive the Hair and Fur one you can check its name but this process is ugly and certainly language sensitive (i experimented this for materials' type). If you go for that, tag it with a TODO :)

kutomer commented 6 years ago

@noalak awesome, thanks, I'll do that.

  1. So is that fine if I'll support just English for now and add a TODO like: materialNode.MaterialClass.ToLower() == "physisches material" || // German // TODO - check if translation is ok (Exporter/BabylonExporter.Material.cs) (just wanna make sure you guys will approve my PR)

  2. After exporting all the data from the Modifier I want to create a new Material in the exported babylon filematerials array with customType FurMaterial (and all the material data)

  3. I saw that `BABYLON.Material.Parse' doesn't support FurMaterial is that right? if so I also need to modify it to support FurMaterials.

  4. I think a How to contribute section in the README can make life easier for future contributors. I can start writing something and you guys can modify, if you want...

something else I need to do or know?

noalak commented 6 years ago
  1. All right, i will check for language sensitiveness as soon as your PR is approved (got a French version)

2., 3. and 4. @deltakosh

Once feature is complete for both exporter and loader, add a sample max file and exported babylon outputs (beautified if possible). Be aware of diffusion rights though.

Any plan on fur animations? Doesn't even know if babylon supports them.

kutomer commented 6 years ago

@noalak thanks again,

No problem I'll add the examples. Not sure I got the time to do the loader right now, is that fine?

To be honest, I didn't plan on doing animations but I'll be happy to add them (Babylon does support animations and I will try to do it as accurate as possible. (demo))

deltakosh commented 6 years ago

Hey!

  1. The FurMaterial has its own serializer/parser already: https://github.com/BabylonJS/Babylon.js/blob/master/materialsLibrary/src/fur/babylon.furMaterial.ts#L428. Just use the same string for customType and it should work :) You may need to update the furMaterial class if you need more properties to be loaded
  2. It will automatically support FurMaterial if you define the right customType property (see below)
  3. Sure!
kutomer commented 6 years ago

@deltakosh thanks, I'll do that @noalak what do you say is that fine if I won't do the loader side for now?

noalak commented 6 years ago

You don't need to do anything loader side since it's already done as deltakosh said :) Export a fur object with your new exporter and try it out in the babylon sandbox. Should work right away!

kutomer commented 6 years ago

@noalak ok, I'll do that. I've meant loading .babylon files in 3dsmax (not sure that this is even possible)

deltakosh commented 6 years ago

It is not unfortunately

kutomer commented 6 years ago
  1. Because there is no separation between the root and the tip in Babylon I'm only using the root parameters, hope that's fine.
  2. Do you have any idea which parameter in 3dsmax represents the fur's angle in Babylon?
  3. How do I extract the diffuseColor from IColor obj? I have no GetDiffuse method like IGameMaterail, and even more importantly how do I extract the texture for the diffuseTexture?

    for (short paramId = 0; paramId < paramBlock.NumParams; paramId++)
    {
    var name = paramBlock.GetLocalName(paramId, 0);
    
    // TODO - check translation
    switch (name)
    {
        // Other paramters I extract
        case "Root Color":
            var color = paramBlock.GetColor(paramId, 0, 0);
            // here... how do I extract those paramaters from color obj?
            break;
    }
    }

Thanks again guys :)

noalak commented 6 years ago
  1. It's not an issue if 3ds max has more parameters than Babylon, just ignore them
  2. No idea. Will ask my graphic designer tomorrow about styling feature in max.
  3. Have you looked at GetMtl getter? Something like this maybe mtl.ActiveTexmap.GetSubTexmap(0); Anyway the diffuse color is just a color with rgb channels. By default, for me root color is a dark yellow. I don't understand the issue here.
kutomer commented 6 years ago
  1. thanks.
  2. thanks, I'll also try to find out.
  3. yes I have, but I have no idea from which paramBlock I can get the material (seems like no one according to the following code example)

    for (short paramId = 0; paramId < paramBlock.NumParams; paramId++)
    {
    var name = paramBlock.GetLocalName(paramId, 0);
    
    // TODO - check translation
    RaiseMessage("name = " + name);
    try
    {
        var a = paramBlock.GetMtl(paramId, 0, 0);
        RaiseMessage("working = " + name);
    } catch(Exception e) {}
    //...
    }

    unfortunately didn't print "working" at all :)

BTW sorry for all the questions, Autodesk documentation really sucks.

update: https://forums.autodesk.com/t5/3ds-max-programming/get-worldmodifier-material-3dsmax-2017/td-p/7678776

@noalak thanks :)

kutomer commented 6 years ago

@noalak any thoughts? :)

noalak commented 6 years ago

Sorry for late answer. In case you are still in trouble find attached the code to retreive the maps.

Maps has paramId = 51 MapsEnable has paramId = 52

Maps should always be enabled when they exist (not null) since there is no checkbox like in StandardMaterial. So it's not necessary to test for it.

Glad you got an answer for the color map ids :)

kutomer commented 6 years ago

Sorry for the delay. Anyways, I think I have only 1 bug left - the hair is exported according to the parameters but for some reason, there is a gap between the hairs and the mesh they suppose to be attached to.

screen shot 2018-02-07 at 1 04 20

Playground where you can see it

@deltakosh would very much appreciate your help :) forgot to say - @noalak thanks again for the answer, it was very helpful :)

julien-moreau commented 6 years ago

Hey can you try to fix the value of furLength to 0 ? Like this: https://playground.babylonjs.com/#87I67A#4

kutomer commented 6 years ago

Thanks, @julien-moreau :) I was certain that furLength actually determines the length of the fur and not the distance from the obj. So the only parameter that actually determines the length of fur is the fur spacing? (I thought that spacing determines from how many meshes each fur will be made of) If that's true I can only suggest changing the name of furLength to furDistance (and of course update the documentation as well)

julien-moreau commented 6 years ago

You are right, sure I will update :) For backward compatibility, we kept the variable names like this one which was here before we update to the high level fur mode. Updating the doc!

kutomer commented 6 years ago

@julien-moreau Awesome, thanks, so I will also update the exporter and will create a PR tomorrow.

julien-moreau commented 6 years ago

Excellent! :)