void PaintMap(SquareGrid graph, AStarSearch astar)
 {
     for(int i = 0; i < graph.height; i++)
     {
         for(int j = 0; j < graph.width; j++)
         {
             Position id = new Position(i, j);
             Position ptr = id;
             if(!astar.cameFrom.TryGetValue(id, out ptr))
             {
                 ptr = id;
                 if (graph.walls.Contains(id))
                 {
                     GetImage((graph.height * i) + j).color = Color.green;
                 }
                 else
                 {
                     var go = mapGroup.transform.GetChild((graph.height * ptr.x) + ptr.y).gameObject;
                     go.GetComponent<Image>().color = Color.grey;
                 }
             }
             else
             {
                 var go = mapGroup.transform.GetChild((graph.height * ptr.x) + ptr.y).gameObject;
                 go.GetComponent<Image>().color = Color.red;
             }
         }
     }
 }
Beispiel #2
0
    public void GenerateMesh(int[,] map, float squareSize)
    {
        triangleDictionary.Clear();
        outlines.Clear();
        checkedVertices.Clear();

        squareGrid = new SquareGrid(map, squareSize);

        vertices  = new List <Vector3>();
        triangles = new List <int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        Mesh mesh = new Mesh();

        GetComponent <MeshFilter>().mesh = mesh;

        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();

        mesh.RecalculateNormals();

        CreateWallMesh();
    }
Beispiel #3
0
    void GenerateSurfaceMeshData(TreeNode rootNode)
    {
        float resolution = 50;

        if (squareGrid == null)
        {
            InitializeMarchingCubes((int)resolution, rootNode);
        }
        float squareSize = rootNode.TreeNodeData.mbounds.width / resolution;

        meshData_Surface = new MeshData();
        squareGrid       = new SquareGrid(MarchMap, squareSize);
        float halfSquare = (squareSize / 2.0f);

        for (int x = 0; x < MarchMap.GetLength(0); x++)
        {
            for (int y = 0; y < MarchMap.GetLength(1); y++)
            {
                int val = rootNode.GetValue(new Vector2(squareSize * x, squareSize * y), 8).mtypeindex;

                MarchMap[x, y] = val;
            }
        }


        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }
    }
Beispiel #4
0
	HashSet<int> checkedVertices = new HashSet<int>(); //Hash used to check vertices and not having to check them again, quicker checks

	public void GenerateMesh(int[,] map, float squareSize) {
		//reset variables with every generation of new mesh for triangledictionary, outlines and checkedVertices
		triangleDictionary.Clear ();
		outlines.Clear ();
		checkedVertices.Clear ();

		squareGrid = new SquareGrid(map, squareSize);

		vertices = new List<Vector3>(); //intialises lists
		triangles = new List<int>();

		//for each square grid triangulate the square
		for (int x = 0; x < squareGrid.squares.GetLength(0); x ++) {
			for (int y = 0; y < squareGrid.squares.GetLength(1); y ++) {
				TriangulateSquare(squareGrid.squares[x,y]);
			}
		}

		Mesh mesh = new Mesh();
		//GetComponent<MeshFilter>().mesh = mesh;
		level.mesh = mesh;

		mesh.vertices = vertices.ToArray(); //covert list to array
		mesh.triangles = triangles.ToArray(); //convert triangles list to array
		mesh.RecalculateNormals();

		CreateWallMesh ();
	}
    public void GenerateMesh(int[,] map, float squareSize)
    {
        squareGrid = new SquareGrid(map, squareSize);

        vertices  = new List <Vector3>();
        triangles = new List <int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        Mesh mesh = new Mesh();

        GetComponent <MeshFilter>().mesh = mesh;

        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        /*
         * MeshCollider mc = GetComponent<MeshCollider>();
         * if (mc != null)
         * {
         *  Destroy(mc);
         *  //mc.enabled = false;
         * }*/
        MeshCollider meshCol = gameObject.AddComponent <MeshCollider>();

        meshCol.sharedMesh = mesh;
    }
Beispiel #6
0
        public void GenerateMesh()
        {
            _mapGenerator.GenerateMap();
            _squareGrid = new SquareGrid(_mapGenerator.Map, 1);

            GetComponent <MeshFilter>().sharedMesh = _squareGrid.Mesh;
        }
    public void GenerateMesh(Map map, float squareSize)
    {
        allVertices.Clear();
        triangles.Clear();
        outlines.Clear();
        trianglesToVertex.Clear();
        checkedVertices.Clear();

        grid = new SquareGrid(map, squareSize);

        for (int x = 0; x < grid.Squares.GetLength(0); x++)
        {
            for (int y = 0; y < grid.Squares.GetLength(1); y++)
            {
                TriangualateSquare(grid.Squares[x, y]);
            }
        }

        Mesh mesh = new Mesh();

        mesh.vertices  = allVertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();
        mesh.name     = "CaveMesh";
        CaveMesh.mesh = mesh;

        CreateWallMesh();
    }
        //The map consists of 0 or 1, where 1 means solid
        //squareSize is how big each square in the grid is
        //The map should be created so that 0,0 is negative X and negative Z, which should maybe change in the future?
        //Maybe more general to be nodebased so we dont have to care about the grid, but marching squares is always on a grid
        public static SquareGrid GenerateMesh(int[,] map, float squareSize)
        {
            //Create the data grid to make it easier to triangulate
            SquareGrid squareGrid = new SquareGrid(map, squareSize);

            //Triangulate
            vertices = new List <Vector3>();

            triangles = new List <int>();

            int xLength = squareGrid.squares.GetLength(0);
            int zLength = squareGrid.squares.GetLength(1);

            for (int x = 0; x < xLength; x++)
            {
                for (int z = 0; z < zLength; z++)
                {
                    Square square = squareGrid.squares[x, z];

                    TriangulateSquare(square);
                }
            }

            //Assign the static vertices and triangles to the grid
            squareGrid.triangles = new List <int>(triangles);

            squareGrid.vertices = new List <Vector3>(vertices);

            return(squareGrid);
        }
