Skip to content

Commit

Permalink
Add point triggers
Browse files Browse the repository at this point in the history
Add roaming locations, spawn locations, and landmark starting grids. Also update some comments and clean up some code.
  • Loading branch information
burninrubber0 committed Feb 24, 2023
1 parent a7c5901 commit 3ad75b3
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 29 deletions.
40 changes: 36 additions & 4 deletions include/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,29 @@ class Converter
void addTriggerRegionFields(BrnTrigger::TriggerRegion region, tinygltf::Value::Object& extras);

void convertLandmark(BrnTrigger::Landmark landmark, tinygltf::Node& node, int index);
void convertStartingGrid(BrnTrigger::StartingGrid grid, tinygltf::Node& node, int index);
void convertBlackspot(BrnTrigger::Blackspot blackspot, tinygltf::Node& node, int index);
void convertVfxBoxRegion(BrnTrigger::VFXBoxRegion vfxBoxRegion, tinygltf::Node& node, int index);
void convertSignatureStunt(BrnTrigger::SignatureStunt signatureStunt, tinygltf::Node& node, int index);
void convertKillzone(BrnTrigger::Killzone killzone, tinygltf::Node& node, int index);
void convertGenericRegion(BrnTrigger::GenericRegion region, tinygltf::Node& node, int index);
void convertTriggerRegion(BrnTrigger::TriggerRegion triggerRegion, tinygltf::Node& node, int index);
void convertRoamingLocation(BrnTrigger::RoamingLocation location, tinygltf::Node& node, int index);
void convertSpawnLocation(BrnTrigger::SpawnLocation location, tinygltf::Node& node, int index);

template <typename T>
void addBoxRegionTransform(T entry, tinygltf::Node& node)
{
node.translation = {
entry.getBoxRegion().getPosX(),
entry.getBoxRegion().getPosY(),
entry.getBoxRegion().getPosZ()
entry.getBoxRegion().getPosX(),
entry.getBoxRegion().getPosY(),
entry.getBoxRegion().getPosZ()
};
Vector4 rotation = EulerToQuatRot({
entry.getBoxRegion().getRotX(),
entry.getBoxRegion().getRotY(),
entry.getBoxRegion().getRotZ()
});
});
node.rotation = {
rotation.getX(),
rotation.getY(),
Expand All @@ -71,4 +74,33 @@ class Converter
entry.getBoxRegion().getDimZ()
};
}

void addPointTransform(Vector3 pos, Vector3 rot, tinygltf::Node& node)
{
node.translation = {
pos.getX(),
pos.getY(),
pos.getZ()
};
Vector4 rotation = EulerToQuatRot({
rot.getX(),
rot.getY(),
rot.getZ()
});
node.rotation = {
rotation.getX(),
rotation.getY(),
rotation.getZ(),
rotation.getW()
};
}

void addPointTransform(Vector3 pos, tinygltf::Node& node)
{
node.translation = {
pos.getX(),
pos.getY(),
pos.getZ()
};
}
};
10 changes: 5 additions & 5 deletions include/trigger-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace BrnTrigger
int32_t regionCount = 0;
};

// BoxRegions are cuboid triggers. They are the only type used.
// Box trigger type. Sphere and line types are not supported.
class BoxRegion
{
public:
Expand Down Expand Up @@ -161,7 +161,7 @@ namespace BrnTrigger
Flags flags = (Flags)0;
};

// Starting grid for race events. Data exists but is unused in retail.
// Starting grid for race events. Unused in retail.
class StartingGrid
{
public:
Expand All @@ -175,7 +175,7 @@ namespace BrnTrigger
Vector3 startingDirections[8];
};

// TODO: Description
//
class SignatureStunt
{
public:
Expand Down Expand Up @@ -319,7 +319,7 @@ namespace BrnTrigger

};

// TODO: Description
// Spawn locations for roaming rivals (shutdown cars)
class RoamingLocation
{
public:
Expand All @@ -333,7 +333,7 @@ namespace BrnTrigger
uint8_t districtIndex = 0;
};

