Panda3D
lwoSurface.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 lwoSurface.cxx
10  * @author drose
11  * @date 2001-04-24
12  */
13 
14 #include "lwoSurface.h"
15 #include "iffInputFile.h"
16 #include "lwoSurfaceBlock.h"
17 #include "lwoSurfaceColor.h"
18 #include "lwoSurfaceParameter.h"
19 #include "lwoSurfaceSidedness.h"
21 
22 #include "indent.h"
23 
24 TypeHandle LwoSurface::_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  */
32 bool LwoSurface::
33 read_iff(IffInputFile *in, size_t stop_at) {
34  _name = in->get_string();
35  _source = in->get_string();
36  read_subchunks_iff(in, stop_at);
37  return true;
38 }
39 
40 /**
41  *
42  */
43 void LwoSurface::
44 write(std::ostream &out, int indent_level) const {
45  indent(out, indent_level)
46  << get_id() << " {\n";
47  indent(out, indent_level + 2)
48  << "name = \"" << _name << "\", source = \"" << _source << "\"\n";
49  write_chunks(out, indent_level + 2);
50  indent(out, indent_level)
51  << "}\n";
52 }
53 
54 /**
55  * Allocates and returns a new chunk of the appropriate type based on the
56  * given ID, according to the context given by this chunk itself.
57  */
60  if (id == IffId("COLR")) {
61  return new LwoSurfaceColor;
62 
63  } else if (id == IffId("DIFF") ||
64  id == IffId("LUMI") ||
65  id == IffId("SPEC") ||
66  id == IffId("REFL") ||
67  id == IffId("TRAN") ||
68  id == IffId("TRNL") ||
69  id == IffId("GLOS") ||
70  id == IffId("SHRP") ||
71  id == IffId("BUMP") ||
72  id == IffId("RSAN") ||
73  id == IffId("RIND")) {
74  return new LwoSurfaceParameter;
75 
76  } else if (id == IffId("SIDE")) {
77  return new LwoSurfaceSidedness;
78 
79  } else if (id == IffId("SMAN")) {
80  return new LwoSurfaceSmoothingAngle;
81 
82  } else if (id == IffId("BLOK")) {
83  return new LwoSurfaceBlock;
84 
85  } else {
86  return IffChunk::make_new_chunk(in, id);
87  }
88 }
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.
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: lwoSurface.cxx:59
A texture layer or shader, part of a LwoSurface chunk.
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: lwoSurface.cxx:33
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Records the base color of a surface, as an entry within a LwoSurface chunk.
std::string get_string()
Extracts a null-terminated string.
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
Records whether polygons are frontfacing only or backfacing also.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Indicates the maximum angle (in radians) between adjacent polygons that should be smooth-shaded.
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
Records some parameter value of a surface material, as an entry within a LwoSurface chunk.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.