summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpetrie911 <69443847+petrie911@users.noreply.github.com>2024-03-14 10:12:28 -0500
committerGitHub <noreply@github.com>2024-03-14 09:12:28 -0600
commit70568034c212d432a1c3aaed013977a69e9ec998 (patch)
tree5212b8c0112407dfcdf8f93fb0bfcd6a56646399
parent2dd431eedf38c8872d96bd635c7b0e19b84eae62 (diff)
Fixes to SF64 factories (#41)
* 3D * and env * so much to fix * Everything can be solved with triangles * fixes
-rw-r--r--src/factories/sf64/AnimFactory.cpp29
-rw-r--r--src/factories/sf64/ColPolyFactory.cpp9
-rw-r--r--src/factories/sf64/ColPolyFactory.h2
-rw-r--r--src/factories/sf64/ObjInitFactory.cpp12
-rw-r--r--src/factories/sf64/TriangleFactory.cpp6
5 files changed, 42 insertions, 16 deletions
diff --git a/src/factories/sf64/AnimFactory.cpp b/src/factories/sf64/AnimFactory.cpp
index c0df138..1d12860 100644
--- a/src/factories/sf64/AnimFactory.cpp
+++ b/src/factories/sf64/AnimFactory.cpp
@@ -65,9 +65,15 @@ void SF64::AnimCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsed
if (Companion::Instance->IsDebug()) {
write << "// 0x" << std::uppercase << std::hex << dataOffset << "\n";
}
-
+ auto dataCount = anim->mFrameData.size();
+ // write << "Frame data end: 0x" << std::hex << std::uppercase << (dataOffset + sizeof(uint16_t) * dataCount) << "\n";
+ // write << "JointKey start: 0x" << std::hex << std::uppercase << keyOffset << "\n";
+ if(dataOffset + sizeof(uint16_t) * dataCount > keyOffset) {
+ dataCount = (keyOffset - dataOffset) / sizeof(uint16_t);
+ write << "// SF64:ANIM error: Frame data overlaps joint key.\n";
+ }
write << "u16 " << dataName << "[] = {";
- for(int i = 0; i < anim->mFrameData.size(); i++) {
+ for(int i = 0; i < dataCount; i++) {
if((i % 12) == 0) {
write << "\n" << fourSpaceTab;
}
@@ -127,6 +133,7 @@ std::optional<std::shared_ptr<IParsedData>> SF64::AnimFactory::parse(std::vector
std::vector<SF64::JointKey> jointKeys;
std::vector<int16_t> frameData;
auto dataCount = 1;
+ auto maxIndex = 0;
auto [_, segment] = Decompressor::AutoDecode(node, buffer, 0xC);
LUS::BinaryReader reader(segment.data, segment.size);
@@ -146,23 +153,27 @@ std::optional<std::shared_ptr<IParsedData>> SF64::AnimFactory::parse(std::vector
for(int i = 0; i <= limbCount; i++) {
auto xLen = keyReader.ReadUInt16();
auto x = keyReader.ReadUInt16();
+ maxIndex = std::max(maxIndex, (int)x);
auto yLen = keyReader.ReadUInt16();
auto y = keyReader.ReadUInt16();
+ maxIndex = std::max(maxIndex, (int)y);
auto zLen = keyReader.ReadUInt16();
auto z = keyReader.ReadUInt16();
+ maxIndex = std::max(maxIndex, (int)z);
jointKeys.push_back(SF64::JointKey({xLen, x, yLen, y, zLen, z}));
- if(x != 0) {
- dataCount += (xLen < 1) ? 1 : (xLen > frameCount) ? frameCount : xLen;
+ if(x != 0 && xLen != 0) {
+ dataCount += (xLen > frameCount) ? frameCount: xLen;
}
- if(y != 0) {
- dataCount += (yLen < 1) ? 1 : (yLen > frameCount) ? frameCount : yLen;
+ if(y != 0 && yLen != 0) {
+ dataCount += (yLen > frameCount) ? frameCount: yLen;
}
- if(z != 0) {
- dataCount += (zLen < 1) ? 1 : (zLen > frameCount) ? frameCount : zLen;
+ if(z != 0 && zLen != 0) {
+ dataCount += (zLen > frameCount) ? frameCount: zLen;
}
}
-
+ // std::cout << dataCount << fourSpaceTab << maxIndex << "\n";
+ dataCount = std::max(dataCount, maxIndex + 1);
auto [___, dataSegment] = Decompressor::AutoDecode(dataNode, buffer, sizeof(uint16_t) * dataCount);
LUS::BinaryReader dataReader(dataSegment.data, dataSegment.size);
dataReader.SetEndianness(LUS::Endianness::Big);
diff --git a/src/factories/sf64/ColPolyFactory.cpp b/src/factories/sf64/ColPolyFactory.cpp
index b98ce3f..96c81eb 100644
--- a/src/factories/sf64/ColPolyFactory.cpp
+++ b/src/factories/sf64/ColPolyFactory.cpp
@@ -43,7 +43,7 @@ void SF64::ColPolyCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar
// if((i++ % 2) == 0) {
write << "\n" << fourSpaceTab;
// }
- write << "{ {" << NUM(poly.tri[0], width) << ", " << NUM(poly.tri[1], width) << ", " << NUM(poly.tri[2], width) << "}, ";
+ write << "{ " << NUM(poly.tri, width) << ", ";
if (poly.unk_06 == 0) {
write << "0, ";
} else {
@@ -142,7 +142,12 @@ std::optional<std::shared_ptr<IParsedData>> SF64::ColPolyFactory::parse(std::vec
meshReader.SetEndianness(LUS::Endianness::Big);
for(int i = 0; i < meshSize; i++) {
- mesh.push_back(Vec3s(meshReader.ReadInt16(), meshReader.ReadInt16(), meshReader.ReadInt16()));
+ Vec3s vtx;
+
+ vtx.x = meshReader.ReadInt16();
+ vtx.y = meshReader.ReadInt16();
+ vtx.z = meshReader.ReadInt16();
+ mesh.push_back(vtx);
}
return std::make_shared<SF64::ColPolyData>(polys, mesh);
diff --git a/src/factories/sf64/ColPolyFactory.h b/src/factories/sf64/ColPolyFactory.h
index 45ff045..fd43f62 100644
--- a/src/factories/sf64/ColPolyFactory.h
+++ b/src/factories/sf64/ColPolyFactory.h
@@ -6,7 +6,7 @@
namespace SF64 {
struct CollisionPoly {
- int16_t tri[3];
+ Vec3s tri;
int16_t unk_06;
Vec3s norm;
int16_t unk_0E;
diff --git a/src/factories/sf64/ObjInitFactory.cpp b/src/factories/sf64/ObjInitFactory.cpp
index 3e4294d..8894036 100644
--- a/src/factories/sf64/ObjInitFactory.cpp
+++ b/src/factories/sf64/ObjInitFactory.cpp
@@ -63,6 +63,7 @@ std::optional<std::shared_ptr<IParsedData>> SF64::ObjInitFactory::parse(std::vec
LUS::BinaryReader reader(segment.data, segment.size);
reader.SetEndianness(LUS::Endianness::Big);
std::vector<ObjectInit> objects;
+ bool terminator = false;
bool processing = true;
while(processing) {
@@ -76,9 +77,14 @@ std::optional<std::shared_ptr<IParsedData>> SF64::ObjInitFactory::parse(std::vec
int16_t id = reader.ReadInt16();
reader.ReadInt16();
- processing = id != -1;
-
- objects.push_back({ zPos1, zPos2, xPos, yPos, {rotX, rotY, rotZ}, id});
+ if(id == -1) {
+ terminator = true;
+ }
+ if(terminator && ((zPos1*zPos2*xPos*yPos*rotX*rotY*rotZ) != 0 || id != -1)) {
+ processing = false;
+ } else {
+ objects.push_back({ zPos1, zPos2, xPos, yPos, {rotX, rotY, rotZ}, id});
+ }
}
return std::make_shared<ObjInitData>(objects);
diff --git a/src/factories/sf64/TriangleFactory.cpp b/src/factories/sf64/TriangleFactory.cpp
index c3ada96..9e50879 100644
--- a/src/factories/sf64/TriangleFactory.cpp
+++ b/src/factories/sf64/TriangleFactory.cpp
@@ -132,8 +132,12 @@ std::optional<std::shared_ptr<IParsedData>> SF64::TriangleFactory::parse(std::ve
std::vector<std::vector<Vec3f>> meshes;
for(int j = 0; j < meshCount; j++) {
std::vector<Vec3f> mesh;
+ Vec3f vtx;
for(int i = 0; i < meshSize; i++) {
- mesh.push_back(Vec3f(meshReader.ReadFloat(), meshReader.ReadFloat(), meshReader.ReadFloat()));
+ vtx.x = meshReader.ReadFloat();
+ vtx.y = meshReader.ReadFloat();
+ vtx.z = meshReader.ReadFloat();
+ mesh.push_back(vtx);
}
meshes.push_back(mesh);
}