add panel code basically. preparing for future dev
This commit is contained in:
parent
6c875d23ae
commit
4701164a6c
60
ballance_blender_plugin/PROPS_virtools_group.py
Normal file
60
ballance_blender_plugin/PROPS_virtools_group.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import bpy
|
||||||
|
from . import UTILS_constants, UTILS_functions, UTILS_virtools_prop
|
||||||
|
|
||||||
|
class BALLANCE_OT_add_virtools_group(bpy.types.Operator):
|
||||||
|
"""Add a Virtools Group for Active Object."""
|
||||||
|
bl_idname = "ballance.add_virtools_group"
|
||||||
|
bl_label = "Add Virtools Group"
|
||||||
|
bl_options = {'UNDO'}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(self, context):
|
||||||
|
return context.object is not None
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
obj = context.object
|
||||||
|
UTILS_virtools_prop.set_virtools_group_data(obj, ("aaa", "bbb", "ccc"))
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
class BALLANCE_OT_rm_virtools_group(bpy.types.Operator):
|
||||||
|
"""Remove a Virtools Group for Active Object."""
|
||||||
|
bl_idname = "ballance.rm_virtools_group"
|
||||||
|
bl_label = "Remove Virtools Group"
|
||||||
|
bl_options = {'UNDO'}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(self, context):
|
||||||
|
return context.object is not None
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
obj = context.object
|
||||||
|
print(UTILS_virtools_prop.get_virtools_group_data(obj))
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
class BALLANCE_UL_virtools_group(bpy.types.UIList):
|
||||||
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||||
|
layout.prop(item, 'group_name', icon='GROUP', text="")
|
||||||
|
|
||||||
|
class BALLANCE_PT_virtools_group(bpy.types.Panel):
|
||||||
|
"""Show Virtools Group Properties."""
|
||||||
|
bl_label = "Virtools Group"
|
||||||
|
bl_idname = "BALLANCE_PT_virtools_group"
|
||||||
|
bl_space_type = 'PROPERTIES'
|
||||||
|
bl_region_type = 'WINDOW'
|
||||||
|
bl_context = "object"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return context.object is not None
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
target = bpy.context.active_object
|
||||||
|
|
||||||
|
row = layout.row()
|
||||||
|
row.template_list("BALLANCE_UL_virtools_group", "", target, "virtools_group",
|
||||||
|
target, "active_virtools_group")
|
||||||
|
|
||||||
|
col = row.column(align=True)
|
||||||
|
col.operator(BALLANCE_OT_add_virtools_group.bl_idname, icon='ADD', text="")
|
||||||
|
col.operator(BALLANCE_OT_rm_virtools_group.bl_idname, icon='REMOVE', text="")
|
26
ballance_blender_plugin/PROPS_virtools_material.py
Normal file
26
ballance_blender_plugin/PROPS_virtools_material.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import bpy
|
||||||
|
from . import UTILS_constants, UTILS_functions, UTILS_virtools_prop
|
||||||
|
|
||||||
|
class BALLANCE_PT_virtools_material(bpy.types.Panel):
|
||||||
|
"""Show Virtools Material Properties."""
|
||||||
|
bl_label = "Virtools Material"
|
||||||
|
bl_idname = "BALLANCE_PT_virtools_material"
|
||||||
|
bl_space_type = 'PROPERTIES'
|
||||||
|
bl_region_type = 'WINDOW'
|
||||||
|
bl_context = "material"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return context.material is not None
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
#target = bpy.context.active_object.active_material
|
||||||
|
target = UTILS_virtools_prop.get_virtools_material(context.material)
|
||||||
|
|
||||||
|
layout.prop(target, 'ambient')
|
||||||
|
layout.prop(target, 'diffuse')
|
||||||
|
layout.prop(target, 'specular')
|
||||||
|
layout.prop(target, 'emissive')
|
||||||
|
layout.prop(target, 'specular_power')
|
||||||
|
|
82
ballance_blender_plugin/UTILS_virtools_prop.py
Normal file
82
ballance_blender_plugin/UTILS_virtools_prop.py
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import bpy
|
||||||
|
from . import UTILS_constants, UTILS_functions
|
||||||
|
|
||||||
|
class BALLANCE_PG_virtools_material(bpy.types.PropertyGroup):
|
||||||
|
ambient: bpy.props.FloatVectorProperty(name="Ambient",
|
||||||
|
subtype='COLOR',
|
||||||
|
min=0.0,
|
||||||
|
max=1.0,
|
||||||
|
default=[0.0,0.0,0.0])
|
||||||
|
|
||||||
|
diffuse: bpy.props.FloatVectorProperty(name="Diffuse",
|
||||||
|
subtype='COLOR',
|
||||||
|
min=0.0,
|
||||||
|
max=1.0,
|
||||||
|
default=[0.0,0.0,0.0])
|
||||||
|
|
||||||
|
specular: bpy.props.FloatVectorProperty(name="Specular",
|
||||||
|
subtype='COLOR',
|
||||||
|
min=0.0,
|
||||||
|
max=1.0,
|
||||||
|
default=[0.0,0.0,0.0])
|
||||||
|
|
||||||
|
emissive: bpy.props.FloatVectorProperty(name="Emissive",
|
||||||
|
subtype='COLOR',
|
||||||
|
min=0.0,
|
||||||
|
max=1.0,
|
||||||
|
default=[0.0,0.0,0.0])
|
||||||
|
|
||||||
|
specular_power: bpy.props.FloatProperty(
|
||||||
|
name="Specular Power",
|
||||||
|
min=0.0,
|
||||||
|
max=100.0,
|
||||||
|
default=0.0,
|
||||||
|
)
|
||||||
|
|
||||||
|
class BALLANCE_PG_virtools_group(bpy.types.PropertyGroup):
|
||||||
|
group_name: bpy.props.StringProperty(
|
||||||
|
name="Group Name",
|
||||||
|
default=""
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_virtools_material(mtl):
|
||||||
|
return mtl.virtools_material
|
||||||
|
|
||||||
|
def get_virtools_material_data(mtl):
|
||||||
|
data = get_virtools_material(mtl)
|
||||||
|
return (data.ambient, data.diffuse, data.specular, data.emissive, data.specular_power)
|
||||||
|
|
||||||
|
def set_virtools_material_data(mtl, ambient, diffuse, specular, emissive, specular_power):
|
||||||
|
data = get_virtools_material(mtl)
|
||||||
|
data.ambient = ambient
|
||||||
|
data.diffuse = diffuse
|
||||||
|
data.specular = specular
|
||||||
|
data.emissive = emissive
|
||||||
|
data.specular_power = specular_power
|
||||||
|
|
||||||
|
def get_virtools_group(obj):
|
||||||
|
return obj.virtools_group
|
||||||
|
|
||||||
|
def get_virtools_group_data(obj):
|
||||||
|
return tuple(str(item.group_name) for item in get_virtools_group(obj))
|
||||||
|
|
||||||
|
def set_virtools_group_data(obj, new_data):
|
||||||
|
data = get_virtools_group(obj)
|
||||||
|
data.clear()
|
||||||
|
|
||||||
|
for item in new_data:
|
||||||
|
it = data.add()
|
||||||
|
it.name = ""
|
||||||
|
it.group_name = item
|
||||||
|
|
||||||
|
def register_props():
|
||||||
|
bpy.types.Object.virtools_group = bpy.props.CollectionProperty(type=BALLANCE_PG_virtools_group)
|
||||||
|
bpy.types.Object.active_virtools_group = bpy.props.IntProperty()
|
||||||
|
bpy.types.Material.virtools_material = bpy.props.PointerProperty(type=BALLANCE_PG_virtools_material)
|
||||||
|
|
||||||
|
def unregister_props():
|
||||||
|
del bpy.types.Material.virtools_material
|
||||||
|
del bpy.types.Object.virtools_group
|
||||||
|
del bpy.types.Object.active_virtools_group
|
||||||
|
|
||||||
|
|
@ -29,6 +29,8 @@ if "bpy" in locals():
|
|||||||
importlib.reload(UTILS_file_io)
|
importlib.reload(UTILS_file_io)
|
||||||
if "UTILS_zip_helper" in locals():
|
if "UTILS_zip_helper" in locals():
|
||||||
importlib.reload(UTILS_zip_helper)
|
importlib.reload(UTILS_zip_helper)
|
||||||
|
if "UTILS_virtools_prop" in locals():
|
||||||
|
importlib.reload(UTILS_virtools_prop)
|
||||||
|
|
||||||
if "BMFILE_export" in locals():
|
if "BMFILE_export" in locals():
|
||||||
importlib.reload(BMFILE_export)
|
importlib.reload(BMFILE_export)
|
||||||
@ -52,11 +54,17 @@ if "bpy" in locals():
|
|||||||
if "NAMES_rename_system" in locals():
|
if "NAMES_rename_system" in locals():
|
||||||
importlib.reload(NAMES_rename_system)
|
importlib.reload(NAMES_rename_system)
|
||||||
|
|
||||||
from . import UTILS_constants, UTILS_functions, UTILS_preferences
|
if "PROPS_virtools_group" in locals():
|
||||||
|
importlib.reload(PROPS_virtools_group)
|
||||||
|
if "PROPS_virtools_material" in locals():
|
||||||
|
importlib.reload(PROPS_virtools_material)
|
||||||
|
|
||||||
|
from . import UTILS_constants, UTILS_functions, UTILS_preferences, UTILS_virtools_prop
|
||||||
from . import BMFILE_export, BMFILE_import
|
from . import BMFILE_export, BMFILE_import
|
||||||
from . import MODS_3dsmax_align, MODS_flatten_uv, MODS_rail_uv
|
from . import MODS_3dsmax_align, MODS_flatten_uv, MODS_rail_uv
|
||||||
from . import OBJS_add_components, OBJS_add_floors, OBJS_add_rails
|
from . import OBJS_add_components, OBJS_add_floors, OBJS_add_rails
|
||||||
from . import NAMES_rename_system
|
from . import NAMES_rename_system
|
||||||
|
from . import PROPS_virtools_group, PROPS_virtools_material
|
||||||
|
|
||||||
# =============================================
|
# =============================================
|
||||||
# menu system
|
# menu system
|
||||||
@ -132,7 +140,16 @@ classes = (
|
|||||||
NAMES_rename_system.BALLANCE_OT_rename_by_group,
|
NAMES_rename_system.BALLANCE_OT_rename_by_group,
|
||||||
NAMES_rename_system.BALLANCE_OT_convert_name,
|
NAMES_rename_system.BALLANCE_OT_convert_name,
|
||||||
NAMES_rename_system.BALLANCE_OT_auto_grouping,
|
NAMES_rename_system.BALLANCE_OT_auto_grouping,
|
||||||
BALLANCE_MT_OutlinerMenu
|
BALLANCE_MT_OutlinerMenu,
|
||||||
|
|
||||||
|
UTILS_virtools_prop.BALLANCE_PG_virtools_material,
|
||||||
|
UTILS_virtools_prop.BALLANCE_PG_virtools_group,
|
||||||
|
PROPS_virtools_group.BALLANCE_OT_add_virtools_group,
|
||||||
|
PROPS_virtools_group.BALLANCE_OT_rm_virtools_group,
|
||||||
|
PROPS_virtools_group.BALLANCE_UL_virtools_group,
|
||||||
|
PROPS_virtools_group.BALLANCE_PT_virtools_group,
|
||||||
|
PROPS_virtools_material.BALLANCE_PT_virtools_material
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def menu_func_bm_import(self, context):
|
def menu_func_bm_import(self, context):
|
||||||
@ -169,13 +186,15 @@ def register():
|
|||||||
bpy.utils.register_class(cls)
|
bpy.utils.register_class(cls)
|
||||||
|
|
||||||
bpy.types.Scene.BallanceBlenderPluginProperty = bpy.props.PointerProperty(type=UTILS_preferences.MyPropertyGroup)
|
bpy.types.Scene.BallanceBlenderPluginProperty = bpy.props.PointerProperty(type=UTILS_preferences.MyPropertyGroup)
|
||||||
|
UTILS_virtools_prop.register_props()
|
||||||
|
|
||||||
bpy.types.TOPBAR_MT_file_import.append(menu_func_bm_import)
|
bpy.types.TOPBAR_MT_file_import.append(menu_func_bm_import)
|
||||||
bpy.types.TOPBAR_MT_file_export.append(menu_func_bm_export)
|
bpy.types.TOPBAR_MT_file_export.append(menu_func_bm_export)
|
||||||
|
|
||||||
bpy.types.VIEW3D_MT_editor_menus.prepend(menu_func_ballance_3d)
|
bpy.types.VIEW3D_MT_editor_menus.prepend(menu_func_ballance_3d)
|
||||||
bpy.types.VIEW3D_MT_add.append(menu_func_ballance_add)
|
bpy.types.VIEW3D_MT_add.append(menu_func_ballance_add)
|
||||||
bpy.types.OUTLINER_HT_header.append(menu_func_ballance_rename)
|
bpy.types.OUTLINER_HT_header.append(menu_func_ballance_rename)
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.types.TOPBAR_MT_file_import.remove(menu_func_bm_import)
|
bpy.types.TOPBAR_MT_file_import.remove(menu_func_bm_import)
|
||||||
bpy.types.TOPBAR_MT_file_export.remove(menu_func_bm_export)
|
bpy.types.TOPBAR_MT_file_export.remove(menu_func_bm_export)
|
||||||
@ -184,6 +203,9 @@ def unregister():
|
|||||||
bpy.types.VIEW3D_MT_add.remove(menu_func_ballance_add)
|
bpy.types.VIEW3D_MT_add.remove(menu_func_ballance_add)
|
||||||
bpy.types.OUTLINER_HT_header.remove(menu_func_ballance_rename)
|
bpy.types.OUTLINER_HT_header.remove(menu_func_ballance_rename)
|
||||||
|
|
||||||
|
UTILS_virtools_prop.unregister_props()
|
||||||
|
del bpy.types.Scene.BallanceBlenderPluginProperty
|
||||||
|
|
||||||
for cls in classes:
|
for cls in classes:
|
||||||
bpy.utils.unregister_class(cls)
|
bpy.utils.unregister_class(cls)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user