Saturday 15 January 2011

visual c++ - OpenSceneGraph - Texture on each face of model -



visual c++ - OpenSceneGraph - Texture on each face of model -

i've got question. here code:

#include <iostream> #include <osg/light> #include <osg/lightsource> #include <osg/positionattitudetransform> #include <osgdb/readfile> #include <osgviewer/viewer> int main(int argc, char** argv) { osg::ref_ptr<osg::node> loadedmodel = osgdb::readnodefile("cube.3ds"); //importing object osg::ref_ptr<osg::stateset> ss = loadedmodel->getorcreatestateset(); osg::ref_ptr<osg::image> image = osgdb::readimagefile("box_1.png"); //loading texture file osg::ref_ptr<osg::texture2d> tex(new osg::texture2d()); /creating texture model image tex->setimage(image); ss->settextureattributeandmodes(0, tex); osg::ref_ptr<osg::texgen> texgen(new osg::texgen()); texgen->setplane(osg::texgen::s, osg::plane(0.075, 0.0, 0.0, 0.5)); texgen->setplane(osg::texgen::t, osg::plane(0.0, 0.035, 0.0, 0.3)); ss->settextureattributeandmodes(0, texgen); osgviewer::viewer viewer; //creating viewer viewer.setscenedata(loadedmodel); viewer.setupviewonsinglescreen(0); homecoming viewer.run(); }

so code doing: takes model file (i.e. "cube.3s") , adding texture (image file "box_1.png" it. can alter texture on object switching 1 image another. here question: stretching image on whole model. how can done placing image on each face of model (they platonic solid (like pyramid, cube , etc.)).

this boils downwards texture coordinates assigned model's vertices when built. if convert cube.3ds .osg or .osgt text format can see uv coordinates texture mapper uses determine in texture map each corner of each face. how textures "pinned" faces.

just load , edit cube or pyramid in 3d modeling tool , prepare uv coordinates want.

alternately, edit .osgt file alter uv coordinates assigned each vertex.

visual-c++ openscenegraph

No comments:

Post a Comment