0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Blender内from_pydata()を使用して点と線を登録する方法

Last updated at Posted at 2020-10-22

スクリプトを用いて頂点、辺を作成する

bpyのblender用pythonのライブラリを使用して頂点、辺を作成するコードは下記となります。こちらのコードはblenderを起動し、text editor内に貼り付けて実行しました。

blender.py
import bpy

# points for 1st mesh
verts_1 = []
verts_1.extend([[-1,1,0],[1,1,0],[1,-1,0],[-1,-1,0]])

# points for 2nd mesh
verts_2 = []
verts_2.append([-2,2,0])
verts_2.append([2,2,0])
verts_2.append([2,-2,0])
verts_2.append([-2,-2,0])

# edges for 2nd mesh
edges_2 = []
edges_2.extend([[0,1],[1,2],[2,3],[3,0]])

# create new 1st mesh 
n_mesh_1 = bpy.data.meshes.new("new_mesh_1")
# create new object and link 1st mesh to object
ob_1 = bpy.data.objects.new("new_object_1",n_mesh_1)
# link object to scene
bpy.context.collection.objects.link(ob_1)

# update mesh data from given points
n_mesh_1.from_pydata(verts_1,[],[])
n_mesh_1.update()

# create new 2nd mesh 
n_mesh_2 = bpy.data.meshes.new("new_mesh_2")
# create new object and link 2nd mesh to object
ob_2 = bpy.data.objects.new("new_object_2",n_mesh_2)
# link object to scene
bpy.context.collection.objects.link(ob_2)

# update mesh data from given points
n_mesh_2.from_pydata(verts_2,edges_2,[])
n_mesh_2.update()

verts_1,verts_2は頂点XYZ座標を配列として格納します。
edges_2は頂点(verts_2の配列番号)を指定して辺の情報を格納します。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?