BlenderCN论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1763|回复: 1

blender权威指南关于operator集成教程章节在2.63版本上运行情况

[复制链接]
发表于 2013-2-17 22:11:22 | 显示全部楼层 |阅读模式
还是有一些改动,参考了其它的一些代码,最后成功运行的代码如下
bl_info = {
    "name" : "Tetrahedron Object",
    "author" : "mobilefzb",
    "version" : (0,1),
    "blender" : (2,6,3),
    "location" : "View3D > Add > Mesh > Tetrahedron Object",
    "description" : "Adds a new Tetrahedron",
    "warning" : "",
    "wiki_url" : "",
    "tracker_url" : "",
    "category" : "Add Mesh"
}

import bpy
from bpy.types import Operator
from bpy.props import FloatVectorProperty
from bpy_extras.object_utils import AddObjectHelper,object_data_add
import math
import mathutils

def add_tetrahedron(self,context) :
    Vertices = [
        mathutils.Vector((0,-1 / math.sqrt(3),0)),
        mathutils.Vector((0.5,1 / (2 * math.sqrt(3)),0)),
        mathutils.Vector((-0.5,1 / (2 * math.sqrt(3)),0)),
        mathutils.Vector((0,0,math.sqrt(2 / 3)))
    ]
   
    NewMesh = bpy.data.meshes.new("Terahedron")
    NewMesh.from_pydata \
    (
        Vertices,
        [],
        [[0,1,2],[0,1,3],[1,2,3],[2,0,3]]
    )
    #these code maybe replaced with object_data_data
    #NewMesh.update()
    #NewObj = bpy.data.objects.new("Tetrahedron",NewMesh)
    #context.scene.objects.link(NewObj)
    #return {"FINISHED"}
    object_data_add(context,NewMesh,operator = self)

class OBJECT_OT_add_tetrahedron(Operator,AddObjectHelper) :
    '''add a tetrahedron'''
    bl_idname = "mesh.add_tetrahedron"
    bl_label = "Add Mesh tetrahedron"
    bl_description = "Create a new Mesh tetrahedron"
    bl_options = {'REGISTER','UNDO'}
   
    def execute(self,context) :
        add_tetrahedron(self,context)
        return {"FINISHED"}
   
def add_object_button(self,context) :
    self.layout.operator(
        OBJECT_OT_add_tetrahedron.bl_idname,
        text = "Add tetrahedron",
        icon = "PLUGIN")

class OBJECT_PT_Panel(bpy.types.Panel) :
    bl_label = "Add Tetrahedron"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"
   
    def draw_header(self,context) :
        layout = self.layout
        layout.label(text = "",icon = "PHYSICS")
    def draw(self,context) :
        row = self.layout.column(align = True)
        row.operator("mesh.add_tetrahedron",text = "Add Tetrahedron")

def register() :
    bpy.utils.register_class(OBJECT_OT_add_tetrahedron)
    bpy.types.INFO_MT_mesh_add.append(add_object_button)
    bpy.utils.register_class(OBJECT_PT_Panel)
   
def unregister() :
    bpy.utils.unregister_class(OBJECT_OT_add_tetrahedron)
    bpy.types.INFO_MT_mesh_add.remove(add_object_button)
    bpy.utils.unregister_class(OBJECT_PT_Panel)
   
if __name__ == "__main__" :
    register()

关键还是一些注册流程发生的了变化

 楼主| 发表于 2013-2-17 22:12:53 | 显示全部楼层
是书上p436页的部分
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

Blender最新中文教学视频|Blender头条|小黑屋|手机版|Archiver|Blender中国 ( 蜀ICP备17002929号 )360网站安全检测平台

GMT+8, 2019-9-16 13:20 , Processed in 0.048863 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表