Notifications
Clear all

[Closed] Bounding box for an array of vertex or faces

Is there min and max functions for an array of vertex or faces similar to the ones for scene objects? I would like to get the bounding box for selected vertex or faces from some mesh.

9 Replies

there is a new value class in MXS >> Box3()
here is the way how to get bounding box of selected poly verts:

bb = box3()
for v in $.selectedverts as bitarray do expandToInclude bb (polyop.getvert $ v)
bb

see the mxs help for more details

First thanks for your reply, unfortunately I am using older max versions so this can´t worck for me. Is there some other way, or do I have to do it manually? By manually I mean comparing every single x, y and z value for every vertex.

you answered your own question.

fn getVertBounding node verts: = 
(
	local bmin = [1e9,1e9,1e9], bmax = [-1e9,-1e9,-1e9]
	
	if verts == unsupplied do verts = node.selectedverts as bitarray
	for v in verts do
	(
		p = polyop.getvert node v
		if p.x < bmin.x do bmin.x = p.x
		if p.y < bmin.y do bmin.y = p.y
		if p.z < bmin.z do bmin.z = p.z
		if p.x > bmax.x do bmax.x = p.x
		if p.y > bmax.y do bmax.y = p.y
		if p.z > bmax.z do bmax.z = p.z
	)
	#(bmin, bmax)
)

but it’s best to always think a bit first and find a solution yourself

OK, thanks again. Posibly this question could sound stupied, but isn´t it beter to use caseof instead of that ifs?

do you always prefer not to think? let’s do so … you will think well, and then tell us why case of does not work here

Sorry, like I said the question might be stupied and looks like it really is. What I meaned was something like this:


p = polyop.getvert node v
case of(
(p.x < bmin.x): bmin.x = p.x
(p.y < bmin.y): bmin.y = p.y
(p.z < bmin.z): bmin.z = p.z
(p.x > bmax.x): bmax.x = p.x
(p.y > bmax.y): bmax.y = p.y
(p.z > bmax.z): bmax.z = p.z
)

Just remember to see some example like that, but looks like my memory plaied a bad joke.

that means the thinking is not necessary in you case … ok, then use the “case of”

well … I might agree that thinking is not interesting, but at least you would try and compare two options

gtafan, this is directly copied from maxscript help file:

The case expression is used to select an expression to be evaluated from a set of labeled expressions based on a test value compared against the labels.

Only the first expression whose label matches the test expression is evaluated.

The bolded sentence is the key. If you use case of in your code for each vert only one of the bmin/bmax x,y,z values will be updated, so at the end you will not have the proper bbox of the verts.

With case of if the p.x < bmin.x the script will update the value of bmin.x and will continue with the next iteration(vertex), all other expressions(p.y<bmin.y, p.z<bmin.z, etc) will not be checked and evaluated. But p.y may also be less than bmin.y and if case of is used the bmin.y will not be udpated.

Thanks, now I see where I was thinking wrong. But 3 separate case of for every axis or a for loop should do it, or am I still wrong?
I mean for example this:

case of(
(p.x < bmin.x): bmin.x = p.x
(p.x > bmax.x): bmax.x = p.x
)
case of(
(p.y < bmin.y): bmin.y = p.y
(p.y > bmax.y): bmax.y = p.y
)
case of(
(p.z < bmin.z): bmin.z = p.z
(p.z > bmax.z): bmax.z = p.z
)