Notifications
Clear all

[Closed] Accessing UVW Unwrap

Hi There,
Does anyone know how I would go about doing the following.

assuming you have a mesh selected that already has a UVW map applier, and a UVW unwrap modifier. The UVW map sets the basic scale and orientation of the mapping required. This script aims to randomise the UVW position on a per polygon basis.

so, the script wants to cycle through every face/polygon in the model, and offset the position of the UVW coords in the UVWUnwrap moodifier.

Thanks!

9 Replies
1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

fn RandomizeUVFaces theObject theMod theOffset =
(
theFaceCount = theMod.numberPolygons() --get number of polygons
for f = 1 to theFaceCount do --loop through polygons
(
theMod.selectPolygons #{f} --select F-th polygon
theMod.GetSelectionFromFace() --convert face to vertex selection
theMod.moveSelectedVertices (random -theOffset theOffset ) --move +/- random offset
)
)--end fn

--call function with object, modifier and offset as arguments:
RandomizeUVFaces $ $.unwrap_uvw [0.05,0.05,0] 

im sorry but i dont really get the use of this script

i see situation like you have a wood fence using a giant tileable texture but you want some chaos in the uv just to dont see the same mark at the same place on every wood plank
or any similar situation
But this would require a noise on the uv element. this seem to be more on a polygon basic.
am i right?

Damm bobo you must be one of the most helpful user of this forum. Thanx

1 Reply
(@bobo)
Joined: 1 year ago

Posts: 0

I don’t know (or care) what the script is for, so I cannot answer
But it does move vertices on a per face basis, so vertices shared by multiple faces are moved multiple times. The result is very similar to moving the vertices instead.
Try creating a Plane with lots of segments, adding a checker map and an Unwrap and running the script to see the result – it is very similar to adding noise to the UV channel…

Thanks (yet) again!

Deadalus : The problem with using a noise on the uvw is that the noise smoothly spans across the geometry, so for example…
I have a wall of glazing as one mesh, ie lots of seperate boxes, I want the mapping on each pane to be different, using a noise would result in either the same noise on each pane(face mapping) or the noise would span across each pane (planar mapping). By randomising the UVW each pane would appear to have a different noise map. I think the traditional way of doing this would be to use a multi-sub material with say 5 materials with the noise phase randomised. This requires 5 materials and extra work to randomise the mat id’s. Using a UVW randomiser would require only one material, and one click of the script. Alot simpler and neater I think!
Unless I have missed a really obvious alternative solution?

Ok, this is almost working, but not quite.

When the script runs, it looks like the vertices are moved randomly, so the shape of the faces (ie rectangular) becomes randomised. I want to keep the original proportions and sizes of the uvw’s the same, but have the uvw’s moved on a per-face basis.
I’ve tried to correct this by applying the random move to the face sub-objects rather than the vertices, and also by trying to detach the edges. For some reason detachedgevertices doesnt seem to work. Any ideas?

fn RandomizeUVFaces theObject theMod theOffset =
(
	theFaceCount = theMod.numberPolygons() --get number of polygons
	for f = 1 to theFaceCount do --loop through polygons
	(
		theMod.selectPolygons #{f} --select F-th polygon
		subObjectLevel = 3 -- switch to face subobject level
		theMod.detachEdgeVertices -- detach edge vertices (not working)
		--theMod.GetSelectionFromFace() --convert face to vertex selection (not required?)
		
		theMod.moveSelected (random -theOffset theOffset ) --move +/- random offset
	)
)--end fn


macroScript randomUVW category:"reForm Utilities" 
(
	--call function with object, modifier and offset as arguments:
	RandomizeUVFaces $ $.unwrap_uvw [0.05,0.05,0]
) 

fn RandomizeUVFaces theObject theMod theOffset =
 (
 	theFaceCount = theMod.numberPolygons() --get number of polygons
 	for f = 1 to theFaceCount do --loop through polygons
 	(
 		numPoints = theMod.numberPointsInFace f --get number of vertices in face
 		theFaceOffset = (random -theOffset theOffset ) --get a single random offset
 		for v = 1 to numPoints do --go through all vertices in the face
 		(
 			vertIndex = theMod.getVertexIndexFromFace f v --get the actual index of the vertex
 			oldPos = theMod.getVertexPosition currenttime vertIndex --get its position
 			theMod.setFaceVertex (OldPos+theFaceOffset) f v false--set its position - this also detaches it 
 		)	
 	)
 )--end fn
 
 
 macroScript randomUVW category:"reForm Utilities" 
 (
 	--call function with object, modifier and offset as arguments:
 	RandomizeUVFaces $ $.unwrap_uvw [0.05,0.05,0]
 	select $
 ) 

<kicks myself at not seeing the obvious solution>

wow, so you need to move the verts together. Just out of interest, why does moveSelected not work?

I definately owe you a pint now

Just a note – to get quads moved around, the incoming object must be EPoly. If it is EMesh, triangular faces will be moved around.

FYI, we both start from step 1 – reading the MAXScript Reference. It appears that I read better (taking into account that I have written parts of it ;)). I had no idea how to solve the problem until I opened the Unwrap_UVW topic and searched for “detach” – I found the right method that moves vertices by detaching them. The rest was once again looking for the methods I needed to find how many vertices a face has, find the index of the vertex by the order index in the face etc.
I guess the other methods do not work because they are not the right ones

Fantastic! that works a treat.

hehe, yes you do read the manual alot better than me! I still have trouble understanding how commands can be used, and where and when you can or cannot use them… Its all a case of trial and (more often) error.

My problem is I always expect things to be easier than they are.