Beispiel #9
0
        public static void SquareGridTest()
        {
            using (WorldWindow game = new WorldWindow())
            {
                Vector3 eye = new Vector3(-4, 4, -4);
                game.Camera.LookAt(eye, new Vector3());


                SquareGrid          grid = new SquareGrid(4, 4, 2.3f, 1.1f);
                ShaderModelRenderer sm   = new ShaderModelRenderer(grid);

                game.Models.Add(sm);


                UserInterface ui = new UserInterface(game);

                float time = 0;
                game.UpdateFrame += (o, e) =>
                {
                    time += (float)e.Time;
                    double fps = e.Time == 0 ? 1000 : 1.0 / e.Time;
                    ui.PrintCommonStats(e.Time);
                };

                game.Run(30);
            }
        }
    public void GenerateMesh(int[,,] map, float square_Size)
    {
        squareSize = square_Size;

        triangleDictionary.Clear();
        outlines.Clear();
        checkedVertices.Clear();

        squareGrid = new SquareGrid(map, squareSize);

        vertices = new List<Vector3>();
        triangles = new List<int>();

        for (int x = 0; x < squareGrid.cubes.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.cubes.GetLength(1); y++)
            {
                for (int z = 0; z < squareGrid.cubes.GetLength(2); z++)
                {
                    TriangulateCube(squareGrid.cubes[x, y, z]);
                }
            }
        }

        Mesh mesh = new Mesh();
        GetComponent<MeshFilter>().mesh = mesh;

        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        GetComponent<MeshCollider>().sharedMesh = mesh;
    }
	public void GenerateMesh(int[,] map, float squareSize) {

		triangleDictionary.Clear ();
		outlines.Clear ();
		checkedVertices.Clear ();
		
		MeshCollider collider = gameObject.GetComponent(typeof(MeshCollider)) as MeshCollider;
		if(collider != null){
			Destroy (collider);
		}

		squareGrid = new SquareGrid(map, squareSize);

		vertices = new List<Vector3>();
		triangles = new List<int>();

		for (int x = 0; x < squareGrid.squares.GetLength(0); x ++) {
			for (int y = 0; y < squareGrid.squares.GetLength(1); y ++) {
				TriangulateSquare(squareGrid.squares[x,y]);
			}
		}

		Mesh mesh = new Mesh();
		GetComponent<MeshFilter>().mesh = mesh;

		mesh.vertices = vertices.ToArray();
		mesh.triangles = triangles.ToArray();
		mesh.RecalculateNormals();

		CreateWallMesh ();
	}
Beispiel #12
0
    /// <summary>
    /// Returns the number of locations that are no further than 50 steps away.
    /// </summary>
    /// <param name="favoriteNumber">The office designer's favorite number.</param>
    /// <returns>
    /// The number of locations within 50 steps of the origin.
    /// </returns>
    private static int CountLocationsWithin50Steps(int favoriteNumber)
    {
        int count      = 0;
        int maximum    = 50;
        int dimensions = (maximum / 2) + 1;

        SquareGrid maze = BuildMaze(dimensions, dimensions, favoriteNumber);

        for (int x = 0; x < maze.Width; x++)
        {
            for (int y = 0; y < maze.Height; y++)
            {
                var goal = new Point(x, y);

                double cost = GetMinimumStepsToGoal(maze, goal);

                if (cost <= maximum)
                {
                    count++;
                }
            }
        }

        return(count);
    }
Beispiel #13
0
    private List <int> triangles;    // a list is used to hold the triangles as we dont know how many triangles there will be a run time.

    //generates the mesh
    public void GenerateMesh(int[,] map, float squareSize)
    {
        squareGrid = new SquareGrid(map, squareSize, lava);           // creates a new square grid

        vertices  = new List <Vector3>();                             // creates a new list of vertices
        triangles = new List <int>();                                 // creates a new list of triangles

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)     // loop through all the squares in the square grid x
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++) // loop through all the squares in the square grid y
            {
                TriangulateSquares(squareGrid.squares[x, y]);         // triangle the square for the square at position x and y
            }
        }

        Mesh       mesh       = new Mesh();                  // creates a new mesh
        MeshFilter meshFilter = GetComponent <MeshFilter>(); // gets the mesh filter on the object

        meshFilter.mesh = mesh;                              // sets the meshfilters mesh to the mesh that was just created
        mesh.vertices   = vertices.ToArray();                // feeds the vertices positions into the mesh
        mesh.triangles  = triangles.ToArray();               // feeds the calculated triangles to the mesh
        mesh.RecalculateNormals();

        MeshCollider meshCollider = GetComponent <MeshCollider>(); // Gets the mesh collider component

        meshCollider.sharedMesh = mesh;                            // assigns the created mesh to the mesh collider, this allows us to collider with the generated mesh
    }
    HashSet <int> checkedVertices = new HashSet <int>();          //存放已经检查过的点。

    public void GenerateMesh(int[,] map, float squareSize)
    {
        //清空所有队列,字典,哈希表。因为每次生成新地图都要清空。
        #region Clear All List & Dictionary & HashSet
        vertices.Clear();
        triangles.Clear();
        triangleDictionary.Clear();
        outlines.Clear();
        checkedVertices.Clear();
        #endregion

        squareGrid = new SquareGrid(map, squareSize);

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);    //把所有立方体重新组成比较流畅的多边体。
            }
        }
        SetCaveMesh(map.GetLength(0) * squareSize);             //给Cave添加mesh。

        CalculateMeshOutlines();                                //计算所有需要渲染的外边。

        AddBorderLine();                                        //添加最外边。

        if (is2D)
        {
            Generate2DColliders();                              //生成2D轮廓碰撞框。
        }
        else
        {
            CreateWallMesh();                                   //渲染墙。
        }
    }
    /// <summary>
    /// Main method for building the 2D plane mesh
    /// This uses other methods to implement the marching
    /// squares algorthim.
    /// </summary>
    /// <param name="map"></param>
    /// <param name="squareSize"></param>
    public void BuildMesh(int[,] map, float squareSize)
    {
        triangleDictonary.Clear();
        outlines.Clear();
        checkedVertices.Clear();

        squareGrid = new SquareGrid(map, squareSize);

        vertices  = new List <Vector3>();
        triangles = new List <int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        //Builds New Mesh
        //Gets implemented as component in Mesh Object
        Mesh mesh = new Mesh();

        cave.mesh = mesh;

        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        CreateWallMesh();
    }
Beispiel #16
0
    public void GenerateMesh(int[,] map, float squareSize)
    {
        outline.Clear();                // to reset this variable everytime a new mesh is generated - when user clicks the mouse
        verticesAlreadyChecked.Clear(); // to reset this variable everytime a new mesh is generated - when user clicks the mouse
        triDic.Clear();                 // to reset this variable everytime a new mesh is generated - when user clicks the mouse

        squareGrid = new SquareGrid(map, squareSize);


        vertices  = new List <Vector3> ();
        triangles = new List <int> ();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int z = 0; z < squareGrid.squares.GetLength(1); z++)
            {
                BreakingSquareInTriangules(squareGrid.squares [x, z]);
            }
        }

        Mesh mesh = new Mesh();

        GetComponent <MeshFilter> ().mesh = mesh;
        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        ExtrudeMeshForWalls();
    }
