diff options
Diffstat (limited to '')
-rw-r--r-- | lyt/materials/material.cpp | 127 | ||||
-rw-r--r-- | lyt/materials/material.h | 183 | ||||
-rw-r--r-- | lyt/materials/texmap.cpp | 41 | ||||
-rw-r--r-- | lyt/materials/texmap.h | 25 |
4 files changed, 376 insertions, 0 deletions
diff --git a/lyt/materials/material.cpp b/lyt/materials/material.cpp new file mode 100644 index 0000000..a23534c --- /dev/null +++ b/lyt/materials/material.cpp @@ -0,0 +1,127 @@ +#include "material.h" +#include "../layout.h" + +LYTMaterial::LYTMaterial(LYTLayout &layout) : m_layout(layout) { +} + +LYTMaterial::~LYTMaterial() { +} + +LYTLayout &LYTMaterial::layout() const { + return m_layout; +} + + +void LYTMaterial::dumpToDebug() { + qDebug() << "LYTMaterial" << name << "@" << (void*)this; +} + + + +void LYTMaterial::writeToDataStream(QDataStream &out) { + WriteFixedLengthASCII(out, name, 0x14); +} + +void LYTMaterial::readFromDataStream(QDataStream &in) { + name = ReadFixedLengthASCII(in, 0x14); + + for (int i = 0; i < 3; i++) + ReadS10Color(this->colours[i], in); + + for (int i = 0; i < 4; i++) + ReadRGBA8Color(this->tevKColour[i], in); + + + LYTMaterialResourceNum resourceNum; + in >> (quint32&)resourceNum.value; + + // this is really complicated -_- + // first off: TexMap + texMaps.clear(); + + for (int i = 0; i < resourceNum.getTexMapNum(); i++) { + this->readTexMap(in); + } + + // TexSRT + /*texSRTs.clear(); + + for (int i = 0; i < resourceNum.getTexSRTNum(); i++) { + this->readTexSRT(in); + } + + // TexCoordGen + texCoordGens.clear(); + + for (int i = 0; i < resourceNum.getTexCoordGenNum(); i++) { + this->readTexCoordGen(in); + } + + // ChanCtrl + if (resourceNum.hasChanCtrl()) { + this->hasChanCtrl = true; + this->readChanCtrl(in); + } else { + this->hasChanCtrl = false; + } + + // MatCol + if (resourceNum.hasMatCol()) { + this->hasMatCol = true; + this->readMatCol(in); + } else { + this->hasMatCol = false; + } + + // TevSwapTable + if (resourceNum.hasTevSwapTable()) { + this->hasTevSwapTable = true; + this->readTevSwapTable(in); + } else { + this->hasTevSwapTable = false; + } + + // IndTexSRT + indTexSRTs.clear(); + + for (int i = 0; i < resourceNum.getIndTexSRTNum(); i++) { + this->readIndTexSRT(in); + } + + // IndTexStage + indTexStages.clear(); + + for (int i = 0; i < resourceNum.getIndTexStageNum(); i++) { + this->readIndirectStage(in); + } + + // TevStage + tevStages.clear(); + + for (int i = 0; i < resourceNum.getTevStageNum(); i++) { + this->readTevStage(in); + } + + // AlphaCompare + if (resourceNum.hasAlphaCompare()) { + this->hasAlphaCompare = true; + this->readAlphaCompare(in); + } else { + this->hasAlphaCompare = false; + } + + // BlendMode + if (resourceNum.hasBlendMode()) { + this->hasBlendMode = true; + this->readBlendMode(in); + } else { + this->hasBlendMode = false; + }*/ +} + + + +void LYTMaterial::readTexMap(QDataStream &in) { + this->texMaps.append(LYTTexMap()); + this->texMaps.last().readFromDataStream(in, m_layout); +} diff --git a/lyt/materials/material.h b/lyt/materials/material.h new file mode 100644 index 0000000..73a0e57 --- /dev/null +++ b/lyt/materials/material.h @@ -0,0 +1,183 @@ +#ifndef LYTMATERIAL_H +#define LYTMATERIAL_H + +#include <QtCore/QList> +#include <QtCore/QString> +#include <QtCore/QDataStream> +#include <QtCore/QDebug> + +#include "../common.h" +#include "texmap.h" + +class LYTLayout; + + +class LYTMaterialResourceNum { +public: + quint32 value; + + inline int getTexMapNum() { return BitExtract(value, 4, 28); } + inline int getTexSRTNum() { return BitExtract(value, 4, 24); } + inline int getTexCoordGenNum() { return BitExtract(value, 4, 20); } + inline bool hasChanCtrl() { return BitExtract(value, 1, 6); } + inline bool hasMatCol() { return BitExtract(value, 1, 4); } + inline bool hasTevSwapTable() { return BitExtract(value, 1, 19); } + inline bool hasAlphaCompare() { return BitExtract(value, 1, 8); } + inline bool hasBlendMode() { return BitExtract(value, 1, 7); } + inline int getIndTexSRTNum() { return BitExtract(value, 2, 17); } + inline int getIndTexStageNum() { return BitExtract(value, 3, 14); } + inline int getTevStageNum() { return BitExtract(value, 5, 9); } +}; + + + +class LYTTexCoordGen { +public: + void writeToDataStream(QDataStream &out); + void readFromDataStream(QDataStream &in); + + void dumpToDebug(); + + quint8 genType; + quint8 src; + quint8 mtx; +}; + +class LYTChanCtrl { +public: + void writeToDataStream(QDataStream &out); + void readFromDataStream(QDataStream &in); + + void dumpToDebug(); + + quint8 colourMatSrc; + quint8 alphaMatSrc; +}; + +class LYTTevSwapMode { +public: + void writeToDataStream(QDataStream &out); + void readFromDataStream(QDataStream &in); + + void dumpToDebug(); + + int red; + int green; + int blue; + int alpha; +}; + +class LYTTexSRT { +public: + void writeToDataStream(QDataStream &out); + void readFromDataStream(QDataStream &in); + + void dumpToDebug(); + + float xTrans; + float yTrans; + float rotate; + float xScale; + float yScale; +}; + +class LYTIndirectStage { +public: + void writeToDataStream(QDataStream &out); + void readFromDataStream(QDataStream &in); + + void dumpToDebug(); + +}; + +class LYTTevStage { +public: + void writeToDataStream(QDataStream &out); + void readFromDataStream(QDataStream &in); + + void dumpToDebug(); + +}; + +class LYTAlphaCompare { +public: + void writeToDataStream(QDataStream &out); + void readFromDataStream(QDataStream &in); + + void dumpToDebug(); + +}; + +class LYTBlendMode { +public: + void writeToDataStream(QDataStream &out); + void readFromDataStream(QDataStream &in); + + void dumpToDebug(); + +}; + + + + +class LYTMaterial { +public: + LYTMaterial(LYTLayout &layout); + ~LYTMaterial(); + + + void writeToDataStream(QDataStream &out); + void readFromDataStream(QDataStream &in); + + void dumpToDebug(); + + LYTLayout &layout() const; + + QString name; + + QColor colours[3]; + QColor tevKColour[4]; + + QList<LYTTexMap> texMaps; + QList<LYTTexSRT> texSRTs; + QList<LYTTexCoordGen> texCoordGens; + + bool hasChanCtrl; + LYTChanCtrl chanCtrl; + + bool hasMatCol; + QColor matCol; + + bool hasTevSwapTable; + LYTTevSwapMode tevSwapTable; + + bool hasAlphaCompare; + LYTAlphaCompare alphaCompare; + + bool hasBlendMode; + LYTBlendMode blendMode; + + QList<LYTIndirectStage> indTexStages; + QList<LYTTexSRT> indTexSRTs; + + QList<LYTTevStage> tevStages; + + + +protected: + LYTLayout &m_layout; + + void readTexMap(QDataStream &in); + void readTexSRT(QDataStream &in); + void readTexCoordGen(QDataStream &in); + void readChanCtrl(QDataStream &in); + void readMatCol(QDataStream &in); + void readTevSwapTable(QDataStream &in); + void readAlphaCompare(QDataStream &in); + void readBlendMode(QDataStream &in); + void readIndirectStage(QDataStream &in); + void readIndTexSRT(QDataStream &in); + void readTevStage(QDataStream &in); +}; + +#endif // LYTMATERIAL_H diff --git a/lyt/materials/texmap.cpp b/lyt/materials/texmap.cpp new file mode 100644 index 0000000..1bb416b --- /dev/null +++ b/lyt/materials/texmap.cpp @@ -0,0 +1,41 @@ +#include "texmap.h" +#include "../layout.h" + +LYTTexMap::LYTTexMap() { +} + +void LYTTexMap::dumpToDebug() { + qDebug() << "LYTTexMap @" << (void*)this << ":" << textureName; + qDebug() << "- wrap_s:" << wrap_s << "- wrap_t:" << wrap_t; + qDebug() << "- mag_filter:" << mag_filter << "- min_filter:" << min_filter; +} + + +void LYTTexMap::writeToDataStream(QDataStream &out, LYTLayout &layout) { + quint16 texNum = layout.m_textureRefs.indexOf(textureName); + out << (quint16)texNum; + + quint8 var1, var2; + var1 = wrap_s | (((min_filter + 7) & 7) << 2); + var2 = wrap_t | (((mag_filter + 1) & 1) << 2); + out << (quint8)var1; + out << (quint8)var2; +} + + +void LYTTexMap::readFromDataStream(QDataStream &in, LYTLayout &layout) { + quint16 texNum; + in >> (quint16&)texNum; + + textureName = layout.m_textureRefs[texNum]; + + quint8 var1, var2; + in >> (quint8&)var1; + in >> (quint8&)var2; + + wrap_s = BitExtract(var1, 2, 30); + wrap_t = BitExtract(var2, 2, 30); + + min_filter = (BitExtract(var1, 3, 27) + 1) & 7; + mag_filter = (BitExtract(var2, 1, 29) + 1) & 1; +} diff --git a/lyt/materials/texmap.h b/lyt/materials/texmap.h new file mode 100644 index 0000000..5f74478 --- /dev/null +++ b/lyt/materials/texmap.h @@ -0,0 +1,25 @@ +#ifndef LYTTEXMAP_H +#define LYTTEXMAP_H + +#include "../common.h" +#include <QtCore/QDataStream> + +class LYTLayout; // forward declaration + +class LYTTexMap { +public: + LYTTexMap(); + + void writeToDataStream(QDataStream &out, LYTLayout &layout); + void readFromDataStream(QDataStream &in, LYTLayout &layout); + + void dumpToDebug(); + + QString textureName; + int wrap_s; + int wrap_t; + int mag_filter; + int min_filter; +}; + +#endif // LYTTEXMAP_H |