for i = 1 to 3 do
(
if n.min[i] < bMin[i] do bMin[i] = n.min[i]
if n.max[i] > bMax[i] do bMax[i] = n.max[i]
)
Is this really an optimization ?
No, only shorter code.
The main difference is that your algorithm is recursive, while mine uses the join hack to get max to do the recursion for me.
p.s. – I wrote my code the same time you did, not as a response to your code.
performance comparison (100 iterations with hierarchy of ~100 objects):
maxscript recursive:
time: 186 ms
memory: 1108120L
join method:
time: 71 ms
memory: 27256L
further optimization (cached n.min and n.max and unrolled loop):
fn getHierarchyBBox node =
(
local bMin = [1e100, 1e100, 1e100]
local bMax = [-1e100, -1e100, -1e100]
for n in join #() node do
(
local nMin = n.min
local nMax = n.max
if nMin[1] < bMin[1] do bMin[1] = nMin[1]
if nMax[1] > bMax[1] do bMax[1] = nMax[1]
if nMin[2] < bMin[2] do bMin[2] = nMin[2]
if nMax[2] > bMax[2] do bMax[2] = nMax[2]
if nMin[3] < bMin[3] do bMin[3] = nMin[3]
if nMax[3] > bMax[3] do bMax[3] = nMax[3]
)
#(bMin, bMax)
)
A coworker of mine discovered the join trick by mistake a few days ago, I was keen to find a practical use for it
Here is the callback that changes the wirecolor of an object’s sibling to red.
(
global IdentifyGroups_savedSiblings
global IdentifyGroups_wireColor = (color 176 26 26)
local storeWirecolor, manageSiblingsColor, revertSiblingsColor, setSiblingsColor
sW = attributes storedWirecolor
(
parameters main
(
color type:#color
)
)
fn storeWirecolor obj =
(
custattributes.add obj sW
print "storeWirecolor"
obj.storedWirecolor.color = obj.wirecolor
)
fn manageSiblingsColor ev nd =
(
if IdentifyGroups_savedSiblings != undefined do revertSiblingsColor IdentifyGroups_savedSiblings
setSiblingsColor selection
redrawviews()
)
mapped fn revertSiblingsColor obj =
(
if (isProperty obj "storedWirecolor") then obj.wirecolor = obj.storedWirecolor.color
else obj.wirecolor = color (random 0 255) (random 0 255) (random 0 255)
)
mapped fn setSiblingsColor obj color:(color 176 26 26) =
(
if (isValidNode obj) do
(
IdentifyGroups_savedSiblings = undefined
if obj.parent != undefined do
(
IdentifyGroups_savedSiblings = for o in obj.parent.children where o != obj collect o
print IdentifyGroups_savedSiblings
for child in IdentifyGroups_savedSiblings do
(
if (isProperty child "storedWirecolor") then child.storedWirecolor.color = child.wirecolor
else storeWirecolor child
child.wirecolor = color
)
)
)
)
global wirecolorCallback = NodeEventCallback selectionChanged:manageSiblingsColor added:manageSiblingsColor deleted:manageSiblingsColor
)
Cheers for those bits guys, very useful.
Denis, I’m a bit confused about the concept of using a Scripted Manipulator for this…
Do we still use a BoxGizmo object?
i think that it will be more complicated to receive all hierarchy change events using a simple node (or inherited from Dummy). a simple node receives only message about only immediate children change.
a manipulator receives probably all scene change messages. i will check…
it seems like i was wrong. the manipulator doesn’t easy receive link/unlink messages.
ok. we changing a plan. i have better idea. scripted controllers…
my function is not working right… i need to review it. children.min/children.max returns only bbox of last child. it’s strange… i have to check what to do.