mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Fixes to SF64 factories (#41)
* 3D * and env * so much to fix * Everything can be solved with triangles * fixes
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace SF64 {
|
||||
|
||||
struct CollisionPoly {
|
||||
int16_t tri[3];
|
||||
Vec3s tri;
|
||||
int16_t unk_06;
|
||||
Vec3s norm;
|
||||
int16_t unk_0E;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user