// TODO: Description
// Vehicle spawn locations in and outside each Junkyard
class SpawnLocation
{
enum class Type : uint8_t;
Expand Down
85 changes: 65 additions & 20 deletions src/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,28 +247,26 @@ void Converter::convertTriggersToGLTF()
// Remaining TriggerRegion triggers (checked against all of the above)
// Add starting grids, roaming locations, and spawn locations afterward

// Get counts
int currentNodeCount = 0;
//int landmarkCount = triggerData->getLandmarkCount();
//int signatureStuntCount = triggerData->getSignatureStuntCount();
//int genericRegionCount = triggerData->getGenericRegionCount();
//int killzoneCount = triggerData->getKillzoneCount();
//int blackspotCount = triggerData->getBlackspotCount();
//int vfxBoxRegionCount = triggerData->getVfxBoxRegionCount();
//int roamingLocationCount = triggerData->getRoamingLocationCount();
//int spawnLocationCount = triggerData->getSpawnLocationCount();
//int regionCount = triggerData->getRegionCount();

// Create nodes

// TriggerRegion derived nodes
int currentNodeCount = 0;
int landmarkNodeIndex = currentNodeCount;
int landmarkChildCount = 0;
for (int i = 0; i < triggerData->getLandmarkCount(); ++i)
{
model->nodes.push_back(Node());
model->nodes.back().mesh = 0;
for (int j = 0; j < triggerData->getLandmark(i).getStartingGridCount(); ++j)
{
model->nodes.push_back(Node());
model->nodes.back().mesh = 0;
model->nodes[landmarkNodeIndex + i + landmarkChildCount].children.push_back(landmarkNodeIndex + i + landmarkChildCount + j + 1);
convertStartingGrid(triggerData->getLandmark(i).getStartingGrid(j), model->nodes[landmarkNodeIndex + i + landmarkChildCount + j + 1], j);
currentNodeCount++;
}
convertLandmark(triggerData->getLandmark(i), model->nodes[i + landmarkNodeIndex], i);
currentNodeCount++;
landmarkChildCount += triggerData->getLandmark(i).getStartingGridCount();
}
int blackspotNodeIndex = currentNodeCount;
for (int i = 0; i < triggerData->getBlackspotCount(); ++i)
Expand Down Expand Up @@ -353,8 +351,26 @@ void Converter::convertTriggersToGLTF()
}
}

// Point triggers
int roamingLocationNodeIndex = currentNodeCount;
for (int i = 0; i < triggerData->getRoamingLocationCount(); ++i)
{
model->nodes.push_back(Node());
model->nodes.back().mesh = 0;
convertRoamingLocation(triggerData->getRoamingLocation(i), model->nodes[roamingLocationNodeIndex + i], i);
currentNodeCount++;
}
int spawnLocationNodeIndex = currentNodeCount;
for (int i = 0; i < triggerData->getSpawnLocationCount(); ++i)
{
model->nodes.push_back(Node());
model->nodes.back().mesh = 0;
convertSpawnLocation(triggerData->getSpawnLocation(i), model->nodes[spawnLocationNodeIndex + i], i);
currentNodeCount++;
}

// Add node indices to scene
for (int i = 0; i < triggerData->getRegionCount(); ++i)
for (int i = 0; i < currentNodeCount; ++i)
model->scenes[0].nodes.push_back(i);

// Set up asset
Expand Down Expand Up @@ -438,7 +454,13 @@ void Converter::convertLandmark(BrnTrigger::Landmark landmark, Node& node, int i
node.name = "Landmark " + std::to_string(index) + " (" + std::to_string(landmark.getId()) + ")";
}

void Converter::convertBlackspot(BrnTrigger::Blackspot blackspot, tinygltf::Node& node, int index)
void Converter::convertStartingGrid(BrnTrigger::StartingGrid grid, Node& node, int index)
{
for (int i = 0; i < 8; ++i)
addPointTransform(grid.getStartingPosition(i), grid.getStartingDirection(i), node);
}

