root/OpenSceneGraph/trunk/src/osgWrappers/serializers/osg/Material.cpp @ 13041

Revision 13041, 2.0 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1#include <osg/Material>
2#include <osgDB/ObjectWrapper>
3#include <osgDB/InputStream>
4#include <osgDB/OutputStream>
5
6#define MATERIAL_FUNC( PROP, TYPE ) \
7    static bool check##PROP( const osg::Material& attr ) { return true; } \
8    static bool read##PROP( osgDB::InputStream& is, osg::Material& attr ) { \
9        bool frontAndBack; TYPE value1, value2; \
10        is >> frontAndBack; \
11        is >> osgDB::PROPERTY("Front") >> value1; \
12        is >> osgDB::PROPERTY("Back") >> value2; \
13        if ( frontAndBack ) \
14            attr.set##PROP(osg::Material::FRONT_AND_BACK, value1); \
15        else { \
16            attr.set##PROP(osg::Material::FRONT, value1); \
17            attr.set##PROP(osg::Material::BACK, value2); \
18        } \
19        return true; \
20    } \
21    static bool write##PROP( osgDB::OutputStream& os, const osg::Material& attr ) { \
22        os << attr.get##PROP##FrontAndBack(); \
23        os << osgDB::PROPERTY("Front") << TYPE(attr.get##PROP(osg::Material::FRONT)); \
24        os << osgDB::PROPERTY("Back") << TYPE(attr.get##PROP(osg::Material::BACK)) << std::endl; \
25        return true; \
26    }
27
28MATERIAL_FUNC( Ambient, osg::Vec4f )
29MATERIAL_FUNC( Diffuse, osg::Vec4f )
30MATERIAL_FUNC( Specular, osg::Vec4f )
31MATERIAL_FUNC( Emission, osg::Vec4f )
32MATERIAL_FUNC( Shininess, float )
33
34REGISTER_OBJECT_WRAPPER( Material,
35                         new osg::Material,
36                         osg::Material,
37                         "osg::Object osg::StateAttribute osg::Material" )
38{
39    BEGIN_ENUM_SERIALIZER( ColorMode, OFF );
40        ADD_ENUM_VALUE( AMBIENT );
41        ADD_ENUM_VALUE( DIFFUSE );
42        ADD_ENUM_VALUE( SPECULAR );
43        ADD_ENUM_VALUE( EMISSION );
44        ADD_ENUM_VALUE( AMBIENT_AND_DIFFUSE );
45        ADD_ENUM_VALUE( OFF );
46    END_ENUM_SERIALIZER();  // _colorMode
47
48    ADD_USER_SERIALIZER( Ambient );  // _ambient
49    ADD_USER_SERIALIZER( Diffuse );  // _diffuse
50    ADD_USER_SERIALIZER( Specular );  // _specular
51    ADD_USER_SERIALIZER( Emission );  // _emission
52    ADD_USER_SERIALIZER( Shininess );  // _shininess
53}
Note: See TracBrowser for help on using the browser.