User Tools

Site Tools


super_mario_64:custom_object

Custom object (decomp)

This page describes how to create a custom object with custom 3D model and custom behavior using the Super Mario 64 decompilation project.

Export 3D model (Fast64)

In Blender, install the Fast64 plugin, select your object you want to export, open the Fast64 menu and expand SM64 Geolayout Exporter. Ensure to select C as the export.

Choose Actor Data as the export type and provide a group name such as common0. The exported model requires a unique folder name such as custom_platform. For the geolayout name, it's advised to use the same as the folder name and “_geo” appended, such as custom_platform_geo.

Ensure the newly created model.inc.c file is included in actors/<group>.c file, such as in actors/common0.c (should be done by Fast64 exporter).

Ensure the newly created geo_header.h file is included in actors/<group>.h file, such as in actors/common0.h (should be done by Fast64 exporter).

Ensure the newly created geo.inc.c file is included in actors/<group>_geo.c file, such as in actors/common0_geo.c (should be done by Fast64 exporter).

Load custom model

It's a good idea to give your 3D model a unique name, such as MODEL_CUSTOM_COIN, and an ID from 0x00 to 0xFF. Define it in include/model_ids.h. Ensure it does not share an ID with another model that might be loaded in the same level.

In your level script file (such as levels/bob/script.c) or in a global script located in levels/scripts.c, add a LOAD_MODEL_FROM_GEO command, such as LOAD_MODEL_FROM_GEO(MODEL_CUSTOM_COIN, custom_coin_geo).

Create behavior script

Open data/behavior_data.c in your favorite code editor. You may want to add a dedicated file, such as data/custom_coin.c (it is automatically found and included by the Makefile). Also add your new behavior name as a declaration in a header file, such as in include/behavior_data.h.

The easiest way to create your own behavior script is to copy an existing one that's most closely to what you want. Copy the related lines and rename the variable accordingly.

Create native code

If you need new native C code, create a new code file in src/game/behaviors, such as src/game/behaviors/custom_coin.inc.c, and include that file in src/game/obj_behaviors.c. You might want to copy an existing behavior code for reference. However, make sure all variables and function names are unique in the source code. For example, rename bhv_yelow_coin_loop to bhv_custom_coin_loop. Declare your custom functions in a suitable header file, such as in src/game/obj_behaviors.h or src/game/behavior_actions.h.

Add object to level (Fast64)

In your level inside Blender, add an Empty. Set object type to Object.

Set model to Custom and model ID to your defined ID from include/model_ids.h, such as MODEL_CUSTOM_COIN.

Set behavior to Custom and behavior name to your defined name in data/behavior_data.c, such as bhvCustomCoin.

super_mario_64/custom_object.txt · Last modified: 2020/11/05 17:44 by Tenry