Ejemplo n.º 1
0
        public void CreateCorner(VertexGenerator vg, TerrainPiece previousTerrain, TerrainPiece currentTerrain, Transform newParent)
        {
            //Our plane is made up of the last top and bottom verts of the previous mesh, and the first top and bottom verts of the current mesh
            List <Vector3> topVerticies    = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Front, true);
            List <Vector3> bottomVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Front, false);

            //Create our front mesh piece
            MeshPiece meshPiece = new MeshPiece(vg, MeshPiece.Plane.Front, settings);

            meshPiece.CreateCorner(topVerticies, bottomVerticies);

            //The first mesh could be null if we are below the minimum verticies we need to create a plane
            if (meshPiece.MeshObject != null)
            {
                TransformHelpers th = new TransformHelpers();

                //Now we've created the front of our mesh
                InstantiateTerrainObject(0f, newParent);
                MeshPieces.Add(meshPiece);

                //Add detail mesh
                if (settings.DrawDetailMeshRenderer)
                {
                    MeshPiece meshPieceDetail = new MeshPiece(vg, MeshPiece.Plane.Detail, settings);
                    topVerticies    = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Detail, true);
                    bottomVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Detail, false);
                    meshPieceDetail.CreateCorner(topVerticies, bottomVerticies);
                    MeshPieces.Add(meshPieceDetail);
                }

                if (settings.DrawTopMeshCollider || settings.DrawTopMeshRenderer)
                {
                    //Create the verticies for the top of our mesh, and add that too
                    MeshPiece meshPieceTop = new MeshPiece(vg, MeshPiece.Plane.Top, settings);

                    //Use the top verts as our bottom z row
                    bottomVerticies = th.CopyList(topVerticies);
                    Vector3 firstBottomVertex = topVerticies[0];

                    //Then shift the top verts into the z plane
                    topVerticies = th.MoveStartVertex(topVerticies, firstBottomVertex, new Vector3(firstBottomVertex.x, firstBottomVertex.y, firstBottomVertex.z + settings.TopPlaneHeight), false);
                    meshPieceTop.CreateCorner(topVerticies, bottomVerticies);
                    if (settings.TopPhysicsMaterial2D != null)
                    {
                        meshPieceTop.edgeCollider.sharedMaterial = settings.TopPhysicsMaterial2D; // assign Physics Material if any
                    }
                    if (settings.TerrainLayer != 0)
                    {
                        meshPieceTop.MeshObject.layer = settings.TerrainLayer; // assign Layer if any
                    }
                    MeshPieces.Add(meshPieceTop);
                }

                //Just to tidy up the heirarchy
                ParentMeshesToTerrainObject();
            }
        }
