Lodding script

Users who are viewing this thread

killkhergit

Squire
As the title suggests here's a lodding script you can use with (gmax)/3dsmax:

Code:
actionMan.executeAction 0 "40010"  -- File: Import File
Weldtest = $.numverts
actionMan.executeAction 0 "311"  -- Tools: Zoom Extents All Selected
	modPanel.addModToSelection (Vertex_Weld ()) ui:on
		$.modifiers[#Vertex_Weld].threshold = 1.0e-015
		if $.NumVerts < Weldtest do
		(
			messagebox "Gefixt!! / Fixed!!"
			macros.run "Modifier Stack" "Convert_to_Mesh"
			actionMan.executeAction 0 "40011"  -- File: Export File
		)
	macros.run "Modifier Stack" "Convert_to_Mesh"
	modPanel.addModToSelection (MultiRes ()) ui:on
		$.modifiers[#MultiRes].mergeVertex = on
		$.modifiers[#MultiRes].mergeWithinMesh = on
		$.modifiers[#MultiRes].reqGenerate = off
		$.modifiers[#MultiRes].vertexPercent = 50
	actionMan.executeAction 0 "40011"  -- File: Export File
		$.modifiers[#MultiRes].vertexPercent = 20
	actionMan.executeAction 0 "40011"  -- File Export File
if $.modifiers[#MultiRes].vertexCount < 35 do
(
	messagebox "Erg weinig vertices!! / Low vertex count!!"
)
	$.modifiers[#MultiRes].vertexPercent = 10
	actionMan.executeAction 0 "40011"  -- File Export File	
actionMan.executeAction 0 "40005"  -- File: Reset File
actionMan.executeAction 0 "40470"  -- MAX Script: Run Script

It's not 100% perfect (yet), but it will do.

Explanation:

- An "actionman" normally is a keyboard shortcut

- The messageboxes are "Dutch / English"

- When you want to use it, open up (g)max, menubar --> MAXScript, new, paste it, save it as the default format (.ms)

- How to use: open up max or reset. Having objects loaded in the current scene might screw your model up.
Then go to the asset browser, select maxscript, then "Run Script", or nenubar --> MAXscript, run script

- Upon running it will immediately prompt you to import a file (I for now suggest using .obj or a single-object "Editable Mesh/Poly"max, they're confirmed to work). When a message pops up saying "fixed", it has welded and cleaned up some vertices, asking you to export.

- When you're done exporting it will apply a LOD modifier, which lowers the model's detail to 50%. Export. Down to 20%. Export.

- Then, when a message says "Low vertext count", it's because the vertex count has dropped so much, adding a LOD to be loaded will actualy slow down the game.

- If the limit isn't reached it will go down to 10 percent. Export.

- For use on multiple objects one by one, it will ask you to reset and run a script again.

- Don't try to save a mesh as (name).lod# yet. Still have to figure out how to let Max export names with periods. Instead, just save your files as axe, axe1, axe2 etc, and then paste ".lod" between the name and the number.

- How to let LOD's work:

Let's say you made an axe called the "zezomgaxe", do the following:

Export.
Run the script
Result files, numbers are just an example:
zezomgaxe
zezomgaxe1
zezomgaxe2
zezomgaxe3
Add ".lod":
zezomgaxe (fixed or not)
zezomgaxe.lod1
zezomgaxe.lod2
zezomgaxe.lod3
Import.
Correct names if needed
Correct texture name missfires if needed (BRFedit empties the "Material" textbox if you decide to change the object's name in-BRF) . Use the same texture as the original "zezomgaxe". Coords WILL be preserved.
Save BRF.

Feedback will be appreciated  :mrgreen:
 
I have a fairly large job making .lods and ran across this thread.  I have a lot of expereince with resource files and texturing, but I am not familiar with 3-D software. 

What is the learning curve for the software and getting this script to run?  It looks very promissing and excatly what I need. 


What are the steps from the beginning (i.e. export .obj from resource, import, run script, etc.). 


Thank you
 
Getting this script to run is quite easy.

Copy the code to a *.ms file (a 3dsMax script file) and run it via Max's Menu Bar --> MAXScript --> Run Script, but from what I know this is a really old version of my script though...

Should you need a newer one, which includes opening and saving prompts and some other stuff, PM me. I don't have it with me now.

And oh, don't start making models using 3dsMax. Practice with Wings3D first. 3dsMax has much better tutorials though. Max is way better when you need high detail models. Wings does fine for MnB.
 
killkhergit said:
Getting this script to run is quite easy.

Copy the code to a *.ms file (a 3dsMax script file) and run it via Max's Menu Bar --> MAXScript --> Run Script, but from what I know this is a really old version of my script though...

Should you need a newer one, which includes opening and saving prompts and some other stuff, PM me. I don't have it with me now.

And oh, don't start making models using 3dsMax. Practice with Wings3D first. 3dsMax has much better tutorials though. Max is way better when you need high detail models. Wings does fine for MnB.

All I need is lower detailed models at the moment.  I have all the items I need in the mod, but some of them are to much detail and some people are getting crashes unless they lower textures or turn off formations. 

I guess I'll download a trail version of 3dsMax and try to get this working.  Can you please post the newer version of the script?

Thank you!
 
OK I downloaded gmax 1.2, installed the script, tried to run the script but it tells me the .obj file I selected has "No appropriate import module found" / "Improper file format". 

What I did was use the brfeditor to export a model as a .obj file and saved it to my desktop. 

Is there a plug-in required to read .obj in gmax?  I have no expereince with this software but should be able to run a script...


 
Works very well in max, there are some problems with how the texture gets applied though.  Retexturing LODs would be a terrible chore :wink:

EDIT: oh never mind, editable poly works!
 
There is a slight problem, for sure this time :smile:

The LODs get skewed in one direction more and more.  I wanted to use your script to make lods for armour but it's not working too well, only the first pass is useable really.

 
Well, as I said a few posts ago, that it was an old version.

This one is the 'latest' one:

Code:
resetMaxFile() #noPrompt
importFile ("C:/Documents and Settings/Leo Mes/Bureaublad/in.obj")
max tool maximize
Min = 0
distance1 = 0
distance2 = 0
distance4 = 0
actionMan.executeAction 0 "369"  -- Views: View Edged Faces Toggle
actionMan.executeAction 0 "311"  -- Tools: Zoom Extents All Selected
macros.run "Modifier Stack" "SubObject_5"
   rollout mesh_buttons "Delete separated detail meshes, like sword counterweights, shouldercovers or belts."
   (
      button Button_done "Done!"
         on Button_done pressed do
         (
            destroyDialog(mesh_buttons)
            subobjectlevel = 0
            if doesFileExist("C:/Documents and Settings/Leo Mes/Bureaublad/insimple.obj") == false do exportFile ("C:/Documents and Settings/Leo Mes/Bureaublad/insimple.obj") #noPrompt using:exporterPlugin.classes[15]
            Weldtest = $.NumVerts
            modPanel.addModToSelection (Vertex_Weld ()) ui:on
            $.modifiers[#Vertex_Weld].threshold = 1.0e-003
               if Weldtest > $.NumVerts do
               (
                  messagebox "Some vertices are welded!"
                  if doesFileExist ("C:/Documents and Settings/Leo Mes/Bureaublad/outsimplewelded.obj") == false do exportFile ("C:/Documents and Settings/Leo Mes/Bureaublad/outsimplewelded.obj") #noPrompt using:exporterPlugin.classes[15]
               )         
            modPanel.addModToSelection (Unwrap_UVW ()) ui:on
            modPanel.addModToSelection (MultiRes ()) ui:on
            subobjectlevel = 1
               rollout the_buttons "Select type, select high-priority verts, then hit press me!"
               (
                  button Button_rest "Armor / Weapon"
                  button Button_horse "Horse"
                  button Button_cont "Press me!"
                     on Button_rest pressed do
                     (
                        distance1 = $.NumVerts*0.4
                        distance2 = $.NumVerts*0.2
                        distance4 = $.NumVerts*0.1
                     )
                     on Button_horse pressed do
                     (
                        distance1 = $.NumVerts*0.5
                        distance2 = $.NumVerts*0.25
                        distance4 = $.NumVerts*0.125
                     )
                     on Button_cont pressed do
                     (
                        Min = $_null_.selectedVerts.count
                        distance1 = distance1 as integer
                        distance2 = distance2 as integer
                        distance4 = distance4 as integer
                        destroyDialog(the_buttons)
                        $.modifiers[#MultiRes].BoundaryMetric = on
                        $.modifiers[#MultiRes].baseVertices = on
                        $.modifiers[#MultiRes].mergeVertex = on
                        $.modifiers[#MultiRes].mergeThreshold = 0.25
                        $.modifiers[#MultiRes].mergeWithinMesh = on
                        $.modifiers[#MultiRes].reqGenerate = off
                        $.modifiers[#MultiRes].vertexCount = distance1
                           if $.modifiers[#MultiRes].vertexCount == 0 do
                           (
                              messagebox "ERROR, fixing"
                              $.modifiers[#MultiRes].vertexCount = distance1
                           )
                        if doesFileExist("C:/Documents and Settings/Leo Mes/Bureaublad/out.lod1.obj") == false do exportFile ("C:/Documents and Settings/Leo Mes/Bureaublad/out.lod1.obj") #noPrompt using:exporterPlugin.classes[15]
                        $.modifiers[#MultiRes].vertexCount = distance2
                           if $.modifiers[#MultiRes].vertexCount < Min do
                           (
                              messagebox "Too low vertex count, raising"
                              $.modifiers[#MultiRes].vertexCount = Min
                           )
                        if doesFileExist("C:/Documents and Settings/Leo Mes/Bureaublad/out.lod2.obj") == false do exportFile ("C:/Documents and Settings/Leo Mes/Bureaublad/out.lod2.obj") #noPrompt using:exporterPlugin.classes[15]
                        $.modifiers[#MultiRes].vertexCount = distance4
                           if $.modifiers[#MultiRes].vertexCount < Min do
                           (
                              messagebox "Too low vertex count, raising"
                              $.modifiers[#MultiRes].vertexCount = Min
                           )               
                        if doesFileExist("C:/Documents and Settings/Leo Mes/Bureaublad/out.lod4.obj") == false do exportFile ("C:/Documents and Settings/Leo Mes/Bureaublad/out.lod4.obj") #noPrompt using:exporterPlugin.classes[15]
                        actionMan.executeAction 0 "40005"  -- File: Reset File
                     )
               )
            CreateDialog the_buttons 360 80 900 480
         )
   )
CreateDialog mesh_buttons 520 32 900 400

Greatest improvement is the addition of high priority vertices.

Usable in just the same way as the previous script, except for the in- and exporting thing. This script works with files placed on my old XP desktop. You should change the file paths (it's quite simple to understand what's going on) to your own desktop or where input and output files are stored.

Also, don't forget that lod4 models aren't much larger that a few pixels in view, so having a crooked model mostly doesn't matter...
 
@killkhergit

I got your PM but thought I would respond here so it may help others as well. 

1. Export your .obj file (I'm guessing brfedit or openbrf will work) to your desktop and rename the mesh to "in.obj"

2. Modify the script “importFile ("C:/Documents and Settings/Leo Mes/Bureaublad/in.obj")” to point to your desktop

Run script.  I am not at my computer right now and available to test but I did not do these two things before.  I will post my results when I test them out. 

Thanks again for your help. 
 
OK I tried to run script again and still does not work. 

I exported a .obj file from openbrf (also tried with brfedit).  Named the file "in.obj" and placed on desktop.  I modified second line (well all references to your desktop) of script to point to my desktop (see spoiler):


I run the script Maxscript / run script /

I get error:

- - No Appropriate import module found (click ok)

- - Improper file format (click ok)

- - Runtime error:  No such macro script:  SubObject_5



Here is the code I modified:
resetMaxFile() #noPrompt
importFile ("C:/Users/Jacob Collins/Desktop/in.obj")
max tool maximize
Min = 0
distance1 = 0
distance2 = 0
distance4 = 0
actionMan.executeAction 0 "369" -- Views: View Edged Faces Toggle
actionMan.executeAction 0 "311" -- Tools: Zoom Extents All Selected
macros.run "Modifier Stack" "SubObject_5"
rollout mesh_buttons "Delete separated detail meshes, like sword counterweights, shouldercovers or belts."
(
button Button_done "Done!"
on Button_done pressed do
(
destroyDialog(mesh_buttons)
subobjectlevel = 0
if doesFileExist("C:/Users/Jacob Collins/Desktop/insimple.obj") == false do exportFile ("C:/Users/Jacob Collins/Desktop/insimple.obj") #noPrompt using:exporterPlugin.classes[15]
Weldtest = $.NumVerts
modPanel.addModToSelection (Vertex_Weld ()) ui:eek:n
$.modifiers[#Vertex_Weld].threshold = 1.0e-003
if Weldtest > $.NumVerts do
(
messagebox "Some vertices are welded!"
if doesFileExist ("C:/Users/Jacob Collins/Desktop/outsimplewelded.obj") == false do exportFile ("C:/Users/Jacob Collins/Desktop/outsimplewelded.obj") #noPrompt using:exporterPlugin.classes[15]
)
modPanel.addModToSelection (Unwrap_UVW ()) ui:eek:n
modPanel.addModToSelection (MultiRes ()) ui:eek:n
subobjectlevel = 1
rollout the_buttons "Select type, select high-priority verts, then hit press me!"
(
button Button_rest "Armor / Weapon"
button Button_horse "Horse"
button Button_cont "Press me!"
on Button_rest pressed do
(
distance1 = $.NumVerts*0.4
distance2 = $.NumVerts*0.2
distance4 = $.NumVerts*0.1
)
on Button_horse pressed do
(
distance1 = $.NumVerts*0.5
distance2 = $.NumVerts*0.25
distance4 = $.NumVerts*0.125
)
on Button_cont pressed do
(
Min = $_null_.selectedVerts.count
distance1 = distance1 as integer
distance2 = distance2 as integer
distance4 = distance4 as integer
destroyDialog(the_buttons)
$.modifiers[#MultiRes].BoundaryMetric = on
$.modifiers[#MultiRes].baseVertices = on
$.modifiers[#MultiRes].mergeVertex = on
$.modifiers[#MultiRes].mergeThreshold = 0.25
$.modifiers[#MultiRes].mergeWithinMesh = on
$.modifiers[#MultiRes].reqGenerate = off
$.modifiers[#MultiRes].vertexCount = distance1
if $.modifiers[#MultiRes].vertexCount == 0 do
(
messagebox "ERROR, fixing"
$.modifiers[#MultiRes].vertexCount = distance1
)
if doesFileExist("C:/Users/Jacob Collins/Desktop/out.lod1.obj") == false do exportFile ("C:/Users/Jacob Collins/Desktop/out.lod1.obj") #noPrompt using:exporterPlugin.classes[15]
$.modifiers[#MultiRes].vertexCount = distance2
if $.modifiers[#MultiRes].vertexCount < Min do
(
messagebox "Too low vertex count, raising"
$.modifiers[#MultiRes].vertexCount = Min
)
if doesFileExist("C:/Users/Jacob Collins/Desktop/out.lod2.obj") == false do exportFile ("C:/Users/Jacob Collins/Desktop/out.lod2.obj") #noPrompt using:exporterPlugin.classes[15]
$.modifiers[#MultiRes].vertexCount = distance4
if $.modifiers[#MultiRes].vertexCount < Min do
(
messagebox "Too low vertex count, raising"
$.modifiers[#MultiRes].vertexCount = Min
)
if doesFileExist("C:/Users/Jacob Collins/Desktop/out.lod4.obj") == false do exportFile ("C:/Users/Jacob Collins/Desktop/out.lod4.obj") #noPrompt using:exporterPlugin.classes[15]
actionMan.executeAction 0 "40005" -- File: Reset File
)
)
CreateDialog the_buttons 360 80 900 480
)
)
CreateDialog mesh_buttons 520 32 900 400



Looking a little closer and the script calls out for macros “Modifier Stack" "SubObject_5".  I believe I am missing SubObject_5 macro.  Is it possible to get this as well? 

Thanks
 
Cyclohexane said:
...
Looking a little closer and the script calls out for macros “Modifier Stack" "SubObject_5".  I believe I am missing SubObject_5 macro.  Is it possible to get this as well? 

Thanks

Random useful pic:

http://www.3dvalley.com/tutorialsdata/images/wheel/tut6_full11.gif

See the 'Vertex/Edge/Border/Polygon/Element' bit? They're the five ways of selecting bits and pieces of models. If, for example, you select 'Vertex', you can edit the selected mesh at vertex level. Controlling these selections by script works like this: I tell the current selection to go to the Modify Panel, and select number 5, using the line you mentioned, of the selectors. Taking a look at an imported OBJ tells me number five of that list is 'Element', which means I tell Max to go to Element selection.

Could be that GMax doesn't support these selectors (not obvious), or that you can't control them by script (quite possible).
 
killkhergit said:
Cyclohexane said:
...
Looking a little closer and the script calls out for macros “Modifier Stack" "SubObject_5".  I believe I am missing SubObject_5 macro.  Is it possible to get this as well? 

Thanks

Random useful pic:

http://www.3dvalley.com/tutorialsdata/images/wheel/tut6_full11.gif

See the 'Vertex/Edge/Border/Polygon/Element' bit? They're the five ways of selecting bits and pieces of models. If, for example, you select 'Vertex', you can edit the selected mesh at vertex level. Controlling these selections by script works like this: I tell the current selection to go to the Modify Panel, and select number 5, using the line you mentioned, of the selectors. Taking a look at an imported OBJ tells me number five of that list is 'Element', which means I tell Max to go to Element selection.

Could be that GMax doesn't support these selectors (not obvious), or that you can't control them by script (quite possible).

So you are saying that gmax will not work with this script?  I know 3dmax has a 30 day trail.  I'd be willing to try it out if I knew for certain as I feel this is the only way I could quickly make a bunch of lods without a big learning curve. 
 
I keep getting the message, "ERROR, fixing" with your new code.  The old code seems to work; well, excepting the fact that the textures are strange looking afterward, but it worked.  What am I doing wrong?
 
TheRighteousMan said:
I keep getting the message, "ERROR, fixing" with your new code.  The old code seems to work; well, excepting the fact that the textures are strange looking afterward, but it worked.  What am I doing wrong?

http://area.autodesk.com/forum/autodesk-3ds-max/maxscript/modifiersmultiresvertexcount-changes-to-zero

I asked it over at the Autodesk forums a while ago, and it seems there's a bug in assigning values using script to MultiRes.

The script uses a workaround, and I added a messagebox telling that the error had occurred again. Remove the messagebox and everything should be working just fine. Or you could change it to the percentage workaround (see other forum).

TheRighteousMan said:
I keep getting the message, "ERROR, fixing" with your new code.  The old code seems to work; well, excepting the fact that the textures are strange looking afterward, but it worked.  What am I doing wrong?

Do consider the lod models at level two or more will only be a few pixels large on screen.

You could also try selecting important mapping vertices as 'High Priority'.
 
killkhergit said:
TheRighteousMan said:
I keep getting the message, "ERROR, fixing" with your new code.  The old code seems to work; well, excepting the fact that the textures are strange looking afterward, but it worked.  What am I doing wrong?

http://area.autodesk.com/forum/autodesk-3ds-max/maxscript/modifiersmultiresvertexcount-changes-to-zero

I asked it over at the Autodesk forums a while ago, and it seems there's a bug in assigning values using script to MultiRes.

The script uses a workaround, and I added a messagebox telling that the error had occurred again. Remove the messagebox and everything should be working just fine. Or you could change it to the percentage workaround (see other forum).

TheRighteousMan said:
I keep getting the message, "ERROR, fixing" with your new code.  The old code seems to work; well, excepting the fact that the textures are strange looking afterward, but it worked.  What am I doing wrong?

Do consider the lod models at level two or more will only be a few pixels large on screen.

You could also try selecting important mapping vertices as 'High Priority'.

I'm not sure what you are getting at above but like TheRighteousMan, I got the old script to work using 3dsmax (gmax will not).  In order to fix the textures, I changed the export precision to 10. 

This is really a cool tool but unfortunately, I have to do everything within a month because there is no way I am going to buy 3dsmax (a couple thousand I believe is the price). 

If you really want to help the community out (more than you have), create a script like this that works for gmax (OSP). 

But great tool!
 
Back
Top Bottom