[osg-users] Geometry

65 views
Skip to first unread message

Vincent Bourdier

unread,
Apr 18, 2008, 10:17:27 AM4/18/08
to osg
Hi All,

I've a new problem, which is about Geometries.

this is simple : I've a node, already with a texture, and I want to put a second texture on it. BUT, the second texture have to be well positioned on the node, without depending on the Geometry's texture coordinates...

I've tried osg::TexGen and osg::TextureCubeMap but the second texture is never put correctly on the node...

How can I get the texture coordinates ? or how can I put the second texture right on the node ?
Thanks.

Regards,
   Vincent.

Brian R Hill

unread,
Apr 18, 2008, 10:28:24 AM4/18/08
to OpenSceneGraph Users, osg
Vincent,

I'm not sure what you're trying to do. The second texture will only look
right on the geometry if you define the texture coordinates to make it
right.

Each texture has it's own texture coordinates:
osg::Geometry::setTexCoordArray(texture unit, texture coordinate array)

The first texture should use texture unit 0 and the second should use
texture unit 1.

Brian

-----osg-user...@lists.openscenegraph.org wrote: -----


To: osg <osg-...@lists.openscenegraph.org>
From: "Vincent Bourdier" <vincent....@gmail.com>
Sent by: osg-user...@lists.openscenegraph.org
Date: 04/18/2008 10:17AM
Subject: [osg-users] Geometry

Hi All,

Regards,
Vincent.
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This is a PRIVATE message. If you are not the intended recipient, please
delete without copying and kindly advise us by e-mail of the mistake in
delivery. NOTE: Regardless of content, this e-mail shall not operate to
bind CSC to any order or other contract unless pursuant to explicit written
agreement or government initiative expressly permitting the use of e-mail
for such purpose.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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

Vincent Bourdier

unread,
Apr 18, 2008, 10:32:10 AM4/18/08
to OpenSceneGraph Users
Brian,
ok so if I understand well, i can set a second array of coordinate of texture. but for that I need the geometry... and i only can get the drawable from a geode... so how can I get the geometry ?

thanks for help.

Vincent.

2008/4/18, Brian R Hill <bhi...@csc.com>:

Jean-Sébastien Guay

unread,
Apr 18, 2008, 10:36:05 AM4/18/08
to OpenSceneGraph Users
Bonjour Vincent,

> this is simple : I've a node, already with a texture, and I want to put
> a second texture on it. BUT, the second texture have to be well
> positioned on the node, without depending on the Geometry's texture
> coordinates...

Geometry can (and should) have texture coordinates for each texture unit
you want to use. In your case you want to use units 0 and 1, so you
should have texture coordinates for units 0 and 1.

> I've tried osg::TexGen and osg::TextureCubeMap but the second texture is
> never put correctly on the node...

**** Option 1 ****

osg::TexGen generates texture coordinates in a few different modes. It
might be what you want, but it might not. See glTexGen (search Google or
consult the red book) for a description of the different modes TexGen
supports. In your case, if your first texture (unit 0) is applied
correctly and you want to generate texture coordinates on unit 1 using a
TexGen, you should use:

osg::ref_ptr<osg::TexGen> texgen = new osg::TexGen;
texgen->setMode( <the mode you want> );
geometry->getOrCreateStateSet()->setTextureAttributeAndModes(1,
texgen.get(), osg::StateAttribute::ON);

The "1" there specifies the texture unit you want the TexGen to affect.

Then you would add your texture as you normally do, but to unit 1 as well.

osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D(
osgDB::readImageFile("blah.jpg"));
geometry->getOrCreateStateSet()->setTextureAttributeAndModes(1,
texture.get(), osg::StateAttribute::ON);

**** Option 2 ****

But as I said, TexGen only generates texture coordinates in a few
specific modes. If you want something else, you'll have to make texture
coordinates in your modeling program, or programmatically... For example:

osg::ref_ptr<osg::Vec2Array> texcoordsUnit1 = new osg::Vec2Array;

// Populate the Vec2Array with texture coordinates, normally as
// many Vec2 instances as you have vertices in your geometry.

geomtry->setTexCoordArray(1, texcoordsUnit1.get());

Again, assigned to unit 1.

**** Option 3 ****

You could also use the same texture coordinates on unit 1 as on unit 0:

geometry->setTexCoordArray(1, geometry->getTexCoordArray(0));

(I think that should work, never tested it, but if it doesn't work you
could clone the texcoord array from unit 0 and then assign it to unit 1)

So you see, lots of options. It all depends on what you want as your
texture coordinates!

Hope this helps, and hope it was comprehensible... :-)

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/

Jean-Sébastien Guay

unread,
Apr 18, 2008, 10:38:27 AM4/18/08
to OpenSceneGraph Users
Bonjour Vincent,

> ok so if I understand well, i can set a second array of coordinate of
> texture. but for that I need the geometry... and i only can get the
> drawable from a geode... so how can I get the geometry ?

Use a NodeVisitor to get to the geode you want (only you can know which
one you want, either by name or any other trait, or just find any
geode), and then get its drawables and check to see if they're instances
of osg::Geometry.

Check the examples for uses of NodeVisitor to find a node.

J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/

Vincent Bourdier

unread,
Apr 18, 2008, 10:41:37 AM4/18/08
to OpenSceneGraph Users
Hi Jean-Sébastien,

This is a very clear and complete explanation.

I'll will try all these to get the best in my case.

thanks a lot for these quick answers !!

Regards,
   Vincent.

2008/4/18, Jean-Sébastien Guay <jean-seba...@cm-labs.com>:

Brian R Hill

unread,
Apr 18, 2008, 10:47:20 AM4/18/08
to OpenSceneGraph Users, OpenSceneGraph Users
Vincent,

The geode can have any number of drawables associated with it. You need to
know which one you are interested in.

for (unsigned int ii=0; ii<geode->getNumDrawables(); ++ii)
{
osg::Geometry * geom = dynamic_cast<osg::Geometry
*>(geode->getDrawable(ii));
if (geom)
{
// do your stuff here
}
}


Brian
-----osg-user...@lists.openscenegraph.org wrote: -----


To: "OpenSceneGraph Users" <osg-...@lists.openscenegraph.org>

Date: 04/18/2008 10:32AM
Subject: Re: [osg-users] Geometry

Brian,
ok so if I understand well, i can set a second array of coordinate of
texture. but for that I need the geometry... and i only can get the
drawable from a geode... so how can I get the geometry ?

thanks for help.

Vincent.


2008/4/18, Brian R Hill < bhi...@csc.com >:
Vincent,

I'm not sure what you're trying to do. The second texture will only look
right on the geometry if you define the texture coordinates to make it
right.

Each texture has it's own texture coordinates:
osg::Geometry::setTexCoordArray(texture unit, texture coordinate array)

The first texture should use texture unit 0 and the second should use
texture unit 1.

Brian

----- osg-user...@lists.openscenegraph.org wrote: -----

Reply all
Reply to author
Forward
0 new messages