Bounding box of selected faces

Hi guys, how´s going?
i know there´s some scripts of "create bounding box" objetcs, that creates a box over the selected objects (like this one - http://www.scriptspot.com/3ds-max/scripts/translated-bounding-box). I need a script that makes the same thing, but only in the selected faces (or any sub-object, but mostly faces). I found this one - http://www.scriptspot.com/3ds-max/scripts/bounding-boxer - and it does what i want, but it too "complicated", i need something quicker. Does anyone can help me? I tried to do it using max listener, detaching the faces as a copy and then creating a bounding box using the new object, but for some reason it doesn´t work all the times.
Thanks in advance,

Jsrocha

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

Now I saw(in Brakno's image) that my solution not works with rotated objects.
Here the fixed code. It works with rotated object, but if the objet is rotated ad sub-object level it will not work.
There is one very ugly line of code, but with it all matrix/math operations are skipped. :)

(	
	if selection.count == 1 and classOf (curO = selection[1]) == Editable_Poly do
	(
		if (selFacesBA = polyop.getFaceSelection curO).numberset != 0 do
		(
			faceVertsBA = polyop.getVertsUsingFace curO selFacesBA
			curOtransform = curO.transform
			curO.rotation = quat 0 0 0 1
			with redraw off 
			(
				tMesh = mesh mesh:curO.mesh
				tMesh.pos = curO.pos
				tMesh.objectOffsetPos = curO.objectOffsetPos
				if faceVertsBA.count > 0 do 
				(
					delete tMesh.verts[((tMesh.verts as BitArray) - (faceVertsBA))]
				)
				c = snapshot tMesh
				c.transform = matrix3 1
-- 				d = dummy boxsize:(c.max - c.min)
				size = (c.max - c.min)
				d = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:size[2] width:size[1] height:size[3]
				centerPivot d
				delete c
				d.transform = tMesh.transform
				d.pos = tMesh.center
				d.name = tMesh.name + "_box"
				--	very ugly, but skip all math operations
				d.parent = curO
				delete tMesh
				curO.transform = curOtransform
				d.parent = undefined
			)
		)
	)
)
barigazy's picture

...

Definitely we have to go back to elementary school to learn matrix.
Life is easier with knowledge of the matrix, no more mambo-jambo-pseudo codes.
:)

barigazy

barigazy's picture

...

You last code works fine. Now try to rotate object and resetXForm and then try code. Again matrix problem :)

barigazy

miauu's picture

Ii will not works in this

Ii will not works in this case. The sama as when the object is rotated at sub-object level.
But it is better than nothing. :)
You can continue to fight with the matrix. I give up.:)

barigazy's picture

...

I give Up before U (after I posted my concept). I tried with matrix there but without of luck.
:)

barigazy

miauu's picture

.

The corrected code:

(	
	if selection.count == 1 and classOf (curO = selection[1]) == Editable_Poly do
	(
		if (selFacesBA = polyop.getFaceSelection curO).numberset != 0 do
		(
			faceVertsBA = polyop.getVertsUsingFace curO selFacesBA
			with redraw off 
			(
				tMesh = mesh mesh:curO.mesh
				tMesh.pos = curO.pos
				tMesh.objectOffsetPos = curO.objectOffsetPos
				if faceVertsBA.count > 0 do 
				(
					delete tMesh.verts[((tMesh.verts as BitArray) - (faceVertsBA))]
				)
				c = snapshot tMesh
				c.transform = matrix3 1
				size = (c.max - c.min)
				d = Box lengthsegs:1 widthsegs:1 heightsegs:1 length:size[2] width:size[1] height:size[3]
				centerPivot d
				delete c
				d.transform = tMesh.transform
				d.pos = tMesh.center
				d.name = tMesh.name + "_box"
				delete tMesh
			)
		)
	)
)