Beispiel #17
0
    public void GenerateMesh(int[,] map, float squareSize)
    {
        outlines.Clear();
        checkedVertices.Clear();
        triangleDictionary.Clear();

        squareGrid = new SquareGrid(map, squareSize);//pasa el mapa y el tamaño del cuadrado
        vertices   = new List <Vector3>();
        triangles  = new List <int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)//anem a visitar cada quadrat
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        Mesh mesh = new Mesh();

        cave.mesh = mesh;

        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        CreateWallMesh();
    }
    public void Init(Buffer <bool> map, bool updateMeshEachFrame, bool createPhysics)
    {
        this.updateMeshEachFrame = updateMeshEachFrame;
        blinkSpeed = Random.Range(1.0f, 2.5f);

        mutableMesh = new MutableMesh();

        SquareGrid grid = new SquareGrid(
            map.width * ShapeAnalizer.scale,
            map.height * ShapeAnalizer.scale,
            mutableMesh
            );

        shapeAnalizer = GenerateMap(map, grid);

        var meshFilter = gameObject.GetComponent <MeshFilter> ();

        Vector3[] vertices      = mutableMesh.GetVertexes().ToArray();
        float     tileAmount    = 0.5f;
        float     textureWidth  = ShapeAnalizer.scale * map.width;
        float     textureHeight = ShapeAnalizer.scale * map.height;

        Vector2[] uvs = new Vector2[vertices.Length];
        for (int i = 0; i < vertices.Length; i++)
        {
            float percentX = Mathf.InverseLerp(0, textureWidth, vertices[i].x) * tileAmount;
            float percentY = Mathf.InverseLerp(0, textureHeight, vertices[i].y) * tileAmount;
            uvs[i] = new Vector2(percentX, percentY);
        }
        var mesh = new Mesh()
        {
            vertices  = vertices,
            triangles = mutableMesh.GetTriangles().ToArray(),
            uv        = uvs,
            uv2       = uvs,
            colors    = mutableMesh.GetColors().ToArray(),
        };

        mesh.RecalculateTangents();
        mesh.RecalculateNormals();
        mesh.RecalculateBounds();
        meshFilter.sharedMesh = mesh;

        GetComponent <Renderer> ().material.color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);

        if (createPhysics)
        {
            CreatePhysics(map);
        }
        transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);

        var pupil = Instantiate(eyePrefab, shapeAnalizer.eye.center, Quaternion.identity, transform);

        pupil.transform.localScale = new Vector3(2.0f, 2.0f, 1.0f);

        shapeAnalizer.eye.SetPupil(pupil, 0.12f);
        shapeAnalizer.eye.MovePupil(Vector3.zero);

        StartCoroutine(BlinkPeriodically());
    }
    public void GenerateMesh(int[,] map, float squareSize)
    {
        outlines.Clear();
        checkedVerts.Clear();

        triDict.Clear();

        vertices = new List<Vector3>();
        tris = new List<int>();

        sGrid = new SquareGrid(map, squareSize);

        for (int x = 0; x < sGrid.squares.GetLength(0); x++)
        {
            for (int z = 0; z < sGrid.squares.GetLength(1); z++)
            {
                TriangulateSquare(sGrid.squares[x, z]);
            }
        }

        if (GetComponent<MapGenerator>().currentGenMode == MapGenerator.GenMode.Walls)
        {
            Mesh mesh = new Mesh();
            GetComponent<MeshFilter>().mesh = mesh;

            mesh.vertices = vertices.ToArray();
            mesh.triangles = tris.ToArray();

            mesh.RecalculateNormals();

            CreateWallMesh();
        }
    }
    public static void GenerateMesh(float[,] map, float squareSize, float[] square_distortion_rows, float[] square_distortion_columns, float height, GameObject gameObject, Color32 color_mesh)
    {
        Mesh         mesh = new Mesh();
        MeshFilter   mf   = (MeshFilter)gameObject.AddComponent(typeof(MeshFilter));
        MeshRenderer mr   = (MeshRenderer)gameObject.AddComponent(typeof(MeshRenderer));

        triangleDictionary.Clear();
        outlines.Clear();
        checkedVertices.Clear();

        squareGrid = new SquareGrid(map, squareSize, square_distortion_rows, square_distortion_columns, height);

        vertices  = new List <Vector3>();
        triangles = new List <int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        Material material_original = Resources.Load("Base Material", typeof(Material)) as Material;

        mr.material.CopyPropertiesFromMaterial(material_original);
        mr.material.name = "Material_" + height.ToString();
        mr.material.SetColor("_Color", color_mesh);

        CreateWallMesh(mesh, mf);
    }
Beispiel #21
0
    public Mesh GenerateMesh(bool[,] map, float squareSize)
    {
        triangleDictionary.Clear();
        outlines.Clear();
        checkedVertices.Clear();
        squareGrid = new SquareGrid(map, squareSize);
        vertices   = new List <Vector3>();
        triangles  = new List <int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }
        Vector2[] uvs = new Vector2[vertices.Count];
        for (int i = 0; i < uvs.Length; i++)
        {
            uvs[i] = new Vector2(vertices[i].x, vertices[i].z);
        }
        Mesh mesh = new Mesh
        {
            vertices  = vertices.ToArray(),
            triangles = triangles.ToArray(),
            uv        = uvs
        };

        mesh.RecalculateNormals();
        return(mesh);
    }
    //Turns the 2D map into the mesh
    public void GenerateMesh(int[,] map, float squareSize)
    {
        triangleDictionary.Clear();
        outlines.Clear();
        checkedVertices.Clear();
        squareGrid = new SquareGrid(map, squareSize);

        vertices = new List<Vector3>();
        trianges = new List<int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        Mesh mesh = new Mesh();
        surface.mesh = mesh;

        mesh.vertices = vertices.ToArray();
        mesh.triangles = trianges.ToArray();
        mesh.RecalculateNormals();

        if (!is2D)
        {
            CreateWallMesh();
        }
    }
