root/OpenSceneGraph/trunk/src/osgPlugins/ive/Material.cpp @ 13041

Revision 13041, 3.2 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/**********************************************************************
2 *
3 *    FILE:            Material.cpp
4 *
5 *    DESCRIPTION:    Read/Write osg::Material in binary format to disk.
6 *
7 *    CREATED BY:        Auto generated by iveGenerated
8 *                    and later modified by Rune Schmidt Jensen.
9 *
10 *    HISTORY:        Created 20.3.2003
11 *
12 *    Copyright 2003 VR-C
13 **********************************************************************/
14
15#include "Exception.h"
16#include "Material.h"
17#include "Object.h"
18
19using namespace ive;
20
21void Material::write(DataOutputStream* out){
22    // Write Material's identification.
23    out->writeInt(IVEMATERIAL);
24    // If the osg class is inherited by any other class we should also write this to file.
25    osg::Object*  obj = dynamic_cast<osg::Object*>(this);
26    if(obj){
27        ((ive::Object*)(obj))->write(out);
28    }
29    else
30        out_THROW_EXCEPTION("Material::write(): Could not cast this osg::Material to an osg::Object.");
31    // Write Material's properties.
32
33    //    Write color mode
34    out->writeInt(_colorMode);
35    // Write ambient
36    out->writeBool(_ambientFrontAndBack);
37    out->writeVec4(_ambientFront);
38    out->writeVec4(_ambientBack);
39    // Write diffuse
40    out->writeBool(_diffuseFrontAndBack);
41    out->writeVec4(_diffuseFront);
42    out->writeVec4(_diffuseBack);
43    // Write specular
44    out->writeBool(_specularFrontAndBack);
45    out->writeVec4(_specularFront);
46    out->writeVec4(_specularBack);
47    // Write emmision
48    out->writeBool(_emissionFrontAndBack);
49    out->writeVec4(_emissionFront);
50    out->writeVec4(_emissionBack);
51    // Write shininess
52    out->writeBool(_shininessFrontAndBack);
53    out->writeFloat(_shininessFront);
54    out->writeFloat(_shininessBack);
55
56}
57
58void Material::read(DataInputStream* in){
59    // Read Material's identification.
60    int id = in->peekInt();
61    if(id == IVEMATERIAL){
62        // Code to read Material's properties.
63        id = in->readInt();
64        // If the osg class is inherited by any other class we should also read this from file.
65        osg::Object*  obj = dynamic_cast<osg::Object*>(this);
66        if(obj){
67            ((ive::Object*)(obj))->read(in);
68        }
69        else
70            in_THROW_EXCEPTION("Material::read(): Could not cast this osg::Material to an osg::Object.");
71
72        // Read color mode.
73        _colorMode = (osg::Material::ColorMode)in->readInt();
74        // Read ambient
75        _ambientFrontAndBack = in->readBool();
76        _ambientFront = in->readVec4();
77        _ambientBack = in->readVec4();
78        // Read diffuse
79        _diffuseFrontAndBack = in->readBool();
80        _diffuseFront = in->readVec4();
81        _diffuseBack = in->readVec4();
82        // Read specular
83        _specularFrontAndBack = in->readBool();
84        _specularFront = in->readVec4();
85        _specularBack = in->readVec4();
86        // Read emission
87        _emissionFrontAndBack = in->readBool();
88        _emissionFront = in->readVec4();
89        _emissionBack = in->readVec4();
90        // Read shiniess
91        _shininessFrontAndBack = in->readBool();
92        _shininessFront = in->readFloat();
93        _shininessBack = in->readFloat();
94    }
95    else{
96        in_THROW_EXCEPTION("Material::read(): Expected Material identification.");
97    }
98}
Note: See TracBrowser for help on using the browser.