Notifications
Clear all

[Closed] select elements insted of polygons UVW unwrapp modifiers

Hi, if I have an object with mutiple elements (img 01 )and I want to flip the uvs at random for each element, how would I do that, I wrote something that I tough would work, but “selectPolygons” dont care that I have select by element toggled.

img 01:


polyCount = polyop.getNumFaces $;

for i = 1 to polyCount do (
	$.modifiers[1].selectPolygons #{i};
	if (random 0 1) == 1 then(
		$.modifiers[1].mirrorH();
	)
)


thanks in advance.

9 Replies

The simplest way would be something like this:

(
gc()
delete objects

obj = converttopoly (plane length:100 width:100 lengthsegs:10 widthsegs:6 isselected:on)
obj.mat = standard diffusemap:(gradient_ramp()) showinviewport:on

unwrap = unwrap_uvw()
modpanel.addmodtoselection unwrap ui:on
unwrap.edit()

subobjectlevel = 1
max select all
unwrap.breakSelected()

subobjectlevel = 3
faces = (for j = 1 to obj.numfaces by random 2 5 collect j) as bitarray

for j in faces do
(
	unwrap.selectFaces #{j}
	unwrap.mirrorH()
)

print faces
unwrap.selectFaces #{}
-- unwrap.selectFaces faces
)
1 Reply
(@patan77)
Joined: 11 months ago

Posts: 0

I’m looking at this (and I might be missing something) but dont this just flip random polys individually similar to my script, not the actuall uvs per element?

what I want to happen is, selcting the whole element (which consists of mutiple broken up uvs) then flip all of that element the same.
img 02:

Sorry Patrik, I really didn’t read/test your code. Just read “element” and looked at the picture and I thought you’re talking about UV elements, not mesh elements.

Try this:

(
gc()
delete objects

obj = converttopoly (box isselected:on)
polyop.deleteverts obj #all

for x = 0 to 5 do
(
	for y = 0 to 5 do
	(
		polyop.attach obj (box lengthsegs:1 widthsegs:1 heightsegs:1 length:20 width:40 height:10 mapcoords:on pos:[x*45,y*25,0])
	)
)

unwrap = unwrap_uvw()
modpanel.addmodtoselection unwrap ui:on
unwrap.flattenMap 0 #([1,0,0], [-1,0,0], [0,1,0], [0,-1,0], [0,0,1], [0,0,-1]) 0.001 true 0 true false


faces = (for j = 1 to obj.numfaces by random 10 30 collect j) as bitarray

subobjectlevel = 3
for j in faces do
(
	element = polyop.getelementsusingface obj j
	for i in element do
	(
		unwrap.selectFaces #{i}
		unwrap.mirrorH()
	)
	for i in element do faces[i] = false
)

unwrap.selectInvertedFaces()
unwrap.edit()
)
3 Replies
(@patan77)
Joined: 11 months ago

Posts: 0

Thanks, he definitely no need to apologise for “misreading” my first post, all attempts of trying to help are appreciated

I tried your second code, and could not get it to work with my test mesh

But I made a mix of your code and my original and I were able to get it to work on my mesh: (img 03)

img 03:

Working code

obj = $
setCommandPanelTaskMode mode:#modify;
subobjectlevel = 3

faces = (for j = 1 to obj.numfaces collect j) as bitarray;

for j in faces do
(
	element_prev = polyop.getelementsusingface obj (j);
	if (j+1) <= obj.numfaces then(
		element = polyop.getelementsusingface obj (j+1);
	)else(
		element = element_prev
	)	
	
	face_prev = (element as array)[1];
	face_element = (element_prev as array)[1];
	
	if face_element != face_prev then(
		polyop.setFaceSelection $ element_prev;
		if (random 0 1) == 1 then(
			$.modifiers[1].mirrorH();
		)
	)
)

(@denist)
Joined: 11 months ago

Posts: 0

i could be easier to help if you’ve posted your mesh…

it looks like your final code is much simpler then Jorge’s because the mesh doesn’t need any extra mapping.
also from your code we can see that geometry elements correspond to map elements. which is not intuitive as well.

(@patan77)
Joined: 11 months ago

Posts: 0

well I thought the “test mesh” mesh in the image was easy enough to replicate, its just a box with couple of edge loops then copy that box a few times and rotate a few of them then attach to a single editable poly and add unw unwrap modifier and select flatten mapping…

if you want to test it here is the max scene:
http://www.patan77.com/download/elements_test_scene_max_2015.zip
EDIT: the texture map is wrong in that test scene should be “gradient ramp” not “gradient”^^

but its fine now because my code is working now, and PolyTools3D code contained the parts I was looking for.

Thank you for the file. It makes it easier to understand the situation.

See if the following code works for what you need.

(
 	max modify mode
 
 	obj = $
 	unwrap = modpanel.getcurrentobject()
 
 	-- Grab some random faces
 	faces = (for j = 1 to 5 collect random 1 obj.numfaces) as bitarray
 	
 	-- Get all elements using those faces
 	faces = polyop.getelementsusingface obj faces
 
 	-- We need to change to face mode
 	subobjectlevel = 3
 	
 	-- Bitarray to hold the processed faces
 	done = #{}
 	
 	for j in faces where not done[j] do
 	(
 		-- Select 1 face
 		unwrap.selectfaces #{j}
 		
 		-- Select its UV Shell
 		unwrap.selectelement()
 		
 		-- Mirror the UV Shell
 		unwrap.mirrorH()
 		
 		-- Add this Shell faces to the done bitarray to avoid further mirroring
 		done += unwrap.getselectedfaces()
 	)
 	
 	/* Not needed, just for previewing */
 	unwrap.selectfaces faces
 	unwrap.edit()
 	/* ------------------------------- */
 )
1 Reply
(@patan77)
Joined: 11 months ago

Posts: 0

Thanks that also works

as i understand the idea is to add a variant to the using of the same texture… h-flip is the one. but there are another