-----------
import open3d as o3d
import open3d.visualization.gui as gui
import open3d.visualization.rendering as rendering
import platform
class MainWindow_o3d:
def __init__(self):
self._id = 0
self.window = gui.Application.instance.create_window("open3d visualizer example", 1024, 768)
self.scene = gui.SceneWidget()
self.scene.scene = rendering.Open3DScene(self.window.renderer)
self.scene.scene.set_background([1, 1, 1, 1])
self.scene.scene.scene.set_sun_light(
[-1, -1, -1], # direction
[1, 1, 1], # color
100000) # intensity
self.scene.scene.scene.enable_sun_light(True)
bbox = o3d.geometry.AxisAlignedBoundingBox([-10, -10, -10],
[10, 10, 10])
self.scene.setup_camera(60, bbox, [0, 0, 0])
self.window.add_child(self.scene)
# 図形描画
self.func_draw_test()
def func_draw_test(self):
self.scene.scene.clear_geometry() # 画面クリア
# 点の座標データ
points = [[0, 0, 0], [10, 10, 10]]
colors = [[1, 0, 0], [0, 0, 1]] # 赤、青
# 点群オブジェクトの作成
pcd = o3d.geometry.PointCloud()
pcd.points = o3d.utility.Vector3dVector(points)
pcd.colors = o3d.utility.Vector3dVector(colors)
# シーンに点群を追加
material = rendering.MaterialRecord()
material.shader = "defaultUnlit"
self.scene.scene.add_geometry("Points", pcd, material)
# --- 面の追加 ---
# 面1 (XY平面) の頂点
vertices_plane1 = [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]]
triangles_plane1 = [[0, 1, 2], [2, 3, 0]] # 頂点のインデックスで面を作る
colors_plane1 = [[0, 1, 0]] # 緑
# 面1の作成
mesh_plane1 = o3d.geometry.TriangleMesh()
mesh_plane1.vertices = o3d.utility.Vector3dVector(vertices_plane1)
mesh_plane1.triangles = o3d.utility.Vector3iVector(triangles_plane1)
mesh_plane1.paint_uniform_color(colors_plane1[0])
# 面2 (YZ平面) の頂点
vertices_plane2 = [[0, 0, 0], [0, 10, 0], [0, 10, 10], [0, 0, 10]]
triangles_plane2 = [[0, 1, 2], [2, 3, 0]]
colors_plane2 = [[0, 0, 1]] # 青
# 面2の作成
mesh_plane2 = o3d.geometry.TriangleMesh()
mesh_plane2.vertices = o3d.utility.Vector3dVector(vertices_plane2)
mesh_plane2.triangles = o3d.utility.Vector3iVector(triangles_plane2)
mesh_plane2.paint_uniform_color(colors_plane2[0])
# シーンに面を追加
self.scene.scene.add_geometry("Plane1", mesh_plane1, material)
self.scene.scene.add_geometry("Plane2", mesh_plane2, material)
# --- XYZ軸の追加 ---
# 軸の長さ
axis_length = 15.0
# 座標軸を生成
axes = o3d.geometry.TriangleMesh.create_coordinate_frame(size=axis_length)
# シーンに軸を追加
self.scene.scene.add_geometry("Axes", axes, material)
def main():
gui.Application.instance.initialize()
MainWindow_o3d()
gui.Application.instance.run()
if __name__ == "__main__":
main()
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme