Jump to content

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);
});
Link to comment
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.

Link to comment
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

Link to comment
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.

Link to comment
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! ?

Link to comment
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);
});
Link to comment
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.

Link to comment
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.  ^__^

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...