public bool DeleteFrame(FrameEntry EntryToDelete) { // Early return out if its invalid if (EntryToDelete == null) { return(false); } // Remove Parent reference FrameObjectBase BaseObject = (EntryToDelete as FrameObjectBase); if (BaseObject != null) { FrameObjectBase ParentObject = BaseObject.Parent; if (ParentObject != null) { bool bDeleted = ParentObject.Children.Remove(BaseObject); Debug.Assert(bDeleted, "Failed to delete an object which should be in the child array."); BaseObject.Parent = null; } } return(FrameObjects.Remove(EntryToDelete.RefID)); }
public FrameEntry(FrameEntry entry) { refID = StringHelpers.RandomGenerator.Next(); refs = new Dictionary <string, int>(); for (int i = 0; i != entry.refs.Count; i++) { refs.Add(entry.refs.ElementAt(i).Key, entry.refs.ElementAt(i).Value); } }
public FrameEntry(FrameEntry entry) { refID = StringHelpers.GetNewRefID(); refs = new Dictionary <FrameEntryRefTypes, int>(); for (int i = 0; i < entry.refs.Count; i++) { refs.Add(entry.refs.ElementAt(i).Key, entry.refs.ElementAt(i).Value); } }
public void SetParentOfObject(int parentId, FrameEntry childEntry, FrameEntry parentEntry) { //get the index and child object FrameObjectBase obj = (childEntry as FrameObjectBase); //fix any parent-children relationships. if (obj.Parent != null) { obj.Parent.Children.Remove(obj); obj.Parent = null; } if (parentEntry != null) //this is if the user wants to change parent { int index = (parentEntry is FrameHeaderScene) ? frameScenes.IndexOfValue(parentEntry.RefID) : GetIndexOfObject(parentEntry.RefID); FrameObjectBase parentObj = (parentEntry as FrameObjectBase); //fix any parent relationships only if ParentObj is not null. if (parentObj != null) { parentObj.Children.Add(obj); obj.Parent = parentObj; } //set parent indexes. if (parentId == 0) { obj.ParentIndex1.SetParent(index, parentEntry); obj.ReplaceRef(FrameEntryRefTypes.Parent1, parentEntry.RefID); } else if (parentId == 1) { obj.ParentIndex2.SetParent(index, parentEntry); obj.ReplaceRef(FrameEntryRefTypes.Parent2, parentEntry.RefID); } } else //this is if the user wants to remove the parent relationship, therefore -1 = root. { if (parentId == 0) { obj.ParentIndex1.SetParent(-1, "root", 0); obj.SubRef(FrameEntryRefTypes.Parent1); } else if (parentId == 1) { obj.ParentIndex2.SetParent(-1, "root", 0); obj.SubRef(FrameEntryRefTypes.Parent2); } } foreach (var pair in frameObjects) { (pair.Value as FrameObjectBase).SetWorldTransform(); } }
public TreeNode BuildTree(FrameNameTable.FrameNameTable table) { TreeNode root = new TreeNode("FrameResource Contents"); root.Tag = header; int numBlocks = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies; Dictionary <int, TreeNode> parsedNodes = new Dictionary <int, TreeNode>(); Dictionary <int, TreeNode> notAddedNodes = new Dictionary <int, TreeNode>(); //Add scene groups into the scene viewer. for (int i = 0; i != frameScenes.Count; i++) { FrameHeaderScene scene = frameScenes.Values.ElementAt(i); TreeNode node = new TreeNode(scene.ToString()); node.Tag = scene; node.Name = scene.RefID.ToString(); parsedNodes.Add(i, node); root.Nodes.Add(node); } ////add entries from the table, add table data and then add to scene viewer. for (int i = 0; i != table.FrameData.Length; i++) { if (table.FrameData[i].FrameIndex == -1) { continue; } var frameData = table.FrameData[i]; FrameObjectBase fObject = (GetEntryFromIdx(numBlocks + frameData.FrameIndex).Data as FrameObjectBase); fObject.IsOnFrameTable = true; fObject.FrameNameTableFlags = table.FrameData[i].Flags; int p1idx = numBlocks + fObject.ParentIndex1.Index; int p2idx = numBlocks + fObject.ParentIndex2.Index; int thisKey = numBlocks + table.FrameData[i].FrameIndex; TreeNode node = (!parsedNodes.ContainsKey(thisKey)) ? new TreeNode(fObject.ToString()) : parsedNodes[thisKey]; node.Tag = fObject; node.Name = fObject.RefID.ToString(); if (p1idx == -1 && p2idx == -1) { //might be temp? it fixes cars loading in or non binded entries. root.Nodes.Add(node); continue; } else { FrameEntry pBase = (GetEntryFromIdx(p2idx).Data as FrameEntry); TreeNode[] nodes = root.Nodes.Find(pBase.RefID.ToString(), true); if (nodes.Length > 0) { nodes[0].Nodes.Add(node); } } if (!parsedNodes.ContainsKey(thisKey)) { parsedNodes.Add(thisKey, node); } } foreach (FrameHolder holder in NewFrames) { FrameObjectBase fObject = holder.Data as FrameObjectBase; if (fObject == null) { continue; } TreeNode node = (!parsedNodes.ContainsKey(holder.Idx)) ? new TreeNode(fObject.ToString()) : parsedNodes[holder.Idx]; node.Tag = fObject; node.Name = fObject.RefID.ToString(); if (!parsedNodes.ContainsKey(holder.Idx)) { parsedNodes.Add(holder.Idx, node); } } foreach (FrameHolder holder in NewFrames) { FrameObjectBase fObject = holder.Data as FrameObjectBase; if (fObject == null) { continue; } if (fObject.ParentIndex1.Index != -1) { parsedNodes[fObject.ParentIndex1.Index].Nodes.Add(parsedNodes[holder.Idx]); } else if (fObject.ParentIndex2.Index != -1) { parsedNodes[fObject.ParentIndex2.Index].Nodes.Add(parsedNodes[holder.Idx]); } else if (fObject.ParentIndex1.Index == -1 && fObject.ParentIndex2.Index == -1) { root.Nodes.Add(parsedNodes[holder.Idx]); } else { Debug.WriteLine("Not added {0}", holder.Data); } } return(root); }
public void WriteToFile(BinaryWriter writer) { //BEFORE WE WRITE, WE NEED TO COMPILE AND UPDATE THE FRAME. UpdateFrameData(); header.WriteToFile(writer); int totalBlockCount = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies; int currentIdx = header.SceneFolders.Count; for (; currentIdx != header.SceneFolders.Count + header.NumGeometries; currentIdx++) { (NewFrames[currentIdx].Data as FrameGeometry).WriteToFile(writer); } for (; currentIdx != header.SceneFolders.Count + header.NumGeometries + header.NumMaterialResources; currentIdx++) { (NewFrames[currentIdx].Data as FrameMaterial).WriteToFile(writer); } for (; currentIdx != header.SceneFolders.Count + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos; currentIdx++) { (NewFrames[currentIdx].Data as FrameBlendInfo).WriteToFile(writer); } for (; currentIdx != header.SceneFolders.Count + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons; currentIdx++) { (NewFrames[currentIdx].Data as FrameSkeleton).WriteToFile(writer); } for (; currentIdx != header.SceneFolders.Count + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies; currentIdx++) { (NewFrames[currentIdx].Data as FrameSkeletonHierachy).WriteToFile(writer); } int savedIdx = currentIdx; for (; savedIdx != header.SceneFolders.Count + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies + header.NumObjects; savedIdx++) { FrameEntry entry = NewFrames[savedIdx].Data; if (entry.GetType() == typeof(FrameObjectJoint)) { writer.Write((int)ObjectType.Joint); } else if (entry.GetType() == typeof(FrameObjectSingleMesh)) { writer.Write((int)ObjectType.SingleMesh); } else if (entry.GetType() == typeof(FrameObjectFrame)) { writer.Write((int)ObjectType.Frame); } else if (entry.GetType() == typeof(FrameObjectLight)) { writer.Write((int)ObjectType.Light); } else if (entry.GetType() == typeof(FrameObjectCamera)) { writer.Write((int)ObjectType.Camera); } else if (entry.GetType() == typeof(FrameObjectComponent_U005)) { writer.Write((int)ObjectType.Component_U00000005); } else if (entry.GetType() == typeof(FrameObjectSector)) { writer.Write((int)ObjectType.Sector); } else if (entry.GetType() == typeof(FrameObjectDummy)) { writer.Write((int)ObjectType.Dummy); } else if (entry.GetType() == typeof(FrameObjectDeflector)) { writer.Write((int)ObjectType.ParticleDeflector); } else if (entry.GetType() == typeof(FrameObjectArea)) { writer.Write((int)ObjectType.Area); } else if (entry.GetType() == typeof(FrameObjectTarget)) { writer.Write((int)ObjectType.Target); } else if (entry.GetType() == typeof(FrameObjectModel)) { writer.Write((int)ObjectType.Model); } else if (entry.GetType() == typeof(FrameObjectCollision)) { writer.Write((int)ObjectType.Collision); } } savedIdx = currentIdx; for (; savedIdx != header.SceneFolders.Count + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies + header.NumObjects; savedIdx++) { FrameEntry entry = NewFrames[savedIdx].Data; if (entry.GetType() == typeof(FrameObjectJoint)) { (entry as FrameObjectJoint).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectSingleMesh)) { (entry as FrameObjectSingleMesh).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectFrame)) { (entry as FrameObjectFrame).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectLight)) { (entry as FrameObjectLight).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectCamera)) { (entry as FrameObjectCamera).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectComponent_U005)) { (entry as FrameObjectComponent_U005).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectSector)) { (entry as FrameObjectSector).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectDummy)) { (entry as FrameObjectDummy).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectDeflector)) { (entry as FrameObjectDeflector).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectArea)) { (entry as FrameObjectArea).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectTarget)) { (entry as FrameObjectTarget).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectModel)) { (entry as FrameObjectModel).WriteToFile(writer); } else if (entry.GetType() == typeof(FrameObjectCollision)) { (entry as FrameObjectCollision).WriteToFile(writer); } } }
public FrameHolder(int idx, FrameEntry data) { Idx = idx; Data = data; }