Exemple #1
0
        public static unsafe void AabbCollider <T>(OverlapAabbInput input, [NoAlias] Collider *collider, [NoAlias] ref T collector)
            where T : struct, IOverlapCollector
        {
            if (!CollisionFilter.IsCollisionEnabled(input.Filter, collider->Filter))
            {
                return;
            }

            switch (collider->Type)
            {
            case ColliderType.Mesh:
                AabbMesh(input, (MeshCollider *)collider, ref collector);
                break;

            case ColliderType.Compound:
                AabbCompound(input, (CompoundCollider *)collider, ref collector);
                break;

            case ColliderType.Terrain:
                AabbTerrain(input, (TerrainCollider *)collider, ref collector);
                break;

            default:
                SafetyChecks.ThrowNotImplementedException();
                return;
            }
        }
Exemple #2
0
        // Test input against the broadphase tree, filling allHits with the body indices of every overlap.
        // Returns true if there was at least overlap.
        public bool OverlapAabb(OverlapAabbInput input, ref NativeList <int> allHits)
        {
            int hitsBefore = allHits.Length;

            Broadphase.OverlapAabb(input, m_Bodies, ref allHits);
            return(allHits.Length > hitsBefore);
        }
Exemple #3
0
        private static unsafe void AabbMesh <T>(OverlapAabbInput input, [NoAlias] MeshCollider *mesh, [NoAlias] ref T collector)
            where T : struct, IOverlapCollector
        {
            var leafProcessor = new MeshLeafProcessor(mesh);

            mesh->Mesh.BoundingVolumeHierarchy.AabbOverlap(input, ref leafProcessor, ref collector);
            leafProcessor.Flush(ref collector);
        }
Exemple #4
0
            public unsafe void AabbLeaf <T>(OverlapAabbInput input, int rigidBodyIndex, ref T collector)
                where T : struct, IOverlapCollector
            {
                rigidBodyIndex += BaseRigidBodyIndex;
                RigidBody body = m_Bodies[rigidBodyIndex];

                if (body.Collider.IsCreated && CollisionFilter.IsCollisionEnabled(input.Filter, body.Collider.Value.Filter))
                {
                    collector.AddRigidBodyIndices(&rigidBodyIndex, 1);
                }
            }
Exemple #5
0
        // Test broadphase nodes against the aabb in input. For any overlapping
        // tree leaves, put the body indices into the output leafIndices.
        public void OverlapAabb(OverlapAabbInput input, NativeArray <RigidBody> rigidBodies, ref NativeList <int> rigidBodyIndices)
        {
            if (input.Filter.IsEmpty)
            {
                return;
            }
            var leafProcessor = new BvhLeafProcessor(rigidBodies);
            var leafCollector = new RigidBodyOverlapsCollector {
                RigidBodyIndices = rigidBodyIndices
            };

            leafProcessor.BaseRigidBodyIndex = m_DynamicTree.NumBodies;
            m_StaticTree.BoundingVolumeHierarchy.AabbOverlap(input, ref leafProcessor, ref leafCollector);

            leafProcessor.BaseRigidBodyIndex = 0;
            m_DynamicTree.BoundingVolumeHierarchy.AabbOverlap(input, ref leafProcessor, ref leafCollector);
        }
Exemple #6
0
            public void AabbLeaf <T>(OverlapAabbInput input, int primitiveKey, [NoAlias] ref T collector) where T : struct, IOverlapCollector
            {
                fixed(uint *keys = m_Keys)
                {
                    keys[m_NumKeys++] = new ColliderKey(m_NumColliderKeyBits, (uint)(primitiveKey << 1)).Value;

                    Mesh.PrimitiveFlags flags = m_Mesh->GetPrimitiveFlags(primitiveKey);
                    if (Mesh.IsPrimitiveFlagSet(flags, Mesh.PrimitiveFlags.IsTrianglePair) &&
                        !Mesh.IsPrimitiveFlagSet(flags, Mesh.PrimitiveFlags.IsQuad))
                    {
                        keys[m_NumKeys++] = new ColliderKey(m_NumColliderKeyBits, (uint)(primitiveKey << 1) | 1).Value;
                    }
                }

                if (m_NumKeys > k_MaxKeys - 8)
                {
                    Flush(ref collector);
                }
            }
Exemple #7
0
            public void AabbLeaf <T>(OverlapAabbInput input, int childIndex, [NoAlias] ref T collector) where T : struct, IOverlapCollector
            {
                ColliderKey childKey = new ColliderKey(m_NumColliderKeyBits, (uint)(childIndex));

                // Recurse if child is a composite
                ref CompoundCollider.Child child = ref m_CompoundCollider->Children[childIndex];