Exemplo n.º 1
0
        public void When_CreatingSimpleCubeBigGraph_ExpectRightWidth(Structure structure)
        {
            Component simpleCubeBig      = structure.components[0];
            NodeGraph simpleCubeBigGraph = ComponentGraphGenerator.GenerateComponentNodeGraph(simpleCubeBig);

            Assert.AreEqual(7, simpleCubeBigGraph.GetEdgeWidth(0));
        }
Exemplo n.º 2
0
        public void When_CreatingNodegraphFromSimpleCube_Expect_Result(Structure structure)
        {
            Component simpleCube        = structure.components[0];
            NodeGraph nodegraph         = ComponentGraphGenerator.GenerateComponentNodeGraph(simpleCube);
            NodeGraph expectedNodegraph = CreateNodegraphSimpleCube();

            Assert.AreEqual(expectedNodegraph, nodegraph);
        }
Exemplo n.º 3
0
        public void When_CreatingSimpleLeftTurnGraph_ExpectRightWidths(Structure structure)
        {
            Component SimpleLeftTurn      = structure.components[0];
            NodeGraph SimpleLeftTurnGraph = ComponentGraphGenerator.GenerateComponentNodeGraph(SimpleLeftTurn);

            Assert.AreEqual(1, SimpleLeftTurnGraph.GetEdgeWidth(0));
            Assert.AreEqual(Math.Sqrt(0.5), SimpleLeftTurnGraph.GetEdgeWidth(1));
            Assert.AreEqual(1, SimpleLeftTurnGraph.GetEdgeWidth(2));
        }
Exemplo n.º 4
0
        public void When_FindFloorFacesOfSimpleCube_Expect_TwoBottomFaces(Structure structure)
        {
            Component simpleCube = structure.components[0];

            List <int> floorFaces = ComponentGraphGenerator.GetFloorFaces(simpleCube);

            Assert.AreEqual(2, floorFaces.Count);
            Assert.Contains(6, floorFaces);
            Assert.Contains(7, floorFaces);
        }
Exemplo n.º 5
0
        public void When_FindFloorFaceOfSimpleCube_Expect_FloorFace(Structure structure)
        {
            Component simpleCube = structure.components[0];

            int lowestVertex = ComponentGraphGenerator.FindLowestVertex(simpleCube);

            int faceIndex = ComponentGraphGenerator.FindStartFloorFace(simpleCube, lowestVertex);

            Assert.That(faceIndex == SimpleCubeBottomFace1 || faceIndex == SimpleCubeBottomFace2);
        }
Exemplo n.º 6
0
        public void When_GetShellVerticesOfSimpleCube_Expect_FloorSideVertices(Structure structure)
        {
            Component simpleCube = structure.components[0];

            List <int>       floorFaces        = ComponentGraphGenerator.GetFloorFaces(simpleCube);
            LinkedList <int> floorSideVertices = ComponentGraphGenerator.GetShellVertices(simpleCube, floorFaces);

            Assert.AreEqual(4, floorSideVertices.Count);
            Assert.Contains(1, floorSideVertices);
            Assert.Contains(3, floorSideVertices);
            Assert.Contains(0, floorSideVertices);
            Assert.Contains(5, floorSideVertices);
        }
Exemplo n.º 7
0
        public void When_SplitLinkedListOfSimpleCube_Expect_LongSideVertices(Structure structure)
        {
            Component simpleCube = structure.components[0];

            List <int>       floorFaces        = ComponentGraphGenerator.GetFloorFaces(simpleCube);
            LinkedList <int> floorSideVertices = ComponentGraphGenerator.GetShellVertices(simpleCube, floorFaces);

            (LinkedList <int>, LinkedList <int>)sides = ComponentGraphGenerator.SplitLinkedList(simpleCube, floorSideVertices);

            Assert.AreEqual(2, sides.Item1.Count);
            Assert.AreEqual(2, sides.Item2.Count);
            Assert.Contains(0, sides.Item1);
            Assert.Contains(1, sides.Item1);
            Assert.Contains(3, sides.Item2);
            Assert.Contains(5, sides.Item2);
        }
Exemplo n.º 8
0
        public void When_GenerateComponentNodeGraphFromComponentWithUnevenFloorVertices_Expect_NodeGraph(Structure structure)
        {
            Component component = structure.components[0];

            NodeGraph nodeGraph = ComponentGraphGenerator.GenerateComponentNodeGraph(component);

            Vect3 node1coordinate = new Vect3(-0.5, -0.5, 0);
            Vect3 node2coordinate = new Vect3(7.5, -0.5, 0);

            Edge resultEdge = new Edge(1, 0);

            resultEdge.index = 0;
            resultEdge.width = 1;

            Assert.AreEqual(2, nodeGraph.Nodes.Count);
            Assert.AreEqual(1, nodeGraph.Edges.Count);
            Assert.That(nodeGraph.Nodes.Exists(n => n.coordinate == node1coordinate));
            Assert.That(nodeGraph.Nodes.Exists(n => n.coordinate == node2coordinate));
            Assert.Contains(resultEdge, nodeGraph.Edges);
        }
