Example #1
0
        public void DeleteUnrequired(Vector3 inputMin, Vector3 inputMax, float y)
        {
            if (subQuads.Count > 0)
            {
                a.DeleteUnrequired(inputMin, inputMax, y);
                b.DeleteUnrequired(inputMin, inputMax, y);
                c.DeleteUnrequired(inputMin, inputMax, y);
                d.DeleteUnrequired(inputMin, inputMax, y);
            }
            else
            {
                for (int i = 0; i < localVerts.Count; i++)
                {
                    VertexReference reference = instance.vertIndexDictionary[instance.verts[localVerts[i]]];

                    if (reference.references == 1)
                    {
                        Vector3 v = instance.transform.TransformPoint(instance.verts[localVerts[i]]);
                        if (v.x > instance.minBounds.x && v.x < instance.maxBounds.x)
                        {
                            if (v.z > instance.maxBounds.z && v.z < instance.minBounds.z)
                            {
                                localVerts.RemoveAt(i);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
    private void Awake()
    {
        instance   = this;
        emptyMesh  = new Mesh();
        parentQuad = new Quad(0, 0, 100, 100);

        AutoSubdivide(parentQuad);

//        NeighbourSubdivide(parentQuad);
        parentQuad.EnsureMaxDepth();

        parentQuad.FinaliseGeometry(min, max, transform.position.y);

        parentQuad.DeleteUnrequired(min, max, transform.position.y);
        tris.Clear();
        parentQuad.RedrawGeometry(min, max, transform.position.y);


        Vector3 minT = transform.InverseTransformPoint(min);
        Vector3 maxT = transform.InverseTransformPoint(max);

        for (int i = 0; i < verts.Count; i++)
        {
            Vector3 localPos = verts[i];
            //float realXPos = trans.TransformPoint(localPos).x;
            //float realZPos = trans.TransformPoint(localPos).z;

            float realXPos = localPos.x;
            float realZPos = localPos.y;

            float percX = ((realXPos - minT.x) * 100) / (maxT.x - minT.x);
            float percY = ((realZPos - minT.y) * 100) / (maxT.y - minT.y);



            int pixelX = Mathf.Clamp(Mathf.RoundToInt(percX / 100 * testTexture.width), 0, testTexture.width - 1);
            int pixelY = Mathf.Clamp(Mathf.RoundToInt(percY / 100 * testTexture.height), 0, testTexture.height - 1);

            float r = testTexture.GetPixel(pixelX, pixelY).r;

            float val = r;
            float Fy  = (val * maxHeight);

            localPos = new Vector3(localPos.x, localPos.y, Fy);

            verts[i] = localPos;
        }

        emptyMesh.vertices  = verts.ToArray();
        emptyMesh.triangles = tris.ToArray();
        emptyMesh.uv        = UVs.ToArray();

        emptyMesh.RecalculateBounds();
        emptyMesh.RecalculateNormals();

        emptyMesh.RecalculateTangents();



        GetComponent <MeshFilter>().mesh         = emptyMesh;
        GetComponent <MeshCollider>().sharedMesh = emptyMesh;
        string path = "Assets/TerrainChunks/MeshData/";


        AssetDatabase.CreateAsset(emptyMesh, path + ID + "_MESH.mesh");
        AssetDatabase.SaveAssets();

        verts.Clear();
        indexFromVector.Clear();
        tris.Clear();
        UVs.Clear();
    }