From 7f5ba744da7b7aff2aaf23b74da74340808e2873 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 7 Oct 2016 17:40:08 -1000 Subject: [PATCH] Additional BlenderConnection World capabilities --- hecl/blender/hecl/sact/__init__.py | 39 ++++++++++++++----- hecl/blender/hecl/swld/__init__.py | 17 ++++---- hecl/blender/hecl_blendershell.py | 4 ++ hecl/extern/athena | 2 +- .../hecl/Blender/BlenderConnection.hpp | 1 + hecl/include/hecl/Database.hpp | 14 ++----- hecl/lib/Blender/BlenderConnection.cpp | 17 ++++++++ hecl/lib/Project.cpp | 18 +++++++++ 8 files changed, 85 insertions(+), 27 deletions(-) diff --git a/hecl/blender/hecl/sact/__init__.py b/hecl/blender/hecl/sact/__init__.py index c13fae964..30ceaa0e7 100644 --- a/hecl/blender/hecl/sact/__init__.py +++ b/hecl/blender/hecl/sact/__init__.py @@ -204,12 +204,7 @@ def write_action_aabb(writebuf, arm_obj, mesh_obj): root_aabb_min[0], root_aabb_min[1], root_aabb_min[2], root_aabb_max[0], root_aabb_max[1], root_aabb_max[2])) -# Cook -def cook(writebuf): - bpy.context.scene.hecl_auto_remap = False - sact_data = bpy.context.scene.hecl_sact_data - - # Output armatures +def _out_armatures(sact_data, writebuf): writebuf(struct.pack('I', len(bpy.data.armatures))) for arm in bpy.data.armatures: writebuf(struct.pack('I', len(arm.name))) @@ -231,7 +226,7 @@ def cook(writebuf): for child in bone.children: writebuf(struct.pack('i', arm.bones.find(child.name))) - # Output subtypes +def _out_subtypes(sact_data, writebuf): writebuf(struct.pack('I', len(sact_data.subtypes))) for subtype in sact_data.subtypes: writebuf(struct.pack('I', len(subtype.name))) @@ -273,8 +268,7 @@ def cook(writebuf): else: writebuf(struct.pack('I', 0)) - - # Output actions +def _out_actions(sact_data, writebuf): writebuf(struct.pack('I', len(sact_data.actions))) for action_idx in range(len(sact_data.actions)): sact_data.active_action = action_idx @@ -306,6 +300,33 @@ def cook(writebuf): mesh = bpy.data.objects[subtype.linked_mesh] write_action_aabb(writebuf, arm, mesh) +# Cook +def cook(writebuf): + bpy.context.scene.hecl_auto_remap = False + sact_data = bpy.context.scene.hecl_sact_data + + # Output armatures + _out_armatures(sact_data, writebuf) + + # Output subtypes + _out_subtypes(sact_data, writebuf) + + # Output actions + _out_actions(sact_data, writebuf) + +# Cook Character Data only +def cook_character_only(writebuf): + sact_data = bpy.context.scene.hecl_sact_data + + # Output armatures + _out_armatures(sact_data, writebuf) + + # Output subtypes + _out_subtypes(sact_data, writebuf) + + # Output no actions + writebuf(struct.pack('I', 0)) + # 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/swld/__init__.py b/hecl/blender/hecl/swld/__init__.py index ab0ca4190..a76e1d730 100644 --- a/hecl/blender/hecl/swld/__init__.py +++ b/hecl/blender/hecl/swld/__init__.py @@ -5,7 +5,7 @@ def build_dock_connections(): areas = [] docks = [] - for obj in bpy.context.scene.objects: + for obj in sorted(bpy.context.scene.objects, key=lambda x: x.name): if obj.type == 'MESH' and obj.parent is None: dock_list = [] for ch in obj.children: @@ -29,8 +29,8 @@ def build_dock_connections(): dock_dict[dockA[2].name] = dockB match = True break - if not match: - raise RuntimeError('No dock match for %s' % dockA[2].name) + #if not match: + # raise RuntimeError('No dock match for %s' % dockA[2].name) return (areas, dock_dict) @@ -66,10 +66,13 @@ def cook(writebuf): for vi in range(4): v = wmtx * ch.data.vertices[vi].co writebuf(struct.pack('fff', v[0], v[1], v[2])) - conn_dock = dock_conns[ch.name] - writebuf(struct.pack('I', conn_dock[0])) - writebuf(struct.pack('I', conn_dock[1])) - + if ch.name in dock_conns: + conn_dock = dock_conns[ch.name] + writebuf(struct.pack('I', conn_dock[0])) + writebuf(struct.pack('I', conn_dock[1])) + else: + writebuf(struct.pack('I', 0xffffffff)) + writebuf(struct.pack('I', 0xffffffff)) # Panel draw def draw(layout, context): diff --git a/hecl/blender/hecl_blendershell.py b/hecl/blender/hecl_blendershell.py index 41d5fd2b8..8ac6ed57f 100644 --- a/hecl/blender/hecl_blendershell.py +++ b/hecl/blender/hecl_blendershell.py @@ -310,6 +310,10 @@ def dataout_loop(): writepipeline(b'OK') hecl.sact.cook(writepipebuf) + elif cmdargs[0] == 'ACTORCOMPILECHARACTERONLY': + writepipeline(b'OK') + hecl.sact.cook_character_only(writepipebuf) + elif cmdargs[0] == 'GETARMATURENAMES': writepipeline(b'OK') hecl.sact.get_armature_names(writepipebuf) diff --git a/hecl/extern/athena b/hecl/extern/athena index b3ca9a0a9..a5a3244e1 160000 --- a/hecl/extern/athena +++ b/hecl/extern/athena @@ -1 +1 @@ -Subproject commit b3ca9a0a9023580db5dff68158606a64841b7f4e +Subproject commit a5a3244e1aee88f683f95bc1ffc226759acf9ca1 diff --git a/hecl/include/hecl/Blender/BlenderConnection.hpp b/hecl/include/hecl/Blender/BlenderConnection.hpp index b1d9aa984..2d6fe0b58 100644 --- a/hecl/include/hecl/Blender/BlenderConnection.hpp +++ b/hecl/include/hecl/Blender/BlenderConnection.hpp @@ -750,6 +750,7 @@ public: }; Actor compileActor(); + Actor compileActorCharacterOnly(); std::vector getArmatureNames(); std::vector getSubtypeNames(); std::vector getActionNames(); diff --git a/hecl/include/hecl/Database.hpp b/hecl/include/hecl/Database.hpp index dcbf0094a..42bebc0cf 100644 --- a/hecl/include/hecl/Database.hpp +++ b/hecl/include/hecl/Database.hpp @@ -110,7 +110,7 @@ public: {(void)path;LogModule.report(logvisor::Error, "not implemented");return false;} virtual const DataSpecEntry* overrideDataSpec(const ProjectPath& path, const Database::DataSpecEntry* oldEntry, - BlenderToken& btok) + BlenderToken& btok) const {(void)path;return oldEntry;} virtual void doCook(const ProjectPath& path, const ProjectPath& cookedPath, bool fast, BlenderToken& btok, FCookProgress progress) @@ -454,19 +454,13 @@ public: PackageDepsgraph buildPackageDepsgraph(const ProjectPath& path); /** Add ProjectPath to bridge cache */ - void addBridgePathToCache(uint64_t id, const ProjectPath& path) { m_bridgePathCache[id] = path; } + void addBridgePathToCache(uint64_t id, const ProjectPath& path); /** Clear all ProjectPaths in bridge cache */ - void clearBridgePathCache() { m_bridgePathCache.clear(); } + void clearBridgePathCache(); /** Lookup ProjectPath from bridge cache */ - const ProjectPath* lookupBridgePath(uint64_t id) const - { - auto search = m_bridgePathCache.find(id); - if (search == m_bridgePathCache.cend()) - return nullptr; - return &search->second; - } + const ProjectPath* lookupBridgePath(uint64_t id) const; }; diff --git a/hecl/lib/Blender/BlenderConnection.cpp b/hecl/lib/Blender/BlenderConnection.cpp index ec7ddea0a..44b6c17e4 100644 --- a/hecl/lib/Blender/BlenderConnection.cpp +++ b/hecl/lib/Blender/BlenderConnection.cpp @@ -1377,6 +1377,23 @@ BlenderConnection::DataStream::Actor BlenderConnection::DataStream::compileActor return Actor(*m_parent); } +BlenderConnection::DataStream::Actor +BlenderConnection::DataStream::compileActorCharacterOnly() +{ + if (m_parent->m_loadedType != BlendType::Actor) + BlenderLog.report(logvisor::Fatal, _S("%s is not an ACTOR blend"), + m_parent->m_loadedBlend.getAbsolutePath().c_str()); + + m_parent->_writeLine("ACTORCOMPILECHARACTERONLY"); + + char readBuf[256]; + m_parent->_readLine(readBuf, 256); + if (strcmp(readBuf, "OK")) + BlenderLog.report(logvisor::Fatal, "unable to compile actor: %s", readBuf); + + return Actor(*m_parent); +} + BlenderConnection::DataStream::World BlenderConnection::DataStream::compileWorld() { diff --git a/hecl/lib/Project.cpp b/hecl/lib/Project.cpp index 13234c3ee..eee18bbbc 100644 --- a/hecl/lib/Project.cpp +++ b/hecl/lib/Project.cpp @@ -543,5 +543,23 @@ PackageDepsgraph Project::buildPackageDepsgraph(const ProjectPath& path) return PackageDepsgraph(); } +void Project::addBridgePathToCache(uint64_t id, const ProjectPath& path) +{ + m_bridgePathCache[id] = path; +} + +void Project::clearBridgePathCache() +{ + m_bridgePathCache.clear(); +} + +const ProjectPath* Project::lookupBridgePath(uint64_t id) const +{ + auto search = m_bridgePathCache.find(id); + if (search == m_bridgePathCache.cend()) + return nullptr; + return &search->second; +} + } }