Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FrsMaterial.h « scene_graph « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 18d3c8839dde943aea04fc4296436dec3d9e9aae (plain)
1
2
3
4
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#pragma once

/** \file
 * \ingroup freestyle
 * \brief Class used to handle materials.
 */

#include "../system/FreestyleConfig.h"

#ifdef WITH_CXX_GUARDEDALLOC
#  include "MEM_guardedalloc.h"
#endif

namespace Freestyle {

/*! Class defining a material */
class FrsMaterial {
 public:
  /*! Default constructor */
  inline FrsMaterial();

  /*! Builds a Material from its line, diffuse, ambient, specular, emissive
   *  colors, a shininess coefficient and line color priority.
   *    \param iLine:
   *      A 4 element float-array containing the line color.
   *    \param iDiffuse:
   *      A 4 element float-array containing the diffuse color.
   *    \param iAmbiant:
   *      A 4 element float-array containing the ambient color.
   *    \param iSpecular:
   *      A 4 element float-array containing the specular color.
   *    \param iEmission:
   *      A 4 element float-array containing the emissive color.
   *    \param iShininess:
   *      The shininess coefficient.
   *    \param iPriority:
   *      The line color priority.
   */
  inline FrsMaterial(const float *iLine,
                     const float *iDiffuse,
                     const float *iAmbiant,
                     const float *iSpecular,
                     const float *iEmission,
                     const float iShininess,
                     const int iPriority);

  /*! Copy constructor */
  inline FrsMaterial(const FrsMaterial &m);

  /*! Destructor */
  virtual ~FrsMaterial()
  {
  }

  /*! Returns the line color as a 4 float array */
  inline const float *line() const
  {
    return Line;
  }

  /*! Returns the red component of the line color */
  inline const float lineR() const
  {
    return Line[0];
  }

  /*! Returns the green component of the line color */
  inline const float lineG() const
  {
    return Line[1];
  }

  /*! Returns the blue component of the line color */
  inline const float lineB() const
  {
    return Line[2];
  }

  /*! Returns the alpha component of the line color */
  inline const float lineA() const
  {
    return Line[3];
  }

  /*! Returns the diffuse color as a 4 float array */
  inline const float *diffuse() const
  {
    return Diffuse;
  }

  /*! Returns the red component of the diffuse color */
  inline const float diffuseR() const
  {
    return Diffuse[0];
  }

  /*! Returns the green component of the diffuse color */
  inline const float diffuseG() const
  {
    return Diffuse[1];
  }

  /*! Returns the blue component of the diffuse color */
  inline const float diffuseB() const
  {
    return Diffuse[2];
  }

  /*! Returns the alpha component of the diffuse color */
  inline const float diffuseA() const
  {
    return Diffuse[3];
  }

  /*! Returns the specular color as a 4 float array */
  inline const float *specular() const
  {
    return Specular;
  }

  /*! Returns the red component of the specular color */
  inline const float specularR() const
  {
    return Specular[0];
  }

  /*! Returns the green component of the specular color */
  inline const float specularG() const
  {
    return Specular[1];
  }

  /*! Returns the blue component of the specular color */
  inline const float specularB() const
  {
    return Specular[2];
  }

  /*! Returns the alpha component of the specular color */
  inline const float specularA() const
  {
    return Specular[3];
  }

  /*! Returns the ambient color as a 4 float array */
  inline const float *ambient() const
  {
    return Ambient;
  }

  /*! Returns the red component of the ambient color */
  inline const float ambientR() const
  {
    return Ambient[0];
  }

  /*! Returns the green component of the ambient color */
  inline const float ambientG() const
  {
    return Ambient[1];
  }

  /*! Returns the blue component of the ambient color */
  inline const float ambientB() const
  {
    return Ambient[2];
  }

  /*! Returns the alpha component of the ambient color */
  inline const float ambientA() const
  {
    return Ambient[3];
  }

  /*! Returns the emissive color as a 4 float array */
  inline const float *emission() const
  {
    return Emission;
  }

  /*! Returns the red component of the emissive color */
  inline const float emissionR() const
  {
    return Emission[0];
  }

  /*! Returns the green component of the emissive color */
  inline const float emissionG() const
  {
    return Emission[1];
  }

  /*! Returns the blue component of the emissive color */
  inline const float emissionB() const
  {
    return Emission[2];
  }

  /*! Returns the alpha component of the emissive color */
  inline const float emissionA() const
  {
    return Emission[3];
  }

  /*! Returns the shininess coefficient */
  inline const float shininess() const
  {
    return Shininess;
  }

  /*! Returns the line color priority */
  inline const int priority() const
  {
    return Priority;
  }

  /*! Sets the line color.
   *    \param r:
   *      Red component
   *    \param g:
   *      Green component
   *    \param b:
   *     Blue component
   *    \param a:
   *      Alpha component
   */
  inline void setLine(const float r, const float g, const float b, const float a);

  /*! Sets the diffuse color.
   *    \param r:
   *      Red component
   *    \param g:
   *      Green component
   *    \param b:
   *     Blue component
   *    \param a:
   *      Alpha component
   */
  inline void setDiffuse(const float r, const float g, const float b, const float a);

  /*! Sets the specular color.
   *    \param r:
   *      Red component
   *    \param g:
   *      Green component
   *    \param b:
   *     Blue component
   *    \param a:
   *      Alpha component
   */
  inline void setSpecular(const float r, const float g, const float b, const float a);

