vladimr Posted April 15, 2018 Share Posted April 15, 2018 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 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 15, 2018 Share Posted April 15, 2018 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). Quote Link to comment Share on other sites More sharing options...
MarianG Posted April 15, 2018 Share Posted April 15, 2018 Hi Vladimr, did you see this : http://www.babylonjs.com/scenes/worldmonger/ Take a look at elevation js file. It should help Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.