Sample Project - Mesh export (3DS MAX)

This chapter explains how to get a mesh from 3DS MAX into N3D format. As already stated in the Mesh Conversion Tool (ogre2n3d.exe) document, the N3D Mesh Converter works only with the Ogre3D XML format.

You need an export plug-in for 3DS MAX. I use the OgreMax Scene Exporter for this task. Once installed, you find an menu entry called "OgreMax" in the main menu, that you can use to export your scene:

3dsmax.png

Click "Export Selected" or "Export Scene", save the scene into "OgreMax Scene (*.SCENE)" format and then browse to the export folder.

You should find *.scene, *.material, *.mesh and also *.mesh.xml files. The .mesh.xml file is the one we want! Lets open a command-promt and convert the mesh into N3D format. To convert the mesh, we use the following command line:

ogre2n3d.exe "TorusKnot01.mesh.xml"
The directory in which ogre2n3d.exe is located needs to be added to the PATH environment variable, otherwise specify the full path to ogre2n3d.exe. Please note you should not use filenames with spaces. The devkitARM toolchain seems to be allergic to filenames with spaces.

ogre2n3d_2.png

The ogre2n3d Mesh Converter creates a file called "TorusKnot01.n3dmesh.bin" in our example, which is the final format N3D requires. Copy the "TorusKnot01.n3dmesh.bin" file into your "data" directory from your project and devkitARM will automatically create a header and link the file the next time you build the project.

Building the "libn3d/samples/meshexport" project:

sampleproject_exportmesh_build.png

Testing the "libn3d/samples/meshexport" project in NO$GBA :

sampleproject_exportmesh.png

See also:
Mesh Conversion Tool (ogre2n3d.exe)
Sourcecode:
//
// N3D Mesh Export Sample (http:www.console-dev.de)
//
// Please refer to the N3D documentation, chapter "Mesh export (3DS MAX)"
//
#include <n3d.h>
#include <n3dsampleframework.h>
#include "TorusKnot01_n3dmesh_bin.h"

// Prototypes
void SetupMatrices();
void RenderScene(const N3DFLOAT _timeStep);

// The N3DDEVICE represents the interface to the Nintendo DS 3D hardware.
N3DDEVICE g_device;



// Program entry point
int main(void)
{
    // Initialize the hardware
    N3DSampleFrameworkInit();

    // Initialize the 3D device. This method must be called before using
    // anything else from the N3DDEVICE.
    g_device.Init();

    // Setup the projection and view matrix only once
    // at the beginning of the application.
    SetupMatrices();


    // Infinite loop to keep the application running.
    for(;;)
    {
        N3DFLOAT timeStep(1.0f / 60.0f);

        RenderScene(timeStep);

        N3DSampleFrameworkWaitForVBlank();
    }

    return 0;
}






void SetupMatrices()
{   
    // Build the projection matrix
    N3DMATRIX projMatrix;

    N3DMatrixPerspectiveFovLH(projMatrix, N3DFLOAT(N3DPI / 4.0f), N3DFLOAT(4.0f / 3.0f), N3DFLOAT(1.0f), N3DFLOAT(100.0f));
    g_device.SetTransform(N3DTS_PROJECTION, projMatrix);


    // Build the view matrix
    N3DMATRIX   viewMatrix;
    N3DVECTOR3  eye(N3DFLOAT(0), N3DFLOAT(0), N3DFLOAT(0));
    N3DVECTOR3  at(N3DFLOAT(0), N3DFLOAT(0), N3DFLOAT(4));
    N3DVECTOR3  up(N3DFLOAT(0), N3DFLOAT(1), N3DFLOAT(0));

    N3DMatrixLookAtLH(viewMatrix, eye, at, up);
    g_device.SetTransform(N3DTS_VIEW, viewMatrix);
}






void RenderScene(const N3DFLOAT _timeStep)
{
    // Set the clear color and new depth value, then start the new scene.
    g_device.Clear(N3DCLEAR_TARGET | N3DCLEAR_DEPTH, N3DCOLOR(0, 0, 0.8f), N3DFLOAT(1.0f));
    g_device.BeginScene();

    // Setup a light source. Lights in N3D are always directional
    // lights with an infinite distance.
    N3DLIGHT light;

    // Set the light color to white
    light.color.r= N3DFLOAT(1.0f);
    light.color.g= N3DFLOAT(1.0f);
    light.color.b= N3DFLOAT(1.0f);

    // Point into the scene
    light.direction.x = N3DFLOAT(0);
    light.direction.y = N3DFLOAT(0);
    light.direction.z = N3DFLOAT(1);

    g_device.SetLight(0, light);
    g_device.LightEnable(0, true);


    // Setup a material
    N3DMATERIAL material;

    material.ambient.r = N3DFLOAT(0.2f);
    material.ambient.g = N3DFLOAT(0.2f);
    material.ambient.b = N3DFLOAT(0.2f);

    material.diffuse.r = N3DFLOAT(0.4f);
    material.diffuse.g = N3DFLOAT(0.4f);
    material.diffuse.b = N3DFLOAT(0.6f);

    material.specular.r = N3DFLOAT(0.7f);
    material.specular.g = N3DFLOAT(0.7f);
    material.specular.b = N3DFLOAT(1.0f);

    material.emissive.r = N3DFLOAT(0.0f);
    material.emissive.g = N3DFLOAT(0.0f);
    material.emissive.b = N3DFLOAT(0.0f);

    // completely opaque
    material.alpha = N3DFLOAT(1);

    g_device.SetMaterial(material);


    // Transform and draw geometry.
    // Let the object rotate around its own Y-axis and move it
    // 3 units into the scene.
    N3DMATRIX transMatrix;
    N3DMATRIX rotationMatrix;
    N3DMATRIX worldMatrix;
    static N3DFLOAT angle(0);

    angle += _timeStep * N3DFLOAT(22.5f);
    N3DMatrixRotationY(rotationMatrix, DegreeToRadian(angle));
    N3DMatrixTranslation(transMatrix, N3DFLOAT(0), N3DFLOAT(0), N3DFLOAT(2));
    N3DMatrixMultiply(worldMatrix, rotationMatrix, transMatrix);

    g_device.SetTransform(N3DTS_WORLD, worldMatrix);

    N3DCMDSTREAM* pCmdStream = (N3DCMDSTREAM*)TorusKnot01_n3dmesh_bin;
    g_device.DrawPrimitive(*pCmdStream);


    // End the scene and present it.
    g_device.EndScene();
    g_device.Present();
}

Generated on Wed Aug 29 19:48:04 2007 for N3D by  doxygen 1.5.3