Panda3D
lwoLayer.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 lwoLayer.cxx
10  * @author drose
11  * @date 2001-04-24
12  */
13 
14 #include "lwoLayer.h"
15 #include "lwoInputFile.h"
16 
17 #include "dcast.h"
18 #include "indent.h"
19 
20 TypeHandle LwoLayer::_type_handle;
21 
22 /**
23  * Resets the layer's parameters to initial defaults for a generic layer
24  * created implicitly.
25  */
26 void LwoLayer::
28  _number = -1;
29  _flags = 0;
30  _pivot.set(0.0, 0.0, 0.0);
31  _name = "Generic";
32  _parent = -1;
33 }
34 
35 /**
36  * Reads the data of the chunk in from the given input file, if possible. The
37  * ID and length of the chunk have already been read. stop_at is the byte
38  * position of the file to stop at (based on the current position at
39  * in->get_bytes_read()). Returns true on success, false otherwise.
40  */
41 bool LwoLayer::
42 read_iff(IffInputFile *in, size_t stop_at) {
43  LwoInputFile *lin = DCAST(LwoInputFile, in);
44 
45  _number = lin->get_be_uint16();
46  _flags = lin->get_be_uint16();
47  _pivot = lin->get_vec3();
48  _name = lin->get_string();
49 
50  if (lin->get_bytes_read() >= stop_at) {
51  _parent = -1;
52  } else {
53  _parent = lin->get_be_uint16();
54  if (_parent == 0xffff) {
55  _parent = -1;
56  }
57  }
58 
59  return true;
60 }
61 
62 /**
63  *
64  */
65 void LwoLayer::
66 write(std::ostream &out, int indent_level) const {
67  indent(out, indent_level)
68  << get_id() << " { number = " << _number << ", flags = 0x"
69  << std::hex << _flags << std::dec << ", pivot = " << _pivot
70  << ", _name = \"" << _name << "\", _parent = " << _parent << " }\n";
71 }
uint16_t get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
LVecBase3 get_vec3()
Reads a three-component vector of floats.
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
Definition: iffInputFile.I:44
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_string()
Extracts a null-terminated string.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:30
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: lwoLayer.cxx:42
A specialization of IffInputFile to handle reading a Lightwave Object file.
Definition: lwoInputFile.h:26
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
void make_generic()
Resets the layer's parameters to initial defaults for a generic layer created implicitly.
Definition: lwoLayer.cxx:27
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:25
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.