Panda3D
 All Classes Functions Variables Enumerations
fltMesh.cxx
1 // Filename: fltMesh.cxx
2 // Created by: drose (28Feb01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "fltMesh.h"
16 #include "fltRecordReader.h"
17 #include "fltRecordWriter.h"
18 #include "fltHeader.h"
19 #include "fltMaterial.h"
20 #include "config_flt.h"
21 
22 TypeHandle FltMesh::_type_handle;
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: FltMesh::Constructor
26 // Access: Public
27 // Description:
28 ////////////////////////////////////////////////////////////////////
29 FltMesh::
30 FltMesh(FltHeader *header) : FltGeometry(header) {
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function: FltMesh::extract_record
35 // Access: Protected, Virtual
36 // Description: Fills in the information in this bead based on the
37 // information given in the indicated datagram, whose
38 // opcode has already been read. Returns true on
39 // success, false if the datagram is invalid.
40 ////////////////////////////////////////////////////////////////////
41 bool FltMesh::
42 extract_record(FltRecordReader &reader) {
43  if (!FltBeadID::extract_record(reader)) {
44  return false;
45  }
46 
47  DatagramIterator &iterator = reader.get_iterator();
48  iterator.skip_bytes(4); // Undocumented padding.
49 
50  if (!FltGeometry::extract_record(reader)) {
51  return false;
52  }
53 
54  nassertr(reader.get_opcode() == FO_mesh, false);
55 
56  check_remaining_size(iterator);
57  return true;
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: FltMesh::extract_ancillary
62 // Access: Protected, Virtual
63 // Description: Checks whether the given bead, which follows this
64 // bead sequentially in the file, is an ancillary record
65 // of this bead. If it is, extracts the relevant
66 // information and returns true; otherwise, leaves it
67 // alone and returns false.
68 ////////////////////////////////////////////////////////////////////
69 bool FltMesh::
70 extract_ancillary(FltRecordReader &reader) {
71  if (reader.get_opcode() == FO_local_vertex_pool) {
72  _vpool = new FltLocalVertexPool(_header);
73  return _vpool->extract_record(reader);
74  }
75 
76  return FltBeadID::extract_ancillary(reader);
77 }
78 
79 ////////////////////////////////////////////////////////////////////
80 // Function: FltMesh::build_record
81 // Access: Protected, Virtual
82 // Description: Fills up the current record on the FltRecordWriter with
83 // data for this record, but does not advance the
84 // writer. Returns true on success, false if there is
85 // some error.
86 ////////////////////////////////////////////////////////////////////
87 bool FltMesh::
88 build_record(FltRecordWriter &writer) const {
89  if (!FltBeadID::build_record(writer)) {
90  return false;
91  }
92 
93  Datagram &datagram = writer.update_datagram();
94  datagram.pad_bytes(4); // Undocumented padding.
95 
96  if (!FltGeometry::build_record(writer)) {
97  return false;
98  }
99 
100  writer.set_opcode(FO_mesh);
101 
102  return true;
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: FltMesh::write_ancillary
107 // Access: Protected, Virtual
108 // Description: Writes whatever ancillary records are required for
109 // this record. Returns FE_ok on success, or something
110 // else if there is some error.
111 ////////////////////////////////////////////////////////////////////
112 FltError FltMesh::
113 write_ancillary(FltRecordWriter &writer) const {
114  if (_vpool != (FltLocalVertexPool *)NULL) {
115  if (!_vpool->build_record(writer)) {
116  assert(!flt_error_abort);
117  return FE_bad_data;
118  }
119  FltError result = writer.advance();
120  if (result != FE_ok) {
121  return result;
122  }
123  }
124 
125  return FltBeadID::write_ancillary(writer);
126 }
127 
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly...
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
This is a base class for both FltFace and FltMesh, which are two different kinds of geometric primiti...
Definition: fltGeometry.h:36
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
Definition: datagram.cxx:111
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:48
A local vertex pool, as might appear in the middle of the hierarchy, for instance for a mesh...
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
FltError advance()
Writes the current record to the flt file, and resets the current record to receive new data...
void check_remaining_size(const DatagramIterator &di, const string &name=string()) const
Checks that the iterator has no bytes left, as it should at the end of a successfully read record...
Definition: fltRecord.cxx:313
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
void set_opcode(FltOpcode opcode)
Sets the opcode associated with the current record.
Datagram & update_datagram()
Returns a modifiable reference to the datagram associated with the current record.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43