00001 // Filename: fltMesh.cxx00002 // Created by: drose (28Feb01)00003 //00004 ////////////////////////////////////////////////////////////////////00005 //00006 // PANDA 3D SOFTWARE00007 // Copyright (c) Carnegie Mellon University. All rights reserved.00008 //00009 // All use of this software is subject to the terms of the revised BSD00010 // license. You should have received a copy of this license along00011 // with this source code in a file named "LICENSE."00012 //00013 ////////////////////////////////////////////////////////////////////00014
00015 #include "fltMesh.h"00016 #include "fltRecordReader.h"00017 #include "fltRecordWriter.h"00018 #include "fltHeader.h"00019 #include "fltMaterial.h"00020 #include "config_flt.h"00021
00022 TypeHandle FltMesh::_type_handle;
00023
00024 ////////////////////////////////////////////////////////////////////00025 // Function: FltMesh::Constructor00026 // Access: Public00027 // Description:00028 ////////////////////////////////////////////////////////////////////00029 FltMesh::
00030 FltMesh(FltHeader *header) : FltGeometry(header) {
00031 }
00032
00033 ////////////////////////////////////////////////////////////////////00034 // Function: FltMesh::extract_record00035 // Access: Protected, Virtual00036 // Description: Fills in the information in this bead based on the00037 // information given in the indicated datagram, whose00038 // opcode has already been read. Returns true on00039 // success, false if the datagram is invalid.00040 ////////////////////////////////////////////////////////////////////00041 boolFltMesh::00042extract_record(FltRecordReader &reader) {
00043 if (!FltBeadID::extract_record(reader)) {
00044 returnfalse;
00045 }
00046
00047 DatagramIterator &iterator = reader.get_iterator();
00048 iterator.skip_bytes(4); // Undocumented padding.00049
00050 if (!FltGeometry::extract_record(reader)) {
00051 returnfalse;
00052 }
00053
00054 nassertr(reader.get_opcode() == FO_mesh, false);
00055
00056 check_remaining_size(iterator);
00057 returntrue;
00058 }
00059
00060 ////////////////////////////////////////////////////////////////////00061 // Function: FltMesh::extract_ancillary00062 // Access: Protected, Virtual00063 // Description: Checks whether the given bead, which follows this00064 // bead sequentially in the file, is an ancillary record00065 // of this bead. If it is, extracts the relevant00066 // information and returns true; otherwise, leaves it00067 // alone and returns false.00068 ////////////////////////////////////////////////////////////////////00069 boolFltMesh::00070extract_ancillary(FltRecordReader &reader) {
00071 if (reader.get_opcode() == FO_local_vertex_pool) {
00072 _vpool = newFltLocalVertexPool(_header);
00073 return _vpool->extract_record(reader);
00074 }
00075
00076 returnFltBeadID::extract_ancillary(reader);
00077 }
00078
00079 ////////////////////////////////////////////////////////////////////00080 // Function: FltMesh::build_record00081 // Access: Protected, Virtual00082 // Description: Fills up the current record on the FltRecordWriter with00083 // data for this record, but does not advance the00084 // writer. Returns true on success, false if there is00085 // some error.00086 ////////////////////////////////////////////////////////////////////00087 boolFltMesh::00088build_record(FltRecordWriter &writer) const {
00089 if (!FltBeadID::build_record(writer)) {
00090 returnfalse;
00091 }
00092
00093 Datagram &datagram = writer.update_datagram();
00094 datagram.pad_bytes(4); // Undocumented padding.00095
00096 if (!FltGeometry::build_record(writer)) {
00097 returnfalse;
00098 }
00099
00100 writer.set_opcode(FO_mesh);
00101
00102 returntrue;
00103 }
00104
00105 ////////////////////////////////////////////////////////////////////00106 // Function: FltMesh::write_ancillary00107 // Access: Protected, Virtual00108 // Description: Writes whatever ancillary records are required for00109 // this record. Returns FE_ok on success, or something00110 // else if there is some error.00111 ////////////////////////////////////////////////////////////////////00112 FltError FltMesh::00113write_ancillary(FltRecordWriter &writer) const {
00114 if (_vpool != (FltLocalVertexPool *)NULL) {
00115 if (!_vpool->build_record(writer)) {
00116 assert(!flt_error_abort);
00117 return FE_bad_data;
00118 }
00119 FltError result = writer.advance();
00120 if (result != FE_ok) {
00121 return result;
00122 }
00123 }
00124
00125 returnFltBeadID::write_ancillary(writer);
00126 }
00127