Creating 3D model assets
Following steps describe how to create a 3D model template that is very beneficial in creation of 3D models of buildings.
- Define a layout entity in your mod with desired layout specified using ASCII (see
ExampleMachineData.cs). - Set prefab path to
"TODO"since we don't have a prefab yet. - Compile and deploy the mod.
- Launch game with the newly created machine and run console command
generate_layout_entity_mesh_templatefollowed by your entity ID. This will generate an OBJ file in%APPDATA%/Captain of Industry/Misc/GeneratedMeshTemplateswhich represents a 3D bounding box of layout of your new entity with exact port locations. - If you don't have a 3D model, load the newly created template model to a 3D editor of your choice and create 3D model that fits it. If you already have a 3D model, you can compare it to the generated template and edit the ASCII layout accordingly.
- When 3D model is complete, export FBX or OBJ and follow the next steps.
Following steps describe how to package a 3D model.
- We recommend organizing assets in directories. Under the
Assetsdirectory create<mod name>/<model name>directory, in our case that isExampleMod/ExampleModel. - Import 3D model files (OBJ, FBX, etc.) and textures (PNG, JPG, etc.) to the model directory. You can simply use drag & drop. Creating a separate folder for each asset is recommended.
- Drag the 3D model from Project pane to the Unity scene. Reset its position and rotation to all zeros using Inspector (you can use the three dots menu next to transform) and make it look as you want (add materials, etc.). Note: it is important that your asset has zero position and rotation. If you need to reposition it, change the 3D model or make a child object that can be moved.
- Create a prefab by dragging the root object and dropping it to the project pane. This will make a new
.prefabfile. In our example we created the prefab in the<mod name>directory. - Assign the newly created prefab to any asset bundle from the drop-down menu on the bottom of the Inspector tab. You can create a new temporary bundle called
asdfor pick any existing one. - To use prefabs in your mod, simply right-click any prefab and select
Copy Path. That path can be used to load your prefab in the game. - Follow steps under the Packaging asset bundles to package the created assets.