Changeset 13041 for OpenSceneGraph/trunk/src/osgPlugins/ac/ac3d.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgPlugins/ac/ac3d.cpp (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/ac/ac3d.cpp
r11498 r13041 71 71 { 72 72 public: 73 73 74 74 ReaderWriterAC() 75 75 { 76 76 supportsExtension("ac","AC3D Database format"); 77 77 } 78 78 79 79 virtual const char* className() const { return "AC3D Database Reader"; } 80 80 … … 87 87 std::string fileName = osgDB::findDataFile( file, options ); 88 88 OSG_INFO << "osgDB ac3d reader: starting reading \"" << fileName << "\"" << std::endl; 89 89 90 90 // Anders Backmann - correct return if path not found 91 91 if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; … … 97 97 98 98 // code for setting up the database path so that internally referenced file are 99 // searched for on relative paths. 99 // searched for on relative paths. 100 100 osg::ref_ptr<Options> local_opt; 101 101 if (options) … … 163 163 return WriteResult::FILE_SAVED; 164 164 } 165 165 166 166 virtual WriteResult writeNode(const osg::Node& node,std::ostream& fout, const Options* opts) const 167 167 { … … 178 178 else 179 179 OSG_WARN<<"File must start with a geode "<<std::endl; 180 180 181 181 fout.flush(); 182 182 return WriteResult::FILE_SAVED; … … 221 221 { 222 222 // look for quoted strings 223 223 224 224 // throw away the quote 225 225 stream.get(); 226 226 227 227 // extract characters until either an error happens or a quote is found 228 228 while (stream.good()) … … 235 235 } 236 236 } 237 237 238 238 return s; 239 239 } … … 788 788 }; 789 789 std::vector<Ref> _refs; 790 790 791 791 struct TriangleData { 792 792 VertexIndex index[3]; 793 793 }; 794 794 std::vector<TriangleData> _triangles; 795 795 796 796 struct QuadData { 797 797 VertexIndex index[4]; … … 869 869 weightedNormal += newNormal; 870 870 } 871 871 872 872 if (needTessellation) 873 873 { … … 948 948 shadeModel->setMode(osg::ShadeModel::FLAT); 949 949 stateSet->setAttribute(shadeModel); 950 950 951 951 // Set up the arrays, allways store texture coords, may be we need them later ... 952 952 osg::Geometry* geometry = new osg::Geometry; … … 1139 1139 float creaseAngle = 61; 1140 1140 unsigned objectType = ObjectTypeGroup; 1141 1141 1142 1142 while (!stream.eof() && stream.good()) { 1143 1143 std::string token; 1144 1144 stream >> token; 1145 1145 1146 1146 if (token == "MATERIAL") { 1147 1147 MaterialData mat; … … 1152 1152 std::string type; 1153 1153 stream >> type; 1154 1154 1155 1155 if (type == "group") 1156 1156 objectType = ObjectTypeGroup; … … 1204 1204 else if (token == "numvert") { 1205 1205 osg::Matrix currentTransform = transform*parentTransform; 1206 1206 1207 1207 unsigned num; 1208 1208 stream >> num; 1209 1209 if (num != 0) { 1210 1210 vertexSet->reserve(num); 1211 1211 1212 1212 for (unsigned n = 0; n < num; ++n) { 1213 1213 osg::Vec3 p; … … 1224 1224 std::vector<Bins> primitiveBins(fileData.getNumMaterials()); 1225 1225 vertexSet->setCreaseAngle(creaseAngle); 1226 1226 1227 1227 for (unsigned n = 0; n < num; ++n) { 1228 1228 std::string token; 1229 1229 stream >> token; 1230 1230 1231 1231 if (token != "SURF") { 1232 1232 OSG_FATAL << "osgDB ac3d reader: expected SURF line while reading object \"" … … 1234 1234 return group.release(); 1235 1235 } 1236 1236 1237 1237 stream >> token; 1238 1238 unsigned flags = strtol(token.c_str(), NULL, 0); 1239 1239 1240 1240 stream >> token; 1241 1241 if (token != "mat") { … … 1244 1244 return group.release(); 1245 1245 } 1246 1246 1247 1247 // read the material index 1248 1248 unsigned matIdx; … … 1253 1253 return group.release(); 1254 1254 } 1255 1255 1256 1256 // now get the correct PrimitiveBin 1257 1257 PrimitiveBin* primitiveBin = 0; … … 1262 1262 return group.release(); 1263 1263 } 1264 1264 1265 1265 // read the refs 1266 1266 stream >> token; … … 1270 1270 return group.release(); 1271 1271 } 1272 1272 1273 1273 unsigned nRefs = 0; 1274 1274 stream >> nRefs; … … 1278 1278 return group.release(); 1279 1279 } 1280 1280 1281 1281 // in case this is an invalid refs count for this primitive 1282 1282 // read further, but do not store that primitive … … 1292 1292 return group.release(); 1293 1293 } 1294 1294 1295 1295 // Read the texture corrdinates 1296 1296 osg::Vec2 texCoord; … … 1303 1303 std::getline(stream, dummy); 1304 1304 } 1305 1305 1306 1306 if (acceptPrimitive) 1307 1307 { 1308 1308 texCoord[0] = textureOffset[0] + texCoord[0]*textureRepeat[0]; 1309 1309 texCoord[1] = textureOffset[1] + texCoord[1]*textureRepeat[1]; 1310 1310 1311 1311 if (!primitiveBin->vertex(index, texCoord)) 1312 1312 { … … 1323 1323 } 1324 1324 } 1325 1325 1326 1326 for (unsigned i = 0; i < primitiveBins.size(); ++i) 1327 1327 primitiveBins[i].finalize(group.get(), fileData.getMaterial(i), textureData); … … 1346 1346 ls->setStateSetModes(*lightStateSet, osg::StateAttribute::ON); 1347 1347 } 1348 1348 1349 1349 group->addChild(k); 1350 1350 } … … 1359 1359 ac3dLight->setDiffuse(osg::Vec4(0.5f,0.5f,0.5f,1.0f)); 1360 1360 ac3dLight->setSpecular(osg::Vec4(1.0f,1.0f,0.5f,1.0f)); 1361 1361 1362 1362 osg::LightSource* ac3dLightSource = new osg::LightSource; 1363 1363 ac3dLightSource->setDataVariance(osg::Object::STATIC); 1364 1364 ac3dLightSource->setLight(ac3dLight); 1365 1365 ac3dLightSource->setLocalStateSetModes(osg::StateAttribute::ON); 1366 1366 1367 1367 // for some mad reason, you need to set this so that the light works. WHY? 1368 1368 return ac3dLightSource; … … 1371 1371 } 1372 1372 } 1373 1373 1374 1374 return group.release(); 1375 1375 }
