Jump to content

How to implement large probably 1000x1000 grid. Not necessarily 3D?


Majeed Siddiqui
 Share

Recommended Posts

if you just need to draw a grid without any logic on a plane, you could use the grid material : http://doc.babylonjs.com/extensions/Grid

if you need to draw a grid as crossed lines in one draw call, you could use the LineSystem : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#linesystem with 1000 x 1000 orthogonal lines

example : http://www.babylonjs-playground.com/#1YCYTA

maybe some LOD would be useful here :D

Link to comment
Share on other sites

On 8/4/2016 at 6:14 PM, jerome said:

if you just need to draw a grid without any logic on a plane, you could use the grid material : http://doc.babylonjs.com/extensions/Grid

if you need to draw a grid as crossed lines in one draw call, you could use the LineSystem : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#linesystem with 1000 x 1000 orthogonal lines

example : http://www.babylonjs-playground.com/#1YCYTA

maybe some LOD would be useful here :D

Thank you so much for your response!

As you mentioned do you want to do any processing? I would like to create boxes of random size that should align with grid squares. For example, if grid is 8x8 square and there is a box of size 2x3 then it should exactly take 2x3=6 square on grid. Is there any way to force this? Actually I want have drag and drop for those boxes that's why this restriction is needed. Or do I have to do maths stuff to force this? 

Link to comment
Share on other sites

hi 

may be this help 

i use shader for tile generator 

http://www.babylonjs-playground.com/#Q87ZR#2  100x200   without smooth

http://www.babylonjs-playground.com/#Q87ZR#3  1000x1000 smooth

var plan = BABYLON.Mesh.CreateGround("a", 200, 200, 1, scene);
		plan.material = new BABYLONX.ShaderBuilder()
		    .SetUniform('plansize','vec2')
            .SetUniform('gridSize','vec2')
            .SetUniform('smoothPower','vec2')
            .InLine('float fg = length(pos-camera)/60. ;\n\
			float smooth_px = ((sin(pos.x*(1./plansize.x)*gridSize.x *3.141592)));\n\
			float smooth_pz = ((sin(pos.z*(1./plansize.y)*gridSize.y *3.141592)));\n\
		    float px = abs(floor(sin(pos.x*(1./plansize.x)*gridSize.x *3.141592)));\n\
			float pz = abs(floor(sin(pos.z*(1./plansize.y)*gridSize.y *3.141592)));\n\
		    if(px+pz > 1.95 || px+pz < 0.05 ) result = vec4(1.); \n\
			else result = vec4(0.);\n\
			fg = min(smoothPower.x,max(0.,pow(fg,0.5)*smoothPower.y));\n\
		    vec3 smooth = vec3((pow(smooth_px *smooth_pz,0.8)*(1.-fg) ));\n\
			result = vec4( result.xyz*pow((1.-fg),2.)+ smooth, 1.); ')
			.BuildMaterial(scene);
		plan.material.setVector2('plansize',{x:200,y:200})
       plan.material.setVector2('gridSize',{x:1000,y:1000})
         plan.material.setVector2('smoothPower',{x:0.9,y:2.8})

 smoothPower
x : [0< x < 1.]  => 0 no smooth  .. 1 : no Grid
y : [1. < y < ... ] =>  1. : liner smooth , 2.8   arc smooth

http://www.babylonjs-playground.com/#Q87ZR#4

Link to comment
Share on other sites

21 hours ago, NasimiAsl said:

hi 

may be this help 

i use shader for tile generator 

http://www.babylonjs-playground.com/#Q87ZR#2  100x200   without smooth

http://www.babylonjs-playground.com/#Q87ZR#3  1000x1000 smooth


var plan = BABYLON.Mesh.CreateGround("a", 200, 200, 1, scene);
		plan.material = new BABYLONX.ShaderBuilder()
		    .SetUniform('plansize','vec2')
            .SetUniform('gridSize','vec2')
            .SetUniform('smoothPower','vec2')
            .InLine('float fg = length(pos-camera)/60. ;\n\
			float smooth_px = ((sin(pos.x*(1./plansize.x)*gridSize.x *3.141592)));\n\
			float smooth_pz = ((sin(pos.z*(1./plansize.y)*gridSize.y *3.141592)));\n\
		    float px = abs(floor(sin(pos.x*(1./plansize.x)*gridSize.x *3.141592)));\n\
			float pz = abs(floor(sin(pos.z*(1./plansize.y)*gridSize.y *3.141592)));\n\
		    if(px+pz > 1.95 || px+pz < 0.05 ) result = vec4(1.); \n\
			else result = vec4(0.);\n\
			fg = min(smoothPower.x,max(0.,pow(fg,0.5)*smoothPower.y));\n\
		    vec3 smooth = vec3((pow(smooth_px *smooth_pz,0.8)*(1.-fg) ));\n\
			result = vec4( result.xyz*pow((1.-fg),2.)+ smooth, 1.); ')
			.BuildMaterial(scene);
		plan.material.setVector2('plansize',{x:200,y:200})
       plan.material.setVector2('gridSize',{x:1000,y:1000})
         plan.material.setVector2('smoothPower',{x:0.9,y:2.8})

 smoothPower
x : [0< x < 1.]  => 0 no smooth  .. 1 : no Grid
y : [1. < y < ... ] =>  1. : liner smooth , 2.8   arc smooth

http://www.babylonjs-playground.com/#Q87ZR#4

This one has almost 60 fps! Thanks a lot!

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