[osg-users] Updating scene properties instead of recreation it each frame.
Igor Spiridonov
igwasm at rambler.ru
Sun Jul 1 22:34:34 PDT 2018
Hi. I'm wandering if it's ok what i'm doing and how to do it properly.
I have data of primitives which comes from source periodically. These primitives are points, lines, polygons. They have different sizes, colors, vertices, etc. My first approach was to create a new subscene each time i receive new data and replace a current node to a new one. But to create a new scene each frame is not very fast operation(a lot of allocation /deallocation). So instead of that I've decided to update existing scene by changing vertices, primitive types, etc. But I'v noticed that some data somewhat cached. For example.
Code:
osg::Vec3Array& vertices = static_cast<osg::Vec3Array&>(*geometry.getVertexArray());
vertices.clear();
for (int i = 0; i < logPolygon.points.size(); i++)
{
auto& point = logPolygon.points[i];
vertices.push_back(osg::Vec3(point.X / 100.f, point.Y / 100.f, 0.f));
}
geometry.setVertexArray(&vertices); // i need to do that otherwise scene is incorrect.
My first question is why do I need to set vertex array again? "geometry.setVertexArray(&vertices);"
The second question is it ok to do such update of all properties instead of full scene recreation? What other drawbacks can be? Is there a better approach?
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74235#74235
More information about the osg-users
mailing list