Re: [osg-users] Fwd: setting a polygon height

65 views
Skip to first unread message

Mohammed Rashad

unread,
Feb 25, 2013, 11:19:36 PM2/25/13
to OpenSceneGraph Users
Hi Robert,

Is it possible to have a 2D square looks like a cube?
for example I have 2D polygon if I could add a height parameter so that its look like a cube but faces are polygons. I dont know what are the exact terms to use to get good response.
hope this image url helps http://i.stack.imgur.com/OnRz3.png


----- Original Message -----
From: "Robert Osfield" <robert....@gmail.com>
To: "OpenSceneGraph Users" <osg-...@lists.openscenegraph.org>
Sent: Monday, February 25, 2013 9:26:16 PM
Subject: Re: [osg-users] Fwd: setting a polygon height

Hi Mohammed,

I'm guessing most of the community like me are rather perplexed by
what specifically you are expecting/looking for. The "heights of a
polygon" are simply it's z dimenion when you have a coordinate system
with Z up like the OSG defaults. So setting it randomly would just
entail setting the z value, but as your code show you already setting
the xyz values then one would have to guess that this isn't what you
mean at all. This leaves us rather stuck trying to guess what you
actually mean. Mentioning extrusion doesn't help either as this
rather tangential topic, or perhaps in your current view it's not.
Alas we can't jump in your head and know what you are meaning.

The only thing I can say with certainly is to say that the OSG doesn't
have an extrusion tool. The OSG is primarily a scene graph, not a
scene building tool.

Robert.

On 25 February 2013 15:37, Mohammed Rashad
<mohamme...@research.iiit.ac.in> wrote:
>
> Any update on this?
>
> ----- Forwarded Message -----
> From: "Mohammed Rashad" <mohamme...@research.iiit.ac.in>
> To: osg-...@lists.openscenegraph.org
> Sent: Wednesday, February 13, 2013 12:13:24 PM
> Subject: [osg-users] setting a polygon height
>
> How to set the height of a polygon in OSG 3.0?
>
> I have created some polygon which are 2D. I want to assing random heights for the polygon. How this can be done?
> osg::Geometry* polyGeom = new osg::Geometry();
> and i then feed the vertices like:
> osg::Vec3 myCoords[] =
> {
> osg::Vec3(-1.0464, 1.0f, -0.193626),
> osg::Vec3(-1.0258, 1.0f, -0.26778),
> osg::Vec3(-0.807461, 1.0f, -0.181267),
> osg::Vec3(-0.766264, 1.0f, -0.0576758),
> osg::Vec3(-0.980488, 1.0f, -0.094753)
> };
>
> Is there anything like ExtrudeGeometry in OSG?
> _______________________________________________
> osg-users mailing list
> osg-...@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> _______________________________________________
> osg-users mailing list
> osg-...@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Sergey Kurdakov

unread,
Feb 26, 2013, 2:26:00 AM2/26/13
to OpenSceneGraph Users
Hi Mohammed,

yes - it is possible - to move vertices changing their coordinates in callback or in shader (say you have 'flat cube' assuming initially you have all  neccesary cube vertices in place, then you have what you want, if you have just one square - then tesselate accordingly, then move vertices as assumed initially ).

( every example with cloth or ocean,  for example, makes just that - moves vertices, the same way
it is possible to achieve what you need), correct?

as to how to move vertice coordinaties in either case, just check examples 

Regards
Sergey


Robert Osfield

unread,
Feb 26, 2013, 4:27:49 AM2/26/13
to OpenSceneGraph Users
Hi Mohammed,

On 26 February 2013 04:19, Mohammed Rashad
<mohamme...@research.iiit.ac.in> wrote:
> Is it possible to have a 2D square looks like a cube?

You can do anything you want with your geometry, but you have to
create what you want, the OSG doesn't provide a means of automatically
converting a square/polygon to a object with sides and end caps like
your photo. What you are asking for is very specific function and is
has to be implemented in user code.

Once you have you geometry you can animate it using an update callback
that updates the vertices on the geometry, or use a shader to do the
same.

Robert.

Christian Buchner

unread,
Feb 26, 2013, 5:17:52 AM2/26/13
to OpenSceneGraph Users
I've done this stuff before for buildings that are vertically extruded from a polygon shape

step
1) create an osg::Geometry
2) create a vertex buffer with two copies of the polygon vertices, the second copy having a different z coordinate. use setVertexArray()
3) For proper lighting, create a normal array also with one normal per vertex, matching the indexing in the vertex array. use setNormalArray().
4) run a tesselation algorithm to to create a list of triangles that will form the top and bottom faces (concave polygons aren't supported in hardware, so tesselation is mandatory)
5) using an index buffer, create triangle primitives for the top and bottom faces based on the tesselation results
6) create a quads primitive for the surfaces on the side, possibly also using index buffers. You can't really use a quad strip here, or the normal vectors for touching quads will be shared, which leads to an (undesired) smooth shading effect for the sides.

some very small code snippets

// less then 256 vertices can use an UByte based index buffer
std::vector<unsigned char>  indices_c;
// omitted here is the tesselation process creating the vertex indices
roofGeometry->addPrimitiveSet(new osg::DrawElementsUByte( GL_TRIANGLES, indices_c.size(), &indices_c[0] ));

// alternatively less then 65536 vertices can use an UShort based index buffer
std::vector<unsigned short> indices_s;
// omitted here is the tesselation process creating the vertex indices
roofGeometry->addPrimitiveSet(new osg::DrawElementsUShort( GL_TRIANGLES, indices_s.size(), &indices_s[0] ));

// I am actually storing my vertices for the quads in a separate Geometry, so I can use DrawArrays instead of an index buffer for the quads making up the sides. Then the vertices for each quad are taken in sequential order from the vertex buffer.
sideGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,num_vertices_per_polygon_ring);

If you need your quad strip on the side to have different color or different vertex attributes, your vertex buffer needs to contain the polygon ring four times.

You should look at some osg examples that create their own geometry based on vertex buffers to get the hang of it.

Christian

2013/2/26 Robert Osfield <robert....@gmail.com>
Reply all
Reply to author
Forward
0 new messages