00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "fltGeometry.h"
00020 #include "fltRecordReader.h"
00021 #include "fltRecordWriter.h"
00022 #include "fltHeader.h"
00023 #include "fltMaterial.h"
00024
00025 TypeHandle FltGeometry::_type_handle;
00026
00027
00028
00029
00030
00031
00032 FltGeometry::
00033 FltGeometry(FltHeader *header) : FltBeadID(header) {
00034 _ir_color = 0;
00035 _relative_priority = 0;
00036 _draw_type = DT_solid_backface;
00037 _texwhite = false;
00038 _color_name_index = 0;
00039 _alt_color_name_index = 0;
00040 _billboard_type = BT_none;
00041 _detail_texture_index = -1;
00042 _texture_index = -1;
00043 _material_index = -1;
00044 _dfad_material_code = 0;
00045 _dfad_feature_id = 0;
00046 _ir_material_code = 0;
00047 _transparency = 0;
00048 _lod_generation_control = 0;
00049 _line_style_index = 0;
00050 _flags = 0;
00051 _light_mode = LM_face_no_normal;
00052 _texture_mapping_index = 0;
00053 _color_index = 0;
00054 _alt_color_index = 0;
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 Colorf FltGeometry::
00069 get_color() const {
00070 Colorf color;
00071
00072 if (!has_color() || (_texwhite && has_texture())) {
00073
00074 color.set(1.0, 1.0, 1.0, 1.0);
00075
00076 } else if (has_material()) {
00077
00078 FltMaterial *material = get_material();
00079 color.set(material->_diffuse[0],
00080 material->_diffuse[1],
00081 material->_diffuse[2],
00082 material->_alpha);
00083 } else {
00084 RGBColorf rgb =
00085 _header->get_rgb(_color_index, (_flags & F_packed_color) != 0,
00086 _packed_color);
00087 color.set(rgb[0], rgb[1], rgb[2], 1.0);
00088 }
00089
00090
00091 float alpha = 1.0 - (_transparency / 65535.0);
00092 color[3] *= alpha;
00093
00094 return color;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103 RGBColorf FltGeometry::
00104 get_rgb() const {
00105 if (!has_color() || (_texwhite && has_texture())) {
00106
00107 return RGBColorf(1.0, 1.0, 1.0);
00108 }
00109
00110 if (has_material()) {
00111
00112 FltMaterial *material = get_material();
00113 return material->_diffuse;
00114 }
00115
00116 return _header->get_rgb(_color_index, (_flags & F_packed_color) != 0,
00117 _packed_color);
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 bool FltGeometry::
00127 has_alt_color() const {
00128 return (_flags & F_no_alt_color) == 0;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138 Colorf FltGeometry::
00139 get_alt_color() const {
00140 nassertr(has_alt_color(), Colorf(0.0, 0.0, 0.0, 0.0));
00141
00142 return _header->get_color(_alt_color_index, (_flags & F_packed_color) != 0,
00143 _alt_packed_color, _transparency);
00144 }
00145
00146
00147
00148
00149
00150
00151
00152
00153 RGBColorf FltGeometry::
00154 get_alt_rgb() const {
00155 nassertr(has_alt_color(), RGBColorf(0.0, 0.0, 0.0));
00156
00157 return _header->get_rgb(_alt_color_index, (_flags & F_packed_color) != 0,
00158 _alt_packed_color);
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 bool FltGeometry::
00170 extract_record(FltRecordReader &reader) {
00171 DatagramIterator &iterator = reader.get_iterator();
00172
00173 _ir_color = iterator.get_be_int32();
00174 _relative_priority = iterator.get_be_int16();
00175 _draw_type = (DrawType)iterator.get_int8();
00176 _texwhite = (iterator.get_int8() != 0);
00177 _color_name_index = iterator.get_be_int16();
00178 _alt_color_name_index = iterator.get_be_int16();
00179 iterator.skip_bytes(1);
00180 _billboard_type = (BillboardType)iterator.get_int8();
00181 _detail_texture_index = iterator.get_be_int16();
00182 _texture_index = iterator.get_be_int16();
00183 _material_index = iterator.get_be_int16();
00184 _dfad_material_code = iterator.get_be_int16();
00185 _dfad_feature_id = iterator.get_be_int16();
00186 _ir_material_code = iterator.get_be_int32();
00187 _transparency = iterator.get_be_uint16();
00188 _lod_generation_control = iterator.get_uint8();
00189 _line_style_index = iterator.get_uint8();
00190 if (_header->get_flt_version() >= 1420) {
00191 _flags = iterator.get_be_uint32();
00192 _light_mode = (LightMode)iterator.get_uint8();
00193 iterator.skip_bytes(1 + 4);
00194 iterator.skip_bytes(2);
00195
00196 if (!_packed_color.extract_record(reader)) {
00197 return false;
00198 }
00199 if (!_alt_packed_color.extract_record(reader)) {
00200 return false;
00201 }
00202
00203 if (_header->get_flt_version() >= 1520) {
00204 _texture_mapping_index = iterator.get_be_int16();
00205 iterator.skip_bytes(2);
00206 _color_index = iterator.get_be_int32();
00207 _alt_color_index = iterator.get_be_int32();
00208 iterator.skip_bytes(2 + 2);
00209 }
00210 }
00211
00212 return true;
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 bool FltGeometry::
00224 build_record(FltRecordWriter &writer) const {
00225 Datagram &datagram = writer.update_datagram();
00226
00227 datagram.add_be_int32(_ir_color);
00228 datagram.add_be_int16(_relative_priority);
00229 datagram.add_int8(_draw_type);
00230 datagram.add_int8(_texwhite);
00231 datagram.add_be_uint16(_color_name_index);
00232 datagram.add_be_uint16(_alt_color_name_index);
00233 datagram.pad_bytes(1);
00234 datagram.add_int8(_billboard_type);
00235 datagram.add_be_int16(_detail_texture_index);
00236 datagram.add_be_int16(_texture_index);
00237 datagram.add_be_int16(_material_index);
00238 datagram.add_be_int16(_dfad_material_code);
00239 datagram.add_be_int16(_dfad_feature_id);
00240 datagram.add_be_int32(_ir_material_code);
00241 datagram.add_be_uint16(_transparency);
00242 datagram.add_uint8(_lod_generation_control);
00243 datagram.add_uint8(_line_style_index);
00244 datagram.add_be_uint32(_flags);
00245 datagram.add_uint8(_light_mode);
00246 datagram.pad_bytes(1 + 4);
00247 datagram.pad_bytes(2);
00248
00249 if (!_packed_color.build_record(writer)) {
00250 return false;
00251 }
00252 if (!_alt_packed_color.build_record(writer)) {
00253 return false;
00254 }
00255
00256 if (_header->get_flt_version() >= 1520) {
00257
00258 datagram.add_be_int16(_texture_mapping_index);
00259 datagram.pad_bytes(2);
00260 datagram.add_be_int32(_color_index);
00261 datagram.add_be_int32(_alt_color_index);
00262 datagram.pad_bytes(2 + 2);
00263 }
00264
00265 return true;
00266 }