In my addon I draw some thing and as a optimization, to not recalculate what to draw each frame I have 2 checks:
- I save
object.matrix_worldand then compare saved matrix with current > if they are different I go to recalculate without checking mesh.
- If matrices are same I go check mesh. I use API instrument
data.vertices.foreach_get()(thanks to kkar for advise) as fast way to store vertices coordinates data inside numpy array. I compare then saved array with current newly created and if they same I do not recalculate what to draw.
Numpy work really fast, comparing those two arrays go really fast. But this optimization is still slow (at least it not fits my expectations) because each time I again ang again do this
vertices.foreach_get() and write coordinates to new empty numpy array to compare it… and this step is not fast enough. In edit mode it even slower because
bmesh has no
vertices.foreach_get() so I have to do
object.update_from_editmode() and only then do
vertices.foreach_get() (writing coordinates by extracting
for v in data.vertices loop work even slower).
I noticed how Blender work with high poly meshes when entering edit mode. First going some lag and then it go absolutely smooth and fast, untill any mesh editing begin. I think some check has to exist to know if it need to just stay idle or start recalculate mesh.
So here is the question - do anyone have any ideas of better (faster) ways to check is mesh same as in previous frame or different? (by using Python API of course)
I feel like I made some not bad but pretty dumb solution… it work pretty well for low/mid poly models, it sucks hard on high poly.
It has to exist something better and faster. Maybe exist some way to store mesh data in variable and then compare it with new data as just two pieces of bytes in memory, without necessity to dig through each vertex coordinates and compare thousandths of floats to find difference.