Exemple #1
0
    /// <summary>
    /// Finds path to connect shape with nodes from already drawn shape (polygon);
    /// Reason for this function is to find 2 possible paths from start to end Node , one wich we are going to draw as new shape
    ///
    /// </summary>
    /// <param name="polygon">Drawn shape</param>
    /// <param name="connectingNodes">List of Nodes needed to connect to complete shape</param>
    /// <param name="prevEle">Last connect node from map.vertices</param>
    /// <param name="i"> index where map.endNode is in map.vertices</param>
    /// <param name="locVertices">temporary  vertices of finished shape</param>
    /// <param name="locShape">>temporary  vertices of finished shape</param>
    public void YetDunno(MeshMan polygon, ref List <Vector2> connectingNodes, Vector2 prevEle, int i, ref List <Vector2> locVertices, int Dir)
    {
        int fckUpCounter = 0;

        while (polygon.nodes[i] != startNode)
        {
            connectingNodes.Add(polygon.nodes[i]);
            i += Dir;
            // For list to be cyclic
            if (i >= polygon.nodes.Count)
            {
                i = 0;
            }
            if (i < 0)
            {
                i = polygon.nodes.Count - 1;
            }

            fckUpCounter++;
            if (fckUpCounter > 30)
            {
                Debug.Log("FUUUUUUUUUUUUUUUUUUUUUUUUUUUCK");
                break;
            }
        }

        // Joining path to already existing vertices and shape
        foreach (var ele in connectingNodes)
        {
            locVertices.Add(ele);
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        StopWatch.Reset();
        StopWatch.Start();

        // update sensor position
        UpdateSensor(ref SensorField, ref SensorData);

        // update visible mesh vertices
        SubStopWatch.Reset();
        SubStopWatch.Start();
        List <bool> MeshGuide = MeshMan.UpdateVertices(SensorField);

        MeshDensity = MeshMan.Density;
        SubStopWatch.Stop();
        MeshManSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        // project to non-occluded vertices
        SubStopWatch.Reset();
        SubStopWatch.Start();
        Oc = new Intersector.Occlusion(OcclusionObjSize, OcclusionObjDistance, SensorField.FOV);
        List <Intersector.PointValue <byte> > Updates =
            VertexInter.ProjectToVisible(SensorData, SensorField, Oc, Observer.ExtraData, MeshGuide);

        SubStopWatch.Stop();
        IntersectSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        // update voxel grid
        SubStopWatch.Reset();
        SubStopWatch.Start();
        VoxGridMan.Set(Updates, UpdateVoxStruct);
        SubStopWatch.Stop();
        VoxGridManSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        // visualize data
        SubStopWatch.Reset();
        SubStopWatch.Start();
        // render spheres
        if (RenderVerts)
        {
            VertMarkers = Visualizer.CreateMarkers(Updates,
                                                   VertexMarkerSize, 0, 255, MinColor, MaxColor);
            VertVis.Visualize(VertMarkers);
        }
        // color mesh
        if (ColoredMesh)
        {
            Visualizer.ColorMesh(Observer.SurfaceObjects, Observer.ExtraData, MeshGuide,
                                 VoxGridMan, MinColor, MaxColor, 0, 255);
        }
        SubStopWatch.Stop();
        VertVisSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        StopWatch.Stop();
        DriverSpeed = StopWatch.ElapsedTicks / (double)Stopwatch.Frequency;
    }
Exemple #3
0
 private void UpdateMeshBounds()
 {
     MeshBounds = MeshMan.AllMeshBounds();
     while (BoundsRandNums.Count < MeshBounds.Count)
     {
         BoundsRandNums.Add(Random.value);
     }
     while (BoundColors.Count < MeshBounds.Count)
     {
         BoundColors.Add(Visualizer.RandomColor(BoundsColor1, BoundsColor2));
     }
 }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        StopWatch.Reset();
        StopWatch.Start();

        // update sensor position
        UpdateSensor();

        // update visible mesh vertices
        SubStopWatch.Reset();
        SubStopWatch.Start();
        List <bool> MeshGuide = MeshMan.UpdateVertices(SensorField);

        MeshDensity = MeshMan.Density;
        SubStopWatch.Stop();
        MeshManSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        // project to non-occluded vertices
        SubStopWatch.Reset();
        SubStopWatch.Start();
        Oc = new Intersector.Occlusion(OcclusionObjSize, OcclusionObjDistance, SensorField.FOV);
        List <Intersector.PointValue <byte> > Updates =
            VertexInter.ProjectToVisible(SensorData, SensorField, SensorDataHeight, SensorDataWidth,
                                         Oc, Observer.ExtraData, MeshGuide,
                                         Closest, Furthest, SensorField.Transform.position, SensorFOVReduction, ProximityConfig);

        SubStopWatch.Stop();
        IntersectSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        // update voxel grid
        SubStopWatch.Reset();
        SubStopWatch.Start();
        if (VoxGridFilter == DataFilter.live)
        {
            VoxGridMan.Reset();        // reset if filtered to live data only
        }
        VoxGridMan.Set(Updates, true); // true: update voxel structure
        SubStopWatch.Stop();
        VoxGridManSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        // visualize data
        SubStopWatch.Reset();
        SubStopWatch.Start();
        HandleVis(Updates, MeshGuide);
        SubStopWatch.Stop();
        VertVisSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        StopWatch.Stop();
        DriverSpeed = StopWatch.ElapsedTicks / (double)Stopwatch.Frequency;
    }
