Panda3D
vrmlAppearance.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file vrmlAppearance.cxx
10  * @author drose
11  * @date 1999-06-24
12  */
13 
14 #include "vrmlAppearance.h"
15 #include "vrmlNode.h"
16 #include "deg_2_rad.h"
17 
18 VRMLAppearance::
19 VRMLAppearance(const VrmlNode *appearance) {
20  _has_material = false;
21  _transparency = 0.0;
22  _color.set(1.0f, 1.0f, 1.0f, 1.0f);
23  _has_tex_transform = false;
24 
25  if (appearance != nullptr) {
26  const VrmlNode *material = appearance->get_value("material")._sfnode._p;
27  if (material != nullptr) {
28  _has_material = true;
29  const double *c = material->get_value("diffuseColor")._sfvec;
30  _transparency = material->get_value("transparency")._sffloat;
31  _color.set(c[0], c[1], c[2], 1.0 - _transparency);
32  }
33 
34  const VrmlNode *tex_transform = appearance->get_value("textureTransform")._sfnode._p;
35  if (tex_transform != nullptr) {
36  if (strcmp(tex_transform->_type->getName(), "TextureTransform") == 0) {
37  _has_tex_transform = true;
38  const double *c = tex_transform->get_value("center")._sfvec;
39  _tex_center.set(c[0], c[1]);
40  _tex_rotation = tex_transform->get_value("rotation")._sffloat;
41  const double *s = tex_transform->get_value("scale")._sfvec;
42  _tex_scale.set(s[0], s[1]);
43  const double *t = tex_transform->get_value("translation")._sfvec;
44  _tex_translation.set(t[0], t[1]);
45  }
46  }
47 
48  const VrmlNode *texture = appearance->get_value("texture")._sfnode._p;
49  if (texture != nullptr) {
50  if (strcmp(texture->_type->getName(), "ImageTexture") == 0) {
51  MFArray *url = texture->get_value("url")._mf;
52  if (!url->empty()) {
53  const char *filename = (*url->begin())._sfstring;
54  _tex = new EggTexture("tref", filename);
55 
56  if (_has_tex_transform) {
57  _tex->add_translate2d(-_tex_center);
58  _tex->add_scale2d(_tex_scale);
59  _tex->add_rotate2d(rad_2_deg(_tex_rotation));
60  _tex->add_translate2d(_tex_center);
61  _tex->add_translate2d(_tex_translation);
62  }
63  }
64  }
65  }
66  }
67 }
Defines a texture map that may be applied to geometry.
Definition: eggTexture.h:30
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.