ScriptSpot

Forum topic · General Scripting

uvwmap gizmo to ojbect center

By dussla · 2014-02-28

Description

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 (30)

.

Haider of Sweden · 2014-03-07

EPoly Slice


New Suggestion:
Align Slice plane to poly face

.
Bugs
When running resetEPM_SlicePlane(), the interface refreshes shortly and then turns off the Slice Plane button
- I suggest it should simply reset the Slice Plane gizmo, leaving the user with the Slice Plane button like it was before..

barigazy · 2014-03-04

@Haider of Sweden
Now you see why this need to be separate fn from resetModyGizmoTm

;)

...part4 ei. next step2 :)

barigazy · 2014-03-04

• • • EPoly SlicePlane Reseter Fn • • •

This fn works on multiple selected objects (PolyMeshObject and Editable_Poly)

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
)
fn setCommandPanelRedraw act =
(
WM_SETREDRAW = 0x000B
windows.sendmessage (windows.getchildhwnd #max "Command Panel")[1] WM_SETREDRAW act 0
)
fn resetEPM_SlicePlane = if selection.count != 0 do
(
local nodesPairs = dataPair solo:#() mody:#()
for o in selection do
(
if isKindOf o Editable_Poly then append nodesPairs.solo o else
(
if (mody = getMody o modyClass:Edit_Poly) != null do append nodesPairs.mody #(mody, o)
)
)
setCommandPanelRedraw 0
if nodesPairs.solo.count != 0 do
(
if getCommandPanelTaskMode() != #create do setCommandPanelTaskMode mode:#create
with redraw off for o in nodesPairs.solo do o.ResetSliceplane()
)
if nodesPairs.mody.count != 0 do
(
select (for i = 1 to nodesPairs.mody.count collect nodesPairs.mody[i][2])
if getCommandPanelTaskMode() != #modify do setCommandPanelTaskMode mode:#modify
for i = 1 to nodesPairs.mody.count do
(
modPanel.setCurrentObject nodesPairs.mody[i][1] node:nodesPairs.mody[i][2] ui:on
nodesPairs.mody[i][1].ResetSliceplane()
)
) ; setCommandPanelRedraw 1
)
resetEPM_SlicePlane()

barigazy · 2014-03-03

What's next?

:)

.

Haider of Sweden · 2014-03-04

Forgive me for being such an amateur, but it takes some time for me to understand how I run the script and such.

First some basic questions.
Previously you used resetModyGizmoTm selection while later, you used resetModyGizmoTm node.

I got "undefined" when I tried

resetModyGizmoTm nodes whichClass:Slice center:off

What am I missing?

barigazy · 2014-03-04

My fault. When I write the code I often change vars names.
So when you want to execute fn use

resetModyGizmoTm selection whichClass:Slice center:off

.

Haider of Sweden · 2014-03-04

Thanks, it works now
I learned where to check the class names and found out that slice class name is SliceModifier and not Slice ;-)

I did some tests on the FFD.
If I modify the control points, and fiddle with the Set Volume, resetModyGizmoTm will reset everything, not only the Lattice position but also the shape.
Why is that?

Next step:
I am thinking that it might be complicated to add support for new items all the time. So is it possible to make the script work on the _selected_ sub-selection instead?

Next step2:
EPoly Slice: I would like to see gizmo controllers for that too. Should I post a new separate thread for that, or do you think that it is possible to create a generic script that supports both EPoly slice and modifier sub-objects? It mustn't necessary be the same function. You could create a script with multiple functions, where one function is for controlling the one gizmo type, and another function for the other function type.
In the end and from a user-friendly point of view, they are all the "same type of things".

barigazy · 2014-03-04

@If I modify the control points, and fiddle with the Set Volume, resetModyGizmoTm will reset everything, not only the Lattice position but also the shape.Why is that?

because of this


resetLattice mody

barigazy · 2014-03-04

@Next step:
I am thinking that it might be complicated to add support for new items all the time. So is it possible to make the script work on the _selected_ sub-selection instead?

It's easier this way just say what you want more.

.

Haider of Sweden · 2014-03-04

Wow, this is so much fun!

Reset Mody Gizmo


because of this
resetLattice mody

....

It's easier this way just say what you want more

All right. I will gather an amount of useful cases where users might want to alter the gizmos, _which_ gizmos and how. I will suggest a UI that allows different things instead of all things in one, eg center, reset scale, reset rotate and so on.
So I'll get back to you, but first I need to understand some things:

1. does maxscript allow a UI that shows in _realtime_ (without need to refresh) what modifier is active and that shows "not supported" if the type of modifier is not supported yet? Currently we have three supported modifiers; UVMap, Slice and FFD. For now, a simple UI will do fine for the sake of testing.