Beispiel #23
0
    private HashSet <int> checkedVertices = new HashSet <int>();          //存放已经检查过的点。
    #endregion

    public void GenerateMesh(TileType[,] map, float squareSize)
    {
        #region 每次生成新地图都要清空所有队列,字典,哈希表
        vertices.Clear();
        triangles.Clear();
        triangleDictionary.Clear();
        outlines.Clear();
        checkedVertices.Clear();
        #endregion

        squareGrid = new SquareGrid(map, squareSize);

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);    //把所有方形细分成多个三角形
            }
        }
        SetCaveMesh(map.GetLength(0) * squareSize);             //给Cave添加mesh。

        CalculateMeshOutlines();                                //计算所有需要渲染的外边。

        AddBorderLine();                                        //添加最外边。

        if (is2D)
        {
            Generate2DColliders();                              //生成2D轮廓碰撞框。
        }
        else
        {
            CreateWallMesh();                                   //渲染墙。
            ResetMeshHeight();
        }
    }
    public Mesh triangolate(OIGrid grid)
    {
        int[,] map = grid.asMatrix();
        Vector3 center = Vector3.zero;


        triangleDictionary.Clear();
        outlines.Clear();
        checkedVertices.Clear();

        squareGrid = new SquareGrid(map, SQUARE_SIZE, center);

        vertices  = new List <Vector3>();
        triangles = new List <int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        Mesh mapMesh = new Mesh();

        mapMesh.vertices  = vertices.ToArray();
        mapMesh.triangles = triangles.ToArray();
        //mapMesh.RecalculateNormals();
        //mapMesh.RecalculateBounds();
        return(mapMesh);
    }
Beispiel #25
0
    public void GenerateMesh(int[,] Map, float SquareSize)
    {
        TriangleDictionary.Clear();
        Outlines.Clear();
        CheckedVertices.Clear();

        SqrGrid   = new SquareGrid(Map, SquareSize);
        Vertices  = new List <Vector3>();
        Triangles = new List <int>();

        for (int x = 0; x < SqrGrid.Squares.GetLength(0); x++)
        {
            for (int y = 0; y < SqrGrid.Squares.GetLength(1); y++)
            {
                TriangulateSquare(SqrGrid.Squares[x, y]);
            }
        }

        Mesh mesh = new Mesh();

        GetComponent <MeshFilter>().mesh = mesh;

        mesh.vertices  = Vertices.ToArray();
        mesh.triangles = Triangles.ToArray();
        mesh.RecalculateNormals();

        CreateWallMesh();
    }
    // Generates the Mesh.
    public override void AssembleMap(char[,] map, char wallChar, char roomChar)
    {
        outlines.Clear();
        checkedVertices.Clear();
        triangleDictionary.Clear();

        squareGrid = new SquareGrid(map, wallChar, squareSize);

        vertices  = new List <Vector3>();
        triangles = new List <int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        CreateTopMesh(map.GetLength(0), map.GetLength(1));

        CreateWallMesh();

        CreateFloorMesh(map.GetLength(0), map.GetLength(1));
    }
Beispiel #27
0
        public void GenerateMesh()
        {
            _mapGenerator.GenerateMap();
            _squareGrid = new SquareGrid(_mapGenerator.Map, 1);

            GetComponent<MeshFilter>().sharedMesh = _squareGrid.Mesh;
        }
    public void GenerateMesh(int[,] map, float squareSize, float wallHeight)
    {
        vertices  = new List <Vector3>();
        triangles = new List <int>();

        triangleDictionary = new Dictionary <int, List <Triangle> >();
        outlines           = new List <List <int> >();
        checkedVertices    = new HashSet <int>();

        squareGrid = new SquareGrid(map, squareSize);

        for (int x = 0; x < squareGrid.Squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.Squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.Squares[x, y]);
            }
        }

        cave.mesh = new Mesh();

        cave.mesh.vertices  = vertices.ToArray();
        cave.mesh.triangles = triangles.ToArray();
        cave.mesh.RecalculateNormals();

        CreateWallMesh(wallHeight);
    }
Beispiel #29
0
        public void BasicGridCreation()
        {
            IGridConfiguration conf = CreateTestConfig();
            IGrid grid = new SquareGrid(conf);

            Assert.AreEqual(conf.ColumnCount, grid.Columns.Count);
            Assert.AreEqual(conf.RowCount, grid.Rows.Count);

            foreach (CellCollection column in grid.Columns)
            {
                for (int i = 0; i < column.Count; i++)
                {
                    Assert.IsNotNull(column[i]);
                    Assert.AreEqual(i, column[i].Row);
                }
            }

            foreach (CellCollection row in grid.Rows)
            {
                for (int i = 0; i < row.Count; i++)
                {
                    Assert.IsNotNull(row[i]);
                    Assert.AreEqual(i, row[i].Column);
                }
            }
        }
Beispiel #30
0
        #pragma warning disable S2368 // Public methods should not have multidimensional array parameters
        public IEnumerator GenerateMesh(int[,] map, float squareSize, int wallTile)
        #pragma warning restore S2368 // Public methods should not have multidimensional array parameters
        {
            this.squareSize = squareSize;
            mapSize         = new Vector2(map.GetLength(0), map.GetLength(1));

            squareGrid = new SquareGrid(map, squareSize, wallTile);
            for (int x = 0; x < squareGrid.Squares.GetLength(0); x++)
            {
                for (int y = 0; y < squareGrid.Squares.GetLength(1); y++)
                {
                    TriangulateSquare(squareGrid.Squares[x, y]);
                }
            }

            Mesh mesh = new Mesh();

            meshFilter.mesh = mesh;

            mesh.vertices  = vertices.ToArray();
            mesh.triangles = triangles.ToArray();
            mesh.RecalculateNormals();
            mesh.uv = CreateUV();
            yield return(Wait("Created mesh"));

            yield return(StartCoroutine(Generate2DCollider()));

            GenerateBackground();
        }
Beispiel #31
0
        public void ShiftColumnDown()
        {
            IGridConfiguration conf = CreateTestConfig();
            IGrid grid = new SquareGrid(conf);

            List <ICellContent> contents = new List <ICellContent>(conf.ColumnCount * conf.RowCount);

            FillColumnContents(grid, contents);

            Assert.AreSame(contents[0], grid.Columns[0][0].Content);
            Assert.AreSame(contents[1], grid.Columns[0][1].Content);
            ICellContent firstRowContent = grid.Columns[0][0].Content;

            grid.Accept(new ColumnDownShifter(0, 3));

            Assert.AreSame(firstRowContent, grid.Columns[0][3].Content);

            grid.Accept(new ColumnDownShifter(0, 10));

            Assert.AreSame(firstRowContent, grid.Columns[0][3].Content);

            grid.Accept(new ColumnDownShifter(0, 13));

            Assert.AreSame(firstRowContent, grid.Columns[0][1].Content);
        }
    public Mesh GenerateMesh(Map map, float squareSize)
    {
        vertices = new List<Vector3>();
        triangles = new List<int>();

        triangleDictionary = new Dictionary<int, List<Triangle>>();
        outlines = new List<List<int>>();
        checkedVertices = new HashSet<int>();

        squareGrid = new SquareGrid(map, squareSize);
        for (int x = 0; x < squareGrid.squares.GetLength(0); x ++) {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y ++) {
                TriangulateSquare(squareGrid.squares[x,y]);
            }
        }

        Mesh mesh = new Mesh();
        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();

        mesh.RecalculateNormals();
        mesh.RecalculateBounds();

        if(generateColliders) {
            Generate2DColliders();
        }

        return mesh;
    }
