Now I am working in adding occlusion in AR application. For that, I
need to override draw function.
I found some example using Producer::Camera::SceneHandler, using this
class we can write down our own draw function. I put openGL draw
function primitives inside draw function. It works fine. However,
other model in the scenegraph seems not be drawn. I dont know how to
call draw function for other models.
Below I put my codes:
When I run this codes, only cubes are drawn in the screen. The other
model (domino) is not drawn.
I think I need to call function to draw domino inside MySceneHandler2,
I tried several ways but it is not success.
If you have any suggestion, please let me know.
class MySceneHandler2 : public Producer::Camera::SceneHandler
{
public:
MySceneHandler2(osgProducer::OsgSceneHandler *sh) :
Producer::Camera::SceneHandler(),
_sh(sh)
{}
virtual void draw( Producer::Camera & camera )
{
glEnable( GL_DEPTH_TEST );
glClearColor( 0.5, 0.5, 0.5, 1.0 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
// Lazy initialize
if( !_initialized ) init();
glPushMatrix();
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glTranslatef( _x, _y, _z);
glRotatef( _angle, 1, 0, 0 );
glRotatef( _angle, 0, 1, 0 );
// Draw the OpenGL cube
glCallList( _cube );
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glPopMatrix();
glFlush();
}
osgProducer::OsgSceneHandler *_sh;
}
int main(int argc, char **argv)
{
osgProducer::Viewer *viewer = new osgProducer::Viewer();
viewer->setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
osg::Node* modelNode = osgDB::readNodeFile("I:/Research/OSG-based-
NAVER/NAVER/bin/models/wood_domino.pfb");
osg::MatrixTransform* modelTransform = new osg::MatrixTransform;
osg::Matrix modelScale;
osg::Matrix modelTranslate;
osg::Matrix modelRot;
modelScale.makeScale(1.0, 1.0, 1.0);
modelRot.makeRotate(0.,osg::Vec3f(1.,0.,0.));
modelTranslate.makeTranslate(osg::Vec3(0, 0, 0));
modelTransform->postMult(modelTranslate);
modelTransform->postMult(modelRot);
modelTransform->postMult(modelScale);
modelTransform->addChild(modelNode);
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild(modelTransform);
osgProducer::OsgSceneHandler *sh =
dynamic_cast<osgProducer::OsgSceneHandler *>(
viewer->getCamera(0)->getSceneHandler() );
osgUtil::SceneView *sv = NULL;
if( sh != 0L )
{
sh->getSceneView()->getRenderStage()->setClearMask(0);
sv= sh->getSceneView();
}
viewer->getCamera(0)->getRenderSurface()->fullScreen(true);
viewer->realize();
viewer->getCamera(0)->setSceneHandler( new MySceneHandler2(sh) );
viewer->setSceneData(root.get());
while (!viewer->done())
{
viewer->sync();
viewer->update();
viewer->frame();
}
viewer->sync();
viewer->cleanup_frame();
viewer->sync();
return 0;
}
virtual void | setDrawCallback (DrawCallback *dc) |
| Set the DrawCallback which allows users to attach customize the drawing of existing Drawable object. |
I have tried using setDrawCallback, but this function is member of
Drawable class so I can not attach it to osg::Node or
osg::ModelTransform.
On Apr 12, 10:10 pm, "Changhoon Park" <changhoonp...@gmail.com> wrote:
> virtual void setDrawCallback<http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDo...>(
> DrawCallback<http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDo...>*dc)
> Set the DrawCallback<http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDo...>which
> allows users to attach customize the drawing of existing
> Drawable<http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDo...>object.
>
> Hello sylvi
>
> What about using drawcallback?
>
> You can define a different way of drawing for a specific node without
> disturbing other nodes.
>
> C. Park
>
> --
> Changhoon PARK- Hide quoted text -
>
> - Show quoted text -
| const Drawable * | getDrawable (unsigned int i) const |
Return the Drawable at position
i. |
I found the way how to overide draw function using
osg::Drawable::DrawCallback and osg::NodeVisitor to traverse the node.
I took example from osgcallback.
It seems work in my simple application. Now I am adding it to
nvmOSGART.
I will give you an update later.
Thank you.
sylvi
On Apr 12, 10:48 pm, "Changhoon Park" <changhoonp...@gmail.com> wrote:
> const Drawable<http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDo...>*
> getDrawable<http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDo...>(unsigned
> int i) const
> Return the Drawable<http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDo...>at
> position
> i.
>
> osg::Geode ...
>
> > > > modelRot.makeRotate (0.,osg::Vec3f(1.,0.,0.));
It is still not perfect but it seems better than no occlusion at all.
How does it work?
I create 3D model for floor, wall, stair and attach those model to the
marker.
Inside OSGART, I create the DrawCallback and NodeVisitor class. (code
is attached below).
(I dont use PreDraw or PostDraw since this process has to be done in
the first stage of draw)
In the XML file, we specify which models are the occlusion model.
The occlusion models need to be draw first before the other models,
therefore
the occlusion models have to be attach first before the other models
are attached to the marker.
In draw callback function, by disabling the color buffer, the
occlusion model will be drawn in Depth Buffer only.
Next, the other models will be drawn in color and depth buffer.
As the result, when the occlusion model is closer to the camera, the
image capture by camera will appear occludes the 3D model.
sylvi
=================================================
codes:
class DrawableOcclusionDrawCallback : public
osg::Drawable::DrawCallback
{
virtual void drawImplementation(osg::State& state,const
osg::Drawable* drawable) const
{
glPushAttrib(GL_COLOR_BUFFER_BIT);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); //disable color
buffer
drawable->drawImplementation(state);
glPopAttrib(); //restore the values
}
};
class InsertOcclusionCallbacksVisitor : public osg::NodeVisitor
{
public:
InsertOcclusionCallbacksVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
}
virtual void apply(osg::Node& node)
{
traverse(node);
}
virtual void apply(osg::Geode& geode)
{
for(unsigned int i=0;i<geode.getNumDrawables();++i)
{
geode.getDrawable(i)->setDrawCallback(new
DrawableOcclusionDrawCallback());
}
}
virtual void apply(osg::Transform& node)
{
apply((osg::Node&)node);
}
};
On Apr 13, 12:02 pm, "Changhoon Park" <changhoonp...@gmail.com> wrote:
> Good job !
>
> Maybe you can find difference between callback of module and that of scene
> graph node.
>
> In my thinking, you case is first one to use node callbacks.
>
> You can extend your modules to define draw callback.
> If there will be more cases like you, we will extend our kernel to support
> node callback at the module
>
> C. Park.
>
> > > > > > modelRot.makeRotate(0.,osg::Vec3f(1.,0.,0.));
Do I answer your question?
sylvi
On Apr 14, 10:46 pm, "Changhoon Park" <changhoonp...@gmail.com> wrote:
> Hello sylvi
>
> I wonder that what if there are one more than occlusion object.
> like the oder of rendering ?
>
> C. Park
>
> On 4/14/07, sylvi <sylv...@gmail.com> wrote:
>
>
>
>
>
> > I have added the occlusion into nvmOSGART module.
> > The result can be seen in
>
> >http://groups.google.com/group/naver-based-on-osg/web/occlusion-resul...
> > InsertOcclusionCallbacksVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
> ...
>
> read more »- Hide quoted text -