Panda3D
lwoHeader.cxx
1 // Filename: lwoHeader.cxx
2 // Created by: drose (24Apr01)
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 "lwoHeader.h"
16 #include "lwoInputFile.h"
17 
18 #include "dcast.h"
19 #include "indent.h"
20 
21 TypeHandle LwoHeader::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: LwoHeader::Constructor
25 // Access: Public
26 // Description:
27 ////////////////////////////////////////////////////////////////////
28 LwoHeader::
29 LwoHeader() {
30  _valid = false;
31  _version = 0.0;
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: LwoHeader::read_iff
36 // Access: Public, Virtual
37 // Description: Reads the data of the chunk in from the given input
38 // file, if possible. The ID and length of the chunk
39 // have already been read. stop_at is the byte position
40 // of the file to stop at (based on the current position
41 // at in->get_bytes_read()). Returns true on success,
42 // false otherwise.
43 ////////////////////////////////////////////////////////////////////
44 bool LwoHeader::
45 read_iff(IffInputFile *in, size_t stop_at) {
46  LwoInputFile *lin = DCAST(LwoInputFile, in);
47 
48  _lwid = lin->get_id();
49 
50  if (_lwid == IffId("LWO2")) {
51  _valid = true;
52  _version = 6.0;
53  } else if (_lwid == IffId("LWOB")) {
54  _valid = true;
55  _version = 5.0;
56  }
57 
58  if (_valid) {
59  lin->set_lwo_version(_version);
60  }
61 
62  read_chunks_iff(lin, stop_at);
63 
64  return true;
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: LwoHeader::write
69 // Access: Public, Virtual
70 // Description:
71 ////////////////////////////////////////////////////////////////////
72 void LwoHeader::
73 write(ostream &out, int indent_level) const {
74  indent(out, indent_level)
75  << get_id() << " {\n";
76  indent(out, indent_level + 2)
77  << "id = " << _lwid << "\n";
78  write_chunks(out, indent_level + 2);
79  indent(out, indent_level)
80  << "}\n";
81 }
void set_lwo_version(double version)
Changes the version number reported for the Lightwave file.
Definition: lwoInputFile.I:37
virtual bool read_iff(IffInputFile *in, size_t stop_at)
Reads the data of the chunk in from the given input file, if possible.
Definition: lwoHeader.cxx:45
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:33
A specialization of IffInputFile to handle reading a Lightwave Object file.
Definition: lwoInputFile.h:29
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A four-byte chunk ID appearing in an "IFF" file.
Definition: iffId.h:29
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:31
IffId get_id()
Extracts a 4-character IFF ID.