ANIM cook fix; OBB generation crash fix

This commit is contained in:
Jack Andersen 2018-06-15 16:26:58 -10:00
parent 513d9c99cd
commit 079c343557
5 changed files with 18 additions and 6 deletions

View File

@ -119,6 +119,10 @@ static FittedOBB FitOBB(const ColMesh& mesh, const std::vector<int>& index)
cyy += ( 9.0*mui.y*mui.y + p.y*p.y + q.y*q.y + r.y*r.y )*(Ai/12.0); cyy += ( 9.0*mui.y*mui.y + p.y*p.y + q.y*q.y + r.y*r.y )*(Ai/12.0);
cyz += ( 9.0*mui.y*mui.z + p.y*p.z + q.y*q.z + r.y*r.z )*(Ai/12.0); cyz += ( 9.0*mui.y*mui.z + p.y*p.z + q.y*q.z + r.y*r.z )*(Ai/12.0);
} }
if (zeus::close_enough(Am, 0.f))
return {};
// divide out the Am fraction from the average position and // divide out the Am fraction from the average position and
// covariance terms // covariance terms
mu = mu / Am; mu = mu / Am;
@ -131,7 +135,7 @@ static FittedOBB FitOBB(const ColMesh& mesh, const std::vector<int>& index)
// now build the covariance matrix // now build the covariance matrix
C(0,0)=cxx; C(0,1)=cxy; C(0,2)=cxz; C(0,0)=cxx; C(0,1)=cxy; C(0,2)=cxz;
C(1,0)=cxy; C(1,1)=cyy; C(1,2)=cyz; C(1,0)=cxy; C(1,1)=cyy; C(1,2)=cyz;
C(2,0)=cxz; C(1,2)=cyz; C(2,2)=czz; C(2,0)=cxz; C(2,1)=cyz; C(2,2)=czz;
// set the obb parameters from the covariance matrix // set the obb parameters from the covariance matrix
return BuildFromCovarianceMatrix(C, mesh, index); return BuildFromCovarianceMatrix(C, mesh, index);

View File

@ -649,10 +649,14 @@ ANIM::ANIM(const BlenderAction& act,
newAnim.chanKeys.emplace_back(); newAnim.chanKeys.emplace_back();
std::vector<DNAANIM::Value>& rotVals = newAnim.chanKeys.back(); std::vector<DNAANIM::Value>& rotVals = newAnim.chanKeys.back();
rotVals.reserve(chan.keys.size()); rotVals.reserve(chan.keys.size());
float sign = 0.f;
for (const BlenderAction::Channel::Key& key : chan.keys) for (const BlenderAction::Channel::Key& key : chan.keys)
{ {
zeus::CQuaternion q(key.rotation.val); zeus::CQuaternion q(key.rotation.val);
q = rig.restoreRotation(newChan.id, q); q = rig.restoreRotation(newChan.id, q);
if (sign == 0.f)
sign = q.w < 0.f ? -1.f : 1.f;
q *= sign;
rotVals.emplace_back(q.w, q.x, q.y, q.z); rotVals.emplace_back(q.w, q.x, q.y, q.z);
} }

View File

@ -59,9 +59,9 @@ void Buckets::Sort()
if (sPlaneObjectBucket->size()) if (sPlaneObjectBucket->size())
{ {
std::sort(sPlaneObjectBucket->begin(), sPlaneObjectBucket->end(), std::sort(sPlaneObjectBucket->begin(), sPlaneObjectBucket->end(),
[](u16 a, u16 b) -> bool [](u16 a, u16 b)
{ {
return (*sPlaneObjectData)[a].GetDistance() >= (*sPlaneObjectData)[b].GetDistance(); return (*sPlaneObjectData)[a].GetDistance() > (*sPlaneObjectData)[b].GetDistance();
}); });
precision = 50 / u32(sPlaneObjectBucket->size() + 1); precision = 50 / u32(sPlaneObjectBucket->size() + 1);
pitch = 1.f / (delta / float(precision - 2)); pitch = 1.f / (delta / float(precision - 2));
@ -128,8 +128,10 @@ void Buckets::Sort()
if (bucket.size()) if (bucket.size())
{ {
std::sort(bucket.begin(), bucket.end(), std::sort(bucket.begin(), bucket.end(),
[](CDrawable* a, CDrawable* b) -> bool [](CDrawable* a, CDrawable* b)
{ {
if (a->GetDistance() == b->GetDistance())
return a->GetExtraSort() > b->GetExtraSort();
return a->GetDistance() > b->GetDistance(); return a->GetDistance() > b->GetDistance();
}); });
} }
@ -747,7 +749,8 @@ void CBooRenderer::AddWorldSurfaces(CBooModel& model)
zeus::CAABox aabb = surf->GetBounds(); zeus::CAABox aabb = surf->GetBounds();
zeus::CVector3f pt = aabb.closestPointAlongVector(xb0_viewPlane.vec); zeus::CVector3f pt = aabb.closestPointAlongVector(xb0_viewPlane.vec);
Buckets::Insert(pt, aabb, EDrawableType::WorldSurface, surf, xb0_viewPlane, Buckets::Insert(pt, aabb, EDrawableType::WorldSurface, surf, xb0_viewPlane,
mat.heclIr.m_blendDst != boo::BlendFactor::Zero); mat.heclIr.m_blendSrc == boo::BlendFactor::SrcAlpha &&
mat.heclIr.m_blendDst == boo::BlendFactor::InvSrcAlpha);
surf = surf->m_next; surf = surf->m_next;
} }
} }

View File

@ -15,6 +15,7 @@ CScriptSpawnPoint::CScriptSpawnPoint(TUniqueId uid, std::string_view name, const
{ {
x64_itemCounts[int(CPlayerState::EItemType::ThermalVisor)] = 1; x64_itemCounts[int(CPlayerState::EItemType::ThermalVisor)] = 1;
x64_itemCounts[int(CPlayerState::EItemType::XRayVisor)] = 1; x64_itemCounts[int(CPlayerState::EItemType::XRayVisor)] = 1;
x64_itemCounts[int(CPlayerState::EItemType::GrappleBeam)] = 1;
x10c_24_firstSpawn = defaultSpawn; x10c_24_firstSpawn = defaultSpawn;
x10c_25_morphed = morphed; x10c_25_morphed = morphed;
} }

2
hecl

@ -1 +1 @@
Subproject commit d6e7abc61fb51a665bf954db03798c23e1ae5f57 Subproject commit a2d6ffa1dcea67585381a6993cdc1e083024877a