/// <summary> /// Read data from file. /// </summary> /// <param name="reader"></param> public void ReadFromFile(MemoryStream reader, bool isBigEndian) { isScene = reader.ReadBoolean(); numFolderNames = reader.ReadInt32(isBigEndian); numGeometries = reader.ReadInt32(isBigEndian); numMaterialResources = reader.ReadInt32(isBigEndian); numBlendInfos = reader.ReadInt32(isBigEndian); numSkeletons = reader.ReadInt32(isBigEndian); numSkelHierachies = reader.ReadInt32(isBigEndian); numObjects = reader.ReadInt32(isBigEndian); if (isScene) { unk1 = reader.ReadSingle(isBigEndian); unk2 = reader.ReadSingle(isBigEndian); sceneName = new HashName(reader, isBigEndian); for (int i = 0; i < (4 * 3); i++) { unkData[i] = reader.ReadSingle(isBigEndian); } unk3 = reader.ReadBoolean(); } for (int i = 0; i != numFolderNames; i++) { FrameHeaderScene scene = new FrameHeaderScene(); scene.ReadFromFile(reader, isBigEndian); sceneFolders.Add(scene); } }
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(scene.RefID, node); root.Nodes.Add(node); AddChildren(parsedNodes, scene.Children, node); } foreach (var pair in frameObjects) { FrameObjectBase frame = (pair.Value as FrameObjectBase); TreeNode node; if (parsedNodes.ContainsKey(pair.Key)) { continue; } if (frame.ParentIndex1.Index == -1 && frame.ParentIndex2.Index == -1) { node = new TreeNode(frame.ToString()); node.Tag = frame; node.Name = frame.RefID.ToString(); root.Nodes.Add(node); parsedNodes.Add(frame.RefID, node); AddChildren(parsedNodes, frame.Children, node); } } foreach (var pair in frameObjects) { if (!parsedNodes.ContainsKey(pair.Key)) { FrameObjectBase frame = (pair.Value as FrameObjectBase); Debug.WriteLine("Failed " + frame.ToString()); TreeNode node = new TreeNode(frame.ToString()); node.Tag = frame; node.Name = frame.RefID.ToString(); root.Nodes.Add(node); //throw new FormatException("Unhandled frame! Name is: " + pair.Value.ToString()); } } return(root); }
public FrameHeaderScene AddSceneFolder(string name) { FrameHeaderScene scene = new FrameHeaderScene(); scene.Name = new Utils.Types.Hash(name); header.SceneFolders.Add(scene); frameScenes.Add(scene.RefID, scene); return(scene); }
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 DefineFrameBlockParents() { for (int i = 0; i < frameObjects.Count; i++) { var entry = (frameObjects.ElementAt(i)); FrameObjectBase obj = (entry.Value as FrameObjectBase); if (obj == null) { continue; } if (obj is FrameObjectModel) { FrameObjectModel model = (obj as FrameObjectModel); foreach (var attachment in model.AttachmentReferences) { attachment.Attachment = (frameObjects.ElementAt(attachment.AttachmentIndex - GetBlockCount).Value as FrameObjectBase); } } if (obj.ParentIndex1.Index > -1) { if (obj.ParentIndex1.Index <= (frameScenes.Count - 1) && (frameScenes.Count - 1) != -1) { FrameHeaderScene scene = (frameScenes.ElementAt(obj.ParentIndex1.Index).Value as FrameHeaderScene); obj.ParentIndex1.RefID = scene.RefID; obj.ParentIndex1.Name = scene.Name.ToString(); scene.Children.Add(obj); } else if (obj.ParentIndex1.Index >= GetBlockCount) { FrameObjectBase parent = GetObjectFromIndex(obj.ParentIndex1.Index - GetBlockCount); obj.ParentIndex1.RefID = parent.RefID; obj.ParentIndex1.Name = parent.Name.ToString(); obj.Parent = parent; parent.Children.Add(obj); } else { throw new Exception("Unhandled Frame!"); } obj.AddRef(FrameEntryRefTypes.Parent1, obj.ParentIndex1.RefID); } if (obj.ParentIndex2.Index > -1) { if (obj.ParentIndex2.Index <= (frameScenes.Count - 1) && (frameScenes.Count - 1) != -1) { FrameHeaderScene scene = (frameScenes.ElementAt(obj.ParentIndex2.Index).Value as FrameHeaderScene); obj.ParentIndex2.RefID = scene.RefID; obj.ParentIndex2.Name = scene.Name.ToString(); if (obj.Parent == null) { scene.Children.Add(obj); } } else if (obj.ParentIndex2.Index >= GetBlockCount) { FrameObjectBase parent = GetObjectFromIndex(obj.ParentIndex2.Index - GetBlockCount); obj.ParentIndex2.RefID = parent.RefID; obj.ParentIndex2.Name = parent.Name.ToString(); obj.Root = parent; if (obj.Parent == null) { parent.Children.Add(obj); } } else { throw new Exception("Unhandled Frame!"); } obj.AddRef(FrameEntryRefTypes.Parent2, obj.ParentIndex2.RefID); } obj.SetWorldTransform(); } }