uvwmap gizmo to ojbect center

i made uvwmap and some moved gizmo

i would like to uvwmap gizmo -> object center again

always thank you for good script and good advice ~

Comments

Comment viewing options

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

...part2 (option "center")

For now I added new argument "center". If "on" then gizmo will be placed at the center else at the pivot position.

fn getMody node modyClass: = if node.modifiers.count > 0 do
(
	local mody
	for m in node.modifiers while mody == undefined where iskindof m modyClass do mody = m ; mody
)
mapped fn resetModyGizmoTm nodes whichClass: center: = if isValidNode nodes do
(
	mody = getMody nodes modyClass:whichClass
	if mody != null and validModifier nodes mody do
	(
		tm = if center then (translate (matrix3 1) (in coordsys nodes.objecttransform nodes.center)) else (matrix3 1)
		case of
		(
			(isProperty mody #gizmo) : mody.gizmo.transform = tm
			(isProperty mody #slice_plane) : mody.slice_plane.transform = tm
		)
	)
)
resetModyGizmoTm selection whichClass:SliceModifier center:off

bga

barigazy's picture

...

Now how to use it
It's very simple, just select some objects and run this code
NOTE: in "whichClass" argument put any modifiers class

resetModyGizmoTm selection whichClass:Uvwmap
-- or for the slice modifier
resetModyGizmoTm selection whichClass:SliceModifier

bga

fajar's picture

-- this code reset the uvw

-- this code reset the uvw map on selected object
-- insert true the thing that you want to reset [I include position, rotation & scale]
 
fn centerTheUvwGizmo resetPos:true resetRot:false resetScales:false =
(
	for i in selection do
	(
		for y in i.modifiers where isKindof y Uvwmap do
		(
			with undo "uvwmap gizmo center" on
			(
			--theGismoPos= [0,0,i.center[3]]
 
			 if resetPos == true do y.gizmo.position = [0,0,0]
			 if resetRot== true do y.gizmo.rotation = (quat 0 0 -1 0)	
			 if resetScales == true do y.gizmo.scale = [1,1,1]
			)
		)
	)
)

usage : select object that already had uvwmap modifier then execute the function [Ctrl+E]
ex: if you want to reset scale only you only need to change resetScales from false to true

centerTheUvwGizmo resetPos:false resetRot:false resetScales:true

your code not working simple because many unworking part:

select i  == --why do you use this ? I already define for something in selection 
 
							mod_obj = modPanel.getCurrentObject() --- this is too , when you already define for y in i.modifier....unworking
							gizmo_rotation = mod_obj.gizmo.rotation --- gizmo rotation refer to quat matrix not eulerangle,see maxscript help about uvwmaping modifier
 
							mod_obj.gizmo.rotation = gizmo_rotation * ((eulerangles  0 90  0) as quat)----refer to above.
 
 
 
							clearSelection() --- why do you need to clear selection 
						)

below simple design UI to make it better understanding how to use

fn centerTheUvwGizmo resetPos:true resetRot:false resetScales:false =
(
	for i in selection do
	(
		for y in i.modifiers where isKindof y Uvwmap do
		(
			with undo "uvwmap gizmo center" on
			(
			--theGismoPos= [0,0,i.center[3]]
 
			 if resetPos == true do y.gizmo.position = [0,0,0]
			 if resetRot== true do y.gizmo.rotation = (quat 0 0 -1 0)	
			 if resetScales == true do y.gizmo.scale = [1,1,1]
			)
		)
	)
)
 
 
rollout resetUvw "Untitled" width:162 height:125
(
	button btn1 "reset uvw pos" pos:[5,9] width:138 height:26
	button btn2 "reset uvw sccale" pos:[6,38] width:138 height:26
	button btn3 "reset uvw rotation" pos:[6,67] width:138 height:26
	button btn4 "reset all" pos:[5,94] width:138 height:26
 
	on btn1 pressed do 
	(
		centerTheUvwGizmo resetPos:true resetRot:false resetScales:false
	)
 
	on btn2 pressed do 
	(
		centerTheUvwGizmo resetPos:false resetRot:false resetScales:true
	)
 
	on btn3 pressed do 
	(
		centerTheUvwGizmo resetPos:false resetRot:true resetScales:false
	)
 
	on btn4 pressed do 
	(
		centerTheUvwGizmo resetPos:true resetRot:true resetScales:true
	)
 
)
createDialog resetUvw
fajar's picture

try this...fn

try this...

fn centerAllTheModifierGizmo =
(
	for i in selection do
	(
		for y in i.modifiers where (hasProperty  y "gizmo") do
		(
			with undo "center gizmo" on
			(
			theGismoPos= [0,0,i.center[3]]
			setproperty y.gizmo "position" theGismoPos
			)
		)
	)
)

usage:

centerAllTheModifierGizmo ()

alternatively you can change i.center[3] to 0

Haider of Sweden's picture

.

Thanks, regarding the centerAllTheModifierGizmo.
But that would require that the gizmo is called "Gizmo".
What if you want to extend the capacity of the script: For example, slice, uses gizmo name "Slice Plane".

I like your UI. The same features could be available for e.g. Slice: Reset Position, Scale and rotation. You could either make your code generic, compatible with all types of gizmos, or you could add items successively every time you want to make it compatible with yet one more item.

Further features could be that it works on sub-object "gizmos", for example in Editable Poly > Slice plane.
- center gizmo to selection.
- scale gizmo to selection

Kind regards
Haider
www.haider.se

barigazy's picture

... universal solution

This functions allows you to reset any modifiers gizmo transform(of course if it have one)

fn getMody node modyClass: = if node.modifiers.count > 0 do
(
	local mody
	for m in node.modifiers while mody == undefined where iskindof m modyClass do mody = m ; mody
)
mapped fn resetModyGizmoTm nodes whichClass: = if isValidNode nodes do
(
	mody = getMody nodes modyClass:whichClass
	if mody != null and validModifier nodes mody do
	(
		case of
		(
			(isProperty mody #gizmo) : mody.gizmo.transform = (translate (matrix3 1) (in coordsys nodes.objecttransform nodes.center))
			(isProperty mody #slice_plane) : mody.slice_plane.transform = (translate (matrix3 1) (in coordsys nodes.objecttransform nodes.center))
		)
	)
)

bga

dussla's picture

rotate gizmo

good reply thank you
i made this rotuine with your routine

but that is not work

there is many modifier ex) edit poly , shell , uvwmap
i would like to roate uvw gizmo only

what problem this code ?

 if selection[1] != undefined do 
 
		(
 
 
 
 
 
			for i in selection do
			(
 
 
 
				for y in i.modifiers where isKindof y Uvwmap do
					(
						with undo "uvwmap gizmo center" on
						(
 
							select i
 
							mod_obj = modPanel.getCurrentObject()
							gizmo_rotation = mod_obj.gizmo.rotation
 
							mod_obj.gizmo.rotation = gizmo_rotation * ((eulerangles  0 90  0) as quat)
 
 
 
							clearSelection()
						)
					)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
			 )
 
 
 
 
 
		)
fajar's picture

what the meaning to all gizmo

what the meaning to all gizmo ? all kind of modifier that have gizmo?

Haider of Sweden's picture

More ideas

@fajar: I wonder if this code can be rewritten to fit to all kind of gizmos?

Kind regards
Haider
www.haider.se

fajar's picture

fn centerTheUvwGizmo =( for

fn centerTheUvwGizmo =
(
	for i in selection do
	(
		for y in i.modifiers where isKindof y Uvwmap do
		(
			with undo "uvwmap gizmo center" on
			(
			theGismoPos= [0,0,i.center[3]]
			y.gizmo.position = theGismoPos
			)
		)
	)
)

its still raw tho, but work :)

how to :

select object that have uvwmap modifiers and run the function

centerTheUvwGizmo()

Comment viewing options

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