  /*! Sets the ambient color.
   *    \param r:
   *      Red component
   *    \param g:
   *      Green component
   *    \param b:
   *     Blue component
   *    \param a:
   *      Alpha component
   */
  inline void setAmbient(const float r, const float g, const float b, const float a);

  /*! Sets the emissive color.
   *    \param r:
   *      Red component
   *    \param g:
   *      Green component
   *    \param b:
   *     Blue component
   *    \param a:
   *      Alpha component
   */
  inline void setEmission(const float r, const float g, const float b, const float a);

  /*! Sets the shininess.
   *    \param s:
   *      Shininess
   */
  inline void setShininess(const float s);

  /*! Sets the line color priority.
   *    \param priority:
   *      Priority
   */
  inline void setPriority(const int priority);

  /* operators */
  inline FrsMaterial &operator=(const FrsMaterial &m);
  inline bool operator!=(const FrsMaterial &m) const;
  inline bool operator==(const FrsMaterial &m) const;

 private:
  /*! Material properties */
  float Line[4];
  float Diffuse[4];
  float Specular[4];
  float Ambient[4];
  float Emission[4];
  float Shininess;
  int Priority;

#ifdef WITH_CXX_GUARDEDALLOC
  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:FrsMaterial")
#endif
};

FrsMaterial::FrsMaterial()
{
  Line[0] = Line[1] = Line[2] = 0.0f;
  Line[3] = 1.0f;

  Ambient[0] = Ambient[1] = Ambient[2] = 0.2f;
  Ambient[3] = 1.0f;

  Diffuse[0] = Diffuse[1] = Diffuse[2] = 0.8f;
  Diffuse[3] = 1.0f;

  Emission[0] = Emission[1] = Emission[2] = 0.0f;
  Emission[3] = 1.0f;

  Specular[0] = Specular[1] = Specular[2] = 0.0f;
  Specular[3] = 1.0f;

  Shininess = 0.0f;
  Priority = 0;
}

FrsMaterial::FrsMaterial(const float *iLine,
                         const float *iDiffuse,
                         const float *iAmbiant,
                         const float *iSpecular,
                         const float *iEmission,
                         const float iShininess,
                         const int iPriority)
{
  for (int i = 0; i < 4; i++) {
    Line[i] = iLine[i];
    Diffuse[i] = iDiffuse[i];
    Specular[i] = iSpecular[i];
    Ambient[i] = iAmbiant[i];
    Emission[i] = iEmission[i];
  }

  Shininess = iShininess;
  Priority = iPriority;
}

FrsMaterial::FrsMaterial(const FrsMaterial &m)
{
  for (int i = 0; i < 4; i++) {
    Line[i] = m.line()[i];
    Diffuse[i] = m.diffuse()[i];
    Specular[i] = m.specular()[i];
    Ambient[i] = m.ambient()[i];
    Emission[i] = m.emission()[i];
  }

  Shininess = m.shininess();
  Priority = m.priority();
}

void FrsMaterial::setLine(const float r, const float g, const float b, const float a)
{
  Line[0] = r;
  Line[1] = g;
  Line[2] = b;
  Line[3] = a;
}

void FrsMaterial::setDiffuse(const float r, const float g, const float b, const float a)
{
  Diffuse[0] = r;
  Diffuse[1] = g;
  Diffuse[2] = b;
  Diffuse[3] = a;
}

void FrsMaterial::setSpecular(const float r, const float g, const float b, const float a)
{
  Specular[0] = r;
  Specular[1] = g;
  Specular[2] = b;
  Specular[3] = a;
}

void FrsMaterial::setAmbient(const float r, const float g, const float b, const float a)
{
  Ambient[0] = r;
  Ambient[1] = g;
  Ambient[2] = b;
  Ambient[3] = a;
}

void FrsMaterial::setEmission(const float r, const float g, const float b, const float a)
{
  Emission[0] = r;
  Emission[1] = g;
  Emission[2] = b;
  Emission[3] = a;
}

void FrsMaterial::setShininess(const float s)
{
  Shininess = s;
}

void FrsMaterial::setPriority(const int priority)
{
  Priority = priority;
}

FrsMaterial &FrsMaterial::operator=(const FrsMaterial &m)
{
  for (int i = 0; i < 4; i++) {
    Line[i] = m.line()[i];
    Diffuse[i] = m.diffuse()[i];
    Specular[i] = m.specular()[i];
    Ambient[i] = m.ambient()[i];
    Emission[i] = m.emission()[i];
  }

  Shininess = m.shininess();
  Priority = m.priority();
  return *this;
}

bool FrsMaterial::operator!=(const FrsMaterial &m) const
{
  if (Shininess != m.shininess()) {
    return true;
  }
  if (Priority != m.priority()) {
    return true;
  }

  for (int i = 0; i < 4; i++) {
    if (Line[i] != m.line()[i]) {
      return true;
    }
    if (Diffuse[i] != m.diffuse()[i]) {
      return true;
    }
    if (Specular[i] != m.specular()[i]) {
      return true;
    }
    if (Ambient[i] != m.ambient()[i]) {
      return true;
    }
    if (Emission[i] != m.emission()[i]) {
      return true;
    }
  }

  return false;
}

bool FrsMaterial::operator==(const FrsMaterial &m) const
{
  return (!((*this) != m));
}

} /* namespace Freestyle */