Exemple #5
0
    public MeshMan GetBiggestPolygon(ref List <MeshMan> shapes)
    {
        double  area;
        double  max          = 0;
        MeshMan maxAreaShape = shapes[0];

        foreach (var ele in shapes)
        {
            area = AreOfPolygon(ele.nodes);
            if (area > max)
            {
                maxAreaShape = ele;
                max          = area;
            }
        }
        return(maxAreaShape);
    }
Exemple #6
0
    // Update is called once per frame
    void Update()
    {
        StopWatch.Reset();
        StopWatch.Start();

        // call MeshManager to update
        SubStopWatch.Reset();
        SubStopWatch.Start();
        MeshMan.UpdateVertices(ref Vertices);
        SubStopWatch.Stop();
        MeshManSpeed = (double)SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        // update VoxelGrid
        SubStopWatch.Reset();
        SubStopWatch.Start();
        VoxGridMan.Set(Vertices);
        SubStopWatch.Stop();
        VoxGridManSpeed = (double)SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        StopWatch.Stop();
        DriverSpeed = (double)StopWatch.ElapsedTicks / (double)Stopwatch.Frequency;
    }
Exemple #7
0
    // Update is called once per frame
    void Update()
    {
        StopWatch.Reset();
        StopWatch.Start();

        // update sensor position
        UpdateSensor(ref SensorField, ref SensorData);

        // update visible mesh vertices
        SubStopWatch.Reset();
        SubStopWatch.Start();
        List <bool> MeshGuide = MeshMan.UpdateVertices(SensorField);

        MeshDensity = MeshMan.Density;
        SubStopWatch.Stop();
        MeshManSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        // project to non-occluded vertices
        SubStopWatch.Reset();
        SubStopWatch.Start();
        Oc = new Intersector.Occlusion(OcclusionObjSize, OcclusionObjDistance, SensorField.FOV);
        List <Intersector.PointValue <byte> > Updates =
            VertexInter.ProjectToVisible(SensorData, SensorField, Oc, Observer.ExtraData, MeshGuide,
                                         Closest, Furthest, SensorField.Transform.position);

        SubStopWatch.Stop();
        IntersectSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        // update voxel grid
        SubStopWatch.Reset();
        SubStopWatch.Start();
        // reset if filtered to live data only
        if (VoxGridFilter == DataFilter.live)
        {
            VoxGridMan.Reset();
        }
        VoxGridMan.Set(Updates, UpdateVoxStruct);
        SubStopWatch.Stop();
        VoxGridManSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;

        // visualize data
        SubStopWatch.Reset();
        SubStopWatch.Start();
        content = new List <Visualizer.Content>();
        // render spheres
        if (RenderVerts)
        {
            if (VoxGridFilter == DataFilter.mesh || VoxGridFilter == DataFilter.live)
            {
                // render all non-occluded mesh vertices
                content.AddRange(Visualizer.CreateMarkers(Updates,
                                                          VertexMarkerSize, MinColorVal, MaxColorVal, MinColor, MaxColor));
            }
            else
            {
                // render all visible voxel vertices
                List <Voxel <byte> > curVoxels = VoxGridMan.Voxels();
                for (int i = 0; i < curVoxels.Count; i++)
                {
                    List <Intersector.PointValue <byte> > tmp = new List <Intersector.PointValue <byte> >();
                    tmp.Add(new Intersector.PointValue <byte>(curVoxels[i].point, curVoxels[i].value));
                    content.AddRange(Visualizer.CreateMarkers(tmp,
                                                              VertexMarkerSize, MinColorVal, MaxColorVal, MinColor, MaxColor));
                }
            }
        }
        // visualize voxels
        if (VoxVis)
        {
            for (int i = 0; i < Voxels.Count; i++)
            {
                if (BoundsRandNums[i] <= ShowFrac)
                {
                    Bounds voxBound = new Bounds();
                    voxBound.min = Voxels[i].min;
                    voxBound.max = Voxels[i].max;
                    if (VertexInter.AnyInView(MeshManager.IntersectionPoints(voxBound), SensorField))
                    {
                        content.AddRange(Visualizer.CreateBoundingLines(voxBound, BoundsLineWidth, BoundColors[i]));
                    }
                }
            }
        }
        // visualize mesh bounds
        if (MeshBoundsVis)
        {
            for (int i = 0; i < MeshBounds.Count; i++)
            {
                if (BoundsRandNums[i] <= ShowFrac &&
                    VertexInter.AnyInView(MeshManager.IntersectionPoints(MeshBounds[i]), SensorField))
                {
                    content.AddRange(Visualizer.CreateBoundingLines(MeshBounds[i], BoundsLineWidth, BoundColors[i]));
                }
            }
        }
        VertVis.Visualize(content);
        // color mesh
        if (ColoredMesh)
        {
            // color mesh by voxel grid value if Data Filter is not .all. If so, colored all 'no data'
            if (VoxGridFilter != DataFilter.all)
            {
                Visualizer.ColorMesh(Observer.SurfaceObjects, Observer.ExtraData, MeshGuide,
                                     VoxGridMan, MinColor, MaxColor, NoDataColor, MinColorVal, MaxColorVal);
            }
            else
            {
                Visualizer.ColorMesh(Observer.SurfaceObjects, Observer.ExtraData, MeshGuide,
                                     VoxGridMan, NoDataColor, NoDataColor, NoDataColor, MinColorVal, MaxColorVal);
            }
        }
        SubStopWatch.Stop();
        VertVisSpeed = SubStopWatch.ElapsedTicks / (double)Stopwatch.Frequency;



        StopWatch.Stop();
        DriverSpeed = StopWatch.ElapsedTicks / (double)Stopwatch.Frequency;
    }
