Kaynağa Gözat

*** empty log message ***

David Rose 24 yıl önce
ebeveyn
işleme
c4a8d6e24b

+ 1 - 1
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) {

+ 1 - 1
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);

+ 1 - 1
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 \

+ 0 - 15
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

+ 0 - 10
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

+ 0 - 3
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;

+ 48 - 8
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 &centroid) const {
 //               using a cubic projection.
 ////////////////////////////////////////////////////////////////////
 LPoint2d CLwoSurface::
-map_cubic(const LPoint3d &pos, const LPoint3d &) const {
+map_cubic(const LPoint3d &pos, const LPoint3d &centroid) 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;
   

+ 1 - 1
pandatool/src/lwoegg/cLwoSurface.h

@@ -81,7 +81,7 @@ private:
   LPoint2d map_cubic(const LPoint3d &pos, const LPoint3d &centroid) const;
 
   // Define a pointer to one of the above member functions.
-  LPoint2d (CLwoSurface::*_map_uv)(const LPoint3d &pos, const LPoint3d &centroid) const;
+  LPoint2d (CLwoSurface::*_map_uvs)(const LPoint3d &pos, const LPoint3d &centroid) const;
 };
 
 #include "cLwoSurface.I"

+ 23 - 0
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

+ 80 - 0
pandatool/src/lwoprogs/lwoScan.cxx

@@ -0,0 +1,80 @@
+// Filename: test_lwo.cxx
+// Created by:  drose (24Apr01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#include "lwoScan.h"
+
+#include <lwoInputFile.h>
+#include <lwoChunk.h>
+#include <config_lwo.h>
+
+////////////////////////////////////////////////////////////////////
+//     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;
+}

+ 30 - 0
pandatool/src/lwoprogs/lwoScan.h

@@ -0,0 +1,30 @@
+// Filename: lwoScan.h
+// Created by:  drose (30Apr01)
+// 
+////////////////////////////////////////////////////////////////////
+
+#ifndef LWOSCAN_H
+#define LWOSCAN_H
+
+#include <programBase.h>
+#include <filename.h>
+
+////////////////////////////////////////////////////////////////////
+// 	 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
+

+ 0 - 0
pandatool/src/eggprogs/lwoToEgg.cxx → pandatool/src/lwoprogs/lwoToEgg.cxx


+ 0 - 0
pandatool/src/eggprogs/lwoToEgg.h → pandatool/src/lwoprogs/lwoToEgg.h