Re: [osg-users] geometry and normals

2014-07-26 Thread Gianni Ambrosio

STTrife wrote:
 
 Anyway you have indexed vertices obviously, but you can also use non-indexed 
 vertices. In that case you just specify the vertices for each triangle 
 separately.
 

That's basically my first implementation and the reason why I asked 
confirmation here was to understand which is the better way in my case. In a 
road I have always adjacent triangles (holes or disjointed parts are very rare) 
so I think what Robert suggested is the proper solution.

STTrife wrote:
 
 Now I've confused myself :P

I was too, that's why I asked here ;)

Regards
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60464#60464





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-25 Thread Bram Vaessen
it seems like you are using referenced vertices in your roads mesh? (at least 
that is what I understand from int* oConnections
(the int references vertices indexes right?)

I think that if you want to use the accelerated drawing you should convert it 
to simple vertex arrays, where the vertices are not indexed.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60455#60455





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-25 Thread Gianni Ambrosio
Hi STTrife,
which is the difference between what you say and what Robert suggested here?

robertosfield wrote:
 
 As for memory/GL efficiency, the most efficient way to the geometry to the 
 GPU is to use index primitives via the osg::DrawElements* primitive set, this 
 allows you to share vertex, normal, texture coordinate data etc.
 


Regards,
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60457#60457





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-25 Thread Bram Vaessen
Well to give better advice, I would need to understand what is exactly stored 
in float* oPoints and int* oConnections.

What I assume is that oPoints (an array of floats) contains
x1,y1,z1,x2,y2,z2, etc.
and then oConnections (an array of ints) contains a serie of references to 
those points for example 2 refers to x2,y2,z2.

Maybe you could first tell something about this (if this is correct or not) 
before I comment further... maybe I misunderstand what is in those arrays...

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60458#60458





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-25 Thread Gianni Ambrosio
OK,
this is an exaple (flat square road):

Code:

   osg::Geometry* geometry = getGeometry();
   osg::Vec3 myCoords[] =
   {
  osg::Vec3(-1.0f,1.0f,0.0f),
  osg::Vec3(-1.0f,-1.0f,0.0f),
  osg::Vec3(1.0f,-1.0f,0.0f),
  osg::Vec3(1.0f,1.0f,0.0f)
   };
   int numCoords = sizeof(myCoords)/sizeof(osg::Vec3);
   geometry-setVertexArray(new osg::Vec3Array(numCoords,myCoords));
   unsigned short myIndices[] =
   {
  0,
  1,
  2,
  0,
  2,
  3
   };
   int numIndices = sizeof(myIndices)/sizeof(unsigned short);
   geometry-addPrimitiveSet(new 
osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES,numIndices,myIndices));




Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60459#60459





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-25 Thread Bram Vaessen
First: In your example the coordinates are stored in an array of Vec3, but in 
the other code you posted, the oPoints is an array of float so there seems to 
be a bit of a contradiction there?

Anyway you have indexed vertices obviously, but you can also use non-indexed 
vertices. In that case you just specify the vertices for each triangle 
separately. 

When I started working on my project I heard or read that this is better, 
because it can be handled faster by modern graphics card (something about the 
card not being able to use the fasted render path when indices are used), and 
the extra memory it takes is less important because modern graphics cards have 
plenty of memory. 

But I can't find a solid source on that now so I'm really starting to doubt if 
this is (still) true...

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60460#60460





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-25 Thread Robert Osfield
Hi Bram,

Most modern hardware will be best driven using indexed primitives sets
rather than duplicating vertices - it typically wins on memory bandwidth
and ability to utilize the vertex cache on the GPU.  If the amount of
shared indices is low then duplicating vertices is likely to be better.

Robert.


On 25 July 2014 14:30, Bram Vaessen bram.vaes...@gmail.com wrote:

 First: In your example the coordinates are stored in an array of Vec3, but
 in the other code you posted, the oPoints is an array of float so there
 seems to be a bit of a contradiction there?

 Anyway you have indexed vertices obviously, but you can also use
 non-indexed vertices. In that case you just specify the vertices for each
 triangle separately.

 When I started working on my project I heard or read that this is better,
 because it can be handled faster by modern graphics card (something about
 the card not being able to use the fasted render path when indices are
 used), and the extra memory it takes is less important because modern
 graphics cards have plenty of memory.

 But I can't find a solid source on that now so I'm really starting to
 doubt if this is (still) true...

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=60460#60460





 ___
 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] geometry and normals

2014-07-24 Thread Gianni Ambrosio
Hi Robert,
one more question.

I would like to implement a method in my core class to get vertices and indices 
to use both in osg geometry and in a wavefront writer. The problem is the array 
type. I don't want to write the same code twice one for the wavefront writer 
and one for osg geometry just because they use different array/vector types.
The wavefront writer can use C arrays or std::vectors. 
I see that a C array can be used in a DrawElementsUShort constructor.
On the other side setVertexArray gets an osg::Array as parameter. I'm trying to 
understand how to use a C array or a std::vector instead.

In any case at a certain point I have memory allocation for vertices and 
indices twice (the array I created and the copy for osg geometry).

Regards,
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60430#60430





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-24 Thread Robert Osfield
HI Giannu,

I can't work out what your one more question is, I've re-read what you
written and am just as confused.

Robert.


