TEV->Blender fixes

This commit is contained in:
Jack Andersen 2015-10-10 19:56:42 -10:00
parent c13757106b
commit f77900a9cb
4 changed files with 76 additions and 20 deletions

View File

@ -1,6 +1,9 @@
#ifndef _DNACOMMON_CMDL_HPP_
#define _DNACOMMON_CMDL_HPP_
#include <Athena/FileWriter.hpp>
#include <HECL/Frontend.hpp>
#include <HECL/Backend/GX.hpp>
#include "PAK.hpp"
#include "BlenderConnection.hpp"
#include "GX.hpp"
@ -1021,6 +1024,46 @@ bool ReadCMDLToBlender(HECL::BlenderConnection& conn,
return true;
}
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.getAbsolutePath());
Header head;
head.magic = 0xDEADBABE;
head.version = Version;
head.flags.flags = 0;
head.aabbMin = mesh.aabbMin.val;
head.aabbMax = mesh.aabbMax.val;
head.matSetCount = mesh.materialSets.size();
head.secCount = head.matSetCount + 5 + mesh.surfaces.size();
head.secSizes.reserve(head.secCount);
/* Build material sets */
{
HECL::Frontend::Frontend FE;
int setIdx = 0;
for (const std::vector<Mesh::Material>& mset : mesh.materialSets)
{
int matIdx = 0;
for (const Mesh::Material& mat : mset)
{
std::string diagName = HECL::SysFormat(_S("%s:%d:%d"), inPath.getLastComponent(), setIdx, matIdx);
HECL::Frontend::IR matIR = FE.compileSource(mat.source, diagName);
HECL::Backend::GX matGX;
matGX.reset(matIR);
++matIdx;
}
++setIdx;
}
}
head.write(writer);
return true;
}
}
}

View File

@ -48,6 +48,7 @@ struct CMDL
static bool Cook(const DNACMDL::Mesh& mesh,
const HECL::ProjectPath& outPath)
{
return true;
}
};

View File

