mirror of https://github.com/AxioDL/metaforce.git
Blender addon fixes
This commit is contained in:
parent
47f08c3487
commit
9878a8853e
|
@ -23,8 +23,8 @@ BlenderConnection* SharedBlenderConnection = nullptr;
|
|||
#define DEFAULT_BLENDER_BIN "blender"
|
||||
#endif
|
||||
|
||||
extern "C" uint8_t BLENDERSHELL[];
|
||||
extern "C" size_t BLENDERSHELL_SZ;
|
||||
extern "C" uint8_t HECL_BLENDERSHELL[];
|
||||
extern "C" size_t HECL_BLENDERSHELL_SZ;
|
||||
|
||||
size_t BlenderConnection::_readLine(char* buf, size_t bufSz)
|
||||
{
|
||||
|
@ -137,7 +137,7 @@ void BlenderConnection::_closePipe()
|
|||
|
||||
BlenderConnection::BlenderConnection(bool silenceBlender)
|
||||
{
|
||||
/* Put blendershell.py in temp dir */
|
||||
/* Put hecl_blendershell.py in temp dir */
|
||||
#ifdef _WIN32
|
||||
wchar_t* TMPDIR = _wgetenv(L"TEMP");
|
||||
if (!TMPDIR)
|
||||
|
@ -148,11 +148,11 @@ BlenderConnection::BlenderConnection(bool silenceBlender)
|
|||
TMPDIR = (char*)"/tmp";
|
||||
#endif
|
||||
HECL::SystemString blenderShellPath(TMPDIR);
|
||||
blenderShellPath += _S("/blendershell.py");
|
||||
blenderShellPath += _S("/hecl_blendershell.py");
|
||||
FILE* fp = HECL::Fopen(blenderShellPath.c_str(), _S("w"));
|
||||
if (!fp)
|
||||
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);
|
||||
|
||||
/* Construct communication pipes */
|
||||
|
@ -391,6 +391,8 @@ void BlenderConnection::PyOutStream::linkBlend(const SystemString& target, const
|
|||
" if scene.name == '%s':\n"
|
||||
" obj_scene = scene\n"
|
||||
" break\n"
|
||||
" if not obj_scene:\n"
|
||||
" raise RuntimeError('unable to find %s in %s')\n"
|
||||
" obj = None\n"
|
||||
" for object in obj_scene.objects:\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"
|
||||
"\n",
|
||||
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,
|
||||
|
|
|
@ -115,15 +115,18 @@ public:
|
|||
~PyOutStream() {close();}
|
||||
void close()
|
||||
{
|
||||
if (m_parent && m_lk)
|
||||
if (m_lk)
|
||||
{
|
||||
m_parent->_writeLine("PYEND");
|
||||
char readBuf[16];
|
||||
m_parent->_readLine(readBuf, 16);
|
||||
if (strcmp(readBuf, "DONE"))
|
||||
BlenderLog.report(LogVisor::FatalError, "unable to close PyOutStream with blender");
|
||||
if (m_parent)
|
||||
{
|
||||
m_parent->_writeLine("PYEND");
|
||||
char readBuf[16];
|
||||
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, ...)
|
||||
{
|
||||
|
|
|
@ -11,11 +11,11 @@ list(APPEND PY_SOURCES
|
|||
addon/sact/SACTEvent.py
|
||||
addon/sact/SACTSubtype.py)
|
||||
|
||||
bintoc(blendershell.c blendershell.py BLENDERSHELL)
|
||||
bintoc(hecl_blendershell.c hecl_blendershell.py HECL_BLENDERSHELL)
|
||||
|
||||
add_library(HECLBlender
|
||||
BlenderConnection.cpp
|
||||
BlenderConnection.hpp
|
||||
blendershell.py
|
||||
blendershell.c
|
||||
hecl_blendershell.py
|
||||
hecl_blendershell.c
|
||||
${PY_SOURCES})
|
||||
|
|
|
@ -89,6 +89,34 @@ def command(cmdline, writepipeline, writepipebuf):
|
|||
except:
|
||||
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
|
||||
def register():
|
||||
|
@ -96,8 +124,11 @@ def register():
|
|||
hmdl.register()
|
||||
sact.register()
|
||||
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():
|
||||
bpy.app.handlers.load_post.remove(scene_loaded)
|
||||
hmdl.unregister()
|
||||
sact.unregister()
|
||||
bpy.utils.unregister_class(hecl_scene_panel)
|
||||
|
|
|
@ -6,7 +6,7 @@ def active_action_update(self, context):
|
|||
if not bpy.app.background:
|
||||
if context.scene.hecl_type == 'ACTOR' and context.scene.hecl_auto_select:
|
||||
if SACTAction_load.poll(context):
|
||||
bpy.ops.scene.SACTAction_load()
|
||||
bpy.ops.scene.sactaction_load()
|
||||
|
||||
# Action type update
|
||||
def action_type_update(self, context):
|
||||
|
@ -17,7 +17,6 @@ def action_type_update(self, context):
|
|||
# Actor action class
|
||||
class SACTAction(bpy.types.PropertyGroup):
|
||||
name = bpy.props.StringProperty(name="Action Name")
|
||||
action = bpy.props.StringProperty(name="Blender Action")
|
||||
|
||||
# Panel draw
|
||||
def draw(layout, context):
|
||||
|
@ -43,12 +42,10 @@ def draw(layout, context):
|
|||
layout.operator("scene.sactaction_load", icon='FILE_TICK', text="Load Action")
|
||||
|
||||
# Name edit field
|
||||
layout.prop(action, 'name', text="Name")
|
||||
|
||||
layout.prop_search(action, 'action', bpy.data, 'actions', text="Action")
|
||||
layout.prop_search(action, 'name', bpy.data, 'actions', text="Name")
|
||||
linked_action = None
|
||||
if bpy.data.actions.find(action.action) != -1:
|
||||
linked_action = bpy.data.actions[action.action]
|
||||
if bpy.data.actions.find(action.name) != -1:
|
||||
linked_action = bpy.data.actions[action.name]
|
||||
|
||||
# Validate
|
||||
if linked_action is None:
|
||||
|
@ -151,9 +148,9 @@ class SACTAction_load(bpy.types.Operator):
|
|||
# Set single action into armature
|
||||
if subtype.linked_armature in bpy.data.objects:
|
||||
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 =\
|
||||
bpy.data.actions[action_data.action]
|
||||
bpy.data.actions[action_data.name]
|
||||
armature_obj.animation_data_clear()
|
||||
armature_obj.animation_data_create()
|
||||
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",
|
||||
min=1, max=60, default=30,
|
||||
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_add)
|
||||
bpy.utils.register_class(SACTAction_load)
|
||||
|
|
|
@ -169,9 +169,9 @@ def update_action_events(dummy):
|
|||
|
||||
if actor_data.active_action in range(len(actor_data.actions)):
|
||||
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 =\
|
||||
bpy.data.actions[action_data.action]
|
||||
bpy.data.actions[action_data.name]
|
||||
for i in range(len(action_obj.hecl_events)):
|
||||
event = action_obj.hecl_events[i]
|
||||
marker_name = 'hecl_' + str(action_obj.hecl_index) + '_' + str(i) + '_' + event.name
|
||||
|
|
|
@ -4,8 +4,7 @@ import bpy
|
|||
def active_subtype_update(self, context):
|
||||
if context.scene.hecl_type == 'ACTOR' and context.scene.hecl_auto_select:
|
||||
if SACTSubtype_load.poll(context):
|
||||
bpy.ops.scene.SACTSubtype_load()
|
||||
|
||||
bpy.ops.scene.sactsubtype_load()
|
||||
|
||||
|
||||
# Actor subtype class
|
||||
|
|
|
@ -245,6 +245,7 @@ def register():
|
|||
SACTAction.register()
|
||||
bpy.utils.register_class(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():
|
||||
bpy.utils.unregister_class(SACTData)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 2cc94bf4edd4e86aebe4bf92500e730f2ac91f07
|
||||
Subproject commit d0577ae3040aa19861009b95bf28ea05f12b8c53
|
Loading…
Reference in New Issue