Creating a Model

From C4 Engine Wiki

Jump to: navigation, search

The C4 Engine stores information about a scene or a model in its own file format. A world containing all of the scene data for an entire level is stored in a file with the extension .wld, and the data for a single model is stored in a file with the extension .mdl. The formats of these two file types are nearly identical. The only difference between them is that a world's root node is an infinite zone, and a model's root node is a model.

Contents

Dynamic vs Static Models in C4

Note that models (.mdl files) should only be used for models that are dynamic (ie. will 'move') - such as characters or vehicles. For static models such as furniture, rocks, trees etc, referenced worlds should be used. These are basically 'prefabs' and are simply small world files (saved as .wld) separately built, and placed into larger world "levels" etc wherever needed.

Importing Scene Data

Scene data stored in the Collada format can be imported by the C4 Engine inside the World Editor. Collada files, having the .dae extension, should be placed somewhere inside a sub-directory of the Import/ directory (but not at the top level of the Import/ directory). A Collada file can be imported into the World Editor by choosing World > Import Scene. A list of files and sub-directories in the Import/ directory will then appear. After selecting a Collada file, the imported geometry (as well as any lights and materials) will appear in the World Editor. At this point, you may make any changes that you need to.

During the import process, the World Editor will keep track of the materials used by the imported geometry. The texture maps are correctly assigned to each geometry, and the Collada importer will attempt to import texture images with the default settings if you tell it to. Texture images can be imported manually using the Texture Importer tool.

Also, if a node's name starts with the prefix "MARKER_", then it will be imported as a marker node.

Exporting Models

A model (.mdl) resource is created by saving a scene as a model in the World Editor. Once the model has been prepared in the World Editor, it is exported by choosing World > Save As Model. A dialog will then appear that lets you name the exported model. (You may also save the model as a world file for later use if you'd like.)

Here are the steps:

  1. Export your model (with skinned info and animation) to the Collada format from your favorite 3D authoring tool.
  2. Put the Collada .dae file in a sub-directory of the Import directory (not at the top level of the Import directory).
  3. Launch C4, and create a new world by choosing Tools > New World (Cmd-N/Ctrl-N).
  4. Choose World > Import Scene, and select the Collada file you just exported from the 3D authoring tool.
  5. Now you should see your model in the World Editor.
  6. If you are making a character model that will use physics, you need to add a physics shape from the 'Physics' panel to your model (eg. Box Shape), as a child of the Infinite Zone. Size it to approximate your character - it should just touch the ground. Be sure to open its Node Info window (Ctrl+I) and tick "Do not apply model animation" under the Node tab. Also under the Shape tab set the Shape Density. This you can calculate by dividing the estimated body mass of your character(in tons) by the physic shape's volume (which is displayed as V=... m³) alongside the density for you. See Physics wiki page for more info.
  7. Fix up the materials, if necessary, and then choose World > Save as Model.
  8. Now open the Model Viewer by choosing Tools > Open Model. Select the .mdl file you just saved in the previous step.
  9. To import animation, follow these additional steps:
    1. Click the Import button under the Animation list on the left side of the Model Viewer window.
    2. Select the same Collada file you just used to import the model. This time the animation data will be imported instead.
    3. Select the new animation in the list, and click the Play button. Your animation should now play.
    4. Import additional animations by first saving them as separate Collada files (from your 3D authoring tool) in the same sub-directory of the Import directory.

Using the Model Viewer

Any model for which a .mdl resource has been created can be opened in the Model Viewer tool. To open a model, either choose Tools > Open Model or type model <name> in the command console.

On the left side of the Model Viewer window, there is a list of animations that can be played for the model. Animation resources should be stored in the same location as the model resource to which they pertain. For example, if a model is named Data/game/vampire/Vampire.mdl, then its animations should be stored in the Data/game/vampire/ directory. Clicking on any animation in the list immediately assigns that animation to the model being viewed. The animation can be played using the controls at the bottom of the window.

A new animation can be imported by clicking the Import button just below the animation list. You will then see a list of files in the Import directory. If an existing animation is re-imported, then the old animation file in the Data/ directory is overwritten.

Personal tools