I’m a bit confused with the RectangleClipping class.
I know that sometimes it culls out faces that are still (partially) in the view.
I’m wondering why this is happening.
Let’s have a look at lite’s collectFaces method:
For the sake of simplicity, I’ve removed quadfaces code
arcane override function collectFaces(mesh:Mesh, faces:Vector.<Face>):void
{
_faces = mesh._faces;
_uvtData = mesh._uvtData;
_screenVertices = mesh._screenVertices;
_screenVerticesCull = new Vector.<int>();
_index = _screenVerticesCull.length = _screenVertices.length / 2;
_screenVerticesCull.fixed = true;
while (_index--) // for every screen vertex
{
_indexX = _index * 2;
_indexY = _indexX + 1;
_indexZ = _index * 3 + 2;
if (_uvtData[_indexZ] < 0) // check the t of uvt.
{
_screenVerticesCull[_index] += 0x10000; //add 16
}
else
{
if (_screenVertices[_indexX] < _minX)
_screenVerticesCull[_index] += 0x1000; //outside minX : add 8
else if (_screenVertices[_indexX] > _maxX)
_screenVerticesCull[_index] += 0x100; //outside maxX : add 4
if (_screenVertices[_indexY] < _minY)
_screenVerticesCull[_index] += 0x10; //outside minY : add 2
else if (_screenVertices[_indexY] > _maxY)
_screenVerticesCull[_index] += 0x1; //outside maxY : add 1
}
}
for each (_face in _faces) // for each face
{
if (mesh.bothsides || _screenVertices[_face.x0] * (_screenVertices[_face.y2] - _screenVertices[_face.y1]) + _screenVertices[_face.x1] * (_screenVertices[_face.y0] - _screenVertices[_face.y2]) + _screenVertices[_face.x2] * (_screenVertices[_face.y1] - _screenVertices[_face.y0]) > 0) // This is for checking whether we're viewing it from a visible side or not.
{
_cullCount = _screenVerticesCull[_face.i0] + _screenVerticesCull[_face.i1] + _screenVerticesCull[_face.i2]; //describes the face's situation with a number
if (!(_cullCount >> 16) && (_cullCount >> 12 & 15) < 3 && (_cullCount >> 8 & 15) < 3 && (_cullCount >> 4 & 15) < 3 && (_cullCount & 15) < 3)
faces[faces.length] = _face;
}
}
}
Could somebody explain to me why unwanted culling happens using RectangleClipping? Because it checks the position of every screen vertex, so it shouldn’t do this, right?
Many thanks in advance,
Declan