From 4a389040fc416b5103597f9e5b082021eca21345 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 20 Oct 2015 15:34:35 -1000 Subject: [PATCH] Mesh cooker fixes --- DataSpec/DNACommon/CMDL.hpp | 3 +- DataSpec/DNAMP1/CMDL.hpp | 24 ++++++++++++- DataSpec/DNAMP1/CMDLMaterials.cpp | 57 ++++++++++++++++++++++--------- DataSpec/DNAMP1/CMDLMaterials.hpp | 6 ++-- DataSpec/DNAMP2/CMDLMaterials.hpp | 2 +- hecl | 2 +- 6 files changed, 70 insertions(+), 24 deletions(-) diff --git a/DataSpec/DNACommon/CMDL.hpp b/DataSpec/DNACommon/CMDL.hpp index 443576cad..6f63facdd 100644 --- a/DataSpec/DNACommon/CMDL.hpp +++ b/DataSpec/DNACommon/CMDL.hpp @@ -1042,8 +1042,6 @@ static void WriteDLVal(Athena::io::FileWriter& writer, GX::AttrType type, atUint template bool WriteCMDL(const HECL::ProjectPath& outPath, const HECL::ProjectPath& inPath, const Mesh& mesh) { - Athena::io::FileWriter writer(outPath.getWithExtension(_S(".recook")).getAbsolutePath()); - Header head; head.magic = 0xDEADBABE; head.version = Version; @@ -1183,6 +1181,7 @@ bool WriteCMDL(const HECL::ProjectPath& outPath, const HECL::ProjectPath& inPath } /* Write sections */ + Athena::io::FileWriter writer(outPath.getAbsolutePath()); head.write(writer); std::vector::const_iterator padIt = paddingSizes.cbegin(); diff --git a/DataSpec/DNAMP1/CMDL.hpp b/DataSpec/DNAMP1/CMDL.hpp index f0bb1eebf..d4c18e6ca 100644 --- a/DataSpec/DNAMP1/CMDL.hpp +++ b/DataSpec/DNAMP1/CMDL.hpp @@ -8,6 +8,8 @@ #include "CINF.hpp" #include "CSKR.hpp" +#include + namespace Retro { namespace DNAMP1 @@ -42,6 +44,25 @@ struct CMDL return false; DNACMDL::ReadCMDLToBlender, MaterialSet, std::pair, DNACMDL::SurfaceHeader_1_2, 2> (conn, rs, pakRouter, entry, dataSpec, loadRp); + conn.saveBlend(); + +#if 1 + return true; +#endif + + /* Cook and re-extract test */ + HECL::ProjectPath tempOut = outPath.getWithExtension(_S(".recook"), true); + HECL::BlenderConnection::DataStream ds = conn.beginData(); + HECL::BlenderConnection::DataStream::Mesh mesh = ds.compileMesh(-1); + ds.close(); + DNACMDL::WriteCMDL(tempOut, outPath, mesh); + + Athena::io::FileReader reader(tempOut.getAbsolutePath()); + HECL::ProjectPath tempBlend = outPath.getWithExtension(_S(".recook.blend"), true); + if (!conn.createBlend(tempBlend, HECL::BlenderConnection::TypeMesh)) + return false; + DNACMDL::ReadCMDLToBlender, MaterialSet, std::pair, DNACMDL::SurfaceHeader_1_2, 2> + (conn, reader, pakRouter, entry, dataSpec, loadRp); return conn.saveBlend(); } @@ -49,7 +70,8 @@ struct CMDL const HECL::ProjectPath& inPath, const DNACMDL::Mesh& mesh) { - return DNACMDL::WriteCMDL(outPath, inPath, mesh); + HECL::ProjectPath tempOut = outPath.getWithExtension(_S(".recook")); + return DNACMDL::WriteCMDL(tempOut, inPath, mesh); } }; diff --git a/DataSpec/DNAMP1/CMDLMaterials.cpp b/DataSpec/DNAMP1/CMDLMaterials.cpp index 2a7e49fdd..4b930449f 100644 --- a/DataSpec/DNAMP1/CMDLMaterials.cpp +++ b/DataSpec/DNAMP1/CMDLMaterials.cpp @@ -166,7 +166,7 @@ void Material::AddTextureAnim(Stream& out, " new_nodetree.links.remove(link)\n" " new_nodetree.links.new(soc_from, node.inputs[0])\n" " new_nodetree.links.new(node.outputs[0], soc_to)\n\n", - idx, vals[0], vals[1], vals[3], vals[2]); + idx, vals[0], vals[1], vals[2], vals[3]); break; case UVAnimation::ANIM_MODEL: out.format("for link in list(tex_links):\n" @@ -571,6 +571,17 @@ static void AddTEVStage(Stream& out, const MaterialSet::Material::TEVStage& stag if (stage.colorInD() == GX::CC_ZERO || (c_tev_opts & 7) == 7) c_tev_opts |= 8; + /* Special A/D (additive) optimization */ + if (stage.colorInA() != GX::CC_ZERO && + stage.colorInB() == GX::CC_ZERO && + stage.colorInC() == GX::CC_ZERO && + stage.colorInD() != GX::CC_ZERO) + { + c_tev_opts |= 0x1f; + AddColorCombiner(out, COMB_ADD, cd, ca, nullptr); + ++c_combiner_idx; + } + if (!(c_tev_opts & 1)) { /* A nodes */ @@ -634,6 +645,17 @@ static void AddTEVStage(Stream& out, const MaterialSet::Material::TEVStage& stag if (stage.alphaInD() == GX::CA_ZERO || (a_tev_opts & 7) == 7) a_tev_opts |= 8; + /* Special A/D (additive) optimization */ + if (stage.alphaInA() != GX::CA_ZERO && + stage.alphaInB() == GX::CA_ZERO && + stage.alphaInC() == GX::CA_ZERO && + stage.alphaInD() != GX::CA_ZERO) + { + a_tev_opts |= 0x1f; + AddAlphaCombiner(out, COMB_ADD, ad, aa, nullptr); + ++a_combiner_idx; + } + if (!(a_tev_opts & 1)) { /* A nodes */ @@ -762,7 +784,7 @@ void _ConstructMaterial(Stream& out, /* Texture Indices */ out << "tex_maps = []\n"; - for (atUint32 idx : material.texureIdxs) + for (atUint32 idx : material.textureIdxs) out.format("tex_maps.append(texmap_list[%u])\n", idx); /* KColor entries */ @@ -911,10 +933,19 @@ MaterialSet::Material::Material(const HECL::Backend::GX& gx, flags.setLightmapUVArray(lightmapUVs); atUint16 texFlags = 0; + tevStageTexInfo.reserve(gx.m_tevCount); + textureIdxs.reserve(gx.m_tevCount); for (int i=0 ; i textureCount = 0; - Vector texureIdxs; + Vector textureIdxs; struct VAFlags : BigDNA { DECL_DNA @@ -236,8 +236,8 @@ struct MaterialSet : BigDNA { DECL_DNA Value pad = 0; - Value texSlot = 0; - Value tcgSlot = 0; + Value texSlot = 0xff; + Value tcgSlot = 0xff; }; Vector tevStageTexInfo; diff --git a/DataSpec/DNAMP2/CMDLMaterials.hpp b/DataSpec/DNAMP2/CMDLMaterials.hpp index 7e848b10a..de94ac24a 100644 --- a/DataSpec/DNAMP2/CMDLMaterials.hpp +++ b/DataSpec/DNAMP2/CMDLMaterials.hpp @@ -27,7 +27,7 @@ struct MaterialSet : BigDNA const Flags& getFlags() const {return flags;} Value textureCount; - Vector texureIdxs; + Vector textureIdxs; using VAFlags = DNAMP1::MaterialSet::Material::VAFlags; DNAMP1::MaterialSet::Material::VAFlags vaFlags; const VAFlags& getVAFlags() const {return vaFlags;} diff --git a/hecl b/hecl index ad061af83..43498db9f 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit ad061af83e93d766aab3bd0985a7984f9cbea5bf +Subproject commit 43498db9f7a56f46ba8844c83113c5d8e2fb7adc