Blender3D 中的对象方法?

Object methods in Blender3D?

我进入 Blender 的 python API 大约 30 分钟,我一直在阅读文档。也许我看起来不够努力,但从我所看到的,我不能只将一个对象(如 ico_sphere)分配给一个名为 Sphere 的变量,然后只修改它的属性方法?

import bpy

bpy.ops.object.select_all(action="SELECT")
bpy.ops.object.delete()

Sphere = bpy.ops.mesh.primitive_ico_sphere_add(location=[0,0,0])

# Does something like this work?
Sphere.set_color('red')

我做了很多 matplotlib 我想知道 bpy 是否有类似的面向对象的接口?

在 blender 中,运算符 returns 状态,通常是 {'FINISHED'}

在 运行 添加对象运算符后,可以在 bpy.context.object 中找到新对象。

bpy.ops.mesh.primitive_ico_sphere_add(location=[0,0,0])
Sphere = bpy.context.object
Sphere.location = (1,2,3)
Sphere.active_material = bpy.data.materials.new('mymat')
Sphere.active_material.diffuse_color = (1,0,0,1)

请注意,基于节点的材质需要更多工作。有一个 Blender 特定的 SE 站点,您可以在其中找到一些脚本示例,例如 this.