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

Blender

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

# materialsプロパティによるメッシュデータを用いたマテリアルデータの取得
"Mesh".materials

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

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

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

materialsプロパティによるメッシュデータを用いたマテリアルデータの取得

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

"Mesh".materials
→ IDMaterials: bpy_prop_collection

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

import bpy

SampleMesh    = bpy.data.meshes["Cube"]
MeshMaterials = SampleMesh.materials

print(f"Mesh Materials:\n{MeshMaterials} {type(MeshMaterials)}")
for key, value in MeshMaterials.items():
    print(f"[{key}] {value}")

MeshMaterialList = [MeshMaterial for MeshMaterial in MeshMaterials]
print(f"Mesh Material List:\n{MeshMaterialList}")
Mesh Materials:
<bpy_collection[1], IDMaterials> <class 'bpy_prop_collection'>
[Material] <bpy_struct, Material("Material") at 0x000001A043186208>
Mesh Material List:
[bpy.data.materials['Material']]

まとめ

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

関連検索ワード

How to get material data from mesh data?

関連キーワード

blender, python, get, material, 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