コード例 #1
0
    public void DrawStructure(DrawStructure choices, Structure structure, Vect3 structureMiddlePoint)
    {
        GameObject structureObject = new GameObject("Structure");

        for (int componentIndex = 0; componentIndex < structure.components.Count; componentIndex++)
        {
            GameObject componentObject = new GameObject(string.Format("Component {0}", componentIndex));
            componentObject.transform.parent = structureObject.transform;
            Nodegraph_Generator.Component component = structure.components[componentIndex];

            // To prepare color
            List <int>       floorFaces = ComponentGraphGenerator.GetFloorFaces(component);
            LinkedList <int> linkedList = ComponentGraphGenerator.GetShellVertices(component, floorFaces);
            (LinkedList <int>, LinkedList <int>)sidePair = ComponentGraphGenerator.SplitLinkedList(component, linkedList);

            if (choices.drawVertices)
            {
                GameObject verticesObject = new GameObject(string.Format("Component {0}, Vertices", componentIndex));
                verticesObject.transform.parent = componentObject.transform;
                for (int vertexIndex = 0; vertexIndex < component.vertices.Count; vertexIndex++)
                {
                    Vertex     vertex         = component.GetVertex(vertexIndex);
                    Vect3      vertexPosition = Utilities.GetScaledTransletedVect3(vertex.coordinate, structureMiddlePoint, scalingFactor);
                    GameObject vertexObject   = Utilities.DrawObject(vertexPrefab, vertexPosition, verticesObject);
                    vertexObject.name = string.Format("Vertex {0}", vertexIndex);
                    if (choices.colorFloor)
                    {
                        if (sidePair.Item1.Contains(vertexIndex))
                        {
                            Utilities.ColorObject(vertexObject, Color.blue);
                        }
                        else if (sidePair.Item2.Contains(vertexIndex))
                        {
                            Utilities.ColorObject(vertexObject, Color.red);
                        }
                    }
                }
            }

            if (choices.drawFaces)
            {
                var        drawnVertexPairs = new List <(int, int)>();
                var        drawnFaceSides   = new List <GameObject>();
                GameObject faces            = new GameObject(string.Format("Component {0}, Faces", componentIndex));
                faces.transform.parent = componentObject.transform;
                for (int faceIndex = 0; faceIndex < component.faces.Count; faceIndex++)
                {
                    Face face            = component.GetFace(faceIndex);
                    var  faceMiddlepoint = new Vect3();
                    for (int i = 0; i < face.vertexIndices.Length; i++)
                    {
                        int    firstVertexIndex = face.vertexIndices[i];
                        Vertex firstVertex      = component.GetVertex(firstVertexIndex);
                        faceMiddlepoint += firstVertex.coordinate;
                        for (int j = i + 1; j < face.vertexIndices.Length; j++)
                        {
                            int secondVertexIndex = face.vertexIndices[j];
                            if (!(drawnVertexPairs.Contains((firstVertexIndex, secondVertexIndex)) ||
                                  drawnVertexPairs.Contains((secondVertexIndex, firstVertexIndex))))
                            {
                                Vertex secondVertex = component.GetVertex(secondVertexIndex);
                                Vect3  startPos     = Utilities.GetScaledTransletedVect3(firstVertex.coordinate,
                                                                                         structureMiddlePoint, scalingFactor);
                                Vect3 endPos = Utilities.GetScaledTransletedVect3(secondVertex.coordinate,
                                                                                  structureMiddlePoint, scalingFactor);
                                GameObject faceSideObject = Utilities.DrawLine(startPos, endPos, faces);
                                faceSideObject.name = string.Format("Faceside to Face {0}", faceIndex);
                                Utilities.ColorObject(faceSideObject,
                                                      (choices.colorFloor && floorFaces.Contains(faceIndex)) ? Color.green : Color.black);
                                drawnVertexPairs.Add((secondVertexIndex, firstVertexIndex));
                                drawnFaceSides.Add(faceSideObject);
                            }
                            else
                            {
                                GameObject faceSideObject = drawnFaceSides[drawnVertexPairs.FindIndex(a =>
                                                                                                      (a.Item1 == firstVertexIndex && a.Item2 == secondVertexIndex) || (a.Item1 == secondVertexIndex && a.Item2 == firstVertexIndex))];
                                if (choices.colorFloor && floorFaces.Contains(faceIndex))
                                {
                                    Utilities.ColorObject(faceSideObject, Color.green);
                                }
                                faceSideObject.name += ", " + faceIndex;
                            }
                        }
                    }