[Closed] Dropdownlist/spinner help
Hello there.
I have recieved help on here in the past which I am very grateful for. For the last year the little workflow tool which I made has saved maybe weeks of work in uv mapping models using a per-pixel material. This is on the old Battlefield2/2142 platform where you work from pallettes of repeating textures. For the last couple of weeks I have been trying to refine the tool for the rest of the mod team I am with to improve the workflow even more.
I’ve watched and read many fascinating tutorials and been thumbing through the maxscript reference religiously but I just am not getting it. I’m trying to do something which I’m guessing should be fairly simple but I just don’t know what I’m doing.
rollout ddl_test "Per-Pixel Material Tool"
(
-- -------------------------------------
dropdownlist ddl_width "Width" items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
on ddl_width selected i do
format "You selected '%'!
" ddl_width.items[i]
-- -------------------------------------
dropdownlist ddl_height "Height" items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
on ddl_height selected i do
format "You selected '%'!
" ddl_height.items[i]
-- -------------------------------------
button btn_map "Map"
on btn_map pressed do
(
macros.run "Modifier Stack" "Convert_to_Mesh"
faceArr = (getFaceSelection $) as array
faceNormal = in coordsys $ (getFaceNormal $ faceArr[1])
worldUpVector = [0,0,1]
rightVector = normalize (cross worldUpVector faceNormal)
upVector = normalize ( cross rightVector faceNormal)
theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]
modPanel.addModToSelection (Uvwmap ()) ui:on
$.modifiers[#UVW_Mapping].gizmo.transform = theMatrix
$.modifiers[#UVW_Mapping].length = 20.48
$.modifiers[#UVW_Mapping].width = 2.56
$.modifiers[#UVW_Mapping].mapChannel = 2
macros.run "Modifier Stack" "Collapse_Stack"
subobjectLevel = 4
)
-- -------------------------------------
)
createDialog ddl_test
What the tool is supposed to do is apply a planar map to an individual poly to a certain scale and channel. I had it working fine as a little pushbutton macro but I was trying to enhance it into a proper rollout so you could change the scale and map channel on the fly. My problem is at the moment, I don’t have a clue how to link the information selected in the the dropdownlists into the output button. I havn’t added a spinner for the map channel yet and I appreciate there may be junk or incorrect code in amongst that.
I had a slightly better version of this but I stripped it back as I was trying to follow the maxscript reference guide. I am sorry to have to ask but I am lost. The video tutorials make it look so simple but I just can’t fathom it and I’m falling behind massively with the work I’m supposed to be doing.
Any help at all would be greatly appreciated.
Do you mean like this?
rollout ddl_test "Per-Pixel Material Tool"
(
-- -------------------------------------
dropdownlist ddl_width "Width" items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
on ddl_width selected i do
format "You selected '%'!
" ddl_width.items[i]
-- -------------------------------------
dropdownlist ddl_height "Height" items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
on ddl_height selected i do
format "You selected '%'!
" ddl_height.items[i]
-- -------------------------------------
button btn_map "Map"
on btn_map pressed do
(
macros.run "Modifier Stack" "Convert_to_Mesh"
faceArr = (getFaceSelection $) as array
faceNormal = in coordsys $ (getFaceNormal $ faceArr[1])
worldUpVector = [0,0,1]
rightVector = normalize (cross worldUpVector faceNormal)
upVector = normalize ( cross rightVector faceNormal)
theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]
modPanel.addModToSelection (Uvwmap ()) ui:on
$.modifiers[#UVW_Mapping].gizmo.transform = theMatrix
$.modifiers[#UVW_Mapping].length = ddl_width.selected as float *0.01
$.modifiers[#UVW_Mapping].width = ddl_height.selected as float *0.01
$.modifiers[#UVW_Mapping].mapChannel = 2
macros.run "Modifier Stack" "Collapse_Stack"
subobjectLevel = 4
)
-- -------------------------------------
)
createDialog ddl_test
I divided the values in the dropdowns by 100 because i noticed that the values you had in there were 2.56 and 20.48.
First of all, thankyou!
It’s definently doing something now. It seems to map the entire model instead of just the selected face or poly but that is definently a kick in the right direction. I was trying something similar to that but your code actually does something as where the things I attemped weren’t. I have to go to work now but that at least has given me some direction. So honestly, thankyou. ;).
Actually. I have reinstalled recently so I may have to check other settings too.
Sorry I didn’t test the rest of your code as I wasn’t sure how it was supposed to work. All I did was get the selection from the dropdown and convert it to a float value.
No really, don’t apologise. If you could imagine a button which applies a planar map at a certain length, width and channel which aligns to the surface normal of an individual poly. That is what I have been using, what i am attempting to do is make it so you can alter the length, width and channel on the fly with drop down boxes and a spinner.
faceArr = (getFaceSelection $) as array
faceNormal = in coordsys $ (getFaceNormal $ faceArr[1])
worldUpVector = [0,0,1]
rightVector = normalize (cross worldUpVector faceNormal)
upVector = normalize ( cross rightVector faceNormal)
theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]
modPanel.addModToSelection (Uvwmap ()) ui:on
$.modifiers[#UVW_Mapping].gizmo.transform = theMatrix
$.modifiers[#UVW_Mapping].length = 2.56
$.modifiers[#UVW_Mapping].width = 5.12
$.modifiers[#UVW_Mapping].mapChannel = 2
macros.run "Modifier Stack" "Collapse_Stack"
subobjectLevel = 4
That would have been my original “button” which was in the form of a macro-script. I really had better go now. Damn shame I find this more fascinating than my job. lol.
Still thanks are in order.
I had a look at the rest of your code over lunch.
try (destroydialog ddl_test) catch()
rollout ddl_test "Per-Pixel Material Tool"
(
-- -------------------------------------
dropdownlist ddl_width "Width" items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
on ddl_width selected i do
format "You selected '%'!
" ddl_width.items[i]
-- -------------------------------------
dropdownlist ddl_height "Height" items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
on ddl_height selected i do
format "You selected '%'!
" ddl_height.items[i]
-- -------------------------------------
spinner mapCh "Map Channel:" range:[1,99,1] type:#integer
button btn_map "Map"
on btn_map pressed do
(
macros.run "Modifier Stack" "Convert_to_Mesh"
faceArr = (getFaceSelection $) as array
faceNormal = in coordsys $ (getFaceNormal $ faceArr[1])
worldUpVector = [0,0,1]
rightVector = normalize (cross worldUpVector faceNormal)
upVector = normalize ( cross rightVector faceNormal)
theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]
UVWwidth = ddl_width.selected as float --*0.01
UVWheight = ddl_height.selected as float --*0.01
addModifier $ (UVWmap length:UVWwidth width:UVWheight mapChannel:mapCh.value)
$.modifiers[1].gizmo.transform = theMatrix
--macros.run "Modifier Stack" "Collapse_Stack" diabled for debugging!
--subobjectLevel = 4 diabled for debugging!
)
-- -------------------------------------
)
createDialog ddl_test
Is this what you’re trying to do?
EDIT: I forgot to add the spinner for map channel and I messed up the rotation of the gizmo.
Here it is working perectly. I am a happy bunny! Next i might extend it a bit further by adding shortcuts to a couple of little things and I suppose it may be possible to add a check to see if the model is a mesh first but in practical terms, this does what I want it to. I could show some examples of it in use maybe if anyone were interested to see why it’s relevant. I don’t know how I can return the favour but you at least have my gratitude.
try (destroydialog ddl_test) catch()
rollout ddl_test "Per-Pixel Material Tool"
(
-- -------------------------------------
dropdownlist ddl_width "Width" items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
-- -------------------------------------
dropdownlist ddl_height "Height" items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
-- -------------------------------------
spinner spn_mapCh "Map Channel:" range:[1,5,2] type:#integer
-- -------------------------------------
button btn_map "Map"
on btn_map pressed do
(
faceArr = (getFaceSelection $) as array
faceNormal = in coordsys $ (getFaceNormal $ faceArr[1])
worldUpVector = [0,0,1]
rightVector = normalize (cross worldUpVector faceNormal)
upVector = normalize ( cross rightVector faceNormal)
theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]
-- -----
modPanel.addModToSelection (Uvwmap ()) ui:on
$.modifiers[#UVW_Mapping].gizmo.transform = theMatrix
$.modifiers[#UVW_Mapping].length = ddl_height.selected as float *0.01
$.modifiers[#UVW_Mapping].width = ddl_width.selected as float *0.01
$.modifiers[#UVW_Mapping].mapChannel = spn_mapCh.value
-- -----
macros.run "Modifier Stack" "Collapse_Stack"
subobjectLevel = 4
)
-- -------------------------------------
)
createDialog ddl_test
I get an error when I run the script you posted above.
The one below works for me and it also checks whether the selection is an editable mesh before applying the UVWmap.
try (destroydialog ddl_test) catch()
rollout ddl_test "Per-Pixel Material Tool"
(
-- -------------------------------------
dropdownlist ddl_width "Width" items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
-- -------------------------------------
dropdownlist ddl_height "Height" items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
-- -------------------------------------
spinner spn_mapCh "Map Channel:" range:[1,5,2] type:#integer
-- -------------------------------------
button btn_map "Map"
on btn_map pressed do
(
if isKindOf $ editable_mesh then
(
faceArr = (getFaceSelection $) as array
faceNormal = in coordsys $ (getFaceNormal $ faceArr[1])
worldUpVector = [0,0,1]
rightVector = normalize (cross worldUpVector faceNormal)
upVector = normalize ( cross rightVector faceNormal)
theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]
-- -----
UVWwidth = ddl_width.selected as float *0.01
UVWheight = ddl_height.selected as float *0.01
addModifier $ (UVWmap length:UVWwidth width:UVWheight mapChannel:spn_mapCh.value)
$.modifiers[1].gizmo.transform = theMatrix
-- -----
collapseStack $
subobjectLevel = 4
)
else
(
messagebox "Selection must be an Editable Mesh!"
)
)
-- -------------------------------------
)
createDialog ddl_test
Hello again. I have been looking at this a lot and I’m guessing we have different versions of max. I use max 9.
I think I’ve had to use the code I used because of this…
“A limitation of the addModifier() function is that it cannot generally apply modifiers to sub-object selections, and so it disables any current sub-object levels. To apply a modifier to a sub-object selection in the same manner that 3ds Max applies modifiers, use the modPanel.addModToSelection(). This function correctly observes the currently selected sub-object level in the Modify panel.”
rollout rollout2 "Per-Pixel Material Tool" width:152 height:162
(
-- -------------------------------------
dropdownList ddl_width "" pos:[80,8] width:66 height:21 items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
label lbl_ddl_width "Texture Width" pos:[8,10] width:72 height:16
-- -------------------------------------
dropdownList ddl_height "" pos:[80,32] width:66 height:21 items:#("8", "16", "32", "64", "128", "256", "512", "1024", "2048") selection:1
label lbl_ddl_height "Texture Height" pos:[8,36] width:72 height:16
-- -------------------------------------
spinner spn_mapCh "" pos:[-20,64] width:128 height:16 range:[1,5,2] type:#integer fieldwidth:18
label lbl_spn_mapCh "Map Channel" pos:[8,64] width:72 height:16
-- -------------------------------------
button btn_map "Map" pos:[8,88] width:130 height:30
-- -------------------------------------
on btn_map pressed do
(
if isKindOf $ editable_mesh then
(
faceArr = (getFaceSelection $) as array
faceNormal = in coordsys $ (getFaceNormal $ faceArr[1])
worldUpVector = [0,0,1]
rightVector = normalize (cross worldUpVector faceNormal)
upVector = normalize ( cross rightVector faceNormal)
theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]
modPanel.addModToSelection (Uvwmap ()) ui:off
$.modifiers[#UVW_Mapping].gizmo.transform = theMatrix
$.modifiers[#UVW_Mapping].length = ddl_height.selected as float *0.01
$.modifiers[#UVW_Mapping].width = ddl_width.selected as float *0.01
$.modifiers[#UVW_Mapping].mapChannel = spn_mapCh.value
collapseStack $
subobjectLevel = 4
)
else
(
convertToMesh $
subobjectLevel = 4
faceArr = (getFaceSelection $) as array
faceNormal = in coordsys $ (getFaceNormal $ faceArr[1])
worldUpVector = [0,0,1]
rightVector = normalize (cross worldUpVector faceNormal)
upVector = normalize ( cross rightVector faceNormal)
theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]
modPanel.addModToSelection (Uvwmap ()) ui:off
$.modifiers[#UVW_Mapping].gizmo.transform = theMatrix
$.modifiers[#UVW_Mapping].length = ddl_height.selected as float *0.01
$.modifiers[#UVW_Mapping].width = ddl_width.selected as float *0.01
$.modifiers[#UVW_Mapping].mapChannel = spn_mapCh.value
collapseStack $
subobjectLevel = 4
)
)
)
-- ------------------------------------
myFloater = newrolloutfloater "2142NE Tools" 160 500
addrollout rollout2 myFloater
This is what works on my version, it doesn’t seem to throw up any errors.
This is how it works…
Select an editable mesh…
Select a face (or quad face)…
Press the map button and it applies the map at the selected scale on the selected channel.
Now go around and do the rest of the model.
Then it leaves the shells scaled correctly for the texture I am using which is important for good in game resolution.
The next thing I’ve been doing is trying to get the same idea working on all selected faces(or polygons) of an editable poly.
I’ve been doing lots of reading, examining other scripts and I thought I’d work on getting all the little features right as I go. I have a way of getting the selected number of faces, the selected faces as an array and print these values out to prove they work. So I need to get the surface normal and position of these selected faces and apply the uvwmap to them. I’ve been working trying to get a callback working to update the selection values every time you select different faces.instead of every time you press a button.
This is as far as I’ve really got with this side of it. I’ve found more code that is relevant but still trying to make it work.
(
selection_bitarray = #{}
b = bit.Set 0 1 true
$.getFacesByFlag & selection_bitarray b
selection_array = (selection_bitarray as array)
num_faces = selection_array.count
for i = 1 to num_faces do -- iterate from 1 to number of selected Polygons
(
faceCentre = polyOp.getFaceCenter (not sure) i
faceNormal = polyOp.getFaceNormal (not sure) i
)
)
I’ve been lookng at a script called “Object Placer”. http://www.3dtotal.com/team/Tutorials_3/scripted_utility/scripted_utility01.asp
This script makes copies from a source object and aligns and centres them to the normal of the faces of the selected editable polygon. This is basically what I want to but I want to apply uvwmaps instead of copied objects. I can see roughly how he does it but i’m still getting to grips with the basics.
You have been busy…
Sorry I didn’t realise this about addModifier().
I’m on Max 2012 so we are using different versions of max. I get an error if I use your
$.modifiers[#UVW_Mapping].
as I guess the naming has changed between versions.
I had a look at your editable poly code and this seems to work here…
(subObjectLevel = 4
selFacesBA = polyop.getFaceSelection $
selFaces = selFacesBA as array
for face in selFaces do
(
polyop.setFaceSelection $ face
faceNormal = in coordsys $ (polyOp.getFaceNormal $ face)
worldUpVector = [0,0,1]
rightVector = normalize (cross worldUpVector faceNormal)
upVector = normalize ( cross rightVector faceNormal)
theMatrix = matrix3 rightVector upVector faceNormal [0,0,0]
modPanel.addModToSelection (Uvwmap ())
$.modifiers[1].gizmo.transform = theMatrix
$.modifiers[1].length = 100
$.modifiers[1].width = 100
$.modifiers[1].mapChannel = 1
collapseStack $
)
)
I forgot to thank you for this. Thankyou! Well I’ve been developing the interface and adding all the other bits it needs but it’s taking a little while. Slowly getting little things to work without asking questions. I’ll post it on here when it’s a little more presentable, it may be useful to other people in the future.