Jump to content

tiled mesh and texture


Alvaro
 Share

Recommended Posts

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);
            }  
Link to comment
Share on other sites

Hello !

  • If you want to merge several meshes in one you can use the BABYLON.VertexData.merge() function
  • Another 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.js

It 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.

Link to comment
Share on other sites

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 ^^

Link to comment
Share on other sites

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 :wacko:

 

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...