That’s fine! The first step is to organize them.
You don’t need to do this manually, we can automate this.
For example, we could:
- Put the bones into a single array.
local bones = someModel:GetChildren()
- Sort them on one axis:
table.sort(bones, function(a, b) return a.Position.Z < b.Position.Z end)
- Split the resulting table into chunks based on how many per row there are (you hardcode that number)
- Sort the subtables.
If we put all that together:
local function Gridify(objects, cols: number)
-- first sort top to bottom
table.sort(objects, function(a, b) return a.Position.Z < b.Position.Z end)
local grid = {}
-- then, split up into groups
for row = 1, #objects / cols do
-- the first object in the row
local lowerIndex = 1 + (row - 1) * cols
-- the last object in the row
local upperIndex = row * cols
-- copy this row into its own table..
local thisRow = {}
table.move(objects, lowerIndex, upperIndex, 1, thisRow)
-- ... so we can sort it based on position
table.sort(thisRow, function(a, b) return a.Position.X < b.Position.X end)
grid[row] = thisRow
end
return grid
end
With this function, say we did local grid = Gridify(bonesParent:GetChildren())
.
Then grid[7][12]
would give us the Bone
instance in row 7, column 12.
For instance, I tried this on a grid of parts. I’m showing the (row, column) positions that this function calculated in this image:
So we’ve succesfully organized the bones into a grid. The next question is: how are the triangles connected in this grid? Does it look like this?
+---+---+---+---+---+
| /| /| /| /| /|
| / | / | / | / | / |
|/ |/ |/ |/ |/ |
+---+---+---+---+---+
| /| /| /| /| /|
| / | / | / | / | / |
|/ |/ |/ |/ |/ |
+---+---+---+---+---+
Or this?
+---+---+---+---+---+
|\ |\ |\ |\ |\ |
| \ | \ | \ | \ | \ |
| \| \| \| \| \|
+---+---+---+---+---+
|\ |\ |\ |\ |\ |
| \ | \ | \ | \ | \ |
| \| \| \| \| \|
+---+---+---+---+---+
… or maybe this?
+---+---+---+---+---+
| /| /| /| /| /|
| / | / | / | / | / |
|/ |/ |/ |/ |/ |
+---+---+---+---+---+
|\ |\ |\ |\ |\ |
| \ | \ | \ | \ | \ |
| \| \| \| \| \|
+---+---+---+---+---+