OSGRAWSceneFileType.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045
00046 #include "OSGConfig.h"
00047
00048 #include <iostream>
00049 #include <fstream>
00050
00051 #include "OSGLog.h"
00052
00053 #include "OSGNode.h"
00054 #include "OSGGeometry.h"
00055 #include "OSGSimpleMaterial.h"
00056 #include "OSGTypedGeoIntegralProperty.h"
00057
00058 #include "OSGRAWSceneFileType.h"
00059
00060 OSG_USING_NAMESPACE
00061
00062 #if defined(OSG_WIN32_ICL) && !defined(OSG_CHECK_FIELDSETARG)
00063 #pragma warning (disable : 383)
00064 #endif
00065
00066
00072
00073
00074
00075
00076
00077 const Char8 *RAWSceneFileType::_suffixA[] = {"raw"};
00078
00079
00080 RAWSceneFileType RAWSceneFileType::_the(_suffixA,
00081 sizeof(_suffixA),
00082 false,
00083 10,
00084 SceneFileType::OSG_READ_SUPPORTED);
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 #ifdef __sgi
00122 #pragma set woff 1209
00123 #endif
00124
00125 NodeTransitPtr RAWSceneFileType::read( std::istream &is,
00126 const Char8 *,
00127 Resolver ) const
00128 {
00129 NodeTransitPtr root;
00130 GeometryUnrecPtr geo;
00131 GeoPnt3rPropertyUnrecPtr points;
00132 GeoVec3rPropertyUnrecPtr normals;
00133 GeoIntegralPropertyUnrecPtr index;
00134 GeoIntegralPropertyUnrecPtr lens;
00135 GeoIntegralPropertyUnrecPtr type;
00136
00137 Vec3r vec[3];
00138
00139 UInt32 i = 0, n, triCount = 0;
00140
00141 Real32 x,y,z;
00142
00143 if(is)
00144 {
00145 root = Node ::create();
00146 geo = Geometry::create();
00147
00148 root->setCore( geo );
00149
00150 points = GeoPnt3rProperty::create();
00151
00152 geo->setPositions(points);
00153
00154 normals = GeoVec3rProperty::create();
00155
00156 geo->setNormals(normals);
00157
00158 triCount = i = 0;
00159
00160
00161 while(1)
00162 {
00163 is >> x >> y >> z;
00164
00165 if(is.eof())
00166 {
00167 break;
00168 }
00169 else
00170 {
00171 points->editFieldPtr()->push_back(Pnt3r(x, y, z));
00172
00173 vec[i].setValues(x,y,z);
00174
00175 std::cerr << x << " " << y << " " << z << std::endl;
00176
00177 if(i == 2)
00178 {
00179 vec[0] -= vec[1];
00180 vec[1] -= vec[2];
00181 vec[0].crossThis(vec[1]);
00182 vec[0].normalize();
00183
00184 normals->editFieldPtr()->push_back(vec[0]);
00185 normals->editFieldPtr()->push_back(vec[0]);
00186 normals->editFieldPtr()->push_back(vec[0]);
00187
00188 i = 0;
00189 triCount++;
00190 }
00191 else
00192 {
00193 i++;
00194 }
00195 }
00196 }
00197
00198 if(triCount != 0)
00199 {
00200 index = GeoUIntProperty::create();
00201
00202 geo->setIndex(index, Geometry::PositionsIndex);
00203 geo->setIndex(index, Geometry::NormalsIndex );
00204
00205 n = triCount * 3;
00206
00207 for(i = 0; i < n; i++)
00208 index->push_back(i);
00209
00210
00211
00212 lens = GeoUIntProperty::create();
00213
00214 geo->setLengths(lens);
00215
00216 lens->push_back(n);
00217
00218 type = GeoUInt8Property::create();
00219
00220 geo->setTypes(type);
00221
00222 type->push_back(GL_TRIANGLES);
00223 }
00224
00225 SimpleMaterialUnrecPtr mat = SimpleMaterial::create();
00226
00227 mat->setDiffuse (Color3r( .8f, .8f, .8f));
00228 mat->setSpecular (Color3r( 1.f, 1.f, 1.f ));
00229 mat->setShininess(20.f );
00230
00231 geo->setMaterial(mat);
00232 }
00233
00234 if(triCount)
00235 {
00236 SNOTICE << triCount << " triangle read " << std::endl;
00237 }
00238
00239 return root;
00240 }
00241
00242 #ifdef __sgi
00243 #pragma reset woff 1209
00244 #endif
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00269 RAWSceneFileType::RAWSceneFileType(const Char8 *suffixArray[],
00270 UInt16 suffixByteCount,
00271 bool override,
00272 UInt32 overridePriority,
00273 UInt32 flags) :
00274 SceneFileType(suffixArray,
00275 suffixByteCount,
00276 override,
00277 overridePriority,
00278 flags)
00279 {
00280 }
00281
00282 RAWSceneFileType &RAWSceneFileType::the(void)
00283 {
00284 return _the;
00285 }
00286
00287 const Char8 *RAWSceneFileType::getName(void) const
00288 {
00289 return "RAW Geometry";
00290 }
00291
00292
00293 RAWSceneFileType::~RAWSceneFileType (void )
00294 {
00295 return;
00296 }
00297
00298