With the following code
def weight_from_distance( scene ):
floor = bpy.data.objects['GridGrass']
cam = bpy.data.objects['Camera']
vert_distances = [
( cam.location - floor.matrix_world @ v.co ).length for v in floor.data.vertices
]
maxDist = max( vert_distances )
minDist = min( vert_distances )
for i, d in enumerate( vert_distances ):
# Normalize distance and set as vertex weight
floor.data.vertices[i].groups[0].weight = ( d - minDist ) / ( maxDist - minDist ) #Line 16
pSysName = 'ParticleSystem'
vertGroupName = 'GrassGrowth'
floor.particle_systems[ pSysName ].vertex_group_density = vertGroupName # Update / Refresh
I get an error
Which seems to be saying that my mesh has no vertices, even though it is a huge terrain mesh with thousands of vertices?
Here's my terrain. It may be worth noting that it's a Grid.