Ejemplo n.º 1
0
        public void RipModel(string file)
        {
            NsbmdPolygon polygon;
            int matId;
            NsbmdMaterial material;
            int num3;
            DiffuseMaterial material2;
            MeshBuilder builder;
            Model3D modeld;
            MTX44 mtx = new MTX44();
            List<MKDS_Course_Editor.Export3DTools.Group> list = new List<MKDS_Course_Editor.Export3DTools.Group>();
            List<Vector3> list2 = new List<Vector3>();
            for (int i = 0; i < (this.Model.Polygons.Count - 1); i++)
            {
                polygon = this.Model.Polygons[i];
                matId = polygon.MatId;
                material = this.Model.Materials[matId];
            }
            MTX44 mtx2 = new MTX44();
            mtx2.LoadIdentity();
            for (num3 = 0; num3 < this.Model.Objects.Count; num3++)
            {
                NsbmdObject obj2 = this.Model.Objects[num3];
                float[] transVect = obj2.TransVect;
                float[] numArray2 = loadIdentity();
                if (obj2.RestoreID != -1)
                {
                    mtx2 = MatrixStack[obj2.RestoreID];
                }
                if (obj2.StackID != -1)
                {
                    if (obj2.visible)
                    {
                        MTX44 b = new MTX44();
                        b.SetValues(obj2.materix);
                        mtx2 = mtx2.MultMatrix(b);
                    }
                    else
                    {
                        mtx2.Zero();
                    }
                    MatrixStack[obj2.StackID] = mtx2;
                    stackID = obj2.StackID;
                    float[] numArray3 = mtx2.MultVector(new float[3]);
                    list2.Add(new Vector3(numArray3[0], numArray3[1], numArray3[2]));
                }
            }
            num3 = 0;
            while (num3 < (this.Model.Polygons.Count - 1))
            {
                polygon = this.Model.Polygons[num3];
                if ((gOptTexture && !gOptWireFrame) && g_mat)
                {
                    matId = polygon.MatId;
                    if (matId == -1)
                    {
                        this.mattt.Add(new ImageBrush());
                    }
                    else
                    {
                        this.mattt.Add(this.matt[matId]);
                        material = this.Model.Materials[matId];
                    }
                }
                stackID = polygon.StackID;
                list.Add(Process3DCommandRipper(polygon.PolyData, Model.Materials[polygon.MatId], polygon.JointID, true));
                num3++;
            }
            File.Create(file).Close();
            HelixToolkit.ObjExporter exporter = new HelixToolkit.ObjExporter(file, "Created with Spiky's DS Map Editor " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString());
            int index = 0;
            foreach (MKDS_Course_Editor.Export3DTools.Group group in list)
            {
                ImageBrush brush = new ImageBrush();
                try
                {
                    brush.ImageSource = this.mattt[index].ImageSource;
                    brush.Opacity = this.mattt[index].Opacity;
                    brush.Viewbox = this.mattt[index].Viewbox;
                    brush.ViewboxUnits = this.mattt[index].ViewboxUnits;
                    brush.Viewport = this.mattt[index].Viewport;
                    brush.ViewportUnits = this.mattt[index].ViewportUnits;
                }
                catch
                {
                }
                if (brush.ImageSource != null)
                {
                    material2 = new DiffuseMaterial(brush);
                }
                else
                {
                    material2 = new DiffuseMaterial(new SolidColorBrush());
                }
                material2.SetValue(matName, this.Model.Materials[this.Model.Polygons[index].MatId].MaterialName);
                material2.SetValue(polyName, this.Model.Polygons[index].Name);
                material2.Brush.Opacity = ((float)this.Model.Materials[this.Model.Polygons[index].MatId].Alpha) / 31f;
                material2.AmbientColor = System.Windows.Media.Color.FromArgb(this.Model.Materials[this.Model.Polygons[index].MatId].AmbientColor.A, this.Model.Materials[this.Model.Polygons[index].MatId].AmbientColor.R, this.Model.Materials[this.Model.Polygons[index].MatId].AmbientColor.G, this.Model.Materials[this.Model.Polygons[index].MatId].AmbientColor.B);
                material2.Color = System.Windows.Media.Color.FromArgb(0xff, this.Model.Materials[this.Model.Polygons[index].MatId].DiffuseColor.R, this.Model.Materials[this.Model.Polygons[index].MatId].DiffuseColor.G, this.Model.Materials[this.Model.Polygons[index].MatId].DiffuseColor.B);
                builder = new MeshBuilder();
                foreach (MKDS_Course_Editor.Export3DTools.Polygon polygon2 in group)
                {
                    IList<Point3D> list3;
                    IList<Vector3D> list4;
                    IList<System.Windows.Point> list5;
                    switch (polygon2.PolyType)
                    {
                        case PolygonType.Triangle:
                            list3 = new List<Point3D>();
                            list4 = new List<Vector3D>();
                            list5 = new List<System.Windows.Point>();
                            num3 = 0;
                            goto Label_08AB;

                        case PolygonType.Quad:
                            list3 = new List<Point3D>();
                            list4 = new List<Vector3D>();
                            list5 = new List<System.Windows.Point>();
                            num3 = 0;
                            goto Label_0C5E;

                        case PolygonType.TriangleStrip:
                            list3 = new List<Point3D>();
                            list4 = new List<Vector3D>();
                            list5 = new List<System.Windows.Point>();
                            num3 = 0;
                            goto Label_0D66;

                        case PolygonType.QuadStrip:
                            list3 = new List<Point3D>();
                            list4 = new List<Vector3D>();
                            list5 = new List<System.Windows.Point>();
                            num3 = 0;
                            goto Label_0E7C;

                        default:
                            {
                                continue;
                            }
                    }
                Label_0608:
                    list3.Add(new Point3D((double)polygon2.Vertex[num3].X, (double)polygon2.Vertex[num3].Y, (double)polygon2.Vertex[num3].Z));
                    list4.Add(new Vector3D((double)polygon2.Normals[num3].X, (double)polygon2.Normals[num3].Y, (double)polygon2.Normals[num3].Z));
                    list5.Add(new System.Windows.Point((double)polygon2.TexCoords[num3].X, (double)polygon2.TexCoords[num3].Y));
                    list3.Add(new Point3D((double)polygon2.Vertex[num3 + 1].X, (double)polygon2.Vertex[num3 + 1].Y, (double)polygon2.Vertex[num3 + 1].Z));
                    list4.Add(new Vector3D((double)polygon2.Normals[num3 + 1].X, (double)polygon2.Normals[num3 + 1].Y, (double)polygon2.Normals[num3 + 1].Z));
                    list5.Add(new System.Windows.Point((double)polygon2.TexCoords[num3 + 1].X, (double)polygon2.TexCoords[num3 + 1].Y));
                    list3.Add(new Point3D((double)polygon2.Vertex[num3 + 2].X, (double)polygon2.Vertex[num3 + 2].Y, (double)polygon2.Vertex[num3 + 2].Z));
                    list4.Add(new Vector3D((double)polygon2.Normals[num3 + 2].X, (double)polygon2.Normals[num3 + 2].Y, (double)polygon2.Normals[num3 + 2].Z));
                    list5.Add(new System.Windows.Point((double)polygon2.TexCoords[num3 + 2].X, (double)polygon2.TexCoords[num3 + 2].Y));
                    builder.AddTriangles(list3, list4, list5);
                    list3.Clear();
                    list4.Clear();
                    list5.Clear();
                    num3 += 3;
                Label_08AB:
                    if (num3 < polygon2.Vertex.Length)
                    {
                        goto Label_0608;
                    }
                    continue;
                Label_08E4:
                    list3.Add(new Point3D((double)polygon2.Vertex[num3].X, (double)polygon2.Vertex[num3].Y, (double)polygon2.Vertex[num3].Z));
                    list4.Add(new Vector3D((double)polygon2.Normals[num3].X, (double)polygon2.Normals[num3].Y, (double)polygon2.Normals[num3].Z));
                    list5.Add(new System.Windows.Point((double)polygon2.TexCoords[num3].X, (double)polygon2.TexCoords[num3].Y));
                    list3.Add(new Point3D((double)polygon2.Vertex[num3 + 1].X, (double)polygon2.Vertex[num3 + 1].Y, (double)polygon2.Vertex[num3 + 1].Z));
                    list4.Add(new Vector3D((double)polygon2.Normals[num3 + 1].X, (double)polygon2.Normals[num3 + 1].Y, (double)polygon2.Normals[num3 + 1].Z));
                    list5.Add(new System.Windows.Point((double)polygon2.TexCoords[num3 + 1].X, (double)polygon2.TexCoords[num3 + 1].Y));
                    list3.Add(new Point3D((double)polygon2.Vertex[num3 + 2].X, (double)polygon2.Vertex[num3 + 2].Y, (double)polygon2.Vertex[num3 + 2].Z));
                    list4.Add(new Vector3D((double)polygon2.Normals[num3 + 2].X, (double)polygon2.Normals[num3 + 2].Y, (double)polygon2.Normals[num3 + 2].Z));
                    list5.Add(new System.Windows.Point((double)polygon2.TexCoords[num3 + 2].X, (double)polygon2.TexCoords[num3 + 2].Y));
                    list3.Add(new Point3D((double)polygon2.Vertex[num3 + 3].X, (double)polygon2.Vertex[num3 + 3].Y, (double)polygon2.Vertex[num3 + 3].Z));
                    list4.Add(new Vector3D((double)polygon2.Normals[num3 + 3].X, (double)polygon2.Normals[num3 + 3].Y, (double)polygon2.Normals[num3 + 3].Z));
                    list5.Add(new System.Windows.Point((double)polygon2.TexCoords[num3 + 3].X, (double)polygon2.TexCoords[num3 + 3].Y));
                    builder.AddQuads(list3, list4, list5);
                    list3.Clear();
                    list4.Clear();
                    list5.Clear();
                    num3 += 4;
                Label_0C5E:
                    if (num3 < polygon2.Vertex.Length)
                    {
                        goto Label_08E4;
                    }
                    continue;
                Label_0C97:
                    list3.Add(new Point3D((double)polygon2.Vertex[num3].X, (double)polygon2.Vertex[num3].Y, (double)polygon2.Vertex[num3].Z));
                    list4.Add(new Vector3D((double)polygon2.Normals[num3].X, (double)polygon2.Normals[num3].Y, (double)polygon2.Normals[num3].Z));
                    list5.Add(new System.Windows.Point((double)polygon2.TexCoords[num3].X, (double)polygon2.TexCoords[num3].Y));
                    num3++;
                Label_0D66:
                    if (num3 < polygon2.Vertex.Length)
                    {
                        goto Label_0C97;
                    }
                    builder.AddTriangleStrip(list3, list4, list5);
                    continue;
                Label_0DAD:
                    list3.Add(new Point3D((double)polygon2.Vertex[num3].X, (double)polygon2.Vertex[num3].Y, (double)polygon2.Vertex[num3].Z));
                    list4.Add(new Vector3D((double)polygon2.Normals[num3].X, (double)polygon2.Normals[num3].Y, (double)polygon2.Normals[num3].Z));
                    list5.Add(new System.Windows.Point((double)polygon2.TexCoords[num3].X, (double)polygon2.TexCoords[num3].Y));
                    num3++;
                Label_0E7C:
                    if (num3 < polygon2.Vertex.Length)
                    {
                        goto Label_0DAD;
                    }
                    builder.AddTriangleStrip(list3, list4, list5);
                }
                modeld = new GeometryModel3D(builder.ToMesh(false), material2);
                exporter.Export(modeld);
                index++;
            }

            exporter.Close();
            this.writevertex = false;
        }