/// <summary> /// Clear out every scene node from this scene graph. /// </summary> public void Clear() { _rootNode.ClearChildren(); _rootNode = new SceneNode("Root"); _cameraList.Clear(); }
/// <summary> /// Loads the scene graph from a given binary reader. /// </summary> /// <param name="stream">Binary reader to load this scene graph from.</param> /// <param name="baseNode">The base node that all loading should be started from, this allows you to ignore this node and any nodes higher in the graph like the Root Camera.</param> /// <param name="keepPersistent">If set to true persistent ob jects will be kept.</param> /// <param name="keepCameras">If set to true all cameras will not be destroyed.</param> public void Load(BinaryReader reader, bool keepPersistent, bool keepCameras, SceneNode baseNode) { // Dispose of all old entities. // Lets compile a list of all peristent nodes if we are keeping them. ArrayList persistentList = new ArrayList(); if (keepPersistent == true) { ArrayList entityList = new ArrayList(_nodeList); foreach (SceneNode node in entityList) { if (node.IsPersistent == true) { persistentList.Add(node); } else { node.Dispose(); } } entityList.Clear(); entityList = null; } // Get starting memory. long startingMemory = GC.GetTotalMemory(true); // Clear out any non-persistent cameras. if (keepCameras == false) { ArrayList removalList = new ArrayList(); foreach (CameraNode camera in _cameraList) { if (camera.IsPersistent == false) { removalList.Add(camera); } } foreach (CameraNode camera in removalList) { _cameraList.Remove(camera); } } // Reset unique ID counter. _uniqueIDTracker = 0; // Clean out base node. if (baseNode != null) { baseNode.ClearChildren(); } else { _rootNode.ClearChildren(); } bool baseNodeExists = reader.ReadBoolean(); if (baseNodeExists == true) { int childCount = reader.ReadInt32(); for (int i = 0; i < childCount; i++) { if (baseNode != null) { baseNode.AddChild(LoadNode(reader)); } else { _rootNode.AddChild(LoadNode(reader)); } } } else { _rootNode = LoadNode(reader, true); } // Lets see if we can reattached any persistent nodes, if not lets just // tack them onto the root node. if (keepPersistent == true) { foreach (SceneNode node in persistentList) { if (node.Parent == null || node.Parent.IsPersistent == false) { (baseNode == null ? _rootNode : baseNode).AddChild(node); } } } // Say how many have been created. DebugLogger.WriteLog("Loaded " + _uniqueIDTracker + " nodes into scene graph, with a cumulative memory allocation of " + (((GC.GetTotalMemory(true) - startingMemory) / 1024.0f) / 1024.0f) + "mb."); // Go through each node and grab its properties SyncronizeNodes(); // Reset loading percentage. _loadingProgress = 0; }
/// <summary> /// Loads the scene graph from a given binary reader. /// </summary> /// <param name="stream">Binary reader to load this scene graph from.</param> /// <param name="baseNode">The base node that all loading should be started from, this allows you to ignore this node and any nodes higher in the graph like the Root Camera.</param> /// <param name="keepPersistent">If set to true persistent ob jects will be kept.</param> /// <param name="keepCameras">If set to true all cameras will not be destroyed.</param> public void Load(BinaryReader reader, bool keepPersistent, bool keepCameras, SceneNode baseNode) { // Dispose of all old entities. // Lets compile a list of all peristent nodes if we are keeping them. ArrayList persistentList = new ArrayList(); if (keepPersistent == true) { ArrayList entityList = new ArrayList(_nodeList); foreach (SceneNode node in entityList) if (node.IsPersistent == true) persistentList.Add(node); else node.Dispose(); entityList.Clear(); entityList = null; } // Get starting memory. long startingMemory = GC.GetTotalMemory(true); // Clear out any non-persistent cameras. if (keepCameras == false) { ArrayList removalList = new ArrayList(); foreach (CameraNode camera in _cameraList) if (camera.IsPersistent == false) removalList.Add(camera); foreach (CameraNode camera in removalList) _cameraList.Remove(camera); } // Reset unique ID counter. _uniqueIDTracker = 0; // Clean out base node. if (baseNode != null) baseNode.ClearChildren(); else _rootNode.ClearChildren(); bool baseNodeExists = reader.ReadBoolean(); if (baseNodeExists == true) { int childCount = reader.ReadInt32(); for(int i = 0; i < childCount; i++) { if (baseNode != null) baseNode.AddChild(LoadNode(reader)); else _rootNode.AddChild(LoadNode(reader)); } } else _rootNode = LoadNode(reader, true); // Lets see if we can reattached any persistent nodes, if not lets just // tack them onto the root node. if (keepPersistent == true) { foreach (SceneNode node in persistentList) { if (node.Parent == null || node.Parent.IsPersistent == false) (baseNode == null ? _rootNode : baseNode).AddChild(node); } } // Say how many have been created. DebugLogger.WriteLog("Loaded " + _uniqueIDTracker + " nodes into scene graph, with a cumulative memory allocation of " + (((GC.GetTotalMemory(true) - startingMemory) / 1024.0f) / 1024.0f) + "mb."); // Go through each node and grab its properties SyncronizeNodes(); // Reset loading percentage. _loadingProgress = 0; }