Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

How can I apply a transformation only once in open3D

Open JaouadROS opened this issue 6 months ago • 2 comments

Checklist

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:

from colorama import init
import numpy as np
import open3d as o3d
import cv2

# Paths to the 3D object and video file
obj_path = "Compressor HD.obj"

# Callback function to update the texture of the plane with video frames
def update(vis):
    global obj_mesh, initial_rotation

    obj_mesh.rotate(o3d.geometry.get_rotation_matrix_from_xyz(np.radians([10, 0, 0])), center=[0, 0, 0])

    vis.update_geometry(obj_mesh)
    vis.poll_events()
    vis.update_renderer()
    return False

if __name__ == "__main__":

    vis = o3d.visualization.VisualizerWithKeyCallback()
    vis.create_window()

    # Load and add the 3D object to the scene
    obj_mesh = o3d.io.read_triangle_mesh(obj_path)
    obj_mesh.compute_vertex_normals()
    vis.add_geometry(obj_mesh)

    initial_rotation = obj_mesh.get_rotation_matrix_from_xyz([0, 0, 0])

    # Create and add coordinate frame
    axis_length = 200 
    coordinate_frame = o3d.geometry.TriangleMesh.create_coordinate_frame(size=axis_length, origin=[0, 0, 0])
    vis.add_geometry(coordinate_frame)

    # Register callback to update video frame texture
    vis.register_animation_callback(update)

    vis.run()
    vis.destroy_window()
    cv2.destroyAllWindows()

JaouadROS avatar Jul 25 '24 20:07 JaouadROS