Panda3D
|
00001 // Filename: fltMesh.cxx 00002 // Created by: drose (28Feb01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // 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::Constructor 00026 // Access: Public 00027 // Description: 00028 //////////////////////////////////////////////////////////////////// 00029 FltMesh:: 00030 FltMesh(FltHeader *header) : FltGeometry(header) { 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: FltMesh::extract_record 00035 // Access: Protected, Virtual 00036 // Description: Fills in the information in this bead based on the 00037 // information given in the indicated datagram, whose 00038 // opcode has already been read. Returns true on 00039 // success, false if the datagram is invalid. 00040 //////////////////////////////////////////////////////////////////// 00041 bool FltMesh:: 00042 extract_record(FltRecordReader &reader) { 00043 if (!FltBeadID::extract_record(reader)) { 00044 return false; 00045 } 00046 00047 DatagramIterator &iterator = reader.get_iterator(); 00048 iterator.skip_bytes(4); // Undocumented padding. 00049 00050 if (!FltGeometry::extract_record(reader)) { 00051 return false; 00052 } 00053 00054 nassertr(reader.get_opcode() == FO_mesh, false); 00055 00056 check_remaining_size(iterator); 00057 return true; 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: FltMesh::extract_ancillary 00062 // Access: Protected, Virtual 00063 // Description: Checks whether the given bead, which follows this 00064 // bead sequentially in the file, is an ancillary record 00065 // of this bead. If it is, extracts the relevant 00066 // information and returns true; otherwise, leaves it 00067 // alone and returns false. 00068 //////////////////////////////////////////////////////////////////// 00069 bool FltMesh:: 00070 extract_ancillary(FltRecordReader &reader) { 00071 if (reader.get_opcode() == FO_local_vertex_pool) { 00072 _vpool = new FltLocalVertexPool(_header); 00073 return _vpool->extract_record(reader); 00074 } 00075 00076 return FltBeadID::extract_ancillary(reader); 00077 } 00078 00079 //////////////////////////////////////////////////////////////////// 00080 // Function: FltMesh::build_record 00081 // Access: Protected, Virtual 00082 // Description: Fills up the current record on the FltRecordWriter with 00083 // data for this record, but does not advance the 00084 // writer. Returns true on success, false if there is 00085 // some error. 00086 //////////////////////////////////////////////////////////////////// 00087 bool FltMesh:: 00088 build_record(FltRecordWriter &writer) const { 00089 if (!FltBeadID::build_record(writer)) { 00090 return false; 00091 } 00092 00093 Datagram &datagram = writer.update_datagram(); 00094 datagram.pad_bytes(4); // Undocumented padding. 00095 00096 if (!FltGeometry::build_record(writer)) { 00097 return false; 00098 } 00099 00100 writer.set_opcode(FO_mesh); 00101 00102 return true; 00103 } 00104 00105 //////////////////////////////////////////////////////////////////// 00106 // Function: FltMesh::write_ancillary 00107 // Access: Protected, Virtual 00108 // Description: Writes whatever ancillary records are required for 00109 // this record. Returns FE_ok on success, or something 00110 // else if there is some error. 00111 //////////////////////////////////////////////////////////////////// 00112 FltError FltMesh:: 00113 write_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 return FltBeadID::write_ancillary(writer); 00126 } 00127