Custom object
This page describes how to create a custom object with custom 3D model and custom behavior for Super Mario 64.
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.
Choose a group name you want to add your actor to, such as common0.
Choose a unique folder name. It's recommended to add the word custom to the name, for example custom_platform.
Choose a unique geolayout name, 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).
Collision data
If the object shall become a solid object, such as a moving platform, you also need to export the collision data. Expand SM64 Collision Exporter for that and select C.
Export type is Actor Data. For the name, you should use the same you previously chose for the folder, such as custom_platform. The group name should also be the same as above.
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.inc.c and include this in data/behavior_data.c. Also add your new behavior name to 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. Example:
1 // original yellow coin (for reference)
2 const BehaviorScript bhvYellowCoin[] = {
3 BEGIN(OBJ_LIST_LEVEL),
4 BILLBOARD(),
5 OR_INT(oFlags, (OBJ_FLAG_COMPUTE_DIST_TO_MARIO | OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE)),
6 CALL_NATIVE(bhv_yellow_coin_init), // defined in src/game/behaviors/coin.inc.c
7 BEGIN_LOOP(),
8 CALL_NATIVE(bhv_yellow_coin_loop), // defined in src/game/behaviors/coin.inc.c
9 END_LOOP(),
10 };
11
12 // your own copy
13 const BehaviorScript bhvCustomCoin[] = {
14 BEGIN(OBJ_LIST_LEVEL),
15 BILLBOARD(),
16 OR_INT(oFlags, (OBJ_FLAG_COMPUTE_DIST_TO_MARIO | OBJ_FLAG_UPDATE_GFX_POS_AND_ANGLE)),
17 CALL_NATIVE(bhv_custom_coin_init), // define your own in src/game/behaviors/custom_coin.inc.c
18 BEGIN_LOOP(),
19 CALL_NATIVE(bhv_custom_coin_loop), // define your own in src/game/behaviors/custom_coin.inc.c
20 END_LOOP(),
21 };
Solid object
If the object shall be a solid object, such as a moving platform, the collision data must also be loaded in the script. Call LOAD_COLLISION_DATA(custom_platform_collision)
before initialization and CALL_NATIVE(load_object_collision_model)
at the end inside the loop.
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.