2015-08-10 01:53:24 +00:00
|
|
|
#ifndef _DNAMP3_CMDL_MATERIALS_HPP_
|
|
|
|
#define _DNAMP3_CMDL_MATERIALS_HPP_
|
|
|
|
|
|
|
|
#include "../DNACommon/DNACommon.hpp"
|
|
|
|
#include "../DNACommon/GX.hpp"
|
|
|
|
#include "../DNAMP1/CMDLMaterials.hpp"
|
|
|
|
#include "DNAMP3.hpp"
|
|
|
|
|
2017-12-29 08:08:12 +00:00
|
|
|
namespace DataSpec::DNAMP3
|
2015-08-10 01:53:24 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
struct MaterialSet : BigDNA
|
|
|
|
{
|
2015-09-19 01:38:40 +00:00
|
|
|
static constexpr bool OneSection() {return true;}
|
|
|
|
|
2015-08-10 01:53:24 +00:00
|
|
|
DECL_DNA
|
|
|
|
Value<atUint32> materialCount;
|
|
|
|
|
2015-10-19 03:28:47 +00:00
|
|
|
/* Dummy methods from MP1/2 */
|
|
|
|
void addTexture(const UniqueID32&) {}
|
|
|
|
void addMaterialEndOff(atUint32) {++materialCount;}
|
|
|
|
|
2015-08-10 01:53:24 +00:00
|
|
|
struct Material : BigDNA
|
|
|
|
{
|
|
|
|
Delete expl;
|
|
|
|
using VAFlags = DNAMP1::MaterialSet::Material::VAFlags;
|
|
|
|
struct Header : BigDNA
|
|
|
|
{
|
|
|
|
DECL_DNA
|
|
|
|
Value<atUint32> size;
|
|
|
|
struct Flags : BigDNA
|
|
|
|
{
|
|
|
|
DECL_DNA
|
|
|
|
Value<atUint32> flags;
|
2015-09-07 04:05:44 +00:00
|
|
|
bool alphaBlending() const {return (flags & 0x8) != 0;}
|
|
|
|
void setAlphaBlending(bool enabled) {flags &= ~0x8; flags |= atUint32(enabled) << 3;}
|
|
|
|
bool punchthroughAlpha() const {return (flags & 0x10) != 0;}
|
|
|
|
void setPunchthroughAlpha(bool enabled) {flags &= ~0x10; flags |= atUint32(enabled) << 4;}
|
|
|
|
bool additiveBlending() const {return (flags & 0x20) != 0;}
|
|
|
|
void setAdditiveBlending(bool enabled) {flags &= ~0x20; flags |= atUint32(enabled) << 5;}
|
|
|
|
bool shadowOccluderMesh() const {return (flags & 0x100) != 0;}
|
|
|
|
void setShadowOccluderMesh(bool enabled) {flags &= ~0x100; flags |= atUint32(enabled) << 8;}
|
|
|
|
bool lightmapUVArray() const {return false;} /* For polymorphic compatibility with MP1/2 */
|
2015-08-10 01:53:24 +00:00
|
|
|
} flags;
|
|
|
|
Value<atUint32> groupIdx;
|
|
|
|
Value<atUint32> unk1;
|
2015-08-15 22:56:55 +00:00
|
|
|
VAFlags vaFlags;
|
2015-08-10 01:53:24 +00:00
|
|
|
Value<atUint32> unk2;
|
|
|
|
Value<atUint32> unk3;
|
|
|
|
Value<atUint32> unk4;
|
|
|
|
} header;
|
2015-09-07 04:05:44 +00:00
|
|
|
const Header::Flags& getFlags() const {return header.flags;}
|
|
|
|
const VAFlags& getVAFlags() const {return header.vaFlags;}
|
2015-08-10 01:53:24 +00:00
|
|
|
|
|
|
|
struct ISection : BigDNA
|
|
|
|
{
|
|
|
|
Delete expl;
|
2015-11-21 01:16:07 +00:00
|
|
|
enum class Type : atUint32
|
2015-08-10 01:53:24 +00:00
|
|
|
{
|
|
|
|
PASS = SBIG('PASS'),
|
|
|
|
CLR = SBIG('CLR '),
|
|
|
|
INT = SBIG('INT ')
|
|
|
|
} m_type;
|
|
|
|
ISection(Type type) : m_type(type) {}
|
2017-12-29 08:08:12 +00:00
|
|
|
virtual void constructNode(hecl::blender::PyOutStream& out,
|
2015-09-19 01:38:40 +00:00
|
|
|
const PAKRouter<PAKBridge>& pakRouter,
|
|
|
|
const PAK::Entry& entry,
|
|
|
|
const Material::ISection* prevSection,
|
|
|
|
unsigned idx,
|
|
|
|
unsigned& texMapIdx,
|
|
|
|
unsigned& texMtxIdx,
|
|
|
|
unsigned& kColorIdx) const=0;
|
2015-08-10 01:53:24 +00:00
|
|
|
};
|
|
|
|
struct SectionPASS : ISection
|
|
|
|
{
|
2015-11-21 01:16:07 +00:00
|
|
|
SectionPASS() : ISection(ISection::Type::PASS) {}
|
2015-08-10 01:53:24 +00:00
|
|
|
DECL_DNA
|
|
|
|
Value<atUint32> size;
|
2015-11-21 01:16:07 +00:00
|
|
|
enum class Subtype : atUint32
|
2015-08-10 01:53:24 +00:00
|
|
|
{
|
|
|
|
DIFF = SBIG('DIFF'),
|
|
|
|
RIML = SBIG('RIML'),
|
|
|
|
BLOL = SBIG('BLOL'),
|
|
|
|
BLOD = SBIG('BLOD'),
|
|
|
|
CLR = SBIG('CLR '),
|
|
|
|
TRAN = SBIG('TRAN'),
|
|
|
|
INCA = SBIG('INCA'),
|
|
|
|
RFLV = SBIG('RFLV'),
|
|
|
|
RFLD = SBIG('RFLD'),
|
|
|
|
LRLD = SBIG('LRLD'),
|
|
|
|
LURD = SBIG('LURD'),
|
|
|
|
BLOI = SBIG('BLOI'),
|
|
|
|
XRAY = SBIG('XRAY'),
|
|
|
|
TOON = SBIG('TOON')
|
|
|
|
};
|
2015-08-23 06:42:29 +00:00
|
|
|
DNAFourCC subtype;
|
2015-08-10 01:53:24 +00:00
|
|
|
struct Flags : BigDNA
|
|
|
|
{
|
|
|
|
DECL_DNA
|
|
|
|
Value<atUint32> flags;
|
2015-09-19 01:38:40 +00:00
|
|
|
bool TRANInvert() const {return (flags & 0x10) != 0;}
|
|
|
|
void setTRANInvert(bool enabled) {flags &= ~0x10; flags |= atUint32(enabled) << 4;}
|
2015-08-10 01:53:24 +00:00
|
|
|
} flags;
|
|
|
|
UniqueID64 txtrId;
|
|
|
|
Value<atUint32> uvSrc;
|
|
|
|
Value<atUint32> uvAnimSize;
|
|
|
|
struct UVAnimation : BigDNA
|
|
|
|
{
|
|
|
|
DECL_DNA
|
|
|
|
Value<atUint16> unk1;
|
|
|
|
Value<atUint16> unk2;
|
|
|
|
DNAMP1::MaterialSet::Material::UVAnimation anim;
|
|
|
|
};
|
|
|
|
Vector<UVAnimation, DNA_COUNT(uvAnimSize != 0)> uvAnim;
|
2015-09-19 01:38:40 +00:00
|
|
|
|
2017-12-29 08:08:12 +00:00
|
|
|
void constructNode(hecl::blender::PyOutStream& out,
|
2015-09-19 01:38:40 +00:00
|
|
|
const PAKRouter<PAKBridge>& pakRouter,
|
|
|
|
const PAK::Entry& entry,
|
|
|
|
const Material::ISection* prevSection,
|
|
|
|
unsigned idx,
|
|
|
|
unsigned& texMapIdx,
|
|
|
|
unsigned& texMtxIdx,
|
|
|
|
unsigned& kColorIdx) const;
|
2015-08-10 01:53:24 +00:00
|
|
|
};
|
|
|
|
struct SectionCLR : ISection
|
|
|
|
{
|
2015-11-21 01:16:07 +00:00
|
|
|
SectionCLR() : ISection(ISection::Type::CLR) {}
|
2015-08-10 01:53:24 +00:00
|
|
|
DECL_DNA
|
2015-11-21 01:16:07 +00:00
|
|
|
enum class Subtype : atUint32
|
2015-08-10 01:53:24 +00:00
|
|
|
{
|
|
|
|
CLR = SBIG('CLR '),
|
|
|
|
DIFB = SBIG('DIFB')
|
|
|
|
};
|
2015-08-23 06:42:29 +00:00
|
|
|
DNAFourCC subtype;
|
2015-08-10 01:53:24 +00:00
|
|
|
GX::Color color;
|
2015-09-19 01:38:40 +00:00
|
|
|
|
2017-12-29 08:08:12 +00:00
|
|
|
void constructNode(hecl::blender::PyOutStream& out,
|
2015-09-19 01:38:40 +00:00
|
|
|
const PAKRouter<PAKBridge>& pakRouter,
|
|
|
|
const PAK::Entry& entry,
|
|
|
|
const Material::ISection* prevSection,
|
|
|
|
unsigned idx,
|
|
|
|
unsigned& texMapIdx,
|
|
|
|
unsigned& texMtxIdx,
|
|
|
|
unsigned& kColorIdx) const;
|
2015-08-10 01:53:24 +00:00
|
|
|
};
|
|
|
|
struct SectionINT : ISection
|
|
|
|
{
|
2015-11-21 01:16:07 +00:00
|
|
|
SectionINT() : ISection(ISection::Type::INT) {}
|
2015-08-10 01:53:24 +00:00
|
|
|
DECL_DNA
|
2015-11-21 01:16:07 +00:00
|
|
|
enum class Subtype : atUint32
|
2015-08-10 01:53:24 +00:00
|
|
|
{
|
|
|
|
OPAC = SBIG('OPAC'),
|
|
|
|
BLOD = SBIG('BLOD'),
|
|
|
|
BLOI = SBIG('BLOI'),
|
|
|
|
BNIF = SBIG('BNIF'),
|
|
|
|
XRBR = SBIG('XRBR')
|
|
|
|
};
|
2015-08-23 06:42:29 +00:00
|
|
|
DNAFourCC subtype;
|
2015-08-10 01:53:24 +00:00
|
|
|
Value<atUint32> value;
|
2015-09-19 01:38:40 +00:00
|
|
|
|
2017-12-29 08:08:12 +00:00
|
|
|
void constructNode(hecl::blender::PyOutStream& out,
|
2015-09-19 01:38:40 +00:00
|
|
|
const PAKRouter<PAKBridge>& pakRouter,
|
|
|
|
const PAK::Entry& entry,
|
|
|
|
const Material::ISection* prevSection,
|
|
|
|
unsigned idx,
|
|
|
|
unsigned& texMapIdx,
|
|
|
|
unsigned& texMtxIdx,
|
|
|
|
unsigned& kColorIdx) const;
|
2015-08-10 01:53:24 +00:00
|
|
|
};
|
|
|
|
struct SectionFactory : BigDNA
|
|
|
|
{
|
|
|
|
Delete expl;
|
|
|
|
std::unique_ptr<ISection> section;
|
2016-03-04 23:04:53 +00:00
|
|
|
void read(athena::io::IStreamReader& reader)
|
2015-08-10 01:53:24 +00:00
|
|
|
{
|
2015-08-23 06:42:29 +00:00
|
|
|
DNAFourCC type;
|
2015-08-10 01:53:24 +00:00
|
|
|
type.read(reader);
|
2015-11-21 01:16:07 +00:00
|
|
|
switch (ISection::Type(type.toUint32()))
|
2015-08-10 01:53:24 +00:00
|
|
|
{
|
2015-11-21 01:16:07 +00:00
|
|
|
case ISection::Type::PASS:
|
2015-08-10 01:53:24 +00:00
|
|
|
section.reset(new struct SectionPASS);
|
|
|
|
section->read(reader);
|
|
|
|
break;
|
2015-11-21 01:16:07 +00:00
|
|
|
case ISection::Type::CLR:
|
2015-08-10 01:53:24 +00:00
|
|
|
section.reset(new struct SectionCLR);
|
|
|
|
section->read(reader);
|
|
|
|
break;
|
2015-11-21 01:16:07 +00:00
|
|
|
case ISection::Type::INT:
|
2015-08-10 01:53:24 +00:00
|
|
|
section.reset(new struct SectionINT);
|
|
|
|
section->read(reader);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
section.reset(nullptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
void write(athena::io::IStreamWriter& writer) const
|
2015-08-10 01:53:24 +00:00
|
|
|
{
|
|
|
|
if (!section)
|
|
|
|
return;
|
|
|
|
writer.writeUBytes((atUint8*)§ion->m_type, 4);
|
|
|
|
section->write(writer);
|
|
|
|
}
|
2015-10-18 04:08:45 +00:00
|
|
|
size_t binarySize(size_t __isz) const
|
|
|
|
{
|
|
|
|
return section->binarySize(__isz + 4);
|
|
|
|
}
|
2015-08-10 01:53:24 +00:00
|
|
|
};
|
|
|
|
std::vector<SectionFactory> sections;
|
2016-03-04 23:04:53 +00:00
|
|
|
void read(athena::io::IStreamReader& reader)
|
2015-08-10 01:53:24 +00:00
|
|
|
{
|
|
|
|
header.read(reader);
|
|
|
|
sections.clear();
|
|
|
|
do {
|
|
|
|
sections.emplace_back();
|
|
|
|
sections.back().read(reader);
|
|
|
|
} while (sections.back().section);
|
|
|
|
sections.pop_back();
|
|
|
|
}
|
2016-03-04 23:04:53 +00:00
|
|
|
void write(athena::io::IStreamWriter& writer) const
|
2015-08-10 01:53:24 +00:00
|
|
|
{
|
|
|
|
header.write(writer);
|
|
|
|
for (const SectionFactory& section : sections)
|
|
|
|
section.write(writer);
|
|
|
|
writer.writeUBytes((atUint8*)"END ", 4);
|
|
|
|
}
|
2015-10-18 04:08:45 +00:00
|
|
|
size_t binarySize(size_t __isz) const
|
|
|
|
{
|
|
|
|
__isz = header.binarySize(__isz);
|
|
|
|
for (const SectionFactory& section : sections)
|
|
|
|
__isz = section.binarySize(__isz);
|
|
|
|
return __isz + 4;
|
|
|
|
}
|
2015-08-10 01:53:24 +00:00
|
|
|
};
|
|
|
|
Vector<Material, DNA_COUNT(materialCount)> materials;
|
|
|
|
|
2017-12-29 08:08:12 +00:00
|
|
|
static void RegisterMaterialProps(hecl::blender::PyOutStream& out);
|
|
|
|
static void ConstructMaterial(hecl::blender::PyOutStream& out,
|
2015-09-19 01:38:40 +00:00
|
|
|
const PAKRouter<PAKBridge>& pakRouter,
|
|
|
|
const PAK::Entry& entry,
|
2015-08-10 01:53:24 +00:00
|
|
|
const MaterialSet::Material& material,
|
|
|
|
unsigned groupIdx, unsigned matIdx);
|
|
|
|
|
2017-12-29 08:08:12 +00:00
|
|
|
void readToBlender(hecl::blender::PyOutStream& os,
|
2015-09-07 04:05:44 +00:00
|
|
|
const PAKRouter<PAKBridge>& pakRouter,
|
|
|
|
const PAKRouter<PAKBridge>::EntryType& entry,
|
2015-09-19 01:38:40 +00:00
|
|
|
unsigned setIdx)
|
2015-08-10 01:53:24 +00:00
|
|
|
{
|
2015-09-19 01:38:40 +00:00
|
|
|
DNACMDL::ReadMaterialSetToBlender_3(os, *this, pakRouter, entry, setIdx);
|
2015-08-10 01:53:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // _DNAMP3_CMDL_MATERIALS_HPP_
|