| Lesson #9
Using thinEdge models
This lesson will make you familiar with loading and displaying M15 models using thinBASIC
Please welcome to lesson 9! Starting from TBGL module v0.1.7 you can load and view thinEdge models using built in functions.
This is allows to let all the graphic work on a slave ... err friend or hired artist. And you, as a coder can just do what you need with them.
All TBGL commands related to M15 model handling are in format TBGL_m15<NameHere>.
The first of them you should call is TBGL_m15InitModelBuffers
This function is defined as follows:
This is quite self explanatory, but just for make sure you understood it well...
First parameter, NumberOfModels, specifies how many models will you use at maximum in your script. There is no limit on this value.
Second parameter, MaxVertices, contains maximum number of vertices used in any of the used models. It is nonsense to dim it for 25000, if your game character has only 1000 for example.
How could you get the number of vertices ? You can find it out in thinEdge program setup / Informational tab. Or you can open the files using Notepad and watch second line where should be something like "VERTEXNUM,1704". The number is info about vertices used.
Now, when you have model buffer dimensioned, starts the easy stuff!
To load thinEdge model you use function:
First two parameters are easy again - you specify target file and directory, where textures are stored.
ModelID is index of model, you will possibly use it for later model call.
targetDisplayList is optional field. If you specify zero, no display list will be created. Else, it will be created under number you specified.
NormalsCalculation can take 2 values.
%TBGL_NORMAL_PRECISE will produce same calculations as thinEdge does. It is ideal for furniture, machines, house models and so on...
%TBGL_NORMAL_SMOOTH is another beast. It will find points shared across multiple polygons and then interpolate final normal vector. This is lmost obligatory for models created using "Create rotated shape" tool. The model will result smoother than it is. So you can create quite low poly rotated models in thinEdge, and the simulate higher detail using this trick.
If you created game with multiple level and each level uses different models, you can erase models, which you no longer use:
This will erase any data attached to this model and you can load this position with new model without any problems.
And now comes the most important part - bringing models to your script render.
If you've choosen to create display list when loading the file, you should definitely use classic:
It is fastest, reliable and easy.
If you want to work with model, which has some parts changing ( color, animation ... ) you must use:
Of course, this TBGL command is highly optimized and for example autodetects status of texture mapping. If it is disabled, it will be enabled just for drawing the model, and then it will set the original status again. Simply drawing models does not have any undesirable side effects on your rendering.
This advantage is completely lost when you are using display list!
That's for this time all you need to know. Hope you get it well, if not, please ask about it on the forum.
Next tutorial will let you understand animation of thinEdge models from within the script. Quite complex topic, so get your brains ready !
© Petr Schreiber, 2006