[Closed] calculating distance between objects
As I go deeper and deeper with my spagetti code like I found more and more interesting
stuff to do in order to achieve my goal.
How to select objects in hierarchy which are in specified distance from root?
let say I have bone and object binded to this bone, I would like to select this
binded objects if distance from root for x or y or z >200
One more, I gonna operate on different scenes. Do distance 200 from
object to object will always be this same percentage of distance for different scenes?
I hope it’s clear enough:)
I forgot to mention that object(s) binded to root I’m looking for, can be many-selection
fn SelectByDistance dist =
(
local sel = for o in selection where (distance [0,0,0] o.pos < dist) collect o
clearSelection()
select sel
)
SelectByDistance 20
Something like that ?
Thankyou Feranti, I check it it don’t select objects no matter what distance between object is. I don’t know even how to define objects inside this function or do I have to or not. My bad.
I thing operation should look like this:
for o in selection where o is in herarchy do
(
if o position.distance from root>200 then select o
)
Can you do something like this but working?I would be very
grateful.
fn SelectByDistanceFromParent dist =
(
local sel = for o in selection where (o.parent!=undefined AND distance o.parent.pos o.pos > dist) collect o
clearSelection()
select sel
)
SelectByDistanceFromParent 100
Is that better ?
To use it, select the objects you want to filter, change the distance value in the last line, and run the code.
Looking at your first post, are you sure you want to filter object by distance (a sphere around the parent) or according x or y or z (a cube around the parent) ?
If so, use that code instead:
fn SelectByDistanceFromParent dist =
(
local sel = for o in selection where (o.parent != undefined AND (abs (o.pos.x-o.parent.pos.x) > dist OR abs (o.pos.y-o.parent.pos.y ) > dist OR abs (o.pos.z-o.parent.pos.z) > dist) ) collect o
clearSelection()
select sel
)
SelectByDistanceFromParent 100
Today I go back to this script, it worked beck then when I test it but don’t work in practice.
Second script look like what I’m looking for however it works only between two objects so this time I will be more precised.
I have to distinguish objects which don’t belong to any animation systems in spite of they are in hierarchy with them.
I want to filter(select) object in selection which perform following conditions:
- object(s) are children in specified dystans (x,y,z) from their parents.
Dystans should be as variable version 1) and version 2) 1 distance unit=1 parent size.
So idea is to grab object children far a way from their roots which are surely not bones continuation or attached character item.
I attache test scene, when You select each of this selection or all of them only red objects should be selected. I would be thankful for help
Here is another last try on it. I filtered bones and biped objects :
fn _getPos node =
(
if (classof node == Biped_Object) then biped.getTransform node #pos
else node.pos
)
fn SelectByDistanceFromParent dist =
(
local sel = for o in selection where ((classof o != Biped_Object) AND (classof o != BoneGeometry) AND o.parent != undefined AND (abs ((_getPos o).x-(_getPos o.parent).x) > dist OR abs ((_getPos o).y-(_getPos o.parent).y ) > dist OR abs ((_getPos o).z-(_getPos o.parent).z) > dist) ) collect o
clearSelection()
select sel
)
SelectByDistanceFromParent 100 -- the distance you want here
But I still don’t really understand some points… like this one:
Dystans should be as variable version 1) and version 2) 1 distance unit=1 parent size
Moreover, in your example scene, how did you you mean to distinguish the parent sphere “belonging to the animated system” and the red one ? I don’t see ho i could make the difference, except if the grey sphere were wearing keys… But in this case, this means that you can’t animate the red sphere because it will be considered as part of your “animated system”.
Nethermind, if you want to filter the animated object only, here is a thread about it:
http://forums.cgsociety.org/showthread.php?f=98&t=1143002
…which is yours, by the way