F
F
Fenghuang2014-11-15 17:07:53
3D
Fenghuang, 2014-11-15 17:07:53

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

2 answer(s)
S
SHVV, 2014-11-16
@Fenghuang

Didn't work with OSG, but it looks like you are creating a planar projection of the texture onto the object. So it's not surprising that they don't overlap very well.
Have you tried using texture coordinates loaded from a file? Are they there?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question