Trait parameters UI

This commit is contained in:
Lubos Lenco 2016-01-28 12:32:05 +01:00
parent 18a1195ca5
commit c8bdae0ba9
4 changed files with 166 additions and 6 deletions

View file

@ -32,6 +32,7 @@ import bpy
import math
from mathutils import *
import json
import ast
from bpy_extras.io_utils import ExportHelper
kNodeTypeNode = 0
@ -2007,9 +2008,11 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
x.class_name = t.nodes_name_prop.replace('.', '_')
elif t.type_prop == 'Scene Instance':
x.type = 'Script'
x.class_name = "SceneInstance:'" + t.scene_prop.replace('.', '_') + "'"
x.class_name = 'SceneInstance'
x.parameters = [t.scene_prop.replace('.', '_')]
elif t.type_prop == 'Animation':
x.type = 'Script'
x.class_name = 'Animation'
names = []
starts = []
ends = []
@ -2018,10 +2021,14 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
names.append(at.name)
starts.append(at.start_prop)
ends.append(at.end_prop)
x.class_name = "Animation:'" + t.start_track_name_prop + "':" + str(names) + ":" + str(starts) + ":" + str(ends)
x.parameters = [t.start_track_name_prop, names, starts, ends]
else: # Script
x.type = t.type_prop
x.class_name = t.class_name_prop
if len(node.my_paramstraitlist) > 0:
x.parameters = []
for pt in node.my_paramstraitlist: # Append parameters
x.parameters.append(ast.literal_eval(pt.name))
o.traits.append(x)
@ -2046,9 +2053,9 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
body_mass = rb.mass
x = Object()
x.type = 'Script'
x.class_name = 'RigidBody:' + str(body_mass) + \
':' + shape + \
":" + str(rb.friction)
x.class_name = 'RigidBody;' + str(body_mass) + \
';' + shape + \
";" + str(rb.friction)
o.traits.append(x)
def cb_export_camera(self, object, o):

View file

@ -3,6 +3,7 @@ import nodes
import pipeline_nodes
import armory
import traits_animation
import traits_params
import traits
import props
@ -12,6 +13,7 @@ def register():
pipeline_nodes.register()
armory.register()
traits_animation.register()
traits_params.register()
traits.register()
props.register()
@ -21,5 +23,6 @@ def unregister():
pipeline_nodes.unregister()
armory.unregister()
traits_animation.unregister()
traits_params.unregister()
traits.unregister()
props.unregister()

View file

@ -3,6 +3,7 @@ import bpy
import os
import json
from traits_animation import ListAnimationTraitItem
from traits_params import ListParamsTraitItem
from bpy.types import Menu, Panel, UIList
from bpy.props import *
@ -191,6 +192,27 @@ class ToolsTraitsPanel(bpy.types.Panel):
item.name = item.class_name_prop
row = layout.row()
row.prop(item, "class_name_prop")
# Params
layout.label("Parameters")
paramsrow = layout.row()
paramsrows = 2
if len(obj.my_animationtraitlist) > 1:
paramsrows = 4
row = layout.row()
row.template_list("MY_UL_ParamsTraitList", "The_List", obj, "my_paramstraitlist", obj, "paramstraitlist_index", rows=paramsrows)
col = row.column(align=True)
col.operator("my_paramstraitlist.new_item", icon='ZOOMIN', text="")
col.operator("my_paramstraitlist.delete_item", icon='ZOOMOUT', text="")
if len(obj.my_paramstraitlist) > 1:
col.separator()
col.operator("my_paramstraitlist.move_item", icon='TRIA_UP', text="").direction = 'UP'
col.operator("my_paramstraitlist.move_item", icon='TRIA_DOWN', text="").direction = 'DOWN'
if obj.paramstraitlist_index >= 0 and len(obj.my_paramstraitlist) > 0:
item = obj.my_paramstraitlist[obj.paramstraitlist_index]
# Nodes
elif item.type_prop =='Nodes':
@ -210,7 +232,8 @@ class ToolsTraitsPanel(bpy.types.Panel):
item.name = item.type_prop
row = layout.row()
row.prop_search(item, "start_track_name_prop", obj, "my_animationtraitlist", "Start Track")
# List
# Tracks list
layout.label("Tracks")
animrow = layout.row()
animrows = 2
if len(obj.my_animationtraitlist) > 1:

