public SpatialGrid(TranslokatorLoader translokator) { bIsReady = true; gridBounds = translokator.Bounds; width = translokator.Grids[0].Width; height = translokator.Grids[0].Height; cellSize = new Vector2(gridBounds.Width / width, gridBounds.Height / height); cells = new SpatialCell[width * height]; origin = gridBounds.Minimum; var index = 0; for (int i = 0; i < width; i++) { for (int x = 0; x < height; x++) { var extents = new BoundingBox(); extents.Minimum = new Vector3(origin.X + cellSize.X * x, origin.Y + cellSize.Y * i, 10.0f); extents.Maximum = new Vector3(origin.X + cellSize.X * (x + 1), origin.Y + cellSize.Y * (i + 1), 10.0f); cells[index++] = new SpatialCell(extents); } } for (int i = 0; i != translokator.ObjectGroups.Length; i++) { ObjectGroup objectGroup = translokator.ObjectGroups[i]; for (int x = 0; x != objectGroup.NumObjects; x++) { ResourceTypes.Translokator.Object obj = objectGroup.Objects[x]; for (int y = 0; y != obj.NumInstances; y++) { Instance instance = obj.Instances[y]; var cell = GetCell(instance.Position); RenderBoundingBox box = new RenderBoundingBox(); box.SetTransform(Matrix.Translation(instance.Position)); box.Init(new BoundingBox(-Vector3.One, Vector3.One)); cells[cell].AddAsset(box, StringHelpers.GetNewRefID()); } } } }
public SpatialGrid(KynogonRuntimeMesh mesh) { bIsReady = true; var min = new Vector3(mesh.BoundMin, float.MinValue); var max = new Vector3(mesh.BoundMax, float.MaxValue); gridBounds = new BoundingBox(min, max); width = mesh.CellSizeY; height = mesh.CellSizeX; origin = new Vector3(gridBounds.Minimum.X, gridBounds.Minimum.Y, 0.0f); cellSize = new Vector2(gridBounds.Width / width, gridBounds.Height / height); cells = new SpatialCell[width * height]; var index = 0; for (int i = 0; i < width; i++) { for (int x = 0; x < height; x++) { KynogonRuntimeMesh.Cell cell = mesh.Cells[index]; foreach (var set in cell.Sets) { if (gridBounds.Minimum.Z < set.X) { gridBounds.Minimum.Z = set.X; } if (gridBounds.Maximum.Z > set.Y) { gridBounds.Maximum.Z = set.Y; } } var extents = new BoundingBox(); extents.Minimum = new Vector3(origin.X + cellSize.X * x, origin.Y + cellSize.Y * i, 0.0f); extents.Maximum = new Vector3(origin.X + cellSize.X * (x + 1), origin.Y + cellSize.Y * (i + 1), 0.0f); cells[index] = new SpatialCell(cell, extents); index++; } } }