diff --git a/src/osgPlugins/OpenFlight/AncillaryRecords.cpp b/src/osgPlugins/OpenFlight/AncillaryRecords.cpp index 9b06c15c4..0af8174a9 100644 --- a/src/osgPlugins/OpenFlight/AncillaryRecords.cpp +++ b/src/osgPlugins/OpenFlight/AncillaryRecords.cpp @@ -6,6 +6,7 @@ #include #include +#include #include "Registry.h" #include "Document.h" @@ -116,6 +117,13 @@ class Multitexture : public Record META_Record(Multitexture) + // Effect + enum EffectMode + { + TEXTURE_ENVIRONMENT = 0, + BUMP_MAP = 1 + }; + protected: virtual ~Multitexture() {} @@ -131,16 +139,40 @@ class Multitexture : public Record if (mask & layerBit) { int16 textureIndex = in.readInt16(); - /* int16 effectIndex =*/ in.readInt16(); - /* int16 mappingIndex =*/ in.readInt16(); - /* uint16 data=*/ in.readUInt16(); + int16 effect = in.readInt16(); + /*int16 mappingIndex =*/ in.readInt16(); + /*uint16 data =*/ in.readUInt16(); osg::ref_ptr texturePoolStateset = document.getOrCreateTexturePool()->get(textureIndex); if (stateset.valid() && texturePoolStateset.valid()) { - osg::Texture2D* texture = dynamic_cast(texturePoolStateset->getTextureAttribute(0,osg::StateAttribute::TEXTURE)); + // Apply texture from texture pool. + osg::Texture* texture = dynamic_cast(texturePoolStateset->getTextureAttribute(0,osg::StateAttribute::TEXTURE)); if (texture) stateset->setTextureAttributeAndModes(layer,texture,osg::StateAttribute::ON); + + // Apply texture environment + switch (effect) + { + case TEXTURE_ENVIRONMENT: + { + // Use texture environment setting from .attr file. + osg::TexEnv* texenv = dynamic_cast(texturePoolStateset->getTextureAttribute(0,osg::StateAttribute::TEXENV)); + if (texenv) + stateset->setTextureAttribute(layer,texenv); + } + break; + case BUMP_MAP: + { + // Dot3 bumpmap + //osg::TexEnvCombine* texEnvCombine = new osg::TexEnvCombine; + //texEnvCombine->setCombine_RGB(osg::TexEnvCombine::DOT3_RGB); + //texEnvCombine->setSource0_RGB(osg::TexEnvCombine::PRIMARY_COLOR); + //texEnvCombine->setSource1_RGB(osg::TexEnvCombine::TEXTURE); + //stateset->setTextureAttribute(layer,texEnvCombine); + } + break; + } } } } @@ -194,8 +226,8 @@ class UVList : public Record uint32 layerBit = 0x80000000u >> (layer-1); if (mask & layerBit) { - float32 u = in.readFloat32(); - float32 v = in.readFloat32(); + float32 u = in.readFloat32(); + float32 v = in.readFloat32(); // Add texture coodinates to geometry. if (_parent.valid()) diff --git a/src/osgPlugins/OpenFlight/GeometryRecords.cpp b/src/osgPlugins/OpenFlight/GeometryRecords.cpp index b9363d661..5646d938b 100644 --- a/src/osgPlugins/OpenFlight/GeometryRecords.cpp +++ b/src/osgPlugins/OpenFlight/GeometryRecords.cpp @@ -148,10 +148,33 @@ public: } } - if (vertex.validNormal()) + bool strict = false; // prepare for "strict" reader option. + if (strict) { - osg::Vec3Array* normals = getOrCreateNormalArray(*_geometry); - normals->push_back(vertex._normal); + if (vertex.validNormal()) + { + osg::Vec3Array* normals = getOrCreateNormalArray(*_geometry); + normals->push_back(vertex._normal); + } + } + else + { + // Add normal only if lit. + if (isLit()) + { + osg::Vec3Array* normals = getOrCreateNormalArray(*_geometry); + + if (vertex.validNormal()) + normals->push_back(vertex._normal); + else // if lit and no normal in Vertex + { + // Use previous normal if available. + if (normals->empty()) + normals->push_back(osg::Vec3(0,0,1)); + else + normals->push_back(normals->back()); + } + } } for (int layer=0; layersetName(name); + // Read vertex programs int idx; for( idx=0; idxaddShader( vertexShader ); } } + + // Read fragment programs for( idx=0; idxempty()) + { + _header->getOrCreateStateSet()->addUniform( new osg::Uniform("TextureUnit0", 0) ); + _header->getOrCreateStateSet()->addUniform( new osg::Uniform("TextureUnit1", 1) ); + _header->getOrCreateStateSet()->addUniform( new osg::Uniform("TextureUnit2", 2) ); + _header->getOrCreateStateSet()->addUniform( new osg::Uniform("TextureUnit3", 3) ); + } + } + } }; RegisterRecordProxy
g_Header(HEADER_OP);