RobS Posted October 3, 2016 Share Posted October 3, 2016 Hi, I've been messing with mesh.applyDisplacementMapFromBuffer() using a separate canvas to create a dynamic image (just messing with gradients at the moment). I'm hoping to animate the result but currently when you apply applyDisplacementMapFromBuffer() repeatedly it adds the new displacement map to the existing displaced map so things get a bit crazy looking. So basically I need something to call to before applyDisplacementMapFromBuffer() that restores the mesh to it's original state. I've looked at setVerticesData, updateVerticesData, setVertexBuffer and not got anywhere, once they're called the applyDisplacementMapFromBuffer has no effect. Here's some vague example code: var plane = BABYLON.Mesh.CreateGround("plane", 192, 108, 100, scene, true); var originalVertices = plane.getVerticesData(BABYLON.VertexBuffer.PositionKind); mergeCanvas = document.getElementById("mergemap") var mergeCTX = mergeCanvas.getContext('2d'); var mw = mergeCanvas.width; var mh = mergeCanvas.height; engine.runRenderLoop(function() { // imagine some stuff happens here to draw into the mergeCTX var buffer = mergeCTX.getImageData(0, 0, mw, mh).data; // reset needs to happen here plane.updateVerticesData(BABYLON.VertexBuffer.PositionKind,originalVertices) plane.applyDisplacementMapFromBuffer(buffer, mw, mh, 0, 1); }); Sorry for the fairly vague info but any pointers will be much appreciated. Cheers, Rob Quote Link to comment Share on other sites More sharing options...
RobS Posted October 3, 2016 Author Share Posted October 3, 2016 Typical, 5 minutes after posting I find a solution! var plane = BABYLON.Mesh.CreateGround("plane", 192, 108, 100, scene, true); var originalVertices = plane.getVerticesData(BABYLON.VertexBuffer.PositionKind).slice(0); mergeCanvas = document.getElementById("mergemap") var mergeCTX = mergeCanvas.getContext('2d'); var mw = mergeCanvas.width; var mh = mergeCanvas.height; var updatePositions = function (positions) { for (var idx = 0; idx < positions.length; idx++) { positions[idx] = originalVertices[idx] } }; engine.runRenderLoop(function() { // imagine some stuff happens here to draw into the mergeCTX var buffer = mergeCTX.getImageData(0, 0, mw, mh).data; plane.updateMeshPositions(updatePositions); plane.applyDisplacementMapFromBuffer(buffer, mw, mh, 0, 1); }); Is that the best way? Cheers, Rob GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 3, 2016 Share Posted October 3, 2016 This is exactly what I would have suggested 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.