armory/blender/props.py

89 lines
3.3 KiB
Python
Raw Normal View History

2015-12-02 00:05:20 +01:00
import shutil
import bpy
import os
import json
from bpy.types import Menu, Panel, UIList
from bpy.props import *
def cb_scene_update(context):
edit_obj = bpy.context.edit_object
if edit_obj is not None and edit_obj.is_updated_data is True:
edit_obj.geometry_cached = False
def initObjectProperties():
2016-01-11 16:03:55 +01:00
# For geometry
2015-12-02 00:05:20 +01:00
bpy.types.Object.geometry_cached = bpy.props.BoolProperty(name="Geometry cached", default=False)
bpy.types.Object.instanced_children = bpy.props.BoolProperty(name="Instanced children", default=False)
2016-01-11 16:03:55 +01:00
bpy.types.Object.custom_material = bpy.props.BoolProperty(name="Custom material", default=False)
bpy.types.Object.custom_material_name = bpy.props.StringProperty(name="Name", default="")
# For camera
bpy.types.Camera.frustum_culling = bpy.props.BoolProperty(name="Frustum Culling", default=False)
bpy.types.Camera.pipeline_path = bpy.props.StringProperty(name="Pipeline Path", default="pipeline_resource/forward_pipeline")
bpy.types.Camera.pipeline_pass = bpy.props.StringProperty(name="Pipeline Pass", default="forward")
# For material
2015-12-03 14:38:33 +01:00
bpy.types.Material.receive_shadow = bpy.props.BoolProperty(name="Receive shadow", default=True)
2015-12-05 14:52:31 +01:00
bpy.types.Material.alpha_test = bpy.props.BoolProperty(name="Alpha test", default=False)
2015-12-07 21:05:27 +01:00
bpy.types.Material.custom_shader = bpy.props.BoolProperty(name="Custom shader", default=False)
bpy.types.Material.custom_shader_name = bpy.props.StringProperty(name="Name", default="")
2015-12-02 00:05:20 +01:00
bpy.types.Material.export_tangents = bpy.props.BoolProperty(name="Export tangents", default=False)
2015-12-03 14:38:33 +01:00
# Menu in object region
2016-01-11 16:03:55 +01:00
class ObjectPropsPanel(bpy.types.Panel):
2015-12-02 00:05:20 +01:00
bl_label = "Cycles Props"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "object"
def draw(self, context):
layout = self.layout
obj = bpy.context.object
if obj.type == 'MESH':
layout.prop(obj, 'instanced_children')
2016-01-11 16:03:55 +01:00
layout.prop(obj, 'custom_material')
if obj.custom_material:
layout.prop(obj, 'custom_material_name')
# Menu in camera region
class DataPropsPanel(bpy.types.Panel):
bl_label = "Cycles Props"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "data"
def draw(self, context):
layout = self.layout
obj = bpy.context.object
if obj.type == 'CAMERA':
layout.prop(obj.data, 'frustum_culling')
layout.prop(obj.data, 'pipeline_path')
layout.prop(obj.data, 'pipeline_pass')
2015-12-02 00:05:20 +01:00
2015-12-03 14:38:33 +01:00
# Menu in materials region
class MatsPropsPanel(bpy.types.Panel):
bl_label = "Cycles Props"
bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW"
bl_context = "material"
def draw(self, context):
layout = self.layout
mat = bpy.context.material
layout.prop(mat, 'receive_shadow')
2015-12-05 14:52:31 +01:00
layout.prop(mat, 'alpha_test')
2015-12-07 21:05:27 +01:00
layout.prop(mat, 'custom_shader')
if mat.custom_shader:
layout.prop(mat, 'custom_shader_name')
2015-12-03 14:38:33 +01:00
2015-12-02 00:05:20 +01:00
# Registration
2015-12-07 20:04:23 +01:00
def register():
bpy.utils.register_module(__name__)
initObjectProperties()
2015-12-07 21:05:27 +01:00
bpy.app.handlers.scene_update_post.append(cb_scene_update)
2015-12-07 20:04:23 +01:00
def unregister():
2015-12-07 21:05:27 +01:00
bpy.app.handlers.scene_update_post.remove(cb_scene_update)
2015-12-07 20:04:23 +01:00
bpy.utils.unregister_module(__name__)