From 5e03278eff95f1c2f1fd939c72a94a80441eb2f8 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 8 Dec 2017 19:17:51 -1000 Subject: [PATCH] Add triangle flip bit for collision geometry --- DataSpec/DNACommon/DeafBabe.cpp | 39 ++++++++++++++++++---- DataSpec/DNAMP1/DeafBabe.hpp | 14 +++----- DataSpec/DNAMP2/DeafBabe.hpp | 6 ++-- Runtime/Collision/CCollisionSurface.cpp | 4 +-- Runtime/Collision/CMetroidAreaCollider.cpp | 6 ++-- Runtime/World/CActor.cpp | 1 + hecl | 2 +- 7 files changed, 48 insertions(+), 24 deletions(-) diff --git a/DataSpec/DNACommon/DeafBabe.cpp b/DataSpec/DNACommon/DeafBabe.cpp index 1f7ce6a94..c92b5e7d1 100644 --- a/DataSpec/DNACommon/DeafBabe.cpp +++ b/DataSpec/DNACommon/DeafBabe.cpp @@ -30,10 +30,27 @@ void DeafBabeSendToBlender(hecl::BlenderConnection::PyOutStream& os, const DEAFB const typename DEAFBABE::Edge& edge2 = db.edgeVertConnections[tri.edges[2]]; if (!edge0.verts[0] && !edge1.verts[0] && !edge2.verts[0]) break; + + int vindices[3]; + vindices[2] = + (edge1.verts[0] != edge0.verts[0] && edge1.verts[0] != edge0.verts[1]) ? + edge1.verts[0] : edge1.verts[1]; + + if (triMat.flipFace()) + { + vindices[0] = edge0.verts[1]; + vindices[1] = edge0.verts[0]; + } + else + { + vindices[0] = edge0.verts[0]; + vindices[1] = edge0.verts[1]; + } + os << "tri_verts = []\n"; - os.format("tri_verts.append(col_bm.verts[%u])\n", edge0.findCommon(edge1)); - os.format("tri_verts.append(col_bm.verts[%u])\n", edge1.findCommon(edge2)); - os.format("tri_verts.append(col_bm.verts[%u])\n", edge2.findCommon(edge0)); + os.format("tri_verts.append(col_bm.verts[%u])\n", vindices[0]); + os.format("tri_verts.append(col_bm.verts[%u])\n", vindices[1]); + os.format("tri_verts.append(col_bm.verts[%u])\n", vindices[2]); os.format("face = col_bm.faces.get(tri_verts)\n" "if face is None:\n" @@ -117,7 +134,7 @@ static void PopulateAreaFields(DEAFBABE& db, template void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataStream::ColMesh& colMesh) { - db.materials.reserve(colMesh.materials.size()); + db.materials.reserve(colMesh.materials.size() * 2); for (const hecl::BlenderConnection::DataStream::ColMesh::Material& mat : colMesh.materials) { db.materials.emplace_back(); @@ -164,7 +181,6 @@ void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataS db.materials.back().setSpiderBall(mat.spiderBall); db.materials.back().setScrewAttackWallJump(mat.screwAttackWallJump); } - db.materialCount = colMesh.materials.size(); zeus::CAABox fullAABB; @@ -193,7 +209,16 @@ void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataS db.triangleEdgeConnections.reserve(colMesh.trianges.size()); for (const auto& tri : colMesh.trianges) { - db.triMats.push_back(tri.matIdx); + if (tri.flip) + { + db.triMats.push_back(db.materials.size()); + db.materials.push_back(db.materials[tri.matIdx]); + db.materials.back().setFlipFace(true); + } + else + { + db.triMats.push_back(tri.matIdx); + } db.triangleEdgeConnections.emplace_back(); db.triangleEdgeConnections.back().edges[0] = tri.edges[0]; @@ -210,6 +235,8 @@ void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataS db.triMatsCount = colMesh.trianges.size(); db.triangleEdgesCount = colMesh.trianges.size() * 3; + db.materialCount = db.materials.size(); + PopulateAreaFields(db, colMesh, fullAABB); } diff --git a/DataSpec/DNAMP1/DeafBabe.hpp b/DataSpec/DNAMP1/DeafBabe.hpp index b7282d82c..0c7f299e9 100644 --- a/DataSpec/DNAMP1/DeafBabe.hpp +++ b/DataSpec/DNAMP1/DeafBabe.hpp @@ -16,7 +16,7 @@ struct DeafBabe : BigDNA struct Material : BigDNA { DECL_DNA - Value material; + Value material = 0; bool unknown() const { return material & 1; } void setUnknown(bool v) { material &= ~1; material |= int(v); } bool surfaceStone() const { return (material >> 1) & 1; } @@ -60,13 +60,15 @@ struct DeafBabe : BigDNA bool u20() const { return (material >> 20) & 1; } void setU20(bool v) { material &= ~(1ull << 20); material |= (v << 20); } bool cameraPassthrough() const { return (material >> 21) & 1; } - void setCameraPassthrough(bool v) { material &= ~(1ull << 21); material |= (v << 19); } + void setCameraPassthrough(bool v) { material &= ~(1ull << 21); material |= (v << 21); } bool surfaceWood() const { return (material >> 22) & 1; } void setSurfaceWood(bool v) { material &= ~(1ull << 22); material |= (v << 22); } bool surfaceOrganic() const { return (material >> 23) & 1; } void setSurfaceOrganic(bool v) { material &= ~(1ull << 23); material |= (v << 23); } bool u24() const { return (material >> 24) & 1; } void setU24(bool v) { material &= ~(1ull << 24); material |= (v << 24); } + bool flipFace() const { return (material >> 25) & 1; } + void setFlipFace(bool v) { material &= ~(1ull << 25); material |= (v << 25); } bool seeThrough() const { return (material >> 26) & 1; } void setSeeThrough(bool v) { material &= ~(1ull << 26); material |= (v << 26); } bool scanPassthrough() const { return (material >> 27) & 1; } @@ -109,14 +111,6 @@ struct DeafBabe : BigDNA { DECL_DNA Value verts[2]; - atUint16 findCommon(const Edge& other) const - { - if (verts[0] == other.verts[0] || verts[0] == other.verts[1]) - return verts[0]; - if (verts[1] == other.verts[0] || verts[1] == other.verts[1]) - return verts[1]; - return -1; - } }; struct Triangle : BigDNA diff --git a/DataSpec/DNAMP2/DeafBabe.hpp b/DataSpec/DNAMP2/DeafBabe.hpp index ad0a14070..42a7aee77 100644 --- a/DataSpec/DNAMP2/DeafBabe.hpp +++ b/DataSpec/DNAMP2/DeafBabe.hpp @@ -16,7 +16,7 @@ struct DeafBabe : BigDNA struct Material : BigDNA { DECL_DNA - Value material; + Value material = 0; bool unknown() const { return material & 1; } void setUnknown(bool v) { material &= ~1; material |= atUint64(v); } bool surfaceStone() const { return (material >> 1ull) & 1; } @@ -60,11 +60,13 @@ struct DeafBabe : BigDNA bool projectilePassthrough() const { return (material >> 20ull) & 1; } void setProjectilePassthrough(bool v) { material &= ~(1ull << 20ull); material |= (atUint64(v) << 20ull); } bool cameraPassthrough() const { return (material >> 21ull) & 1; } - void setCameraPassthrough(bool v) { material &= ~(1ull << 21ull); material |= (atUint64(v) << 19ull); } + void setCameraPassthrough(bool v) { material &= ~(1ull << 21ull); material |= (atUint64(v) << 21ull); } bool surfaceWood() const { return (material >> 22ull) & 1; } void setSurfaceWood(bool v) { material &= ~(1ull << 22ull); material |= (atUint64(v) << 22ull); } bool surfaceOrganic() const { return (material >> 23ull) & 1; } void setSurfaceOrganic(bool v) { material &= ~(1ull << 23ull); material |= (atUint64(v) << 23ull); } + bool flipFace() const { return (material >> 24ull) & 1; } + void setFlipFace(bool v) { material &= ~(1ull << 24ull); material |= (atUint64(v) << 24ull); } bool surfaceRubber() const { return (material >> 25) & 1; } void setSurfaceRubber(bool v) { material &= ~(1ull << 25ull); material |= (atUint64(v) << 25ull); } bool seeThrough() const { return (material >> 26ull) & 1; } diff --git a/Runtime/Collision/CCollisionSurface.cpp b/Runtime/Collision/CCollisionSurface.cpp index 44c516e53..ab5e4e4bf 100644 --- a/Runtime/Collision/CCollisionSurface.cpp +++ b/Runtime/Collision/CCollisionSurface.cpp @@ -12,8 +12,8 @@ CCollisionSurface::CCollisionSurface(const zeus::CVector3f& a, const zeus::CVect zeus::CVector3f CCollisionSurface::GetNormal() const { - zeus::CVector3f v1 = xc_b.cross(x0_a); - return zeus::CUnitVector3f({v1.y, v1.z, v1.x}, true); + zeus::CVector3f v1 = (xc_b - x0_a).cross(x18_c - x0_a); + return zeus::CUnitVector3f(v1, true); } zeus::CPlane CCollisionSurface::GetPlane() const diff --git a/Runtime/Collision/CMetroidAreaCollider.cpp b/Runtime/Collision/CMetroidAreaCollider.cpp index 62945c89a..12a3d27fb 100644 --- a/Runtime/Collision/CMetroidAreaCollider.cpp +++ b/Runtime/Collision/CMetroidAreaCollider.cpp @@ -653,7 +653,7 @@ bool CMetroidAreaCollider::SphereCollisionCheck(const CAreaOctTree& octTree, con bool CMetroidAreaCollider::MovingAABoxCollisionCheck_BoxVertexTri(const CCollisionSurface& surf, const zeus::CAABox& aabb, const rstl::reserved_vector& vertIndices, const zeus::CVector3f& dir, double& d, - zeus::CVector3f& normal, zeus::CVector3f& point) + zeus::CVector3f& normalOut, zeus::CVector3f& pointOut) { bool ret = false; for (u32 idx : vertIndices) @@ -661,8 +661,8 @@ bool CMetroidAreaCollider::MovingAABoxCollisionCheck_BoxVertexTri(const CCollisi zeus::CVector3f point = aabb.getPoint(idx); if (CollisionUtil::RayTriangleIntersection_Double(point, dir, surf.GetVerts(), d)) { - point = float(d) * dir + point; - normal = surf.GetNormal(); + pointOut = float(d) * dir + point; + normalOut = surf.GetNormal(); ret = true; } } diff --git a/Runtime/World/CActor.cpp b/Runtime/World/CActor.cpp index 269ac2885..c9aa46824 100644 --- a/Runtime/World/CActor.cpp +++ b/Runtime/World/CActor.cpp @@ -323,6 +323,7 @@ void CActor::SetRotation(const zeus::CQuaternion &q) void CActor::SetTranslation(const zeus::CVector3f& tr) { + auto old = x34_transform.origin; x34_transform.origin = tr; xe4_27_notInSortedLists = true; xe4_28_ = true; diff --git a/hecl b/hecl index f52faef9e..914545051 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit f52faef9e474889e23803d23b00f860e0da2cb99 +Subproject commit 914545051e9be680ea6bd85c0143f3fbd5f3ebf9