I’ve been working away at this script for some time now, but I’m still very much in the process of trying to learn MaxScript so trying to build a rather complex script at the same time is just a tad challenging. :P
That being said completing this script will undoubtedly save me weeks or even months depending on the project.
The problem I’m currently having is trying to get the script to Auto Smooth editable poly objects to 45°
Here’s the code.
(E-Meshes are properly auto smoothing to 45° it's just E-Poly's that aren't working)(I’ve also provided the entire script to give some better context as to what I’m working with)
-- This will apply the default 45° auto smooth to all selected objects<br> fn autosmooth45 tresh: = if selection.count == 0 then (messageBox "Select Some Objects!" title:"Warning" beep:off) else<br> (<br> local poAS = polyop.autoSmooth<br> local moAS = meshop.autosmooth<br> for o in selection where isKindOf o GeometryClass and not isKindOf o Targetobject do<br> (<br> if o.modifiers.count != 0 then (messageBox "Please collapse modifier stack!" title:"Warning" beep:off) else<br> (<br> case classof o of <br> (<br> (Editable_Poly):<br> (<br> o.autoSmoothThreshold = tresh<br> o.EditablePoly.autosmooth ()<br> update o<br> )<br> (Editable_Mesh): (moAS o o.faces tresh ; update o)<br> )<br> )<br> )<br> )
And here's the code for the button, although i doubt there's anything wrong with that. :P
on btn_smooth45 pressed do<br> (<br> autosmooth45 tresh:45<br> )
For those of you who are curious I’m going to be using this script for creating content for a game called Killing Floor 2, more specifically porting maps from the first game (UE2) to the second game (UE3).
Currently I’m having to sort through thousands of objects and it’s taking me months to get the geometry into an acceptable state to be pushed into the KF2 SDK, so having this script will be a massive time saver. XD
Replies
Wow thanks guys that worked!
Here’s what I got so far:
So another quick question, how would I go about making the “autoSmoothThreshold” adjustable with a spinner.
The Max documentation says that the threshold angle is a property of the “polyop.autoSmooth” method so I assumed that I could just get away with this:
("spn_angle" being the spinner in question)However that doesn’t seem to work.
But I'm telling you, just use a Smooth modifier. So much less code.
From this:
-- This will apply the default 45° auto smooth to all selected objects fn autosmooth45 tresh: = if selection.count == 0 then (messageBox "Select Some Objects!" title:"Warning" beep:off) else ( local poAS = polyop.autoSmooth local moAS = meshop.autosmooth for o in selection where isKindOf o GeometryClass and not isKindOf o Targetobject do ( if o.modifiers.count != 0 then (messageBox "Please collapse modifier stack!" title:"Warning" beep:off) else ( case classof o of ( (Editable_Poly): ( polyop.setFaceSelection o #all poAS o update o ) (Editable_Mesh): (moAS o o.faces tresh ; update o) ) ) ) ) -- This will auto smooth with a custom value (Not working either) fn autosmoothcus tresh:spn_angle.value = if selection.count == 0 then (messageBox "Select Some Objects!" title:"Warning" beep:off) else ( local poAS = polyop.setFaceSmoothGroup local moAS = meshop.autosmooth for o in selection where isKindOf o GeometryClass and not isKindOf o Targetobject do ( if o.modifiers.count != 0 then addModifier o (messageBox "Please collapse modifier stack!" title:"Warning" beep:off) else ( case classof o of ( (Editable_Poly): (poAS o o.faces tresh add:false) (Editable_Mesh): (moAS o o.faces tresh ; update o) ) ) ) ) --This will remove all smoothing groups from all selected objects fn smoothclear = ( local numFaces = polyop.getNumfaces $ local faces = (for i in 1 to numFaces collect i) as bitarray polyOp.setFaceSmoothGroup $ faces 1 ) ... ... on btn_smooth45 pressed do ( autosmooth45 tresh:45 ) on btn_autosmooth pressed do ( autosmoothcus tresh:spn_angle.value ) on btn_clear pressed do ( smoothclear() )
To this:
Holly crap, shorter is an understatement.
I wish I would have known about that when I first started this.
Thanks a bunch.
So I have another, quick question.
I’ve been trying to get a simple attach script to work.
As far as I know this is the correct way to do it:
However whenever I execute it nothing happens. (the conversion to an editable poly works, but nothing gets attached)
My goal is to basically replicate the default functionality of Max's attach feature found in the modify panel.
When the objects with different materials get attached I would like the materials in question to be put into a Multi/Sub Object material. (The first option in the “Attach Options” dialogue that appears when you try to attach objects with different material assignments)
(Hopefully I explained that decently enough XD)
I have seen this thread here:
http://forums.cgsociety.org/archive/index.php?t-922140.html
Which I’m assuming is the one you’re referring to, however I can’t for the life of me get those functions to work. (Lack of knowledge on my end is pretty apparent so it’s no surprise)
The one linked off CG society looks like it probably comes into it's own when you're dealing with hundreds of objects
I decided I'd probably find this handy so I wrote it up for myself : the multi-sub material is automatically created by default - simply use the eyedropper to pick the material off the combined object. I'd advise against doing any scripting of the material editor if you can avoid it - it's a horrible place to visit.
I will most definitely heed your warning, the only reason I brought it up was because I’ve seen a few scripts that do not use the default material merging method when attaching objects so I thought I’d be as clear as possible. XD
I really appreciate the help. I learn best by going through other peoples code, however it seems that most scripts available online are generally quite a bit more complex than what I’m trying to achieve and the documentation doesn’t provide particle examples for everything so that can be hit and miss at times as well.
I’m really thankful that people are willing to show me the basic methods of doing simple tasks, it gives me a good starting point.
the polyop stuff is unusually consistent and well organised for maxscript so you'll probably find you can build yourself a bunch of useful mesh manipulating buttons quite quickly