Blender Model Compiler
BeigeAlert
Texas Join Date: 2013-08-08 Member: 186657Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, NS2 Map Tester, Reinforced - Diamond, Reinforced - Shadow, Subnautica Playtester, Pistachionauts
The day is finally here! I'm proud to finally be releasing a tool that allows you to compile .blend files directly into .model files for ns2. Unlike the previous release, this one is FULLY FEATURED -- that means animations and physics will properly export! Also unlike the previous release, this is not a script that will be run from within blender, but rather these scripts are designed to be run by builder.exe.
https://www.dropbox.com/s/k6r8z8uccdzig34/BlenderCompiler.exe?dl=1
Simply place that exe file in your Natural Selection 2 folder -- the same folder as Builder.exe -- and run it. You'll be prompted for the location of your blender executable.
The script will automatically make the necessary changes to builder_setup.xml so builder will run the program. It will also automatically copy the python scripts necessary to "Natural Selection 2/utils/blender_scripts"
To use the utility, simply start up a mod, and place a .blend file into the source directory. Builder will automatically find it, run the BlenderCompiler.exe file (it's not just an installer -- don't delete it!!!), which launches an instance of blender in the background that runs the scripts that do the exporting. Not any .blend will work, however. There is a small amount of prep that needs to be performed in the files to make the scripts accept them. See the "Spark Model Manual" for details (link in launchpad).
There's a feature in the blender compiler that allows you to output multiple .model files from a single .blend. This is useful for making different variations of a similar prop, or for breaking a prop into many pieces (eg catwalks). HOWEVER, what this means is that we're violating the assumption made by Builder.exe that every source file has exactly 1 output file. To deal with this, builder will always report a failed build when compiling blender files, but will also print out useful error text telling you what really happened, including if it was successful or not.
Long story short: do not trust builder when it says it failed. Read the error text and check your output to verify!.
I have tried to be thorough in the manual about how to use this tool, and I hope to have some quality example files for you to look at soon.
As usual, if you find any bugs please post here, and I'll get to them when I can.
Cheers!
Beige
https://www.dropbox.com/s/k6r8z8uccdzig34/BlenderCompiler.exe?dl=1
Simply place that exe file in your Natural Selection 2 folder -- the same folder as Builder.exe -- and run it. You'll be prompted for the location of your blender executable.
The script will automatically make the necessary changes to builder_setup.xml so builder will run the program. It will also automatically copy the python scripts necessary to "Natural Selection 2/utils/blender_scripts"
To use the utility, simply start up a mod, and place a .blend file into the source directory. Builder will automatically find it, run the BlenderCompiler.exe file (it's not just an installer -- don't delete it!!!), which launches an instance of blender in the background that runs the scripts that do the exporting. Not any .blend will work, however. There is a small amount of prep that needs to be performed in the files to make the scripts accept them. See the "Spark Model Manual" for details (link in launchpad).
There's a feature in the blender compiler that allows you to output multiple .model files from a single .blend. This is useful for making different variations of a similar prop, or for breaking a prop into many pieces (eg catwalks). HOWEVER, what this means is that we're violating the assumption made by Builder.exe that every source file has exactly 1 output file. To deal with this, builder will always report a failed build when compiling blender files, but will also print out useful error text telling you what really happened, including if it was successful or not.
Long story short: do not trust builder when it says it failed. Read the error text and check your output to verify!.
I have tried to be thorough in the manual about how to use this tool, and I hope to have some quality example files for you to look at soon.
As usual, if you find any bugs please post here, and I'll get to them when I can.
Cheers!
Beige
Comments
Well...
Apparently it works.
I say this:
Shivers in the pants before clicking the spoiler button ??? ... Come on...
File provided for dummies.
_ Fixed a typo in the part of the program that inserts the new lines into the "builder_setup.xml" file. It would complain about a parsing error.
To fix, all you have to do is re-download the EXE (same link), and replace the one in your Natural Selection 2 directory, and run it (I mean double click it, not run it through builder just yet). You'll be prompted for permission to "repair" the editor_setup.xml file. Utility will take care of all the changes that need to be made.
Unfortunately, there's no way for me to make bolded text in the error output.
The keymaps thing I've never seen before... I think it my have something to do with an addon you're using? I certainly don't call to it in my scripts, so that's something else at work.
I hope to have some good example assets ready soonish.
I'm looking into the lowercase filenames problem now. You're right, it shouldn't be doing that.
The exporter will no longer force file names to lowercase... however I still recommend everybody follow the proper ns2 naming conventions and keep it lowercase anyways.
Maybe a line of dashes would do it as a visual separator.
Ex:
All file blah blah success
Can it also be used for uncompiling a .model file into a .blend files or is the source file still needed in this case?
For example a cosmetic mod that would replace the vanilla jump animation of marines.
Yes! If you know how to use Blender, this tool does it all!
Unfortunately it's not an importer. Though I have been playing around with the idea, just not really had the time to make anything with it yet.
Btw got any idea how mods like these managed to partially edit existing models?
They probably just opened up the included example assets and made their changes there.
If you look in your "Natural Selection 2" directory, you should see a folder called "assets", and in there are a bunch of the source assets from the game. There's one called "modelsrc/marine/rifle/" and in there are both the rifle model and rifle_view model source .max files. You'll need 3dsmax to do anything meaningful with the files though, and specifically 3dsmax 2009 if you want to do anything involving physics.
Bugfix update!
Fixed a bug that made models fail to compile if a physics solid was parented to an empty object.
Fixed a bug that made physics objects without parents be oriented incorrectly.
To update, simply re-download the executable from the link on the first page, overwrite the one in your Natural Selection 2 directory, and run it. This will automatically copy out the fixed scripts to the proper directories.
Fixed a small bug caused by the above bug, oops! (Collision solids were improperly transformed if they weren't parented to bones).
Fixed a bug where the exported normals/tangents/binormals wouldn't be correct if object had a transform.
To update, simply re-download the executable from the link on the first page, overwrite the one in your Natural Selection 2 directory, and run it. This will automatically copy out the fixed scripts to the proper directories.
Fixed a bug where animations wouldn't export properly.
Added a new feature to allow the compiler to use normal maps from pre-existing NS2 props: "flip_bitangent". Setting this flag in the model_compile text block flips the bitangent from what it is in Blender. (Meaning that normal maps from NS2 can be used in Blender-exported assets, otherwise you'd need to invert the y (green) component of the tangent space normal map).
EDIT: Also fixed another issue that would cause some animations to either be too long, or have a negative length.
@ZdrytchX