PDA

View Full Version : fit selection to use all of the 0-1 uvw range?


Gibbz
11-01-2005, 05:25 AM
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...

Blue
11-01-2005, 06:11 AM
Check out the pack > normalize function of the Unwrap_UVW mod.

normalize - determines whether the clusters will be fit to 0 to 1 space.

Gibbz
11-01-2005, 10:46 AM
ive tryed messing with that, but it does not want to distort to fit exactly the zero-1 range....

prettyPixel
11-01-2005, 11:37 AM
Maybe this thread responds to your question ?

http://forums.cgsociety.org/showthread.php?t=278913

Gibbz
11-01-2005, 11:43 AM
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?

prettyPixel
11-01-2005, 01:01 PM
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)

stuh505
11-01-2005, 01:56 PM
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)

prettyPixel
11-01-2005, 02:08 PM
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.

Gibbz
11-01-2005, 10:52 PM
Hey yes i want to scale the selection to fit in the 0-1 range.

I would appreciate seeing a simplified version :)

Thanks
Bronson

prettyPixel
11-02-2005, 12:33 AM
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.

Gibbz
11-02-2005, 03:17 AM
Edit: Nm i got it working, now to make sence of it :)

also may i use it in my script?

CGTalk Moderation
11-02-2005, 03:17 AM
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.