Beispiel #33
0
    public void GenerateMesh(float[,] chunk)
    {
        //Creates or Recreates a mesh and colliders for the clump.
        triangleDictionary.Clear();
        outlines.Clear();
        checkedVertices.Clear();

        squareGrid = new SquareGrid(chunk, SQUARESIZE);

        vertices  = new List <Vector3>();
        triangles = new List <int>();
        colors    = new List <Color>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        Mesh mesh = new Mesh();

        GetComponent <MeshFilter>().mesh = mesh;

        CalculateMeshOutlines();
        mesh.vertices  = vertices.ToArray();
        mesh.colors    = colors.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        Generate2DColliders();
    }
	public void GenerateMesh(int[,] map, float squareSize){
		outline.Clear (); // to reset this variable everytime a new mesh is generated - when user clicks the mouse
		verticesAlreadyChecked.Clear (); // to reset this variable everytime a new mesh is generated - when user clicks the mouse
		triDic.Clear(); // to reset this variable everytime a new mesh is generated - when user clicks the mouse

		squareGrid = new SquareGrid (map, squareSize);


		vertices = new List<Vector3> ();
		triangles = new List<int> ();

		for (int x = 0; x < squareGrid.squares.GetLength (0); x++) {
			for (int z = 0; z < squareGrid.squares.GetLength (1); z++) {
				BreakingSquareInTriangules (squareGrid.squares [x, z]);
			}
		}

		Mesh mesh = new Mesh ();
		GetComponent<MeshFilter> ().mesh = mesh;
		mesh.vertices = vertices.ToArray ();
		mesh.triangles = triangles.ToArray ();
		mesh.RecalculateNormals ();

		ExtrudeMeshForWalls ();
	}
Beispiel #35
0
    private HashSet <int> checkedVertices = new HashSet <int>();          //存放已经检查过的点。

    #endregion

    public void GenerateMesh(TileType[,] map)
    {
        #region 每次生成新地图都要清空所有队列,字典,哈希表
        vertices.Clear();
        triangles.Clear();
        triangleDictionary.Clear();
        outlines.Clear();
        checkedVertices.Clear();
        #endregion

        squareGrid = new SquareGrid(map);

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);    //把所有方形细分成多个三角形
            }
        }
        SetCaveMesh(map.GetLength(0));             //给Cave添加mesh。

        CalculateMeshOutlines();                   //计算所有需要渲染的外边。

        CreateWallMesh();                          //渲染墙。
        ResetMeshHeight();
    }
Beispiel #36
0
        public MainWindow()
        {
            InitializeComponent();

            // TODO: Разобраться с файлом настроек и не городить такие безобразные строчки
            GlobalSettings.EightWay = Properties.Settings.Default.EightWay;

            // Data
            _searchingAlg = new DijkstraSearch();
            _nodeGrid     = SquareGrid.CreateWithForest();
            _start        = _nodeGrid[3, 3];
            _start.Type   = NodeType.Start;
            _goal         = _nodeGrid[8, 7];
            _goal.Type    = NodeType.Goal;
            _nodeGrid.AddWall(8, 1);
            _history = _history = _searchingAlg.SearchWithHistory(_nodeGrid, _start, _goal);

            // View
            GridView.Init(_history);
            GridView.ShowStep(-1);

            GridView.WallAdded    += GridView_WallAdded;
            GridView.WallRemoved  += GridView_WallRemoved;
            GridView.StartChanged += GridView_StartChanged;
            GridView.GoalChanged  += GridView_GoalChanged;
        }
Beispiel #37
0
        protected override void Paint(Graphics graphics, float widthInInches, float heightInInches, float dpiX, float dpiY,
                                      float xMarginInInches, float yMarginInInches, int?pageNumber = null)
        {
            var pen = new Pen(options.Colour);

            IGridPixelDimensions pixelDimensions;
            IGrid grid;

            switch (options.GridType)
            {
            case GridType.Hex:
                pixelDimensions = new HexGridPixelDimensions(xMarginInInches, yMarginInInches, widthInInches,
                                                             heightInInches, options.PolygonsPerInch, dpiX, dpiY);
                grid = new HexGrid(pixelDimensions);
                break;

            case GridType.Square:
                pixelDimensions = new SquareGridPixelDimensions(xMarginInInches, yMarginInInches, widthInInches,
                                                                heightInInches, options.PolygonsPerInch, dpiX, dpiY);
                grid = new SquareGrid(pixelDimensions);
                break;

            default:
                throw new IndexOutOfRangeException();
            }

            var pathDrawer = new PathDrawer(graphics, pen);

            pathDrawer.DrawPaths(grid.GetGrid());
        }
        public static void AStar()
        {
            var grid = new SquareGrid(10, 10);

            for (var x = 1; x < 4; x++)
            {
                for (var y = 7; y < 9; y++)
                {
                    grid.Walls.Add(new Location(x, y));
                }
            }
            grid.Forests = new HashSet <Location>
            {
                new Location(3, 4), new Location(3, 5),
                new Location(4, 1), new Location(4, 2),
                new Location(4, 3), new Location(4, 4),
                new Location(4, 5), new Location(4, 6),
                new Location(4, 7), new Location(4, 8),
                new Location(5, 1), new Location(5, 2),
                new Location(5, 3), new Location(5, 4),
                new Location(5, 5), new Location(5, 6),
                new Location(5, 7), new Location(5, 8),
                new Location(6, 2), new Location(6, 3),
                new Location(6, 4), new Location(6, 5),
                new Location(6, 6), new Location(6, 7),
                new Location(7, 3), new Location(7, 4),
                new Location(7, 5)
            };

            // Run A*
            var astar = new AStarSearch(grid, new Location(1, 4), new Location(8, 5));

            DrawGrid(grid, astar);
        }
