137 lines
3.4 KiB
C++
137 lines
3.4 KiB
C++
|
#include "osg/Billboard"
|
||
|
|
||
|
#include "osgDB/Registry"
|
||
|
#include "osgDB/Input"
|
||
|
#include "osgDB/Output"
|
||
|
|
||
|
using namespace osg;
|
||
|
using namespace osgDB;
|
||
|
|
||
|
// forward declare functions to use later.
|
||
|
bool Billboard_readLocalData(Object& obj, Input& fr);
|
||
|
bool Billboard_writeLocalData(const Object& obj, Output& fw);
|
||
|
|
||
|
// register the read and write functions with the osgDB::Registry.
|
||
|
RegisterDotOsgWrapperProxy g_BillboardProxy
|
||
|
(
|
||
|
new osg::Billboard,
|
||
|
"Billboard",
|
||
|
"Object Node Geode Billboard",
|
||
|
&Billboard_readLocalData,
|
||
|
&Billboard_writeLocalData
|
||
|
);
|
||
|
|
||
|
bool Billboard_readLocalData(Object& obj, Input& fr)
|
||
|
{
|
||
|
bool iteratorAdvanced = false;
|
||
|
|
||
|
Billboard& billboard = static_cast<Billboard&>(obj);
|
||
|
|
||
|
if (fr[0].matchWord("Mode"))
|
||
|
{
|
||
|
if (fr[1].matchWord("AXIAL_ROT"))
|
||
|
{
|
||
|
billboard.setMode(Billboard::AXIAL_ROT);
|
||
|
fr+=2;
|
||
|
iteratorAdvanced = true;
|
||
|
}
|
||
|
else if (fr[1].matchWord("POINT_ROT_EYE"))
|
||
|
{
|
||
|
billboard.setMode(Billboard::POINT_ROT_EYE);
|
||
|
fr+=2;
|
||
|
iteratorAdvanced = true;
|
||
|
}
|
||
|
else if (fr[1].matchWord("POINT_ROT_WORLD"))
|
||
|
{
|
||
|
billboard.setMode(Billboard::POINT_ROT_WORLD);
|
||
|
fr+=2;
|
||
|
iteratorAdvanced = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (fr[0].matchWord("Axis"))
|
||
|
{
|
||
|
float x,y,z;
|
||
|
if (fr[1].getFloat(x) && fr[2].getFloat(y) && fr[3].getFloat(z))
|
||
|
{
|
||
|
billboard.setAxis(Vec3(x,y,z));
|
||
|
fr+=4;
|
||
|
iteratorAdvanced = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// read the position data.
|
||
|
bool matchFirst = false;
|
||
|
if ((matchFirst=fr.matchSequence("Positions {")) || fr.matchSequence("Positions %i {"))
|
||
|
{
|
||
|
|
||
|
// set up coordinates.
|
||
|
int entry = fr[0].getNoNestedBrackets();
|
||
|
|
||
|
Billboard::PositionList& positionList = billboard.getPositionList();
|
||
|
positionList.clear();
|
||
|
|
||
|
if (matchFirst)
|
||
|
{
|
||
|
fr += 2;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//positionList.(capacity);
|
||
|
fr += 3;
|
||
|
}
|
||
|
|
||
|
Vec3 pos;
|
||
|
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
|
||
|
{
|
||
|
if (fr[0].getFloat(pos[0]) && fr[1].getFloat(pos[1]) && fr[2].getFloat(pos[2]))
|
||
|
{
|
||
|
fr += 3;
|
||
|
positionList.push_back(pos);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
++fr;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
iteratorAdvanced = true;
|
||
|
++fr;
|
||
|
|
||
|
}
|
||
|
|
||
|
return iteratorAdvanced;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool Billboard_writeLocalData(const Object& obj, Output& fw)
|
||
|
{
|
||
|
|
||
|
const Billboard& billboard = static_cast<const Billboard&>(obj);
|
||
|
|
||
|
switch(billboard.getMode())
|
||
|
{
|
||
|
case(Billboard::AXIAL_ROT): fw.indent() << "Mode AXIAL_ROT"<<endl; break;
|
||
|
case(Billboard::POINT_ROT_EYE): fw.indent() << "Mode POINT_ROT_EYE"<<endl; break;
|
||
|
case(Billboard::POINT_ROT_WORLD): fw.indent() << "Mode POINT_ROT_WORLD"<<endl; break;
|
||
|
}
|
||
|
|
||
|
const Vec3& axis = billboard.getAxis();
|
||
|
fw.indent() << "Axis " << axis[0] << " "<<axis[1]<<" "<<axis[2]<<endl;
|
||
|
|
||
|
fw.indent() << "Positions {"<<endl;
|
||
|
fw.moveIn();
|
||
|
|
||
|
Billboard::PositionList positionList = billboard.getPositionList();
|
||
|
for(Billboard::PositionList::iterator piter = positionList.begin();
|
||
|
piter != positionList.end();
|
||
|
++piter)
|
||
|
{
|
||
|
fw.indent() << (*piter)[0] << " "<<(*piter)[1]<<" "<<(*piter)[2]<<endl;
|
||
|
}
|
||
|
fw.moveOut();
|
||
|
fw.indent() << "}"<<endl;
|
||
|
|
||
|
return true;
|
||
|
}
|