Added support for billboard in OpenFlight loader. Submission from Nikolaus Hanekamp.
This commit is contained in:
parent
231b2de41e
commit
13ed25221a
@ -75,9 +75,9 @@ void DynGeoSet::append(DynGeoSet* source)
|
||||
|
||||
DynGeoSet::DynGeoSet():osg::GeoSet()
|
||||
{
|
||||
// disable the attribute delete functor since the vectors contained in DynGeoSet
|
||||
// will delete the memory for us.
|
||||
_adf = NULL;
|
||||
// disable the attribute delete functor since the vectors contained in DynGeoSet
|
||||
// will delete the memory for us.
|
||||
_adf = NULL;
|
||||
}
|
||||
|
||||
void DynGeoSet::setBinding()
|
||||
@ -100,6 +100,7 @@ void DynGeoSet::setBinding()
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool DynGeoSet::setLists()
|
||||
{
|
||||
if ((_primLenList.size() > 0) && (_coordList.size() > 0))
|
||||
@ -125,7 +126,6 @@ bool DynGeoSet::setLists()
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GeoSetBuilder
|
||||
@ -135,6 +135,7 @@ bool DynGeoSet::setLists()
|
||||
// OpenFlight don't save data in GeoSets. This class tries to find
|
||||
// existing GeoSets with matching state before creating a new GeoSet.
|
||||
|
||||
|
||||
GeoSetBuilder::GeoSetBuilder(osg::Geode* geode)
|
||||
{
|
||||
_geode = geode;
|
||||
@ -149,8 +150,12 @@ void GeoSetBuilder::initPrimData()
|
||||
}
|
||||
|
||||
|
||||
osg::Geode* GeoSetBuilder::createOsgGeoSets()
|
||||
osg::Geode* GeoSetBuilder::createOsgGeoSets(osg::Geode* geode)
|
||||
{
|
||||
if( geode == NULL) geode = _geode.get();
|
||||
|
||||
if( geode == NULL) return geode;
|
||||
|
||||
for(DynGeoSetList::iterator itr=_dynGeoSetList.begin();
|
||||
itr!=_dynGeoSetList.end();
|
||||
++itr)
|
||||
@ -163,16 +168,16 @@ osg::Geode* GeoSetBuilder::createOsgGeoSets()
|
||||
{
|
||||
dgset->setLists();
|
||||
dgset->setNumPrims(prims);
|
||||
_geode.get()->addDrawable(dgset);
|
||||
geode->addDrawable(dgset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _geode.get();
|
||||
return geode;
|
||||
}
|
||||
|
||||
|
||||
bool GeoSetBuilder::addPrimitive()
|
||||
bool GeoSetBuilder::addPrimitive(bool dontMerge)
|
||||
{
|
||||
DynGeoSet* dgset = getDynGeoSet(); // This is the new geoset we want to add
|
||||
|
||||
@ -185,12 +190,19 @@ bool GeoSetBuilder::addPrimitive()
|
||||
|
||||
dgset->setBinding();
|
||||
|
||||
DynGeoSet* match = findMatchingGeoSet();
|
||||
if (match)
|
||||
match->append(dgset);
|
||||
else
|
||||
if( dontMerge == true)
|
||||
{
|
||||
_dynGeoSetList.push_back(dgset);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
DynGeoSet* match = findMatchingGeoSet();
|
||||
if (match)
|
||||
match->append(dgset);
|
||||
else
|
||||
_dynGeoSetList.push_back(dgset);
|
||||
}
|
||||
|
||||
initPrimData(); // initialize _dynGeoSet
|
||||
return true;
|
||||
}
|
||||
|
@ -43,9 +43,9 @@ class DynGeoSet : public osg::GeoSet
|
||||
{
|
||||
public:
|
||||
|
||||
DynGeoSet();
|
||||
DynGeoSet();
|
||||
|
||||
virtual osg::Object* clone() const { return new DynGeoSet(); }
|
||||
virtual osg::Object* clone() const { return new DynGeoSet(); }
|
||||
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const DynGeoSet*>(obj)!=NULL; }
|
||||
virtual const char* className() const { return "GeoSet"; }
|
||||
|
||||
@ -114,15 +114,15 @@ class DynGeoSet : public osg::GeoSet
|
||||
class GeoSetBuilder
|
||||
{
|
||||
public:
|
||||
|
||||
GeoSetBuilder(osg::Geode* geode);
|
||||
GeoSetBuilder(osg::Geode* geode = NULL);
|
||||
virtual ~GeoSetBuilder() {}
|
||||
|
||||
bool addPrimitive();
|
||||
osg::Geode* createOsgGeoSets();
|
||||
bool addPrimitive( bool dontMerge = false);
|
||||
osg::Geode* createOsgGeoSets(osg::Geode* geode = NULL);
|
||||
|
||||
inline DynGeoSet* getDynGeoSet() { return _dynGeoSet.get(); }
|
||||
inline const DynGeoSet* getDynGeoSet() const { return _dynGeoSet.get(); }
|
||||
inline bool empty() { return _dynGeoSetList.empty(); } ;
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -158,8 +158,8 @@ osg::Node* ConvertFromFLT::visitAncillary(osg::Group* osgParent, PrimNodeRecord*
|
||||
osg::Node* ConvertFromFLT::visitPrimaryNode(osg::Group* osgParent, PrimNodeRecord* rec)
|
||||
{
|
||||
osg::Node* node = NULL;
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
GeoSetBuilder geoSetBuilder(geode);
|
||||
GeoSetBuilder geoSetBuilder;
|
||||
GeoSetBuilder billboardBuilder;
|
||||
|
||||
// Visit
|
||||
for(int i=0; i < rec->getNumChildren(); i++)
|
||||
@ -169,7 +169,13 @@ osg::Node* ConvertFromFLT::visitPrimaryNode(osg::Group* osgParent, PrimNodeRecor
|
||||
if (child && child->isPrimaryNode())
|
||||
{
|
||||
if (child->isOfType(FACE_OP))
|
||||
visitFace(&geoSetBuilder, (FaceRecord*)child);
|
||||
{
|
||||
FaceRecord* fr = (FaceRecord*)child;
|
||||
if( fr->getData()->swTemplateTrans == 2) //Axis type rotate
|
||||
visitFace(&billboardBuilder, fr);
|
||||
else
|
||||
visitFace(&geoSetBuilder, fr);
|
||||
}
|
||||
else if (child->isOfType(LIGHT_POINT_OP))
|
||||
visitLightPoint(&geoSetBuilder, (LightPointRecord*)child);
|
||||
else
|
||||
@ -177,10 +183,23 @@ osg::Node* ConvertFromFLT::visitPrimaryNode(osg::Group* osgParent, PrimNodeRecor
|
||||
}
|
||||
}
|
||||
|
||||
geoSetBuilder.createOsgGeoSets();
|
||||
if( !geoSetBuilder.empty() )
|
||||
{
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
geoSetBuilder.createOsgGeoSets(geode );
|
||||
|
||||
if (osgParent && (geode->getNumDrawables() > 0))
|
||||
osgParent->addChild( geode );
|
||||
if (osgParent && (geode->getNumDrawables() > 0))
|
||||
osgParent->addChild( geode );
|
||||
}
|
||||
|
||||
if( !billboardBuilder.empty() )
|
||||
{
|
||||
osg::Billboard* billboard = new osg::Billboard;
|
||||
billboardBuilder.createOsgGeoSets(billboard );
|
||||
|
||||
if (osgParent && (billboard->getNumDrawables() > 0))
|
||||
osgParent->addChild( billboard );
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
@ -983,10 +1002,8 @@ int ConvertFromFLT::visitVertexList(GeoSetBuilder* pBuilder, VertexListRecord* r
|
||||
|
||||
|
||||
// Return 1 if record is a known vertex record else return 0.
|
||||
int ConvertFromFLT::addVertex(GeoSetBuilder* pBuilder, Record* rec)
|
||||
int ConvertFromFLT::addVertex(DynGeoSet* dgset, Record* rec)
|
||||
{
|
||||
DynGeoSet* dgset = pBuilder->getDynGeoSet();
|
||||
|
||||
switch(rec->getOpcode())
|
||||
{
|
||||
case VERTEX_C_OP:
|
||||
|
@ -140,7 +140,8 @@ class ConvertFromFLT
|
||||
private:
|
||||
|
||||
int addVertices(GeoSetBuilder* pBuilder, PrimNodeRecord* primRec);
|
||||
int addVertex(GeoSetBuilder* pBuilder, Record* rec);
|
||||
int addVertex(DynGeoSet* dgset, Record* rec);
|
||||
int addVertex(GeoSetBuilder* pBuilder, Record* rec) {return addVertex( pBuilder->getDynGeoSet(), rec);} ;
|
||||
Record* getVertexFromPool(int nOffset);
|
||||
void regisiterVertex(int nOffset, Record* pRec);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user