Читаем Введение в написание скриптов на Питоне для Блендера 2.5x. Примеры кода полностью

                        angle = sign*float(words[m])*Deg2Rad

                        mats.append(Matrix.Rotation(angle, 3, axis))

                        m += 1

                    mat = node.inverse * mats[0] * mats[1] * mats[2] * node.matrix

                    pb.rotation_quaternion = mat.to_quaternion()

                    for n in range(4):

                        pb.keyframe_insert('rotation_quaternion',

                                          index=n, frame=frame, group=name)

    return 


#

# initSceneProperties(scn):

#  


def initSceneProperties(scn):

    bpy.types.Scene.MyBvhRot90 = bpy.props.BoolProperty(

        name="Rotate 90 degrees",

        description="Rotate the armature to make Z point up")

    scn['MyBvhRot90'] = True


    bpy.types.Scene.MyBvhScale = bpy.props.FloatProperty(

        name="Scale",

        default = 1.0,

        min = 0.01,

        max = 100)

    scn['MyBvhScale'] = 1.0  


initSceneProperties(bpy.context.scene)  


#

# class BvhImportPanel(bpy.types.Panel):


class BvhImportPanel(bpy.types.Panel):

    bl_label = "BVH import"

    bl_space_type = "VIEW_3D"

    bl_region_type = "UI" 


    def draw(self, context):

        self.layout.prop(context.scene, "MyBvhRot90")

        self.layout.prop(context.scene, "MyBvhScale")

        self.layout.operator("simple_bvh.load") 


#

# class OBJECT_OT_LoadBvhButton(bpy.types.Operator, ImportHelper):


class OBJECT_OT_LoadBvhButton(bpy.types.Operator, ImportHelper):

    bl_idname = "simple_bvh.load"

    bl_label = "Load BVH file (.bvh)" 


    # From ImportHelper. Filter filenames.

    filename_ext = ".bvh"

    filter_glob = bpy.props.StringProperty(default="*.bvh", options={'HIDDEN'})


    filepath = bpy.props.StringProperty(name="File Path",

        maxlen=1024, default="")  


    def execute(self, context):

        import bpy, os

        readBvhFile(context, self.properties.filepath,

            context.scene.MyBvhRot90, context.scene.MyBvhScale)

        return{'FINISHED'}  


    def invoke(self, context, event):

        context.window_manager.fileselect_add(self)

        return {'RUNNING_MODAL'}  


#

# Registration


def menu_func(self, context):

    self.layout.operator("simple_bvh.load", text="Simple BVH (.bvh)...")  


def register():

    bpy.utils.register_module(__name__)

    bpy.types.INFO_MT_file_import.append(menu_func)  


def unregister():

    bpy.utils.unregister_module(__name__)

    bpy.types.INFO_MT_file_import.remove(menu_func)  


if __name__ == "__main__":

    try:

        unregister()

    except:

        pass

    register()



Многофайловые пакеты

Пакеты — это способ структурирования пространства имен модулей Питона, используя "точечную нотацию имен модулей". Например, имя модуля A.B определяет подмодуль с именем B в пакете с именем A. Точно так же как использование модулей спасает авторов различных модулей от необходимости беспокоиться о существовании совпадающих глобальных имен переменных, использование точечной нотации имен модулей спасает авторов многомодульных пакетов от необходимости волноваться о совпадающих именах модулей. За дополнительной информацией о пакетах Питона, пожалуйста, обратитесь к документации на пакеты Питона

Перейти на страницу:

Похожие книги