Fixed a bug in the Optimizer where BIND_PER_PRIMITIVE_SET primitives where being eroneously merged.
Added missing support for reading geometry indices from the .osg format. Added handling of geometry indices into the primitive functor in osg::Geometry. Moved the method implementions of AnimationPathManipulator into src/osgGA and added extra convinience methods for setting the manipulator with an hand built AnimationPath. FCVS: VisualStudio/osgPlugins/iv/iv.dsp
This commit is contained in:
@@ -857,15 +857,123 @@ void Geometry::accept(PrimitiveFunctor& functor)
|
||||
{
|
||||
if (!_vertexArray.valid() || _vertexArray->empty()) return;
|
||||
|
||||
functor.setVertexArray(_vertexArray->size(),&(_vertexArray->front()));
|
||||
|
||||
for(PrimitiveSetList::iterator itr=_primitives.begin();
|
||||
itr!=_primitives.end();
|
||||
++itr)
|
||||
if (!_vertexIndices.valid())
|
||||
{
|
||||
(*itr)->accept(functor);
|
||||
functor.setVertexArray(_vertexArray->size(),&(_vertexArray->front()));
|
||||
|
||||
for(PrimitiveSetList::iterator itr=_primitives.begin();
|
||||
itr!=_primitives.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->accept(functor);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
for(PrimitiveSetList::iterator itr=_primitives.begin();
|
||||
itr!=_primitives.end();
|
||||
++itr)
|
||||
{
|
||||
PrimitiveSet* primitiveset = itr->get();
|
||||
GLenum mode=primitiveset->getMode();
|
||||
switch(primitiveset->getType())
|
||||
{
|
||||
case(PrimitiveSet::DrawArraysPrimitiveType):
|
||||
{
|
||||
const DrawArrays* drawArray = static_cast<const DrawArrays*>(primitiveset);
|
||||
functor.begin(mode);
|
||||
|
||||
unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount();
|
||||
for(unsigned int vindex=drawArray->getFirst();
|
||||
vindex<indexEnd;
|
||||
++vindex)
|
||||
{
|
||||
functor.vertex((*_vertexArray)[_vertexIndices->index(vindex)]);
|
||||
}
|
||||
|
||||
functor.end();
|
||||
break;
|
||||
}
|
||||
case(PrimitiveSet::DrawArrayLengthsPrimitiveType):
|
||||
{
|
||||
|
||||
const DrawArrayLengths* drawArrayLengths = static_cast<const DrawArrayLengths*>(primitiveset);
|
||||
unsigned int vindex=drawArrayLengths->getFirst();
|
||||
for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin();
|
||||
primItr!=drawArrayLengths->end();
|
||||
++primItr)
|
||||
{
|
||||
|
||||
functor.begin(mode);
|
||||
|
||||
for(GLsizei primCount=0;primCount<*primItr;++primCount)
|
||||
{
|
||||
functor.vertex((*_vertexArray)[_vertexIndices->index(vindex)]);
|
||||
++vindex;
|
||||
}
|
||||
|
||||
functor.end();
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(PrimitiveSet::DrawElementsUBytePrimitiveType):
|
||||
{
|
||||
const DrawElementsUByte* drawElements = static_cast<const DrawElementsUByte*>(primitiveset);
|
||||
functor.begin(mode);
|
||||
|
||||
unsigned int primCount=0;
|
||||
for(DrawElementsUByte::const_iterator primItr=drawElements->begin();
|
||||
primItr!=drawElements->end();
|
||||
++primCount,++primItr)
|
||||
{
|
||||
unsigned int vindex=*primItr;
|
||||
functor.vertex((*_vertexArray)[_vertexIndices->index(vindex)]);
|
||||
}
|
||||
|
||||
functor.end();
|
||||
break;
|
||||
}
|
||||
case(PrimitiveSet::DrawElementsUShortPrimitiveType):
|
||||
{
|
||||
const DrawElementsUShort* drawElements = static_cast<const DrawElementsUShort*>(primitiveset);
|
||||
functor.begin(mode);
|
||||
|
||||
for(DrawElementsUShort::const_iterator primItr=drawElements->begin();
|
||||
primItr!=drawElements->end();
|
||||
++primItr)
|
||||
{
|
||||
unsigned int vindex=*primItr;
|
||||
functor.vertex((*_vertexArray)[_vertexIndices->index(vindex)]);
|
||||
}
|
||||
|
||||
functor.end();
|
||||
break;
|
||||
}
|
||||
case(PrimitiveSet::DrawElementsUIntPrimitiveType):
|
||||
{
|
||||
const DrawElementsUInt* drawElements = static_cast<const DrawElementsUInt*>(primitiveset);
|
||||
functor.begin(mode);
|
||||
|
||||
for(DrawElementsUInt::const_iterator primItr=drawElements->begin();
|
||||
primItr!=drawElements->end();
|
||||
++primItr)
|
||||
{
|
||||
unsigned int vindex=*primItr;
|
||||
functor.vertex((*_vertexArray)[_vertexIndices->index(vindex)]);
|
||||
}
|
||||
|
||||
functor.end();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Geometry::verifyBindings() const
|
||||
|
||||
80
src/osgGA/AnimationPathManipulator.cpp
Normal file
80
src/osgGA/AnimationPathManipulator.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include <osgGA/AnimationPathManipulator>
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace osgGA;
|
||||
|
||||
AnimationPathManipulator::AnimationPathManipulator(osg::AnimationPath* animationPath)
|
||||
{
|
||||
_animationPath = animationPath;
|
||||
}
|
||||
|
||||
AnimationPathManipulator::AnimationPathManipulator( const std::string& filename )
|
||||
{
|
||||
_animationPath = osgNew osg::AnimationPath;
|
||||
_animationPath->setLoopMode(osg::AnimationPath::LOOP);
|
||||
|
||||
FILE *fp = fopen( filename.c_str(), "r" );
|
||||
if( fp == NULL )
|
||||
{
|
||||
osg::notify(osg::WARN) << "AnimationPathManipulator: Cannot open animation path file \"" << filename << "\".\n";
|
||||
_valid = false;
|
||||
return;
|
||||
}
|
||||
while( !feof( fp ))
|
||||
{
|
||||
double time;
|
||||
osg::Vec3 position;
|
||||
osg::Quat rotation;
|
||||
fscanf( fp, "%lf %f %f %f %f %f %f %f\n",
|
||||
&time, &position[0], &position[1], &position[2],
|
||||
&rotation[0], &rotation[1], &rotation[2], &rotation[3] );
|
||||
|
||||
if( !feof(fp))
|
||||
_animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us)
|
||||
{
|
||||
if( !valid() ) return false;
|
||||
|
||||
us = us;
|
||||
|
||||
bool retval = false;
|
||||
switch( ea.getEventType() )
|
||||
{
|
||||
case GUIEventAdapter::FRAME:
|
||||
handleFrame( ea.time() );
|
||||
|
||||
break;
|
||||
case GUIEventAdapter::KEYBOARD:
|
||||
switch( ea.getKey())
|
||||
{
|
||||
default:
|
||||
retval = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void AnimationPathManipulator::handleFrame( double time )
|
||||
{
|
||||
osg::AnimationPath::ControlPoint cp;
|
||||
_animationPath->getInterpolatedControlPoint( time, cp );
|
||||
|
||||
osg::Matrix mat;
|
||||
cp.getMatrix( mat );
|
||||
|
||||
osg::Vec3 eye(mat(3,0), mat(3,1), mat(3,2));
|
||||
mat(3,0) = 0.0;
|
||||
mat(3,1) = 0.0;
|
||||
mat(3,2) = 0.0;
|
||||
osg::Vec3 look = eye + (osg::Vec3(0,1,0) * mat);
|
||||
osg::Vec3 up = osg::Vec3(0,0,1) * mat;
|
||||
if( _camera.valid() )
|
||||
_camera->setView( eye, look, up );
|
||||
}
|
||||
@@ -3,6 +3,7 @@ include $(TOPDIR)/Make/makedefs
|
||||
|
||||
|
||||
CXXFILES = \
|
||||
AnimationPathManipulator.cpp\
|
||||
CameraManipulator.cpp\
|
||||
DriveManipulator.cpp\
|
||||
FlightManipulator.cpp\
|
||||
|
||||
@@ -99,6 +99,18 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
|
||||
}
|
||||
|
||||
if (fr.matchSequence("VertexIndices %w %i {"))
|
||||
{
|
||||
++fr;
|
||||
IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
|
||||
if (indices)
|
||||
{
|
||||
geom.setVertexIndices(indices);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Geometry::AttributeBinding normalBinding=Geometry::BIND_OFF;
|
||||
if (fr[0].matchWord("NormalBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),normalBinding))
|
||||
{
|
||||
@@ -138,6 +150,16 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
++fr;
|
||||
}
|
||||
if (fr.matchSequence("NormalIndices %w %i {"))
|
||||
{
|
||||
++fr;
|
||||
IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
|
||||
if (indices)
|
||||
{
|
||||
geom.setNormalIndices(indices);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
Geometry::AttributeBinding colorBinding=Geometry::BIND_OFF;
|
||||
if (fr[0].matchWord("ColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),colorBinding))
|
||||
@@ -158,6 +180,18 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
}
|
||||
}
|
||||
|
||||
if (fr.matchSequence("ColorIndices %w %i {"))
|
||||
{
|
||||
++fr;
|
||||
IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
|
||||
if (indices)
|
||||
{
|
||||
geom.setColorIndices(indices);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Geometry::AttributeBinding secondaryColorBinding=Geometry::BIND_OFF;
|
||||
if (fr[0].matchWord("SecondaryColorBinding") && Geometry_matchBindingTypeStr(fr[1].getStr(),secondaryColorBinding))
|
||||
{
|
||||
@@ -177,6 +211,16 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
}
|
||||
}
|
||||
|
||||
if (fr.matchSequence("SecondaryColorIndices %w %i {"))
|
||||
{
|
||||
++fr;
|
||||
IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
|
||||
if (indices)
|
||||
{
|
||||
geom.setSecondaryColorIndices(indices);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Geometry::AttributeBinding fogCoordBinding=Geometry::BIND_OFF;
|
||||
@@ -219,6 +263,18 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
++fr;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("FogCoordIndices %w %i {"))
|
||||
{
|
||||
++fr;
|
||||
IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
|
||||
if (indices)
|
||||
{
|
||||
geom.setFogCoordIndices(indices);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (fr.matchSequence("TexCoordArray %i %w %i {"))
|
||||
{
|
||||
int unit=0;
|
||||
@@ -234,6 +290,20 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
|
||||
}
|
||||
|
||||
if (fr.matchSequence("TexCoordIndices %i %w %i {"))
|
||||
{
|
||||
int unit=0;
|
||||
fr[1].getInt(unit);
|
||||
|
||||
fr+=2;
|
||||
IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
|
||||
if (indices)
|
||||
{
|
||||
geom.setTexCoordIndices(unit,indices);
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
@@ -479,6 +549,40 @@ void Array_writeLocalData(Output& fw, Iterator first, Iterator last,int noItemsP
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
switch(array.getType())
|
||||
@@ -487,7 +591,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_writeLocalData(fw,carray.begin(),carray.end());
|
||||
Array_writeLocalDataAsInts(fw,carray.begin(),carray.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -511,7 +615,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_writeLocalData(fw,carray.begin(),carray.end());
|
||||
Array_writeLocalDataAsInts(fw,carray.begin(),carray.end());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1045,12 +1045,18 @@ struct LessGeometry
|
||||
if (lhs->getStateSet()<rhs->getStateSet()) return true;
|
||||
if (rhs->getStateSet()<lhs->getStateSet()) return false;
|
||||
|
||||
if (lhs->getNormalBinding()<rhs->getNormalBinding()) return true;
|
||||
if (rhs->getNormalBinding()<lhs->getNormalBinding()) return false;
|
||||
|
||||
if (lhs->getColorBinding()<rhs->getColorBinding()) return true;
|
||||
if (rhs->getColorBinding()<lhs->getColorBinding()) return false;
|
||||
|
||||
if (lhs->getNormalBinding()<rhs->getNormalBinding()) return true;
|
||||
if (rhs->getNormalBinding()<lhs->getNormalBinding()) return false;
|
||||
|
||||
if (lhs->getSecondaryColorBinding()<rhs->getSecondaryColorBinding()) return true;
|
||||
if (rhs->getSecondaryColorBinding()<lhs->getSecondaryColorBinding()) return false;
|
||||
|
||||
if (lhs->getFogCoordBinding()<rhs->getFogCoordBinding()) return true;
|
||||
if (rhs->getFogCoordBinding()<lhs->getFogCoordBinding()) return false;
|
||||
|
||||
if (lhs->getNumTexCoordArrays()<rhs->getNumTexCoordArrays()) return true;
|
||||
if (rhs->getNumTexCoordArrays()<lhs->getNumTexCoordArrays()) return false;
|
||||
|
||||
@@ -1205,7 +1211,11 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode)
|
||||
osg::Geometry* geom = dynamic_cast<osg::Geometry*>(geode.getDrawable(i));
|
||||
if (geom)
|
||||
{
|
||||
if (geom->getNumPrimitiveSets()>0)
|
||||
if (geom->getNumPrimitiveSets()>0 &&
|
||||
geom->getNormalBinding()!=osg::Geometry::BIND_PER_PRIMITIVE_SET &&
|
||||
geom->getColorBinding()!=osg::Geometry::BIND_PER_PRIMITIVE_SET &&
|
||||
geom->getSecondaryColorBinding()!=osg::Geometry::BIND_PER_PRIMITIVE_SET &&
|
||||
geom->getFogCoordBinding()!=osg::Geometry::BIND_PER_PRIMITIVE_SET)
|
||||
{
|
||||
osg::Geometry::PrimitiveSetList& primitives = geom->getPrimitiveSetList();
|
||||
unsigned int primNo=0;
|
||||
@@ -1312,6 +1322,10 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
|
||||
lhs.setColorArray(rhs.getColorArray());
|
||||
}
|
||||
|
||||
// need to implement handle secondary color array.
|
||||
|
||||
// need to implement handle fog coord array.
|
||||
|
||||
for(unsigned int unit=0;unit<lhs.getNumTexCoordArrays();++unit)
|
||||
{
|
||||
// we need to add the handling of the other array types...
|
||||
|
||||
Reference in New Issue
Block a user