Panda3D
lwoSurfaceBlock.cxx
1 // Filename: lwoSurfaceBlock.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 "lwoSurfaceBlock.h"
16 #include "iffInputFile.h"
17 #include "lwoSurfaceBlockAxis.h"
18 #include "lwoSurfaceBlockImage.h"
19 #include "lwoSurfaceBlockHeader.h"
20 #include "lwoSurfaceBlockProjection.h"
21 #include "lwoSurfaceBlockRepeat.h"
22 #include "lwoSurfaceBlockTMap.h"
23 #include "lwoSurfaceBlockWrap.h"
24 #include "lwoSurfaceBlockVMapName.h"
25 
26 #include "dcast.h"
27 #include "indent.h"
28 
29 TypeHandle LwoSurfaceBlock::_type_handle;
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: LwoSurfaceBlock::read_iff
33 // Access: Public, Virtual
34 // Description: Reads the data of the chunk in from the given input
35 // file, if possible. The ID and length of the chunk
36 // have already been read. stop_at is the byte position
37 // of the file to stop at (based on the current position
38 // at in->get_bytes_read()). Returns true on success,
39 // false otherwise.
40 ////////////////////////////////////////////////////////////////////
42 read_iff(IffInputFile *in, size_t stop_at) {
43  PT(IffChunk) chunk = in->get_subchunk(this);
44  if (chunk == (IffChunk *)NULL) {
45  return false;
46  }
47  if (!chunk->is_of_type(LwoSurfaceBlockHeader::get_class_type())) {
48  nout << "Invalid chunk for header of surface block: " << *chunk << "\n";
49  return false;
50  }
51 
52  _header = DCAST(LwoSurfaceBlockHeader, chunk);
53 
54  read_subchunks_iff(in, stop_at);
55  return true;
56 }
57 
58 ////////////////////////////////////////////////////////////////////
59 // Function: LwoSurfaceBlock::write
60 // Access: Public, Virtual
61 // Description:
62 ////////////////////////////////////////////////////////////////////
63 void LwoSurfaceBlock::
64 write(ostream &out, int indent_level) const {
65  indent(out, indent_level)
66  << get_id() << " {\n";
67  _header->write(out, indent_level + 2);
68  out << "\n";
69  write_chunks(out, indent_level + 2);
70  indent(out, indent_level)
71  << "}\n";
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: LwoSurfaceBlock::make_new_chunk
76 // Access: Protected, Virtual
77 // Description: Allocates and returns a new chunk of the appropriate
78 // type based on the given ID, according to the context
79 // given by this chunk itself.
80 ////////////////////////////////////////////////////////////////////
83  if (id == IffId("IMAP") ||
84  id == IffId("PROC") ||
85  id == IffId("GRAD") ||
86  id == IffId("SHDR")) {
87  return new LwoSurfaceBlockHeader;
88 
89  } else if (id == IffId("TMAP")) {
90  return new LwoSurfaceBlockTMap;
91 
92  } else if (id == IffId("PROJ")) {
93  return new LwoSurfaceBlockProjection;
94 
95  } else if (id == IffId("AXIS")) {
96  return new LwoSurfaceBlockAxis;
97 
98  } else if (id == IffId("IMAG")) {
99  return new LwoSurfaceBlockImage;
100 
101  } else if (id == IffId("WRAP")) {
102  return new LwoSurfaceBlockWrap;
103 
104  } else if (id == IffId("WRPH") ||
105  id == IffId("WRPW")) {
106  return new LwoSurfaceBlockRepeat;
107 
108  } else if (id == IffId("VMAP")) {
109  return new LwoSurfaceBlockVMapName;
110 
111  } else {
112  return IffChunk::make_new_chunk(in, id);
113  }
114 }
115 
virtual bool read_iff(IffInputFile *in, size_t stop_at)
Reads the data of the chunk in from the given input file, if possible.
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
For cylindrical and spherical projections, this parameter controls how many times the image repeats o...
The tMap chunk within a LwoSurfaceBlock chunk.
Specifies how the texture image appears for areas outside the image.
Specifies the name of a set of UV&#39;s defined on the polygons that use this model.
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on...
Definition: iffChunk.h:32
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:33
Indicates the projection mode for this particular shader.
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...
Indicates the axis for this particular shader&#39;s projection.
The header chunk within a LwoSurfaceBlock chunk.
Specifies the particular image that is being applied as a texture.
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