public void TestRecreationOfChildNodeAfterRemovalByReference() { Node node = new OctreeNode( this.fakeSceneManager ); Node childNode = node.CreateChild( Name ); node.RemoveChild( childNode ); node.CreateChild( Name ); }
public override SceneNode CreateSceneNode( string name ) { OctreeNode node = new OctreeNode( this, name ); sceneNodeList.Add( node ); return node; }
public override SceneNode CreateSceneNode() { OctreeNode node = new OctreeNode( this ); sceneNodeList.Add( node ); return node; }
public void Init( AxisAlignedBox box, int depth ) { rootSceneNode = new OctreeNode( this, "SceneRoot" ); rootSceneNode.SetAsRootNode(); defaultRootNode = rootSceneNode; maxDepth = depth; octree = new Octree( null ); octree.Box = box; Vector3 Min = box.Minimum; Vector3 Max = box.Maximum; octree.HalfSize = ( Max - Min ) / 2; numObjects = 0; Vector3 scalar = new Vector3( 1.5f, 1.5f, 1.5f ); scaleFactor.Scale = scalar; }
/// <summary> /// Removes the specified node and all of it's child subtree from the octree, but not from the scene graph. /// </summary> /// <remarks> /// This iterates the whole node tree starting from the specified node and removes them from octree partitions, /// but doesn't remove them from the scene graph. /// </remarks> /// <param name="child"></param> protected void RemoveNodesFromOctree( OctreeNode baseNode ) { foreach ( OctreeNode child in baseNode.Children ) { baseNode.RemoveNodesFromOctree( child ); } ( (OctreeSceneManager)baseNode.Creator ).RemoveOctreeNode( baseNode ); }
public override SceneNode CreateSceneNode(string name) { OctreeNode node = new OctreeNode(this, name); sceneNodeList[node.Name] = node; return node; }
public void RemoveNode(OctreeNode node) { node.Octant = null; NodeList.Remove(node); UnRef(); }
public void AddOctreeNode( OctreeNode node, Octree octant ) { AddOctreeNode( node, octant, 0 ); }
public void RemoveNode(OctreeNode node) { OctreeNode check; int i; int Index; Index = NodeList.Count - 1; for(i=Index;i>0;i--) { check = (OctreeNode)NodeList[i]; if(check == node) { node.Octant = null; NodeList.RemoveAt(i); UnRef(); } } }
public void AddNode(OctreeNode node) { // TODO: Att some points, some nodes seemed to be added if they already existed. Investigate. nodeList[node.Name] = node; node.Octant = this; Ref(); }
public void TestReaddingOfChildNodeAfterRemovalByName() { Node node = new OctreeNode( this.fakeSceneManager ); Node childNode = node.CreateChild( Name ); node.RemoveChild( Name ); node.AddChild( childNode ); }
public void AddOctreeNode(OctreeNode node, Octree octant, int depth) { AxisAlignedBox box = node.WorldAABB; //if the octree is twice as big as the scene node, //we will add it to a child. if ((depth < this.maxDepth) && octant.IsTwiceSize(box)) { int x, y, z; octant.GetChildIndexes(box, out x, out y, out z); if (octant.Children[x, y, z] == null) { octant.Children[x, y, z] = new Octree(octant); Vector3[] corners = octant.Box.Corners; Vector3 min, max; if (x == 0) { min.x = corners[0].x; max.x = (corners[0].x + corners[4].x) / 2; } else { min.x = (corners[0].x + corners[4].x) / 2; max.x = corners[4].x; } if (y == 0) { min.y = corners[0].y; max.y = (corners[0].y + corners[4].y) / 2; } else { min.y = (corners[0].y + corners[4].y) / 2; max.y = corners[4].y; } if (z == 0) { min.z = corners[0].z; max.z = (corners[0].z + corners[4].z) / 2; } else { min.z = (corners[0].z + corners[4].z) / 2; max.z = corners[4].z; } octant.Children[x, y, z].Box.SetExtents(min, max); octant.Children[x, y, z].HalfSize = (max - min) / 2; } AddOctreeNode(node, octant.Children[x, y, z], ++depth); } else { octant.AddNode(node); } }
/** Checks the given OctreeNode, and determines if it needs to be moved * to a different octant. */ public void UpdateOctreeNode( OctreeNode node ) { AxisAlignedBox box = node.WorldAABB; if ( box.IsNull ) { return; } if ( node.Octant == null ) { //if outside the octree, force into the root node. if ( !node.IsInBox( octree.Box ) ) { octree.AddNode( node ); } else { AddOctreeNode( node, octree ); } return; } if ( !node.IsInBox( node.Octant.Box ) ) { RemoveOctreeNode( node ); //if outside the octree, force into the root node. if ( !node.IsInBox( octree.Box ) ) { octree.AddNode( node ); } else { AddOctreeNode( node, octree ); } } }
/** Walks through the octree, adding any visible objects to the render queue. @remarks If any octant in the octree if completely within the the view frustum, all subchildren are automatically added with no visibility tests. */ public void WalkOctree(OctreeCamera camera, RenderQueue queue, Octree octant, VisibleObjectsBoundsInfo visibleBounds, bool onlyShadowCasters, bool foundVisible) { //return immediately if nothing is in the node. if(octant.NumNodes == 0) { return; } Visibility v = Visibility.None; if(foundVisible) { v = Visibility.Full; } else if(octant == octree) { v = Visibility.Partial; } else { AxisAlignedBox box = octant.CullBounds; v = camera.GetVisibility(box); } // if the octant is visible, or if it's the root node... if(v != Visibility.None) { if(this.ShowBoundingBoxes) { // TODO: Implement Octree.WireBoundingBox //boxList.Add(octant.WireBoundingBox); } bool vis = true; for(int i = 0; i < octant.NodeList.Count; i++) { OctreeNode node = (OctreeNode)octant.NodeList[i]; // if this octree is partially visible, manually cull all // scene nodes attached directly to this level. if(v == Visibility.Partial) { vis = camera.IsObjectVisible(node.WorldAABB); } if(vis) { numObjects++; node.AddToRenderQueue(camera, queue, onlyShadowCasters, visibleBounds); visible.Add(node); if(DisplayNodes) { GetRenderQueue().AddRenderable(node); } // check if the scene manager or this node wants the bounding box shown. if(node.ShowBoundingBox || this.ShowBoundingBoxes) { node.AddBoundingBoxToQueue(queue); } } } if(octant.Children[0,0,0] != null ) WalkOctree(camera, queue, octant.Children[0,0,0], visibleBounds, onlyShadowCasters, ( v == Visibility.Full ) ); if(octant.Children[1,0,0] != null ) WalkOctree(camera, queue, octant.Children[1,0,0], visibleBounds, onlyShadowCasters, ( v == Visibility.Full ) ); if(octant.Children[0,1,0] != null ) WalkOctree(camera, queue, octant.Children[0,1,0], visibleBounds, onlyShadowCasters, ( v == Visibility.Full ) ); if(octant.Children[1,1,0] != null ) WalkOctree(camera, queue, octant.Children[1,1,0], visibleBounds, onlyShadowCasters, ( v == Visibility.Full ) ); if(octant.Children[0,0,1] != null ) WalkOctree(camera, queue, octant.Children[0,0,1], visibleBounds, onlyShadowCasters, ( v == Visibility.Full ) ); if(octant.Children[1,0,1] != null ) WalkOctree(camera, queue, octant.Children[1,0,1], visibleBounds, onlyShadowCasters, ( v == Visibility.Full ) ); if(octant.Children[0,1,1] != null ) WalkOctree(camera, queue, octant.Children[0,1,1], visibleBounds, onlyShadowCasters, ( v == Visibility.Full ) ); if(octant.Children[1,1,1] != null ) WalkOctree(camera, queue, octant.Children[1,1,1], visibleBounds, onlyShadowCasters, ( v == Visibility.Full ) ); } }
/*public void RemoveOctreeNode(OctreeNode node, Octree tree, int depth) { }*/ /** Only removes the node from the octree. It leaves the octree, even if it's empty. */ public void RemoveOctreeNode( OctreeNode node ) { Octree tree = node.Octant; if ( tree != null ) { tree.RemoveNode( node ); } }
public void AddOctreeNode(OctreeNode node, Octree octant) { AddOctreeNode(node, octant, 0); }
public void AddOctreeNode( OctreeNode node, Octree octant, int depth ) { AxisAlignedBox box = node.WorldAABB; //if the octree is twice as big as the scene node, //we will add it to a child. if ( ( depth < maxDepth ) && octant.IsTwiceSize( box ) ) { int x, y, z; octant.GetChildIndexes( box, out x, out y, out z ); if ( octant.Children[ x, y, z ] == null ) { octant.Children[ x, y, z ] = new Octree( octant ); Vector3[] corners = octant.Box.Corners; Vector3 min, max; if ( x == 0 ) { min.x = corners[ 0 ].x; max.x = ( corners[ 0 ].x + corners[ 4 ].x ) / 2; } else { min.x = ( corners[ 0 ].x + corners[ 4 ].x ) / 2; max.x = corners[ 4 ].x; } if ( y == 0 ) { min.y = corners[ 0 ].y; max.y = ( corners[ 0 ].y + corners[ 4 ].y ) / 2; } else { min.y = ( corners[ 0 ].y + corners[ 4 ].y ) / 2; max.y = corners[ 4 ].y; } if ( z == 0 ) { min.z = corners[ 0 ].z; max.z = ( corners[ 0 ].z + corners[ 4 ].z ) / 2; } else { min.z = ( corners[ 0 ].z + corners[ 4 ].z ) / 2; max.z = corners[ 4 ].z; } octant.Children[ x, y, z ].Box.SetExtents( min, max ); octant.Children[ x, y, z ].HalfSize = ( max - min ) / 2; } AddOctreeNode( node, octant.Children[ x, y, z ], ++depth ); } else { octant.AddNode( node ); } }
public void RemoveNode( OctreeNode node ) { node.Octant = null; NodeList.Remove( node ); UnRef(); }