fit selection to use all of the 0-1 uvw range?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Display Modes
  11 November 2005
fit selection to use all of the 0-1 uvw range?

Just wondering where to start to fit selected faces in the 0-1 range in the uvw editor.

So ive got unfold done, i then need to get the selection of the unfold, and runt he script to get it to scale to fit perfectly in the zero to 1 range.

Ive tryed messing a little with $.modifiers[#unwrap_uvw].unwrap5.getGizmoTM () but ive not done matrix maths since high school and it only spits out zeros for me...
__________________

 
  11 November 2005
Check out the pack > normalize function of the Unwrap_UVW mod.

normalize - determines whether the clusters will be fit to 0 to 1 space.
__________________
Blue
 
  11 November 2005
ive tryed messing with that, but it does not want to distort to fit exactly the zero-1 range....
__________________

 
  11 November 2005
thanks, i was just looking at that now

edt: doesnt seem to be working.... do i need to be in unrwap uvw or edit poly mode?
__________________


Last edited by Gibbz : 11 November 2005 at 11:46 AM.
 
  11 November 2005
I'm not sure to understand the problem.
Can you give more details about the context of usage ?

Don't forget the unwrap function est very depedent of the context.
The mode must be "max modify mode"
The object and only this object will be selected, and in some case the modifier itself (setCurrentObject)
 
  11 November 2005
I think that he means he wants to select some arbitrary faces, and then have the map verts associated with those faces be scaled so that they fit the largest possible area between (0-1, 0-1)
 
  11 November 2005
Ah ok. The script which I wrote operates on the entire mapfaces, not a selection.
I believe that there are just one line to change

I will make a function a little later.
 
  11 November 2005
Hey yes i want to scale the selection to fit in the 0-1 range.

I would appreciate seeing a simplified version

Thanks
Bronson
__________________

 
  11 November 2005
Here is a "simplified" version under the form of a simple function.

fn getFirstItem theBitArray = (for i in theBitArray do return i)

fn getSizeUVW obj theFaces objUnwrapMod =
	(
	objUnwrap1=objUnwrapMod.unwrap
	objUnwrap2=objUnwrapMod.unwrap2
	objUnwrapGetVertexPosition = objUnwrap1.getVertexPosition
	objUnwrapGetVertexIndexFromFace = objUnwrap1.getVertexIndexFromFace
	objUnwrapNumberPointsInFace = objUnwrap1.numberPointsInFace
	coord=objUnwrapGetVertexPosition 0f (objUnwrapGetVertexIndexFromFace (getFirstItem theFaces) 1)
	minU=coord.x ; minV=coord.y ; minW=coord.z
	maxU=coord.x ; maxV=coord.y ; maxW=coord.z
	for f in theFaces do (
		nVerts=objUnwrapNumberPointsInFace f
		for v=1 to nVerts do (
			coord=objUnwrapGetVertexPosition 0f (objUnwrapGetVertexIndexFromFace f v)
			if coord.x<minU do minU=coord.x
			if coord.y<minV do minV=coord.y
			if coord.z<minW do minW=coord.z
			if coord.x>maxU do maxU=coord.x
			if coord.y>maxV do maxV=coord.y
			if coord.z>maxW do maxW=coord.z
			)
		)
	-- min,max,size,center
	#([minU,minV,minW],[maxU,maxV,maxW],[maxU-minU,maxV-minV,maxW-minW],[(minU+((maxU-minU)/2.0)),(minV+((maxV-minV)/2.0)),(minW+((maxW-minW)/2.0))])
	)--fn

fn normalizeCoord coord size =
	(
	sx=if size[3].x==0 then 1.0 else (1.0/size[3].x)
	sy=if size[3].y==0 then 1.0 else (1.0/size[3].y)
	sz=if size[3].z==0 then 1.0 else (1.0/size[3].z)
	coord*=(transMatrix [-size[1].x,-size[1].y,-size[1].z])*(scaleMatrix [sx,sy,sz])
	)

fn normalizeUVW obj theFaces objUnwrapMod =
	(
	objUnwrap1=objUnwrapMod.unwrap
	objUnwrap2=objUnwrapMod.unwrap2
	size=getSizeUVW obj theFaces objUnwrapMod
	vertsFlag=#{}
	objUnwrap1NumberPointsInFace = objUnwrap1.numberPointsInFace
	objUnwrap1GetVertexIndexFromFace = objUnwrap1.getVertexIndexFromFace
	objUnwrap1SetVertexPosition = objUnwrap1.setVertexPosition
	objUnwrap1GetVertexPosition = objUnwrap1.getVertexPosition
	for thisFace in theFaces do (
		numPoints=objUnwrap1NumberPointsInFace thisFace
		for currentFaceVertex=1 to numPoints do (
			currentMapvert=objUnwrap1GetVertexIndexFromFace thisFace currentFaceVertex
			if not vertsFlag[currentMapvert] do ( objUnwrap1SetVertexPosition 0f currentMapvert (normalizeCoord (objUnwrap1GetVertexPosition 0f currentMapvert) size) )
			vertsFlag[currentMapvert]=true
			)
		)
	)



if selection.count==1 do (
	max modify mode
	obj=selection[1]
	select obj
	if classof obj.modifiers[1]==Unwrap_UVW
		then (
			objUnwrapMod=obj.modifiers[1]
			theFaces=objUnwrapMod.unwrap2.getSelectedFaces()
			if theFaces.numberset!=0
				then (
					normalizeUVW obj theFaces objUnwrapMod
					)
				else messageBox("no faces selected in the unwrap")
			)
		else messageBox("the top modifier must be an unwrap with a face selection")	
	)


I hope this helps

EDIT: warning: initially a column of blanks spaces seems to be added by the forum in the code. Strange... I think I removed all spaces but I am not sure.

Last edited by prettyPixel : 11 November 2005 at 09:44 AM.
 
  11 November 2005
Edit: Nm i got it working, now to make sence of it

also may i use it in my script?
__________________


Last edited by Gibbz : 11 November 2005 at 03:34 AM.
 
  11 November 2005
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 04:52 PM.


Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.