Search Unity

Map Editor and Mod Tools for Fractured State

Discussion in 'Works In Progress - Archive' started by KelsoMRK, Mar 9, 2012.

  1. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    The past few months I've been working on a moddable RTS game called Fractured State. The technical goal of the game is to load as much data at run time as possible so folks can change the game in any number of ways. I also want to provide tools and plugins to facilitate this process and let users manage the mods they have installed quickly and easily. Most of the game data is loaded via XML files and PNG textures. When the game is launched it loads the assets for the active mod before loading the "base" assets. If a base asset has the same name as a modded one then it isn't loaded and the modded asset "wins" so to speak. Here's some chronology of the work I've been doing on the terrain features for the map editor.

    Once I got the mesh generating I worked on splitting up a texture atlas into a set of tiles that can be painted onto the terrain. This is done by shifting the UV coordinates of the mesh around on the texture sheet.



    The size of the individual tiles as well as the material settings (Diffuse color, texture, etc) are all controlled via a series of XML files so it's easy to swap properties in and out or make a mod that adds new terrains or edits existing ones.

    Another shot of UV tiling progress.


    Once that was done I started finalizing the sculpting functions. Because of the overlapping vertex positions Unity's built in normals calculations didn't give ideal results - as you can see here.


    So I wrote an extender method for the Mesh class that calculates smooth normals.


    I then spent about a week putting a GUI Skin together and getting the mod loading working a bit better. In this shot the first terrain in the list is loaded from a mod while the rest are in the base code. You can see what mod is active via the tooltip in the lower left corner.


    Lastly, I started thinking about how to get more definition out of the terrain mesh with lightmap baking and ambient occlusion. As luck would have it, hausmaus posted this awesome thread about baking per-vertex ambient occlusion so I roughed it out in the editor. Here's the result.


    This is far from perfect as it has the fractal look of the out-of-the-box normals calculation but it was a great starting point (thanks again hausmaus!). The next step will be to smooth the result out a bit so overlapping vertex positions share the same vertex color. This should speed up the calculation and get rid of the fragmenting. After that it's off to shader town to integrate it into the editor more tightly.

    So far this project has been super fun. It presents an interesting challenge because Unity has spent so much time creating awesome workflows that just work and do a lot of the heavy lifting. Because I want folks to edit this game without the Unity editor I've had to create some of that functionality for myself and develop my own workflows. It's been a blast and I've learned a ton.

    If you can, please take a minute and read my blog at http://fracturedstate.net and, if you're really inclined, join the forum and leave a comment.

    Thanks for reading!
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Been cleaning up some workflow and adding features the past 2 weeks. Because calculating smooth terrain normals is pretty intensive I shunted it off to a background thread which took a fair bit of work because Unity isn't thread safe. Still takes a bit of time but at least you can now do other stuff while it's processing.

    Also did a bit of Python work on an exporter for mesh data in Blender. I messed around with writing a .X run time importer but decided to just roll my own format and it's actually making life much easier. It's a plaintext format so if folks aren't inclined to use Blender it should be pretty straightforward to write an exporter for whatever suite you're using.



    The exporter doesn't export any Material data because the workflow keeps materials and meshes loosely coupled. All you have to do is pair them up in an object's data file and the framework will apply everything correctly. The nice thing about this is you can use the same model multiple times with different textures and only have to export it once.

    Once that was done I added a new tool module in the editor to load in the object's XML file and load the exported Blender mesh. Add a super awesome texture and we've got our first map prop!



    Still have to do some work on organizing props in the editor by categorizing them and drawing a collapsible tree view - so that's the project for the next few days.
     
  3. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    First alpha version of Map Editor is out now. Go here to download it for Mac and PC. Also on that page is the Python script to export mesh data out of Blender.



    Let me know what you think!
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Reposting this video demo in order to keep everything together.

    This is the new terrain texture painting system that I have been developing over the past few weeks. It allows for up to 8 textures per terrain, is real time, and uses alpha mask "brushes". Brushes are PNG files that you just drop into the Brush directory of the game. The Editor finds them and loads them automatically. Terrains are declared in Terrain.xml and point to texture files in the game directory. These are loaded at run time in order to build the texture list you see on the right. The actual pixel painting is managed by a shader with 2 control maps. RGBA in those textures maps to a texture in the terrain list. This way we can paint textures on top of textures, blend them together, and - eventually - erase textures even if they are "in between" layers.

     
  5. DaneC020

    DaneC020

    Joined:
    Mar 19, 2010
    Posts:
    191
    Very cool looking. I have been wanting to work on a similar solution for my game, unfortunately I haven't gotten to the texturing stage yet. I appreciate you showing the community the progress of your editor, as it helps provide insight to those such as myself trying to tackle a similar issue. I will definitely keep watching and wish you the best of luck with your project!

    -Dane
     
  6. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Thanks for the feedback! I'm very pleased with the way the texture painting turned out.
     
  7. TehWut

    TehWut

    Joined:
    Jun 18, 2011
    Posts:
    1,577
    Wow, this stuff is simply amazing, So genius! but way over my head..

    can't wait to try it out, planning on releasing a simple version soon?
     
  8. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Thanks!

    The Editor is always available for free at http://fracturedstate.net. Pricing on the final game is yet to be determined as we're just not far enough along at this point. The current Editor build is a bit outdated and doesn't include the new texture painting system, but I'm going to try and get an updated version up by the end of the week.