Ymap frustum culling

This commit is contained in:
dexy 2019-03-23 22:23:37 +11:00
parent a434d9ad55
commit bd283a5c07
2 changed files with 38 additions and 0 deletions

View File

@ -334,5 +334,20 @@ namespace CodeWalker.World
}
return true;
}
public bool ContainsAABBNoClipNoOpt(ref Vector3 bmin, ref Vector3 bmax)
{
var c = (bmax + bmin) * 0.5f - Position;
var e = (bmax - bmin) * 0.5f;
for (int i = 0; i < 5; i++)
{
var pd = Planes[i].D;
var pn = Planes[i].Normal;
var d = (c.X * pn.X) + (c.Y * pn.Y) + (c.Z * pn.Z);
var r = (e.X * (pn.X > 0 ? pn.X : -pn.X)) + (e.Y * (pn.Y > 0 ? pn.Y : -pn.Y)) + (e.Z * (pn.Z > 0 ? pn.Z : -pn.Z));
if ((d + r) < -pd) return false;
//if ((d - r) < -pd) ; //intersecting
}
return true;
}
}
}

View File

@ -1672,6 +1672,16 @@ namespace CodeWalker.Rendering
return false;
}
if (!ymap.HasChanged)//don't cull edited project ymaps, because extents may not have been updated!
{
var eemin = ymap._CMapData.entitiesExtentsMin;
var eemax = ymap._CMapData.entitiesExtentsMax;
if (!camera.ViewFrustum.ContainsAABBNoClipNoOpt(ref eemin, ref eemax))
{
return false;
}
}
return true;
}
private void RenderWorldCalcEntityVisibility(YmapEntityDef ent)
@ -2522,6 +2532,19 @@ namespace CodeWalker.Rendering
{
RenderCollisionMesh(sdrawable.Bound, entity);
}
//FragDrawable fdrawable = rndbl.Key as FragDrawable;
//if (fdrawable != null)
//{
// if (fdrawable.Bound != null)
// {
// RenderCollisionMesh(fdrawable.Bound, entity);
// }
// var fbound = fdrawable.OwnerFragment?.PhysicsLODGroup?.PhysicsLOD1?.Bound;
// if (fbound != null)
// {
// RenderCollisionMesh(fbound, entity);
// }
//}
}
if (renderskeletons && rndbl.HasSkeleton)
{