void Converter::convertBlackspot(BrnTrigger::Blackspot blackspot, Node& node, int index)
{
addBoxRegionTransform(blackspot, node);

Expand All @@ -451,14 +473,14 @@ void Converter::convertBlackspot(BrnTrigger::Blackspot blackspot, tinygltf::Node
node.name = "Blackspot " + std::to_string(index) + " (" + std::to_string(blackspot.getId()) + ")";
}

void Converter::convertVfxBoxRegion(BrnTrigger::VFXBoxRegion vfxBoxRegion, tinygltf::Node& node, int index)
void Converter::convertVfxBoxRegion(BrnTrigger::VFXBoxRegion vfxBoxRegion, Node& node, int index)
{
addBoxRegionTransform(vfxBoxRegion, node);

node.name = "VFXBoxRegion " + std::to_string(index) + " (" + std::to_string(vfxBoxRegion.getId()) + ")";
}

void Converter::convertSignatureStunt(BrnTrigger::SignatureStunt signatureStunt, tinygltf::Node& node, int index)
void Converter::convertSignatureStunt(BrnTrigger::SignatureStunt signatureStunt, Node& node, int index)
{
Value::Object extras;
extras["ID"] = Value((int)signatureStunt.getId());
Expand All @@ -468,7 +490,7 @@ void Converter::convertSignatureStunt(BrnTrigger::SignatureStunt signatureStunt,
node.name = "SignatureStunt " + std::to_string(index) + " (" + std::to_string(signatureStunt.getId()) + ")";
}

void Converter::convertKillzone(BrnTrigger::Killzone killzone, tinygltf::Node& node, int index)
void Converter::convertKillzone(BrnTrigger::Killzone killzone, Node& node, int index)
{
Value::Array regionIds;
for (int i = 0; i < killzone.getRegionIdCount(); ++i)
Expand All @@ -481,7 +503,7 @@ void Converter::convertKillzone(BrnTrigger::Killzone killzone, tinygltf::Node& n
node.name = "Killzone " + std::to_string(index);
}

void Converter::convertGenericRegion(BrnTrigger::GenericRegion region, tinygltf::Node& node, int index)
void Converter::convertGenericRegion(BrnTrigger::GenericRegion region, Node& node, int index)
{
addBoxRegionTransform(region, node);

Expand All @@ -502,9 +524,32 @@ void Converter::convertGenericRegion(BrnTrigger::GenericRegion region, tinygltf:
node.name = "GenericRegion " + std::to_string(index) + " (" + std::to_string(id) + ")";
}

void Converter::convertTriggerRegion(BrnTrigger::TriggerRegion triggerRegion, tinygltf::Node& node, int index)
void Converter::convertTriggerRegion(BrnTrigger::TriggerRegion triggerRegion, Node& node, int index)
{
addBoxRegionTransform(triggerRegion, node);

node.name = "TriggerRegion " + std::to_string(index) + " (" + std::to_string(triggerRegion.getId()) + ")";
}

void Converter::convertRoamingLocation(BrnTrigger::RoamingLocation location, Node& node, int index)
{
addPointTransform(location.getPosition(), node);

Value::Object extras;
extras["District index"] = Value(location.getDistrictIndex());
node.extras = Value(extras);

node.name = "RoamingLocation " + std::to_string(index);
}

void Converter::convertSpawnLocation(BrnTrigger::SpawnLocation location, Node& node, int index)
{
addPointTransform(location.getPosition(), location.getDirection(), node);

Value::Object extras;
extras["Junkyard ID"] = Value((int)location.getJunkyardId());
extras["Type"] = Value((uint8_t)location.getType());
node.extras = Value(extras);

node.name = "SpawnLocation " + std::to_string(index);
}

0 comments on commit 3ad75b3

Please sign in to comment.