【Blender×Python】辺データをメッシュデータから取得する方法について徹底解説

Blender

「bpy」とは、PythonからBlenderの機能を呼び出すことができるBlender Python APIのことです。Blenderはオープンソースの3Dアニメーションソフトウェアであり、「bpy」を使うことでBlenderの様々な機能をPythonスクリプトから呼び出して利用することができます。本記事では、「bpy」を用いた辺データをメッシュデータから取得する方法を紹介します。

# edgesプロパティによるメッシュデータを用いた辺データの取得
"Mesh".edges

下記の様な内容で悩んでいる/困っている場合に使える方法を参考までにご共有させて頂きます。

・Blender上で、どの様にPythonを使うの?
・Blender上のPythonで、どの様に辺データをメッシュデータから取得するの?

また、「bpy」を使用する上で基礎的な情報は下記の記事で紹介しております。
他の「bpy」のクラスや関数について気になる方はこちらの記事をご覧ください。

edgesプロパティによるメッシュデータを用いた辺データの取得

“Mesh”.edgesプロパティの基本構文

"Mesh".edges
→ MeshEdges: bpy_prop_collection

“Mesh”.edgesプロパティの使い方

import bpy

CubeMesh = bpy.data.meshes["Cube"]
CubeMeshEdges = CubeMesh.edges

for key, value in CubeMeshEdges.items():
    print(f"[{key}] {value}, {value.index}, {value.vertices}, {[vertex_id for vertex_id in value.vertices]}")
Cube Mesh Edges:
<bpy_collection[12], MeshEdges> <class 'bpy_prop_collection'>
[0] <bpy_struct, MeshEdge at 0x000001A03770A848>, 0, <bpy_int[2], MeshEdge.vertices>, [2, 0]
[1] <bpy_struct, MeshEdge at 0x000001A03770A854>, 1, <bpy_int[2], MeshEdge.vertices>, [0, 1]
[2] <bpy_struct, MeshEdge at 0x000001A03770A860>, 2, <bpy_int[2], MeshEdge.vertices>, [1, 3]
[3] <bpy_struct, MeshEdge at 0x000001A03770A86C>, 3, <bpy_int[2], MeshEdge.vertices>, [3, 2]
[4] <bpy_struct, MeshEdge at 0x000001A03770A878>, 4, <bpy_int[2], MeshEdge.vertices>, [6, 2]
[5] <bpy_struct, MeshEdge at 0x000001A03770A884>, 5, <bpy_int[2], MeshEdge.vertices>, [3, 7]
[6] <bpy_struct, MeshEdge at 0x000001A03770A890>, 6, <bpy_int[2], MeshEdge.vertices>, [7, 6]
[7] <bpy_struct, MeshEdge at 0x000001A03770A89C>, 7, <bpy_int[2], MeshEdge.vertices>, [4, 6]
[8] <bpy_struct, MeshEdge at 0x000001A03770A8A8>, 8, <bpy_int[2], MeshEdge.vertices>, [7, 5]
[9] <bpy_struct, MeshEdge at 0x000001A03770A8B4>, 9, <bpy_int[2], MeshEdge.vertices>, [5, 4]
[10] <bpy_struct, MeshEdge at 0x000001A03770A8C0>, 10, <bpy_int[2], MeshEdge.vertices>, [0, 4]
[11] <bpy_struct, MeshEdge at 0x000001A03770A8CC>, 11, <bpy_int[2], MeshEdge.vertices>, [5, 1]

まとめ

「bpy」(Blender Python API)は、Pythonを使ったBlenderの開発に非常に役立ちます。この記事では、辺データをメッシュデータから取得する方法を紹介しました。ぜひ活用してみてください。

関連検索ワード

How to get an edge data from mesh data?

関連キーワード

blender, python, get, edge, mesh, 取得, 辺, メッシュ

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny