00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "ac3dsurface.h"
00020
00021 #include "macros.h"
00022 #include "ac3dmacros.h"
00023
00024 #include <cstring>
00025
00026 namespace AC3D {
00027
00028
00029
00030 AC3DSurface::AC3DSurface():
00031 uiAttribute(0)
00032 {
00033 OPENCITY_DEBUG("ctor1");
00034 }
00035
00036
00037
00038 AC3DSurface::AC3DSurface
00039 (
00040 stringstream& data
00041 ):
00042 uiAttribute(0)
00043 {
00044
00045
00046 this->Parse( data );
00047 }
00048
00049
00050
00051 AC3DSurface::~AC3DSurface()
00052 {
00053 }
00054
00055
00056
00057 const unsigned int
00058 AC3DSurface::GetMat() const
00059 {
00060 return this->uiMat;
00061 }
00062
00063
00064
00065 const vector<Ref>&
00066 AC3DSurface::GetVRef() const
00067 {
00068 return this->vRef;
00069 }
00070
00071
00072
00073 void
00074 AC3DSurface::Parse
00075 (
00076 stringstream& data
00077 )
00078 {
00079 char line[AC3D_MAX_LINE_LENGTH];
00080 unsigned int numRef;
00081 bool end;
00082 Ref newRef;
00083
00084
00085
00086 data.getline( line, AC3D_MAX_LINE_LENGTH );
00087 end = false;
00088 while (data.good() && !end) {
00089 if ( strncmp( line, AC3D_TOKEN_SURF, AC3D_TOKEN_SURF_L ) == 0 ) {
00090 sscanf( line, "SURF %x", &(this->uiAttribute));
00091 this->type = (SURFACE_TYPE)(this->uiAttribute & 0xF);
00092 this->bShaded = this->uiAttribute & 0x10;
00093 this->bTwoSide = this->uiAttribute & 0x20;
00094 data.getline( line, AC3D_MAX_LINE_LENGTH );
00095 } else
00096 if ( strncmp( line, AC3D_TOKEN_MAT, AC3D_TOKEN_MAT_L ) == 0 ) {
00097 sscanf( line, "mat %u", &(this->uiMat) );
00098 data.getline( line, AC3D_MAX_LINE_LENGTH );
00099 } else
00100 if ( strncmp( line, AC3D_TOKEN_REFS, AC3D_TOKEN_REFS_L ) == 0 ) {
00101 sscanf( line, "refs %u", &(this->uiNumRef) );
00102
00103
00104 numRef = this->uiNumRef;
00105 data.getline( line, AC3D_MAX_LINE_LENGTH );
00106 while (data.good() && (numRef-- > 0)) {
00107 sscanf(
00108 line,
00109 "%u %f %f",
00110 &newRef.uiVertIndex, &newRef.fTexS, &newRef.fTexT
00111 );
00112 this->vRef.push_back( newRef );
00113 data.getline( line, AC3D_MAX_LINE_LENGTH );
00114 }
00115 end = true;
00116 }
00117 }
00118
00119 data.clear();
00120 }
00121
00122
00123
00124 string
00125 AC3DSurface::ToStr() const
00126 {
00127 stringstream ss;
00128 vector<Ref>::size_type pos, size;
00129
00130 ss.flags( stringstream::hex );
00131 ss << "SURF 0x" << this->uiAttribute << endl;
00132 ss.flags( stringstream::dec );
00133
00134 ss << "mat " << this->uiMat << endl
00135 << "refs " << this->uiNumRef << endl;
00136
00137 size = this->vRef.size();
00138 for (pos = 0; pos < size; pos++ ) {
00139 ss << vRef[pos].uiVertIndex << " "
00140 << vRef[pos].fTexS << " "
00141 << vRef[pos].fTexT << endl;
00142 }
00143
00144 return ss.str();
00145 }
00146
00147
00148
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177