Add triangle flip bit for collision geometry

This commit is contained in:
Jack Andersen 2017-12-08 19:17:51 -10:00
parent 0c1d0b5ce3
commit 5e03278eff
7 changed files with 48 additions and 24 deletions

View File

@ -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<class DEAFBABE>
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);
}

View File

@ -16,7 +16,7 @@ struct DeafBabe : BigDNA
struct Material : BigDNA
{
DECL_DNA
Value<atUint32> material;
Value<atUint32> 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<atUint16> 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

View File

@ -16,7 +16,7 @@ struct DeafBabe : BigDNA
struct Material : BigDNA
{
DECL_DNA
Value<atUint64> material;
Value<atUint64> 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; }

View File

@ -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

View File

@ -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<u32, 8>& 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;
}
}

View File

@ -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;

2
hecl

@ -1 +1 @@
Subproject commit f52faef9e474889e23803d23b00f860e0da2cb99
Subproject commit 914545051e9be680ea6bd85c0143f3fbd5f3ebf9