
Jason
The main issue that goes for all array attributes is that they are fully copied over the C/lua boundary which is very slow for huge arrays like in the mesh node... . We might try to come up with something smarter in the future, we just don't know whatgrimm wrote:Thanks Thomas,
I will finish up my function to do it then, it's just really slow, depending on the number of vertices in the mesh.![]()
Jason
Great! Yeah, printing is just slow and if you try to print something like a million lines it will just take forever.grimm wrote:Ok, it's much faster than I thought.I was printing the values out so I could see if I was getting the right information and that was slowing things down. Onwards!
Jason
Code: Select all
-- calculate the statistics of a mesh and return a table of those values
function getMeshStats(verts)
local meshStats = {}
local minX = 0
local maxX = 0
local minY = 0
local maxY = 0
local minZ = 0
local maxZ = 0
local lengthX = 0
local lengthY = 0
local lengthZ = 0
local x, y, z
-- find the bounding box
for k,v in pairs(verts) do
x = v[1]
if x > maxX then maxX = x end
if x < minX then minX = x end
y = v[2]
if y > maxY then maxY = y end
if y < minY then minY = y end
z = v[3]
if z > maxZ then maxZ = z end
if z < minZ then minZ = z end
end
meshStats["min_x"] = minX
meshStats["max_x"] = maxX
meshStats["min_y"] = minY
meshStats["max_y"] = maxY
meshStats["min_z"] = minZ
meshStats["max_z"] = maxZ
-- find the mesh's length for each axis
lengthX = maxX - minX
lengthY = maxY - minY
lengthZ = maxZ - minZ
meshStats["x_len"] = lengthX
meshStats["y_len"] = lengthY
meshStats["z_len"] = lengthZ
-- find the mesh's position
local posX = lengthX/2.0 + minX
local posY = lengthY/2.0 + minY
local posZ = lengthZ/2.0 + minZ
meshStats["pos_x"] = posX
meshStats["pos_y"] = posY
meshStats["pos_z"] = posZ
return meshStats
end
selectedMesh = octane.project.getSelection()[1]
verts = selectedMesh:getAttribute(octane.A_VERTICES)
meshStats = getMeshStats(verts)
print "X info"
print(meshStats["pos_x"])
print(meshStats["min_x"])
print(meshStats["max_x"])
print "Y info"
print(meshStats["pos_y"])
print(meshStats["min_y"])
print(meshStats["max_y"])
print "Z info"
print(meshStats["pos_z"])
print(meshStats["min_z"])
print(meshStats["max_z"])