(Original guide by Paraxade)
This tutorial will cover how to add custom breakable objects to Sonic Generations.
Step 1: Modeling
- The first thing you will need to do is create the model for your breakable object. You will need two models: the intact version, and the broken version made up of a bunch of little pieces.
- Make sure it's properly scaled! You will want to make sure this is correct before you do anything else so you don't have to repeat the process later. You can create a box with Sonic's dimensions (0.5m x 0.5m x 1.0m) for reference, or import the model into a stage scene.
Step 2: Exporting the mesh and collision
- Before you export, you will have to reset the XForm on your objects. Select your object(s), then go into the tools tab on the right sidebar. Click on "Reset XForm", then "Reset Selected".
- You should also make sure the object's coordinates are at 0,0,0. Select all your objects, use the transform tool and type in the values at the bottom.
- Keep in mind you do not want to export both the intact and broken versions of the object at the same time. Make sure only one is in the scene when you export.
- You can now export the scene through OgreMax. Use the default settings. In the same folder as the .scene file, you'll get a .mesh file for each object in the scene, as well as materials and textures. If the textures aren't there, just copy them over for organizational purposes. Repeat the process for the broken version.
- To get the collision, select all your objects. Add the Havok Shape modifier, and set the shape type to Convex Hull. Then add the Havok Rigid Body modifier, and fill in a number for Mass. 3-5kg usually works well enough.
- Next, export through the Havok Content Tools toolbar option. Make a new configuration for breakable objects. These are the filters and settings you should use, in this order: Settings for Transform Scene | Settings for Create Rigid Bodies | Settings for Write to Platform (Note that if you already have a configuration for exporting stages, the configuration for exporting objects is the same, minus the Create World filter. I would also recommend changing the write location so you don't overwrite any stage collision you've previously exported.) Repeat the process for the broken version.
- Name the files: objectname.phy.hkx and objectname_brk.phy.hkx.
Step 3: Converting .mesh to .model
- Each model needs a bone attached to it. This is a pain to do manually, but luckily the SVN version of SonicGLvl will do it automatically when you convert to .model.
- Open SonicGLvl. Click on "Models --> Convert Ogre .mesh to .model".
- Select each .mesh file and save it in a different folder from the original .mesh as a .model file. You need to do each mesh one at a time. Note that SonicGLvl does not change the file extension automatically, so you will have to do that manually as you go. Alternatively, you can save it as a .mesh and then do a batch renaming afterwards.
- When you're finally done, you should have a folder full of .model files, your textures, and some new .material files. These material files are different than the ones that Ogre exported, and these are the ones that you will import into the game.
Step 4: Importing the object into the game
- If you've done everything correctly up to this point, then you should have a folder with a bunch of .model files, textures, and .material files. You should also have two .hkx files, one for the intact model and one for the broken model. The next step is to add these files into the game with Generations Archive Editor. We'll use Green Hill as an example; if you're importing into a different level, then obviously just replace "ghz" with your level's abbreviation.
- Open #ghz_cmn.ar.00. Add your two .hkx files to this file, then open StageObject.sto.xml. Add the name of your object, both the intact and broken versions, to the listing in this file. Remember the names you enter here, you'll need them again later.
- Open ghz_cmn.ar.00. Add all of the .model, .material, and .dds files to this file.
Step 5: Adding an ObjectProduction entry
- The next thing we need to do is add two entries for the object in ObjectProduction. The file specifically that you will have to modify is ObjectProduction.phy.xml in bb/#SystemCommon.ar.00. Since the intact and broken versions of the object are different objects, you will need two entries.
- Copy one of the other object entries to use as a base. These are the things you need to modify:
- Object name: The entry's name. This is the name you have to specify to actually add the object to a level. Remember that it needs to be the same as whatever you added to StageObject.sto.xml.
- <Model>: The .model file(s) that your object uses. The broken version will have multiple .model files; just make as many <Model> tags as you need to specify all of them.
- <RigidBodyContainer>: Filename of your .hkx file.
- <RigidBody>: The node names in 3DS Max when you exported your collision. Like with <Model>, use as many as you need to specify all of them.
- <NextObjName>: On the intact object's entry, specify the name of the broken object's entry. On the broken entry, this should be blank.
- <IsHoming>: You can optionally set this to "true" to make it possible to homing attack the object.
- <SoundID>: The sound the object plays when you break it. Look through some of the other entries to find out which sound effects are available.
- After you're done, save the file.
- Now all that's left is to add the object to your level. Go into SonicGLvl and create an ObjectPhysics. Change the "Type" parameter to the name of your object. (Again, this is whatever you entered in ObjectProduction.) You can optionally set IsDynamic to true. This will make it so your object can be moved and will be affected by gravity; the broken pieces will be dynamic regardless. Then save the file and run the level. If you've done everything correctly, then everything should be working properly.
Optional: Creating a SonicGLvl Template
- This step isn't strictly required, but highly recommended. If you create a template, then you'll be able to see the object instead of a small grey box in SonicGLvl. This makes it much easier to do accurate object placement.
- Find your .mesh and .material files (the ones that exported with OgreMax, NOT the ones you got after converting to .model). Add these to the SonicGLvl media folder. Materials go in /materials/scripts. Textures go in /materials/textures. Meshes go in /models/common.
- Your .material file should have the same filename as the .mesh file. The texture should have the same filename it had when you exported.
- Next you have to add it as an AltMesh. Go to templates/common and open ObjectPhysics.xml. Scroll down to the bottom and add an AltMesh entry.
- Set <Condition> to "Type==[your object's name]".
- Set <Mesh> to the filename of the .mesh file.
- Now save the file, and you're done. The next time you boot up SonicGLvl, you should see your object appear in ObjectPhysics instead of the grey box.