Browse Source

support 14.0 files

David Rose 23 years ago
parent
commit
732f747bee

+ 7 - 5
pandatool/src/flt/Sources.pp

@@ -21,8 +21,9 @@
      fltTransformPut.h fltTransformRecord.h  \
      fltTransformRotateAboutEdge.h fltTransformRotateAboutPoint.h  \
      fltTransformRotateScale.h fltTransformScale.h  \
-     fltTransformTranslate.h fltUnsupportedRecord.h fltVertex.I  \
-     fltVertex.h fltVertexList.h 
+     fltTransformTranslate.h fltUnsupportedRecord.h \
+     fltVectorRecord.cxx fltVectorRecord.h \
+     fltVertex.I fltVertex.h fltVertexList.h 
     
  #define INCLUDED_SOURCES \
      config_flt.cxx fltBead.cxx fltBeadID.cxx fltCurve.cxx  \
@@ -38,7 +39,8 @@
      fltTransformRotateAboutEdge.cxx  \
      fltTransformRotateAboutPoint.cxx fltTransformRotateScale.cxx  \
      fltTransformScale.cxx fltTransformTranslate.cxx  \
-     fltUnsupportedRecord.cxx fltVertex.cxx fltVertexList.cxx 
+     fltUnsupportedRecord.cxx fltVectorRecord.cxx \
+     fltVertex.cxx fltVertexList.cxx 
 
   #define INSTALL_HEADERS \
     fltBead.h fltBeadID.h fltCurve.I fltCurve.h \
@@ -55,7 +57,7 @@
     fltTransformGeneralMatrix.h fltTransformPut.h fltTransformRecord.h \
     fltTransformRotateAboutEdge.h fltTransformRotateAboutPoint.h \
     fltTransformRotateScale.h fltTransformScale.h \
-    fltTransformTranslate.h fltUnsupportedRecord.h fltVertex.I \
-    fltVertex.h fltVertexList.h
+    fltTransformTranslate.h fltUnsupportedRecord.h fltVectorRecord.h \
+    fltVertex.I fltVertex.h fltVertexList.h
 
 #end ss_lib_target

+ 2 - 0
pandatool/src/flt/config_flt.cxx

@@ -28,6 +28,7 @@
 #include "fltMesh.h"
 #include "fltLocalVertexPool.h"
 #include "fltMeshPrimitive.h"
+#include "fltVectorRecord.h"
 #include "fltVertexList.h"
 #include "fltLOD.h"
 #include "fltInstanceDefinition.h"