127
blender/traits_params.py Executable file
View file

@ -0,0 +1,127 @@
import shutil
import bpy
import os
import json
from bpy.types import Menu, Panel, UIList
from bpy.props import *
class ListParamsTraitItem(bpy.types.PropertyGroup):
# Group of properties representing an item in the list
name = bpy.props.StringProperty(
name="Name",
description="A name for this item",
default="Untitled")
# enabled_prop = bpy.props.BoolProperty(
# name="",
# description="A name for this item",
# default=True)
class MY_UL_ParamsTraitList(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
# We could write some code to decide which icon to use here...
custom_icon = 'OBJECT_DATAMODE'
# Make sure your code supports all 3 layout types
if self.layout_type in {'DEFAULT', 'COMPACT'}:
#layout.prop(item, "enabled_prop")
#layout.label(item.name, icon = custom_icon)
layout.prop(item, "name", text="", emboss=False, icon=custom_icon)
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
layout.label("", icon = custom_icon)
def initObjectProperties():
bpy.types.Object.my_paramstraitlist = bpy.props.CollectionProperty(type = ListParamsTraitItem)
bpy.types.Object.paramstraitlist_index = bpy.props.IntProperty(name = "Index for my_list", default = 0)
class LIST_OT_ParamsTraitNewItem(bpy.types.Operator):
# Add a new item to the list
bl_idname = "my_paramstraitlist.new_item"
bl_label = "Add a new item"
def execute(self, context):
bpy.context.object.my_paramstraitlist.add()
bpy.context.object.paramstraitlist_index += 1
return{'FINISHED'}
class LIST_OT_ParamsTraitDeleteItem(bpy.types.Operator):
# Delete the selected item from the list
bl_idname = "my_paramstraitlist.delete_item"
bl_label = "Deletes an item"
@classmethod
def poll(self, context):
""" Enable if there's something in the list """
return len(bpy.context.object.my_paramstraitlist) > 0
def execute(self, context):
list = bpy.context.object.my_paramstraitlist
index = bpy.context.object.paramstraitlist_index
list.remove(index)
if index > 0:
index = index - 1
bpy.context.object.paramstraitlist_index = index
return{'FINISHED'}
class LIST_OT_ParamsTraitMoveItem(bpy.types.Operator):
# Move an item in the list
bl_idname = "my_paramstraitlist.move_item"
bl_label = "Move an item in the list"
direction = bpy.props.EnumProperty(
items=(
('UP', 'Up', ""),
('DOWN', 'Down', ""),))
@classmethod
def poll(self, context):
""" Enable if there's something in the list. """
return len(bpy.context.object.my_paramstraitlist) > 0
def move_index(self):
# Move index of an item render queue while clamping it
index = bpy.context.object.paramstraitlist_index
list_length = len(bpy.context.object.my_paramstraitlist) - 1
new_index = 0
if self.direction == 'UP':
new_index = index - 1
elif self.direction == 'DOWN':
new_index = index + 1
new_index = max(0, min(new_index, list_length))
index = new_index
def execute(self, context):
list = bpy.context.object.my_paramstraitlist
index = bpy.context.object.paramstraitlist_index
if self.direction == 'DOWN':
neighbor = index + 1
#queue.move(index,neighbor)
self.move_index()
elif self.direction == 'UP':
neighbor = index - 1
#queue.move(neighbor, index)
self.move_index()
else:
return{'CANCELLED'}
return{'FINISHED'}
def register():
bpy.utils.register_module(__name__)
initObjectProperties()
def unregister():
bpy.utils.unregister_module(__name__)