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
00044 #include <stdlib.h>
00045 #include <stdio.h>
00046
00047 #include "OSGConfig.h"
00048
00049 #include <OSGGL.h>
00050
00051 #include <iostream>
00052 #include <fstream>
00053
00054 #include <vector>
00055
00056 #include <OSGLog.h>
00057
00058 #include <OSGNode.h>
00059 #include <OSGGeometry.h>
00060 #include <OSGGeoProperty.h>
00061 #include <OSGGeoFunctions.h>
00062 #include <OSGSimpleTexturedMaterial.h>
00063 #include <OSGImageFileHandler.h>
00064 #include <OSGPathHandler.h>
00065 #include <OSGGroup.h>
00066 #include <OSGSceneFileHandler.h>
00067 #include <OSGTriangleIterator.h>
00068
00069 #include "OSGOBJSceneFileType.h"
00070
00071 OSG_USING_NAMESPACE
00072
00073
00079 #if defined(OSG_WIN32_ICL) && !defined(OSG_CHECK_FIELDSETARG)
00080 #pragma warning (disable : 383)
00081 #endif
00082
00083
00084
00085
00086
00087 const Char8 *OBJSceneFileType::_suffixA[] = { "obj" };
00088
00089 OBJSceneFileType OBJSceneFileType::_the (_suffixA,
00090 sizeof(_suffixA),
00091 false,
00092 10,
00093 SceneFileType::OSG_READ_SUPPORTED|
00094 SceneFileType::OSG_WRITE_SUPPORTED);
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
00122
00123
00124
00125
00126
00127
00128
00129
00130 NodePtr OBJSceneFileType::read(std::istream &is, const Char8 *) const
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
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
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
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
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 if( !(indexMask & 1) ) {
00331
00332 FFATAL (( "IndexMask unmatch, can not create geo\n"));
00333 meshIndexMask = 0;
00334 break;
00335 }else{
00336
00337 meshIndexMask &= indexMask;
00338 }
00339 }
00340 }
00341 else
00342 {
00343 FWARNING (("Mesh with empty faceList\n"));
00344 }
00345
00346
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
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
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
00433 lensPtr->push_back(n);
00434
00435
00436 typePtr->push_back(GL_POLYGON);
00437
00438
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
00455 if ((meshIndexMask & 4) == 0)
00456 calcVertexNormals(geoPtr);
00457
00458
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 }
00496
00497 void OBJSceneFileType::write(const NodePtr &node,
00498 std::ostream &os,
00499 UInt32 &pIndex,
00500 UInt32 &nIndex,
00501 UInt32 &tIndex) const
00502 {
00503 UInt32 i,pCount=0,nCount=0,tCount=0;
00504 GeometryPtr g = GeometryPtr::dcast(node->getCore());
00505 if(g != NullFC)
00506 {
00507
00508 os << "g Geometry" << std::endl;
00509 os << "usemtl Geometry" << std::endl;
00510 Matrix mat = node->getToWorld();
00511
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
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
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
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 }
00574
00575 bool OBJSceneFileType::write(const NodePtr &node, std::ostream &os,
00576 const Char8 *fileNameOrExtension) const
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 }
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631 OBJSceneFileType::OBJSceneFileType(const Char8 *suffixArray[],
00632 UInt16 suffixByteCount,
00633 bool override,
00634 UInt32 overridePriority,
00635 UInt32 flags) :
00636 SceneFileType(suffixArray,
00637 suffixByteCount,
00638 override,
00639 overridePriority,
00640 flags),
00641 _dataElemMap()
00642
00643 {
00644 initElemMap();
00645 }
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668 OBJSceneFileType::OBJSceneFileType(const OBJSceneFileType &obj) :
00669 SceneFileType(obj)
00670 {
00671 initElemMap();
00672 }
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695 OBJSceneFileType &OBJSceneFileType::the(void)
00696 {
00697 return _the;
00698 }
00699
00700 OBJSceneFileType::~OBJSceneFileType(void)
00701 {
00702 return;
00703 }
00704
00705 const Char8 *OBJSceneFileType::getName(void) const
00706 {
00707 return "Wavefront Geometry";
00708 }
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731 void OBJSceneFileType::initElemMap(void)
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 }
00767
00768 Int32 OBJSceneFileType::readMTL ( const Char8 *fileName,
00769 std::map<std::string, SimpleTexturedMaterialPtr> & mtlMap )
00770 const
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 ;
00858 in >> elem;
00859
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 }
00940
00941
00942
00943
00944
00945 #ifdef __sgi
00946 #pragma set woff 1174
00947 #endif
00948
00949 #ifdef OSG_LINUX_ICC
00950 #pragma warning( disable : 177 )
00951 #endif
00952
00953 namespace
00954 {
00955 static Char8 cvsid_cpp[] = "@(#)$Id: $";
00956 static Char8 cvsid_hpp[] = OSGOBJSCENEFILETYPE_HEADER_CVSID;
00957 }
00958