Alvaro Posted July 7, 2014 Share Posted July 7, 2014 Hi All! I am trying to build a simply terrain viewer using babylon.js. (I am new working with this kind of frameworks). I have several tile pieces and each one have information about altitude (height map). The idea is to let the javascript ask for new tiles when needed. So I have a tile manager that checking the position of the camera, select the tile where the camera is and ask for more tiles, if needed, to continue adding information to the map. I am using the WorldMonger terrain texture to see grass, rocks, etc.. on the terrain. I am creating a new Mesh for each tile and changing the position to locate it in the right place. This works great but because each tile is a new Mesh I can see the "jump" in the texture between two tiles and therefore it is not good enough. So my first idea was create only one mesh and update it everything I got new information. I would be applying the texture only once time and I would have only one mesh. It sounds like an improvement to me. The problem is that I cannot make it work. To test it I am loading only two tiles, to see if I can see the two tiles on the viewer. But I can only see one. I have tried different approach but at the end the result is always the same. This is a example of the "update" piece of my code: (any ideas? what is wrong?) if (this._singleMesh.getTotalVertices() == 0) { this._singleMesh.setVerticesData(BABYLON.VertexBuffer.PositionKind, positions, updatable); this._singleMesh.setVerticesData(BABYLON.VertexBuffer.NormalKind, normals, updatable); this._singleMesh.setVerticesData(BABYLON.VertexBuffer.UVKind, uvs, updatable); this._singleMesh.setIndices(indices); } else { positions = positions.concat(this._singleMesh.getVerticesData(BABYLON.VertexBuffer.PositionKind)); normals = normals.concat(this._singleMesh.getVerticesData(BABYLON.VertexBuffer.NormalKind)); uvs = uvs.concat(this._singleMesh.getVerticesData(BABYLON.VertexBuffer.UVKind)); indices = indices.concat(this._singleMesh.getIndices()); this._singleMesh.updateVerticesData(positions, BABYLON.VertexBuffer.PositionKind, updatable); this._singleMesh.updateVerticesData(normals, BABYLON.VertexBuffer.NormalKind, updatable); this._singleMesh.updateVerticesData(uvs, BABYLON.VertexBuffer.UVKind, updatable); this._singleMesh.setIndices(indices); } Quote Link to comment Share on other sites More sharing options...
celian-garcia Posted July 8, 2014 Share Posted July 8, 2014 Hello !If you want to merge several meshes in one you can use the BABYLON.VertexData.merge() functionAnother solution would be to still have tiles but as you saw you'll have 2 problems - Join each mesh to remove the "jump" you talked about. - Recompute UVs values I wrote articles in french about this second method I used. Here is a code I wrote. You can use it if you want !https://github.com/kostar111/rando3D/blob/master/Rando/Rando.TileContainer.jsIt will not work just like it , alone. But if you want to use it I can explain you what you'll need. Don't hesitate to ask me. Quote Link to comment Share on other sites More sharing options...
celian-garcia Posted July 10, 2014 Share Posted July 10, 2014 I misunderstood I think, in fact I think I have the same problem. Is it something like that ? : If yes I can't help you ^^ sorry Quote Link to comment Share on other sites More sharing options...
Alvaro Posted July 13, 2014 Author Share Posted July 13, 2014 That is exactly what it is. But when applying a material like in WorldMonger it looks worse. Sorry, I think I didn't explain the point properly. I will take a look at your code any way. Thank you! Quote Link to comment Share on other sites More sharing options...
celian-garcia Posted July 13, 2014 Share Posted July 13, 2014 No it's me I don't have a good english ^^ I tried with a single mesh and MultiMaterial and it does the same jump...http://kostar111.github.io/TiledGroundBJS/map/ I didn't try to apply materials like in WorldMonger but it seems to resolve the problem if we see the result they obtain.I looked at it briefly and I saw something like effect.setTexture, is it the way you tried ? Any way we seem to have the same problem ^^ Quote Link to comment Share on other sites More sharing options...
Alvaro Posted July 14, 2014 Author Share Posted July 14, 2014 The world of monger is using only one height map, that is why you don't see the problem there. If you find a solution let me know, maybe someone else answer with a big idea Cheers! Quote Link to comment Share on other sites More sharing options...
celian-garcia Posted July 14, 2014 Share Posted July 14, 2014 I am pretty sure that an answer would be in the WORLDMONGER.GroundMaterial but it use BABYLON.Effect which take .fx extern files and it is too much far from my young skills in 3D However I'm ok to say there may be another solution and if not, it is a bug which should be fixed. Let's wait other answers and the big idea as you said ^^ Good week! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 15, 2014 Share Posted July 15, 2014 Do you have a demo running somewhere ? Quote Link to comment Share on other sites More sharing options...
celian-garcia Posted July 16, 2014 Share Posted July 16, 2014 The big idea came from mister deltakosh as usual ^^ Ok this is linked to texture wrapping. To remove this effect:material1.diffuseTexture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;material1.diffuseTexture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE; If you apply it with your "new mesh for each tile" it should remove the jump ! I did it and it works perfectly. Quote Link to comment Share on other sites More sharing options...
Alvaro Posted August 24, 2014 Author Share Posted August 24, 2014 Thank you man, I can see in the url you posted some comments ago that it is working for you. Which version of babylon.js are you using? I can only find the "wrapV" property but no the other, what seems weird. Quote Link to comment Share on other sites More sharing options...
Alvaro Posted August 24, 2014 Author Share Posted August 24, 2014 I see the problem, you are using standard materials and applying the wrapV and wrapU to them and after that pushing the standard materials into a multimaterial. My situation is different. My material is generated according with the altitude of the terrain. So I don't have an image. Anyway, I saw your new function, and I will take a look. Quote Link to comment Share on other sites More sharing options...
celian-garcia Posted August 24, 2014 Share Posted August 24, 2014 Oh you saw my tuto about TiledGround ! In fact it is not possible to set elevations of tiled grounds I created.But the wrapU and wrapV trick should work with a classic plane or ground or groundFromHeightMap. If you want elevations, you should have one mesh (ground or groundfromheightmap) by tile. Edit : I read twice your post and I understand whar you're saying about the fact you don't have an image so I can't help you sorry 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.