Esempio n. 1
0
        /// <summary>
        /// Construit une représentation graphique du Diagramme de Voronoi de la triangulation
        /// </summary>
        public void BuildVoronoi(WingedEdgeMesh mesh)
        {
            List <StandardVertex> lines = new List <StandardVertex>();

            // On va commencer par construire les sommets correspondant aux centre des faces de la triangulation
            // qui sont les noeuds du diagramme de voronoir
            CleanVoronoi();

            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                // On récupère le centre de la face (barycentre)

                List <VertexWE> vertices = mesh.GetFaceVertices(mesh.Faces[i]);

                Vector3 center = vertices[0].Position + vertices[1].Position + vertices[2].Position;
                center = center / 3.0f;

                Troll3D.Entity entity = new Troll3D.Entity(Entity);
                entity.transform_.SetPosition(
                    center.X,
                    center.Y,
                    0.0f);

                entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

                MaterialDX11 material = new MaterialDX11();
                material.SetMainColor(0.0f, 1.0f, 1.0f, 1.0f);
                MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();
                meshrenderer.material_ = material;
                meshrenderer.model_    = Quad.GetMesh();

                // On récupère les voisins

                List <FaceWE> neighbours = mesh.GetFaceNeighbours(mesh.Faces[i]);

                for (int j = 0; j < neighbours.Count; j++)
                {
                    // On récupère le centre de la face (barycentre)

                    List <VertexWE> verticesNeighbour = mesh.GetFaceVertices(neighbours[j]);

                    Vector3 centerNeighbour = verticesNeighbour[0].Position + verticesNeighbour[1].Position + verticesNeighbour[2].Position;
                    centerNeighbour = centerNeighbour / 3.0f;

                    lines.Add(new StandardVertex(center));
                    lines.Add(new StandardVertex(centerNeighbour));
                }

                VoronoiPoints.Add(entity);
            }

            if (lines.Count > 0)
            {
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Display  = true;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Vertices = lines;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).UpdateRenderer();
            }
        }
        public void BuildVoronoi(WingedEdgeMesh mesh)
        {
            List <StandardVertex> lines = new List <StandardVertex>();

            // We start by building the vertices corresponding to the face's center of the triangulation who are node of the Voronoi diagram
            CleanVoronoi();

            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                // We get back the face's center (barycentre)

                List <VertexWE> vertices = mesh.GetFaceVertices(mesh.Faces[i]);

                Vector3 center = vertices[0].Position + vertices[1].Position + vertices[2].Position;
                center = center / 3.0f;

                Troll3D.Entity entity = new Troll3D.Entity(Entity);
                entity.transform_.SetPosition(
                    center.X,
                    center.Y,
                    0.0f);

                entity.transform_.SetScale(0.02f, 0.02f, 1.0f);

                MaterialDX11 material = new MaterialDX11();
                material.SetMainColor(0.0f, 1.0f, 1.0f, 1.0f);
                MeshRenderer meshrenderer = entity.AddComponent <MeshRenderer>();
                meshrenderer.material_ = material;
                meshrenderer.model_    = Quad.GetMesh();

                // We get back the neighbours

                List <FaceWE> neighbours = mesh.GetFaceNeighbours(mesh.Faces[i]);

                for (int j = 0; j < neighbours.Count; j++)
                {
                    // On récupère le centre de la face (barycentre)

                    List <VertexWE> verticesNeighbour = mesh.GetFaceVertices(neighbours[j]);

                    Vector3 centerNeighbour = verticesNeighbour[0].Position + verticesNeighbour[1].Position + verticesNeighbour[2].Position;
                    centerNeighbour = centerNeighbour / 3.0f;

                    lines.Add(new StandardVertex(center));
                    lines.Add(new StandardVertex(centerNeighbour));
                }

                VoronoiPoints.Add(entity);
            }

            if (lines.Count > 0)
            {
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Display  = true;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Vertices = lines;
                (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).UpdateRenderer();
            }
        }
 public void CleanVoronoi()
 {
     for (int i = 0; i < VoronoiPoints.Count; i++)
     {
         Scene.CurrentScene.RemoveRenderable(( MeshRenderer )VoronoiPoints[i].GetComponent(ComponentType.MeshRenderer));
     }
     VoronoiPoints.Clear();
     (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Display = false;
 }
Esempio n. 4
0
 public void CleanVoronoi()
 {
     // On commence par "effacer" les derniers points
     for (int i = 0; i < VoronoiPoints.Count; i++)
     {
         Scene.CurrentScene.RemoveRenderable(( MeshRenderer )VoronoiPoints[i].GetComponent(ComponentType.MeshRenderer));
     }
     VoronoiPoints.Clear();
     (( LineRenderer )VoronoiLines.GetComponent(ComponentType.LineRenderer)).Display = false;
 }