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; }
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); }
// 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); }