Panda3D
lwoSurfaceBlock.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 lwoSurfaceBlock.cxx
10  * @author drose
11  * @date 2001-04-24
12  */
13 
14 #include "lwoSurfaceBlock.h"
15 #include "iffInputFile.h"
16 #include "lwoSurfaceBlockAxis.h"
17 #include "lwoSurfaceBlockImage.h"
18 #include "lwoSurfaceBlockHeader.h"
20 #include "lwoSurfaceBlockRepeat.h"
21 #include "lwoSurfaceBlockTMap.h"
22 #include "lwoSurfaceBlockWrap.h"
24 
25 #include "dcast.h"
26 #include "indent.h"
27 
28 TypeHandle LwoSurfaceBlock::_type_handle;
29 
30 /**
31  * Reads the data of the chunk in from the given input file, if possible. The
32  * ID and length of the chunk have already been read. stop_at is the byte
33  * position of the file to stop at (based on the current position at
34  * in->get_bytes_read()). Returns true on success, false otherwise.
35  */
37 read_iff(IffInputFile *in, size_t stop_at) {
38  PT(IffChunk) chunk = in->get_subchunk(this);
39  if (chunk == nullptr) {
40  return false;
41  }
42  if (!chunk->is_of_type(LwoSurfaceBlockHeader::get_class_type())) {
43  nout << "Invalid chunk for header of surface block: " << *chunk << "\n";
44  return false;
45  }
46 
47  _header = DCAST(LwoSurfaceBlockHeader, chunk);
48 
49  read_subchunks_iff(in, stop_at);
50  return true;
51 }
52 
53 /**
54  *
55  */
56 void LwoSurfaceBlock::
57 write(std::ostream &out, int indent_level) const {
58  indent(out, indent_level)
59  << get_id() << " {\n";
60  _header->write(out, indent_level + 2);
61  out << "\n";
62  write_chunks(out, indent_level + 2);
63  indent(out, indent_level)
64  << "}\n";
65 }
66 
67 /**
68  * Allocates and returns a new chunk of the appropriate type based on the
69  * given ID, according to the context given by this chunk itself.
70  */
73  if (id == IffId("IMAP") ||
74  id == IffId("PROC") ||
75  id == IffId("GRAD") ||
76  id == IffId("SHDR")) {
77  return new LwoSurfaceBlockHeader;
78 
79  } else if (id == IffId("TMAP")) {
80  return new LwoSurfaceBlockTMap;
81 
82  } else if (id == IffId("PROJ")) {
83  return new LwoSurfaceBlockProjection;
84 
85  } else if (id == IffId("AXIS")) {
86  return new LwoSurfaceBlockAxis;
87 
88  } else if (id == IffId("IMAG")) {
89  return new LwoSurfaceBlockImage;
90 
91  } else if (id == IffId("WRAP")) {
92  return new LwoSurfaceBlockWrap;
93 
94  } else if (id == IffId("WRPH") ||
95  id == IffId("WRPW")) {
96  return new LwoSurfaceBlockRepeat;
97 
98  } else if (id == IffId("VMAP")) {
99  return new LwoSurfaceBlockVMapName;
100 
101  } else {
102  return IffChunk::make_new_chunk(in, id);
103  }
104 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
For cylindrical and spherical projections, this parameter controls how many times the image repeats o...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The tMap chunk within a LwoSurfaceBlock chunk.
Specifies how the texture image appears for areas outside the image.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Specifies the name of a set of UV'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:30
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
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's projection.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The header chunk within a LwoSurfaceBlock chunk.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Specifies the particular image that is being applied as a texture.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
A four-byte chunk ID appearing in an "IFF" file.
Definition: iffId.h:26
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:25
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.