Exemple #8
0
    bool connectingToAnotherShape(int x, int y, int origX, int origY)
    {
        MeshMan        shape;
        List <MeshMan> shapes = map.NodeInShapes(new Vector2(x, y));

        shape = map.GetBiggestPolygon(ref shapes);
        if (map.vertices.Count == 0) // first element, add to list of verices
        {
            map.vertices.Add(new Vector2(origX, origY));
        }
        map.endNode = new Vector2(x, y);

        // find index of end node
        var index = shape.nodes.FindIndex(a => a == map.endNode);
        // temporary List of nodes in shape wich we need to add to shape to conncet
        List <Vector2> connectingNodes  = new List <Vector2>();
        List <Vector2> connectingNodes1 = new List <Vector2>();

        List <Vector2> tempVertices_1 = new List <Vector2>(map.vertices);
        List <Vector2> tempVertices_2 = new List <Vector2>(map.vertices);

        Debug.Log("STAR AND END " + map.startNode + " " + map.endNode);
        if (!ReferenceEquals(map.isNodeInShape(map.startNode), map.isNodeInShape(map.endNode)))
        {
            return(false);
        }
        if (map.startNode == map.endNode)
        {
            return(false);
        }
        // Nedd to remember shape
        //if (map.startNode != map.endNode)
        //{
        //    Debug.Log("NOT sAME SHAPE");
        //}

        //Debug.Log("START NODE" + map.startNode);
        //Debug.Log("END NODE  " + map.endNode);

        // Find Path from start to end node
        //Debug.Log("Connecting nodes " );
        // when something goes wrong , dont crash whole PC!!! (fcking BSOD)
        // int fckUpCounter = 0;


        // get Last element from vertices
        Vector2 prevEle = map.vertices[map.vertices.Count - 1];

        // Make both paths
        map.YetDunno(shape, ref connectingNodes, prevEle, index, ref tempVertices_1, 1);
        map.YetDunno(shape, ref connectingNodes1, prevEle, index, ref tempVertices_2, -1);

        //Debug.Log("VERTICES +1 ");
        //foreach (var ele in tempVertices_1)
        //{
        //    Debug.Log(ele);
        //}
        //Debug.Log("VERTICES -1 ");
        //foreach (var ele in tempVertices_2)
        //{
        //    Debug.Log(ele);
        //}

        MeshMan meshData = null;

        Debug.Log("ID : S " + shape.id);


        //if (map.separateShapes)
        //Get helper shape to update , if no exiting , create new
        if (map.separateShapes)
        {
            if (!shape.isRendered)
            {
                Debug.Log("Updating");
                meshData = shape.GetComponent <MeshMan>();
            }
            else
            {
                Debug.Log("Creating");
                GameObject GO = Instantiate(map.trianglePref, map.trianglePref.transform.position, map.trianglePref.transform.rotation) as GameObject;
                meshData = GO.GetComponent <MeshMan>();

                meshData.id = map.ShapeId;
                map.ShapeId++;
            }
        }

        // bigger polygon is union of those two...
        if (map.separateShapes)
        {
            if (map.AreOfPolygon(tempVertices_1) > map.AreOfPolygon(tempVertices_2))
            {
                map.vertices    = new List <Vector2>(tempVertices_2);
                meshData.nodes  = new List <Vector2>(tempVertices_1);
                connectingNodes = connectingNodes1;
            }
            else
            {
                map.vertices   = new List <Vector2>(tempVertices_1);
                meshData.nodes = new List <Vector2>(tempVertices_2);
            }
        }
        else
        {
            // FEJKS !!!!!!!!!!
            // Vertices != Shape ... vertices define actual rendered shape
            //                       shape define just connecting part ... lot of rewrting to correct it.. IMA LAZY
            if (map.AreOfPolygon(tempVertices_1) < map.AreOfPolygon(tempVertices_2))
            {
                map.vertices = new List <Vector2>(tempVertices_2);
            }
            else
            {
                map.vertices    = new List <Vector2>(tempVertices_1);
                connectingNodes = connectingNodes1;
            }
        }
        // RESET Z POSITION OF ORIGINAL SHAPE
        foreach (var ele in shape.nodes)
        {
            Vector3 tempPos = map.graph[(int)ele.x, (int)ele.y].Go.transform.position;
            tempPos.z = 0f;
            map.graph[(int)ele.x, (int)ele.y].Go.transform.position = tempPos;
        }


        foreach (var ele in connectingNodes)
        {
            //  Filling shape
            int temp = map.DeltaMovement(prevEle, ele);
            if (map.currentDir != temp)
            {
                map.shape.Add(prevEle);
                map.currentDir = temp;
            }
            prevEle = ele;
            // Debug.Log("PREV ELE:" + prevEle);
        }

        /// Fix missing nodes in shape
        if (map.DeltaMovement(prevEle, map.startNode) != map.currentDir)
        {
            if (!map.shape.Contains(prevEle))
            {
                // Debug.Log("ADDED prevELE" + prevEle);
                map.shape.Add(prevEle);
            }
        }
        if (map.DeltaMovement(prevEle, map.startNode) != map.fistDirShape)
        {
            if (!map.shape.Contains(map.startNode))
            {
                Debug.Log("ADDED startELE" + map.startNode);
                map.shape.Add(map.startNode);
            }
        }

        // Debug.Log("AREA OF SHAPE :" + map.AreOfPolygon(map.vertices));
        // Draw mesh
        //Debug.Log("VERTICES");
        foreach (var ele in map.vertices)
        {
            Vector3 tempPos = map.graph[(int)ele.x, (int)ele.y].Go.transform.position;
            tempPos.z = -2f;
            map.graph[(int)ele.x, (int)ele.y].Go.transform.position = tempPos;
        }



        MeshMan tempMM = map.CreateMesh();

        tempMM.shapes.AddRange(shape.shapes);
        // Pass reference to helper shape
        if (map.separateShapes)
        {
            shape.helperShape   = meshData;
            tempMM.helperShape  = meshData;
            meshData.isRendered = false;

            Debug.Log("CONNECTED " + meshData.id + " ---> LEFT  S" + tempMM.id + "  RIGHT S" + shape.id);
        }
        else
        {
            Destroy(shape.gameObject);
        }
        map.ClearPath(false);
        return(true);
    }
