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::
66 get_vec3() {
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  */
79 get_filename() {
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 }
LwoPoints
An array of points that will be referenced by later chunks.
Definition: lwoPoints.h:26
LwoVertexMap
A mapping of floating-point values per integer index.
Definition: lwoVertexMap.h:27
lwoDiscontinuousVertexMap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LwoSurface
Describes the shading attributes of a surface.
Definition: lwoSurface.h:25
LwoLayer
Signals the start of a new layer.
Definition: lwoLayer.h:28
lwoPolygonTags.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoInputFile.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
IffInputFile::get_be_float32
PN_stdfloat get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
Definition: iffInputFile.cxx:165
lwoBoundingBox.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoPolygons.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoHeader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LwoInputFile::get_filename
Filename get_filename()
Reads a Lightwave platform-neutral filename and converts it to a Panda platform-neutral filename.
Definition: lwoInputFile.cxx:79
IffId
A four-byte chunk ID appearing in an "IFF" file.
Definition: iffId.h:26
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
LwoHeader
The first chunk in a Lightwave Object file.
Definition: lwoHeader.h:24
LwoInputFile::get_vx
int get_vx()
Reads a Lightwave variable-length index.
Definition: lwoInputFile.cxx:50
IffInputFile::get_be_uint16
uint16_t get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
Definition: iffInputFile.cxx:139
LwoDiscontinuousVertexMap
A mapping of floating-point values per integer index.
Definition: lwoDiscontinuousVertexMap.h:28
lwoClip.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoVertexMap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LwoPolygonTags
An association of polygons defined in the most recent LwoPolygons chunk to tag ids defined in the mos...
Definition: lwoPolygonTags.h:26
lwoSurface.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LwoBoundingBox
Stores the bounding box for the vertex data in a layer.
Definition: lwoBoundingBox.h:26
LwoClip
A single image file, or a numbered sequence of images (e.g.
Definition: lwoClip.h:25
lwoPoints.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LwoInputFile::get_vec3
LVecBase3 get_vec3()
Reads a three-component vector of floats.
Definition: lwoInputFile.cxx:66
lwoTags.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoLayer.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LwoTags
An array of tag strings that will be referenced by later chunks.
Definition: lwoTags.h:31
IffChunk
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on.
Definition: iffChunk.h:30
Filename
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
LwoPolygons
An array of polygons that will be referenced by later chunks.
Definition: lwoPolygons.h:29
IffInputFile::get_string
std::string get_string()
Extracts a null-terminated string.
Definition: iffInputFile.cxx:178