From e65fe14c5321cf4998835c40912fd05ef53ac3b6 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sun, 2 Oct 2016 12:34:10 -1000 Subject: [PATCH] BlenderConnection tweaks --- hecl/blender/hecl/swld/__init__.py | 9 +++--- hecl/blender/hecl_blendershell.py | 15 ++++++++++ hecl/extern/athena | 2 +- .../hecl/Blender/BlenderConnection.hpp | 3 ++ hecl/include/hecl/Database.hpp | 19 ++++++++++-- hecl/lib/Blender/BlenderConnection.cpp | 29 +++++++++++++++++++ 6 files changed, 69 insertions(+), 8 deletions(-) diff --git a/hecl/blender/hecl/swld/__init__.py b/hecl/blender/hecl/swld/__init__.py index a7941420c..ab0ca4190 100644 --- a/hecl/blender/hecl/swld/__init__.py +++ b/hecl/blender/hecl/swld/__init__.py @@ -1,4 +1,4 @@ -import bpy +import bpy, struct from mathutils import Vector def build_dock_connections(): @@ -44,9 +44,9 @@ def cook(writebuf): writebuf(struct.pack('I', len(obj.name))) writebuf(obj.name.encode()) - pt = Vector(copy_obj.bound_box[0]) + pt = Vector(obj.bound_box[0]) writebuf(struct.pack('fff', pt[0], pt[1], pt[2])) - pt = Vector(copy_obj.bound_box[6]) + pt = Vector(obj.bound_box[6]) writebuf(struct.pack('fff', pt[0], pt[1], pt[2])) wmtx = obj.matrix_world @@ -67,7 +67,8 @@ def cook(writebuf): 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('II', conn_dock[0], conn_dock[1])) + writebuf(struct.pack('I', conn_dock[0])) + writebuf(struct.pack('I', conn_dock[1])) # Panel draw diff --git a/hecl/blender/hecl_blendershell.py b/hecl/blender/hecl_blendershell.py index c2663cbd7..41d5fd2b8 100644 --- a/hecl/blender/hecl_blendershell.py +++ b/hecl/blender/hecl_blendershell.py @@ -291,6 +291,21 @@ def dataout_loop(): writepipebuf(struct.pack('IIfffffb', layer, type, obj.data.energy, spotCutoff, constant, linear, quadratic, castShadow)) + elif cmdargs[0] == 'GETTEXTURES': + writepipeline(b'OK') + + img_count = 0 + for img in bpy.data.images: + if img.type == 'IMAGE': + img_count += 1 + writepipebuf(struct.pack('I', img_count)) + + for img in bpy.data.images: + if img.type == 'IMAGE': + path = os.path.normpath(bpy.path.abspath(img.filepath)) + writepipebuf(struct.pack('I', len(path))) + writepipebuf(path.encode()) + elif cmdargs[0] == 'ACTORCOMPILE': writepipeline(b'OK') hecl.sact.cook(writepipebuf) diff --git a/hecl/extern/athena b/hecl/extern/athena index d3d63082d..b3ca9a0a9 160000 --- a/hecl/extern/athena +++ b/hecl/extern/athena @@ -1 +1 @@ -Subproject commit d3d63082d0087e2f85ee3bd43d27f077f40f6ebf +Subproject commit b3ca9a0a9023580db5dff68158606a64841b7f4e diff --git a/hecl/include/hecl/Blender/BlenderConnection.hpp b/hecl/include/hecl/Blender/BlenderConnection.hpp index e9629e450..b1d9aa984 100644 --- a/hecl/include/hecl/Blender/BlenderConnection.hpp +++ b/hecl/include/hecl/Blender/BlenderConnection.hpp @@ -658,6 +658,9 @@ public: /** Gather all lights in scene (AREA blends only) */ std::vector compileLights(); + /** Gather all texture paths in scene */ + std::vector getTextures(); + /** Intermediate actor representation prepared by blender from a single HECL actor blend */ struct Actor { diff --git a/hecl/include/hecl/Database.hpp b/hecl/include/hecl/Database.hpp index d9f507a1e..dcbf0094a 100644 --- a/hecl/include/hecl/Database.hpp +++ b/hecl/include/hecl/Database.hpp @@ -132,9 +132,6 @@ public: virtual bool canPackage(const PackagePassInfo& info, SystemString& reasonNo) {(void)info;reasonNo=_S("not implemented");return false;} - virtual void gatherDependencies(const PackagePassInfo& info, - std::unordered_set& implicitsOut) - {(void)info;(void)implicitsOut;} virtual void doPackage(const PackagePassInfo& info) {(void)info;} @@ -273,6 +270,7 @@ private: ProjectPath m_dotPath; ProjectPath m_cookedRoot; std::vector m_compiledSpecs; + std::unordered_map m_bridgePathCache; bool m_valid = false; public: Project(const hecl::ProjectRootPath& rootPath); @@ -455,6 +453,21 @@ public: */ PackageDepsgraph buildPackageDepsgraph(const ProjectPath& path); + /** Add ProjectPath to bridge cache */ + void addBridgePathToCache(uint64_t id, const ProjectPath& path) { m_bridgePathCache[id] = path; } + + /** Clear all ProjectPaths in bridge cache */ + void clearBridgePathCache() { m_bridgePathCache.clear(); } + + /** 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; + } + }; } diff --git a/hecl/lib/Blender/BlenderConnection.cpp b/hecl/lib/Blender/BlenderConnection.cpp index ee3e9ec8e..ec7ddea0a 100644 --- a/hecl/lib/Blender/BlenderConnection.cpp +++ b/hecl/lib/Blender/BlenderConnection.cpp @@ -1332,6 +1332,35 @@ std::vector BlenderConnection::DataStream: return ret; } +std::vector BlenderConnection::DataStream::getTextures() +{ + m_parent->_writeLine("GETTEXTURES"); + + char readBuf[256]; + m_parent->_readLine(readBuf, 256); + if (strcmp(readBuf, "OK")) + BlenderLog.report(logvisor::Fatal, "unable to get textures: %s", readBuf); + + uint32_t texCount; + m_parent->_readBuf(&texCount, 4); + std::vector texs; + texs.reserve(texCount); + for (uint32_t i=0 ; i_readBuf(&bufSz, 4); + std::string readStr(bufSz, ' '); + m_parent->_readBuf(&readStr[0], bufSz); + SystemStringView absolute(readStr); + + SystemString relative = + m_parent->m_loadedBlend.getProject().getProjectRootPath().getProjectRelativeFromAbsolute(absolute); + texs.emplace_back(m_parent->m_loadedBlend.getProject().getProjectWorkingPath(), relative); + } + + return texs; +} + BlenderConnection::DataStream::Actor BlenderConnection::DataStream::compileActor() { if (m_parent->m_loadedType != BlendType::Actor)