Answer the question
In order to leave comments, you need to log in
What is the correct way to texture each side of a model?
Hello! I ask for help in this problem. There are models that are loaded into the openscenegraph project in visual studio. There is an image that is used as a texture for these models. All models are regular mogohedra. I was able to get the texture to change when changing the image, but the problem is that the texture is stretched over the object and is not displayed correctly on each of the sides (for example, a cube). Please advise how can I fix this. I can’t attach a texture to a model in 3ds max because I need to do it using osg. Here is the code itself:
#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"); //загрузка модели
osg::ref_ptr<osg::StateSet> ss = loadedModel->getOrCreateStateSet();
osg::ref_ptr<osg::Image> image = osgDB::readImageFile("box_1.png"); //подгрузка изображения
osg::ref_ptr<osg::Texture2D> tex(new osg::Texture2D()); //создаем текстуру
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);
return viewer.run();
}/code>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question