|
楼主 |
发表于 2014-8-9 19:04:53
|
显示全部楼层
添加模型的代码是这样的:
- osg::ref_ptr<osg::Node> MainWindow::drawMash(int zone_number, int reg_number)
- {
- Zone* zone = &zones[zone_number];
- Regn* r = &zone->regs[reg_number];
- //osg::ref_ptr< osg::Group > root = new osg::Group;
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- geode->setName(r->name);
- //定义颜色数组
- osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;
- c->push_back(osg::Vec4(1.f,0.f,0.f,0.3f));
- //定义颜色数组
- osg::ref_ptr<osg::Vec4Array> b = new osg::Vec4Array;
- b->push_back(osg::Vec4(1.f,1.f,1.f,0.3f));
- if(r->dim == CellDim){
- if (r->nedges) {
- int ne;
- osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
- //首先定义点
- osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
- geom->setVertexArray(v.get());
- for (ne = 0; ne < r->nedges; ne++) {
- v->push_back(osg::Vec3(zone->nodes[r->edges[ne].nodes[0]][0],zone->nodes[r->edges[ne].nodes[0]][1],zone->nodes[r->edges[ne].nodes[0]][2]));
- v->push_back(osg::Vec3(zone->nodes[r->edges[ne].nodes[1]][0],zone->nodes[r->edges[ne].nodes[1]][1],zone->nodes[r->edges[ne].nodes[1]][2]));
- }
- geom->setColorArray(b.get());
- geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);
- //设置关联方式
- geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, r->nedges*2));
- geode->addDrawable(geom.get());
- }
- }else{
- int nf,nn;
- Face *f;
- for (f = r->faces, nf = 0; nf < r->nfaces; nf++, f++) {
- osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
- //首先定义点
- osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
- geom->setVertexArray(v.get());
- for (nn = 0; nn < f->nnodes; nn++){
- v->push_back(osg::Vec3(zone->nodes[f->nodes[nn]][0],zone->nodes[f->nodes[nn]][1],zone->nodes[f->nodes[nn]][2]));
- }
- geom->setColorArray(c.get());
- geom->setColorBinding(osg::Geometry::BIND_OVERALL);
- //设置关联方式
- geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, f->nnodes));
- geode->addDrawable(geom.get());
- }
- }
- osg::StateSet *ss=geode->getOrCreateStateSet();
- ss->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
- return geode.get();
- }
复制代码
求各位大神指教啊、 |
|