ScriptSpot home

Forum topic · General Scripting

Bbox Border plane and attach all mesh

By Alex · 2013-05-04

Description

Hi !
I looking for to create a little script who makes planes around my bounding box : like this picture ...

http://img15.hostingpics.net/pics/230428bboxplane.jpg

I don't need the top and bottom plane.

And I need too another script can attach all mesh together without lost Texture Information.

Someone know how I can do this?

Regards

Kasimashi

Comments (17)
miauu

One of the textures can be saved. You have tochoos which one.

Alex

:)

Works perfectly thanks you :)

But what about Attach all mesh ?

Reply to Alex
miauu

How exactly do you want to preserve the textures? If you have a Box and in the diffuse slot you have bitmap with texture - "forest.jpg",and you have a Sphere with the bitmap with texture -"rain.jpg" in the diffuse slot, when you attach the Box and the Sphere w\ich of the bitmaps should be assigned to the diffuse slot of the new object?

Reply to miauu
Alex

Ok !!!!!

Ok That why the initial texture is lost !!! :D ok ! :D

Thanks you !!! :D

Have a nice day :)

Regards

Kasimashi

miauu

Try this:

A better method to detect the plane width and length can be added, but I don't have time right now.



(
	fn planesOverFaces obj orient = 
	(	
		local planeArr = #()
		local ev = polyop.getEdgeVerts
		local gv = polyop.getvert
		local gfe = polyop.getFaceEdges
		local gfsc = polyop.getSafeFaceCenter
		local gfn = polyop.getFaceNormal
		local allFaces = (obj.Faces as bitarray) as array
		for f in allFaces do
		(
			getEdges = gfe obj f
			local sizeArr = #()
			for i in getEdges do
			(
				append sizeArr (distance (gv obj (ev obj i)[2]) (gv obj (ev obj i)[1]))
			)
			if orient == 0 then
			(w = amin sizeArr ; l = amax sizeArr)
			else
			(l = amin sizeArr ; w = amax sizeArr)
			fc = gfsc obj f
			nf = gfn obj f
			xv = normalize (cross nf [0,0,1])
			yv = normalize (cross nf xv)
			thePlane = plane length:l width:w lengthsegs:1 widthsegs:1 name:(uniquename "FacePlane")\
			isSelected:on wirecolor:(random black white) transform:(matrix3 xv yv nf fc)
			append planeArr thePlane
		)
		select planeArr
	)

	fn createBoxAsCage obj = if isValidNode obj do
	(
		local bb = in coordsys local nodeLocalBoundingBox obj
		local wX = abs((bb[1]-bb[2]).x) , lY = abs((bb[1]-bb[2]).y) , hZ = abs((bb[1]-bb[2]).z)
		local cage = convertToPoly (box width:wX length:lY height:hZ mapcoords:on name:"Cage" wirecolor:black)
		CenterPivot cage
		local tm = obj.transform
		tm.row4 = obj.center
		cage.transform = tm
		polyop.deleteFaces cage #{1,2}
		planesOverFaces cage (if wX < hZ then 0 else 1)
                delete cage
	)
	createBoxAsCage selection[1]
)

miauu

As planes:


(
	selObj = selection[1]
	theWidthX = abs (selObj.max.x - selObj.min.x)
	theLengthY = abs (selObj.max.y - selObj.min.y)
	theHeightZ = abs (selObj.max.z - selObj.min.z)
	boxAsCage = box width:theWidthX length:theLengthY height:theHeightZ --boxMode:true
	CenterPivot boxAsCage
	boxAsCage.pos = selObj.center
	boxAsCage.pivot = selObj.pivot
	convertToPoly boxAsCage
	polyop.deleteFaces boxAsCage #{1..2}
	
	for f = polyop.getNumFaces boxAsCage to 1 by -1 do
		polyop.detachFaces boxAsCage #{f} delete:true asNode:true  node:boxAsCage
)
Reply to miauu
Branko Živković

Now you have both versions complited

fn createBoxAsCage obj = if isValidNode obj do
(
local bb = in coordsys local nodeLocalBoundingBox obj
local wX = abs((bb[1]-bb[2]).x) , lY = abs((bb[1]-bb[2]).y) , hZ = abs((bb[1]-bb[2]).z)
local cage = convertToPoly (box width:wX length:lY height:hZ mapcoords:on name:"Cage" wirecolor:black)
CenterPivot cage
local tm = obj.transform
tm.row4 = obj.center
cage.transform = tm
polyop.deleteFaces cage #{1,2}
local mtlArr = #()
for m = 4 to 1 by -1 do
(
id = (polyop.getFaceMatID cage m) - 2
side = ("Side_"+m as string)
polyop.setFaceMatID cage m id
polyop.detachFaces cage #{m} delete:true asNode:true node:boxAsCage name:side
(getnodebyname side).material = standard name:("Mtl_" + m as string) diffuse:(random black white)
CenterPivot (getnodebyname side)
)
delete cage
)
-- example
delete objects
tea = Teapot pos:[20,50,30] dir:[0.616459,-0.51929,0.591875] scale:[.8,.8,.8]
createBoxAsCage tea

Reply to miauu
Branko Živković

Hey Kostadin,

you left over one dead geometry using detach method, because after detaching all four faces main object stay dead. :)

Reply to miauu
Alex

:p

Thanks ! but last thing :) It's standard primitive plane not a editable poly :)

Regards Friend !

Reply to Alex
Branko Živković

Hey dude you are not serious. Next time be more specific. On this forum I already write snippet for plane aligment. You need to find this by yourself.

Alex

Thanks !!!!

Thanks you miauu and barigazy but I need 4 Planes :) I don't need a box :p How can I detach face ?

Thanks again for your help !

What about "attach all mesh"?

Regards friend!

miauu

Local BBox of the selected object or world bbox?

This is for world bbox:


(
	selObj = selection[1]
	theWidthX = abs (selObj.max.x - selObj.min.x)
	theLengthY = abs (selObj.max.y - selObj.min.y)
	theHeightZ = abs (selObj.max.z - selObj.min.z)
	boxAsCage = box width:theWidthX length:theLengthY height:theHeightZ --boxMode:true
	CenterPivot boxAsCage
	boxAsCage.pos = selObj.center
	boxAsCage.pivot = selObj.pivot
	convertToPoly boxAsCage
	polyop.deleteFaces boxAsCage #{1..2}
)

It will create a editable poly box around your object. If you want planes - detach the faces of the created box.

What is texture information?

Reply to miauu
Branko Živković

:)

A bit acurate. This time I will consider object orientation, scale and mtlID's

fn createBoxAsCage obj = if isValidNode obj do
(
local bb = in coordsys local nodeLocalBoundingBox obj
local wX = abs((bb[1]-bb[2]).x) , lY = abs((bb[1]-bb[2]).y) , hZ = abs((bb[1]-bb[2]).z)
local cage = convertToPoly (box width:wX length:lY height:hZ mapcoords:on)
CenterPivot cage
local tm = obj.transform
tm.row4 = obj.center
cage.transform = tm
polyop.deleteFaces cage #{1,2}
local mtlArr = for m = 1 to 4 collect
(
local id = (polyop.getFaceMatID cage m) - 2
polyop.setFaceMatID cage m id
standard name:("Mtl_" + m as string) diffuse:(random black white)
)
cage.material = Multimaterial materialList:mtlArr
cage
)
-- example
delete objects
tea = Teapot pos:[20,50,30] dir:[0.616459,-0.51929,0.591875] scale:[.8,.8,.8]
createBoxAsCage tea

Reply to miauu
Branko Živković

Yup. Both solutions are good
Regards friend!