metaforce/DataSpec/DNAMP1/ANCS.hpp

393 lines
12 KiB
C++
Raw Normal View History

2015-08-08 04:49:42 +00:00
#ifndef _DNAMP1_ANCS_HPP_
#define _DNAMP1_ANCS_HPP_
2015-08-11 23:32:02 +00:00
#include <unordered_set>
2015-08-08 04:49:42 +00:00
#include "../DNACommon/DNACommon.hpp"
2015-08-11 23:32:02 +00:00
#include "../DNACommon/ANCS.hpp"
#include "CMDLMaterials.hpp"
#include "BlenderConnection.hpp"
2015-08-08 04:49:42 +00:00
namespace Retro
{
namespace DNAMP1
{
struct ANCS : BigYAML
{
DECL_YAML
Value<atUint16> version;
struct CharacterSet : BigYAML
{
DECL_YAML
Value<atUint16> version;
Value<atUint32> characterCount;
struct CharacterInfo : BigYAML
{
2015-08-08 23:24:17 +00:00
DECL_YAML
2015-08-08 04:49:42 +00:00
Delete expl;
atUint32 idx;
std::string name;
UniqueID32 cmdl;
UniqueID32 cskr;
UniqueID32 cinf;
struct Animation : BigYAML
{
DECL_YAML
Value<atUint32> animIdx;
String<-1> strA;
String<-1> strB;
};
std::vector<Animation> animations;
struct PASDatabase : BigYAML
{
DECL_YAML
Value<atUint32> magic;
Value<atUint32> animStateCount;
Value<atUint32> defaultState;
struct AnimState : BigYAML
{
2015-08-08 23:24:17 +00:00
DECL_YAML
2015-08-08 04:49:42 +00:00
Delete expl;
atUint32 id;
struct ParmInfo : BigYAML
{
2015-08-08 23:24:17 +00:00
DECL_YAML
2015-08-08 04:49:42 +00:00
Delete expl;
enum DataType
{
DTInt32 = 0,
DTUInt32 = 1,
DTFloat = 2,
DTBool = 3,
DTEnum = 4
};
union Parm
{
atInt32 int32;
atUint32 uint32;
float float32;
bool bool1;
Parm() : int32(0) {}
Parm(atInt32 val) : int32(val) {}
Parm(atUint32 val) : uint32(val) {}
Parm(float val) : float32(val) {}
Parm(bool val) : bool1(val) {}
};
atUint32 parmType;
atUint32 unk1;
float unk2;
Parm parmVals[2];
};
std::vector<ParmInfo> parmInfos;
struct AnimInfo
{
atUint32 id;
std::vector<ParmInfo::Parm> parmVals;
};
std::vector<AnimInfo> animInfos;
};
2015-08-08 23:24:17 +00:00
Vector<AnimState, DNA_COUNT(animStateCount)> animStates;
2015-08-08 04:49:42 +00:00
} pasDatabase;
struct ParticleResData
{
std::vector<UniqueID32> part;
std::vector<UniqueID32> swhc;
std::vector<UniqueID32> unk;
std::vector<UniqueID32> elsc;
} partResData;
2015-08-08 23:24:17 +00:00
atUint32 unk1 = 0;
atUint32 unk2 = 0;
atUint32 unk3 = 0;
2015-08-08 04:49:42 +00:00
struct ActionAABB : BigYAML
{
DECL_YAML
String<-1> name;
Value<atVec3f> aabb[2];
};
std::vector<ActionAABB> animAABBs;
struct Effect : BigYAML
{
DECL_YAML
String<-1> name;
Value<atUint32> compCount;
struct EffectComponent : BigYAML
{
DECL_YAML
String<-1> name;
FourCC type;
UniqueID32 id;
String<-1> name2;
Value<float> unk1;
Value<atUint32> unk2;
Value<atUint32> unk3;
};
Vector<EffectComponent, DNA_COUNT(compCount)> comps;
};
std::vector<Effect> effects;
UniqueID32 cmdlOverride;
UniqueID32 cskrOverride;
std::vector<atUint32> animIdxs;
};
2015-08-08 23:24:17 +00:00
Vector<CharacterInfo, DNA_COUNT(characterCount)> characters;
2015-08-08 04:49:42 +00:00
} characterSet;
struct AnimationSet : BigYAML
{
2015-08-08 23:24:17 +00:00
DECL_YAML
2015-08-08 04:49:42 +00:00
Delete expl;
struct IMetaAnim : BigYAML
{
Delete expl;
enum Type
{
MAPrimitive = 0,
MABlend = 1,
MAPhaseBlend = 2,
MARandom = 3,
MASequence = 4
} m_type;
const char* m_typeStr;
IMetaAnim(Type type, const char* typeStr)
: m_type(type), m_typeStr(typeStr) {}
2015-08-11 23:32:02 +00:00
virtual void gatherPrimitives(std::unordered_set<UniqueID32>& out)=0;
2015-08-08 04:49:42 +00:00
};
struct MetaAnimFactory : BigYAML
{
2015-08-08 23:24:17 +00:00
DECL_YAML
2015-08-08 04:49:42 +00:00
Delete expl;
std::unique_ptr<IMetaAnim> m_anim;
};
struct MetaAnimPrimitive : IMetaAnim
{
MetaAnimPrimitive() : IMetaAnim(MAPrimitive, "Primitive") {}
DECL_YAML
UniqueID32 animId;
Value<atUint32> animIdx;
String<-1> animName;
Value<float> unk1;
Value<atUint32> unk2;
2015-08-11 23:32:02 +00:00
void gatherPrimitives(std::unordered_set<UniqueID32>& out)
{
out.insert(animId);
}
2015-08-08 04:49:42 +00:00
};
struct MetaAnimBlend : IMetaAnim
{
MetaAnimBlend() : IMetaAnim(MABlend, "Blend") {}
DECL_YAML
MetaAnimFactory animA;
MetaAnimFactory animB;
Value<float> unkFloat;
Value<atUint8> unk;
2015-08-11 23:32:02 +00:00
void gatherPrimitives(std::unordered_set<UniqueID32>& out)
{
animA.m_anim->gatherPrimitives(out);
animB.m_anim->gatherPrimitives(out);
}
2015-08-08 04:49:42 +00:00
};
struct MetaAnimPhaseBlend : IMetaAnim
{
MetaAnimPhaseBlend() : IMetaAnim(MAPhaseBlend, "PhaseBlend") {}
DECL_YAML
MetaAnimFactory animA;
MetaAnimFactory animB;
Value<float> unkFloat;
Value<atUint8> unk;
2015-08-11 23:32:02 +00:00
void gatherPrimitives(std::unordered_set<UniqueID32>& out)
{
animA.m_anim->gatherPrimitives(out);
animB.m_anim->gatherPrimitives(out);
}
2015-08-08 04:49:42 +00:00
};
struct MetaAnimRandom : IMetaAnim
{
MetaAnimRandom() : IMetaAnim(MARandom, "Random") {}
DECL_YAML
Value<atUint32> animCount;
struct Child : BigYAML
{
DECL_YAML
MetaAnimFactory anim;
Value<atUint32> probability;
};
Vector<Child, DNA_COUNT(animCount)> children;
2015-08-11 23:32:02 +00:00
void gatherPrimitives(std::unordered_set<UniqueID32>& out)
{
for (const auto& child : children)
child.anim.m_anim->gatherPrimitives(out);
}
2015-08-08 04:49:42 +00:00
};
struct MetaAnimSequence : IMetaAnim
{
MetaAnimSequence() : IMetaAnim(MASequence, "Sequence") {}
DECL_YAML
Value<atUint32> animCount;
Vector<MetaAnimFactory, DNA_COUNT(animCount)> children;
2015-08-11 23:32:02 +00:00
void gatherPrimitives(std::unordered_set<UniqueID32>& out)
{
for (const auto& child : children)
child.m_anim->gatherPrimitives(out);
}
2015-08-08 04:49:42 +00:00
};
struct Animation : BigYAML
{
DECL_YAML
String<-1> name;
MetaAnimFactory metaAnim;
};
std::vector<Animation> animations;
struct IMetaTrans : BigYAML
{
Delete expl;
enum Type
{
MTMetaAnim = 0,
MTTrans = 1,
MTPhaseTrans = 2,
MTNoTrans = 3,
} m_type;
const char* m_typeStr;
IMetaTrans(Type type, const char* typeStr)
: m_type(type), m_typeStr(typeStr) {}
};
struct MetaTransFactory : BigYAML
{
2015-08-08 23:24:17 +00:00
DECL_YAML
2015-08-08 04:49:42 +00:00
Delete expl;
std::unique_ptr<IMetaTrans> m_trans;
};
struct MetaTransMetaAnim : IMetaTrans
{
MetaTransMetaAnim() : IMetaTrans(MTMetaAnim, "MetaAnim") {}
DECL_YAML
MetaAnimFactory anim;
};
struct MetaTransTrans : IMetaTrans
{
MetaTransTrans() : IMetaTrans(MTTrans, "Trans") {}
DECL_YAML
Value<float> time;
Value<atUint32> unk1;
Value<atUint8> unk2;
Value<atUint8> unk3;
Value<atUint32> unk4;
};
struct MetaTransPhaseTrans : IMetaTrans
{
MetaTransPhaseTrans() : IMetaTrans(MTPhaseTrans, "PhaseTrans") {}
DECL_YAML
Value<float> time;
Value<atUint32> unk1;
Value<atUint8> unk2;
Value<atUint8> unk3;
Value<atUint32> unk4;
};
struct Transition : BigYAML
{
DECL_YAML
Value<atUint32> unk;
Value<atUint32> animIdxA;
Value<atUint32> animIdxB;
MetaTransFactory metaTrans;
};
std::vector<Transition> transitions;
2015-08-08 23:24:17 +00:00
MetaTransFactory defaultTransition;
2015-08-08 04:49:42 +00:00
struct AdditiveAnimationInfo : BigYAML
{
DECL_YAML
Value<atUint32> animIdx;
Value<float> unk1;
Value<float> unk2;
};
std::vector<AdditiveAnimationInfo> additiveAnims;
float floatA = 0.0;
float floatB = 0.0;
struct HalfTransition : BigYAML
{
DECL_YAML
Value<atUint32> animIdx;
MetaTransFactory metaTrans;
};
std::vector<HalfTransition> halfTransitions;
struct AnimationResources : BigYAML
{
DECL_YAML
UniqueID32 animId;
UniqueID32 evntId;
};
2015-08-08 04:58:50 +00:00
std::vector<AnimationResources> animResources;
2015-08-08 04:49:42 +00:00
} animationSet;
2015-08-08 23:24:17 +00:00
2015-08-11 23:32:02 +00:00
void getCharacterResInfo(std::vector<DNAANCS::CharacterResInfo<UniqueID32>>& out) const
{
out.clear();
out.reserve(characterSet.characters.size());
for (const CharacterSet::CharacterInfo& ci : characterSet.characters)
{
out.emplace_back();
DNAANCS::CharacterResInfo<UniqueID32>& chOut = out.back();
chOut.name = ci.name;
chOut.cmdl = ci.cmdl;
chOut.cskr = ci.cskr;
chOut.cinf = ci.cinf;
}
}
void getAnimationResInfo(std::unordered_set<UniqueID32>& out) const
{
out.clear();
for (const AnimationSet::Animation& ai : animationSet.animations)
ai.metaAnim.m_anim->gatherPrimitives(out);
}
static bool Extract(const SpecBase& dataSpec,
PAKEntryReadStream& rs,
const HECL::ProjectPath& outPath,
PAKRouter<PAKBridge>& pakRouter,
const PAK::Entry& entry,
bool force)
2015-08-08 23:24:17 +00:00
{
ANCS ancs;
ancs.read(rs);
2015-08-11 23:32:02 +00:00
FILE* fp = HECL::Fopen((outPath.getAbsolutePath() + ".yaml").c_str(), _S("wb"));
2015-08-08 23:24:17 +00:00
ancs.toYAMLFile(fp);
fclose(fp);
2015-08-11 23:32:02 +00:00
HECL::BlenderConnection& conn = HECL::BlenderConnection::SharedConnection();
DNAANCS::ReadANCSToBlender<PAKRouter<PAKBridge>, ANCS, MaterialSet, 2>
(conn, ancs, outPath, pakRouter, entry, dataSpec.getMasterShaderPath(), force);
return conn.saveBlend();
2015-08-08 23:24:17 +00:00
}
2015-08-08 04:49:42 +00:00
};
}
}
#endif // _DNAMP1_ANCS_HPP_