Exemple #9
0
    public MeshMan CreateMesh()
    {
        //MESH GO
        GameObject GO       = Instantiate(trianglePref, trianglePref.transform.position, trianglePref.transform.rotation) as GameObject;
        MeshMan    meshData = GO.GetComponent <MeshMan>();

        meshData.nodes = new List <Vector2>(vertices);

        meshData.id = ShapeId;
        ShapeId++;



        Vector2 top = shape[0];
        Vector2 bot = shape[0];

        FindBoundingBounds(ref bot, ref top, ref shape);

        Debug.Log("BOUNDING BOUNDS " + bot + "  " + top);

        for (int j = (int)bot.y; j < (int)top.y; j++)
        {
            for (int i = (int)bot.x; i < (int)top.x; i++)
            {
                if (PointInPolygon(new Vector2(i, j), ref shape))
                {
                    if (tiles[i, j] != 0)
                    {
                        graph[i, j].isConnected = true;
                    }
                }
            }
        }

        // JUST FOR TESTING PURPOSES
        // *********************************************************************************
        for (int i = 0; i < mapSizeX; i++)
        {
            for (int j = 0; j < mapSizeY; j++)
            {
                int tile = tiles[i, j];
                if (tile != 0)
                {
                    if (graph[i, j].isConnected)
                    {
                        graph[i, j].Go.GetComponent <SpriteRenderer>().color = Color.blue;
                    }
                }
            }
        }

        // *********************************************************************************



        // MESH RENDERER

        MeshRenderer mshRen = GO.GetComponent <MeshRenderer>();

        ShapeRecognition shapeRec        = FindObjectOfType <ShapeRecognition>();
        Shape            recognizedShape = shapeRec.ValidShape();

        if (!FFA)
        {
            board.ProcessShape(recognizedShape);
        }


        if (recognizedShape != null)
        {
            //Debug.Log("VALID SHAPE, FILL WITH OTHER COLLOR");
            mshRen.material = valid;
            meshData.shapes.Add(recognizedShape);
        }

        else
        {
            mshRen.material = invalid;
        }

        //Aray of nodes to list of vertices in world coordinates
        Vector2[] vertices2D = vertices.ToArray();
        TileToWroldArray(ref vertices2D);

        // Fill shape with triagnels
        Triangulator tr = new Triangulator(vertices2D);

        int[] triangles = tr.Triangulate();

        // Convert to Vector3
        Vector3[] verticesV = new Vector3[vertices2D.Length];
        for (int i = 0; i < verticesV.Length; i++)
        {
            verticesV[i] = new Vector3(vertices2D[i].x, vertices2D[i].y, 0);
        }

        Mesh msh = new Mesh();

        msh.vertices  = verticesV;
        msh.triangles = triangles;

        msh.RecalculateNormals();
        msh.RecalculateBounds();

        MeshFilter filter = GO.GetComponent <MeshFilter>();


        GO.AddComponent <MeshCollider>();

        GO.GetComponent <MeshCollider>().sharedMesh = msh;
        filter.mesh = msh;

        /*
         * foreach (var ele in map.vertices)
         * {
         *
         *  Debug.Log(ele);
         * }
         *
         * for (int i = 0; i < triangles.Length; i++)
         * {
         *
         *  Debug.Log(triangles[i]);
         * }
         */
        return(meshData);
    }
