|
我在OSG中加载了一个模型,交互操作之后选择重新加载其他的模型,在一个全新的场景中显示模型,每次的加载都在新的场景中显示三维模型,这个要怎么实现啊??
我在交互模型时点选模型上的三角面片,为了实现选中面片的高亮,我用如下代码实现:- osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
- osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
- v->push_back(p0);
- v->push_back(p1);
- v->push_back(p2);
- osg::ref_ptr<osg::Vec4Array> vc = new osg::Vec4Array;
- vc->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
- vc->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
- vc->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
- osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType, 4, 4>* colorIndex = new osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType, 4, 4>();
- colorIndex->push_back(indexList.at(0) - min);
- colorIndex->push_back(indexList.at(1) - min);
- colorIndex->push_back(indexList.at(2) - min);
- geom->setVertexArray(v.get());
- geom->setColorArray(vc.get());
- //geom->setColorIndices(colorIndex);
- geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
- geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 3));
- geode->addDrawable(geom.get());
- root->addChild(geode);
复制代码 但是当我重新加载别的模型的时候程序直接崩溃,调了好久也不知道什么问题,还请大家帮忙啊……先谢过大家了! |
|