Jump to content

Need advices about a new VertexData.CreateTiledGround() function


celian-garcia
 Share

Recommended Posts

Hello everybody ! 

I've just made a function which will permite to create a tiled ground. There is several applications for it : board games, tiled map textures...

Check out the github https://github.com/kostar111/TiledGroundBJS

 

I'd like to know if the function seems to be easy to use or not, in order to make an eventual pull request.

 

Parameters of the function are :

  • xmin, zmin, xmax, zmax : correspond to the extent of the future tiled ground.
  • precision : number of subdivisions inside a tile (precision.w = subdivisions in the width & precision.h = subdivisions in the height)
  • subdivisions : number of tiles (subdivisions.w = number of tiles in the width & subdivisions.h = number of tiles in the height

Basically it is very similar to the VertexData.CreateGround function but with differents indices so we could use BABYLON.MultiMaterial to apply materials by tiles.

 

Here are some jsfiddle you can play with

http://jsfiddle.net/q9d28/ chess

http://jsfiddle.net/4h35v/3/ space-invaders character

Link to comment
Share on other sites

I just find a thing really strange, if we look at the map demo, we can see there is a "jump" between differents materials of the MultiMaterial object.

post-8511-0-36022200-1405413016.jpeg

 

but if I use a Multimaterial with only one material duplicated, the jump disappeared

post-8511-0-18709400-1405413017.jpeg

 

It looks like the first pixel's column of the texture was duplicated (or moved) in the last pixel's column

And idem for the rows.

 

So I think the jump is already there at the second picture but we don't see it because it is a pixel's column which correspond with first pixel's column of the next texture.

 

I don't know if I am clear because it is not so easy to explain, moreover in English ^^

 

I prepare something more clear and visible.

Link to comment
Share on other sites

I made an example more clear here

http://kostar111.github.io/TiledGroundBJS/materialBug/

 

I just made a plane and applied this texture :

post-8511-0-50629600-1405414963.png

 

The texture have on the left a white column and on the right a red column .

If we look at the demo I've made, we can see a white column after the red one, and a red column before the white one.

 

How can it be explained ?

Link to comment
Share on other sites

The code I use in the last example

http://kostar111.github.io/TiledGroundBJS/materialBug/

is as simple as that : 

var ground = new BABYLON.Mesh.CreatePlane("ground", 1, scene);ground.rotation.x = Math.PI/2;var material1 = new BABYLON.StandardMaterial(    "material1",    scene);material1.diffuseTexture = new BABYLON.Texture(    "texture.png",    scene);ground.material = material1;

And I've console.logged the uvs in the demo and here I have 

[0, 0, 1, 0, 1, 1, 0, 1]

Link to comment
Share on other sites

Ok it fixed the problem with Planes and Grounds so it will be fixed in Geotrek 3D ! Thank you very much  =) .

 

but .. not with the TiledGround :/ I'll try to fix it tomorrow. There is something wrong on my uvs values I think or maybe the wrapping behaviour is different with submaterials ? So I made the pull request maybe a little fast ^^

Link to comment
Share on other sites

Ok the clamp trick works with the TiledGround now  !

 

Here is the result : http://kostar111.github.io/TiledGroundBJS/map/ -> No jump at all !  :)

 

The stilling "problem" is I had to duplicates positions which are in the joints : you know, one with u = 1 at the end of the tile and one with u = 0 at the beginning of the next tile (idem with v values), and I don't know what would be the behaviour with collisions or Ray intersections for example if the ray come exactly in the joint.

I'll test these kind of situations and come back later. But I'm relatively confident ^^

Link to comment
Share on other sites

Oh yes I'll try it ;) I'm not familiar with it but I think it is not "sorcier". (I was not familiar with JS 5 months ago haha)

I can include also old cylinder's changings to the Mesh.CreateCylinder() function just to include the subdivisions parameter.

 

And about Geometry I could update the Cylinder one and create a TiledGround one using this code format

var Ground = (function (_super) {    __extends(Ground, _super);    function Ground(id, scene, width, height, subdivisions, canBeRegenerated, mesh) {        this.width = width;        this.height = height;        this.subdivisions = subdivisions;        _super.call(this, id, scene, this._regenerateVertexData(), canBeRegenerated, mesh);    }    Ground.prototype._regenerateVertexData = function () {        return BABYLON.VertexData.CreateGround(this.width, this.height, this.subdivisions);    };    Ground.prototype.copy = function (id) {        return new Ground(id, this.getScene(), this.width, this.height, this.subdivisions, this.canBeRegenerated(), null);    };    return Ground;})(_Primitive);Primitives.Ground = Ground; 

Anyway I'll try it all and see if it working well. And obviously in TypeScript too. 

Bye

Link to comment
Share on other sites

I understand, yeah I can make it with mesh. I've just found cool the new groundMesh class :)  in particular the getHeightAtCoordinates() function which is simple but can be useful.

I would prefer to find a way to modify the optimize function but for the moment I'll change GroundMesh to Mesh.

 

By the way I found something weird with this last function and I think I resolved it. Here is the topic http://www.html5gamedevs.com/topic/8015-getheightatcoordinates-return-wrong-value/ if you want to see it.

Link to comment
Share on other sites

  • 3 weeks later...

Kostar111 ... I am working on a fresher tutorial #2... its at...

 

https://github.com/BabylonJS/Babylon.js/wiki/zzz-work-in-progress-02

 

Just a slight adjustment to your edit, and i put a link to your very cool tiled ground tutorial... in there, as well. 

 

Hope you approve.  If you'd like to make an edit to the tiled ground area... within that work-in-progress document... please do, and I will make sure your edit "holds" through all my future document edits/pastes.

 

I love your tiled ground tutorial... it totally rocks!  Nice work!

Link to comment
Share on other sites

Nice ! I like it =) Sure I approve it. Aaand I have no edit to make I found it good, you are surely a better writer than me ;) , seeing the big comments you make usually in the forum. Oo

 

I don't know if I can change "kostar111" name in Github but I don't like it I'll probably change it if I can.

 

Thank you very much for your consideration ! And see you in September 'cause I'm in holidays haha

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