From 03c8bcc4f5a5ccc09249b062cacf059f88f02451 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 24 Apr 2001 21:02:58 +0000 Subject: [PATCH] *** empty log message *** --- pandatool/src/lwo/Sources.pp | 12 +++ pandatool/src/lwo/config_lwo.cxx | 12 +++ pandatool/src/lwo/iffInputFile.cxx | 4 +- pandatool/src/lwo/iffInputFile.h | 2 +- .../lwo/{lwoGroupChunk.I => lwoBoundingBox.I} | 2 +- pandatool/src/lwo/lwoBoundingBox.cxx | 42 ++++++++++ pandatool/src/lwo/lwoBoundingBox.h | 51 ++++++++++++ pandatool/src/lwo/lwoChunk.h | 2 - pandatool/src/lwo/{lwoTags.I => lwoClip.I} | 2 +- pandatool/src/lwo/lwoClip.cxx | 62 +++++++++++++++ pandatool/src/lwo/lwoClip.h | 36 +++++++++ pandatool/src/lwo/lwoDiscontinuousVertexMap.I | 4 - pandatool/src/lwo/lwoDiscontinuousVertexMap.h | 2 - pandatool/src/lwo/lwoGroupChunk.cxx | 49 ++++++++---- pandatool/src/lwo/lwoGroupChunk.h | 13 ++-- pandatool/src/lwo/lwoHeader.I | 12 --- pandatool/src/lwo/lwoHeader.cxx | 6 +- pandatool/src/lwo/lwoHeader.h | 5 +- pandatool/src/lwo/lwoInputFile.cxx | 14 +++- pandatool/src/lwo/lwoInputFile.h | 2 - pandatool/src/lwo/lwoLayer.cxx | 1 + pandatool/src/lwo/lwoLayer.h | 2 - pandatool/src/lwo/lwoPoints.I | 4 - pandatool/src/lwo/lwoPoints.h | 2 - pandatool/src/lwo/lwoPolygonTags.I | 4 - pandatool/src/lwo/lwoPolygonTags.h | 2 - pandatool/src/lwo/lwoPolygons.I | 4 - pandatool/src/lwo/lwoPolygons.h | 2 - .../src/lwo/{lwoLayer.I => lwoStillImage.I} | 2 +- pandatool/src/lwo/lwoStillImage.cxx | 41 ++++++++++ pandatool/src/lwo/lwoStillImage.h | 49 ++++++++++++ .../src/lwo/{lwoChunk.I => lwoSurface.I} | 2 +- pandatool/src/lwo/lwoSurface.cxx | 77 +++++++++++++++++++ pandatool/src/lwo/lwoSurface.h | 38 +++++++++ .../lwo/{lwoInputFile.I => lwoSurfaceColor.I} | 2 +- pandatool/src/lwo/lwoSurfaceColor.cxx | 43 +++++++++++ pandatool/src/lwo/lwoSurfaceColor.h | 51 ++++++++++++ pandatool/src/lwo/lwoSurfaceParameter.I | 4 + pandatool/src/lwo/lwoSurfaceParameter.cxx | 43 +++++++++++ pandatool/src/lwo/lwoSurfaceParameter.h | 50 ++++++++++++ pandatool/src/lwo/lwoTags.cxx | 4 +- pandatool/src/lwo/lwoTags.h | 2 - pandatool/src/lwo/lwoVertexMap.I | 4 - pandatool/src/lwo/lwoVertexMap.h | 2 - 44 files changed, 680 insertions(+), 89 deletions(-) rename pandatool/src/lwo/{lwoGroupChunk.I => lwoBoundingBox.I} (77%) create mode 100644 pandatool/src/lwo/lwoBoundingBox.cxx create mode 100644 pandatool/src/lwo/lwoBoundingBox.h rename pandatool/src/lwo/{lwoTags.I => lwoClip.I} (82%) create mode 100644 pandatool/src/lwo/lwoClip.cxx create mode 100644 pandatool/src/lwo/lwoClip.h delete mode 100644 pandatool/src/lwo/lwoDiscontinuousVertexMap.I delete mode 100644 pandatool/src/lwo/lwoPoints.I delete mode 100644 pandatool/src/lwo/lwoPolygonTags.I delete mode 100644 pandatool/src/lwo/lwoPolygons.I rename pandatool/src/lwo/{lwoLayer.I => lwoStillImage.I} (78%) create mode 100644 pandatool/src/lwo/lwoStillImage.cxx create mode 100644 pandatool/src/lwo/lwoStillImage.h rename pandatool/src/lwo/{lwoChunk.I => lwoSurface.I} (80%) create mode 100644 pandatool/src/lwo/lwoSurface.cxx create mode 100644 pandatool/src/lwo/lwoSurface.h rename pandatool/src/lwo/{lwoInputFile.I => lwoSurfaceColor.I} (77%) create mode 100644 pandatool/src/lwo/lwoSurfaceColor.cxx create mode 100644 pandatool/src/lwo/lwoSurfaceColor.h create mode 100644 pandatool/src/lwo/lwoSurfaceParameter.I create mode 100644 pandatool/src/lwo/lwoSurfaceParameter.cxx create mode 100644 pandatool/src/lwo/lwoSurfaceParameter.h delete mode 100644 pandatool/src/lwo/lwoVertexMap.I diff --git a/pandatool/src/lwo/Sources.pp b/pandatool/src/lwo/Sources.pp index 45da00cd77..ed72b5d4d7 100644 --- a/pandatool/src/lwo/Sources.pp +++ b/pandatool/src/lwo/Sources.pp @@ -11,7 +11,9 @@ config_lwo.cxx config_lwo.h iffChunk.I iffChunk.cxx iffChunk.h \ iffGenericChunk.I iffGenericChunk.cxx iffGenericChunk.h iffId.I \ iffId.cxx iffId.h iffInputFile.I iffInputFile.cxx iffInputFile.h \ + lwoBoundingBox.I lwoBoundingBox.cxx lwoBoundingBox.h \ lwoChunk.I lwoChunk.cxx lwoChunk.h \ + lwoClip.I lwoClip.cxx lwoClip.h \ lwoDiscontinuousVertexMap.I lwoDiscontinuousVertexMap.cxx lwoDiscontinuousVertexMap.h \ lwoGroupChunk.I lwoGroupChunk.cxx lwoGroupChunk.h \ lwoHeader.I lwoHeader.cxx \ @@ -21,12 +23,18 @@ lwoPolygons.h lwoPolygons.I lwoPolygons.cxx \ lwoPolygonTags.h lwoPolygonTags.I lwoPolygonTags.cxx \ lwoTags.h lwoTags.I lwoTags.cxx \ + lwoStillImage.h lwoStillImage.I lwoStillImage.cxx \ + lwoSurface.h lwoSurface.I lwoSurface.cxx \ + lwoSurfaceColor.h lwoSurfaceColor.I lwoSurfaceColor.cxx \ + lwoSurfaceParameter.h lwoSurfaceParameter.I lwoSurfaceParameter.cxx \ lwoVertexMap.h lwoVertexMap.I lwoVertexMap.cxx #define INSTALL_HEADERS \ iffChunk.I iffChunk.h iffGenericChunk.I iffGenericChunk.h iffId.I \ iffId.h iffInputFile.I iffInputFile.h \ + lwoBoundingBox.I lwoBoundingBox.h \ lwoChunk.I lwoChunk.h \ + lwoClip.I lwoClip.h \ lwoDiscontinuousVertexMap.I lwoDiscontinuousVertexMap.h \ lwoGroupChunk.I lwoGroupChunk.h \ lwoHeader.I lwoHeader.h \ @@ -36,6 +44,10 @@ lwoPolygons.I lwoPolygons.h \ lwoPolygonTags.I lwoPolygonTags.h \ lwoTags.I lwoTags.h \ + lwoStillImage.I lwoStillImage.h \ + lwoSurface.I lwoSurface.h \ + lwoSurfaceColor.I lwoSurfaceColor.h \ + lwoSurfaceParameter.I lwoSurfaceParameter.h \ lwoVertexMap.I lwoVertexMap.h #end ss_lib_target diff --git a/pandatool/src/lwo/config_lwo.cxx b/pandatool/src/lwo/config_lwo.cxx index 4a17d518f7..3a7c68b89f 100644 --- a/pandatool/src/lwo/config_lwo.cxx +++ b/pandatool/src/lwo/config_lwo.cxx @@ -7,7 +7,9 @@ #include "iffChunk.h" #include "iffGenericChunk.h" #include "iffInputFile.h" +#include "lwoBoundingBox.h" #include "lwoChunk.h" +#include "lwoClip.h" #include "lwoDiscontinuousVertexMap.h" #include "lwoGroupChunk.h" #include "lwoHeader.h" @@ -16,6 +18,10 @@ #include "lwoPoints.h" #include "lwoPolygons.h" #include "lwoPolygonTags.h" +#include "lwoStillImage.h" +#include "lwoSurface.h" +#include "lwoSurfaceColor.h" +#include "lwoSurfaceParameter.h" #include "lwoTags.h" #include "lwoVertexMap.h" @@ -27,7 +33,9 @@ ConfigureFn(config_lwo) { IffChunk::init_type(); IffGenericChunk::init_type(); IffInputFile::init_type(); + LwoBoundingBox::init_type(); LwoChunk::init_type(); + LwoClip::init_type(); LwoDiscontinuousVertexMap::init_type(); LwoGroupChunk::init_type(); LwoHeader::init_type(); @@ -37,6 +45,10 @@ ConfigureFn(config_lwo) { LwoPolygons::init_type(); LwoPolygonTags::init_type(); LwoTags::init_type(); + LwoStillImage::init_type(); + LwoSurface::init_type(); + LwoSurfaceColor::init_type(); + LwoSurfaceParameter::init_type(); LwoVertexMap::init_type(); } diff --git a/pandatool/src/lwo/iffInputFile.cxx b/pandatool/src/lwo/iffInputFile.cxx index 36dde7e246..02b87fbdd9 100644 --- a/pandatool/src/lwo/iffInputFile.cxx +++ b/pandatool/src/lwo/iffInputFile.cxx @@ -256,7 +256,7 @@ get_chunk() { } //////////////////////////////////////////////////////////////////// -// Function: IffInputFile::get_sub_chunk +// Function: IffInputFile::get_subchunk // Access: Public // Description: Similar to get_chunk(), except the chunk size is only // a 16-bit number instead of 32-bit, and it takes a @@ -266,7 +266,7 @@ get_chunk() { // id's encountered. //////////////////////////////////////////////////////////////////// PT(IffChunk) IffInputFile:: -get_sub_chunk(IffChunk *context) { +get_subchunk(IffChunk *context) { IffId id = get_id(); PN_uint16 length = get_be_uint16(); diff --git a/pandatool/src/lwo/iffInputFile.h b/pandatool/src/lwo/iffInputFile.h index 3583ef7037..20c2880c5f 100644 --- a/pandatool/src/lwo/iffInputFile.h +++ b/pandatool/src/lwo/iffInputFile.h @@ -51,7 +51,7 @@ public: IffId get_id(); PT(IffChunk) get_chunk(); - PT(IffChunk) get_sub_chunk(IffChunk *context); + PT(IffChunk) get_subchunk(IffChunk *context); bool read_byte(char &byte); bool read_bytes(Datagram &datagram, size_t length); diff --git a/pandatool/src/lwo/lwoGroupChunk.I b/pandatool/src/lwo/lwoBoundingBox.I similarity index 77% rename from pandatool/src/lwo/lwoGroupChunk.I rename to pandatool/src/lwo/lwoBoundingBox.I index 4086a06a0b..03c50e4bb8 100644 --- a/pandatool/src/lwo/lwoGroupChunk.I +++ b/pandatool/src/lwo/lwoBoundingBox.I @@ -1,4 +1,4 @@ -// Filename: lwoGroupChunk.I +// Filename: lwoBoundingBox.I // Created by: drose (24Apr01) // //////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/lwo/lwoBoundingBox.cxx b/pandatool/src/lwo/lwoBoundingBox.cxx new file mode 100644 index 0000000000..17c5270e1b --- /dev/null +++ b/pandatool/src/lwo/lwoBoundingBox.cxx @@ -0,0 +1,42 @@ +// Filename: lwoBoundingBox.cxx +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#include "lwoBoundingBox.h" +#include "lwoInputFile.h" + +#include + +TypeHandle LwoBoundingBox::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: LwoBoundingBox::read_iff +// Access: Public, Virtual +// Description: Reads the data of the chunk in from the given input +// file, if possible. The ID and length of the chunk +// have already been read. stop_at is the byte position +// of the file to stop at (based on the current position +// at in->get_bytes_read()). Returns true on success, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool LwoBoundingBox:: +read_iff(IffInputFile *in, size_t stop_at) { + LwoInputFile *lin = DCAST(LwoInputFile, in); + + _min = lin->get_vec3(); + _max = lin->get_vec3(); + + return true; +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoBoundingBox::write +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +void LwoBoundingBox:: +write(ostream &out, int indent_level) const { + indent(out, indent_level) + << get_id() << " { min = " << _min << ", max = " << _max << " }\n"; +} diff --git a/pandatool/src/lwo/lwoBoundingBox.h b/pandatool/src/lwo/lwoBoundingBox.h new file mode 100644 index 0000000000..fe59a7ca66 --- /dev/null +++ b/pandatool/src/lwo/lwoBoundingBox.h @@ -0,0 +1,51 @@ +// Filename: lwoBoundingBox.h +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#ifndef LWOBOUNDINGBOX_H +#define LWOBOUNDINGBOX_H + +#include + +#include "lwoChunk.h" + +#include + +//////////////////////////////////////////////////////////////////// +// Class : LwoBoundingBox +// Description : Stores the bounding box for the vertex data in a +// layer. Optional. +//////////////////////////////////////////////////////////////////// +class LwoBoundingBox : public LwoChunk { +public: + LVecBase3f _min; + LVecBase3f _max; + +public: + virtual bool read_iff(IffInputFile *in, size_t stop_at); + virtual void write(ostream &out, int indent_level = 0) const; + +public: + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + LwoChunk::init_type(); + register_type(_type_handle, "LwoBoundingBox", + LwoChunk::get_class_type()); + } + +private: + static TypeHandle _type_handle; +}; + +#include "lwoBoundingBox.I" + +#endif + + diff --git a/pandatool/src/lwo/lwoChunk.h b/pandatool/src/lwo/lwoChunk.h index 4b001b70d3..10fd77656f 100644 --- a/pandatool/src/lwo/lwoChunk.h +++ b/pandatool/src/lwo/lwoChunk.h @@ -39,8 +39,6 @@ private: static TypeHandle _type_handle; }; -#include "lwoChunk.I" - #endif diff --git a/pandatool/src/lwo/lwoTags.I b/pandatool/src/lwo/lwoClip.I similarity index 82% rename from pandatool/src/lwo/lwoTags.I rename to pandatool/src/lwo/lwoClip.I index a3c958b283..706fb12608 100644 --- a/pandatool/src/lwo/lwoTags.I +++ b/pandatool/src/lwo/lwoClip.I @@ -1,4 +1,4 @@ -// Filename: lwoTags.I +// Filename: lwoClip.I // Created by: drose (24Apr01) // //////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/lwo/lwoClip.cxx b/pandatool/src/lwo/lwoClip.cxx new file mode 100644 index 0000000000..460f2c7888 --- /dev/null +++ b/pandatool/src/lwo/lwoClip.cxx @@ -0,0 +1,62 @@ +// Filename: lwoClip.cxx +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#include "lwoClip.h" +#include "iffInputFile.h" +#include "lwoStillImage.h" + +#include + +TypeHandle LwoClip::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: LwoClip::read_iff +// Access: Public, Virtual +// Description: Reads the data of the chunk in from the given input +// file, if possible. The ID and length of the chunk +// have already been read. stop_at is the byte position +// of the file to stop at (based on the current position +// at in->get_bytes_read()). Returns true on success, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool LwoClip:: +read_iff(IffInputFile *in, size_t stop_at) { + _index = in->get_be_int32(); + return read_subchunks_iff(in, stop_at); +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoClip::write +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +void LwoClip:: +write(ostream &out, int indent_level) const { + indent(out, indent_level) + << get_id() << " {\n"; + indent(out, indent_level + 2) + << "index = " << _index << "\n"; + write_chunks(out, indent_level + 2); + indent(out, indent_level) + << "}\n"; +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoClip::make_new_chunk +// Access: Protected, Virtual +// Description: Allocates and returns a new chunk of the appropriate +// type based on the given ID, according to the context +// given by this chunk itself. +//////////////////////////////////////////////////////////////////// +IffChunk *LwoClip:: +make_new_chunk(IffInputFile *in, IffId id) { + if (id == IffId("STIL")) { + return new LwoStillImage; + + } else { + return IffChunk::make_new_chunk(in, id); + } +} + diff --git a/pandatool/src/lwo/lwoClip.h b/pandatool/src/lwo/lwoClip.h new file mode 100644 index 0000000000..49e4dc857a --- /dev/null +++ b/pandatool/src/lwo/lwoClip.h @@ -0,0 +1,36 @@ +// Filename: lwoClip.h +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#ifndef LWOCLIP_H +#define LWOCLIP_H + +#include + +#include "lwoGroupChunk.h" + +//////////////////////////////////////////////////////////////////// +// Class : LwoClip +// Description : A single image file, or a numbered sequence of images +// (e.g. a texture-flip animation). +//////////////////////////////////////////////////////////////////// +class LwoClip : public LwoGroupChunk { +public: + int _index; + +public: + virtual bool read_iff(IffInputFile *in, size_t stop_at); + virtual void write(ostream &out, int indent_level = 0) const; + + virtual IffChunk *make_new_chunk(IffInputFile *in, IffId id); + +private: + static TypeHandle _type_handle; +}; + +#include "lwoClip.I" + +#endif + + diff --git a/pandatool/src/lwo/lwoDiscontinuousVertexMap.I b/pandatool/src/lwo/lwoDiscontinuousVertexMap.I deleted file mode 100644 index 8c27fe919d..0000000000 --- a/pandatool/src/lwo/lwoDiscontinuousVertexMap.I +++ /dev/null @@ -1,4 +0,0 @@ -// Filename: lwoDiscontinuousVertexMap.I -// Created by: drose (24Apr01) -// -//////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/lwo/lwoDiscontinuousVertexMap.h b/pandatool/src/lwo/lwoDiscontinuousVertexMap.h index 3fc9f74ceb..f6c16249ca 100644 --- a/pandatool/src/lwo/lwoDiscontinuousVertexMap.h +++ b/pandatool/src/lwo/lwoDiscontinuousVertexMap.h @@ -54,8 +54,6 @@ private: static TypeHandle _type_handle; }; -#include "lwoDiscontinuousVertexMap.I" - #endif diff --git a/pandatool/src/lwo/lwoGroupChunk.cxx b/pandatool/src/lwo/lwoGroupChunk.cxx index 01be93b805..bff033a28a 100644 --- a/pandatool/src/lwo/lwoGroupChunk.cxx +++ b/pandatool/src/lwo/lwoGroupChunk.cxx @@ -11,28 +11,28 @@ TypeHandle LwoGroupChunk::_type_handle; //////////////////////////////////////////////////////////////////// -// Function: LwoGroupChunk::get_num_children +// Function: LwoGroupChunk::get_num_chunks // Access: Public // Description: Returns the number of child chunks of this group. //////////////////////////////////////////////////////////////////// int LwoGroupChunk:: -get_num_children() const { - return _children.size(); +get_num_chunks() const { + return _chunks.size(); } //////////////////////////////////////////////////////////////////// -// Function: LwoGroupChunk::get_child +// Function: LwoGroupChunk::get_chunk // Access: Public // Description: Returns the nth child chunk of this group. //////////////////////////////////////////////////////////////////// IffChunk *LwoGroupChunk:: -get_child(int n) const { - nassertr(n >= 0 && n < (int)_children.size(), (IffChunk *)NULL); - return _children[n]; +get_chunk(int n) const { + nassertr(n >= 0 && n < (int)_chunks.size(), (IffChunk *)NULL); + return _chunks[n]; } //////////////////////////////////////////////////////////////////// -// Function: LwoGroupChunk::read_children_iff +// Function: LwoGroupChunk::read_chunks_iff // Access: Public // Description: Reads a sequence of child chunks, until byte stop_at // has been been reached, and stores them as the @@ -41,28 +41,47 @@ get_child(int n) const { // otherwise. //////////////////////////////////////////////////////////////////// bool LwoGroupChunk:: -read_children_iff(IffInputFile *in, size_t stop_at) { +read_chunks_iff(IffInputFile *in, size_t stop_at) { while (in->get_bytes_read() < stop_at && !in->is_eof()) { PT(IffChunk) chunk = in->get_chunk(); if (chunk == (IffChunk *)NULL) { return false; } - _children.push_back(chunk); + _chunks.push_back(chunk); } return (in->get_bytes_read() == stop_at); } //////////////////////////////////////////////////////////////////// -// Function: LwoGroupChunk::write_children +// Function: LwoGroupChunk::read_subchunks_iff // Access: Public -// Description: Formats the list of children for output to the user +// Description: Similar to read_chunks_iff(), but reads them as +// subchunks. +//////////////////////////////////////////////////////////////////// +bool LwoGroupChunk:: +read_subchunks_iff(IffInputFile *in, size_t stop_at) { + while (in->get_bytes_read() < stop_at && !in->is_eof()) { + PT(IffChunk) chunk = in->get_subchunk(this); + if (chunk == (IffChunk *)NULL) { + return false; + } + _chunks.push_back(chunk); + } + + return (in->get_bytes_read() == stop_at); +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoGroupChunk::write_chunks +// Access: Public +// Description: Formats the list of chunks for output to the user // (primarily for debugging), one per line. //////////////////////////////////////////////////////////////////// void LwoGroupChunk:: -write_children(ostream &out, int indent_level) const { - Children::const_iterator ci; - for (ci = _children.begin(); ci != _children.end(); ++ci) { +write_chunks(ostream &out, int indent_level) const { + Chunks::const_iterator ci; + for (ci = _chunks.begin(); ci != _chunks.end(); ++ci) { (*ci)->write(out, indent_level); } } diff --git a/pandatool/src/lwo/lwoGroupChunk.h b/pandatool/src/lwo/lwoGroupChunk.h index 751cd76631..0f0479f29c 100644 --- a/pandatool/src/lwo/lwoGroupChunk.h +++ b/pandatool/src/lwo/lwoGroupChunk.h @@ -22,15 +22,16 @@ //////////////////////////////////////////////////////////////////// class LwoGroupChunk : public LwoChunk { public: - int get_num_children() const; - IffChunk *get_child(int n) const; + int get_num_chunks() const; + IffChunk *get_chunk(int n) const; protected: - bool read_children_iff(IffInputFile *in, size_t stop_at); - void write_children(ostream &out, int indent_level) const; + bool read_chunks_iff(IffInputFile *in, size_t stop_at); + bool read_subchunks_iff(IffInputFile *in, size_t stop_at); + void write_chunks(ostream &out, int indent_level) const; - typedef vector< PT(IffChunk) > Children; - Children _children; + typedef vector< PT(IffChunk) > Chunks; + Chunks _chunks; public: virtual TypeHandle get_type() const { diff --git a/pandatool/src/lwo/lwoHeader.I b/pandatool/src/lwo/lwoHeader.I index 00049390ba..392594ddcd 100644 --- a/pandatool/src/lwo/lwoHeader.I +++ b/pandatool/src/lwo/lwoHeader.I @@ -2,15 +2,3 @@ // Created by: drose (24Apr01) // //////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////// -// Function: LwoHeader::get_lwid -// Access: Public -// Description: Returns the Lightwave ID of the file. This is the -// first ID read within the header, and indicates the -// version of the Lightwave file in some mysterious way. -//////////////////////////////////////////////////////////////////// -IffId LwoHeader:: -get_lwid() const { - return _lwid; -} diff --git a/pandatool/src/lwo/lwoHeader.cxx b/pandatool/src/lwo/lwoHeader.cxx index a9e4bed6b7..9f63847c26 100644 --- a/pandatool/src/lwo/lwoHeader.cxx +++ b/pandatool/src/lwo/lwoHeader.cxx @@ -23,7 +23,7 @@ TypeHandle LwoHeader::_type_handle; bool LwoHeader:: read_iff(IffInputFile *in, size_t stop_at) { _lwid = in->get_id(); - return read_children_iff(in, stop_at); + return read_chunks_iff(in, stop_at); } //////////////////////////////////////////////////////////////////// @@ -36,8 +36,8 @@ write(ostream &out, int indent_level) const { indent(out, indent_level) << get_id() << " {\n"; indent(out, indent_level + 2) - << _lwid << "\n"; - write_children(out, indent_level + 2); + << "id = " << _lwid << "\n"; + write_chunks(out, indent_level + 2); indent(out, indent_level) << "}\n"; } diff --git a/pandatool/src/lwo/lwoHeader.h b/pandatool/src/lwo/lwoHeader.h index 7c2a2041a6..9235bbca88 100644 --- a/pandatool/src/lwo/lwoHeader.h +++ b/pandatool/src/lwo/lwoHeader.h @@ -16,14 +16,11 @@ //////////////////////////////////////////////////////////////////// class LwoHeader : public LwoGroupChunk { public: - INLINE IffId get_lwid() const; + IffId _lwid; public: virtual bool read_iff(IffInputFile *in, size_t stop_at); virtual void write(ostream &out, int indent_level = 0) const; - -private: - IffId _lwid; public: virtual TypeHandle get_type() const { diff --git a/pandatool/src/lwo/lwoInputFile.cxx b/pandatool/src/lwo/lwoInputFile.cxx index 2f5f880946..f905ad8df2 100644 --- a/pandatool/src/lwo/lwoInputFile.cxx +++ b/pandatool/src/lwo/lwoInputFile.cxx @@ -4,14 +4,17 @@ //////////////////////////////////////////////////////////////////// #include "lwoInputFile.h" +#include "lwoBoundingBox.h" +#include "lwoClip.h" #include "lwoDiscontinuousVertexMap.h" #include "lwoHeader.h" #include "lwoLayer.h" #include "lwoPoints.h" #include "lwoPolygons.h" #include "lwoPolygonTags.h" -#include "lwoVertexMap.h" #include "lwoTags.h" +#include "lwoSurface.h" +#include "lwoVertexMap.h" TypeHandle LwoInputFile::_type_handle; @@ -123,6 +126,15 @@ make_new_chunk(IffId id) { } else if (id == IffId("PTAG")) { return new LwoPolygonTags; + } else if (id == IffId("CLIP")) { + return new LwoClip; + + } else if (id == IffId("SURF")) { + return new LwoSurface; + + } else if (id == IffId("BBOX")) { + return new LwoBoundingBox; + } else { return IffInputFile::make_new_chunk(id); } diff --git a/pandatool/src/lwo/lwoInputFile.h b/pandatool/src/lwo/lwoInputFile.h index 4a71088c80..bc20fe7ede 100644 --- a/pandatool/src/lwo/lwoInputFile.h +++ b/pandatool/src/lwo/lwoInputFile.h @@ -47,8 +47,6 @@ private: static TypeHandle _type_handle; }; -#include "lwoInputFile.I" - #endif diff --git a/pandatool/src/lwo/lwoLayer.cxx b/pandatool/src/lwo/lwoLayer.cxx index 2e729e8e65..9c66210494 100644 --- a/pandatool/src/lwo/lwoLayer.cxx +++ b/pandatool/src/lwo/lwoLayer.cxx @@ -23,6 +23,7 @@ TypeHandle LwoLayer::_type_handle; bool LwoLayer:: read_iff(IffInputFile *in, size_t stop_at) { LwoInputFile *lin = DCAST(LwoInputFile, in); + _number = lin->get_be_uint16(); _flags = lin->get_be_uint16(); _pivot = lin->get_vec3(); diff --git a/pandatool/src/lwo/lwoLayer.h b/pandatool/src/lwo/lwoLayer.h index 1f14f7d142..8cbbec0b59 100644 --- a/pandatool/src/lwo/lwoLayer.h +++ b/pandatool/src/lwo/lwoLayer.h @@ -54,8 +54,6 @@ private: static TypeHandle _type_handle; }; -#include "lwoLayer.I" - #endif diff --git a/pandatool/src/lwo/lwoPoints.I b/pandatool/src/lwo/lwoPoints.I deleted file mode 100644 index 992e23ae9a..0000000000 --- a/pandatool/src/lwo/lwoPoints.I +++ /dev/null @@ -1,4 +0,0 @@ -// Filename: lwoPoints.I -// Created by: drose (24Apr01) -// -//////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/lwo/lwoPoints.h b/pandatool/src/lwo/lwoPoints.h index 820fce92fc..42a07ab51a 100644 --- a/pandatool/src/lwo/lwoPoints.h +++ b/pandatool/src/lwo/lwoPoints.h @@ -48,8 +48,6 @@ private: static TypeHandle _type_handle; }; -#include "lwoPoints.I" - #endif diff --git a/pandatool/src/lwo/lwoPolygonTags.I b/pandatool/src/lwo/lwoPolygonTags.I deleted file mode 100644 index a5d46822df..0000000000 --- a/pandatool/src/lwo/lwoPolygonTags.I +++ /dev/null @@ -1,4 +0,0 @@ -// Filename: lwoPolygonTags.I -// Created by: drose (24Apr01) -// -//////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/lwo/lwoPolygonTags.h b/pandatool/src/lwo/lwoPolygonTags.h index 2522940247..a8601b1850 100644 --- a/pandatool/src/lwo/lwoPolygonTags.h +++ b/pandatool/src/lwo/lwoPolygonTags.h @@ -50,8 +50,6 @@ private: static TypeHandle _type_handle; }; -#include "lwoPolygonTags.I" - #endif diff --git a/pandatool/src/lwo/lwoPolygons.I b/pandatool/src/lwo/lwoPolygons.I deleted file mode 100644 index d4c92f29f0..0000000000 --- a/pandatool/src/lwo/lwoPolygons.I +++ /dev/null @@ -1,4 +0,0 @@ -// Filename: lwoPolygons.I -// Created by: drose (24Apr01) -// -//////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/lwo/lwoPolygons.h b/pandatool/src/lwo/lwoPolygons.h index e92ab98f42..f4780c7ed5 100644 --- a/pandatool/src/lwo/lwoPolygons.h +++ b/pandatool/src/lwo/lwoPolygons.h @@ -65,8 +65,6 @@ private: static TypeHandle _type_handle; }; -#include "lwoPolygons.I" - #endif diff --git a/pandatool/src/lwo/lwoLayer.I b/pandatool/src/lwo/lwoStillImage.I similarity index 78% rename from pandatool/src/lwo/lwoLayer.I rename to pandatool/src/lwo/lwoStillImage.I index 876e46a87b..44a6e1b09e 100644 --- a/pandatool/src/lwo/lwoLayer.I +++ b/pandatool/src/lwo/lwoStillImage.I @@ -1,4 +1,4 @@ -// Filename: lwoLayer.I +// Filename: lwoStillImage.I // Created by: drose (24Apr01) // //////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/lwo/lwoStillImage.cxx b/pandatool/src/lwo/lwoStillImage.cxx new file mode 100644 index 0000000000..84ea07ad49 --- /dev/null +++ b/pandatool/src/lwo/lwoStillImage.cxx @@ -0,0 +1,41 @@ +// Filename: lwoStillImage.cxx +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#include "lwoStillImage.h" +#include "lwoInputFile.h" + +#include + +TypeHandle LwoStillImage::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: LwoStillImage::read_iff +// Access: Public, Virtual +// Description: Reads the data of the chunk in from the given input +// file, if possible. The ID and length of the chunk +// have already been read. stop_at is the byte position +// of the file to stop at (based on the current position +// at in->get_bytes_read()). Returns true on success, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool LwoStillImage:: +read_iff(IffInputFile *in, size_t stop_at) { + LwoInputFile *lin = DCAST(LwoInputFile, in); + + _filename = lin->get_filename(); + + return true; +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoStillImage::write +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +void LwoStillImage:: +write(ostream &out, int indent_level) const { + indent(out, indent_level) + << get_id() << " { filename = \"" << _filename << "\" }\n"; +} diff --git a/pandatool/src/lwo/lwoStillImage.h b/pandatool/src/lwo/lwoStillImage.h new file mode 100644 index 0000000000..1cd9243dcb --- /dev/null +++ b/pandatool/src/lwo/lwoStillImage.h @@ -0,0 +1,49 @@ +// Filename: lwoStillImage.h +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#ifndef LWOSTILLIMAGE_H +#define LWOSTILLIMAGE_H + +#include + +#include "lwoChunk.h" + +#include + +//////////////////////////////////////////////////////////////////// +// Class : LwoStillImage +// Description : A single still image associated with a LwoClip chunk. +//////////////////////////////////////////////////////////////////// +class LwoStillImage : public LwoChunk { +public: + Filename _filename; + +public: + virtual bool read_iff(IffInputFile *in, size_t stop_at); + virtual void write(ostream &out, int indent_level = 0) const; + +public: + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + LwoChunk::init_type(); + register_type(_type_handle, "LwoStillImage", + LwoChunk::get_class_type()); + } + +private: + static TypeHandle _type_handle; +}; + +#include "lwoStillImage.I" + +#endif + + diff --git a/pandatool/src/lwo/lwoChunk.I b/pandatool/src/lwo/lwoSurface.I similarity index 80% rename from pandatool/src/lwo/lwoChunk.I rename to pandatool/src/lwo/lwoSurface.I index 423029f5ea..0746a92c64 100644 --- a/pandatool/src/lwo/lwoChunk.I +++ b/pandatool/src/lwo/lwoSurface.I @@ -1,4 +1,4 @@ -// Filename: lwoChunk.I +// Filename: lwoSurface.I // Created by: drose (24Apr01) // //////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/lwo/lwoSurface.cxx b/pandatool/src/lwo/lwoSurface.cxx new file mode 100644 index 0000000000..93f0af7072 --- /dev/null +++ b/pandatool/src/lwo/lwoSurface.cxx @@ -0,0 +1,77 @@ +// Filename: lwoSurface.cxx +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#include "lwoSurface.h" +#include "iffInputFile.h" +#include "lwoSurfaceColor.h" +#include "lwoSurfaceParameter.h" + +#include + +TypeHandle LwoSurface::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: LwoSurface::read_iff +// Access: Public, Virtual +// Description: Reads the data of the chunk in from the given input +// file, if possible. The ID and length of the chunk +// have already been read. stop_at is the byte position +// of the file to stop at (based on the current position +// at in->get_bytes_read()). Returns true on success, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool LwoSurface:: +read_iff(IffInputFile *in, size_t stop_at) { + _name = in->get_string(); + _source = in->get_string(); + return read_subchunks_iff(in, stop_at); +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoSurface::write +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +void LwoSurface:: +write(ostream &out, int indent_level) const { + indent(out, indent_level) + << get_id() << " {\n"; + indent(out, indent_level + 2) + << "name = \"" << _name << "\", source = \"" << _source << "\"\n"; + write_chunks(out, indent_level + 2); + indent(out, indent_level) + << "}\n"; +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoSurface::make_new_chunk +// Access: Protected, Virtual +// Description: Allocates and returns a new chunk of the appropriate +// type based on the given ID, according to the context +// given by this chunk itself. +//////////////////////////////////////////////////////////////////// +IffChunk *LwoSurface:: +make_new_chunk(IffInputFile *in, IffId id) { + if (id == IffId("COLR")) { + return new LwoSurfaceColor; + + } else if (id == IffId("DIFF") || + id == IffId("LUMI") || + id == IffId("SPEC") || + id == IffId("REFL") || + id == IffId("TRAN") || + id == IffId("TRNL") || + id == IffId("GLOS") || + id == IffId("SHRP") || + id == IffId("BUMP") || + id == IffId("RSAN") || + id == IffId("RIND")) { + return new LwoSurfaceParameter; + + } else { + return IffChunk::make_new_chunk(in, id); + } +} + diff --git a/pandatool/src/lwo/lwoSurface.h b/pandatool/src/lwo/lwoSurface.h new file mode 100644 index 0000000000..f76e224b89 --- /dev/null +++ b/pandatool/src/lwo/lwoSurface.h @@ -0,0 +1,38 @@ +// Filename: lwoSurface.h +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#ifndef LWOSURFACE_H +#define LWOSURFACE_H + +#include + +#include "lwoGroupChunk.h" + +//////////////////////////////////////////////////////////////////// +// Class : LwoSurface +// Description : Describes the shading attributes of a surface. This +// is similar to the concept usually called a "material" +// in other file formats. +//////////////////////////////////////////////////////////////////// +class LwoSurface : public LwoGroupChunk { +public: + string _name; + string _source; + +public: + virtual bool read_iff(IffInputFile *in, size_t stop_at); + virtual void write(ostream &out, int indent_level = 0) const; + + virtual IffChunk *make_new_chunk(IffInputFile *in, IffId id); + +private: + static TypeHandle _type_handle; +}; + +#include "lwoSurface.I" + +#endif + + diff --git a/pandatool/src/lwo/lwoInputFile.I b/pandatool/src/lwo/lwoSurfaceColor.I similarity index 77% rename from pandatool/src/lwo/lwoInputFile.I rename to pandatool/src/lwo/lwoSurfaceColor.I index 093ff73a3a..92a0c844a7 100644 --- a/pandatool/src/lwo/lwoInputFile.I +++ b/pandatool/src/lwo/lwoSurfaceColor.I @@ -1,4 +1,4 @@ -// Filename: lwoInputFile.I +// Filename: lwoSurfaceColor.I // Created by: drose (24Apr01) // //////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/lwo/lwoSurfaceColor.cxx b/pandatool/src/lwo/lwoSurfaceColor.cxx new file mode 100644 index 0000000000..3a120596f5 --- /dev/null +++ b/pandatool/src/lwo/lwoSurfaceColor.cxx @@ -0,0 +1,43 @@ +// Filename: lwoSurfaceColor.cxx +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#include "lwoSurfaceColor.h" +#include "lwoInputFile.h" + +#include + +TypeHandle LwoSurfaceColor::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: LwoSurfaceColor::read_iff +// Access: Public, Virtual +// Description: Reads the data of the chunk in from the given input +// file, if possible. The ID and length of the chunk +// have already been read. stop_at is the byte position +// of the file to stop at (based on the current position +// at in->get_bytes_read()). Returns true on success, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool LwoSurfaceColor:: +read_iff(IffInputFile *in, size_t stop_at) { + LwoInputFile *lin = DCAST(LwoInputFile, in); + + _color = lin->get_vec3(); + _envelope = lin->get_vx(); + + return true; +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoSurfaceColor::write +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +void LwoSurfaceColor:: +write(ostream &out, int indent_level) const { + indent(out, indent_level) + << get_id() << " { color = " << _color + << ", envelope = " << _envelope << " }\n"; +} diff --git a/pandatool/src/lwo/lwoSurfaceColor.h b/pandatool/src/lwo/lwoSurfaceColor.h new file mode 100644 index 0000000000..c411915a85 --- /dev/null +++ b/pandatool/src/lwo/lwoSurfaceColor.h @@ -0,0 +1,51 @@ +// Filename: lwoSurfaceColor.h +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#ifndef LWOSURFACECOLOR_H +#define LWOSURFACECOLOR_H + +#include + +#include "lwoChunk.h" + +#include + +//////////////////////////////////////////////////////////////////// +// Class : LwoSurfaceColor +// Description : Records the base color of a surface, as an entry +// within a LwoSurface chunk. +//////////////////////////////////////////////////////////////////// +class LwoSurfaceColor : public LwoChunk { +public: + RGBColorf _color; + int _envelope; + +public: + virtual bool read_iff(IffInputFile *in, size_t stop_at); + virtual void write(ostream &out, int indent_level = 0) const; + +public: + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + LwoChunk::init_type(); + register_type(_type_handle, "LwoSurfaceColor", + LwoChunk::get_class_type()); + } + +private: + static TypeHandle _type_handle; +}; + +#include "lwoSurfaceColor.I" + +#endif + + diff --git a/pandatool/src/lwo/lwoSurfaceParameter.I b/pandatool/src/lwo/lwoSurfaceParameter.I new file mode 100644 index 0000000000..55948833b8 --- /dev/null +++ b/pandatool/src/lwo/lwoSurfaceParameter.I @@ -0,0 +1,4 @@ +// Filename: lwoSurfaceParameter.I +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/lwo/lwoSurfaceParameter.cxx b/pandatool/src/lwo/lwoSurfaceParameter.cxx new file mode 100644 index 0000000000..2ef59280c7 --- /dev/null +++ b/pandatool/src/lwo/lwoSurfaceParameter.cxx @@ -0,0 +1,43 @@ +// Filename: lwoSurfaceParameter.cxx +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#include "lwoSurfaceParameter.h" +#include "lwoInputFile.h" + +#include + +TypeHandle LwoSurfaceParameter::_type_handle; + +//////////////////////////////////////////////////////////////////// +// Function: LwoSurfaceParameter::read_iff +// Access: Public, Virtual +// Description: Reads the data of the chunk in from the given input +// file, if possible. The ID and length of the chunk +// have already been read. stop_at is the byte position +// of the file to stop at (based on the current position +// at in->get_bytes_read()). Returns true on success, +// false otherwise. +//////////////////////////////////////////////////////////////////// +bool LwoSurfaceParameter:: +read_iff(IffInputFile *in, size_t stop_at) { + LwoInputFile *lin = DCAST(LwoInputFile, in); + + _value = lin->get_be_float32(); + _envelope = lin->get_vx(); + + return true; +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoSurfaceParameter::write +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +void LwoSurfaceParameter:: +write(ostream &out, int indent_level) const { + indent(out, indent_level) + << get_id() << " { value = " << _value + << ", envelope = " << _envelope << " }\n"; +} diff --git a/pandatool/src/lwo/lwoSurfaceParameter.h b/pandatool/src/lwo/lwoSurfaceParameter.h new file mode 100644 index 0000000000..cd9931ae9e --- /dev/null +++ b/pandatool/src/lwo/lwoSurfaceParameter.h @@ -0,0 +1,50 @@ +// Filename: lwoSurfaceParameter.h +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#ifndef LWOSURFACEPARAMETER_H +#define LWOSURFACEPARAMETER_H + +#include + +#include "lwoChunk.h" + +//////////////////////////////////////////////////////////////////// +// Class : LwoSurfaceParameter +// Description : Records some parameter value of a surface material, +// as an entry within a LwoSurface chunk. The meaning +// of the value is determined by the id of this chunk. +//////////////////////////////////////////////////////////////////// +class LwoSurfaceParameter : public LwoChunk { +public: + float _value; + int _envelope; + +public: + virtual bool read_iff(IffInputFile *in, size_t stop_at); + virtual void write(ostream &out, int indent_level = 0) const; + +public: + virtual TypeHandle get_type() const { + return get_class_type(); + } + virtual TypeHandle force_init_type() {init_type(); return get_class_type();} + static TypeHandle get_class_type() { + return _type_handle; + } + static void init_type() { + LwoChunk::init_type(); + register_type(_type_handle, "LwoSurfaceParameter", + LwoChunk::get_class_type()); + } + +private: + static TypeHandle _type_handle; +}; + +#include "lwoSurfaceParameter.I" + +#endif + + diff --git a/pandatool/src/lwo/lwoTags.cxx b/pandatool/src/lwo/lwoTags.cxx index 1d3e8d5a10..c3744dcfd8 100644 --- a/pandatool/src/lwo/lwoTags.cxx +++ b/pandatool/src/lwo/lwoTags.cxx @@ -65,10 +65,10 @@ write(ostream &out, int indent_level) const { if (!_tags.empty()) { Tags::const_iterator ti = _tags.begin(); - out << *ti; + out << '"' << *ti << '"'; ++ti; while (ti != _tags.end()) { - out << ", " << *ti; + out << ", \"" << *ti << '"'; ++ti; } } diff --git a/pandatool/src/lwo/lwoTags.h b/pandatool/src/lwo/lwoTags.h index 52338e5ddc..a5d3ea23dc 100644 --- a/pandatool/src/lwo/lwoTags.h +++ b/pandatool/src/lwo/lwoTags.h @@ -49,8 +49,6 @@ private: static TypeHandle _type_handle; }; -#include "lwoTags.I" - #endif diff --git a/pandatool/src/lwo/lwoVertexMap.I b/pandatool/src/lwo/lwoVertexMap.I deleted file mode 100644 index b3e41b913b..0000000000 --- a/pandatool/src/lwo/lwoVertexMap.I +++ /dev/null @@ -1,4 +0,0 @@ -// Filename: lwoVertexMap.I -// Created by: drose (24Apr01) -// -//////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/lwo/lwoVertexMap.h b/pandatool/src/lwo/lwoVertexMap.h index 67ea493a82..338dc8cfb0 100644 --- a/pandatool/src/lwo/lwoVertexMap.h +++ b/pandatool/src/lwo/lwoVertexMap.h @@ -53,8 +53,6 @@ private: static TypeHandle _type_handle; }; -#include "lwoVertexMap.I" - #endif