Panda3D
|
00001 // Filename: eggVertexUV.cxx 00002 // Created by: drose (20Jul04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "eggVertexUV.h" 00016 #include "eggParameters.h" 00017 00018 #include "indent.h" 00019 00020 TypeHandle EggVertexUV::_type_handle; 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: EggVertexUV::Constructor 00024 // Access: Published 00025 // Description: 00026 //////////////////////////////////////////////////////////////////// 00027 EggVertexUV:: 00028 EggVertexUV(const string &name, const LTexCoordd &uv) : 00029 EggNamedObject(name), 00030 _flags(0), 00031 _uvw(uv[0], uv[1], 0.0) 00032 { 00033 if (get_name() == "default") { 00034 clear_name(); 00035 } 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: EggVertexUV::Constructor 00040 // Access: Published 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 EggVertexUV:: 00044 EggVertexUV(const string &name, const LTexCoord3d &uvw) : 00045 EggNamedObject(name), 00046 _flags(F_has_w), 00047 _uvw(uvw) 00048 { 00049 if (get_name() == "default") { 00050 clear_name(); 00051 } 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: EggVertexUV::Copy Constructor 00056 // Access: Published 00057 // Description: 00058 //////////////////////////////////////////////////////////////////// 00059 EggVertexUV:: 00060 EggVertexUV(const EggVertexUV ©) : 00061 EggNamedObject(copy), 00062 _duvs(copy._duvs), 00063 _flags(copy._flags), 00064 _tangent(copy._tangent), 00065 _binormal(copy._binormal), 00066 _uvw(copy._uvw) 00067 { 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: EggVertexUV::Copy Assignment Operator 00072 // Access: Published 00073 // Description: 00074 //////////////////////////////////////////////////////////////////// 00075 EggVertexUV &EggVertexUV:: 00076 operator = (const EggVertexUV ©) { 00077 EggNamedObject::operator = (copy); 00078 _duvs = copy._duvs; 00079 _flags = copy._flags; 00080 _tangent = copy._tangent; 00081 _binormal = copy._binormal; 00082 _uvw = copy._uvw; 00083 00084 return (*this); 00085 } 00086 00087 //////////////////////////////////////////////////////////////////// 00088 // Function: EggVertexUV::Destructor 00089 // Access: Published, Virtual 00090 // Description: 00091 //////////////////////////////////////////////////////////////////// 00092 EggVertexUV:: 00093 ~EggVertexUV() { 00094 } 00095 00096 //////////////////////////////////////////////////////////////////// 00097 // Function: EggVertexUV::transform 00098 // Access: Published, Virtual 00099 // Description: Applies the indicated transformation matrix to the 00100 // UV's tangent and/or binormal. This does nothing if 00101 // there is no tangent or binormal. 00102 //////////////////////////////////////////////////////////////////// 00103 void EggVertexUV:: 00104 transform(const LMatrix4d &mat) { 00105 if (has_tangent()) { 00106 _tangent = _tangent * mat; 00107 _tangent.normalize(); 00108 } 00109 if (has_binormal()) { 00110 _binormal = _binormal * mat; 00111 _binormal.normalize(); 00112 } 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: EggVertexUV::write 00117 // Access: Public 00118 // Description: 00119 //////////////////////////////////////////////////////////////////// 00120 void EggVertexUV:: 00121 write(ostream &out, int indent_level) const { 00122 string inline_name = get_name(); 00123 if (!inline_name.empty()) { 00124 inline_name += ' '; 00125 } 00126 00127 if (_duvs.empty() && (_flags & ~F_has_w) == 0) { 00128 if (has_w()) { 00129 indent(out, indent_level) 00130 << "<UV> " << inline_name << "{ " << get_uvw() << " }\n"; 00131 } else { 00132 indent(out, indent_level) 00133 << "<UV> " << inline_name << "{ " << get_uv() << " }\n"; 00134 } 00135 } else { 00136 indent(out, indent_level) << "<UV> " << inline_name << "{\n"; 00137 if (has_w()) { 00138 indent(out, indent_level+2) << get_uvw() << "\n"; 00139 } else { 00140 indent(out, indent_level+2) << get_uv() << "\n"; 00141 } 00142 if (has_tangent()) { 00143 indent(out, indent_level + 2) 00144 << "<Tangent> { " << get_tangent() << " }\n"; 00145 } 00146 if (has_binormal()) { 00147 indent(out, indent_level + 2) 00148 << "<Binormal> { " << get_binormal() << " }\n"; 00149 } 00150 _duvs.write(out, indent_level + 2, "<Duv>", get_num_dimensions()); 00151 indent(out, indent_level) << "}\n"; 00152 } 00153 } 00154 00155 //////////////////////////////////////////////////////////////////// 00156 // Function: EggVertexUV::compare_to 00157 // Access: Public 00158 // Description: An ordering operator to compare two vertices for 00159 // sorting order. This imposes an arbitrary ordering 00160 // useful to identify unique vertices. 00161 //////////////////////////////////////////////////////////////////// 00162 int EggVertexUV:: 00163 compare_to(const EggVertexUV &other) const { 00164 if (_flags != other._flags) { 00165 return _flags - other._flags; 00166 } 00167 int compare; 00168 compare = _uvw.compare_to(other._uvw, egg_parameters->_uv_threshold); 00169 if (compare != 0) { 00170 return compare; 00171 } 00172 00173 if (has_tangent()) { 00174 compare = _tangent.compare_to(other._tangent, egg_parameters->_normal_threshold); 00175 if (compare != 0) { 00176 return compare; 00177 } 00178 } 00179 00180 if (has_binormal()) { 00181 compare = _binormal.compare_to(other._binormal, egg_parameters->_normal_threshold); 00182 if (compare != 0) { 00183 return compare; 00184 } 00185 } 00186 00187 if (_duvs != other._duvs) { 00188 return _duvs < other._duvs ? -1 : 1; 00189 } 00190 00191 return 0; 00192 }