Beispiel #1
0
 // Token: 0x060024D1 RID: 9425 RVA: 0x000B4DA8 File Offset: 0x000B2FA8
 public MeshCache(Mesh mesh)
 {
     this.mesh         = mesh;
     this.subMeshCount = mesh.subMeshCount;
     this.subMeshCache = new MeshCache.SubMeshCache[this.subMeshCount];
     if (this.subMeshCount == 1)
     {
         this.subMeshCache[0] = new MeshCache.SubMeshCache(mesh, true);
         return;
     }
     MeshCache.SubMeshCache sub = new MeshCache.SubMeshCache(mesh, false);
     for (int i = 0; i < this.subMeshCache.Length; i++)
     {
         this.subMeshCache[i] = new MeshCache.SubMeshCache(mesh, i);
         this.subMeshCache[i].RebuildVertexBuffer(sub, true);
     }
 }
Beispiel #2
0
 // Token: 0x06003057 RID: 12375 RVA: 0x000CCF80 File Offset: 0x000CB180
 public void CopySubMeshCache(MeshCache.SubMeshCache source)
 {
     this.vertexCount = source.vertexCount;
     Array.Copy(source.vertices, 0, this.vertices, 0, this.vertexCount);
     this.hasNormals  = source.hasNormals;
     this.hasTangents = source.hasTangents;
     this.hasColors   = source.hasColors;
     this.hasUv       = source.hasUv;
     this.hasUv2      = source.hasUv2;
     this.hasUv3      = source.hasUv3;
     this.hasUv4      = source.hasUv4;
     if (source.hasNormals)
     {
         this.CopyArray <Vector3>(source.normals, ref this.normals, this.vertexCount);
     }
     if (source.hasTangents)
     {
         this.CopyArray <Vector4>(source.tangents, ref this.tangents, this.vertexCount);
     }
     if (source.hasUv)
     {
         this.CopyArray <Vector2>(source.uv, ref this.uv, this.vertexCount);
     }
     if (source.hasUv2)
     {
         this.CopyArray <Vector2>(source.uv2, ref this.uv2, this.vertexCount);
     }
     if (source.hasUv3)
     {
         this.CopyArray <Vector2>(source.uv3, ref this.uv3, this.vertexCount);
     }
     if (source.hasUv4)
     {
         this.CopyArray <Vector2>(source.uv4, ref this.uv4, this.vertexCount);
     }
     if (source.hasColors)
     {
         this.CopyArray <Color32>(source.colors32, ref this.colors32, this.vertexCount);
     }
 }
