/// <summary>
 /// Constructor used to build Lods. This is used when you want to compile all mesh data together, ready for exporting.
 /// </summary>
 public Model(FrameObjectModel frameModel, IndexBuffer[] indexBuffers, VertexBuffer[] vertexBuffers,
              FrameGeometry frameGeometry, FrameMaterial frameMaterial)
 {
     this.frameModel    = frameModel;
     this.indexBuffers  = indexBuffers;
     this.vertexBuffers = vertexBuffers;
     this.frameGeometry = frameGeometry;
     this.frameMaterial = frameMaterial;
     model           = new M2TStructure();
     model.IsSkinned = true;
     model.Name      = frameMesh.Name.String;
     model.BuildLods(frameGeometry, frameMaterial, vertexBuffers, indexBuffers);
 }
示例#2
0
        /// <summary>
        /// Reads the file into the memory.
        /// </summary>
        /// <param name="reader"></param>
        public void ReadFromFile(BinaryReader reader)
        {
            header = new FrameHeader();
            header.ReadFromFile(reader);

            objectTypes = new int[header.NumObjects];
            frameBlocks = new int[header.SceneFolders.Length + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies];

            int j = 0;

            for (int i = 0; i != header.SceneFolders.Length; i++)
            {
                frameScenes.Add(header.SceneFolders[i].RefID, header.SceneFolders[i]);
                frameBlocks[j++] = header.SceneFolders[i].RefID;
            }
            for (int i = 0; i != header.NumGeometries; i++)
            {
                FrameGeometry geo = new FrameGeometry(reader);
                frameGeometries.Add(geo.RefID, geo);
                frameBlocks[j++] = geo.RefID;
            }
            for (int i = 0; i != header.NumMaterialResources; i++)
            {
                FrameMaterial mat = new FrameMaterial(reader);
                frameMaterials.Add(mat.RefID, mat);
                frameBlocks[j++] = mat.RefID;
            }
            for (int i = 0; i != header.NumBlendInfos; i++)
            {
                FrameBlendInfo blendInfo = new FrameBlendInfo(reader);
                frameBlendInfos.Add(blendInfo.RefID, blendInfo);
                frameBlocks[j++] = blendInfo.RefID;
            }
            for (int i = 0; i != header.NumSkeletons; i++)
            {
                FrameSkeleton skeleton = new FrameSkeleton(reader);
                frameSkeletons.Add(skeleton.RefID, skeleton);
                frameBlocks[j++] = skeleton.RefID;
            }
            for (int i = 0; i != header.NumSkelHierachies; i++)
            {
                FrameSkeletonHierachy skeletonHierachy = new FrameSkeletonHierachy(reader);
                frameSkeletonHierachies.Add(skeletonHierachy.RefID, skeletonHierachy);
                frameBlocks[j++] = skeletonHierachy.RefID;
            }

            if (header.NumObjects > 0)
            {
                for (int i = 0; i != header.NumObjects; i++)
                {
                    objectTypes[i] = reader.ReadInt32();
                }

                for (int i = 0; i != header.NumObjects; i++)
                {
                    FrameObjectBase newObject = new FrameObjectBase();
                    if (objectTypes[i] == (int)ObjectType.Joint)
                    {
                        newObject = new FrameObjectJoint(reader);
                    }

                    else if (objectTypes[i] == (int)ObjectType.SingleMesh)
                    {
                        newObject = new FrameObjectSingleMesh(reader);
                        FrameObjectSingleMesh mesh = newObject as FrameObjectSingleMesh;

                        if (mesh.MeshIndex != -1)
                        {
                            mesh.AddRef(FrameEntryRefTypes.Mesh, frameBlocks[mesh.MeshIndex]);
                        }

                        if (mesh.MaterialIndex != -1)
                        {
                            mesh.AddRef(FrameEntryRefTypes.Material, frameBlocks[mesh.MaterialIndex]);
                        }
                    }
                    else if (objectTypes[i] == (int)ObjectType.Frame)
                    {
                        newObject = new FrameObjectFrame(reader);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Light)
                    {
                        newObject = new FrameObjectLight(reader);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Camera)
                    {
                        newObject = new FrameObjectCamera(reader);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Component_U00000005)
                    {
                        newObject = new FrameObjectComponent_U005(reader);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Sector)
                    {
                        newObject = new FrameObjectSector(reader);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Dummy)
                    {
                        newObject = new FrameObjectDummy(reader);
                    }

                    else if (objectTypes[i] == (int)ObjectType.ParticleDeflector)
                    {
                        newObject = new FrameObjectDeflector(reader);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Area)
                    {
                        newObject = new FrameObjectArea(reader);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Target)
                    {
                        newObject = new FrameObjectTarget(reader);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Model)
                    {
                        FrameObjectModel mesh = new FrameObjectModel(reader);
                        mesh.ReadFromFile(reader);
                        mesh.ReadFromFilePart2(reader, frameSkeletons[frameBlocks[mesh.SkeletonIndex]], frameBlendInfos[frameBlocks[mesh.BlendInfoIndex]]);
                        mesh.AddRef(FrameEntryRefTypes.Mesh, frameBlocks[mesh.MeshIndex]);
                        mesh.AddRef(FrameEntryRefTypes.Material, frameBlocks[mesh.MaterialIndex]);
                        mesh.AddRef(FrameEntryRefTypes.BlendInfo, frameBlocks[mesh.BlendInfoIndex]);
                        mesh.AddRef(FrameEntryRefTypes.Skeleton, frameBlocks[mesh.SkeletonIndex]);
                        mesh.AddRef(FrameEntryRefTypes.SkeletonHierachy, frameBlocks[mesh.SkeletonHierachyIndex]);
                        newObject = mesh;
                    }
                    else if (objectTypes[i] == (int)ObjectType.Collision)
                    {
                        newObject = new FrameObjectCollision(reader);
                    }

                    frameObjects.Add(newObject.RefID, newObject);
                }
            }
            DefineFrameBlockParents();
        }
