#include <OSGOBJSceneFileType.h>

Public Types | |
| typedef std::vector < FieldContainerPtr > | FCPtrStore |
Flags | |
| enum | { OSG_READ_SUPPORTED = 1, OSG_WRITE_SUPPORTED = 2 } |
Public Member Functions | |
Destructors | |
| virtual | ~OBJSceneFileType (void) |
Get | |
| virtual const Char8 * | getName (void) const |
Read | |
| virtual NodePtr | read (std::istream &is, const Char8 *fileNameOrExtension) const |
Write | |
| virtual bool | write (const NodePtr &node, std::ostream &os, const Char8 *fileNameOrExtension) const |
Set | |
| void | setOptions (const Char8 *options) |
Get | |
| virtual std::list< IDString > & | suffixList (void) |
| bool | doOverride (void) |
| UInt32 | getOverridePriority (void) |
| UInt32 | getFlags (void) |
| const Char8 * | getOptions (void) |
Read | |
| virtual NodePtr | readFile (const Char8 *fileName) const |
Write | |
| virtual bool | writeFile (const NodePtr &node, const Char8 *fileName) const |
Debug | |
| void | print (void) |
Static Public Member Functions | |
Class Get | |
| static OBJSceneFileType & | the (void) |
Protected Member Functions | |
Constructors | |
| OBJSceneFileType (const Char8 *suffixArray[], UInt16 suffixByteCount, bool override, UInt32 overridePriority, UInt32 flags) | |
| OBJSceneFileType (const OBJSceneFileType &obj) | |
Protected Attributes | |
Member | |
| std::list< IDString > | _suffixList |
| bool | _override |
| UInt32 | _overridePriority |
| UInt32 | _flags |
| std::string | _options |
Static Protected Attributes | |
Member | |
| static const Char8 * | _suffixA [] = { "obj" } |
| static OBJSceneFileType | _the |
Private Types | |
| enum | DataElem { UNKNOWN_DE = 0, VERTEX_DE, VERTEX_TEXTURECOORD_DE, VERTEX_NORMAL_DE, FACE_DE, LIB_MTL_DE, USE_MTL_DE, GROUP_DE, SMOOTHING_GROUP_DE, OBJECT_DE } |
| enum | MaterialElem { UNKNOWN_ME = 0, NEW_MTL_ME, MTL_DIFFUSE_ME, MTL_AMBIENT_ME, MTL_SPECULAR_ME, MTL_SHININESS_ME, MTL_ILLUM_ME, MTL_TRANSPARENCY_ME, MTL_DISSOLVE_ME, MTL_MAP_KD_ME, MTL_MAP_KA_ME, MTL_MAP_KS_ME, MTL_REFL_ME } |
| typedef SceneFileType | Inherited |
Private Member Functions | |
| void | initElemMap (void) |
| Int32 | readMTL (const Char8 *fileName, std::map< std::string, SimpleTexturedMaterialPtr > &mtlMap) const |
| void | write (const NodePtr &node, std::ostream &os, UInt32 &pIndex, UInt32 &nIndex, UInt32 &tIndex) const |
| void | operator= (const OBJSceneFileType &source) |
Private Attributes | |
| std::map< std::string, DataElem > | _dataElemMap |
| std::map< std::string, MaterialElem > | _mtlElemMap |
Friends | |
| class | Mesh |
| class | Face |
Classes | |
| struct | Face |
| struct | Mesh |
| struct | TiePoint |
Definition at line 57 of file OSGOBJSceneFileType.h.
typedef SceneFileType osg::OBJSceneFileType::Inherited [private] |
Definition at line 126 of file OSGOBJSceneFileType.h.
typedef std::vector<FieldContainerPtr> osg::SceneFileType::FCPtrStore [inherited] |
Reimplemented in osg::OSGSceneFileType, and osg::VRMLSceneFileType.
Definition at line 65 of file OSGSceneFileType.h.
enum osg::OBJSceneFileType::DataElem [private] |
| UNKNOWN_DE | |
| VERTEX_DE | |
| VERTEX_TEXTURECOORD_DE | |
| VERTEX_NORMAL_DE | |
| FACE_DE | |
| LIB_MTL_DE | |
| USE_MTL_DE | |
| GROUP_DE | |
| SMOOTHING_GROUP_DE | |
| OBJECT_DE |
Definition at line 128 of file OSGOBJSceneFileType.h.
00129 { 00130 UNKNOWN_DE = 0, 00131 00132 VERTEX_DE, VERTEX_TEXTURECOORD_DE, VERTEX_NORMAL_DE, 00133 FACE_DE, 00134 00135 LIB_MTL_DE, 00136 USE_MTL_DE, 00137 00138 GROUP_DE, SMOOTHING_GROUP_DE, OBJECT_DE 00139 };
enum osg::OBJSceneFileType::MaterialElem [private] |
| UNKNOWN_ME | |
| NEW_MTL_ME | |
| MTL_DIFFUSE_ME | |
| MTL_AMBIENT_ME | |
| MTL_SPECULAR_ME | |
| MTL_SHININESS_ME | |
| MTL_ILLUM_ME | |
| MTL_TRANSPARENCY_ME | |
| MTL_DISSOLVE_ME | |
| MTL_MAP_KD_ME | |
| MTL_MAP_KA_ME | |
| MTL_MAP_KS_ME | |
| MTL_REFL_ME |
Definition at line 143 of file OSGOBJSceneFileType.h.
00144 { 00145 UNKNOWN_ME = 0, 00146 00147 NEW_MTL_ME, 00148 MTL_DIFFUSE_ME, MTL_AMBIENT_ME, MTL_SPECULAR_ME, 00149 MTL_SHININESS_ME, MTL_ILLUM_ME, 00150 MTL_TRANSPARENCY_ME, MTL_DISSOLVE_ME, 00151 MTL_MAP_KD_ME, MTL_MAP_KA_ME, MTL_MAP_KS_ME, 00152 MTL_REFL_ME 00153 };
anonymous enum [inherited] |
Definition at line 78 of file OSGSceneFileType.h.
00079 { 00080 OSG_READ_SUPPORTED = 1, 00081 OSG_WRITE_SUPPORTED = 2 00082 };
| OBJSceneFileType::~OBJSceneFileType | ( | void | ) | [virtual] |
| OBJSceneFileType::OBJSceneFileType | ( | const Char8 * | suffixArray[], | |
| UInt16 | suffixByteCount, | |||
| bool | override, | |||
| UInt32 | overridePriority, | |||
| UInt32 | flags | |||
| ) | [protected] |
constructors & destructors
Definition at line 631 of file OSGOBJSceneFileType.cpp.
References initElemMap().
00635 : 00636 SceneFileType(suffixArray, 00637 suffixByteCount, 00638 override, 00639 overridePriority, 00640 flags), 00641 _dataElemMap() 00642 00643 { 00644 initElemMap(); 00645 }
| OBJSceneFileType::OBJSceneFileType | ( | const OBJSceneFileType & | obj | ) | [protected] |
constructors & destructors
Definition at line 668 of file OSGOBJSceneFileType.cpp.
References initElemMap().
00668 : 00669 SceneFileType(obj) 00670 { 00671 initElemMap(); 00672 }
| OBJSceneFileType & OBJSceneFileType::the | ( | void | ) | [static] |
Definition at line 695 of file OSGOBJSceneFileType.cpp.
References _the.
00696 { 00697 return _the; 00698 }
| const Char8 * OBJSceneFileType::getName | ( | void | ) | const [virtual] |
| NodePtr OBJSceneFileType::read | ( | std::istream & | is, | |
| const Char8 * | fileNameOrExtension | |||
| ) | const [virtual] |
Reimplemented from osg::SceneFileType.
Definition at line 130 of file OSGOBJSceneFileType.cpp.
References _dataElemMap, osg::beginEditCP(), osg::calcVertexNormals(), osg::GroupBase::create(), osg::Node::create(), osg::SimpleTexturedMaterialBase::create(), osg::GeometryBase::create(), osg::GeoProperty< GeoPropertyDesc >::create(), osg::createSharedIndex(), osg::endEditCP(), FACE_DE, FFATAL, FWARNING, GROUP_DE, INT_MAX, LIB_MTL_DE, osg::Geometry::MapNormal, osg::Geometry::MapPosition, osg::Geometry::MapTexCoords, osg::NullFC, OBJECT_DE, readMTL(), SMOOTHING_GROUP_DE, osg::SceneFileHandler::the(), UNKNOWN_DE, osg::SceneFileHandler::updateReadProgress(), USE_MTL_DE, VERTEX_DE, VERTEX_NORMAL_DE, and VERTEX_TEXTURECOORD_DE.
00131 { 00132 NodePtr rootPtr, nodePtr; 00133 std::string elem; 00134 std::map<std::string, DataElem>::const_iterator elemI; 00135 Vec3f vec3f; 00136 Vec2f vec2f; 00137 Real32 x,y,z; 00138 GeoPositionsPtr coordPtr = GeoPositions3f::create(); 00139 GeoTexCoordsPtr texCoordPtr = GeoTexCoords2f::create(); 00140 GeoNormalsPtr normalPtr = GeoNormals3f::create(); 00141 GeometryPtr geoPtr; 00142 GeoIndicesPtr indexPtr; 00143 GeoPLengthsPtr lensPtr; 00144 GeoPTypesPtr typePtr; 00145 DataElem dataElem; 00146 Char8 strBuf[8192], *token, *nextToken; 00147 Int32 strBufSize = sizeof(strBuf)/sizeof(Char8); 00148 Int32 index, posIndex = 0, indexType; 00149 Int32 i,j,n,primCount[3]; 00150 std::list<Mesh> meshList; 00151 std::map<std::string, SimpleTexturedMaterialPtr> mtlMap; 00152 std::map<std::string, SimpleTexturedMaterialPtr>::iterator mtlI; 00153 Mesh emptyMesh; 00154 Face emptyFace; 00155 TiePoint emptyTie; 00156 Int32 indexMask, meshIndexMask; 00157 std::list<Face>::iterator faceI; 00158 std::list<Mesh>::iterator meshI; 00159 bool isSingleIndex; 00160 00161 // create the first mesh entry 00162 meshList.push_back(emptyMesh); 00163 meshI = meshList.begin(); 00164 00165 if(is) 00166 { 00167 primCount[0] = 0; 00168 primCount[1] = 0; 00169 primCount[2] = 0; 00170 00171 beginEditCP(coordPtr); 00172 beginEditCP(texCoordPtr); 00173 beginEditCP(normalPtr); 00174 00175 for (is >> elem; is.eof() == false; is >> elem) 00176 if (elem[0] == '#' || 00177 elem[0] == '$' 00178 ) 00179 is.ignore(INT_MAX, '\n'); 00180 else 00181 { 00182 SceneFileHandler::the().updateReadProgress(); 00183 elemI = _dataElemMap.find(elem); 00184 dataElem = ((elemI == _dataElemMap.end()) ? 00185 UNKNOWN_DE : elemI->second ); 00186 switch (dataElem) 00187 { 00188 case OBJECT_DE: 00189 case GROUP_DE: 00190 case SMOOTHING_GROUP_DE: 00191 is.ignore(INT_MAX, '\n'); 00192 break; 00193 case VERTEX_DE: 00194 primCount[0]++; 00195 is >> x >> y >> z; 00196 vec3f.setValues(x,y,z); 00197 coordPtr->push_back(vec3f); 00198 break; 00199 case VERTEX_TEXTURECOORD_DE: 00200 primCount[1]++; 00201 is >> x >> y; 00202 vec2f.setValues(x,y); 00203 texCoordPtr->push_back(vec2f); 00204 break; 00205 case VERTEX_NORMAL_DE: 00206 primCount[2]++; 00207 is >> x >> y >> z; 00208 vec3f.setValues(x,y,z); 00209 normalPtr->push_back(vec3f); 00210 break; 00211 case LIB_MTL_DE: 00212 is >> elem; 00213 readMTL ( elem.c_str(), mtlMap ); 00214 is.ignore(INT_MAX, '\n'); 00215 break; 00216 case USE_MTL_DE: 00217 is >> elem; 00218 if (meshI->faceList.empty() == false) 00219 { 00220 meshList.push_front(emptyMesh); 00221 meshI = meshList.begin(); 00222 } 00223 mtlI = mtlMap.find(elem); 00224 if (mtlI == mtlMap.end()) 00225 { 00226 FFATAL (("Unkown mtl %s\n", elem.c_str())); 00227 } 00228 else 00229 meshI->mtlPtr = mtlI->second; 00230 break; 00231 case FACE_DE: 00232 meshI->faceList.push_front(emptyFace); 00233 faceI = meshI->faceList.begin(); 00234 is.get(strBuf,strBufSize); 00235 token = strBuf; 00236 indexType = 0; 00237 while (token && *token) 00238 { 00239 for (; *token == '/'; token++) 00240 indexType++; 00241 for (; isspace(*token); token++) 00242 indexType = 0; 00243 index = strtol(token, &nextToken, 10); 00244 if (token == nextToken) 00245 break; 00246 if (indexType == 0) 00247 faceI->tieVec.push_back(emptyTie); 00248 if (index >= 0) 00249 index--; 00250 else 00251 index = primCount[indexType] + index; 00252 faceI->tieVec.back().index[indexType] = index; 00253 token = nextToken; 00254 } 00255 break; 00256 case UNKNOWN_DE: 00257 default: 00258 FWARNING (( "Unkown obj data elem: %s\n", 00259 elem.c_str())); 00260 is.ignore(INT_MAX, '\n'); 00261 break; 00262 } 00263 } 00264 00265 endEditCP(coordPtr); 00266 endEditCP(texCoordPtr); 00267 endEditCP(normalPtr); 00268 00269 #if 0 00270 std::cerr << "------------------------------------------------" << std::endl; 00271 i = 0; 00272 for (meshI = meshList.begin(); meshI != meshList.end(); meshI++) { 00273 std::cerr << "Mesh " << i << " faceCount :" 00274 << meshI->faceList.size() << std::endl; 00275 j = 0 ; 00276 for ( faceI = meshI->faceList.begin(); faceI != meshI->faceList.end(); 00277 faceI++) 00278 std::cerr << "MESH " << i << "face: " << j++ << "tie num: " 00279 << faceI->tieVec.size() << std::endl; 00280 i++; 00281 } 00282 std::cerr << "------------------------------------------------" << std::endl; 00283 ======= 00284 #endif 00285 // create Geometry objects 00286 for (meshI = meshList.begin(); meshI != meshList.end(); meshI++) 00287 { 00288 geoPtr = Geometry::create(); 00289 indexPtr = GeoIndicesUI32::create(); 00290 lensPtr = GeoPLengthsUI32::create(); 00291 typePtr = GeoPTypesUI8::create(); 00292 00293 // create and check mesh index mask 00294 meshIndexMask = 0; 00295 isSingleIndex = true; 00296 if ( meshI->faceList.empty() == false) 00297 for ( faceI = meshI->faceList.begin(); 00298 faceI != meshI->faceList.end(); faceI++) 00299 { 00300 indexMask = 0; 00301 n = faceI->tieVec.size(); 00302 for (i = 0; i < n; i++) 00303 for (j = 0; j < 3; j++) 00304 { 00305 if ((index = (faceI->tieVec[i].index[j])) >= 0) { 00306 indexMask |= (1 << j); 00307 if (j) 00308 isSingleIndex &= (posIndex == index); 00309 else 00310 posIndex = index; 00311 } 00312 } 00313 if (meshIndexMask == 0) 00314 meshIndexMask = indexMask; 00315 else 00316 if (meshIndexMask != indexMask) 00317 { 00318 // consider this real-world example: 00319 // [...] 00320 // f 1603//1747 1679//1744 1678//1743 00321 // s 1 00322 // f 9/1/10 5/2/9 1680/3/1748 1681/4/174 00323 // [...] 00324 // Some faces contain texture coords and others do not. 00325 // The old version did just skip this geometry. 00326 // This version should continue if there's at least 00327 // the vertex index 00328 // I've seen the change in the maskIndex only after a smooth group, 00329 // so it's perhaps smarter to not ignore the smooth group further up in this code 00330 if( !(indexMask & 1) ) { 00331 // if there are vertex indices there's no reason to get in here 00332 FFATAL (( "IndexMask unmatch, can not create geo\n")); 00333 meshIndexMask = 0; 00334 break; 00335 }else{ 00336 // consider the minimum similarities of mesh masks 00337 meshIndexMask &= indexMask; 00338 } 00339 } 00340 } 00341 else 00342 { 00343 FWARNING (("Mesh with empty faceList\n")); 00344 } 00345 00346 // fill the geo properties 00347 if (meshIndexMask) 00348 { 00349 beginEditCP ( geoPtr ); 00350 { 00351 geoPtr->setPositions ( coordPtr ); 00352 geoPtr->setIndices ( indexPtr ); 00353 geoPtr->setLengths ( lensPtr ); 00354 geoPtr->setTypes ( typePtr ); 00355 00356 if ( (meshIndexMask & 2) && texCoordPtr->size() > 0 ) 00357 { 00358 // just make sure that there are tex coords for ALL meshes 00359 geoPtr->setTexCoords ( texCoordPtr ); 00360 } 00361 else 00362 { 00363 geoPtr->setTexCoords ( NullFC ); 00364 meshIndexMask &= ~Geometry::MapTexCoords; 00365 } 00366 00367 if ( (meshIndexMask & 4) && normalPtr->size() > 0 ) 00368 { 00369 // just make sure that there are normals for ALL vertices 00370 geoPtr->setNormals ( normalPtr ); 00371 } 00372 else 00373 { 00374 geoPtr->setNormals ( NullFC ); 00375 meshIndexMask &= ~Geometry::MapNormal; 00376 } 00377 00378 if (isSingleIndex) 00379 { 00380 indexType = 0; 00381 if (meshIndexMask & 1) 00382 indexType |= Geometry::MapPosition; 00383 if (meshIndexMask & 2) 00384 indexType |= Geometry::MapTexCoords; 00385 if (meshIndexMask & 4) 00386 indexType |= Geometry::MapNormal; 00387 geoPtr->getIndexMapping().push_back( indexType ); 00388 } 00389 else 00390 { 00391 if (meshIndexMask & 1) 00392 { 00393 indexType = Geometry::MapPosition; 00394 geoPtr->getIndexMapping().push_back( indexType); 00395 } 00396 if (meshIndexMask & 2) 00397 { 00398 indexType = Geometry::MapTexCoords; 00399 geoPtr->getIndexMapping().push_back( indexType); 00400 } 00401 if (meshIndexMask & 4) 00402 { 00403 indexType = Geometry::MapNormal; 00404 geoPtr->getIndexMapping().push_back( indexType); 00405 } 00406 } 00407 00408 if (meshI->mtlPtr == NullFC) 00409 { 00410 meshI->mtlPtr = SimpleTexturedMaterial::create(); 00411 beginEditCP( meshI->mtlPtr ); 00412 { 00413 meshI->mtlPtr->setDiffuse( Color3f( .8, .8, .8 ) ); 00414 meshI->mtlPtr->setSpecular( Color3f( 1, 1, 1 ) ); 00415 meshI->mtlPtr->setShininess( 20 ); 00416 } 00417 endEditCP( meshI->mtlPtr ); 00418 } 00419 geoPtr->setMaterial ( meshI->mtlPtr ); 00420 } 00421 endEditCP ( geoPtr ); 00422 00423 beginEditCP(lensPtr); 00424 beginEditCP(typePtr); 00425 beginEditCP(indexPtr); 00426 00427 for ( faceI = meshI->faceList.begin(); 00428 faceI != meshI->faceList.end(); faceI++) 00429 { 00430 n = faceI->tieVec.size(); 00431 00432 // add the lens entry 00433 lensPtr->push_back(n); 00434 00435 // add the type entry 00436 typePtr->push_back(GL_POLYGON); 00437 00438 // create the index values 00439 for (i = 0; i < n; i++) 00440 if (isSingleIndex) 00441 indexPtr->push_back( faceI->tieVec[i].index[0]); 00442 else 00443 for (j = 0; j < 3; j++) 00444 if ( meshIndexMask & (1 << j)) 00445 indexPtr->push_back( faceI->tieVec[i].index[j]); 00446 } 00447 00448 endEditCP(indexPtr); 00449 endEditCP(typePtr); 00450 endEditCP(lensPtr); 00451 00452 createSharedIndex( geoPtr ); 00453 00454 // check if we have normals 00455 if ((meshIndexMask & 4) == 0) 00456 calcVertexNormals(geoPtr); 00457 00458 // create and link the node 00459 nodePtr = Node::create(); 00460 beginEditCP ( nodePtr ); 00461 { 00462 nodePtr->setCore( geoPtr ); 00463 } 00464 endEditCP ( nodePtr ); 00465 00466 if (meshList.size() > 1) 00467 { 00468 if (rootPtr == NullFC) 00469 { 00470 rootPtr = Node::create(); 00471 beginEditCP (rootPtr); 00472 { 00473 rootPtr->setCore ( Group::create() ); 00474 rootPtr->addChild(nodePtr); 00475 } 00476 endEditCP (rootPtr); 00477 } 00478 else 00479 { 00480 beginEditCP(rootPtr); 00481 { 00482 rootPtr->addChild(nodePtr); 00483 } 00484 endEditCP (rootPtr); 00485 } 00486 } 00487 else 00488 rootPtr = nodePtr; 00489 } 00490 } 00491 } 00492 00493 SceneFileHandler::the().updateReadProgress(100); 00494 return rootPtr; 00495 }
| bool OBJSceneFileType::write | ( | const NodePtr & | node, | |
| std::ostream & | os, | |||
| const Char8 * | fileNameOrExtension | |||
| ) | const [virtual] |
Reimplemented from osg::SceneFileType.
Definition at line 575 of file OSGOBJSceneFileType.cpp.
Referenced by write().
00577 { 00578 UInt32 pIndex=1; 00579 UInt32 tIndex=1; 00580 UInt32 nIndex=1; 00581 00582 write(node,os,pIndex,tIndex,nIndex); 00583 00584 return true; 00585 }
| void OBJSceneFileType::initElemMap | ( | void | ) | [private] |
Definition at line 731 of file OSGOBJSceneFileType.cpp.
References _dataElemMap, _mtlElemMap, FACE_DE, GROUP_DE, LIB_MTL_DE, MTL_AMBIENT_ME, MTL_DIFFUSE_ME, MTL_DISSOLVE_ME, MTL_ILLUM_ME, MTL_MAP_KA_ME, MTL_MAP_KD_ME, MTL_MAP_KS_ME, MTL_REFL_ME, MTL_SHININESS_ME, MTL_SPECULAR_ME, MTL_TRANSPARENCY_ME, NEW_MTL_ME, OBJECT_DE, SMOOTHING_GROUP_DE, UNKNOWN_DE, UNKNOWN_ME, USE_MTL_DE, VERTEX_DE, VERTEX_NORMAL_DE, and VERTEX_TEXTURECOORD_DE.
Referenced by OBJSceneFileType().
00732 { 00733 if (_dataElemMap.empty()) 00734 { 00735 _dataElemMap[""] = UNKNOWN_DE; 00736 00737 _dataElemMap["v"] = VERTEX_DE; 00738 _dataElemMap["vt"] = VERTEX_TEXTURECOORD_DE; 00739 _dataElemMap["vn"] = VERTEX_NORMAL_DE; 00740 _dataElemMap["f"] = FACE_DE; 00741 _dataElemMap["fo"] = FACE_DE; 00742 _dataElemMap["mtllib"] = LIB_MTL_DE; 00743 _dataElemMap["usemtl"] = USE_MTL_DE; 00744 _dataElemMap["g"] = GROUP_DE; 00745 _dataElemMap["s"] = SMOOTHING_GROUP_DE; 00746 _dataElemMap["o"] = OBJECT_DE; 00747 } 00748 00749 if (_mtlElemMap.empty()) 00750 { 00751 _mtlElemMap[""] = UNKNOWN_ME; 00752 00753 _mtlElemMap["newmtl"] = NEW_MTL_ME; 00754 _mtlElemMap["Kd"] = MTL_DIFFUSE_ME; 00755 _mtlElemMap["Ka"] = MTL_AMBIENT_ME; 00756 _mtlElemMap["Ks"] = MTL_SPECULAR_ME; 00757 _mtlElemMap["Ns"] = MTL_SHININESS_ME; 00758 _mtlElemMap["Tr"] = MTL_TRANSPARENCY_ME; 00759 _mtlElemMap["d"] = MTL_DISSOLVE_ME; 00760 _mtlElemMap["map_Kd"] = MTL_MAP_KD_ME; 00761 _mtlElemMap["map_Ka"] = MTL_MAP_KA_ME; 00762 _mtlElemMap["map_Ks"] = MTL_MAP_KS_ME; 00763 _mtlElemMap["illum"] = MTL_ILLUM_ME; 00764 _mtlElemMap["refl"] = MTL_REFL_ME; 00765 } 00766 }
| Int32 OBJSceneFileType::readMTL | ( | const Char8 * | fileName, | |
| std::map< std::string, SimpleTexturedMaterialPtr > & | mtlMap | |||
| ) | const [private] |
Definition at line 768 of file OSGOBJSceneFileType.cpp.
References _mtlElemMap, osg::beginEditCP(), osg::SimpleTexturedMaterialBase::create(), osg::endEditCP(), FFATAL, osg::PathHandler::findFile(), FWARNING, osg::SceneFileHandler::getPathHandler(), INT_MAX, MTL_AMBIENT_ME, MTL_DIFFUSE_ME, MTL_DISSOLVE_ME, MTL_ILLUM_ME, MTL_MAP_KA_ME, MTL_MAP_KD_ME, MTL_MAP_KS_ME, MTL_REFL_ME, MTL_SHININESS_ME, MTL_SPECULAR_ME, MTL_TRANSPARENCY_ME, NEW_MTL_ME, osg::NullFC, osg::SceneFileHandler::the(), and UNKNOWN_ME.
Referenced by read().
00771 { 00772 if(fileName == NULL || strlen(fileName) == 0) 00773 return 0; 00774 00775 Int32 mtlCount = 0; 00776 00777 PathHandler *pathHandler = SceneFileHandler::the().getPathHandler(); 00778 std::string fullFilePath; 00779 if(pathHandler != NULL) 00780 fullFilePath = pathHandler->findFile(fileName); 00781 else 00782 fullFilePath = fileName; 00783 00784 if(fullFilePath.empty()) 00785 { 00786 FWARNING (("Couldn't open '%s'!\n", fileName)); 00787 return 0; 00788 } 00789 00790 std::ifstream in(fullFilePath.c_str()); 00791 SimpleTexturedMaterialPtr mtlPtr = NullFC; 00792 Real32 a,b,c; 00793 std::string elem; 00794 std::map<std::string, MaterialElem>::const_iterator elemI; 00795 MaterialElem mtlElem; 00796 std::map<std::string, OSG::ImagePtr> imageMap; 00797 std::map<std::string, OSG::ImagePtr>::iterator iI; 00798 ImagePtr image = NullFC; 00799 bool constDiffuse = false, constAmbient = false, constSpecular = false; 00800 00801 if (in) 00802 for (in >> elem; in.eof() == false; in >> elem) 00803 if (elem[0] == '#' || elem[0] == '$' ) 00804 in.ignore(INT_MAX, '\n'); 00805 else 00806 { 00807 elemI = _mtlElemMap.find(elem); 00808 mtlElem = ((elemI == _mtlElemMap.end()) ? 00809 UNKNOWN_ME : elemI->second); 00810 if (mtlElem == NEW_MTL_ME) 00811 { 00812 in >> elem; 00813 if (mtlPtr != NullFC) 00814 endEditCP(mtlPtr); 00815 mtlPtr = SimpleTexturedMaterial::create(); 00816 beginEditCP(mtlPtr); 00817 mtlPtr->setColorMaterial(GL_NONE); 00818 mtlPtr->setEnvMode(GL_MODULATE); 00819 mtlMap[elem] = mtlPtr; 00820 mtlCount++; 00821 constDiffuse = false; 00822 constAmbient = false; 00823 constSpecular = false; 00824 } 00825 else 00826 { 00827 if (mtlPtr == NullFC) 00828 { 00829 FFATAL (( "Invalid Mtl token: %s, newmtl expected in %s\n", 00830 elem.c_str(), fileName )); 00831 in.ignore(INT_MAX, '\n'); 00832 } 00833 else 00834 { 00835 switch (mtlElem) 00836 { 00837 case MTL_DIFFUSE_ME: 00838 in >> a >> b >> c; 00839 if (!constDiffuse) 00840 mtlPtr->setDiffuse( Color3f( a,b,c )); 00841 break; 00842 case MTL_AMBIENT_ME: 00843 in >> a >> b >> c; 00844 if (!constAmbient) 00845 mtlPtr->setAmbient( Color3f( a,b,c )); 00846 break; 00847 case MTL_SPECULAR_ME: 00848 in >> a >> b >> c; 00849 if (!constSpecular) 00850 mtlPtr->setSpecular( Color3f( a,b,c )); 00851 break; 00852 case MTL_SHININESS_ME: 00853 in >> a; 00854 mtlPtr->setShininess(a); 00855 break; 00856 case MTL_ILLUM_ME: 00857 ; // TODO: What to do with illum ?!? 00858 in >> elem; 00859 // FFATAL (("obj mtl illum not handled yet\n")); 00860 break; 00861 case MTL_REFL_ME: 00862 mtlPtr->setEnvMap(true); 00863 break; 00864 case MTL_TRANSPARENCY_ME: 00865 in >> a; 00866 mtlPtr->setTransparency(a); 00867 break; 00868 case MTL_DISSOLVE_ME: 00869 in >> a; 00870 mtlPtr->setTransparency(1.f - a); 00871 break; 00872 case MTL_MAP_KD_ME: 00873 case MTL_MAP_KA_ME: 00874 case MTL_MAP_KS_ME: 00875 image = NullFC; 00876 in >> elem; 00877 iI = imageMap.find(elem); 00878 if (iI == imageMap.end()) 00879 { 00880 std::string fullElemPath; 00881 if(pathHandler != NULL) 00882 fullElemPath = pathHandler->findFile(elem.c_str()); 00883 else 00884 fullElemPath = elem.c_str(); 00885 image = OSG::ImageFileHandler::the().read(fullElemPath.c_str()); 00886 if(image != NullFC) 00887 { 00888 beginEditCP(image, 00889 OSG::Image::ForceAlphaBinaryFieldMask); 00890 image->setForceAlphaBinary( 00891 image->calcIsAlphaBinary()); 00892 endEditCP(image, 00893 OSG::Image::ForceAlphaBinaryFieldMask); 00894 imageMap[elem] = image; 00895 } 00896 } 00897 else 00898 { 00899 image = iI->second; 00900 } 00901 if (image != NullFC) { 00902 mtlPtr->setImage(image); 00903 switch (mtlElem) { 00904 case MTL_MAP_KD_ME: 00905 constDiffuse = true; 00906 mtlPtr->setDiffuse ( Color3f( 1, 1, 1) ); 00907 break; 00908 case MTL_MAP_KA_ME: 00909 constAmbient = true; 00910 mtlPtr->setAmbient ( Color3f( 1, 1, 1) ); 00911 break; 00912 case MTL_MAP_KS_ME: 00913 constSpecular = true; 00914 mtlPtr->setSpecular ( Color3f( 1, 1, 1) ); 00915 break; 00916 default: 00917 break; 00918 } 00919 } 00920 else 00921 { 00922 FFATAL (( "Can not find %s texture file in mtl %s \n", 00923 elem.c_str(), fileName )); 00924 } 00925 break; 00926 default: 00927 FWARNING (( "Invalid %s entry in %s\n", 00928 elem.c_str(), fileName )); 00929 in.ignore(INT_MAX, '\n'); 00930 } 00931 } 00932 } 00933 } 00934 00935 if (mtlPtr != NullFC) 00936 endEditCP(mtlPtr); 00937 00938 return mtlCount; 00939 }
| void OBJSceneFileType::write | ( | const NodePtr & | node, | |
| std::ostream & | os, | |||
| UInt32 & | pIndex, | |||
| UInt32 & | nIndex, | |||
| UInt32 & | tIndex | |||
| ) | const [private] |
Definition at line 497 of file OSGOBJSceneFileType.cpp.
References osg::AttachmentContainerPtr::dcast(), osg::NodePtr::getCore(), osg::TriangleIterator::getNormalIndex(), osg::TriangleIterator::getPositionIndex(), osg::TriangleIterator::getTexCoordsIndex(), osg::TransformationMatrix< ValueTypeT >::multMatrixPnt(), osg::TransformationMatrix< ValueTypeT >::multMatrixVec(), osg::NullFC, and write().
00502 { 00503 UInt32 i,pCount=0,nCount=0,tCount=0; 00504 GeometryPtr g = GeometryPtr::dcast(node->getCore()); 00505 if(g != NullFC) 00506 { 00507 // HACK separate it in several geometry nodes. 00508 os << "g Geometry" << std::endl; 00509 os << "usemtl Geometry" << std::endl; 00510 Matrix mat = node->getToWorld(); 00511 // write vertices 00512 if(g->getPositions()) 00513 { 00514 pCount = g->getPositions()->getSize(); 00515 for(i=0 ; i< pCount ; ++i) 00516 { 00517 Pnt3f v = g->getPositions()->getValue(i); 00518 mat.multMatrixPnt(v); 00519 os << "v " << v[0] << " " << v[1] << " " << v[2] << std::endl; 00520 } 00521 } 00522 // write normals 00523 if(g->getNormals()) 00524 { 00525 nCount = g->getNormals()->getSize(); 00526 for(i=0 ; i< nCount ; ++i) 00527 { 00528 Vec3f v = g->getNormals()->getValue(i); 00529 mat.multMatrixVec(v); 00530 os << "vn " << v[0] << " " << v[1] << " " << v[2] << std::endl; 00531 } 00532 } 00533 // texture coords 00534 if(g->getTexCoords()) 00535 { 00536 tCount = g->getTexCoords()->getSize(); 00537 for(i=0 ; i< tCount ; ++i) 00538 { 00539 Vec2f v = g->getTexCoords()->getValue(i); 00540 os << "vt " << v[0] << " " << v[1] << std::endl; 00541 } 00542 } 00543 // write indices 00544 TriangleIterator f; 00545 for(f=g->beginTriangles() ; f!=g->endTriangles() ; ++f) 00546 { 00547 os << "f"; 00548 for(i=0 ; i<3 ; ++i) 00549 { 00550 os << " " << f.getPositionIndex(i) + pIndex; 00551 if(nCount || tCount) 00552 { 00553 os << "/"; 00554 if(tCount) 00555 os << f.getTexCoordsIndex(i) + tIndex; 00556 if(nCount) 00557 os << "/" << f.getNormalIndex(i) + nIndex; 00558 } 00559 } 00560 os << std::endl; 00561 } 00562 pIndex += pCount; 00563 tIndex += tCount; 00564 nIndex += nCount; 00565 } 00566 for(MFNodePtr::iterator nI=node->getMFChildren()->begin(); 00567 nI != node->getMFChildren()->end(); 00568 ++nI) 00569 { 00570 write((*nI),os,pIndex,nIndex,tIndex); 00571 } 00572 00573 }
| void osg::OBJSceneFileType::operator= | ( | const OBJSceneFileType & | source | ) | [private] |
| void SceneFileType::setOptions | ( | const Char8 * | options | ) | [inherited] |
Definition at line 115 of file OSGSceneFileType.cpp.
References osg::SceneFileType::_options.
Referenced by osg::SceneFileHandler::setOptions().
00116 { 00117 _options = options; 00118 }
| std::list< IDString > & SceneFileType::suffixList | ( | void | ) | [virtual, inherited] |
Definition at line 138 of file OSGSceneFileType.cpp.
References osg::SceneFileType::_suffixList.
Referenced by osg::SceneFileHandler::addSceneFileType(), and osg::SceneFileHandler::subSceneFileType().
00139 { 00140 return _suffixList; 00141 }
| bool SceneFileType::doOverride | ( | void | ) | [inherited] |
Definition at line 145 of file OSGSceneFileType.cpp.
References osg::SceneFileType::_override.
Referenced by osg::SceneFileHandler::addSceneFileType(), and osg::SceneFileHandler::FindOverride::operator()().
00146 { 00147 return _override; 00148 }
| UInt32 SceneFileType::getOverridePriority | ( | void | ) | [inherited] |
Definition at line 152 of file OSGSceneFileType.cpp.
References osg::SceneFileType::_overridePriority.
Referenced by osg::SceneFileHandler::addSceneFileType(), and osg::SceneFileHandler::FindOverride::operator()().
00153 { 00154 return _overridePriority; 00155 }
| UInt32 SceneFileType::getFlags | ( | void | ) | [inherited] |
Definition at line 159 of file OSGSceneFileType.cpp.
References osg::SceneFileType::_flags.
Referenced by osg::SceneFileHandler::getSuffixList(), and osg::SceneFileHandler::print().
00160 { 00161 return _flags; 00162 }
| const Char8 * SceneFileType::getOptions | ( | void | ) | [inherited] |
Definition at line 166 of file OSGSceneFileType.cpp.
References osg::SceneFileType::_options.
Referenced by osg::SceneFileHandler::getOptions().
00167 { 00168 return _options.c_str(); 00169 }
Definition at line 181 of file OSGSceneFileType.cpp.
References FWARNING, and osg::NullFC.
Referenced by osg::SceneFileHandler::read().
| bool SceneFileType::writeFile | ( | const NodePtr & | node, | |
| const Char8 * | fileName | |||
| ) | const [virtual, inherited] |
Definition at line 197 of file OSGSceneFileType.cpp.
References FWARNING.
Referenced by osg::SceneFileHandler::write().
00199 { 00200 FWARNING (("FILE INTERFACE NOT IMPLEMENTED!\n")); 00201 return false; 00202 }
| void SceneFileType::print | ( | void | ) | [inherited] |
Definition at line 121 of file OSGSceneFileType.cpp.
References osg::SceneFileType::_suffixList, osg::SceneFileType::getName(), osg::LOG_DEBUG, osg::osgLog(), and osg::Log::stream().
00122 { 00123 std::list<IDString>::iterator sI; 00124 00125 osgLog() << getName(); 00126 00127 if (_suffixList.empty()) 00128 osgLog() << "NONE"; 00129 else 00130 for (sI = _suffixList.begin(); sI != _suffixList.end(); sI++) 00131 osgLog().stream(OSG::LOG_DEBUG) << sI->str() << " "; 00132 00133 osgLog() << std::endl; 00134 }
friend class Mesh [friend] |
Definition at line 159 of file OSGOBJSceneFileType.h.
friend class Face [friend] |
Definition at line 162 of file OSGOBJSceneFileType.h.
const Char8 * OBJSceneFileType::_suffixA = { "obj" } [static, protected] |
Definition at line 106 of file OSGOBJSceneFileType.h.
OBJSceneFileType OBJSceneFileType::_the [static, protected] |
std::map<std::string, DataElem> osg::OBJSceneFileType::_dataElemMap [private] |
std::map<std::string, MaterialElem> osg::OBJSceneFileType::_mtlElemMap [private] |
std::list<IDString> osg::SceneFileType::_suffixList [protected, inherited] |
Definition at line 152 of file OSGSceneFileType.h.
Referenced by osg::SceneFileType::print(), osg::SceneFileType::SceneFileType(), and osg::SceneFileType::suffixList().
bool osg::SceneFileType::_override [protected, inherited] |
UInt32 osg::SceneFileType::_overridePriority [protected, inherited] |
Definition at line 155 of file OSGSceneFileType.h.
Referenced by osg::SceneFileType::getOverridePriority().
UInt32 osg::SceneFileType::_flags [protected, inherited] |
std::string osg::SceneFileType::_options [protected, inherited] |
Definition at line 158 of file OSGSceneFileType.h.
Referenced by osg::SceneFileType::getOptions(), osg::SceneFileType::setOptions(), and osg::VRMLSceneFileType::write().
1.5.5