/// <summary> /// Render 3D scene /// </summary> /// <param name="tree">BSP tree</param> /// <param name="camera">Camera</param> /// <param name="frustum">View frustum</param> /// <param name="depthPlanes">Depth planes</param> private void Render3D(BSPTree tree, IList <IBSPItem> items, Point3D cameraPos, Matrix3D displayMatrix, Frustum frustum, DepthPlanes depthPlanes) { bool clipFade = ClipFade; bool showCubes = ShowCubes; bool limitDepth = LimitDepth; MeshGeometry3D thumbnailMesh = new MeshGeometry3D(); MeshGeometry3D mesh = new MeshGeometry3D(); //MeshGeometry3D flatMesh = new MeshGeometry3D(); // List<BSPCube> renderItems = new List<BSPCube>(); foreach (BSPCube cube in items) { ContainmentType type = frustum.Contains(cube.Bounds); if (type != ContainmentType.Disjoint && (clipFade || type != ContainmentType.Intersects) && (!limitDepth || depthPlanes.Includes(cube.Position))) { double alpha = (type == ContainmentType.Intersects) ? 0.2 : 1.0; if (!string.IsNullOrEmpty(cube.Url) || EmptyImages) { cube.RenderThumbnail(thumbnailMesh, cameraPos, alpha, displayMatrix, thumbnails); } if (showCubes) { cube.Render(mesh, cameraPos, alpha); } //cube.RenderFlat( flatMesh, cameraPos, displayMatrix, new Rect( 0, 0, 0.5, 1 ) ); } } geometry.Geometry = mesh; thumbnailGeometry.Geometry = thumbnailMesh; //flatGeometry.Geometry = flatMesh; }
/* /// <summary> * /// Render 2D scene * /// </summary> * /// <param name="tree">BSP tree</param> * /// <param name="camera">Camera</param> * /// <param name="frustum">View frustum</param> * /// <param name="depthPlanes">Depth planes</param> * private void Render2D( BSPTree tree, IList<IBSPItem> items, Point3D cameraPos, Matrix3D displayMatrix, Frustum frustum, DepthPlanes depthPlanes ) * { * int index = 0; * bool clipFade = ClipFade; * * foreach ( BSPCube cube in items ) * { * ContainmentType type = frustum.Contains( cube.Bounds ); * * if ( type != ContainmentType.Disjoint * && ( clipFade || type != ContainmentType.Intersects ) * && depthPlanes.Includes( cube.Position ) ) * { * Sphere sphere; * * if ( index < canvas.Children.Count ) sphere = canvas.Children[ index ] as Sphere; * else canvas.Children.Add( sphere = new Sphere() ); * * sphere.Visibility = Visibility.Visible; * sphere.RenderTransform = new MatrixTransform( cube.SphereMatrix( cameraPos, displayMatrix ) ); * sphere.Brush = ( cube.MaterialOffset >= 0.5 ) ? SphereBrush : SelectedSphereBrush; * sphere.Opacity = Math.Abs( 0.5 - cube.MaterialOffset ) * 2; * * if ( type == ContainmentType.Intersects ) sphere.Opacity *= 0.2; * ++index; * } * } * * while ( index < canvas.Children.Count ) canvas.Children[ index++ ].Visibility = Visibility.Hidden; * } */ /// <summary> /// Recursively render tree /// </summary> /// <param name="tree">Tree node</param> private void RenderTree(BSPTree tree, IList <IBSPItem> items, Point3D cameraPos, Frustum frustum, DepthPlanes depthPlanes) { bool limitDepth = LimitDepth; if (tree != null && frustum.Contains(tree.Bounds) != ContainmentType.Disjoint && (!limitDepth || depthPlanes.Includes(tree.Bounds))) { Halfspace halfspace = tree.Partition.Classify(cameraPos); if (halfspace == Halfspace.Negative) { if (tree.Front != null) { RenderTree(tree.Front, items, cameraPos, frustum, depthPlanes); } } else if (tree.Back != null) { RenderTree(tree.Back, items, cameraPos, frustum, depthPlanes); } foreach (IBSPItem item in tree.Items) { items.Add(item); } if (halfspace == Halfspace.Negative) { if (tree.Back != null) { RenderTree(tree.Back, items, cameraPos, frustum, depthPlanes); } } else if (tree.Front != null) { RenderTree(tree.Front, items, cameraPos, frustum, depthPlanes); } } }
/* /// <summary> /// Render 2D scene /// </summary> /// <param name="tree">BSP tree</param> /// <param name="camera">Camera</param> /// <param name="frustum">View frustum</param> /// <param name="depthPlanes">Depth planes</param> private void Render2D( BSPTree tree, IList<IBSPItem> items, Point3D cameraPos, Matrix3D displayMatrix, Frustum frustum, DepthPlanes depthPlanes ) { int index = 0; bool clipFade = ClipFade; foreach ( BSPCube cube in items ) { ContainmentType type = frustum.Contains( cube.Bounds ); if ( type != ContainmentType.Disjoint && ( clipFade || type != ContainmentType.Intersects ) && depthPlanes.Includes( cube.Position ) ) { Sphere sphere; if ( index < canvas.Children.Count ) sphere = canvas.Children[ index ] as Sphere; else canvas.Children.Add( sphere = new Sphere() ); sphere.Visibility = Visibility.Visible; sphere.RenderTransform = new MatrixTransform( cube.SphereMatrix( cameraPos, displayMatrix ) ); sphere.Brush = ( cube.MaterialOffset >= 0.5 ) ? SphereBrush : SelectedSphereBrush; sphere.Opacity = Math.Abs( 0.5 - cube.MaterialOffset ) * 2; if ( type == ContainmentType.Intersects ) sphere.Opacity *= 0.2; ++index; } } while ( index < canvas.Children.Count ) canvas.Children[ index++ ].Visibility = Visibility.Hidden; } */ /// <summary> /// Recursively render tree /// </summary> /// <param name="tree">Tree node</param> private void RenderTree( BSPTree tree, IList<IBSPItem> items, Point3D cameraPos, Frustum frustum, DepthPlanes depthPlanes ) { bool limitDepth = LimitDepth; if ( tree != null && frustum.Contains( tree.Bounds ) != ContainmentType.Disjoint && ( !limitDepth || depthPlanes.Includes( tree.Bounds ) ) ) { Halfspace halfspace = tree.Partition.Classify( cameraPos ); if ( halfspace == Halfspace.Negative ) { if ( tree.Front != null ) RenderTree( tree.Front, items, cameraPos, frustum, depthPlanes ); } else if ( tree.Back != null ) RenderTree( tree.Back, items, cameraPos, frustum, depthPlanes ); foreach ( IBSPItem item in tree.Items ) items.Add( item ); if ( halfspace == Halfspace.Negative ) { if ( tree.Back != null ) RenderTree( tree.Back, items, cameraPos, frustum, depthPlanes ); } else if ( tree.Front != null ) RenderTree( tree.Front, items, cameraPos, frustum, depthPlanes ); } }
/// <summary> /// Render 3D scene /// </summary> /// <param name="tree">BSP tree</param> /// <param name="camera">Camera</param> /// <param name="frustum">View frustum</param> /// <param name="depthPlanes">Depth planes</param> private void Render3D( BSPTree tree, IList<IBSPItem> items, Point3D cameraPos, Matrix3D displayMatrix, Frustum frustum, DepthPlanes depthPlanes ) { bool clipFade = ClipFade; bool showCubes = ShowCubes; bool limitDepth = LimitDepth; MeshGeometry3D thumbnailMesh = new MeshGeometry3D(); MeshGeometry3D mesh = new MeshGeometry3D(); //MeshGeometry3D flatMesh = new MeshGeometry3D(); // List<BSPCube> renderItems = new List<BSPCube>(); foreach ( BSPCube cube in items ) { ContainmentType type = frustum.Contains( cube.Bounds ); if ( type != ContainmentType.Disjoint && ( clipFade || type != ContainmentType.Intersects ) && ( !limitDepth || depthPlanes.Includes( cube.Position ) ) ) { double alpha = ( type == ContainmentType.Intersects ) ? 0.2 : 1.0; if ( !string.IsNullOrEmpty( cube.Url ) || EmptyImages ) { cube.RenderThumbnail( thumbnailMesh, cameraPos, alpha, displayMatrix, thumbnails ); } if ( showCubes ) cube.Render( mesh, cameraPos, alpha ); //cube.RenderFlat( flatMesh, cameraPos, displayMatrix, new Rect( 0, 0, 0.5, 1 ) ); } } geometry.Geometry = mesh; thumbnailGeometry.Geometry = thumbnailMesh; //flatGeometry.Geometry = flatMesh; }