2016-12-05 01:54:01 +01:00
|
|
|
import bpy
|
|
|
|
from bpy.types import Menu, Panel, UIList
|
|
|
|
from bpy.props import *
|
|
|
|
|
|
|
|
def update_size_prop(self, context):
|
|
|
|
if context.object == None:
|
|
|
|
return
|
|
|
|
mdata = context.object.data
|
2017-08-21 12:17:55 +02:00
|
|
|
i = mdata.arm_lodlist_index
|
|
|
|
ar = mdata.arm_lodlist
|
2016-12-05 01:54:01 +01:00
|
|
|
# Clamp screen size to not exceed previous entry
|
|
|
|
if i > 0 and ar[i - 1].screen_size_prop < self.screen_size_prop:
|
|
|
|
self.screen_size_prop = ar[i - 1].screen_size_prop
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmLodListItem(bpy.types.PropertyGroup):
|
2016-12-05 01:54:01 +01:00
|
|
|
# Group of properties representing an item in the list
|
|
|
|
name = bpy.props.StringProperty(
|
|
|
|
name="Name",
|
|
|
|
description="A name for this item",
|
|
|
|
default="")
|
|
|
|
|
|
|
|
enabled_prop = bpy.props.BoolProperty(
|
|
|
|
name="",
|
|
|
|
description="A name for this item",
|
|
|
|
default=True)
|
|
|
|
|
|
|
|
screen_size_prop = bpy.props.FloatProperty(
|
|
|
|
name="Screen Size",
|
|
|
|
description="A name for this item",
|
|
|
|
min=0.0,
|
|
|
|
max=1.0,
|
|
|
|
default=0.0,
|
|
|
|
update=update_size_prop)
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmLodList(bpy.types.UIList):
|
2016-12-05 01:54:01 +01:00
|
|
|
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")
|
|
|
|
name = item.name
|
|
|
|
if name == '':
|
|
|
|
name = 'None'
|
|
|
|
row = layout.row()
|
|
|
|
row.label(name, icon=custom_icon)
|
2017-08-22 15:57:49 +02:00
|
|
|
col = row.column()
|
|
|
|
col.alignment = 'RIGHT'
|
|
|
|
col.label("{:.2f}".format(item.screen_size_prop))
|
2016-12-05 01:54:01 +01:00
|
|
|
|
|
|
|
elif self.layout_type in {'GRID'}:
|
|
|
|
layout.alignment = 'CENTER'
|
|
|
|
layout.label("", icon = custom_icon)
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmLodListNewItem(bpy.types.Operator):
|
2016-12-05 01:54:01 +01:00
|
|
|
# Add a new item to the list
|
2017-08-21 12:17:55 +02:00
|
|
|
bl_idname = "arm_lodlist.new_item"
|
2016-12-05 01:54:01 +01:00
|
|
|
bl_label = "Add a new item"
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
mdata = bpy.context.object.data
|
2017-08-21 12:17:55 +02:00
|
|
|
mdata.arm_lodlist.add()
|
|
|
|
mdata.arm_lodlist_index = len(mdata.arm_lodlist) - 1
|
2016-12-05 01:54:01 +01:00
|
|
|
return{'FINISHED'}
|
|
|
|
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
class ArmLodListDeleteItem(bpy.types.Operator):
|
2016-12-05 01:54:01 +01:00
|
|
|
# Delete the selected item from the list
|
2017-08-21 12:17:55 +02:00
|
|
|
bl_idname = "arm_lodlist.delete_item"
|
2016-12-05 01:54:01 +01:00
|
|
|
bl_label = "Deletes an item"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(self, context):
|
|
|
|
""" Enable if there's something in the list """
|
|
|
|
mdata = bpy.context.object.data
|
2017-08-21 12:17:55 +02:00
|
|
|
return len(mdata.arm_lodlist) > 0
|
2016-12-05 01:54:01 +01:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
mdata = bpy.context.object.data
|
2018-08-01 10:20:42 +02:00
|
|
|
lodlist = mdata.arm_lodlist
|
2017-08-21 12:17:55 +02:00
|
|
|
index = mdata.arm_lodlist_index
|
2016-12-05 01:54:01 +01:00
|
|
|
|
2018-08-01 10:20:42 +02:00
|
|
|
n = lodlist[index].name
|
|
|
|
if n in context.scene.objects:
|
|
|
|
obj = bpy.data.objects[n]
|
|
|
|
context.scene.objects.unlink(obj)
|
|
|
|
|
|
|
|
lodlist.remove(index)
|
2016-12-05 01:54:01 +01:00
|
|
|
|
|
|
|
if index > 0:
|
|
|
|
index = index - 1
|
|
|
|
|
2017-08-21 12:17:55 +02:00
|
|
|
mdata.arm_lodlist_index = index
|
2016-12-05 01:54:01 +01:00
|
|
|
return{'FINISHED'}
|
|
|
|
|
|
|
|
def register():
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.register_class(ArmLodListItem)
|
|
|
|
bpy.utils.register_class(ArmLodList)
|
|
|
|
bpy.utils.register_class(ArmLodListNewItem)
|
|
|
|
bpy.utils.register_class(ArmLodListDeleteItem)
|
|
|
|
|
|
|
|
bpy.types.Mesh.arm_lodlist = bpy.props.CollectionProperty(type=ArmLodListItem)
|
|
|
|
bpy.types.Mesh.arm_lodlist_index = bpy.props.IntProperty(name="Index for my_list", default=0)
|
|
|
|
bpy.types.Mesh.arm_lod_material = bpy.props.BoolProperty(name="Material Lod", description="Use materials of lod objects", default=False)
|
2016-12-05 01:54:01 +01:00
|
|
|
|
|
|
|
def unregister():
|
2017-08-21 12:17:55 +02:00
|
|
|
bpy.utils.unregister_class(ArmLodListItem)
|
|
|
|
bpy.utils.unregister_class(ArmLodList)
|
|
|
|
bpy.utils.unregister_class(ArmLodListNewItem)
|
|
|
|
bpy.utils.unregister_class(ArmLodListDeleteItem)
|