Panda3D

Loading...
Searching...
No Matches
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"
17#include "lwoDiscontinuousVertexMap.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 */
34LwoInputFile::
35LwoInputFile() {
36}
37
38/**
39 *
40 */
41LwoInputFile::
42~LwoInputFile() {
43}
44
45/**
46 * Reads a Lightwave variable-length index. This is either a 2-byte or 4-byte
47 * integer.
48 */
49 int LwoInputFile::
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 */
65LVecBase3 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 */
78 Filename LwoInputFile::
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::
100make_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}
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
IffChunk
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on.
Definition iffChunk.h:30
IffId
A four-byte chunk ID appearing in an "IFF" file.
Definition iffId.h:26
IffInputFile::get_be_float32
PN_stdfloat get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
Definition iffInputFile.cxx:165
IffInputFile::get_be_uint16
uint16_t get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
Definition iffInputFile.cxx:139
IffInputFile::get_string
std::string get_string()
Extracts a null-terminated string.
Definition iffInputFile.cxx:178
LwoHeader
The first chunk in a Lightwave Object file.
Definition lwoHeader.h:24
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
LwoInputFile::get_vec3
LVecBase3 get_vec3()
Reads a three-component vector of floats.
Definition lwoInputFile.cxx:66
LwoInputFile::get_vx
int get_vx()
Reads a Lightwave variable-length index.
Definition lwoInputFile.cxx:50
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
lwoBoundingBox.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoClip.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoDiscontinuousVertexMap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoHeader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoInputFile.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoLayer.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoPoints.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoPolygonTags.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoPolygons.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoSurface.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoTags.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
lwoVertexMap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.