private void SaveRW4Model(DatabaseIndex index, RW4Model model)
        {
            //Save the new thing to a stream!

            ModifiedRW4File modifiedData = new ModifiedRW4File();

            foreach (RW4Section section in model.Sections)
            {
                if (section.TypeCode == SectionTypeCodes.Texture)
                {
                    SporeMaster.RenderWare4.Texture tex = section.obj as SporeMaster.RenderWare4.Texture;
                    model.Sections[(int)tex.texData.section.Number].obj = tex.texData;
                }
            }

            RW4Section meshSection = model.Sections.Find(s => s.TypeCode == SectionTypeCodes.Mesh);

            if (meshSection != null)
            {
                SporeMaster.RenderWare4.RW4Mesh mesh = meshSection.obj as SporeMaster.RenderWare4.RW4Mesh;

                model.Sections[(int)mesh.vertices.section.Number].obj  = mesh.vertices;
                model.Sections[(int)mesh.triangles.section.Number].obj = mesh.triangles;

                model.Sections[(int)mesh.vertices.vertices.section.Number].obj   = mesh.vertices.vertices.section.obj;
                model.Sections[(int)mesh.triangles.triangles.section.Number].obj = mesh.triangles.triangles.section.obj;
            }

            //save back the model
            using (MemoryStream writer = new MemoryStream())
            {
                model.Write(writer);

                modifiedData.RW4FileData = writer.ToArray();
                index.ModifiedData       = modifiedData;
                index.IsModified         = true;
                index.Compressed         = false;
            }
        }
Example #2
0
        private void SaveRW4Model()
        {
            //Save the new thing to a stream!

            if (this.DataContext != null)
            {
                //  try
                //  {

                ModifiedRW4File   modifiedData = new ModifiedRW4File();
                DatabaseIndexData index        = (DatabaseIndexData)this.DataContext;

                using (Stream stream = new MemoryStream(index.Data))
                {
                    //first read the current RW4model

                    List <RW4Section> sections = dataGrid1.ItemsSource as List <RW4Section>;
                    _rw4model.Sections = sections;

                    foreach (RW4Section section in _rw4model.Sections)
                    {
                        if (section.TypeCode == SectionTypeCodes.Texture)
                        {
                            SporeMaster.RenderWare4.Texture tex = section.obj as SporeMaster.RenderWare4.Texture;
                            _rw4model.Sections[(int)tex.texData.section.Number].obj = tex.texData;
                        }
                    }

                    RW4Section meshSection = _rw4model.Sections.Find(s => s.TypeCode == SectionTypeCodes.Mesh);
                    if (meshSection != null)
                    {
                        SporeMaster.RenderWare4.RW4Mesh mesh = meshSection.obj as SporeMaster.RenderWare4.RW4Mesh;

                        //update the bounding box

                        /*RW4Section bboxSection = _rw4model.Sections.Find(s => s.TypeCode == SectionTypeCodes.BBox);
                         * if (bboxSection != null)
                         * {
                         *  RW4BBox boundingBox = bboxSection.obj as RW4BBox;
                         *  if (meshSection != null)
                         *  {
                         *      boundingBox.minx = mesh.vertices.vertices.Min(v => v.X);
                         *      boundingBox.miny = mesh.vertices.vertices.Min(v => v.Y);
                         *      boundingBox.minz = mesh.vertices.vertices.Min(v => v.Z);
                         *
                         *      boundingBox.maxx = mesh.vertices.vertices.Max(v => v.X);
                         *      boundingBox.maxy = mesh.vertices.vertices.Max(v => v.Y);
                         *      boundingBox.maxz = mesh.vertices.vertices.Max(v => v.Z);
                         *
                         *      bboxSection.obj = boundingBox;
                         *  }
                         * }*/

                        _rw4model.Sections[(int)mesh.vertices.section.Number].obj  = mesh.vertices;
                        _rw4model.Sections[(int)mesh.triangles.section.Number].obj = mesh.triangles;

                        _rw4model.Sections[(int)mesh.vertices.vertices.section.Number].obj   = mesh.vertices.vertices.section.obj;
                        _rw4model.Sections[(int)mesh.triangles.triangles.section.Number].obj = mesh.triangles.triangles.section.obj;
                    }



                    //save back the model

                    using (MemoryStream writer = new MemoryStream())
                    {
                        _rw4model.Write(writer);

                        modifiedData.RW4FileData = writer.ToArray();
                        index.Index.ModifiedData = modifiedData;
                        index.Index.IsModified   = true;
                        index.Index.Compressed   = false;
                    }
                }

                //ViewHexDiff hex = new ViewHexDiff(index.Data, modifiedData.RW4FileData);
                //hex.ShowDialog();
            }
        }