MaterialNode.cc 17.4 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
Jan Möbius's avatar
Jan Möbius committed
4
 *      Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen      *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
37
 *   $Revision$                                                       *
Jan Möbius's avatar
Jan Möbius committed
38
39
40
41
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56




//=============================================================================
//
//  CLASS MaterialNode - IMPLEMENTATION
//
//=============================================================================


//== INCLUDES =================================================================


#include "MaterialNode.hh"
57
#include "DrawModes.hh"
Jan Möbius's avatar
 
Jan Möbius committed
58

59
#include <cstdio>
Matthias Möller's avatar
Matthias Möller committed
60
#include <sstream>
Jan Möbius's avatar
 
Jan Möbius committed
61

62
63
64
65
66
67
#include <Qt>

#if QT_VERSION >= 0x050000
#include <QJsonDocument>
#include <QJsonObject>
#elif defined(ENABLE_QJSON)
68
69
70
71
#include <QJson/Serializer>
#include <QJson/Parser>
#endif

72
73
74
75
76
77
#if defined(ENABLE_QJSON) || QT_VERSION >= 0x050000
#define JSON_SERIALIZABLE 1
#else
#define JSON_SERIALIZABLE 0
#endif

Jan Möbius's avatar
 
Jan Möbius committed
78
79
//== NAMESPACES ===============================================================

80
namespace {
Jan Möbius's avatar
 
Jan Möbius committed
81

82
enum ClassProperties {
83
#if JSON_SERIALIZABLE
84
85
86
87
88
    CP_JSON_SERIALIZABLE = 1
#else
    CP_JSON_SERIALIZABLE = 0
#endif
};
Jan Möbius's avatar
 
Jan Möbius committed
89

90
91
92
inline QVariantList col2vl(const ACG::Vec4f &col) {
    return QVariantList() << col[0] << col[1] << col[2] << col[3];
}
Jan Möbius's avatar
 
Jan Möbius committed
93

94
95
96
97
inline ACG::Vec4f vl2col(const QVariantList &vl) {
    if (vl.size() < 4) return ACG::Vec4f();
    return ACG::Vec4f(vl[0].toFloat(), vl[1].toFloat(), vl[2].toFloat(), vl[3].toFloat());
}
Jan Möbius's avatar
 
Jan Möbius committed
98

99
100
101
102
103
104
105
106
107
108
109
} /* anonymous namespace */

