From ce4e89c47586a1dcf2b28eaf91d4c612bd7c4ac8 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 5 Oct 2005 22:35:23 +0000 Subject: [PATCH] LoaderOptions, supporting auto-converting animation from maya filess --- panda/src/egg2pg/loaderFileTypeEgg.cxx | 2 +- panda/src/egg2pg/loaderFileTypeEgg.h | 2 +- panda/src/framework/pandaFramework.cxx | 2 + panda/src/framework/pandaFramework.h | 3 + panda/src/framework/windowFramework.cxx | 9 ++- panda/src/framework/windowFramework.h | 1 + panda/src/pgraph/Sources.pp | 3 + panda/src/pgraph/loader.I | 4 +- panda/src/pgraph/loader.cxx | 6 +- panda/src/pgraph/loader.h | 6 +- panda/src/pgraph/loaderFileType.cxx | 2 +- panda/src/pgraph/loaderFileType.h | 4 +- panda/src/pgraph/loaderFileTypeBam.cxx | 4 +- panda/src/pgraph/loaderFileTypeBam.h | 2 +- panda/src/pgraph/loaderOptions.I | 71 +++++++++++++++++++ panda/src/pgraph/loaderOptions.cxx | 19 +++++ panda/src/pgraph/loaderOptions.h | 52 ++++++++++++++ panda/src/pgraph/pgraph_composite3.cxx | 1 + panda/src/testbed/pview.cxx | 10 ++- pandatool/src/mayaprogs/mayaPview.cxx | 3 + pandatool/src/mayaprogs/mayaSavePview.cxx | 4 +- .../src/ptloader/loaderFileTypePandatool.cxx | 8 ++- .../src/ptloader/loaderFileTypePandatool.h | 2 +- 23 files changed, 202 insertions(+), 18 deletions(-) create mode 100644 panda/src/pgraph/loaderOptions.I create mode 100644 panda/src/pgraph/loaderOptions.cxx create mode 100644 panda/src/pgraph/loaderOptions.h diff --git a/panda/src/egg2pg/loaderFileTypeEgg.cxx b/panda/src/egg2pg/loaderFileTypeEgg.cxx index daa39f1bea..878b344c85 100644 --- a/panda/src/egg2pg/loaderFileTypeEgg.cxx +++ b/panda/src/egg2pg/loaderFileTypeEgg.cxx @@ -58,7 +58,7 @@ get_extension() const { // Description: //////////////////////////////////////////////////////////////////// PT(PandaNode) LoaderFileTypeEgg:: -load_file(const Filename &path, bool) const { +load_file(const Filename &path, const LoaderOptions &) const { PT(PandaNode) result = load_egg_file(path); return result; } diff --git a/panda/src/egg2pg/loaderFileTypeEgg.h b/panda/src/egg2pg/loaderFileTypeEgg.h index a8a5010891..121f1f74a2 100644 --- a/panda/src/egg2pg/loaderFileTypeEgg.h +++ b/panda/src/egg2pg/loaderFileTypeEgg.h @@ -34,7 +34,7 @@ public: virtual string get_name() const; virtual string get_extension() const; - virtual PT(PandaNode) load_file(const Filename &path, bool report_errors) const; + virtual PT(PandaNode) load_file(const Filename &path, const LoaderOptions &optoins) const; public: static TypeHandle get_class_type() { diff --git a/panda/src/framework/pandaFramework.cxx b/panda/src/framework/pandaFramework.cxx index f2dbf5ee85..4b3dee2f25 100644 --- a/panda/src/framework/pandaFramework.cxx +++ b/panda/src/framework/pandaFramework.cxx @@ -29,6 +29,8 @@ #include "mouseAndKeyboard.h" #include "mouseRecorder.h" +LoaderOptions PandaFramework::_loader_options; + //////////////////////////////////////////////////////////////////// // Function: PandaFramework::Constructor // Access: Public diff --git a/panda/src/framework/pandaFramework.h b/panda/src/framework/pandaFramework.h index 96bdf4848c..a403b8dda8 100644 --- a/panda/src/framework/pandaFramework.h +++ b/panda/src/framework/pandaFramework.h @@ -114,6 +114,9 @@ public: INLINE void set_exit_flag(); INLINE void clear_exit_flag(); +public: + static LoaderOptions _loader_options; + protected: virtual PT(WindowFramework) make_window_framework(); virtual void make_default_pipe(); diff --git a/panda/src/framework/windowFramework.cxx b/panda/src/framework/windowFramework.cxx index 41ea36880f..ff1e8561cb 100644 --- a/panda/src/framework/windowFramework.cxx +++ b/panda/src/framework/windowFramework.cxx @@ -571,12 +571,19 @@ load_model(const NodePath &parent, Filename filename) { } } + LoaderOptions options = PandaFramework::_loader_options; + if (search) { + options.set_flags(options.get_flags() | LoaderOptions::LF_search); + } else { + options.set_flags(options.get_flags() & ~LoaderOptions::LF_search); + } + Loader loader; PT(PandaNode) node; if (is_image) { node = load_image_as_model(filename); } else { - node = loader.load_sync(filename, search); + node = loader.load_sync(filename, options); } if (node == (PandaNode *)NULL) { diff --git a/panda/src/framework/windowFramework.h b/panda/src/framework/windowFramework.h index 98899b8908..9d50be8681 100644 --- a/panda/src/framework/windowFramework.h +++ b/panda/src/framework/windowFramework.h @@ -32,6 +32,7 @@ #include "pvector.h" #include "typedWritableReferenceCount.h" #include "graphicsWindow.h" +#include "loaderOptions.h" class PandaFramework; class AmbientLight; diff --git a/panda/src/pgraph/Sources.pp b/panda/src/pgraph/Sources.pp index 3c24092ad0..af71397a6f 100644 --- a/panda/src/pgraph/Sources.pp +++ b/panda/src/pgraph/Sources.pp @@ -64,6 +64,7 @@ loaderFileType.h \ loaderFileTypeBam.h \ loaderFileTypeRegistry.h \ + loaderOptions.I loaderOptions.h \ lodNode.I lodNode.h \ materialAttrib.I materialAttrib.h \ modelNode.I modelNode.h \ @@ -169,6 +170,7 @@ loaderFileType.cxx \ loaderFileTypeBam.cxx \ loaderFileTypeRegistry.cxx \ + loaderOptions.cxx \ lodNode.cxx \ materialAttrib.cxx \ modelNode.cxx \ @@ -268,6 +270,7 @@ loaderFileType.h \ loaderFileTypeBam.h \ loaderFileTypeRegistry.h \ + loaderOptions.I loaderOptions.h \ lodNode.I lodNode.h \ materialAttrib.I materialAttrib.h \ modelNode.I modelNode.h \ diff --git a/panda/src/pgraph/loader.I b/panda/src/pgraph/loader.I index 5d613ccfcf..a9f8d8927e 100644 --- a/panda/src/pgraph/loader.I +++ b/panda/src/pgraph/loader.I @@ -123,9 +123,9 @@ add_file(const Filename &file, LoaderFileType *type) { // loaded. //////////////////////////////////////////////////////////////////// INLINE PT(PandaNode) Loader:: -load_sync(const Filename &filename, bool search) const { +load_sync(const Filename &filename, const LoaderOptions &options) const { if (!_file_types_loaded) { load_file_types(); } - return load_file(filename, search); + return load_file(filename, options); } diff --git a/panda/src/pgraph/loader.cxx b/panda/src/pgraph/loader.cxx index c1a4fa66b8..8fee3e84cb 100644 --- a/panda/src/pgraph/loader.cxx +++ b/panda/src/pgraph/loader.cxx @@ -407,10 +407,12 @@ process_request() { // loaded. //////////////////////////////////////////////////////////////////// PT(PandaNode) Loader:: -load_file(const Filename &filename, bool search) const { +load_file(const Filename &filename, const LoaderOptions &options) const { Results results; int num_files; + bool search = (options.get_flags() & LoaderOptions::LF_search) != 0; + if (search) { // Look for the file along the model path. num_files = find_all_files(filename, get_model_path(), results); @@ -452,7 +454,7 @@ load_file(const Filename &filename, bool search) const { for (int i = 0; i < num_files; ++i) { const Filename &path = results.get_file(i); LoaderFileType *type = results.get_file_type(i); - PT(PandaNode) result = type->load_file(path, true); + PT(PandaNode) result = type->load_file(path, options); if (result != (PandaNode *)NULL) { return result; } diff --git a/panda/src/pgraph/loader.h b/panda/src/pgraph/loader.h index c57859955d..4676315a26 100644 --- a/panda/src/pgraph/loader.h +++ b/panda/src/pgraph/loader.h @@ -21,6 +21,7 @@ #include "pandabase.h" +#include "loaderOptions.h" #include "notify.h" #include "pandaNode.h" #include "filename.h" @@ -71,7 +72,8 @@ PUBLISHED: int find_all_files(const Filename &filename, const DSearchPath &search_path, Results &results) const; - INLINE PT(PandaNode) load_sync(const Filename &filename, bool search = true) const; + INLINE PT(PandaNode) load_sync(const Filename &filename, + const LoaderOptions &options = LoaderOptions()) const; uint request_load(const string &event_name, const Filename &filename, bool search = true); bool check_load(uint id); @@ -82,7 +84,7 @@ private: static bool _file_types_loaded; virtual bool process_request(); - PT(PandaNode) load_file(const Filename &filename, bool search) const; + PT(PandaNode) load_file(const Filename &filename, const LoaderOptions &options) const; typedef TokenBoard LoaderTokenBoard; LoaderTokenBoard *_token_board; diff --git a/panda/src/pgraph/loaderFileType.cxx b/panda/src/pgraph/loaderFileType.cxx index 2a12e972be..73e92eccec 100644 --- a/panda/src/pgraph/loaderFileType.cxx +++ b/panda/src/pgraph/loaderFileType.cxx @@ -57,7 +57,7 @@ get_additional_extensions() const { // Description: //////////////////////////////////////////////////////////////////// PT(PandaNode) LoaderFileType:: -load_file(const Filename &path, bool report_errors) const { +load_file(const Filename &path, const LoaderOptions &options) const { loader_cat.error() << get_type() << " cannot read PandaNode objects.\n"; return NULL; diff --git a/panda/src/pgraph/loaderFileType.h b/panda/src/pgraph/loaderFileType.h index 24c389a4e0..6b39265346 100644 --- a/panda/src/pgraph/loaderFileType.h +++ b/panda/src/pgraph/loaderFileType.h @@ -27,6 +27,8 @@ #include "pointerTo.h" #include "dSearchPath.h" +class LoaderOptions; + //////////////////////////////////////////////////////////////////// // Class : LoaderFileType // Description : This is the base class for a family of scene-graph @@ -47,7 +49,7 @@ PUBLISHED: virtual string get_additional_extensions() const; public: - virtual PT(PandaNode) load_file(const Filename &path, bool report_errors) const; + virtual PT(PandaNode) load_file(const Filename &path, const LoaderOptions &options) const; public: static TypeHandle get_class_type() { diff --git a/panda/src/pgraph/loaderFileTypeBam.cxx b/panda/src/pgraph/loaderFileTypeBam.cxx index 4eecab30c5..a02ae214f5 100644 --- a/panda/src/pgraph/loaderFileTypeBam.cxx +++ b/panda/src/pgraph/loaderFileTypeBam.cxx @@ -19,6 +19,7 @@ #include "loaderFileTypeBam.h" #include "config_pgraph.h" #include "bamFile.h" +#include "loaderOptions.h" #include "dcast.h" @@ -59,7 +60,8 @@ get_extension() const { // Description: //////////////////////////////////////////////////////////////////// PT(PandaNode) LoaderFileTypeBam:: -load_file(const Filename &path, bool report_errors) const { +load_file(const Filename &path, const LoaderOptions &options) const { + bool report_errors = (options.get_flags() & LoaderOptions::LF_report_errors) != 0; BamFile bam_file; if (!bam_file.open_read(path, report_errors)) { return NULL; diff --git a/panda/src/pgraph/loaderFileTypeBam.h b/panda/src/pgraph/loaderFileTypeBam.h index a9a3a75b1a..16df75fa59 100644 --- a/panda/src/pgraph/loaderFileTypeBam.h +++ b/panda/src/pgraph/loaderFileTypeBam.h @@ -34,7 +34,7 @@ public: virtual string get_name() const; virtual string get_extension() const; - virtual PT(PandaNode) load_file(const Filename &path, bool report_errors) const; + virtual PT(PandaNode) load_file(const Filename &path, const LoaderOptions &options) const; public: static TypeHandle get_class_type() { diff --git a/panda/src/pgraph/loaderOptions.I b/panda/src/pgraph/loaderOptions.I new file mode 100644 index 0000000000..be9220fd88 --- /dev/null +++ b/panda/src/pgraph/loaderOptions.I @@ -0,0 +1,71 @@ +// Filename: loaderOptions.I +// Created by: drose (05Oct05) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, 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://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: LoaderOptions::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE LoaderOptions:: +LoaderOptions(int flags) : + _flags(flags) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: LoaderOptions::Copy Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE LoaderOptions:: +LoaderOptions(const LoaderOptions ©) : + _flags(copy._flags) +{ +} + +//////////////////////////////////////////////////////////////////// +// Function: LoaderOptions::Copy Assignment Operator +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void LoaderOptions:: +operator = (const LoaderOptions ©) { + _flags = copy._flags; +} + +//////////////////////////////////////////////////////////////////// +// Function: LoaderOptions::set_flags +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void LoaderOptions:: +set_flags(int flags) { + _flags = flags; +} + +//////////////////////////////////////////////////////////////////// +// Function: LoaderOptions::get_flags +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE int LoaderOptions:: +get_flags() const { + return _flags; +} + diff --git a/panda/src/pgraph/loaderOptions.cxx b/panda/src/pgraph/loaderOptions.cxx new file mode 100644 index 0000000000..b75ef28e18 --- /dev/null +++ b/panda/src/pgraph/loaderOptions.cxx @@ -0,0 +1,19 @@ +// Filename: loaderOptions.cxx +// Created by: drose (05Oct05) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, 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://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#include "loaderOptions.h" diff --git a/panda/src/pgraph/loaderOptions.h b/panda/src/pgraph/loaderOptions.h new file mode 100644 index 0000000000..abfc734ba6 --- /dev/null +++ b/panda/src/pgraph/loaderOptions.h @@ -0,0 +1,52 @@ +// Filename: loaderOptions.h +// Created by: drose (05Oct05) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001 - 2004, 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://etc.cmu.edu/panda3d/docs/license/ . +// +// To contact the maintainers of this program write to +// panda3d-general@lists.sourceforge.net . +// +//////////////////////////////////////////////////////////////////// + +#ifndef LOADEROPTIONS_H +#define LOADEROPTIONS_H + +#include "pandabase.h" + +//////////////////////////////////////////////////////////////////// +// Class : LoaderOptions +// Description : Specifies parameters that may be passed to the +// loader. +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA LoaderOptions { +PUBLISHED: + // At the moment, we only have this one set of flags. Maybe one day + // there will be more options. + enum LoaderFlags { + LF_search = 0x0001, + LF_report_errors = 0x0002, + LF_convert_anim = 0x0004, + }; + + INLINE LoaderOptions(int flags = LF_search | LF_report_errors); + INLINE LoaderOptions(const LoaderOptions ©); + INLINE void operator = (const LoaderOptions ©); + + INLINE void set_flags(int flags); + INLINE int get_flags() const; + +private: + int _flags; +}; + +#include "loaderOptions.I" + +#endif diff --git a/panda/src/pgraph/pgraph_composite3.cxx b/panda/src/pgraph/pgraph_composite3.cxx index 573bd57a5c..5d551c2d74 100644 --- a/panda/src/pgraph/pgraph_composite3.cxx +++ b/panda/src/pgraph/pgraph_composite3.cxx @@ -7,6 +7,7 @@ #include "loaderFileType.cxx" #include "loaderFileTypeBam.cxx" #include "loaderFileTypeRegistry.cxx" +#include "loaderOptions.cxx" #include "lodNode.cxx" #include "materialAttrib.cxx" #include "modelNode.cxx" diff --git a/panda/src/testbed/pview.cxx b/panda/src/testbed/pview.cxx index e782189418..c0565d6fe3 100644 --- a/panda/src/testbed/pview.cxx +++ b/panda/src/testbed/pview.cxx @@ -210,6 +210,10 @@ help() { "animations.\n\n" "Options:\n\n" + + " -a\n" + " Convert and play animations, if loading an external file type\n" + " (like .mb) directly and if the converter supports animations.\n\n" " -c\n" " Automatically center models within the viewing window on startup.\n" @@ -257,11 +261,15 @@ main(int argc, char *argv[]) { extern char *optarg; extern int optind; - static const char *optflags = "cls:Vhi"; + static const char *optflags = "acls:Vhi"; int flag = getopt(argc, argv, optflags); while (flag != EOF) { switch (flag) { + case 'a': + PandaFramework::_loader_options.set_flags(PandaFramework::_loader_options.get_flags() | LoaderOptions::LF_convert_anim); + break; + case 'c': auto_center = true; break; diff --git a/pandatool/src/mayaprogs/mayaPview.cxx b/pandatool/src/mayaprogs/mayaPview.cxx index 838c3638d0..c800051755 100755 --- a/pandatool/src/mayaprogs/mayaPview.cxx +++ b/pandatool/src/mayaprogs/mayaPview.cxx @@ -133,6 +133,9 @@ convert(const NodePath &parent) { // results. converter._polygon_output = true; + // We also want to get the animation if there is any. + converter.set_animation_convert(AC_both); + PathReplace *path_replace = converter.get_path_replace(); // Accept relative pathnames in the Maya file. diff --git a/pandatool/src/mayaprogs/mayaSavePview.cxx b/pandatool/src/mayaprogs/mayaSavePview.cxx index 70921bb137..bd7ff5f7a4 100644 --- a/pandatool/src/mayaprogs/mayaSavePview.cxx +++ b/pandatool/src/mayaprogs/mayaSavePview.cxx @@ -59,7 +59,7 @@ doIt(const MArgList &) { // asynchronously. MString quoted = MString("\"") + filename + MString("\""); int retval = _spawnlp(_P_DETACH, "pview", - "pview", "-cl", quoted.asChar(), NULL); + "pview", "-cla", quoted.asChar(), NULL); if (retval == -1) { return MS::kFailure; } @@ -68,7 +68,7 @@ doIt(const MArgList &) { // On non-Windows (e.g. Unix), we just use the system function, // which runs synchronously. We could fork a process, but no one's // asked for this yet. - MString command = MString("pview -c \"") + filename + MString("\""); + MString command = MString("pview -cla \"") + filename + MString("\""); int command_result = system(command.asChar()); if (command_result != 0) { diff --git a/pandatool/src/ptloader/loaderFileTypePandatool.cxx b/pandatool/src/ptloader/loaderFileTypePandatool.cxx index 11abdc74de..b33dda3eab 100644 --- a/pandatool/src/ptloader/loaderFileTypePandatool.cxx +++ b/pandatool/src/ptloader/loaderFileTypePandatool.cxx @@ -22,6 +22,7 @@ #include "config_util.h" #include "load_egg_file.h" #include "eggData.h" +#include "loaderOptions.h" TypeHandle LoaderFileTypePandatool::_type_handle; @@ -96,7 +97,7 @@ resolve_filename(Filename &path) const { // Description: //////////////////////////////////////////////////////////////////// PT(PandaNode) LoaderFileTypePandatool:: -load_file(const Filename &path, bool) const { +load_file(const Filename &path, const LoaderOptions &options) const { PT(PandaNode) result; PT(EggData) egg_data = new EggData; @@ -106,6 +107,11 @@ load_file(const Filename &path, bool) const { file_path.append_directory(path.get_dirname()); _converter->get_path_replace()->_path = file_path; + if (options.get_flags() & LoaderOptions::LF_convert_anim) { + // Convert animation, if the converter supports it. + _converter->set_animation_convert(AC_both); + } + if (_converter->convert_file(path)) { DistanceUnit input_units = _converter->get_input_units(); if (input_units != DU_invalid && ptloader_units != DU_invalid && diff --git a/pandatool/src/ptloader/loaderFileTypePandatool.h b/pandatool/src/ptloader/loaderFileTypePandatool.h index 1b12576f11..1b270f5131 100644 --- a/pandatool/src/ptloader/loaderFileTypePandatool.h +++ b/pandatool/src/ptloader/loaderFileTypePandatool.h @@ -42,7 +42,7 @@ public: virtual string get_additional_extensions() const; virtual void resolve_filename(Filename &path) const; - virtual PT(PandaNode) load_file(const Filename &path, bool report_errors) const; + virtual PT(PandaNode) load_file(const Filename &path, const LoaderOptions &options) const; private: SomethingToEggConverter *_converter;