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

    def invoke(self, context, event):

        context.window_manager.fileselect_add(self)

        return {'RUNNING_MODAL'}  


#

# Меню Export


class EXPORT_OT_simple_obj(bpy.types.Operator, ExportHelper):

    bl_idname = "io_export_scene.simple_obj"

    bl_description = 'Export from simple OBJ file format (.obj)'

    bl_label = "Export simple OBJ"

    bl_space_type = "PROPERTIES"

    bl_region_type = "WINDOW" 


    # Из ExportHelper. Фильтрация имён файлов.

    filename_ext = ".obj"

    filter_glob = StringProperty(default="*.obj", options={'HIDDEN'})


    filepath = bpy.props.StringProperty(

        name="File Path",

        description="File path used for exporting the simple OBJ file",

        maxlen= 1024, default= "")


    rot90 = bpy.props.BoolProperty(

        name = "Rotate 90 degrees",

        description="Rotate mesh to Y up",

        default = True)


    scale = bpy.props.FloatProperty(

        name = "Scale",

        description="Scale mesh",

        default = 0.1, min = 0.001, max = 1000.0)  


    def execute(self, context):

        print("Load", self.properties.filepath)

        from . import simple_obj_export

        simple_obj_export.export_simple_obj(

            self.properties.filepath,

            context.object,

            self.rot90,

            1.0/self.scale)

 return {'FINISHED'}  


    def invoke(self, context, event):

        context.window_manager.fileselect_add(self)

        return {'RUNNING_MODAL'}  


#

# Регистрация


def menu_func_import(self, context):

    self.layout.operator(IMPORT_OT_simple_obj.bl_idname, text="Simple OBJ (.obj)...")  


def menu_func_export(self, context):

    self.layout.operator(EXPORT_OT_simple_obj.bl_idname, text="Simple OBJ (.obj)...")  


def register():

    bpy.utils.register_module(__name__)

    bpy.types.INFO_MT_file_import.append(menu_func_import)

    bpy.types.INFO_MT_file_export.append(menu_func_export)  


def unregister():

    bpy.utils.unregister_module(__name__)

    bpy.types.INFO_MT_file_import.remove(menu_func_import)

    bpy.types.INFO_MT_file_export.remove(menu_func_export)  


if __name__ == "__main__":

    register()




Симуляции

В этом разделе мы обращаемся к потенциалу симуляций Блендера из Питона. Некоторые из примеров были вдохновлены книгой Bounce, Tumble and Splash Тони Муллена (ищите в Сети великолепный перевод от Morthan'а, пользуясь случаем, передаю ему большое СПАСИБО! - прим. пер.). Однако, большинство рендеров не выглядят так же хорошо, как в книге Муллена, так как целью этих заметок не было найти оптимальный способ для настройки параметров, а скорее чтобы показать, как их можно настраивать из Питона.


Частицы

Эта программа добавляет две системы частиц.



#---------------------------------------------------

# File particle.py

#---------------------------------------------------

import bpy, mathutils, math

from mathutils import Vector, Matrix

from math import pi  


def run(origo):

    # Добавление меша эмиттера

    origin = Vector(origo)

    bpy.ops.mesh.primitive_plane_add(location=origin)

    emitter = bpy.context.object  


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

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