Ejemplo n.º 2
0
        private void SetVerticies(Vector3 origin, float angle, List<Vector3> keyVerticies)
        {
			if (keyVerticies !=null){KeyTopVerticies = keyVerticies;}
			
			//Don't try and set the vertices if we're below the min we need for a plane
			if (BelowMinVerts()){return;}
            if (vg.CurrentTerrainRule == null) { return; }

          
            TransformHelpers th = new TransformHelpers();

            AllTopVerticies = vg.GenerateCalculatedVertices(KeyTopVerticies);

            //For the front plane, set a fixed lower boundary on the verts (bottom of mesh will be a straight line)
            if (PlaneType == Plane.Front)
            {               
                Vector3 firstBottomVertex = AllTopVerticies[0];
                Vector3 shift = new Vector3(firstBottomVertex.x, firstBottomVertex.y - settings.MainPlaneHeight, firstBottomVertex.z);

                AllBottomVerticies = th.MoveStartVertex(AllTopVerticies, AllTopVerticies[0], shift, true);
                KeyBottomVerticies = th.MoveStartVertex(KeyTopVerticies, AllTopVerticies[0], shift, true);

                //Test perp verts
                //Vector3 shift = new Vector3(firstBottomVertex.x, firstBottomVertex.y, firstBottomVertex.z);
                //AllBottomVerticies = th.GetPerpendicularOffset(AllTopVerticies, settings.MainPlaneHeight);
                //KeyBottomVerticies = th.GetPerpendicularOffset(KeyTopVerticies, settings.MainPlaneHeight);
            }

            if (PlaneType == Plane.Detail)
            {
                Vector3 firstBottomVertex = th.CopyVertex(AllTopVerticies[0]);
                Vector3 shift = new Vector3(firstBottomVertex.x, firstBottomVertex.y - settings.DetailPlaneHeight, firstBottomVertex.z);

                AllBottomVerticies = th.MoveStartVertex(AllTopVerticies,firstBottomVertex, shift, true);
                KeyBottomVerticies = th.MoveStartVertex(KeyTopVerticies, firstBottomVertex, shift, true);
            }

            //For the top of the mesh, shift the verticies in the z direction
            if (PlaneType == Plane.Top)
            {
               
                //The bottom verts are a copy of the top
                AllBottomVerticies = th.CopyList(AllTopVerticies);
                KeyBottomVerticies = th.CopyList(KeyTopVerticies);
				
				Vector3 firstBottomVertex = AllTopVerticies[0];

                //Then shift the top verts into the z plane
                AllTopVerticies = th.MoveStartVertex(AllTopVerticies, AllTopVerticies[0], new Vector3(firstBottomVertex.x, firstBottomVertex.y, firstBottomVertex.z + settings.TopPlaneHeight), false);
            }


            //Now stich top and bottom verticies together into a plane
            PlaneVerticies = vg.GetPlaneVerticies(AllBottomVerticies, AllTopVerticies);


            //For the top plane we have to move our point of origin based on the plane height
            if (PlaneType == Plane.Top)
            {
                origin = new Vector3(origin.x, origin.y, origin.z + settings.TopPlaneHeight);
            }

			
			//Now move the whole plane to the point of origin (usually where the last mesh ended)
            //Move relative to the vertex at index 1 (the top of the plane) instead of zero (the bottom of the plane) since we want to match the top of the meshes
            PlaneVerticies = th.MoveStartVertex(PlaneVerticies, PlaneVerticies[1], origin, false);

            //Store the rotated verticies so we know where the actual end point of the mesh is (and where to start the next one)
            //Create the mesh from the rotate verticies, but generate it from the non-rotated ones
            if (angle!=0)
            {
                RotatedPlaneVerticies = th.RotateVertices(PlaneVerticies, angle);	
			    RotatedPlaneVerticies = th.MoveStartVertex(RotatedPlaneVerticies, RotatedPlaneVerticies[1], origin, false);
            }
            else
            {
                RotatedPlaneVerticies = PlaneVerticies;
            }

           
        }
