Jump to content

Update shape with heightmap


Xav
 Share

Recommended Posts

Hi,

I am trying to find out if it is possible to adapt this 'sphere.applyDisplacementMap ("/ assets / amiga.jpg", 0, 1.5);' of this example https://www.babylonjs.com/demos/displacementmap/ on an object create in blender with the adapted uvs. 
To make it simple I would like to be able to change the shape of my object with a heightmap. I do not need to animate it.
I do not find a track to create this effect so I ask the question as to whether it is really possible.

Thank you

Link to comment
Share on other sites

Ok sorry,

An exemple on picture exemple.jpg.

It works very well with:

var sphere = BABYLON.Mesh.CreateSphere("Sphere", 32, 3, scene, true);    
sphere.applyDisplacementMap("Assets/test.jpg", 0, .2);

When i want to apply this on an obj create in blender it no longer works...

Is my question clearer?

Thanks

 

exemple.jpg

Link to comment
Share on other sites

I continued my research on this subject.
The problem would not it come that my mesh is not Updatable? As specified In the doc: "The mesh must be set as updatable. Its internal geometry is directly modified, no new buffer are allocated."

I found this post :

Is it possible to make a mesh updatable if it was created in an external softaware, to modify its mesh with a Heigth map?

Thanks

Link to comment
Share on other sites

Hello,

I found the solution:

            var obj = scene.getMeshByName("piece001");   

            var positions = obj.getVerticesData(BABYLON.VertexBuffer.PositionKind);
            var vb = obj.getVertexBuffer(BABYLON.VertexBuffer.PositionKind);
            vb._buffer._updatable = true;
            obj.applyDisplacementMap("test/test.jpg", 0, 10 , function() {
                obj.updateVerticesData(vb);
                console.log("OK!");
            });

 

Babylon.js is PERFECT :)!!!!

 

I think is now possible to export this mesh to an .obj file with the updatable shape ?

Thanks.

Link to comment
Share on other sites

Hi Xav, good to see you again.  I know of ONE way... perhaps the WRONG way...

https://www.babylonjs-playground.com/#P9UZG#12

In the BJS framework, applyDisplacementMap uses a helper func called applyDisplacementMapFromBuffer.  BOTH have been "hijacked" into that playground... but...

...it is likely hijacked from OLD version of BJS.  You might wish to get fresher versions from here.

Take a look at lines 31-43 (a save/restore wrapping, there, worth studying someday).  But most important... rotation, translation, and scaling of the IMAGE used-for the displaceMap... can be done there.  Not sure about continuously-updating the context2d image, in a renderloop.  I think a bit of custom code could do it.

Hope this helps.  Others will comment soon, I'm sure.

Link to comment
Share on other sites

Hello
Thanks Wingnut I had actually started looking at this. I will continue to develop this idea in parallel and obviously if I get something convincing I would share it ;).
Thanks Deltakosh actually I saw this especially that there is a post on this subject that runs on the forum: http: //www.html5gamedevs.com/topic/29587-babylon-objects-to-obj-file/

Again thank you for the time you give us to answer. Babylon.js is really a great tool very polyvalent :D

Thank you for everything !

Link to comment
Share on other sites

  • 1 month later...

Hello,

I found time to explore this idea a bit more.
Sorry but I can not get the script to export a mesh to .obj extension for the playground.
This works perfectly on my local machine.

https://www.babylonjs-playground.com/#P9UZG#14

My question is how to save everything in a file mesh.obj and mesh.mtl? If possible locally at the moment.

If anyone has an idea or a track to do that.

Thank you

 

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...