HI Gianni,

An osg::Array subclass like Vec3Array "is a" std::vector<> so you can use
all your usual std::vector<> access methods and code for it.  Sample
applies to DrawElementsUShort.

The easist way to manage things would be simply have your road code build
it using osg::Vec3Array, or get it to fill in the std::vector<> passed in
from external OSG glue code that passes in the std::vector<> from the
Vec3Array, i.e.


void MyClass::MyMethodPopulatingVertexData(std::vector<Vec3>& vertices)
{
    fill in data
}

myobject->MyMethodPopulatingVertexArray(*vec3Array);

If don't want to even integrate the std::vector<Vec3> but have your own
equivilant to Vec3 then you'll end up needing to copy the data across to
Vec3Array yourself or go the more complicated route of implementing your
own osg::Array subclass to integrate your own data.  The later requires
more work to glue it together though, you'll need to look at existing
osg::Array subclasses for guidance on how to do this.

Robert.

On 24 July 2014 13:54, Gianni Ambrosio <[email protected]> wrote:

> Here I am with an example that explains my scenario.
> I commented the code with questions, hoping this is clearer.
>
>
> Code:
>
> // This is a core road that contains all data and must not know of OSG at
> all
> class Road
> {
>         // This method builds vertices and indexes based on the internal
> data
>         // It must not use osg::Arrays but C arrays or std::vectors
>         void getPointsAndConnections(float*& oPoints, int& oPointSize,
> int*& oConnections, int& oConnectionSize);
> }
>
> // This class can not use OSG classes either (so no osg::Array here)
> class WaveFrontWriter
> {
>         // This method is pleased to use getPointsAndConnection() since it
> returns useful data.
>         // Here I can use a C array of an std::vector, not osg::Array
>         void write(Road* road) {
>                 road->getPointsAndConnections(vertices, vsize, indices,
> isize);
>                 // here vertices, vsize, indices, isize are used for
> writing the file ...
>         }
> }
>
> // Here is the 3D representation of the road
> class OsgRoad
> {
>         // This method is also pleased to use getPointsAndConnection() of
> Road core class
>         void draw(Road* road) {
>                 road->getPointsAndConnections(vertices, vsize, indices,
> isize);
>                 osg::Geometry* geometry = new osg::Geometry();
>                 // how to use incoming C arrays (or std::vectors would be
> also nice) in the following call?
>                 geometry->setVertexArray(<what here?>);
>                 // the following call luckily accepts C arrays but ...
>                 // 1) does it make a copy of the passed C array? (if so,
> that means memory duplication in my case)
>                 // 2) if not, is it responsible of deallocation?
>                 addPrimitiveSet(new
> osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, isize, indices));
>         }
> }
>
>
>
>
> Thank you in advance.
> Gianni
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=60435#60435
>
>
>
>
>
> _______________________________________________
> 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

Reply via email to