Ejemplo n.º 3
0
        private void SetVerticies(Vector3 origin, float angle, List <Vector3> keyVerticies)
        {
            if (keyVerticies != null)
            {
                KeyTopVerticies = keyVerticies;
            }

            //Don't try and set the vertices if we're below the min we need for a plane
            if (BelowMinVerts())
            {
                return;
            }
            if (vg.CurrentTerrainRule == null)
            {
                return;
            }


            TransformHelpers th = new TransformHelpers();

            AllTopVerticies = vg.GenerateCalculatedVertices(KeyTopVerticies);

            //For the front plane, set a fixed lower boundary on the verts (bottom of mesh will be a straight line)
            if (PlaneType == Plane.Front)
            {
                Vector3 firstBottomVertex = AllTopVerticies[0];
                Vector3 shift             = new Vector3(firstBottomVertex.x, firstBottomVertex.y - settings.MainPlaneHeight, firstBottomVertex.z);

                AllBottomVerticies = th.MoveStartVertex(AllTopVerticies, AllTopVerticies[0], shift, true);
                KeyBottomVerticies = th.MoveStartVertex(KeyTopVerticies, AllTopVerticies[0], shift, true);

                //Test perp verts
                //Vector3 shift = new Vector3(firstBottomVertex.x, firstBottomVertex.y, firstBottomVertex.z);
                //AllBottomVerticies = th.GetPerpendicularOffset(AllTopVerticies, settings.MainPlaneHeight);
                //KeyBottomVerticies = th.GetPerpendicularOffset(KeyTopVerticies, settings.MainPlaneHeight);
            }

            if (PlaneType == Plane.Detail)
            {
                Vector3 firstBottomVertex = th.CopyVertex(AllTopVerticies[0]);
                Vector3 shift             = new Vector3(firstBottomVertex.x, firstBottomVertex.y - settings.DetailPlaneHeight, firstBottomVertex.z);

                AllBottomVerticies = th.MoveStartVertex(AllTopVerticies, firstBottomVertex, shift, true);
                KeyBottomVerticies = th.MoveStartVertex(KeyTopVerticies, firstBottomVertex, shift, true);
            }

            //For the top of the mesh, shift the verticies in the z direction
            if (PlaneType == Plane.Top)
            {
                //The bottom verts are a copy of the top
                AllBottomVerticies = th.CopyList(AllTopVerticies);
                KeyBottomVerticies = th.CopyList(KeyTopVerticies);

                Vector3 firstBottomVertex = AllTopVerticies[0];

                //Then shift the top verts into the z plane
                AllTopVerticies = th.MoveStartVertex(AllTopVerticies, AllTopVerticies[0], new Vector3(firstBottomVertex.x, firstBottomVertex.y, firstBottomVertex.z + settings.TopPlaneHeight), false);
            }


            //Now stich top and bottom verticies together into a plane
            PlaneVerticies = vg.GetPlaneVerticies(AllBottomVerticies, AllTopVerticies);


            //For the top plane we have to move our point of origin based on the plane height
            if (PlaneType == Plane.Top)
            {
                origin = new Vector3(origin.x, origin.y, origin.z + settings.TopPlaneHeight);
            }


            //Now move the whole plane to the point of origin (usually where the last mesh ended)
            //Move relative to the vertex at index 1 (the top of the plane) instead of zero (the bottom of the plane) since we want to match the top of the meshes
            PlaneVerticies = th.MoveStartVertex(PlaneVerticies, PlaneVerticies[1], origin, false);

            //Store the rotated verticies so we know where the actual end point of the mesh is (and where to start the next one)
            //Create the mesh from the rotate verticies, but generate it from the non-rotated ones
            if (angle != 0)
            {
                RotatedPlaneVerticies = th.RotateVertices(PlaneVerticies, angle);
                RotatedPlaneVerticies = th.MoveStartVertex(RotatedPlaneVerticies, RotatedPlaneVerticies[1], origin, false);
            }
            else
            {
                RotatedPlaneVerticies = PlaneVerticies;
            }
        }
Ejemplo n.º 4
0
        public void CreateCorner(VertexGenerator vg, TerrainPiece previousTerrain, TerrainPiece currentTerrain)
        {
            //Our plane is made up of the last top and bottom verts of the previous mesh, and the first top and bottom verts of the current mesh
            List<Vector3> topVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Front, true);
            List<Vector3> bottomVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Front, false);

            //Create our front mesh piece
            MeshPiece meshPiece = new MeshPiece(vg, MeshPiece.Plane.Front, settings);
            meshPiece.CreateCorner(topVerticies, bottomVerticies);

            //The first mesh could be null if we are below the minimum verticies we need to create a plane
            if (meshPiece.MeshObject != null)
            {
                TransformHelpers th = new TransformHelpers();

                //Now we've created the front of our mesh
                InstantiateTerrainObject();
                MeshPieces.Add(meshPiece);

                //Add detail mesh

                if (settings.DrawDetailMeshRenderer)
                {
                    MeshPiece meshPieceDetail = new MeshPiece(vg, MeshPiece.Plane.Detail, settings);
                    topVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Detail, true);
                    bottomVerticies = GetCornerVerts(previousTerrain, currentTerrain, MeshPiece.Plane.Detail, false);
                    meshPieceDetail.CreateCorner(topVerticies, bottomVerticies);
                    MeshPieces.Add(meshPieceDetail);
                }

                if (settings.DrawTopMeshCollider || settings.DrawTopMeshRenderer)
                {
                    //Create the verticies for the top of our mesh, and add that too
                    MeshPiece meshPieceTop = new MeshPiece(vg, MeshPiece.Plane.Top, settings);

                    //Use the top verts as our bottom z row
                    bottomVerticies = th.CopyList(topVerticies);
                    Vector3 firstBottomVertex = topVerticies[0];

                    //Then shift the top verts into the z plane
                    topVerticies = th.MoveStartVertex(topVerticies, firstBottomVertex, new Vector3(firstBottomVertex.x, firstBottomVertex.y, firstBottomVertex.z + settings.TopPlaneHeight), false);
                    meshPieceTop.CreateCorner(topVerticies, bottomVerticies);
                    MeshPieces.Add(meshPieceTop);
                }

                //Just to tidy up the heirarchy
                ParentMeshesToTerrainObject();

            }
        }