00001 // Filename: fltMesh.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 "fltMesh.h" 00020 #include "fltRecordReader.h" 00021 #include "fltRecordWriter.h" 00022 #include "fltHeader.h" 00023 #include "fltMaterial.h" 00024 #include "config_flt.h" 00025 00026 TypeHandle FltMesh::_type_handle; 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: FltMesh::Constructor 00030 // Access: Public 00031 // Description: 00032 //////////////////////////////////////////////////////////////////// 00033 FltMesh:: 00034 FltMesh(FltHeader *header) : FltGeometry(header) { 00035 } 00036 00037 //////////////////////////////////////////////////////////////////// 00038 // Function: FltMesh::extract_record 00039 // Access: Protected, Virtual 00040 // Description: Fills in the information in this bead based on the 00041 // information given in the indicated datagram, whose 00042 // opcode has already been read. Returns true on 00043 // success, false if the datagram is invalid. 00044 //////////////////////////////////////////////////////////////////// 00045 bool FltMesh:: 00046 extract_record(FltRecordReader &reader) { 00047 if (!FltBeadID::extract_record(reader)) { 00048 return false; 00049 } 00050 00051 DatagramIterator &iterator = reader.get_iterator(); 00052 iterator.skip_bytes(4); // Undocumented padding. 00053 00054 if (!FltGeometry::extract_record(reader)) { 00055 return false; 00056 } 00057 00058 nassertr(reader.get_opcode() == FO_mesh, false); 00059 00060 check_remaining_size(iterator); 00061 return true; 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: FltMesh::extract_ancillary 00066 // Access: Protected, Virtual 00067 // Description: Checks whether the given bead, which follows this 00068 // bead sequentially in the file, is an ancillary record 00069 // of this bead. If it is, extracts the relevant 00070 // information and returns true; otherwise, leaves it 00071 // alone and returns false. 00072 //////////////////////////////////////////////////////////////////// 00073 bool FltMesh:: 00074 extract_ancillary(FltRecordReader &reader) { 00075 if (reader.get_opcode() == FO_local_vertex_pool) { 00076 _vpool = new FltLocalVertexPool(_header); 00077 return _vpool->extract_record(reader); 00078 } 00079 00080 return FltBeadID::extract_ancillary(reader); 00081 } 00082 00083 //////////////////////////////////////////////////////////////////// 00084 // Function: FltMesh::build_record 00085 // Access: Protected, Virtual 00086 // Description: Fills up the current record on the FltRecordWriter with 00087 // data for this record, but does not advance the 00088 // writer. Returns true on success, false if there is 00089 // some error. 00090 //////////////////////////////////////////////////////////////////// 00091 bool FltMesh:: 00092 build_record(FltRecordWriter &writer) const { 00093 if (!FltBeadID::build_record(writer)) { 00094 return false; 00095 } 00096 00097 Datagram &datagram = writer.update_datagram(); 00098 datagram.pad_bytes(4); // Undocumented padding. 00099 00100 if (!FltGeometry::build_record(writer)) { 00101 return false; 00102 } 00103 00104 writer.set_opcode(FO_mesh); 00105 00106 return true; 00107 } 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function: FltMesh::write_ancillary 00111 // Access: Protected, Virtual 00112 // Description: Writes whatever ancillary records are required for 00113 // this record. Returns FE_ok on success, or something 00114 // else if there is some error. 00115 //////////////////////////////////////////////////////////////////// 00116 FltError FltMesh:: 00117 write_ancillary(FltRecordWriter &writer) const { 00118 if (_vpool != (FltLocalVertexPool *)NULL) { 00119 if (!_vpool->build_record(writer)) { 00120 assert(!flt_error_abort); 00121 return FE_bad_data; 00122 } 00123 FltError result = writer.advance(); 00124 if (result != FE_ok) { 00125 return result; 00126 } 00127 } 00128 00129 return FltBeadID::write_ancillary(writer); 00130 } 00131