Panda3D
Loading...
Searching...
No Matches
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
24TypeHandle 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 */
33read_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 */
43void LwoSurface::
44write(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}
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on.
Definition iffChunk.h:30
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
IffId get_id() const
Returns the ID associated with this chunk.
Definition iffChunk.I:25
A four-byte chunk ID appearing in an "IFF" file.
Definition iffId.h:26
A wrapper around an istream used for reading an IFF file.
std::string get_string()
Extracts a null-terminated string.
A texture layer or shader, part of a LwoSurface chunk.
Records the base color of a surface, as an entry within a LwoSurface chunk.
Records some parameter value of a surface material, as an entry within a LwoSurface chunk.
Records whether polygons are frontfacing only or backfacing also.
Indicates the maximum angle (in radians) between adjacent polygons that should be smooth-shaded.
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...
virtual bool read_iff(IffInputFile *in, size_t stop_at)
Reads the data of the chunk in from the given input file, if possible.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.