コード例 #1
0
 public SportsController(AspModel db)
 {
     this.db = db;
 }
コード例 #2
0
 public TeamsController(AspModel db)
 {
     this.db = db;
 }
コード例 #3
0
// ========================================================

    public static void Main()
    {
        SearchOption SOAD = SearchOption.AllDirectories;

        string[] filesName = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.asp", SOAD);
        System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

// ========================================================

        foreach (var file in filesName)
        {
            using (BinaryReader br = new BinaryReader(File.Open(file, FileMode.Open)))
            {
                string name = file.Replace(".asp", "");

                using (StreamWriter objw = new StreamWriter(name + ".obj"))
                {
                    using (StreamWriter mtlw = new StreamWriter(name + ".mtl"))
                    {
                        Console.WriteLine("====== Beginning ASP import... ======");

                        model = new AspModel();

                        FourCC chunkId = new FourCC();

                        while (model.readFourCC(br, ref chunkId))
                        {
                            if (chunkId.ToString() == "BMSH")
                            {
                                model.readBMSH(br);
                            }

                            else if (chunkId.ToString() == "BONH")
                            {
                                model.readBONH(br);
                            }
                            else if (chunkId.ToString() == "BSUB")
                            {
                                model.readBSUB(br);
                            }
                            else if (chunkId.ToString() == "BSMM")
                            {
                                model.readBSMM(br);
                            }
                            else if (chunkId.ToString() == "BVTX")
                            {
                                model.readBVTX(br);
                            }
                            else if (chunkId.ToString() == "BCRN")
                            {
                                model.readBCRN(br);
                            }
                            else if (chunkId.ToString() == "WCRN")
                            {
                                model.readWCRN(br);
                            }
                            else if (chunkId.ToString() == "BVMP")
                            {
                                model.readBVMP(br);
                            }
                            else if (chunkId.ToString() == "BTRI")
                            {
                                model.readBTRI(br);
                            }
                            else if (chunkId.ToString() == "BVWL")
                            {
                                model.readBVWL(br);
                            }
                            else if (chunkId.ToString() == "STCH")
                            {
                                model.readSTCH(br);
                            }
                            else if (chunkId.ToString() == "RPOS")
                            {
                                model.readRPOS(br);
                            }
                            else if (chunkId.ToString() == "BBOX")
                            {
                                model.readBBOX(br);
                            }
//                  else if (chunkId.ToString() == "BEND") model.readBEND(br); // ó ìåíÿ îøèáêà EOF -_-
                            else
                            {
                            } // Unhandled chunk; Ignore it.
                        }

                        Console.WriteLine("====== Reached end of ASP data ======");

                        //==========================================================

                        objw.WriteLine("");

                        Console.WriteLine("Writing OBJ...");

                        int subMeshIndex = 0;
                        var subMeshes    = model.subMeshes;

                        objw.WriteLine("# File generated by asp2obj from DSiege ASPECT \"" + file + "\".");
                        objw.WriteLine("mtllib " + name + ".mtl");

                        // Per-vertex info:

                        foreach (var mesh in subMeshes)
                        {
                            objw.WriteLine("g AspMesh_" + subMeshIndex++);

                            // Vertexes: //----------------------------------------------------------

                            foreach (var c in mesh.wCorners)
                            {
                                Vec3 v = new Vec3 {
                                    X = (c.pos.X * modelScale),
                                    Y = -(c.pos.Z * modelScale),
                                    Z = (c.pos.Y * modelScale)
                                };

                                objw.WriteLine("v " + v.X + " " + v.Y + " " + v.Z);
                            }
                            objw.WriteLine();

                            // Vertex normals: //----------------------------------------------------

                            foreach (var c in mesh.wCorners)
                            {
                                Vec3 n = c.normal;
                                objw.WriteLine("vn " + n.X + " " + n.Y + " " + n.Z);
                            }
                            objw.WriteLine();

                            // Texture coordinates: //-----------------------------------------------

                            foreach (var c in mesh.wCorners)
                            {
                                Vec2 t = c.texCoord;
                                objw.WriteLine("vt " + t.U + " " + t.V);
                            }
                            objw.WriteLine();
                        }

                        // Faces:

                        subMeshIndex = 0;

                        int cornerOffset = 0;

                        var modelTextures = model.textureNames;

                        foreach (var mesh in subMeshes)
                        {
                            objw.WriteLine("g AspMesh_" + subMeshIndex++);

                            int f = 0;

                            for (int i = 0; i < mesh.textureCount; ++i)
                            {
                                objw.WriteLine("usemtl " + modelTextures[mesh.matInfo[i].textureIndex]);
                                objw.WriteLine("s 1\n"); // Allow smooth shading.

                                for (int j = 0; j < mesh.matInfo[i].faceSpan; ++j)
                                {
                                    var offset = mesh.faceInfo.cornerStart[i] + cornerOffset;
                                    var a      = mesh.faceInfo.cornerIndex[f].index[0] + offset + 1;
                                    var b      = mesh.faceInfo.cornerIndex[f].index[1] + offset + 1;
                                    var c      = mesh.faceInfo.cornerIndex[f].index[2] + offset + 1; // +1 for the OBJ

                                    // Position + texture + normal

                                    objw.WriteLine("f " + a + "/" + a + "/" + a + " "
                                                   + b + "/" + b + "/" + b + " "
                                                   + c + "/" + c + "/" + c + "\n");
                                    ++f;
                                }
                            }
                            cornerOffset += mesh.cornerCount;
                        }

                        objw.WriteLine();

                        Console.WriteLine("OBJ Finished.");

                        //==========================================================

                        Console.WriteLine("Writing MTL...");

                        subMeshes     = model.subMeshes;
                        modelTextures = model.textureNames;

                        mtlw.WriteLine();

                        foreach (var mesh in subMeshes)
                        {
                            for (int i = 0; i < mesh.textureCount; ++i)
                            {
                                var textureName = modelTextures[mesh.matInfo[i].textureIndex];

                                mtlw.WriteLine("newmtl " + textureName);
                                mtlw.WriteLine("Ka 0.00 0.00 0.00"); // Ambient
                                mtlw.WriteLine("Kd 1.00 1.00 1.00"); // Diffuse
                                mtlw.WriteLine("Ks 0.50 0.50 0.50"); // Specular
                                mtlw.WriteLine("Ns 95.00");          // Specular exponent/power
                                mtlw.WriteLine("map_Kd " + (textureName + texFileNameExt));
                            }
                        }

                        mtlw.WriteLine();

                        Console.WriteLine("MTL Finished.");

                        //==========================================================
                    } //using sw
                }     //using sw
            }         //using br
        }             // foreach (var file in filesName)
    }                 // public static void Main()