[Closed] attach to nearest object by threshold
Here’s the situation. I have an apartment building and I need to attach windowglas to it’s encasing window so i can rotate the windows to an open position and the glass will follow.
I was thinking this would be easiest by selecting the glass and set it’s parent to the closest objects to its boundingbox by a certain threshold (say 3 units or whatever) or something ?
anyone care to help me out here
Do you have the glass and the window boxes rightly named? If not, do you have materials applied to it? Because if you do, it’s would be good to rename the glass as Glass_ something and window boxes as WindowBoxes_ something just to get a good start.
never mind
I figured it out.
here’s the code in case someone else runs into this.
for obj in $window* do -- loop through all windows
(
for glass in $glass* do -- loop through all glass objects
(
-- compare the position of glass objects to window objects within a threshold of 5 units
if (((glass.pos.y - 5.0) <= obj.pos.y) and ((glass.pos.y + 5.0) >= obj.pos.y) and
((glass.pos.z - 5.0) <= obj.pos.z) and ((glass.pos.z + 5.0) >= obj.pos.z) and
((glass.pos.x - 5.0) <= obj.pos.x) and ((glass.pos.x + 5.0) >= obj.pos.x)) do
(
glass.parent = obj -- set the window as parent of the glass in the "same" position
)
)
obj.pivot.z = obj.min.z -- set the pivot of the window to it's lowest point (for easy rotation from the windows bottom edge)
)
Why not just use a distance function?
if distance $myObj $glassObj <= 5 do ...
-Johan
Just for reference then, the updated script.
Thanks Johan
for window in $window* do
(
for windowglass in $glass* do
(
if distance windowglass.pos window.pos <= 5 do
(
windowglass.parent = window
)
)
window.pivot.z = window.min.z
)