2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-06-05 18:33:28 +00:00

Blender addon fixes

This commit is contained in:
Jack Andersen 2015-08-12 21:30:23 -10:00
parent 47f08c3487
commit 9878a8853e
10 changed files with 63 additions and 32 deletions

View File

@ -23,8 +23,8 @@ BlenderConnection* SharedBlenderConnection = nullptr;
#define DEFAULT_BLENDER_BIN "blender" #define DEFAULT_BLENDER_BIN "blender"
#endif #endif
extern "C" uint8_t BLENDERSHELL[]; extern "C" uint8_t HECL_BLENDERSHELL[];
extern "C" size_t BLENDERSHELL_SZ; extern "C" size_t HECL_BLENDERSHELL_SZ;
size_t BlenderConnection::_readLine(char* buf, size_t bufSz) size_t BlenderConnection::_readLine(char* buf, size_t bufSz)
{ {
@ -137,7 +137,7 @@ void BlenderConnection::_closePipe()
BlenderConnection::BlenderConnection(bool silenceBlender) BlenderConnection::BlenderConnection(bool silenceBlender)
{ {
/* Put blendershell.py in temp dir */ /* Put hecl_blendershell.py in temp dir */
#ifdef _WIN32 #ifdef _WIN32
wchar_t* TMPDIR = _wgetenv(L"TEMP"); wchar_t* TMPDIR = _wgetenv(L"TEMP");
if (!TMPDIR) if (!TMPDIR)
@ -148,11 +148,11 @@ BlenderConnection::BlenderConnection(bool silenceBlender)
TMPDIR = (char*)"/tmp"; TMPDIR = (char*)"/tmp";
#endif #endif
HECL::SystemString blenderShellPath(TMPDIR); HECL::SystemString blenderShellPath(TMPDIR);
blenderShellPath += _S("/blendershell.py"); blenderShellPath += _S("/hecl_blendershell.py");
FILE* fp = HECL::Fopen(blenderShellPath.c_str(), _S("w")); FILE* fp = HECL::Fopen(blenderShellPath.c_str(), _S("w"));
if (!fp) if (!fp)
BlenderLog.report(LogVisor::FatalError, _S("unable to open %s for writing"), blenderShellPath.c_str()); BlenderLog.report(LogVisor::FatalError, _S("unable to open %s for writing"), blenderShellPath.c_str());
fwrite(BLENDERSHELL, 1, BLENDERSHELL_SZ, fp); fwrite(HECL_BLENDERSHELL, 1, HECL_BLENDERSHELL_SZ, fp);
fclose(fp); fclose(fp);
/* Construct communication pipes */ /* Construct communication pipes */
@ -391,6 +391,8 @@ void BlenderConnection::PyOutStream::linkBlend(const SystemString& target, const
" if scene.name == '%s':\n" " if scene.name == '%s':\n"
" obj_scene = scene\n" " obj_scene = scene\n"
" break\n" " break\n"
" if not obj_scene:\n"
" raise RuntimeError('unable to find %s in %s')\n"
" obj = None\n" " obj = None\n"
" for object in obj_scene.objects:\n" " for object in obj_scene.objects:\n"
" if object.name == obj_scene.name:\n" " if object.name == obj_scene.name:\n"
@ -399,7 +401,7 @@ void BlenderConnection::PyOutStream::linkBlend(const SystemString& target, const
" obj = bpy.data.objects['%s']\n" " obj = bpy.data.objects['%s']\n"
"\n", "\n",
objName.c_str(), target.c_str(), link?"True":"False", objName.c_str(), target.c_str(), link?"True":"False",
objName.c_str(), objName.c_str()); objName.c_str(), objName.c_str(), target.c_str(), objName.c_str());
} }
bool BlenderConnection::cookBlend(std::function<char*(uint32_t)> bufGetter, bool BlenderConnection::cookBlend(std::function<char*(uint32_t)> bufGetter,

View File

@ -115,15 +115,18 @@ public:
~PyOutStream() {close();} ~PyOutStream() {close();}
void close() void close()
{ {
if (m_parent && m_lk) if (m_lk)
{ {
m_parent->_writeLine("PYEND"); if (m_parent)
char readBuf[16]; {
m_parent->_readLine(readBuf, 16); m_parent->_writeLine("PYEND");
if (strcmp(readBuf, "DONE")) char readBuf[16];
BlenderLog.report(LogVisor::FatalError, "unable to close PyOutStream with blender"); m_parent->_readLine(readBuf, 16);
if (strcmp(readBuf, "DONE"))
BlenderLog.report(LogVisor::FatalError, "unable to close PyOutStream with blender");
}
m_lk.unlock();
} }
m_lk.unlock();
} }
void format(const char* fmt, ...) void format(const char* fmt, ...)
{ {

View File

@ -11,11 +11,11 @@ list(APPEND PY_SOURCES
addon/sact/SACTEvent.py addon/sact/SACTEvent.py
addon/sact/SACTSubtype.py) addon/sact/SACTSubtype.py)
bintoc(blendershell.c blendershell.py BLENDERSHELL) bintoc(hecl_blendershell.c hecl_blendershell.py HECL_BLENDERSHELL)
add_library(HECLBlender add_library(HECLBlender
BlenderConnection.cpp BlenderConnection.cpp
BlenderConnection.hpp BlenderConnection.hpp
blendershell.py hecl_blendershell.py
blendershell.c hecl_blendershell.c
${PY_SOURCES}) ${PY_SOURCES})

View File

@ -89,6 +89,34 @@ def command(cmdline, writepipeline, writepipebuf):
except: except:
writepipeline(b'EXCEPTION') writepipeline(b'EXCEPTION')
# Load scene callback
from bpy.app.handlers import persistent
@persistent
def scene_loaded(dummy):
# Hide everything from an external library
for o in bpy.context.scene.objects:
if o.library:
o.hide = True
# Linked-Child Detection
for scene in bpy.data.scenes:
if scene.hecl_type == 'ACTOR':
actor_data = scene.hecl_sact_data
for subtype in actor_data.subtypes:
if subtype.linked_mesh in bpy.data.objects:
mesh_obj = bpy.data.objects[subtype.linked_mesh]
if subtype.linked_armature in bpy.data.objects:
arm_obj = bpy.data.objects[subtype.linked_armature]
mesh_obj.parent = arm_obj
mesh_obj.parent_type = 'ARMATURE'
# Show only the active mesh and action
if sact.SACTSubtype.SACTSubtype_load.poll(bpy.context):
bpy.ops.scene.sactsubtype_load()
if sact.SACTAction.SACTAction_load.poll(bpy.context):
bpy.ops.scene.sactaction_load()
# Registration # Registration
def register(): def register():
@ -96,8 +124,11 @@ def register():
hmdl.register() hmdl.register()
sact.register() sact.register()
bpy.utils.register_class(hecl_scene_panel) bpy.utils.register_class(hecl_scene_panel)
bpy.types.Scene.hecl_auto_select = bpy.props.BoolProperty(name='HECL Auto Select', default=True)
bpy.app.handlers.load_post.append(scene_loaded)
def unregister(): def unregister():
bpy.app.handlers.load_post.remove(scene_loaded)
hmdl.unregister() hmdl.unregister()
sact.unregister() sact.unregister()
bpy.utils.unregister_class(hecl_scene_panel) bpy.utils.unregister_class(hecl_scene_panel)

View File

@ -6,7 +6,7 @@ def active_action_update(self, context):
if not bpy.app.background: if not bpy.app.background:
if context.scene.hecl_type == 'ACTOR' and context.scene.hecl_auto_select: if context.scene.hecl_type == 'ACTOR' and context.scene.hecl_auto_select:
if SACTAction_load.poll(context): if SACTAction_load.poll(context):
bpy.ops.scene.SACTAction_load() bpy.ops.scene.sactaction_load()
# Action type update # Action type update
def action_type_update(self, context): def action_type_update(self, context):
@ -17,7 +17,6 @@ def action_type_update(self, context):
# Actor action class # Actor action class
class SACTAction(bpy.types.PropertyGroup): class SACTAction(bpy.types.PropertyGroup):
name = bpy.props.StringProperty(name="Action Name") name = bpy.props.StringProperty(name="Action Name")
action = bpy.props.StringProperty(name="Blender Action")
# Panel draw # Panel draw
def draw(layout, context): def draw(layout, context):
@ -43,12 +42,10 @@ def draw(layout, context):
layout.operator("scene.sactaction_load", icon='FILE_TICK', text="Load Action") layout.operator("scene.sactaction_load", icon='FILE_TICK', text="Load Action")
# Name edit field # Name edit field
layout.prop(action, 'name', text="Name") layout.prop_search(action, 'name', bpy.data, 'actions', text="Name")
layout.prop_search(action, 'action', bpy.data, 'actions', text="Action")
linked_action = None linked_action = None
if bpy.data.actions.find(action.action) != -1: if bpy.data.actions.find(action.name) != -1:
linked_action = bpy.data.actions[action.action] linked_action = bpy.data.actions[action.name]
# Validate # Validate
if linked_action is None: if linked_action is None:
@ -151,9 +148,9 @@ class SACTAction_load(bpy.types.Operator):
# Set single action into armature # Set single action into armature
if subtype.linked_armature in bpy.data.objects: if subtype.linked_armature in bpy.data.objects:
armature_obj = bpy.data.objects[subtype.linked_armature] armature_obj = bpy.data.objects[subtype.linked_armature]
if action_data.action in bpy.data.actions: if action_data.name in bpy.data.actions:
action_obj =\ action_obj =\
bpy.data.actions[action_data.action] bpy.data.actions[action_data.name]
armature_obj.animation_data_clear() armature_obj.animation_data_clear()
armature_obj.animation_data_create() armature_obj.animation_data_create()
armature_obj.animation_data.action = action_obj armature_obj.animation_data.action = action_obj
@ -196,8 +193,6 @@ def register():
description="Frame-rate at which action is authored; to be interpolated at 60-fps by runtime", description="Frame-rate at which action is authored; to be interpolated at 60-fps by runtime",
min=1, max=60, default=30, min=1, max=60, default=30,
update=active_action_update) update=active_action_update)
bpy.types.Action.hecl_anim_props = bpy.props.StringProperty(name="Animation Metadata")
bpy.types.Action.hecl_index = bpy.props.IntProperty(name="HECL Actor Action Index")
bpy.utils.register_class(SACTAction) bpy.utils.register_class(SACTAction)
bpy.utils.register_class(SACTAction_add) bpy.utils.register_class(SACTAction_add)
bpy.utils.register_class(SACTAction_load) bpy.utils.register_class(SACTAction_load)

View File

@ -169,9 +169,9 @@ def update_action_events(dummy):
if actor_data.active_action in range(len(actor_data.actions)): if actor_data.active_action in range(len(actor_data.actions)):
action_data = actor_data.actions[actor_data.active_action] action_data = actor_data.actions[actor_data.active_action]
if action_data.action in bpy.data.actions: if action_data.name in bpy.data.actions:
action_obj =\ action_obj =\
bpy.data.actions[action_data.action] bpy.data.actions[action_data.name]
for i in range(len(action_obj.hecl_events)): for i in range(len(action_obj.hecl_events)):
event = action_obj.hecl_events[i] event = action_obj.hecl_events[i]
marker_name = 'hecl_' + str(action_obj.hecl_index) + '_' + str(i) + '_' + event.name marker_name = 'hecl_' + str(action_obj.hecl_index) + '_' + str(i) + '_' + event.name

View File

@ -4,8 +4,7 @@ import bpy
def active_subtype_update(self, context): def active_subtype_update(self, context):
if context.scene.hecl_type == 'ACTOR' and context.scene.hecl_auto_select: if context.scene.hecl_type == 'ACTOR' and context.scene.hecl_auto_select:
if SACTSubtype_load.poll(context): if SACTSubtype_load.poll(context):
bpy.ops.scene.SACTSubtype_load() bpy.ops.scene.sactsubtype_load()
# Actor subtype class # Actor subtype class

View File

@ -245,6 +245,7 @@ def register():
SACTAction.register() SACTAction.register()
bpy.utils.register_class(SACTData) bpy.utils.register_class(SACTData)
bpy.types.Scene.hecl_sact_data = bpy.props.PointerProperty(type=SACTData) bpy.types.Scene.hecl_sact_data = bpy.props.PointerProperty(type=SACTData)
bpy.types.Action.hecl_fps = bpy.props.IntProperty(name='HECL Acion FPS', default=30)
def unregister(): def unregister():
bpy.utils.unregister_class(SACTData) bpy.utils.unregister_class(SACTData)

@ -1 +1 @@
Subproject commit 2cc94bf4edd4e86aebe4bf92500e730f2ac91f07 Subproject commit d0577ae3040aa19861009b95bf28ea05f12b8c53