RobS

Members
  • Content Count

    4
  • Joined

  • Last visited

  1. 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
  2. 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
  3. I believe I've sorted it: http://www.babylonjs-playground.com/#YLJVQ#4 if (pl.physicsImpostor){ scene.getPhysicsEngine().removeImpostor(pl.physicsImpostor); } To (surprisingly) remove the imposter rather than this route. pl.physicsImpostor = new BABYLON.PhysicsImpostor(pl, BABYLON.PhysicsImpostor.NoImpostor, scene); No Script errors from Cannon now. Cheers, Rob
  4. Hi, Thought I'd pop this in here as it's my first post but it might require moving to bugs. I'm trying to toggle physics on and off for certain meshes, I've knocked together this simple demo which basically works: http://www.babylonjs-playground.com/#YLJVQ#2 On run the 10 planes drop on to the box, bounce around a bit then settle. All good. If you then click the scene it should go in to a physics paused state and the 10 planes reset themselves above the plane. Cannon is throwing an error here and so the 2nd to 10th plane slowly start sinking down. Error stems from line 68. If I use Oimo then the pause state works well however the unpaused physics motion is a bit mad so I'd prefer to stick with Cannon. So really, this leaves me with two questions. Is the way I'm changing the physics impostors the best way enable/disable physics? And, is this a bug in CannonJS? Cheers, Rob