Panda3D
 All Classes Functions Variables Enumerations
lwoInputFile.cxx
1 // Filename: lwoInputFile.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 "lwoInputFile.h"
16 #include "lwoBoundingBox.h"
17 #include "lwoClip.h"
18 #include "lwoDiscontinuousVertexMap.h"
19 #include "lwoHeader.h"
20 #include "lwoLayer.h"
21 #include "lwoPoints.h"
22 #include "lwoPolygons.h"
23 #include "lwoPolygonTags.h"
24 #include "lwoTags.h"
25 #include "lwoSurface.h"
26 #include "lwoVertexMap.h"
27 
28 TypeHandle LwoInputFile::_type_handle;
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: LwoInputFile::Constructor
32 // Access: Public
33 // Description:
34 ////////////////////////////////////////////////////////////////////
35 LwoInputFile::
36 LwoInputFile() {
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: LwoInputFile::Destructor
41 // Access: Public, Virtual
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 LwoInputFile::
45 ~LwoInputFile() {
46 }
47 
48 ////////////////////////////////////////////////////////////////////
49 // Function: LwoInputFile::get_vx
50 // Access: Public
51 // Description: Reads a Lightwave variable-length index. This is
52 // either a 2-byte or 4-byte integer.
53 ////////////////////////////////////////////////////////////////////
55 get_vx() {
56  PN_uint16 top = get_be_uint16();
57  if ((top & 0xff00) == 0xff00) {
58  // The first byte is 0xff, which indicates we have a 4-byte
59  // integer.
60  PN_uint16 bottom = get_be_uint16();
61  return ((int)(top & 0xff) << 16) | bottom;
62  }
63 
64  // The first byte is not 0xff, which indicates we have a 2-byte
65  // integer.
66  return top;
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: LwoInputFile::get_vec3
71 // Access: Public
72 // Description: Reads a three-component vector of floats.
73 ////////////////////////////////////////////////////////////////////
76  LVecBase3 result;
77  result[0] = get_be_float32();
78  result[1] = get_be_float32();
79  result[2] = get_be_float32();
80  return result;
81 }
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: LwoInputFile::get_filename
85 // Access: Public
86 // Description: Reads a Lightwave platform-neutral filename and
87 // converts it to a Panda platform-neutral filename.
88 ////////////////////////////////////////////////////////////////////
91  string name = get_string();
92  size_t colon = name.find(':');
93  if (colon == string::npos) {
94  // No colon; it's just a relative path.
95  return Filename(name);
96  }
97 
98  // The colon separates the device and the path.
99  string device = name.substr(0, colon);
100  string path = name.substr(colon + 1);
101 
102  nout << "Ignoring filename device " << device << "\n";
103  return Filename("/", path);
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: LwoInputFile::make_new_chunk
108 // Access: Protected, Virtual
109 // Description: Allocates and returns a new chunk of the appropriate
110 // type based on the given ID.
111 ////////////////////////////////////////////////////////////////////
112 IffChunk *LwoInputFile::
113 make_new_chunk(IffId id) {
114  if (id == IffId("FORM")) {
115  return new LwoHeader;
116 
117  } else if (id == IffId("LAYR")) {
118  return new LwoLayer;
119 
120  } else if (id == IffId("PNTS")) {
121  return new LwoPoints;
122 
123  } else if (id == IffId("VMAP")) {
124  return new LwoVertexMap;
125 
126  } else if (id == IffId("VMAD")) {
127  return new LwoDiscontinuousVertexMap;
128 
129  } else if (id == IffId("POLS")) {
130  return new LwoPolygons;
131 
132  } else if (id == IffId("TAGS") ||
133  id == IffId("SRFS")) {
134  return new LwoTags;
135 
136  } else if (id == IffId("PTAG")) {
137  return new LwoPolygonTags;
138 
139  } else if (id == IffId("CLIP")) {
140  return new LwoClip;
141 
142  } else if (id == IffId("SURF")) {
143  return new LwoSurface;
144 
145  } else if (id == IffId("BBOX")) {
146  return new LwoBoundingBox;
147 
148  } else {
149  return IffInputFile::make_new_chunk(id);
150  }
151 }
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
int get_vx()
Reads a Lightwave variable-length index.
LVecBase3 get_vec3()
Reads a three-component vector of floats.
string get_string()
Extracts a null-terminated string.
Describes the shading attributes of a surface.
Definition: lwoSurface.h:28
An association of polygons defined in the most recent LwoPolygons chunk to tag ids defined in the mos...
The first chunk in a Lightwave Object file.
Definition: lwoHeader.h:26
PN_uint16 get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
A single image file, or a numbered sequence of images (e.g.
Definition: lwoClip.h:27
Filename get_filename()
Reads a Lightwave platform-neutral filename and converts it to a Panda platform-neutral filename...
An array of tag strings that will be referenced by later chunks.
Definition: lwoTags.h:35
Stores the bounding box for the vertex data in a layer.
The basic kind of record in an EA &quot;IFF&quot; file, which the LightWave object file is based on...
Definition: iffChunk.h:32
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
Signals the start of a new layer.
Definition: lwoLayer.h:32
A mapping of floating-point values per integer index.
Definition: lwoVertexMap.h:30
PN_stdfloat get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
An array of polygons that will be referenced by later chunks.
Definition: lwoPolygons.h:32
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
A mapping of floating-point values per integer index.
An array of points that will be referenced by later chunks.
Definition: lwoPoints.h:29