protected void ProcessVisibleLeaf( BspNode leaf, Camera camera, bool onlyShadowCasters )
{
// Skip world geometry if we're only supposed to process shadow casters
// World is pre-lit
if ( !onlyShadowCasters )
{
// Parse the leaf node's faces, add face groups to material map
int numGroups = leaf.NumFaceGroups;
int idx = leaf.FaceGroupStart;
while ( numGroups-- > 0 )
{
int realIndex = level.LeafFaceGroups[ idx++ ];
// Is it already checked ?
if ( faceGroupChecked.ContainsKey( realIndex ) && faceGroupChecked[ realIndex ] == true )
continue;
faceGroupChecked[ realIndex ] = true;
BspStaticFaceGroup faceGroup = level.FaceGroups[ realIndex ];
// Get Material reference by handle
Material mat = GetMaterial( faceGroup.materialHandle );
// Check normal (manual culling)
ManualCullingMode cullMode = mat.GetTechnique( 0 ).GetPass( 0 ).ManualCullingMode;
if ( cullMode != ManualCullingMode.None )
{
float dist = faceGroup.plane.GetDistance( camera.DerivedPosition );
if ( ( ( dist < 0 ) && ( cullMode == ManualCullingMode.Back ) ) ||
( ( dist > 0 ) && ( cullMode == ManualCullingMode.Front ) ) )
continue;
}
// Try to insert, will find existing if already there
matFaceGroupMap.Add( mat, faceGroup );
}
}
// Add movables to render queue, provided it hasn't been seen already.
foreach ( MovableObject obj in leaf.Objects.Values )
{
if ( !objectsForRendering.ContainsKey( obj.Name ) )
{
if ( obj.IsVisible &&
( !onlyShadowCasters || obj.CastShadows ) &&
camera.IsObjectVisible( obj.GetWorldBoundingBox() ) )
{
obj.NotifyCurrentCamera( camera );
obj.UpdateRenderQueue( this.renderQueue );
// Check if the bounding box should be shown.
SceneNode node = (SceneNode)obj.ParentNode;
if ( node.ShowBoundingBox || this.showBoundingBoxes )
{
node.AddBoundingBoxToQueue( this.renderQueue );
}
objectsForRendering.Add( obj );
}
}
}
}