Esempio n. 1
0
        public void Query(Bounds obbBounds, quaternion rotation, NativeList <T> resultList)
        {
            Assert.IsTrue(resultList.IsCreated);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckReadAndThrow(_safety);
#endif

            var bounds = TransformBounds(obbBounds, rotation);
            bounds.Clamp(_data->WorldBounds);

            CalculStartEndIterationInternal(_data, bounds, out var start, out var end);

            var hashMapUnic = new NativeHashMap <int, byte>(64, Allocator.Temp);

            var hashPosition = new int3(0F);

            //add offset for simplify logic and allowed pruning
            obbBounds.Size += _data->CellSize * 1F;

            var inverseRotation = math.inverse(rotation);

            for (int x = start.x; x < end.x; ++x)
            {
                hashPosition.x = x;

                for (int y = start.y; y < end.y; ++y)
                {
                    hashPosition.y = y;

                    for (int z = start.z; z < end.z; ++z)
                    {
                        hashPosition.z = z;

                        var pos = GetPositionVoxel(hashPosition, true);

                        if (obbBounds.RayCastOBBFast(pos - new float3(_data->CellSize.x * 0.5F, 0F, 0F), _right, inverseRotation, _data->CellSize.x) ||
                            obbBounds.RayCastOBBFast(pos - new float3(0F, _data->CellSize.y * 0.5F, 0F), _up, inverseRotation, _data->CellSize.y) ||
                            obbBounds.RayCastOBBFast(pos - new float3(0F, 0F, _data->CellSize.z * 0.5F), _forward, inverseRotation, _data->CellSize.z))
                        {
                            var hash = Hash(hashPosition);

                            if (_buckets.TryGetFirstValue(hash, out var item, out var it))
                            {
                                do
                                {
                                    hashMapUnic.TryAdd(item, 0);
                                }while (_buckets.TryGetNextValue(out item, ref it));
                            }
                        }
                    }
                }
            }

            ExtractValueFromHashMap(hashMapUnic, bounds, resultList);
        }
Esempio n. 2
0
        public void Query(Bounds obbBounds, quaternion rotation, NativeList <int3> voxelIndexes)
        {
            Assert.IsTrue(voxelIndexes.IsCreated);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            AtomicSafetyHandle.CheckReadAndThrow(_safety);
#endif

            var bounds = TransformBounds(obbBounds, rotation);
            bounds.Clamp(_data->WorldBounds);

            CalculStartEndIterationInternal(_data, bounds, out var start, out var end);

            var hashPosition = new int3(0F);

            //add offset for simplify logic and allowed pruning
            obbBounds.Size += _data->CellSize * 1F;

            var inverseRotation = math.inverse(rotation);

            for (int x = start.x; x < end.x; ++x)
            {
                hashPosition.x = x;

                for (int y = start.y; y < end.y; ++y)
                {
                    hashPosition.y = y;

                    for (int z = start.z; z < end.z; ++z)
                    {
                        hashPosition.z = z;

                        var pos = GetPositionVoxel(hashPosition, true);

                        if (obbBounds.RayCastOBBFast(pos - new float3(_data->CellSize.x * 0.5F, 0F, 0F), _right, inverseRotation, _data->CellSize.x) ||
                            obbBounds.RayCastOBBFast(pos - new float3(0F, _data->CellSize.y * 0.5F, 0F), _up, inverseRotation, _data->CellSize.y) ||
                            obbBounds.RayCastOBBFast(pos - new float3(0F, 0F, _data->CellSize.z * 0.5F), _forward, inverseRotation, _data->CellSize.z))
                        {
                            voxelIndexes.Add(hashPosition);
                        }
                    }
                }
            }
        }