Added support for reading and writing Sphere, Box, Cone, Cylinder and Grid shapes.
This commit is contained in:
@@ -734,6 +734,8 @@ void ComputeBoundShapeVisitor::apply(const ConvexHull& hull)
|
||||
void ComputeBoundShapeVisitor::apply(const HeightField& field)
|
||||
{
|
||||
|
||||
|
||||
|
||||
float zMin=FLT_MAX;
|
||||
float zMax=-FLT_MAX;
|
||||
|
||||
@@ -747,6 +749,12 @@ void ComputeBoundShapeVisitor::apply(const HeightField& field)
|
||||
}
|
||||
}
|
||||
|
||||
if (zMin>zMax)
|
||||
{
|
||||
// no valid entries so don't reset the bounding box
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (field.zeroRotation())
|
||||
{
|
||||
|
||||
@@ -377,3 +377,164 @@ bool FieldReaderIterator::matchSequence(const char* str)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool FieldReaderIterator::readSequence(const char* keyword,std::string& value)
|
||||
{
|
||||
if ((*this)[0].matchWord(keyword) && (*this)[1].isString())
|
||||
{
|
||||
value = (*this)[1].getStr();
|
||||
(*this)+=2;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(const char* keyword,unsigned int& value)
|
||||
{
|
||||
if ((*this)[0].matchWord(keyword) && (*this)[1].getUInt(value))
|
||||
{
|
||||
(*this)+=2;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(const char* keyword,int& value)
|
||||
{
|
||||
if ((*this)[0].matchWord(keyword) && (*this)[1].getInt(value))
|
||||
{
|
||||
(*this)+=2;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(const char* keyword,float& value)
|
||||
{
|
||||
if ((*this)[0].matchWord(keyword) &&
|
||||
(*this)[1].getFloat(value))
|
||||
{
|
||||
(*this)+=2;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec2& value)
|
||||
{
|
||||
if ((*this)[0].matchWord(keyword) &&
|
||||
(*this)[1].getFloat(value[0]) &&
|
||||
(*this)[2].getFloat(value[1]))
|
||||
{
|
||||
(*this)+=3;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec3& value)
|
||||
{
|
||||
if ((*this)[0].matchWord(keyword) &&
|
||||
(*this)[1].getFloat(value[0]) &&
|
||||
(*this)[2].getFloat(value[1]) &&
|
||||
(*this)[3].getFloat(value[2]))
|
||||
{
|
||||
(*this)+=4;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(const char* keyword,osg::Vec4& value)
|
||||
{
|
||||
if ((*this)[0].matchWord(keyword) &&
|
||||
(*this)[1].getFloat(value[0]) &&
|
||||
(*this)[2].getFloat(value[1]) &&
|
||||
(*this)[3].getFloat(value[2]) &&
|
||||
(*this)[4].getFloat(value[3]))
|
||||
{
|
||||
(*this)+=5;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(std::string& value)
|
||||
{
|
||||
if ((*this)[0].isString())
|
||||
{
|
||||
value = (*this)[0].getStr();
|
||||
(*this)+=1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(unsigned int& value)
|
||||
{
|
||||
if ((*this)[0].getUInt(value))
|
||||
{
|
||||
(*this)+=1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(int& value)
|
||||
{
|
||||
if ((*this)[0].getInt(value))
|
||||
{
|
||||
(*this)+=1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(float& value)
|
||||
{
|
||||
if ((*this)[0].getFloat(value))
|
||||
{
|
||||
(*this)+=1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(osg::Vec2& value)
|
||||
{
|
||||
if ((*this)[0].getFloat(value[0]) &&
|
||||
(*this)[1].getFloat(value[1]))
|
||||
{
|
||||
(*this)+=2;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(osg::Vec3& value)
|
||||
{
|
||||
if ((*this)[0].getFloat(value[0]) &&
|
||||
(*this)[1].getFloat(value[1]) &&
|
||||
(*this)[2].getFloat(value[2]))
|
||||
{
|
||||
(*this)+=3;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FieldReaderIterator::readSequence(osg::Vec4& value)
|
||||
{
|
||||
if ((*this)[0].getFloat(value[0]) &&
|
||||
(*this)[1].getFloat(value[1]) &&
|
||||
(*this)[2].getFloat(value[2]) &&
|
||||
(*this)[3].getFloat(value[3]))
|
||||
{
|
||||
(*this)+=4;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "osg/Drawable"
|
||||
#include "osg/Notify"
|
||||
|
||||
#include "osgDB/Registry"
|
||||
#include "osgDB/Input"
|
||||
@@ -34,6 +35,16 @@ bool Drawable_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
ref_ptr<Object> readObject = fr.readObject();
|
||||
if (readObject.valid())
|
||||
{
|
||||
osg::Shape* shape = dynamic_cast<osg::Shape*>(readObject.get());
|
||||
if (shape) drawable.setShape(shape);
|
||||
else notify(WARN)<<"Warning:: "<<readObject->className()<<" loaded but cannot not be attached to Drawable."<<std::endl;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
|
||||
if (fr[0].matchWord("supportsDisplayList"))
|
||||
{
|
||||
if (fr[1].matchWord("TRUE"))
|
||||
@@ -65,6 +76,7 @@ bool Drawable_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
@@ -79,6 +91,11 @@ bool Drawable_writeLocalData(const Object& obj, Output& fw)
|
||||
fw.writeObject(*drawable.getStateSet());
|
||||
}
|
||||
|
||||
if (drawable.getShape())
|
||||
{
|
||||
fw.writeObject(*drawable.getShape());
|
||||
}
|
||||
|
||||
if (!drawable.getSupportsDisplayList())
|
||||
{
|
||||
fw.indent()<<"supportsDisplayList ";
|
||||
@@ -90,5 +107,6 @@ bool Drawable_writeLocalData(const Object& obj, Output& fw)
|
||||
if (drawable.getUseDisplayList()) fw << "TRUE" << std::endl;
|
||||
else fw << "FALSE" << std::endl;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "osgDB/Registry"
|
||||
#include "osgDB/Input"
|
||||
#include "osgDB/Output"
|
||||
#include "osgDB/ParameterOutput"
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgDB;
|
||||
@@ -717,7 +717,7 @@ bool GeoSet_writeLocalData(const Object& obj, Output& fw)
|
||||
}
|
||||
if (writeOutPrimitiveLengths)
|
||||
{
|
||||
writeArrayBlock(fw,geoset.getPrimLengths(),geoset.getPrimLengths()+geoset.getNumPrims());
|
||||
writeArray(fw,geoset.getPrimLengths(),geoset.getPrimLengths()+geoset.getNumPrims());
|
||||
}
|
||||
|
||||
GeoSet& non_const_geoset = const_cast<GeoSet&>(geoset);
|
||||
@@ -1010,13 +1010,13 @@ bool GeoSet_writeIndexData(Output& fw, const char* IndexName,const GeoSet::Index
|
||||
{
|
||||
// write our CoordIndex
|
||||
fw.indent() << IndexName << " ushort " << ip._size<< std::endl;
|
||||
writeArrayBlock(fw,ip._ptr._ushort,ip._ptr._ushort+ip._size);
|
||||
writeArray(fw,ip._ptr._ushort,ip._ptr._ushort+ip._size);
|
||||
}
|
||||
else
|
||||
{
|
||||
// write our CoordIndex
|
||||
fw.indent() << IndexName << " uint " << ip._size<< std::endl;
|
||||
writeArrayBlock(fw,ip._ptr._uint,ip._ptr._uint+ip._size);
|
||||
writeArray(fw,ip._ptr._uint,ip._ptr._uint+ip._size);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/Input>
|
||||
#include <osgDB/Output>
|
||||
#include <osgDB/ParameterOutput>
|
||||
|
||||
using namespace osg;
|
||||
using namespace osgDB;
|
||||
@@ -557,74 +557,6 @@ Array* Array_readLocalData(Input& fr)
|
||||
}
|
||||
|
||||
|
||||
template<class Iterator>
|
||||
void Array_writeLocalData(Output& fw, Iterator first, Iterator last,int noItemsPerLine=8)
|
||||
{
|
||||
fw.indent() << "{"<<std::endl;
|
||||
fw.moveIn();
|
||||
|
||||
int column=0;
|
||||
|
||||
for(Iterator itr=first;
|
||||
itr!=last;
|
||||
++itr)
|
||||
{
|
||||
if (column==0) fw.indent();
|
||||
|
||||
fw << *itr;
|
||||
|
||||
++column;
|
||||
if (column==noItemsPerLine)
|
||||
{
|
||||
fw << std::endl;
|
||||
column = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fw << " ";
|
||||
}
|
||||
}
|
||||
if (column!=0) fw << std::endl;
|
||||
|
||||
fw.moveOut();
|
||||
fw.indent()<<"}"<<std::endl;
|
||||
|
||||
}
|
||||
|
||||
template<class Iterator>
|
||||
void Array_writeLocalDataAsInts(Output& fw, Iterator first, Iterator last,int noItemsPerLine=8)
|
||||
{
|
||||
fw.indent() << "{"<<std::endl;
|
||||
fw.moveIn();
|
||||
|
||||
int column=0;
|
||||
|
||||
for(Iterator itr=first;
|
||||
itr!=last;
|
||||
++itr)
|
||||
{
|
||||
if (column==0) fw.indent();
|
||||
|
||||
fw << (int)*itr;
|
||||
|
||||
++column;
|
||||
if (column==noItemsPerLine)
|
||||
{
|
||||
fw << std::endl;
|
||||
column = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fw << " ";
|
||||
}
|
||||
}
|
||||
if (column!=0) fw << std::endl;
|
||||
|
||||
fw.moveOut();
|
||||
fw.indent()<<"}"<<std::endl;
|
||||
|
||||
}
|
||||
|
||||
bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
if (array.referenceCount()>1)
|
||||
@@ -651,7 +583,7 @@ bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
const ByteArray& carray = static_cast<const ByteArray&>(array);
|
||||
fw<<array.className()<<" "<<carray.size()<<std::endl;
|
||||
Array_writeLocalDataAsInts(fw,carray.begin(),carray.end());
|
||||
writeArrayAsInts(fw,carray.begin(),carray.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -659,7 +591,7 @@ bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
const ShortArray& carray = static_cast<const ShortArray&>(array);
|
||||
fw<<array.className()<<" "<<carray.size()<<std::endl;
|
||||
Array_writeLocalData(fw,carray.begin(),carray.end());
|
||||
writeArray(fw,carray.begin(),carray.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -667,7 +599,7 @@ bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
const IntArray& carray = static_cast<const IntArray&>(array);
|
||||
fw<<array.className()<<" "<<carray.size()<<std::endl;
|
||||
Array_writeLocalData(fw,carray.begin(),carray.end());
|
||||
writeArray(fw,carray.begin(),carray.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -675,7 +607,7 @@ bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
const UByteArray& carray = static_cast<const UByteArray&>(array);
|
||||
fw<<array.className()<<" "<<carray.size()<<std::endl;
|
||||
Array_writeLocalDataAsInts(fw,carray.begin(),carray.end());
|
||||
writeArrayAsInts(fw,carray.begin(),carray.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -683,7 +615,7 @@ bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
const UShortArray& carray = static_cast<const UShortArray&>(array);
|
||||
fw<<array.className()<<" "<<carray.size()<<std::endl;
|
||||
Array_writeLocalData(fw,carray.begin(),carray.end());
|
||||
writeArray(fw,carray.begin(),carray.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -691,7 +623,7 @@ bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
const UIntArray& carray = static_cast<const UIntArray&>(array);
|
||||
fw<<array.className()<<" "<<carray.size()<<" ";
|
||||
Array_writeLocalData(fw,carray.begin(),carray.end());
|
||||
writeArray(fw,carray.begin(),carray.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -699,7 +631,7 @@ bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
const UByte4Array& carray = static_cast<const UByte4Array&>(array);
|
||||
fw<<array.className()<<" "<<carray.size()<<" ";
|
||||
Array_writeLocalData(fw,carray.begin(),carray.end(),1);
|
||||
writeArray(fw,carray.begin(),carray.end(),1);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -707,7 +639,7 @@ bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
const FloatArray& carray = static_cast<const FloatArray&>(array);
|
||||
fw<<array.className()<<" "<<carray.size()<<std::endl;
|
||||
Array_writeLocalData(fw,carray.begin(),carray.end());
|
||||
writeArray(fw,carray.begin(),carray.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -715,7 +647,7 @@ bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
const Vec2Array& carray = static_cast<const Vec2Array&>(array);
|
||||
fw<<array.className()<<" "<<carray.size()<<std::endl;
|
||||
Array_writeLocalData(fw,carray.begin(),carray.end(),1);
|
||||
writeArray(fw,carray.begin(),carray.end(),1);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -723,7 +655,7 @@ bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
const Vec3Array& carray = static_cast<const Vec3Array&>(array);
|
||||
fw<<array.className()<<" "<<carray.size()<<std::endl;
|
||||
Array_writeLocalData(fw,carray.begin(),carray.end(),1);
|
||||
writeArray(fw,carray.begin(),carray.end(),1);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -731,7 +663,7 @@ bool Array_writeLocalData(const Array& array,Output& fw)
|
||||
{
|
||||
const Vec4Array& carray = static_cast<const Vec4Array&>(array);
|
||||
fw<<array.className()<<" "<<carray.size()<<std::endl;
|
||||
Array_writeLocalData(fw,carray.begin(),carray.end(),1);
|
||||
writeArray(fw,carray.begin(),carray.end(),1);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -912,7 +844,7 @@ bool Primitive_writeLocalData(const PrimitiveSet& prim,Output& fw)
|
||||
{
|
||||
const DrawArrayLengths& cprim = static_cast<const DrawArrayLengths&>(prim);
|
||||
fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.getFirst()<<" "<<cprim.size()<<std::endl;
|
||||
Array_writeLocalData(fw,cprim.begin(),cprim.end());
|
||||
writeArray(fw,cprim.begin(),cprim.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -920,7 +852,7 @@ bool Primitive_writeLocalData(const PrimitiveSet& prim,Output& fw)
|
||||
{
|
||||
const DrawElementsUByte& cprim = static_cast<const DrawElementsUByte&>(prim);
|
||||
fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl;
|
||||
Array_writeLocalData(fw,cprim.begin(),cprim.end());
|
||||
writeArrayAsInts(fw,cprim.begin(),cprim.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -928,7 +860,7 @@ bool Primitive_writeLocalData(const PrimitiveSet& prim,Output& fw)
|
||||
{
|
||||
const DrawElementsUShort& cprim = static_cast<const DrawElementsUShort&>(prim);
|
||||
fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl;
|
||||
Array_writeLocalData(fw,cprim.begin(),cprim.end());
|
||||
writeArray(fw,cprim.begin(),cprim.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -936,7 +868,7 @@ bool Primitive_writeLocalData(const PrimitiveSet& prim,Output& fw)
|
||||
{
|
||||
const DrawElementsUInt& cprim = static_cast<const DrawElementsUInt&>(prim);
|
||||
fw<<cprim.className()<<" "<<Geometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl;
|
||||
Array_writeLocalData(fw,cprim.begin(),cprim.end());
|
||||
writeArray(fw,cprim.begin(),cprim.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -41,6 +41,7 @@ CXXFILES =\
|
||||
Projection.cpp\
|
||||
ReaderWriterOSG.cpp\
|
||||
ShadeModel.cpp\
|
||||
Shape.cpp\
|
||||
ShapeDrawable.cpp\
|
||||
StateSet.cpp\
|
||||
Sequence.cpp\
|
||||
|
||||
Reference in New Issue
Block a user