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