# 3d grid/matrix inside a mesh

Hi All,

I’m trying to create a matrix/grid inside a 3D mesh.

I can create grids, i can create random points inside meshes and colliders, I can even slice the grids using a plane… but I’m having trouble combining the 2.

I’m trying to create an environment where I can get any 3D mesh (Any shape/design/3D file format) and then create a series of 3D points inside it at a given distance from each other.

And obviously only have the points that are inside the mesh, removing the others.

I’ve looked into Octree and just found out about KDtree but really not sure i need to get that complicated.

Does anyone know how I can achieve this, how would you go about doing this?

Not looking for code or anything, just direction.

Sorry but I think I’m not really sure what you’re actually asking here. A grid is a rather abstract concept. It could be simply snapping points to the closest grid point, it could be about drawing grid lines. This part:

I’m trying to create an environment
where I can get any 3D mesh (Any
shape/design/3D file format) and then
create a series of 3D points inside it
at a given distance from each other.

And obviously only have the points
that are inside the mesh, removing the
others.

sounds more like you’re looking for generating point cloud data and / or working on boolean operations (CSG). To me it sounds like you don’t really sure what you actually want or that you have trouble explaining it Maybe it’s just me not understanding it.

KD-trees and octrees are just a way for space partitioning to speed up searching for things inside the tree.

To me it’s still not clear if you actually want to work with 3d meshes or if you’re just interested in getting the points inside them (for whatever reasons). Since you talked about arbitrary meshes I’d like to note that a mesh in general does not really represent any volume as a mesh only defines the surface. A mesh does not need to be closed. So if you’re thinking about CSG there’s not always a reasonable way to construct a logical volume out of surface meshes. While the logic behind CSG is relatively simple, implementing them is much harder. When you want to implement boolean operation between 3d meshes there are many edge cases which can drive you mad, believe me Under the hood it’s just basic geometry / maths / equations.