From 86f9f62ef60bb60f3ef0b6e7824ca7b770baeb83 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 12 Feb 2017 20:51:15 -1000 Subject: [PATCH] Targeted subresource generation for Actor and World blends --- hecl/blender/hecl/sact/__init__.py | 31 +++++++++++++++++++ hecl/blender/hecl_blendershell.py | 5 +++ .../hecl/Blender/BlenderConnection.hpp | 1 + hecl/lib/Blender/BlenderConnection.cpp | 21 ++++++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/hecl/blender/hecl/sact/__init__.py b/hecl/blender/hecl/sact/__init__.py index 30ceaa0e7..ca7d475b4 100644 --- a/hecl/blender/hecl/sact/__init__.py +++ b/hecl/blender/hecl/sact/__init__.py @@ -300,6 +300,30 @@ def _out_actions(sact_data, writebuf): mesh = bpy.data.objects[subtype.linked_mesh] write_action_aabb(writebuf, arm, mesh) +def _out_action_no_subtypes(sact_data, writebuf, action_name): + for action_idx in range(len(sact_data.actions)): + action = sact_data.actions[action_idx] + if action.name == action_name: + sact_data.active_action = action_idx + writebuf(struct.pack('I', len(action.name))) + writebuf(action.name.encode()) + + bact = None + if action.name in bpy.data.actions: + bact = bpy.data.actions[action.name] + if not bact: + raise RuntimeError('action %s not found' % action.name) + + writebuf(struct.pack('f', 1.0 / bact.hecl_fps)) + writebuf(struct.pack('b', int(bact.hecl_additive))) + writebuf(struct.pack('b', int(bact.hecl_looping))) + + write_action_channels(writebuf, bact) + writebuf(struct.pack('I', 0)) + return + + raise RuntimeError("Unable to find action '%s'" % action_name) + # Cook def cook(writebuf): bpy.context.scene.hecl_auto_remap = False @@ -327,6 +351,13 @@ def cook_character_only(writebuf): # Output no actions writebuf(struct.pack('I', 0)) +def cook_action_channels_only(writebuf, action_name): + sact_data = bpy.context.scene.hecl_sact_data + + # Output action without AABBs + _out_action_no_subtypes(sact_data, writebuf, action_name) + + # Access actor's contained armature names def get_armature_names(writebuf): writebuf(struct.pack('I', len(bpy.data.armatures))) diff --git a/hecl/blender/hecl_blendershell.py b/hecl/blender/hecl_blendershell.py index c7d53e28f..5d2397883 100644 --- a/hecl/blender/hecl_blendershell.py +++ b/hecl/blender/hecl_blendershell.py @@ -347,6 +347,11 @@ def dataout_loop(): writepipestr(b'OK') hecl.sact.cook_character_only(writepipebuf) + elif cmdargs[0] == 'ACTIONCOMPILECHANNELSONLY': + actionName = cmdargs[1] + writepipestr(b'OK') + hecl.sact.cook_action_channels_only(writepipebuf, actionName) + elif cmdargs[0] == 'GETARMATURENAMES': writepipestr(b'OK') hecl.sact.get_armature_names(writepipebuf) diff --git a/hecl/include/hecl/Blender/BlenderConnection.hpp b/hecl/include/hecl/Blender/BlenderConnection.hpp index 4aad124b0..9dc46b80d 100644 --- a/hecl/include/hecl/Blender/BlenderConnection.hpp +++ b/hecl/include/hecl/Blender/BlenderConnection.hpp @@ -802,6 +802,7 @@ public: Actor compileActor(); Actor compileActorCharacterOnly(); + Actor::Action compileActionChannelsOnly(const std::string& name); std::vector getArmatureNames(); std::vector getSubtypeNames(); std::vector getActionNames(); diff --git a/hecl/lib/Blender/BlenderConnection.cpp b/hecl/lib/Blender/BlenderConnection.cpp index ddefc166f..64f911602 100644 --- a/hecl/lib/Blender/BlenderConnection.cpp +++ b/hecl/lib/Blender/BlenderConnection.cpp @@ -1225,10 +1225,10 @@ BlenderConnection::DataStream::Actor::Action::Action(BlenderConnection& conn) subtypeAABBs.reserve(aabbCount); for (uint32_t i=0 ; im_loadedType != BlendType::Actor) + BlenderLog.report(logvisor::Fatal, _S("%s is not an ACTOR blend"), + m_parent->m_loadedBlend.getAbsolutePath().c_str()); + + char req[128]; + snprintf(req, 128, "ACTIONCOMPILECHANNELSONLY %s", name.c_str()); + m_parent->_writeStr(req); + + char readBuf[256]; + m_parent->_readStr(readBuf, 256); + if (strcmp(readBuf, "OK")) + BlenderLog.report(logvisor::Fatal, "unable to compile action: %s", readBuf); + + return Actor::Action(*m_parent); +} + BlenderConnection::DataStream::World BlenderConnection::DataStream::compileWorld() {