Panda3D
 All Classes Functions Variables Enumerations
lwoSurface.cxx
1 // Filename: lwoSurface.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 "lwoSurface.h"
16 #include "iffInputFile.h"
17 #include "lwoSurfaceBlock.h"
18 #include "lwoSurfaceColor.h"
19 #include "lwoSurfaceParameter.h"
20 #include "lwoSurfaceSidedness.h"
21 #include "lwoSurfaceSmoothingAngle.h"
22 
23 #include "indent.h"
24 
25 TypeHandle LwoSurface::_type_handle;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Function: LwoSurface::read_iff
29 // Access: Public, Virtual
30 // Description: Reads the data of the chunk in from the given input
31 // file, if possible. The ID and length of the chunk
32 // have already been read. stop_at is the byte position
33 // of the file to stop at (based on the current position
34 // at in->get_bytes_read()). Returns true on success,
35 // false otherwise.
36 ////////////////////////////////////////////////////////////////////
37 bool LwoSurface::
38 read_iff(IffInputFile *in, size_t stop_at) {
39  _name = in->get_string();
40  _source = in->get_string();
41  read_subchunks_iff(in, stop_at);
42  return true;
43 }
44 
45 ////////////////////////////////////////////////////////////////////
46 // Function: LwoSurface::write
47 // Access: Public, Virtual
48 // Description:
49 ////////////////////////////////////////////////////////////////////
50 void LwoSurface::
51 write(ostream &out, int indent_level) const {
52  indent(out, indent_level)
53  << get_id() << " {\n";
54  indent(out, indent_level + 2)
55  << "name = \"" << _name << "\", source = \"" << _source << "\"\n";
56  write_chunks(out, indent_level + 2);
57  indent(out, indent_level)
58  << "}\n";
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function: LwoSurface::make_new_chunk
63 // Access: Protected, Virtual
64 // Description: Allocates and returns a new chunk of the appropriate
65 // type based on the given ID, according to the context
66 // given by this chunk itself.
67 ////////////////////////////////////////////////////////////////////
70  if (id == IffId("COLR")) {
71  return new LwoSurfaceColor;
72 
73  } else if (id == IffId("DIFF") ||
74  id == IffId("LUMI") ||
75  id == IffId("SPEC") ||
76  id == IffId("REFL") ||
77  id == IffId("TRAN") ||
78  id == IffId("TRNL") ||
79  id == IffId("GLOS") ||
80  id == IffId("SHRP") ||
81  id == IffId("BUMP") ||
82  id == IffId("RSAN") ||
83  id == IffId("RIND")) {
84  return new LwoSurfaceParameter;
85 
86  } else if (id == IffId("SIDE")) {
87  return new LwoSurfaceSidedness;
88 
89  } else if (id == IffId("SMAN")) {
90  return new LwoSurfaceSmoothingAngle;
91 
92  } else if (id == IffId("BLOK")) {
93  return new LwoSurfaceBlock;
94 
95  } else {
96  return IffChunk::make_new_chunk(in, id);
97  }
98 }
99 
string get_string()
Extracts a null-terminated string.
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
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:69
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:38
Records the base color of a surface, as an entry within a LwoSurface chunk.
The basic kind of record in an EA &quot;IFF&quot; 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
Records whether polygons are frontfacing only or backfacing also.
IffId get_id() const
Returns the ID associated with this chunk.
Definition: iffChunk.I:31
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:85
A four-byte chunk ID appearing in an &quot;IFF&quot; file.
Definition: iffId.h:29
Records some parameter value of a surface material, as an entry within a LwoSurface chunk...