Beispiel #39
0
        public void CreateSquareGridTest_1x1()
        {
            int   xColumns = 1;
            int   zRows    = 1;
            float xPitch   = 10;
            float zPitch   = 10;

            Vector3[] vertices;
            int[]     indices;
            BeginMode drawMode;

            SquareGrid.CreateSquareGrid(xColumns, zRows, xPitch, zPitch, out vertices, out indices, out drawMode);

            Assert.AreEqual(BeginMode.TriangleStrip, drawMode);
            Assert.AreEqual(4, vertices.Length);
            Assert.AreEqual(4, indices.Length);

            Vector3[] expectedV = new Vector3[]
            {
                new Vector3(0, 0, 0),
                new Vector3(xPitch, 0, 0),
                new Vector3(0, 0, zPitch),
                new Vector3(xPitch, 0, zPitch)
            };
            int[] expectedI = new int[] { 0, 2, 1, 3 };


            for (int i = 0; i < vertices.Length; i++)
            {
                Assert.AreEqual(expectedV[i], vertices[i]);
                Assert.AreEqual(expectedI[i], indices[i]);
            }
        }
Beispiel #40
0
    public void GenerateMesh(int[,] map, float squareSize)
    {
        // Clear all the lists every time we want to make a new mesh!
        triangleDictionary.Clear ();
        outlines.Clear ();
        checkedVertices.Clear ();

        squareGrid = new SquareGrid (map, squareSize);

        vertices = new List<Vector3>();
        triangles = new List<int>();

        for (int x = 0; x<squareGrid.squares.GetLength(0); x++) {
            for (int y = 0; y<squareGrid.squares.GetLength(1); y++) {
                TriangulateSquare (squareGrid.squares [x, y]);
            }
        }

        Mesh mesh = new Mesh ();
        GetComponent<MeshFilter> ().mesh = mesh;

        mesh.vertices = vertices.ToArray ();
        mesh.triangles = triangles.ToArray ();
        mesh.RecalculateNormals ();

        if (!is2D) {
            CreateWallMesh ();
        }
    }
Beispiel #41
0
    public void GenerateMesh(int[,] map, float squareSize)
    {
        if(wallCollider == null)
        {
            wallCollider = walls.gameObject.AddComponent<MeshCollider> ();
        }
        outlines.Clear();
        checkedVertices.Clear ();
        triangleDictionary.Clear();

        squareGrid = new SquareGrid(map, squareSize);

        vertices = new List<Vector3>();
        triangles = new List<int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for(int y =0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x,y]);
            }
        }

        Mesh mesh = new Mesh();
        cave.mesh = mesh;
        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        if(!is2D) {
            CreateWallMesh();
        }
    }
