00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "eggMaterial.h"
00020
00021 #include <indent.h>
00022
00023 TypeHandle EggMaterial::_type_handle;
00024
00025
00026
00027
00028
00029
00030
00031 EggMaterial::
00032 EggMaterial(const string &mref_name)
00033 : EggNode(mref_name)
00034 {
00035 _flags = 0;
00036 }
00037
00038
00039
00040
00041
00042
00043 EggMaterial::
00044 EggMaterial(const EggMaterial ©)
00045 : EggNode(copy),
00046 _diff(copy._diff),
00047 _amb(copy._amb),
00048 _emit(copy._emit),
00049 _spec(copy._spec),
00050 _shininess(copy._shininess),
00051 _local(copy._local),
00052 _flags(copy._flags)
00053 {
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063 void EggMaterial::
00064 write(ostream &out, int indent_level) const {
00065 write_header(out, indent_level, "<Material>");
00066
00067 if (has_diff()) {
00068 indent(out, indent_level + 2)
00069 << "<Scalar> diffr { " << get_diff()[0] << " }\n";
00070 indent(out, indent_level + 2)
00071 << "<Scalar> diffg { " << get_diff()[1] << " }\n";
00072 indent(out, indent_level + 2)
00073 << "<Scalar> diffb { " << get_diff()[2] << " }\n";
00074 if (get_diff()[3] != 1.0) {
00075 indent(out, indent_level + 2)
00076 << "<Scalar> diffa { " << get_diff()[3] << " }\n";
00077 }
00078 }
00079
00080 if (has_amb()) {
00081 indent(out, indent_level + 2)
00082 << "<Scalar> ambr { " << get_amb()[0] << " }\n";
00083 indent(out, indent_level + 2)
00084 << "<Scalar> ambg { " << get_amb()[1] << " }\n";
00085 indent(out, indent_level + 2)
00086 << "<Scalar> ambb { " << get_amb()[2] << " }\n";
00087 if (get_amb()[3] != 1.0) {
00088 indent(out, indent_level + 2)
00089 << "<Scalar> amba { " << get_amb()[3] << " }\n";
00090 }
00091 }
00092
00093 if (has_emit()) {
00094 indent(out, indent_level + 2)
00095 << "<Scalar> emitr { " << get_emit()[0] << " }\n";
00096 indent(out, indent_level + 2)
00097 << "<Scalar> emitg { " << get_emit()[1] << " }\n";
00098 indent(out, indent_level + 2)
00099 << "<Scalar> emitb { " << get_emit()[2] << " }\n";
00100 if (get_emit()[3] != 1.0) {
00101 indent(out, indent_level + 2)
00102 << "<Scalar> emita { " << get_emit()[3] << " }\n";
00103 }
00104 }
00105
00106 if (has_spec()) {
00107 indent(out, indent_level + 2)
00108 << "<Scalar> specr { " << get_spec()[0] << " }\n";
00109 indent(out, indent_level + 2)
00110 << "<Scalar> specg { " << get_spec()[1] << " }\n";
00111 indent(out, indent_level + 2)
00112 << "<Scalar> specb { " << get_spec()[2] << " }\n";
00113 if (get_spec()[3] != 1.0) {
00114 indent(out, indent_level + 2)
00115 << "<Scalar> speca { " << get_spec()[3] << " }\n";
00116 }
00117 }
00118
00119 if (has_shininess()) {
00120 indent(out, indent_level + 2)
00121 << "<Scalar> shininess { " << get_shininess() << " }\n";
00122 }
00123
00124 if (has_local()) {
00125 indent(out, indent_level + 2)
00126 << "<Scalar> local { " << get_local() << " }\n";
00127 }
00128
00129 indent(out, indent_level) << "}\n";
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 bool EggMaterial::
00151 is_equivalent_to(const EggMaterial &other, int eq) const {
00152 if (eq & E_attributes) {
00153 if (_flags != other._flags ||
00154 (has_diff() && get_diff() != other.get_diff()) ||
00155 (has_amb() && get_amb() != other.get_amb()) ||
00156 (has_emit() && get_emit() != other.get_emit()) ||
00157 (has_spec() && get_spec() != other.get_spec()) ||
00158 (has_shininess() && get_shininess() != other.get_shininess()) ||
00159 (has_local() && get_local() != other.get_local())) {
00160 return false;
00161 }
00162 }
00163
00164 if (eq & E_mref_name) {
00165 if (get_name() != other.get_name()) {
00166 return false;
00167 }
00168 }
00169
00170 return true;
00171 }
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 bool EggMaterial::
00183 sorts_less_than(const EggMaterial &other, int eq) const {
00184 if (eq & E_attributes) {
00185 if (_flags != other._flags) {
00186 return _flags < (int)other._flags;
00187 }
00188 if (has_diff() && get_diff() != other.get_diff()) {
00189 return get_diff().compare_to(other.get_diff()) < 0;
00190 }
00191 if (has_amb() && get_amb() != other.get_amb()) {
00192 return get_amb().compare_to(other.get_amb()) < 0;
00193 }
00194 if (has_emit() && get_emit() != other.get_emit()) {
00195 return get_emit().compare_to(other.get_emit()) < 0;
00196 }
00197 if (has_spec() && get_spec() != other.get_spec()) {
00198 return get_spec().compare_to(other.get_spec()) < 0;
00199 }
00200 if (has_shininess() && get_shininess() != other.get_shininess()) {
00201 return get_shininess() < other.get_shininess();
00202 }
00203 if (has_local() && get_local() != other.get_local()) {
00204 return get_local() < other.get_local();
00205 }
00206 }
00207
00208 if (eq & E_mref_name) {
00209 if (get_name() != other.get_name()) {
00210 return get_name() < other.get_name();
00211 }
00212 }
00213
00214 return false;
00215 }