private void AddCameraToSort(Camera camera) { float3 min = camera.ViewportToWorldPoint(new Vector3(0F, 1F)); float3 max = camera.ViewportToWorldPoint(new Vector3(1F, 0F, camera.farClipPlane)); var b = new Bounds(); b.SetMinMax(math.min(min, max), math.max(min, max)); _cameraDataList.Add(new QuerySpatialHashingJob.CameraData { Bounds = b }); }
/// <inheritdoc /> protected override void InitSpatialHashing() { var matrix = GetSingleton <IsometricMatrix>(); var size = new float3(600, 600, 50); var pivot = new float3(size.x, 0F, 0F); var bottomPosition = matrix.IsoToScreen(pivot); var topPosition = matrix.IsoToScreen(new float3(pivot.x - size.x, pivot.yz + size.yz)); var isoBottom = pivot; isoBottom.y += size.y; var rightPosition = matrix.IsoToScreen(isoBottom); var leftPosition = matrix.IsoToScreen(new float3(pivot.x - size.x, pivot.yz)); var screenMin = new float2(leftPosition.x, bottomPosition.y); var screenMax = new float2(rightPosition.x, topPosition.y); var bounds = new Bounds(); bounds.SetMinMax(new float3(screenMin, 0F), new float3(screenMax, 1F)); size = new float3(6, 6, 3); pivot = new float3(size.x, 0F, 0F); bottomPosition = matrix.IsoToScreen(pivot); topPosition = matrix.IsoToScreen(new float3(pivot.x - size.x, pivot.yz + size.yz)); isoBottom = pivot; isoBottom.y += size.y; rightPosition = matrix.IsoToScreen(isoBottom); leftPosition = matrix.IsoToScreen(new float3(pivot.x - size.x, pivot.yz)); screenMin = new float2(leftPosition.x, bottomPosition.y); screenMax = new float2(rightPosition.x, topPosition.y); Debug.Log($"SpatialHashing Bounds {bounds} CellSize {new float3(screenMax - screenMin, 1F)}"); _spatialHash = new SpatialHash <IsometricData>(bounds, new float3(screenMax - screenMin, 1F), Allocator.Persistent); }
public void CreationTopologicalListJobTest() { var b = new Bounds(new float3(9400F, 400F, 0.5F), new float3(9600F, 5200F, 0.5F) * 2F); var spatialHash = new SpatialHash <IsometricData>(b, new float3(192F, 144F, 1F), Allocator.TempJob); var isoObject = new IsometricData { IsoPosition = new float3(17F, -1F, 0F), IsoSize = new float3(1F, 1F, 1F), ScreenMin = new float2(39.99997F, -144F), ScreenMax = new float2(71.99997F, -112F) }; //1 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(16F, -1F, 0F), IsoSize = new float3(3F, 1F, 1F), ScreenMin = new float2(-8.000031F, -136F), ScreenMax = new float2(55.99997F, -88F) }; //2 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(13F, -1F, 3F), IsoSize = new float3(1F, 1F, 1F), ScreenMin = new float2(-24.00002F, -64F), ScreenMax = new float2(7.999985F, -32F) }; //3 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(17F, -2F, 0F), IsoSize = new float3(3F, 1F, 1F), ScreenMin = new float2(-8.000031F, -152F), ScreenMax = new float2(55.99997F, -104F) }; //4 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(13F, -4F, 2F), IsoSize = new float3(1F, 3F, 1F), ScreenMin = new float2(-72.00002F, -104F), ScreenMax = new float2(-8.000015F, -56F) }; //5 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(14F, -2F, 0F), IsoSize = new float3(1F, 1F, 1F), ScreenMin = new float2(-24.00003F, -128F), ScreenMax = new float2(7.999969F, -96F) }; //6 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(14F, -5F, 0F), IsoSize = new float3(1F, 3F, 1F), ScreenMin = new float2(-72.00003F, -152F), ScreenMax = new float2(-8.000031F, -104F) }; //7 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(20F, -1F, 0F), IsoSize = new float3(3F, 1F, 1F), ScreenMin = new float2(55.99997F, -168F), ScreenMax = new float2(120F, -120F) }; //8 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(14F, -1F, 1F), IsoSize = new float3(1F, 1F, 1F), ScreenMin = new float2(-8.000031F, -104F), ScreenMax = new float2(23.99997F, -72F) }; //9 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(13F, -2F, 1F), IsoSize = new float3(1F, 1F, 1F), ScreenMin = new float2(-40.00002F, -104F), ScreenMax = new float2(-8.000031F, -72F) }; //10 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(17F, -1F, 1F), IsoSize = new float3(3F, 1F, 1F), ScreenMin = new float2(7.999969F, -128F), ScreenMax = new float2(71.99997F, -80F) }; //11 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(13F, -1F, 1F), IsoSize = new float3(1F, 1F, 1F), ScreenMin = new float2(-24.00002F, -96F), ScreenMax = new float2(7.999969F, -64F) }; //12 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(14F, -2F, 1F), IsoSize = new float3(1F, 1F, 1F), ScreenMin = new float2(-24.00003F, -112F), ScreenMax = new float2(7.999969F, -80F) }; //13 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(18F, -1F, 1F), IsoSize = new float3(1F, 1F, 1F), ScreenMin = new float2(55.99997F, -136F), ScreenMax = new float2(87.99997F, -104F) }; //14 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(16F, -1F, 2F), IsoSize = new float3(3F, 1F, 1F), ScreenMin = new float2(-8.000015F, -104F), ScreenMax = new float2(55.99997F, -56F) }; //15 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(13F, -1F, 0F), IsoSize = new float3(1F, 1F, 1F), ScreenMin = new float2(-24.00003F, -112F), ScreenMax = new float2(7.999969F, -80F) }; //16 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(13F, -5F, 0F), IsoSize = new float3(1F, 1F, 1F), ScreenMin = new float2(-88.00003F, -144F), ScreenMax = new float2(-56.00003F, -112F) }; //17 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(13F, -1F, 2F), IsoSize = new float3(1F, 1F, 1F), ScreenMin = new float2(-24.00002F, -80F), ScreenMax = new float2(7.999985F, -48F) }; //18 spatialHash.Add(ref isoObject); isoObject = new IsometricData { IsoPosition = new float3(13F, -4F, 0F), IsoSize = new float3(1F, 3F, 1F), ScreenMin = new float2(-72.00003F, -136F), ScreenMax = new float2(-8.000031F, -88F) }; //19 spatialHash.Add(ref isoObject); const int iTemCount = 19; var chunkIndicies = new NativeList <int3>(Allocator.TempJob); var cellCount = spatialHash.CellCount; for (int x = 0; x < cellCount.x; x++) { for (int y = 0; y < cellCount.y; y++) { for (int z = 0; z < cellCount.x; z++) { chunkIndicies.Add(new int3(x, y, z)); } } } var topologicalListFrontToBack = new NativeMultiHashMap <int, int>(60, Allocator.TempJob); var queue = new NativeQueue <int>(Allocator.TempJob); var job = new IsoSortingSystem.CreationTopologicalListJob { SpatialHashing = spatialHash, ChunkList = chunkIndicies, TopologicalListFrontToBack = topologicalListFrontToBack.ToConcurrent(), IsometricDataPresent = queue.ToConcurrent() }; job.Schedule(chunkIndicies, 1).Complete(); var hashset = new HashSet <int>(); while (queue.Count > 0) { hashset.Add(queue.Dequeue()); } Assert.AreEqual(iTemCount, hashset.Count); FindAllItem(topologicalListFrontToBack, 18, 3, 5, 3, 15); FindAllItem(topologicalListFrontToBack, 16, 5, 6, 7, 10, 12, 13, 2, 4, 6, 9, 12, 13, 15, 19); FindAllItem(topologicalListFrontToBack, 15); FindAllItem(topologicalListFrontToBack, 14); FindAllItem(topologicalListFrontToBack, 13); FindAllItem(topologicalListFrontToBack, 12, 9, 5, 13, 10, 13, 15, 18, 18); FindAllItem(topologicalListFrontToBack, 11, 14, 15); FindAllItem(topologicalListFrontToBack, 9, 11, 13, 15); FindAllItem(topologicalListFrontToBack, 8, 14); FindAllItem(topologicalListFrontToBack, 6, 4, 7, 13, 13); FindAllItem(topologicalListFrontToBack, 4); FindAllItem(topologicalListFrontToBack, 3); FindAllItem(topologicalListFrontToBack, 2, 1, 4, 6, 9, 11, 13, 15); FindAllItem(topologicalListFrontToBack, 1, 4, 8, 11, 14); FindAllItem(topologicalListFrontToBack, 19, 5, 6, 7, 10, 13, 17); FindAllItem(topologicalListFrontToBack, 17, 7); FindAllItem(topologicalListFrontToBack, 10, 5, 13); FindAllItem(topologicalListFrontToBack, 7); FindAllItem(topologicalListFrontToBack, 5); spatialHash.Dispose(); chunkIndicies.Dispose(); topologicalListFrontToBack.Dispose(); queue.Dispose(); }