|
本帖最后由 xuganggm 于 2012-3-19 16:12 编辑
大家好,我有个很奇怪的问题,就是运行下面一段代码之后导致 StateSetManipulator 不起作用了。
就是不能按 t 键来 启用/关闭纹理(还有光照,线框、点显示模式切换等)。
我试了 geom->addPrimitiveSet 只能添加 前两个中的一个 POLYGON, 其他的 PrimitiveSet 都不能添加,
Tessellator 那一段也注释掉,StateSetManipulator 才能起作用。
非常奇怪,不知道为什么,有人知道这个问题原因吗?
我用的 OSG 2.9.15。无论 windows linux,32位, 还有 linux 64位 的 release ,都有这个问题。
但是在 windows 32 debug 模式下是好的,没有这个问题。后来 windows 64位 也好了。- osg::ref_ptr<osg::Vec3Array> new3DPolygonVertexArray = new osg::Vec3Array;
- ... get new3DPolygonVertexArray ...
- osg::Geode *new3dGeode = create3dShapeFrom2dPolygon(new3DPolygonVertexArray, m_ZThreshold3d, m_baseShapeColor, m_shapeFileDepthTest);
- destSwitch->addChild(new3dGeode);
- osg::Geode *create3dShapeFrom2dPolygon (osg::Vec3Array *new3DPolygonVertexArray, float zThreshold3d, osg::Vec4 colour, bool depthTest)
- {
- osg::Geode* boxGeode = new osg::Geode();
- osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
- geom->setUseVertexBufferObjects( true );
- float min = 0.0;
- float max = 0.0;
- // Some times begin = end.
- if (*(new3DPolygonVertexArray->begin()) != *(new3DPolygonVertexArray->end() -1))
- {
- new3DPolygonVertexArray->push_back(*(new3DPolygonVertexArray->begin()));
- }
- osg::ref_ptr<osg::Vec3Array> tmpArray = new osg::Vec3Array;
- geom->setVertexArray(tmpArray.get());
- // Ignore the last point.
- for (osg::Vec3Array::iterator iter = new3DPolygonVertexArray->begin(); iter < new3DPolygonVertexArray->end() -1; iter++)
- {
- tmpArray->push_back(osg::Vec3(iter->x(), iter->y(), min)); // Top
- }
- for (osg::Vec3Array::iterator iter = new3DPolygonVertexArray->begin(); iter < new3DPolygonVertexArray->end() -1; iter++)
- {
- tmpArray->push_back(osg::Vec3(iter->x(), iter->y(), max)); // Bottom
- }
- unsigned int numTopPoints = (tmpArray->size())/2;
- geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, 0, numTopPoints)); // Top
- //geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON, numTopPoints, numTopPoints)); // Bottom
- {
- osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator;
- tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_POLYGONS);
- tscx->setBoundaryOnly(false);
- tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD);
- tscx->retessellatePolygons(*(geom.get()));
- }
- numTopPoints = (tmpArray->size())/2;
- unsigned int numQUAD_STRIP = new3DPolygonVertexArray->size() -1;//(numPointsAfterTessellate - numPoints*2)/2;
- for (osg::Vec3Array::iterator iter = new3DPolygonVertexArray->begin(); iter < new3DPolygonVertexArray->end(); iter++)
- {
- tmpArray->push_back(osg::Vec3(iter->x(), iter->y(), min)); // Sides
- tmpArray->push_back(osg::Vec3(iter->x(), iter->y(), max));
- }
- for (unsigned int i = 0; i< numQUAD_STRIP; i++)
- {
- geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP, numTopPoints *2 + 2*i, 4));// Sides
- }
- geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, 0, numTopPoints));
- geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP, numTopPoints, numTopPoints));
- geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, numTopPoints*2, numQUAD_STRIP*2));
- boxGeode->addDrawable(geom.get());
- return boxGeode;
- }
复制代码 |
|