remove ObjectType vertex-color, fix animated models
This commit is contained in:
parent
78f67d8afd
commit
7c789acea3
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#define SOURCES \
|
||||
config_mayaegg.cxx config_mayaegg.h \
|
||||
mayaEggGroupUserData.cxx mayaEggGroupUserData.I mayaEggGroupUserData.h \
|
||||
mayaToEggConverter.cxx mayaToEggConverter.h
|
||||
|
||||
#end ss_lib_target
|
||||
|
|
|
|||
|
|
@ -17,8 +17,9 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "config_mayaegg.h"
|
||||
#include "mayaEggGroupUserData.h"
|
||||
|
||||
#include <dconfig.h>
|
||||
#include "dconfig.h"
|
||||
|
||||
Configure(config_mayaegg);
|
||||
NotifyCategoryDef(mayaegg, ":maya");
|
||||
|
|
@ -42,5 +43,7 @@ init_libmayaegg() {
|
|||
return;
|
||||
}
|
||||
initialized = true;
|
||||
|
||||
MayaEggGroupUserData::init_type();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
// Filename: mayaEggGroupUserData.I
|
||||
// Created by: drose (03Jun03)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MayaEggGroupUserData::Constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE MayaEggGroupUserData::
|
||||
MayaEggGroupUserData() {
|
||||
_vertex_color = false;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MayaEggGroupUserData::Copy constructor
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE MayaEggGroupUserData::
|
||||
MayaEggGroupUserData(const MayaEggGroupUserData ©) :
|
||||
EggUserData(copy),
|
||||
_vertex_color(copy._vertex_color)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MayaEggGroupUserData::Copy assignment operator
|
||||
// Access: Public
|
||||
// Description:
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void MayaEggGroupUserData::
|
||||
operator = (const MayaEggGroupUserData ©) {
|
||||
EggUserData::operator = (copy);
|
||||
_vertex_color = copy._vertex_color;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Filename: mayaEggGroupUserData.cxx
|
||||
// Created by: drose (03Jun03)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "mayaEggGroupUserData.h"
|
||||
|
||||
TypeHandle MayaEggGroupUserData::_type_handle;
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
// Filename: mayaEggGroupUserData.h
|
||||
// Created by: drose (03Jun03)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 MAYAEGGGROUPUSERDATA_H
|
||||
#define MAYAEGGGROUPUSERDATA_H
|
||||
|
||||
#include "pandatoolbase.h"
|
||||
#include "eggUserData.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : MayaEggGroupUserData
|
||||
// Description : This class contains extra user data which is
|
||||
// piggybacked onto EggGroup objects for the purpose of
|
||||
// the maya converter.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class MayaEggGroupUserData : public EggUserData {
|
||||
public:
|
||||
INLINE MayaEggGroupUserData();
|
||||
INLINE MayaEggGroupUserData(const MayaEggGroupUserData ©);
|
||||
INLINE void operator = (const MayaEggGroupUserData ©);
|
||||
|
||||
bool _vertex_color;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
EggUserData::init_type();
|
||||
register_type(_type_handle, "MayaEggGroupUserData",
|
||||
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 "mayaEggGroupUserData.I"
|
||||
|
||||
#endif
|
||||
|
|
@ -20,6 +20,7 @@
|
|||
#include "mayaShader.h"
|
||||
#include "maya_funcs.h"
|
||||
#include "config_mayaegg.h"
|
||||
#include "mayaEggGroupUserData.h"
|
||||
|
||||
#include "eggData.h"
|
||||
#include "eggGroup.h"
|
||||
|
|
@ -462,7 +463,7 @@ convert_char_chan(double start_frame, double end_frame, double frame_inc,
|
|||
|
||||
for (ti = _tables.begin(); ti != _tables.end(); ++ti) {
|
||||
JointAnim *joint_anim = (*ti).second;
|
||||
get_transform(joint_anim->_dag_path, tgroup);
|
||||
get_joint_transform(joint_anim->_dag_path, tgroup);
|
||||
joint_anim->_anim->add_data(tgroup->get_transform());
|
||||
}
|
||||
|
||||
|
|
@ -637,7 +638,7 @@ process_model_node(const MDagPath &dag_path, EggGroupNode *egg_root) {
|
|||
|
||||
if (egg_group != (EggGroup *)NULL) {
|
||||
egg_group->set_group_type(EggGroup::GT_joint);
|
||||
get_transform(dag_path, egg_group);
|
||||
get_joint_transform(dag_path, egg_group);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -722,11 +723,20 @@ process_model_node(const MDagPath &dag_path, EggGroupNode *egg_root) {
|
|||
return false;
|
||||
|
||||
} else {
|
||||
if (mayaegg_cat.is_debug()) {
|
||||
mayaegg_cat.debug()
|
||||
<< "Locator at " << dag_path.fullPathName().asChar() << "\n";
|
||||
}
|
||||
|
||||
// Presumably, the locator's position has some meaning to the
|
||||
// end-user, so we will implicitly tag it with the DCS flag so it
|
||||
// won't get flattened out.
|
||||
egg_group->set_dcs_type(EggGroup::DC_net);
|
||||
if (_animation_convert != AC_model) {
|
||||
// For now, don't set the DCS flag on locators within
|
||||
// character models, since egg-optchar doesn't understand
|
||||
// this. Perhaps there's no reason to ever change this, since
|
||||
// locators within character models may not be meaningful.
|
||||
egg_group->set_dcs_type(EggGroup::DC_net);
|
||||
get_transform(dag_path, egg_group);
|
||||
}
|
||||
make_locator(dag_path, dag_node, egg_group, egg_root);
|
||||
|
|
@ -843,20 +853,20 @@ get_transform(const MDagPath &dag_path, EggGroup *egg_group) {
|
|||
switch (_transform_type) {
|
||||
case TT_all:
|
||||
break;
|
||||
|
||||
|
||||
case TT_model:
|
||||
if (!egg_group->get_model_flag() &&
|
||||
egg_group->get_dcs_type() == EggGroup::DC_none) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case TT_dcs:
|
||||
if (egg_group->get_dcs_type() == EggGroup::DC_none) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case TT_none:
|
||||
case TT_invalid:
|
||||
return;
|
||||
|
|
@ -879,6 +889,67 @@ get_transform(const MDagPath &dag_path, EggGroup *egg_group) {
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MayaToEggConverter::get_joint_transform
|
||||
// Access: Private
|
||||
// Description: Extracts the transform on the indicated Maya node,
|
||||
// as appropriate for a joint in an animated character,
|
||||
// and applies it to the indicated node. This is
|
||||
// different from get_transform() in that it does not
|
||||
// respect the _transform_type flag, and it does not
|
||||
// consider the relative transforms within the egg file.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void MayaToEggConverter::
|
||||
get_joint_transform(const MDagPath &dag_path, EggGroup *egg_group) {
|
||||
MStatus status;
|
||||
MObject transformNode = dag_path.transform(&status);
|
||||
// This node has no transform - i.e., it's the world node
|
||||
if (!status && status.statusCode() == MStatus::kInvalidParameter) {
|
||||
return;
|
||||
}
|
||||
|
||||
MFnDagNode transform(transformNode, &status);
|
||||
if (!status) {
|
||||
status.perror("MFnDagNode constructor");
|
||||
return;
|
||||
}
|
||||
|
||||
MTransformationMatrix matrix(transform.transformationMatrix());
|
||||
|
||||
if (mayaegg_cat.is_spam()) {
|
||||
mayaegg_cat.spam()
|
||||
<< " translation: " << matrix.translation(MSpace::kWorld)
|
||||
<< "\n";
|
||||
double d[3];
|
||||
MTransformationMatrix::RotationOrder rOrder;
|
||||
|
||||
matrix.getRotation(d, rOrder, MSpace::kWorld);
|
||||
mayaegg_cat.spam()
|
||||
<< " rotation: ["
|
||||
<< d[0] << ", "
|
||||
<< d[1] << ", "
|
||||
<< d[2] << "]\n";
|
||||
matrix.getScale(d, MSpace::kWorld);
|
||||
mayaegg_cat.spam()
|
||||
<< " scale: ["
|
||||
<< d[0] << ", "
|
||||
<< d[1] << ", "
|
||||
<< d[2] << "]\n";
|
||||
}
|
||||
|
||||
MMatrix mat = matrix.asMatrix();
|
||||
MMatrix ident_mat;
|
||||
ident_mat.setToIdentity();
|
||||
|
||||
if (!mat.isEquivalent(ident_mat, 0.0001)) {
|
||||
egg_group->set_transform
|
||||
(LMatrix4d(mat[0][0], mat[0][1], mat[0][2], mat[0][3],
|
||||
mat[1][0], mat[1][1], mat[1][2], mat[1][3],
|
||||
mat[2][0], mat[2][1], mat[2][2], mat[2][3],
|
||||
mat[3][0], mat[3][1], mat[3][2], mat[3][3]));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: MayaToEggConverter::make_nurbs_surface
|
||||
// Access: Private
|
||||
|
|
@ -1359,7 +1430,11 @@ make_polyset(const MDagPath &dag_path, const MFnMesh &mesh,
|
|||
|
||||
// Save this modeling flag for the vertex color check later (see the
|
||||
// comment below).
|
||||
bool egg_vertex_color = egg_group->has_object_type("vertex-color");
|
||||
bool egg_vertex_color = false;
|
||||
if (egg_group->has_user_data(MayaEggGroupUserData::get_class_type())) {
|
||||
egg_vertex_color =
|
||||
DCAST(MayaEggGroupUserData, egg_group->get_user_data())->_vertex_color;
|
||||
}
|
||||
|
||||
while (!pi.isDone()) {
|
||||
EggPolygon *egg_poly = new EggPolygon;
|
||||
|
|
@ -1762,6 +1837,14 @@ r_get_egg_group(const string &name, const MDagPath &dag_path,
|
|||
egg_group->remove_object_type("model");
|
||||
egg_group->set_model_flag(true);
|
||||
}
|
||||
|
||||
// And "vertex-color" has meaning only to this converter.
|
||||
if (egg_group->has_object_type("vertex-color")) {
|
||||
egg_group->remove_object_type("vertex-color");
|
||||
MayaEggGroupUserData *user_data = new MayaEggGroupUserData;
|
||||
user_data->_vertex_color = true;
|
||||
egg_group->set_user_data(user_data);
|
||||
}
|
||||
}
|
||||
|
||||
_groups.insert(Groups::value_type(name, egg_group));
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ private:
|
|||
bool process_model_node(const MDagPath &dag_path, EggGroupNode *egg_root);
|
||||
bool process_chan_node(const MDagPath &dag_path, EggGroupNode *egg_root);
|
||||
void get_transform(const MDagPath &dag_path, 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
|
||||
|
|
|
|||
Loading…
Reference in New Issue