2014-11-14 70 views
1

我有另一個問題。 這裏是我的代碼:OpenSceneGraph - 模型的每個面上的紋理

#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 from file 
    osg::ref_ptr<osg::Texture2D> tex(new osg::Texture2D()); /creating texture for model from 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); 
    return viewer.run(); 
    } 

那麼這段代碼是幹什麼:它從文件模型(即「cube.3s」),並添加紋理(圖片來自文件「box_1.png」到它,你可以通過將一幅圖像切換到另一幅圖像來改變對象的紋理,但是這裏有一個問題:他在整個模型上拉伸圖像,只需將所有圖像放在模型的每個面上就可以完成它們(它們是柏拉圖式的固體(如金字塔,立方體和等等))

回答

2

這一切都歸結爲模型頂點構建時分配給模型頂點的紋理座標如果將cube.3ds轉換爲.OSG或.OSGT文本格式,您可以看到UV座標紋理映射器用來確定whe重新在紋理貼圖中查找每個面部的每個角落。這就是紋理如何「固定」在臉上。

只需在3D建模工具中加載和編輯該立方體或金字塔,然後根據需要修復UV座標。

或者,您可以編輯.osgt文件以更改分配給每個頂點的UV座標。