Panda3D
lwoLayer.cxx
1 // Filename: lwoLayer.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 "lwoLayer.h"
16 #include "lwoInputFile.h"
17 
18 #include "dcast.h"
19 #include "indent.h"
20 
21 TypeHandle LwoLayer::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: LwoLayer::make_generic
25 // Access: Public
26 // Description: Resets the layer's parameters to initial defaults for
27 // a generic layer created implicitly.
28 ////////////////////////////////////////////////////////////////////
29 void LwoLayer::
31  _number = -1;
32  _flags = 0;
33  _pivot.set(0.0, 0.0, 0.0);
34  _name = "Generic";
35  _parent = -1;
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: LwoLayer::read_iff
40 // Access: Public, Virtual
41 // Description: Reads the data of the chunk in from the given input
42 // file, if possible. The ID and length of the chunk
43 // have already been read. stop_at is the byte position
44 // of the file to stop at (based on the current position
45 // at in->get_bytes_read()). Returns true on success,
46 // false otherwise.
47 ////////////////////////////////////////////////////////////////////
48 bool LwoLayer::
49 read_iff(IffInputFile *in, size_t stop_at) {
50  LwoInputFile *lin = DCAST(LwoInputFile, in);
51 
52  _number = lin->get_be_uint16();
53  _flags = lin->get_be_uint16();
54  _pivot = lin->get_vec3();
55  _name = lin->get_string();
56 
57  if (lin->get_bytes_read() >= stop_at) {
58  _parent = -1;
59  } else {
60  _parent = lin->get_be_uint16();
61  if (_parent == 0xffff) {
62  _parent = -1;
63  }
64  }
65 
66  return true;
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: LwoLayer::write
71 // Access: Public, Virtual
72 // Description:
73 ////////////////////////////////////////////////////////////////////
74 void LwoLayer::
75 write(ostream &out, int indent_level) const {
76  indent(out, indent_level)
77  << get_id() << " { number = " << _number << ", flags = 0x"
78  << hex << _flags << dec << ", pivot = " << _pivot
79  << ", _name = \"" << _name << "\", _parent = " << _parent << " }\n";
80 }
LVecBase3 get_vec3()
Reads a three-component vector of floats.
string get_string()
Extracts a null-terminated string.
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
Definition: iffInputFile.I:56
PN_uint16 get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:33
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:49
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
void make_generic()
Resets the layer&#39;s parameters to initial defaults for a generic layer created implicitly.
Definition: lwoLayer.cxx:30
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:31