@@ -91,6 +92,7 @@ init_libflt() {
   FltMesh::init_type();
   FltLocalVertexPool::init_type();
   FltMeshPrimitive::init_type();
+  FltVectorRecord::init_type();
   FltVertexList::init_type();
   FltLOD::init_type();
   FltInstanceDefinition::init_type();

+ 19 - 17
pandatool/src/flt/fltGeometry.cxx

@@ -187,24 +187,26 @@ extract_record(FltRecordReader &reader) {
   _transparency = iterator.get_be_uint16();
   _lod_generation_control = iterator.get_uint8();
   _line_style_index = iterator.get_uint8();
-  _flags = iterator.get_be_uint32();
-  _light_mode = (LightMode)iterator.get_uint8();
-  iterator.skip_bytes(1 + 4);
-  iterator.skip_bytes(2); // Undocumented padding.
+  if (_header->get_flt_version() >= 1420) {
+    _flags = iterator.get_be_uint32();
+    _light_mode = (LightMode)iterator.get_uint8();
+    iterator.skip_bytes(1 + 4);
+    iterator.skip_bytes(2); // Undocumented padding.
 
-  if (!_packed_color.extract_record(reader)) {
-    return false;
-  }
-  if (!_alt_packed_color.extract_record(reader)) {
-    return false;
-  }
-
-  if (_header->get_flt_version() >= 1520) {
-    _texture_mapping_index = iterator.get_be_int16();
-    iterator.skip_bytes(2);
-    _color_index = iterator.get_be_int32();
-    _alt_color_index = iterator.get_be_int32();
-    iterator.skip_bytes(2 + 2);
+    if (!_packed_color.extract_record(reader)) {
+      return false;
+    }
+    if (!_alt_packed_color.extract_record(reader)) {
+      return false;
+    }
+    
+    if (_header->get_flt_version() >= 1520) {
+      _texture_mapping_index = iterator.get_be_int16();
+      iterator.skip_bytes(2);
+      _color_index = iterator.get_be_int32();
+      _alt_color_index = iterator.get_be_int32();
+      iterator.skip_bytes(2 + 2);
+    }
   }
 
   return true;

+ 4 - 1
pandatool/src/flt/fltGroup.cxx

@@ -61,7 +61,10 @@ extract_record(FltRecordReader &reader) {
   _special_id2 = iterator.get_be_int16();
   _significance = iterator.get_be_int16();
   _layer_id = iterator.get_int8();
-  iterator.skip_bytes(5);
+  iterator.skip_bytes(1);
+  if (_header->get_flt_version() >= 1420) {
+    iterator.skip_bytes(4);
+  }
 
   check_remaining_size(iterator);
   return true;

+ 35 - 27
pandatool/src/flt/fltHeader.cxx

@@ -272,7 +272,7 @@ set_flt_version(int version) {
 ////////////////////////////////////////////////////////////////////
 int FltHeader::
 min_flt_version() {
-  return 1420;
+  return 1400;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -303,7 +303,7 @@ check_version() const {
 
   if (version < min_flt_version()) {
     nout << "Warning!  The version number of this file appears to be "
-         << version << ", which is older than " << min_flt_version() / 100.0
+         << version / 100.0 << ", which is older than " << min_flt_version() / 100.0
          << ", the oldest OpenFlight version understood by this program.  "
       "It is unlikely that this program will be able to read the file "
       "correctly.\n";
@@ -312,7 +312,7 @@ check_version() const {
 
   if (version > max_flt_version()) {
     nout << "Warning!  The version number of this file appears to be "
-         << version << ", which is newer than " << max_flt_version() / 100.0
+         << version / 100.0 << ", which is newer than " << max_flt_version() / 100.0
          << ", the newest OpenFlight version understood by this program.  "
       "Chances are good that the program will still be able to read it "
       "correctly, but any features in the file that are specific to "
@@ -1214,29 +1214,31 @@ extract_record(FltRecordReader &reader) {
   _lambert_lower_lat = iterator.get_be_float64();
   _next_light_id = iterator.get_be_int16();
   iterator.skip_bytes(2);
-  _next_road_id = iterator.get_be_int16();
-  _next_cat_id = iterator.get_be_int16();
-
-  if (get_flt_version() >= 1520 && iterator.get_remaining_size() > 0) {
-    iterator.skip_bytes(2 + 2 + 2 + 2);
-    _earth_model = (EarthModel)iterator.get_be_int32();
-
-    // Undocumented padding.
-    iterator.skip_bytes(4);
-
-    if (get_flt_version() >= 1560 && iterator.get_remaining_size() > 0) {
-      _next_adaptive_id = iterator.get_be_int16();
-      _next_curve_id = iterator.get_be_int16();
+  if (get_flt_version() >= 1420 && iterator.get_remaining_size() > 0) {
+    _next_road_id = iterator.get_be_int16();
+    _next_cat_id = iterator.get_be_int16();
+
+    if (get_flt_version() >= 1520 && iterator.get_remaining_size() > 0) {
+      iterator.skip_bytes(2 + 2 + 2 + 2);
+      _earth_model = (EarthModel)iterator.get_be_int32();
+      
+      // Undocumented padding.
       iterator.skip_bytes(4);
-
-      if (get_flt_version() >= 1570 && iterator.get_remaining_size() > 0) {
-        _delta_z = iterator.get_be_float64();
-        _radius = iterator.get_be_float64();
-        _next_mesh_id = iterator.get_be_int16();
-        iterator.skip_bytes(2);
-
-        // Undocumented padding.
+      
+      if (get_flt_version() >= 1560 && iterator.get_remaining_size() > 0) {
+        _next_adaptive_id = iterator.get_be_int16();
+        _next_curve_id = iterator.get_be_int16();
         iterator.skip_bytes(4);
+        
+        if (get_flt_version() >= 1570 && iterator.get_remaining_size() > 0) {
+          _delta_z = iterator.get_be_float64();
+          _radius = iterator.get_be_float64();
+          _next_mesh_id = iterator.get_be_int16();
+          iterator.skip_bytes(2);
+          
+          // Undocumented padding.
+          iterator.skip_bytes(4);
+        }
       }
     }
   }
@@ -1495,7 +1497,7 @@ extract_color_palette(FltRecordReader &reader) {
     }
   }
 
-  check_remaining_size(iterator);
+  check_remaining_size(iterator, "color palette");
   return true;
 }
 
@@ -1545,7 +1547,7 @@ extract_14_material_palette(FltRecordReader &reader) {
     add_material(material);
   }
 
-  check_remaining_size(iterator);
+  check_remaining_size(iterator, "material palette");
   return true;
 }
 
@@ -1631,7 +1633,13 @@ extract_eyepoint_palette(FltRecordReader &reader) {
   }
 
   _got_eyepoint_trackplane_palette = true;
-  check_remaining_size(iterator);
+
+  if (get_flt_version() >= 1420) {
+    // I have no idea what bytes are supposed to be here in earlier
+    // versions that 14.2, but who really cares?  Don't bother
+    // reporting it if there are too many bytes in old versions.
+    check_remaining_size(iterator, "eyepoint palette");
+  }
   return true;
 }
 

+ 12 - 3
pandatool/src/flt/fltRecord.cxx

@@ -313,14 +313,20 @@ set_comment(const string &comment) {
 //               exactly the sort of thing we expect.
 ////////////////////////////////////////////////////////////////////
 void FltRecord::
-check_remaining_size(const DatagramIterator &di) const {
+check_remaining_size(const DatagramIterator &di, const string &name) const {
   if (di.get_remaining_size() == 0) {
     return;
   }
 
   if (_header->get_flt_version() <= _header->max_flt_version()) {
     nout << "Warning!  Ignoring extra " << di.get_remaining_size()
-         << " bytes at the end of a " << get_type() << " record.\n";
+         << " bytes at the end of a ";
+    if (name.empty()) {
+      nout << get_type();
+    } else {
+      nout << name;
+    }
+    nout << " record.\n";
   }
 }
 
@@ -533,8 +539,11 @@ create_new_record(FltOpcode opcode) const {
   case FO_external_ref:
     return new FltExternalReference(_header);
 
+  case FO_vector:
+    return new FltVectorRecord(_header);
+
   default:
-    nout << "Unsupported record " << opcode << "\n";
+    nout << "Ignoring unsupported record " << opcode << "\n";
     return new FltUnsupportedRecord(_header);
   }
 }

+ 2 - 1
pandatool/src/flt/fltRecord.h

@@ -71,7 +71,8 @@ public:
   void clear_comment();
   void set_comment(const string &comment);
 
-  void check_remaining_size(const DatagramIterator &di) const;
+  void check_remaining_size(const DatagramIterator &di, 
+                            const string &name = string()) const;
 
   virtual void output(ostream &out) const;
   virtual void write(ostream &out, int indent_level = 0) const;

+ 5 - 1
pandatool/src/flt/fltTexture.cxx

@@ -218,7 +218,11 @@ extract_record(FltRecordReader &reader) {
   nassertr(reader.get_opcode() == FO_texture, false);
   DatagramIterator &iterator = reader.get_iterator();
 
-  _filename = iterator.get_fixed_string(200);
+  if (_header->get_flt_version() < 1420) {
+    _filename = iterator.get_fixed_string(80);
+  } else {
+    _filename = iterator.get_fixed_string(200);
+  }
   _pattern_index = iterator.get_be_int32();
   _x_location = iterator.get_be_int32();
   _y_location = iterator.get_be_int32();

+ 93 - 0
pandatool/src/flt/fltVectorRecord.cxx

@@ -0,0 +1,93 @@
+// Filename: fltVectorRecord.cxx
+// Created by:  drose (30Aug02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#include "fltVectorRecord.h"
+#include "fltRecordReader.h"
+#include "fltRecordWriter.h"
+
+TypeHandle FltVectorRecord::_type_handle;
+
+////////////////////////////////////////////////////////////////////
+//     Function: FltVectorRecord::Constructor
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+FltVectorRecord::
+FltVectorRecord(FltHeader *header) : FltRecord(header) {
+  _vector.set(0.0f, 0.0f, 0.0f);
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FltVectorRecord::get_vector
+//       Access: Public
+//  Description: Returns the vector value.
+////////////////////////////////////////////////////////////////////
+const LVector3f &FltVectorRecord::
+get_vector() const {
+  return _vector;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FltVectorRecord::extract_record
+//       Access: Protected, Virtual
+//  Description: Fills in the information in this record based on the
+//               information given in the indicated datagram, whose
+//               opcode has already been read.  Returns true on
+//               success, false if the datagram is invalid.
+////////////////////////////////////////////////////////////////////
+bool FltVectorRecord::
+extract_record(FltRecordReader &reader) {
+  if (!FltRecord::extract_record(reader)) {
+    return false;
+  }
+
+  nassertr(reader.get_opcode() == FO_vector, false);
+  DatagramIterator &iterator = reader.get_iterator();
+
+  _vector[0] = iterator.get_be_float32();
+  _vector[1] = iterator.get_be_float32();
+  _vector[2] = iterator.get_be_float32();
+
+  check_remaining_size(iterator);
+  return true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: FltVectorRecord::build_record
+//       Access: Protected, Virtual
+//  Description: Fills up the current record on the FltRecordWriter with
+//               data for this record, but does not advance the
+//               writer.  Returns true on success, false if there is
+//               some error.
+////////////////////////////////////////////////////////////////////
+bool FltVectorRecord::
+build_record(FltRecordWriter &writer) const {
+  if (!FltRecord::build_record(writer)) {
+    return false;
+  }
+
+  writer.set_opcode(FO_vector);
+  Datagram &datagram = writer.update_datagram();
+
+  datagram.add_be_float32(_vector[0]);
+  datagram.add_be_float32(_vector[1]);
+  datagram.add_be_float32(_vector[2]);
+
+  return true;
+}
+

+ 70 - 0
pandatool/src/flt/fltVectorRecord.h

@@ -0,0 +1,70 @@
+// Filename: fltVectorRecord.h
+// Created by:  drose (30Aug02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// PANDA 3D SOFTWARE
+// Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
+//
+// All use of this software is subject to the terms of the Panda 3d
+// Software license.  You should have received a copy of this license
+// along with this source code; you will also find a current copy of
+// the license at http://www.panda3d.org/license.txt .
+//
+// To contact the maintainers of this program write to
+// [email protected] .
+//
+////////////////////////////////////////////////////////////////////
+
+#ifndef FLTVECTORRECORD_H
+#define FLTVECTORRECORD_H
+
+#include <pandatoolbase.h>
+
+#include "fltRecord.h"
+
+#include <luse.h>
+
+////////////////////////////////////////////////////////////////////
+//       Class : FltVectorRecord
+// Description : This is an ancillary record of the old (pre-15.4)
+//               face node.  Its only use is to provide the direction
+//               vector for unidirectional and bidirectional light
+//               point faces.
+////////////////////////////////////////////////////////////////////
+class FltVectorRecord : public FltRecord {
+public:
+  FltVectorRecord(FltHeader *header);
+
+  const LVector3f &get_vector() const;
+
+protected:
+  LVector3f _vector;
+
+protected:
+  virtual bool extract_record(FltRecordReader &reader);
+  virtual bool build_record(FltRecordWriter &writer) 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() {
+    FltRecord::init_type();
+    register_type(_type_handle, "FltVectorRecord",
+                  FltRecord::get_class_type());
+  }
+
+private:
+  static TypeHandle _type_handle;
+
+  friend class FltBead;
+};
+
+#endif
+
+

+ 12 - 10
pandatool/src/flt/fltVertex.cxx

@@ -203,16 +203,18 @@ extract_record(FltRecordReader &reader) {
     _uv[1] = iterator.get_be_float32();
   }
 
-  if (!_packed_color.extract_record(reader)) {
-    return false;
-  }
-  if (_header->get_flt_version() >= 1520) {
-    _color_index = iterator.get_be_int32();
-
-    if (_has_normal && iterator.get_remaining_size() > 0) {
-      // If we extracted a normal, our double-word alignment is off; now
-      // we have a few extra bytes to ignore.
-      iterator.skip_bytes(4);
+  if (iterator.get_remaining_size() > 0) {
+    if (!_packed_color.extract_record(reader)) {
+      return false;
+    }
+    if (_header->get_flt_version() >= 1520) {
+      _color_index = iterator.get_be_int32();
+      
+      if (_has_normal && iterator.get_remaining_size() > 0) {
+        // If we extracted a normal, our double-word alignment is off; now
+        // we have a few extra bytes to ignore.
+        iterator.skip_bytes(4);
+      }
     }
   }