How to build a simple 3D model viewer on Ubuntu 12.10

by Carson Reynolds

Suppose you want to cook up something to view 3D models for animation, solids modeling, and suchlike. Blender does the job but it has so many bells and whistles included that it makes a poor choice to add into your own C codebase. Thankfully the folks over at lib3ds have a nice library which can render files using Audiodesk’s 3D-Studio .3ds format. This tutorial explains how to build and run their sample code.

The first step would be to install a minimal set of compiler tools for C on Ubuntu using the terminal:

sudo apt-get install build-essential

From there you can install lib3ds-dev which will give you the shared object and header files necessary to build lib3ds code.

sudo apt-get install lib3ds-dev

After that you should decompress the example code into a directory. For instance:

cd $HOME/Desktop
mkdir 3dsplay
cd 3dsplay
gzip -d < /usr/share/doc/lib3ds-dev/examples/3dsplay.c.gz \
> 3dsplay.c

Next you can use a Makefile I wrote to build the example.

sudo apt-get install wget
wget http://bit.ly/Va0mQa
sudo apt-get install freeglut3-dev
make

You ought to be able at this point (if there were no problems) to load up a .3ds file and view it in a window.

wget http://bit.ly/Uxdphy
./3dsplay perfectcube.3ds

Here’s what I see on my display after all that:

Image

Also the previously mentioned Blender can export a variety of 3D file formats to .3ds. For example, you can grab one of .blend files from this collection to get a few more examples to play.

Advertisements