Page 1 of 2
Get information from a mesh node?
Posted: Mon Jan 20, 2014 10:00 pm
by grimm
Is there a way yet to query a mesh node and get information about it? I'm interested in getting the mesh nodes position and bounding box. I have been able to pull the vertices out of the node and I can calculate the position and bounding box with a function from them. But, is there a better way? Thanks
Jason
Re: Get information from a mesh node?
Posted: Mon Jan 20, 2014 10:11 pm
by stratified
Hi jason,
Unfortunately not, for the bounding box you have to go via the raw vertex data. And depending on your scene, you can get the position via placement or scatter nodes.
cheers,
Thomas
Re: Get information from a mesh node?
Posted: Mon Jan 20, 2014 10:14 pm
by grimm
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
Re: Get information from a mesh node?
Posted: Mon Jan 20, 2014 10:43 pm
by stratified
grimm 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
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 what
cheers,
Thomas
Re: Get information from a mesh node?
Posted: Mon Jan 20, 2014 10:52 pm
by grimm
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
Re: Get information from a mesh node?
Posted: Mon Jan 20, 2014 11:35 pm
by stratified
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
Great! Yeah, printing is just slow and if you try to print something like a million lines it will just take forever.
If you have heaps of output to print it's better to run the script from the menu and look at the log output. The log window is much faster because it isn't updated in real time.
cheers,
Thomas
Re: Get information from a mesh node?
Posted: Tue Jan 21, 2014 12:03 am
by grimm
Thanks Thomas, that's good to know. Here is my function if anyone is interested, any ideas to make it better will be greatly appreciated.
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"])
If you do run the script, just make sure to select a mesh node first. Otherwise it will not work.
Jason
Re: Get information from a mesh node?
Posted: Tue Jan 21, 2014 9:54 am
by bepeg4d
thanks jason, useful to understand the scale and orientation of a mesh

note: the result don't take care of a different scale setting in the preferences of the mesh, and is always displayed in meters.
ciao beppe
Re: Get information from a mesh node?
Posted: Tue Jan 21, 2014 7:17 pm
by grimm
Hi bepeg4d,
Yes, in this case I needed the raw numbers, but that doesn't mean you can't add your own scalular to the script.
Jason
Re: Get information from a mesh node?
Posted: Tue Jan 21, 2014 7:34 pm
by bepeg4d
shouldn't come up without any calculation?
i mean, if the mesh is already scaled, the script should give the current dimensions... at least this is what i was expected

ciao beppe