2
* This library is open source and may be redistributed and/or modified under
3
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or (at
4
* your option) any later version. The full license is in the LICENSE file
5
* included with this distribution, and on the openscenegraph.org website.
7
* This library is distributed in the hope that it will be useful, but
8
* WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* OpenSceneGraph Public License for more details.
14
// Copyright(c) 2008 Skew Matrix Software LLC.
17
#include "MaterialPaletteManager.h"
18
#include "DataOutputStream.h"
21
#include <osg/Material>
30
MaterialPaletteManager::MaterialPaletteManager( ExportOptions& fltOpt )
34
// TODO: Pay attention to the version here(?)
38
int MaterialPaletteManager::add(osg::Material const* material)
41
if (material == NULL) return -1;
44
// If this material has already been cached, set 'index' to the cached value
45
MaterialPalette::const_iterator it = _materialPalette.find(material);
46
if ( it != _materialPalette.end() )
48
index = it->second.Index;
51
// New material? Add it to the cache...
55
_materialPalette.insert(std::make_pair(material,
56
MaterialRecord(material, index) ) );
63
MaterialPaletteManager::write( DataOutputStream& dos ) const
67
MaterialPalette::const_iterator it = _materialPalette.begin();
68
for ( ; it != _materialPalette.end(); ++it)
70
MaterialRecord m = it->second;
71
Vec4f const& ambient = m.Material->getAmbient(osg::Material::FRONT);
72
Vec4f const& diffuse = m.Material->getDiffuse(osg::Material::FRONT);
73
Vec4f const& specular = m.Material->getSpecular(osg::Material::FRONT);
74
Vec4f const& emissive = m.Material->getEmission(osg::Material::FRONT);
75
float shininess = m.Material->getShininess(osg::Material::FRONT);
77
dos.writeInt16( (int16) MATERIAL_PALETTE_OP );
78
dos.writeInt16( 84 ); // Length - FIXME: hard-code/FLT version?
79
dos.writeInt32( m.Index );
80
dos.writeString( std::string( "" ), 12 ); // Name - FIXME: put a 'real' name here?
81
dos.writeInt32( 0 ); // Flags
82
dos.writeFloat32(ambient.r() );
83
dos.writeFloat32(ambient.g() );
84
dos.writeFloat32(ambient.b() );
85
dos.writeFloat32(diffuse.r() );
86
dos.writeFloat32(diffuse.g() );
87
dos.writeFloat32(diffuse.b() );
88
dos.writeFloat32(specular.r() );
89
dos.writeFloat32(specular.g() );
90
dos.writeFloat32(specular.b() );
91
dos.writeFloat32(emissive.r() );
92
dos.writeFloat32(emissive.g() );
93
dos.writeFloat32(emissive.b() );
94
dos.writeFloat32(shininess);
95
dos.writeFloat32( diffuse.a() ); // alpha
96
dos.writeFloat32(1.0f); // 'Reserved' - unused
98
if (m.Material->getAmbientFrontAndBack() == false ||
99
m.Material->getDiffuseFrontAndBack() == false ||
100
m.Material->getSpecularFrontAndBack() == false ||
101
m.Material->getEmissionFrontAndBack() == false ||
102
m.Material->getShininessFrontAndBack() == false )
105
std::string warning( "fltexp: No support for different front and back material properties." );
106
osg::notify( osg::WARN ) << warning << std::endl;
107
_fltOpt.getWriteResult().warn( warning );
115
} // End namespace fltexp