Quellcode durchsuchen

Added support for blender x-files

Josh Yelon vor 20 Jahren
Ursprung
Commit
61639a1ef9

+ 2 - 1
pandatool/src/xfile/xFile.cxx

@@ -36,11 +36,12 @@ PT(XFile) XFile::_standard_templates;
 //  Description:
 ////////////////////////////////////////////////////////////////////
 XFile::
-XFile() : XFileNode(this, "") {
+XFile(bool keep_names) : XFileNode(this, "") {
   _major_version = 3;
   _minor_version = 2;
   _format_type = FT_text;
   _float_size = FS_64;
+  _keep_names = keep_names;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 3 - 2
pandatool/src/xfile/xFile.h

@@ -38,7 +38,7 @@ class XFileDataNodeTemplate;
 ////////////////////////////////////////////////////////////////////
 class XFile : public XFileNode {
 public:
-  XFile();
+  XFile(bool keep_names=false);
   ~XFile();
 
   virtual void clear();
@@ -79,7 +79,8 @@ private:
   int _major_version, _minor_version;
   FormatType _format_type;
   FloatSize _float_size;
-
+  bool _keep_names;
+  
   typedef pmap<WindowsGuid, XFileNode *> NodesByGuid;
   NodesByGuid _nodes_by_guid;
 

+ 9 - 4
pandatool/src/xfile/xFileNode.cxx

@@ -35,9 +35,14 @@ TypeHandle XFileNode::_type_handle;
 ////////////////////////////////////////////////////////////////////
 XFileNode::
 XFileNode(XFile *x_file, const string &name) :
-  Namable(make_nice_name(name)),
+  Namable(),
   _x_file(x_file)
 {
+  if (x_file && x_file->_keep_names) {
+    set_name(name);
+  } else {
+    set_name(make_nice_name(name));
+  }
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -565,15 +570,15 @@ make_nice_name(const string &str) {
       case '-':
         result += (*si);
         break;
-
       default:
         result += "_";
       }
     }
   }
 
-  if (!str.empty() && isdigit(str[0])) {
-    // If the name begins with a digit, we must make it begin with
+  if (str.empty() || isdigit(str[0])) {
+    // If the name begins with a digit, or if it
+    // is empty, then we must make it begin with
     // something else, like for instance an underscore.
     result = '_' + result;
   }

+ 1 - 1
pandatool/src/xfile/xFileNode.h

@@ -102,7 +102,7 @@ public:
   XFileDataNode *add_Frame(const string &name);
   XFileDataNode *add_FrameTransformMatrix(const LMatrix4d &mat);
 
-protected:
+public:
   static string make_nice_name(const string &str);
 
 protected:

+ 2 - 3
pandatool/src/xfile/xLexer.lxx

@@ -597,21 +597,20 @@ WHITESPACE           [ ]+
   return TOKEN_GUID;
 }
 
-[A-Za-z_-][A-Za-z_0-9-]* { 
+[A-Za-z_-][A-Za-z0-9_.-]* { 
   // Identifier.
   accept();
   xyylval.str = xyytext;
   return TOKEN_NAME;
 }
 
-[0-9-]+[A-Za-z_-][A-Za-z_0-9-]* { 
+[0-9-]+[A-Za-z_-][A-Za-z0-9_.-]* { 
   // Identifier with leading digit.
   accept();
   xyylval.str = xyytext;
   return TOKEN_NAME;
 }
 
-  
 . {
   // Any other character is invalid.
   accept();

+ 33 - 3
pandatool/src/xfileegg/xFileToEggConverter.cxx

@@ -40,7 +40,7 @@ XFileToEggConverter::
 XFileToEggConverter() {
   _make_char = false;
   _frame_rate = 30.0;
-  _x_file = new XFile;
+  _x_file = new XFile(true);
   _dart_node = NULL;
 }
 
@@ -54,7 +54,7 @@ XFileToEggConverter(const XFileToEggConverter &copy) :
   SomethingToEggConverter(copy),
   _make_char(copy._make_char)
 {
-  _x_file = new XFile;
+  _x_file = new XFile(true);
   _dart_node = NULL;
 }
 
@@ -149,6 +149,14 @@ convert_file(const Filename &filename) {
     return false;
   }
 
+  if (_keep_model && !_keep_animation) {
+    strip_nodes(EggTable::get_class_type());
+  }
+  
+  if (_keep_animation && !_keep_model) {
+    strip_nodes(EggGroup::get_class_type());
+  }
+  
   return !had_error();
 }
 
@@ -178,6 +186,27 @@ close() {
   _joints.clear();
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: XFileToEggConverter::strip_nodes
+//       Access: Public
+//  Description: Removes all groups of the given type.  This is used
+//               to implement the -anim and -model options.
+////////////////////////////////////////////////////////////////////
+void XFileToEggConverter::
+strip_nodes(TypeHandle t) {
+  pvector <EggNode *> garbage;
+  EggGroupNode::iterator i;
+  for (i=_egg_data->begin(); i!=_egg_data->end(); ++i) {
+    EggNode *node = (*i);
+    if (node->is_of_type(t)) {
+      garbage.push_back(node);
+    }
+  }
+  for (int n=0; n<(int)garbage.size(); n++) {
+    _egg_data->remove_child(garbage[n]);
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: XFileToEggConverter::get_dart_node
 //       Access: Public
@@ -391,10 +420,11 @@ convert_object(XFileDataNode *obj, EggGroupNode *egg_parent) {
 ////////////////////////////////////////////////////////////////////
 bool XFileToEggConverter::
 convert_frame(XFileDataNode *obj, EggGroupNode *egg_parent) {
+
   string name = obj->get_name();
   EggGroup *group = new EggGroup(name);
   egg_parent->add_child(group);
-
+  
   if (_make_char) {
     group->set_group_type(EggGroup::GT_joint);
     if (name.empty()) {

+ 3 - 0
pandatool/src/xfileegg/xFileToEggConverter.h

@@ -62,11 +62,14 @@ public:
   EggTexture *create_unique_texture(const EggTexture &copy);
   EggMaterial *create_unique_material(const EggMaterial &copy);
   EggGroup *find_joint(const string &joint_name);
+  void strip_nodes(TypeHandle t);
 
 public:
   bool _make_char;
   string _char_name;
   double _frame_rate;
+  bool _keep_model;
+  bool _keep_animation;
 
 private:
   typedef XFileAnimationSet::FrameData FrameData;

+ 13 - 1
pandatool/src/xfileprogs/xFileToEgg.cxx

@@ -60,6 +60,16 @@ XFileToEgg() :
      "and the frames are played sequentially at the specified frame rate.",
      &XFileToEgg::dispatch_double, NULL, &_frame_rate);
 
+  add_option
+    ("anim", "", 0,
+     "Generate animation data only (all geometry will be discarded).",
+     &XFileToEgg::dispatch_none, &_keep_animation);
+
+  add_option
+    ("model", "", 0,
+     "Generate model data only (all animation data will be discarded).",
+     &XFileToEgg::dispatch_none, &_keep_model);
+
   redescribe_option
     ("ui",
      "Specify the units of the input " + _format_name + " file.");
@@ -95,7 +105,9 @@ run() {
   converter._frame_rate = _frame_rate;
   converter._make_char = _make_char;
   converter._char_name = _char_name;
-
+  converter._keep_model = _keep_model;
+  converter._keep_animation = _keep_animation;
+  
   // Copy in the path and animation parameters.
   apply_parameters(converter);
 

+ 2 - 0
pandatool/src/xfileprogs/xFileToEgg.h

@@ -40,6 +40,8 @@ public:
   bool _make_char;
   string _char_name;
   double _frame_rate;
+  bool _keep_model;
+  bool _keep_animation;
 };
 
 #endif