From 12be8e54930b888229145403c9d448cf83341589 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 13 Jul 2002 14:16:41 +0000 Subject: [PATCH] Support added for multitextured TXP files, sent in by Boris Bralo. --- src/osgPlugins/txp/TrPageArchive.cpp | 96 +++++++++++++++------------- src/osgPlugins/txp/TrPageParser.cpp | 26 +++++--- 2 files changed, 68 insertions(+), 54 deletions(-) diff --git a/src/osgPlugins/txp/TrPageArchive.cpp b/src/osgPlugins/txp/TrPageArchive.cpp index f30980dd9..1bf558861 100644 --- a/src/osgPlugins/txp/TrPageArchive.cpp +++ b/src/osgPlugins/txp/TrPageArchive.cpp @@ -174,39 +174,13 @@ void TrPageArchive::LoadMaterials() // TODO : multitextuting // also note that multitexturing in terrapage can came from two sides // - multiple textures per material, and multiple materials per geometry - if(numMatTex) + if( numMatTex ) { - int texId; - trpgTextureEnv texEnv; - mat->GetTexture(0,texId,texEnv); - - // Set up texture environment - TexEnv *osg_texenv = new TexEnv(); - int32 te_mode; - texEnv.GetEnvMode(te_mode); - switch( te_mode ) - { - case trpgTextureEnv::Alpha : - osg_texenv->setMode(TexEnv::REPLACE); - break; - case trpgTextureEnv::Decal: - osg_texenv->setMode(TexEnv::DECAL); - break; - case trpgTextureEnv::Blend : - osg_texenv->setMode(TexEnv::BLEND); - break; - case trpgTextureEnv::Modulate : - osg_texenv->setMode(TexEnv::MODULATE); - break; - } - - osg_state_set->setTextureAttribute(0,osg_texenv); - Material *osg_material = new Material; float64 alpha; mat->GetAlpha(alpha); - + trpgColor color; mat->GetAmbient(color); osg_material->setAmbient( Material::FRONT_AND_BACK , @@ -246,27 +220,57 @@ void TrPageArchive::LoadMaterials() osg_state_set->setAttributeAndModes(osg_alpha_func, StateAttribute::ON); } - int wrap_s, wrap_t; - texEnv.GetWrap(wrap_s, wrap_t); - - Texture* osg_texture = m_textures[texId].get(); - if(osg_texture) + for (int ntex = 0; ntex < numMatTex; ntex ++ ) { - osg_texture->setWrap(Texture::WRAP_S, wrap_s == trpgTextureEnv::Repeat ? Texture::REPEAT: Texture::CLAMP ); - osg_texture->setWrap(Texture::WRAP_T, wrap_t == trpgTextureEnv::Repeat ? Texture::REPEAT: Texture::CLAMP ); - osg_state_set->setTextureAttributeAndModes(0,osg_texture, StateAttribute::ON); + int texId; + trpgTextureEnv texEnv; + mat->GetTexture(ntex,texId,texEnv); - if(osg_texture->getImage()) - { - switch (osg_texture->getImage()->getPixelFormat()) - { - case GL_LUMINANCE_ALPHA: - case GL_RGBA: - osg_state_set->setMode(GL_BLEND,StateAttribute::ON); - osg_state_set->setRenderingHint(StateSet::TRANSPARENT_BIN); - } + // Set up texture environment + TexEnv *osg_texenv = new TexEnv(); + int32 te_mode; + texEnv.GetEnvMode(te_mode); + switch( te_mode ) + { + case trpgTextureEnv::Alpha : + osg_texenv->setMode(TexEnv::REPLACE); + break; + case trpgTextureEnv::Decal: + osg_texenv->setMode(TexEnv::DECAL); + break; + case trpgTextureEnv::Blend : + osg_texenv->setMode(TexEnv::BLEND); + break; + case trpgTextureEnv::Modulate : + osg_texenv->setMode(TexEnv::MODULATE); + break; } - } + + osg_state_set->setTextureAttribute(ntex,osg_texenv); + + int wrap_s, wrap_t; + texEnv.GetWrap(wrap_s, wrap_t); + + Texture* osg_texture = m_textures[texId].get(); + if(osg_texture) + { + osg_texture->setWrap(Texture::WRAP_S, wrap_s == trpgTextureEnv::Repeat ? Texture::REPEAT: Texture::CLAMP ); + osg_texture->setWrap(Texture::WRAP_T, wrap_t == trpgTextureEnv::Repeat ? Texture::REPEAT: Texture::CLAMP ); + osg_state_set->setTextureAttributeAndModes(ntex,osg_texture, StateAttribute::ON); + + if(osg_texture->getImage()) + { + switch (osg_texture->getImage()->getPixelFormat()) + { + case GL_LUMINANCE_ALPHA: + case GL_RGBA: + osg_state_set->setMode(GL_BLEND,StateAttribute::ON); + osg_state_set->setRenderingHint(StateSet::TRANSPARENT_BIN); + } + } + } + } + int cullMode; mat->GetCullMode(cullMode); diff --git a/src/osgPlugins/txp/TrPageParser.cpp b/src/osgPlugins/txp/TrPageParser.cpp index f823a6a42..92d21979d 100644 --- a/src/osgPlugins/txp/TrPageParser.cpp +++ b/src/osgPlugins/txp/TrPageParser.cpp @@ -223,14 +223,20 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) Geometry *geometry = 0L; // Get texture coordinates - Vec2Array* tex_coords = 0L; trpgTexData td; - if (geom.GetTexCoordSet(0,&td)) + int num_tex; + geom.GetNumTexCoordSets(num_tex); + Vec2Array** tex_coords = new Vec2Array*[num_tex]; + for (int texno = 0; texno < num_tex; texno++) { - tex_coords = new Vec2Array(numVert); - for (int i=0 ;i < numVert; i++) + tex_coords[texno] = 0L; + if (geom.GetTexCoordSet(texno,&td)) { - (*tex_coords)[i].set(td.floatData[2*i+0],td.floatData[2*i+1]); + tex_coords[texno] = new Vec2Array(numVert); + for (int i=0 ;i < numVert; i++) + { + (*(tex_coords[texno]))[i].set(td.floatData[2*i+0],td.floatData[2*i+1]); + } } } @@ -297,8 +303,11 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) for (int j=0; j < numSwap; j++ ) { std::swap((*vertices)[start], (*vertices)[end]); - if( tex_coords ) - std::swap((*tex_coords)[start], (*tex_coords)[end]); + for(int texno = 0; texno < num_tex; texno ++ ) + { + if( tex_coords[texno] ) + std::swap((*tex_coords[texno])[start], (*tex_coords[texno])[end]); + } if(normals) std::swap((*normals)[start], (*normals)[end]); start++; @@ -334,7 +343,8 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) if (tex_coords) { - geometry->setTexCoordArray( 0, tex_coords); + for (int texno = 0; texno < num_tex; texno++) + geometry->setTexCoordArray( texno, tex_coords[texno]); } geometry->setStateSet(sset.get());