[osg-users] EXTERNAL: Re: Writing texture coordinates on a mesh without going through traversal code?

Rowley, Marlin R marlin.r.rowley at lmco.com
Sat Apr 14 09:27:40 PDT 2018


Hi Robert!

After a lot of hours staying up last night, this morning I found the solution.  It was surprisingly easy.

When I get back to work on Monday I will post the code that hopefully will help other people in the future.  It didn’t have to be as complicated as we were going from before.  Especially not with VS/PS 3.0+.  Fixed-function pipeline is all but obsolete these days.

-M

From: osg-users [mailto:osg-users-bounces at lists.openscenegraph.org] On Behalf Of Robert Osfield
Sent: Saturday, April 14, 2018 2:15 AM
To: OpenSceneGraph Users <osg-users at lists.openscenegraph.org>
Subject: EXTERNAL: Re: [osg-users] Writing texture coordinates on a mesh without going through traversal code?

HI Marlin,

I would hope that you can implement what you need without getting your hands dirty with internals of the OSG. It sound like you want something similar to osg::ClipPlaneNode.  Have a look at osgclip to see how it works.

Robert.

On 13 April 2018 at 22:30, Rowley, Marlin R <marlin.r.rowley at lmco.com<mailto:marlin.r.rowley at lmco.com>> wrote:
Hello!

I’m trying to generate my own texture coordinates (on-the-fly) by having a callback that runs when a piece of geometry intersects my object.  So for example, I create a realworld frustum and when my frustum has a shader that’s bound to some arbitrary object in the world.  When my frustum intersects this object, I would like to generate texture coordinates on this object based on how far or near I am to the frustum’s near/far planes (it’s perspective frustum).  We had the following code for doing this:

void ViewshedOSG::updateTextureCoordinates()
{
// write the plane equation for all 3 planes
// that make up the camera view frustum.  We can
// then access this from the shader to test whether
// we are in the frustum's volume or not.
    osg::Matrixd projection = mCamera->getViewMatrix();
      mTexGen->setPlanesFromMatrix(projection *
      osg::Matrix::translate(1.0, 1.0, 1.0) *
      osg::Matrix::scale(0.5f, 0.5f, 0.5f));
// Bring our models viewspace coordinates back
// into model space coordinate of the camera frustum
osg::RefMatrix * refMatrix = new osg::RefMatrix
           (mCamera->getInverseViewMatrix() * *_cv->getModelViewMatrix());
// Copy the texture generator to the mesh where you
// can index it's coordinates from the ViewshedID
      _cv->getRenderStage()->getPositionalStateContainer()->
            addPositionedTextureAttribute
            (mId, refMatrix, mTexGen.get());
}


However, this code was based on a cull visitor calling this function from a callback.  I have my own callback and it’s not based on a visitor. Is there anyway to get the objects modelview matrix() without calling it from a cull visitor?  Also only need to write the ‘addPositionedTextureAttribute’ on the geometry in order to access the coordinates through a shader.

I’m trying to keep this simple.  Am I in the right direction?

Thanks,

-M
----------------------------------------
Marlin Rowley
Software Engineer, Staff
[cid:image002.jpg at 01D39374.DEC5A2E0]
Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
marlin.r.rowley at lmco.com<mailto:marlin.r.rowley at lmco.com>


_______________________________________________
osg-users mailing list
osg-users at lists.openscenegraph.org<mailto:osg-users at lists.openscenegraph.org>
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20180414/547cd7ff/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 3114 bytes
Desc: image001.jpg
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20180414/547cd7ff/attachment-0001.jpg>


More information about the osg-users mailing list