bma73 Posted February 15, 2016 Share Posted February 15, 2016 Hi, I'm manipulating the vertices of a ground mesh using the .updateMeshPositions() method and now i want to get the height at a specific point (x,z) on the mesh with .getHeightAtCoordinates(). Unfortunately, this doesn't seem to work... Here is a playground example:http://www.babylonjs-playground.com/#1JXJVF#2 What am I doing wrong? Thank you! BMA Quote Link to comment Share on other sites More sharing options...
jerome Posted February 16, 2016 Share Posted February 16, 2016 The altitudes are computed, for performance reasons, once on the first call to getHeightAtCoordinates() because the height map, designed from an image, wasn't supposed to be updated then Nevertheless, if you want to force the altitude recomputation at will, just use the private method _computeHeightQuads() : https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.groundMesh.ts#L109 heightMap._computeHeightQuads(); This will generate a new underlying pre-computed altitude array. Note well that, for now, this is not optimized to be used in the render loop because a new big array is generated each call. Your GC will shout ! Until I find a way to fix this, you should use a ribbon instead (if you don't need the heights from an image) and the same dedicated user function than in this example : Quote Link to comment Share on other sites More sharing options...
jerome Posted February 16, 2016 Share Posted February 16, 2016 Ok, I guess I've got an idea to make a fix to optimize the update for Ground mesh regarding the GC keep posted Quote Link to comment Share on other sites More sharing options...
jerome Posted February 16, 2016 Share Posted February 16, 2016 I just PRed an optimization, regarding the GC, with a new public method called updateCoordinateHeights() to force the height array reomputation on demand without any memory reallocation. I'll show a PG example as soon as the fix is pushed in the PG engine. [EDIT] : adam 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 16, 2016 Share Posted February 16, 2016 it is pushed to PG Quote Link to comment Share on other sites More sharing options...
jerome Posted February 17, 2016 Share Posted February 17, 2016 here's the commented PG : http://www.babylonjs-playground.com/#1JXJVF#3 satguru 1 Quote Link to comment Share on other sites More sharing options...
bma73 Posted June 6, 2016 Author Share Posted June 6, 2016 thank you for the updates - that's really working like a charm. I've got another related question: How do I apply the normal info from "getNormalAtCoordinates(x, z)" to the box' rotation in this examplehttp://www.babylonjs-playground.com/#1JXJVF#9 Any help would be really appreciated :-) Quote Link to comment Share on other sites More sharing options...
jerome Posted June 6, 2016 Share Posted June 6, 2016 please have a look a this example : http://jerome.bousquie.fr/BJS/demos/getHeightAtCoordinates.html code here : http://jerome.bousquie.fr/BJS/demos/getHeightAtCoordinates.js the boxes are rotated according the terrain normals : just a cross product (two actually) between the box direction (velocity) and the current terrain normal. ground API doc : http://doc.babylonjs.com/classes/2.4/GroundMesh 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.