Hello, I try to insert the 3d grass around the player and removed when the player is too far.
But my program is not optimized…
Are you there a more optimized way to do this ? Is there already a specialized API you ?
after I want to dynamically insert 3d grass, 3d tree…etc and remove when player is too far.
VegetationMatrice = [ * VisibilityVegetation for _ in range(VisibilityVegetation)]
for i in range(0, VisibilityVegetation):
for j in range(0, VisibilityVegetation):
m = loader.loadModel("resources/grass/grass.obj")
min, max = m.getTightBounds()
size = max-min
m.setPos(x, y, 0)
m.setPos(pos2, pos2, height)
The most efficient method to render vegetation is probably using instancing combined with some LOD algorithm.
As for that, I also have some code lying arround, but its outdated and won’t work anymore, so it would be quite some work to make it running again.
Yes, you can do so by calling model.set_instance_count(num_instances). However, you will have to write a shader then which positions your objects (since they otherwise will be all at the same position).
In your shader you can access the current instance id with gl_InstanceID. You would have to pass some sort of array (e.g. a PTALVecBase3f storing positions of the instances) as shader input, and use that in the shader then.