From 2dd431eedf38c8872d96bd635c7b0e19b84eae62 Mon Sep 17 00:00:00 2001 From: petrie911 <69443847+petrie911@users.noreply.github.com> Date: Wed, 13 Mar 2024 17:49:25 -0500 Subject: SF64 Triangle factory, fixed a bug in ColPolys (#40) * 3D * and env * so much to fix * Everything can be solved with triangles --- src/factories/sf64/ColPolyFactory.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/factories/sf64/ColPolyFactory.cpp') diff --git a/src/factories/sf64/ColPolyFactory.cpp b/src/factories/sf64/ColPolyFactory.cpp index 3cff5c6..b98ce3f 100644 --- a/src/factories/sf64/ColPolyFactory.cpp +++ b/src/factories/sf64/ColPolyFactory.cpp @@ -112,18 +112,18 @@ std::optional> SF64::ColPolyFactory::parse(std::vec const auto count = GetSafeNode(node, "count"); std::vector polys; std::vector mesh; - int meshCount = 0; + int meshSize = 0; auto [_, segment] = Decompressor::AutoDecode(node, buffer, count * sizeof(SF64::CollisionPoly)); LUS::BinaryReader reader(segment.data, segment.size); reader.SetEndianness(LUS::Endianness::Big); for(int i = 0; i < count; i++) { int16_t v0 = reader.ReadInt16(); - meshCount = std::max(meshCount, (int)v0); + meshSize = std::max(meshSize, (int)v0); int16_t v1 = reader.ReadInt16(); - meshCount = std::max(meshCount, (int)v1); + meshSize = std::max(meshSize, (int)v1); int16_t v2 = reader.ReadInt16(); - meshCount = std::max(meshCount, (int)v2); + meshSize = std::max(meshSize, (int)v2); int16_t pad1 = reader.ReadInt16(); int16_t nx = reader.ReadInt16(); int16_t ny = reader.ReadInt16(); @@ -133,13 +133,15 @@ std::optional> SF64::ColPolyFactory::parse(std::vec polys.push_back(CollisionPoly({{v0, v1, v2}, pad1, {nx, ny, nz}, pad2, dist})); } - + meshSize++; const auto meshOffset = GetSafeNode(node, "mesh_offset", offset + count * sizeof(SF64::CollisionPoly)); - auto [__, meshSegment] = Decompressor::AutoDecode(node, buffer, meshCount * sizeof(Vec3s)); + YAML::Node meshNode; + meshNode["offset"] = meshOffset; + auto [__, meshSegment] = Decompressor::AutoDecode(meshNode, buffer, meshSize * sizeof(Vec3s)); LUS::BinaryReader meshReader(meshSegment.data, meshSegment.size); meshReader.SetEndianness(LUS::Endianness::Big); - for(int i = 0; i < meshCount; i++) { + for(int i = 0; i < meshSize; i++) { mesh.push_back(Vec3s(meshReader.ReadInt16(), meshReader.ReadInt16(), meshReader.ReadInt16())); } -- cgit v1.2.3