1 // -*-c++-*-
2 
3 /*
4  * $Id$
5  *
6  * Loader for DirectX .x files.
7  * Copyright (c)2002-2006 Ulrich Hertlein <u.hertlein@sandbox.de>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23 
24 #ifndef _DX_TYPES_H_
25 #define _DX_TYPES_H_
26 
27 #include <string>
28 #include <vector>
29 #include <fstream>
30 
31 #include <osg/Math>
32 
33 namespace DX {
34 
35     /*
36      * DirectX templates
37      * http://astronomy.swin.edu.au/~pbourke/geomformats/directx/
38      */
39 
40     // Vector
41     typedef struct {
42         float x,y,z;
43 
44         inline void normalize() {
45             float lenRecip = 1.0f / sqrtf(x * x + y * y + z * z);
46             x *= lenRecip;
47             y *= lenRecip;
48             z *= lenRecip;
49         }
50     } Vector;
51 
52     // Coords2d
53     typedef struct {
54         float u,v;
55     } Coords2d;
56 
57     // ColorRGBA
58     typedef struct {
59         float red,green,blue,alpha;
60     } ColorRGBA;
61 
62     // ColorRGB
63     typedef struct {
64         float red,green,blue;
65     } ColorRGB;
66 
67     // IndexedColor
68     typedef struct {
69         unsigned int index;
70         ColorRGBA indexColor;
71     } IndexedColor;
72 
73     // TextureFilename
74     typedef std::string TextureFilename;
75 
76     // Material (potentially with multiple textures)
77     typedef struct {
78         // dgm - materials can have names for later reference
79         std::string name;
80         ColorRGBA faceColor;
81         float power;
82         ColorRGB specularColor;
83         ColorRGB emissiveColor;
84         std::vector<TextureFilename> texture;
85     } Material;
86 
87     // MeshFace
88     typedef std::vector<unsigned int> MeshFace;
89 
90     // MeshTextureCoords
91     typedef std::vector<Coords2d> MeshTextureCoords;
92 
93     // MeshNormals
94     typedef struct {
95         std::vector<Vector> normals;
byte_classes(&self) -> &ByteClasses96         std::vector<MeshFace> faceNormals;
97     } MeshNormals;
98 
99     // MeshVertexColors.
100     typedef std::vector<IndexedColor> MeshVertexColors;
prefilter_obj(&self) -> Option<&PrefilterObj>101 
102     // MeshMaterialList
103     typedef struct {
104         std::vector<unsigned int> faceIndices;
105         std::vector<Material> material;
106     } MeshMaterialList;
heap_bytes(&self) -> usize107 
108     /// Tokenize a string.
109     extern void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = " \t\r\n;,");
110 
111     /// Parse 'Material'.
112     extern void parseMaterial(std::istream& fin, Material& material);
max_pattern_len(&self) -> usize113 
114     /// Read 'TextureFilename'.
115     extern void readTexFilename(std::istream& fin, TextureFilename& texture);
116 
117     /// Read 'Coords2d'.
pattern_count(&self) -> usize118     extern void readCoords2d(std::istream& fin, std::vector<Coords2d>& v, unsigned int count);
119 
120     // Read 'Vector'
121     extern void readVector(std::istream& fin, std::vector<Vector>& v, unsigned int count);
122 
state_len(&self) -> usize123     /// Read index list.
124     extern void readIndexList(std::istream& fin, std::vector<unsigned int>& v, unsigned int count);
125 
126     /// Read 'MeshFace'.
127     extern void readMeshFace(std::istream& fin, std::vector<MeshFace>& v, unsigned int count);
matches(&self, id: S) -> &[(PatternID, PatternLength)]128 
129 } // namespace
130 
131 #endif
132