blender

I302 blender python LLM確認


 生成AIをつかって作業してみたログです。AI環境は、常に変化が起こっているのでログの意味でしかないかもしれません。料金の発生しない範囲と、ローカルLLMで行ってみます。(2025/03)
 ここではモデリングを行っていますが、編集するようなコードは、比較的作りやすいような感触があります。(過去実施

 作業性のため、VScode経由で行います。

Copilot

githubで提供されているCopilotを使用してみます。
(要:githubのアカウントと拡張機能のインストール)

GPT-4o(2025/03)

仕様を参照して、I302.pyにコードを作成してください。

仕様.txtに簡単な指示を書いて、参照させています。
blenderで開いているpythonファイルに入力して、保存、実行させます。

ファイル構成:
 仕様.txt
 I302.py

以下のテーブルを作成するblenderのpythonコードを作成してください。

4本脚のテーブル
天板のサイズ
幅:2
奥行:1
厚み:0.1
天板の下端の高さ:0.3

脚は任意に作成してください。
import bpy

def create_table():
    # テーブルの天板を作成
    bpy.ops.mesh.primitive_cube_add(size=2, location=(0, 0, 0.3 + 0.1 / 2))
    top = bpy.context.object
    top.scale[0] = 1  # 幅: 2 / 2
    top.scale[1] = 0.5  # 奥行: 1 / 2
    top.scale[2] = 0.05  # 厚み: 0.1 / 2

    # 脚の位置を定義
    leg_positions = [
        (0.9, 0.4, 0.15),
        (-0.9, 0.4, 0.15),
        (0.9, -0.4, 0.15),
        (-0.9, -0.4, 0.15)
    ]

    # 脚を作成
    for pos in leg_positions:
        bpy.ops.mesh.primitive_cube_add(size=0.1, location=pos)
        leg = bpy.context.object
        leg.scale[2] = 1.5  # 脚の高さ: 0.3 / 2

# 実行
create_table()

脚の位置関係がおかしいので、細かく指定したり、変数化して手動で修正可能にする必要がありそうです。

Gemini 2.0 Flash

同じ要領で、Gemini 2.0 Flash(2025/03)で行った場合です。

import bpy

def create_table(width, depth, thickness, leg_height):
    """4本脚のテーブルを作成します."""

    # 天板を作成
    bpy.ops.mesh.primitive_cube_add(size=1, enter_editmode=False, align='WORLD', location=(0, 0, leg_height + thickness / 2))
    table_top = bpy.context.object
    table_top.name = "TableTop"
    table_top.scale = (width / 2, depth / 2, thickness / 2)

    # 脚を作成
    leg_width = 0.1  # 脚の幅
    leg_depth = 0.1  # 脚の奥行き

    # 脚の位置
    leg1_x = width / 2 - leg_width / 2
    leg1_y = depth / 2 - leg_depth / 2
    leg2_x = -width / 2 + leg_width / 2
    leg2_y = depth / 2 - leg_depth / 2
    leg3_x = width / 2 - leg_width / 2
    leg3_y = -depth / 2 + leg_depth / 2
    leg4_x = -width / 2 + leg_width / 2
    leg4_y = -depth / 2 + leg_depth / 2

    # 脚を作成する関数
    def create_leg(x, y):
        bpy.ops.mesh.primitive_cube_add(size=1, enter_editmode=False, align='WORLD', location=(x, y, leg_height/2))
        leg = bpy.context.object
        leg.name = "TableLeg"
        leg.scale = (leg_width / 2, leg_depth / 2, leg_height/2)
        return leg

    # 4本の脚を作成
    leg1 = create_leg(leg1_x, leg1_y)
    leg2 = create_leg(leg2_x, leg2_y)
    leg3 = create_leg(leg3_x, leg3_y)
    leg4 = create_leg(leg4_x, leg4_y)

# テーブルのパラメータ
width = 2
depth = 1
thickness = 0.1
leg_height = 0.3

# テーブルを作成
create_table(width, depth, thickness, leg_height)

ローカルLLM

以下はローカルLLMで試した場合です。(2025/03)

上記のCopilotと同じ要領でおこなった場合です。確認は少数ですが、Copilotと比べて、訓練などが足りてないようです。

ローカルLLMについて

gemma-3-4b-it-GGUF/gemma-3-4b-it-Q4_K_M.gguf

import bpy

def create_table():
    """Creates a 4-leg table with specified dimensions."""

    # Define table parameters
    tabletop_width = 2.0
    tabletop_depth = 1.0
    tabletop_thickness = 0.1
    tabletop_bottom_height = 0.3

    # Create the tabletop
    bpy.ops.mesh.primitive_plane_add(size=1, enter_editmode=False, align='WORLD', location=(0, 0, 0))
    tabletop = bpy.context.object
    tabletop.name = "TableTop"
    tabletop.scale[0] = tabletop_width / 2  # Scale to desired width
    tabletop.scale[1] = tabletop_depth / 2 # Scale to desired depth
    tabletop.location[2] = tabletop_thickness / 2 # Adjust Z location for thickness

    # Create the table legs (4 identical legs)
    leg_length = tabletop_bottom_height + tabletop_thickness/2  # Height of leg including tabletop thickness
    for i in range(4):
        bpy.ops.mesh.primitive_cylinder_add(radius=0.1, depth=leg_length, enter_editmode=False, align='WORLD', location=(tabletop_width / 2 - 0.1, tabletop_depth / 2 - 0.1, 0))
        leg = bpy.context.object
        leg.name = f"Leg_{i+1}"
        leg.rotation_euler[0] = 1.5708 # Rotate 90 degrees around X axis for vertical position

    # Optionally, join the tabletop and legs (for easier manipulation)
    # bpy.ops.object.join()


# Execute the function to create the table
create_table()
天板が平面で、脚も4つ同じところに置かれています。

Llama 3 8b

コードにエラーがあり実行できませんでした。

import bpy
import mathutils

# Define the table dimensions
width = 2
depth = 1
thickness = 0.1
bottom_height = 0.3

# Create the table mesh
table_mesh = bpy.data.meshes.new('TableMesh')
table_mesh.from_pydata([
    (-width/2, -depth/2, bottom_height),
    (width/2, -depth/2, bottom_height),
    (width/2, depth/2, bottom_height),
    (-width/2, depth/2, bottom_height),
    (-width/2, -depth/2, 0),
    (width/2, -depth/2, 0),
    (width/2, depth/2, 0),
    (-width/2, depth/2, 0)
], [(0, 0, 0), (width, 0, 0), (width, depth, 0), (-width, depth, 0), (-width, -depth, 0), (0, -depth, 0), (0, depth, 0)])

# Create the legs
leg_mesh = bpy.data.meshes.new('LegMesh')
leg_mesh.from_pydata([
    (0, 0, 0),
    (1, 0, 0),
    (1, 1, 0),
    (0, 1, 0)
], [(0, 0, thickness), (1, 0, thickness), (1, 1, thickness), (0, 1, thickness)])

# Create the table object
table = bpy.data.objects.new('Table', table_mesh)

# Create the leg objects
leg1 = bpy.data.objects.new('Leg1', leg_mesh)
leg2 = bpy.data.objects.new('Leg2', leg_mesh)
leg3 = bpy.data.objects.new('Leg3', leg_mesh)
leg4 = bpy.data.objects.new('Leg4', leg_mesh)

# Position the legs
leg1.location = (0, -depth/2, bottom_height)
leg2.location = (width/2, -depth/2, bottom_height)
leg3.location = (-width/2, depth/2, bottom_height)
leg4.location = (width/2, depth/2, bottom_height)

# Parent the legs to the table
table.children.link(leg1)
table.children.link(leg2)
table.children.link(leg3)
table.children.link(leg4)

# Select and make the table object active
bpy.context.scene.collection.objects.link(table)
bpy.context.view_layer.objects.active = table

Qwen2.5 7B Instruct 1M

import bpy

def create_table():
    """Creates a 4-leg table with the specified dimensions."""

    # Define table parameters
    tabletop_width = 2.0
    tabletop_depth = 1.0
    tabletop_thickness = 0.1
    tabletop_bottom_height = 0.3

    # Create the tabletop
    bpy.ops.mesh.primitive_plane_add(size=1, enter_editmode=False, align='WORLD', location=(0, 0, 0))
    tabletop = bpy.context.object
    tabletop.name = "TableTop"
    tabletop.scale[0] = tabletop_width / 2  # Scale to desired width
    tabletop.scale[1] = tabletop_depth / 2 # Scale to desired depth
    tabletop.location[2] = tabletop_thickness / 2 # Move up to desired thickness

    # Create the table legs (4 identical legs)
    leg_length = tabletop_bottom_height + tabletop_thickness  # Length from bottom of tabletop to top of leg
    leg_width = 0.1
    leg_depth = 0.1

    for i in range(4):
        bpy.ops.mesh.primitive_cube_add(size=1, enter_editmode=False, align='WORLD', location=(tabletop_width / 2 - leg_width/2 + i * (tabletop_width / 2 + leg_width), tabletop_depth / 2 - leg_depth/2 ,leg_length))
        leg = bpy.context.object
        leg.name = f"Leg_{i+1}"
        leg.scale[0] = leg_width / 2
        leg.scale[1] = leg_depth / 2

    # Optionally, join the tabletop and legs for a single object (if desired)
    # bpy.ops.object.join()


# Execute the function to create the table
create_table()
天板が平面で、脚も4つ同じところに置かれています。

コメント