Esempio n. 1
0
        // Public

        // Static Methods

        /// <summary>
        /// Crée un nouveau cône dont le cercle de base est composé du nombre
        /// de sommet passé en paramètre
        /// </summary>
        /// <param name="discretisation"></param>
        /// <returns></returns>
        public static Mesh GetMesh(int discretisation)
        {
            StandardMesh smesh = new StandardMesh();

            // On commence par crée les points du cercle qui forme la base du cône
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        0.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }

            smesh.AddVertex(new StandardVertex(new Vector3(0.0f, 1.0f, 0.0f)));


            for (int i = 0; i < discretisation - 1; i++)
            {
                smesh.AddFace(i + 1, i, smesh.GetVertexCount() - 1);
            }

            smesh.AddFace(0, smesh.GetVertexCount() - 2, smesh.GetVertexCount() - 1);

            // On construit la base


            int startSecondCircle = smesh.GetVertexCount();

            // On Crée une deuxième fois les sommets à la base du cone pour éviter les problèmes
            // de normales (comme le cube par exemple)
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        0.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }


            for (int i = 0; i < discretisation - 1; i++)
            {
                smesh.AddFace(startSecondCircle, startSecondCircle + i, startSecondCircle + i + 1);
            }

            smesh.ComputeNormals();
            smesh.ComputeTangents();

            return(smesh.ReturnMesh());
        }
Esempio n. 2
0
        // Public

        // Static Methods

        /// <summary>
        /// Retourne un cylindre, la valeur passé en paramètre détermine le niveau de
        /// détail du cylindre
        /// </summary>
        public static Mesh GetMesh(int discretisation)
        {
            StandardMesh smesh = new StandardMesh();

            // On commence par crée les points du cercle qui forme la base du cylindre
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        0.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }

            for (int i = 0; i < discretisation - 1; i++)
            {
                smesh.AddFace(0, i, i + 1);
            }

            int meshOffset = smesh.GetVertexCount();

            // On commence par crée un deuxième cercle en haut du cylindre
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        1.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }

            for (int i = 0; i < discretisation - 1; i++)
            {
                smesh.AddFace(meshOffset, meshOffset + i + 1, meshOffset + i);
            }

            meshOffset = smesh.GetVertexCount();

            // On Crée encore une fois le cercle à la base et en haut du cylindre pour éviter les souscis de normales
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        0.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }
            // On Crée encore une fois le cercle à la base et en haut du cylindre pour éviter les souscis de normales
            for (int i = 0; i < discretisation; i++)
            {
                float angleVal = 2.0f * 3.141592f * (float)i / (float)discretisation;

                StandardVertex svertex = new StandardVertex(
                    new Vector3(
                        (float)Math.Cos(angleVal),
                        1.0f,
                        (float)Math.Sin(angleVal)

                        ));

                smesh.AddVertex(svertex);
            }


            for (int i = 0; i < discretisation - 1; i++)
            {
                smesh.AddFace(meshOffset + i, meshOffset + discretisation + i, meshOffset + i + 1);
                smesh.AddFace(meshOffset + i + 1, meshOffset + discretisation + i, meshOffset + discretisation + i + 1);
            }

            smesh.AddFace(meshOffset + discretisation - 1, meshOffset + discretisation + discretisation - 1, meshOffset);
            smesh.AddFace(meshOffset, meshOffset + discretisation + discretisation - 1, meshOffset + discretisation);
            //smesh.AddFace(meshOffset + i + 1, meshOffset + discretisation + i, meshOffset + discretisation + i + 1);

            smesh.ComputeNormals();
            smesh.ComputeTangents();
            return(smesh.ReturnMesh());
        }
Esempio n. 3
0
        public static Mesh Mesh(float radius, int xdiscretisation, int ydiscretisation)
        {
            StandardMesh mesh = new StandardMesh();

            List <StandardVertex> vertices = new List <StandardVertex>();
            List <int>            indices_ = new List <int>();

            // Création des sommets

            mesh.AddVertex(new StandardVertex(
                               new Vector3(0.0f, -radius, 0.0f),
                               new Vector3(0.0f, -1.0f, 0.0f),
                               new Vector2(0.0f, 0.0f)
                               ));

            for (int i = 0; i < ydiscretisation; ++i)
            {
                for (int j = 0; j < xdiscretisation; ++j)
                {
                    float val = (float)Math.PI * (float)i / (float)ydiscretisation;
                    val = -(float)Math.Cos(val);

                    Vector3 position = new Vector3(
                        (float)Math.Sin(Math.PI * i / (float)ydiscretisation) * (float)Math.Cos(2.0f * Math.PI * j / xdiscretisation) * radius,
                        val * radius,
                        (float)Math.Sin(Math.PI * i / (float)ydiscretisation) * (float)Math.Sin(2.0f * Math.PI * j / xdiscretisation) * radius);

                    Vector3 normal = position;
                    normal.Normalize();
                    mesh.AddVertex(
                        new StandardVertex(
                            position,
                            normal,
                            new Vector2((float)j / (float)xdiscretisation, (float)i / (float)ydiscretisation)
                            ));
                }
            }

            mesh.AddVertex(new StandardVertex(
                               new Vector3(0.0f, radius, 0.0f),
                               new Vector3(0.0f, 1.0f, 0.0f),
                               new Vector2(0.0f, 1.0f)
                               ));

            // Création des faces
            for (int i = 0; i < xdiscretisation - 1; i++)
            {
                indices_.Add(0);
                indices_.Add(i + 1);
                indices_.Add(i + 2);
            }


            indices_.Add(0);
            indices_.Add(xdiscretisation);
            indices_.Add(1);

            for (int i = 0; i < ydiscretisation - 1; i++)
            {
                for (int j = 0; j < xdiscretisation - 1; j++)
                {
                    mesh.AddFace(
                        1 + xdiscretisation * i + j,        // 1
                        1 + xdiscretisation * (i + 1) + j,  // 5
                        1 + xdiscretisation * i + j + 1);   // 2

                    mesh.AddFace(
                        (1 + xdiscretisation * i + j + 1),        // 2
                        (1 + xdiscretisation * (i + 1) + j),      // 5
                        (1 + xdiscretisation * (i + 1) + j + 1)); // 6
                }

                mesh.AddFace(
                    (1 + xdiscretisation * (i + 1) - 1), // 4
                    (1 + xdiscretisation * (i + 1)),     // 5
                    (1 + xdiscretisation * i));          // 1

                mesh.AddFace(
                    (1 + xdiscretisation * (i + 1) - 1),                   // 4
                    (1 + xdiscretisation * (i + 1) + xdiscretisation - 1), // 5
                    (1 + xdiscretisation * (i + 1)));                      // 5
            }

            for (int i = 1; i < xdiscretisation; i++)
            {
                mesh.AddFace(
                    (mesh.GetVertexCount() - i - 2),
                    (mesh.GetVertexCount() - 1),
                    (mesh.GetVertexCount() - i - 1));
            }

            mesh.AddFace(
                (mesh.GetVertexCount() - 2),
                (mesh.GetVertexCount() - 1),
                (mesh.GetVertexCount() - xdiscretisation - 1));

            //mesh.ComputeNormals();
            mesh.ComputeTangents();



            return(mesh.ReturnMesh());
        }