コード例 #1
0
ファイル: Methods.cs プロジェクト: Hengle/LD43
        static public FastList <T> SearchAllScenes <T>(bool searchInActiveGameObjects) where T : Component
        {
            var list = new FastList <T>();

            #if !UNITY_5
            FastList <GameObject> gos = GetAllRootGameObjects();

            for (int i = 0; i < gos.Count; i++)
            {
                var result = SearchParent <T>(gos.items[i], searchInActiveGameObjects);

                list.AddRange(result);
            }
            #else
            list.items = GameObject.FindObjectsOfType <T>();
            list.SetCount(list.items.Length);

            if (!searchInActiveGameObjects)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (!list.items[i].gameObject.activeInHierarchy)
                    {
                        list.RemoveAt(i--);
                    }
                }
            }
            #endif

            return(list);
        }
コード例 #2
0
ファイル: RemoveOverlappingTris.cs プロジェクト: Hengle/LD43
        static bool LinecastAll(Vector3 p1, Vector3 p2, int layerMask)
        {
            Vector3 dir = p2 - p1;

            hitInfos2.SetCount(Physics.RaycastNonAlloc(p1, dir, hitInfos2.items, dir.magnitude, layerMask));
            return(hitInfos2.Count > 0);
        }
コード例 #3
0
        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;
        }