From 2f0febba279274ce52eeae280ea91260713edd24 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 2 Jan 2022 19:25:11 -0800 Subject: [PATCH] Blender 3.0 fixes --- DataSpec/Blender/RetroMasterShader.py | 12 ++--- DataSpec/DNAMP1/DNAMP1.cpp | 24 +++++----- DataSpec/DNAMP1/FRME.cpp | 2 +- hecl/blender/hecl_blendershell.py | 6 ++- hecl/lib/Blender/SDNARead.cpp | 69 +++++++++++++++------------ hecl/lib/hecl.cpp | 2 +- 6 files changed, 64 insertions(+), 51 deletions(-) diff --git a/DataSpec/Blender/RetroMasterShader.py b/DataSpec/Blender/RetroMasterShader.py index fe97fd640..70f837978 100644 --- a/DataSpec/Blender/RetroMasterShader.py +++ b/DataSpec/Blender/RetroMasterShader.py @@ -768,8 +768,8 @@ def make_retro_shader_mp3_color(): input.default_value = (0.0, 0.0, 0.0, 1.0) input = new_grp.inputs.new("NodeSocketInt", "Add INCA") input.default_value = 0 - input.min_value = 0.000000 - input.max_value = 1.000000 + input.min_value = 0 + input.max_value = 1 input = new_grp.inputs.new("NodeSocketFloatFactor", "OPAC") input.default_value = 1.0 input.min_value = 0.000000 @@ -1057,8 +1057,8 @@ def make_retro_shader_mp3_bloom(): input.max_value = 1.000000 input = new_grp.inputs.new("NodeSocketInt", "Add INCA") input.default_value = 0 - input.min_value = 0.000000 - input.max_value = 1.000000 + input.min_value = 0 + input.max_value = 1 new_grp.outputs.new("NodeSocketShader", "Shader") nodes = {} node = new_grp.nodes.new("ShaderNodeMath") @@ -1261,8 +1261,8 @@ def make_retro_shader_mp3(): input.max_value = 1.000000 input = new_grp.inputs.new("NodeSocketInt", "Add INCA") input.default_value = 0 - input.min_value = 0.000000 - input.max_value = 1.000000 + input.min_value = 0 + input.max_value = 1 input = new_grp.inputs.new("NodeSocketFloatFactor", "BNIF") input.default_value = 0.0 input.min_value = 0.000000 diff --git a/DataSpec/DNAMP1/DNAMP1.cpp b/DataSpec/DNAMP1/DNAMP1.cpp index b071c99da..aeda873f6 100644 --- a/DataSpec/DNAMP1/DNAMP1.cpp +++ b/DataSpec/DNAMP1/DNAMP1.cpp @@ -215,17 +215,19 @@ void PAKBridge::addCMDLRigPairs(PAKRouter& pakRouter, CharacterAssoci PAK::Entry* cmdlEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cmdl); PAK::Entry* cskrEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cskr); PAK::Entry* cinfEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cinf); - cmdlEnt->name = fmt::format(FMT_STRING("ANCS_{}_{}_model"), id, ci.name); - cskrEnt->name = fmt::format(FMT_STRING("ANCS_{}_{}_skin"), id, ci.name); - cinfEnt->name = fmt::format(FMT_STRING("ANCS_{}_{}_skel"), id, ci.name); - if (ci.cmdlIce.isValid() && ci.cskrIce.isValid()) { - charAssoc.m_cmdlRigs[ci.cmdlIce] = {ci.cskrIce, ci.cinf}; - charAssoc.m_cskrToCharacter[ci.cskrIce] = - std::make_pair(entry.id, fmt::format(FMT_STRING("{}.ICE_{}.CSKR"), ci.name, ci.cskrIce)); - PAK::Entry* cmdlEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cmdlIce); - PAK::Entry* cskrEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cskrIce); - cmdlEnt->name = fmt::format(FMT_STRING("ANCS_{}_{}_icemodel"), id, ci.name); - cskrEnt->name = fmt::format(FMT_STRING("ANCS_{}_{}_iceskin"), id, ci.name); + if (cmdlEnt != nullptr && cskrEnt != nullptr && cinfEnt != nullptr) { + cmdlEnt->name = fmt::format(FMT_STRING("ANCS_{}_{}_model"), id, ci.name); + cskrEnt->name = fmt::format(FMT_STRING("ANCS_{}_{}_skin"), id, ci.name); + cinfEnt->name = fmt::format(FMT_STRING("ANCS_{}_{}_skel"), id, ci.name); + if (ci.cmdlIce.isValid() && ci.cskrIce.isValid()) { + charAssoc.m_cmdlRigs[ci.cmdlIce] = {ci.cskrIce, ci.cinf}; + charAssoc.m_cskrToCharacter[ci.cskrIce] = + std::make_pair(entry.id, fmt::format(FMT_STRING("{}.ICE_{}.CSKR"), ci.name, ci.cskrIce)); + PAK::Entry* cmdlEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cmdlIce); + PAK::Entry* cskrEnt = (PAK::Entry*)m_pak.lookupEntry(ci.cskrIce); + cmdlEnt->name = fmt::format(FMT_STRING("ANCS_{}_{}_icemodel"), id, ci.name); + cskrEnt->name = fmt::format(FMT_STRING("ANCS_{}_{}_iceskin"), id, ci.name); + } } } std::map> animInfo; diff --git a/DataSpec/DNAMP1/FRME.cpp b/DataSpec/DNAMP1/FRME.cpp index 1927a6129..27e89411a 100644 --- a/DataSpec/DNAMP1/FRME.cpp +++ b/DataSpec/DNAMP1/FRME.cpp @@ -338,7 +338,7 @@ bool FRME::Extract(const SpecBase& dataSpec, PAKEntryReadStream& rs, const hecl: "cam.lens_unit = 'FOV'\n" "cam.clip_start = {}\n" "cam.clip_end = {}\n" - "bpy.context.scene.render.resolution_x = 480 * {}\n"), + "bpy.context.scene.render.resolution_x = int(480 * {})\n"), proj->znear, proj->zfar, proj->aspect); if (proj->aspect > 1.f) os.format(FMT_STRING("cam.angle = math.atan2({}, 1.0 / math.tan(math.radians({} / 2.0))) * 2.0\n"), diff --git a/hecl/blender/hecl_blendershell.py b/hecl/blender/hecl_blendershell.py index 7af8a934f..14c01ad04 100644 --- a/hecl/blender/hecl_blendershell.py +++ b/hecl/blender/hecl_blendershell.py @@ -505,7 +505,11 @@ try: bpy.context.preferences.filepaths.save_version = 0 print('SAVING %s' % loaded_blend) if loaded_blend: - if 'FINISHED' in bpy.ops.wm.save_as_mainfile(filepath=loaded_blend, check_existing=False, compress=True): + if bpy.app.version >= (3, 0, 0): + ret = bpy.ops.wm.save_as_mainfile(filepath=loaded_blend, check_existing=False, compress=False) + else: + ret = bpy.ops.wm.save_as_mainfile(filepath=loaded_blend, check_existing=False, compress=True) + if 'FINISHED' in ret: writepipestr(b'FINISHED') else: writepipestr(b'CANCELLED') diff --git a/hecl/lib/Blender/SDNARead.cpp b/hecl/lib/Blender/SDNARead.cpp index 723d2986e..4b839131d 100644 --- a/hecl/lib/Blender/SDNARead.cpp +++ b/hecl/lib/Blender/SDNARead.cpp @@ -79,44 +79,51 @@ SDNARead::SDNARead(std::string_view path) { r.readUBytesToBuf(magicBuf, 7); r.seek(0, athena::SeekOrigin::Begin); if (strncmp(magicBuf, "BLENDER", 7)) { - /* Try gzip decompression */ - std::unique_ptr compBuf(new uint8_t[4096]); - m_data.resize((length * 2 + 4095) & ~4095); - z_stream zstrm = {}; - inflateInit2(&zstrm, 16 + MAX_WBITS); - zstrm.next_out = (Bytef*)m_data.data(); - zstrm.avail_out = m_data.size(); - zstrm.total_out = 0; + atUint32 magic = hecl::SLittle(*(atUint32*)(magicBuf)); + if (magic == 0xfd2fb528) { + /* Try zstandard decompression */ + // TODO: Implement + m_data = {}; + } else if (magic == 0x88b1f) { + /* Try gzip decompression */ + std::unique_ptr compBuf(new uint8_t[4096]); + m_data.resize((length * 2 + 4095) & ~4095); + z_stream zstrm = {}; + inflateInit2(&zstrm, 16 + MAX_WBITS); + zstrm.next_out = (Bytef*)m_data.data(); + zstrm.avail_out = m_data.size(); + zstrm.total_out = 0; - atUint64 rs; - while ((rs = r.readUBytesToBuf(compBuf.get(), 4096))) { - int inflateRet; - zstrm.next_in = compBuf.get(); - zstrm.avail_in = rs; - while (zstrm.avail_in) { - if (!zstrm.avail_out) { - zstrm.avail_out = m_data.size(); - m_data.resize(zstrm.avail_out * 2); - zstrm.next_out = (Bytef*)m_data.data() + zstrm.avail_out; + atUint64 rs; + while ((rs = r.readUBytesToBuf(compBuf.get(), 4096))) { + int inflateRet; + zstrm.next_in = compBuf.get(); + zstrm.avail_in = rs; + while (zstrm.avail_in) { + if (!zstrm.avail_out) { + zstrm.avail_out = m_data.size(); + m_data.resize(zstrm.avail_out * 2); + zstrm.next_out = (Bytef*)m_data.data() + zstrm.avail_out; + } + inflateRet = inflate(&zstrm, Z_NO_FLUSH); + if (inflateRet == Z_STREAM_END) + break; + if (inflateRet != Z_OK) { + inflateEnd(&zstrm); + m_data = std::vector(); + return; + } } - inflateRet = inflate(&zstrm, Z_NO_FLUSH); if (inflateRet == Z_STREAM_END) break; - if (inflateRet != Z_OK) { - inflateEnd(&zstrm); - m_data = std::vector(); - return; - } } - if (inflateRet == Z_STREAM_END) - break; - } - inflateEnd(&zstrm); + inflateEnd(&zstrm); - if (strncmp((char*)m_data.data(), "BLENDER", 7)) { - m_data = std::vector(); - return; + if (strncmp((char*)m_data.data(), "BLENDER", 7)) { + m_data = std::vector(); + return; + } } } else { m_data.resize(length); diff --git a/hecl/lib/hecl.cpp b/hecl/lib/hecl.cpp index ce55f8c7b..a5e871850 100644 --- a/hecl/lib/hecl.cpp +++ b/hecl/lib/hecl.cpp @@ -161,7 +161,7 @@ bool IsPathBlend(const hecl::ProjectPath& path) { } buf = hecl::SLittle(buf); - return buf == 0x4e454c42 || buf == 0x88b1f; + return buf == 0x4e454c42 || buf == 0x88b1f || buf == 0xfd2fb528; } bool IsPathYAML(const hecl::ProjectPath& path) {