Beispiel #42
0
    public void GenerateFloorMesh(int[,] map, float squareSize)
    {
        squareGrid = new SquareGrid(map, squareSize);

        vertices = new List<Vector3>();
        triangles = new List<int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x ++) {
            for (int z = 0; z < squareGrid.squares.GetLength(1); z ++) {
                TriangulateSquare(squareGrid.squares[x,z]);
            }
        }

        Mesh mesh 		 = new Mesh(); 			// The mesh (verticies, uvs, triangels).
        GameObject floor = new GameObject();	// The GameObject the mesh should be attached to.
        floor.name 		 = "Floor";				// Name of the GameObject that appears in the "hierarchy list"
        mesh.name 		 = "FloorPMesh" ;  		// Name of the mesh, appears in the inspector under meshRenderer (if u select the Gameobject floor)

        mesh.vertices  = vertices.ToArray(); 	// Assign the possitions of the verticies with a array of vector3's
        mesh.triangles = triangles.ToArray();  	// Generate the triangels from positions of the vertices
        mesh.RecalculateNormals();

        // Generate UVs
        int tileAmount = 100;
        Vector2[] uvs = new Vector2[vertices.Count];
        for (int i =0; i < vertices.Count; i ++) {
            float percentX = Mathf.InverseLerp(-map.GetLength(0)*squareSize, map.GetLength(0)*squareSize,vertices[i].x) * tileAmount;
            float percentY = Mathf.InverseLerp(-map.GetLength(0)*squareSize, map.GetLength(0)*squareSize,vertices[i].z) * tileAmount;
            uvs[i] = new Vector2(percentX,percentY);
        }
        mesh.uv = uvs;

        // add the meshfilter to the gameobject and assign the mesh we just created.
        floor.AddComponent<MeshFilter>().mesh = mesh;

        floor.AddComponent<MeshCollider>();

        floor.tag = "Floor";

        //MOUSEOVER
        floor.AddComponent<MapMouseOver>();

        // add the meshrenderer component to the gameObject. (and store the component in a variable)
        MeshRenderer renderer = floor.AddComponent<MeshRenderer>();

        //move the floor in y
        floor.transform.Translate( new Vector3 (0, -terrainHeight, 0) );

        /* LETS NOT DO THIS
        // add the standard shader to the meshRender component
        renderer.material.shader = Shader.Find("Standard");

        // Assign a texture
        Texture2D text = (Texture2D)Resources.Load("Textures/MapTextures/Floor_Tile_01");
        renderer.material.mainTexture = (Texture2D)text;
        */
        //LETS DO THIS INSTEAD
        renderer.material = Resources.Load("Materials/MapMaterials/Mat_Floor_Tile_01") as Material;
    }
    public void GenerateMesh(int[,] map)
    {
        //		squareWidth = squareSize;
        triangleDictionary.Clear ();
        outlines.Clear ();
        checkedVertices.Clear ();

        squareGrid = new SquareGrid(map, squareWidth);

        vertices = new List<Vector3>();
        triangles = new List<int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x ++) {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y ++) {
                TriangulateSquare(squareGrid.squares[x,y]);
            }
        }

        Mesh mesh = new Mesh();
        cave.mesh = mesh;

        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        int tileAmount = 15;
        Vector2[] uvs = new Vector2[vertices.Count];
        for (int i =0; i < vertices.Count; i ++) {
            float percentX = Mathf.InverseLerp(-map.GetLength(0)/2*squareWidth,map.GetLength(0)/2*squareWidth,vertices[i].x) * tileAmount;
            float percentY = Mathf.InverseLerp(-map.GetLength(1)/2*squareWidth,map.GetLength(1)/2*squareWidth,vertices[i].z) * tileAmount;
            uvs[i] = new Vector2(percentX,percentY);
        }
        mesh.uv = uvs;

        CreateWallMesh ();

        Mesh fl = new Mesh();

        Vector3[] flv = {new Vector3(-map.GetLength(0)*squareWidth/2,-5*squareWidth,-map.GetLength(1)*squareWidth/2),
            new Vector3(map.GetLength(0)*squareWidth/2,-5*squareWidth,-map.GetLength(1)*squareWidth/2),
            new Vector3(-map.GetLength(0)*squareWidth/2,-5*squareWidth,map.GetLength(1)*squareWidth/2),
            new Vector3(map.GetLength(0)*squareWidth/2,-5*squareWidth,map.GetLength(1)*squareWidth/2) };

        int[] flt = {0,2,3, 3,1,0};

        fl.vertices = flv;
        fl.triangles = flt;
        floor.mesh = fl;
        MeshCollider floorCollider = floor.gameObject.AddComponent<MeshCollider> ();
        floorCollider.sharedMesh = fl;
        fl.RecalculateNormals();
        float tileAmountX = map.GetLength(0)/2;
        float tileAmountY = map.GetLength(1);
        Vector2[] uv = {new Vector2(0,0), new Vector2(tileAmountX,0),new Vector2(0,tileAmountY),new Vector2(tileAmountX,tileAmountY)};
        fl.uv = uv;
    }
 void ResetMapGroup(SquareGrid graph)
 {
     for(int i = 0; i < graph.height; i++)
     {
         for (int j = 0; j < graph.width; j++)
         {
             GetImage((graph.height * i) + j).color = graph.walls.Contains(new Position(i, j)) ? Color.white : Color.gray;
         }
     }
 }
    public void GenerateMesh(int[,] map, float squareSize)
    {
        outlines.Clear(); //Reset these variables with each new mesh
        checkedVertices.Clear();
        triangleDictionary.Clear();

        squareGrid = new SquareGrid(map, squareSize);

        vertices = new List<Vector3>();
        triangles = new List<int>();

        //        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        //        {
        //            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
        //            {
        //                TriangulateSquare(squareGrid.squares[x, y]);
        //            }
        //        }

        for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
        {
            for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        Mesh mesh = new Mesh();
        cave.mesh = mesh;

        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        Vector2[] uvs = new Vector2[vertices.Count];
        for (int i = 0; i < vertices.Count; i++)
        {

            float percentX = Mathf.InverseLerp(-map.GetLength(0) / 2 * squareSize, map.GetLength(0) / 2 * squareSize, vertices[i].x)*tileAmount;
            float percentY = Mathf.InverseLerp(-map.GetLength(0) / 2 * squareSize, map.GetLength(0) / 2 * squareSize, vertices[i].z)*tileAmount;

            uvs[i] = new Vector2(percentX, percentY);
        }
        mesh.uv = uvs;

        if (is2D)
        {
            Generate2DColliders();
        }
        else
        {
            CreateWallMesh();
        }
    }
Beispiel #46
0
    public void GenerateMesh(int[,] map, float squareSize, float wallHeight, bool is2D)
    {
        outlines.Clear();
        checkedVertices.Clear();
        triangleDictionary.Clear();

        squareGrid = new SquareGrid(map, squareSize);

        vertices = new List<Vector3>();
        triangles = new List<int>();
        cappedVertexLists = new List<List<Vector3>>();
        cappedTriangleLists = new List<List<int>>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        if (is2D)
        {
            CreateCeilingMesh(map, squareSize);

            foreach (var item in GameObject.FindGameObjectsWithTag("Wall"))
            {
                if (Application.isPlaying)
                    Destroy(item);
                else
                    DestroyImmediate(item);
            }

            cave.transform.rotation = Quaternion.Euler(270, 0, 0);
            Generate2DColliders();
        }
        else
        {
            CreateCeilingMesh(map, squareSize);

            EdgeCollider2D[] currentColliders = GetComponents<EdgeCollider2D>();
            foreach (var collider in currentColliders)
            {
                if (Application.isPlaying)
                    Destroy(collider);
                else
                    DestroyImmediate(collider);
            }

            cave.transform.rotation = Quaternion.Euler(0, 0, 0);
            CreateWallMesh(wallHeight);
        }
    }
    public void GenerateMesh(int[,] map, float squareSize)
    {
        vertics = new List<Vector3>();
        triangles = new List<int>();

        trianglesDictionary = new Dictionary<int, List<Triangle>>();
        outLines = new List<List<int>>();
        checkedVertices = new HashSet<int>();

        squareGrid = new SquareGrid(map, squareSize);

        CreateFloorMesh();
        CreateWallMesh();
    }
    void Start()
    {
        var graph = new SquareGrid(5, 5);
        for(int i = 0; i < 4; i++)
        {
            graph.walls.Add(new Position(i, 1));
        }

        ResetMapGroup(graph);

        var astar = new AStarSearch(graph, new Position(0, 0), new Position(0, 2));

        PaintMap(graph, astar);
    }
Beispiel #49
0
    public void GenerateMesh(int[,] map, float squareSize)
    {
        triangleDictionary.Clear ();
        outlines.Clear ();
        checkedVertices.Clear ();

        squareGrid = new SquareGrid(map, squareSize);

        vertices = new List<Vector3>();
        triangles = new List<int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x ++) {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y ++) {
                TriangulateSquare(squareGrid.squares[x,y]);
            }
        }

        Mesh mesh = new Mesh();
        cave.mesh = mesh;

        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        int tileAmount = 10;
        Vector2[] uvs = new Vector2[vertices.Count];
        for (int i =0; i < vertices.Count; i ++) {
            float percentX = Mathf.InverseLerp(-map.GetLength(0)/2*squareSize,map.GetLength(0)/2*squareSize,vertices[i].x) * tileAmount;
            float percentY = Mathf.InverseLerp(-map.GetLength(0)/2*squareSize,map.GetLength(0)/2*squareSize,vertices[i].z) * tileAmount;
            uvs[i] = new Vector2(percentX,percentY);
        }
        mesh.uv = uvs;

        if (Walldcs == null) {
            Walldcs = new List<GameObject> ();
        } else {
            foreach (GameObject g in Walldcs) {
                Destroy(g);
            }
            Walldcs.Clear();
        }

        if (is2D) {
            Generate2DColliders();
        } else {
            CreateWallMesh ();
            PlaceWalldcs();
        }
    }
