_ElementoZerO_ Posted July 15, 2016 Share Posted July 15, 2016 Hi! i'm trying to add some grass mesh on a height map, but the getHeightAtCoordinates return sometimes a wrong value ( and the grass is up in the sky..) i using the same code of the instances example: BABYLON.SceneLoader.ImportMesh("", "./assets/mesh/world/", "grass.babylon", this.GameKernel.scene, function (grass) { var x1 = 0; var z1 = 0; grass[0].material.opacityTexture = null; grass[0].material.backFaceCulling = false; grass[0].isVisible = true; grass[0].position.y = ground.getHeightAtCoordinates(x1, z1); // Getting height from ground object grass[0].position.x = x1; grass[0].position.z = z1; grass[0].material.specularColor = new BABYLON.Color3(0, 0, 0); grass[0].material.ambientColor = new BABYLON.Color3(1, 1, 1); //newMeshes[0].scale = 0.5 //shadowGenerator.getShadowMap().renderList.push(newMeshes[0]); var range = 200; var count = 100; var x,y,z; var newGrassInstance; for(var j = 0; j < count; j++) { x =(grass[0].position.x)-((range / 2) - (Math.random() * range)); for (var i = 0; i < count; i++) { newGrassInstance = grass[0].createInstance("x" + x +"y" + y+ "z" + z ); z = (grass[0].position.z)-((range / 2) - (Math.random() * range)); y = ground.getHeightAtCoordinates(x, z); // Getting height from ground object //console.log("y: " + y ); newGrassInstance.position = new BABYLON.Vector3(x, y, z); /* if(ground.intersectsMesh(newGrassInstance, true)) console.log("x" + x +"y" + y+ "z" + z +"is on ground"); else console.log("x" + x +"y" + y+ "z" + z + " not on ground");*/ newGrassInstance.rotate(BABYLON.Axis.Y, Math.random() * Math.PI * 2, BABYLON.Space.WORLD); var scale = 0.5 + Math.random() * 2; newGrassInstance.scaling.addInPlace(new BABYLON.Vector3(scale, scale, scale)); } } }); the attach image show the result.. where i'm wrong? ps the ground is not rotate i'm read in the source code that the function return non consistent value in this case Quote Link to comment Share on other sites More sharing options...
adam Posted July 15, 2016 Share Posted July 15, 2016 Is your ground using the same coordinate system as your grass instances? edit: In other words, do they have the same parents? Quote Link to comment Share on other sites More sharing options...
jerome Posted July 15, 2016 Share Posted July 15, 2016 quite difficult to answer without a repro case showing the same issue could you please provide a simple PG with the same problem ? Quote Link to comment Share on other sites More sharing options...
_ElementoZerO_ Posted July 15, 2016 Author Share Posted July 15, 2016 28 minutes ago, adam said: Is your ground using the same coordinate system as your grass instances? I'm using the tree mesh take from instance demo and i have the same problem...i take this grass mesh from a free site...how i can check? 28 minutes ago, jerome said: quite difficult to answer without a repro case showing the same issue could you please provide a simple PG with the same problem ? The project is very big..if you want i can send you a link in private. Quote Link to comment Share on other sites More sharing options...
jerome Posted July 15, 2016 Share Posted July 15, 2016 nope, please do the same error in something simpler and shorter sometimes, making PG helps to discover one's own error ;-) Quote Link to comment Share on other sites More sharing options...
adam Posted July 15, 2016 Share Posted July 15, 2016 Can you provide us with a link to the grass model? Quote Link to comment Share on other sites More sharing options...
_ElementoZerO_ Posted July 15, 2016 Author Share Posted July 15, 2016 15 minutes ago, adam said: Can you provide us with a link to the grass model? .blender of grass and .babylon exported and i'm try to create a PG how can upload file in PG? grass.babylon grass.babylon.manifest grass_c.blend Quote Link to comment Share on other sites More sharing options...
adam Posted July 15, 2016 Share Posted July 15, 2016 Here is your grass in the PG: http://www.babylonjs-playground.com/#XB7FW _ElementoZerO_ 1 Quote Link to comment Share on other sites More sharing options...
_ElementoZerO_ Posted July 15, 2016 Author Share Posted July 15, 2016 ok as i imagined thank you, now i work on this pg and try to reproduce the issue, i'll post the updated PlayGround Quote Link to comment Share on other sites More sharing options...
_ElementoZerO_ Posted July 16, 2016 Author Share Posted July 16, 2016 i can not reproduce the issue in the playground i copy and past my code and all work... http://www.babylonjs-playground.com/#XB7FW#10 what i can try to do?? Quote Link to comment Share on other sites More sharing options...
jerome Posted July 16, 2016 Share Posted July 16, 2016 So the error is probably somewhere else ... in the values x, z that you pass to getHeightAtCoordinates() maybe in your code or the way your ground is built That's why I said that making a PG often helps to find where the error is (or where it's not) Quote Link to comment Share on other sites More sharing options...
adam Posted July 16, 2016 Share Posted July 16, 2016 If your ground is parented to another mesh, you should make sure your plants have the same parent. Quote Link to comment Share on other sites More sharing options...
_ElementoZerO_ Posted July 16, 2016 Author Share Posted July 16, 2016 36 minutes ago, adam said: If your ground is parented to another mesh, you should make sure your plants have the same parent. ground parent is undefined, i check this with console.log(ground); Quote Link to comment Share on other sites More sharing options...
dbawel Posted July 17, 2016 Share Posted July 17, 2016 Do you really need the physical geometry for the grass? That's allot of computation as I don't see the Geometry built for simulating wind dynamics or other dynamics - so might you simply use sprites? Otherwise, your framerate will crawl on mobile - as it's quite slow now. Just a thought... DB Quote Link to comment Share on other sites More sharing options...
_ElementoZerO_ Posted July 17, 2016 Author Share Posted July 17, 2016 9 hours ago, dbawel said: Do you really need the physical geometry for the grass? That's allot of computation as I don't see the Geometry built for simulating wind dynamics or other dynamics - so might you simply use sprites? Otherwise, your framerate will crawl on mobile - as it's quite slow now. Just a thought... DB You're right but this little game is for an exams and i promised to my prof grass mesh...but i still not resolve the issue.. The framerate that you see in the image is from my old notebook....with desktop computer with gtx 260 (old too..) i have about 30-40 fps Quote Link to comment Share on other sites More sharing options...
jerome Posted July 17, 2016 Share Posted July 17, 2016 imho, if I were you, I would restart to reimplement the code from the working PG step by step and I would test at each step if something is then getting wrong in order to localize the error Quote Link to comment Share on other sites More sharing options...
_ElementoZerO_ Posted July 17, 2016 Author Share Posted July 17, 2016 7 hours ago, jerome said: imho, if I were you, I would restart to reimplement the code from the working PG step by step and I would test at each step if something is then getting wrong in order to localize the error maybe is the only way.. i tried with sprite and same issue... Quote Link to comment Share on other sites More sharing options...
Boz Posted July 17, 2016 Share Posted July 17, 2016 Hey ! I don't know why but I got a problem with this same function.. Maybe a problem with v2.4 ? I go inside the babylonjs code but it should work. So I created my own function, which works well : var groundHeightAt = function(x, z) { // Create ray from position x,z at the maximum altitude and launch it vertically to hit the ground var maxHeight = // define your max height // mine is skybox.getBoundingInfo().boundingBox.maximum.y var ray = new BABYLON.Ray(new BABYLON.Vector3(x, maxHeight, z), // Origin new BABYLON.Vector3(0, -1, 0), // Direction 2*maxHeight); // Length var res = ground.intersects(ray, true); return res.pickedPoint.y; } Where is the difference ? _ElementoZerO_ 1 Quote Link to comment Share on other sites More sharing options...
dbawel Posted July 17, 2016 Share Posted July 17, 2016 I'm finding broken features in 2.4 - and will report right now outlining one of the bugs. I switched our server back to Version 2.2 - although, this probably isn't part of your issue. I am however finding bugs with videoTexture playback in 2.4 though. As I mentioned, I'll post a bug report now. DB _ElementoZerO_ 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted July 18, 2016 Share Posted July 18, 2016 @_ElementoZero_ Another approach could be to reduce your ground size and number sprite number and to try to isolate some cases where the grass is not at the right altitude in your code, then to log the x z values that you are apssing to the function and what y is returned Without any log/data or any issue repro PG we can hardly imagine what/how you're doing and what values are handled in the code. You don't tell us either how is your ground designed in your code : size, subdivisions, max/min height, position, etc Quote Link to comment Share on other sites More sharing options...
_ElementoZerO_ Posted July 18, 2016 Author Share Posted July 18, 2016 8 hours ago, Pouet said: Hey ! I don't know why but I got a problem with this same function.. Maybe a problem with v2.4 ? I go inside the babylonjs code but it should work. So I created my own function, which works well : var groundHeightAt = function(x, z) { // Create ray from position x,z at the maximum altitude and launch it vertically to hit the ground var maxHeight = // define your max height // mine is skybox.getBoundingInfo().boundingBox.maximum.y var ray = new BABYLON.Ray(new BABYLON.Vector3(x, maxHeight, z), // Origin new BABYLON.Vector3(0, -1, 0), // Direction 2*maxHeight); // Length var res = ground.intersects(ray, true); return res.pickedPoint.y; } Where is the difference ? 33 minutes ago, jerome said: @_ElementoZero_ Another approach could be to reduce your ground size and number sprite number and to try to isolate some cases where the grass is not at the right altitude in your code, then to log the x z values that you are apssing to the function and what y is returned Without any log/data or any issue repro PG we can hardly imagine what/how you're doing and what values are handled in the code. You don't tell us either how is your ground designed in your code : size, subdivisions, max/min height, position, etc I'll try ! thank you guys ! this.sizeX = 2600;//2600;//2608; this.sizeY = 2032;//2000;//2032; var ground = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "./textures/heightMap.png", this.sizeX, this.sizeY, 300, 0, 255, this.GameKernel.scene, false); ground.position.y = 0; var groundMaterial = new BABYLON.StandardMaterial("groundMaterial", this.GameKernel.scene); groundMaterial.diffuseTexture = new BABYLON.Texture("./textures/sand.jpg", this.GameKernel.scene); groundMaterial.diffuseTexture.uScale = 60; groundMaterial.diffuseTexture.vScale = 60; groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0); ground.material = groundMaterial; ground.receiveShadows = true; //this._deactivateSpecular(ground); ground.checkCollisions = true; ground.applyGravity = true; this.ground = ground; Another think my code is based on this tutorial: http://pixelcodr.com/tutos/shooter/shooter.html Quote Link to comment Share on other sites More sharing options...
_ElementoZerO_ Posted July 18, 2016 Author Share Posted July 18, 2016 MAYBE I RESOLVE, guys i simply use the preview version (2.5) and now seems work i'll update you.. UPDATE: now that i think the PlayGround use the 2.5 .... Quote Link to comment Share on other sites More sharing options...
jerome Posted July 18, 2016 Share Posted July 18, 2016 yep, the PG uses the latest built and you are right, a bug (fixed in 2.5) was introduced just before the 2.4 relase in the cross product use in computeHeightQuads() , that affected getHeightAtEtc() : a simple conflict in the use of temporary pre-allocated vector3s, somethng we use under the hood to not reuse the memory and to not trigger the GC. Have a look a the bug fixes here please : https://github.com/BabylonJS/Babylon.js/blob/master/dist/preview release/what's new.md I didn't know you were using the 2.4 version, sorry. _ElementoZerO_ 1 Quote Link to comment Share on other sites More sharing options...
_ElementoZerO_ Posted July 18, 2016 Author Share Posted July 18, 2016 is my fault i don't write that i use 2.4 ver.. A question how i can put the mesh on all ground surface and use incremental load? with my function is very slow..and limited to a given zone.. Quote Link to comment Share on other sites More sharing options...
dbawel Posted July 18, 2016 Share Posted July 18, 2016 @_ElementoZerO_ - I don't know if this is affecting your scene - however when we removed incremental loading from our latest scene just a few days ago, our performance increased considerably. So it is certainly worth a test, and to share your results with the community. As previously mentioned, we're still using Version 2.2 as for us it has proven to be stable for all elements we are using for our current app (and for @MasterSplinter, this means applications loaded through a link in WebGL). However, I will be working with v2.4 again later this week as soon as I receive confirmation that the bug with videoTextures as well as others reported on the forum are fixed. And as I always mention, babylon.js is a very new framework, and I am always impressed by how stable each release is - even though I'm currently having issues with v2.4. Compared to past experience with new release software, babylon.js is by far the most stable and thoroughly tested for each release due to the unique group of developers building this framework - as well as the very enthusiastic group of developers and users on this forum testing and posting daily, not to mention that the builders are enguaged daily with this community. I'm quite proud to be considered a part of the history we are all building here. And I know that soon babylon.js will be in the media spotlight, as I'm aware of what others are developing, as well as a few major players in the film industry which are already in process of providing high praise for what this framework is able to accomplish and how they are making amazing use of this - across all platforms, which for the film and other industries is beyond belief. So thank you for posting and keeping us all informed on your progress. We're all in this together, and are all benefiting greatly from it. By the way, if DK or Davrous get this far in the post, is it possible to add a spell-check to the text editor on this forum? This would help allot of users, especially those whose first language is not English. Just thought I'd ask, as I thought I remember having this feature in early 2014. But I'm probably mistaken. Cheers, DB _ElementoZerO_ 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.