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