[osg-users] [build] using 3Ds Model in osgFX::BumpMapping and the Texture UV Coords for diffuse are not loaded

Tobias Rick raveworld at freenet.de
Thu Nov 5 12:47:06 PST 2015


Hi all,

I tried to use the example from the link in the next posts (I need to have at least two posts to send Links) to generate a bumpmap via a normal map texture.

What I did is, that I have added a Node to the osgFX::BumpMapping and the node contains the 3Ds model. When I set up the texture state, the bumpmap texture coordinates are loaded correctly but there aren't loaded any diffuse texture coordinates and the diffuse texture on the model is infinitely streched. In 3D studio max I set for the 3ds model an uvMap. My c++ Code looks like this:


> #include <osg/Group>
> #include <osg/Image>
> #include <osg/MatrixTransform>
> #include <osg/Node>
> #include <osg/StateSet>
> #include <osg/Texture2D>
> #include <osgDB/ReadFile>
> #include <osgGA/TrackballManipulator>
> #include <osgViewer/Viewer>
> 
> #include <osgFX/BumpMapping>
> #include <osg/TexMat>
> 
> int main(int argc, char **argv) {
> 
> 	//TODO UV Map for diffuse texture
> 
> 	osg::Group* bumpRoot = new osg::Group();
> 
> 	osgFX::BumpMapping *bump = new osgFX::BumpMapping();
> 	osg::Node* bumpModel = new osg::Node();
> 
> 	bumpModel = osgDB::readNodeFile("Models/model_scifi_roadway_00straight.3ds");
> 	bump->addChild(bumpModel);
> 
> 	osg::Texture2D *normal = new osg::Texture2D();
> 	osg::Texture2D *diffuse = new osg::Texture2D();
> 
> 	const char* normal_texture = "Textures/Normal/texture_scifi_roadway_00normal.png";
> 	const char* diffuse_texture = "Textures/texture_scifi_roadway_00.png";
> 
> 	osg::Image *normal_image  = osgDB::readImageFile( normal_texture );
> 	osg::Image *diffuse_image = osgDB::readImageFile( diffuse_texture );
> 
> 	normal->setImage( normal_image );
> 	normal->setDataVariance(osg::Object::DYNAMIC);
> 	normal->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
> 	normal->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
> 	normal->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
> 	normal->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
> 	normal->setMaxAnisotropy(8);
> 
> 	diffuse->setImage( diffuse_image );
> 	diffuse->setDataVariance(osg::Object::DYNAMIC);
> 	diffuse->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
> 	diffuse->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
> 	diffuse->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
> 	diffuse->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
> 	diffuse->setMaxAnisotropy(8);
> 
> 	osg::TexMat* texMat = new osg::TexMat;
> 	osg::Vec3d texPosition(0.0, 0.0, 0.0);
> 	osg::Vec3d texAngles(0.0, 0.0, 0.0);
> 	osg::Vec3d texScale(1.0, 1.0, 1.0);
> 	osg::Matrixd texRot;
> 	texRot.makeRotate(
> 		osg::DegreesToRadians(texAngles.x()), osg::Vec3(1, 0, 0),
> 		osg::DegreesToRadians(texAngles.y()), osg::Vec3(0, 1, 0),
> 		osg::DegreesToRadians(texAngles.z()), osg::Vec3(0, 0, 1));
> 	texMat->setMatrix(osg::Matrix::scale(texScale)*texRot*osg::Matrix::translate(texPosition));
> 
> 	osg::StateSet *state = new osg::StateSet();
> 	state = bumpModel->getOrCreateStateSet();
> 	state->setTextureAttributeAndModes( 0, diffuse, osg::StateAttribute::ON );
> 	state->setTextureAttributeAndModes(0, texMat, osg::StateAttribute::ON);
> 	state->setTextureAttributeAndModes( 1, normal, osg::StateAttribute::ON );
> 	state->setTextureAttributeAndModes(1, texMat, osg::StateAttribute::ON);
> 	state->setGlobalDefaults();
> 	state->setMode(GL_LIGHTING, osg::StateAttribute::ON);
> 	state->setMode(GL_BLEND, osg::StateAttribute::ON);
> 	state->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
> 	state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
> 
> 	bump->setStateSet(state);
> 
> 	bump->setEnabled(true);
> 	bump->setLightNumber(0);
> 	bump->setOverrideNormalMapTexture(normal);
> 	bump->setOverrideDiffuseTexture(diffuse);
> 	bump->prepareChildren();
> 	//bump->setUpDemo();
> 
> 	osg::MatrixTransform *MT = new osg::MatrixTransform();
> 	MT->addChild(bump);
> 	bumpRoot->addChild(MT);
> 
> 	osgViewer::Viewer bumpViewer;
> 	bumpViewer.setSceneData(bumpRoot);
> 	bumpViewer.setCameraManipulator(new osgGA::TrackballManipulator());
> 	bumpViewer.realize();
> 
> 	while (!bumpViewer.done()) {
> 		bumpViewer.frame();
> 	}
> 
> }



I hope anybody can help.

Thank you!

Cheers,
Tobias

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








More information about the osg-users mailing list