Panda3D
|
00001 // Filename: vrmlAppearance.cxx 00002 // Created by: drose (24Jun99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // PANDA 3D SOFTWARE 00006 // Copyright (c) Carnegie Mellon University. All rights reserved. 00007 // 00008 // All use of this software is subject to the terms of the revised BSD 00009 // license. You should have received a copy of this license along 00010 // with this source code in a file named "LICENSE." 00011 //////////////////////////////////////////////////////////////////// 00012 00013 #include "vrmlAppearance.h" 00014 #include "vrmlNode.h" 00015 #include "deg_2_rad.h" 00016 00017 VRMLAppearance:: 00018 VRMLAppearance(const VrmlNode *appearance) { 00019 _has_material = false; 00020 _transparency = 0.0; 00021 _color.set(1.0f, 1.0f, 1.0f, 1.0f); 00022 _has_tex_transform = false; 00023 00024 if (appearance != NULL) { 00025 const VrmlNode *material = appearance->get_value("material")._sfnode._p; 00026 if (material != NULL) { 00027 _has_material = true; 00028 const double *c = material->get_value("diffuseColor")._sfvec; 00029 _transparency = material->get_value("transparency")._sffloat; 00030 _color.set(c[0], c[1], c[2], 1.0 - _transparency); 00031 } 00032 00033 const VrmlNode *tex_transform = appearance->get_value("textureTransform")._sfnode._p; 00034 if (tex_transform != NULL) { 00035 if (strcmp(tex_transform->_type->getName(), "TextureTransform") == 0) { 00036 _has_tex_transform = true; 00037 const double *c = tex_transform->get_value("center")._sfvec; 00038 _tex_center.set(c[0], c[1]); 00039 _tex_rotation = tex_transform->get_value("rotation")._sffloat; 00040 const double *s = tex_transform->get_value("scale")._sfvec; 00041 _tex_scale.set(s[0], s[1]); 00042 const double *t = tex_transform->get_value("translation")._sfvec; 00043 _tex_translation.set(t[0], t[1]); 00044 } 00045 } 00046 00047 const VrmlNode *texture = appearance->get_value("texture")._sfnode._p; 00048 if (texture != NULL) { 00049 if (strcmp(texture->_type->getName(), "ImageTexture") == 0) { 00050 MFArray *url = texture->get_value("url")._mf; 00051 if (!url->empty()) { 00052 const char *filename = (*url->begin())._sfstring; 00053 _tex = new EggTexture("tref", filename); 00054 00055 if (_has_tex_transform) { 00056 _tex->add_translate2d(-_tex_center); 00057 _tex->add_scale2d(_tex_scale); 00058 _tex->add_rotate2d(rad_2_deg(_tex_rotation)); 00059 _tex->add_translate2d(_tex_center); 00060 _tex->add_translate2d(_tex_translation); 00061 } 00062 } 00063 } 00064 } 00065 } 00066 } 00067 00068