|
|
@@ -188,7 +188,19 @@ public:
|
|
|
virtual std::string AnimationName(int charId, int id) override
|
|
|
{
|
|
|
// Get the animation file name, then look up the friendly name of the "raw" animation
|
|
|
+ if (charId >= mModelLoader->getModels().size())
|
|
|
+ {
|
|
|
+ std::cout << "ERROR CHAR ID IS OUT OF BOUNDS" << std::endl;
|
|
|
+ return std::to_string(id);
|
|
|
+ }
|
|
|
+
|
|
|
const auto& modelInfo = mModelLoader->getModels().at(charId);
|
|
|
+ if (id >= modelInfo.animations.size())
|
|
|
+ {
|
|
|
+ std::cout << "ERROR ANIMATION ID IS OUT OF BOUNDS" << std::endl;
|
|
|
+ return std::to_string(id);
|
|
|
+ }
|
|
|
+
|
|
|
const auto rawName = modelInfo.animations.at(id).name;
|
|
|
|
|
|
// Trim off ".yos" or whatever other crazy extension the model loader adds in
|
|
|
@@ -265,6 +277,8 @@ public:
|
|
|
std::vector<Record> mGatewaysToThisField;
|
|
|
};
|
|
|
typedef std::map<u16, SpawnPointDb> FieldSpawnPointsMap;
|
|
|
+typedef std::map<u16, float> FieldScaleFactorMap;
|
|
|
+
|
|
|
|
|
|
typedef std::map<std::string, std::set<std::string>> ModelAnimationMap;
|
|
|
class ModelsAndAnimationsDb
|
|
|
@@ -314,11 +328,22 @@ static size_t FieldId(const std::string& name, const std::vector<std::string>& f
|
|
|
throw std::runtime_error("No Id found for field name");
|
|
|
}
|
|
|
|
|
|
+static float FieldScaleFactor(const FieldScaleFactorMap& scaleFactorMap, size_t fieldId)
|
|
|
+{
|
|
|
+ auto it = scaleFactorMap.find(fieldId);
|
|
|
+ if (it == std::end(scaleFactorMap))
|
|
|
+ {
|
|
|
+ throw std::runtime_error("Scale factor not found for field id");
|
|
|
+ }
|
|
|
+ return it->second;
|
|
|
+}
|
|
|
+
|
|
|
static void FF7PcFieldToQGearsField(
|
|
|
QGears::FLevelFilePtr& field,
|
|
|
const std::string& outDir,
|
|
|
const std::vector<std::string>& fieldIdToNameLookup,
|
|
|
const FieldSpawnPointsMap& spawnMap,
|
|
|
+ const FieldScaleFactorMap& scaleFactorMap,
|
|
|
ModelsAndAnimationsDb& modelAnimationDb,
|
|
|
MapCollection& maps)
|
|
|
{
|
|
|
@@ -435,9 +460,10 @@ static void FF7PcFieldToQGearsField(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // TODO: Get these scales from the field game data, 1024 for md1_1 and 512 for md1_2, DAT CFG has them as 2 and 1?
|
|
|
- const float downscaler_next = 128.0f; // * MapIdToScale( map_id );
|
|
|
- const float downscaler_this = 128.0f; // * field.scale
|
|
|
+ // Get this fields Id
|
|
|
+ const size_t thisFieldId = FieldId(field->getName(), fieldIdToNameLookup);
|
|
|
+
|
|
|
+ const float downscaler_this = 128.0f * FieldScaleFactor(scaleFactorMap, thisFieldId);
|
|
|
|
|
|
const auto& gateways = triggers->GetGateways();
|
|
|
for (size_t i = 0; i < gateways.size(); i++)
|
|
|
@@ -464,8 +490,6 @@ static void FF7PcFieldToQGearsField(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Get this fields Id
|
|
|
- const size_t thisFieldId = FieldId(field->getName(), fieldIdToNameLookup);
|
|
|
|
|
|
// Use that to find the pre-computed list of gateways in all other fields that link to this field
|
|
|
auto spawnIterator = spawnMap.find(thisFieldId);
|
|
|
@@ -484,10 +508,15 @@ static void FF7PcFieldToQGearsField(
|
|
|
// Must also include the gateway index for the case where 2 fields have more than one door linking to each other
|
|
|
xmlEntityPoint->SetAttribute("name", "Spawn_" + fieldIdToNameLookup.at(spawnPointRecords[i].mFieldId) + "_" + std::to_string(spawnPointRecords[i].GatewayIndex));
|
|
|
|
|
|
+ const float downscaler_next = 128.0f * FieldScaleFactor(scaleFactorMap, gateway.destinationFieldId);
|
|
|
|
|
|
- xmlEntityPoint->SetAttribute("position",
|
|
|
- Ogre::StringConverter::toString(
|
|
|
- Ogre::Vector3(gateway.destination.x, gateway.destination.y, gateway.destination.z) / downscaler_next));
|
|
|
+ // Position Z is actually the target walkmesh triangle ID, so this is tiny bit more
|
|
|
+ // complex as we have to say "get the Z value of the triangle with that ID". Note that ID actually just means index.
|
|
|
+ const float zOfTriangleWithId = field->getWalkmesh()->getTriangles().at(static_cast<unsigned int>(gateway.destination.z)).a.z;
|
|
|
+
|
|
|
+ const Ogre::Vector3 posVec(gateway.destination.x / downscaler_next, gateway.destination.y / downscaler_next, zOfTriangleWithId);
|
|
|
+
|
|
|
+ xmlEntityPoint->SetAttribute("position", Ogre::StringConverter::toString(posVec));
|
|
|
|
|
|
const float rotation = (360.0f * static_cast<float>(gateway.dir)) / 255.0f;
|
|
|
xmlEntityPoint->SetAttribute("rotation", std::to_string(rotation));
|
|
|
@@ -498,108 +527,109 @@ static void FF7PcFieldToQGearsField(
|
|
|
|
|
|
doc.LinkEndChild(element.release());
|
|
|
doc.SaveFile(outDir + "/" + FieldMapDir() + "/" + field->getName() + "/map.xml");
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
- const QGears::PaletteFilePtr& pal = field->getPalette();
|
|
|
- const QGears::BackgroundFilePtr& bg = field->getBackground();
|
|
|
- std::unique_ptr<Ogre::Image> bgImage(bg->createImage(pal));
|
|
|
- bgImage->save(outDir + "/" + FieldMapDir() + "/" + field->getName() + "/tiles.png");
|
|
|
+ const QGears::PaletteFilePtr& pal = field->getPalette();
|
|
|
+ const QGears::BackgroundFilePtr& bg = field->getBackground();
|
|
|
+ std::unique_ptr<Ogre::Image> bgImage(bg->createImage(pal));
|
|
|
+ bgImage->save(outDir + "/" + FieldMapDir() + "/" + field->getName() + "/tiles.png");
|
|
|
|
|
|
- {
|
|
|
- TiXmlDocument doc;
|
|
|
- std::unique_ptr<TiXmlElement> element(new TiXmlElement("background2d"));
|
|
|
-
|
|
|
- // Magic constants
|
|
|
- const int kScaleUpFactor = 3;
|
|
|
- const int kPsxScreenWidth = 320;
|
|
|
- const int kPsxScreenHeight = 240;
|
|
|
-
|
|
|
- // Get texture atlas size
|
|
|
- const int width = bgImage->getWidth();
|
|
|
- const int height = bgImage->getHeight();
|
|
|
-
|
|
|
- const QGears::CameraMatrixFilePtr& camMatrix = field->getCameraMatrix();
|
|
|
- const Ogre::Vector3 position = camMatrix->getPosition();
|
|
|
- const Ogre::Quaternion orientation = camMatrix->getOrientation();
|
|
|
- const Ogre::Degree fov = camMatrix->getFov(static_cast<float>(kPsxScreenHeight));
|
|
|
-
|
|
|
-
|
|
|
- const int min_x = triggers->getCameraRange().left * kScaleUpFactor;
|
|
|
- const int min_y = triggers->getCameraRange().top * kScaleUpFactor;
|
|
|
- const int max_x = triggers->getCameraRange().right * kScaleUpFactor;
|
|
|
- const int max_y = triggers->getCameraRange().bottom * kScaleUpFactor;
|
|
|
-
|
|
|
- element->SetAttribute("image", FieldMapDir() + "/" + field->getName() + "/tiles.png");
|
|
|
- element->SetAttribute("position", Ogre::StringConverter::toString(position));
|
|
|
- element->SetAttribute("orientation", Ogre::StringConverter::toString(orientation));
|
|
|
- element->SetAttribute("fov", Ogre::StringConverter::toString(fov));
|
|
|
- element->SetAttribute("range", std::to_string(min_x) + " " + std::to_string(min_y) + " " + std::to_string(max_x) + " " + std::to_string(max_y));
|
|
|
- element->SetAttribute("clip", std::to_string(kPsxScreenWidth * kScaleUpFactor) + " " + std::to_string(kPsxScreenHeight * kScaleUpFactor));
|
|
|
-
|
|
|
- // Write out the *_BG.XML data
|
|
|
- auto& layers = bg->getLayers();
|
|
|
- for (const auto& layer : layers)
|
|
|
{
|
|
|
- // TODO: Should we only output tiles to construct enabled layers?
|
|
|
- // if (layer.enabled)
|
|
|
+ TiXmlDocument doc;
|
|
|
+ std::unique_ptr<TiXmlElement> element(new TiXmlElement("background2d"));
|
|
|
+
|
|
|
+ // Magic constants
|
|
|
+ const int kScaleUpFactor = 3;
|
|
|
+ const int kPsxScreenWidth = 320;
|
|
|
+ const int kPsxScreenHeight = 240;
|
|
|
+
|
|
|
+ // Get texture atlas size
|
|
|
+ const int width = bgImage->getWidth();
|
|
|
+ const int height = bgImage->getHeight();
|
|
|
+
|
|
|
+ const QGears::CameraMatrixFilePtr& camMatrix = field->getCameraMatrix();
|
|
|
+ const Ogre::Vector3 position = camMatrix->getPosition() / FieldScaleFactor(scaleFactorMap, thisFieldId);
|
|
|
+ const Ogre::Quaternion orientation = camMatrix->getOrientation();
|
|
|
+ const Ogre::Degree fov = camMatrix->getFov(static_cast<float>(kPsxScreenHeight));
|
|
|
+
|
|
|
+
|
|
|
+ const int min_x = triggers->getCameraRange().left * kScaleUpFactor;
|
|
|
+ const int min_y = triggers->getCameraRange().top * kScaleUpFactor;
|
|
|
+ const int max_x = triggers->getCameraRange().right * kScaleUpFactor;
|
|
|
+ const int max_y = triggers->getCameraRange().bottom * kScaleUpFactor;
|
|
|
+
|
|
|
+ element->SetAttribute("image", FieldMapDir() + "/" + field->getName() + "/tiles.png");
|
|
|
+ element->SetAttribute("position", Ogre::StringConverter::toString(position));
|
|
|
+ element->SetAttribute("orientation", Ogre::StringConverter::toString(orientation));
|
|
|
+ element->SetAttribute("fov", Ogre::StringConverter::toString(fov));
|
|
|
+ element->SetAttribute("range", std::to_string(min_x) + " " + std::to_string(min_y) + " " + std::to_string(max_x) + " " + std::to_string(max_y));
|
|
|
+ element->SetAttribute("clip", std::to_string(kPsxScreenWidth * kScaleUpFactor) + " " + std::to_string(kPsxScreenHeight * kScaleUpFactor));
|
|
|
+
|
|
|
+ // Write out the *_BG.XML data
|
|
|
+ auto& layers = bg->getLayers();
|
|
|
+ for (const auto& layer : layers)
|
|
|
{
|
|
|
-
|
|
|
- for (const QGears::BackgroundFile::SpriteData& sprite : layer.sprites)
|
|
|
+ // TODO: Should we only output tiles to construct enabled layers?
|
|
|
+ // if (layer.enabled)
|
|
|
{
|
|
|
- std::unique_ptr<TiXmlElement> xmlElement(new TiXmlElement("tile"));
|
|
|
|
|
|
- xmlElement->SetAttribute("destination",
|
|
|
- Ogre::StringConverter::toString(sprite.dst.x * kScaleUpFactor) + " " +
|
|
|
- Ogre::StringConverter::toString(sprite.dst.y * kScaleUpFactor));
|
|
|
+ for (const QGears::BackgroundFile::SpriteData& sprite : layer.sprites)
|
|
|
+ {
|
|
|
+ std::unique_ptr<TiXmlElement> xmlElement(new TiXmlElement("tile"));
|
|
|
|
|
|
- xmlElement->SetAttribute("width", Ogre::StringConverter::toString(sprite.width * kScaleUpFactor));
|
|
|
- xmlElement->SetAttribute("height", Ogre::StringConverter::toString(sprite.height * kScaleUpFactor));
|
|
|
+ xmlElement->SetAttribute("destination",
|
|
|
+ Ogre::StringConverter::toString(sprite.dst.x * kScaleUpFactor) + " " +
|
|
|
+ Ogre::StringConverter::toString(sprite.dst.y * kScaleUpFactor));
|
|
|
|
|
|
- // Each tile is added to a big texture atlas with hard coded size of 1024x1024, convert UV's to the 0.0f to 1.0f range
|
|
|
- const float u0 = static_cast<float>(sprite.src.x) / bgImage->getWidth();
|
|
|
- const float v0 = static_cast<float>(sprite.src.y) / bgImage->getHeight();
|
|
|
+ xmlElement->SetAttribute("width", Ogre::StringConverter::toString(sprite.width * kScaleUpFactor));
|
|
|
+ xmlElement->SetAttribute("height", Ogre::StringConverter::toString(sprite.height * kScaleUpFactor));
|
|
|
|
|
|
- const float u1 = static_cast<float>(sprite.src.x + sprite.width) / bgImage->getWidth();
|
|
|
- const float v1 = static_cast<float>(sprite.src.y + sprite.height) / bgImage->getHeight();
|
|
|
+ // Each tile is added to a big texture atlas with hard coded size of 1024x1024, convert UV's to the 0.0f to 1.0f range
|
|
|
+ const float u0 = static_cast<float>(sprite.src.x) / bgImage->getWidth();
|
|
|
+ const float v0 = static_cast<float>(sprite.src.y) / bgImage->getHeight();
|
|
|
|
|
|
- xmlElement->SetAttribute("uv",
|
|
|
- Ogre::StringConverter::toString(u0) + " " + Ogre::StringConverter::toString(v0) + " " +
|
|
|
- Ogre::StringConverter::toString(u1) + " " + Ogre::StringConverter::toString(v1)
|
|
|
- );
|
|
|
+ const float u1 = static_cast<float>(sprite.src.x + sprite.width) / bgImage->getWidth();
|
|
|
+ const float v1 = static_cast<float>(sprite.src.y + sprite.height) / bgImage->getHeight();
|
|
|
|
|
|
- // TODO: Figure out how to scale this value correctly
|
|
|
- xmlElement->SetAttribute("depth", "999" /* Ogre::StringConverter::toString(static_cast<float>(sprite.depth) / (4096.0f/10.0f))*/);
|
|
|
+ xmlElement->SetAttribute("uv",
|
|
|
+ Ogre::StringConverter::toString(u0) + " " + Ogre::StringConverter::toString(v0) + " " +
|
|
|
+ Ogre::StringConverter::toString(u1) + " " + Ogre::StringConverter::toString(v1)
|
|
|
+ );
|
|
|
|
|
|
- // TODO: Copied from DatFile::AddTile - add to common method
|
|
|
- Ogre::String blending_str = "";
|
|
|
- if (sprite.blending == 0)
|
|
|
- {
|
|
|
- blending_str = "alpha";
|
|
|
- }
|
|
|
- else if (sprite.blending == 1 || sprite.blending == 3) // 3 is source + 0.25 * destination
|
|
|
- {
|
|
|
- blending_str = "add";
|
|
|
- }
|
|
|
- else if (sprite.blending == 2)
|
|
|
- {
|
|
|
- blending_str = "subtract";
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // TODO: Should probably throw to fail conversion
|
|
|
- blending_str = "unknown";
|
|
|
+ // TODO: Figure out how to scale this value correctly
|
|
|
+ xmlElement->SetAttribute("depth", "999" /* Ogre::StringConverter::toString(static_cast<float>(sprite.depth) / (4096.0f/10.0f))*/);
|
|
|
+
|
|
|
+ // TODO: Copied from DatFile::AddTile - add to common method
|
|
|
+ Ogre::String blending_str = "";
|
|
|
+ if (sprite.blending == 0)
|
|
|
+ {
|
|
|
+ blending_str = "alpha";
|
|
|
+ }
|
|
|
+ else if (sprite.blending == 1 || sprite.blending == 3) // 3 is source + 0.25 * destination
|
|
|
+ {
|
|
|
+ blending_str = "add";
|
|
|
+ }
|
|
|
+ else if (sprite.blending == 2)
|
|
|
+ {
|
|
|
+ blending_str = "subtract";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // TODO: Should probably throw to fail conversion
|
|
|
+ blending_str = "unknown";
|
|
|
+ }
|
|
|
+ xmlElement->SetAttribute("blending", blending_str);
|
|
|
+
|
|
|
+ element->LinkEndChild(xmlElement.release());
|
|
|
}
|
|
|
- xmlElement->SetAttribute("blending", blending_str);
|
|
|
-
|
|
|
- element->LinkEndChild(xmlElement.release());
|
|
|
}
|
|
|
}
|
|
|
+ doc.LinkEndChild(element.release());
|
|
|
+ doc.SaveFile(outDir + "/" + FieldMapDir() + "/" + field->getName() + "/bg.xml");
|
|
|
}
|
|
|
- doc.LinkEndChild(element.release());
|
|
|
- doc.SaveFile(outDir + "/" + FieldMapDir() + "/" + field->getName() +"/bg.xml");
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
{
|
|
|
// Save out the walk mesh as XML
|
|
|
const QGears::WalkmeshFilePtr& walkmesh = field->getWalkmesh();
|
|
|
@@ -672,6 +702,32 @@ static bool IsAFieldFile(Ogre::String& resourceName)
|
|
|
&& resourceName != "maplist");
|
|
|
}
|
|
|
|
|
|
+// Exclude fields which cause fatal crash bugs :)
|
|
|
+// this can be removed when whatever is causing the crash(s) is fixed
|
|
|
+static bool WillCrash(Ogre::String& resourceName)
|
|
|
+{
|
|
|
+ if (
|
|
|
+ // crashes in back ground image generation
|
|
|
+ resourceName == "bugin1a" ||
|
|
|
+
|
|
|
+ // Hangs in decompliation
|
|
|
+ resourceName == "frcyo" ||
|
|
|
+
|
|
|
+ // bg image crash
|
|
|
+ resourceName == "fr_e" ||
|
|
|
+ resourceName == "las4_2" ||
|
|
|
+ resourceName == "las4_3" ||
|
|
|
+ resourceName == "lastmap" ||
|
|
|
+ resourceName == "md_e1" ||
|
|
|
+ resourceName == "trnad_3"
|
|
|
+ )
|
|
|
+ {
|
|
|
+ // NOTE: Even so, conversion of all models will fail with a bone index out of bounds
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
static bool IsTestField(Ogre::String& resourceName)
|
|
|
{
|
|
|
if (
|
|
|
@@ -692,6 +748,11 @@ static bool IsTestField(Ogre::String& resourceName)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+static void CollectFieldScaleFactors(QGears::FLevelFilePtr& field, FieldScaleFactorMap& scaleFactors, const std::vector<std::string>& fieldIdToNameLookup)
|
|
|
+{
|
|
|
+ scaleFactors[FieldId(field->getName(), fieldIdToNameLookup)] = ::SUDM::FF7::Field::ScaleFactor(field->getRawScript());
|
|
|
+}
|
|
|
+
|
|
|
void FF7DataInstaller::ConvertFields(std::string archive, std::string inputDir, std::string outDir)
|
|
|
{
|
|
|
mOutputDir = outDir;
|
|
|
@@ -707,13 +768,15 @@ void FF7DataInstaller::ConvertFields(std::string archive, std::string inputDir,
|
|
|
|
|
|
// On the first pass collate required field information
|
|
|
FieldSpawnPointsMap spawnPoints;
|
|
|
+ FieldScaleFactorMap scaleFactors;
|
|
|
for (auto& resourceName : *resources)
|
|
|
{
|
|
|
// Exclude things that are not fields
|
|
|
- if (IsAFieldFile(resourceName))
|
|
|
+ if (IsAFieldFile(resourceName) /*&& IsTestField(resourceName)*/)
|
|
|
{
|
|
|
QGears::FLevelFilePtr field = QGears::LZSFLevelFileManager::getSingleton().load(resourceName, "FFVIIFields").staticCast<QGears::FLevelFile>();
|
|
|
CollectSpawnPoints(field, mapList->GetMapList(), spawnPoints);
|
|
|
+ CollectFieldScaleFactors(field, scaleFactors, mapList->GetMapList());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -726,12 +789,18 @@ void FF7DataInstaller::ConvertFields(std::string archive, std::string inputDir,
|
|
|
// Exclude things that are not fields
|
|
|
if (IsAFieldFile(resourceName))
|
|
|
{
|
|
|
- if (IsTestField(resourceName))
|
|
|
+ if (IsTestField(resourceName) &&
|
|
|
+ !WillCrash(resourceName))
|
|
|
{
|
|
|
+ std::cout << "Converting: " << resourceName << std::endl;
|
|
|
CreateDir(FieldMapDir() + "/" + resourceName);
|
|
|
|
|
|
QGears::FLevelFilePtr field = QGears::LZSFLevelFileManager::getSingleton().load(resourceName, "FFVIIFields").staticCast<QGears::FLevelFile>();
|
|
|
- FF7PcFieldToQGearsField(field, outDir, mapList->GetMapList(), spawnPoints, modelAnimationDb, maps);
|
|
|
+ FF7PcFieldToQGearsField(field, outDir, mapList->GetMapList(), spawnPoints, scaleFactors, modelAnimationDb, maps);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout << "Skip: " << resourceName << " as it has a crash or hang issue" << std::endl;
|
|
|
}
|
|
|
}
|
|
|
}
|