Notifications
Clear all

[Closed] need help for bend in Unwrap

Hello to all.
I am trying to add some functionality in the Unwrap modifier.
This is based on Chugnut’s unwrap code.
I would like to have a ‘bend’ spinner to bend selected UVverts in either U or V direction about the transform center.
I have tried a few times without success. Could any one help ?
here is the starting code:

(
 	local uv = modpanel.getcurrentobject()
 	local offset, range, uvs=#(), sel = (uv.getselectedvertices()) as array
 	struct dims (width, height, mid, maxUV, minUV)
 	
 	function getdims sel &uv =
 	( -- bouding box of selected UVs
 		minUV = [99999,99999,0]
 		maxUV = [-99999,-99999,0]
 		mid = [0,0,0]
 	
 		for i in sel do
 		(
 			p = uv.getvertexposition currenttime i
 			--check X
 			if p.x > maxUV.x then (maxUV.x = p.x)
 			else (if p.x < minUV.x do (minUV.x = p.x))
 			--check Y
 			if p.y > maxUV.y then (maxUV.y = p.y)
 			else (if p.y < minUV.y do (minUV.y = p.y))
 		)
 	
 		w = (maxUV.x - minUV.x)
 		h = (maxUV.y - minUV.y)
 		return (dims width:w height:h mid:([minUV.x + (w * 0.5), minUV.y + (h * 0.5),0]) maxUV:maxuv minUV:minuv)
 	)
 	
 	fn getsetup =
 	(
 		ConvertSel uv 1
 		uv.snappivot activecentre
 		uvs = #()
 		sel = (uv.getselectedvertices()) as array
 		dim = unwrapUI.getdims sel &uv
 		
 		/*
 		1 is the center
 		2 is the lower left of the selection
 		3 is the lower center of the selection
 		4 is the lower right of the selection
 		5 is the right center of the selection
 		6 is the upper right of the selection
 		7 is the upper center of the selection
 		8 is the upper left of the selection
 		9 is the left center of the selection
 		*/
 		
 		offset = case activecentre of
 		(
 			1:[dim.mid.x, dim.mid.y, 0]
 			2:[dim.minuv.x, dim.minuv.y, 0]
 			3:[dim.mid.x, dim.minuv.y, 0]
 			4:[dim.maxuv.x, dim.minuv.y, 0]
 			5:[dim.maxuv.x, dim.mid.y, 0]
 			6:[dim.maxuv.x, dim.maxuv.y, 0]
 			7:[dim.mid.x, dim.maxuv.y, 0]
 			8:[dim.minuv.x, dim.maxuv.y, 0]
 			9:[dim.minuv.x, dim.mid.y, 0]
 		)
 	
 		for i in sel do append uvs ((uv.getvertexposition currenttime i) - offset)
 	
 		dim.maxuv -= offset
 		dim.minuv -= offset
 		range = dim.maxuv - dim.minuv
 	)
 	
 	fn BendU dir angle
 	(
 		for i = 1 to sel.count do
 		(
 			local p = uvs[i]
 			if angle != 0 then
 			(
 				/* WRONG .......
 				theDirMatrix=rotateZMatrix 0
 				theRadius = (180/spnBU.value*range.y/Pi/2)
 				theRadiusOffset = [theRadius,0,0] * theDirMatrix
 				TM = rotateZMatrix ((spnBU.value*p.y/range.y)) * theDirMatrix
 				TM.row4 = theRadiusOffset
 				uv.setvertexposition2 currenttime sel[i] (([p.x,p.y,0]-theRadiusOffset)*TM + offset) true false
 				*/
 			)
 			else p
 		)
 	)
 )