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