| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include "Exception.h" |
|---|
| 16 | #include "Material.h" |
|---|
| 17 | #include "Object.h" |
|---|
| 18 | |
|---|
| 19 | using namespace ive; |
|---|
| 20 | |
|---|
| 21 | void Material::write(DataOutputStream* out){ |
|---|
| 22 | |
|---|
| 23 | out->writeInt(IVEMATERIAL); |
|---|
| 24 | |
|---|
| 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 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | out->writeInt(_colorMode); |
|---|
| 35 | |
|---|
| 36 | out->writeBool(_ambientFrontAndBack); |
|---|
| 37 | out->writeVec4(_ambientFront); |
|---|
| 38 | out->writeVec4(_ambientBack); |
|---|
| 39 | |
|---|
| 40 | out->writeBool(_diffuseFrontAndBack); |
|---|
| 41 | out->writeVec4(_diffuseFront); |
|---|
| 42 | out->writeVec4(_diffuseBack); |
|---|
| 43 | |
|---|
| 44 | out->writeBool(_specularFrontAndBack); |
|---|
| 45 | out->writeVec4(_specularFront); |
|---|
| 46 | out->writeVec4(_specularBack); |
|---|
| 47 | |
|---|
| 48 | out->writeBool(_emissionFrontAndBack); |
|---|
| 49 | out->writeVec4(_emissionFront); |
|---|
| 50 | out->writeVec4(_emissionBack); |
|---|
| 51 | |
|---|
| 52 | out->writeBool(_shininessFrontAndBack); |
|---|
| 53 | out->writeFloat(_shininessFront); |
|---|
| 54 | out->writeFloat(_shininessBack); |
|---|
| 55 | |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | void Material::read(DataInputStream* in){ |
|---|
| 59 | |
|---|
| 60 | int id = in->peekInt(); |
|---|
| 61 | if(id == IVEMATERIAL){ |
|---|
| 62 | |
|---|
| 63 | id = in->readInt(); |
|---|
| 64 | |
|---|
| 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 | |
|---|
| 73 | _colorMode = (osg::Material::ColorMode)in->readInt(); |
|---|
| 74 | |
|---|
| 75 | _ambientFrontAndBack = in->readBool(); |
|---|
| 76 | _ambientFront = in->readVec4(); |
|---|
| 77 | _ambientBack = in->readVec4(); |
|---|
| 78 | |
|---|
| 79 | _diffuseFrontAndBack = in->readBool(); |
|---|
| 80 | _diffuseFront = in->readVec4(); |
|---|
| 81 | _diffuseBack = in->readVec4(); |
|---|
| 82 | |
|---|
| 83 | _specularFrontAndBack = in->readBool(); |
|---|
| 84 | _specularFront = in->readVec4(); |
|---|
| 85 | _specularBack = in->readVec4(); |
|---|
| 86 | |
|---|
| 87 | _emissionFrontAndBack = in->readBool(); |
|---|
| 88 | _emissionFront = in->readVec4(); |
|---|
| 89 | _emissionBack = in->readVec4(); |
|---|
| 90 | |
|---|
| 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 | } |
|---|