Sign in to follow this  
dogyear

Export displacement maps from Blender

Recommended Posts

Hi Everyone!

I am new to babylonJs and for the life of me can't figure out how to export a mesh that contains a displacement map.  Does the blender exporter support displacement maps?  If no then how can I apply a displacement map after the mesh has been exported to babylonJs?  I have tried the following code after importing the mesh.  Again I would prefer it if I can just export the mesh with the displacement mapping, but if that's not possible then I would like to apply it after it has been imported to babylonJs.

BABYLON.SceneLoader.ImportMesh('', 'assets/models/island/', 'island.babylon', scene, function (newMeshes) {
newMeshes[0].applyDisplacementMap('/assets/models/island/Sand_003_DISP.png', 0, 5);
});

Share this post


Link to post
Share on other sites

Hi @dogyear. Welcome :) 
I don't know if you can directly export your mesh with displacement map :(. Hope somebody with more experience with this can help.
But I think I know why it doesn't work to add displacement after import, few months ago I had same problem. Please take a look at this topic

 

 

To apply displacement map on a mesh, this should have positions, normals and UVs.

Share this post


Link to post
Share on other sites

@MarianG Thanks.  I do have UVs and normals set on my meshes.  I'm not sure what I am doing wrong because I'm most likely doing something wrong.

@JCPalmer Cool!  Do you know how can I export the displacement maps?  I have set the displacements on my blender texture, but they don't export with the babylon file.  Here's what my blender looks like

 

image.png.0be8cac3c5000a6c89772c13980eff91.png

Share this post


Link to post
Share on other sites

Since the exporter does not support it, you would have to add it.  Kind of a waste of my time outlining any changes, since there does not seem like it can be serialized.  Parse() is what is called to deserialize  an exported mesh.  See not place where a url can be taken from the data & call applyDisplacementMap() for you.

Share this post


Link to post
Share on other sites

@JCPalmer ah... You must've miss typed because your original reply said the exporter does support exporting displacement maps. I got really excited lol!  It would've made things so much easier as I know much more about Blender than BabylonJs.  Oh well.  Your tip seems simple enough. I'll do the force update when get home tonight. Thank you for the pointer! 😀

Share this post


Link to post
Share on other sites

@JCPalmer It tried adding true at the end, but nothing seems to happen.  Going through the playground reveals a lot of examples with imported meshes that just doesn't work.  I've also tried replacing the nulls with undefined without success.  Are there other boilerplate code that must be present?

 

BABYLON.SceneLoader.ImportMesh('', 'assets/models/island/', 'island.babylon', scene, function (newMeshes) {
newMeshes[0].applyDisplacementMap('/assets/models/island/displace.png', 0, 5, null, null, null, true);
});

Share this post


Link to post
Share on other sites

Be absolutely sure that is the mesh you think it is.  The number of times someone got this wrong is huge.  Either console.log the mesh name, or better

scene.getMeshByName('victim').applyDisplacementMap(...)

Next check console that your file is actually being found.

If this does not work, then a topic in the Q & A, might be better, since this is not really a blender issue.

Share this post


Link to post
Share on other sites

@JCPalmer Thanks for all your help so far.  I have tried what you suggested and it seems I was targeting the correct mesh.  When I check my console tab, the applyDisplacementMap function was loading my displacement map image, but the displacement is still not being applied.  I will move this question to Q&A after scouring that section for more info.  ^__^

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.