From c4a8d6e24b6ea8b08ebb83aaaee939ec7232c960 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 30 Apr 2001 16:49:58 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/linmath/lmatrix4_src.I | 2 +- panda/src/linmath/lmatrix4_src.h | 2 +- pandatool/src/eggbase/Sources.pp | 2 +- pandatool/src/eggprogs/Sources.pp | 15 ---- pandatool/src/lwo/Sources.pp | 10 --- pandatool/src/lwo/lwoSurfaceBlockTMap.h | 3 - pandatool/src/lwoegg/cLwoSurface.cxx | 56 +++++++++++-- pandatool/src/lwoegg/cLwoSurface.h | 2 +- pandatool/src/lwoprogs/Sources.pp | 23 ++++++ pandatool/src/lwoprogs/lwoScan.cxx | 80 +++++++++++++++++++ pandatool/src/lwoprogs/lwoScan.h | 30 +++++++ .../src/{eggprogs => lwoprogs}/lwoToEgg.cxx | 0 .../src/{eggprogs => lwoprogs}/lwoToEgg.h | 0 13 files changed, 185 insertions(+), 40 deletions(-) create mode 100644 pandatool/src/lwoprogs/Sources.pp create mode 100644 pandatool/src/lwoprogs/lwoScan.cxx create mode 100644 pandatool/src/lwoprogs/lwoScan.h rename pandatool/src/{eggprogs => lwoprogs}/lwoToEgg.cxx (100%) rename pandatool/src/{eggprogs => lwoprogs}/lwoToEgg.h (100%) diff --git a/panda/src/linmath/lmatrix4_src.I b/panda/src/linmath/lmatrix4_src.I index bb420adb32..9c68ad61f9 100644 --- a/panda/src/linmath/lmatrix4_src.I +++ b/panda/src/linmath/lmatrix4_src.I @@ -1117,7 +1117,7 @@ translate_mat(FLOATTYPE tx, FLOATTYPE ty, FLOATTYPE tz) { // degrees counterclockwise about the indicated vector. //////////////////////////////////////////////////////////////////// INLINE_LINMATH FLOATNAME(LMatrix4) FLOATNAME(LMatrix4):: -rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) &axis, +rotate_mat(FLOATTYPE angle, FLOATNAME(LVecBase3) axis, CoordinateSystem cs) { if (cs == CS_default) { diff --git a/panda/src/linmath/lmatrix4_src.h b/panda/src/linmath/lmatrix4_src.h index 8ef783d216..87022fef18 100644 --- a/panda/src/linmath/lmatrix4_src.h +++ b/panda/src/linmath/lmatrix4_src.h @@ -106,7 +106,7 @@ PUBLISHED: INLINE_LINMATH static FLOATNAME(LMatrix4) translate_mat(const FLOATNAME(LVecBase3) &trans); INLINE_LINMATH static FLOATNAME(LMatrix4) translate_mat(FLOATTYPE tx, FLOATTYPE ty, FLOATTYPE tz); INLINE_LINMATH static FLOATNAME(LMatrix4) rotate_mat(FLOATTYPE angle, - FLOATNAME(LVecBase3) &axis, + FLOATNAME(LVecBase3) axis, CoordinateSystem cs = CS_default); INLINE_LINMATH static FLOATNAME(LMatrix4) scale_mat(const FLOATNAME(LVecBase3) &scale); INLINE_LINMATH static FLOATNAME(LMatrix4) scale_mat(FLOATTYPE sx, FLOATTYPE sy, FLOATTYPE sz); diff --git a/pandatool/src/eggbase/Sources.pp b/pandatool/src/eggbase/Sources.pp index a22470a016..319d0296f2 100644 --- a/pandatool/src/eggbase/Sources.pp +++ b/pandatool/src/eggbase/Sources.pp @@ -3,7 +3,7 @@ #define LOCAL_LIBS \ progbase #define OTHER_LIBS \ - egg:c panda:m + egg:c linmath:c panda:m #define SOURCES \ eggBase.cxx eggBase.h \ diff --git a/pandatool/src/eggprogs/Sources.pp b/pandatool/src/eggprogs/Sources.pp index bceb27d27f..f83f49212a 100644 --- a/pandatool/src/eggprogs/Sources.pp +++ b/pandatool/src/eggprogs/Sources.pp @@ -29,18 +29,3 @@ eggTopstrip.cxx eggTopstrip.h #end bin_target - -#begin bin_target - #define TARGET lwo2egg - #define LOCAL_LIBS lwo lwoegg eggbase progbase - - #define OTHER_LIBS \ - egg:c pandaegg:m \ - linmath:c panda:m \ - express:c pandaexpress:m \ - dtoolutil:c dconfig:c dtoolconfig:m dtool:m pystub - - #define SOURCES \ - lwoToEgg.cxx lwoToEgg.h - -#end bin_target diff --git a/pandatool/src/lwo/Sources.pp b/pandatool/src/lwo/Sources.pp index 56e3b692ea..cf2e9f1772 100644 --- a/pandatool/src/lwo/Sources.pp +++ b/pandatool/src/lwo/Sources.pp @@ -83,13 +83,3 @@ lwoVertexMap.h #end ss_lib_target - -#begin test_bin_target - #define TARGET test_lwo - #define LOCAL_LIBS lwo $[LOCAL_LIBS] - #define OTHER_LIBS $[OTHER_LIBS] pystub:c - - #define SOURCES \ - test_lwo.cxx - -#end test_bin_target diff --git a/pandatool/src/lwo/lwoSurfaceBlockTMap.h b/pandatool/src/lwo/lwoSurfaceBlockTMap.h index 8328936a93..8802a891fc 100644 --- a/pandatool/src/lwo/lwoSurfaceBlockTMap.h +++ b/pandatool/src/lwo/lwoSurfaceBlockTMap.h @@ -15,9 +15,6 @@ // Description : The tMap chunk within a LwoSurfaceBlock chunk. //////////////////////////////////////////////////////////////////// class LwoSurfaceBlockTMap : public LwoGroupChunk { -public: - string _ordinal; - public: virtual bool read_iff(IffInputFile *in, size_t stop_at); virtual void write(ostream &out, int indent_level = 0) const; diff --git a/pandatool/src/lwoegg/cLwoSurface.cxx b/pandatool/src/lwoegg/cLwoSurface.cxx index 65fbc0a349..5a788babbc 100644 --- a/pandatool/src/lwoegg/cLwoSurface.cxx +++ b/pandatool/src/lwoegg/cLwoSurface.cxx @@ -31,6 +31,7 @@ CLwoSurface(LwoToEggConverter *converter, const LwoSurface *surface) : _flags = 0; _checked_texture = false; _has_uvs = false; + _map_uvs = NULL; _block = (CLwoSurfaceBlock *)NULL; // Walk through the chunk list, looking for some basic properties. @@ -207,6 +208,8 @@ check_texture() { } _checked_texture = true; _egg_texture = (EggTexture *)NULL; + _has_uvs = false; + _map_uvs = NULL; if (_block == (CLwoSurfaceBlock *)NULL) { // No texture. Not even a shader block. @@ -233,7 +236,41 @@ check_texture() { Filename pathname = _converter->convert_texture_path(clip->_filename); _egg_texture = new EggTexture("clip" + format_string(clip_index), pathname); - _has_uvs = true; + + // Do we need to generate UV's? + switch (_block->_projection_mode) { + case LwoSurfaceBlockProjection::M_planar: + _has_uvs = true; + _map_uvs = &CLwoSurface::map_planar; + break; + + case LwoSurfaceBlockProjection::M_cylindrical: + _has_uvs = true; + _map_uvs = &CLwoSurface::map_cylindrical; + break; + + case LwoSurfaceBlockProjection::M_spherical: + _has_uvs = true; + _map_uvs = &CLwoSurface::map_spherical; + break; + + case LwoSurfaceBlockProjection::M_cubic: + _has_uvs = true; + _map_uvs = &CLwoSurface::map_cubic; + break; + + case LwoSurfaceBlockProjection::M_front: + // Cannot generate "front" UV's, since this depends on a camera. + // Is it supposed to be updated in real time, like a projected + // texture? + break; + + case LwoSurfaceBlockProjection::M_uv: + // "uv" projection means to use the existing UV's already defined + // for the vertex. This case was already handled in the code that + // created the EggVertex pointers. + break; + }; return true; } @@ -247,6 +284,8 @@ check_texture() { //////////////////////////////////////////////////////////////////// void CLwoSurface:: generate_uvs(vector_PT_EggVertex &egg_vertices) { + nassertv(_map_uvs != NULL); + // To do this properly near seams and singularities (for instance, // the back seam and the poles of the spherical map), we will need // to know the polygon's centroid. @@ -264,10 +303,10 @@ generate_uvs(vector_PT_EggVertex &egg_vertices) { for (vi = egg_vertices.begin(); vi != egg_vertices.end(); ++vi) { EggVertex *egg_vertex = (*vi); LPoint3d pos = egg_vertex->get_pos3(); - egg_vertex->set_uv(map_spherical(pos, centroid)); + LPoint2d uv = (this->*_map_uvs)(pos, centroid); + egg_vertex->set_uv(uv); } } - //////////////////////////////////////////////////////////////////// // Function: CLwoSurface::map_planar @@ -379,13 +418,14 @@ map_cylindrical(const LPoint3d &pos, const LPoint3d ¢roid) const { // using a cubic projection. //////////////////////////////////////////////////////////////////// LPoint2d CLwoSurface:: -map_cubic(const LPoint3d &pos, const LPoint3d &) const { +map_cubic(const LPoint3d &pos, const LPoint3d ¢roid) const { // A cubic projection is a planar projection, but we eliminate the - // dominant axis instead of arbitrarily eliminating Y. + // dominant axis (based on the polygon's centroid) instead of + // arbitrarily eliminating Y. - double x = fabs(pos[0]); - double y = fabs(pos[1]); - double z = fabs(pos[2]); + double x = fabs(centroid[0]); + double y = fabs(centroid[1]); + double z = fabs(centroid[2]); double u, v; diff --git a/pandatool/src/lwoegg/cLwoSurface.h b/pandatool/src/lwoegg/cLwoSurface.h index f540f62141..5a19bce6dd 100644 --- a/pandatool/src/lwoegg/cLwoSurface.h +++ b/pandatool/src/lwoegg/cLwoSurface.h @@ -81,7 +81,7 @@ private: LPoint2d map_cubic(const LPoint3d &pos, const LPoint3d ¢roid) const; // Define a pointer to one of the above member functions. - LPoint2d (CLwoSurface::*_map_uv)(const LPoint3d &pos, const LPoint3d ¢roid) const; + LPoint2d (CLwoSurface::*_map_uvs)(const LPoint3d &pos, const LPoint3d ¢roid) const; }; #include "cLwoSurface.I" diff --git a/pandatool/src/lwoprogs/Sources.pp b/pandatool/src/lwoprogs/Sources.pp new file mode 100644 index 0000000000..93344fe1f1 --- /dev/null +++ b/pandatool/src/lwoprogs/Sources.pp @@ -0,0 +1,23 @@ +#begin bin_target + #define TARGET lwo2egg + #define LOCAL_LIBS lwo lwoegg eggbase progbase + + #define OTHER_LIBS \ + egg:c pandaegg:m \ + linmath:c panda:m \ + express:c pandaexpress:m \ + dtoolutil:c dconfig:c dtoolconfig:m dtool:m pystub + + #define SOURCES \ + lwoToEgg.cxx lwoToEgg.h + +#end bin_target + +#begin bin_target + #define TARGET lwo-scan + #define LOCAL_LIBS lwo progbase + + #define SOURCES \ + lwoScan.cxx lwoScan.h + +#end bin_target diff --git a/pandatool/src/lwoprogs/lwoScan.cxx b/pandatool/src/lwoprogs/lwoScan.cxx new file mode 100644 index 0000000000..5695a90330 --- /dev/null +++ b/pandatool/src/lwoprogs/lwoScan.cxx @@ -0,0 +1,80 @@ +// Filename: test_lwo.cxx +// Created by: drose (24Apr01) +// +//////////////////////////////////////////////////////////////////// + +#include "lwoScan.h" + +#include +#include +#include + +//////////////////////////////////////////////////////////////////// +// Function: LwoScan::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +LwoScan:: +LwoScan() { + clear_runlines(); + add_runline("[opts] input.lwo"); + + set_program_description + ("This program simply reads a Lightwave object file and dumps its " + "contents to standard output. It's mainly useful for debugging " + "problems with lwo2egg."); +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoScan::run +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +void LwoScan:: +run() { + LwoInputFile in; + if (!in.open_read(_input_filename)) { + nout << "Unable to open " << _input_filename << "\n"; + exit(1); + } + + PT(IffChunk) chunk = in.get_chunk(); + if (chunk == (IffChunk *)NULL) { + nout << "Unable to read file.\n"; + } else { + while (chunk != (IffChunk *)NULL) { + chunk->write(cout, 0); + chunk = in.get_chunk(); + } + } +} + +//////////////////////////////////////////////////////////////////// +// Function: LwoScan::handle_args +// Access: Protected, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +bool LwoScan:: +handle_args(ProgramBase::Args &args) { + if (args.empty()) { + nout << "You must specify the Lightwave object file to read on the command line.\n"; + return false; + } + if (args.size() != 1) { + nout << "You may specify only one Lightwave object file to read on the command line.\n"; + return false; + } + + _input_filename = args[0]; + + return true; +} + + +int +main(int argc, char *argv[]) { + LwoScan prog; + prog.parse_command_line(argc, argv); + prog.run(); + return 0; +} diff --git a/pandatool/src/lwoprogs/lwoScan.h b/pandatool/src/lwoprogs/lwoScan.h new file mode 100644 index 0000000000..e48edcc0aa --- /dev/null +++ b/pandatool/src/lwoprogs/lwoScan.h @@ -0,0 +1,30 @@ +// Filename: lwoScan.h +// Created by: drose (30Apr01) +// +//////////////////////////////////////////////////////////////////// + +#ifndef LWOSCAN_H +#define LWOSCAN_H + +#include +#include + +//////////////////////////////////////////////////////////////////// +// Class : LwoScan +// Description : A program to read a Lightwave file and report its +// structure and contents. +//////////////////////////////////////////////////////////////////// +class LwoScan : public ProgramBase { +public: + LwoScan(); + + void run(); + +protected: + virtual bool handle_args(Args &args); + + Filename _input_filename; +}; + +#endif + diff --git a/pandatool/src/eggprogs/lwoToEgg.cxx b/pandatool/src/lwoprogs/lwoToEgg.cxx similarity index 100% rename from pandatool/src/eggprogs/lwoToEgg.cxx rename to pandatool/src/lwoprogs/lwoToEgg.cxx diff --git a/pandatool/src/eggprogs/lwoToEgg.h b/pandatool/src/lwoprogs/lwoToEgg.h similarity index 100% rename from pandatool/src/eggprogs/lwoToEgg.h rename to pandatool/src/lwoprogs/lwoToEgg.h