Takunojiの日記

自分が勉強したプログラム技術メモ

Blender Python Basic 〜 テクスチャサンプルコード 〜

グレースペンシル

gp = bpy.context.scene.grease_pencil

 

点の追加2

mport bpy, bmesh

obj = bpy.context.object
me = obj.data
bm = bmesh.from_edit_mesh(me)

v1 = bm.verts.new*1
v2 = bm.verts.new*2
v3 = bm.verts.new*3

bm.faces.new*4

bmesh.update_edit_mesh(obj.data)

点の追加
First of all you have to create a object and a mesh, after that you can add the vertex to it:

# name: string for new object name
# verts: array of position coords - [(-1.0, 1.0, 0.0), (-1.0, -1.0, 0.0)]

def create_Vertices (name, verts):
# Create mesh and object
me = bpy.data.meshes.new(name+'Mesh')
ob = bpy.data.objects.new(name, me)
ob.show_name = True
# Link object to scene
bpy.context.scene.objects.link(ob)
me.from_pydata(verts, , )
# Update mesh with new data
me.update()

 

テクスチャ関連

Materials/Textures – mapping — PyMove3D

# new texture, テクスチャ取得→イメージ取得と読み込み→テクスチャに貼り付け

    texUV = bpy.data.textures.new(texname, type="IMAGE")

    image_path = os.path.expanduser("//wuerfelbilder/blume.jpg")

    image = bpy.data.images.load(image_path)

    texUV.image = image

 # connect textur with material
    マテリアル作成、テクスチャを設定、プロパティの設定(要調査)

    bpy.data.materials[matname].texture_slots.add()

    bpy.data.materials[matname].active_texture = texUV

    bpy.data.materials[matname].texture_slots[0].texture_coords = "GLOBAL"

    bpy.data.materials[matname].texture_slots[0].mapping = "CUBE"

# escape edit mode

    if bpy.ops.object.mode_set.poll():

        bpy.ops.object.mode_set(mode='OBJECT')



    # delete all mesh objects

    bpy.ops.object.select_by_type(type='MESH')

    bpy.ops.object.delete()



    # delete all materials

    for i in bpy.data.materials.values():

        bpy.data.materials.remove(i)



    # delete all textures

    for i in bpy.data.textures.values():

        bpy.data.textures.remove(i)
    # new texture

        texUV = bpy.data.textures.new(namen[i][1], type="IMAGE")

        image_path = os.path.expanduser("//wuerfelbilder/{}".format(i))

        image = bpy.data.images.load(image_path)

        texUV.image = image



  # connect texture with material

        bpy.data.materials[matname].texture_slots.add()

        bpy.data.materials[matname].active_texture = texUV

        bpy.data.materials[matname].texture_slots[0].texture_coords = "ORCO"

        bpy.data.materials[matname].texture_slots[0].mapping = "CUBE"

*1:2.0, 2.0, 2.0

*2:-2.0, 2.0, 2.0

*3:-2.0, -2.0, 2.0

*4:v1, v2, v3