소스 검색

add mayaCopy

David Rose 23 년 전
부모
커밋
064dc06178
4개의 변경된 파일274개의 추가작업 그리고 0개의 파일을 삭제
  1. 30 0
      pandatool/src/maya/mayaApi.cxx
  2. 1 0
      pandatool/src/maya/mayaApi.h
  3. 170 0
      pandatool/src/mayaprogs/mayaCopy.cxx
  4. 73 0
      pandatool/src/mayaprogs/mayaCopy.h

+ 30 - 0
pandatool/src/maya/mayaApi.cxx

@@ -167,6 +167,36 @@ read(const Filename &filename) {
   return true;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: MayaApi::write
+//       Access: Public
+//  Description: Writes the global model space to the indicated file.
+//               Returns true if successful, false otherwise.
+////////////////////////////////////////////////////////////////////
+bool MayaApi::
+write(const Filename &filename) {
+  MFileIO::newFile(true);
+
+  maya_cat.info() << "Writing " << filename << "\n";
+  string os_filename = filename.to_os_specific();
+#ifdef WIN32
+  os_filename = back_to_front_slash(os_filename);
+#endif
+
+  const char *type = MFileIO::mayaBinary;
+  string extension = filename.get_extension();
+  if (extension == "ma") {
+    type = MFileIO::mayaAscii;
+  }
+
+  MStatus stat = MFileIO::saveAs(os_filename.c_str(), type, true);
+  if (!stat) {
+    stat.perror(filename.c_str());
+    return false;
+  }
+  return true;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: MayaApi::clear
 //       Access: Public

+ 1 - 0
pandatool/src/maya/mayaApi.h

@@ -47,6 +47,7 @@ public:
   bool is_valid() const;
 
   bool read(const Filename &filename);
+  bool write(const Filename &filename);
   bool clear();
 
   DistanceUnit get_units();

+ 170 - 0
pandatool/src/mayaprogs/mayaCopy.cxx

@@ -0,0 +1,170 @@
+// Filename: mayaCopy.cxx
+// Created by:  drose (10May02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// 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 "mayaCopy.h"
+
+#include "cvsSourceDirectory.h"
+#include "dcast.h"
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaCopy::Constructor
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+MayaCopy::
+MayaCopy() {
+  set_program_description
+    ("mayacopy copies one or more Maya .mb files into a "
+     "CVS source hierarchy.  "
+     "Rather than copying the named files immediately into the current "
+     "directory, it first scans the entire source hierarchy, identifying all "
+     "the already-existing files.  If the named file to copy matches the "
+     "name of an already-existing file in the current directory or elsewhere "
+     "in the hierarchy, that file is overwritten.  Other .mb files, as "
+     "well as texture files, that are externally referenced by the "
+     "named .mb file(s) are similarly copied.");
+
+  clear_runlines();
+  add_runline("[opts] file.mb [file.mb ... ]");
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaCopy::run
+//       Access: Public
+//  Description:
+////////////////////////////////////////////////////////////////////
+void MayaCopy::
+run() {
+  SourceFiles::iterator fi;
+  for (fi = _source_files.begin(); fi != _source_files.end(); ++fi) {
+    ExtraData ed;
+    ed._type = FT_maya;
+
+    CVSSourceDirectory *dest = import(*fi, &ed, _model_dir);
+    if (dest == (CVSSourceDirectory *)NULL) {
+      exit(1);
+    }
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaCopy::copy_file
+//       Access: Protected, Virtual
+//  Description: Called by import() if verify_file() indicates that a
+//               file needs to be copied.  This does the actual copy
+//               of a file from source to destination.  If new_file is
+//               true, then dest does not already exist.
+////////////////////////////////////////////////////////////////////
+bool MayaCopy::
+copy_file(const Filename &source, const Filename &dest,
+          CVSSourceDirectory *dir, void *extra_data, bool new_file) {
+  ExtraData *ed = (ExtraData *)extra_data;
+  switch (ed->_type) {
+  case FT_maya:
+    return copy_maya_file(source, dest, dir);
+
+  case FT_texture:
+    return copy_texture(source, dest, dir);
+  }
+
+  nout << "Internal error: invalid type " << (int)ed->_type << "\n";
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaCopy::copy_maya_file
+//       Access: Private
+//  Description:
+////////////////////////////////////////////////////////////////////
+bool MayaCopy::
+copy_maya_file(const Filename &source, const Filename &dest,
+               CVSSourceDirectory *dir) {
+  if (!_maya->read(source)) {
+    mayaegg_cat.error()
+      << "Unable to read " << source << "\n";
+    return false;
+  }
+
+  if (!_maya->write(dest)) {
+    mayaegg_cat.error()
+      << "Cannot write " << dest << "\n";
+    return false;
+  }
+
+  return true;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: MayaCopy::copy_texture
+//       Access: Private
+//  Description:
+////////////////////////////////////////////////////////////////////
+bool MayaCopy::
+copy_texture(const Filename &source, const Filename &dest,
+             CVSSourceDirectory *dir) {
+  if (!copy_binary_file(source, dest)) {
+    return false;
+  }
+
+  return true;
+}
+
+/*
+////////////////////////////////////////////////////////////////////
+//     Function: MayaCopy::scan_maya
+//       Access: Private
+//  Description: Recursively walks through the maya file hierarchy,
+//               looking for texture references and external maya file
+//               references.
+////////////////////////////////////////////////////////////////////
+void MayaCopy::
+scan_maya(MayaRecord *record, MayaCopy::Refs &refs, MayaCopy::Textures &textures) {
+  if (record->is_of_type(MayaFace::get_class_type())) {
+    MayaFace *face;
+    DCAST_INTO_V(face, record);
+    if (face->has_texture()) {
+      textures.insert(face->get_texture());
+    }
+
+  } else if (record->is_of_type(MayaExternalReference::get_class_type())) {
+    MayaExternalReference *ref;
+    DCAST_INTO_V(ref, record);
+
+    refs.insert(ref);
+  }
+
+  int i;
+  int num_subfaces = record->get_num_subfaces();
+  for (i = 0; i < num_subfaces; i++) {
+    scan_maya(record->get_subface(i), refs, textures);
+  }
+
+  int num_children = record->get_num_children();
+  for (i = 0; i < num_children; i++) {
+    scan_maya(record->get_child(i), refs, textures);
+  }
+}
+*/
+
+
+int main(int argc, char *argv[]) {
+  MayaCopy prog;
+  prog.parse_command_line(argc, argv);
+  prog.run();
+  return 0;
+}

+ 73 - 0
pandatool/src/mayaprogs/mayaCopy.h

@@ -0,0 +1,73 @@
+// Filename: mayaCopy.h
+// Created by:  drose (10May02)
+//
+////////////////////////////////////////////////////////////////////
+//
+// 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 MAYACOPY_H
+#define MAYACOPY_H
+
+#include "pandatoolbase.h"
+
+#include "cvsCopy.h"
+
+#include "dSearchPath.h"
+#include "pointerTo.h"
+
+#include "pset.h"
+
+class MayaShader;
+
+////////////////////////////////////////////////////////////////////
+//       Class : MayaCopy
+// Description : A program to copy Maya .mb files into the cvs
+//               tree.
+////////////////////////////////////////////////////////////////////
+class MayaCopy : public CVSCopy {
+public:
+  MayaCopy();
+
+  void run();
+
+protected:
+  virtual bool copy_file(const Filename &source, const Filename &dest,
+                         CVSSourceDirectory *dir, void *extra_data,
+                         bool new_file);
+
+private:
+  enum FileType {
+    FT_maya,
+    FT_texture
+  };
+
+  class ExtraData {
+  public:
+    FileType _type;
+    MayaShader *_shader;
+  };
+
+  bool copy_maya_file(const Filename &source, const Filename &dest,
+                     CVSSourceDirectory *dir);
+  bool copy_texture(const Filename &source, const Filename &dest,
+                    CVSSourceDirectory *dir);
+
+
+  typedef pset< PT(MayaExternalReference) > Refs;
+  typedef pset< PT(MayaTexture) > Textures;
+
+  void scan_maya(MayaRecord *record, Refs &refs, Textures &textures);
+};
+
+#endif