Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/flt/fltGeometry.cxx

Go to the documentation of this file.
00001 // Filename: fltGeometry.cxx
00002 // Created by:  drose (28Feb01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
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 //     Function: FltGeometry::Constructor
00029 //       Access: Public
00030 //  Description:
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 //     Function: FltGeometry::get_color
00060 //       Access: Public
00061 //  Description: Returns the primary color of the face, as a
00062 //               four-component value (including alpha as the
00063 //               transparency channel).
00064 //
00065 //               If has_color() is false, the result is white, but
00066 //               still reflects the transparency correctly.
00067 ////////////////////////////////////////////////////////////////////
00068 Colorf FltGeometry::
00069 get_color() const {
00070   Colorf color;
00071 
00072   if (!has_color() || (_texwhite && has_texture())) {
00073     // Force this one white.
00074     color.set(1.0, 1.0, 1.0, 1.0);
00075 
00076   } else if (has_material()) {
00077     // If we have a material, that replaces the color.
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   // Modify the whole thing by our transparency.
00091   float alpha = 1.0 - (_transparency / 65535.0);
00092   color[3] *= alpha;
00093 
00094   return color;
00095 }
00096 
00097 ////////////////////////////////////////////////////////////////////
00098 //     Function: FltGeometry::get_rgb
00099 //       Access: Public
00100 //  Description: Returns the primary color of the face, as a
00101 //               three-component value ignoring transparency.
00102 ////////////////////////////////////////////////////////////////////
00103 RGBColorf FltGeometry::
00104 get_rgb() const {
00105   if (!has_color() || (_texwhite && has_texture())) {
00106     // Force this one white.
00107     return RGBColorf(1.0, 1.0, 1.0);
00108   }
00109 
00110   if (has_material()) {
00111     // If we have a material, that replaces the color.
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 //     Function: FltGeometry::has_alt_color
00122 //       Access: Public
00123 //  Description: Returns true if the face has an alternate color
00124 //               indicated, false otherwise.
00125 ////////////////////////////////////////////////////////////////////
00126 bool FltGeometry::
00127 has_alt_color() const {
00128   return (_flags & F_no_alt_color) == 0;
00129 }
00130 
00131 ////////////////////////////////////////////////////////////////////
00132 //     Function: FltGeometry::get_alt_color
00133 //       Access: Public
00134 //  Description: If has_alt_color() indicates true, returns the alternate
00135 //               color of the face, as a four-component value
00136 //               (including alpha as the transparency channel).
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 //     Function: FltGeometry::get_alt_rgb
00148 //       Access: Public
00149 //  Description: If has_alt_color() indicates true, returns the alternate
00150 //               color of the face, as a three-component value
00151 //               ignoring transparency.
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 //     Function: FltGeometry::extract_record
00163 //       Access: Protected, Virtual
00164 //  Description: Fills in the information in this bead based on the
00165 //               information given in the indicated datagram, whose
00166 //               opcode has already been read.  Returns true on
00167 //               success, false if the datagram is invalid.
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); // Undocumented padding.
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 //     Function: FltGeometry::build_record
00217 //       Access: Protected, Virtual
00218 //  Description: Fills up the current record on the FltRecordWriter with
00219 //               data for this record, but does not advance the
00220 //               writer.  Returns true on success, false if there is
00221 //               some error.
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); // Undocumented padding.
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     // New with 15.2
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 }

Generated on Fri May 2 03:19:10 2003 for Panda-Tool by doxygen1.3