On 24 July 2014 11:43, Gianni Ambrosio g.ambrosio+...@gmail.com wrote:

 Hi Robert,
 one more question.

 I would like to implement a method in my core class to get vertices and
 indices to use both in osg geometry and in a wavefront writer. The problem
 is the array type. I don't want to write the same code twice one for the
 wavefront writer and one for osg geometry just because they use different
 array/vector types.
 The wavefront writer can use C arrays or std::vectors.
 I see that a C array can be used in a DrawElementsUShort constructor.
 On the other side setVertexArray gets an osg::Array as parameter. I'm
 trying to understand how to use a C array or a std::vector instead.

 In any case at a certain point I have memory allocation for vertices and
 indices twice (the array I created and the copy for osg geometry).

 Regards,
 Gianni

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=60430#60430





 ___
 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] geometry and normals

2014-07-24 Thread Gianni Ambrosio
OK, is there a way to pass a C array to geometry-setVertexArray()?

Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60432#60432





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-24 Thread Trajce Nikolov NICK
Hi Gianni,

this is more into STL programming. This link explains cheap conversion
between C array and STL vector

http://stackoverflow.com/questions/1733143/converting-between-c-stdvector-and-c-array-without-copying

Nick


On Thu, Jul 24, 2014 at 1:28 PM, Gianni Ambrosio g.ambrosio+...@gmail.com
wrote:

 OK, is there a way to pass a C array to geometry-setVertexArray()?

 Gianni

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=60432#60432





 ___
 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


Re: [osg-users] geometry and normals

2014-07-24 Thread Gianni Ambrosio
Hi Nick,
no this is not a problem of converting C arrays to stl vectors. I'm going to 
explain the case in detail soon ..

Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60434#60434





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-24 Thread Gianni Ambrosio
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
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-24 Thread Robert Osfield
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::vectorVec3 vertices)
{
fill in data
}

myobject-MyMethodPopulatingVertexArray(*vec3Array);

If don't want to even integrate the std::vectorVec3 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 g.ambrosio+...@gmail.com 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
 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] geometry and normals

2014-07-23 Thread Robert Osfield
Hi Gianni,

The SmoothingVisititor is really just a fallback for when no normals are
provided with a model, the best way to get the precisely the result you
want is to provider per vertex normals.

As for memory/GL efficiency, the most efficient way to the geometry to the
GPU is to use index primitives via the osg::DrawElements* primitive set,
this allows you to share vertex, normal, texture coordinate data etc.

Robert.


On 23 July 2014 13:59, Gianni Ambrosio ga...@vi-grade.com wrote:

 Hi All,
 I need to draw a surface. Looking at OSG examples I implemented it this
 way:


 Code:

osg::Geometry* geometry = getGeometry();
osg::Vec3Array* vertices = new osg::Vec3Array;
GraphicVectorPtr graphicVector = road-graphicVector();
size_t count = graphicVector-count();
size_t addedPoints = 0;
vertices-reserve(count * 3);
for (size_t i = 0; icount; ++i) {
   const GraphicItem item = (*graphicVector)[i];
   if (item.points.size() == 9) {
  vertices-push_back(osg::Vec3(item.points[0], item.points[1],
 item.points[2]));
  vertices-push_back(osg::Vec3(item.points[3], item.points[4],
 item.points[5]));
  vertices-push_back(osg::Vec3(item.points[6], item.points[7],
 item.points[8]));
  addedPoints+=3;
   }
}
geometry-setVertexArray(vertices);
geometry-addPrimitiveSet(new
 osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, addedPoints));




 Now, first of all I would like to know if this is correct. I mean I want
 to draw triangles and I don't want to waste memory.

 The problem is that I see a basically flat surface. I tried then with a
 SmoothingVisitor on the geometry and the flat surface problem is solved. So
 I guess it was related to normals not set, right?

 Now, since I don't like so much how the surface is rendered with the
 SmoothingVisitor, is there a way of render the surface as it is drawn?

 Regards,
 Gianni

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=60407#60407





 ___
 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] geometry and normals

2014-07-23 Thread Gianni Ambrosio
Hi Robert,
just because I had in mind a thread in this forum where it seems, on the 
contrary, that was NOT recommended for GL efficiency. Do you mean something 
like the code inside createBackground() of osggeometry.cpp example?

polyGeom-setVertexArray(new osg::Vec3Array(numCoords,myCoords));
... 
polyGeom-addPrimitiveSet(new 
osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP,numIndices,myIndices));

so, basically the same content of a obj/wavefront file?

Regards,
Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60412#60412





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-23 Thread Robert Osfield
HI Gianni,


On 23 July 2014 16:25, Gianni Ambrosio ga...@vi-grade.com wrote:

 Hi Robert,
 just because I had in mind a thread in this forum where it seems, on the
 contrary, that was NOT recommended for GL efficiency.


What isn't recommend is using the deprecated
osg::Geometry::setVertex/Color/Normal/etc./Indices(..) functionality,
sharing vertices via vertex indices isn't supported by OpenGL and has to be
simulated by caching vertex data on the CPU and then send this as a buffer.
 In OSG-3.2 these methods are deprecated and will be removed completely
from OSG-3.4 onwards.



 Do you mean something like the code inside createBackground() of
 osggeometry.cpp example?

 polyGeom-setVertexArray(new osg::Vec3Array(numCoords,myCoords));
 ...
 polyGeom-addPrimitiveSet(new
 osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP,numIndices,myIndices));


Using DrawElementsUShort is the correct way to provide indices and is fully
supported by OpenGL and is the recommend way to provide primitive data
where vertices can be shared.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] geometry and normals

2014-07-23 Thread Gianni Ambrosio
Thank you Robert for explanation and clarification.

Gianni

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=60415#60415





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org