.3ds
binary file format to BRender .dat
format. Type 3DS2BR, followed by return, to display a list of 3DS2BR command line options. The steps involved in converting a .3ds
file are detailed below. This example converts the model description file duck.3ds
, supplied with 3D Studio (and included on the Tutorial Programs disk for your convenience) to BRender format. duck.3ds
describes a three component model hierarchy - a yellow duck body with two black eyes. The command line,
3DS2BR duck.3ds -nomatrix -mod duck.dat -scr duck.matextracts information describing model geometry and stores it in
duck.dat
. Material descriptions are stored in the script file duck.mat
(the -nomatrix
option ensures that inverse mesh matrices are not applied - see Chapter 8 for more information on 3DS2BR). Enter the following command line,
geoconv duck.dat -lto display information on the newly created file
duck.dat
. The following listing should be displayed:
GEOCONV 1.21 Copyright (C) 1994-1995 by Argonaut Technologies Limited Models: 3This listing tells us that three models are combined to build the model described in
Materials: 2 BLACK PLASTIC YELLOW PLASTIC
duck.dat
- one model describes the duck's body, the other two its eyes.
The following command line collapses the model hierarchy described in duck.dat
into a single model. This model is then translated to the origin and scaled to fit within a sphere of radius 1.
If you again enter geoconv duck.dat -l
the following listing will be displayed,
GEOCONV 1.21 Copyright (C) 1994-1995 by Argonaut Technologies Limited Models: 1
Materials: 2 BLACK PLASTIC YELLOW PLASTIC
duck.dat
now describes a single model of radius 1 (0.9999). Note that material associations are retained.
To recap: the following command lines were used to import the 3D Studio .3ds
model description file.
3DS2BR duck.3ds -nomatrix -mod duck.dat -scr duck.mat geoconv duck.dat -m -c -n -o duck.datTwo output files were created -
duck.dat
to store model geometry, duck.mat
to store material descriptions. The model hierarchy described in duck.dat
was collapsed into a single model. This model was then translated to the origin before being normalised to a radius of 1.
The imported `duck' model is used in BRTUTOR7.C
. Note that associated materials must be loaded and registered before the model is loaded (otherwise it will appear matt grey). If associated materials are not found in the registry when a model is loaded the default material is used. The application may then assign any registered material to the model.
The following code loads materials from the script file duck.mat
, and adds them to the registry.
i = BrFmtScriptMaterialLoadMany("duck.mat",mats,BR_ASIZE(mats)); BrMaterialAddMany(mats,i);
BrFmtScriptMaterialLoadMany
and BrMaterialAddMany
are called because more than one material is being loaded and registered. The macro BR_ASIZE
(defined in header file compiler.h
) calculates the size of an array. BrFmtScriptMaterialLoadMany
returns the number of materials successfully loaded.
duck = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL)); duck->model = BrModelLoad("duck.dat"); BrModelAdd(duck->model);The material script file
duck.mat
is listed below.
duck.mat
# BRender Material Script material = [ identifier = "BLACK PLASTIC"; flags = [light,smooth]; colour = [0,0,0]; ambient = 0.000000; diffuse = 0.000000; specular = 1.000000; power = 69.309998; ]; material = [ identifier = "YELLOW PLASTIC"; flags = [light,smooth]; colour = [202,179,52]; ambient = 0.679216; diffuse = 0.679216; specular 0.741569; power = 23.770000; ];
YELLOW PLASTIC
is used for the duck body, BLACK PLASTIC
for the eyes. Note that the above material description will only work in true- colour mode. In 8-bit indexed mode, the colour
field is ignored. Instead, BRender looks for an index into a colour palette. We will need to edit the script file if we want to use the duck model in 8-bit mode. In the palette provided with BRender (std.pal
), the `yellow' colour ramp ranges from index 224 (yellow so dark it's black) to index 255 (yellow so bright it's white). Try editing duck.mat
as follows, and running the program in 8-bit indexed mode (simply pass NULL to DOSfxBegin instead of "VESA,W:320,H:200,B:15").
duck.mat
# BRender Material Script # material = [ identifier = "BLACK PLASTIC"; flags = [light,smooth]; colour = [0,0,0]; ambient = 0.000000; diffuse = 0.000000; specular = 1.000000; power = 69.309998; index_base = 0; index_range = 0; ]; material = [ identifier = "YELLOW PLASTIC"; flags = [light,smooth]; colour = [202,179,52]; ambient = 0.679216; diffuse = 0.679216; specular 0.741569; power = 23.770000; index_base = 224; index_range = 24; ];
BRTUTOR7.C
/* * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved. * Program to Display a Revolving Yellow Duck. */ #include <stddef.h> #include <stdio.h> #include "brender.h" #include "dosio.h" int main(int argc, char **argv) { br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette; br_actor *world, *observer, *duck; int i; br_material *mats[10]; /*for storing pointers to material descriptions*/ /********* Initialise BRender and Graphics Hardware ***********/ BrBegin(); /* * Initialise screen buffer and set up CLUT (ignored in true colour) */ . . . . . . . . . . . . . . . . . . BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16); back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN); depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16); /*************** Build the World Database **********************/ world = BrActorAllocate(BR_ACTOR_NONE,NULL); BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL))); /* * Load and Position Camera */ observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL)); observer->t.type = BR_TRANSFORM_MATRIX34; BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), BR_SCALAR(5.0)); /* * Load and Apply Duck Materials */ i = BrFmtScriptMaterialLoadMany("duck.mat",mats,BR_ASIZE(mats)); BrMaterialAddMany(mats,i); /* * Load and Position Duck Model */ duck = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL)); duck->model = BrModelLoad("duck.dat"); BrModelAdd(duck->model); duck->t.type = BR_TRANSFORM_MATRIX34; BrMatrix34RotateX(&duck->t.t.mat,BR_ANGLE_DEG(30)); /********************** Animation Loop ***********************/ for(i=0; i < 200; i++) { BrPixelmapFill(back_buffer,0); BrPixelmapFill(depth_buffer,0xFFFFFFFF); BrZbSceneRender(world,observer,back_buffer,depth_buffer); BrPixelmapDoubleBuffer(screen_buffer,back_buffer); BrMatrix34PostRotateX(&duck->t.t.mat,BR_ANGLE_DEG(2.0)); } /* * Close down */ BrPixelmapFree(depth_buffer); BrPixelmapFree(back_buffer); BrZbEnd(); . . . . . . . . . . . . . . . . . . BrEnd(); return 0; }
BRTUTOR7.C