2. I still dont understand the reason why center:on/off behaves like it does.
I understand "nodes.objecttransform nodes.center" (the object's own center point), but what is "translate (matrix3 1)"?

EPoly SlicePlane

I am not going to call this headline "slice plane resetter", becuase we're going to develop it to be more than just a resetter ;)


resetEPM_SlicePlane()

Seems not to work? The viewport flashes shortly, it jumps to the create-tab and I get the output "undefined"

Meanwhile: Is it possible to normal align the EPoly SlicePlane?

barigazy · 2014-03-04

Check abain *resetEPM_SlicePlane* fn. I tested it on 50 selected objects that not have Edit_Poly modifier (EPoly Objects) and with EP Modifier and it works fine

barigazy · 2014-03-04

@1. does maxscript allow a UI that shows in _realtime_ (without need to refresh) what modifier is active and that shows "not supported" if the type of modifier is not supported yet?
Yep it supports that but I not have time to create that behavior for dialog.

@Currently we have three supported modifiers; UVMap, Slice and FFD. For now, a simple UI will do fine for the sake of testing.
At least you can create one. It's not difficult. Open maxscript help document and
you can find meny examples how to do that.

@2. I still dont understand the reason why center:on/off behaves like it does.
I understand "nodes.objecttransform nodes.center" (the object's own center point), but what is "translate (matrix3 1)"?

Neither do I. :). Just kidding. When you assigne modifier you will see that some of theses are created at center and some at pivot position. You need to know which modifiers have different start position. Also if base object transform is changed then it also affects the modifier position.

.

Haider of Sweden · 2014-03-05

OK, it did actually work.

If I have an Edit Poly modifier, and run resetEPM_SlicePlane(), the max listener outputs "0"
If I run it on Editaple Poly, the output is "undefined".

New Suggestion:
Align Slice plane to poly face. I tried using Normal Align tool, but it doesnt work on a gizmo :(

barigazy · 2014-03-05

fn will always returns what is executed last.

...part3 (FFD support)

barigazy · 2014-03-03


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 #lattice_transform) : (resetLattice mody ; mody.lattice_transform = tm)
(isProperty mody #gizmo) : mody.gizmo.transform = tm
(isProperty mody #slice_plane) : mody.slice_plane.transform = tm
)
)
)

.

Haider of Sweden · 2014-03-03

Great work!

When I tried some other modifier, like taper:

resetModyGizmoTm selection whichClass:Taper

... it worked fine (although; I wonder why the gizmo didnt center properly - could you see and explain?)

But for the slice, there was no effect. Can you explain why?

Furthermore, if one wants to develop the script further, for example add support for FFD_2x2x2 which has "lattice" gizmos, should I add new rows like:

(isProperty mody #FFD_2x2x2) : mody.lattice.transform = (translate (matrix3 1) (in coordsys nodes.objecttransform nodes.center))

What about the "set volume" sub object, what should it be called?

ps. just half-off-topic. How do I wrap code in the way you do, so it has a frame aound it? I tried both code and blockcode with no luck..

barigazy · 2014-03-03

I not tested the code for every modifier class. I only post an example how can be done. Feel free to modify my snippet to suit your need and if you are "stuck" somewhere post your code here. Then we can try to find another solution.

.

Haider of Sweden · 2014-03-03

Thanks.

- These examples are compatible, but can you please explain why the gizmo placement moves up after centering?


resetModyGizmoTm selection whichClass:Twist
resetModyGizmoTm selection whichClass:Taper

- I understand why the slice didnt work, a small misspelling: "slice_slane" should be "slice_plane"

- I understand that if I want to more subObject items, like "lattice", I add:


(isProperty mody #lattice) : mody.lattice.transform = (translate (matrix3 1) (in coordsys nodes.objecttransform nodes.center))

... but what should I type for e.g. "Set Volume" subobject in FFD 2x2x2?

- Previously, you said "alternatively you can change i.center[3] to 0". Can you please explain the difference?

- Can this be used for Editable Polygon > Slice Plane?

...part2 (option "center")

barigazy · 2014-03-04

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

barigazy · 2014-03-03

@Can this be used for Editable Polygon - Slice Plane?
No. EPoly Slice plane use different concept ei.methods.

barigazy · 2014-03-02

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

-- this code reset the uvw

fajar · 2014-03-02


-- 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

try this...fn

fajar · 2014-03-02

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

rotate gizmo

dussla · 2014-03-02

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()
						)
					)


			
			





				





			 )




	
		)

.

Haider of Sweden · 2014-03-02

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

... universal solution

barigazy · 2014-03-03

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))
		)
	)
)

fajar · 2014-03-02

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

More ideas

Haider of Sweden · 2014-03-01

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

fn centerTheUvwGizmo =( for

fajar · 2014-03-01


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()