Skip to content

Commit

Permalink
Updated stage importing guides
Browse files Browse the repository at this point in the history
  • Loading branch information
PTKay committed Feb 10, 2024
1 parent 263dcb1 commit 0024e2e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,29 @@ description: Importing Collision tutorial for Sonic Generations
- [HedgeArcPack](/tools/hedgehog-engine/common/files/#hedgearcpack){ target="_blank"}

#### Part 1 (Creating Collision in Blender)
You'll need model for the collision. If you want collision with different parameters (or tags), you'll need special ini file for HavokConverter with tags. You can download it [here](https://gist.github.com/TheExentist151/8e4896b807d49cd86ff2b643d34c7aa2).
Let me show you how to apply tags in your collision:
You'll need a separate model for the collision. While it is possible to use your stage's model files as a collision, we still recommend that you create a separate project/model for it, even if it's a copy of it.

First, you need to find mesh on which you want to apply tags.

Second, you need to add the tag in the end of the name. (for example: level_stone`@STONE`).
It is possible to specify tags for your collision, which control the type of collision it has. For this, you'll need a special ini file for HavokConverter with tags. You can download it [here](https://gist.github.com/TheExentist151/8e4896b807d49cd86ff2b643d34c7aa2).
To apply these tags to your collision model, you can simply rename the meshes and add the tag as a prefix to its name. Below is an example of how you can do this, in case you want a mesh to have the "Stone" collision tag:

!!! info "Example"
![Tag example](assets/importing-collision/tag_example.png)

You can find other tags in `HavokConverter` if you drop this ini file in `"libgens-sonicglvl-master/bin"`.
You can find all the available tags by opening `HavokConverter` after placing the mentioned INI file in the same folder as its executable.

#### Part 2 (Importing Your Custom Collision in the Game)
Open `libgens-sonicglvl-master/bin` folder and drop special ini file in it. Open `HavokConverter.exe` and fill:
#### Part 2 (Converting Your Model Into a Collision File)
Open `HavokConverter.exe` and fill the following options:

- Source 3D model files - Your collision model files
- Output file - Directory which will contain the converted collision (add phy.hkx in the end of the name)

![Havok Converter Settings](assets/importing-collision/havok_converter_window.png)

Now you can click `Convert` button and wait.
Now you can click the `Convert` button and wait.

Next, you'll need to unpack original level's file which is located in the root of .cpk file (for example: `#ghz200.ar.00`). Unpack it with `HedgeArcPack`, and drop your collision file. Open `Terrain.stg.xml`, find `RigidBodyContainer`, and paste here your collision's name without the extension and save it. You can also enable `Collision Render` to see your collision in-game.
#### Part 3 (Importing Your Collision into the Game)
When the conversion process finishes, extract your custom stage's `#` file, and place the generated `phy.hkx` file there. Afterwards, open the `Terrain.stg.xml` file, and edit the collision file that is mentioned. This is mentioned in the `RigidBodyContainer` tag. Change its value to your `phy.hkx` filename, without the extension. Below is an example for a file name `MyCollision.phy.hkx`:

![Rigid Body Container](assets/importing-collision/rigid_body_container.png)

Pack this archive using `HedgeArcPack` and drop it in your mod's folder.

???+info "Root folder"
![Root folder](assets/importing-collision/mod_folder_root.png)

???+info ""disk" folder"
![Disk folder](assets/importing-collision/mod_folder_disk.png)
Now re-pack this file and replace the original. After booting into the game, you should now notice that your level has working collision.
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,32 @@ description: Importing Terrain tutorial for Sonic Generations
- [Sonic GLvl](/tools/hedgehog-engine/blueblur/levels/#sonicglvl){ target="_blank"}
- [Blender](https://blender.org){ target="_blank"}
- [HedgeArcPack](/tools/hedgehog-engine/common/files/#hedgearcpack){ target="_blank"}
- [PackCpk (From SkythTools)](/tools/general/files/#skythtools)
- [ModelConverter](/tools/hedgehog-engine/common/models/#modelconverter)

#### Part 1 (Creating Terrain in Blender)
First of all, you need terrain for your level. You can do the terrain yourself, or take already created terrain.
If your level contains transparent materials you need to add a proper layer tag to it. For transparency, you have two available layers, and you should pick the one that's best suited for your use case in order to avoid issues.

Layers | Usage
------ |-------
trans | Used for translucent materials, as in, materials which are not 100% opaque but also not 100% transparent (ex. windows)
punch | Used for materials which have binary transparency (one part is 100% opaque, another is 100% transparent). Useful for most kinds of textures, like leaves or grass
trans | Used for translucent materials, as in, materials which are not 100% opaque but also not 100% transparent (ex. windows)

In order to specify a layer for a material, use the `@LYR` prefix, with the layer name between parenthesis after it.
!!! info "Example"
![Transparent material example](assets/importing-terrain/transparent_material_example.png)

You can then export your terrain as an FBX file.
You can then export your terrain from Blender into an Assimp compatible format (FBX, DAE or OBJ work).

#### Part 2 (Importing the Level to the Game)
Download SonicGLvl, and run `bin/HedgehogConverter.exe`. Fill up the following entries:

- Source 3D model files - Your terrain model files
- Source textures directory - Directory containing the texture files of your terrain
- Terrain output directory - Directory which will contain the converted terrain
- Terrain output directory - Directory which will contain the converted terrain.

Make sure that the folder has a name that matches the target stage you want to replace. For example, for Green Hill Modern, use the folder name `ghz200`.

Be sure to also turn on the following options under "Materials":

Expand All @@ -41,38 +45,54 @@ In the end, you should have something similar to this:

![HedgehogConverter settings](assets/importing-terrain/hedgehog_converter_window.png)

Next, click `Convert` button and wait. Once that's done, go to your level's directory and extract any .ar archive using HedgeArcPack. After that, extract archives from the original level in bb or bb2.cpk/Packed/ folder. I'll be using ghz200 stage.
Take <code style="color: green;">ghz200_Direct01.light</code> and drop this file in your level's archive and pack it.
Next, you'll need to unpack the # file which is localed in the root of cpk. In my case, it is <code style="color: green;">#ghz200.ar.00</code>. Unpack it, and open <code style="color: green;">"Terrain.stg.xml"</code>, find DataName, paste your light file's name without the extension and save it.
Next, click the `Convert` button and wait.

#### Part 3 (Getting missing files)
Once the conversion is done, we need to get files that might be missing from your stage.

##### \#stage.ar file
Your stage needs a `\#` file in order to store set-data, collision, and other stage information. We can use the file from the stage we're replacing. If you're replacing Green Hill Modern, go to `disk/bb.cpk` (extract using PackCpk), and copy the `#ghz200.ar.00` and `#ghz200.arl` files into your stage mod files (`disk/bb` folder).

![Light in Terrain.stg.xml](assets/importing-terrain/light_dataname.png)
##### Fix-up Terrain.stg.xml
The `Terrain.stg.xml` file contains information about the stage's terrain. This includes what sky model to use and what sunlight to use. If you did not setup any sunlight for your stage, and do not have a separate sky model for your stage's skybox, you'll need to remove these references from this file, otherwise the game will crash. To do this, extract `#ghz200.ar.00`, and edit the file using your editor of choice (I recommend Notepad++ or Visual Studio Code). Now you'll want to remove the `Sky` XML section and/or `Light` section, depending on the files that you don't have. Here's an example of a before and after, to better illustrate what you need to remove:

Pack this archive and drop it in your mod's folder. Now you should have your mod files with a setup that looks something like this:
![Terrain.stg.xml](assets/importing-terrain/light_dataname.png)
![Terrain.stg.xml after removing sections](assets/importing-terrain/light_dataname_after.png)

After making the necessary fixes, re-pack `#ghz200` and replace the original file.

Now you should have your mod files with a setup that looks something like this:

???+info "Root folder"
![Root Folder](assets/importing-terrain/mod_folder_root.png)

???+info ""disk" folder"
![Disk folder](assets/importing-terrain/mod_folder_disk.png)

???+info ""Packed/LevelSlot" folder"
![Packed - LevelSlot folder](assets/importing-terrain/mod_folder_packed.png)
???+info ""Packed/StageName" folder"
![Packed - StageName folder](assets/importing-terrain/mod_folder_packed.png)

#### Part 3 (Sonic GLvl Basic Setup)
#### Part 4 (Sonic GLvl Basic Setup)

Next up, open your level in SonicGlvl by opening the # file, and press Ctrl+A, Delete. It'll delete all the objects from your level. Find <code style="color: green;">"SonicSpawn"</code> in the objects menu and place it anywhere.
Be sure to set "Active" to "true" in the settings of <code style="color: green;">"SonicSpawn"</code> object.
Next up, we need to do some very basic setup of your level's set data in SonicGlvl. Open the app, and open your stage's `#` archive from there. Once the level has been imported into SonicGlvl, press Ctrl+A and then Delete. This will delete all the objects that are present in your level's set data, which are the original objects from the stage we are replacing. Now, find <code style="color: green;">"SonicSpawn"</code> in the objects menu on the left, and place it anywhere you want. This will be where Sonic will spawn in your level. Also, be sure to set the "Active" property to "true" in the settings of the <code style="color: green;">"SonicSpawn"</code> object.

![SonicSpawn object and settings](assets/importing-terrain/sonicspawn_glvl.png)

After that, press "File", "Save Stage Data" and "Save Stage Terrain".
After that, go to "File" and press "Save Stage Data" and "Save Stage Terrain".

#### Part 4 (Creating Skybox - Recommended)

Skyboxes in Sonic Generations are just regular .model files. Though not mandatory for the game to boot, they are recommended so that your level at least has a sky to look at. You can take these from the original levels or create one yourself.

##### Making one yourself
Export your skybox model from Blender into an Assimp compatible file format. Then, using ModelConverter, drag and drop the model file into the Sonic Generations .bat file. This will generate the .model file, as well as material files. You will need to convert the textures of your skybox manually into the DDS format.

#### Part 4 (Creating Skybox)
##### Grabbing one from a level
Go to the `Packed` folder in bb/bb2, and open the folder corresponding to the level you want the skybox from. Then, extract the `.ar` archive, and look for the sky's `.model` file. The name should have something to do with "sky". If yo don't manage to find it, look at the stage's `Terrain.stage.xml` file, as it will mention the skybox's model name there. You will need the .model file, the textures (`.dds` files) and the materials of the sky model.

Skyboxes in Sonic Generations is just regular model files. You can take them from the original levels or create them yourself.
Take your skybox's files and drop them into your level archive. Then, open # file, and open <code style="color: green;">Terrain.stg.xml</code> again. Find Model and paste your skybox's model name here without the extension and save it.
##### Using the Skybox files
After getting the necessary skybox model files, place them inside your stage's `Packed/stageName/stage.ar` file. Then, open `#` file of your stage, and open the <code style="color: green;">Terrain.stg.xml</code> file. You'll need to create a `Sky` tag and write the name of the `.model` file of your skybox, without the extension. Below is an example of how you should write this. In this example, the skybox has a model file named `MySkybox.model`:

![Skybox in Terrain.stg.xml](assets/importing-terrain/skybox_model.png)
![Skybox in Terrain.stg.xml](assets/importing-terrain/skybox_model.png)

But this is only the terrain and skybox, now you need to create collision for your level. You can see this tutorial [here](/guides/hedgehog-engine/blueblur/levels/importing-collision).
This concludes this guide. If you boot your stage now, you'll notice that you will fall through the ground. This is because you only ported the terrain, and not the collision. To do this, follow the guide [here](/guides/hedgehog-engine/blueblur/levels/importing-collision).

0 comments on commit 0024e2e

Please sign in to comment.