Mesh cooker fixes

This commit is contained in:
Jack Andersen 2015-10-20 15:34:35 -10:00
parent bf8a007514
commit 4a389040fc
6 changed files with 70 additions and 24 deletions

View File

@ -1042,8 +1042,6 @@ static void WriteDLVal(Athena::io::FileWriter& writer, GX::AttrType type, atUint
template <class MaterialSet, class SurfaceHeader, atUint32 Version>
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<size_t>::const_iterator padIt = paddingSizes.cbegin();

View File

@ -8,6 +8,8 @@
#include "CINF.hpp"
#include "CSKR.hpp"
#include <Athena/FileReader.hpp>
namespace Retro
{
namespace DNAMP1
@ -42,6 +44,25 @@ struct CMDL
return false;
DNACMDL::ReadCMDLToBlender<PAKRouter<PAKBridge>, MaterialSet, std::pair<CSKR*,CINF*>, 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<MaterialSet, DNACMDL::SurfaceHeader_1_2, 2>(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<PAKRouter<PAKBridge>, MaterialSet, std::pair<CSKR*,CINF*>, 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<MaterialSet, DNACMDL::SurfaceHeader_1_2, 2>(outPath, inPath, mesh);
HECL::ProjectPath tempOut = outPath.getWithExtension(_S(".recook"));
return DNACMDL::WriteCMDL<MaterialSet, DNACMDL::SurfaceHeader_1_2, 2>(tempOut, inPath, mesh);
}
};

View File

@ -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<gx.m_tevCount ; ++i)
if (gx.m_tevs[i].m_texMapIdx != -1)
{
const HECL::Backend::GX::TEVStage& stage = gx.m_tevs[i];
tevStageTexInfo.emplace_back();
TEVStageTexInfo& texInfo = tevStageTexInfo.back();
if (stage.m_texGenIdx != -1)
texInfo.tcgSlot = stage.m_texGenIdx;
if (stage.m_texMapIdx != -1)
{
const HECL::ProjectPath& texPath = texPathsIn.at(gx.m_tevs[i].m_texMapIdx);
texInfo.texSlot = textureIdxs.size();
const HECL::ProjectPath& texPath = texPathsIn.at(stage.m_texMapIdx);
texFlags |= 1 << i;
++textureCount;
bool found = false;
@ -923,16 +954,17 @@ MaterialSet::Material::Material(const HECL::Backend::GX& gx,
if (texPath == texPathsOut[t])
{
found = true;
texureIdxs.push_back(t);
textureIdxs.push_back(t);
break;
}
}
if (!found)
{
texureIdxs.push_back(texPathsOut.size());
textureIdxs.push_back(texPathsOut.size());
texPathsOut.push_back(texPath);
}
}
}
flags.setTextureSlots(texFlags);
vaFlags.setPosition(GX::INDEX16);
@ -985,7 +1017,7 @@ MaterialSet::Material::Material(const HECL::Backend::GX& gx,
blendDstFac = BlendFactor(gx.m_blendDst);
blendSrcFac = BlendFactor(gx.m_blendSrc);
if (flags.samusReflectionIndirectTexture())
indTexSlot.push_back(texureIdxs.size());
indTexSlot.push_back(textureIdxs.size());
colorChannelCount = 1;
colorChannels.emplace_back();
@ -1008,6 +1040,7 @@ MaterialSet::Material::Material(const HECL::Backend::GX& gx,
ch.setAttenuationFn(GX::AF_SPOT);
tevStageCount = gx.m_tevCount;
tevStages.reserve(gx.m_tevCount);
for (int i=0 ; i<gx.m_tevCount ; ++i)
{
const HECL::Backend::GX::TEVStage& stage = gx.m_tevs[i];
@ -1034,15 +1067,6 @@ MaterialSet::Material::Material(const HECL::Backend::GX& gx,
target.setAlphaOpOutReg(stage.m_aRegOut);
target.setKColorIn(stage.m_kColor);
target.setKAlphaIn(stage.m_kAlpha);
tevStageTexInfo.emplace_back();
TEVStageTexInfo& texInfo = tevStageTexInfo.back();
texInfo.texSlot = -1;
if (stage.m_texMapIdx != -1)
texInfo.texSlot = stage.m_texMapIdx;
texInfo.tcgSlot = -1;
if (stage.m_texGenIdx != -1)
texInfo.tcgSlot = stage.m_texGenIdx;
}
tcgCount = gx.m_tcgCount;
@ -1060,6 +1084,7 @@ MaterialSet::Material::Material(const HECL::Backend::GX& gx,
{
if (!tcg.m_gameFunction.compare("RetroUVMode0Node") ||
!tcg.m_gameFunction.compare("RetroUVMode1Node") ||
!tcg.m_gameFunction.compare("RetroUVMode6Node") ||
!tcg.m_gameFunction.compare("RetroUVMode7Node"))
{
target.setNormalize(true);

View File

@ -61,7 +61,7 @@ struct MaterialSet : BigDNA
const Flags& getFlags() const {return flags;}
Value<atUint32> textureCount = 0;
Vector<atUint32, DNA_COUNT(textureCount)> texureIdxs;
Vector<atUint32, DNA_COUNT(textureCount)> textureIdxs;
struct VAFlags : BigDNA
{
DECL_DNA
@ -236,8 +236,8 @@ struct MaterialSet : BigDNA
{
DECL_DNA
Value<atUint16> pad = 0;
Value<atUint8> texSlot = 0;
Value<atUint8> tcgSlot = 0;
Value<atUint8> texSlot = 0xff;
Value<atUint8> tcgSlot = 0xff;
};
Vector<TEVStageTexInfo, DNA_COUNT(tevStageCount)> tevStageTexInfo;

View File

@ -27,7 +27,7 @@ struct MaterialSet : BigDNA
const Flags& getFlags() const {return flags;}
Value<atUint32> textureCount;
Vector<atUint32, DNA_COUNT(textureCount)> texureIdxs;
Vector<atUint32, DNA_COUNT(textureCount)> textureIdxs;
using VAFlags = DNAMP1::MaterialSet::Material::VAFlags;
DNAMP1::MaterialSet::Material::VAFlags vaFlags;
const VAFlags& getVAFlags() const {return vaFlags;}

2
hecl

@ -1 +1 @@
Subproject commit ad061af83e93d766aab3bd0985a7984f9cbea5bf
Subproject commit 43498db9f7a56f46ba8844c83113c5d8e2fb7adc