Re: [osg-users] Update node color on demand
Hi, try in void ColorVisitor::apply(osg::Geode ) { . if (colorArrays) { for (unsigned int i = 0; i < colorArrays->size(); i++) { osg::Vec4 *color = >operator [](i); // // could also use *color = m_color // color->set(m_color._v[0], m_color._v[1], m_color._v[2], m_color._v[3]); } colorArrays->dirty() or ->dirtyBufferObject() I am not sure what was the right call. Please look it up. It is not enough only to change the color, you have to dirty the array to be updated } On Tue, Nov 27, 2018 at 2:10 AM Diego Mancilla wrote: > Hello Trajce, > > The visitor class implementation is on my previous post on this thread. I > took that code from Gordon Tomlison's OSG Samples, and it works when is > used previous to the rendering as you can see on my initial post (other > thread: http://forum.openscenegraph.org/viewtopic.php?p=75209#75209). > > > As I said everything gets called when it should, but on runtime, the > lines wont change color. I you look at the code snippet of my main: > > > > Code: > _lines = osgDB::readNodeFile("lines.dxf"); > _topo->setDataVariance(osg::Object::DYNAMIC); > osg::Geode* geode = new osg::Geode; > > _mViewer->addEventHandler(new ColorHandler); > > ColorVisitor newColor; > newColor.setColor( 1.0f, 0.0f, 0.0f ); > _lines->accept(newColor); > geode->addChild(_lines); > _mViewer->realize(); > > > > The color of the lines turns red on start. But then, when I try to change > it to another color on runetime, nothing happens. > > Anyway, here is the visitor implementation (.cpp): > > > Code: > ColorVisitor::ColorVisitor(): > osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) > { > m_color.set(1.0, 1.0, 1.0, 1.0); > m_colorArrays = new osg::Vec4Array; > m_colorArrays->push_back(m_color); > }; > > ColorVisitor::ColorVisitor(const osg::Vec4 ): > osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) > { > m_color = color; > m_colorArrays = new osg::Vec4Array; > m_colorArrays->push_back(m_color); > > }; > > ColorVisitor::~ColorVisitor() > { > }; > > void ColorVisitor::apply(osg::Node ) { > // > // > // Handle traversal of osg::Node node types > // > // > traverse(node); > }; > > void ColorVisitor::apply(osg::Geode ) { > // > // > // Handle traversal of osg::Geode node types > // > // > > osg::StateSet *state = NULL; > unsigned intvertNum = 0; > // > // We need to iterate through all the drawables check if > // the contain any geometry that we will need to process > // > > unsigned int numGeoms = geode.getNumDrawables(); > > for (unsigned int geodeIdx = 0; geodeIdx < numGeoms; geodeIdx++) > { > // > // Use 'asGeometry' as its supposed to be faster than a > dynamic_cast > // every little saving counts > // > osg::Geometry *curGeom = > geode.getDrawable(geodeIdx)->asGeometry(); > // > // Only process if the drawable is geometry > // > if (curGeom) > { > osg::Vec4Array *colorArrays = dynamic_cast *>(curGeom->getColorArray()); > if (colorArrays) { > for (unsigned int i = 0; i < colorArrays->size(); i++) > { > osg::Vec4 *color = >operator [](i); > // > // could also use *color = m_color > // > color->set(m_color._v[0], m_color._v[1], > m_color._v[2], m_color._v[3]); > } > > } > else > { > curGeom->setColorArray(m_colorArrays.get()); > curGeom->setColorBinding(osg::Geometry::BIND_OVERALL); > } > } > } > }; > > void ColorVisitor::setColor(const float r, const float g, const float b, > const float a) > { > // --- > // > // Set the color to change apply to the nodes geometry > // > // --- > osg::Vec4 *c = _colorArrays->operator [](0); > m_color.set(r, g, b, a); > *c = m_color; > }; > > void ColorVisitor::setColor(const osg::Vec4 ) { > // --- > // > // Set the color to change apply to the nodes geometry > // > // --- > osg::Vec4 *c = _colorArrays->operator [](0); > m_color = color; > *c = m_color; > }; > > > > > > Cheers, > > -- > Read this topic online here: >
Re: [osg-users] pass mat4 as attribute for glsl
Hi Ye Cong: For instance rendering,You can see osgEarth::Drawinstance,they use uniform texture buffer instead of vertex attribute. If you insist on using VertexAttribute,I guess you may inherit the osg::Geometry,and rewrite DrawImplement method,create a GLExtension to do this. just like this: contextID = state.getContextID(); osg::ref_ptr ext = osg::GLExtensions::Get(contextID, true); ext->glVertexAttribPointer(blabla); ext->glVertexAttribPointer(blabla); Finally,you can use Matrix Array uniform ,but it's a stupid way I think. -- Original -- From: "Cong Ye"; Date: 2018??11??27??(??) 12:58 To: "osg-users"; Subject: [osg-users] pass mat4 as attribute for glsl Hi, I am currently working on a project requires gpu instancing. I worked out a way to do the instancing with vec4 as position attribute in. However, in the real case, instances need to be scaled/rotated/translated. Now, I want to send the transform matrix as an attribute to the shader. Normally, general opengl uses glVertexAttribPointer with offset and glVertexAttribDivisor to sperate mat4 to vec4 then pass to the shader. However, I don't find the replacement function to do the offset data structure pass. Could someone enlighten me about it, please? thanks very much! ... Thank you! Cheers, Cong -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=75249#75249 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] pass mat4 as attribute for glsl
I found the gpuculling example. It may solve my problem.. -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=75250#75250 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] pass mat4 as attribute for glsl
Hi, I am currently working on a project requires gpu instancing. I worked out a way to do the instancing with vec4 as position attribute in. However, in the real case, instances need to be scaled/rotated/translated. Now, I want to send the transform matrix as an attribute to the shader. Normally, general opengl uses glVertexAttribPointer with offset and glVertexAttribDivisor to sperate mat4 to vec4 then pass to the shader. However, I don't find the replacement function to do the offset data structure pass. Could someone enlighten me about it, please? thanks very much! ... Thank you! Cheers, Cong -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=75249#75249 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Update node color on demand
Hello Trajce, The visitor class implementation is on my previous post on this thread. I took that code from Gordon Tomlison's OSG Samples, and it works when is used previous to the rendering as you can see on my initial post (other thread: http://forum.openscenegraph.org/viewtopic.php?p=75209#75209). As I said everything gets called when it should, but on runtime, the lines wont change color. I you look at the code snippet of my main: Code: _lines = osgDB::readNodeFile("lines.dxf"); _topo->setDataVariance(osg::Object::DYNAMIC); osg::Geode* geode = new osg::Geode; _mViewer->addEventHandler(new ColorHandler); ColorVisitor newColor; newColor.setColor( 1.0f, 0.0f, 0.0f ); _lines->accept(newColor); geode->addChild(_lines); _mViewer->realize(); The color of the lines turns red on start. But then, when I try to change it to another color on runetime, nothing happens. Anyway, here is the visitor implementation (.cpp): Code: ColorVisitor::ColorVisitor(): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { m_color.set(1.0, 1.0, 1.0, 1.0); m_colorArrays = new osg::Vec4Array; m_colorArrays->push_back(m_color); }; ColorVisitor::ColorVisitor(const osg::Vec4 ): osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { m_color = color; m_colorArrays = new osg::Vec4Array; m_colorArrays->push_back(m_color); }; ColorVisitor::~ColorVisitor() { }; void ColorVisitor::apply(osg::Node ) { // // // Handle traversal of osg::Node node types // // traverse(node); }; void ColorVisitor::apply(osg::Geode ) { // // // Handle traversal of osg::Geode node types // // osg::StateSet *state = NULL; unsigned intvertNum = 0; // // We need to iterate through all the drawables check if // the contain any geometry that we will need to process // unsigned int numGeoms = geode.getNumDrawables(); for (unsigned int geodeIdx = 0; geodeIdx < numGeoms; geodeIdx++) { // // Use 'asGeometry' as its supposed to be faster than a dynamic_cast // every little saving counts // osg::Geometry *curGeom = geode.getDrawable(geodeIdx)->asGeometry(); // // Only process if the drawable is geometry // if (curGeom) { osg::Vec4Array *colorArrays = dynamic_cast(curGeom->getColorArray()); if (colorArrays) { for (unsigned int i = 0; i < colorArrays->size(); i++) { osg::Vec4 *color = >operator [](i); // // could also use *color = m_color // color->set(m_color._v[0], m_color._v[1], m_color._v[2], m_color._v[3]); } } else { curGeom->setColorArray(m_colorArrays.get()); curGeom->setColorBinding(osg::Geometry::BIND_OVERALL); } } } }; void ColorVisitor::setColor(const float r, const float g, const float b, const float a) { // --- // // Set the color to change apply to the nodes geometry // // --- osg::Vec4 *c = _colorArrays->operator [](0); m_color.set(r, g, b, a); *c = m_color; }; void ColorVisitor::setColor(const osg::Vec4 ) { // --- // // Set the color to change apply to the nodes geometry // // --- osg::Vec4 *c = _colorArrays->operator [](0); m_color = color; *c = m_color; }; Cheers, -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=75248#75248 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Update node color on demand
Hi Diego, can you post your Visitor code? It can be something like missing calling ->dirty() on the color array or such On Mon, Nov 26, 2018 at 8:30 PM Diego Mancilla wrote: > Hello, > > I have tried Eran's suggestion with no success. I have successfully > created the handler, and it gets called but no color change... > > My current code: > > On main: > > Code: > _lines = osgDB::readNodeFile("lines.dxf"); > _topo->setDataVariance(osg::Object::DYNAMIC); > osg::Geode* geode = new osg::Geode; > > _mViewer->addEventHandler(new ColorHandler); > > ColorVisitor newColor; > newColor.setColor( 1.0f, 0.0f, 0.0f ); > _lines->accept(newColor); > geode->addChild(_lines); > _mViewer->realize(); > > > > > The handler: > > > Code: > bool ColorHandler::handle(const osgGA::GUIEventAdapter& ea, > osgGA::GUIActionAdapter& aa) > { > if (ea.getEventType() == ea.USER) > { > auto changeColorEvent = dynamic_cast ChangeColorEvent*>(ea.getUserData()); > if (changeColorEvent != nullptr) > { > std::cout << "Hola Handler!!!" << std::endl; > std::cout << "new color: " << > changeColorEvent->r<<" "<< changeColorEvent->g<< " "<< > changeColorEvent->b< ColorVisitor newColor; > newColor.setColor(changeColorEvent->r, > changeColorEvent->g, changeColorEvent->b); > changeColorEvent->node->accept(newColor); > return true; > } > } > return false; > > > > Thank you! > > Cheers, > Diego > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=75245#75245 > > > > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > -- trajce nikolov nick ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] osg::Cylinder height change not shown in OSG 3.6.3
Hi, I have an osg::Cylinder in an osg::ShapeDrawable and I change its height in an UpdateCallback like this: Code: cylinder->setHeight( h ); drawable->dirtyDisplayList(); drawable->dirtyBound(); This works in OSG 3.4.1 but with OSG 3.6.3 (at least on my Windows builds) the height change doesn't show up. Checking the value with getHeight shows that the cylinder height is updated so maybe the issue is that dirtyDisplayList is no longer sufficient to trigger the display update. I can try to put together a small self-contained example if this doesn't give anyone a clue what is going on. Any help will be much appreciated. And if this has exposed an OSG bug it would be good to fix for 3.6.4. Thanks! Cheers, Stuart -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=75246#75246 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Update node color on demand
Hello, I have tried Eran's suggestion with no success. I have successfully created the handler, and it gets called but no color change... My current code: On main: Code: _lines = osgDB::readNodeFile("lines.dxf"); _topo->setDataVariance(osg::Object::DYNAMIC); osg::Geode* geode = new osg::Geode; _mViewer->addEventHandler(new ColorHandler); ColorVisitor newColor; newColor.setColor( 1.0f, 0.0f, 0.0f ); _lines->accept(newColor); geode->addChild(_lines); _mViewer->realize(); The handler: Code: bool ColorHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) { if (ea.getEventType() == ea.USER) { auto changeColorEvent = dynamic_cast(ea.getUserData()); if (changeColorEvent != nullptr) { std::cout << "Hola Handler!!!" << std::endl; std::cout << "new color: " << changeColorEvent->r<<" "<< changeColorEvent->g<< " "<< changeColorEvent->bg, changeColorEvent->b); changeColorEvent->node->accept(newColor); return true; } } return false; Thank you! Cheers, Diego -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=75245#75245 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Update node color on demand
Hello Eran, Thank you again. I will try what you suggest. Cheers, -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=75244#75244 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] osgEarth often crashes in multi-display extension mode
Hi all, I have successfully compiled the osg and osgEarth. During the debugging process, I found that when using a single display,viewer(osgviewer and osgearth_viewer) could successfully running the cow.osg and glsl.earth. Now I want to use multi-display(two displays), the question is when using multi-display copy mode, the cow.osg and glsl.earth could be run successfully.But when using the multi-display extension mode, the cow.osg is runing OK, the glsl.earth crashes often occur(e.g. xxx has stopped working). Why does the osgEarth crash in multi-display extension mode? I'm surprised by such a problem. Is it a hardware problem or a software problem? Could you give me some suggestion about this question? Best regards?? Judy Fan.___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org