first submit: converts the model only on this version. No animation yet.

This commit is contained in:
Asad M. Zaman 2003-10-15 01:46:44 +00:00
parent 3a24581e96
commit d01bc14649
12 changed files with 3047 additions and 0 deletions

View File

@ -0,0 +1,27 @@
#define BUILD_DIRECTORY $[HAVE_SOFTIMAGE]
#begin lib_target
#define USE_PACKAGES softimage
#define TARGET softegg
#define LOCAL_LIBS \
converter pandatoolbase
#define OTHER_LIBS \
egg:c pandaegg:m \
linmath:c putil:c panda:m \
express:c pandaexpress:m \
dtoolutil:c dtoolbase:c dconfig:c dtoolconfig:m dtool:m pystub
#define BUILDING_DLL BUILDING_MISC
#define UNIX_SYS_LIBS \
m
#define SOURCES \
config_softegg.cxx config_softegg.h \
softEggGroupUserData.cxx softEggGroupUserData.I softEggGroupUserData.h \
softToEggConverter.cxx softToEggConverter.h \
soft2Egg.c \
softNodeTree.cxx softNodeTree.h \
softNodeDesc.cxx softNodeDesc.h
#end lib_target

View File

@ -0,0 +1,63 @@
// Filename: config_softegg.cxx
// Created by: masad (25Sep03)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2003, 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
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "config_softegg.h"
#include "softEggGroupUserData.h"
#include "dconfig.h"
Configure(config_softegg);
NotifyCategoryDef(softegg, ":soft");
ConfigureFn(config_softegg) {
init_libsoftegg();
}
// These control the default behavior of the softegg converter, but
// not necessarily the default behavior of the soft2egg command-line
// tool (which has its own defaults).
// Should we respect the Soft? double-sided flag (true) or ignore it
// and assume everything is single-sided (false)?
const bool soft_default_double_sided = config_softegg.GetBool("soft-default-double-sided", false);
// Should we apply vertex color even when a texture is applied (true)
// or only when no texture is applied or the vertex-color egg flag is
// set (false)?
const bool soft_default_vertex_color = config_softegg.GetBool("soft-default-vertex-color", true);
////////////////////////////////////////////////////////////////////
// Function: init_libsoftegg
// Description: Initializes the library. This must be called at
// least once before any of the functions or classes in
// this library can be used. Normally it will be
// called by the static initializers and need not be
// called explicitly, but special cases exist.
////////////////////////////////////////////////////////////////////
void
init_libsoftegg() {
static bool initialized = false;
if (initialized) {
return;
}
initialized = true;
SoftEggGroupUserData::init_type();
// SoftNodeDesc::init_type();
}

View File

@ -0,0 +1,32 @@
// Filename: config_softegg.h
// Created by: masad (25Sep03)
//
////////////////////////////////////////////////////////////////////
//
// 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
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef CONFIG_SOFTEGG_H
#define CONFIG_SOFTEGG_H
#include "pandatoolbase.h"
#include "notifyCategoryProxy.h"
NotifyCategoryDeclNoExport(softegg);
extern const bool soft_default_double_sided;
extern const bool soft_default_vertex_color;
extern void init_libsoftegg();
#endif

View File

@ -0,0 +1,56 @@
// Filename: softEggGroupUserData.I
// Created by: masad (25Sep03)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2003, 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
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: SoftEggGroupUserData::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE SoftEggGroupUserData::
SoftEggGroupUserData() {
_vertex_color = false;
_double_sided = false;
}
////////////////////////////////////////////////////////////////////
// Function: SoftEggGroupUserData::Copy constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE SoftEggGroupUserData::
SoftEggGroupUserData(const SoftEggGroupUserData &copy) :
EggUserData(copy),
_vertex_color(copy._vertex_color),
_double_sided(copy._double_sided)
{
}
////////////////////////////////////////////////////////////////////
// Function: SoftEggGroupUserData::Copy assignment operator
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE void SoftEggGroupUserData::
operator = (const SoftEggGroupUserData &copy) {
EggUserData::operator = (copy);
_vertex_color = copy._vertex_color;
_double_sided = copy._double_sided;
}

