Get information from a mesh node?

Forums: Get information from a mesh node?
Forum for OctaneRender Lua scripting examples, discussion and support.

Get information from a mesh node?

Postby grimm » Mon Jan 20, 2014 10:00 pm

grimm Mon Jan 20, 2014 10:00 pm
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
Linux Mint 19 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 435.17
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1144
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Get information from a mesh node?

Postby stratified » Mon Jan 20, 2014 10:11 pm

stratified Mon Jan 20, 2014 10:11 pm
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
User avatar
stratified
OctaneRender Team
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Re: Get information from a mesh node?

Postby grimm » Mon Jan 20, 2014 10:14 pm

grimm Mon Jan 20, 2014 10:14 pm
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
Linux Mint 19 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 435.17
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1144
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Get information from a mesh node?

Postby stratified » Mon Jan 20, 2014 10:43 pm

stratified Mon Jan 20, 2014 10:43 pm
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
User avatar
stratified
OctaneRender Team
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Re: Get information from a mesh node?

Postby grimm » Mon Jan 20, 2014 10:52 pm

grimm Mon Jan 20, 2014 10:52 pm
Ok, it's much faster than I thought. :D 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
Linux Mint 19 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 435.17
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1144
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Get information from a mesh node?

Postby stratified » Mon Jan 20, 2014 11:35 pm

stratified Mon Jan 20, 2014 11:35 pm
grimm wrote:Ok, it's much faster than I thought. :D 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
User avatar
stratified
OctaneRender Team
OctaneRender Team
 
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Re: Get information from a mesh node?

Postby grimm » Tue Jan 21, 2014 12:03 am

grimm Tue Jan 21, 2014 12:03 am
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
Linux Mint 19 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 435.17
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1144
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Get information from a mesh node?

Postby bepeg4d » Tue Jan 21, 2014 9:54 am

bepeg4d Tue Jan 21, 2014 9:54 am
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
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 6643
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy

Re: Get information from a mesh node?

Postby grimm » Tue Jan 21, 2014 7:17 pm

grimm Tue Jan 21, 2014 7:17 pm
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. :D

Jason
Linux Mint 19 x64 | Nvidia GTX 980 4GB (displays) RTX 2070 8GB| Intel I7 5820K 3.8 Ghz | 32Gb Memory | Nvidia Driver 435.17
User avatar
grimm
Licensed Customer
Licensed Customer
 
Posts: 1144
Joined: Wed Jan 27, 2010 8:11 pm
Location: Spokane, Washington, USA

Re: Get information from a mesh node?

Postby bepeg4d » Tue Jan 21, 2014 7:34 pm

bepeg4d Tue Jan 21, 2014 7:34 pm
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
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 6643
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy
Next

Return to Lua Scripting


Who is online

Users browsing this forum: No registered users and 0 guests

Mon Oct 21, 2019 7:53 pm [ UTC ]