-
Notifications
You must be signed in to change notification settings - Fork 2
Creating .asset_bg files
In COM3D2 the character-related models are stored in .model, while all other things are either loaded as Unity Prefabs from resources.assets or from .asset_bg files (well, lets ignore the part that COM doesn't have any relevant .asset_bg files, yet). This means one have to use .asset_bg files in order to add stuff to say Photo Mode, for use as Backgrounds or Props. What is .aset_bg file? Actually, it's nothing special, it's just Unity Asset Bundle with different file extension changed to .asset_bg . I'm not sure as to why KISS doesn't allow modders to load .asset_bg files, but can't say I care for their reasoning on this matter, hence ModLoader enables loading of .asset_bg files from Mod folder.
For the time being, COM3D2 only allows loading of Asset Bundles built in Unity Editor 5.6.4, meaning you can't rip CM3D2 bundles for use in COM3D2. Well, they will be loaded, but because this version of unity doesn't like legacy bundles (CM3D2 uses Unity bundles from 4.6.9 to 5.3.5), the loaded mesh materials won't load properly.
First of all, we need a model we want to put into the game. I'm going to go with this simple hammer:
The body and it's dimensions are shown because sense of scale is important when making you model. This particular body has the same dimensions as if it was imported with Scale of 1. Designing you model in appropriate scale relative to the unscaled body will save you headache with scale factor and other nonsense.
Now it's time to export the hammer. I personally suggests using FBX , as this is format is the most compatible with Unity, it also supports weigh-painted meshes and animation. It is also a scene format, meaning you can export whole scenes into a single file. Do note, the FBX import-export is a plugin that is shipped with Blender, but not enabled by default, so you have to manually enable it.
When export FBX for unity, it is important to set proper Scalings on export, otherwise the scale in Unity is bound to be off. The settings shown result in model that is 1x1x1 Blender unit, to be 1x1x1 Meter in Unity. Which is as convenient as it can get.
Boot up Unity 5.6.4 editor and create project, if you don't have any. Simply drop FBX file into Assets folder, to make Unity import it. Once imported, drag imported FBX into hierarchy window in order to place it into the scene without adding any transformation to it.
Once it in the scene,you can proceed to make it pretty by setting up materials and other stuff you care about. Since it's going to be a Unity Asset, you can use ANY Unity shaders and other fancy things (like fancy-ass Uber-realistic PBR shaders, Animation, Particle systems etc.) that free version of Unity editor allows you to put inside a prefab. For sake of tutorial I'm going with Standard shader. Once you've done with the looks, Take your object from hierarchy and drag it back into a folder to make a prefab of it.
Now with prefab selected, assign it to an Asset Bundle int the Bottom Right screen. Now that you have an Asset Bundle Created with a prefab assigned to it, now is the time build it. For reasons I'm yet to grasp, this can only be done by means of the script. Create a folder inside the Assets, called Editor. Then inside Editor folder create a C# Script and name it whatever you want. Lets ignore the fact that C# is not a scripting language... Open the the created.cs file and paste the following code into it
using UnityEditor;
public class CreateAssetBundles
{
[MenuItem("Assets/Build Bundle")]
static void BuildAllAssetBundles()
{
string assetBundleDirectory = "Assets/Bundles";
BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
}
}
The way this thing works, is that it'll add Build Bundle prompt under Assets and Right click menu for assets. The button initiates Unity Editors BuildPipeline.BuildAssetBundles() method which will build a bundle and place it at a path specified in assetBundleDirectory string. The path is relative to projects folder. Do note, the the specified path must exist, or script will spit an error. Of course, you can add the code that would create folder if it doesn't exist, but it's up to you.
Save the script file and right click on your prefab:
Wait till it's done, and navigate to the folder you've specified in assetBundleDirectory. Since I've placed into the folder that is inside Assets folder, i can use Show In Explorer button, that Unity explorer has for quick access.
In addition to your bundle that script will also generated 3 files with extensions .meta .manifest and .manifest.meta None of which you should care about, and the bundle itself will have no extension at all. Copy/move it to you Mod folder, and give it extension of .asset_bg
Now it's time to create a entry in phot_bg_object_list.nei in order to load out file into the game as background object. For that we're going to utilize nei append functionality of ModLoader that supports that particular .nei file. Using Sybaris Arc Editor export phot_bg_object_list.nei into Mod/PhotoBG_OBJ_NEI and name it according to ModLoader's specification. In this example I'm going with phot_bg_object_list_hammer.nei. Now it's time to edit the thing, using NEI editor within Sybaris Arc Editor:]
Since we don't need any of this entries, the fastest way to remove them is to Export the contents as .csv file, remove all EXCEPT first row, save and import edited .csv file into our .nei.
Now, add a new row and lets get to editing:
1 - is the ID assigned to the object, which should be relevant but is not. So it can be any number or an empty cell
2 - is the category under which your object will appear
3 - is the name of the object as it'll appear in the game
4 - is the name of referenced prefab or asset_bg file without extension.
And the last row should be left empty as it's a way for KISS to disable objects if the user doesn't have proper DLC installed. Note Newer versions of this files (since game version 1.13 or maybe a bit earlier) has 4th column split into 2 with one dedicated to prefabs and the other is for .asset_bg files, however ModLoader makes either choice valid.
Once you're done, boot the game and have fun with it: