0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Open3D : mesh にテクスチャをはる方法

Posted at

Open3Dでmeshにテクスチャをはる

  1. meshを作成する(読み込む)
  2. テクスチャの画像ファイルを読み込む
  3. マッピングを設定する

です。

import open3d as o3d
import numpy as np

# 適当にメッシュを作成する! 別に read_triangle_mesh で読み込んでもいいです
mesh = o3d.geometry.TriangleMesh()
mesh.vertices = o3d.utility.Vector3dVector([
    [0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0],
    [0, 0, 1], [1, 0, 1], [1, 1, 1], [0, 1, 1]
])
mesh.triangles = o3d.utility.Vector3iVector([
    [0, 1, 2], [2, 3, 0], [4, 5, 6], [6, 7, 4], [0, 1, 5], [5, 4, 0],
    [1, 2, 6], [6, 5, 1], [2, 3, 7], [7, 6, 2], [3, 0, 4], [4, 7, 3]
])
mesh.compute_vertex_normals()

##########################################
# テクスチャファイルを読み込む
texture = o3d.io.read_image("texture.png")
mesh.textures = [texture]

# マッピングを設定する
triangle_uvs = np.random.rand(len(mesh.triangles) * 3, 2)
mesh.triangle_uvs = o3d.utility.Vector2dVector(triangle_uvs)
mesh.triangle_material_ids = o3d.utility.IntVector([0]*len(mesh.triangles))

##########################################
# 描画する
o3d.visualization.draw_geometries([mesh])

使った画像はこういう感じ。

image.png

実行するとこう。

image.png

ぜんぜんマッピングの位置合わせなどはしていないので適当に貼られていますが、、、
とりあえず無事にはることが出来ます。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?