Hello everyone!

I've been using 'osgconv' to make native ive binary versions of osg ascii
files. However, if a texture is used more than once, it is resaved each time it
is used. For your reference, I've created a sample file called 'billboards.zip'
which you can download from the following URL:
http://www.geocities.com/andrlet/index.html

So I traced through the code, and found that 'write' in
'osgPlugins/ive/Textures2D.cpp' doesn't check to see if the texture has already
been written out. So here I put in a check to make sure that the texture data is
written out only the first time (see code example below), and subsequently only
references to the texture filename are written out.

Unfortunately this didn't solve my problem, as the texture only appears once in
the first child Geode (where it is saved), and not in subsequent children.

Is there another solution which can prevent repeat saves of the same texture?
(I've thought about modifying the ive loader too but would like to avoid that).

All suggestions are very much welcome.

Best regards,
- Andrew


// modified part of Texture2D.cpp, from osgPlugins/ive (replace ::write)

std::set<std::string> savedFileNames;
void Texture2D::write(DataOutputStream* out){
    // Write Texture2D's identification.
    out->writeInt(IVETEXTURE2D);
    // If the osg class is inherited by any other class we should also write
this to file.
    osg::Texture*  tex = dynamic_cast<osg::Texture*>(this);
    if(tex){
        ((ive::Texture*)(tex))->write(out);
    }
    else
        throw Exception("Texture2D::write(): Could not cast this osg::Texture2D
to an osg::Texture.");
    // Write Texture2D's properties.
    // Write image.

    // Should we include images date in stream
    IncludeImageMode includeImg = out->getIncludeImageMode();

    // get filename for texture image, and write out data only once
    osg::Image *myImage = getImage();
    std::string imgName = myImage->getFileName();

    if (savedFileNames.find(imgName) == savedFileNames.end()) {
        savedFileNames.insert(imgName);
    } else {
        includeImg = IMAGE_REFERENCE_FILE;
    }
    out->writeChar(includeImg);
    out->writeImage(includeImg,getImage());
}



_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to