Hello Igor,

You're coming across as pretty aggressive. No one is forcing you to use OSG, it's a tool, if you choose to use it then you'll have to learn how to use it, like any other tool...

Ok, i'm still trying just to get data from object...
For the beginning i'm trying to copy only vertex array's.

For example - only first mesh:

vertices[s][v] = 
temp->asGroup()->getChild(0)->asGroup()->getChild(0)->asGeode()->getDrawable(0)->asGeometry()->getVertexArray()[v];

Stringing things like this is the best way to get incomprehensible code, in addition to getting crashes. What happens if temp is not a Group? if it has no children? if its child is not a group? if its child has no children? if its child's child is not a geode? if its child's child has no drawables? if the drawable is not a Geometry? if the Geometry has no vertex array? And you have a bug above, getVertexArray() returns a pointer to an osg::Array, not the array itself, so you need to dereference the pointer before getting the value at index v, but still you don't know the type of the data so you need to cast it...

The safe way to code this is to use a NodeVisitor to get to the osg::Geodes in the subgraph. Then iterate through the Geode's drawables, casting them to Geometry if possible, then getting the vertex array and casting that to an osg::Vec3Array, then if that returns a valid pointer iterate through the vertices and get them.

Perhaps I'm being too kind by giving you code which you could have just looked through the OSG examples to get, but perhaps this will help get you started on the right path.

class GetVerticesVisitor : public osg::NodeVisitor
{
public:
    GetVerticesVisitor()
        : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
    {
    }

    virtual void apply(osg::Geode& geode)
    {
        // Iterate through the drawables.
        for (unsigned int i = 0; i < geode.getNumDrawables(); ++i)
        {
            osg::Geometry* geometry =
                geode.getDrawlabe(i)->asGeometry();
            if (geometry)    // Make sure the object is a Geometry
            {
                osg::Vec3Array* vertices =
                    dynamic_cast<osg::Vec3Array*>(
                        geometry->getVertexArray());
                if (vertices)    // Make sure it was a Vec3Array
                {
                    // Use vertices as an std::vector, for example:
                    for (unsigned int j = 0; j < vertices->size(); ++j)
                    {
                        osg::Vec3 vertex_at_j = (*vertices)[j];
                    }
                }
            }
        }

        osg::NodeVisitor::apply(geode);
    }
};

This is just off the top of my head, hope it compiles cleanly but there may be a typo or two. But this demonstrates the safe and general way to get to vertex data given any loaded file. You don't have to know anything about the structure of the loaded file, and it will work, as opposed to the horrid series of calls you were stringing together above that would have worked on one model but not on the next.

If you want to be even more general, you should look into the PrimitiveFunctor and PrimitiveIndexFunctor interfaces. The above class will give you the vertex data, but will not tell you how these are arranged to form triangles. This is stored in the PrimitiveSet, also a member of the Geometry (like the vertex array). And the general way to get triangles or primitives from a Geometry is using PrimitiveFunctor and PrimitiveIndexFunctor.

And WTF? WTF is osg::Array?

WTF are you taking that tone with us? We're supposed to be civilized human beings here, and you're asking us for help. Please be polite at least.

It's a class. It helps OSG bridge the gap between data that OpenGL can understand and data that the user can understand (in a structure like an std::vector).

Why it is returned when index is set?

I don't understand this question.

Why it even exists?

Err, well you could assume it exists because it's useful... Just an idea.

How should i get data?

See above (GetVerticesVisitor).

getDataPointer() returns GLvoid pointer. Shame on me, but i dont know, how to 
use it.

You can cast GLvoid* into something else with static_cast or reinterpret_cast. But this is not what you need. It's not a safe way to get at the data. The above visitor is the safe way.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay    jean-sebastien.g...@cm-labs.com
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to