- Timestamp:
- 01/08/10 11:52:03 (3 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/3ds/WriterNodeVisitor.cpp
r10853 r10932 16 16 #include <osg/io_utils> 17 17 #include <osg/CullFace> 18 #include <osgDB/WriteFile> 19 18 20 #include "WriterNodeVisitor.h" 19 21 #include <assert.h> … … 398 400 399 401 400 /// Creates a unique 3DS name for a given texture, and copies the image file to disk at an appropriate location if necessary.401 //std::string WriterNodeVisitor::export3DSTexture(const osg::Image * image, const std::string & texName) {402 // std::string extension = osgDB::getFileExtension(texName);403 // if (is83(texName))404 // {405 // std::string newName = texName;406 // if (extension.empty())407 // newName += ".rgb";408 // if (osgDB::Registry::instance()->writeImage(*image, osgDB::concatPaths(_directory, newName), options).status() ==409 // osgDB::ReaderWriter::WriteResult::ERROR_IN_WRITING_FILE)410 // failedApply();411 // return texName;412 // }413 // if (extension.empty())414 // {415 // extension = "rgb";416 // }417 // std::string newName = getUniqueName(texName, "tex");418 // newName += "." + extension;419 // osgDB::Registry::instance()->writeImage(*image, osgDB::concatPaths(_directory, newName), options);420 // return newName;421 //}422 423 402 std::string 424 403 getPathRelative(const std::string & srcBad, 425 404 const std::string & dstBad) 426 405 { 406 if(srcBad.empty()) 407 return osgDB::getSimpleFileName(dstBad); 427 408 const std::string & src = osgDB::convertFileNameToNativeStyle(srcBad); 428 409 const std::string & dst = osgDB::convertFileNameToNativeStyle(dstBad); … … 440 421 ++itDst; 441 422 } 442 if (itSrc != src.end() || !is3DSpath(result))423 if (itSrc != src.end()) 443 424 result = osgDB::getSimpleFileName(dst); 444 425 return result; … … 477 458 path = oss.str(); 478 459 } 479 else 460 else { 480 461 path = getPathRelative(_srcDirectory, mat.image->getFileName()); 481 // if(!is3DSpath(path)) 482 path = osgDB::getSimpleFileName(path); 462 } 463 if(!is3DSpath(path)) { 464 path = getUniqueName(path, "", true); 465 //path = osgDB::getSimpleFileName(path); 466 } 483 467 484 468 strcpy(tex.name, path.c_str()); … … 486 470 osgDB::makeDirectoryForFile(path); 487 471 488 if (mat.image && mat.image->data()) osgDB::Registry::instance()->writeImage(*(mat.image), path, NULL); 472 //if (mat.image->valid()) osgDB::writeImageFile(*(mat.image), path); 473 osgDB::writeImageFile(*(mat.image), path); 489 474 if (mat.texture_transparency) tex.flags |= LIB3DS_TEXTURE_ALPHA_SOURCE; 490 475 if (mat.texture_no_tile) tex.flags |= LIB3DS_TEXTURE_NO_TILE; … … 500 485 501 486 502 std::string WriterNodeVisitor::getUniqueName(const std::string& defaultValue, const std::string & _defaultPrefix, bool nameIsPath) {487 std::string WriterNodeVisitor::getUniqueName(const std::string& _defaultValue, const std::string & _defaultPrefix, bool nameIsPath) { 503 488 if (_defaultPrefix.length()>=4) throw "Default prefix is too long"; // Arbitrarily defined to 3 chars. You can modify this, but you may have to change the code so that finding a number is okay, even when changing the default prefix length. 504 489 505 490 // Tests if default name is valid and unique 506 bool defaultIs83 = is83(defaultValue); 507 bool defaultIsValid = nameIsPath ? is3DSpath(defaultValue) : defaultIs83; 508 if (defaultIsValid && _nameMap.find(defaultValue) == _nameMap.end()) { 509 _nameMap.insert(defaultValue); 510 return defaultValue; 511 } 491 bool defaultIs83 = is83(_defaultValue); 492 bool defaultIsValid = nameIsPath ? is3DSpath(_defaultValue) : defaultIs83; 493 if (defaultIsValid && _nameMap.find(_defaultValue) == _nameMap.end()) { 494 _nameMap.insert(_defaultValue); 495 return _defaultValue; 496 } 497 498 // Handling of paths is not well done yet. Defaulting to something very simple. 499 // We should actually ensure each component is 8 chars long, and final filename is 8.3, and total is <64 chars. 500 std::string defaultValue(nameIsPath ? osgDB::getSimpleFileName(_defaultValue) : _defaultValue); 501 std::string ext(nameIsPath ? osgDB::getFileExtensionIncludingDot(_defaultValue).substr(0, std::min<unsigned int>(_defaultValue.size(), 4)) : ""); // 4 chars = dot + 3 chars 512 502 513 503 std::string defaultPrefix(_defaultPrefix.empty() ? "_" : _defaultPrefix); … … 561 551 } 562 552 _nameMap.insert(res); 563 return res ;553 return res + ext; 564 554 } 565 555 }
