Panda3D
 All Classes Functions Variables Enumerations
lwoSurfaceBlockHeader.cxx
1 // Filename: lwoSurfaceBlockHeader.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 "lwoSurfaceBlockHeader.h"
16 #include "lwoInputFile.h"
17 #include "lwoSurfaceBlockChannel.h"
18 #include "lwoSurfaceBlockEnabled.h"
19 #include "lwoSurfaceBlockOpacity.h"
20 #include "lwoSurfaceBlockAxis.h"
21 
22 #include "dcast.h"
23 #include "indent.h"
24 
25 TypeHandle LwoSurfaceBlockHeader::_type_handle;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: LwoSurfaceBlockHeader::read_iff
29 // Access: Public, Virtual
30 // Description: Reads the data of the chunk in from the given input
31 // file, if possible. The ID and length of the chunk
32 // have already been read. stop_at is the byte position
33 // of the file to stop at (based on the current position
34 // at in->get_bytes_read()). Returns true on success,
35 // false otherwise.
36 ////////////////////////////////////////////////////////////////////
38 read_iff(IffInputFile *in, size_t stop_at) {
39  LwoInputFile *lin = DCAST(LwoInputFile, in);
40 
41  _ordinal = lin->get_string();
42  read_subchunks_iff(lin, stop_at);
43 
44  return true;
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: LwoSurfaceBlockHeader::write
49 // Access: Public, Virtual
50 // Description:
51 ////////////////////////////////////////////////////////////////////
52 void LwoSurfaceBlockHeader::
53 write(ostream &out, int indent_level) const {
54  indent(out, indent_level)
55  << get_id() << " {\n";
56  indent(out, indent_level + 2)
57  << "ordinal = 0x" << hex << setfill('0');
58 
59  string::const_iterator si;
60  for (si = _ordinal.begin(); si != _ordinal.end(); ++si) {
61  out << setw(2) << (int)(unsigned char)(*si);
62  }
63 
64  out << dec << setfill(' ') << "\n";
65 
66  write_chunks(out, indent_level + 2);
67  indent(out, indent_level)
68  << "}\n";
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: LwoSurfaceBlockHeader::make_new_chunk
73 // Access: Protected, Virtual
74 // Description: Allocates and returns a new chunk of the appropriate
75 // type based on the given ID, according to the context
76 // given by this chunk itself.
77 ////////////////////////////////////////////////////////////////////
80  if (id == IffId("CHAN")) {
81  return new LwoSurfaceBlockChannel;
82 
83  } else if (id == IffId("ENAB")) {
84  return new LwoSurfaceBlockEnabled;
85 
86  } else if (id == IffId("OPAC")) {
87  return new LwoSurfaceBlockOpacity;
88 
89  } else if (id == IffId("AXIS")) {
90  return new LwoSurfaceBlockAxis;
91 
92  } else {
93  return IffChunk::make_new_chunk(in, id);
94  }
95 }
96 
Indicates how transparent or opaque this particular layer is in relation to the layers beneath it...
Indicates which channel the texture in this LwoSurfaceBlock is applied to.
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...
string get_string()
Extracts a null-terminated string.
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:50
The basic kind of record in an EA &quot;IFF&quot; file, which the LightWave object file is based on...
Definition: iffChunk.h:32
virtual bool read_iff(IffInputFile *in, size_t stop_at)
Reads the data of the chunk in from the given input file, if possible.
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:33
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:31
Indicates the axis for this particular shader&#39;s projection.
Indicates whether this particular layer or shader should be rendered or not.
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 &quot;IFF&quot; file.
Definition: iffId.h:29