From cc9d12f34fa4033e2e7e1f560bcdcfa1e6637977 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 19 Jun 2008 14:35:18 +0000 Subject: [PATCH] From Rudolf Weidemann, "in the OpenFlight format materials can have editable names. In the OSG OpenFlight plugin these names are ignored when reading, and empty strings are written. As we need these names in the OSG scene graph by our application, I changed the plugin code, so the names are now stored in class "osg::Material" (derived from "osg::Object") by material->setName(); (see "PaletteRecords.cpp, line 195) when reading the file, and written to file by dos.writeString( m.Material->getName(), 12 ); (see MaterialPaletteManager.cpp, line 80). As these names otherwise get lost when reading an OpenFlight file and writing it again e.g. by osgconv example.flt converted_example.flt these changes make the plugin more complete. The changes were made to OSG revision 8425, and were tested by osgconv example.flt converted_example.flt comparing the material palettes of both files inside Multigen Creator." --- src/osgPlugins/OpenFlight/MaterialPaletteManager.cpp | 2 +- src/osgPlugins/OpenFlight/PaletteRecords.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/osgPlugins/OpenFlight/MaterialPaletteManager.cpp b/src/osgPlugins/OpenFlight/MaterialPaletteManager.cpp index 158b007a6..b44e9c3ac 100644 --- a/src/osgPlugins/OpenFlight/MaterialPaletteManager.cpp +++ b/src/osgPlugins/OpenFlight/MaterialPaletteManager.cpp @@ -77,7 +77,7 @@ MaterialPaletteManager::write( DataOutputStream& dos ) const dos.writeInt16( (int16) MATERIAL_PALETTE_OP ); dos.writeInt16( 84 ); // Length - FIXME: hard-code/FLT version? dos.writeInt32( m.Index ); - dos.writeString( std::string( "" ), 12 ); // Name - FIXME: put a 'real' name here? + dos.writeString( m.Material->getName(), 12 ); dos.writeInt32( 0 ); // Flags dos.writeFloat32(ambient.r() ); dos.writeFloat32(ambient.g() ); diff --git a/src/osgPlugins/OpenFlight/PaletteRecords.cpp b/src/osgPlugins/OpenFlight/PaletteRecords.cpp index 0ed52a8a2..4340bb79d 100644 --- a/src/osgPlugins/OpenFlight/PaletteRecords.cpp +++ b/src/osgPlugins/OpenFlight/PaletteRecords.cpp @@ -192,6 +192,7 @@ protected: float32 alpha = in.readFloat32(); osg::Material* material = new osg::Material; + material->setName(name); material->setAmbient(osg::Material::FRONT_AND_BACK,osg::Vec4(ambient,alpha)); material->setDiffuse (osg::Material::FRONT_AND_BACK,osg::Vec4(diffuse,alpha)); material->setSpecular(osg::Material::FRONT_AND_BACK,osg::Vec4(specular,alpha));