Apply UV to material ID

Okay guys last request for awhile!
We need to cycle and apply the following to all objects selected 1 by 1.

1: add a Poly select.
2: select a material ID.
3: Add a UVW map.
(if no polygons are selected on step 2,than skip steps 3 - 7)
4:Set Map channel to 2
5: set UVW map's length + width.
6: Set Alignment to X,Y, or Z
7:Move the UVW gizmo on X y or Z relative to the object's pivot point. (or relative to world x0 y0 z0 if its easier.)

8:do steps 1 - 7 again on the same object up to as many times as is needed for each side of the object specified above.
(my guess is that steps 1-7 would be copy pasted under the first set of steps 1-7.

The purpose of this script is to UV map lots of blocks so that each block will have the texture pixels match up when blocks of various sizes are aligned next to one another.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tuxmask75's picture

Well guys, Miauu finished

Well guys, Miauu finished that script. everything turned out nicely!
Thx for the help and suggestions!

miauu's picture

.

Using the code below all Edit_Poly and UVWMap modifiers will be instances. If you want them to be unique a few lines have to be moved from one part of the script to another.

Works with selected objects.
(
	global rol_uvToMatID
	try(destroyDialog rol_uvToMatID)catch()
	rollout rol_uvToMatID "UV to matID"
	(
		group "Settings"
		(
			spinner spn_matID "Faces matID:" range:[1,100,2] type:#integer		
			spinner spn_mapChannel "Map Channel:" range:[1,100,2] type:#integer
			spinner spn_mapLength "Length:" range:[0,1e9,2] type:#worldunits
			spinner spn_mapWidth "Width:" range:[0,1e9,2] type:#worldunits
			radiobuttons rb_axis "Alignment:" labels:#("X\t", "Y\t", "Z\t") default:1 columns:3
		)
		button btn_doIt "DO IT" width:160 offset:[0,10]
 
		on btn_doIt pressed do
		(
			selObjsArr = selection as array
			if selObjsArr.count != 0 then
			(
				max modify mode
				--
				epMod = (Edit_Poly())
				uvwMapMod = (Uvwmap ())						
				uvwMapMod.mapChannel = spn_mapChannel.value
				uvwMapMod.length = spn_mapLength.value	
				uvwMapMod.width = spn_mapWidth.value
				--	0 == X, 1 == Y, 2 == Z
				uvwMapMod.axis = (rb_axis.state - 1)
				--
				for o in selObjsArr do
				(
					select o					
					addModifier o epMod
					subobjectlevel = 4
					epMod.selectByMaterialID = (spn_matID.value - 1)
					epMod.ButtonOp #SelectByMaterial
					if (epMod.getSelection #Face node:o).numberset != 0 do
					(						
						addModifier o uvwMapMod
					)
				)
			)
			else
				messagebox "Select some objects" title:"Empty Selection"
		)
 
	)
	createdialog rol_uvToMatID 	--	width: height: style:#(#style_titlebar, #style_sysmenu, #style_resizing, /*#style_toolwindow*/)
)
tuxmask75's picture

Getting this

Getting this error.
http://imageshack.us/photo/my-images/593/nr1y.png/

as for step 7, the UV gizmo needs to start out at 0 of the current object's Pivit point. Next part of step 7 is to be able to move the UV gismo relative to that pivit point on X Y and Z.
Yes poly select can be replaced by edit poly.

miauu's picture

.

The error is because WORKS WITH SELECTED OBJECTS needs to be outside of the script. My mistake.
I am not sure how the gizmo have to be moved. Try this script:

(
	global rol_uvToMatID
	try(destroyDialog rol_uvToMatID)catch()
	rollout rol_uvToMatID "UV to matID"
	(
		group "Settings"
		(
			spinner spn_matID "Faces matID:" range:[1,100,2] type:#integer		
			spinner spn_mapChannel "Map Channel:" range:[1,100,2] type:#integer
			spinner spn_mapLength "Length:" range:[0,1e9,2] type:#worldunits
			spinner spn_mapWidth "Width:" range:[0,1e9,2] type:#worldunits
			spinner spn_gizmoX "Gizmo X pos:" range:[0,1e9,2] type:#worldunits
			spinner spn_gizmoY "Gizmo Y pos:" range:[0,1e9,2] type:#worldunits
			spinner spn_gizmoZ "Gizmo Z pos:" range:[0,1e9,2] type:#worldunits
			radiobuttons rb_axis "Alignment:" labels:#("X\t", "Y\t", "Z\t") default:1 columns:3
		)
		button btn_doIt "DO IT" width:160 offset:[0,10]
 
		on btn_doIt pressed do
		(
			selObjsArr = selection as array
			if selObjsArr.count != 0 then
			(
				max modify mode
				--
				epMod = (Edit_Poly())
				uvwMapMod = (Uvwmap ())						
				uvwMapMod.mapChannel = spn_mapChannel.value
				uvwMapMod.length = spn_mapLength.value	
				uvwMapMod.width = spn_mapWidth.value
				--	0 == X, 1 == Y, 2 == Z
				uvwMapMod.axis = (rb_axis.state - 1)				
				--
				for o in selObjsArr do
				(
					select o					
					addModifier o epMod
					subobjectlevel = 4
					epMod.selectByMaterialID = (spn_matID.value - 1)
					epMod.ButtonOp #SelectByMaterial
					if (epMod.getSelection #Face node:o).numberset != 0 do
					(						
						addModifier o uvwMapMod
						uvwMapMod.gizmo.position.x = o.pivot.x + spn_gizmoX.value
						uvwMapMod.gizmo.position.y = o.pivot.y + spn_gizmoY.value
						uvwMapMod.gizmo.position.z = o.pivot.z + spn_gizmoZ.value
					)
				)
			)
			else
				messagebox "Select some objects" title:"Empty Selection"
		) 
	)
	createdialog rol_uvToMatID
)
tuxmask75's picture

Okay its getting there! I

Okay its getting there! I think that we are forgetting to be in Edit polygon selection mode before material ID is selected. the ID faces needs to stay selected under the UVW since the goal is to apply the UVW to the selected polygons only.
I'm sorry if I was not very clear Before.

tuxmask75's picture

Oh yes~Idea! for the UVW

Oh yes~Idea! for the UVW gizmo starting position maybe use the align tool to align to objects pivit point center.
And!!! than for the UVW Gizmo position's type in box use the Offset:Screen move tool function?

barigazy's picture

...

Or U can use this tool for UVW Map modifier randomization

barigazy

tuxmask75's picture

Thanks but

Thanks barigazy but its not what im looking for.. and also lacking the Apply to selected Material ID polygons.
miauu's script when finished is exactly what I am looking for.

miauu's picture

.

what/where the UV gizmo have to be moved in step 7?
Also, can Poly Select modifier be replaced with Edit_Poly?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.