[osg-users] writeNode after readNode makes the osgb model much bigger size

2018-01-15 Thread tangrijing
Hi,

I read 123.osgb file to a node, and then write it to 456.osgb ,however,the 
456.osgb has a 10 times bigger size than 123.osgb. My code is here:

osg::ref_ptr node = osgDB::readRefNodeFile(123.osgb);

osg::ref_ptr options = new 
osgDB::ReaderWriter::Options;
options->setOptionString("WriteImageHint=IncludeData");

osgDB::ReaderWriter::WriteResult result = 
osgDB::Registry::instance()->writeNode(*node, “456.osgb”,options);


I than use a  texure compress method cited from osgconv.cpp, the result is 
still 2 times bigger size than the original file.


void MyNodeVisitor::compress()
{
MyGraphicsContext context;
if (!context.valid())
{
osg::notify(osg::NOTICE) << "Error: Unable to create graphis 
context, problem with running osgViewer-" << osgViewerGetVersion() << ", cannot 
run compression." << std::endl;
return;
}

osg::ref_ptr state = new osg::State;
state->initializeExtensionProcs();

for (TextureSet::iterator itr = _textureSet.begin();
itr != _textureSet.end();
++itr)
{
osg::Texture* texture = const_cast(itr->get());

osg::Texture2D* texture2D = 
dynamic_cast(texture);
osg::Texture3D* texture3D = 
dynamic_cast(texture);

osg::ref_ptr image = texture2D ? 
texture2D->getImage() : (texture3D ? texture3D->getImage() : 0);
if (image.valid() &&
(image->getPixelFormat() == GL_RGB || 
image->getPixelFormat() == GL_RGBA) &&
(image->s() >= 32 && image->t() >= 32))
{
texture->setInternalFormatMode(_internalFormatMode);

// need to disable the unref after apply, otherwise the 
image could go out of scope.
bool unrefImageDataAfterApply = 
texture->getUnRefImageDataAfterApply();
texture->setUnRefImageDataAfterApply(false);

// get OpenGL driver to create texture from image.
texture->apply(*state);

// restore the original setting

texture->setUnRefImageDataAfterApply(unrefImageDataAfterApply);

image->readImageFromCurrentTexture(0, true);


texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);
}
}
}



my question is ,how can i make the 456.osgb has the same size with 123.osgb

Thank you!

Cheers,
tangrijing

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72745#72745





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] writeNode after readNode makes the osgb model much bigger size

2018-01-12 Thread Julien Valentin
Hi Tangrijing

You may use osgDB::writeNode(*node, “456.osgb.zip”,options);
or try store Images as external compressed ive

Cheers


jane_rita wrote:
> Hi,
> 
> I read 123.osgb file to a node, and then write it to 456.osgb ,however,the 
> 456.osgb has a 10 times bigger size than 123.osgb. My code is here:
> 
> osg::ref_ptr node = osgDB::readRefNodeFile(123.osgb);
> 
> osg::ref_ptr options = new 
> osgDB::ReaderWriter::Options;
> options->setOptionString("WriteImageHint=IncludeData");
> 
> osgDB::ReaderWriter::WriteResult result = 
> osgDB::Registry::instance()->writeNode(*node, “456.osgb”,options);
> 
> 
> I than use a  texure compress method cited from osgconv.cpp, the result is 
> still 2 times bigger size than the original file.
> 
> 
> void MyNodeVisitor::compress()
> {
> MyGraphicsContext context;
> if (!context.valid())
> {
> osg::notify(osg::NOTICE) << "Error: Unable to create graphis 
> context, problem with running osgViewer-" << osgViewerGetVersion() << ", 
> cannot run compression." << std::endl;
> return;
> }
> 
> osg::ref_ptr state = new osg::State;
> state->initializeExtensionProcs();
> 
> for (TextureSet::iterator itr = _textureSet.begin();
> itr != _textureSet.end();
> ++itr)
> {
> osg::Texture* texture = const_cast(itr->get());
> 
> osg::Texture2D* texture2D = 
> dynamic_cast(texture);
> osg::Texture3D* texture3D = 
> dynamic_cast(texture);
> 
> osg::ref_ptr image = texture2D ? 
> texture2D->getImage() : (texture3D ? texture3D->getImage() : 0);
> if (image.valid() &&
> (image->getPixelFormat() == GL_RGB || 
> image->getPixelFormat() == GL_RGBA) &&
> (image->s() >= 32 && image->t() >= 32))
> {
> texture->setInternalFormatMode(_internalFormatMode);
> 
> // need to disable the unref after apply, otherwise 
> the image could go out of scope.
> bool unrefImageDataAfterApply = 
> texture->getUnRefImageDataAfterApply();
> texture->setUnRefImageDataAfterApply(false);
> 
> // get OpenGL driver to create texture from image.
> texture->apply(*state);
> 
> // restore the original setting
> 
> texture->setUnRefImageDataAfterApply(unrefImageDataAfterApply);
> 
> image->readImageFromCurrentTexture(0, true);
> 
> 
> texture->setInternalFormatMode(osg::Texture::USE_IMAGE_DATA_FORMAT);
> }
> }
> }
> 
> 
> 
> my question is ,how can i make the 456.osgb has the same size with 123.osgb
> 
> Thank you!
> 
> Cheers,
> tangrijing


--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72746#72746





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org