## Retrieve scene objects of a defined area

Typically: "How do I... ", "How can I... " questions
makbut
Posts: 10
Joined: 29 Dec 2016, 11:39

### Retrieve scene objects of a defined area

Hello,

I have a big scene where I have placed a lot of cuboid scene objects and in each simulation step I want to get the position and orientation of all objects inside a specific area of interest which changes constantly as the robot moves.

I don't want to iterate through all objects, get their position and check if the position is inside my desired area. On the other hand I would like to know if there is any way of searching inside a defined area, find if there are any scene objects there, retrieve them and then get their position?

Is there any way to do so?

coppelia
Posts: 7966
Joined: 14 Dec 2012, 00:25

### Re: Retrieve scene objects of a defined area

Hello,

why don't you want to iterate over every objects? I am afraid there is no alternative. You can do something like:

Code: Select all

local allObjects=simGetObjectsInTree(sim_handle_scene,sim_handle_all,0)
for i=1,#allObjects,1 do
local pos=simGetObjectPosition(allObjects[i],-1)
if pos[1]>xMin and pos[1]<xMax and pos[2]>yMin and pos[2]<yMax and pos[3]>zMin and pos[3]<zMax  then
print("inside the area!")
end
end

Cheers

makbut
Posts: 10
Joined: 29 Dec 2016, 11:39

### Re: Retrieve scene objects of a defined area

Yes, I am doing more or less the same.
It is just that I have a lot of objects and I was trying to find an optimal way of getting those that are of interest by minimizing the "for loop".
Thank you very much for the answer,