示例#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);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        public void FinaliseGeometry(Vector3 inputMin, Vector3 inputMax, float y)
        {
            if (subQuads.Count > 0)
            {
                a.FinaliseGeometry(inputMin, inputMax, y);
                b.FinaliseGeometry(inputMin, inputMax, y);
                c.FinaliseGeometry(inputMin, inputMax, y);
                d.FinaliseGeometry(inputMin, inputMax, y);
            }
            else
            {
                (Vector2 minV2, Vector2 maxV2) = NormaliseValuesZ(inputMin, inputMax);

                Vector2 minA = new Vector2(minX / 100, minY / 100);
                Vector2 maxB = new Vector2(maxX / 100, minY / 100);
                Vector2 maxC = new Vector2(minX / 100, maxY / 100);
                Vector2 maxD = new Vector2(maxX / 100, maxY / 100);

                Vector2 UVAB     = (minA + maxB) / 2;
                Vector2 UVAC     = (minA + maxC) / 2;
                Vector2 UVCD     = (maxC + maxD) / 2;
                Vector2 UVBD     = (maxB + maxD) / 2;
                Vector2 UVCENTER = (minA + maxB + maxC + maxD) / 4;

                //0
                Vector3 a = new Vector3(minV2.x, y, minV2.y);

                //1
                Vector3 b = new Vector3(maxV2.x, y, minV2.y);

                //2
                Vector3 c = new Vector3(minV2.x, y, maxV2.y);

                //3
                Vector3 d = new Vector3(maxV2.x, y, maxV2.y);

                //Top (4)
                Vector3 aToB = (a + b) / 2;

                //Right (5)
                Vector3 bToD = (b + d) / 2;

                //Bottom (6)
                Vector3 cToD = (c + d) / 2;

                //Left (7)
                Vector3 aToC = (a + c) / 2;

                //Center (8)
                Vector3 center = (a + b + c + d) / 4;

                //A = 0, A->B = 1, B = 2, B->D = 3, D = 4, D->C = 5, C = 6, C->A = 7, CENTER = 8

                List <Vector3> rangeAdd   = new List <Vector3>(new Vector3[] { a, aToB, b, bToD, d, cToD, c, aToC, center });
                List <Vector2> rangeAddUV = new List <Vector2>(new Vector2[] { minA, UVAB, maxB, UVBD, maxD, UVCD, maxC, UVAC, UVCENTER });

                for (int i = 0; i < rangeAdd.Count; i++)
                {
                    if (!instance.verts.Contains(instance.transform.InverseTransformPoint(rangeAdd[i])))
                    {
                        instance.verts.Add(instance.transform.InverseTransformPoint(rangeAdd[i]));
                        instance.UVs.Add(rangeAddUV[i]);
                        VertexReference reference = new VertexReference();
                        reference.vertex = instance.verts.Count - 1;
                        if (i != 8)
                        {
                            reference.references = 1;
                        }
                        reference.quads = new List <Quad>();
                        reference.quads.Add(this);

                        instance.vertIndexDictionary.Add(instance.transform.InverseTransformPoint(rangeAdd[i]), reference);
                    }
                    else
                    {
                        VertexReference reference = instance.vertIndexDictionary[instance.transform.InverseTransformPoint(rangeAdd[i])];
                        reference.quads.Add(this);
                        reference.references += 1;
                    }
                    //Won't work because sometimes it's not called!!
                    localVerts.Add(instance.vertIndexDictionary[instance.transform.InverseTransformPoint(rangeAdd[i])].vertex);
                }

                //A -> B (Index of local vert corresponding to global vertex index)
                Edge e1 = new Edge(0, 1, 2);

                //B to D
                Edge e2 = new Edge(2, 3, 4);

                //C to D
                Edge e3 = new Edge(4, 5, 6);

                //A -> C
                Edge e4 = new Edge(0, 7, 6);

                edges.AddRange(new Edge[] { e1, e2, e3, e4 });

                //If one of the verts get deleted a triangle get's made using the same ciclical pattern
                for (int i = 0; i < localVerts.Count; i++)
                {
                    if (i == localVerts.Count - 1 || i == 0)
                    {
                        continue;
                    }

                    int aT = i - 1;
                    int bT = i;
                    int cT = localVerts.Count - 1;

                    Triangle t = new Triangle();
                    t.a = aT;
                    t.b = bT;
                    t.c = cT;

                    //Temporary Add
                    instance.tris.AddRange(new int[] { localVerts[aT], localVerts[bT], localVerts[cT] });

                    triangles.Add(t);
                }

                instance.tris.AddRange(new int[] { localVerts[localVerts.Count - 2], localVerts[0], localVerts[localVerts.Count - 1] });
                Triangle t2 = new Triangle();
                t2.a = 7;
                t2.b = 0;
                t2.c = 8;

                triangles.Add(t2);
            }
        }