@ -305,7 +305,7 @@ static void AddColorCombiner(Stream& out, CombinerType type,
if (v)
out.format("new_nodetree.links.new(combiner_node.outputs['Color'], %s)\n", v);
out << "color_combiner_nodes.append(combiner_node)\n\n";
out << "color_combiner_sockets.append(combiner_node.outputs['Color'])\n\n";
}
static void AddAlphaCombiner(Stream& out, enum CombinerType type,
@ -347,7 +347,7 @@ static void AddAlphaCombiner(Stream& out, enum CombinerType type,
if (v)
out.format("new_nodetree.links.new(combiner_node.outputs[0], %s)\n", v);
out << "alpha_combiner_nodes.append(combiner_node)\n\n";
out << "alpha_combiner_sockets.append(combiner_node.outputs[0])\n\n";
}
static void TranslateColorSocket(char* socketOut, GX::TevColorArg arg,
@ -486,30 +486,36 @@ static void AddTEVStage(Stream& out, const MaterialSet::Material::TEVStage& stag
if (!(c_tev_opts & 1))
{
/* A nodes */
AddColorCombiner(out, COMB_SUB, "ONE", ca, NULL);
++c_combiner_idx;
AddColorCombiner(out, COMB_MULT, "color_combiner_nodes[-1].outputs[0]", cc, NULL);
AddColorCombiner(out, COMB_SUB, "ONE", ca, nullptr);
++c_combiner_idx;
if (strcmp(cc, "ONE"))
{
AddColorCombiner(out, COMB_MULT, cc, "color_combiner_sockets[-1]", nullptr);
++c_combiner_idx;
}
}
if (!(c_tev_opts & 2))
{
/* B nodes */
AddColorCombiner(out, COMB_MULT, cb, cc, NULL);
if (!strcmp(cc, "ONE"))
out.format("color_combiner_sockets.append(%s)\n", cb);
else
AddColorCombiner(out, COMB_MULT, cc, cb, nullptr);
++c_combiner_idx;
}
if (!(c_tev_opts & 4))
{
/* A+B node */
AddColorCombiner(out, COMB_ADD, "color_combiner_nodes[-2].outputs[0]", "color_combiner_nodes[-1].outputs[0]", NULL);
AddColorCombiner(out, COMB_ADD, "color_combiner_sockets[-1]", "color_combiner_sockets[-2]", nullptr);
++c_combiner_idx;
}
if (!(c_tev_opts & 8))
{
/* +D node */
AddColorCombiner(out, COMB_ADD, "color_combiner_nodes[-1].outputs[0]", cd, NULL);
AddColorCombiner(out, COMB_ADD, cd, "color_combiner_sockets[-1]", nullptr);
++c_combiner_idx;
}
@ -527,30 +533,36 @@ static void AddTEVStage(Stream& out, const MaterialSet::Material::TEVStage& stag
if (!(a_tev_opts & 1))
{
/* A nodes */
AddAlphaCombiner(out, COMB_SUB, "ONE", aa, NULL);
++a_combiner_idx;
AddAlphaCombiner(out, COMB_MULT, "alpha_combiner_nodes[-1].outputs[0]", ac, NULL);
AddAlphaCombiner(out, COMB_SUB, "ONE", aa, nullptr);
++a_combiner_idx;
if (strcmp(ac, "ONE"))
{
AddAlphaCombiner(out, COMB_MULT, ac, "alpha_combiner_sockets[-1]", nullptr);
++a_combiner_idx;
}
}
if (!(a_tev_opts & 2))
{
/* B nodes */
AddAlphaCombiner(out, COMB_MULT, ab, ac, NULL);
if (!strcmp(ac, "ONE"))
out.format("alpha_combiner_sockets.append(%s)\n", ab);
else
AddAlphaCombiner(out, COMB_MULT, ac, ab, nullptr);
++a_combiner_idx;
}
if (!(a_tev_opts & 4))
{
/* A+B node */
AddAlphaCombiner(out, COMB_ADD, "alpha_combiner_nodes[-2].outputs[0]", "alpha_combiner_nodes[-1].outputs[0]", NULL);
AddAlphaCombiner(out, COMB_ADD, "alpha_combiner_sockets[-1]", "alpha_combiner_sockets[-2]", nullptr);
++a_combiner_idx;
}
if (!(a_tev_opts & 8))
{
/* +D node */
AddAlphaCombiner(out, COMB_ADD, "alpha_combiner_nodes[-1].outputs[0]", ad, NULL);
AddAlphaCombiner(out, COMB_ADD, ad, "alpha_combiner_sockets[-1]", nullptr);
++a_combiner_idx;
}
@ -561,14 +573,14 @@ static void AddTEVStage(Stream& out, const MaterialSet::Material::TEVStage& stag
strncpy(c_regs[stage.colorOpOutReg()], cd, 64);
}
else
snprintf(c_regs[stage.colorOpOutReg()], 64, "color_combiner_nodes[%u].outputs[0]", c_combiner_idx - 1);
snprintf(c_regs[stage.colorOpOutReg()], 64, "color_combiner_sockets[%u]", c_combiner_idx - 1);
if (a_tev_opts == 0xf)
{
if (stage.alphaInD() != GX::CA_ZERO)
strncpy(a_regs[stage.alphaOpOutReg()], ad, 64);
}
else
snprintf(a_regs[stage.alphaOpOutReg()], 64, "alpha_combiner_nodes[%u].outputs[0]", a_combiner_idx - 1);
snprintf(a_regs[stage.alphaOpOutReg()], 64, "alpha_combiner_sockets[%u]", a_combiner_idx - 1);
/* Row Break in gridder */
out << "gridder.row_break(2)\n";
@ -601,8 +613,8 @@ void _ConstructMaterial(Stream& out,
"\n"
"texture_nodes = []\n"
"kcolor_nodes = []\n"
"color_combiner_nodes = []\n"
"alpha_combiner_nodes = []\n"
"color_combiner_sockets = []\n"
"alpha_combiner_sockets = []\n"
"tex_links = []\n"
"tev_reg_sockets = [None]*4\n"
"\n", groupIdx, matIdx);

View File

@ -221,11 +221,11 @@ struct MaterialSet : BigDNA
void setType(GX::TexGenType val) {flags &= ~0xf; flags |= atUint32(val);}
GX::TexGenSrc source() const {return GX::TexGenSrc(flags >> 4 & 0x1f);}
void setSource(GX::TexGenSrc val) {flags &= ~0x1f0; flags |= atUint32(val) << 4;}
GX::TexMtx mtx() const {return GX::TexMtx(flags >> 9 & 0x1f + 30);}
GX::TexMtx mtx() const {return GX::TexMtx((flags >> 9 & 0x1f) + 30);}
void setMtx(GX::TexMtx val) {flags &= ~0x3e00; flags |= (atUint32(val)-30) << 9;}
bool normalize() const {return flags >> 14 & 0x1;}
void setNormalize(bool val) {flags &= ~0x4000; flags |= atUint32(val) << 14;}
GX::PTTexMtx postMtx() const {return GX::PTTexMtx(flags >> 15 & 0x3f + 64);}
GX::PTTexMtx postMtx() const {return GX::PTTexMtx((flags >> 15 & 0x3f) + 64);}
void setPostMtx(GX::PTTexMtx val) {flags &= ~0x1f8000; flags |= (atUint32(val)-64) << 15;}
};
Vector<TexCoordGen, DNA_COUNT(tcgCount)> tcgs;