示例#3
0
        /// <summary>
        /// This reconstructs the data.
        /// </summary>
        public void UpdateFrameData()
        {
            int totalResources = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies;

            Dictionary <int, object> newFrame = new Dictionary <int, object>();

            foreach (KeyValuePair <int, FrameHeaderScene> entry in frameScenes)
            {
                newFrame.Add(entry.Key, entry.Value);
            }
            foreach (KeyValuePair <int, FrameGeometry> entry in frameGeometries)
            {
                newFrame.Add(entry.Key, entry.Value);
            }
            foreach (KeyValuePair <int, FrameMaterial> entry in frameMaterials)
            {
                newFrame.Add(entry.Key, entry.Value);
            }
            foreach (KeyValuePair <int, FrameBlendInfo> entry in frameBlendInfos)
            {
                newFrame.Add(entry.Key, entry.Value);
            }
            foreach (KeyValuePair <int, FrameSkeleton> entry in frameSkeletons)
            {
                newFrame.Add(entry.Key, entry.Value);
            }
            foreach (KeyValuePair <int, FrameSkeletonHierachy> entry in frameSkeletonHierachies)
            {
                newFrame.Add(entry.Key, 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 = newFrame.Count;

            for (int i = 0; i != frameObjects.Count; i++)
            {
                FrameObjectBase block = (frameObjects.ElementAt(i).Value as FrameObjectBase);
                newFrame.Add(block.RefID, block);
            }
            for (int i = objectPosStart; i != newFrame.Count; i++)
            {
                FrameObjectBase block = (newFrame.ElementAt(i).Value as FrameObjectBase);
                Console.WriteLine("Working on block " + block.Name.String);

                if (block.Refs.ContainsKey("Parent1"))
                {
                    block.ParentIndex1.Index = newFrame.IndexOfValue(block.Refs["Parent1"]);
                }
                else
                {
                    block.ParentIndex1.Index = -1;
                }

                if (block.Refs.ContainsKey("Parent2"))
                {
                    block.ParentIndex2.Index = newFrame.IndexOfValue(block.Refs["Parent2"]);
                }
                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 = newFrame.IndexOfValue(mesh.Refs["Material"]);
                    }

                    if (mesh.MeshIndex != -1)
                    {
                        mesh.MeshIndex = newFrame.IndexOfValue(mesh.Refs["Mesh"]);
                    }

                    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         = newFrame.IndexOfValue(mesh.Refs["Material"]);
                    mesh.MeshIndex             = newFrame.IndexOfValue(mesh.Refs["Mesh"]);
                    mesh.BlendInfoIndex        = newFrame.IndexOfValue(mesh.Refs["BlendInfo"]);
                    mesh.SkeletonIndex         = newFrame.IndexOfValue(mesh.Refs["Skeleton"]);
                    mesh.SkeletonHierachyIndex = newFrame.IndexOfValue(mesh.Refs["SkeletonHierachy"]);
                    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;
        }