OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

writeNode after readNode makes the osgb model much bigger size


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
jane_rita
Newbie


Joined: 12 Jan 2018
Posts: 1

PostPosted: Fri Jan 12, 2018 6:56 am    Post subject:
writeNode after readNode makes the osgb model much bigger size
Reply with quote

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<osg::Node> node = osgDB::readRefNodeFile(123.osgb);

osg::ref_ptr<osgDB::ReaderWriter::Options> 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<osg::State> state = new osg::State;
state->initializeExtensionProcs();

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

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

osg::ref_ptr<osg::Image> 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
Back to top
View user's profile Send private message
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 372
Location: France

PostPosted: Fri Jan 12, 2018 8:42 pm    Post subject:
Re: writeNode after readNode makes the osgb model much bigger size
Reply with quote

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<osg::Node> node = osgDB::readRefNodeFile(123.osgb);

osg::ref_ptr<osgDB::ReaderWriter::Options> 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<osg::State> state = new osg::State;
state->initializeExtensionProcs();

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

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

osg::ref_ptr<osg::Image> 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
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts writeNode after readNode makes the os... jane_rita General 0 Fri Jan 12, 2018 6:57 am View latest post
No new posts PIXEL_SIZE_ON_SCREEN And RangeList of... xiaoming General 1 Thu Jan 11, 2018 1:42 am View latest post
No new posts load a osg model with rigged animatio... Andrea74 General 7 Fri Nov 24, 2017 9:40 am View latest post
No new posts Backwards compatibility for .osgb files stephandavid3 General 0 Fri Nov 17, 2017 11:27 pm View latest post
No new posts Backward compatibility of osgb file t... saedrna1 General 4 Thu Nov 02, 2017 8:20 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP