LoaderOptions, supporting auto-converting animation from maya filess

This commit is contained in:
David Rose 2005-10-05 22:35:23 +00:00
parent 71f3a958a1
commit ce4e89c475
23 changed files with 202 additions and 18 deletions

View File

@ -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;
}

View File

@ -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() {

View File

@ -29,6 +29,8 @@
#include "mouseAndKeyboard.h"
#include "mouseRecorder.h"
LoaderOptions PandaFramework::_loader_options;
////////////////////////////////////////////////////////////////////
// Function: PandaFramework::Constructor
// Access: Public

View File

@ -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();

View File

@ -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) {

View File

@ -32,6 +32,7 @@
#include "pvector.h"
#include "typedWritableReferenceCount.h"
#include "graphicsWindow.h"
#include "loaderOptions.h"
class PandaFramework;
class AmbientLight;

View File

@ -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 \

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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<LoaderToken> LoaderTokenBoard;
LoaderTokenBoard *_token_board;

View File

@ -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;

View File

@ -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() {

View File

@ -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;

View File

@ -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() {

View File

@ -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 &copy) :
_flags(copy._flags)
{
}
////////////////////////////////////////////////////////////////////
// Function: LoaderOptions::Copy Assignment Operator
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE void LoaderOptions::
operator = (const LoaderOptions &copy) {
_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;
}

View File

@ -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"

View File

@ -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 &copy);
INLINE void operator = (const LoaderOptions &copy);
INLINE void set_flags(int flags);
INLINE int get_flags() const;
private:
int _flags;
};
#include "loaderOptions.I"
#endif

View File

@ -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"

View File

@ -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;

View File

@ -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.

View File

@ -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) {

View File

@ -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 &&

View File

@ -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;