Beispiel #3
0
        public void RemoveTrianglesBelowSurface(Transform t, MeshCombineJobManager.MeshCombineJob meshCombineJob, MeshCache.SubMeshCache newMeshCache, ref byte[] vertexIsBelow)
        {
            if (vertexIsBelow == null)
            {
                vertexIsBelow = new byte[65534];
            }

            Vector3 pos       = Vector3.zero;
            int     layerMask = meshCombineJob.meshCombiner.surfaceLayerMask;

            // float rayHeight = meshCombineJob.meshCombiner.maxSurfaceHeight;

            Vector3[] newVertices  = newMeshCache.vertices;
            int[]     newTriangles = newMeshCache.triangles;

            List <MeshObject> meshObjects = meshCombineJob.meshObjectsHolder.meshObjects;

            int startIndex = meshCombineJob.startIndex;
            int endIndex   = meshCombineJob.endIndex;

            const byte belowSurface = 1, aboveSurface = 2;

            for (int i = startIndex; i < endIndex; i++)
            {
                MeshObject meshObject = meshObjects[i];

                Capture(meshObject.cachedGO.mr.bounds, layerMask, new Vector3(0, -1, 0), new Int2(1024, 1024));

                int startTriangleIndex = meshObject.startNewTriangleIndex;
                int endTriangleIndex   = meshObject.newTriangleCount + startTriangleIndex;

                // Debug.Log("startIndex " + startIndex + " triangle " + startTriangleIndex + " - " + endTriangleIndex);

                for (int j = startTriangleIndex; j < endTriangleIndex; j += 3)
                {
                    bool isAboveSurface = false;

                    for (int k = 0; k < 3; k++)
                    {
                        int vertexIndex = newTriangles[j + k];
                        if (vertexIndex == -1)
                        {
                            continue;
                        }

                        byte isBelow = vertexIsBelow[vertexIndex];

                        if (isBelow == 0)
                        {
                            pos = t.TransformPoint(newVertices[vertexIndex]);

                            float height = GetHeight(pos);

                            isBelow = pos.y < height ? belowSurface : aboveSurface;
                            vertexIsBelow[vertexIndex] = isBelow;

                            if (pos.y < height)
                            {
                                vertexIsBelow[vertexIndex] = isBelow = belowSurface;
                            }
                            else
                            {
                                vertexIsBelow[vertexIndex] = isBelow = aboveSurface;
                            }
                        }

                        if (isBelow != belowSurface)
                        {
                            isAboveSurface = true; break;
                        }
                    }

                    if (!isAboveSurface)
                    {
                        meshCombineJob.trianglesRemoved += 3;
                        newTriangles[j] = -1;
                    }
                }
            }

            Array.Clear(vertexIsBelow, 0, newVertices.Length);
        }
        static public void RemoveOverlap(Transform t, MeshCombineJobManager.MeshCombineJob meshCombineJob, MeshCache.SubMeshCache newMeshCache, ref byte[] vertexIsInsideCollider)
        {
            if (vertexIsInsideCollider == null)
            {
                vertexIsInsideCollider = new byte[65534];
            }

            int overlapLayerMask = meshCombineJob.meshCombiner.overlapLayerMask;
            int voxelizeLayer    = meshCombineJob.meshCombiner.voxelizeLayer;

            int voxelizeLayerMask = 1 << voxelizeLayer;
            int lodGroupLayer     = meshCombineJob.meshCombiner.lodGroupLayer;
            int lodGroupLayerMask = 1 << lodGroupLayer;

            int lodLevel = meshCombineJob.meshObjectsHolder.lodLevel;

            Vector3 cellOffset = meshCombineJob.position;

            CreateOverlapColliders.newT.position = -cellOffset;
            t.parent.position -= cellOffset;

#if !UNITY_2017
            if (!Physics.autoSyncTransforms)
            {
                Physics.SyncTransforms();
            }
#endif

            CreateOverlapColliders.EnableLodLevelCollider(lodLevel, lodGroupLayer);

            Vector3[] newVertices  = newMeshCache.vertices;
            int[]     newTriangles = newMeshCache.triangles;

            FastList <MeshObject> meshObjects = meshCombineJob.meshObjectsHolder.meshObjects;

            int startIndex = meshCombineJob.startIndex;
            int endIndex   = meshCombineJob.endIndex;

            bool queriesHitBackfaces = Physics.queriesHitBackfaces;
            Physics.queriesHitBackfaces = true;

            toCombineGos.Clear();
            for (int i = startIndex; i < endIndex; i++)
            {
                toCombineGos.Add(meshObjects.items[i].cachedGO.go);
            }

            for (int a = startIndex; a < endIndex; a++)
            {
                MeshObject       meshObject = meshObjects.items[a];
                CachedGameObject cachedGO   = meshObject.cachedGO;

                GameObject go;
                CreateOverlapColliders.lookupOrigCollider.TryGetValue(cachedGO.go, out go);

                int startTriangleIndex = meshObject.startNewTriangleIndex;
                int endTriangleIndex   = meshObject.newTriangleCount + startTriangleIndex;

                Bounds bounds = cachedGO.mr.bounds;
                bounds.center -= cellOffset;

                int oldLayer = 0;

                if (go)
                {
                    oldLayer = go.layer;
                    go.layer = voxelizeLayer;
                }

                colliders.SetCount(Physics.OverlapBoxNonAlloc(bounds.center, bounds.extents, colliders.items, Quaternion.identity, overlapLayerMask));

                if (go)
                {
                    go.layer = oldLayer;
                }

                // Debug.Log("collider Count " + colliders.Count);

                if (colliders.Count == 0)
                {
                    continue;
                }

                collidersInfo.SetCount(colliders.Count);

                for (int i = 0; i < colliders.Count; i++)
                {
                    GameObject colliderGo = colliders.items[i].gameObject;
                    collidersInfo.items[i] = new ColliderInfo()
                    {
                        layer = colliderGo.layer, go = colliderGo
                    };
                    colliderGo.layer = voxelizeLayer;
                }

                // Debug.Log("start " + startTriangleIndex + " end " + endTriangleIndex);

                for (int i = startTriangleIndex; i < endTriangleIndex; i += 3)
                {
                    int vertIndexA = newTriangles[i];
                    if (vertIndexA == -1)
                    {
                        continue;
                    }

                    byte isInsideVoxel = vertexIsInsideCollider[vertIndexA];

                    if (isInsideVoxel != outsideVoxel)
                    {
                        tri.a = t.TransformPoint(newVertices[vertIndexA]);

                        hitInfos.SetCount(Physics.RaycastNonAlloc(tri.a, Vector3.up, hitInfos.items, Mathf.Infinity, voxelizeLayerMask));

                        if (!AnythingInside())
                        {
                            vertexIsInsideCollider[vertIndexA] = outsideVoxel; continue;
                        }

                        tri.b = t.TransformPoint(newVertices[newTriangles[i + 1]]);
                        tri.c = t.TransformPoint(newVertices[newTriangles[i + 2]]);

                        if (LinecastAll(tri.a, tri.b, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }
                        if (LinecastAll(tri.b, tri.c, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }
                        if (LinecastAll(tri.c, tri.a, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }
                        if (LinecastAll(tri.a, (tri.b + tri.c) * 0.5f, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }
                        if (LinecastAll(tri.b, (tri.c + tri.a) * 0.5f, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }
                        if (LinecastAll(tri.c, (tri.a + tri.b) * 0.5f, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }

                        //tri.Calc();
                        //Vector3 origin = tri.a + (tri.dirAb / 2) + ((tri.c - tri.h1) / 2);

                        //if (Physics.CheckBox(origin, new Vector3(0.05f, tri.h, tri.ab) / 2, Quaternion.LookRotation(tri.dirAb, tri.dirAc), voxelizeLayerMask))
                        //{
                        //    colliderGO.layer = oldLayer;
                        //    continue;
                        //}

                        if (CreateOverlapColliders.foundLodGroup && AreAllHitInfosALodGroup() && !IsOneColliderGOInToCombineGos() && !CheckAnyInsideOfLodGroups(lodGroupLayerMask, lodLevel))
                        {
                            continue;
                        }

                        meshCombineJob.trianglesRemoved += 3;
                        newTriangles[i] = -1;
                    }
                }

                for (int i = 0; i < colliders.Count; i++)
                {
                    ColliderInfo colliderInfo = collidersInfo.items[i];
                    colliderInfo.go.layer = colliderInfo.layer;
                }
            }

            Array.Clear(vertexIsInsideCollider, 0, newVertices.Length);
            // Debug.Log("Removed " + meshCombineJob.trianglesRemoved);

            newMeshCache.triangles      = newTriangles;
            Physics.queriesHitBackfaces = queriesHitBackfaces;

            t.parent.position += cellOffset;
        }
Beispiel #5
0
        // Token: 0x060024B0 RID: 9392 RVA: 0x000B388C File Offset: 0x000B1A8C
        public void RemoveTrianglesBelowSurface(Transform t, MeshCombineJobManager.MeshCombineJob meshCombineJob, MeshCache.SubMeshCache newMeshCache, ref byte[] vertexIsBelow)
        {
            if (vertexIsBelow == null)
            {
                vertexIsBelow = new byte[65534];
            }
            Vector3 vector        = Vector3.zero;
            int     collisionMask = meshCombineJob.meshCombiner.surfaceLayerMask;

            Vector3[]             vertices    = newMeshCache.vertices;
            int[]                 triangles   = newMeshCache.triangles;
            FastList <MeshObject> meshObjects = meshCombineJob.meshObjectsHolder.meshObjects;
            int startIndex = meshCombineJob.startIndex;
            int endIndex   = meshCombineJob.endIndex;

            for (int i = startIndex; i < endIndex; i++)
            {
                MeshObject meshObject = meshObjects.items[i];
                this.Capture(meshObject.cachedGO.mr.bounds, collisionMask, new Vector3(0f, -1f, 0f), new Int2(1024, 1024));
                int startNewTriangleIndex = meshObject.startNewTriangleIndex;
                int num = meshObject.newTriangleCount + startNewTriangleIndex;
                for (int j = startNewTriangleIndex; j < num; j += 3)
                {
                    bool flag = false;
                    for (int k = 0; k < 3; k++)
                    {
                        int num2 = triangles[j + k];
                        if (num2 != -1)
                        {
                            byte b = vertexIsBelow[num2];
                            if (b == 0)
                            {
                                vector = t.TransformPoint(vertices[num2]);
                                float height = this.GetHeight(vector);
                                b = ((vector.y < height) ? 1 : 2);
                                vertexIsBelow[num2] = b;
                                if (vector.y < height)
                                {
                                    b = (vertexIsBelow[num2] = 1);
                                }
                                else
                                {
                                    b = (vertexIsBelow[num2] = 2);
                                }
                            }
                            if (b != 1)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (!flag)
                    {
                        meshCombineJob.trianglesRemoved += 3;
                        triangles[j] = -1;
                    }
                }
            }
            Array.Clear(vertexIsBelow, 0, vertices.Length);
        }
Beispiel #6
0
 // Token: 0x0600305E RID: 12382 RVA: 0x000CD2F4 File Offset: 0x000CB4F4
 public void RebuildVertexBuffer(MeshCache.SubMeshCache sub, bool resizeArrays)
 {
     int[] array  = new int[sub.vertices.Length];
     int[] array2 = new int[array.Length];
     this.vertexCount = 0;
     for (int i = 0; i < this.triangleCount; i++)
     {
         int num = this.triangles[i];
         if (array[num] == 0)
         {
             array[num] = this.vertexCount + 1;
             array2[this.vertexCount] = num;
             this.triangles[i]        = this.vertexCount;
             this.vertexCount++;
         }
         else
         {
             this.triangles[i] = array[num] - 1;
         }
     }
     if (resizeArrays)
     {
         this.vertices = new Vector3[this.vertexCount];
     }
     this.hasNormals  = sub.hasNormals;
     this.hasTangents = sub.hasTangents;
     this.hasColors   = sub.hasColors;
     this.hasUv       = sub.hasUv;
     this.hasUv2      = sub.hasUv2;
     this.hasUv3      = sub.hasUv3;
     this.hasUv4      = sub.hasUv4;
     if (resizeArrays)
     {
         if (this.hasNormals)
         {
             this.normals = new Vector3[this.vertexCount];
         }
         if (this.hasTangents)
         {
             this.tangents = new Vector4[this.vertexCount];
         }
         if (this.hasUv)
         {
             this.uv = new Vector2[this.vertexCount];
         }
         if (this.hasUv2)
         {
             this.uv2 = new Vector2[this.vertexCount];
         }
         if (this.hasUv3)
         {
             this.uv3 = new Vector2[this.vertexCount];
         }
         if (this.hasUv4)
         {
             this.uv4 = new Vector2[this.vertexCount];
         }
         if (this.hasColors)
         {
             this.colors32 = new Color32[this.vertexCount];
         }
     }
     for (int j = 0; j < this.vertexCount; j++)
     {
         int num2 = array2[j];
         this.vertices[j] = sub.vertices[num2];
         if (this.hasNormals)
         {
             this.normals[j] = sub.normals[num2];
         }
         if (this.hasTangents)
         {
             this.tangents[j] = sub.tangents[num2];
         }
         if (this.hasUv)
         {
             this.uv[j] = sub.uv[num2];
         }
         if (this.hasUv2)
         {
             this.uv2[j] = sub.uv2[num2];
         }
         if (this.hasUv3)
         {
             this.uv3[j] = sub.uv3[num2];
         }
         if (this.hasUv4)
         {
             this.uv4[j] = sub.uv4[num2];
         }
         if (this.hasColors)
         {
             this.colors32[j] = sub.colors32[num2];
         }
     }
 }