Importing 3d objects into the DC
|I have been playing around with making video games on the Dreamcast. I wanted a way to create and import 3d models into the Dreamcast. I ended up writing my own export script for the Open Source 3D modelling program "Blender". Also, I wrote c++ class to import the 3d model into the Sega Dreamcast using KallistiOS and the KGL libraries (KGL provides very basic OpenGL functionality). This page provides some source code and my export script that could hopefully be useful for other people looking to do the same thing.|
Why the Dreamcast?
The Sega Dreamcast has excellent Open Source tools for developing games on the system. The existence of KallistiOS and the gcc compiler for the Dreamcast mean that I can create whatever games I can dream up without worrying too much about licensing Official Dev Kit platforms that are generally reserved for big video game companies. The Dreamcast is great for this purpose because it can run the games off an ordinary CD-ROM without the use of a mod chip, so I can hand the game to my friends and they can play it.
I'm just getting started with 3-d modelling. I tried a few different pieces of software (Wings-3D, Maya educational version) before commiting to Blender. Blender was intimidating to me at first because when I loaded it up, I didn't intuitively know what do to. However, once I decided to give Blender a chance, it turned out to be really easy to work with, you just gotta go through a few quick tutorials first.
I took a Blender VRML '97 export script (written by Rick Kimball, Ken Miller, Steve Matthews, and Bart) and transformed it into something that exports a model into my own format. VRML had a lot of the features that I wanted, but I didn't have a good way of parsing the VRML file into the Dreamcast, so I wanted a binary format. It would probably be better to have learned an existing format and loaded that instead of creating my own, but for now this was the easiest way for me to get started. Here are the features that the script supports:
- The script exports a UV-textured 3d model, with some support for animations.
- The script exports to Jake Format (.jfm), my own simple format.
- Multiple Blender objects can be exported together into a single .jfm file.
I'm using Cryptic Allusions' KallistiOS KGL library to display the 3D image. The texture is loaded as an indexed 256-color .pcx file that I created using the Gimp. The program loads the .jfm file and the .pcx texture, and displays the animation. You can rotate the model using the analog stick. The code is suprisingly brief and clean, so it should be easy to understand and learn from.
The program also can be compiled for Linux using the Glut library. On my system, "make linux" builds the a.out executable for me. I'm using David Henry's pcx.c pcx file importer to load the textures. You can rotate the model using the mouse.
Other operating systems
It should be easy to compile the code for other systems that have the glut library. It should hopefully compile much like the Linux version. If you get it working on another operating system and you want to send me the result, I'd be glad to post it here.
Here is a brief description of the important files:
|blender/jakeformat.py||The .jfm (Jake format) export script. Under linux, I put this file in my home directory under ".blender/scripts", and Blender added .jfm as an export menu option.|
|blender/dreamcast.blend||Blender object file. Load blender, and open this file. It's a model of a Sega Dreamcast. Alt-A should show the animation. File-Export->Jake Format (.jfm) will export the file.|
|blender/dreamcast.jpg||The texture file for the blender model.|
|kglgame/kglgame.cc||The main program file. This mostly just sets up the opengl stuff, and calls on the object3d object to load and display.|
|kglgame/Makefile||You may have to edit this file a little to compile for your system. Some good commands to use are "make" to build the dc elf, and "make linux" to create a linux "a.out" executable.|
|kglgame/drawables/object3d.cc||This does the loading and displaying of the .jfm file.|
|kglgame/romdisk/dreamcast.jfm||This is the exported Dreamcast animation that gets displayed by the program.|
|kglgame/romdisk/dreamcast.pcx||This is the texture image that gets loaded by the program to go with the .jfm file.|
|kglgame/a.out||A linux executable. This requires the romdisk/ folder to be in the same directory as a.out.|
|kglgame/kglgame.elf||A Dreamcast .elf file. This file contains all the data, so the romdisk folder is not required in this case. Just upload kglgame.elf to the dreamcast and run it to see the animated Dreamcast display.|
Here are the versions of the different programs that I created this stuff with:
Blender 3D: Noob to Pro - Great place to get started working in Blender
Texturing a Castle Tutorial - Learn Blender UV Texture Mapping
Elephants Dream - a cool animated feature made using Blender.