public FrameObjectModel(FrameObjectSingleMesh other) : base(other) { restTransform = new Matrix[0]; attachmentReferences = new AttachmentReference[0]; blendMeshSplits = new WeightedByMeshSplit[0]; hitBoxInfo = new HitBoxInfo[0]; }
public void DuplicateBlocks(FrameObjectSingleMesh mesh) { FrameMaterial material = new FrameMaterial(mesh.Material); mesh.ReplaceRef(FrameEntryRefTypes.Material, material.RefID); mesh.Material = material; frameMaterials.Add(material.RefID, material); }
public FrameObjectSingleMesh(FrameObjectSingleMesh other) : base(other) { flags = other.flags; bounds = other.bounds; unk14 = other.unk14; meshIndex = other.meshIndex; materialIndex = other.materialIndex; omTextureHash = new HashName(other.omTextureHash.String); unk18_1 = other.unk18_1; unk18_2 = other.unk18_2; unk18_3 = other.unk18_3; material = other.material; geometry = other.geometry; }
public static FrameObjectBase ReadFrameByObjectID(MemoryStream stream, ObjectType FrameType, bool isBigEndian) { switch (FrameType) { case ObjectType.Joint: FrameObjectJoint joint = new FrameObjectJoint(); joint.ReadFromFile(stream, isBigEndian); return(joint); case ObjectType.SingleMesh: FrameObjectSingleMesh mesh = new FrameObjectSingleMesh(); mesh.ReadFromFile(stream, isBigEndian); return(mesh); case ObjectType.Frame: FrameObjectFrame frame = new FrameObjectFrame(); frame.ReadFromFile(stream, isBigEndian); return(frame); case ObjectType.Light: FrameObjectLight light = new FrameObjectLight(); light.ReadFromFile(stream, isBigEndian); return(light); case ObjectType.Camera: FrameObjectCamera camera = new FrameObjectCamera(); camera.ReadFromFile(stream, isBigEndian); return(camera); case ObjectType.Component_U00000005: FrameObjectComponent_U005 u005 = new FrameObjectComponent_U005(); u005.ReadFromFile(stream, isBigEndian); return(u005); case ObjectType.Sector: FrameObjectSector sector = new FrameObjectSector(); sector.ReadFromFile(stream, isBigEndian); return(sector); case ObjectType.Dummy: FrameObjectDummy dummy = new FrameObjectDummy(); dummy.ReadFromFile(stream, isBigEndian); return(dummy); case ObjectType.ParticleDeflector: FrameObjectDeflector deflector = new FrameObjectDeflector(); deflector.ReadFromFile(stream, isBigEndian); return(deflector); case ObjectType.Area: FrameObjectArea area = new FrameObjectArea(); area.ReadFromFile(stream, isBigEndian); return(area); case ObjectType.Target: FrameObjectTarget target = new FrameObjectTarget(); target.ReadFromFile(stream, isBigEndian); return(target); case ObjectType.Model: FrameObjectModel model = new FrameObjectModel(); model.ReadFromFile(stream, isBigEndian); return(model); case ObjectType.Collision: FrameObjectCollision collision = new FrameObjectCollision(); collision.ReadFromFile(stream, isBigEndian); return(collision); default: Debug.WriteLine("Missing frame type!"); return(null); } }
public void UpdateFrameData() { SanitizeFrameData(); int currentCount = 0; List <FrameHolder> updatedFrames = new List <FrameHolder>(); foreach (KeyValuePair <int, FrameHeaderScene> entry in frameScenes) { updatedFrames.Add(new FrameHolder(currentCount++, entry.Value)); } foreach (KeyValuePair <int, FrameGeometry> entry in frameGeometries) { updatedFrames.Add(new FrameHolder(currentCount++, entry.Value)); } foreach (KeyValuePair <int, FrameMaterial> entry in frameMaterials) { updatedFrames.Add(new FrameHolder(currentCount++, entry.Value)); } foreach (KeyValuePair <int, FrameBlendInfo> entry in frameBlendInfos) { updatedFrames.Add(new FrameHolder(currentCount++, entry.Value)); } foreach (KeyValuePair <int, FrameSkeleton> entry in frameSkeletons) { updatedFrames.Add(new FrameHolder(currentCount++, entry.Value)); } foreach (KeyValuePair <int, FrameSkeletonHierachy> entry in frameSkeletonHierachies) { updatedFrames.Add(new FrameHolder(currentCount++, entry.Value)); } //We have to add the objects to the new frame AND THEN update refs. This is kind of odd, and I think i've done something wrong. int objectPosStart = currentCount; for (int i = 0; i != frameObjects.Count; i++) { FrameObjectBase block = (frameObjects.ElementAt(i).Value as FrameObjectBase); updatedFrames.Add(new FrameHolder(currentCount++, block)); } for (int i = objectPosStart; i != updatedFrames.Count; i++) { FrameObjectBase block = (updatedFrames[i].Data as FrameObjectBase); Console.WriteLine("Working on block " + block.Name.String); if (block.Refs.ContainsKey("Parent1")) { block.ParentIndex1.Index = GetLocalEntryFromRefID(updatedFrames, block.Refs["Parent1"]).Idx; } else { block.ParentIndex1.Index = -1; } if (block.Refs.ContainsKey("Parent2")) { block.ParentIndex2.Index = GetLocalEntryFromRefID(updatedFrames, block.Refs["Parent2"]).Idx; } else { block.ParentIndex2.Index = -1; } if (block.Type == typeof(FrameObjectSingleMesh).ToString()) { FrameObjectSingleMesh mesh = (block as FrameObjectSingleMesh); Console.WriteLine(string.Format("Updating: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex)); if (mesh.MaterialIndex != -1) { mesh.MaterialIndex = GetLocalEntryFromRefID(updatedFrames, block.Refs["Material"]).Idx; } if (mesh.MeshIndex != -1) { mesh.MeshIndex = GetLocalEntryFromRefID(updatedFrames, block.Refs["Mesh"]).Idx; } block = mesh; Console.WriteLine(string.Format("Updated: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex)); } if (block.Type == typeof(FrameObjectModel).ToString()) { FrameObjectModel mesh = (block as FrameObjectModel); Console.WriteLine(string.Format("Updating: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex)); mesh.MaterialIndex = GetLocalEntryFromRefID(updatedFrames, block.Refs["Material"]).Idx; mesh.MeshIndex = GetLocalEntryFromRefID(updatedFrames, block.Refs["Mesh"]).Idx; mesh.BlendInfoIndex = GetLocalEntryFromRefID(updatedFrames, block.Refs["BlendInfo"]).Idx; mesh.SkeletonIndex = GetLocalEntryFromRefID(updatedFrames, block.Refs["Skeleton"]).Idx; mesh.SkeletonHierachyIndex = GetLocalEntryFromRefID(updatedFrames, block.Refs["SkeletonHierachy"]).Idx; block = mesh; Console.WriteLine(string.Format("Updated: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex)); } } header.NumFolderNames = frameScenes.Count; header.NumGeometries = frameGeometries.Count; header.NumMaterialResources = frameMaterials.Count; header.NumBlendInfos = frameBlendInfos.Count; header.NumSkeletons = frameSkeletons.Count; header.NumSkelHierachies = frameSkeletonHierachies.Count; header.NumObjects = frameObjects.Count; header.NumFolderNames = header.SceneFolders.Count; NewFrames = updatedFrames; }
public void SanitizeFrameData() { Dictionary <int, bool> isGeomUsed = new Dictionary <int, bool>(frameGeometries.Count); Dictionary <int, bool> isMatUsed = new Dictionary <int, bool>(frameMaterials.Count); Dictionary <int, bool> isBlendInfoUsed = new Dictionary <int, bool>(frameBlendInfos.Count); Dictionary <int, bool> isSkelUsed = new Dictionary <int, bool>(frameSkeletons.Count); Dictionary <int, bool> isSkelHierUsed = new Dictionary <int, bool>(frameSkeletonHierachies.Count); foreach (KeyValuePair <int, FrameGeometry> entry in frameGeometries) { isGeomUsed.Add(entry.Key, false); } foreach (KeyValuePair <int, FrameMaterial> entry in frameMaterials) { isMatUsed.Add(entry.Key, false); } foreach (KeyValuePair <int, FrameBlendInfo> entry in frameBlendInfos) { isBlendInfoUsed.Add(entry.Key, false); } foreach (KeyValuePair <int, FrameSkeleton> entry in frameSkeletons) { isSkelUsed.Add(entry.Key, false); } foreach (KeyValuePair <int, FrameSkeletonHierachy> entry in frameSkeletonHierachies) { isSkelHierUsed.Add(entry.Key, false); } foreach (KeyValuePair <int, object> entry in frameObjects) { if (entry.Value is FrameObjectModel) { FrameObjectModel mesh = (entry.Value as FrameObjectModel); isGeomUsed[mesh.Refs[FrameEntry.MeshRef]] = true; isMatUsed[mesh.Refs[FrameEntry.MaterialRef]] = true; isBlendInfoUsed[mesh.Refs[FrameEntry.BlendInfoRef]] = true; isSkelHierUsed[mesh.Refs[FrameEntry.SkeletonHierRef]] = true; isSkelUsed[mesh.Refs[FrameEntry.SkeletonRef]] = true; } else if (entry.Value is FrameObjectSingleMesh) { FrameObjectSingleMesh mesh = (entry.Value as FrameObjectSingleMesh); if (mesh.MeshIndex > -1) { isGeomUsed[mesh.Refs[FrameEntry.MeshRef]] = true; } if (mesh.MaterialIndex > -1) { isMatUsed[mesh.Refs[FrameEntry.MaterialRef]] = true; } } } for (int i = 0; i != isGeomUsed.Count; i++) { KeyValuePair <int, bool> pair = isGeomUsed.ElementAt(i); if (pair.Value != true) { frameGeometries.Remove(pair.Key); Console.WriteLine("Deleted with ID: {0}", pair.Key); } } for (int i = 0; i != isMatUsed.Count; i++) { KeyValuePair <int, bool> pair = isMatUsed.ElementAt(i); if (pair.Value != true) { frameMaterials.Remove(pair.Key); Console.WriteLine("Deleted with ID: {0}", pair.Key); } } for (int i = 0; i != isBlendInfoUsed.Count; i++) { KeyValuePair <int, bool> pair = isBlendInfoUsed.ElementAt(i); if (pair.Value != true) { frameBlendInfos.Remove(pair.Key); Console.WriteLine("Deleted with ID: {0}", pair.Key); } } for (int i = 0; i != isSkelUsed.Count; i++) { KeyValuePair <int, bool> pair = isSkelUsed.ElementAt(i); if (pair.Value != true) { frameSkeletons.Remove(pair.Key); Console.WriteLine("Deleted with ID: {0}", pair.Key); } } for (int i = 0; i != isSkelHierUsed.Count; i++) { KeyValuePair <int, bool> pair = isSkelHierUsed.ElementAt(i); if (pair.Value != true) { frameSkeletonHierachies.Remove(pair.Key); Console.WriteLine("Deleted with ID: {0}", pair.Key); } } }
public void ReadFromFile(MemoryStream reader, bool isBigEndian) { header = new FrameHeader(); header.ReadFromFile(reader, isBigEndian); int j = 0; for (int i = 0; i != header.SceneFolders.Count; i++) { frameScenes.Add(header.SceneFolders[i].RefID, header.SceneFolders[i]); NewFrames.Add(new FrameHolder(j++, header.SceneFolders[i])); } for (int i = 0; i != header.NumGeometries; i++) { FrameGeometry geo = new FrameGeometry(reader, isBigEndian); frameGeometries.Add(geo.RefID, geo); NewFrames.Add(new FrameHolder(j++, geo)); } for (int i = 0; i != header.NumMaterialResources; i++) { FrameMaterial mat = new FrameMaterial(reader, isBigEndian); frameMaterials.Add(mat.RefID, mat); NewFrames.Add(new FrameHolder(j++, mat)); } for (int i = 0; i != header.NumBlendInfos; i++) { FrameBlendInfo blendInfo = new FrameBlendInfo(reader, isBigEndian); frameBlendInfos.Add(blendInfo.RefID, blendInfo); NewFrames.Add(new FrameHolder(j++, blendInfo)); } for (int i = 0; i != header.NumSkeletons; i++) { FrameSkeleton skeleton = new FrameSkeleton(reader, isBigEndian); frameSkeletons.Add(skeleton.RefID, skeleton); NewFrames.Add(new FrameHolder(j++, skeleton)); } for (int i = 0; i != header.NumSkelHierachies; i++) { FrameSkeletonHierachy skeletonHierachy = new FrameSkeletonHierachy(reader, isBigEndian); frameSkeletonHierachies.Add(skeletonHierachy.RefID, skeletonHierachy); NewFrames.Add(new FrameHolder(j++, skeletonHierachy)); } int[] objectTypes = new int[header.NumObjects]; int numBlocks = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies; if (header.NumObjects > 0) { for (int i = 0; i != header.NumObjects; i++) { objectTypes[i] = reader.ReadInt32(isBigEndian); } for (int i = 0; i != header.NumObjects; i++) { FrameObjectBase newObject = new FrameObjectBase(); if (objectTypes[i] == (int)ObjectType.Joint) { newObject = new FrameObjectJoint(reader, isBigEndian); } else if (objectTypes[i] == (int)ObjectType.SingleMesh) { newObject = new FrameObjectSingleMesh(reader, isBigEndian); FrameObjectSingleMesh mesh = newObject as FrameObjectSingleMesh; if (mesh.MeshIndex != -1) { mesh.AddRef(FrameEntryRefTypes.Mesh, GetEntryFromIdx(mesh.MeshIndex).Data.RefID); mesh.Geometry = frameGeometries[mesh.Refs["Mesh"]]; } if (mesh.MaterialIndex != -1) { mesh.AddRef(FrameEntryRefTypes.Material, GetEntryFromIdx(mesh.MaterialIndex).Data.RefID); mesh.Material = frameMaterials[mesh.Refs["Material"]]; } } else if (objectTypes[i] == (int)ObjectType.Frame) { newObject = new FrameObjectFrame(reader, isBigEndian); } else if (objectTypes[i] == (int)ObjectType.Light) { newObject = new FrameObjectLight(reader, isBigEndian); } else if (objectTypes[i] == (int)ObjectType.Camera) { newObject = new FrameObjectCamera(reader, isBigEndian); } else if (objectTypes[i] == (int)ObjectType.Component_U00000005) { newObject = new FrameObjectComponent_U005(reader, isBigEndian); } else if (objectTypes[i] == (int)ObjectType.Sector) { newObject = new FrameObjectSector(reader, isBigEndian); } else if (objectTypes[i] == (int)ObjectType.Dummy) { newObject = new FrameObjectDummy(reader, isBigEndian); } else if (objectTypes[i] == (int)ObjectType.ParticleDeflector) { newObject = new FrameObjectDeflector(reader, isBigEndian); } else if (objectTypes[i] == (int)ObjectType.Area) { newObject = new FrameObjectArea(reader, isBigEndian); } else if (objectTypes[i] == (int)ObjectType.Target) { newObject = new FrameObjectTarget(reader, isBigEndian); } else if (objectTypes[i] == (int)ObjectType.Model) { FrameObjectModel mesh = new FrameObjectModel(reader, isBigEndian); mesh.ReadFromFile(reader, isBigEndian); mesh.ReadFromFilePart2(reader, isBigEndian, (FrameSkeleton)GetEntryFromIdx(mesh.SkeletonIndex).Data, (FrameBlendInfo)GetEntryFromIdx(mesh.BlendInfoIndex).Data); mesh.AddRef(FrameEntryRefTypes.Mesh, GetEntryFromIdx(mesh.MeshIndex).Data.RefID); mesh.Geometry = frameGeometries[mesh.Refs[FrameEntry.MeshRef]]; mesh.AddRef(FrameEntryRefTypes.Material, GetEntryFromIdx(mesh.MaterialIndex).Data.RefID); mesh.Material = frameMaterials[mesh.Refs[FrameEntry.MaterialRef]]; mesh.AddRef(FrameEntryRefTypes.BlendInfo, GetEntryFromIdx(mesh.BlendInfoIndex).Data.RefID); mesh.BlendInfo = frameBlendInfos[mesh.Refs[FrameEntry.BlendInfoRef]]; mesh.AddRef(FrameEntryRefTypes.Skeleton, GetEntryFromIdx(mesh.SkeletonIndex).Data.RefID); mesh.Skeleton = frameSkeletons[mesh.Refs[FrameEntry.SkeletonRef]]; mesh.AddRef(FrameEntryRefTypes.SkeletonHierachy, GetEntryFromIdx(mesh.SkeletonHierachyIndex).Data.RefID); mesh.SkeletonHierarchy = frameSkeletonHierachies[mesh.Refs[FrameEntry.SkeletonHierRef]]; newObject = mesh; } else if (objectTypes[i] == (int)ObjectType.Collision) { newObject = new FrameObjectCollision(reader, isBigEndian); } frameObjects.Add(newObject.RefID, newObject); NewFrames.Add(new FrameHolder(i + numBlocks, newObject)); } } objectTypes = null; DefineFrameBlockParents(); }
private FrameObjectBase ReadFrame(MemoryStream stream) { int OldRefID = stream.ReadInt32(false); // read old RefID so we can make lookup dictionary ObjectType frameType = (ObjectType)stream.ReadInt16(false); FrameObjectBase parent = FrameFactory.ReadFrameByObjectID(stream, frameType, false); Debug.WriteLine(parent.ToString()); if (parent is FrameObjectSingleMesh || parent is FrameObjectModel) { // Read the required blocks; FrameGeometry geometry = new FrameGeometry(); geometry.ReadFromFile(stream, false); FrameMaterial material = new FrameMaterial(); material.ReadFromFile(stream, false); // Add them into our pool of blocks FrameGeometries.Add(geometry.RefID, geometry); FrameMaterials.Add(material.RefID, material); // Add our references onto our mesh FrameObjectSingleMesh mesh = (parent as FrameObjectSingleMesh); mesh.AddRef(FrameEntryRefTypes.Geometry, geometry.RefID); mesh.Geometry = FrameGeometries[geometry.RefID]; mesh.AddRef(FrameEntryRefTypes.Material, material.RefID); mesh.Material = FrameMaterials[material.RefID]; if (parent is FrameObjectModel) { // Read the rigged specific blocks FrameBlendInfo blendInfo = new FrameBlendInfo(); blendInfo.ReadFromFile(stream, false); FrameSkeleton skeleton = new FrameSkeleton(); skeleton.ReadFromFile(stream, false); FrameSkeletonHierachy hierarchy = new FrameSkeletonHierachy(); hierarchy.ReadFromFile(stream, false); // Add our new rigged specific blocks into our pools FrameBlendInfos.Add(blendInfo.RefID, blendInfo); FrameSkeletons.Add(skeleton.RefID, skeleton); FrameSkeletonHierarchy.Add(hierarchy.RefID, hierarchy); // Finally, add our references to the model. FrameObjectModel model = (parent as FrameObjectModel); model.AddRef(FrameEntryRefTypes.BlendInfo, blendInfo.RefID); model.BlendInfo = FrameBlendInfos[blendInfo.RefID]; model.AddRef(FrameEntryRefTypes.Skeleton, skeleton.RefID); model.Skeleton = FrameSkeletons[skeleton.RefID]; model.AddRef(FrameEntryRefTypes.SkeletonHierachy, hierarchy.RefID); model.SkeletonHierarchy = FrameSkeletonHierarchy[hierarchy.RefID]; model.ReadFromFilePart2(stream, false); } // We have to make sure we have index and buffer pools available // We have to do it for all LODs too; if any more than 1. foreach (var lod in geometry.LOD) { IndexBuffer indexBuffer = new IndexBuffer(stream, false); VertexBuffer vertexBuffer = new VertexBuffer(stream, false); SceneData.IndexBufferPool.TryAddBuffer(indexBuffer); SceneData.VertexBufferPool.TryAddBuffer(vertexBuffer); } } // Read FrameNameTable data parent.IsOnFrameTable = stream.ReadBoolean(); parent.FrameNameTableFlags = (FrameNameTable.NameTableFlags)stream.ReadUInt32(false); // Read ParentIndex from previous SDS int OldParentIndex1RefId = stream.ReadInt32(false); int OldParentIndex2RefId = stream.ReadInt32(false); // Temporarily store it as a reference. parent.AddRef(FrameEntryRefTypes.Parent1, OldParentIndex1RefId); parent.AddRef(FrameEntryRefTypes.Parent2, OldParentIndex2RefId); // We can finally add our new frame object FrameObjects.Add(parent.RefID, parent); // Push new FrameObject int OldRefLookupTable OldRefIDLookupTable.Add(OldRefID, parent); // Read how many children this frame has, and proceed to read them too. int count = stream.ReadInt32(false); for (int i = 0; i < count; i++) { FrameObjectBase child = ReadFrame(stream); } return(parent); }
public void UpdateFrameData() { SanitizeFrameData(); int[] offsets = new int[7]; offsets[0] = 0; offsets[1] = offsets[0] + frameScenes.Count; offsets[2] = offsets[1] + frameGeometries.Count; offsets[3] = offsets[2] + frameMaterials.Count; offsets[4] = offsets[3] + frameBlendInfos.Count; offsets[5] = offsets[4] + frameSkeletons.Count; offsets[6] = offsets[5] + frameSkeletonHierachies.Count; for (int i = 0; i < frameObjects.Count; i++) { FrameObjectBase block = (frameObjects.ElementAt(i).Value as FrameObjectBase); Console.WriteLine("Working on block " + block.Name.String); if (block.Refs.ContainsKey(FrameEntry.Parent1Ref)) { if (frameScenes.ContainsKey(block.Refs[FrameEntry.Parent1Ref])) { block.ParentIndex1.Index = frameScenes.IndexOfValue(block.Refs[FrameEntry.Parent1Ref]); } else { block.ParentIndex1.Index = offsets[6] + (block.Refs.ContainsKey(FrameEntry.Parent1Ref) ? frameObjects.IndexOfValue(block.Refs[FrameEntry.Parent1Ref]) : -1); } } if (block.Refs.ContainsKey(FrameEntry.Parent2Ref)) { if (frameScenes.ContainsKey(block.Refs[FrameEntry.Parent2Ref])) { block.ParentIndex2.Index = frameScenes.IndexOfValue(block.Refs[FrameEntry.Parent2Ref]); } else { block.ParentIndex2.Index = offsets[6] + (block.Refs.ContainsKey(FrameEntry.Parent2Ref) ? frameObjects.IndexOfValue(block.Refs[FrameEntry.Parent2Ref]) : -1); } } if (block.Type == typeof(FrameObjectSingleMesh).ToString()) { FrameObjectSingleMesh mesh = (block as FrameObjectSingleMesh); Console.WriteLine(string.Format("Updating: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex)); if (mesh.MeshIndex != -1) { mesh.MeshIndex = offsets[1] + frameGeometries.IndexOfValue(mesh.Refs[FrameEntry.GeometryRef]); } if (mesh.MaterialIndex != -1) { mesh.MaterialIndex = offsets[2] + frameMaterials.IndexOfValue(mesh.Refs[FrameEntry.MaterialRef]); } block = mesh; Console.WriteLine(string.Format("Updated: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex)); } if (block.Type == typeof(FrameObjectModel).ToString()) { FrameObjectModel mesh = (block as FrameObjectModel); Console.WriteLine(string.Format("Updating: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex)); if (mesh.MeshIndex != -1) { mesh.MeshIndex = offsets[1] + frameGeometries.IndexOfValue(mesh.Refs[FrameEntry.GeometryRef]); } if (mesh.MaterialIndex != -1) { mesh.MaterialIndex = offsets[2] + frameMaterials.IndexOfValue(mesh.Refs[FrameEntry.MaterialRef]); } if (mesh.BlendInfoIndex != -1) { mesh.BlendInfoIndex = offsets[3] + frameBlendInfos.IndexOfValue(mesh.Refs[FrameEntry.BlendInfoRef]); } if (mesh.SkeletonIndex != -1) { mesh.SkeletonIndex = offsets[4] + frameSkeletons.IndexOfValue(mesh.Refs[FrameEntry.SkeletonRef]); } if (mesh.SkeletonHierachyIndex != -1) { mesh.SkeletonHierachyIndex = offsets[5] + frameSkeletonHierachies.IndexOfValue(mesh.Refs[FrameEntry.SkeletonHierRef]); } foreach (var attachment in mesh.AttachmentReferences) { attachment.AttachmentIndex = offsets[6] + frameObjects.IndexOfValue(attachment.Attachment.RefID); } block = mesh; Console.WriteLine(string.Format("Updated: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex)); } } header.SceneFolders = frameScenes.Values.ToList(); header.NumFolderNames = frameScenes.Count; header.NumGeometries = frameGeometries.Count; header.NumMaterialResources = frameMaterials.Count; header.NumBlendInfos = frameBlendInfos.Count; header.NumSkeletons = frameSkeletons.Count; header.NumSkelHierachies = frameSkeletonHierachies.Count; header.NumObjects = frameObjects.Count; header.NumFolderNames = frameScenes.Count; }
private FrameObjectBase ReadFrame(MemoryStream stream) { ObjectType frameType = (ObjectType)stream.ReadInt16(false); FrameObjectBase parent = FrameFactory.ReadFrameByObjectID(stream, frameType, false); Debug.WriteLine(parent.ToString()); if (parent is FrameObjectSingleMesh || parent is FrameObjectModel) { // Read the required blocks; FrameGeometry geometry = new FrameGeometry(); geometry.ReadFromFile(stream, false); FrameMaterial material = new FrameMaterial(); material.ReadFromFile(stream, false); // Add them into our pool of blocks frameGeometries.Add(geometry.RefID, geometry); frameMaterials.Add(material.RefID, material); // Add our references onto our mesh FrameObjectSingleMesh mesh = (parent as FrameObjectSingleMesh); mesh.AddRef(FrameEntryRefTypes.Geometry, geometry.RefID); mesh.Geometry = frameGeometries[geometry.RefID]; mesh.AddRef(FrameEntryRefTypes.Material, material.RefID); mesh.Material = frameMaterials[material.RefID]; //mesh.Parent.ParentIndex1 if (parent is FrameObjectModel) { // Read the rigged specific blocks FrameBlendInfo blendInfo = new FrameBlendInfo(); blendInfo.ReadFromFile(stream, false); FrameSkeleton skeleton = new FrameSkeleton(); skeleton.ReadFromFile(stream, false); FrameSkeletonHierachy hierarchy = new FrameSkeletonHierachy(); hierarchy.ReadFromFile(stream, false); // Add our new rigged specific blocks into our pools frameBlendInfos.Add(blendInfo.RefID, blendInfo); frameSkeletons.Add(skeleton.RefID, skeleton); frameSkeletonHierachies.Add(hierarchy.RefID, hierarchy); // Finally, add our references to the model. FrameObjectModel model = (parent as FrameObjectModel); model.AddRef(FrameEntryRefTypes.BlendInfo, blendInfo.RefID); model.BlendInfo = frameBlendInfos[blendInfo.RefID]; model.AddRef(FrameEntryRefTypes.Skeleton, skeleton.RefID); model.Skeleton = frameSkeletons[skeleton.RefID]; model.AddRef(FrameEntryRefTypes.SkeletonHierachy, hierarchy.RefID); model.SkeletonHierarchy = frameSkeletonHierachies[hierarchy.RefID]; } // Read the buffers; IndexBuffer indexBuffer = new IndexBuffer(stream, false); VertexBuffer vertexBuffer = new VertexBuffer(stream, false); // We have to make sure we have index and buffer pools available // We have to do it for all LODs too; if any more than 1. foreach (var lod in geometry.LOD) { SceneData.IndexBufferPool.TryAddBuffer(indexBuffer); SceneData.VertexBufferPool.TryAddBuffer(vertexBuffer); } } // We can finally add our new frame object frameObjects.Add(parent.RefID, parent); // Read how many children this frame has, and proceed to read them too. int count = stream.ReadInt32(false); for (int i = 0; i < count; i++) { FrameObjectBase child = ReadFrame(stream); // Add References early.. child.AddRef(FrameEntryRefTypes.Parent1, parent.RefID); child.AddRef(FrameEntryRefTypes.Parent2, parent.RefID); SetParentOfObject(0, child, parent); SetParentOfObject(1, child, parent); } return(parent); }
public void ReadFromFile(MemoryStream reader, bool isBigEndian) { header = new FrameHeader(); header.ReadFromFile(reader, isBigEndian); List <int> refs = new List <int>(); for (int i = 0; i != header.SceneFolders.Count; i++) { frameScenes.Add(header.SceneFolders[i].RefID, header.SceneFolders[i]); refs.Add(header.SceneFolders[i].RefID); } for (int i = 0; i != header.NumGeometries; i++) { FrameGeometry geo = new FrameGeometry(reader, isBigEndian); frameGeometries.Add(geo.RefID, geo); refs.Add(geo.RefID); } for (int i = 0; i != header.NumMaterialResources; i++) { FrameMaterial mat = new FrameMaterial(reader, isBigEndian); frameMaterials.Add(mat.RefID, mat); refs.Add(mat.RefID); } for (int i = 0; i != header.NumBlendInfos; i++) { FrameBlendInfo blendInfo = new FrameBlendInfo(reader, isBigEndian); frameBlendInfos.Add(blendInfo.RefID, blendInfo); refs.Add(blendInfo.RefID); } for (int i = 0; i != header.NumSkeletons; i++) { FrameSkeleton skeleton = new FrameSkeleton(reader, isBigEndian); frameSkeletons.Add(skeleton.RefID, skeleton); refs.Add(skeleton.RefID); } for (int i = 0; i != header.NumSkelHierachies; i++) { FrameSkeletonHierachy skeletonHierachy = new FrameSkeletonHierachy(reader, isBigEndian); frameSkeletonHierachies.Add(skeletonHierachy.RefID, skeletonHierachy); refs.Add(skeletonHierachy.RefID); } int[] objectTypes = new int[header.NumObjects]; if (header.NumObjects > 0) { for (int i = 0; i != header.NumObjects; i++) { objectTypes[i] = reader.ReadInt32(isBigEndian); } for (int i = 0; i != header.NumObjects; i++) { FrameObjectBase newObject = FrameFactory.ReadFrameByObjectID(reader, (ObjectType)objectTypes[i], isBigEndian); if (objectTypes[i] == (int)ObjectType.SingleMesh) { FrameObjectSingleMesh mesh = newObject as FrameObjectSingleMesh; if (mesh.MeshIndex != -1) { mesh.AddRef(FrameEntryRefTypes.Geometry, refs[mesh.MeshIndex]); mesh.Geometry = frameGeometries[mesh.Refs[FrameEntry.GeometryRef]]; } if (mesh.MaterialIndex != -1) { mesh.AddRef(FrameEntryRefTypes.Material, refs[mesh.MaterialIndex]); mesh.Material = frameMaterials[mesh.Refs[FrameEntry.MaterialRef]]; } } else if (objectTypes[i] == (int)ObjectType.Model) { FrameObjectModel mesh = newObject as FrameObjectModel; mesh.AddRef(FrameEntryRefTypes.Geometry, refs[mesh.MeshIndex]); mesh.Geometry = frameGeometries[mesh.Refs[FrameEntry.GeometryRef]]; mesh.AddRef(FrameEntryRefTypes.Material, refs[mesh.MaterialIndex]); mesh.Material = frameMaterials[mesh.Refs[FrameEntry.MaterialRef]]; mesh.AddRef(FrameEntryRefTypes.BlendInfo, refs[mesh.BlendInfoIndex]); mesh.BlendInfo = frameBlendInfos[mesh.Refs[FrameEntry.BlendInfoRef]]; mesh.AddRef(FrameEntryRefTypes.Skeleton, refs[mesh.SkeletonIndex]); mesh.Skeleton = frameSkeletons[mesh.Refs[FrameEntry.SkeletonRef]]; mesh.AddRef(FrameEntryRefTypes.SkeletonHierachy, refs[mesh.SkeletonHierachyIndex]); mesh.SkeletonHierarchy = frameSkeletonHierachies[mesh.Refs[FrameEntry.SkeletonHierRef]]; mesh.ReadFromFilePart2(reader, isBigEndian); newObject = mesh; } frameObjects.Add(newObject.RefID, newObject); } } objectTypes = null; DefineFrameBlockParents(); }