Branko is right. Matrix in all 3dCAD sfoftware is for people who knows much about math. I am not one of them.
That's why I use Anubis code - no Matrix and Mat operations at all.
:)

miauu's picture

.

This is combination of two scripts, written by Anubis.
You have to optimize the code.

(	
	if selection.count == 1 and classOf (curO = selection[1]) == Editable_Poly do
	(
		if (selFacesBA = polyop.getFaceSelection curO).numberset != 0 do
		(
			faceVertsBA = polyop.getVertsUsingFace curO selFacesBA
			with redraw off 
			(
				tMesh = mesh mesh:curO.mesh
				tMesh.pos = curO.pos
				tMesh.objectOffsetPos = curO.objectOffsetPos
				if faceVertsBA.count > 0 do 
				(
					delete tMesh.verts[((tMesh.verts as BitArray) - (faceVertsBA))]
				)
				c = snapshot tMesh
				c.transform = matrix3 1
				d = dummy boxsize:(c.max - c.min)
				delete c
				d.transform = tMesh.transform
				d.pos = tMesh.center
				d.name = tMesh.name + "_box"
				delete tMesh
			)
		)
	)
)
barigazy's picture

...

I have different concept but still not good

(
	local obj = selection[1], faces = #{}
	local dp = datapair #() #()
	local getNorm = polyop.getFaceNormal
	local faceC = polyop.getFaceCenter
	local xV,yV,zV,cnt = [0,0,0] 
	if not (faces = obj.selectedfaces as bitarray).isEmpty do
	(
		for i in faces do
		(
			if dp.v1.count == 0 then append dp.v1 i
			else if (distance (getNorm obj dp.v1[1]) (getNorm obj i)) < 0.01 then append dp.v1 i else append dp.v2 i
		)
	)
	case of
	(
		(dp.v1.count < dp.v2.count): 
		(
			xV = getNorm obj dp.v1[1] ; zV = getNorm obj dp.v2[1] ; yV = normalize (cross xV zV)
			for i = 1 to dp.v2.count do cnt += faceC obj dp.v2[i] ; cnt /= dp.v2.count
		)
		(dp.v1.count > dp.v2.count): 
		(
			xV = getNorm obj dp.v2[1] ; zV = getNorm obj dp.v1[1] ; yV = normalize (cross xV zV)
			for i = 1 to dp.v1.count do cnt += faceC obj dp.v1[i] ; cnt /= dp.v1.count
		)
		default: 
		(
			xV = getNorm obj dp.v1[1] ; zV = getNorm obj dp.v2[1] ; yV = normalize (cross xV zV)
			for i = 1 to dp.v2.count do cnt += faceC obj dp.v2[i] ; cnt /= dp.v2.count
		)
	)
	local tm = matrix3 xV yV zV cnt
	polyop.detachFaces obj faces delete:off asNode:on name:"tempObj"
	CenterPivot $tempObj ; ResetXForm $tempObj ; convertToMesh $tempObj
	w = in coordsys tm abs($tempObj.max.x - $tempObj.min.x)
	l = in coordsys tm abs($tempObj.max.y - $tempObj.min.y)
	h = in coordsys tm abs($tempObj.max.z - $tempObj.min.z)
	delete $tempObj
	Box lengthsegs:1 widthsegs:1 heightsegs:1 length:l width:w height:h transform:tm name:"BoxFromFaces" isSelected:on
)

This is the result of theses two examples

barigazy

jsrocha's picture

Hey Barigazy, i tried your

Hey Barigazy, i tried your code here, but i got strange results. My first test results ok:
http://prntscr.com/1qr58l

but the second got wrong:
http://prntscr.com/1qr5ca

Thanks man,

Jsrocha

barigazy's picture

...

My method is wrong. Try to rotate object and you'll see.
I love Matrix movie but matrix in max is pain in the ... :)
Only few people know how to deal with it. Bobo and DenisT.
Kostadin are you here to confirm this :)

barigazy

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.