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"
20 #include "lwoSurfaceSmoothingAngle.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 */
58 IffChunk *LwoSurface::
59 make_new_chunk(IffInputFile *in, IffId id) {
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 }
IffChunk
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on.
Definition: iffChunk.h:30
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
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
IffInputFile
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:30
IffInputFile::get_string
std::string get_string()
Extracts a null-terminated string.
Definition: iffInputFile.cxx:178
LwoSurfaceBlock
A texture layer or shader, part of a LwoSurface chunk.
Definition: lwoSurfaceBlock.h:25
LwoSurfaceColor
Records the base color of a surface, as an entry within a LwoSurface chunk.
Definition: lwoSurfaceColor.h:26
LwoSurfaceParameter
Records some parameter value of a surface material, as an entry within a LwoSurface chunk.
Definition: lwoSurfaceParameter.h:26
LwoSurfaceSidedness
Records whether polygons are frontfacing only or backfacing also.
Definition: lwoSurfaceSidedness.h:25
LwoSurfaceSmoothingAngle
Indicates the maximum angle (in radians) between adjacent polygons that should be smooth-shaded.
Definition: lwoSurfaceSmoothingAngle.h:25
LwoSurface::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: lwoSurface.cxx:59
LwoSurface::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: lwoSurface.cxx:33
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
iffInputFile.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
indent.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoSurfaceBlock.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoSurfaceColor.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoSurfaceParameter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoSurfaceSidedness.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoSurfaceSmoothingAngle.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoSurface.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.