Jump to content

GridMaterial - Intersect action


rdzar
 Share

Recommended Posts

I've been playing with creating a grid for a while now, and I found out the latest alpha provides a nice one. Love it, a performance I'm not able to create with mass-meshes or lines.

But.. for this use-case I'm searching for a way to know the exact position within that grid, so I'm able to hover a active-tile mesh on it. As I'm trying to use the grid, as a real grid. The GridMaterial provides no actions as far as I could find for this and I was wondering, is there any other way to make this work that I just didn't think of?

Thanks in advance!

 

(BTW using OnIntersectionEnterTrigger errors on the grid)

https://www.babylonjs-playground.com/#83YJIL#1

Link to comment
Share on other sites

On 7/14/2017 at 1:39 AM, Pryme8 said:

grid material, then Math.floor the position/unit size
 

so
var x,y;
x=Math.floor(pick.x/unitSize);
z=Math.floor(pick.z/unitSize);

and if you want the middle not the 0,0 point of the unit then add half the unit size back.

 

Mmm, this would work of I'm on the 2D side If I'm understanding correct? But with 3D and Camera Panning this is going to be pretty interesting. As the meshes is too much, I'm dropping FPS like crazy with them using pick & subMeshId so still figuring out a way to find the tile location without adding a thousand SubMeshes :)

 

-----

Ok; solved kinda based of this ^. For future reference / search engine. To retrieve mouse position within the grid without using SubMeshes and keep them 60FPS rolling;

// Subtract ground from pickedPoint (after mesh check)
const subtractedPoint = pickResult.pickedPoint.subtract(ground.position);

// Calculate X & Y (where tiles.w and tiles.h are the TiledGround W&H, e.g. 20-20)
const x = tiles.w - Math.floor(subtractedPoint.x / tileHeightWidth);
const y = tiles.h - Math.floor(subtractedPoint.z / tileHeightWidth); // z == depth === y

// To use the x & y position to be on the 0,0 point correct it from the TiledGroundCenter e.g.
x = -x + 250; // 250 = half of example 500w TiledGround
z = -y;

image.png
 

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