Exemplo n.º 9
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;
                            }
                        }
                    }
Exemplo n.º 10
0
        public void When_FindLowestVertexOfSimpleCube_Expect_YIsZero(Structure structure)
        {
            Component simpleCube = structure.components[0];

            Assert.That(Util.NearlyEqual(simpleCube.vertices[ComponentGraphGenerator.FindLowestVertex(simpleCube)].coordinate.y, 0));
        }
Exemplo n.º 11
0
        public void When_FindFloorOfSimpleCube_Expect_TwoFaces(Structure structure)
        {
            Component simpleCube = structure.components[0];

            Assert.AreEqual(2, ComponentGraphGenerator.GetFloorFaces(simpleCube).Count);
        }
Exemplo n.º 12
0
        public void When_FindStartFloorFaceEmptyComponent_ExpectThrowEmptyListException_Helper()
        {
            Component c = new Component();

            ComponentGraphGenerator.FindStartFloorFace(c, 1);
        }
Exemplo n.º 13
0
        public void When_FindLowestVertexEmptyComponent_ExpectThrowEmptyListException_Helper()
        {
            Component c = new Component();

            ComponentGraphGenerator.FindLowestVertex(c);
        }
Exemplo n.º 14
0
    // Start is called before the first frame update
    void Start()
    {
        // Build Up Structure
        AssimpInterpreter interpreter = new AssimpInterpreter();

        structure = interpreter.Interpret(AssetDatabase.GetAssetPath(files.modelFile));

        VoxelGridGraphGenerator.outerLayerLimit        = voxelStrategy.peelFactor;
        VoxelGridGraphGenerator.VoxelDistanceThreshold = voxelStrategy.GraphVoxelDeviationThreshold;
        VoxelGridGraphGenerator.mergeThreshold         = voxelStrategy.mergeThreshold;

        VoxelGrid.DefaultComponentWiseResolutionDivider = voxelStrategy.ComponentResDivider;
        structureMiddlePoint = Utilities.GetStructureMiddlePoint(structure);

        bool draw = drawNodeGraph.drawNodes || drawNodeGraph.drawEdges;

        List <NodeGraph> nodeGraphs = new List <NodeGraph>();

        List <VoxelGrid> voxelGrids = new List <VoxelGrid>();
        List <(DistanceGrid, VoxelGrid)> skeletonGrids = new List <(DistanceGrid, VoxelGrid)>();

        if (graphStrategy.strategy == Strategy.Voxel)
        {
            if (voxelStrategy.voxelScope == VoxelScope.component)
            {
                foreach (var component in structure.components)
                {
                    gridTimer.Start();
                    VoxelGrid voxelGrid = new VoxelGrid(component);
                    gridTimer.Stop();
                    gridProcessingTimer.Start();
                    if (draw || drawVoxels.fillInternalVolume || drawVoxels.skeletalize)
                    {
                        voxelGrid.FillInternalVolume(component);
                    }
                    gridProcessingTimer.Stop();
                    if (draw)
                    {
                        graphGenerationTimer.Start();
                        nodeGraphs.Add(VoxelGridGraphGenerator.GenerateNodeGraph(component));
                        graphGenerationTimer.Stop();
                    }

                    if (drawVoxels.drawVoxels)
                    {
                        gridProcessingTimer.Start();
                        if (drawVoxels.skeletalize)
                        {
                            skeletonGrids.Add((VoxelGridGraphGenerator.GenerateSkeletalGrid(voxelGrid), voxelGrid));
                        }
                        else if (drawVoxels.peel)
                        {
                            skeletonGrids.Add((VoxelGridGraphGenerator.GeneratePeeledGrid(voxelGrid), voxelGrid));
                        }
                        gridProcessingTimer.Stop();
                    }
                    voxelGrids.Add(voxelGrid);
                }
            }
            else if (voxelStrategy.voxelScope == VoxelScope.structure)
            {
                gridTimer.Start();
                VoxelGrid voxelGrid = new VoxelGrid(structure, plane1Normal: Vect3.Right, plane2Normal: Vect3.Up, plane3Normal: Vect3.Forward);
                gridTimer.Stop();
                gridProcessingTimer.Start();
                if (draw || drawVoxels.fillInternalVolume || drawVoxels.skeletalize || drawVoxels.peel)
                {
                    voxelGrid.FillInternalVolume(structure);
                }
                gridProcessingTimer.Stop();
                if (draw)
                {
                    graphGenerationTimer.Start();
                    nodeGraphs.Add(VoxelGridGraphGenerator.GenerateNodeGraph(structure));
                    graphGenerationTimer.Stop();
                }

                if (drawVoxels.drawVoxels)
                {
                    gridProcessingTimer.Start();
                    if (drawVoxels.skeletalize)
                    {
                        skeletonGrids.Add((VoxelGridGraphGenerator.GenerateSkeletalGrid(voxelGrid), voxelGrid));
                    }
                    if (drawVoxels.peel)
                    {
                        skeletonGrids.Add((VoxelGridGraphGenerator.GeneratePeeledGrid(voxelGrid), voxelGrid));
                    }
                    gridProcessingTimer.Stop();
                }
                voxelGrids.Add(voxelGrid);
            }
        }
        else if (graphStrategy.strategy == Strategy.Mesh)
        {
            foreach (Nodegraph_Generator.Component component in structure.components)
            {
                graphGenerationTimer.Start();
                nodeGraphs.Add(ComponentGraphGenerator.GenerateComponentNodeGraph(component));
                graphGenerationTimer.Stop();
            }

            if (meshStrategy.drawCollisions)
            {
                drawTimer.Start();
                drawer.DrawCollisions(nodeGraphs, structureMiddlePoint);
                drawTimer.Stop();
            }

            if (meshStrategy.unifyGraph)
            {
                graphGenerationTimer.Start();
                NodeGraph nodeGraph = GraphUnifier.UnifyGraphs(nodeGraphs);
                graphGenerationTimer.Stop();
                nodeGraphs.Clear();
                nodeGraphs.Add(nodeGraph);
            }
        }
        else if (graphStrategy.strategy == Strategy.XML)
        {
            graphGenerationTimer.Start();
            nodeGraphs.Add(XMLCreator.readXML <NodeGraph>(AssetDatabase.GetAssetPath(files.XMLFile)));
            graphGenerationTimer.Stop();
        }

        drawTimer.Start();
        if (drawStructure.drawFaces || drawStructure.drawVertices)
        {
            drawer.DrawStructure(drawStructure, structure, structureMiddlePoint);
        }

        if (drawOBBs.oBBType == OBBType.components)
        {
            foreach (var voxelGrid in voxelGrids)
            {
                foreach (var oBB in voxelGrid.componentOBBs.Values)
                {
                    drawer.DrawOBB(oBB, drawOBBs, structureMiddlePoint);
                }
            }
        }
        else if (drawOBBs.oBBType == OBBType.voxelGrid)
        {
            foreach (var voxelGrid in voxelGrids)
            {
                drawer.DrawOBB(voxelGrid.orientedBbox, drawOBBs, structureMiddlePoint);
            }
        }

        if (drawVoxels.drawVoxels)
        {
            if (drawVoxels.skeletalize || drawVoxels.peel)
            {
                foreach (var skeletonGrid in skeletonGrids)
                {
                    drawer.DrawSkeletonGrid(skeletonGrid.Item1, skeletonGrid.Item2, structureMiddlePoint);
                }
            }
            else
            {
                foreach (var voxelGrid in voxelGrids)
                {
                    drawer.DrawVoxelGrid(voxelGrid, structureMiddlePoint);
                }
            }
        }

        if (drawNodeGraph.drawNodes || drawNodeGraph.drawEdges)
        {
            foreach (NodeGraph nodeGraph in nodeGraphs)
            {
                drawer.DrawNodeGraph(drawNodeGraph, nodeGraph, structureMiddlePoint);
            }
        }
        drawTimer.Stop();

        if (graphStrategy.writeXML && !(graphStrategy.strategy == Strategy.XML))
        {
            if (nodeGraphs.Count == 1)
            {
                string filename = System.IO.Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(files.modelFile));
                filename += ".xml";
                XMLCreator.writeXML(nodeGraphs[0], System.IO.Path.Combine("Assets", "XML", filename));
            }
            else
            {
                string filename = System.IO.Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(files.modelFile));
                int    counter  = 1;
                foreach (NodeGraph nodeGraph in nodeGraphs)
                {
                    string subfilename = filename + (counter++) + ".xml";
                    XMLCreator.writeXML(nodeGraphs[0], System.IO.Path.Combine("Assets", "XML", subfilename));
                }
            }
        }

        ReportProcessTimes();
    }