Cleaned up handling of vertex arrays in osg::Geometry.
Added support for vertex attribute arrays in .osg and .ive.
This commit is contained in:
@@ -51,107 +51,230 @@ class SG_EXPORT Geometry : public Drawable
|
||||
BIND_PER_VERTEX
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct AttributeData
|
||||
// template<typename T>
|
||||
// struct AttributeData
|
||||
// {
|
||||
// AttributeData():
|
||||
// binding(BIND_OFF),
|
||||
// normalize(GL_FALSE),
|
||||
// offset(0) {}
|
||||
//
|
||||
// AttributeData(T* a, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
// array(a),
|
||||
// indices(0),
|
||||
// binding(b),
|
||||
// normalize(n),
|
||||
// offset(0) {}
|
||||
//
|
||||
// AttributeData(T* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
// array(a),
|
||||
// indices(i),
|
||||
// binding(b),
|
||||
// normalize(n),
|
||||
// offset(0) {}
|
||||
//
|
||||
// // AttributeData(const AttributeData& rhs, const CopyOp& copyop=CopyOp::SHADLLOW_COPY):
|
||||
// // array(dynamic_cast<T*>(copyop(rhs.array)),
|
||||
// // indices(dynamic_cast<IndexArray*>(copyop(rhs.indices)),
|
||||
// // binding(ths,binding),
|
||||
// // normalize(GL_FALSE),
|
||||
// // offset(rhs.offset) {}
|
||||
//
|
||||
// AttributeData& operator = (const AttributeData& rhs)
|
||||
// {
|
||||
// array = rhs.array;
|
||||
// indices = rhs.indices;
|
||||
// binding = rhs.binding;
|
||||
// normalize = rhs.normalize;
|
||||
// offset = rhs.offset;
|
||||
// return *this;
|
||||
// }
|
||||
//
|
||||
// ref_ptr<T> array;
|
||||
// ref_ptr<IndexArray> indices;
|
||||
// AttributeBinding binding;
|
||||
// GLboolean normalize;
|
||||
// mutable unsigned int offset;
|
||||
// };
|
||||
|
||||
// typedef AttributeData<Array> ArrayData;
|
||||
struct ArrayData
|
||||
{
|
||||
AttributeData():
|
||||
_normalize(GL_FALSE),
|
||||
_binding(BIND_OFF),
|
||||
_offset(0) {}
|
||||
|
||||
ref_ptr<T> _array;
|
||||
ref_ptr<IndexArray> _indices;
|
||||
AttributeBinding _binding;
|
||||
|
||||
// only used in vertex attributes
|
||||
GLboolean _normalize;
|
||||
|
||||
unsigned int _offset;
|
||||
};
|
||||
|
||||
|
||||
void setVertexArray(Array* array) { _vertexArray = array; dirtyDisplayList(); dirtyBound(); }
|
||||
Array* getVertexArray() { return _vertexArray.get(); }
|
||||
const Array* getVertexArray() const { return _vertexArray.get(); }
|
||||
|
||||
void setVertexIndices(IndexArray* array) { _vertexIndices = array; computeFastPathsUsed(); dirtyDisplayList(); dirtyBound(); }
|
||||
IndexArray* getVertexIndices() { return _vertexIndices.get(); }
|
||||
const IndexArray* getVertexIndices() const { return _vertexIndices.get(); }
|
||||
|
||||
|
||||
void setNormalBinding(AttributeBinding ab) { _normalBinding = ab; dirtyDisplayList(); computeFastPathsUsed(); }
|
||||
AttributeBinding getNormalBinding() const { return _normalBinding; }
|
||||
|
||||
void setNormalArray(Vec3Array* array) { _normalArray = array; if (!_normalArray.valid()) _normalBinding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
Vec3Array* getNormalArray() { return _normalArray.get(); }
|
||||
const Vec3Array* getNormalArray() const { return _normalArray.get(); }
|
||||
|
||||
void setNormalIndices(IndexArray* array) { _normalIndices = array; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
IndexArray* getNormalIndices() { return _normalIndices.get(); }
|
||||
const IndexArray* getNormalIndices() const { return _normalIndices.get(); }
|
||||
|
||||
|
||||
void setColorBinding(AttributeBinding ab) { _colorBinding = ab; computeFastPathsUsed();}
|
||||
AttributeBinding getColorBinding() const { return _colorBinding; }
|
||||
|
||||
void setColorArray(Array* array) { _colorArray = array; if (!_colorArray.valid()) _colorBinding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
Array* getColorArray() { return _colorArray.get(); }
|
||||
const Array* getColorArray() const { return _colorArray.get(); }
|
||||
|
||||
void setColorIndices(IndexArray* array) { _colorIndices = array; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
IndexArray* getColorIndices() { return _colorIndices.get(); }
|
||||
const IndexArray* getColorIndices() const { return _colorIndices.get(); }
|
||||
|
||||
|
||||
void setSecondaryColorBinding(AttributeBinding ab) { _secondaryColorBinding = ab; computeFastPathsUsed();}
|
||||
AttributeBinding getSecondaryColorBinding() const { return _secondaryColorBinding; }
|
||||
|
||||
void setSecondaryColorArray(Array* array) { _secondaryColorArray = array; if (!_secondaryColorArray.valid()) _secondaryColorBinding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
Array* getSecondaryColorArray() { return _secondaryColorArray.get(); }
|
||||
const Array* getSecondaryColorArray() const { return _secondaryColorArray.get(); }
|
||||
|
||||
void setSecondaryColorIndices(IndexArray* array) { _secondaryColorIndices = array; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
IndexArray* getSecondaryColorIndices() { return _secondaryColorIndices.get(); }
|
||||
const IndexArray* getSecondaryColorIndices() const { return _secondaryColorIndices.get(); }
|
||||
|
||||
|
||||
void setFogCoordBinding(AttributeBinding ab) { _fogCoordBinding = ab; computeFastPathsUsed();}
|
||||
AttributeBinding getFogCoordBinding() const { return _fogCoordBinding; }
|
||||
|
||||
void setFogCoordArray(Array* array) { _fogCoordArray = array; if (!_fogCoordArray.valid()) _fogCoordBinding=BIND_OFF; dirtyDisplayList(); }
|
||||
Array* getFogCoordArray() { return _fogCoordArray.get(); }
|
||||
const Array* getFogCoordArray() const { return _fogCoordArray.get(); }
|
||||
|
||||
|
||||
void setFogCoordIndices(IndexArray* array) { _fogCoordIndices = array; dirtyDisplayList(); }
|
||||
IndexArray* getFogCoordIndices() { return _fogCoordIndices.get(); }
|
||||
const IndexArray* getFogCoordIndices() const { return _fogCoordIndices.get(); }
|
||||
|
||||
|
||||
struct ArrayPair
|
||||
{
|
||||
ArrayPair():
|
||||
ArrayData():
|
||||
binding(BIND_OFF),
|
||||
normalize(GL_FALSE),
|
||||
offset(0) {}
|
||||
|
||||
ArrayPair(const ArrayPair& rhs):
|
||||
first(rhs.first),
|
||||
second(rhs.second),
|
||||
offset(rhs.offset) {}
|
||||
ArrayData(Array* a, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
indices(0),
|
||||
binding(b),
|
||||
normalize(n),
|
||||
offset(0) {}
|
||||
|
||||
ArrayPair& operator = (const ArrayPair& rhs)
|
||||
ArrayData(Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
indices(i),
|
||||
binding(b),
|
||||
normalize(n),
|
||||
offset(0) {}
|
||||
|
||||
// ArrayData(const ArrayData& rhs, const CopyOp& copyop=CopyOp::SHADLLOW_COPY):
|
||||
// array(dynamic_cast<T*>(copyop(rhs.array)),
|
||||
// indices(dynamic_cast<IndexArray*>(copyop(rhs.indices)),
|
||||
// binding(ths,binding),
|
||||
// normalize(GL_FALSE),
|
||||
// offset(rhs.offset) {}
|
||||
|
||||
ArrayData& operator = (const ArrayData& rhs)
|
||||
{
|
||||
first = rhs.first;
|
||||
second = rhs.second;
|
||||
array = rhs.array;
|
||||
indices = rhs.indices;
|
||||
binding = rhs.binding;
|
||||
normalize = rhs.normalize;
|
||||
offset = rhs.offset;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ref_ptr<Array> first;
|
||||
ref_ptr<IndexArray> second;
|
||||
ref_ptr<Array> array;
|
||||
ref_ptr<IndexArray> indices;
|
||||
AttributeBinding binding;
|
||||
GLboolean normalize;
|
||||
mutable unsigned int offset;
|
||||
};
|
||||
typedef std::vector< ArrayPair > TexCoordArrayList;
|
||||
|
||||
struct Vec3ArrayData
|
||||
{
|
||||
Vec3ArrayData():
|
||||
binding(BIND_OFF),
|
||||
normalize(GL_FALSE),
|
||||
offset(0) {}
|
||||
|
||||
Vec3ArrayData(Vec3Array* a, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
indices(0),
|
||||
binding(b),
|
||||
normalize(n),
|
||||
offset(0) {}
|
||||
|
||||
Vec3ArrayData(Vec3Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE):
|
||||
array(a),
|
||||
indices(i),
|
||||
binding(b),
|
||||
normalize(n),
|
||||
offset(0) {}
|
||||
|
||||
// Vec3ArrayData(const Vec3ArrayData& rhs, const CopyOp& copyop=CopyOp::SHADLLOW_COPY):
|
||||
// array(dynamic_cast<T*>(copyop(rhs.array)),
|
||||
// indices(dynamic_cast<IndexArray*>(copyop(rhs.indices)),
|
||||
// binding(ths,binding),
|
||||
// normalize(GL_FALSE),
|
||||
// offset(rhs.offset) {}
|
||||
|
||||
Vec3ArrayData& operator = (const Vec3ArrayData& rhs)
|
||||
{
|
||||
array = rhs.array;
|
||||
indices = rhs.indices;
|
||||
binding = rhs.binding;
|
||||
normalize = rhs.normalize;
|
||||
offset = rhs.offset;
|
||||
return *this;
|
||||
}
|
||||
|
||||
ref_ptr<Vec3Array> array;
|
||||
ref_ptr<IndexArray> indices;
|
||||
AttributeBinding binding;
|
||||
GLboolean normalize;
|
||||
mutable unsigned int offset;
|
||||
};
|
||||
|
||||
// typedef AttributeData<Vec3Array> Vec3ArrayData;
|
||||
|
||||
/** static ArrayData which is returned get getTexCoordData(i) const and getVertexAttribData(i) const
|
||||
* when i is out of range.*/
|
||||
static const ArrayData s_InvalidArrayData;
|
||||
|
||||
typedef std::vector< ArrayData > ArrayList;
|
||||
|
||||
|
||||
void setVertexArray(Array* array) { _vertexData.array = array; dirtyDisplayList(); dirtyBound(); }
|
||||
Array* getVertexArray() { return _vertexData.array.get(); }
|
||||
const Array* getVertexArray() const { return _vertexData.array.get(); }
|
||||
|
||||
void setVertexIndices(IndexArray* array) { _vertexData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); dirtyBound(); }
|
||||
IndexArray* getVertexIndices() { return _vertexData.indices.get(); }
|
||||
const IndexArray* getVertexIndices() const { return _vertexData.indices.get(); }
|
||||
|
||||
void setVertexData(const ArrayData& arrayData) { _vertexData = arrayData; }
|
||||
ArrayData& getVertexData() { return _vertexData; }
|
||||
const ArrayData& getVertexData() const { return _vertexData; }
|
||||
|
||||
|
||||
void setNormalBinding(AttributeBinding ab) { _normalData.binding = ab; dirtyDisplayList(); computeFastPathsUsed(); }
|
||||
AttributeBinding getNormalBinding() const { return _normalData.binding; }
|
||||
|
||||
void setNormalArray(Vec3Array* array) { _normalData.array = array; if (!_normalData.array.valid()) _normalData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
Vec3Array* getNormalArray() { return _normalData.array.get(); }
|
||||
const Vec3Array* getNormalArray() const { return _normalData.array.get(); }
|
||||
|
||||
void setNormalIndices(IndexArray* array) { _normalData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
IndexArray* getNormalIndices() { return _normalData.indices.get(); }
|
||||
const IndexArray* getNormalIndices() const { return _normalData.indices.get(); }
|
||||
|
||||
void setNormalData(const Vec3ArrayData& arrayData) { _normalData = arrayData; }
|
||||
Vec3ArrayData& getNormalData() { return _normalData; }
|
||||
const Vec3ArrayData& getNormalData() const { return _normalData; }
|
||||
|
||||
|
||||
|
||||
void setColorBinding(AttributeBinding ab) { _colorData.binding = ab; computeFastPathsUsed();}
|
||||
AttributeBinding getColorBinding() const { return _colorData.binding; }
|
||||
|
||||
void setColorArray(Array* array) { _colorData.array = array; if (!_colorData.array.valid()) _colorData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
Array* getColorArray() { return _colorData.array.get(); }
|
||||
const Array* getColorArray() const { return _colorData.array.get(); }
|
||||
|
||||
void setColorIndices(IndexArray* array) { _colorData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
IndexArray* getColorIndices() { return _colorData.indices.get(); }
|
||||
const IndexArray* getColorIndices() const { return _colorData.indices.get(); }
|
||||
|
||||
void setColorData(const ArrayData& arrayData) { _colorData = arrayData; }
|
||||
ArrayData& getColorData() { return _colorData; }
|
||||
const ArrayData& getColorData() const { return _colorData; }
|
||||
|
||||
|
||||
void setSecondaryColorBinding(AttributeBinding ab) { _secondaryColorData.binding = ab; computeFastPathsUsed();}
|
||||
AttributeBinding getSecondaryColorBinding() const { return _secondaryColorData.binding; }
|
||||
|
||||
void setSecondaryColorArray(Array* array) { _secondaryColorData.array = array; if (!_secondaryColorData.array.valid()) _secondaryColorData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
Array* getSecondaryColorArray() { return _secondaryColorData.array.get(); }
|
||||
const Array* getSecondaryColorArray() const { return _secondaryColorData.array.get(); }
|
||||
|
||||
void setSecondaryColorIndices(IndexArray* array) { _secondaryColorData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); }
|
||||
IndexArray* getSecondaryColorIndices() { return _secondaryColorData.indices.get(); }
|
||||
const IndexArray* getSecondaryColorIndices() const { return _secondaryColorData.indices.get(); }
|
||||
|
||||
void setSecondaryColorData(const ArrayData& arrayData) { _secondaryColorData = arrayData; }
|
||||
ArrayData& getSecondaryColorData() { return _secondaryColorData; }
|
||||
const ArrayData& getSecondaryColorData() const { return _secondaryColorData; }
|
||||
|
||||
|
||||
void setFogCoordBinding(AttributeBinding ab) { _fogCoordData.binding = ab; computeFastPathsUsed();}
|
||||
AttributeBinding getFogCoordBinding() const { return _fogCoordData.binding; }
|
||||
|
||||
void setFogCoordArray(Array* array) { _fogCoordData.array = array; if (!_fogCoordData.array.valid()) _fogCoordData.binding=BIND_OFF; dirtyDisplayList(); }
|
||||
Array* getFogCoordArray() { return _fogCoordData.array.get(); }
|
||||
const Array* getFogCoordArray() const { return _fogCoordData.array.get(); }
|
||||
|
||||
void setFogCoordIndices(IndexArray* array) { _fogCoordData.indices = array; dirtyDisplayList(); }
|
||||
IndexArray* getFogCoordIndices() { return _fogCoordData.indices.get(); }
|
||||
const IndexArray* getFogCoordIndices() const { return _fogCoordData.indices.get(); }
|
||||
|
||||
void setFogCoordData(const ArrayData& arrayData) { _fogCoordData = arrayData; }
|
||||
ArrayData& setFogCoordData() { return _fogCoordData; }
|
||||
const ArrayData& setFogCoordData() const { return _fogCoordData; }
|
||||
|
||||
|
||||
|
||||
void setTexCoordArray(unsigned int unit,Array*);
|
||||
Array* getTexCoordArray(unsigned int unit);
|
||||
@@ -161,62 +284,37 @@ class SG_EXPORT Geometry : public Drawable
|
||||
IndexArray* getTexCoordIndices(unsigned int unit);
|
||||
const IndexArray* getTexCoordIndices(unsigned int unit) const;
|
||||
|
||||
void setTexCoordData(unsigned int index,const ArrayData& arrayData);
|
||||
ArrayData& getTexCoordData(unsigned int index);
|
||||
const ArrayData& getTexCoordData(unsigned int index) const;
|
||||
|
||||
unsigned int getNumTexCoordArrays() const { return _texCoordList.size(); }
|
||||
TexCoordArrayList& getTexCoordArrayList() { return _texCoordList; }
|
||||
const TexCoordArrayList& getTexCoordArrayList() const { return _texCoordList; }
|
||||
ArrayList& getTexCoordArrayList() { return _texCoordList; }
|
||||
const ArrayList& getTexCoordArrayList() const { return _texCoordList; }
|
||||
|
||||
|
||||
#ifdef COMPILE_POSSIBLE_NEW_ARRAY_METHODS
|
||||
|
||||
void setArray(AttributeType type, Array* array);
|
||||
Array* getArray(AttributeType type);
|
||||
const Array* getArray(AttributeType type) const;
|
||||
|
||||
void setIndices(AttributeType type, IndexArray* indices);
|
||||
IndexArray* getIndices(AttributeType type);
|
||||
const IndexArray* getIndices(AttributeType type) const;
|
||||
|
||||
void setNormalize(AttributeType type, GLboolean normalize);
|
||||
GLboolean getNormalize(AttributeType type) const;
|
||||
|
||||
void setBinding(AttributeType type,AttributeBinding binding);
|
||||
AttributeBinding getBinding(AttributeType type) const;
|
||||
|
||||
|
||||
unsigned int getNumArrays() const { return _attributeList.size(); }
|
||||
|
||||
AttributeData& getAttributeData(unsigned int type) { return _attributeList[type]; }
|
||||
|
||||
const AttributeData& getAttributeData(unsigned int type) const { return _attributeList[type]; }
|
||||
|
||||
typedef std::vector<AttributeData> AttributeList;
|
||||
|
||||
void setAttributeList(AttributeList& al) { _attributeList = al; }
|
||||
|
||||
AttributeList& getAttributeList() { return _attributeList; }
|
||||
|
||||
const AttributeList& getAttributeList() const { return _attributeList; }
|
||||
|
||||
#endif
|
||||
|
||||
typedef std::pair< GLboolean, ArrayPair > VertexAttribNormArrayPair;
|
||||
typedef std::vector< VertexAttribNormArrayPair > VertexAttribArrayList;
|
||||
typedef std::vector< AttributeBinding > VertexAttribBindingList;
|
||||
|
||||
void setVertexAttribArray(unsigned int index,GLboolean normalize,Array* array,AttributeBinding ab=BIND_OFF);
|
||||
void setVertexAttribArray(unsigned int index,Array* array);
|
||||
Array *getVertexAttribArray(unsigned int index);
|
||||
const Array *getVertexAttribArray(unsigned int index) const;
|
||||
|
||||
bool getVertexAttribNormalize(unsigned int index, GLboolean &ret) const;
|
||||
bool getVertexAttribBinding(unsigned int index, AttributeBinding& ab) const;
|
||||
|
||||
void setVertexAttribIndices(unsigned int index,IndexArray* array);
|
||||
IndexArray* getVertexAttribIndices(unsigned int index);
|
||||
const IndexArray* getVertexAttribIndices(unsigned int index) const;
|
||||
|
||||
void setVertexAttribBinding(unsigned int index,AttributeBinding ab);
|
||||
AttributeBinding getVertexAttribBinding(unsigned int index) const;
|
||||
|
||||
void setVertexAttribNormalize(unsigned int index,GLboolean norm);
|
||||
GLboolean getVertexAttribNormalize(unsigned int index) const;
|
||||
|
||||
void setVertexAttribData(unsigned int index,const ArrayData& arrayData);
|
||||
ArrayData& getVertexAttribData(unsigned int index);
|
||||
const ArrayData& getVertexAttribData(unsigned int index) const;
|
||||
|
||||
unsigned int getNumVertexAttribArrays() const { return _vertexAttribList.size(); }
|
||||
VertexAttribArrayList& getVertexAttribArrayList() { return _vertexAttribList; }
|
||||
const VertexAttribArrayList& getVertexAttribArrayList() const { return _vertexAttribList; }
|
||||
ArrayList& getVertexAttribArrayList() { return _vertexAttribList; }
|
||||
const ArrayList& getVertexAttribArrayList() const { return _vertexAttribList; }
|
||||
|
||||
|
||||
|
||||
@@ -315,38 +413,21 @@ class SG_EXPORT Geometry : public Drawable
|
||||
virtual ~Geometry();
|
||||
|
||||
PrimitiveSetList _primitives;
|
||||
|
||||
#ifdef COMPILE_POSSIBLE_NEW_ARRAY_METHODS
|
||||
AttributeList _attributeList;
|
||||
#endif
|
||||
ref_ptr<Array> _vertexArray;
|
||||
ref_ptr<IndexArray> _vertexIndices;
|
||||
mutable unsigned int _vertexOffset;
|
||||
|
||||
mutable AttributeBinding _normalBinding;
|
||||
ref_ptr<Vec3Array> _normalArray;
|
||||
ref_ptr<IndexArray> _normalIndices;
|
||||
mutable unsigned int _normalOffset;
|
||||
|
||||
mutable AttributeBinding _colorBinding;
|
||||
ref_ptr<Array> _colorArray;
|
||||
ref_ptr<IndexArray> _colorIndices;
|
||||
mutable unsigned int _colorOffset;
|
||||
|
||||
mutable AttributeBinding _secondaryColorBinding;
|
||||
ref_ptr<Array> _secondaryColorArray;
|
||||
ref_ptr<IndexArray> _secondaryColorIndices;
|
||||
mutable unsigned int _secondaryColorOffset;
|
||||
ArrayData _vertexData;
|
||||
|
||||
mutable AttributeBinding _fogCoordBinding;
|
||||
ref_ptr<Array> _fogCoordArray;
|
||||
ref_ptr<IndexArray> _fogCoordIndices;
|
||||
mutable unsigned int _fogCoordOffset;
|
||||
Vec3ArrayData _normalData;
|
||||
|
||||
ArrayData _colorData;
|
||||
|
||||
ArrayData _secondaryColorData;
|
||||
|
||||
ArrayData _fogCoordData;
|
||||
|
||||
TexCoordArrayList _texCoordList;
|
||||
ArrayList _texCoordList;
|
||||
|
||||
VertexAttribArrayList _vertexAttribList;
|
||||
mutable VertexAttribBindingList _vertexAttribBindingList;
|
||||
ArrayList _vertexAttribList;
|
||||
|
||||
|
||||
mutable bool _fastPath;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -586,11 +586,11 @@ void BumpMapping::prepareGeometry(osg::Geometry *geo)
|
||||
osg::ref_ptr<osgUtil::TangentSpaceGenerator> tsg = new osgUtil::TangentSpaceGenerator;
|
||||
tsg->generate(geo, normalunit_);
|
||||
if (!geo->getVertexAttribArray(6))
|
||||
geo->setVertexAttribArray(6, false, tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX);
|
||||
geo->setVertexAttribData(6, osg::Geometry::ArrayData(tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX,GL_TRUE));
|
||||
if (!geo->getVertexAttribArray(7))
|
||||
geo->setVertexAttribArray(7, false, tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX);
|
||||
geo->setVertexAttribData(7, osg::Geometry::ArrayData(tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_TRUE));
|
||||
if (!geo->getVertexAttribArray(15))
|
||||
geo->setVertexAttribArray(15, false, tsg->getNormalArray(), osg::Geometry::BIND_PER_VERTEX);
|
||||
geo->setVertexAttribData(15, osg::Geometry::ArrayData(tsg->getNormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_TRUE));
|
||||
}
|
||||
|
||||
void BumpMapping::prepareNode(osg::Node *node)
|
||||
|
||||
@@ -642,9 +642,8 @@ public:
|
||||
nverts++;
|
||||
return nverts-1;
|
||||
}
|
||||
void settmat(const Matrix *mx) {
|
||||
tmat= new Matrix;
|
||||
*tmat=*mx;
|
||||
void settmat(const Matrix& mx) {
|
||||
tmat= new Matrix(mx);
|
||||
}
|
||||
void makeuv(Vec2 &uv, const double pos[]) {
|
||||
Vec3 p;
|
||||
@@ -923,12 +922,16 @@ class ReaderWriterDW : public osgDB::ReaderWriter
|
||||
//nrecs=0; // a numVerts is followed by nv vetex postiions
|
||||
if (nexpected>0) obj.readOpenings(fp, nexpected);
|
||||
} else if( strncmp(buff,"UVW:",4)==0) { // texture application matrix
|
||||
Matrix mx;
|
||||
sscanf(buff+4,"%f %f %f%f %f %f%f %f %f",
|
||||
&mx(0,0), &mx(0,1), &mx(0,2),
|
||||
&mx(1,0), &mx(1,1), &mx(1,2),
|
||||
&mx(2,0), &mx(2,1), &mx(2,2));
|
||||
obj.settmat(&mx);
|
||||
double mx[3][2];
|
||||
sscanf(buff+4,"%lf %lf %lf %lf %lf %lf %lf %lf %lf",
|
||||
&mx[0][0], &mx[0][1], &mx[0][2],
|
||||
&mx[1][0], &mx[1][1], &mx[1][2],
|
||||
&mx[2][0], &mx[2][1], &mx[2][2]);
|
||||
|
||||
obj.settmat(Matrix(mx[0][0],mx[0][1],mx[0][2],0.0,
|
||||
mx[1][0],mx[1][1],mx[1][2],0.0,
|
||||
mx[2][0],mx[2][1],mx[2][2],0.0,
|
||||
0.0 ,0.0 ,0.0 ,1.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,12 +92,12 @@ void DataOutputStream::writeDouble(double d){
|
||||
_ostream->write((char*)&d, DOUBLESIZE);
|
||||
}
|
||||
|
||||
void DataOutputStream::writeString(std::string s){
|
||||
void DataOutputStream::writeString(const std::string& s){
|
||||
writeInt(s.size());
|
||||
_ostream->write(s.c_str(), s.size());
|
||||
}
|
||||
|
||||
void DataOutputStream::writeCharArray(char* data, int size){
|
||||
void DataOutputStream::writeCharArray(const char* data, int size){
|
||||
_ostream->write(data, size);
|
||||
}
|
||||
|
||||
@@ -144,50 +144,51 @@ void DataOutputStream::writeBinding(osg::Geometry::AttributeBinding b){
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeArray(osg::Array* a){
|
||||
void DataOutputStream::writeArray(const osg::Array* a){
|
||||
switch(a->getType()){
|
||||
case osg::Array::IntArrayType:
|
||||
writeChar((char)0);
|
||||
writeIntArray(static_cast<osg::IntArray*>(a));
|
||||
writeIntArray(static_cast<const osg::IntArray*>(a));
|
||||
break;
|
||||
case osg::Array::UByteArrayType:
|
||||
writeChar((char)1);
|
||||
writeUByteArray(static_cast<osg::UByteArray*>(a));
|
||||
writeUByteArray(static_cast<const osg::UByteArray*>(a));
|
||||
break;
|
||||
case osg::Array::UShortArrayType:
|
||||
writeChar((char)2);
|
||||
writeUShortArray(static_cast<osg::UShortArray*>(a));
|
||||
writeUShortArray(static_cast<const osg::UShortArray*>(a));
|
||||
break;
|
||||
case osg::Array::UIntArrayType:
|
||||
writeChar((char)3);
|
||||
writeUIntArray(static_cast<osg::UIntArray*>(a));
|
||||
writeUIntArray(static_cast<const osg::UIntArray*>(a));
|
||||
break;
|
||||
case osg::Array::UByte4ArrayType:
|
||||
writeChar((char)4);
|
||||
writeUByte4Array(static_cast<osg::UByte4Array*>(a));
|
||||
writeUByte4Array(static_cast<const osg::UByte4Array*>(a));
|
||||
break;
|
||||
case osg::Array::FloatArrayType:
|
||||
writeChar((char)5);
|
||||
writeFloatArray(static_cast<osg::FloatArray*>(a));
|
||||
writeFloatArray(static_cast<const osg::FloatArray*>(a));
|
||||
break;
|
||||
case osg::Array::Vec2ArrayType:
|
||||
writeChar((char)6);
|
||||
writeVec2Array(static_cast<osg::Vec2Array*>(a));
|
||||
writeVec2Array(static_cast<const osg::Vec2Array*>(a));
|
||||
break;
|
||||
case osg::Array::Vec3ArrayType:
|
||||
writeChar((char)7);
|
||||
writeVec3Array(static_cast<osg::Vec3Array*>(a));
|
||||
writeVec3Array(static_cast<const osg::Vec3Array*>(a));
|
||||
break;
|
||||
case osg::Array::Vec4ArrayType:
|
||||
writeChar((char)8);
|
||||
writeVec4Array(static_cast<osg::Vec4Array*>(a));
|
||||
writeVec4Array(static_cast<const osg::Vec4Array*>(a));
|
||||
break;
|
||||
default: throw Exception("Unknown array type in DataOutputStream::writeArray()");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DataOutputStream::writeIntArray(osg::IntArray* a){
|
||||
void DataOutputStream::writeIntArray(const osg::IntArray* a)
|
||||
{
|
||||
int size = a->getNumElements();
|
||||
writeInt(size);
|
||||
for(int i =0; i<size ;i++){
|
||||
@@ -195,7 +196,8 @@ void DataOutputStream::writeIntArray(osg::IntArray* a){
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeUByteArray(osg::UByteArray* a){
|
||||
void DataOutputStream::writeUByteArray(const osg::UByteArray* a)
|
||||
{
|
||||
int size = a->getNumElements();
|
||||
writeInt(size);
|
||||
for(int i =0; i<size ;i++){
|
||||
@@ -203,7 +205,8 @@ void DataOutputStream::writeUByteArray(osg::UByteArray* a){
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeUShortArray(osg::UShortArray* a){
|
||||
void DataOutputStream::writeUShortArray(const osg::UShortArray* a)
|
||||
{
|
||||
int size = a->getNumElements();
|
||||
writeInt(size);
|
||||
for(int i =0; i<size ;i++){
|
||||
@@ -211,7 +214,8 @@ void DataOutputStream::writeUShortArray(osg::UShortArray* a){
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeUIntArray(osg::UIntArray* a){
|
||||
void DataOutputStream::writeUIntArray(const osg::UIntArray* a)
|
||||
{
|
||||
int size = a->getNumElements();
|
||||
writeInt(size);
|
||||
for(int i =0; i<size ;i++){
|
||||
@@ -219,7 +223,8 @@ void DataOutputStream::writeUIntArray(osg::UIntArray* a){
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeUByte4Array(osg::UByte4Array* a){
|
||||
void DataOutputStream::writeUByte4Array(const osg::UByte4Array* a)
|
||||
{
|
||||
int size = a->getNumElements();
|
||||
writeInt(size);
|
||||
for(int i =0; i<size ;i++){
|
||||
@@ -227,7 +232,8 @@ void DataOutputStream::writeUByte4Array(osg::UByte4Array* a){
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeFloatArray(osg::FloatArray* a){
|
||||
void DataOutputStream::writeFloatArray(const osg::FloatArray* a)
|
||||
{
|
||||
int size = a->getNumElements();
|
||||
writeInt(size);
|
||||
for(int i =0; i<size ;i++){
|
||||
@@ -236,7 +242,8 @@ void DataOutputStream::writeFloatArray(osg::FloatArray* a){
|
||||
}
|
||||
|
||||
|
||||
void DataOutputStream::writeVec2Array(osg::Vec2Array* a){
|
||||
void DataOutputStream::writeVec2Array(const osg::Vec2Array* a)
|
||||
{
|
||||
int size = a->size();
|
||||
writeInt(size);
|
||||
for(int i=0;i<size;i++){
|
||||
@@ -244,7 +251,8 @@ void DataOutputStream::writeVec2Array(osg::Vec2Array* a){
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeVec3Array(osg::Vec3Array* a){
|
||||
void DataOutputStream::writeVec3Array(const osg::Vec3Array* a)
|
||||
{
|
||||
int size = a->size();
|
||||
writeInt(size);
|
||||
for(int i = 0; i < size; i++){
|
||||
@@ -252,7 +260,8 @@ void DataOutputStream::writeVec3Array(osg::Vec3Array* a){
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeVec4Array(osg::Vec4Array* a){
|
||||
void DataOutputStream::writeVec4Array(const osg::Vec4Array* a)
|
||||
{
|
||||
int size = a->size();
|
||||
writeInt(size);
|
||||
for(int i=0;i<size;i++){
|
||||
@@ -272,7 +281,7 @@ void DataOutputStream::writeMatrix(const osg::Matrix& mat)
|
||||
}
|
||||
|
||||
|
||||
void DataOutputStream::writeStateSet(osg::StateSet* stateset)
|
||||
void DataOutputStream::writeStateSet(const osg::StateSet* stateset)
|
||||
{
|
||||
StateSetMap::iterator itr = _stateSetMap.find(stateset);
|
||||
if (itr!=_stateSetMap.end())
|
||||
@@ -296,7 +305,7 @@ void DataOutputStream::writeStateSet(osg::StateSet* stateset)
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeStateAttribute(osg::StateAttribute* attribute)
|
||||
void DataOutputStream::writeStateAttribute(const osg::StateAttribute* attribute)
|
||||
{
|
||||
StateAttributeMap::iterator itr = _stateAttributeMap.find(attribute);
|
||||
if (itr!=_stateAttributeMap.end())
|
||||
@@ -316,45 +325,45 @@ void DataOutputStream::writeStateAttribute(osg::StateAttribute* attribute)
|
||||
writeInt(id);
|
||||
|
||||
// write the stateset.
|
||||
if(dynamic_cast<osg::BlendFunc*>(attribute)){
|
||||
if(dynamic_cast<const osg::BlendFunc*>(attribute)){
|
||||
((ive::BlendFunc*)(attribute))->write(this);
|
||||
}
|
||||
// This is a Material
|
||||
else if(dynamic_cast<osg::Material*>(attribute)){
|
||||
else if(dynamic_cast<const osg::Material*>(attribute)){
|
||||
((ive::Material*)(attribute))->write(this);
|
||||
}
|
||||
// This is a CullFace
|
||||
else if(dynamic_cast<osg::CullFace*>(attribute)){
|
||||
else if(dynamic_cast<const osg::CullFace*>(attribute)){
|
||||
((ive::CullFace*)(attribute))->write(this);
|
||||
}
|
||||
// This is a PolygonOffset
|
||||
else if(dynamic_cast<osg::PolygonOffset*>(attribute)){
|
||||
else if(dynamic_cast<const osg::PolygonOffset*>(attribute)){
|
||||
((ive::PolygonOffset*)(attribute))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::ShadeModel*>(attribute)){
|
||||
else if(dynamic_cast<const osg::ShadeModel*>(attribute)){
|
||||
((ive::ShadeModel*)(attribute))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::Point*>(attribute)){
|
||||
else if(dynamic_cast<const osg::Point*>(attribute)){
|
||||
((ive::Point*)(attribute))->write(this);
|
||||
}
|
||||
// This is a Texture2D
|
||||
else if(dynamic_cast<osg::Texture2D*>(attribute)){
|
||||
else if(dynamic_cast<const osg::Texture2D*>(attribute)){
|
||||
((ive::Texture2D*)(attribute))->write(this);
|
||||
}
|
||||
// This is a TextureCubeMap
|
||||
else if(dynamic_cast<osg::TextureCubeMap*>(attribute)){
|
||||
else if(dynamic_cast<const osg::TextureCubeMap*>(attribute)){
|
||||
((ive::TextureCubeMap*)(attribute))->write(this);
|
||||
}
|
||||
// This is a TexEnv
|
||||
else if(dynamic_cast<osg::TexEnv*>(attribute)){
|
||||
else if(dynamic_cast<const osg::TexEnv*>(attribute)){
|
||||
((ive::TexEnv*)(attribute))->write(this);
|
||||
}
|
||||
// This is a TexEnvCombine
|
||||
else if(dynamic_cast<osg::TexEnvCombine*>(attribute)){
|
||||
else if(dynamic_cast<const osg::TexEnvCombine*>(attribute)){
|
||||
((ive::TexEnvCombine*)(attribute))->write(this);
|
||||
}
|
||||
// This is a TexGen
|
||||
else if(dynamic_cast<osg::TexGen*>(attribute)){
|
||||
else if(dynamic_cast<const osg::TexGen*>(attribute)){
|
||||
((ive::TexGen*)(attribute))->write(this);
|
||||
}
|
||||
else{
|
||||
@@ -364,7 +373,7 @@ void DataOutputStream::writeStateAttribute(osg::StateAttribute* attribute)
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeDrawable(osg::Drawable* drawable)
|
||||
void DataOutputStream::writeDrawable(const osg::Drawable* drawable)
|
||||
{
|
||||
DrawableMap::iterator itr = _drawableMap.find(drawable);
|
||||
if (itr!=_drawableMap.end())
|
||||
@@ -383,7 +392,7 @@ void DataOutputStream::writeDrawable(osg::Drawable* drawable)
|
||||
// write the id.
|
||||
writeInt(id);
|
||||
|
||||
if(dynamic_cast<osg::Geometry*>(drawable))
|
||||
if(dynamic_cast<const osg::Geometry*>(drawable))
|
||||
((ive::Geometry*)(drawable))->write(this);
|
||||
else{
|
||||
throw Exception("Unknown drawable in DataOutputStream::writeDrawable()");
|
||||
@@ -391,7 +400,7 @@ void DataOutputStream::writeDrawable(osg::Drawable* drawable)
|
||||
}
|
||||
}
|
||||
|
||||
void DataOutputStream::writeNode(osg::Node* node)
|
||||
void DataOutputStream::writeNode(const osg::Node* node)
|
||||
{
|
||||
NodeMap::iterator itr = _nodeMap.find(node);
|
||||
if (itr!=_nodeMap.end())
|
||||
@@ -410,46 +419,48 @@ void DataOutputStream::writeNode(osg::Node* node)
|
||||
// write the id.
|
||||
writeInt(id);
|
||||
|
||||
if(dynamic_cast<osg::MatrixTransform*>(node)){
|
||||
// this follow code *really* should use a NodeVisitor... Robert Osfield August 2003.
|
||||
|
||||
if(dynamic_cast<const osg::MatrixTransform*>(node)){
|
||||
((ive::MatrixTransform*)(node))->write(this);
|
||||
}
|
||||
// else if(dynamic_cast<osgfIVE::ViewPoint*>(node)){
|
||||
// ((ive::ViewPoint*)(node))->write(this);
|
||||
// }
|
||||
else if(dynamic_cast<osg::PositionAttitudeTransform*>(node)){
|
||||
else if(dynamic_cast<const osg::PositionAttitudeTransform*>(node)){
|
||||
((ive::PositionAttitudeTransform*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::LightSource*>(node)){
|
||||
else if(dynamic_cast<const osg::LightSource*>(node)){
|
||||
((ive::LightSource*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::Sequence*>(node)){
|
||||
else if(dynamic_cast<const osg::Sequence*>(node)){
|
||||
((ive::Sequence*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::Impostor*>(node)){
|
||||
else if(dynamic_cast<const osg::Impostor*>(node)){
|
||||
((ive::Impostor*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::PagedLOD*>(node)){
|
||||
else if(dynamic_cast<const osg::PagedLOD*>(node)){
|
||||
((ive::PagedLOD*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::LOD*>(node)){
|
||||
else if(dynamic_cast<const osg::LOD*>(node)){
|
||||
((ive::LOD*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::Switch*>(node)){
|
||||
else if(dynamic_cast<const osg::Switch*>(node)){
|
||||
((ive::Switch*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::OccluderNode*>(node)){
|
||||
else if(dynamic_cast<const osg::OccluderNode*>(node)){
|
||||
((ive::OccluderNode*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::Transform*>(node)){
|
||||
else if(dynamic_cast<const osg::Transform*>(node)){
|
||||
((ive::Transform*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::Group*>(node)){
|
||||
else if(dynamic_cast<const osg::Group*>(node)){
|
||||
((ive::Group*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::Billboard*>(node)){
|
||||
else if(dynamic_cast<const osg::Billboard*>(node)){
|
||||
((ive::Billboard*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<osg::Geode*>(node)){
|
||||
else if(dynamic_cast<const osg::Geode*>(node)){
|
||||
((ive::Geode*)(node))->write(this);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -34,30 +34,30 @@ public:
|
||||
void writeFloat(float f);
|
||||
void writeLong(long l);
|
||||
void writeDouble(double d);
|
||||
void writeString(std::string s);
|
||||
void writeCharArray(char* data, int size);
|
||||
void writeString(const std::string& s);
|
||||
void writeCharArray(const char* data, int size);
|
||||
void writeVec2(const osg::Vec2& v);
|
||||
void writeVec3(const osg::Vec3& v);
|
||||
void writeVec4(const osg::Vec4& v);
|
||||
void writeUByte4(const osg::UByte4& v);
|
||||
void writeQuat(const osg::Quat& q);
|
||||
void writeBinding(osg::Geometry::AttributeBinding b);
|
||||
void writeArray(osg::Array* a);
|
||||
void writeIntArray(osg::IntArray* a);
|
||||
void writeUByteArray(osg::UByteArray* a);
|
||||
void writeUShortArray(osg::UShortArray* a);
|
||||
void writeUIntArray(osg::UIntArray* a);
|
||||
void writeUByte4Array(osg::UByte4Array* a);
|
||||
void writeFloatArray(osg::FloatArray* a);
|
||||
void writeVec2Array(osg::Vec2Array* a);
|
||||
void writeVec3Array(osg::Vec3Array* a);
|
||||
void writeVec4Array(osg::Vec4Array* a);
|
||||
void writeArray(const osg::Array* a);
|
||||
void writeIntArray(const osg::IntArray* a);
|
||||
void writeUByteArray(const osg::UByteArray* a);
|
||||
void writeUShortArray(const osg::UShortArray* a);
|
||||
void writeUIntArray(const osg::UIntArray* a);
|
||||
void writeUByte4Array(const osg::UByte4Array* a);
|
||||
void writeFloatArray(const osg::FloatArray* a);
|
||||
void writeVec2Array(const osg::Vec2Array* a);
|
||||
void writeVec3Array(const osg::Vec3Array* a);
|
||||
void writeVec4Array(const osg::Vec4Array* a);
|
||||
void writeMatrix(const osg::Matrix& mat);
|
||||
|
||||
void writeStateSet(osg::StateSet* stateset);
|
||||
void writeStateAttribute(osg::StateAttribute* sa);
|
||||
void writeDrawable(osg::Drawable* sa);
|
||||
void writeNode(osg::Node* sa);
|
||||
void writeStateSet(const osg::StateSet* stateset);
|
||||
void writeStateAttribute(const osg::StateAttribute* sa);
|
||||
void writeDrawable(const osg::Drawable* sa);
|
||||
void writeNode(const osg::Node* sa);
|
||||
|
||||
// Set and get include image data in stream
|
||||
void setIncludeImageData(bool b) {_includeImageData=b;};
|
||||
@@ -67,10 +67,10 @@ private:
|
||||
std::ostream* _ostream;
|
||||
|
||||
// Container to map stateset uniques to their respective stateset.
|
||||
typedef std::map<osg::StateSet*,int> StateSetMap;
|
||||
typedef std::map<osg::StateAttribute*,int> StateAttributeMap;
|
||||
typedef std::map<osg::Drawable*,int> DrawableMap;
|
||||
typedef std::map<osg::Node*,int> NodeMap;
|
||||
typedef std::map<const osg::StateSet*,int> StateSetMap;
|
||||
typedef std::map<const osg::StateAttribute*,int> StateAttributeMap;
|
||||
typedef std::map<const osg::Drawable*,int> DrawableMap;
|
||||
typedef std::map<const osg::Node*,int> NodeMap;
|
||||
|
||||
StateSetMap _stateSetMap;
|
||||
StateAttributeMap _stateAttributeMap;
|
||||
|
||||
@@ -109,18 +109,40 @@ void Geometry::write(DataOutputStream* out){
|
||||
out->writeArray(getFogCoordIndices());
|
||||
}
|
||||
// Write texture coord arrays
|
||||
Geometry::TexCoordArrayList& tcal = getTexCoordArrayList();
|
||||
Geometry::ArrayList& tcal = getTexCoordArrayList();
|
||||
out->writeInt(tcal.size());
|
||||
for(unsigned int j=0;j<tcal.size();j++){
|
||||
unsigned int j;
|
||||
for(j=0;j<tcal.size();j++)
|
||||
{
|
||||
// Write coords if valid
|
||||
out->writeBool(tcal[j].first.valid());
|
||||
if (tcal[j].first.valid()){
|
||||
out->writeArray(tcal[j].first.get());
|
||||
out->writeBool(tcal[j].array.valid());
|
||||
if (tcal[j].array.valid()){
|
||||
out->writeArray(tcal[j].array.get());
|
||||
}
|
||||
// Write indices if valid
|
||||
out->writeBool(tcal[j].second.valid());
|
||||
if (tcal[j].second.valid()){
|
||||
out->writeArray(tcal[j].second.get());
|
||||
out->writeBool(tcal[j].indices.valid());
|
||||
if (tcal[j].indices.valid()){
|
||||
out->writeArray(tcal[j].indices.get());
|
||||
}
|
||||
}
|
||||
|
||||
// Write vertex attributes
|
||||
Geometry::ArrayList& vaal = getVertexAttribArrayList();
|
||||
out->writeInt(vaal.size());
|
||||
for(j=0;j<vaal.size();j++)
|
||||
{
|
||||
// Write coords if valid
|
||||
const osg::Geometry::ArrayData& arrayData = vaal[j];
|
||||
out->writeBinding(arrayData.binding);
|
||||
out->writeBool(arrayData.normalize==GL_TRUE);
|
||||
out->writeBool(arrayData.array.valid());
|
||||
if (arrayData.array.valid()){
|
||||
out->writeArray(arrayData.array.get());
|
||||
}
|
||||
// Write indices if valid
|
||||
out->writeBool(arrayData.indices.valid());
|
||||
if (arrayData.indices.valid()){
|
||||
out->writeArray(arrayData.indices.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,7 +245,8 @@ void Geometry::read(DataInputStream* in){
|
||||
}
|
||||
// Read texture coord arrays
|
||||
size = in->readInt();
|
||||
for(i =0;i<size;i++){
|
||||
for(i =0;i<size;i++)
|
||||
{
|
||||
// Read coords if valid
|
||||
bool coords_valid = in->readBool();
|
||||
if(coords_valid)
|
||||
@@ -233,6 +256,25 @@ void Geometry::read(DataInputStream* in){
|
||||
if(indices_valid)
|
||||
setTexCoordIndices(i, static_cast<osg::IndexArray*>(in->readArray()));
|
||||
}
|
||||
|
||||
// Read vertex attrib arrays
|
||||
size = in->readInt();
|
||||
for(i =0;i<size;i++)
|
||||
{
|
||||
setVertexAttribBinding(i,in->readBinding());
|
||||
setVertexAttribNormalize(i,in->readBool()?GL_TRUE:GL_FALSE);
|
||||
|
||||
// Read coords if valid
|
||||
bool coords_valid = in->readBool();
|
||||
if(coords_valid)
|
||||
setVertexAttribArray(i, in->readArray());
|
||||
|
||||
// Read Indices if valid
|
||||
bool indices_valid = in->readBool();
|
||||
if(indices_valid)
|
||||
setVertexAttribIndices(i, static_cast<osg::IndexArray*>(in->readArray()));
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
throw Exception("Geometry::read(): Expected Geometry identification.");
|
||||
|
||||
@@ -313,6 +313,59 @@ bool Geometry_readLocalData(Object& obj, Input& fr)
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
Geometry::AttributeBinding vertexAttribBinding=Geometry::BIND_OFF;
|
||||
if (fr.matchSequence("VertexAttribBinding %i %s") && Geometry_matchBindingTypeStr(fr[2].getStr(),vertexAttribBinding))
|
||||
{
|
||||
int unit=0;
|
||||
fr[1].getInt(unit);
|
||||
geom.setVertexAttribBinding(unit,vertexAttribBinding);
|
||||
fr+=3;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("VertexAttribNormalize %i %s"))
|
||||
{
|
||||
int unit=0;
|
||||
fr[1].getInt(unit);
|
||||
|
||||
if (fr[2].matchString("TRUE"))
|
||||
geom.setVertexAttribNormalize(unit,GL_TRUE);
|
||||
else
|
||||
geom.setVertexAttribNormalize(unit,GL_FALSE);
|
||||
|
||||
fr+=3;
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
if (fr.matchSequence("VertexAttribArray %i"))
|
||||
{
|
||||
int unit=0;
|
||||
fr[1].getInt(unit);
|
||||
|
||||
fr+=2;
|
||||
Array* vertexattrib = Array_readLocalData(fr);
|
||||
if (vertexattrib)
|
||||
{
|
||||
geom.setVertexAttribArray(unit,vertexattrib);
|
||||
}
|
||||
iteratorAdvanced = true;
|
||||
|
||||
}
|
||||
|
||||
if (fr.matchSequence("VertexAttribIndices %i"))
|
||||
{
|
||||
int unit=0;
|
||||
fr[1].getInt(unit);
|
||||
|
||||
fr+=2;
|
||||
IndexArray* indices = dynamic_cast<IndexArray*>(Array_readLocalData(fr));
|
||||
if (indices)
|
||||
{
|
||||
geom.setVertexAttribIndices(unit,indices);
|
||||
}
|
||||
iteratorAdvanced = true;
|
||||
}
|
||||
|
||||
return iteratorAdvanced;
|
||||
}
|
||||
|
||||
@@ -969,21 +1022,45 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
|
||||
Array_writeLocalData(*geom.getFogCoordIndices(),fw);
|
||||
}
|
||||
|
||||
const Geometry::TexCoordArrayList& tcal=geom.getTexCoordArrayList();
|
||||
for(unsigned int i=0;i<tcal.size();++i)
|
||||
const Geometry::ArrayList& tcal=geom.getTexCoordArrayList();
|
||||
unsigned int i;
|
||||
for(i=0;i<tcal.size();++i)
|
||||
{
|
||||
if (tcal[i].first.valid())
|
||||
if (tcal[i].array.valid())
|
||||
{
|
||||
fw.indent()<<"TexCoordArray "<<i<<" ";
|
||||
Array_writeLocalData(*(tcal[i].first),fw);
|
||||
Array_writeLocalData(*(tcal[i].array),fw);
|
||||
}
|
||||
if (tcal[i].second.valid())
|
||||
if (tcal[i].indices.valid())
|
||||
{
|
||||
fw.indent()<<"TexCoordIndices "<<i<<" ";
|
||||
Array_writeLocalData(*(tcal[i].second),fw);
|
||||
Array_writeLocalData(*(tcal[i].indices),fw);
|
||||
}
|
||||
}
|
||||
|
||||
const Geometry::ArrayList& vaal=geom.getVertexAttribArrayList();
|
||||
for(i=0;i<vaal.size();++i)
|
||||
{
|
||||
const osg::Geometry::ArrayData& arrayData = vaal[i];
|
||||
|
||||
if (arrayData.array.valid())
|
||||
{
|
||||
fw.indent()<<"VertexAttribBinding "<<i<<" "<<Geometry_getBindingTypeStr(arrayData.binding)<<std::endl;
|
||||
|
||||
if (arrayData.normalize)
|
||||
fw.indent()<<"VertexAttribNormalize "<<i<<" TRUE"<<std::endl;
|
||||
else
|
||||
fw.indent()<<"VertexAttribNormalize "<<i<<" FALSE"<<std::endl;
|
||||
|
||||
fw.indent()<<"VertexAttribArray "<<i<<" ";
|
||||
Array_writeLocalData(*(arrayData.array),fw);
|
||||
}
|
||||
if (arrayData.indices.valid())
|
||||
{
|
||||
fw.indent()<<"VertexAttribIndices "<<i<<" ";
|
||||
Array_writeLocalData(*(arrayData.indices),fw);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ bool BumpMapping_readLocalData(osg::Object &obj, osgDB::Input &fr)
|
||||
|
||||
osg::ref_ptr<osg::Texture2D> normal_tex = static_cast<osg::Texture2D *>(fr.readObjectOfType(osgDB::type_wrapper<osg::Texture2D>()));
|
||||
if (normal_tex.valid()) {
|
||||
myobj.setOverrideDiffuseTexture(normal_tex.get());
|
||||
myobj.setOverrideNormalMapTexture(normal_tex.get());
|
||||
itAdvanced = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -265,14 +265,14 @@ void Tesselator::retesselatePolygons(osg::Geometry& geom)
|
||||
arrays.push_back(geom.getFogCoordArray());
|
||||
}
|
||||
|
||||
osg::Geometry::TexCoordArrayList& tcal = geom.getTexCoordArrayList();
|
||||
for(osg::Geometry::TexCoordArrayList::iterator tcalItr=tcal.begin();
|
||||
osg::Geometry::ArrayList& tcal = geom.getTexCoordArrayList();
|
||||
for(osg::Geometry::ArrayList::iterator tcalItr=tcal.begin();
|
||||
tcalItr!=tcal.end();
|
||||
++tcalItr)
|
||||
{
|
||||
if (tcalItr->first.valid())
|
||||
if (tcalItr->array.valid())
|
||||
{
|
||||
arrays.push_back(tcalItr->first.get());
|
||||
arrays.push_back(tcalItr->array.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user