Saturday August 15, 2020
 home | about | contact | Donations
 3D Formats Where else are you going to keep your 3D data?...

3DS Part 5- "storing xyz!" - Working Loader

by bkenwright@xbdev.net

<code v8>

Well we can now load all our 3D data in, and it will be all nice and safe in our data containers.  Data containers?...let me show you how and why....

Also note, I put our definition for our data structures in a file called data.h, so it doesn't make our code all messy :)

 /***************************************************************************/ /*                                                                         */ /* File:  data.h                                                           */ /* Author bkenwright@xbdev.net                                             */ /*                                                                         */ /***************************************************************************/   // Well we need to load in and store our 3D file information, so we need to // define some structures to put them in.   // Now the tricky thing to remember is that we could have multiple objects, // so our data structure could grow dynamically as where loading.   // Our only solution is linked lists... now we could write our own, or use // the STL libraries.  I've chosen to use the STL libraries...but you could // always work around them.   #include using namespace std ;   // Its a beautiful thing the STL...its really easy to use and understand // <1> you declare it at the top ..then /* Its like using an array... so for example you'd do vector pOurVector;   When you want to add a new int to your array of int's you'd do int pp = 2; pOurVector->push_back(pp); To use our array vector, we use it like do an array pOurVector[0] = 2; When we've finished with it, we can just delete it. delete[] pOurVector */ struct stMaterial {       char szName[256];       struct{ unsigned char r,g,b ; }Colour;       char szTextureFile[256]; };   struct stVert {       float x, y, z; }; struct stFace {   // 3 Sides of a triangle make a face.       unsigned int A, B, C;       int MaterialID; }; struct stTex {       float tu, tv; };   struct stMesh {       char         szMeshName[256];       int          iNumVerts;       stVert*      pVerts;       int          iNumFaces;       stFace*      pFaces;       stTex*       pTexs;         stMesh()       {             iNumVerts  = 0;             pVerts     = NULL;             iNumFaces  = 0;             pFaces     = NULL;             pTexs      = NULL;       }       };   struct stObject {       int                iNumMeshs;       vector     pMeshs;         int                iNumMaterials;       vector pMaterials;         stObject()       {             iNumMeshs     = 0;             iNumMaterials = 0;       }; };

Well the code is C - function depended at present...which means that we havn't used any fancy C++ objects or classes yet...just incase your not to good with object orientated programming.  But hold on...we will be going down that road eventually.

And of course the we have created an output file, which verifies our data.

 ================================================================ Shape: Box03 iNumFaces: 12              0,         2          3              3,         1          0              4,         5          7              7,         6          4              8,         9          10              11,       12        13              14,       15        16              17,       18        19              20,       21        22              23,       24        25              26,       27        28              29,       30        31 iNumVertices: 32              -6.79,  -2.30    0.00              -2.93,  -2.30    0.00              -6.79,  5.29     0.00              -2.93,  5.29     0.00              -6.79,  -2.30    4.13              -2.93,  -2.30    4.13              -6.79,  5.29     4.13              -2.93,  5.29     4.13              -6.79,  -2.30    0.00              -2.93,  -2.30    0.00              -2.93,  -2.30    4.13              -2.93,  -2.30    4.13              -6.79,  -2.30    4.13              -6.79,  -2.30    0.00              -2.93,  -2.30    0.00              -2.93,  5.29     0.00              -2.93,  5.29     4.13              -2.93,  5.29     4.13              -2.93,  -2.30    4.13              -2.93,  -2.30    0.00              -2.93,  5.29     0.00              -6.79,  5.29     0.00              -6.79,  5.29     4.13              -6.79,  5.29     4.13              -2.93,  5.29     4.13              -2.93,  5.29     0.00              -6.79,  5.29     0.00              -6.79,  -2.30    0.00              -6.79,  -2.30    4.13              -6.79,  -2.30    4.13              -6.79,  5.29     4.13              -6.79,  5.29     0.00 iNumTex: 32              1.00,    0.00              0.00,    0.00              1.00,    1.00              0.00,    1.00              0.00,    0.00              1.00,    0.00              0.00,    1.00              1.00,    1.00              0.00,    0.00              1.00,    0.00              1.00,    1.00              1.00,    1.00              0.00,    1.00              0.00,    0.00              0.00,    0.00              1.00,    0.00              1.00,    1.00              1.00,    1.00              0.00,    1.00              0.00,    0.00              0.00,    0.00              1.00,    0.00              1.00,    1.00              1.00,    1.00              0.00,    1.00              0.00,    0.00              0.00,    0.00              1.00,    0.00              1.00,    1.00              1.00,    1.00              0.00,    1.00              0.00,    0.00 Material vs Faces: 12              MaterialID: 0   , Name: 8 - Default              MaterialID: 0   , Name: 8 - Default              MaterialID: 0   , Name: 8 - Default              MaterialID: 0   , Name: 8 - Default              MaterialID: 0   , Name: 8 - Default              MaterialID: 0   , Name: 8 - Default              MaterialID: 0   , Name: 8 - Default              MaterialID: 0   , Name: 8 - Default              MaterialID: 0   , Name: 8 - Default              MaterialID: 0   , Name: 8 - Default              MaterialID: 0   , Name: 8 - Default              MaterialID: 0   , Name: 8 - Default

 Visitor: 9534626 { 229.27.38.75 } Copyright (c) 2002-2020 xbdev.net - All rights reserved. Designated articles, tutorials and software are the property of their respective owners.