Retrieving scene graph from simulation

Typically: "How do I... ", "How can I... " questions
Post Reply
Klaus
Posts: 21
Joined: 20 Nov 2013, 18:30

Retrieving scene graph from simulation

Post by Klaus » 06 Feb 2018, 18:06

Hello,

I would like to retrieve the current scene's "scene graph" (https://en.wikipedia.org/wiki/Scene_graph) using the remote API.
To clarify, a very simple example of what I mean is something like this:
  • world
    • pole#0
    • car#0
      • wheel#0
      • wheel#1
      • wheel#2
      • wheel#3
      • chassis#0
Considering a scene with a single car and a pole in it.
I looked into the documentation but failed to find it. Is there a command for that?

Thanks in advance.

Klaus

coppelia
Site Admin
Posts: 6736
Joined: 14 Dec 2012, 00:25

Re: Retrieving scene graph from simulation

Post by coppelia » 08 Feb 2018, 07:49

Hello Klaus,

you don't have such a function directly available from the remote API. But you can call a script function that will handle this for you (with simxCallScriptFunction). In that script function, simply iterate over all objects, for instance with:

Code: Select all

function printHierarchy(objHandle,indent)
    if objHandle~=sim.handle_scene then
        local str=string.rep('    ',indent)..sim.getObjectName(objHandle)
        print(str)
        indent=indent+1
    end
    local directChildren=sim.getObjectsInTree(objHandle,sim.handle_all,1+2)
    for i=1,#directChildren,1 do
        printHierarchy(directChildren[i],indent)
    end
end


function sysCall_init()
    printHierarchy(sim.handle_scene,0)
end
Cheers

Post Reply