15 #include "lwoToEggConverter.h" 16 #include "cLwoLayer.h" 18 #include "cLwoPoints.h" 19 #include "cLwoPolygons.h" 20 #include "cLwoSurface.h" 23 #include "lwoHeader.h" 26 #include "lwoPoints.h" 27 #include "lwoPolygons.h" 28 #include "lwoVertexMap.h" 29 #include "lwoDiscontinuousVertexMap.h" 31 #include "lwoPolygonTags.h" 32 #include "lwoInputFile.h" 44 _make_materials =
true;
64 ~LwoToEggConverter() {
128 nout <<
"Reading " << filename <<
"\n";
130 nout <<
"Unable to open " << filename <<
"\n";
134 PT(
IffChunk) chunk = in.get_chunk();
136 nout <<
"Unable to read " << filename <<
"\n";
140 if (!chunk->is_of_type(LwoHeader::get_class_type())) {
141 nout <<
"File " << filename <<
" is not a Lightwave Object file.\n";
147 nout <<
"File " << filename
148 <<
" is not recognized as a Lightwave Object file. " 149 <<
"Perhaps the version is too recent.\n";
164 if (_egg_data->get_coordinate_system() == CS_default) {
165 _egg_data->set_coordinate_system(CS_yup_left);
169 _lwo_header = lwo_header;
175 _egg_data->remove_unused_vertices(
true);
189 if (number >= 0 && number < (
int)_layers.size()) {
190 return _layers[number];
203 if (number >= 0 && number < (
int)_clips.size()) {
204 return _clips[number];
217 Surfaces::const_iterator si;
218 si = _surfaces.find(name);
219 if (si != _surfaces.end()) {
232 void LwoToEggConverter::
236 if (_generic_layer != (
CLwoLayer *)NULL) {
237 delete _generic_layer;
242 for (li = _layers.begin(); li != _layers.end(); ++li) {
251 for (ci = _clips.begin(); ci != _clips.end(); ++ci) {
260 for (pi = _points.begin(); pi != _points.end(); ++pi) {
266 Polygons::iterator gi;
267 for (gi = _polygons.begin(); gi != _polygons.end(); ++gi) {
273 Surfaces::iterator si;
274 for (si = _surfaces.begin(); si != _surfaces.end(); ++si) {
287 void LwoToEggConverter::
295 int num_chunks = _lwo_header->get_num_chunks();
296 for (
int i = 0; i < num_chunks; i++) {
297 const IffChunk *chunk = _lwo_header->get_chunk(i);
299 if (chunk->
is_of_type(LwoLayer::get_class_type())) {
305 if (_layers[number] != (
CLwoLayer *)NULL) {
306 nout <<
"Warning: multiple layers with number " << number <<
"\n";
308 _layers[number] = layer;
313 }
else if (chunk->
is_of_type(LwoClip::get_class_type())) {
320 if (_clips[index] != (
CLwoClip *)NULL) {
321 nout <<
"Warning: multiple clips with index " << index <<
"\n";
323 _clips[index] = clip;
325 }
else if (chunk->
is_of_type(LwoPoints::get_class_type())) {
327 last_layer = make_generic_layer();
332 _points.push_back(points);
333 last_points = points;
335 }
else if (chunk->
is_of_type(LwoVertexMap::get_class_type())) {
337 nout <<
"Vertex map chunk encountered without a preceding points chunk.\n";
343 }
else if (chunk->
is_of_type(LwoDiscontinuousVertexMap::get_class_type())) {
345 nout <<
"Discontinous vertex map chunk encountered without a preceding polygons chunk.\n";
351 }
else if (chunk->
is_of_type(LwoTags::get_class_type())) {
354 }
else if (chunk->
is_of_type(LwoPolygons::get_class_type())) {
356 nout <<
"Polygon chunk encountered without a preceding points chunk.\n";
361 _polygons.push_back(polygons);
362 last_polygons = polygons;
365 }
else if (chunk->
is_of_type(LwoPolygonTags::get_class_type())) {
367 nout <<
"Polygon tags chunk encountered without a preceding polygons chunk.\n";
368 }
else if (tags == (
LwoTags *)NULL) {
369 nout <<
"Polygon tags chunk encountered without a preceding tags chunk.\n";
372 last_polygons->
add_ptags(lwo_ptags, tags);
375 }
else if (chunk->
is_of_type(LwoSurface::get_class_type())) {
377 last_layer = make_generic_layer();
383 bool inserted = _surfaces.insert(Surfaces::value_type(surface->
get_name(), surface)).second;
385 nout <<
"Multiple surface definitions named " << surface->
get_name() <<
"\n";
398 void LwoToEggConverter::
400 if (_generic_layer != (
CLwoLayer *)NULL) {
405 for (li = _layers.begin(); li != _layers.end(); ++li) {
413 for (pi = _points.begin(); pi != _points.end(); ++pi) {
418 Polygons::iterator gi;
419 for (gi = _polygons.begin(); gi != _polygons.end(); ++gi) {
430 void LwoToEggConverter::
432 if (_generic_layer != (
CLwoLayer *)NULL) {
437 for (li = _layers.begin(); li != _layers.end(); ++li) {
445 for (pi = _points.begin(); pi != _points.end(); ++pi) {
450 Polygons::iterator gi;
451 for (gi = _polygons.begin(); gi != _polygons.end(); ++gi) {
463 void LwoToEggConverter::
464 slot_layer(
int number) {
465 nassertv(number - (
int)_layers.size() < 1000);
466 while (number >= (
int)_layers.size()) {
469 nassertv(number >= 0 && number < (
int)_layers.size());
478 void LwoToEggConverter::
479 slot_clip(
int number) {
480 nassertv(number - (
int)_clips.size() < 1000);
481 while (number >= (
int)_clips.size()) {
484 nassertv(number >= 0 && number < (
int)_clips.size());
497 make_generic_layer() {
498 nassertr(_generic_layer == (
CLwoLayer *)NULL, _generic_layer);
503 _generic_layer =
new CLwoLayer(
this, layer);
504 return _generic_layer;
CLwoSurface * get_surface(const string &name) const
Returns a pointer to the surface definition with the given name, or NULL if there is no such surface...
virtual string get_name() const
Returns the English name of the file type this converter supports.
int get_number() const
Returns the index number associated with this particular layer.
void add_vmad(const LwoDiscontinuousVertexMap *lwo_vmad)
Associates the indicated DiscontinousVertexMap with the polygons.
void add_ptags(const LwoPolygonTags *lwo_ptags, const LwoTags *tags)
Associates the indicated PolygonTags and Tags with the polygons in this chunk.
void make_egg()
Creates the egg structures associated with this Lightwave object.
bool had_error() const
Returns true if an error was detected during the conversion process (unless _allow_errors is true)...
Describes the shading attributes of a surface.
void add_vmap(const LwoVertexMap *lwo_vmap)
Associates the indicated VertexMap with the points set.
This class is a wrapper around LwoPolygons and stores additional information useful during the conver...
void make_egg()
Creates the egg structures associated with this Lightwave object.
A single image file, or a numbered sequence of images (e.g.
virtual string get_extension() const
Returns the common extension of the file type this converter supports.
const string & get_name() const
Returns the name of the surface.
void make_egg()
Creates the egg structures associated with this Lightwave object.
This class is a wrapper around LwoClip and stores additional information useful during the conversion...
This class is a wrapper around LwoSurface and stores additional information useful during the convers...
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on...
int get_index() const
Returns the index number of this clip.
The name of a file, such as a texture file or an Egg file.
This class is a wrapper around LwoLayer and stores additional information useful during the conversio...
bool convert_lwo(const LwoHeader *lwo_header)
Fills up the egg_data structure according to the indicated lwo structure.
CLwoLayer * get_layer(int number) const
Returns a pointer to the layer with the given index number, or NULL if there is no such layer...
Signals the start of a new layer.
A mapping of floating-point values per integer index.
void connect_egg()
Connects all the egg structures together.
This class supervises the construction of an EggData structure from the data represented by the LwoHe...
virtual SomethingToEggConverter * make_copy()
Allocates and returns a new copy of the converter.
CLwoClip * get_clip(int number) const
Returns a pointer to the clip with the given index number, or NULL if there is no such clip...
This class is a wrapper around LwoPoints and stores additional information useful during the conversi...
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
void connect_egg()
Connects all the egg structures together.
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz extension)...
An array of polygons that will be referenced by later chunks.
void make_generic()
Resets the layer's parameters to initial defaults for a generic layer created implicitly.
void connect_egg()
Connects all the egg structures together.
A mapping of floating-point values per integer index.
This is a base class for a family of converter classes that manage a conversion from some file type t...
An array of points that will be referenced by later chunks.
virtual bool convert_file(const Filename &filename)
Handles the reading of the input file and converting it to egg.