Panda3D
fltMesh.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file fltMesh.cxx
10  * @author drose
11  * @date 2001-02-28
12  */
13 
14 #include "fltMesh.h"
15 #include "fltRecordReader.h"
16 #include "fltRecordWriter.h"
17 #include "fltHeader.h"
18 #include "fltMaterial.h"
19 #include "config_flt.h"
20 
21 TypeHandle FltMesh::_type_handle;
22 
23 /**
24  *
25  */
26 FltMesh::
27 FltMesh(FltHeader *header) : FltGeometry(header) {
28 }
29 
30 /**
31  * Fills in the information in this bead based on the information given in the
32  * indicated datagram, whose opcode has already been read. Returns true on
33  * success, false if the datagram is invalid.
34  */
35 bool FltMesh::
36 extract_record(FltRecordReader &reader) {
37  if (!FltBeadID::extract_record(reader)) {
38  return false;
39  }
40 
41  DatagramIterator &iterator = reader.get_iterator();
42  iterator.skip_bytes(4); // Undocumented padding.
43 
44  if (!FltGeometry::extract_record(reader)) {
45  return false;
46  }
47 
48  nassertr(reader.get_opcode() == FO_mesh, false);
49 
50  check_remaining_size(iterator);
51  return true;
52 }
53 
54 /**
55  * Checks whether the given bead, which follows this bead sequentially in the
56  * file, is an ancillary record of this bead. If it is, extracts the relevant
57  * information and returns true; otherwise, leaves it alone and returns false.
58  */
59 bool FltMesh::
60 extract_ancillary(FltRecordReader &reader) {
61  if (reader.get_opcode() == FO_local_vertex_pool) {
62  _vpool = new FltLocalVertexPool(_header);
63  return _vpool->extract_record(reader);
64  }
65 
66  return FltBeadID::extract_ancillary(reader);
67 }
68 
69 /**
70  * Fills up the current record on the FltRecordWriter with data for this
71  * record, but does not advance the writer. Returns true on success, false if
72  * there is some error.
73  */
74 bool FltMesh::
75 build_record(FltRecordWriter &writer) const {
76  if (!FltBeadID::build_record(writer)) {
77  return false;
78  }
79 
80  Datagram &datagram = writer.update_datagram();
81  datagram.pad_bytes(4); // Undocumented padding.
82 
83  if (!FltGeometry::build_record(writer)) {
84  return false;
85  }
86 
87  writer.set_opcode(FO_mesh);
88 
89  return true;
90 }
91 
92 /**
93  * Writes whatever ancillary records are required for this record. Returns
94  * FE_ok on success, or something else if there is some error.
95  */
96 FltError FltMesh::
97 write_ancillary(FltRecordWriter &writer) const {
98  if (_vpool != nullptr) {
99  if (!_vpool->build_record(writer)) {
100  assert(!flt_error_abort);
101  return FE_bad_data;
102  }
103  FltError result = writer.advance();
104  if (result != FE_ok) {
105  return result;
106  }
107  }
108 
109  return FltBeadID::write_ancillary(writer);
110 }
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void check_remaining_size(const DatagramIterator &di, const std::string &name=std::string()) const
Checks that the iterator has no bytes left, as it should at the end of a successfully read record.
Definition: fltRecord.cxx:254
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:33
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
Definition: datagram.cxx:99
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:44
A local vertex pool, as might appear in the middle of the hierarchy, for instance for a mesh.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
FltError advance()
Writes the current record to the flt file, and resets the current record to receive new data.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
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:38