Find or define center point of submesh

Bit of a noob so please forgive the elementary question…

Using a slightly modified tiled ground example Playground:

I would like to find the center point of each submesh.
a) Currently when I inspect the submeshes in the console, there’s no info about their center points.
b) Calling getBoundingInfo() on a specific submesh only appears to return the bounding box and bounding sphere for the parent mesh.

  1. Is there any way to determine the centerpoint of each submesh individually?
  2. Or failing that, perhaps I would need to place a new Vector3 object for each centerpoint, but I still don’t know the coordinates to place those.

The end goal is to position a chess piece (an imported mesh not shown in the example) at the center of each submesh, ie on top of its proper square.

Hey there, welcome to the forum! :slight_smile:

One way is to use the grid size and number of rows and columns to calculate the center of each cell. Like below at line 60 I calculated the position for each piece (and also created a few more constants at line 18).

I’m not sure if there’s a straightforward way to get the subMesh’s bounding info e.g. with a simple function call, but maybe others will know about that. :beers:

After checking the source for subMesh it looks like the problem is that its property IsGlobal is being computed incorrectly in this case, which causes the function getBoundingInfo to return the mesh’s bounding info instead of the subMesh’s.

Okay here’s a PR to resolve the issue I think, by checking that the subMesh has all of the mesh’s indices too, not just all the vertices. :slight_smile:

Also here’s another PG that uses the PR build for testing. It uses each subMesh’s bounding info to put a sphere mesh in the center of the subMesh (moved up by half the sphere’s height).

(Without the PR the spheres are all in the center of the mesh since all the subMesh’s have the same bounding info as the mesh, like in the same PG here).


thanks a ton @Blake !

@Blake thanks for jumping on this so quickly. Your solution unblocked me (and also made it clear I didn’t really have much understanding about coordinates in general). Will track the PR as well.