Jump to content

Update the height map dynamically (like a dynamic texture)


vladimr
 Share

Recommended Posts

Hi,
I implement 3D map/ground video (dynamically loaded height map and texture image data via websocket).

For dynamic texture I can use  BABYLON.DynamicTexture(...)
and update it every video frame:
context = ground.material.diffuseTexture.getContext()
...
context.putImageData(...)
ground.material.diffuseTexture.update()

Is there a way to update the height map dynamically like the dynamic texture ?
What I should use instead of BABYLON.Mesh.CreateGroundFromHeightMap ?

Thanks,
Vladimir

Link to comment
Share on other sites

Hiya vladimr!   I might have some help...  https://www.babylonjs-playground.com/#1VGWP9#11

In this playground, I 'borrowed' (hijacked) applyDisplacementMap() and applyDisplacementMapFromBuffer()... from BJS main source.  I think I modified them, too.

Anyway, in lines 17-19... I make a standard ground mesh... sub-divided quite heavily.

Now let's look at line 96.  Pretty much a basic applyDisplacementMap() call... for ground... using a URL.

Let's follow it up... to line 22.  We really don't care about that function... EXCEPT... at line 51.  Line 51... a call to applyDisplacementMapFromBuffer().

Hey... if YOU have a buffer of image colors... YOU could 'intervene' here, and apply ANY buffer, right?  (hint)

You can also look in this file... raw BJS source... https://raw.githubusercontent.com/BabylonJS/Babylon.js/master/dist/babylon.max.js

Control-f doc-search for applyDisplacementMapFromBuffer... look things over, as wanted.  :)  That's where I hijack code-from.

Mesh.prototype.applyDisplacementMapFromBuffer = function (buffer, heightMapWidth, heightMapHeight, minHeight, maxHeight, uvOffset, uvScale)

So... ground.applyDisplacementMapFromBuffer(myBuffer, 100, 100, 5, 0);   Pretty easy.

You don't even need to have hijacked versions of applyDisplacementMap() and applyDisplacementMapFromBuffer() functions in your code.  You just need a good buffered image, and then you can remove lines 21-97 from my playground.  Just create a nice image buffer, somehow, and then do... ground.applyDisplacementMapFromBuffer(myBuffer, 100, 100, 5, 0);  (I think)

This should help get you rolling. (I hope.)   Good luck.  Got questions?  Ask.  We're here to help.  (and we all learn from watching your experiments).  :)

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