00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "eggAttributes.h"
00020 #include "eggParameters.h"
00021 #include "eggMorph.h"
00022 #include "eggMorphList.h"
00023
00024 #include <indent.h>
00025 #include <math.h>
00026
00027 TypeHandle EggAttributes::_type_handle;
00028
00029
00030
00031
00032
00033
00034
00035 EggAttributes::
00036 EggAttributes() {
00037 _flags = 0;
00038 }
00039
00040
00041
00042
00043
00044
00045 EggAttributes::
00046 EggAttributes(const EggAttributes ©) {
00047 (*this) = copy;
00048 }
00049
00050
00051
00052
00053
00054
00055 EggAttributes &EggAttributes::
00056 operator = (const EggAttributes ©) {
00057 _flags = copy._flags;
00058 _normal = copy._normal;
00059 _uv = copy._uv;
00060 _color = copy._color;
00061 _dnormals = copy._dnormals;
00062 _duvs = copy._duvs;
00063 _drgbas = copy._drgbas;
00064 return *this;
00065 }
00066
00067
00068
00069
00070
00071
00072 EggAttributes::
00073 ~EggAttributes() {
00074 }
00075
00076
00077
00078
00079
00080
00081
00082
00083 void EggAttributes::
00084 write(ostream &out, int indent_level) const {
00085 if (has_normal()) {
00086 if (_dnormals.empty()) {
00087 indent(out, indent_level)
00088 << "<Normal> { " << get_normal() << " }\n";
00089 } else {
00090 indent(out, indent_level) << "<Normal> {\n";
00091 indent(out, indent_level+2) << get_normal() << "\n";
00092 _dnormals.write(out, indent_level+2);
00093 indent(out, indent_level) << "}\n";
00094 }
00095 }
00096 if (has_uv()) {
00097 if (_duvs.empty()) {
00098 indent(out, indent_level)
00099 << "<UV> { " << get_uv() << " }\n";
00100 } else {
00101 indent(out, indent_level) << "<UV> {\n";
00102 indent(out, indent_level+2) << get_uv() << "\n";
00103 _duvs.write(out, indent_level+2);
00104 indent(out, indent_level) << "}\n";
00105 }
00106 }
00107 if (has_color()) {
00108 if (_drgbas.empty()) {
00109 indent(out, indent_level)
00110 << "<RGBA> { " << get_color() << " }\n";
00111 } else {
00112 indent(out, indent_level) << "<RGBA> {\n";
00113 indent(out, indent_level+2) << get_color() << "\n";
00114 _drgbas.write(out, indent_level+2);
00115 indent(out, indent_level) << "}\n";
00116 }
00117 }
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 bool EggAttributes::
00129 sorts_less_than(const EggAttributes &other) const {
00130 if (_flags != other._flags) {
00131 return _flags < other._flags;
00132 }
00133
00134 if (has_normal()) {
00135 int compare =
00136 _normal.compare_to(other._normal, egg_parameters->_normal_threshold);
00137 if (compare != 0) {
00138 return compare < 0;
00139 }
00140 if (_dnormals != other._dnormals) {
00141 return _dnormals < other._dnormals;
00142 }
00143 }
00144
00145 if (has_uv()) {
00146 int compare =
00147 _uv.compare_to(other._uv, egg_parameters->_uv_threshold);
00148 if (compare != 0) {
00149 return compare < 0;
00150 }
00151 if (_duvs != other._duvs) {
00152 return _duvs < other._duvs;
00153 }
00154 }
00155
00156 if (has_color()) {
00157 int compare =
00158 _color.compare_to(other._color, egg_parameters->_color_threshold);
00159 if (compare != 0) {
00160 return compare < 0;
00161 }
00162 if (_drgbas != other._drgbas) {
00163 return _drgbas < other._drgbas;
00164 }
00165 }
00166
00167 return false;
00168 }
00169
00170
00171
00172
00173
00174
00175
00176 void EggAttributes::
00177 transform(const LMatrix4d &mat) {
00178 if (has_normal()) {
00179 _normal = _normal * mat;
00180 LVector3d old_normal = _normal;
00181 _normal.normalize();
00182
00183 EggMorphNormalList::iterator mi;
00184 for (mi = _dnormals.begin(); mi != _dnormals.end(); ++mi) {
00185
00186
00187
00188 EggMorphNormal &morph = (EggMorphNormal &)(*mi);
00189
00190
00191
00192
00193
00194 LVector3d offset = (*mi).get_offset() * mat;
00195 LVector3d n = old_normal + offset;
00196 n.normalize();
00197 morph.set_offset(n - _normal);
00198 }
00199 }
00200 }