Closed jurekalfredo closed 2 years ago
You just need to make your code more efficient by reusing things. Every iteration, you're deleting all the old plots, rereading all meshes from file, then re-plotting them. Of course the frame rate is low!
Try instead setting the transform to the plot instead of the mesh. Example below. The important part is the line mesh.actor.SetUserMatrix(transform_to_vtk(pos))
.
import vtkplotlib as vpl
from stl.mesh import Mesh
import numpy as np
from vtkmodules.vtkCommonMath import vtkMatrix4x4
def transform_to_vtk(m):
out = vtkMatrix4x4()
for i in range(4):
for j in range(4):
out.SetElement(i, j, m[j, i])
return out
mesh = vpl.mesh_plot(Mesh.from_file(vpl.data.get_rabbit_stl()))
vpl.show(block=False)
vpl.gcf().camera.Zoom(.5)
pos = np.eye(4)
while 1:
pos[:3, :3] = Mesh.rotation_matrix([0, 0, -1], .1) @ pos[:3, :3]
mesh.actor.SetUserMatrix(transform_to_vtk(pos))
vpl.gcf().update()
vpl.show()
https://user-images.githubusercontent.com/41833946/175405754-41931bb9-967e-4b51-a4cd-018808843b3c.mp4
estoy trabajando en n simulador de robot de 6gdl pero no logro que los movimientos sean fluidos que es lo que estoy haciendo mal ????