2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-12-08 05:18:12 +08:00
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/Notify>
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#define square(x) ((x)*(x))
|
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
Geode::Geode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
Geode::Geode(const Geode& geode,const CopyOp& copyop):
|
|
|
|
Node(geode,copyop)
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
{
|
|
|
|
for(DrawableList::const_iterator itr=geode._drawables.begin();
|
|
|
|
itr!=geode._drawables.end();
|
|
|
|
++itr)
|
|
|
|
{
|
2002-01-29 22:04:06 +08:00
|
|
|
Drawable* drawable = copyop(itr->get());
|
2002-01-29 20:52:04 +08:00
|
|
|
if (drawable) addDrawable(drawable);
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
}
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
Geode::~Geode()
|
|
|
|
{
|
2002-02-09 06:55:21 +08:00
|
|
|
// remove reference to this from children's parent lists.
|
|
|
|
for(DrawableList::iterator itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->removeParent(this);
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
bool Geode::addDrawable( Drawable *drawable )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2006-07-18 19:03:46 +08:00
|
|
|
if (drawable /* && !containsDrawable(drawable)*/)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-02-09 06:55:21 +08:00
|
|
|
// note ref_ptr<> automatically handles incrementing drawable's reference count.
|
|
|
|
_drawables.push_back(drawable);
|
|
|
|
|
|
|
|
// register as parent of drawable.
|
|
|
|
drawable->addParent(this);
|
|
|
|
|
2005-05-02 17:57:58 +08:00
|
|
|
if (drawable->requiresUpdateTraversal())
|
2002-07-10 23:35:47 +08:00
|
|
|
{
|
2002-12-19 23:55:40 +08:00
|
|
|
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
2002-07-10 23:35:47 +08:00
|
|
|
}
|
|
|
|
|
2005-05-02 17:57:58 +08:00
|
|
|
if (drawable->requiresEventTraversal())
|
2005-02-25 22:02:48 +08:00
|
|
|
{
|
|
|
|
setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()+1);
|
|
|
|
}
|
|
|
|
|
2002-02-09 06:55:21 +08:00
|
|
|
dirtyBound();
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
bool Geode::removeDrawable( Drawable *drawable )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2006-05-02 17:45:31 +08:00
|
|
|
return removeDrawables(getDrawableIndex(drawable),1);
|
2002-12-08 05:18:12 +08:00
|
|
|
}
|
|
|
|
|
2006-05-02 17:45:31 +08:00
|
|
|
bool Geode::removeDrawables(unsigned int pos,unsigned int numDrawablesToRemove)
|
2002-12-08 05:18:12 +08:00
|
|
|
{
|
|
|
|
if (pos<_drawables.size() && numDrawablesToRemove>0)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-12-08 05:18:12 +08:00
|
|
|
unsigned int endOfRemoveRange = pos+numDrawablesToRemove;
|
|
|
|
if (endOfRemoveRange>_drawables.size())
|
|
|
|
{
|
|
|
|
notify(DEBUG_INFO)<<"Warning: Geode::removeDrawable(i,numDrawablesToRemove) has been passed an excessive number"<<std::endl;
|
|
|
|
notify(DEBUG_INFO)<<" of drawables to remove, trimming just to end of drawable list."<<std::endl;
|
|
|
|
endOfRemoveRange=_drawables.size();
|
|
|
|
}
|
2002-02-09 06:55:21 +08:00
|
|
|
|
2002-12-19 23:55:40 +08:00
|
|
|
unsigned int updateCallbackRemoved = 0;
|
2005-02-25 22:02:48 +08:00
|
|
|
unsigned int eventCallbackRemoved = 0;
|
2002-12-08 05:18:12 +08:00
|
|
|
for(unsigned i=pos;i<endOfRemoveRange;++i)
|
2002-07-10 23:35:47 +08:00
|
|
|
{
|
2002-12-08 05:18:12 +08:00
|
|
|
// remove this Geode from the child parent list.
|
|
|
|
_drawables[i]->removeParent(this);
|
|
|
|
// update the number of app calbacks removed
|
2005-05-02 17:57:58 +08:00
|
|
|
if (_drawables[i]->requiresUpdateTraversal()) ++updateCallbackRemoved;
|
|
|
|
if (_drawables[i]->requiresEventTraversal()) ++eventCallbackRemoved;
|
2002-07-10 23:35:47 +08:00
|
|
|
}
|
|
|
|
|
2002-12-08 05:18:12 +08:00
|
|
|
_drawables.erase(_drawables.begin()+pos,_drawables.begin()+endOfRemoveRange);
|
|
|
|
|
2005-05-02 17:57:58 +08:00
|
|
|
if (updateCallbackRemoved)
|
2002-12-08 05:18:12 +08:00
|
|
|
{
|
2002-12-19 23:55:40 +08:00
|
|
|
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()-updateCallbackRemoved);
|
2002-12-08 05:18:12 +08:00
|
|
|
}
|
2002-02-09 06:55:21 +08:00
|
|
|
|
2005-05-02 17:57:58 +08:00
|
|
|
if (eventCallbackRemoved)
|
2005-02-25 22:02:48 +08:00
|
|
|
{
|
|
|
|
setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()-eventCallbackRemoved);
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
dirtyBound();
|
2002-02-09 06:55:21 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
bool Geode::replaceDrawable( Drawable *origDrawable, Drawable *newDrawable )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-02-09 06:55:21 +08:00
|
|
|
if (newDrawable==NULL || origDrawable==newDrawable) return false;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-11-21 17:07:11 +08:00
|
|
|
unsigned int pos = getDrawableIndex(origDrawable);
|
2002-11-19 00:14:00 +08:00
|
|
|
if (pos<_drawables.size())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-11-19 00:14:00 +08:00
|
|
|
return setDrawable(pos,newDrawable);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Geode::setDrawable( unsigned int i, Drawable* newDrawable )
|
|
|
|
{
|
|
|
|
if (i<_drawables.size() && newDrawable)
|
|
|
|
{
|
|
|
|
|
|
|
|
Drawable* origDrawable = _drawables[i].get();
|
|
|
|
|
2005-02-25 22:02:48 +08:00
|
|
|
int deltaUpdate = 0;
|
2005-05-02 17:57:58 +08:00
|
|
|
if (origDrawable->requiresUpdateTraversal()) --deltaUpdate;
|
|
|
|
if (newDrawable->requiresUpdateTraversal()) ++deltaUpdate;
|
2005-02-25 22:02:48 +08:00
|
|
|
if (deltaUpdate!=0)
|
2002-07-10 23:35:47 +08:00
|
|
|
{
|
2005-02-25 22:02:48 +08:00
|
|
|
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+deltaUpdate);
|
2002-07-10 23:35:47 +08:00
|
|
|
}
|
|
|
|
|
2005-02-25 22:02:48 +08:00
|
|
|
int deltaEvent = 0;
|
2005-05-02 17:57:58 +08:00
|
|
|
if (origDrawable->requiresEventTraversal()) --deltaEvent;
|
|
|
|
if (newDrawable->requiresEventTraversal()) ++deltaEvent;
|
2005-02-25 22:02:48 +08:00
|
|
|
if (deltaEvent!=0)
|
|
|
|
{
|
|
|
|
setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()+deltaEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-09 06:55:21 +08:00
|
|
|
// remove from origDrawable's parent list.
|
|
|
|
origDrawable->removeParent(this);
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
// note ref_ptr<> automatically handles decrementing origGset's reference count,
|
|
|
|
// and inccrementing newGset's reference count.
|
2002-11-19 00:14:00 +08:00
|
|
|
_drawables[i] = newDrawable;
|
2002-02-09 06:55:21 +08:00
|
|
|
|
|
|
|
// register as parent of child.
|
|
|
|
newDrawable->addParent(this);
|
|
|
|
|
2002-07-10 23:35:47 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
dirtyBound();
|
2002-02-09 06:55:21 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
BoundingSphere Geode::computeBound() const
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2005-05-12 22:03:22 +08:00
|
|
|
BoundingSphere bsphere;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
_bbox.init();
|
2002-05-29 07:43:22 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
DrawableList::const_iterator itr;
|
|
|
|
for(itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
2001-01-11 00:32:10 +08:00
|
|
|
++itr)
|
|
|
|
{
|
2004-04-22 18:47:12 +08:00
|
|
|
_bbox.expandBy((*itr)->getBound());
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2004-04-22 18:47:12 +08:00
|
|
|
if (_bbox.valid())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2005-05-12 22:03:22 +08:00
|
|
|
bsphere.expandBy(_bbox);
|
2001-09-20 05:08:56 +08:00
|
|
|
}
|
2005-05-12 22:03:22 +08:00
|
|
|
return bsphere;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2006-11-14 20:51:31 +08:00
|
|
|
void Geode::compileDrawables(RenderInfo& renderInfo)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
for(DrawableList::iterator itr = _drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
2001-01-11 00:32:10 +08:00
|
|
|
++itr)
|
|
|
|
{
|
2006-11-14 20:51:31 +08:00
|
|
|
(*itr)->compileGLObjects(renderInfo);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|
2005-05-08 04:47:09 +08:00
|
|
|
|
2007-01-05 00:49:58 +08:00
|
|
|
void Geode::setThreadSafeRefUnref(bool threadSafe)
|
|
|
|
{
|
|
|
|
Node::setThreadSafeRefUnref(threadSafe);
|
|
|
|
|
|
|
|
for(DrawableList::const_iterator itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->setThreadSafeRefUnref(threadSafe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-04 22:11:51 +08:00
|
|
|
void Geode::resizeGLObjectBuffers(unsigned int maxSize)
|
|
|
|
{
|
|
|
|
Node::resizeGLObjectBuffers(maxSize);
|
|
|
|
|
|
|
|
for(DrawableList::const_iterator itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->resizeGLObjectBuffers(maxSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-08 04:47:09 +08:00
|
|
|
void Geode::releaseGLObjects(osg::State* state) const
|
|
|
|
{
|
|
|
|
Node::releaseGLObjects(state);
|
|
|
|
|
|
|
|
for(DrawableList::const_iterator itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->releaseGLObjects(state);
|
|
|
|
}
|
|
|
|
}
|