Panda3D
lwoInputFile.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 lwoInputFile.cxx
10  * @author drose
11  * @date 2001-04-24
12  */
13 
14 #include "lwoInputFile.h"
15 #include "lwoBoundingBox.h"
16 #include "lwoClip.h"
18 #include "lwoHeader.h"
19 #include "lwoLayer.h"
20 #include "lwoPoints.h"
21 #include "lwoPolygons.h"
22 #include "lwoPolygonTags.h"
23 #include "lwoTags.h"
24 #include "lwoSurface.h"
25 #include "lwoVertexMap.h"
26 
27 using std::string;
28 
29 TypeHandle LwoInputFile::_type_handle;
30 
31 /**
32  *
33  */
34 LwoInputFile::
35 LwoInputFile() {
36 }
37 
38 /**
39  *
40  */
41 LwoInputFile::
42 ~LwoInputFile() {
43 }
44 
45 /**
46  * Reads a Lightwave variable-length index. This is either a 2-byte or 4-byte
47  * integer.
48  */
50 get_vx() {
51  uint16_t top = get_be_uint16();
52  if ((top & 0xff00) == 0xff00) {
53  // The first byte is 0xff, which indicates we have a 4-byte integer.
54  uint16_t bottom = get_be_uint16();
55  return ((int)(top & 0xff) << 16) | bottom;
56  }
57 
58  // The first byte is not 0xff, which indicates we have a 2-byte integer.
59  return top;
60 }
61 
62 /**
63  * Reads a three-component vector of floats.
64  */
65 LVecBase3 LwoInputFile::
67  LVecBase3 result;
68  result[0] = get_be_float32();
69  result[1] = get_be_float32();
70  result[2] = get_be_float32();
71  return result;
72 }
73 
74 /**
75  * Reads a Lightwave platform-neutral filename and converts it to a Panda
76  * platform-neutral filename.
77  */
80  string name = get_string();
81  size_t colon = name.find(':');
82  if (colon == string::npos) {
83  // No colon; it's just a relative path.
84  return Filename(name);
85  }
86 
87  // The colon separates the device and the path.
88  string device = name.substr(0, colon);
89  string path = name.substr(colon + 1);
90 
91  nout << "Ignoring filename device " << device << "\n";
92  return Filename("/", path);
93 }
94 
95 /**
96  * Allocates and returns a new chunk of the appropriate type based on the
97  * given ID.
98  */
99 IffChunk *LwoInputFile::
100 make_new_chunk(IffId id) {
101  if (id == IffId("FORM")) {
102  return new LwoHeader;
103 
104  } else if (id == IffId("LAYR")) {
105  return new LwoLayer;
106 
107  } else if (id == IffId("PNTS")) {
108  return new LwoPoints;
109 
110  } else if (id == IffId("VMAP")) {
111  return new LwoVertexMap;
112 
113  } else if (id == IffId("VMAD")) {
114  return new LwoDiscontinuousVertexMap;
115 
116  } else if (id == IffId("POLS")) {
117  return new LwoPolygons;
118 
119  } else if (id == IffId("TAGS") ||
120  id == IffId("SRFS")) {
121  return new LwoTags;
122 
123  } else if (id == IffId("PTAG")) {
124  return new LwoPolygonTags;
125 
126  } else if (id == IffId("CLIP")) {
127  return new LwoClip;
128 
129  } else if (id == IffId("SURF")) {
130  return new LwoSurface;
131 
132  } else if (id == IffId("BBOX")) {
133  return new LwoBoundingBox;
134 
135  } else {
136  return IffInputFile::make_new_chunk(id);
137  }
138 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
uint16_t get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
int get_vx()
Reads a Lightwave variable-length index.
LVecBase3 get_vec3()
Reads a three-component vector of floats.
Describes the shading attributes of a surface.
Definition: lwoSurface.h:25
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:24
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A single image file, or a numbered sequence of images (e.g.
Definition: lwoClip.h:25
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:31
Stores the bounding box for the vertex data in a layer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_string()
Extracts a null-terminated string.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on.
Definition: iffChunk.h:30
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Signals the start of a new layer.
Definition: lwoLayer.h:28
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A mapping of floating-point values per integer index.
Definition: lwoVertexMap.h:27
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PN_stdfloat get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An array of polygons that will be referenced by later chunks.
Definition: lwoPolygons.h:29
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A four-byte chunk ID appearing in an "IFF" file.
Definition: iffId.h:26
A mapping of floating-point values per integer index.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An array of points that will be referenced by later chunks.
Definition: lwoPoints.h:26