Hi Allan, Could you take a step back and tells us what problem you are trying to solve as you've dived in with a rather perplexing implementation for a problem that may well have a very straight forward solution.
Robert. On 22 April 2015 at 10:34, allan xia <[email protected]> wrote: > I need to distinguish the vertexs in different models in vertex shaders and > fragment shaders .so I use a nodevisitor to transfer a attribute variable > to the vertex shaders.as follows: > I transfer different value to the vertex shader if the type is dedined > different. > > class AnalysisNodeVisitor :public osg::NodeVisitor{ > public: > AnalysisNodeVisitor(INPUTTYPE > type):osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN){ > m_InputType=type; > } > virtual void apply(osg::Geode &node) > { > for ( unsigned int i=0; i<node.getNumDrawables(); ++i ) > { > osg::Geometry* geom = dynamic_cast<osg::Geometry*>(node.getDrawable(i) ); > if ( geom ){ > osg::FloatArray *fa=new osg::FloatArray; > switch(m_InputType){ > case INPUTTEXTURE: > { > fa->push_back(0.1); > break; > } > case INPUTMATERIAL: > { > fa->push_back(0.2); > break; > } > default : > { > fa->push_back(0.9); > } > } > geom->setVertexAttribArray(6,fa); > geom->setVertexAttribBinding(6,osg::Geometry::BIND_OVERALL); > } > } > traverse( node ); > } > virtual void apply(osg::Node &node){ > traverse(node); > } > public: > INPUTTYPE m_InputType; > }; > > and bind the attribute to the shader: > program->addBindAttribLocation("modelType",6); > > but when I use the AnalysisNodeVisitor,I occur a error. > > AnalysisNodeVisitor anvA(INPUTTEXTURE); > nodeA.accept(anvA); > AnalysisNodeVisitor anvB(INPUTMATERIAL); > nodeB.accept(anvB); > > and in the vertex shader modelType variable of vertexs in nodeA should be > 0.1 and modeType variable of vertexs in NodeB should be 0.2 ,but actually > modeType variable of all vertex is 0.2 .It seems nodeB.accept(anvB) override > the modeType variable of nodeA. what is wrong with it?Am I misunderstand it > ? > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

