|
我在场景中添加了两个模型 对其中一个进行了缩小 然后就没了纹理 不缩小就有 请问是为什么? 代码如下- int main(){
- osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
- osg::ref_ptr<osg::Group> root = new osg::Group();
- osg::ref_ptr<osg::Node> robot = osgDB::readNodeFile("data/aodi.ive"); //读取机器人模型
- osg::ref_ptr<osg::Node> node = osgDB::readNodeFile("data/pointCloud470.ive");
-
- //得到包围盒,来确定动画旋转中心
- const osg::BoundingSphere& bs = robot->getBound();
- osg::Vec3 position = bs.center();
- //缩放比例
- float size = 1.0f/bs.radius()*1.0f;
-
- //创建路径
- osg::ref_ptr<osg::AnimationPath> animationPath = new osg::AnimationPath();
- animationPath = createAnimationPath(position);
- //导出路径
- std::string fileName("D:/GTZ/LearnOSG/LearnOSG/data/animation.path");
- std::ofstream out(fileName.c_str());
- animationPath->write(out);
- osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform();
- //OSG确保只有STATIC数据可以进行图形渲染
- mt->setDataVariance(osg::Object::STATIC);
- //进行适当的变换(平移,缩放以及旋转)
- mt->setMatrix(osg::Matrix::translate(-bs.center())*osg::Matrix::scale(size,size,size)*osg::Matrix::rotate(osg::inDegrees(90.0f), 0.0f, 0.0f, 1.0f));//这里如果让size为1 robot模型就有纹理 如果缩小 就看不到纹理
- mt->addChild(robot.get());
- osg::ref_ptr<osg::PositionAttitudeTransform> pat = new osg::PositionAttitudeTransform();
- //设置更新回调
- pat->setUpdateCallback(new osg::AnimationPathCallback(animationPath.get(),0.0f,1.0f));
- pat->addChild(mt.get());
- root->addChild(pat.get());
- root->addChild(node.get());
- //root->addChild(osgDB::readNodeFile("axes.osgt"));
- osgUtil::Optimizer optimzier;
- optimzier.optimize(root.get());
- viewer->setSceneData(root.get());
- //添加路径动画控制事件
- //viewer->addEventHandler(new AnimationEventHandler(*(viewer.get())));
- viewer->setUpViewInWindow(10,10,1200,800);
- viewer->realize();
-
- viewer->run();
-
- return 0;
- }
复制代码 截图如下 图中白色汽车就会robot模型 看不到纹理
贴图
|
|