namespace ACG {

QVariantMap json_to_variant_map(QString json) {
#ifdef ENABLE_QJSON
    QJson::Parser parser;
    bool ok;
    QVariantMap matMap = parser.parse(json.toUtf8(), &ok).toMap();
    if (!ok) return QVariantMap();
    return matMap;
110
111
112
113
114
115
#elif QT_VERSION >= 0x050000
    QJsonParseError error;
    QJsonDocument jsonDoc = QJsonDocument::fromJson(json.toUtf8(), &error);
    if (error.error != QJsonParseError::NoError || !jsonDoc.isObject())
        return QVariantMap();
    return jsonDoc.object().toVariantMap();
116
117
118
#else
    return QVariantMap();
#endif
119
120
}

121
122
123
124
125
126
127
namespace SceneGraph {


//== IMPLEMENTATION ==========================================================

bool Material::support_json_serialization() {
    return CP_JSON_SERIALIZABLE;
128
129
130
}

QString Material::serializeToJson() const {
131
#if JSON_SERIALIZABLE
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
    QVariantMap matMap;

    matMap["baseColor"] = col2vl(baseColor_);
    matMap["ambientColor"] = col2vl(ambientColor_);
    matMap["diffuseColor"] = col2vl(diffuseColor_);
    matMap["specularColor"] = col2vl(specularColor_);
    matMap["overlayColor"] = col2vl(overlayColor_);
    matMap["shininess"] = shininess_;
    matMap["reflectance"] = reflectance_;
    matMap["pointSize"] = pointSize_;
    matMap["lineWidth"] = lineWidth_;
    matMap["roundPoints"] = roundPoints_;
    matMap["linesSmooth"] = linesSmooth_;
    matMap["alphaTest"] = alphaTest_;
    matMap["alphaClip"] = alphaClip_;
    matMap["blending"] = blending_;
    matMap["blendParam1"] = blendParam1_;
    matMap["blendParam2"] = blendParam2_;
    matMap["colorMaterial"] = colorMaterial_;
    matMap["backfaceCulling"] = backfaceCulling_;
    matMap["multiSampling"] = multiSampling_;

154
#ifdef ENABLE_QJSON
155
156
157
    QJson::Serializer serializer;
    QByteArray bytes = serializer.serialize(matMap);
    return QString::fromUtf8(bytes.constData(), bytes.size());
158
159
160
161
162
163
#elif QT_VERSION >= 0x050000
    const QJsonDocument json_doc(QJsonObject::fromVariantMap(matMap));
    return QString::fromUtf8(
            json_doc.toJson(QJsonDocument::Indented));
#endif

164
#else
165
    return QString("<No suitable serializer at the moment. Sorry.>");
166
#endif
167
168
}

169
void Material::deserializeFromVariantMap(const QVariantMap &matMap) {
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
    if (matMap.contains("baseColor")) baseColor_ = vl2col(matMap["baseColor"].toList());
    if (matMap.contains("ambientColor")) ambientColor_ = vl2col(matMap["ambientColor"].toList());
    if (matMap.contains("diffuseColor")) diffuseColor_ = vl2col(matMap["diffuseColor"].toList());
    if (matMap.contains("specularColor")) specularColor_ = vl2col(matMap["specularColor"].toList());
    if (matMap.contains("overlayColor")) overlayColor_ = vl2col(matMap["overlayColor"].toList());
    if (matMap.contains("shininess")) shininess_ = matMap["shininess"].toFloat();
    if (matMap.contains("reflectance")) reflectance_ = matMap["reflectance"].toDouble();
    if (matMap.contains("pointSize")) pointSize_ = matMap["pointSize"].toFloat();
    if (matMap.contains("lineWidth")) lineWidth_ = matMap["lineWidth"].toFloat();
    if (matMap.contains("roundPoints")) roundPoints_ = matMap["roundPoints"].toBool();
    if (matMap.contains("linesSmooth")) linesSmooth_ = matMap["linesSmooth"].toBool();
    if (matMap.contains("alphaTest")) alphaTest_ = matMap["alphaTest"].toBool();
    if (matMap.contains("alphaClip")) alphaClip_ = matMap["alphaClip"].toFloat();
    if (matMap.contains("blending")) blending_ = matMap["blending"].toBool();
    if (matMap.contains("blendParam1")) blendParam1_ = matMap["blendParam1"].toUInt();
    if (matMap.contains("blendParam2")) blendParam2_ = matMap["blendParam2"].toUInt();
    if (matMap.contains("colorMaterial")) colorMaterial_ = matMap["colorMaterial"].toBool();
    if (matMap.contains("backfaceCulling")) backfaceCulling_ = matMap["backfaceCulling"].toBool();
    if (matMap.contains("multiSampling")) multiSampling_ = matMap["multiSampling"].toBool();
189
190
191
}

void Material::deserializeFromJson(const QString &json) {
192
    deserializeFromVariantMap(ACG::json_to_variant_map(json));
193
194
}

Jan Möbius's avatar
 
Jan Möbius committed
195
196
197
198
MaterialNode::MaterialNode( BaseNode*            _parent,
			    const std::string&   _name,
			    unsigned int         _applyProperties )
  : BaseNode(_parent, _name),
199
    applyProperties_(_applyProperties)
Jan Möbius's avatar
 
Jan Möbius committed
200
201
202
203
204
205
{}


//----------------------------------------------------------------------------


206
void MaterialNode::enter(GLState& _state, const DrawModes::DrawMode&  _drawmode  )
Jan Möbius's avatar
 
Jan Möbius committed
207
208
209
{
  if (applyProperties_ & BaseColor)
  {
Jan Möbius's avatar
Jan Möbius committed
210
211
    materialBackup_.baseColor_ = _state.base_color();
    _state.set_base_color(material_.baseColor_);
Jan Möbius's avatar
 
Jan Möbius committed
212
213
214
215
  }

  if (applyProperties_ & Material)
  {
Jan Möbius's avatar
Jan Möbius committed
216
217
218
    materialBackup_.ambientColor_  = _state.ambient_color();
    materialBackup_.diffuseColor_  = _state.diffuse_color();
    materialBackup_.specularColor_ = _state.specular_color();
219
220
    materialBackup_.overlayColor_  = _state.overlay_color();
    materialBackup_.shininess_     = _state.shininess();
221

Jan Möbius's avatar
Jan Möbius committed
222
223
224
    _state.set_ambient_color(material_.ambientColor_);
    _state.set_diffuse_color(material_.diffuseColor_);
    _state.set_specular_color(material_.specularColor_);
225
    _state.set_overlay_color(material_.overlayColor_);
226
    _state.set_shininess(material_.shininess_);
Jan Möbius's avatar
 
Jan Möbius committed
227
228
229
230
  }

  if (applyProperties_ & PointSize)
  {
Jan Möbius's avatar
Jan Möbius committed
231
232
    materialBackup_.pointSize_ = _state.point_size();
    _state.set_point_size(material_.pointSize_);
Jan Möbius's avatar
 
Jan Möbius committed
233
234
235
236
  }

  if (applyProperties_ & LineWidth)
  {
Jan Möbius's avatar
Jan Möbius committed
237
238
    materialBackup_.lineWidth_ = _state.line_width();
    _state.set_line_width(material_.lineWidth_);
Jan Möbius's avatar
 
Jan Möbius committed
239
240
241
242
  }

  if (applyProperties_ & RoundPoints)
  {
Jan Möbius's avatar
Jan Möbius committed
243
    materialBackup_.roundPoints_ = glIsEnabled(GL_POINT_SMOOTH) &&
Jan Möbius's avatar
 
Jan Möbius committed
244
245
                           glIsEnabled(GL_ALPHA_TEST);

Jan Möbius's avatar
Jan Möbius committed
246
    if( material_.roundPoints_ ) {
247
      glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
248
      ACG::GLState::enable(GL_POINT_SMOOTH);
Jan Möbius's avatar
Jan Möbius committed
249
    } else
250
      ACG::GLState::disable(GL_POINT_SMOOTH);
Jan Möbius's avatar
 
Jan Möbius committed
251
252
  }

253
254
  if (applyProperties_ & LineSmooth)
  {
Jan Möbius's avatar
Jan Möbius committed
255
    materialBackup_.linesSmooth_ = glIsEnabled(GL_LINE_SMOOTH) &&
256
257
                           glIsEnabled(GL_ALPHA_TEST);

Jan Möbius's avatar
Jan Möbius committed
258
    if( material_.linesSmooth_ ) {
Jan Möbius's avatar
Jan Möbius committed
259
      glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
260
      ACG::GLState::enable(GL_LINE_SMOOTH);
261
    } else
262
      ACG::GLState::disable(GL_LINE_SMOOTH);
263
264
  }

Jan Möbius's avatar
Jan Möbius committed
265
266
  if (applyProperties_ & MultiSampling)
  {
Jan Möbius's avatar
Jan Möbius committed
267
268
    materialBackup_.multiSampling_ = _state.multisampling();
    _state.set_multisampling( material_.multiSampling_ );
Jan Möbius's avatar
Jan Möbius committed
269
  }
Jan Möbius's avatar
 
Jan Möbius committed
270
271
272

  if (applyProperties_ & AlphaTest)
  {
Jan Möbius's avatar
Jan Möbius committed
273
274
    materialBackup_.alphaTest_ = glIsEnabled(GL_ALPHA_TEST);
    glGetFloatv(GL_ALPHA_TEST_REF, &materialBackup_.alphaClip_);
Jan Möbius's avatar
 
Jan Möbius committed
275

Jan Möbius's avatar
Jan Möbius committed
276
    if(material_.alphaTest_)
Jan Möbius's avatar
 
Jan Möbius committed
277
    {
278
279
      ACG::GLState::alphaFunc(GL_GREATER, material_.alphaClip_ );
      ACG::GLState::enable(GL_ALPHA_TEST);
Jan Möbius's avatar
 
Jan Möbius committed
280
281
282
    }
    else
    {
283
      ACG::GLState::disable(GL_ALPHA_TEST);
Jan Möbius's avatar
 
Jan Möbius committed
284
285
286
287
288
289
    }
  }


  if (applyProperties_ & Blending)
  {
290
    materialBackup_.blending_ = _state.blending();
Jan Möbius's avatar
Jan Möbius committed
291
292
    glGetIntegerv( GL_BLEND_SRC, (GLint*) &materialBackup_.blendParam1_);
    glGetIntegerv( GL_BLEND_DST, (GLint*) &materialBackup_.blendParam2_);
Jan Möbius's avatar
 
Jan Möbius committed
293

294
    _state.set_blending(material_.blending_);
Jan Möbius's avatar
 
Jan Möbius committed
295

296
    if (material_.blending_)
Jan Möbius's avatar
 
Jan Möbius committed
297
    {
298
      _state.set_depthFunc(GL_LEQUAL);
299
300
      ACG::GLState::blendFunc(material_.blendParam1_, material_.blendParam2_);
      ACG::GLState::enable(GL_BLEND);
Jan Möbius's avatar
 
Jan Möbius committed
301
302
303
    }
    else
    {
304
      _state.set_depthFunc(GL_LESS);
305
      ACG::GLState::disable(GL_BLEND);
Jan Möbius's avatar
 
Jan Möbius committed
306
307
308
309
310
311
    }
  }


  if (applyProperties_ & BackFaceCulling)
  {
Jan Möbius's avatar
Jan Möbius committed
312
    materialBackup_.backfaceCulling_ = glIsEnabled(GL_CULL_FACE);
Jan Möbius's avatar
 
Jan Möbius committed
313

Jan Möbius's avatar
Jan Möbius committed
314
    if ( material_.backfaceCulling_ )
315
      ACG::GLState::enable( GL_CULL_FACE );
Jan Möbius's avatar
 
Jan Möbius committed
316
    else
317
      ACG::GLState::disable( GL_CULL_FACE );
Jan Möbius's avatar
Jan Möbius committed
318

319
320
  }

321
  if ( ( applyProperties_ & ColorMaterial ) && (_drawmode & (DrawModes::SOLID_FACES_COLORED_FLAT_SHADED|DrawModes::SOLID_FACES_COLORED_SMOOTH_SHADED)) )
322
  {
Jan Möbius's avatar
Jan Möbius committed
323
    materialBackup_.colorMaterial_ = glIsEnabled(GL_COLOR_MATERIAL);
324

Jan Möbius's avatar
Jan Möbius committed
325
    if (material_.colorMaterial_ ) {
326
      ACG::GLState::disable( GL_COLOR_MATERIAL );
327
      glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
328
      ACG::GLState::enable( GL_COLOR_MATERIAL );
329
    } else
330
      ACG::GLState::disable( GL_COLOR_MATERIAL );
331
332
  }

Jan Möbius's avatar
 
Jan Möbius committed
333
334
}

335
336
//----------------------------------------------------------------------------

337
void MaterialNode::enterPick(GLState& _state , PickTarget /*_target*/, const DrawModes::DrawMode& /*_drawMode*/ ) {
338

339
340
341
342
343
344
345
346
347
348
349
  if (applyProperties_ & PointSize)
  {
    materialBackup_.pointSize_ = _state.point_size();
    _state.set_point_size(material_.pointSize_);
  }

  if (applyProperties_ & LineWidth)
  {
    materialBackup_.lineWidth_ = _state.line_width();
    _state.set_line_width(material_.lineWidth_);
  }
350
351
}

352
353
354
355
356
357
358
359
360
361
362
363
void MaterialNode::leavePick(GLState& _state, PickTarget /*_target*/, const DrawModes::DrawMode& /*_drawMode*/ ) {

  if (applyProperties_ & PointSize)
  {
    _state.set_point_size(materialBackup_.pointSize_);
  }


  if (applyProperties_ & LineWidth)
  {
    _state.set_line_width(materialBackup_.lineWidth_);
  }
364
365
}

Jan Möbius's avatar
 
Jan Möbius committed
366
367
368
369

//----------------------------------------------------------------------------


370
void MaterialNode::leave(GLState& _state, const DrawModes::DrawMode& _drawmode )
Jan Möbius's avatar
 
Jan Möbius committed
371
372
373
{
  if (applyProperties_ & BaseColor)
  {
Jan Möbius's avatar
Jan Möbius committed
374
    _state.set_base_color(materialBackup_.baseColor_);
Jan Möbius's avatar
 
Jan Möbius committed
375
376
377
378
379
  }


  if (applyProperties_ & Material)
  {
Jan Möbius's avatar
Jan Möbius committed
380
381
382
    _state.set_ambient_color(materialBackup_.ambientColor_);
    _state.set_diffuse_color(materialBackup_.diffuseColor_);
    _state.set_specular_color(materialBackup_.specularColor_);
383
    _state.set_overlay_color(materialBackup_.overlayColor_);
384
    _state.set_shininess(materialBackup_.shininess_);
Jan Möbius's avatar
 
Jan Möbius committed
385
386
387
388
389
  }


  if (applyProperties_ & PointSize)
  {
Jan Möbius's avatar
Jan Möbius committed
390
    _state.set_point_size(materialBackup_.pointSize_);
Jan Möbius's avatar
 
Jan Möbius committed
391
392
393
394
395
  }


  if (applyProperties_ & LineWidth)
  {
Jan Möbius's avatar
Jan Möbius committed
396
    _state.set_line_width(materialBackup_.lineWidth_);
Jan Möbius's avatar
 
Jan Möbius committed
397
398
399
400
401
  }


  if (applyProperties_ & RoundPoints)
  {
Jan Möbius's avatar
Jan Möbius committed
402
    if( materialBackup_.roundPoints_)
403
      ACG::GLState::enable(GL_POINT_SMOOTH);
Jan Möbius's avatar
 
Jan Möbius committed
404
    else
405
      ACG::GLState::disable(GL_POINT_SMOOTH);
Jan Möbius's avatar
 
Jan Möbius committed
406
407
  }

408
409
  if (applyProperties_ & LineSmooth)
  {
Jan Möbius's avatar
Jan Möbius committed
410
    if( materialBackup_.linesSmooth_)
411
      ACG::GLState::enable(GL_LINE_SMOOTH);
412
    else
413
      ACG::GLState::disable(GL_LINE_SMOOTH);
414
415
  }

Jan Möbius's avatar
Jan Möbius committed
416
  if (applyProperties_ & MultiSampling)
Jan Möbius's avatar
Jan Möbius committed
417
    _state.set_multisampling( materialBackup_.multiSampling_ );
Jan Möbius's avatar
Jan Möbius committed
418

Jan Möbius's avatar
 
Jan Möbius committed
419
420
  if (applyProperties_ & AlphaTest)
  {
Jan Möbius's avatar
Jan Möbius committed
421
    if (materialBackup_.alphaTest_)
Jan Möbius's avatar
 
Jan Möbius committed
422
    {
423
424
      ACG::GLState::alphaFunc(GL_GREATER, materialBackup_.alphaClip_);
      ACG::GLState::enable(GL_ALPHA_TEST);
Jan Möbius's avatar
 
Jan Möbius committed
425
426
427
    }
    else
    {
428
      ACG::GLState::disable(GL_ALPHA_TEST);
Jan Möbius's avatar
 
Jan Möbius committed
429
430
431
432
433
434
    }
  }


  if (applyProperties_ & Blending)
  {
435
    _state.set_blending(materialBackup_.blending_);
Jan Möbius's avatar
 
Jan Möbius committed
436

437
    if (materialBackup_.blending_)
Jan Möbius's avatar
 
Jan Möbius committed
438
    {
439
      _state.set_depthFunc(GL_LEQUAL);
440
441
      ACG::GLState::blendFunc(materialBackup_.blendParam1_, materialBackup_.blendParam2_);
      ACG::GLState::enable(GL_BLEND);
Jan Möbius's avatar
 
Jan Möbius committed
442
443
444
    }
    else
    {
445
      _state.set_depthFunc(GL_LESS);
446
      ACG::GLState::disable(GL_BLEND);
Jan Möbius's avatar
 
Jan Möbius committed
447
448
449
450
451
452
    }
  }


  if (applyProperties_ & BackFaceCulling)
  {
Jan Möbius's avatar
Jan Möbius committed
453
    if (materialBackup_.backfaceCulling_)
454
      ACG::GLState::enable( GL_CULL_FACE );
Jan Möbius's avatar
 
Jan Möbius committed
455
    else
456
      ACG::GLState::disable( GL_CULL_FACE );
Jan Möbius's avatar
 
Jan Möbius committed
457
 }
458

459
  if ( ( applyProperties_ & ColorMaterial ) && ( _drawmode & DrawModes::SOLID_FACES_COLORED_FLAT_SHADED )  )
460
  {
Jan Möbius's avatar
Jan Möbius committed
461
    if (materialBackup_.colorMaterial_ ) {
462
      ACG::GLState::enable( GL_COLOR_MATERIAL );
463
    } else
464
      ACG::GLState::disable( GL_COLOR_MATERIAL );
465
466
  }

Jan Möbius's avatar
 
Jan Möbius committed
467
468
469
470
471
472
473
474
475
476
}


//----------------------------------------------------------------------------


void
MaterialNode::read(std::istream& _is)
{

477
478
  char        s[200];
  float       x, y, z, u;
Jan Möbius's avatar
 
Jan Möbius committed
479

480
481
  while (_is && (!_is.eof()) && _is.getline(s,200) ) {
    std::istringstream buffer(s);
Jan Möbius's avatar
 
Jan Möbius committed
482

483
484
485
486
487
    // comment or empty
    if ( s[0] == '#')
      continue;

    std::string specifier = "";
Jan Möbius's avatar
 
Jan Möbius committed
488

489
490
    // Read specifier from buffer
    buffer >> specifier;
Jan Möbius's avatar
 
Jan Möbius committed
491
492

    // BaseColor
493
494
495
496
497
    if (specifier == "BaseColor") {
      buffer >> x >> y >> z >> u;

      if (buffer.good()) {
        material_.baseColor(Vec4f(x, y, z, u));
Jan Möbius's avatar
 
Jan Möbius committed
498
499
500
      }
    }
    // AmbientColor
501
502
503
504
505
    else if (specifier == "AmbientColor") {
      buffer >> x >> y >> z >> u;

      if (buffer.good()) {
        material_.ambientColor(Vec4f(x, y, z, u));
Jan Möbius's avatar
 
Jan Möbius committed
506
507
508
      }
    }
    // DiffuseColor
509
510
511
512
513
    else if (specifier == "DiffuseColor") {
      buffer >> x >> y >> z >> u;

      if (buffer.good()) {
        material_.diffuseColor(Vec4f(x, y, z, u));
Jan Möbius's avatar
 
Jan Möbius committed
514
515
516
      }
    }
    // SpecularColor
517
518
519
520
521
    else if (specifier == "SpecularColor") {
      buffer >> x >> y >> z >> u;

      if (buffer.good()) {
        material_.specularColor(Vec4f(x, y, z, u));
Jan Möbius's avatar
 
Jan Möbius committed
522
523
      }
    }
524
525
526
527
528
529
530
531
    // OverlayColor
    else if (specifier == "OverlayColor") {
      buffer >> x >> y >> z >> u;

      if (buffer.good()) {
        material_.overlayColor(Vec4f(x, y, z, u));
      }
    }
Jan Möbius's avatar
 
Jan Möbius committed
532
    // Shininess
533
534
535
536
    else if (specifier == "Shininess") {
      buffer >> x;

      if (buffer.good()) {
Jan Möbius's avatar
Jan Möbius committed
537
        material_.shininess(x);
Jan Möbius's avatar
 
Jan Möbius committed
538
539
540
      }
    }
    // PointSize
541
542
543
544
    else if (specifier == "PointSize") {
      buffer >> x;

      if (buffer.good()) {
Jan Möbius's avatar
Jan Möbius committed
545
        material_.pointSize(x);
Jan Möbius's avatar
 
Jan Möbius committed
546
547
548
      }
    }
    // LineWidth
549
550
551
552
    else if (specifier == "LineWidth") {
      buffer >> x;

      if (buffer.good()) {
Jan Möbius's avatar
Jan Möbius committed
553
        material_.lineWidth(x);
Jan Möbius's avatar
 
Jan Möbius committed
554
555
556
      }
    }

557
558
    if (!buffer.good())
      std::cerr << "MaterialNode parse error while reading string : " << s << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
559
560
561
562
563
564
565
566

  }
}

//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================