PDA

View Full Version : Search Objects by Radius/Distance from an object


NahuelL
11-07-2010, 04:28 PM
Hey guys,

Is there a way to search objects in the scene by a specific radius (distance) from the pivot of an object?

Here is an example:

http://img149.imageshack.us/img149/8594/searchod.png

Thanks
Nahuel

Bobo
11-07-2010, 04:39 PM
Hey guys,

Is there a way to search objects in the scene by a specific radius (distance) from the pivot of an object?

Thanks
Nahuel

You mean you want to collect all objects that are within a certain radius?
Or you want to get the distance to a specific object?

In the former case, you would say

theRadius = 500.0 --this is the radius to search within
theObject = pickobject() --let the user pick a reference object by clicking in the viewport
select (for o in objects where o != theObject and distance o theObject < theRadius collect o)


In the latter case, you can just use the (distance objectA objectB) expression to get the distance between any two objects. Note that distance() works on scene objects AND Point3 values, so you can also say (distance objectA.pos objectB.pos), as well as (distance objectA.pivot objectB.pivot), or even (distance objectA.pos [100,200,-300]) if you know a reference position in world space and want to specify it explicitly...

NahuelL
11-07-2010, 05:32 PM
Yes, I wanted to collect all objects that were within a certain radius.
Thank you very much!

CGTalk Moderation
11-07-2010, 05:32 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.