How to position instances of a mesh in to any format

how to position instances of a mesh in to any format such as having the instances on a plane and shape the instances in a hexagon

Your question is somewhat not clear to me. One of the possible interpretations is: how to position individual instances of a mesh, so that each instance has its own position. If this is your question, look at this example, which positions 8 instances in an octagonal formation:


what i meant was how would i be able to instance grass mesh or shader with accurate positioning on a plane, similar to if i imported a house glb file and wanted grass instances around it,

this post was close by using vertex painting in blender but was not very clear on how to achieve it exactly.

If you plan to use MeshSurfaceSampler and you want to exclude the area where the house is, you should do this:

  • pick an attribute that keeps weights of every vertex in the mesh
  • let the sampler know what is the name of this attribute (setWeightAttribute)
  • set the weight 0 for each vertex under the house , and 1 to each vertex around the house
  • build an internal “map” of allowed and forbidden areas (build)
  • and then you can pick random positions in the allowed areas (sample)

I’m afraid that I do not understand your question again. Maybe someone could be more helpful

1 Like

As @PavelBoytchev has mentioned you need to use the surface sampler, here’s some example code to put you in the correct direction…

sampler = new MeshSurfaceSampler( groundobj )
.setWeightAttribute( 'color' )
for ( let i = 0; i < instanceCount; i ++ ) {
  sampler.sample( position ); 
  InstanceMesh.setMatrixAt( i, dummy.matrix)
  InstanceMesh.instanceMatrix.needsUpdate = true;

thank you!