Show
Ignore:
Timestamp:
11/23/09 12:00:07 (4 years ago)
Author:
robert
Message:

From Chris Hanson, " Add support for "OutputTextureFiles?" option to IVE plugin to permit creation of external
.dds texture files from internally-embedded textures during IVE writes."

From Robert Osfield, fixed a bug in the above submission, and changed the way that the filename of the file is passed into DataOutputStream? to avoid issues with the .ive's plugins ability to read from istreams.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/ive/DataOutputStream.cpp

    r10762 r10819  
    124124#include <osg/io_utils> 
    125125#include <osgDB/FileUtils> 
     126#include <osgDB/FileNameUtils> 
    126127#include <osgDB/fstream> 
     128#include <osgDB/WriteFile> 
    127129 
    128130#include <stdlib.h> 
     
    143145    _maximumErrorToSizeRatio       = 0.001; 
    144146 
     147    _outputTextureFiles = false; 
     148    _textureFileNameNumber = 0; 
     149 
    145150    _options = options; 
    146151 
    147152    _compressionLevel = 0; 
     153 
     154    if (options) _filename = options->getPluginStringData("filename"); 
     155 
     156    if (_filename.empty()) 
     157    { 
     158        // initialize _filename to a unique identifier in case a real filename is not supplied 
     159        std::ostringstream filenameBuilder; 
     160        filenameBuilder << "file" << ostream; // use address of ostream to formulate unique filename 
     161        _filename = filenameBuilder.str(); 
     162    } 
    148163 
    149164    if (_options.get()) 
     
    158173            setIncludeImageMode(IMAGE_COMPRESS_DATA); 
    159174        } 
    160         osg::notify(osg::DEBUG_INFO) << "ive::DataOutpouStream.setIncludeImageMode()=" << getIncludeImageMode() << std::endl; 
     175        osg::notify(osg::DEBUG_INFO) << "ive::DataOutputStream.setIncludeImageMode()=" << getIncludeImageMode() << std::endl; 
    161176 
    162177        setIncludeExternalReferences(optionsString.find("inlineExternalReferencesInIVEFile")!=std::string::npos); 
    163         osg::notify(osg::DEBUG_INFO) << "ive::DataOutpouStream.setIncludeExternalReferences()=" << getIncludeExternalReferences() << std::endl; 
     178        osg::notify(osg::DEBUG_INFO) << "ive::DataOutputStream.setIncludeExternalReferences()=" << getIncludeExternalReferences() << std::endl; 
    164179 
    165180        setWriteExternalReferenceFiles(optionsString.find("noWriteExternalReferenceFiles")==std::string::npos); 
    166         osg::notify(osg::DEBUG_INFO) << "ive::DataOutpouStream.setWriteExternalReferenceFiles()=" << getWriteExternalReferenceFiles() << std::endl; 
     181        osg::notify(osg::DEBUG_INFO) << "ive::DataOutputStream.setWriteExternalReferenceFiles()=" << getWriteExternalReferenceFiles() << std::endl; 
    167182 
    168183        setUseOriginalExternalReferences(optionsString.find("useOriginalExternalReferences")!=std::string::npos); 
    169         osg::notify(osg::DEBUG_INFO) << "ive::DataOutpouStream.setUseOriginalExternalReferences()=" << getUseOriginalExternalReferences() << std::endl; 
     184        osg::notify(osg::DEBUG_INFO) << "ive::DataOutputStream.setUseOriginalExternalReferences()=" << getUseOriginalExternalReferences() << std::endl; 
     185 
     186        setOutputTextureFiles(optionsString.find("OutputTextureFiles")!=std::string::npos); 
     187        osg::notify(osg::DEBUG_INFO) << "ive::DataOutputStream.setOutputTextureFiles()=" << getOutputTextureFiles() << std::endl; 
    170188 
    171189        _compressionLevel =  (optionsString.find("compressed")!=std::string::npos) ? 1 : 0; 
    172         osg::notify(osg::DEBUG_INFO) << "ive::DataOutpouStream._compressionLevel=" << _compressionLevel << std::endl; 
     190        osg::notify(osg::DEBUG_INFO) << "ive::DataOutputStream._compressionLevel=" << _compressionLevel << std::endl; 
    173191 
    174192        std::string::size_type terrainErrorPos = optionsString.find("TerrainMaximumErrorToSizeRatio="); 
     
    14401458            break; 
    14411459        case IMAGE_REFERENCE_FILE: 
    1442             // Only include image name in stream 
    1443             if (image && !(image->getFileName().empty())){ 
    1444                 writeString(image->getFileName()); 
     1460        { 
     1461            if (image) 
     1462            { 
     1463                // Only include image name in stream 
     1464                std::string fileName = image->getFileName(); 
     1465                // Export an image, if requested 
     1466                if (getOutputTextureFiles()) 
     1467                { 
     1468                    if (fileName.empty()) 
     1469                    { // synthesize a new faux filename 
     1470                        fileName = getTextureFileNameForOutput(); 
     1471                    } 
     1472                    osgDB::writeImageFile(*image, fileName); 
     1473                } 
     1474                writeString(fileName); 
    14451475            } 
    1446             else{ 
     1476            else 
     1477            { 
    14471478                writeString(""); 
    14481479            } 
    14491480            break; 
     1481        } 
    14501482        case IMAGE_INCLUDE_FILE: 
    14511483            // Include image file in stream 
     
    18401872} 
    18411873 
     1874std::string DataOutputStream::getTextureFileNameForOutput() 
     1875{ 
     1876    std::string fileName = osgDB::getNameLessExtension(_filename); 
     1877    if (_textureFileNameNumber>0) 
     1878    { 
     1879        std::ostringstream o; 
     1880        o << '_' << _textureFileNameNumber; 
     1881        fileName += o.str(); 
     1882    } 
     1883     
     1884    fileName += ".dds"; 
     1885    ++_textureFileNameNumber; 
     1886     
     1887    return fileName; 
     1888} 
     1889 
     1890 
     1891 
    18421892void DataOutputStream::setExternalFileWritten(const std::string& filename, bool hasBeenWritten) 
    18431893{