Collision creation script issues

Hey all, I hope everyone is doing well. I have an issue with this script I'm working on, and it is boggling my mind. It is used to take your whole selection and create individual UCX collision hulls around each, constrained to the parent object's dimensions, and named after it.

The thing is, it does all of this just fine. But then it seems to condense all of these new models down to one single point (all verts are stacked one on top of each other at the origin). If someone could take a look at it and tell me what I am missing, it would be much appreciated.

(
----------------------------------------------------------------Design-------------
rollout collCreation "Collision Creator"
	(
		group "Create Collision"
		(
		button coll_btn "Create Collision" align:#center
		)
		on coll_btn pressed do
		(
			selectedObjs = getCurrentSelection()
			for i = 1 to selectedObjs.Count do
			(
-------------------------FUNCTIONS------------------------------------------------
				fn maximum a b = 
				(
					if a > b then return b
						return a
				)
				fn minimum a b = 
				(
					if a < b then return b
						return a
				)
---------------------End FUNCTIONS----------------------------------------------
				local objName = selectedObjs[i].name as string
				objFaces = polyop.getFaceSelection selectedObjs[i]
				objVerts = polyop.getVertsUsingFace selectedObjs[i] objFaces
 
				boxMin = point3 0 0 0
				boxMax = point3 0 0 0
 
				vertPrime == true
 
				for i = 1 to objVerts.count do
				(
					if objVerts[i] == true do
					(
						cV = objVerts[i]
						if vertPrime == true then
						(
							boxMin.x = cV.pos.x
							boxMin.y = cV.pos.y
							boxMin.z = cV.pos.Z
							boxMax.x = cV.pos.x
							boxMax.y = cV.pos.y
							boxMax.z = cV.pos.z
							vertPrime = false
						)
						else 
						(
							boxMin.x = minimum cV.pos.x boxMin.x
							boxMin.y = minimum cV.pos.y boxMin.y
							boxMin.z = minimum cV.pos.z boxMin.z
							boxMax.x = maximum cV.pos.x boxMax.x
							boxMax.y = maximum cV.pos.y boxMax.y
							boxMax.z = maximum cV.pos.z boxMax.z
						)
					)
				)
				center = point3 0 0 0
				center.x = (boxMax.x - boxMin.x) * .5 + boxMin.x
				center.y = (boxMax.y - boxMin.y) * .5 + boxMin.y
				center.z = (boxMax.z - boxMin.z) * .5 + boxMin.z
				(
					bW = (boxMax.x - boxMin.x)
					bL = (boxMax.y - boxMin.y)
					bH = (boxMax.z - boxMin.z)
					bC = center - [0 , 0 , (bH/2)]
 
					newColl = Box name:("UCX_" + objName) length:bL width:bW height:bH pos:bC
					convertToPoly newColl
				)
			)
		)
	)
--------------End Design---------------------------------------------------
createDialog collCreation width:200
cui.RegisterDialogBar collCreation style:#(#cui_floatable,#cui_dock_left,#cui_dock_right,#cui_handles)
)

Comments

Comment viewing options

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

Nevermind on this, I got it

Nevermind on this, I got it figured out. I was massively overcomplicating it.

Comment viewing options

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