From Jan Peciva,
"please, find attached updates to Inventor plugin: - improved transparency - do not treat 32-bit textures as transparent textures unless they really contain transparent pixels - error messages forwarded to osg::notify"
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <osg/BlendFunc>
|
||||
#include <osg/Material>
|
||||
#include <osg/CullFace>
|
||||
#include <osg/Depth>
|
||||
#include <osg/LightModel>
|
||||
#include <osg/LightSource>
|
||||
#include <osg/ShadeModel>
|
||||
@@ -1697,28 +1698,44 @@ ConvertFromInventor::getStateSet(SoCallbackAction* action)
|
||||
// Set transparency
|
||||
SbBool hasTextureTransparency = FALSE;
|
||||
if (ivTexture) {
|
||||
SbVec2s tmp;
|
||||
SbVec2s size(0, 0);
|
||||
int bpp = 0;
|
||||
const unsigned char *data = NULL;
|
||||
if (ivTexture->isOfType(SoTexture2::getClassTypeId()))
|
||||
((SoTexture2*)ivTexture)->image.getValue(tmp, bpp);
|
||||
data = ((SoTexture2*)ivTexture)->image.getValue(size, bpp);
|
||||
#ifdef __COIN__
|
||||
else
|
||||
if (ivTexture->isOfType(SoVRMLImageTexture::getClassTypeId())) {
|
||||
const SbImage *img = ((SoVRMLImageTexture*)ivTexture)->getImage();
|
||||
if (img) img->getValue(tmp, bpp);
|
||||
if (img)
|
||||
data = img->getValue(size, bpp);
|
||||
}
|
||||
#endif
|
||||
hasTextureTransparency = bpp==4 || bpp==2;
|
||||
|
||||
// look whether texture really contains transparency
|
||||
if ((bpp==4 || bpp==2) && data) {
|
||||
data += bpp - 1;
|
||||
for (int y=0; y<size[1]; y++)
|
||||
for (int x=0; x<size[0]; x++, data += bpp)
|
||||
if (*data != 255) {
|
||||
hasTextureTransparency = TRUE;
|
||||
goto finished;
|
||||
}
|
||||
finished:;
|
||||
}
|
||||
}
|
||||
|
||||
if (transparency > 0 || hasTextureTransparency)
|
||||
{
|
||||
osg::ref_ptr<osg::BlendFunc> transparency = new osg::BlendFunc;
|
||||
stateSet->setAttributeAndModes(transparency.get(),
|
||||
osg::StateAttribute::ON);
|
||||
// Blending to SRC_APLHA and ONE_MINUS_SRC_ALPHA
|
||||
stateSet->setAttributeAndModes(new osg::BlendFunc);
|
||||
|
||||
// Disable depth writes
|
||||
stateSet->setAttributeAndModes(new osg::Depth(osg::Depth::LEQUAL, 0., 1., false));
|
||||
|
||||
// Enable depth sorting for transparent objects
|
||||
stateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
||||
stateSet->setNestRenderBins(false);
|
||||
}
|
||||
|
||||
// Set linewidth
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include <Inventor/SoDB.h>
|
||||
#include <Inventor/SoInteraction.h>
|
||||
#include <Inventor/nodekits/SoNodeKit.h>
|
||||
#include <Inventor/errors/SoDebugError.h>
|
||||
#include <Inventor/errors/SoMemoryError.h>
|
||||
#include <Inventor/errors/SoReadError.h>
|
||||
#include <Inventor/nodes/SoSeparator.h>
|
||||
#include <Inventor/actions/SoWriteAction.h>
|
||||
#include <Inventor/actions/SoCallbackAction.h>
|
||||
@@ -21,6 +24,7 @@
|
||||
// forward declarations of static functions
|
||||
static void addSearchPaths(const osgDB::FilePathList *searchPaths);
|
||||
static void removeSearchPaths(const osgDB::FilePathList *searchPaths);
|
||||
static void errorCallback(const SoError *error, void * data);
|
||||
|
||||
|
||||
// Register with Registry to instantiate the inventor reader.
|
||||
@@ -52,16 +56,51 @@ void ReaderWriterIV::initInventor() const
|
||||
SoNodeKit::init();
|
||||
SoInteraction::init();
|
||||
|
||||
// Redirect error messages to OSG notify
|
||||
SoError::setHandlerCallback(errorCallback, NULL);
|
||||
SoDebugError::setHandlerCallback(errorCallback, NULL);
|
||||
SoMemoryError::setHandlerCallback(errorCallback, NULL);
|
||||
SoReadError::setHandlerCallback(errorCallback, NULL);
|
||||
|
||||
#ifdef __COIN__
|
||||
// Disable delayed loading of VRML textures
|
||||
SoVRMLImageTexture::setDelayFetchURL(FALSE);
|
||||
|
||||
|
||||
// initialize convertor
|
||||
ConvertFromInventor::init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void errorCallback(const SoError *error, void *data)
|
||||
{
|
||||
// note: Coin and SGI Inventor puts "Inventor read error..." or "Coin warning..."
|
||||
// introduction string to the error message, so we do not prepend the error message
|
||||
// by anything.
|
||||
|
||||
if (error->isOfType(SoDebugError::getClassTypeId()))
|
||||
{
|
||||
switch (((SoDebugError*)error)->getSeverity())
|
||||
{
|
||||
case SoDebugError::INFO:
|
||||
OSG_INFO << error->getDebugString().getString() << std::endl;
|
||||
break;
|
||||
case SoDebugError::WARNING:
|
||||
OSG_WARN << error->getDebugString().getString() << std::endl;
|
||||
break;
|
||||
case SoDebugError::ERROR:
|
||||
default:
|
||||
OSG_WARN << error->getDebugString().getString() << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_WARN << error->getDebugString().getString() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read from SoInput and convert to OSG.
|
||||
* This is a method used by readNode(string,options) and readNode(istream,options).
|
||||
|
||||
Reference in New Issue
Block a user