From d5e471bac3a81795ef41452d5bfe05e9e622a29c Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 3 Apr 2018 22:31:29 -1000 Subject: [PATCH] Several GameCube cooking fixes --- DataSpec/DNACommon/BabeDead.cpp | 16 +++-- DataSpec/DNACommon/CMDL.cpp | 19 ++---- DataSpec/DNACommon/TXTR.cpp | 6 +- DataSpec/DNAMP1/ANCS.cpp | 24 ++++++- DataSpec/DNAMP1/CMDLMaterials.cpp | 104 +++++++++++++++++------------- DataSpec/DNAMP1/CMDLMaterials.hpp | 6 +- Runtime/Character/CAnimData.cpp | 8 +-- hecl | 2 +- 8 files changed, 108 insertions(+), 77 deletions(-) diff --git a/DataSpec/DNACommon/BabeDead.cpp b/DataSpec/DNACommon/BabeDead.cpp index ed8879547..8860340ab 100644 --- a/DataSpec/DNACommon/BabeDead.cpp +++ b/DataSpec/DNACommon/BabeDead.cpp @@ -22,29 +22,33 @@ void ReadBabeDeadLightToBlender(hecl::blender::PyOutStream& os, return; case BabeDeadLight::LightType::Directional: os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SUN')\n" + "lamp.color = (%f,%f,%f)\n" "lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n" "lamp_obj.rotation_mode = 'QUATERNION'\n" "lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n" "lamp.shadow_method = '%s'\n" - "\n", s, l, + "\n", s, l, light.color.vec[0], light.color.vec[1], light.color.vec[2], light.direction.vec[0], light.direction.vec[1], light.direction.vec[2], light.castShadows ? "RAY_SHADOW" : "NOSHADOW"); return; case BabeDeadLight::LightType::Custom: os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'POINT')\n" + "lamp.color = (%f,%f,%f)\n" "lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n" "lamp.shadow_method = '%s'\n" - "\n", s, l, light.castShadows ? "RAY_SHADOW" : "NOSHADOW"); + "\n", s, l, light.color.vec[0], light.color.vec[1], light.color.vec[2], + light.castShadows ? "RAY_SHADOW" : "NOSHADOW"); break; case BabeDeadLight::LightType::Spot: case BabeDeadLight::LightType::Spot2: os.format("lamp = bpy.data.lamps.new('LAMP_%01u_%03u', 'SPOT')\n" + "lamp.color = (%f,%f,%f)\n" "lamp.spot_size = %.6g\n" "lamp_obj = bpy.data.objects.new(lamp.name, lamp)\n" "lamp_obj.rotation_mode = 'QUATERNION'\n" "lamp_obj.rotation_quaternion = Vector((0,0,-1)).rotation_difference(Vector((%f,%f,%f)))\n" "lamp.shadow_method = '%s'\n" - "\n", s, l, + "\n", s, l, light.color.vec[0], light.color.vec[1], light.color.vec[2], zeus::degToRad(light.spotCutoff), light.direction.vec[0], light.direction.vec[1], light.direction.vec[2], light.castShadows ? "RAY_SHADOW" : "NOSHADOW"); @@ -127,18 +131,18 @@ void WriteBabeDeadLightFromBlender(BabeDeadLight& lightOut, const hecl::blender: lightIn.linear > lightIn.quadratic) { lightOut.falloff = BabeDeadLight::Falloff::Linear; - lightOut.q = 1.f / (lightIn.linear / 250.f); + lightOut.q = 250.f / lightIn.linear; } else if (lightIn.quadratic > lightIn.constant && lightIn.quadratic > lightIn.linear) { lightOut.falloff = BabeDeadLight::Falloff::Quadratic; - lightOut.q = 1.f / (lightIn.quadratic / 25000.f); + lightOut.q = 25000.f / lightIn.quadratic; } else { lightOut.falloff = BabeDeadLight::Falloff::Constant; - lightOut.q = 1.f / (lightIn.constant / 2.f); + lightOut.q = 2.f / lightIn.constant; } lightOut.color = lightIn.color; diff --git a/DataSpec/DNACommon/CMDL.cpp b/DataSpec/DNACommon/CMDL.cpp index c28e8acd2..f85135d54 100644 --- a/DataSpec/DNACommon/CMDL.cpp +++ b/DataSpec/DNACommon/CMDL.cpp @@ -1243,8 +1243,6 @@ bool WriteCMDL(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath hecl::Frontend::Frontend FE; for (const std::vector& mset : mesh.materialSets) { - std::unordered_map uniqueMatMap; - matSets.emplace_back(); MaterialSet& targetMSet = matSets.back(); std::vector texPaths; @@ -1262,7 +1260,7 @@ bool WriteCMDL(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath targetMSet.materials.emplace_back(matGX, mat.iprops, mat.texs, texPaths, mesh.colorLayerCount, mesh.uvLayerCount, - false, false, uniqueMatMap); + false, false); targetMSet.materials.back().binarySize(endOff); targetMSet.head.addMaterialEndOff(endOff); @@ -1353,7 +1351,7 @@ bool WriteCMDL(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath size_t vertSz = matSets.at(0).materials.at(surf.materialIdx).getVAFlags().vertDLSize(); if (surf.verts.size() > 65536) LogDNACommon.report(logvisor::Fatal, "GX DisplayList overflow"); - size_t secSz = 68 + surf.verts.size() * vertSz; + size_t secSz = 67 + surf.verts.size() * vertSz; secSz32 = ROUND_UP_32(secSz); if (secSz32 == 0) secSz32 = 32; @@ -1445,7 +1443,7 @@ bool WriteCMDL(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath SurfaceHeader header; header.centroid = surf.centroid; header.matIdx = surf.materialIdx; - header.dlSize = ROUND_UP_32(4 + surf.verts.size() * vertSz); + header.dlSize = ROUND_UP_32(3 + surf.verts.size() * vertSz); header.reflectionNormal = surf.reflectionNormal; header.write(writer); @@ -1478,8 +1476,6 @@ bool WriteCMDL(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath WriteDLVal(writer, vaFlags.tex6(), vert.iUv[6]); } - writer.writeUByte(0); - writer.fill(atUint8(0), *padIt); ++padIt; } @@ -1696,7 +1692,6 @@ bool WriteMREASecs(std::vector>& secsOut, const hecl::Proje MaterialSet matSet; { MaterialPool matPool; - std::unordered_map uniqueMatMap; size_t surfCount = 0; for (const Mesh& mesh : meshes) @@ -1748,7 +1743,7 @@ bool WriteMREASecs(std::vector>& secsOut, const hecl::Proje matSet.materials.emplace_back(matGX, mat.iprops, mat.texs, texPaths, mesh.colorLayerCount, mesh.uvLayerCount, - lm, false, uniqueMatMap); + lm, false); matSet.materials.back().binarySize(endOff); matSet.head.addMaterialEndOff(endOff); @@ -1914,7 +1909,7 @@ bool WriteMREASecs(std::vector>& secsOut, const hecl::Proje SurfaceHeader header; header.centroid = meshXf * zeus::CVector3f(surf.centroid); header.matIdx = matIdx; - header.dlSize = ROUND_UP_32(4 + surf.verts.size() * vertSz); + header.dlSize = ROUND_UP_32(3 + surf.verts.size() * vertSz); header.reflectionNormal = (meshXf.basis * zeus::CVector3f(surf.reflectionNormal)).normalized(); header.aabbSz = 24; zeus::CAABox aabb(zeus::CVector3f(surf.aabbMin), zeus::CVector3f(surf.aabbMax)); @@ -1924,7 +1919,7 @@ bool WriteMREASecs(std::vector>& secsOut, const hecl::Proje size_t secSz = 0; header.binarySize(secSz); - secSz += 4 + surf.verts.size() * vertSz; + secSz += 3 + surf.verts.size() * vertSz; secSz = ROUND_UP_32(secSz); secsOut.emplace_back(secSz, 0); athena::io::MemoryWriter w(secsOut.back().data(), secsOut.back().size()); @@ -1958,8 +1953,6 @@ bool WriteMREASecs(std::vector>& secsOut, const hecl::Proje WriteDLVal(w, vaFlags.tex5(), vert.iUv[5]); WriteDLVal(w, vaFlags.tex6(), vert.iUv[6]); } - - w.writeUByte(0); } } diff --git a/DataSpec/DNACommon/TXTR.cpp b/DataSpec/DNACommon/TXTR.cpp index bd19bcec6..74c8ed0b0 100644 --- a/DataSpec/DNACommon/TXTR.cpp +++ b/DataSpec/DNACommon/TXTR.cpp @@ -603,7 +603,7 @@ static uint8_t* EncodePaletteSPLT(png_structp png, png_infop info, int numEntrie } } - uint32_t format = 0; /* Default IA8 */ + uint32_t format = 2; /* Default RGB5A3 */ for (int e=0 ; e= 0) { const DNAANCS::Armature& arm = actor.armatures[sub.armature]; @@ -1180,11 +1194,17 @@ bool ANCS::Cook(const hecl::ProjectPath& outPath, ch.cskrOverlay = inPath.ensureAuxInfo(hecl::SystemString(chSysName.sys_str()) + _S('.') + overlaySys.c_str() + _S(".CSKR")); } - - break; } + + break; } + ++subtypeIdx; } + + std::sort(ch.animAABBs.begin(), ch.animAABBs.end(), + [](const ANCS::CharacterSet::CharacterInfo::ActionAABB& a, + const ANCS::CharacterSet::CharacterInfo::ActionAABB& b) + { return a.name < b.name; }); } /* Set Animation Resource IDs */ diff --git a/DataSpec/DNAMP1/CMDLMaterials.cpp b/DataSpec/DNAMP1/CMDLMaterials.cpp index 41b8dcff3..d3a969e35 100644 --- a/DataSpec/DNAMP1/CMDLMaterials.cpp +++ b/DataSpec/DNAMP1/CMDLMaterials.cpp @@ -932,11 +932,10 @@ MaterialSet::Material::Material(const hecl::Backend::GX& gx, int colorCount, int uvCount, bool lightmapUVs, - bool matrixSkinning, - std::unordered_map& uniqueMap) + bool matrixSkinning) { - XXH64_state_t xxHash; - XXH64_reset(&xxHash, 0); + XXH32_state_t xxHash; + XXH32_reset(&xxHash, 0); if (gx.m_kcolorCount) { @@ -979,6 +978,7 @@ MaterialSet::Material::Material(const hecl::Backend::GX& gx, flags.setLightmapUVArray(lightmapUVs); atUint16 texFlags = 0; + atUint16 tcgFlags = 0; tevStageTexInfo.reserve(gx.m_tevCount); textureIdxs.reserve(gx.m_tevCount); for (unsigned i=0 ; i= hecl::Backend::GX::TG_TEX0 && tcg.m_src <= hecl::Backend::GX::TG_TEX6) + tcgFlags |= 1 << (tcg.m_src - hecl::Backend::GX::TG_TEX0); + } if (stage.m_texMapIdx != -1) { texInfo.texSlot = textureIdxs.size(); @@ -1013,7 +1018,7 @@ MaterialSet::Material::Material(const hecl::Backend::GX& gx, } flags.setTextureSlots(texFlags); - XXH64_update(&xxHash, &flags.flags, sizeof(flags.flags)); + XXH32_update(&xxHash, &flags.flags, sizeof(flags.flags)); vaFlags.setPosition(GX::INDEX16); vaFlags.setNormal(GX::INDEX16); @@ -1023,61 +1028,61 @@ MaterialSet::Material::Material(const hecl::Backend::GX& gx, if (1 < colorCount) vaFlags.setColor1(GX::INDEX16); - if (0 < uvCount) + if (tcgFlags & (1 << 0)) vaFlags.setTex0(GX::INDEX16); - if (1 < uvCount) + if (tcgFlags & (1 << 1)) vaFlags.setTex1(GX::INDEX16); - if (2 < uvCount) + if (tcgFlags & (1 << 2)) vaFlags.setTex2(GX::INDEX16); - if (3 < uvCount) + if (tcgFlags & (1 << 3)) vaFlags.setTex3(GX::INDEX16); - if (4 < uvCount) + if (tcgFlags & (1 << 4)) vaFlags.setTex4(GX::INDEX16); - if (5 < uvCount) + if (tcgFlags & (1 << 5)) vaFlags.setTex5(GX::INDEX16); - if (6 < uvCount) + if (tcgFlags & (1 << 6)) vaFlags.setTex6(GX::INDEX16); if (matrixSkinning) { vaFlags.setPnMatIdx(GX::DIRECT); - if (0 < uvCount) + if (tcgFlags & (1 << 0)) vaFlags.setTex0MatIdx(GX::DIRECT); - if (1 < uvCount) + if (tcgFlags & (1 << 1)) vaFlags.setTex1MatIdx(GX::DIRECT); - if (2 < uvCount) + if (tcgFlags & (1 << 2)) vaFlags.setTex2MatIdx(GX::DIRECT); - if (3 < uvCount) + if (tcgFlags & (1 << 3)) vaFlags.setTex3MatIdx(GX::DIRECT); - if (4 < uvCount) + if (tcgFlags & (1 << 4)) vaFlags.setTex4MatIdx(GX::DIRECT); - if (5 < uvCount) + if (tcgFlags & (1 << 5)) vaFlags.setTex5MatIdx(GX::DIRECT); - if (6 < uvCount) + if (tcgFlags & (1 << 6)) vaFlags.setTex6MatIdx(GX::DIRECT); } - XXH64_update(&xxHash, &vaFlags.vaFlags, sizeof(vaFlags.vaFlags)); + XXH32_update(&xxHash, &vaFlags.vaFlags, sizeof(vaFlags.vaFlags)); - XXH64_update(&xxHash, &gx.m_kcolorCount, sizeof(gx.m_kcolorCount)); + XXH32_update(&xxHash, &gx.m_kcolorCount, sizeof(gx.m_kcolorCount)); for (unsigned i=0 ; isecond; + uniqueIdx = XXH32_digest(&xxHash); } HMDLMaterialSet::Material::Material(hecl::Frontend::Frontend& FE, diff --git a/DataSpec/DNAMP1/CMDLMaterials.hpp b/DataSpec/DNAMP1/CMDLMaterials.hpp index d32dad3ae..e9d2c817e 100644 --- a/DataSpec/DNAMP1/CMDLMaterials.hpp +++ b/DataSpec/DNAMP1/CMDLMaterials.hpp @@ -217,6 +217,9 @@ struct MaterialSet : BigDNA void setKColorIn(GX::TevKColorSel val) {kcInput = val;} GX::TevKAlphaSel kAlphaIn() const {return GX::TevKAlphaSel(kaInput);} void setKAlphaIn(GX::TevKAlphaSel val) {kaInput = val;} + + GX::ChannelID rasIn() const {return GX::ChannelID(rascInput);} + void setRASIn(GX::ChannelID id) {rascInput = id;} }; Vector tevStages; struct TEVStageTexInfo : BigDNA @@ -290,8 +293,7 @@ struct MaterialSet : BigDNA int colorCount, int uvCount, bool lightmapUVs, - bool matrixSkinning, - std::unordered_map& uniqueMap); + bool matrixSkinning); }; Vector materials; diff --git a/Runtime/Character/CAnimData.cpp b/Runtime/Character/CAnimData.cpp index eacd0e8e6..689e918b6 100644 --- a/Runtime/Character/CAnimData.cpp +++ b/Runtime/Character/CAnimData.cpp @@ -1031,10 +1031,10 @@ zeus::CAABox CAnimData::GetBoundingBox() const return x108_aabb; CAnimTreeEffectiveContribution contrib = x1f8_animRoot->GetContributionOfHighestInfluence(); - auto search = std::find_if(aabbList.cbegin(), aabbList.cend(), - [&](const std::pair& other) -> bool { - return contrib.x4_name == other.first; - }); + auto search = + rstl::binary_find(aabbList.cbegin(), aabbList.cend(), contrib.x4_name, + [](const std::pair& other) -> + const std::string& { return other.first; }); if (search == aabbList.cend()) return x108_aabb; diff --git a/hecl b/hecl index b094b0638..b0fa3912c 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit b094b0638342c12203aa58380b5a99a7a6bebe3a +Subproject commit b0fa3912c5cced6d60f0bca7e7c48568038d176c