Open JaouadROS opened 3 months ago
First of, I don't think you have to call vis.poll_events()
, vis.update_renderer()
and vis.update_geometry(obj_mesh)
in the callback function.
Calling vis.run()
already does this for you:
https://github.com/isl-org/Open3D/blob/f02e7d24ea115e716445a7fae5093bce60a37d20/cpp/open3d/visualization/visualizer/Visualizer.cpp#L274-L288
But you should return True
or False
to signal if UpdateGeometry()
needs to be called.
I think if you just want to rotate once, you could just add an if
in the callback:
target_rotation = 10
applied_rotation = 0
def update(vis):
global obj_mesh, target_rotation, applied_rotation
if applied_rotation < target_rotation:
applied_rotation += 10
obj_mesh.rotate(o3d.geometry.get_rotation_matrix_from_xyz(np.radians([10, 0, 0])), center=[0, 0, 0])
return True
return False
This is just a quick and dirty way to make it rotate just once.
You might want to extend on this by having a list of poses and a current index, and then in each update-call apply the pose at the current index and increment the index. That way you could apply a list of movements.
Also, you might want to use the current time and update only every x msecs to control the speed of animation. Interpolation between poses might also be of interest for smooth transitions.
Note that I never used the animation callback, but this is just some ideas how I would try to do it. Hope my ideas help you with this. :)
Thank you for your time.
I don't have a list of poses because I do generate poses inside update function and they are changing at every frame of the animation. What I found as a solution is to re apply the initial vertices at the beginning of the update function:
# Initialize the initial vertices
initial_obj_mesh_vertices = np.asarray(obj_mesh.vertices).copy()
# and reply them in the update
obj_mesh.vertices = o3d.utility.Vector3dVector(initial_obj_mesh_vertices)
obj_mesh.compute_vertex_normals()
But I'm still looking for a different way to do it. Ideally, I want to be able to apply the transformation with respect to a fixed reference frame. So that way no matter how many times I apply the transformation, it will be the same and it won't be an accumulated one.
Checklist
main
branch).My Question
I want to apply a simple rotation to my 3D model, say 10° pitch, with respect to the recent rotation only once but the model keeps rotating indefinitely. I tried using rotation matrix in a transformation but I get the same issue.
Later I want to be able to generate a pose (rotation+translation) from the video processing and apply it the 3D model.
Here is an example code: