home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FAQSYS18.ZIP / FAQS.DAT / 3DS2.TXT < prev    next >
Text File  |  1996-08-18  |  56KB  |  1,862 lines

  1.  
  2.                           3D-Studio File Format (.3ds)
  3.                                  Autodesk Ltd.
  4.  
  5.    Document Revision 0.91 - June 1996
  6.  
  7.    Rewritten by Martin van Velsen (email: vvelsen@ronix.ptf.hro.nl )
  8.    and Robin Fercoq ( 3ds-bin + mli )(email: robin@msrwww.fc-net.fr)
  9.    Based on Original document by Jim Pitts ( email: jp5.ukc.ac.uk )
  10.  
  11.    A lot of the chunks are still undocumented if you know what they do
  12.    please email me Martin van Velsen,Robin Feroq or Jimm Pitts. 
  13.    As I get more information of the file format,I will document it for 
  14.    everyone to see. I will post this regurlarly to alt.3d and alt.3d-studio 
  15.    and I can be contacted there if my email does not work.
  16.  
  17.    Disclaimer.
  18.    This document describes the file format of the 3ds files generated by
  19.    3d-studio by Autodesk. By using the information contained within you agree
  20.    not to hold me Jim Pitts or Robin Feroq liable if, from its use, 
  21.    you f^Hmuck something up. OK?
  22.  
  23.  
  24.    A warning beforehand. This docs describes the format of 3ds files produced
  25.    by version 3.0 and higher of 3d-studio. You can find this information at
  26.    byte 29 in the binary file.
  27.  
  28.    This document can be found on the regular newsgroups:
  29.    alt.3d and alt.3d-studio
  30.    It can also be found at:
  31.       "http://www.ptf.hro.nl/odi/free-d/docs/io/3ds/3ds_bin.doc"
  32.    Or 
  33.       "http://www.mediatel.lu"
  34.  
  35.    The 3ds file format is made up of chunks. They describe what information
  36.    is to follow and what it is made up of, it's ID and the location of the
  37.    next block. IF you don't understand a chunk you can quite simply skip it.
  38.    The next chunk pointer is relative to the start of the current chunk and
  39.    in bytes. The binary information in the 3ds file is written in a special
  40.    kind of way. Namely the lest significant byte comes first in an int.
  41.    For example: 4A 5C  (2 bytes in hex) would be 5C high byte and 4A low byte. In a long it
  42.    is: 4A 5C 3B 8F where 5C4A is the low word and 8F 3B is the high word.
  43.    And now for the chunks. A chunk is defined as:
  44.  
  45.    start end size name
  46.    0     1   2    Chunk ID
  47.    2     5   4    Pointer to next chunk relative to the place where
  48.                   Chunk ID is, in other words the length of the chunk
  49.  
  50.    Chunks have a hierarchy imposed on them that is identified byt it's ID.
  51.    A 3ds file has the Primary chunk ID 4D4Dh. This is always the first
  52.    chunk of the file. Within the primary chunk are the main chunks.
  53.  
  54.    to give you a preview and a reference to the hierarchy of chunks, below is
  55.    a diagram to show the diffrent chunk ID's and their place in the file.
  56.    The chunks are given a name because below the diagram is a list which
  57.    defines the names to the actual chunk id's. This makes it easier to
  58.    put it in some source code ( how convenient that some sample code is
  59.    included )
  60.  
  61.                   MAIN3DS  (0x4D4D)
  62.                   |
  63.                   +--EDIT3DS  (0x3D3D)
  64.                   |  |
  65.                   |  +--EDIT_MATERIAL (0xAFFF)
  66.                   |  |  |
  67.                   |  |  +--MAT_NAME01 (0xA000) (See mli Doc) 
  68.                   |  |
  69.                   |  +--EDIT_CONFIG1  (0x0100)
  70.                   |  +--EDIT_CONFIG2  (0x3E3D) 
  71.                   |  +--EDIT_VIEW_P1  (0x7012)
  72.                   |  |  |
  73.                   |  |  +--TOP            (0x0001)
  74.                   |  |  +--BOTTOM         (0x0002)
  75.                   |  |  +--LEFT           (0x0003)
  76.                   |  |  +--RIGHT          (0x0004)
  77.                   |  |  +--FRONT          (0x0005) 
  78.                   |  |  +--BACK           (0x0006)
  79.                   |  |  +--USER           (0x0007)
  80.                   |  |  +--CAMERA         (0xFFFF)
  81.                   |  |  +--LIGHT          (0x0009)
  82.                   |  |  +--DISABLED       (0x0010)  
  83.                   |  |  +--BOGUS          (0x0011)
  84.                   |  |
  85.                   |  +--EDIT_VIEW_P2  (0x7011)
  86.                   |  |  |
  87.                   |  |  +--TOP            (0x0001)
  88.                   |  |  +--BOTTOM         (0x0002)
  89.                   |  |  +--LEFT           (0x0003)
  90.                   |  |  +--RIGHT          (0x0004)
  91.                   |  |  +--FRONT          (0x0005) 
  92.                   |  |  +--BACK           (0x0006)
  93.                   |  |  +--USER           (0x0007)
  94.                   |  |  +--CAMERA         (0xFFFF)
  95.                   |  |  +--LIGHT          (0x0009)
  96.                   |  |  +--DISABLED       (0x0010)  
  97.                   |  |  +--BOGUS          (0x0011)
  98.                   |  |
  99.                   |  +--EDIT_VIEW_P3  (0x7020)
  100.                   |  +--EDIT_VIEW1    (0x7001) 
  101.                   |  +--EDIT_BACKGR   (0x1200) 
  102.                   |  +--EDIT_AMBIENT  (0x2100)
  103.                   |  +--EDIT_OBJECT   (0x4000)
  104.                   |  |  |
  105.                   |  |  +--OBJ_TRIMESH   (0x4100)      
  106.                   |  |  |  |
  107.                   |  |  |  +--TRI_VERTEXL          (0x4110) 
  108.                   |  |  |  +--TRI_VERTEXOPTIONS    (0x4111)
  109.                   |  |  |  +--TRI_MAPPINGCOORS     (0x4140) 
  110.                   |  |  |  +--TRI_MAPPINGSTANDARD  (0x4170)
  111.                   |  |  |  +--TRI_FACEL1           (0x4120)
  112.                   |  |  |  |  |
  113.                   |  |  |  |  +--TRI_SMOOTH            (0x4150)   
  114.                   |  |  |  |  +--TRI_MATERIAL          (0x4130)
  115.                   |  |  |  |
  116.                   |  |  |  +--TRI_LOCAL            (0x4160)
  117.                   |  |  |  +--TRI_VISIBLE          (0x4165)
  118.                   |  |  |
  119.                   |  |  +--OBJ_LIGHT    (0x4600)
  120.                   |  |  |  |
  121.                   |  |  |  +--LIT_OFF              (0x4620)
  122.                   |  |  |  +--LIT_SPOT             (0x4610) 
  123.                   |  |  |  +--LIT_UNKNWN01         (0x465A) 
  124.                   |  |  | 
  125.                   |  |  +--OBJ_CAMERA   (0x4700)
  126.                   |  |  |  |
  127.                   |  |  |  +--CAM_UNKNWN01         (0x4710)
  128.                   |  |  |  +--CAM_UNKNWN02         (0x4720)  
  129.                   |  |  |
  130.                   |  |  +--OBJ_UNKNWN01 (0x4710)
  131.                   |  |  +--OBJ_UNKNWN02 (0x4720)
  132.                   |  |
  133.                   |  +--EDIT_UNKNW01  (0x1100)
  134.                   |  +--EDIT_UNKNW02  (0x1201) 
  135.                   |  +--EDIT_UNKNW03  (0x1300)
  136.                   |  +--EDIT_UNKNW04  (0x1400)
  137.                   |  +--EDIT_UNKNW05  (0x1420)
  138.                   |  +--EDIT_UNKNW06  (0x1450)
  139.                   |  +--EDIT_UNKNW07  (0x1500)
  140.                   |  +--EDIT_UNKNW08  (0x2200)
  141.                   |  +--EDIT_UNKNW09  (0x2201)
  142.                   |  +--EDIT_UNKNW10  (0x2210)
  143.                   |  +--EDIT_UNKNW11  (0x2300)
  144.                   |  +--EDIT_UNKNW12  (0x2302)
  145.                   |  +--EDIT_UNKNW13  (0x2000)
  146.                   |  +--EDIT_UNKNW14  (0xAFFF)
  147.                   |
  148.                   +--KEYF3DS (0xB000)
  149.  
  150.  A chunk type which you can find all through the file are the color chunks
  151.  which are called:
  152.  
  153.  COL_RGB
  154.  COL_TRU
  155.  COL_UNK
  156.  
  157.  Now for the actual numbers, as you will see I used the define, because I
  158.  ripped that part right out of my code. Be carefull however because there
  159.  are a lot of new chunk types which were not documented in the original paper
  160.  by Jim Pitts.
  161.  
  162.  //>------ Primary chunk
  163.  
  164.  #define MAIN3DS       0x4D4D
  165.  
  166.  //>------ Main Chunks
  167.  
  168.  #define EDIT3DS       0x3D3D  // this is the start of the editor config
  169.  #define KEYF3DS       0xB000  // this is the start of the keyframer config
  170.  
  171.  //>------ sub defines of EDIT3DS
  172.  
  173.  #define EDIT_MATERIAL 0xAFFF
  174.  #define EDIT_CONFIG1  0x0100
  175.  #define EDIT_CONFIG2  0x3E3D
  176.  #define EDIT_VIEW_P1  0x7012
  177.  #define EDIT_VIEW_P2  0x7011
  178.  #define EDIT_VIEW_P3  0x7020
  179.  #define EDIT_VIEW1    0x7001
  180.  #define EDIT_BACKGR   0x1200
  181.  #define EDIT_AMBIENT  0x2100
  182.  #define EDIT_OBJECT   0x4000
  183.  
  184.  #define EDIT_UNKNW01  0x1100
  185.  #define EDIT_UNKNW02  0x1201
  186.  #define EDIT_UNKNW03  0x1300
  187.  #define EDIT_UNKNW04  0x1400
  188.  #define EDIT_UNKNW05  0x1420
  189.  #define EDIT_UNKNW06  0x1450
  190.  #define EDIT_UNKNW07  0x1500
  191.  #define EDIT_UNKNW08  0x2200
  192.  #define EDIT_UNKNW09  0x2201
  193.  #define EDIT_UNKNW10  0x2210
  194.  #define EDIT_UNKNW11  0x2300
  195.  #define EDIT_UNKNW12  0x2302 
  196.  #define EDIT_UNKNW13  0x3000
  197.  #define EDIT_UNKNW14  0xAFFF
  198.  
  199.  //>------ sub defines of EDIT_OBJECT
  200.  #define OBJ_TRIMESH   0x4100
  201.  #define OBJ_LIGHT     0x4600
  202.  #define OBJ_CAMERA    0x4700
  203.  
  204.  #define OBJ_UNKNWN01  0x4010
  205.  #define OBJ_UNKNWN02  0x4012 //>>---- Could be shadow
  206.  
  207.  //>------ sub defines of OBJ_CAMERA
  208.  #define CAM_UNKNWN01  0x4710 
  209.  #define CAM_UNKNWN02  0x4720 
  210.  
  211.  //>------ sub defines of OBJ_LIGHT
  212.  #define LIT_OFF       0x4620
  213.  #define LIT_SPOT      0x4610
  214.  #define LIT_UNKNWN01  0x465A
  215.  
  216.  //>------ sub defines of OBJ_TRIMESH
  217.  #define TRI_VERTEXL   0x4110
  218.  #define TRI_FACEL2    0x4111 
  219.  #define TRI_FACEL1    0x4120
  220.  #define TRI_SMOOTH    0x4150
  221.  #define TRI_LOCAL     0x4160
  222.  #define TRI_VISIBLE   0x4165
  223.  
  224.  //>>------ sub defs of KEYF3DS
  225.  
  226.  #define KEYF_UNKNWN01 0xB009
  227.  #define KEYF_UNKNWN02 0xB00A
  228.  #define KEYF_FRAMES   0xB008
  229.  #define KEYF_OBJDES   0xB002
  230.  
  231.  //>>------  these define the different color chunk types
  232.  #define COL_RGB  0x0010
  233.  #define COL_TRU  0x0011
  234.  #define COL_UNK  0x0013
  235.  
  236.  //>>------ defines for viewport chunks
  237.  
  238.  #define TOP           0x0001
  239.  #define BOTTOM        0x0002
  240.  #define LEFT          0x0003
  241.  #define RIGHT         0x0004
  242.  #define FRONT         0x0005
  243.  #define BACK          0x0006
  244.  #define USER          0x0007
  245.  #define CAMERA        0x0008 // 0xFFFF is the actual code read from file
  246.  #define LIGHT         0x0009
  247.  #define DISABLED      0x0010
  248.  #define BOGUS         0x0011
  249.  
  250.  So far for the quick stuff now the more detailed info.
  251.  
  252.  * Main chunks
  253.  
  254.    id
  255.  
  256.   3D3D Start of Editor data  ( this is also the place where the objects are )
  257.   B000 Start of Keyframer data
  258.  
  259.   Directly after a Main chunk is another chunk. This could be any other type
  260.   of chunk allowable within its main chunks scope. ( see diagram )
  261.  
  262.  * Subchunks of 3D3D
  263.   id   Description
  264.  0100  Part of configuration
  265.  1100  unknown
  266.  1200  Background Color
  267.  1201  unknown
  268.  1300  unknown
  269.  1400  unknown
  270.  1420  unknown
  271.  1450  unknown
  272.  1500  unknown
  273.  2100  Ambient Color Block
  274.  2200  fog ?
  275.  2201  fog ?
  276.  2210  fog ?
  277.  2300  unknown
  278.  3000  unknown
  279.  3D3E  Editor configuration main block
  280.  4000  Definition of an Object
  281.  AFFF  Start of material list
  282.  
  283.  * Subchunks of AFFF - Start of material list
  284.  
  285.  - Not much is known as of yet, only one chunk can be defined
  286.  
  287.    id      Description
  288.  A000    Materials name
  289.  A010    unknown
  290.  A020    unknown
  291.  A030    unknown
  292.  A040    unknown
  293.  A041    unknown
  294.  A050    unknown
  295.  A052    unknown
  296.  A053    unknown
  297.  A100    unknown
  298.  A084    unknown
  299.  A087    unknown
  300.  
  301.  * A000 - material name
  302.  
  303.  - This chunk contains the name of the material which is an ASCIIZ string
  304.  
  305.  * Subchunks of 3D3E - Editor configuration
  306.  
  307.   id   Description
  308.  7001  Start of viewport indicator
  309.  7011  Viewport definition ( type 2 )
  310.  7012  Viewport definition ( type 1 )
  311.  7020  Viewport definition ( type 3 )
  312.  
  313.  The 3D3E chunk is a curious one because it contains a lot of redundant
  314.  data. ( or so it seems ) The most important chunk is 7020. this chunk
  315.  describes the 4 viewports wich are active in the editor. I assume that
  316.  U are using the 4 normal viewport layout, because I have not tested it
  317.  with other configurations. The editor confid will contain 5x chunk 7020
  318.  and 5x chunk 7011. only the first 4 7020 chunks are important for how
  319.  the viewports look like. I guess that the other chunks only give additional
  320.  info, but I am not sure. The things you are looking for in these chunks is
  321.  at byte: 6 & 7 ( as offset from the first 6 bytes chunk header and pointer )
  322.  these bytes ( unsigned int ) contain the info at to what view is used, with
  323.  the following id's:
  324.  
  325.   id    Description
  326.  0001   Top
  327.  0002   Bottom
  328.  0003   Left
  329.  0004   Right
  330.  0005   Front
  331.  0006   Back
  332.  0007   User
  333.  FFFF   Camera
  334.  0009   Light
  335.  0010   Disabled
  336.  
  337.  * Subchunks of 4000 - Object description Block
  338.  
  339.  - first item of Subchunk 4000 is an ASCIIZ string of the objects name.
  340.    ASCIIZ means a string of charakters ended by a zero.
  341.  
  342.  Remember an Object can be a Camera a Light or a mesh
  343.   id      Description
  344.  4010     unknown
  345.  4012     shadow ?
  346.  4100     Triangular Polygon List ( Contains only subchunks )
  347.  4600     Light
  348.  4700     Camera
  349.  
  350.  ( Mapping:
  351.  
  352.    These chunks are optional. They stand just after the vertex list when
  353.    the object is mapped. )
  354.  
  355.  * Subchunks of 4100 - Triangular Polygon List
  356.  
  357.   id      Description
  358.  4110     Vertex List
  359.  4111     Vertex Options
  360.  4120     Face List
  361.  4130     Face Material
  362.  4140     Mapping Coordinates
  363.  4150     Face smoothing group
  364.  4160     Translation Matrix
  365.  4165     Object visible/invisble
  366.  4170     Standard Mapping
  367.  
  368.  * 4110 - Vertex List
  369.  
  370.    start end size type          name
  371.    0     1    2   unsigned int  Total vertices in object
  372.    2     5    4   float         X-value
  373.    6     9    4   float         Y-value
  374.   10    13    4   float         Z-value
  375.  
  376.  bytes 2..13 are repeated times the total amount of vertices in the object
  377.  
  378.  * 4111 - Vertex Options
  379.  
  380.  First 2 bytes: number of vertices.
  381.  
  382.  Then a short int for each vertex:
  383.  
  384.  bit 0-7    0
  385.  bit 8-10   x
  386.  bit 11-12  0
  387.  bit 13   vertex selected in selection 3
  388.  bit 14   vertex selected in selection 2
  389.  bit 15   vertex selected in selection 1
  390.  
  391.  bit 8-10 are just like random. From a save to another of the same scene
  392.  it may change.
  393.  
  394.  Other bits (0-7 and 11-12) have effects on visibility of vertex.
  395.  
  396.  The 4111 chunk can be deleted without much influence, 3ds will still load
  397.  the file all right.
  398.  
  399.  
  400.  * 4120 - Face list
  401.  
  402.  start end size type          name
  403.  0     1    2   unsigned int  total polygons in object (numpoly)
  404.  
  405.  2     3    2   unsigned int  number of vertex A
  406.  4     5    2   unsigned int  number of vertex B
  407.  6     7    2   unsigned int  number of vertex C
  408.  8     9    2   unsigned int  face info (*) 
  409.  
  410.  repeats 'numpoly' times for each polygon.
  411.  
  412.  The first three ints are the three vertices of the face.
  413.  0 stands for the first vertex defined in the vertex list.
  414.  The order has a purpose: to give the direction for the normal 
  415.  of each face.
  416.  If you turn a screw (standard screw) in the way the vertices 
  417.  indicate you will find the normal.
  418.  If vertices given in order are A B C:
  419.  
  420.                C
  421.                ^
  422.                |
  423.         A----->B
  424.  
  425.  This means unscrewing => the normal points out of the screen.
  426.  
  427.  (*) this number is is a binary number which expands to 3 values.
  428.      for example 0x0006 would expand to 110 binary. The value should be
  429.      read as 1 1 0 .This value can be found in 3d-studio ascii files as
  430.      AB:1 BC:1 AC:0 .Which probably indicated the order of the vertices.
  431.      For example AB:1 would be a normal line from A to B. But AB:0 would
  432.      mean a line from B to A.
  433.  
  434.      bit 0       AC visibility
  435.      bit 1       BC visibility
  436.      bit 2       AB visibility
  437.      bit 3       Mapping (if there is mapping for this face)
  438.      bit 4-8   0 (not used ?)
  439.      bit 9-10  x (chaotic ???)
  440.      bit 11-12 0 (not used ?)
  441.      bit 13      face selected in selection 3
  442.      bit 14      face selected in selection 2
  443.      bit 15      face selected in selection 1
  444.  
  445.  * 4130 - Face Material Chunk 
  446.  
  447.    If the object is all default material there is no 4130 chunk.
  448.    In fact, there is one 4130 chunk for each material present on the object.
  449.  
  450.    Each 4130 face material chunks begins with an asciiz of a material,
  451.    then after the null character is a short int that gives the number
  452.    of faces of the object concerned by this material, then there is the
  453.    list itself of these faces. 0000 means the first face of the (4120) 
  454.    face list.
  455.  
  456.    ************ Read the Doc on MLI files for more info on **************
  457.    ************ Mapping and Materials                      **************
  458.  
  459.  * 4140 Mapping coordinates.
  460.  
  461.    First 2 bytes: number of vertices.
  462.  
  463.    Then, for each vertex 2 floats that give the mapping coordinates.
  464.    That is, if a point is at the center of the map it will have 0.5 0.5
  465.    as mapping coordinates.
  466.  
  467.  * 4150 - Face Smoothing Group
  468.  
  469.    nfaces*4bytes
  470.  
  471.    If read as long int, the nth bit indicate if the face belongs or not
  472.    to the nth smoothing group.
  473.  
  474.  * 4160 Local axis
  475.  
  476.    Local axis info.
  477.    The three first blocks of three floats are the definition
  478.    (in the absolute axis) of the local axis X Y Z of the object.
  479.    And the last block of three floats is the local center of the object.
  480.  
  481.  
  482.  * 4170 Standard mapping
  483.  
  484.    First 2 bytes: type of mapping
  485.    0 => plannar or specific (in this case, like mapping from the lofter,
  486.                             the information of this chunk is irrelevant)
  487.    1 => cylindrical
  488.    2 => spherical
  489.  
  490.    then come 21 floats that describe the mapping.
  491.  
  492. * 4600 - Light
  493.  
  494.    start end size type   name
  495.    0      3    4  float  Light pos X
  496.    4      7    4  float  Light pos Y
  497.    8     11    4  float  Light pos Z
  498.  
  499.    after this structure check for more chunks.
  500.  
  501.    id      Description ( full description later )
  502.   0010     RGB color
  503.   0011     24 bit color
  504.   4610     Light is a Spot light
  505.   4620     Light is off/on ( Boolean )
  506.  
  507. * 4610 - Spot Light
  508.  
  509.   start end size type   name
  510.    0     3    4  float  Target pos X
  511.    4     7    4  float  Target pos X
  512.    8    11    4  float  Target pos X
  513.   12    15    4  float  Hotspot
  514.   16    19    4  float  Falloff
  515.  
  516. * 0010 - RGB Color
  517.  
  518.   start end size type   name
  519.    0     3   4   float  Red
  520.    4     7   4   float  Green
  521.    8    11   4   float  Blue
  522.  
  523. * 0011 - RGB Color - 24 bit
  524.  
  525.   start end size type   name
  526.    0    1    1   byte   Red
  527.    1    1    1   byte   Green
  528.    2    2    1   byte   Blue
  529.  
  530. * 4700 - Camera
  531.  
  532.  Describes the details of the camera in the scene
  533.  
  534.  start end size type   name
  535.   0     3   4   float  Camera pos X
  536.   4     7   4   float  Camera pos Y
  537.   8    11   4   float  Camera pos Z
  538.  12    15   4   float  Camera target X
  539.  16    19   4   float  Camera target X
  540.  20    23   4   float  Camera target X
  541.  24    27   4   float  Camera bank ( rotation angle )
  542.  28    31   4   float  Camera lens
  543.  
  544.  
  545.  * Keyframer chunk
  546.  
  547.   id         Description
  548.  B00A        unknown
  549.  7001        See first description of this chunk
  550.  B008        Frames
  551.  B009        unknown
  552.  B002        Start object description
  553.  
  554.  * B008 - Frame information
  555.  
  556.  simple structure describing frame info
  557.  
  558.  start end size type            name
  559.    0    3    4  unsigned long   start frame
  560.    4    7    4  unsigned long   end frame
  561.  
  562.  *B002 - Start of Object info
  563.  
  564.  Subhunks
  565.  
  566.   id     Description
  567.  B010    Name & Hierarchy
  568.  B011*   Name Dummy Object
  569.  B013    unknown
  570.  B014*   unknown
  571.  B015    unknown
  572.  B020    Objects pivot point ?
  573.  B021    unknown
  574.  B022    unknown
  575.  
  576.  * B010 - Name & Hierarchy descriptor
  577.  
  578.  start end  size type          name
  579.  0      ?    ?   ASCIIZ        Object name
  580.  ?      ?    ?   unsigned int  unknown
  581.  ?      ?    ?   unsigned int  unknown
  582.  ?      ?    ?   unsigned int  Hierarchy of Object
  583.  
  584.  The object hierarchy is a bit complex but works like this.
  585.  Each Object in the scene is given a number to identify its
  586.  order in the tree. Also each object is orddered in the 3ds
  587.  file as it would appear in the tree.
  588.  The root object is given the number -1 ( FFFF ).
  589.  As the file is read a counter of the object number is kept.
  590.  Is the counter increments the object are children of the
  591.  previous objects.But when the pattern is broken by a number
  592.  what will be less than the current counter the hierarchy returns
  593.  to that level.
  594.  
  595.  for example.
  596.  
  597.     object   hierarchy
  598.     name
  599.  
  600.         A      -1
  601.         B       0                 This example is taken
  602.         C       1                 from 50pman.3ds
  603.         D       2
  604.         E       1                 I would really reccomend
  605.         F       4                 having a look at one of the
  606.         G       5                 examples with the hierarchy
  607.         H       1                 numbers to help work it out.
  608.         I       7
  609.         J       8
  610.         K       0
  611.         L      10
  612.         M      11
  613.         N       0
  614.         O      13
  615.         P      14
  616.  
  617.  
  618.                            A
  619.          +-----------------+----------------+
  620.          B                 K                N
  621.     +----+----+            +                +
  622.     C    E    H            L                O
  623.     +    +    +            +                +
  624.     D    F    I            M                P
  625.          +    +
  626.          G    J
  627.  
  628.  Still not done with this chunk yet !
  629.  If the object name is $$$DUMMY then it is a dummy object
  630.  and therefore you should expect a few extra chunks.
  631.  
  632.  * B011 - Dummy objects name.
  633.  
  634.     Names a dummy object. ASCIIZ string.
  635.  
  636.  * B020 - Pivot Point ?
  637.  
  638.  The Objects pivot point. Not quite sure what the first five floats do yet
  639.  ( ideas ?).
  640.  
  641.  start end size type   name
  642.    0    3    4  float  unknown
  643.    4    7    4  float  unknown
  644.    8   11    4  float  unknown
  645.   12   16    4  float  unknown
  646.   16   19    4  float  unknown
  647.   20   23    4  float  unknown
  648.   24   27    4  float  Pivot Y
  649.   28   32    4  float  Pivot X
  650.  
  651.  
  652.  
  653.  AND NOW FOR THE SOURCE CODE:
  654.  (!!!!!!!!!!! The source code is not UP-TO-DATE it is written after rev 0.9
  655.   of this Doc It will be updated when I can find the time ( or maybe YOU can)
  656.  )
  657.  
  658.  
  659.  -----------------------------8=<  cut here  >=8-----------------------------
  660.  
  661.  
  662.  
  663.  
  664. /*----------------------------------------------------------------------------*\
  665.      This is a lib which reads 3d-studio binary files from version 3.0
  666.      and higher
  667.      (v1.05)
  668.      author: Martin van Velsen
  669.              ( and some great help by Gert van der Spoel )
  670.      email:  vvelsen@ronix.ptf.hro.nl
  671. \*----------------------------------------------------------------------------*/
  672. #ifndef __3DSBIN_H__
  673. #define __3DSBIN_H__
  674.  
  675. #include <stdio.h>
  676. #include <string.h>
  677. #include <stdlib.h>
  678. #include <conio.h>
  679. #include <dos.h>
  680.  
  681. //>------ tools
  682.  
  683. #define __DEBUG__          0
  684.  
  685. #define TRUE               0
  686. #define FALSE              1
  687.  
  688. //>------ Id Chunk
  689.  
  690. #define MAIN3DS       0x4D4D
  691.  
  692. //>------ Main Chunks
  693.  
  694. #define EDIT3DS       0x3D3D  // this is the start of the editor config
  695. #define KEYF3DS       0xB000  // this is the start of the keyframer config
  696.  
  697. //>------ sub defines of EDIT3DS
  698.  
  699. #define EDIT_MATERIAL 0xAFFF
  700. #define EDIT_CONFIG1  0x0100
  701. #define EDIT_CONFIG2  0x3E3D
  702. #define EDIT_VIEW_P1  0x7012
  703. #define EDIT_VIEW_P2  0x7011
  704. #define EDIT_VIEW_P3  0x7020
  705. #define EDIT_VIEW1    0x7001
  706. #define EDIT_BACKGR   0x1200
  707. #define EDIT_AMBIENT  0x2100
  708. #define EDIT_OBJECT   0x4000
  709.  
  710. #define EDIT_UNKNW01  0x1100
  711. #define EDIT_UNKNW02  0x1201
  712. #define EDIT_UNKNW03  0x1300
  713. #define EDIT_UNKNW04  0x1400
  714. #define EDIT_UNKNW05  0x1420
  715. #define EDIT_UNKNW06  0x1450
  716. #define EDIT_UNKNW07  0x1500
  717. #define EDIT_UNKNW08  0x2200
  718. #define EDIT_UNKNW09  0x2201
  719. #define EDIT_UNKNW10  0x2210
  720. #define EDIT_UNKNW11  0x2300
  721. #define EDIT_UNKNW12  0x2302 // new chunk type
  722. #define EDIT_UNKNW13  0x3000
  723. #define EDIT_UNKNW14  0xAFFF
  724.  
  725. //>------ sub defines of EDIT_MATERIAL
  726. #define MAT_NAME01    0xA000  //> includes name (see mli doc for materials)
  727.  
  728. //>------ sub defines of EDIT_OBJECT
  729.  
  730. #define OBJ_TRIMESH   0x4100
  731. #define OBJ_LIGHT     0x4600
  732. #define OBJ_CAMERA    0x4700
  733.  
  734. #define OBJ_UNKNWN01  0x4010
  735. #define OBJ_UNKNWN02  0x4012 //>>---- Could be shadow
  736.  
  737. //>------ sub defines of OBJ_CAMERA
  738. #define CAM_UNKNWN01  0x4710 // new chunk type
  739. #define CAM_UNKNWN02  0x4720 // new chunk type
  740.  
  741. //>------ sub defines of OBJ_LIGHT
  742. #define LIT_OFF       0x4620
  743. #define LIT_SPOT      0x4610
  744. #define LIT_UNKNWN01  0x465A
  745.  
  746. //>------ sub defines of OBJ_TRIMESH
  747. #define TRI_VERTEXL   0x4110
  748. #define TRI_FACEL2    0x4111 // unknown yet
  749. #define TRI_FACEL1    0x4120
  750. #define TRI_SMOOTH    0x4150
  751. #define TRI_LOCAL     0x4160
  752. #define TRI_VISIBLE   0x4165
  753.  
  754. //>>------ sub defs of KEYF3DS
  755.  
  756. #define KEYF_UNKNWN01 0xB009
  757. #define KEYF_UNKNWN02 0xB00A
  758. #define KEYF_FRAMES   0xB008
  759. #define KEYF_OBJDES   0xB002
  760.  
  761. //>>------  these define the different color chunk types
  762. #define COL_RGB  0x0010
  763. #define COL_TRU  0x0011
  764. #define COL_UNK  0x0013 // unknown
  765.  
  766. //>>------ defines for viewport chunks
  767.  
  768. #define TOP           0x0001
  769. #define BOTTOM        0x0002
  770. #define LEFT          0x0003
  771. #define RIGHT         0x0004
  772. #define FRONT         0x0005
  773. #define BACK          0x0006
  774. #define USER          0x0007
  775. #define CAMERA        0x0008 // 0xFFFF is the code read from file
  776. #define LIGHT         0x0009
  777. #define DISABLED      0x0010
  778. #define BOGUS         0x0011
  779.  
  780. //>------ global vars
  781.  
  782. char *viewports [11]={
  783.                       "Bogus",
  784.                       "Top",
  785.                       "Bottom",
  786.                       "Left",
  787.                       "Right",
  788.                       "Front",
  789.                       "Back",
  790.                       "User",
  791.                       "Camera",
  792.                       "Light",
  793.                       "Disabled"
  794.                      };
  795.  
  796. FILE *bin3ds;
  797. unsigned long current_chunk=0L;
  798. unsigned char views_read=0;
  799. unsigned int numb_faces=0,numb_vertices=0;
  800. char temp_name [100];
  801. float trans_mat [4][4]; // translation matrix for objects
  802.  
  803. #endif
  804.  
  805.  
  806.  
  807.  -----------------------------8=<  cut here  >=8-----------------------------
  808.  
  809.  
  810.  
  811. /*----------------------------------------------------------------------------*\
  812.      This is a lib which reads 3d-studio binary files from version 3.0
  813.      and higher
  814.      (v1.05)
  815.      author: Martin van Velsen
  816.              ( and some great help by Gert van der Spoel )
  817.      email:  vvelsen@ronix.ptf.hro.nl
  818. \*----------------------------------------------------------------------------*/
  819. #ifndef __3DSBIN_C__
  820. #define __3DSBIN_C__
  821.  
  822. #include "3ds_bin.h"
  823.  
  824. /*----------------------------------------------------------------------------*/
  825. unsigned char ReadChar (void)
  826. {
  827.  return (fgetc (bin3ds));
  828. }
  829. /*----------------------------------------------------------------------------*/
  830. unsigned int ReadInt (void)
  831. {
  832.  return (ReadChar () | (ReadChar () << 8));
  833. }
  834. /*----------------------------------------------------------------------------*/
  835. unsigned long ReadLong (void)
  836. {
  837.  unsigned long temp1,temp2;
  838.  
  839.  temp1=(ReadChar () | (ReadChar () << 8));
  840.  temp2=(ReadChar () | (ReadChar () << 8));
  841.  
  842.  return (temp1+(temp2*0x10000L));
  843. }
  844. /*----------------------------------------------------------------------------*/
  845. unsigned long ReadChunkPointer (void)
  846. {
  847.  return (ReadLong ());
  848. }
  849. /*----------------------------------------------------------------------------*/
  850. unsigned long GetChunkPointer (void)
  851. {
  852.  return (ftell (bin3ds)-2); // compensate for the already read Marker
  853. }
  854. /*----------------------------------------------------------------------------*/
  855. void ChangeChunkPointer (unsigned long temp_pointer)
  856. {
  857.  fseek (bin3ds,temp_pointer,SEEK_SET);
  858. }
  859. /*----------------------------------------------------------------------------*/
  860. int ReadName (void)
  861. {
  862.  unsigned int teller=0;
  863.  unsigned char letter;
  864.  
  865.  strcpy (temp_name,"Default name");
  866.  
  867.  letter=ReadChar ();
  868.  if (letter==0) return (-1); // dummy object
  869.  temp_name [teller]=letter;
  870.  teller++;
  871.  
  872.  do
  873.  {
  874.   letter=ReadChar ();
  875.   temp_name [teller]=letter;
  876.   teller++;
  877.  }
  878.  while ((letter!=0) && (teller<12));
  879.  
  880.  temp_name [teller-1]=0;
  881.  
  882.  #ifdef __DEBUG__
  883.   printf ("     Found name : %s\n",temp_name);
  884.  #endif
  885.  return (0);
  886. }
  887. /*----------------------------------------------------------------------------*/
  888. int ReadLongName (void)
  889. {
  890.  unsigned int teller=0;
  891.  unsigned char letter;
  892.  
  893.  strcpy (temp_name,"Default name");
  894.  
  895.  letter=ReadChar ();
  896.  if (letter==0) return (-1); // dummy object
  897.  temp_name [teller]=letter;
  898.  teller++;
  899.  
  900.  do
  901.  {
  902.   letter=ReadChar ();
  903.   temp_name [teller]=letter;
  904.   teller++;
  905.  }
  906.  while (letter!=0);
  907.  
  908.  temp_name [teller-1]=0;
  909.  
  910.  #ifdef __DEBUG__
  911.    printf ("Found name : %s\n",temp_name);
  912.  #endif
  913.  return (0);
  914. }
  915. /*----------------------------------------------------------------------------*/
  916. unsigned long ReadUnknownChunk (unsigned int chunk_id)
  917. {
  918.  unsigned long current_pointer;
  919.  unsigned long temp_pointer;
  920.  
  921.  chunk_id=chunk_id;
  922.  
  923.  current_pointer=GetChunkPointer ();
  924.  temp_pointer   =ReadChunkPointer ();
  925.  
  926.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  927.  return (temp_pointer);
  928. }
  929. /*----------------------------------------------------------------------------*/
  930. unsigned long ReadRGBColor (void)
  931. {
  932.  float rgb_val [3];
  933.  
  934.  for (int i=0;i<3;i++)
  935.   fread (&(rgb_val [i]),sizeof (float),1,bin3ds);
  936.  
  937.  #ifdef __DEBUG__
  938.  printf ("     Found Color (RGB) def of: R:%5.2f,G:%5.2f,B:%5.2f\n",
  939.           rgb_val [0],
  940.           rgb_val [1],
  941.           rgb_val [2]);
  942.  #endif
  943.  
  944.  return (12L);
  945. }
  946. /*----------------------------------------------------------------------------*/
  947. unsigned long ReadTrueColor (void)
  948. {
  949.  unsigned char true_c_val [3];
  950.  
  951.  for (int i=0;i<3;i++)
  952.   true_c_val [i]=ReadChar ();
  953.  
  954.  #ifdef __DEBUG__
  955.  printf ("     Found Color (24bit) def of: R:%d,G:%d,B:%d\n",
  956.           true_c_val [0],
  957.           true_c_val [1],
  958.           true_c_val [2]);
  959.  #endif
  960.  
  961.  return (3L);
  962. }
  963. /*----------------------------------------------------------------------------*/
  964. unsigned long ReadBooleanChunk (unsigned char *boolean)
  965. {
  966.  unsigned long current_pointer;
  967.  unsigned long temp_pointer;
  968.  
  969.  current_pointer=GetChunkPointer ();
  970.  temp_pointer   =ReadChunkPointer ();
  971.  
  972.  *boolean=ReadChar ();
  973.  
  974.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  975.  return (temp_pointer);
  976. }
  977. /*----------------------------------------------------------------------------*/
  978. unsigned long ReadSpotChunk (void)
  979. {
  980.  unsigned long current_pointer;
  981.  unsigned long temp_pointer;
  982.  float target [4];
  983.  float hotspot,falloff;
  984.  
  985.  current_pointer=GetChunkPointer ();
  986.  temp_pointer   =ReadChunkPointer ();
  987.  
  988.  fread (&(target [0]),sizeof (float),1,bin3ds);
  989.  fread (&(target [1]),sizeof (float),1,bin3ds);
  990.  fread (&(target [2]),sizeof (float),1,bin3ds);
  991.  fread (&hotspot,sizeof (float),1,bin3ds);
  992.  fread (&falloff,sizeof (float),1,bin3ds);
  993.  
  994.  #ifdef __DEBUG__
  995.  printf ("      The target of the spot is at: X:%5.2f Y:%5.2f Y:%5.2f\n",
  996.           target [0],
  997.           target [1],
  998.           target [2]);
  999.  printf ("      The hotspot of this light is : %5.2f\n",hotspot);
  1000.  printf ("      The falloff of this light is : %5.2f\n",falloff);
  1001.  #endif
  1002.  
  1003.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1004.  return (temp_pointer);
  1005. }
  1006. /*----------------------------------------------------------------------------*/
  1007. unsigned long ReadLightChunk (void)
  1008. {
  1009.  unsigned char end_found=FALSE,boolean;
  1010.  unsigned int temp_int;
  1011.  unsigned long current_pointer;
  1012.  unsigned long temp_pointer;
  1013.  unsigned long tellertje=6L; // 2 id + 4 pointer
  1014.  float light_coors [3];
  1015.  
  1016.  current_pointer=GetChunkPointer ();
  1017.  temp_pointer   =ReadChunkPointer ();
  1018.  
  1019.  fread (&(light_coors [0]),sizeof (float),1,bin3ds);
  1020.  fread (&(light_coors [1]),sizeof (float),1,bin3ds);
  1021.  fread (&(light_coors [2]),sizeof (float),1,bin3ds);
  1022.  
  1023.  #ifdef __DEBUG__
  1024.  printf ("     Found light at coordinates: X: %5.2f, Y: %5.2f,Z: %5.2f\n",
  1025.           light_coors [0],
  1026.           light_coors [1],
  1027.           light_coors [2]);
  1028.  #endif
  1029.  
  1030.  while (end_found==FALSE)
  1031.  {
  1032.    temp_int=ReadInt ();
  1033.  
  1034.        switch (temp_int)
  1035.        {
  1036.         case LIT_UNKNWN01 :
  1037.                            #ifdef __DEBUG__
  1038.                            printf (">>>>> Found Light unknown chunk id of %0X\n",LIT_UNKNWN01);
  1039.                            #endif
  1040.                            tellertje+=ReadUnknownChunk (LIT_UNKNWN01);
  1041.                            break;
  1042.         case LIT_OFF      :
  1043.                            #ifdef __DEBUG__
  1044.                            printf (">>>>> Light is (on/off) chunk: %0X\n",LIT_OFF);
  1045.                            #endif
  1046.                            tellertje+=ReadBooleanChunk (&boolean);
  1047.                            #ifdef __DEBUG__
  1048.                            if (boolean==TRUE)
  1049.                              printf ("      Light is on\n");
  1050.                            else
  1051.                              printf ("      Light is off\n");
  1052.                            #endif
  1053.                            break;
  1054.         case LIT_SPOT     :
  1055.                            #ifdef __DEBUG__
  1056.                            printf (">>>>> Light is SpotLight: %0X\n",TRI_VERTEXL);
  1057.                            #endif
  1058.                            tellertje+=ReadSpotChunk ();
  1059.                            break;
  1060.         case COL_RGB      :
  1061.                            #ifdef __DEBUG__
  1062.                            printf (">>>>> Found Color def (RGB) chunk id of %0X\n",temp_int);
  1063.                            #endif
  1064.                            tellertje+=ReadRGBColor ();
  1065.                            break;
  1066.         case COL_TRU      :
  1067.                            #ifdef __DEBUG__
  1068.                            printf (">>>>> Found Color def (24bit) chunk id of %0X\n",temp_int);
  1069.                            #endif
  1070.                            tellertje+=ReadTrueColor ();
  1071.                            break;
  1072.         default           :break;
  1073.        }
  1074.  
  1075.    tellertje+=2;
  1076.    if (tellertje>=temp_pointer)
  1077.      end_found=TRUE;
  1078.  }
  1079.  
  1080.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1081.  return (temp_pointer);
  1082. }
  1083. /*----------------------------------------------------------------------------*/
  1084. unsigned long ReadCameraChunk (void)
  1085. {
  1086.  unsigned long current_pointer;
  1087.  unsigned long temp_pointer;
  1088.  float camera_eye [3];
  1089.  float camera_focus [3];
  1090.  float rotation,lens;
  1091.  
  1092.  current_pointer=GetChunkPointer ();
  1093.  temp_pointer   =ReadChunkPointer ();
  1094.  
  1095.  fread (&(camera_eye [0]),sizeof (float),1,bin3ds);
  1096.  fread (&(camera_eye [1]),sizeof (float),1,bin3ds);
  1097.  fread (&(camera_eye [2]),sizeof (float),1,bin3ds);
  1098.  
  1099.  #ifdef __DEBUG__
  1100.  printf ("     Found Camera viewpoint at coordinates: X: %5.2f, Y: %5.2f,Z: %5.2f\n",
  1101.           camera_eye [0],
  1102.           camera_eye [1],
  1103.           camera_eye [2]);
  1104.  #endif
  1105.  
  1106.  fread (&(camera_focus [0]),sizeof (float),1,bin3ds);
  1107.  fread (&(camera_focus [1]),sizeof (float),1,bin3ds);
  1108.  fread (&(camera_focus [2]),sizeof (float),1,bin3ds);
  1109.  
  1110.  #ifdef __DEBUG__
  1111.  printf ("     Found Camera focus coors at coordinates: X: %5.2f, Y: %5.2f,Z: %5.2f\n",
  1112.           camera_focus [0],
  1113.           camera_focus [1],
  1114.           camera_focus [2]);
  1115.  #endif
  1116.  
  1117.  fread (&rotation,sizeof (float),1,bin3ds);
  1118.  fread (&lens,sizeof (float),1,bin3ds);
  1119.  #ifdef __DEBUG__
  1120.  printf ("     Rotation of camera is:  %5.4f\n",rotation);
  1121.  printf ("     Lens in used camera is: %5.4fmm\n",lens);
  1122.  #endif
  1123.  
  1124.  if ((temp_pointer-38)>0) // this means more chunks are to follow
  1125.  {
  1126.   #ifdef __DEBUG__
  1127.   printf ("     **** found extra cam chunks ****\n");
  1128.   #endif
  1129.   if (ReadInt ()==CAM_UNKNWN01)
  1130.   {
  1131.    #ifdef __DEBUG__
  1132.    printf ("     **** Found cam 1 type ch ****\n");
  1133.    #endif
  1134.    ReadUnknownChunk (CAM_UNKNWN01);
  1135.   }
  1136.   if (ReadInt ()==CAM_UNKNWN02)
  1137.   {
  1138.    #ifdef __DEBUG__
  1139.    printf ("     **** Found cam 2 type ch ****\n");
  1140.    #endif
  1141.    ReadUnknownChunk (CAM_UNKNWN02);
  1142.   }
  1143.  }
  1144.  
  1145.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1146.  return (temp_pointer);
  1147. }
  1148. /*----------------------------------------------------------------------------*/
  1149. unsigned long ReadVerticesChunk (void)
  1150. {
  1151.  unsigned long current_pointer;
  1152.  unsigned long temp_pointer;
  1153.  float vertices [3]; // x,y,z
  1154.  unsigned int numb_v;
  1155.  
  1156.  current_pointer=GetChunkPointer ();
  1157.  temp_pointer   =ReadChunkPointer ();
  1158.  numb_vertices  =ReadInt ();
  1159.  
  1160.  #ifdef __DEBUG__
  1161.  printf ("      Found (%d) number of vertices\n",numb_vertices);
  1162.  #endif
  1163.  
  1164.  for (int i=0;i<numb_vertices;i++)
  1165.  {
  1166.   fread (&(vertices [0]),sizeof (float),1,bin3ds);
  1167.   fread (&(vertices [1]),sizeof (float),1,bin3ds);
  1168.   fread (&(vertices [2]),sizeof (float),1,bin3ds);
  1169.  
  1170.   #ifdef __DEBUG__
  1171.   printf ("      Vertex nr%4d: X: %5.2f  Y: %5.2f  Z:%5.2f\n",
  1172.            i,
  1173.            vertices [0],
  1174.            vertices [1],
  1175.            vertices [2]);
  1176.   #endif
  1177.  }
  1178.  
  1179.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1180.  return (temp_pointer);
  1181. }
  1182. /*----------------------------------------------------------------------------*/ unsigned long current_pointer;
  1183. unsigned long ReadSmoothingChunk ()
  1184. {
  1185.  unsigned long current_pointer;
  1186.  unsigned long temp_pointer;
  1187.  unsigned long smoothing;
  1188.  
  1189.  current_pointer=GetChunkPointer ();
  1190.  temp_pointer   =ReadChunkPointer ();
  1191.  
  1192.  for (int i=0;i<numb_faces;i++)
  1193.  {
  1194.   smoothing=ReadLong();
  1195.   smoothing=smoothing; // compiler warnig depressor *>:)
  1196.   #ifdef __DEBUG__
  1197.   printf ("      The smoothing group for face [%5d] is %d\n",i,smoothing);
  1198.   #endif
  1199.  }
  1200.  
  1201.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1202.  return (temp_pointer);
  1203. }
  1204. /*----------------------------------------------------------------------------*/
  1205. unsigned long ReadFacesChunk (void)
  1206. {
  1207.  unsigned long current_pointer;
  1208.  unsigned long temp_pointer;
  1209.  unsigned int temp_diff;
  1210.  unsigned int faces [6]; // a,b,c,Diff (Diff= AB: BC: CA: )
  1211.  
  1212.  current_pointer=GetChunkPointer ();
  1213.  temp_pointer   =ReadChunkPointer ();
  1214.  numb_faces     =ReadInt ();
  1215.  #ifdef __DEBUG__
  1216.  printf ("      Found (%d) number of faces\n",numb_faces);
  1217.  #endif
  1218.  
  1219.  for (int i=0;i<numb_faces;i++)
  1220.  {
  1221.   faces [0]=ReadInt ();
  1222.   faces [1]=ReadInt ();
  1223.   faces [2]=ReadInt ();
  1224.   temp_diff=ReadInt () & 0x000F;
  1225.   faces [3]=(temp_diff & 0x0004) >> 2;
  1226.   faces [4]=(temp_diff & 0x0002) >> 1;
  1227.   faces [5]=(temp_diff & 0x0001);
  1228.  
  1229.   #ifdef __DEBUG__
  1230.   printf ("      Face nr:%d, A: %d  B: %d  C:%d , AB:%d  BC:%d  CA:%d\n",
  1231.            i,
  1232.            faces [0],
  1233.            faces [1],
  1234.            faces [2],
  1235.            faces [3],
  1236.            faces [4],
  1237.            faces [5]);
  1238.   #endif
  1239.  }
  1240.  
  1241.  if (ReadInt ()==TRI_SMOOTH)
  1242.   ReadSmoothingChunk ();
  1243.  #ifdef __DEBUG__
  1244.  else
  1245.   printf ("      No smoothing groups found, assuming autosmooth\n");
  1246.  #endif
  1247.  
  1248.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1249.  return (temp_pointer);
  1250. }
  1251. /*----------------------------------------------------------------------------*/
  1252. unsigned long ReadTranslationChunk (void)
  1253. {
  1254.  unsigned long current_pointer;
  1255.  unsigned long temp_pointer;
  1256.  current_pointer=GetChunkPointer ();
  1257.  temp_pointer   =ReadChunkPointer ();
  1258.  
  1259.  for (int j=0;j<4;j++)
  1260.  {
  1261.    for (int i=0;i<3;i++)
  1262.     fread (&(trans_mat [j][i]),sizeof (float),1,bin3ds);
  1263.  }
  1264.  
  1265.  trans_mat [0][3]=0;
  1266.  trans_mat [1][3]=0;
  1267.  trans_mat [2][3]=0;
  1268.  trans_mat [3][3]=1;
  1269.  
  1270.  #ifdef __DEBUG__
  1271.  printf ("     The translation matrix is:\n");
  1272.  for (int i=0;i<4;i++)
  1273.      printf ("      | %5.2f %5.2f %5.2f %5.2f |\n",
  1274.               trans_mat [i][0],
  1275.               trans_mat [i][1],
  1276.               trans_mat [i][2],
  1277.               trans_mat [i][3]);
  1278.  #endif
  1279.  
  1280.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1281.  return (temp_pointer);
  1282. }
  1283. /*----------------------------------------------------------------------------*/
  1284. unsigned long ReadObjChunk (void)
  1285. {
  1286.  unsigned char end_found=FALSE,boolean=TRUE;
  1287.  unsigned int temp_int;
  1288.  unsigned long current_pointer;
  1289.  unsigned long temp_pointer;
  1290.  unsigned long tellertje=6L; // 2 id + 4 pointer
  1291.  
  1292.  current_pointer=GetChunkPointer ();
  1293.  temp_pointer   =ReadChunkPointer ();
  1294.  
  1295.  while (end_found==FALSE)
  1296.  {
  1297.    temp_int=ReadInt ();
  1298.  
  1299.        switch (temp_int)
  1300.        {
  1301.         case TRI_VERTEXL :
  1302.                           #ifdef __DEBUG__
  1303.                           printf (">>>>> Found Object vertices chunk id of %0X\n",temp_int);
  1304.                           #endif
  1305.                           tellertje+=ReadVerticesChunk ();
  1306.                           break;
  1307.         case TRI_FACEL1  :
  1308.                           #ifdef __DEBUG__
  1309.                           printf (">>>>> Found Object faces (1) chunk id of %0X\n",temp_int);
  1310.                           #endif
  1311.                           tellertje+=ReadFacesChunk ();
  1312.                           break;
  1313.         case TRI_FACEL2  :
  1314.                           #ifdef __DEBUG__
  1315.                           printf (">>>>> Found Object faces (2) chunk id of %0X\n",temp_int);
  1316.                           #endif
  1317.                           tellertje+=ReadUnknownChunk (temp_int);
  1318.                           break;
  1319.         case TRI_TRANSL  :
  1320.                           #ifdef __DEBUG__
  1321.                           printf (">>>>> Found Object translation chunk id of %0X\n",temp_int);
  1322.                           #endif
  1323.                           tellertje+=ReadTranslationChunk ();
  1324.                           break;
  1325.         case TRI_VISIBLE :
  1326.                           #ifdef __DEBUG__
  1327.                           printf (">>>>> Found Object vis/invis chunk id of %0X\n",temp_int);
  1328.                           #endif
  1329.                           tellertje+=ReadBooleanChunk (&boolean);
  1330.  
  1331.                           #ifdef __DEBUG__
  1332.                           if (boolean==TRUE)
  1333.                              printf ("      Object is (visible)\n");
  1334.                           else
  1335.                              printf ("      Object is (not visible)\n");
  1336.                           #endif
  1337.                           break;
  1338.         default:          break;
  1339.        }
  1340.  
  1341.    tellertje+=2;
  1342.    if (tellertje>=temp_pointer)
  1343.      end_found=TRUE;
  1344.  }
  1345.  
  1346.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1347.  return (temp_pointer);
  1348. }
  1349. /*----------------------------------------------------------------------------*/
  1350. unsigned long ReadObjectChunk (void)
  1351. {
  1352.  unsigned char end_found=FALSE;
  1353.  unsigned int temp_int;
  1354.  unsigned long current_pointer;
  1355.  unsigned long temp_pointer;
  1356.  unsigned long tellertje=6L; // 2 id + 4 pointer
  1357.  
  1358.  current_pointer=GetChunkPointer ();
  1359.  temp_pointer   =ReadChunkPointer ();
  1360.  
  1361.  if (ReadName ()==-1)
  1362.  {
  1363.   #ifdef __DEBUG__
  1364.   printf (">>>>* Dummy Object found\n");
  1365.   #endif
  1366.  }
  1367.  
  1368.  while (end_found==FALSE)
  1369.  {
  1370.    temp_int=ReadInt ();
  1371.  
  1372.        switch (temp_int)
  1373.        {
  1374.         case OBJ_UNKNWN01:tellertje+=ReadUnknownChunk (OBJ_UNKNWN01);break;
  1375.         case OBJ_UNKNWN02:tellertje+=ReadUnknownChunk (OBJ_UNKNWN02);break;
  1376.         case OBJ_TRIMESH :
  1377.                           #ifdef __DEBUG__
  1378.                           printf (">>>> Found Obj/Mesh chunk id of %0X\n",OBJ_TRIMESH);
  1379.                           #endif
  1380.                           tellertje+=ReadObjChunk ();
  1381.                           break;
  1382.         case OBJ_LIGHT   :
  1383.                           #ifdef __DEBUG__
  1384.                           printf (">>>> Found Light chunk id of %0X\n",OBJ_LIGHT);
  1385.                           #endif
  1386.                           tellertje+=ReadLightChunk ();
  1387.                           break;
  1388.         case OBJ_CAMERA  :
  1389.                           #ifdef __DEBUG__
  1390.                           printf (">>>> Found Camera chunk id of %0X\n",OBJ_CAMERA);
  1391.                           #endif
  1392.                           tellertje+=ReadCameraChunk ();
  1393.                           break;
  1394.         default:          break;
  1395.        }
  1396.  
  1397.    tellertje+=2;
  1398.    if (tellertje>=temp_pointer)
  1399.      end_found=TRUE;
  1400.  }
  1401.  
  1402.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1403.  return (temp_pointer);
  1404. }
  1405. /*----------------------------------------------------------------------------*/
  1406. unsigned long ReadBackgrChunk (void)
  1407. {
  1408.  unsigned char end_found=FALSE;
  1409.  unsigned int temp_int;
  1410.  unsigned long current_pointer;
  1411.  unsigned long temp_pointer;
  1412.  unsigned long tellertje=6L; // 2 id + 4 pointer
  1413.  
  1414.  current_pointer=GetChunkPointer ();
  1415.  temp_pointer   =ReadChunkPointer ();
  1416.  
  1417.  while (end_found==FALSE)
  1418.  {
  1419.    temp_int=ReadInt ();
  1420.  
  1421.        switch (temp_int)
  1422.        {
  1423.         case COL_RGB :
  1424.                       #ifdef __DEBUG__
  1425.                       printf (">> Found Color def (RGB) chunk id of %0X\n",temp_int);
  1426.                       #endif
  1427.                       tellertje+=ReadRGBColor ();
  1428.                       break;
  1429.         case COL_TRU :
  1430.                       #ifdef __DEBUG__
  1431.                       printf (">> Found Color def (24bit) chunk id of %0X\n",temp_int);
  1432.                       #endif
  1433.                       tellertje+=ReadTrueColor ();
  1434.                       break;
  1435.         default:      break;
  1436.        }
  1437.  
  1438.    tellertje+=2;
  1439.    if (tellertje>=temp_pointer)
  1440.      end_found=TRUE;
  1441.  }
  1442.  
  1443.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1444.  return (temp_pointer);
  1445. }
  1446. /*----------------------------------------------------------------------------*/
  1447. unsigned long ReadAmbientChunk (void)
  1448. {
  1449.  unsigned char end_found=FALSE;
  1450.  unsigned int temp_int;
  1451.  unsigned long current_pointer;
  1452.  unsigned long temp_pointer;
  1453.  unsigned long tellertje=6L; // 2 id + 4 pointer
  1454.  
  1455.  current_pointer=GetChunkPointer ();
  1456.  temp_pointer   =ReadChunkPointer ();
  1457.  
  1458.  while (end_found==FALSE)
  1459.  {
  1460.    temp_int=ReadInt ();
  1461.  
  1462.        switch (temp_int)
  1463.        {
  1464.         case COL_RGB :
  1465.                       #ifdef __DEBUG__
  1466.                       printf (">>>> Found Color def (RGB) chunk id of %0X\n",temp_int);
  1467.                       #endif
  1468.                       tellertje+=ReadRGBColor ();
  1469.                       break;
  1470.         case COL_TRU :
  1471.                       #ifdef __DEBUG__
  1472.                       printf (">>>> Found Color def (24bit) chunk id of %0X\n",temp_int);
  1473.                       #endif
  1474.                       tellertje+=ReadTrueColor ();
  1475.                       break;
  1476.         default:      break;
  1477.        }
  1478.  
  1479.    tellertje+=2;
  1480.    if (tellertje>=temp_pointer)
  1481.      end_found=TRUE;
  1482.  }
  1483.  
  1484.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1485.  return (temp_pointer);
  1486. }
  1487. /*----------------------------------------------------------------------------*/
  1488. unsigned long FindCameraChunk (void)
  1489. {
  1490.  long temp_pointer=0L;
  1491.  
  1492.  for (int i=0;i<12;i++)
  1493.   ReadInt ();
  1494.  
  1495.  temp_pointer=11L;
  1496.  temp_pointer=ReadName ();
  1497.  
  1498.  #ifdef __DEBUG__
  1499.  if (temp_pointer==-1)
  1500.    printf (">>>>* No Camera name found\n");
  1501.  #endif
  1502.  
  1503.  return (temp_pointer);
  1504. }
  1505. /*----------------------------------------------------------------------------*/
  1506. unsigned long ReadViewPortChunk (void)
  1507. {
  1508.  unsigned long current_pointer;
  1509.  unsigned long temp_pointer;
  1510.  unsigned int port,attribs;
  1511.  
  1512.  views_read++;
  1513.  
  1514.  current_pointer=GetChunkPointer ();
  1515.  temp_pointer   =ReadChunkPointer ();
  1516.  
  1517.  attribs=ReadInt ();
  1518.  if (attribs==3)
  1519.  {
  1520.   #ifdef __DEBUG__
  1521.   printf ("<Snap> active in viewport\n");
  1522.   #endif
  1523.  }
  1524.  if (attribs==5)
  1525.  {
  1526.   #ifdef __DEBUG__
  1527.   printf ("<Grid> active in viewport\n");
  1528.   #endif
  1529.  }
  1530.  
  1531.  for (int i=1;i<6;i++) ReadInt (); // read 5 ints to get to the viewport
  1532.  
  1533.  port=ReadInt ();
  1534.  if ((port==0xFFFF) || (port==0))
  1535.  {
  1536.    FindCameraChunk ();
  1537.    port=CAMERA;
  1538.  }
  1539.  
  1540.  #ifdef __DEBUG__
  1541.  printf ("Reading [%s] information with id:%d\n",viewports [port],port);
  1542.  #endif
  1543.  
  1544.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1545.  return (temp_pointer);
  1546. }
  1547. /*----------------------------------------------------------------------------*/
  1548. unsigned long ReadViewChunk (void)
  1549. {
  1550.  unsigned char end_found=FALSE;
  1551.  unsigned int temp_int;
  1552.  unsigned long current_pointer;
  1553.  unsigned long temp_pointer;
  1554.  unsigned long tellertje=6L;
  1555.  
  1556.  current_pointer=GetChunkPointer ();
  1557.  temp_pointer   =ReadChunkPointer ();
  1558.  
  1559.  while (end_found==FALSE)
  1560.  {
  1561.    temp_int=ReadInt ();
  1562.  
  1563.        switch (temp_int)
  1564.        {
  1565.         case EDIT_VIEW_P1 :
  1566.                            #ifdef __DEBUG__
  1567.                            printf (">>>> Found Viewport1 chunk id of %0X\n",temp_int);
  1568.                            #endif
  1569.                            tellertje+=ReadViewPortChunk ();
  1570.                            break;
  1571.         case EDIT_VIEW_P2 :
  1572.                            #ifdef __DEBUG__
  1573.                            printf (">>>> Found Viewport2 (bogus) chunk id of %0X\n",temp_int);
  1574.                            #endif
  1575.                            tellertje+=ReadUnknownChunk (EDIT_VIEW_P2);
  1576.                            break;
  1577.        case EDIT_VIEW_P3 :
  1578.                            #ifdef __DEBUG__
  1579.                            printf (">>>> Found Viewport chunk id of %0X\n",temp_int);
  1580.                            #endif
  1581.                            tellertje+=ReadViewPortChunk ();
  1582.                            break;
  1583.         default           :break;
  1584.        }
  1585.  
  1586.    tellertje+=2;
  1587.    if (tellertje>=temp_pointer)
  1588.      end_found=TRUE;
  1589.  
  1590.    if (views_read>3)
  1591.      end_found=TRUE;
  1592.  }
  1593.  
  1594.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1595.  return (temp_pointer);
  1596. }
  1597. /*----------------------------------------------------------------------------*/
  1598. unsigned long ReadMatDefChunk (void)
  1599. {
  1600.  unsigned long current_pointer;
  1601.  unsigned long temp_pointer;
  1602.  
  1603.  current_pointer=GetChunkPointer ();
  1604.  temp_pointer   =ReadChunkPointer ();
  1605.  
  1606.  if (ReadLongName ()==-1)
  1607.  {
  1608.    #ifdef __DEBUG__
  1609.    printf (">>>>* No Material name found\n");
  1610.    #endif
  1611.  }
  1612.  
  1613.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1614.  return (temp_pointer);
  1615. }
  1616. /*----------------------------------------------------------------------------*/
  1617. unsigned long ReadMaterialChunk (void)
  1618. {
  1619.  unsigned char end_found=FALSE;
  1620.  unsigned int temp_int;
  1621.  unsigned long current_pointer;
  1622.  unsigned long temp_pointer;
  1623.  unsigned long tellertje=6L;
  1624.  
  1625.  current_pointer=GetChunkPointer ();
  1626.  temp_pointer   =ReadChunkPointer ();
  1627.  
  1628.  while (end_found==FALSE)
  1629.  {
  1630.    temp_int=ReadInt ();
  1631.  
  1632.        switch (temp_int)
  1633.        {
  1634.         case MAT_NAME01  :
  1635.                           #ifdef __DEBUG__
  1636.                           printf (">>>> Found Material def chunk id of %0X\n",temp_int);
  1637.                           #endif
  1638.                           tellertje+=ReadMatDefChunk ();
  1639.                           break;
  1640.         default:break;
  1641.        }
  1642.  
  1643.    tellertje+=2;
  1644.    if (tellertje>=temp_pointer)
  1645.      end_found=TRUE;
  1646.  }
  1647.  
  1648.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1649.  return (temp_pointer);
  1650. }
  1651. /*----------------------------------------------------------------------------*/
  1652. unsigned long ReadEditChunk (void)
  1653. {
  1654.  unsigned char end_found=FALSE;
  1655.  unsigned int temp_int;
  1656.  unsigned long current_pointer;
  1657.  unsigned long temp_pointer;
  1658.  unsigned long tellertje=6L;
  1659.  
  1660.  current_pointer=GetChunkPointer ();
  1661.  temp_pointer   =ReadChunkPointer ();
  1662.  
  1663.  while (end_found==FALSE)
  1664.  {
  1665.    temp_int=ReadInt ();
  1666.  
  1667.        switch (temp_int)
  1668.        {
  1669.         case EDIT_UNKNW01:tellertje+=ReadUnknownChunk (EDIT_UNKNW01);break;
  1670.         case EDIT_UNKNW02:tellertje+=ReadUnknownChunk (EDIT_UNKNW02);break;
  1671.         case EDIT_UNKNW03:tellertje+=ReadUnknownChunk (EDIT_UNKNW03);break;
  1672.         case EDIT_UNKNW04:tellertje+=ReadUnknownChunk (EDIT_UNKNW04);break;
  1673.         case EDIT_UNKNW05:tellertje+=ReadUnknownChunk (EDIT_UNKNW05);break;
  1674.         case EDIT_UNKNW06:tellertje+=ReadUnknownChunk (EDIT_UNKNW06);break;
  1675.         case EDIT_UNKNW07:tellertje+=ReadUnknownChunk (EDIT_UNKNW07);break;
  1676.         case EDIT_UNKNW08:tellertje+=ReadUnknownChunk (EDIT_UNKNW08);break;
  1677.         case EDIT_UNKNW09:tellertje+=ReadUnknownChunk (EDIT_UNKNW09);break;
  1678.         case EDIT_UNKNW10:tellertje+=ReadUnknownChunk (EDIT_UNKNW10);break;
  1679.         case EDIT_UNKNW11:tellertje+=ReadUnknownChunk (EDIT_UNKNW11);break;
  1680.         case EDIT_UNKNW12:tellertje+=ReadUnknownChunk (EDIT_UNKNW12);break;
  1681.         case EDIT_UNKNW13:tellertje+=ReadUnknownChunk (EDIT_UNKNW13);break;
  1682.  
  1683.         case EDIT_MATERIAL :
  1684.                             #ifdef __DEBUG__
  1685.                             printf (">>> Found Materials chunk id of %0X\n",temp_int);
  1686.                             #endif
  1687.                             tellertje+=ReadMaterialChunk ();
  1688.                             break;
  1689.         case EDIT_VIEW1    :
  1690.                             #ifdef __DEBUG__
  1691.                             printf (">>> Found View main def chunk id of %0X\n",temp_int);
  1692.                             #endif
  1693.                             tellertje+=ReadViewChunk ();
  1694.                             break;
  1695.         case EDIT_BACKGR   :
  1696.                             #ifdef __DEBUG__
  1697.                             printf (">>> Found Backgr chunk id of %0X\n",temp_int);
  1698.                             #endif
  1699.                             tellertje+=ReadBackgrChunk ();
  1700.                             break;
  1701.         case EDIT_AMBIENT  :
  1702.                             #ifdef __DEBUG__
  1703.                             printf (">>> Found Ambient chunk id of %0X\n",temp_int);
  1704.                             #endif
  1705.                             tellertje+=ReadAmbientChunk ();
  1706.                             break;
  1707.         case EDIT_OBJECT   :
  1708.                             #ifdef __DEBUG__
  1709.                             printf (">>> Found Object chunk id of %0X\n",temp_int);
  1710.                             #endif
  1711.                             tellertje+=ReadObjectChunk ();
  1712.                             break;
  1713.         default:            break;
  1714.        }
  1715.  
  1716.    tellertje+=2;
  1717.    if (tellertje>=temp_pointer)
  1718.      end_found=TRUE;
  1719.  }
  1720.  
  1721.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1722.  return (temp_pointer);
  1723. }
  1724. /*----------------------------------------------------------------------------*/
  1725. unsigned long ReadKeyfChunk (void)
  1726. {
  1727.  unsigned char end_found=FALSE;
  1728.  unsigned int temp_int;
  1729.  unsigned long current_pointer;
  1730.  unsigned long temp_pointer;
  1731.  unsigned long tellertje=6L;
  1732.  
  1733.  current_pointer=GetChunkPointer ();
  1734.  temp_pointer   =ReadChunkPointer ();
  1735.  
  1736.  while (end_found==FALSE)
  1737.  {
  1738.    temp_int=ReadInt ();
  1739.  
  1740.        switch (temp_int)
  1741.        {
  1742.         case KEYF_UNKNWN01 :tellertje+=ReadUnknownChunk (temp_int);break;
  1743.         case KEYF_UNKNWN02 :tellertje+=ReadUnknownChunk (temp_int);break;
  1744.         case KEYF_FRAMES   :
  1745.                             #ifdef __DEBUG__
  1746.                             printf (">>> Found Keyframer frames chunk id of %0X\n",temp_int);
  1747.                             #endif
  1748.                             tellertje+=ReadUnknownChunk (temp_int);
  1749.                             break;
  1750.         case KEYF_OBJDES   :
  1751.                             #ifdef __DEBUG__
  1752.                             printf (">>> Found Keyframer object description chunk id of %0X\n",temp_int);
  1753.                             #endif
  1754.                             tellertje+=ReadUnknownChunk (temp_int);
  1755.                             break;
  1756.         case EDIT_VIEW1    :
  1757.                             #ifdef __DEBUG__
  1758.                             printf (">>> Found View main def chunk id of %0X\n",temp_int);
  1759.                             #endif
  1760.                             tellertje+=ReadViewChunk ();
  1761.                             break;
  1762.         default:            break;
  1763.        }
  1764.  
  1765.    tellertje+=2;
  1766.    if (tellertje>=temp_pointer)
  1767.      end_found=TRUE;
  1768.  }
  1769.  
  1770.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1771.  return (temp_pointer);
  1772. }
  1773. /*----------------------------------------------------------------------------*/
  1774. unsigned long ReadMainChunk (void)
  1775. {
  1776.  unsigned char end_found=FALSE;
  1777.  unsigned int temp_int;
  1778.  unsigned long current_pointer;
  1779.  unsigned long temp_pointer;
  1780.  unsigned long tellertje=6L;
  1781.  
  1782.  current_pointer=GetChunkPointer ();
  1783.  temp_pointer   =ReadChunkPointer ();
  1784.  
  1785.  while (end_found==FALSE)
  1786.  {
  1787.    temp_int=ReadInt ();
  1788.  
  1789.        switch (temp_int)
  1790.        {
  1791.         case KEYF3DS :
  1792.                       #ifdef __DEBUG__
  1793.                       printf (">> Found *Keyframer* chunk id of %0X\n",KEYF3DS);
  1794.                       #endif
  1795.                       tellertje+=ReadKeyfChunk ();
  1796.                       break;
  1797.         case EDIT3DS :
  1798.                       #ifdef __DEBUG__
  1799.                       printf (">> Found *Editor* chunk id of %0X\n",EDIT3DS);
  1800.                       #endif
  1801.                       tellertje+=ReadEditChunk ();
  1802.                       break;
  1803.         default:      break;
  1804.        }
  1805.  
  1806.    tellertje+=2;
  1807.    if (tellertje>=temp_pointer)
  1808.     end_found=TRUE;
  1809.  }
  1810.  
  1811.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1812.  return (temp_pointer);
  1813. }
  1814. /*----------------------------------------------------------------------------*/
  1815. int ReadPrimaryChunk (void)
  1816. {
  1817.  unsigned char version;
  1818.  
  1819.  if (ReadInt ()==MAIN3DS)
  1820.  {
  1821.   #ifdef __DEBUG__
  1822.   printf ("> Found Main chunk id of %0X\n",MAIN3DS);
  1823.   #endif
  1824.   //>---------- find version number
  1825.   fseek (bin3ds,28L,SEEK_SET);
  1826.   version=ReadChar ();
  1827.   if (version<3)
  1828.   {
  1829.    #ifdef __DEBUG__
  1830.    printf ("Sorry this lib can only read 3ds files of version 3.0 and higher\n");
  1831.    printf ("The version of the file you want to read is: %d\n",version);
  1832.    #endif
  1833.    return (1);
  1834.   }
  1835.   fseek (bin3ds,2,SEEK_SET);
  1836.   ReadMainChunk ();
  1837.  }
  1838.  else
  1839.   return (1);
  1840.  
  1841.  return (0);
  1842. }
  1843. /*----------------------------------------------------------------------------*/
  1844. /*                      Test Main for the 3ds-bin lib                         */
  1845. /*----------------------------------------------------------------------------*/
  1846. int main (int argc,char **argv)
  1847. {
  1848.  argc=argc;
  1849.  
  1850.  bin3ds=fopen (argv [1],"rb");
  1851.  if (bin3ds==NULL)
  1852.   return (-1);
  1853.  
  1854.  #ifdef __DEBUG__
  1855.  printf ("\nLoading 3ds binary file : %s\n",argv [1]);
  1856.  #endif
  1857.  while (ReadPrimaryChunk ()==0);
  1858.  
  1859.  return (0);
  1860. }
  1861. /*----------------------------------------------------------------------------*/
  1862. #endif