Added overlay meshes to addon

This commit is contained in:
Jack Andersen 2015-09-26 16:23:32 -10:00
parent ee6a812079
commit 35b71d1772
4 changed files with 121 additions and 12 deletions

View File

@ -1,6 +1,4 @@
''' '''Root HECL addon package for Blender'''
Root HECL addon package for Blender
'''
bl_info = { bl_info = {
"name": "HECL", "name": "HECL",
@ -111,6 +109,11 @@ def scene_loaded(dummy):
arm_obj = bpy.data.objects[subtype.linked_armature] arm_obj = bpy.data.objects[subtype.linked_armature]
mesh_obj.parent = arm_obj mesh_obj.parent = arm_obj
mesh_obj.parent_type = 'ARMATURE' mesh_obj.parent_type = 'ARMATURE'
for overlay in subtype.overlays:
if overlay.linked_mesh in bpy.data.objects:
mesh_obj = bpy.data.objects[overlay.linked_mesh]
mesh_obj.parent = arm_obj
mesh_obj.parent_type = 'ARMATURE'
# Show only the active mesh and action # Show only the active mesh and action

View File

@ -7,12 +7,23 @@ def active_subtype_update(self, context):
bpy.ops.scene.sactsubtype_load() bpy.ops.scene.sactsubtype_load()
# Actor subtype overlay class
class SACTSubtypeOverlay(bpy.types.PropertyGroup):
name = bpy.props.StringProperty(name="Overlay Name")
linked_mesh = bpy.props.StringProperty(name="Linked Mesh Object Source", update=active_subtype_update)
show_overlay = bpy.props.BoolProperty(name="Show Overlay Mesh", update=active_subtype_update)
# Actor subtype class # Actor subtype class
class SACTSubtype(bpy.types.PropertyGroup): class SACTSubtype(bpy.types.PropertyGroup):
name = bpy.props.StringProperty(name="Actor Mesh Name") name = bpy.props.StringProperty(name="Actor Mesh Name")
linked_armature = bpy.props.StringProperty(name="Linked Armature Object Source", update=active_subtype_update) linked_armature = bpy.props.StringProperty(name="Linked Armature Object Source", update=active_subtype_update)
linked_mesh = bpy.props.StringProperty(name="Linked Mesh Object Source", update=active_subtype_update) linked_mesh = bpy.props.StringProperty(name="Linked Mesh Object Source", update=active_subtype_update)
overlays =\
bpy.props.CollectionProperty(type=SACTSubtypeOverlay, name="Subtype Overlay List")
active_overlay =\
bpy.props.IntProperty(name="Active Subtype Overlay", default=0, update=active_subtype_update)
# Panel draw # Panel draw
def draw(layout, context): def draw(layout, context):
@ -60,6 +71,25 @@ def draw(layout, context):
if subtype.linked_mesh in bpy.data.objects: if subtype.linked_mesh in bpy.data.objects:
linked_mesh = bpy.data.objects[subtype.linked_mesh] linked_mesh = bpy.data.objects[subtype.linked_mesh]
# Mesh overlays
layout.label("Overlay Meshes:")
row = layout.row()
row.template_list("UI_UL_list", "SCENE_UL_SACTSubtypeOverlays",
subtype, 'overlays', subtype, 'active_overlay')
col = row.column(align=True)
col.operator("scene.sactsubtypeoverlay_add", icon="ZOOMIN", text="")
col.operator("scene.sactsubtypeoverlay_remove", icon="ZOOMOUT", text="")
overlay_mesh = None
if len(subtype.overlays) and subtype.active_overlay >= 0:
overlay = subtype.overlays[subtype.active_overlay]
layout.prop(overlay, 'name', text="Name")
overlay = subtype.overlays[subtype.active_overlay]
layout.prop_search(overlay, 'linked_mesh', bpy.data, 'objects', text="Mesh")
if overlay.linked_mesh in bpy.data.objects:
overlay_mesh = bpy.data.objects[overlay.linked_mesh]
layout.prop(overlay, 'show_overlay', text="Show Overlay")
# Validate # Validate
if linked_mesh is None: if linked_mesh is None:
layout.label("Source mesh not set", icon='ERROR') layout.label("Source mesh not set", icon='ERROR')
@ -70,6 +100,14 @@ def draw(layout, context):
elif linked_mesh.parent_type != 'ARMATURE': elif linked_mesh.parent_type != 'ARMATURE':
layout.label("Source mesh not 'ARMATURE' parent type", icon='ERROR') layout.label("Source mesh not 'ARMATURE' parent type", icon='ERROR')
if overlay_mesh:
if overlay_mesh.type != 'MESH':
layout.label("Overlay mesh not 'MESH'", icon='ERROR')
elif linked_armature is not None and overlay_mesh not in linked_armature.children:
layout.label(overlay_mesh.name+" not a child of "+linked_armature.name, icon='ERROR')
elif overlay_mesh.parent_type != 'ARMATURE':
layout.label("Overlay mesh not 'ARMATURE' parent type", icon='ERROR')
# Subtype 'add' operator # Subtype 'add' operator
class SACTSubtype_add(bpy.types.Operator): class SACTSubtype_add(bpy.types.Operator):
@ -151,26 +189,97 @@ class SACTSubtype_load(bpy.types.Operator):
if object.name in context.scene.objects: if object.name in context.scene.objects:
object.hide = True object.hide = True
# Hide all meshes # Hide all meshes (incl overlays)
for mesh_name in actor_data.subtypes: for mesh_name in actor_data.subtypes:
if mesh_name.linked_mesh in bpy.data.objects: if mesh_name.linked_mesh in bpy.data.objects:
mesh = bpy.data.objects[mesh_name.linked_mesh] mesh = bpy.data.objects[mesh_name.linked_mesh]
if mesh.name in context.scene.objects: if mesh.name in context.scene.objects:
mesh.hide = True mesh.hide = True
for overlay in mesh_name.overlays:
if overlay.linked_mesh in bpy.data.objects:
mesh = bpy.data.objects[overlay.linked_mesh]
if mesh.name in context.scene.objects:
mesh.hide = True
# Show only the chosen subtype # Show only the chosen subtype (and selected overlays)
if subtype.linked_mesh in bpy.data.objects: if subtype.linked_mesh in bpy.data.objects:
mesh_obj = bpy.data.objects[subtype.linked_mesh] mesh_obj = bpy.data.objects[subtype.linked_mesh]
mesh_obj.hide = False mesh_obj.hide = False
if mesh_obj != linked_armature: if mesh_obj != linked_armature:
mesh_obj.parent = linked_armature mesh_obj.parent = linked_armature
mesh_obj.parent_type = 'ARMATURE' mesh_obj.parent_type = 'ARMATURE'
for overlay in subtype.overlays:
if overlay.show_overlay and overlay.linked_mesh in bpy.data.objects:
mesh_obj = bpy.data.objects[overlay.linked_mesh]
mesh_obj.hide = False
if mesh_obj != linked_armature:
mesh_obj.parent = linked_armature
mesh_obj.parent_type = 'ARMATURE'
return {'FINISHED'} return {'FINISHED'}
# Subtype overlay 'add' operator
class SACTSubtypeOverlay_add(bpy.types.Operator):
bl_idname = "scene.sactsubtypeoverlay_add"
bl_label = "New HECL Actor Subtype Overlay"
bl_description = "Add New HECL Actor Subtype Overlay"
@classmethod
def poll(cls, context):
actor_data = context.scene.hecl_sact_data
return (context.scene is not None and
not context.scene.library and
context.scene.hecl_type == 'ACTOR' and
len(actor_data.subtypes) and actor_data.active_subtype >= 0)
def execute(self, context):
actor_data = context.scene.hecl_sact_data
subtype = actor_data.subtypes[actor_data.active_subtype]
overlay_name = 'ActorMesh'
if overlay_name in subtype.overlays:
overlay_name = 'ActorMesh.001'
overlay_idx = 1
while overlay_name in subtype.overlays:
overlay_idx += 1
overlay_name = 'ActorMesh.{:0>3}'.format(overlay_idx)
overlay = subtype.overlays.add()
mesh.name = overlay_name
subtype.active_overlay = len(subtype.overlays)-1
return {'FINISHED'}
# Subtype overlay 'remove' operator
class SACTSubtypeOverlay_remove(bpy.types.Operator):
bl_idname = "scene.sactsubtypeoverlay_remove"
bl_label = "Remove HECL Actor Subtype Overlay"
bl_description = "Remove HECL Actor Subtype Overlay"
@classmethod
def poll(cls, context):
actor_data = context.scene.hecl_sact_data
return (context.scene is not None and
not context.scene.library and
context.scene.hecl_type == 'ACTOR' and
actor_data.active_subtype >= 0 and
len(actor_data.subtypes) and
actor_data.subtypes[actor_data.active_subtype].active_overlay >= 0 and
len(actor_data.subtypes[actor_data.active_subtype].overlays))
def execute(self, context):
actor_data = context.scene.hecl_sact_data
subtype = actor_data.subtypes[actor_data.active_subtype]
subtype.overlays.remove(subtype.active_overlay)
subtype.active_overlay -= 1
if subtype.active_overlay == -1:
subtype.active_overlay = 0
return {'FINISHED'}
# Registration # Registration
def register(): def register():
bpy.utils.register_class(SACTSubtypeOverlay)
bpy.utils.register_class(SACTSubtypeOverlay_add)
bpy.utils.register_class(SACTSubtypeOverlay_remove)
bpy.utils.register_class(SACTSubtype) bpy.utils.register_class(SACTSubtype)
bpy.utils.register_class(SACTSubtype_add) bpy.utils.register_class(SACTSubtype_add)
bpy.utils.register_class(SACTSubtype_remove) bpy.utils.register_class(SACTSubtype_remove)
@ -181,3 +290,6 @@ def unregister():
bpy.utils.unregister_class(SACTSubtype_add) bpy.utils.unregister_class(SACTSubtype_add)
bpy.utils.unregister_class(SACTSubtype_remove) bpy.utils.unregister_class(SACTSubtype_remove)
bpy.utils.unregister_class(SACTSubtype_load) bpy.utils.unregister_class(SACTSubtype_load)
bpy.utils.unregister_class(SACTSubtypeOverlay)
bpy.utils.unregister_class(SACTSubtypeOverlay_add)
bpy.utils.unregister_class(SACTSubtypeOverlay_remove)

2
hecl/extern/Athena vendored

@ -1 +1 @@
Subproject commit 3d90c14795d397dedd7adc404b37ed302adeca7b Subproject commit 4eae90984823ca9bfb039e652194ec2d068a3ee2

View File

@ -30,12 +30,6 @@
#include <Athena/DNA.hpp> #include <Athena/DNA.hpp>
#include "../extern/xxhash/xxhash.h" #include "../extern/xxhash/xxhash.h"
/* Handy MIN/MAX macros */
#ifndef MAX
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
#endif
namespace HECL namespace HECL
{ {