Panda3D
lwoSurfaceBlockHeader.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 lwoSurfaceBlockHeader.cxx
10  * @author drose
11  * @date 2001-04-24
12  */
13 
14 #include "lwoSurfaceBlockHeader.h"
15 #include "lwoInputFile.h"
16 #include "lwoSurfaceBlockChannel.h"
17 #include "lwoSurfaceBlockEnabled.h"
18 #include "lwoSurfaceBlockOpacity.h"
19 #include "lwoSurfaceBlockAxis.h"
20 
21 #include "dcast.h"
22 #include "indent.h"
23 
24 TypeHandle LwoSurfaceBlockHeader::_type_handle;
25 
26 /**
27  * Reads the data of the chunk in from the given input file, if possible. The
28  * ID and length of the chunk have already been read. stop_at is the byte
29  * position of the file to stop at (based on the current position at
30  * in->get_bytes_read()). Returns true on success, false otherwise.
31  */
33 read_iff(IffInputFile *in, size_t stop_at) {
34  LwoInputFile *lin = DCAST(LwoInputFile, in);
35 
36  _ordinal = lin->get_string();
37  read_subchunks_iff(lin, stop_at);
38 
39  return true;
40 }
41 
42 /**
43  *
44  */
45 void LwoSurfaceBlockHeader::
46 write(std::ostream &out, int indent_level) const {
47  indent(out, indent_level)
48  << get_id() << " {\n";
49  indent(out, indent_level + 2)
50  << "ordinal = 0x" << std::hex << std::setfill('0');
51 
52  std::string::const_iterator si;
53  for (si = _ordinal.begin(); si != _ordinal.end(); ++si) {
54  out << std::setw(2) << (int)(unsigned char)(*si);
55  }
56 
57  out << std::dec << std::setfill(' ') << "\n";
58 
59  write_chunks(out, indent_level + 2);
60  indent(out, indent_level)
61  << "}\n";
62 }
63 
64 /**
65  * Allocates and returns a new chunk of the appropriate type based on the
66  * given ID, according to the context given by this chunk itself.
67  */
70  if (id == IffId("CHAN")) {
71  return new LwoSurfaceBlockChannel;
72 
73  } else if (id == IffId("ENAB")) {
74  return new LwoSurfaceBlockEnabled;
75 
76  } else if (id == IffId("OPAC")) {
77  return new LwoSurfaceBlockOpacity;
78 
79  } else if (id == IffId("AXIS")) {
80  return new LwoSurfaceBlockAxis;
81 
82  } else {
83  return IffChunk::make_new_chunk(in, id);
84  }
85 }
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
LwoSurfaceBlockHeader::make_new_chunk
virtual IffChunk * make_new_chunk(IffInputFile *in, IffId id)
Allocates and returns a new chunk of the appropriate type based on the given ID, according to the con...
Definition: lwoSurfaceBlockHeader.cxx:69
LwoSurfaceBlockOpacity
Indicates how transparent or opaque this particular layer is in relation to the layers beneath it.
Definition: lwoSurfaceBlockOpacity.h:25
lwoSurfaceBlockOpacity.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoInputFile.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LwoInputFile
A specialization of IffInputFile to handle reading a Lightwave Object file.
Definition: lwoInputFile.h:26
lwoSurfaceBlockChannel.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
dcast.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoSurfaceBlockAxis.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
IffChunk::get_id
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:25
IffId
A four-byte chunk ID appearing in an "IFF" file.
Definition: iffId.h:26
IffChunk::make_new_chunk
virtual IffChunk * make_new_chunk(IffInputFile *in, IffId id)
Allocates and returns a new chunk of the appropriate type based on the given ID, according to the con...
Definition: iffChunk.cxx:42
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
LwoSurfaceBlockHeader::read_iff
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: lwoSurfaceBlockHeader.cxx:33
lwoSurfaceBlockHeader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LwoSurfaceBlockEnabled
Indicates whether this particular layer or shader should be rendered or not.
Definition: lwoSurfaceBlockEnabled.h:25
IffInputFile
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:30
LwoSurfaceBlockAxis
Indicates the axis for this particular shader's projection.
Definition: lwoSurfaceBlockAxis.h:26
indent.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoSurfaceBlockEnabled.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
IffChunk
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on.
Definition: iffChunk.h:30
LwoSurfaceBlockChannel
Indicates which channel the texture in this LwoSurfaceBlock is applied to.
Definition: lwoSurfaceBlockChannel.h:25
IffInputFile::get_string
std::string get_string()
Extracts a null-terminated string.
Definition: iffInputFile.cxx:178