Code optimization results in twice the fps when running 20 objects. Results may vary.
Initial draw in gen_mesh turns out to be not needed. Editor and runtime functionality not influenced by it.
Array.pushback performs a resize every time which is expensive. Exchanged for one resize and directly set the value at a specific place.
Two expensive operations can still be improved:
Ref<ArrayMesh> array_mesh = Ref<ArrayMesh>(memnew(ArrayMesh)); drops fps by half
array_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, as); is also expensive
Code optimization results in twice the fps when running 20 objects. Results may vary.
Initial draw in gen_mesh turns out to be not needed. Editor and runtime functionality not influenced by it.
Array.pushback performs a resize every time which is expensive. Exchanged for one resize and directly set the value at a specific place.
Two expensive operations can still be improved:
Ref<ArrayMesh> array_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
drops fps by halfarray_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, as);
is also expensive