00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00024
00025
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
00040
00041
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
00056
00057
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
00072
00073
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
00089
00090
00091
00092 EggVertexUV::
00093 ~EggVertexUV() {
00094 }
00095
00096
00097
00098
00099
00100
00101
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
00117
00118
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
00157
00158
00159
00160
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 }