Exemple #10
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // Clicked Mesh Collider
            GameObject go        = MouseCastMesh();
            GameObject clickedGO = MouseCast();
            if (go != null && clickedGO == null)
            {
                // Clear Mesh and Collider
                go.GetComponent <MeshFilter>().mesh = null;

                MeshMan manager = go.GetComponent <MeshMan>();
                Debug.Log("CLEAR MESH");

                //// FIND HELPER SHAPE IN WHICH IS AT LEAST ONE POINT OF SHAPE WE WANT TO DELTE
                //MeshMan helper = null;
                //foreach (var ele in FindObjectsOfType<MeshMan>())
                //{
                //    if (!ele.isRendered)
                //    {
                //        if (ele.nodes.Contains(manager.nodes[0]))
                //        {
                //            helper = ele;
                //            break;
                //        }

                //    }
                //}



                Vector2 top = manager.nodes[0];
                Vector2 bot = manager.nodes[0];
                FindBoundingBounds(ref bot, ref top, ref manager.nodes);

                Debug.Log("BOUNDING BOUNDS " + bot + "  " + top);
                // DELETE INSIDE POINTS
                for (int j = (int)bot.y; j < (int)top.y; j++)
                {
                    for (int i = (int)bot.x; i < (int)top.x; i++)
                    {
                        if (PointInPolygon(new Vector2(i, j), ref manager.nodes))
                        {
                            if (tiles[i, j] != 0)
                            {
                                graph[i, j].Go.GetComponent <Cell>().DeleteLines();
                                graph[i, j].Go.GetComponent <SpriteRenderer>().color = Color.white;
                                graph[i, j].isConnected = false;

                                Vector3 tempPos = graph[i, j].Go.transform.position;
                                tempPos.z = 0f;
                                graph[i, j].Go.transform.position = tempPos;
                            }
                        }
                    }
                }

                bool cointinsEle = false;
                foreach (var ele in manager.nodes)
                {
                    Node toDelete = graph[(int)ele.x, (int)ele.y];
                    Debug.Log(ele.x + " " + ele.y);
                    toDelete.isConnected = false;

                    // Delete lines

                    //LineRenderer line = toDelete.Go.GetComponent<LineRenderer>();
                    //line.SetPosition(0, Vector3.zero);
                    //line.SetPosition(1, Vector3.zero);
                    toDelete.Go.GetComponent <Cell>().DeleteLines();
                    // Enable nodes
                    int numOfNodesShapes = NodesInShapesNum(ele);


                    if ((cointinsEle && numOfNodesShapes <= 2) || (!cointinsEle && numOfNodesShapes <= 1))
                    {
                        toDelete.Go.GetComponent <SpriteRenderer>().color = Color.white;
                        toDelete.isConnected = false;
                        Vector3 tempPos = toDelete.Go.transform.position;
                        tempPos.z = 0f;
                        toDelete.Go.transform.position = tempPos;
                    }
                    else
                    {
                        Debug.Log("FCK : " + NodesInShapesNum(ele));
                    }
                }
                board.DeleteShapes(manager.shapes);
                Destroy(go);
                vertices.Clear();
                shape.Clear();
            }
        }
    }