Hi,

I have a strange problem. Runing the following code will cause 
StateSetManipulator doesn't work. That is I can't enble/ disable texture by 
clicking key "T" (And the Lighting, CyclePolygonMode). 
I've tried. If keep only one geom->addPrimitiveSet of the first two POLYGONs, 
remove the Tessellator part and other PrimitiveSets, the StateSetManipulator 
would work.
I was using OSG 2.9.15. It occurs on windows 32-bit and linux 64-bit release.
On windows 32-bit debug and 64-bit release it works fine.
I saw StateSetManipulator::handle() run. 
The problem is so strange to me. Do you have the answer to this? 

Thank you!

Cheers,
Su


[code]
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); // 即使不 addChild, StateSetManipulator 也不起作用


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;
}[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=46400#46400





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to