#ifndef _DNAMP1_ANCS_HPP_ #define _DNAMP1_ANCS_HPP_ #include #include "../DNACommon/DNACommon.hpp" #include "../DNACommon/ANCS.hpp" #include "CMDLMaterials.hpp" #include "BlenderConnection.hpp" #include "CINF.hpp" #include "CSKR.hpp" #include "ANIM.hpp" #include "athena/FileReader.hpp" namespace DataSpec { namespace DNAMP1 { struct ANCS : BigYAML { using CINFType = CINF; using CSKRType = CSKR; using ANIMType = ANIM; ANCS(const UniqueID32& ancsId) : animationSet(ancsId) {} DECL_YAML Value version; struct CharacterSet : BigYAML { DECL_YAML Value version; Value characterCount; struct CharacterInfo : BigYAML { DECL_YAML Delete expl; atUint32 idx; std::string name; UniqueID32 cmdl; AuxiliaryID32 cskr = _S("skin"); AuxiliaryID32 cinf = {_S("layout"), _S(".blend")}; struct Animation : BigYAML { DECL_YAML Value animIdx; String<-1> strA; String<-1> strB; }; std::vector animations; struct PASDatabase : BigYAML { DECL_YAML Value magic; Value animStateCount; Value defaultState; struct AnimState : BigYAML { DECL_YAML Delete expl; atUint32 id; struct ParmInfo : BigYAML { DECL_YAML Delete expl; enum class DataType { Int32 = 0, UInt32 = 1, Float = 2, Bool = 3, Enum = 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 parmInfos; struct AnimInfo { atUint32 id; std::vector parmVals; }; std::vector animInfos; }; Vector animStates; } pasDatabase; struct ParticleResData { std::vector part; std::vector swhc; std::vector unk; std::vector elsc; } partResData; atUint32 unk1 = 0; struct ActionAABB : BigYAML { DECL_YAML String<-1> name; Value aabb[2]; }; std::vector animAABBs; struct Effect : BigYAML { DECL_YAML String<-1> name; Value compCount; struct EffectComponent : BigYAML { DECL_YAML String<-1> name; DNAFourCC type; UniqueID32 id; String<-1> name2; Value unk1; Value unk2; Value unk3; }; Vector comps; }; std::vector effects; UniqueID32 cmdlOverlay; AuxiliaryID32 cskrOverlay = _S("skin"); std::vector animIdxs; }; Vector characters; } characterSet; struct AnimationSet : BigYAML { DECL_YAML Delete expl; const UniqueID32& m_ancsId; AnimationSet(const UniqueID32& ancsId) : m_ancsId(ancsId), defaultTransition(ancsId) {} struct IMetaAnim : BigYAML { Delete expl; virtual ~IMetaAnim() {} enum class Type { Primitive = 0, Blend = 1, PhaseBlend = 2, Random = 3, Sequence = 4 } m_type; const char* m_typeStr; const UniqueID32& m_ancsId; IMetaAnim(Type type, const char* typeStr, const UniqueID32& ancsId) : m_type(type), m_typeStr(typeStr), m_ancsId(ancsId) {} virtual void gatherPrimitives(std::map>& out)=0; }; struct MetaAnimFactory : BigYAML { DECL_YAML Delete expl; const UniqueID32& m_ancsId; std::unique_ptr m_anim; MetaAnimFactory(const UniqueID32& ancsId) : m_ancsId(ancsId) {} }; struct MetaAnimPrimitive : IMetaAnim { MetaAnimPrimitive(const UniqueID32& ancsId) : IMetaAnim(Type::Primitive, "Primitive", ancsId) {} Delete _d; UniqueID32 animId; Value animIdx; String<-1> animName; Value unk1; Value unk2; void read(athena::io::IStreamReader& __dna_reader) { /* animId */ animId.read(__dna_reader); /* animIdx */ animIdx = __dna_reader.readUint32Big(); /* animName */ animName = __dna_reader.readString(-1); /* unk1 */ unk1 = __dna_reader.readFloatBig(); /* unk2 */ unk2 = __dna_reader.readUint32Big(); } void write(athena::io::IStreamWriter& __dna_writer) const { /* animId */ animId.write(__dna_writer); /* animIdx */ __dna_writer.writeUint32Big(animIdx); /* animName */ __dna_writer.writeString(animName, -1); /* unk1 */ __dna_writer.writeFloatBig(unk1); /* unk2 */ __dna_writer.writeUint32Big(unk2); } void read(athena::io::YAMLDocReader& __dna_docin) { /* animId */ __dna_docin.enumerate("animId", animId); /* animIdx */ animIdx = __dna_docin.readUint32("animIdx"); /* animName */ animName = __dna_docin.readString("animName"); /* unk1 */ unk1 = __dna_docin.readFloat("unk1"); /* unk2 */ unk2 = __dna_docin.readUint32("unk2"); } void write(athena::io::YAMLDocWriter& __dna_docout) const { /* animId */ DNAANCS::WriteOutAnimId(__dna_docout, m_ancsId, animName); /* animIdx */ __dna_docout.writeUint32("animIdx", animIdx); /* animName */ __dna_docout.writeString("animName", animName); /* unk1 */ __dna_docout.writeFloat("unk1", unk1); /* unk2 */ __dna_docout.writeUint32("unk2", unk2); } static const char* DNAType() { return "DataSpec::DNAMP1::ANCS::AnimationSet::MetaAnimPrimitive"; } size_t binarySize(size_t __isz) const { __isz = animId.binarySize(__isz); __isz += animName.size() + 1; return __isz + 12; } void gatherPrimitives(std::map>& out) { out[animIdx] = {animName, animId, UniqueID32(), false}; } }; struct MetaAnimBlend : IMetaAnim { MetaAnimBlend(const UniqueID32& ancsId) : IMetaAnim(Type::Blend, "Blend", ancsId), animA(ancsId), animB(ancsId) {} DECL_YAML MetaAnimFactory animA; MetaAnimFactory animB; Value unkFloat; Value unk; void gatherPrimitives(std::map>& out) { animA.m_anim->gatherPrimitives(out); animB.m_anim->gatherPrimitives(out); } }; struct MetaAnimPhaseBlend : IMetaAnim { MetaAnimPhaseBlend(const UniqueID32& ancsId) : IMetaAnim(Type::PhaseBlend, "PhaseBlend", ancsId), animA(ancsId), animB(ancsId) {} DECL_YAML MetaAnimFactory animA; MetaAnimFactory animB; Value unkFloat; Value unk; void gatherPrimitives(std::map>& out) { animA.m_anim->gatherPrimitives(out); animB.m_anim->gatherPrimitives(out); } }; struct MetaAnimRandom : IMetaAnim { MetaAnimRandom(const UniqueID32& ancsId) : IMetaAnim(Type::Random, "Random", ancsId) {} Delete _d; Value animCount; struct Child : BigYAML { DECL_YAML MetaAnimFactory anim; Value probability; Child(const UniqueID32& ancsId) : anim(ancsId) {} }; Vector children; void read(athena::io::IStreamReader& __dna_reader) { /* animCount */ animCount = __dna_reader.readUint32Big(); /* children */ children.clear(); children.reserve(animCount); for (size_t i=0 ; i>& out) { for (const auto& child : children) child.anim.m_anim->gatherPrimitives(out); } }; struct MetaAnimSequence : IMetaAnim { MetaAnimSequence(const UniqueID32& ancsId) : IMetaAnim(Type::Sequence, "Sequence", ancsId) {} Delete _d; Value animCount; Vector children; void read(athena::io::IStreamReader& __dna_reader) { /* animCount */ animCount = __dna_reader.readUint32Big(); /* children */ children.clear(); children.reserve(animCount); for (size_t i=0 ; i>& out) { for (const auto& child : children) child.m_anim->gatherPrimitives(out); } }; struct Animation : BigYAML { DECL_YAML String<-1> name; MetaAnimFactory metaAnim; Animation(const UniqueID32& ancsId) : metaAnim(ancsId) {} }; std::vector animations; struct IMetaTrans : BigYAML { Delete expl; virtual ~IMetaTrans() {} enum class Type { MetaAnim = 0, Trans = 1, PhaseTrans = 2, NoTrans = 3, } m_type; const char* m_typeStr; const UniqueID32& m_ancsId; IMetaTrans(Type type, const char* typeStr, const UniqueID32& ancsId) : m_type(type), m_typeStr(typeStr), m_ancsId(ancsId) {} }; struct MetaTransFactory : BigYAML { DECL_YAML Delete expl; const UniqueID32& m_ancsId; std::unique_ptr m_trans; MetaTransFactory(const UniqueID32& ancsId) : m_ancsId(ancsId) {} }; struct MetaTransMetaAnim : IMetaTrans { MetaTransMetaAnim(const UniqueID32& ancsId) : IMetaTrans(Type::MetaAnim, "MetaAnim", ancsId), anim(ancsId) {} DECL_YAML MetaAnimFactory anim; }; struct MetaTransTrans : IMetaTrans { MetaTransTrans(const UniqueID32& ancsId) : IMetaTrans(Type::Trans, "Trans", ancsId) {} DECL_YAML Value time; Value unk1; Value unk2; Value unk3; Value unk4; }; struct MetaTransPhaseTrans : IMetaTrans { MetaTransPhaseTrans(const UniqueID32& ancsId) : IMetaTrans(Type::PhaseTrans, "PhaseTrans", ancsId) {} DECL_YAML Value time; Value unk1; Value unk2; Value unk3; Value unk4; }; struct Transition : BigYAML { DECL_YAML Value unk; Value animIdxA; Value animIdxB; MetaTransFactory metaTrans; Transition(const UniqueID32& ancsId) : metaTrans(ancsId) {} }; std::vector transitions; MetaTransFactory defaultTransition; struct AdditiveAnimationInfo : BigYAML { DECL_YAML Value animIdx; Value unk1; Value unk2; }; std::vector additiveAnims; float floatA = 0.0; float floatB = 0.0; struct HalfTransition : BigYAML { DECL_YAML Value animIdx; MetaTransFactory metaTrans; HalfTransition(const UniqueID32& ancsId) : metaTrans(ancsId) {} }; std::vector halfTransitions; struct AnimationResources : BigYAML { DECL_YAML UniqueID32 animId; UniqueID32 evntId; }; std::vector animResources; } animationSet; void getCharacterResInfo(std::vector>& out) const { out.clear(); out.reserve(characterSet.characters.size()); for (const CharacterSet::CharacterInfo& ci : characterSet.characters) { out.emplace_back(); DNAANCS::CharacterResInfo& chOut = out.back(); chOut.name = ci.name; chOut.cmdl = ci.cmdl; chOut.cskr = ci.cskr.getBaseId(); chOut.cinf = ci.cinf.getBaseId(); if (ci.cmdlOverlay) chOut.overlays.emplace_back(FOURCC('OVER'), std::make_pair(ci.cmdlOverlay, ci.cskrOverlay.getBaseId())); } } void getAnimationResInfo(std::map>& out) const { out.clear(); for (const AnimationSet::Animation& ai : animationSet.animations) ai.metaAnim.m_anim->gatherPrimitives(out); for (auto& anim : out) { for (const AnimationSet::AnimationResources& res : animationSet.animResources) { if (res.animId == anim.second.animId) { anim.second.evntId = res.evntId; break; } } } } void fixupPaths(const UniqueID32& ancsId) { for (CharacterSet::CharacterInfo& character : characterSet.characters) { character.cskr = character.cmdl; character.cinf = ancsId; character.cskrOverlay = character.cmdlOverlay; } } static bool Extract(const SpecBase& dataSpec, PAKEntryReadStream& rs, const hecl::ProjectPath& outPath, PAKRouter& pakRouter, const PAK::Entry& entry, bool force, hecl::BlenderToken& btok, std::function fileChanged) { hecl::ProjectPath yamlPath = outPath.getWithExtension(_S(".yaml")); hecl::ProjectPath::Type yamlType = yamlPath.getPathType(); hecl::ProjectPath blendPath = outPath.getWithExtension(_S(".blend")); hecl::ProjectPath::Type blendType = blendPath.getPathType(); if (force || yamlType == hecl::ProjectPath::Type::None || blendType == hecl::ProjectPath::Type::None) { ANCS ancs(entry.id); ancs.read(rs); ancs.fixupPaths(entry.id); if (force || yamlType == hecl::ProjectPath::Type::None) { FILE* fp = hecl::Fopen(yamlPath.getAbsolutePath().c_str(), _S("wb")); ancs.toYAMLFile(fp); fclose(fp); } if (force || blendType == hecl::ProjectPath::Type::None) { hecl::BlenderConnection& conn = btok.getBlenderConnection(); DNAANCS::ReadANCSToBlender, ANCS, MaterialSet, DNACMDL::SurfaceHeader_1, 2> (conn, ancs, blendPath, pakRouter, entry, dataSpec, fileChanged, force); } } return true; } static bool Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath, const DNAANCS::Actor& actor) { /* Search for yaml */ hecl::ProjectPath yamlPath = inPath.getWithExtension(_S(".yaml"), true); if (yamlPath.getPathType() != hecl::ProjectPath::Type::File) Log.report(logvisor::Fatal, _S("'%s' not found as file"), yamlPath.getRelativePath().c_str()); athena::io::FileReader yamlReader(yamlPath.getAbsolutePath()); if (!BigYAML::ValidateFromYAMLFile(yamlReader)) Log.report(logvisor::Fatal, _S("'%s' is not urde::DNAMP1::ANCS type"), yamlPath.getRelativePath().c_str()); ANCS ancs(UniqueID32::kInvalidId); ancs.read(yamlReader); return true; } }; } } #endif // _DNAMP1_ANCS_HPP_