Beispiel #50
0
    public void GenerateMesh(int[,] map, float squareSize)
    {
        squareGrid = new SquareGrid(map, squareSize);

        vertices = new List<Vector3>();
        triangles = new List<int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x ++) {
            for (int z = 0; z < squareGrid.squares.GetLength(1); z ++) {
                TriangulateSquare(squareGrid.squares[x,z]);
            }
        }

        Mesh mesh 		 = new Mesh(); 			// The mesh (verticies, uvs, triangels).
        GameObject roof  = new GameObject();	// The GameObject the mesh should be attached to.
        roof.name 		 = "Roof";				// Name of the GameObject that appears in the "hierarchy list"
        mesh.name 		 = "RoofPMesh" ;  		// Name of the mesh, appears in the inspector under meshRenderer (if u select the Gameobject floor)

        mesh.vertices = vertices.ToArray(); 	// Assign the possitions of the verticies with a array of vector3's
        mesh.triangles = triangles.ToArray();  	// Generate the triangels from positions of the vertices
        mesh.RecalculateNormals();

        // add the meshfilter to the gameobject and assign the mesh we just created.
        roof.AddComponent<MeshFilter>().mesh = mesh;

        // add the meshrenderer component to the gameObject. (and store the component in a variable)
        MeshRenderer renderer = roof.AddComponent<MeshRenderer>();

        // add the standard material to the meshRender component
        renderer.material.shader = Shader.Find("Standard");

        // Generate UVs
        int tileAmount = 32;
        Vector2[] uvs = new Vector2[vertices.Count];
        for (int i =0; i < vertices.Count; i ++) {
            float percentX = Mathf.InverseLerp(-map.GetLength(0)*squareSize, map.GetLength(0)*squareSize,vertices[i].x) * tileAmount;
            float percentY = Mathf.InverseLerp(-map.GetLength(0)*squareSize, map.GetLength(0)*squareSize,vertices[i].z) * tileAmount;
            uvs[i] = new Vector2(percentX,percentY);
        }
        mesh.uv = uvs;

        // Assign a texture
        Texture2D text = (Texture2D)Resources.Load("Textures/MapTextures/Roof_Tile_01");
        renderer.material.mainTexture = (Texture2D)text;

        CreateWallMesh();
    }
	public void GenerateMesh(int[,] map, float squareSize) {
		squareGrid = new SquareGrid(map, squareSize);

		vertices = new List<Vector3>();
		triangles = new List<int>();

		for (int x = 0; x < squareGrid.squares.GetLength(0); x ++) {
			for (int y = 0; y < squareGrid.squares.GetLength(1); y ++) {
				TriangulateSquare(squareGrid.squares[x,y]);
			}
		}

		Mesh mesh = new Mesh();
		GetComponent<MeshFilter>().mesh = mesh;

		mesh.vertices = vertices.ToArray();
		mesh.triangles = triangles.ToArray();
		mesh.RecalculateNormals();

	}
Beispiel #52
0
    public void GenerateMesh(int[,] map, float squareSize)
    {
        outlines.Clear ();
        checkedVertices.Clear ();
        triangleDictionary.Clear ();

        squareGrid = new SquareGrid (map, squareSize);

        vertices = new List<Vector3> ();
        triangles = new List<int> ();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++) {
            for (int y =0; y <squareGrid.squares.GetLength(1); y++) {
                TriangulateSquare(squareGrid.squares[x,y]);
            }
        }

        Mesh mesh = new Mesh ();
        water.mesh = mesh;

        mesh.vertices = vertices.ToArray ();
        mesh.triangles = triangles.ToArray ();
        mesh.RecalculateNormals ();

        int tileAmount = 10;
        Vector2[] uvs = new Vector2[vertices.Count];
        for (int i = 0; i < vertices.Count; i++) {
            float percentX = Mathf.InverseLerp(-map.GetLength(0)/2*squareSize, map.GetLength(0)/2*squareSize, vertices[i].x) * tileAmount;
            float percentY = Mathf.InverseLerp(-map.GetLength(0)/2*squareSize, map.GetLength(0)/2*squareSize, vertices[i].z) * tileAmount;
            uvs[i] = new Vector2(percentX, percentY);
        }
        mesh.uv = uvs;

        // NOTE: should only create walls if it is a 3D camera view
        if (is2D) {
            Generate2DColliders();
        } else {
            CreateWallMesh ();

        }
    }
Beispiel #53
0
    public void GenerateMesh(int[,] map, float squareSize)
    {
        trianglDictionary.Clear();
        outlines.Clear();
        checkedVertices.Clear();

        squareGrid = new SquareGrid(map, squareSize);
        vertices = new List<Vector3>();
        triangles = new List<int>();

        for (int x = 0; x < squareGrid.squares.GetLength(0); x++)
        {
            for (int y = 0; y < squareGrid.squares.GetLength(1); y++)
            {
                TriangulateSquare(squareGrid.squares[x, y]);

            }
        }

        Mesh mesh = new Mesh();
           cave.mesh = mesh;

        mesh.vertices = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateNormals();

        Vector2[] uvs = new Vector2[vertices.Count];

        for (int i = 0; i < vertices.Count; i++)
        {
            float percentX = Mathf.InverseLerp(-map.GetLength(0)/2*squareSize, map.GetLength(0)/2*squareSize,
                vertices[i].x*tileTextureValue);
            float percentY = Mathf.InverseLerp(-map.GetLength(0) / 2 * squareSize, map.GetLength(0)/2 * squareSize,
                vertices[i].z*tileTextureValue);

            uvs[i] = new Vector2(percentX,percentY);
        }
        mesh.uv = uvs;

        CreateWallMesh();
    }
    public void GenerateMesh(int[,] map, float squareSize)
    {
        triangleDictionary.Clear ();
        outlines.Clear ();
        checkedVertices.Clear ();

        squareGrid = new SquareGrid (map, squareSize);

        vertices = new List<Vector3>();
        triangles = new List<int>();

        for (int x = 0; x < squareGrid.squares.GetLength (0); x++) {
            for (int y = 0; y < squareGrid.squares.GetLength (1); y++) {
                TriangulateSquare(squareGrid.squares[x, y]);
            }
        }

        Mesh mesh = new Mesh ();
        GetComponent<MeshFilter> ().mesh = mesh;
        mesh.vertices = vertices.ToArray ();
        mesh.triangles = triangles.ToArray ();
        //mesh.Optimize ();
        mesh.RecalculateNormals ();

        int tileAmount = 3;
        Vector2[] uvs = new Vector2[vertices.Count];
        for (int i =0; i < vertices.Count; i ++) {
            float percentX = Mathf.InverseLerp(-map.GetLength(0)/2*squareSize,map.GetLength(0)/2*squareSize,vertices[i].x) * tileAmount;
            float percentY = Mathf.InverseLerp(-map.GetLength(1)/2*squareSize,map.GetLength(1)/2*squareSize,vertices[i].y) * tileAmount;
            uvs[i] = new Vector2(percentX,percentY);
        }
        mesh.uv = uvs;

        GenerateColliders ();
        //CreateWallMesh();
    }
 public void GenerateMesh(int[,] map, float squareSize)
 {
     squareGrid = new SquareGrid(map, squareSize);
 }
Beispiel #56
0
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 public void GenerateMesh()
 {
     squareGrid = new SquareGrid(grid, xSpacing, ySpacing);
 }