View File

@ -0,0 +1,21 @@
// Filename: softEggGroupUserData.cxx
// Created by: masad (25Sep03)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2003, 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
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "softEggGroupUserData.h"
TypeHandle SoftEggGroupUserData::_type_handle;

View File

@ -0,0 +1,60 @@
// Filename: softEggGroupUserData.h
// Created by: masad (25Sep03)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2003, 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
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef SOFTEGGGROUPUSERDATA_H
#define SOFTEGGGROUPUSERDATA_H
#include "pandatoolbase.h"
#include "eggUserData.h"
////////////////////////////////////////////////////////////////////
// Class : SoftEggGroupUserData
// Description : This class contains extra user data which is
// piggybacked onto EggGroup objects for the purpose of
// the softimage converter.
////////////////////////////////////////////////////////////////////
class SoftEggGroupUserData : public EggUserData {
public:
INLINE SoftEggGroupUserData();
INLINE SoftEggGroupUserData(const SoftEggGroupUserData &copy);
INLINE void operator = (const SoftEggGroupUserData &copy);
bool _vertex_color;
bool _double_sided;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
EggUserData::init_type();
register_type(_type_handle, "SoftEggGroupUserData",
EggUserData::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#include "softEggGroupUserData.I"
#endif

View File

@ -0,0 +1,209 @@
// Filename: softNodeDesc.cxx
// Created by: masad (03Oct03)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2003, 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
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "softNodeDesc.h"
TypeHandle SoftNodeDesc::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: SoftNodeDesc::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
SoftNodeDesc::
SoftNodeDesc(const string &name) :
Namable(name)
// _parent(parent)
{
_model = (SAA_Elem *)NULL;
_egg_group = (EggGroup *)NULL;
_egg_table = (EggTable *)NULL;
_anim = (EggXfmSAnim *)NULL;
_joint_type = JT_none;
#if 0
// Add ourselves to our parent.
if (_parent != (SoftNodeDesc *)NULL) {
_parent->_children.push_back(this);
}
#endif
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeDesc::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
SoftNodeDesc::
~SoftNodeDesc() {
if (_model != (SAA_Elem *)NULL) {
delete _model;
}
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeDesc::set_model
// Access: Public
// Description: Indicates an associated between the SoftNodeDesc and
// some SAA_Elem instance.
////////////////////////////////////////////////////////////////////
void SoftNodeDesc::
set_model(SAA_Elem *model) {
_model = model;
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeDesc::has_model
// Access: Public
// Description: Returns true if a Soft dag path has been associated
// with this node, false otherwise.
////////////////////////////////////////////////////////////////////
bool SoftNodeDesc::
has_model() const {
return (_model != (SAA_Elem *)NULL);
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeDesc::get_model
// Access: Public
// Description: Returns the SAA_Elem * associated with this node. It
// is an error to call this unless has_model()
// returned true.
////////////////////////////////////////////////////////////////////
SAA_Elem *SoftNodeDesc::
get_model() const {
nassertr(_model != (SAA_Elem *)NULL, _model);
return _model;
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeDesc::is_joint
// Access: Private
// Description: Returns true if the node should be treated as a joint
// by the converter.
////////////////////////////////////////////////////////////////////
bool SoftNodeDesc::
is_joint() const {
return _joint_type == JT_joint || _joint_type == JT_pseudo_joint;
}
#if 0
////////////////////////////////////////////////////////////////////
// Function: SoftNodeDesc::is_joint_parent
// Access: Private
// Description: Returns true if the node is the parent or ancestor of
// a joint.
////////////////////////////////////////////////////////////////////
bool SoftNodeDesc::
is_joint_parent() const {
return _joint_type == JT_joint_parent;
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeDesc::clear_egg
// Access: Private
// Description: Recursively clears the egg pointers from this node
// and all children.
////////////////////////////////////////////////////////////////////
void SoftNodeDesc::
clear_egg() {
_egg_group = (EggGroup *)NULL;
_egg_table = (EggTable *)NULL;
_anim = (EggXfmSAnim *)NULL;
Children::const_iterator ci;
for (ci = _children.begin(); ci != _children.end(); ++ci) {
SoftNodeDesc *child = (*ci);
child->clear_egg();
}
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeDesc::mark_joint_parent
// Access: Private
// Description: Indicates that this node has at least one child that
// is a joint or a pseudo-joint.
////////////////////////////////////////////////////////////////////
void SoftNodeDesc::
mark_joint_parent() {
if (_joint_type == JT_none) {
_joint_type = JT_joint_parent;
if (_parent != (SoftNodeDesc *)NULL) {
_parent->mark_joint_parent();
}
}
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeDesc::check_pseudo_joints
// Access: Private
// Description: Walks the hierarchy, looking for non-joint nodes that
// are both children and parents of a joint. These
// nodes are deemed to be pseudo joints, since the
// converter must treat them as joints.
////////////////////////////////////////////////////////////////////
void SoftNodeDesc::
check_pseudo_joints(bool joint_above) {
if (_joint_type == JT_joint_parent && joint_above) {
// This is one such node: it is the parent of a joint
// (JT_joint_parent is set), and it is the child of a joint
// (joint_above is set).
_joint_type = JT_pseudo_joint;
}
if (_joint_type == JT_joint) {
// If this node is itself a joint, then joint_above is true for
// all child nodes.
joint_above = true;
}
// Don't bother traversing further if _joint_type is none, since
// that means this node has no joint children.
if (_joint_type != JT_none) {
bool any_joints = false;
Children::const_iterator ci;
for (ci = _children.begin(); ci != _children.end(); ++ci) {
SoftNodeDesc *child = (*ci);
child->check_pseudo_joints(joint_above);
if (child->is_joint()) {
any_joints = true;
}
}
// If any children qualify as joints, then any sibling nodes that
// are parents of joints are also elevated to joints.
if (any_joints) {
bool all_joints = true;
for (ci = _children.begin(); ci != _children.end(); ++ci) {
SoftNodeDesc *child = (*ci);
if (child->_joint_type == JT_joint_parent) {
child->_joint_type = JT_pseudo_joint;
} else if (child->_joint_type == JT_none) {
all_joints = false;
}
}
if (all_joints) {
// Finally, if all children are joints, then we are too.
if (_joint_type == JT_joint_parent) {
_joint_type = JT_pseudo_joint;
}
}
}
}
}
#endif

View File

@ -0,0 +1,96 @@
// Filename: softNodeDesc.h
// Created by: masad (03Oct03)
//
////////////////////////////////////////////////////////////////////
//
// 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
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef SOFTNODEDESC_H
#define SOFTNODEDESC_H
#include "pandatoolbase.h"
#include "referenceCount.h"
#include "pointerTo.h"
#include "namable.h"
#include <SAA.h>
class EggGroup;
class EggTable;
class EggXfmSAnim;
////////////////////////////////////////////////////////////////////
// Class : SoftNodeDesc
// Description : Describes a single instance of a node aka element in the Soft
// scene graph, relating it to the corresponding egg
// structures (e.g. node, group, or table entry) that
// will be created.
////////////////////////////////////////////////////////////////////
class SoftNodeDesc : public ReferenceCount, public Namable {
public:
SoftNodeDesc(const string &name = string());
~SoftNodeDesc();
void set_model(SAA_Elem *model);
bool has_model() const;
SAA_Elem *get_model() const;
bool is_joint() const;
// bool is_joint_parent() const;
// SoftNodeDesc *_parent;
// typedef pvector< PT(SoftNodeDesc) > Children;
// Children _children;
private:
void clear_egg();
// void mark_joint_parent();
// void check_pseudo_joints(bool joint_above);
SAA_Elem *_model;
EggGroup *_egg_group;
EggTable *_egg_table;
EggXfmSAnim *_anim;
enum JointType {
JT_none, // Not a joint.
JT_joint, // An actual joint in Soft.
JT_pseudo_joint, // Not a joint in Soft, but treated just like a
// joint for the purposes of the converter.
JT_joint_parent, // A parent or ancestor of a joint or pseudo joint.
};
JointType _joint_type;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
ReferenceCount::init_type();
Namable::init_type();
register_type(_type_handle, "SoftNodeDesc",
ReferenceCount::get_class_type(),
Namable::get_class_type());
}
private:
static TypeHandle _type_handle;
friend class SoftNodeTree;
};
#endif

View File

@ -0,0 +1,454 @@
// Filename: softNodeTree.cxx
// Created by: masad (26Sep03)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2003, 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
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include "softNodeTree.h"
#include "softEggGroupUserData.h"
#include "config_softegg.h"
#include "eggGroup.h"
#include "eggTable.h"
#include "eggXfmSAnim.h"
#include "eggData.h"
#include "dcast.h"
#include <SAA.h>
////////////////////////////////////////////////////////////////////
// Function: SoftNodeTree::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
SoftNodeTree::
SoftNodeTree() {
// _root = new SoftNodeDesc;
_root = NULL;
_fps = 0.0;
_egg_data = (EggData *)NULL;
_egg_root = (EggGroupNode *)NULL;
_skeleton_node = (EggGroupNode *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: GetName
// Access: Public
// Description: Given an element, return a copy of the element's
// name WITHOUT prefix.
////////////////////////////////////////////////////////////////////
char *SoftNodeTree::
GetName( SAA_Scene *scene, SAA_Elem *element ) {
int nameLen;
char *name;
// get the name
SAA_elementGetNameLength( scene, element, &nameLen );
name = new char[++nameLen];
SAA_elementGetName( scene, element, nameLen, name );
return name;
}
////////////////////////////////////////////////////////////////////
// Function: GetFullName
// Access: Public
// Description: Given an element, return a copy of the element's
// name complete with prefix.
////////////////////////////////////////////////////////////////////
char *SoftNodeTree::
GetFullName( SAA_Scene *scene, SAA_Elem *element )
{
int nameLen, prefixLen;
char *name, *prefix;
// get the name length
SAA_elementGetNameLength( scene, element, &nameLen );
// get the prefix length
SAA_elementGetPrefixLength( scene, element, &prefixLen );
// allocate the array to hold name
name = new char[++nameLen];
// allocate the array to hold prefix and length + hyphen
prefix = new char[++prefixLen + nameLen + 4];
// get the name
SAA_elementGetName( scene, element, nameLen, name );
// get the prefix
SAA_elementGetPrefix( scene, element, prefixLen, prefix );
// add 'em together
strcat(prefix, "-");
strcat(prefix, name);
// return string
return prefix;
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeTree::build_node
// Access: Public
// Description: Returns a pointer to the node corresponding to the
// indicated dag_path object, creating it first if
// necessary.
////////////////////////////////////////////////////////////////////
SoftNodeDesc *SoftNodeTree::
build_node(SAA_Elem *model, const char *name) {
string node_name = name;
SoftNodeDesc *node_desc = r_build_node(node_name);
node_desc->set_model(model);
return node_desc;
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeTree::build_complete_hierarchy
// Access: Public
// Description: Walks through the complete Soft hierarchy and builds
// up the corresponding tree.
////////////////////////////////////////////////////////////////////
bool SoftNodeTree::
build_complete_hierarchy(SAA_Scene &scene, SAA_Database &database, char **root_name) {
SI_Error status;
// Get the entire Soft scene.
int numModels;
SAA_Elem *models;
SAA_sceneGetNbModels( &scene, &numModels );
cout << "Scene has " << numModels << " model(s)...\n";
// This while loop walks through the entire Soft hierarchy, one
// node at a time.
bool all_ok = true;
if ( numModels ) {
// allocate array of models
models = (SAA_Elem *) new SAA_Elem[numModels];
if ( models != NULL ) {
if ((status = SAA_sceneGetModels( &scene, numModels, models )) != SI_SUCCESS) {
return false;
}
for ( int i = 0; i < numModels; i++ ) {
int level;
status = SAA_elementGetHierarchyLevel( &scene, &models[i], &level );
cout << "level " << level << endl;
char *name = GetName(&scene, &models[i]);
if ( !level ) {
// this is the root node, so this should be the name of the model
*root_name = name;
}
SoftNodeDesc *node_desc = build_node(&models[i], name);
cout << "status is " << status << "\n";
}
}
}
# if 0
if (all_ok) {
_root->check_pseudo_joints(false);
}
#endif
return all_ok;
}
#if 0
////////////////////////////////////////////////////////////////////
// Function: SoftNodeTree::build_selected_hierarchy
// Access: Public
// Description: Walks through the selected subset of the Soft
// hierarchy (or the complete hierarchy, if nothing is
// selected) and builds up the corresponding tree.
////////////////////////////////////////////////////////////////////
bool SoftNodeTree::
build_selected_hierarchy(char *scene_name) {
MStatus status;
MItDag dag_iterator(MItDag::kDepthFirst, MFn::kTransform, &status);
if (!status) {
status.perror("MItDag constructor");
return false;
}
// Get only the selected geometry.
MSelectionList selection;
status = MGlobal::getActiveSelectionList(selection);
if (!status) {
status.perror("MGlobal::getActiveSelectionList");
return false;
}
// Get the selected geometry only if the selection is nonempty;
// otherwise, get the whole scene anyway.
if (selection.isEmpty()) {
softegg_cat.info()
<< "Selection list is empty.\n";
return build_complete_hierarchy();
}
bool all_ok = true;
unsigned int length = selection.length();
for (unsigned int i = 0; i < length; i++) {
MDagPath root_path;
status = selection.getDagPath(i, root_path);
if (!status) {
status.perror("MSelectionList::getDagPath");
} else {
// Now traverse through the selected dag path and all nested
// dag paths.
dag_iterator.reset(root_path);
while (!dag_iterator.isDone()) {
MDagPath dag_path;
status = dag_iterator.getPath(dag_path);
if (!status) {
status.perror("MItDag::getPath");
} else {
build_node(dag_path);
}
dag_iterator.next();
}
}
}
if (all_ok) {
_root->check_pseudo_joints(false);
}
return all_ok;
}
#endif
////////////////////////////////////////////////////////////////////
// Function: SoftNodeTree::get_num_nodes
// Access: Public
// Description: Returns the total number of nodes in the hierarchy,
// not counting the root node.
////////////////////////////////////////////////////////////////////
int SoftNodeTree::
get_num_nodes() const {
return _nodes.size();
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeTree::get_node
// Access: Public
// Description: Returns the nth node in the hierarchy, in an
// arbitrary ordering.
////////////////////////////////////////////////////////////////////
SoftNodeDesc *SoftNodeTree::
get_node(int n) const {
nassertr(n >= 0 && n < (int)_nodes.size(), NULL);
return _nodes[n];
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeTree::clear_egg
// Access: Public
// Description: Removes all of the references to generated egg
// structures from the tree, and prepares the tree for
// generating new egg structures.
////////////////////////////////////////////////////////////////////
void SoftNodeTree::
clear_egg(EggData *egg_data, EggGroupNode *egg_root,
EggGroupNode *skeleton_node) {
// _root->clear_egg();
_egg_data = egg_data;
_egg_root = egg_root;
_skeleton_node = skeleton_node;
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeTree::get_egg_group
// Access: Public
// Description: Returns the EggGroupNode corresponding to the group
// or joint for the indicated node. Creates the group
// node if it has not already been created.
////////////////////////////////////////////////////////////////////
EggGroup *SoftNodeTree::
get_egg_group(SoftNodeDesc *node_desc) {
nassertr(_egg_root != (EggGroupNode *)NULL, NULL);
if (node_desc->_egg_group == (EggGroup *)NULL) {
// We need to make a new group node.
EggGroup *egg_group;
egg_group = new EggGroup(node_desc->get_name());
if (node_desc->is_joint()) {
egg_group->set_group_type(EggGroup::GT_joint);
}
// For now lets add this group to egg_root.
_egg_root->add_child(egg_group);
#if 0
SoftEggGroupUserData *parent_user_data = NULL;
if (node_desc->_parent == _root) {
// The parent is the root.
_egg_root->add_child(egg_group);
} else {
// The parent is another node.
EggGroup *parent_egg_group = get_egg_group(node_desc->_parent);
parent_egg_group->add_child(egg_group);
if (parent_egg_group->has_user_data()) {
DCAST_INTO_R(parent_user_data, parent_egg_group->get_user_data(), NULL);
}
}
if (node_desc->has_models()) {
// Check for an object type setting, from Oliver's plug-in.
MObject dag_object = node_desc->get_dag_path().node();
string object_type;
if (get_enum_attribute(dag_object, "eggObjectTypes1", object_type)) {
egg_group->add_object_type(object_type);
}
if (get_enum_attribute(dag_object, "eggObjectTypes2", object_type)) {
egg_group->add_object_type(object_type);
}
if (get_enum_attribute(dag_object, "eggObjectTypes3", object_type)) {
egg_group->add_object_type(object_type);
}
// Is the node flagged to be invisible? If it is, and is has no
// other egg flags, it is implicitly tagged "backstage", so it
// won't get converted. (But it might be an invisible collision
// solid, which is why we do this only if it has no other egg
// flags.)
bool visible = true;
get_bool_attribute(dag_object, "visibility", visible);
if (!visible && egg_group->get_num_object_types() == 0) {
egg_group->add_object_type("backstage");
}
// We treat the object type "billboard" as a special case: we
// apply this one right away and also flag the group as an
// instance.
if (egg_group->has_object_type("billboard")) {
egg_group->remove_object_type("billboard");
egg_group->set_group_type(EggGroup::GT_instance);
egg_group->set_billboard_type(EggGroup::BT_axis);
} else if (egg_group->has_object_type("billboard-point")) {
egg_group->remove_object_type("billboard-point");
egg_group->set_group_type(EggGroup::GT_instance);
egg_group->set_billboard_type(EggGroup::BT_point_camera_relative);
}
// We also treat the object type "dcs" and "model" as a special
// case, so we can test for these flags later.
if (egg_group->has_object_type("dcs")) {
egg_group->remove_object_type("dcs");
egg_group->set_dcs_type(EggGroup::DC_default);
}
if (egg_group->has_object_type("model")) {
egg_group->remove_object_type("model");
egg_group->set_model_flag(true);
}
// And "vertex-color" and "double-sided" have meaning only to
// this converter.
SoftEggGroupUserData *user_data;
if (parent_user_data == (SoftEggGroupUserData *)NULL) {
user_data = new SoftEggGroupUserData;
} else {
// Inherit the flags from above.
user_data = new SoftEggGroupUserData(*parent_user_data);
}
if (egg_group->has_object_type("vertex-color")) {
egg_group->remove_object_type("vertex-color");
user_data->_vertex_color = true;
}
if (egg_group->has_object_type("double-sided")) {
egg_group->remove_object_type("double-sided");
user_data->_double_sided = true;
}
egg_group->set_user_data(user_data);
}
#endif
// EggUserData *user_data = new EggUserData;
// egg_group->set_user_data(user_data);
node_desc->_egg_group = egg_group;
}
return node_desc->_egg_group;
}
#if 0
////////////////////////////////////////////////////////////////////
// Function: SoftNodeTree::get_egg_table
// Access: Public
// Description: Returns the EggTable corresponding to the joint
// for the indicated node. Creates the table node if it
// has not already been created.
////////////////////////////////////////////////////////////////////
EggTable *SoftNodeTree::
get_egg_table(SoftNodeDesc *node_desc) {
nassertr(_skeleton_node != (EggGroupNode *)NULL, NULL);
nassertr(node_desc->is_joint(), NULL);
if (node_desc->_egg_table == (EggTable *)NULL) {
// We need to make a new table node.
nassertr(node_desc->_parent != (SoftNodeDesc *)NULL, NULL);
EggTable *egg_table = new EggTable(node_desc->get_name());
node_desc->_anim = new EggXfmSAnim("xform", _egg_data->get_coordinate_system());
node_desc->_anim->set_fps(_fps);
egg_table->add_child(node_desc->_anim);
if (!node_desc->_parent->is_joint()) {
// The parent is not a joint; put it at the top.
_skeleton_node->add_child(egg_table);
} else {
// The parent is another joint.
EggTable *parent_egg_table = get_egg_table(node_desc->_parent);
parent_egg_table->add_child(egg_table);
}
node_desc->_egg_table = egg_table;
}
return node_desc->_egg_table;
}
////////////////////////////////////////////////////////////////////
// Function: SoftNodeTree::get_egg_anim
// Access: Public
// Description: Returns the anim table corresponding to the joint
// for the indicated node. Creates the table node if it
// has not already been created.
////////////////////////////////////////////////////////////////////
EggXfmSAnim *SoftNodeTree::
get_egg_anim(SoftNodeDesc *node_desc) {
get_egg_table(node_desc);
return node_desc->_anim;
}
#endif
////////////////////////////////////////////////////////////////////
// Function: SoftNodeTree::r_build_node
// Access: Private
// Description: The recursive implementation of build_node().
////////////////////////////////////////////////////////////////////
SoftNodeDesc *SoftNodeTree::
r_build_node(const string &name) {
// Otherwise, we have to create it. Do this recursively, so we
// create each node along the path.
SoftNodeDesc *node_desc;
node_desc = new SoftNodeDesc(name);
_nodes.push_back(node_desc);
return node_desc;
}
//
//
//

View File

@ -0,0 +1,76 @@
// Filename: softNodeTree.h
// Created by: masad (03Oct03)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2003, 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
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef SOFTNODETREE_H
#define SOFTNODETREE_H
#include "pandatoolbase.h"
#include "softNodeDesc.h"
#include <SAA.h>
class EggGroup;
class EggTable;
class EggXfmSAnim;
class EggData;
class EggGroupNode;
////////////////////////////////////////////////////////////////////
// Class : SoftNodeTree
// Description : Describes a complete tree of soft nodes for
// conversion.
////////////////////////////////////////////////////////////////////
class SoftNodeTree {
public:
SoftNodeTree();
SoftNodeDesc *build_node(SAA_Elem *model, const char *name);
bool build_complete_hierarchy(SAA_Scene &scene, SAA_Database &database, char **root_name);
// bool build_selected_hierarchy(SAA_Scene *s, SAA_Database *d, char *scene_name);
int get_num_nodes() const;
SoftNodeDesc *get_node(int n) const;
char *GetName(SAA_Scene *scene, SAA_Elem *element);
char *GetFullName(SAA_Scene *scene, SAA_Elem *element);
void clear_egg(EggData *egg_data, EggGroupNode *egg_root,
EggGroupNode *skeleton_node);
EggGroup *get_egg_group(SoftNodeDesc *node_desc);
EggTable *get_egg_table(SoftNodeDesc *node_desc);
EggXfmSAnim *get_egg_anim(SoftNodeDesc *node_desc);
PT(SoftNodeDesc) _root;
float _fps;
private:
EggData *_egg_data;
EggGroupNode *_egg_root;
EggGroupNode *_skeleton_node;
SoftNodeDesc *r_build_node(const string &path);
#if 0
typedef pmap<string, SoftNodeDesc *> NodesByPath;
NodesByPath _nodes_by_path;
#endif
typedef pvector<SoftNodeDesc *> Nodes;
Nodes _nodes;
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,210 @@
// Filename: softToEggConverter.h
// Created by: masad (25Sep03)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2003, 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
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef SOFTTOEGGCONVERTER_H
#define SOFTTOEGGCONVERTER_H
#ifdef _MIN
#undef _MIN
#endif
#ifdef _MAX
#undef _MAX
#endif
#include "pandatoolbase.h"
#include "somethingToEggConverter.h"
#include "softNodeTree.h"
#include <SAA.h>
#include <SI_macros.h>
#include "eggTextureCollection.h"
#include "distanceUnit.h"
#include "coordinateSystem.h"
class EggData;
class EggGroup;
class EggTable;
class EggVertexPool;
class EggNurbsCurve;
class EggPrimitive;
class EggXfmSAnim;
//class MayaShaderColorDef;
////////////////////////////////////////////////////////////////////
// Class : SoftToEggConverter
// Description : This class supervises the construction of an EggData
// structure from a single Softimage file, or from the data
// already in th cout << "egg name = " << eggFilename << endl;e global Softimage model space.
//
////////////////////////////////////////////////////////////////////
class SoftToEggConverter : public SomethingToEggConverter {
public:
SoftToEggConverter(const string &program_name = "");
SoftToEggConverter(const SoftToEggConverter &copy);
virtual ~SoftToEggConverter();
void Help();
void Usage();
void ShowOpts();
bool HandleGetopts(int &idx, int argc, char **argv);
bool DoGetopts(int &argc, char **&argv);
virtual SomethingToEggConverter *make_copy();
virtual string get_name() const;
virtual string get_extension() const;
virtual bool convert_file(const Filename &filename);
bool convert_soft(bool from_selection);
bool open_api();
void close_api();
private:
bool convert_flip(double start_frame, double end_frame,
double frame_inc, double output_frame_rate);
bool convert_char_model();
bool convert_char_chan(double start_frame, double end_frame,
double frame_inc, double output_frame_rate);
bool convert_hierarchy(EggGroupNode *egg_root);
bool process_model_node(SoftNodeDesc *node_desc);
void get_transform(SoftNodeDesc *node_Desc, EggGroup *egg_group);
/*
void get_joint_transform(const MDagPath &dag_path, EggGroup *egg_group);
// I ran into core dumps trying to pass around a MFnMesh object by
// value. From now on, all MFn* objects will be passed around by
// reference.
void make_nurbs_surface(const MDagPath &dag_path,
MFnNurbsSurface &surface,
EggGroup *group);
EggNurbsCurve *make_trim_curve(const MFnNurbsCurve &curve,
const string &nurbs_name,
EggGroupNode *egg_group,
int trim_curve_index);
void make_nurbs_curve(const MDagPath &dag_path,
const MFnNurbsCurve &curve,
EggGroup *group);
*/
void make_polyset(SAA_Elem *model, EggGroup *egg_group, SAA_ModelType type, char *node_name);
/*
void make_locator(const MDagPath &dag_path, const MFnDagNode &dag_node,
EggGroup *egg_group);
bool get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh,
pvector<EggGroup *> &joints, MFloatArray &weights);
*/
char *GetTextureName( SAA_Scene *scene, SAA_Elem *texture );
char *GetModelNoteInfo( SAA_Scene *, SAA_Elem * );
void set_shader_attributes(EggPrimitive &primitive,
SAA_Elem &shader);
void apply_texture_properties(EggTexture &tex);
/*
bool compare_texture_properties(EggTexture &tex,
const MayaShaderColorDef &color_def);
*/
bool reparent_decals(EggGroupNode *egg_parent);
string _program_name;
bool _from_selection;
SoftNodeTree _tree;
SI_Error result;
SAA_Scene scene;
SAA_Elem model;
SAA_Database database;
public:
char *_getopts;
// This is argv[0].
const char *_commandName;
// This is the entire command line.
const char *_commandLine;
char *rsrc_path;
char *database_name;
char *scene_name;
char *model_name;
char *eggFileName;
char *animFileName;
char *eggGroupName;
char *tex_path;
char *tex_filename;
char *search_prefix;
char **texNameArray;
int uRepeat, vRepeat;
float matrix[4][4];
int nurbs_step;
int anim_start;
int anim_end;
int anim_rate;
int pose_frame;
int verbose;
int flatten;
int shift_textures;
int ignore_tex_offsets;
int use_prefix;
bool foundRoot;
bool geom_as_joint;
bool make_anim;
bool make_nurbs;
bool make_poly;
bool make_soft;
bool make_morph;
bool make_duv;
bool make_dart;
bool has_morph;
bool make_pose;
/*
MayaShaders _shaders;
*/
EggTextureCollection _textures;
/*
PT(MayaApi) _maya;
*/
bool _polygon_output;
double _polygon_tolerance;
/*
bool _respect_maya_double_sided;
bool _always_show_vertex_color;
*/
enum TransformType {
TT_invalid,
TT_all,
TT_model,
TT_dcs,
TT_none,
};
TransformType _transform_type;
static TransformType string_transform_type(const string &arg);
};
#endif