Cleaned up handling of vertex arrays in osg::Geometry.
Added support for vertex attribute arrays in .osg and .ive.
This commit is contained in:
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