21 #include "pandatoolbase.h" 22 #include "notifyCategoryProxy.h" 27 #include "eggVertex.h" 28 #include "eggPolygon.h" 29 #include "eggComment.h" 30 #include "eggXfmSAnim.h" 31 #include "eggSAnimData.h" 32 #include "eggPrimitive.h" 33 #include "eggGroupNode.h" 34 #include "eggVertexPool.h" 35 #include "eggPolysetMaker.h" 36 #include "eggNurbsSurface.h" 38 #include "texturePool.h" 40 #include "pre_maya_include.h" 41 #include <maya/MStatus.h> 42 #include <maya/MPxCommand.h> 43 #include <maya/MString.h> 44 #include <maya/MStringArray.h> 45 #include <maya/MArgList.h> 46 #include <maya/MGlobal.h> 47 #include <maya/MObject.h> 48 #include <maya/MFloatPoint.h> 49 #include <maya/MFloatPointArray.h> 50 #include <maya/MFloatArray.h> 51 #include <maya/MPointArray.h> 52 #include <maya/MFnMesh.h> 53 #include <maya/MFnDependencyNode.h> 54 #include <maya/MFnTransform.h> 55 #include <maya/MFnLambertShader.h> 56 #include <maya/MPlug.h> 57 #include <maya/MFnSet.h> 58 #include <maya/MDGModifier.h> 59 #include <maya/MSelectionList.h> 60 #include <maya/MDagPath.h> 61 #include <maya/MFnSingleIndexedComponent.h> 62 #include <maya/MFnDoubleIndexedComponent.h> 63 #include <maya/MPlugArray.h> 64 #include <maya/MDagPathArray.h> 65 #include <maya/MMatrix.h> 66 #include <maya/MTransformationMatrix.h> 67 #include <maya/MFnIkJoint.h> 68 #include <maya/MFnSkinCluster.h> 69 #include <maya/MAnimControl.h> 70 #include <maya/MFnAnimCurve.h> 71 #include <maya/MFnNurbsSurface.h> 72 #include <maya/MFnEnumAttribute.h> 73 #include <maya/MFnSet.h> 74 #include "post_maya_include.h" 76 #include "mayaEggLoader.h" 86 NotifyCategoryDeclNoExport(mayaloader);
87 NotifyCategoryDef(mayaloader,
"");
92 bool ConvertEggData(
EggData *data,
bool merge,
bool model,
bool anim,
bool respect_normals);
93 bool ConvertEggFile(
const char *name,
bool merge,
bool model,
bool anim,
bool respect_normals);
107 MObject GetDependencyNode(
string givenName);
111 typedef phash_map<EggGroup *, MayaEggMesh *, pointer_hash> MeshTable;
112 typedef phash_map<EggXfmSAnim *, MayaAnim *, pointer_hash> AnimTable;
113 typedef phash_map<EggGroup *, MayaEggJoint *, pointer_hash> JointTable;
114 typedef phash_map<EggGroup *, MayaEggGroup *, pointer_hash> GroupTable;
115 typedef phash_map<string, MayaEggTex *, string_hash> TexTable;
116 typedef phash_map<EggGroup *, MayaEggNurbsSurface *, pointer_hash> SurfaceTable;
120 JointTable _joint_tab;
121 GroupTable _group_tab;
123 SurfaceTable _surface_tab;
125 vector <MayaEggJoint *> _joint_list;
130 MTime::Unit _timeUnit;
132 void ParseFrameInfo(
string comment);
137 MSelectionList _collision_nodes;
142 return MPoint(vec[0], vec[1], vec[2]);
145 MFloatPoint MakeMayaPoint(
const LVector3d &vec)
147 return MFloatPoint(vec[0], vec[1], vec[2]);
150 MVector MakeMayaVector(
const LVector3d &vec)
152 return MVector(vec[0], vec[1], vec[2]);
155 MColor MakeMayaColor(
const LColor &vec)
157 return MColor(vec[0], vec[1], vec[2], vec[3]);
162 MStatus create_enum_attribute(MObject &node, MString fullName, MString briefName,
163 MStringArray fieldNames,
unsigned fieldIndex) {
166 MFnDependencyNode fnDN( node, &stat );
167 if ( MS::kSuccess != stat ) {
168 mayaloader_cat.error()
169 <<
"Could not create MFnDependencyNode" <<
"\n";
173 MFnEnumAttribute fnAttr;
174 MObject newAttr = fnAttr.create( fullName, briefName,
176 if ( MS::kSuccess != stat ) {
177 mayaloader_cat.error()
178 <<
"Could not create new enum attribute " << fullName.asChar() <<
"\n";
181 for (
unsigned i = 0; i < fieldNames.length(); i++){
182 fnAttr.addField(fieldNames[i], i);
185 stat = fnAttr.setDefault(fieldIndex);
186 if ( MS::kSuccess != stat ) {
187 mayaloader_cat.error()
188 <<
"Could not set value for enum attribute " << fullName.asChar() <<
"\n";
192 fnAttr.setKeyable(
true );
193 fnAttr.setReadable(
true );
194 fnAttr.setWritable(
true );
195 fnAttr.setStorable(
true );
198 stat = fnDN.addAttribute(newAttr, MFnDependencyNode::kLocalDynamicAttr);
199 if ( MS::kSuccess != stat ) {
200 mayaloader_cat.error()
201 <<
"Could not add new enum attribute " << fullName.asChar() <<
"\n";
219 MObject _file_texture;
221 MObject _shading_group;
223 MFnSingleIndexedComponent _component;
224 void AssignNames(
void);
227 void MayaEggTex::AssignNames(
void)
232 MFnDependencyNode shader(_shader);
233 MFnDependencyNode sgroup(_shading_group);
234 MFnDependencyNode filetex(_file_texture);
235 shader.setName(MString(_name.c_str())+
"Shader");
236 sgroup.setName(MString(_name.c_str()));
237 if (_file_texture != MObject::kNullObj) {
238 filetex.setName(MString(_name.c_str())+
"File");
247 name = etex->get_name();
251 if (_tex_tab.count(fn)) {
256 MFnLambertShader shader;
257 MFnDependencyNode filetex;
273 shader.create(
true,&status);
274 MColor firstColor(1.0,1.0,1.0,1.0);
275 status = shader.setColor(firstColor);
276 if (status != MStatus::kSuccess) {
277 mayaloader_cat.error() <<
"setColor failed on LambertShader\n";
278 status.perror(
"shader setColor failed!");
280 sgroup.create(MSelectionList(), MFnSet::kRenderableOnly, &status);
281 MPlug surfplug = sgroup.findPlug(
"surfaceShader");
282 if (surfplug.connectedTo(oldplugs,
true,
false)) {
283 for (
unsigned int i=0; i<oldplugs.length(); i++) {
284 MPlug src = oldplugs[i];
285 status = dgmod.disconnect(src, surfplug);
286 if (status != MStatus::kSuccess) {
287 status.perror(
"Disconnecting old shader");
291 status = dgmod.connect(shader.findPlug(
"outColor"),surfplug);
292 if (status != MStatus::kSuccess) {
293 status.perror(
"Connecting shader");
296 filetex.create(
"file",&status);
297 MString fn_str(fn.c_str());
298 filetex.findPlug(
"fileTextureName").setValue(fn_str);
299 dgmod.connect(filetex.findPlug(
"outColor"),shader.findPlug(
"color"));
304 if (((tex != NULL) && (tex->get_num_components() == 4))
305 || (etex->get_format() == EggTexture::F_alpha)
306 || (etex->get_format() == EggTexture::F_luminance_alpha))
307 dgmod.connect(filetex.findPlug(
"outTransparency"),shader.findPlug(
"transparency"));
309 status = dgmod.doIt();
310 if (status != MStatus::kSuccess) {
311 status.perror(
"DGMod doIt");
318 res->_file_texture = filetex.object();
319 res->_shader = shader.object();
320 res->_shading_group = sgroup.object();
349 MObject parent = MObject::kNullObj;
352 if (mayaloader_cat.is_debug()) {
353 mayaloader_cat.debug() <<
"parent (group) :" << ((MFnDagNode)parent).name().asChar() << endl;
357 result->_name = group->get_name();
358 result->_group = dgn.create(
"transform", MString(result->_name.c_str()), parent, &status);
359 result->_addedEggFlag =
false;
361 if (group->get_cs_type() != EggGroup::CST_none)
362 _collision_nodes.add(result->_group,
true);
370 MMatrix mat(matData);
372 MTransformationMatrix matrix = MTransformationMatrix(mat);
373 MFnTransform tFn(result->_group, &status);
374 if (status != MStatus::kSuccess) {
375 status.perror(
"MFnTransformNode:create failed!");
381 if (status != MStatus::kSuccess) {
382 status.perror(
"MFnDagNode:create failed!");
385 if ((pg) && (pg->_addedEggFlag ==
false)){
387 MStringArray eggFlags;
388 for (
int i = 0; i < context->get_num_object_types(); i++) {
389 eggFlags.append(MString(context->get_object_type(i).c_str()));
392 for (
unsigned i = 0; i < eggFlags.length(); i++) {
393 MString attrName =
"eggObjectTypes";
394 attrName += (int)(i + 1);
395 status = create_enum_attribute(parent, attrName, attrName, eggFlags, i);
396 if (status != MStatus::kSuccess) {
397 status.perror(
"create_enum_attribute failed!");
400 pg->_addedEggFlag =
true;
403 _group_tab[group] = result;
412 return _group_tab[group];
430 MDagPath _joint_dag_path;
436 vector <MayaEggJoint *> _children;
442 void ChooseEndPos(
double thickness);
444 void AssignNames(
void);
449 xv = _trans.get_row3(0);
450 yv = _trans.get_row3(1);
451 zv = _trans.get_row3(2);
459 void MayaEggJoint::AssignNames(
void)
461 string name = _egg_joint->get_name();
462 MFnDependencyNode joint(_joint);
463 joint.setName(name.c_str());
464 if (mayaloader_cat.is_spam()) {
465 mayaloader_cat.spam() <<
"joint " << joint.name().asChar() <<
": -> " << name << endl;
472 if (mayaloader_cat.is_spam()) {
473 mayaloader_cat.spam() <<
"joint:" << joint->get_name() <<
" is null: " << endl;
478 if (mayaloader_cat.is_spam()) {
479 mayaloader_cat.spam() <<
"joint:" << joint->get_name() <<
" is not a joint: " << endl;
483 return _joint_tab[joint];
489 if (mayaloader_cat.is_debug()) {
490 string parent_name =
"";
492 parent_name = context->get_name();
497 result->_trans = t * parent->_trans;
503 result->_thickness = 0.0;
504 result->_egg_joint = joint;
505 result->_egg_parent = context;
506 result->_parent = parent;
507 result->_joint = MObject::kNullObj;
508 result->_inskin =
false;
511 parent->_children.push_back(result);
513 _joint_tab[joint] = result;
516 _joint_list.push_back(result);
523 if (dir.
length() < 0.001) {
527 double firstbest = -1000;
530 double secondbest = 0;
531 for (
unsigned int i=0; i<_children.size(); i++) {
533 LVector3d tryfwd = child->GetPos() - GetPos();
534 if ((child->GetPos() != firstpos) && (tryfwd.
length() > 0.001)) {
537 double quality = trydir.dot(dir);
538 if (quality > firstbest) {
539 secondbest = firstbest;
541 firstpos = child->GetPos();
543 }
else if (quality > secondbest) {
544 secondbest = quality;
548 if (firstbest > secondbest + 0.1) {
554 void MayaEggJoint::ChooseEndPos(
double thickness)
559 parentpos = _parent->GetPos();
560 parentendpos = _parent->_endpos;
563 if (fwd.
length() < 0.001) {
564 fwd = parentendpos - parentpos;
570 _endpos = fwd * thickness * 0.8 + GetPos();
571 _thickness = thickness * 0.8;
573 _endpos = child->GetPos();
574 _thickness = (_endpos - GetPos()).length();
575 if (_thickness > thickness) _thickness = thickness;
580 if (altaxis.
length() < 0.001) {
581 altaxis = orient.cross(
LVector3d(0,0,1));
583 _perp = altaxis.cross(orient);
587 void MayaEggJoint::CreateMayaBone(
MayaEggGroup *eggParent)
594 rxv = _trans.get_row3(0);
595 ryv = _trans.get_row3(1);
596 rzv = _trans.get_row3(2);
598 MFloatPoint xv(MakeMayaPoint(rxv));
599 MFloatPoint yv(MakeMayaPoint(ryv));
600 MFloatPoint zv(MakeMayaPoint(rzv));
601 MFloatPoint pos(MakeMayaPoint(GetPos()));
602 MFloatPoint endpos(MakeMayaPoint(_endpos));
603 MFloatPoint tzv(MakeMayaPoint(_perp));
605 m[0][0]=xv.x; m[0][1]=xv.y; m[0][2]=xv.z; m[0][3]=0;
606 m[1][0]=yv.x; m[1][1]=yv.y; m[1][2]=yv.z; m[1][3]=0;
607 m[2][0]=zv.x; m[2][1]=zv.y; m[2][2]=zv.z; m[2][3]=0;
608 m[3][0]=pos.x; m[3][1]=pos.y; m[3][2]=pos.z; m[3][3]=1;
612 trans = trans * _parent->_joint_abs.inverse();
614 MTransformationMatrix mtm(trans);
618 ikj.create(_parent->_joint);
623 ikj.create(eggParent->_group);
630 _joint = ikj.object();
631 ikj.getPath(_joint_dag_path);
641 typedef pair<double, EggGroup *> MayaEggWeight;
648 vector<MayaEggWeight> _weights;
683 n = k1._weights.size() - k2._weights.size();
690 for (
unsigned int i=0; i<k1._weights.size(); i++) {
691 double d = k1._weights[i].first - k2._weights[i].first;
698 EggGroup *g1 = k1._weights[i].second;
699 EggGroup *g2 = k2._weights[i].second;
707 n = k1._external_index - k2._external_index;
720 typedef phash_set<MayaEggVertex, MEV_Compare> VertTable;
730 MDagPath _shape_dag_path;
735 MFloatPointArray _vertexArray;
736 MVectorArray _normalArray;
737 MColorArray _vertColorArray;
738 MIntArray _vertColorIndices;
739 MIntArray _vertNormalIndices;
741 MStringArray _eggObjectTypes;
749 virtual void ConnectTextures(
void) = 0;
750 void AssignNames(
void);
751 void AddEggFlag(MString);
758 vtx._sumWeights = 0.0;
762 vtx._pos = vert->
get_pos3() * xform;
763 if (vert->has_normal()) {
764 vtx._normal = vert->get_normal() * xform;
770 vtx._external_index = vert->
get_index()-1;
772 EggVertex::GroupRef::const_iterator gri;
780 mayaloader_cat.warning() <<
"negative weight value " << membership <<
" is replaced with 0 on: " << context->get_name() << endl;
784 vtx._weights.push_back(MayaEggWeight(membership, egg_joint));
785 vtx._sumWeights += membership;
788 if (vtx._weights.size()==0) {
790 vtx._weights.push_back(MayaEggWeight(1.0, context));
791 vtx._sumWeights = 1.0;
806 VertTable::const_iterator vti = _vert_tab.find(vtx);
807 if (vti != _vert_tab.end()) {
811 if (mayaloader_cat.is_spam()) {
813 stream <<
"(" << vti->_pos <<
" " << vti->_normal <<
" " << vti->_uv <<
")\n";
814 stream <<
"[" << vtx._pos <<
" " << vtx._normal <<
" " << vtx._uv <<
"]\n";
815 stream <<
"{" << vert->
get_pos3() <<
" ";
816 if (vert->has_normal()) {
817 stream << vert->get_normal() <<
" ";
823 mayaloader_cat.spam() <<
"found a matching vertex: " << *vert << endl << stream.str() << endl;
829 vtx._index = _vert_count++;
835 _vertexArray.append(MakeMayaPoint(vtx._pos));
836 if (vert->has_normal()) {
837 _normalArray.append(MakeMayaVector(vtx._normal));
838 _vertNormalIndices.append(vtx._index);
840 if (vert->has_color()) {
841 if (mayaloader_cat.is_spam()) {
842 mayaloader_cat.spam() <<
"found a vertex color\n";
844 _vertColorArray.append(MakeMayaColor(vert->
get_color()));
845 _vertColorIndices.append(vtx._index);
847 _vert_tab.insert(vtx);
852 void MayaEggGeom::AssignNames(
void)
854 string name = _pool->get_name();
855 int nsize = name.size();
856 if ((nsize > 6) && (name.rfind(
".verts")==(nsize-6))) {
857 name.resize(nsize-6);
859 if ((nsize > 4) && (name.rfind(
".cvs")==(nsize-4))) {
860 name.resize(nsize-4);
863 MFnDependencyNode dnshape(_shapeNode);
864 MFnDependencyNode dntrans(_transNode);
867 dntrans.setName(MString(name.c_str()));
870 string shape_name = string(dntrans.name().asChar());
871 string numbers (
"0123456789");
874 found=shape_name.find_last_not_of(numbers);
875 if (found!=string::npos)
876 shape_name.insert(found+1,
"Shape");
878 shape_name.append(
"Shape");
880 dnshape.setName(MString(shape_name.c_str()));
883 #define CTRLJOINT_DEFORM ((EggGroup*)((char*)(-1))) 886 EggGroup *MayaEggGeom::GetControlJoint(
void)
889 VertTable::const_iterator vert = _vert_tab.begin();
890 if (vert == _vert_tab.end()) {
893 switch (vert->_weights.size()) {
895 for (++vert; vert != _vert_tab.end(); ++vert) {
896 if (vert->_weights.size() != 0) {
897 return CTRLJOINT_DEFORM;
902 result = vert->_weights[0].second;
903 for (++vert; vert != _vert_tab.end(); ++vert) {
904 if ((vert->_weights.size() != 1) || (vert->_weights[0].second != result)) {
905 return CTRLJOINT_DEFORM;
910 return CTRLJOINT_DEFORM;
914 void MayaEggGeom::AddEggFlag(MString fieldName) {
915 bool addNewFlag =
true;
916 for (
unsigned i = 0; i < _eggObjectTypes.length(); i++) {
917 if (_eggObjectTypes[i] == fieldName) {
923 _eggObjectTypes.append(fieldName);
932 typedef phash_map<LTexCoordd, int> TVertTable;
933 typedef phash_map<LColor, int> CVertTable;
938 MColorArray _faceColorArray;
939 MIntArray _faceIndices;
940 MIntArray _polygonCounts;
941 MIntArray _polygonConnects;
950 vector<MayaEggTex*> _face_tex;
952 TVertTable _tvert_tab;
953 CVertTable _cvert_tab;
956 int GetCVert(
const LColor &col);
957 int AddFace(
unsigned numVertices, MIntArray mvertIndices, MIntArray mtvertIndices,
MayaEggTex *tex);
959 void ConnectTextures(
void);
962 int MayaEggMesh::GetTVert(
const LTexCoordd &uv)
964 if (_tvert_tab.count(uv)) {
965 if (mayaloader_cat.is_spam()) {
966 mayaloader_cat.spam() <<
"found uv coords idx: " << _tvert_tab[uv] << endl;
968 return _tvert_tab[uv];
970 int idx = _tvert_count++;
971 _uarray.append(uv.get_x());
972 _varray.append(uv.get_y());
973 _tvert_tab[uv] = idx;
974 if (mayaloader_cat.is_spam()) {
975 mayaloader_cat.spam() <<
"adding uv coords idx:" << idx << endl;
980 int MayaEggMesh::GetCVert(
const LColor &col)
1000 result->_name = parent->get_name();
1001 result->_pool = pool;
1002 result->_parent = parent;
1003 result->_vert_count = 0;
1004 result->_tvert_count = 0;
1005 result->_cvert_count = 0;
1006 result->_face_count = 0;
1007 result->_vertColorArray.clear();
1008 result->_vertNormalIndices.clear();
1009 result->_vertColorIndices.clear();
1010 result->_faceColorArray.clear();
1011 result->_faceIndices.clear();
1012 result->_eggObjectTypes.clear();
1013 result->_renameTrans =
false;
1014 _mesh_tab[parent] = result;
1019 int MayaEggMesh::AddFace(
unsigned numVertices, MIntArray mvertIndices, MIntArray mtvertIndices,
MayaEggTex *tex)
1021 int idx = _face_count++;
1022 _polygonCounts.append(numVertices);
1023 for (
unsigned i = 0; i < mvertIndices.length(); i++)
1025 _polygonConnects.append(mvertIndices[i]);
1026 _uvIds.append(mtvertIndices[i]);
1028 _face_tex.push_back(tex);
1032 void MayaEggMesh::ConnectTextures(
void)
1034 bool subtex =
false;
1035 for (
int i=1; i<_face_count; i++) {
1036 if (_face_tex[i] != _face_tex[0]) {
1041 MFnSet sg(_face_tex[0]->_shading_group);
1042 sg.addMember(_shapeNode);
1045 for (
int i=0; i<_face_count; i++) {
1047 if (tex->_component.object()==MObject::kNullObj) {
1048 tex->_component.create(MFn::kMeshPolygonComponent);
1050 tex->_component.addElement(i);
1052 for (
int i=0; i<_face_count; i++) {
1054 if (tex->_component.object()!=MObject::kNullObj) {
1055 MFnSet sg(tex->_shading_group);
1056 sg.addMember(_shape_dag_path, tex->_component.object());
1057 tex->_component.setObject(MObject::kNullObj);
1073 MPointArray _cvArray;
1074 MDoubleArray _uKnotArray;
1075 MDoubleArray _vKnotArray;
1081 MFnNurbsSurface::Form _uForm;
1082 MFnNurbsSurface::Form _vForm;
1086 void ConnectTextures(
void);
1087 void PrintData(
void);
1095 result->_pool = pool;
1096 result->_parent = parent;
1097 result->_name = parent->get_name();
1099 result->_vert_count = 0;
1100 result->_vertColorArray.clear();
1101 result->_vertNormalIndices.clear();
1102 result->_vertColorIndices.clear();
1104 result->_cvArray.clear();
1105 result->_uKnotArray.clear();
1106 result->_vKnotArray.clear();
1108 result->_uDegree = 0;
1109 result->_vDegree = 0;
1110 result->_uNumCvs = 0;
1111 result->_vNumCvs = 0;
1112 result->_uForm = MFnNurbsSurface::kClosed;
1113 result->_vForm = MFnNurbsSurface::kClosed;
1115 result->_eggObjectTypes.clear();
1116 result->_renameTrans =
false;
1117 _surface_tab[parent] = result;
1122 void MayaEggNurbsSurface::ConnectTextures(
void)
1129 MColor firstColor(0.5,0.5,0.5,1.0);
1130 if (_vertColorArray.length() > 0) {
1131 firstColor = _vertColorArray[0];
1132 MFnLambertShader sh(_tex->_shader);
1133 status = sh.setColor(firstColor);
1134 if (status != MStatus::kSuccess) {
1135 mayaloader_cat.error() <<
"setColor failed on " << _name;
1136 status.perror(
"shader setColor failed!");
1139 MFnSet sg(_tex->_shading_group);
1140 status = sg.addMember(_shapeNode);
1141 if (status != MStatus::kSuccess) {
1142 mayaloader_cat.error() <<
"addMember failed on " << _name;
1143 status.perror(
"shader addMember failed!");
1148 void MayaEggNurbsSurface::PrintData(
void)
1150 if (mayaloader_cat.is_debug()) {
1151 mayaloader_cat.debug() <<
"nurbsSurface : " << _name << endl;
1153 mayaloader_cat.debug() <<
"u_form : " << _uForm << endl;
1154 mayaloader_cat.debug() <<
"v_form : " << _vForm << endl;
1187 void PrintData(
void);
1192 MayaAnim *result = _anim_tab[pool];
1195 result->_pool = pool;
1196 result->_name = pool->get_name();
1197 _anim_tab[pool] = result;
1200 result->_joint = joint;
1206 void MayaAnim::PrintData(
void)
1208 if (mayaloader_cat.is_debug()) {
1209 mayaloader_cat.debug() <<
"anim on joint : " << _joint->get_name() << endl;
1211 _pool->write(mayaloader_cat.debug(), 0);
1220 void MayaEggLoader::CreateSkinCluster(
MayaEggGeom *M)
1222 MString cmd(
"skinCluster -mi ");
1223 vector <MayaEggJoint *> joints;
1225 VertTable::const_iterator vert;
1226 int maxInfluences = 0;
1227 for (vert=M->_vert_tab.begin(); vert != M->_vert_tab.end(); ++vert) {
1228 if ((
int)(vert->_weights.size()) > maxInfluences) {
1229 maxInfluences = vert->_weights.size();
1231 for (
unsigned int i=0; i<vert->_weights.size(); i++) {
1232 MayaEggJoint *joint = FindJoint(vert->_weights[i].second);
1233 if (joint && !joint->_inskin) {
1234 joint->_inskin =
true;
1235 joint->_index = joints.size();
1236 joints.push_back(joint);
1245 cmd += maxInfluences;
1252 if (joints.size() == 0) {
1257 for (
unsigned int i=0; i<joints.size(); i++) {
1258 MFnDependencyNode joint(joints[i]->_joint);
1260 cmd = cmd + joint.name();
1263 MFnDependencyNode shape(M->_shapeNode);
1265 cmd = cmd + shape.name();
1269 if (mayaloader_cat.is_spam()) {
1270 mayaloader_cat.spam() << cmd.asChar() << endl;
1271 string spamCmd = M->_pool->get_name();
1272 for (
unsigned int i=0; i<joints.size(); i++) {
1273 spamCmd = spamCmd +
" ";
1274 spamCmd = spamCmd + joints[i]->_egg_joint->get_name();
1276 mayaloader_cat.spam() << spamCmd <<
": total = " << joints.size() << endl;
1278 status = dgmod.commandToExecute(cmd);
1279 if (status != MStatus::kSuccess) {
1280 perror(
"skinCluster commandToExecute");
1283 status = dgmod.doIt();
1284 if (status != MStatus::kSuccess) {
1285 perror(
"skinCluster doIt");
1289 MPlugArray oldplugs;
1291 if (shape.typeName() ==
"mesh") {
1292 inPlug = shape.findPlug(
"inMesh");
1293 }
else if (shape.typeName() ==
"nurbsSurface") {
1294 inPlug = shape.findPlug(
"create");
1300 if ((!inPlug.connectedTo(oldplugs,
true,
false))||(oldplugs.length() != 1)) {
1301 cerr <<
"skinCluster command failed";
1304 MFnSkinCluster skinCluster(oldplugs[0].node());
1305 MIntArray influenceIndices;
1306 MFnSingleIndexedComponent component;
1307 component.create(MFn::kMeshVertComponent);
1308 component.setCompleteData(M->_vert_count);
1309 for (
unsigned int i=0; i<joints.size(); i++) {
1310 unsigned int index = skinCluster.indexForInfluenceObject(joints[i]->_joint_dag_path, &status);
1311 if (status != MStatus::kSuccess) {
1312 perror(
"skinCluster index");
1315 influenceIndices.append((
int)index);
1318 MDagPathArray paths;
1319 unsigned infcount = skinCluster.influenceObjects(paths, &status);
1320 if (status != MStatus::kSuccess) {
1321 perror(
"influenceObjects");
1324 for (
unsigned int i=0; i<infcount; i++) {
1325 unsigned int index = skinCluster.indexForInfluenceObject(paths[i], &status);
1326 if (status != MStatus::kSuccess) {
1327 perror(
"skinCluster index");
1330 skinCluster.setWeights(M->_shape_dag_path, component.object(), index, 0.0,
false, NULL);
1334 int tot = M->_vert_count * joints.size();
1335 values.setLength(tot);
1336 for (
int i=0; i<tot; i++) {
1339 for (vert=M->_vert_tab.begin(); vert != M->_vert_tab.end(); ++vert) {
1340 for (
unsigned int i=0; i<vert->_weights.size(); i++) {
1341 double strength = vert->_weights[i].first / vert->_sumWeights;
1342 MayaEggJoint *joint = FindJoint(vert->_weights[i].second);
1343 values[vert->_index * joints.size() + joint->_index] = (PN_stdfloat)strength;
1346 skinCluster.setWeights(M->_shape_dag_path, component.object(), influenceIndices, values,
false, NULL);
1348 for (
unsigned int i=0; i<joints.size(); i++) {
1354 joints[i]->_inskin =
false;
1355 joints[i]->_index = -1;
1368 void MayaEggLoader::TraverseEggNode(
EggNode *node,
EggGroup *context,
string delim)
1370 vector<int> vertIndices;
1371 vector<int> tvertIndices;
1372 vector<int> cvertIndices;
1374 string delstring =
" ";
1376 if (node->
is_of_type(EggPolygon::get_class_type())) {
1383 if (poly->empty()) {
1393 if (mayaloader_cat.is_spam()) {
1394 mayaloader_cat.spam() <<
"Texture format : " << etex->get_format() << endl;
1403 EggPolygon::const_iterator ci;
1405 if (mayaloader_cat.is_spam()) {
1406 mayaloader_cat.spam() <<
"traverse mesh pointer " << mesh <<
"\n";
1408 vertIndices.clear();
1409 tvertIndices.clear();
1410 cvertIndices.clear();
1411 int numVertices = 0;
1412 for (ci = poly->begin(); ci != poly->end(); ++ci) {
1419 vertIndices.push_back(mesh->GetVert(vtx, context));
1420 tvertIndices.push_back(mesh->GetTVert(uv * uvtrans));
1421 cvertIndices.push_back(mesh->GetCVert(vtx->
get_color()));
1424 if (mayaloader_cat.is_spam()) {
1425 mayaloader_cat.spam() <<
"num vertices: " << vertIndices.
size() <<
"\n";
1428 if (numVertices < 3)
1431 MIntArray mvertIndices;
1432 MIntArray mtvertIndices;
1433 for (
int i = 0; i < numVertices; i++) {
1434 mvertIndices.append(vertIndices[i]);
1435 mtvertIndices.append(tvertIndices[i]);
1437 if (poly->has_color()) {
1438 if (mayaloader_cat.is_spam()) {
1439 mayaloader_cat.spam() <<
"found a face color of " << poly->
get_color() << endl;
1441 mesh->_faceIndices.append(mesh->_face_count);
1442 mesh->_faceColorArray.append(MakeMayaColor(poly->
get_color()));
1444 mesh->AddFace(numVertices, mvertIndices, mtvertIndices, tex);
1448 mesh->AddEggFlag(
"double-sided");
1452 if (context->get_model_flag()) {
1453 mesh->AddEggFlag(
"model");
1457 switch (context->get_billboard_type()) {
1458 case EggGroup::BT_axis:
1459 mesh->AddEggFlag(
"billboard");
1462 case EggGroup::BT_point_camera_relative:
1463 mesh->AddEggFlag(
"billboard-point");
1471 for (
int i = 0; i < context->get_num_object_types(); i++) {
1472 mesh->AddEggFlag(MString(context->get_object_type(i).c_str()));
1475 }
else if (node->
is_of_type(EggNurbsSurface::get_class_type())) {
1479 EggNurbsSurface::const_iterator ci;
1483 for (ci = eggNurbsSurface->begin(); ci != eggNurbsSurface->end(); ++ci) {
1485 surface->GetVert(vtx, context);
1497 mayaloader_cat.debug() <<
"uvtrans?" << endl;
1504 surface->_tex = tex;
1509 for (uint ui = 0; ui < surface->_uNumCvs; ui++) {
1510 for (uint vi = 0; vi < surface->_vNumCvs; vi++) {
1512 surface->_cvArray.append(MakeMPoint(vtx->
get_pos3()));
1518 surface->_uKnotArray.append(eggNurbsSurface->
get_u_knot(i));
1523 surface->_vKnotArray.append(eggNurbsSurface->
get_v_knot(i));
1530 surface->_uForm = MFnNurbsSurface::kClosed;
1532 surface->_vForm = MFnNurbsSurface::kOpen;
1536 surface->_vForm = MFnNurbsSurface::kClosed;
1538 surface->_vForm = MFnNurbsSurface::kOpen;
1543 surface->AddEggFlag(
"double-sided");
1547 if (context->get_model_flag()) {
1548 surface->AddEggFlag(
"model");
1552 for (
int i = 0; i < context->get_num_object_types(); i++) {
1553 surface->AddEggFlag(MString(context->get_object_type(i).c_str()));
1556 }
else if (node->
is_of_type(EggComment::get_class_type())) {
1557 string comment = (DCAST(
EggComment, node))->get_comment();
1558 if (comment.find(
"2egg") != string::npos) {
1559 if (mayaloader_cat.is_spam()) {
1560 mayaloader_cat.spam() << delim+delstring <<
"found an EggComment: " << comment << endl;
1562 if (comment.find(
"chan") != string::npos) {
1563 ParseFrameInfo(comment);
1566 }
else if (node->
is_of_type(EggSAnimData::get_class_type())) {
1567 if (mayaloader_cat.is_debug()) {
1568 mayaloader_cat.debug() << delim+delstring <<
"found an EggSAnimData: " << node->get_name() << endl;
1576 }
else if (node->
is_of_type(EggGroupNode::get_class_type())) {
1578 if (node->
is_of_type(EggGroup::get_class_type())) {
1581 if (group->get_name() ==
"") {
1583 stream << _unnamed_idx;
1584 group->set_name(
"unnamed" + stream.str());
1588 string group_name = group->get_name();
1589 size_t found = group_name.find(
":");
1590 if (found != string::npos)
1591 group->set_name(group_name.replace(
int(found), 1,
"_"));
1593 string parent_name =
"";
1595 parent_name = context->get_name();
1597 if (mayaloader_cat.is_debug()) {
1598 mayaloader_cat.debug() << delim+delstring << group->get_name() <<
":" << parent_name << endl;
1600 MakeJoint(group, context);
1604 if (mayaloader_cat.is_debug()) {
1605 mayaloader_cat.debug() << delim+delstring << group->get_name() <<
"@" << parent_name << endl;
1607 MakeGroup(group, context);
1610 }
else if (node->
is_of_type(EggTable::get_class_type())) {
1612 if (mayaloader_cat.is_debug()) {
1613 mayaloader_cat.debug() << delim+delstring <<
"found an EggTable: " << node->get_name() << endl;
1615 }
else if (node->
is_of_type(EggXfmSAnim::get_class_type())) {
1618 if (mayaloader_cat.is_debug()) {
1619 mayaloader_cat.debug() << delim+delstring <<
"found an EggXfmSAnim: " << node->get_name() << endl;
1623 EggGroupNode::const_iterator ci;
1624 for (ci = group->begin(); ci != group->end(); ++ci) {
1625 TraverseEggNode(*ci, context, delim+delstring);
1630 bool MayaEggLoader::ConvertEggData(
EggData *data,
bool merge,
bool model,
bool anim,
bool respect_normals)
1633 mayaloader_cat.error() <<
"Currently, only 'merge' mode is implemented.\n";
1647 _timeUnit = MTime::kFilm;
1650 MeshTable::const_iterator ci;
1651 JointTable::const_iterator ji;
1652 TexTable::const_iterator ti;
1653 SurfaceTable::const_iterator si;
1654 AnimTable::const_iterator ei;
1656 if (MGlobal::isYAxisUp()) {
1662 if (mayaloader_cat.is_debug()) {
1663 mayaloader_cat.debug() <<
"root node: " << data->get_type() << endl;
1665 TraverseEggNode(data, NULL,
"");
1669 MFnSet collision_set;
1670 collision_set.create(_collision_nodes, MFnSet::kNone, &status);
1672 if (mayaloader_cat.is_spam()) {
1673 mayaloader_cat.spam() <<
"num meshes : " << _mesh_tab.size() << endl;
1675 for (ci = _mesh_tab.begin(); ci != _mesh_tab.end(); ++ci) {
1677 if (mesh->_face_count==0) {
1686 MObject parent = MObject::kNullObj;
1688 parent = parentNode->_group;
1689 if (mayaloader_cat.is_debug()) {
1690 mayaloader_cat.debug() <<
"mesh's parent (group) : " << parentNode->_name << endl;
1693 mesh->_renameTrans =
true;
1694 if (mayaloader_cat.is_debug()) {
1695 mayaloader_cat.debug() <<
"mesh's parent (null) : " << endl;
1698 if (mayaloader_cat.is_spam()) {
1699 mayaloader_cat.spam() <<
"mesh pointer : " << mesh <<
" and parent_pointer: " << &parent << endl;
1700 mayaloader_cat.spam() <<
"mesh vert_count : " << mesh->_vert_count << endl;
1701 mayaloader_cat.spam() <<
"mesh face_count : " << mesh->_face_count << endl;
1702 mayaloader_cat.spam() <<
"mesh vertexArray size: " << mesh->_vertexArray.length() << endl;
1703 mayaloader_cat.spam() <<
"mesh polygonCounts size: " << mesh->_polygonCounts.length() << endl;
1704 mayaloader_cat.spam() <<
"mesh polygonConnects size: " << mesh->_polygonConnects.length() << endl;
1705 mayaloader_cat.spam() <<
"mesh uarray size: " << mesh->_uarray.length() << endl;
1706 mayaloader_cat.spam() <<
"mesh varray size: " << mesh->_varray.length() << endl;
1708 mesh->_transNode = mfn.create(mesh->_vert_count, mesh->_face_count,
1709 mesh->_vertexArray, mesh->_polygonCounts, mesh->_polygonConnects,
1710 mesh->_uarray, mesh->_varray,
1712 if (mayaloader_cat.is_spam()) {
1713 mayaloader_cat.spam() <<
"transNode created." << endl;
1716 if (!mesh->_renameTrans) {
1717 mesh->_transNode = parent;
1721 for (
unsigned i = 0; i < mesh->_eggObjectTypes.length(); i++) {
1722 MString attrName =
"eggObjectTypes";
1723 attrName += (int)(i + 1);
1724 status = create_enum_attribute(mesh->_transNode, attrName, attrName, mesh->_eggObjectTypes, i);
1725 if (status != MStatus::kSuccess) {
1726 status.perror(
"create_enum_attribute failed!");
1732 MPlug displayColors = mfn.findPlug(
"displayColors");
1733 displayColors.setValue((
bool)
true);
1735 mesh->_shapeNode = mfn.object();
1736 mfn.getPath(mesh->_shape_dag_path);
1737 mesh->ConnectTextures();
1739 if (mayaloader_cat.is_spam()) {
1740 mayaloader_cat.spam() <<
"textures connected." << endl;
1743 mfn.getCurrentUVSetName(cset);
1744 status = mfn.assignUVs(mesh->_polygonCounts, mesh->_uvIds, &cset);
1746 if (status != MStatus::kSuccess) {
1747 status.perror(
"assignUVs failed");
1748 if (mayaloader_cat.is_spam()) {
1753 if (mayaloader_cat.is_spam()) {
1754 mayaloader_cat.spam() <<
"uvs assigned." << endl;
1759 if (respect_normals) {
1760 status = mfn.setVertexNormals(mesh->_normalArray, mesh->_vertNormalIndices, MSpace::kTransform);
1761 if (status != MStatus::kSuccess) {
1762 status.perror(
"setVertexNormals failed!");
1766 if (mayaloader_cat.is_spam()) {
1767 mayaloader_cat.spam() <<
"vertex normals set." << endl;
1779 status = mfn.setVertexColors(mesh->_vertColorArray, mesh->_vertColorIndices);
1780 if (status != MStatus::kSuccess) {
1781 status.perror(
"setVertexColors failed!");
1783 status = mfn.setFaceColors(mesh->_faceColorArray, mesh->_faceIndices);
1791 for (si = _surface_tab.begin(); si != _surface_tab.end(); ++si) {
1793 if (surface->_cvArray.length()==0) {
1798 MFnNurbsSurface mfnNurbsSurface;
1800 MayaEggGroup *parentNode = FindGroup(surface->_parent);
1801 MObject parent = MObject::kNullObj;
1803 parent = parentNode->_group;
1804 if (mayaloader_cat.is_debug()) {
1805 mayaloader_cat.debug() <<
"surface's parent (group) : " << parentNode->_name << endl;
1808 surface->_renameTrans =
true;
1809 if (mayaloader_cat.is_debug()) {
1810 mayaloader_cat.debug() <<
"surface's parent (null) : " << endl;
1814 surface->_transNode = mfnNurbsSurface.create(surface->_cvArray, surface->_uKnotArray, surface->_vKnotArray,
1815 surface->_uDegree, surface->_vDegree, surface->_uForm, surface->_vForm,
1816 true, parent, &status);
1818 if (!surface->_renameTrans) {
1819 surface->_transNode = parent;
1823 for (
unsigned i = 0; i < surface->_eggObjectTypes.length(); i++) {
1824 MString attrName =
"eggObjectTypes";
1825 attrName += (int)(i + 1);
1826 status = create_enum_attribute(surface->_transNode, attrName, attrName, surface->_eggObjectTypes, i);
1827 if (status != MStatus::kSuccess) {
1828 status.perror(
"create_enum_attribute failed!");
1831 surface->_shapeNode = mfnNurbsSurface.object();
1832 mfnNurbsSurface.getPath(surface->_shape_dag_path);
1833 surface->ConnectTextures();
1835 mayaloader_cat.debug() << status.errorString().asChar() << endl;
1839 double thickness = 0.0;
1840 for (ji = _joint_tab.begin(); ji != _joint_tab.end(); ++ji) {
1842 double dfo = ((*ji).second->GetPos()).length();
1843 if (dfo > thickness) {
1847 if (mayaloader_cat.is_spam()) {
1848 mayaloader_cat.spam() <<
"thickness from joints: " << thickness << endl;
1850 thickness = thickness * 0.025;
1851 for (
unsigned int i=0; i<_joint_list.size(); i++) {
1853 if (mayaloader_cat.is_spam()) {
1854 mayaloader_cat.spam() <<
"creating a joint: " << joint->_egg_joint->get_name() << endl;
1856 joint->ChooseEndPos(thickness);
1857 joint->CreateMayaBone(FindGroup(joint->_egg_parent));
1859 if (mayaloader_cat.is_spam()) {
1860 mayaloader_cat.spam() <<
"went past all the joints" << endl;
1862 for (ci = _mesh_tab.begin(); ci != _mesh_tab.end(); ++ci) {
1864 EggGroup *joint = mesh->GetControlJoint();
1866 CreateSkinCluster(mesh);
1869 for (si = _surface_tab.begin(); si != _surface_tab.end(); ++si) {
1871 EggGroup *joint = surface->GetControlJoint();
1873 CreateSkinCluster(surface);
1876 if (mayaloader_cat.is_spam()) {
1877 mayaloader_cat.spam() <<
"went past creating skin cluster" << endl;
1879 for (ci = _mesh_tab.begin(); ci != _mesh_tab.end(); ++ci) {
1880 (*ci).second->AssignNames();
1882 for (si = _surface_tab.begin(); si != _surface_tab.end(); ++si) {
1883 (*si).second->AssignNames();
1885 if (mayaloader_cat.is_spam()) {
1886 mayaloader_cat.spam() <<
"went past mesh AssignNames" << endl;
1888 for (ji = _joint_tab.begin(); ji != _joint_tab.end(); ++ji) {
1889 (*ji).second->AssignNames();
1891 if (mayaloader_cat.is_spam()) {
1892 mayaloader_cat.spam() <<
"went past joint AssignNames" << endl;
1894 for (ti = _tex_tab.begin(); ti != _tex_tab.end(); ++ti) {
1895 (*ti).second->AssignNames();
1897 if (mayaloader_cat.is_spam()) {
1898 mayaloader_cat.spam() <<
"went past tex AssignNames" << endl;
1901 if (mayaloader_cat.is_debug()) {
1902 mayaloader_cat.debug() <<
"-fri: " << _frame_rate <<
" -sf: " << _start_frame
1903 <<
" -ef: " << _end_frame << endl;
1907 MTime maxFrame(_start_frame - 1, _timeUnit);
1908 MTime minFrame = maxFrame;
1910 for (ei = _anim_tab.begin(); ei != _anim_tab.end(); ++ei) {
1912 MObject node = GetDependencyNode(anim->_joint->get_name());
1913 MFnDagNode mfnNode(node, &status);
1915 MMatrix mMat = mfnNode.transformationMatrix(&status);
1917 MObject attrTX = mfnNode.attribute(
"translateX", &status);
1918 MObject attrTY = mfnNode.attribute(
"translateY", &status);
1919 MObject attrTZ = mfnNode.attribute(
"translateZ", &status);
1920 MObject attrRX = mfnNode.attribute(
"rotateX", &status);
1921 MObject attrRY = mfnNode.attribute(
"rotateY", &status);
1922 MObject attrRZ = mfnNode.attribute(
"rotateZ", &status);
1923 MObject attrSX = mfnNode.attribute(
"scaleX", &status);
1924 MObject attrSY = mfnNode.attribute(
"scaleY", &status);
1925 MObject attrSZ = mfnNode.attribute(
"scaleZ", &status);
1927 MFnAnimCurve mfnAnimCurveTX;
1928 MFnAnimCurve mfnAnimCurveTY;
1929 MFnAnimCurve mfnAnimCurveTZ;
1930 MFnAnimCurve mfnAnimCurveRX;
1931 MFnAnimCurve mfnAnimCurveRY;
1932 MFnAnimCurve mfnAnimCurveRZ;
1933 MFnAnimCurve mfnAnimCurveSX;
1934 MFnAnimCurve mfnAnimCurveSY;
1935 MFnAnimCurve mfnAnimCurveSZ;
1937 mfnAnimCurveTX.create(node, attrTX, MFnAnimCurve::kAnimCurveTL, NULL, &status);
1938 mfnAnimCurveTY.create(node, attrTY, MFnAnimCurve::kAnimCurveTL, NULL, &status);
1939 mfnAnimCurveTZ.create(node, attrTZ, MFnAnimCurve::kAnimCurveTL, NULL, &status);
1940 mfnAnimCurveRX.create(node, attrRX, MFnAnimCurve::kAnimCurveTA, NULL, &status);
1941 mfnAnimCurveRY.create(node, attrRY, MFnAnimCurve::kAnimCurveTA, NULL, &status);
1942 mfnAnimCurveRZ.create(node, attrRZ, MFnAnimCurve::kAnimCurveTA, NULL, &status);
1943 mfnAnimCurveSX.create(node, attrSX, MFnAnimCurve::kAnimCurveTU, NULL, &status);
1944 mfnAnimCurveSY.create(node, attrSY, MFnAnimCurve::kAnimCurveTU, NULL, &status);
1945 mfnAnimCurveSZ.create(node, attrSZ, MFnAnimCurve::kAnimCurveTU, NULL, &status);
1947 MTransformationMatrix matrix( mMat );
1948 MVector trans = matrix.translation(MSpace::kTransform, &status);
1951 MTransformationMatrix::RotationOrder order = MTransformationMatrix::kXYZ;
1952 status = matrix.getRotation(rot, order);
1955 status = matrix.getScale(scale, MSpace::kTransform);
1956 MFnAnimCurve::TangentType tangent = MFnAnimCurve::kTangentClamped;
1957 MTime time(_start_frame - 1, _timeUnit);
1959 mfnAnimCurveTX.addKey(time, trans.x, tangent, tangent, NULL, &status);
1960 mfnAnimCurveTY.addKey(time, trans.y, tangent, tangent, NULL, &status);
1961 mfnAnimCurveTZ.addKey(time, trans.z, tangent, tangent, NULL, &status);
1962 mfnAnimCurveRX.addKey(time, rot[0], tangent, tangent, NULL, &status);
1963 mfnAnimCurveRY.addKey(time, rot[1], tangent, tangent, NULL, &status);
1964 mfnAnimCurveRZ.addKey(time, rot[2], tangent, tangent, NULL, &status);
1965 mfnAnimCurveSX.addKey(time, scale[0], tangent, tangent, NULL, &status);
1966 mfnAnimCurveSY.addKey(time, scale[1], tangent, tangent, NULL, &status);
1967 mfnAnimCurveSZ.addKey(time, scale[2], tangent, tangent, NULL, &status);
1969 for (
int frame = 0; frame < anim->_pool->
get_num_rows(); frame++)
1978 MMatrix mat(matData);
1980 matrix = MTransformationMatrix(mat);
1981 trans = matrix.translation(MSpace::kTransform, &status);
1982 status = matrix.getRotation(rot, order);
1983 status = matrix.getScale(scale, MSpace::kTransform);
1984 time = MTime(frame + _start_frame, _timeUnit);
1986 mfnAnimCurveTX.addKey(time, trans.x, tangent, tangent, NULL, &status);
1987 mfnAnimCurveTY.addKey(time, trans.y, tangent, tangent, NULL, &status);
1988 mfnAnimCurveTZ.addKey(time, trans.z, tangent, tangent, NULL, &status);
1989 mfnAnimCurveRX.addKey(time, rot[0], tangent, tangent, NULL, &status);
1990 mfnAnimCurveRY.addKey(time, rot[1], tangent, tangent, NULL, &status);
1991 mfnAnimCurveRZ.addKey(time, rot[2], tangent, tangent, NULL, &status);
1992 mfnAnimCurveSX.addKey(time, scale[0], tangent, tangent, NULL, &status);
1993 mfnAnimCurveSY.addKey(time, scale[1], tangent, tangent, NULL, &status);
1994 mfnAnimCurveSZ.addKey(time, scale[2], tangent, tangent, NULL, &status);
1996 if (maxFrame < time) {
2002 MAnimControl::setMaxTime(maxFrame);
2003 MAnimControl::setMinTime(minFrame);
2006 for (ci = _mesh_tab.begin(); ci != _mesh_tab.end(); ++ci) {
2007 delete (*ci).second;
2009 for (ji = _joint_tab.begin(); ji != _joint_tab.end(); ++ji) {
2010 delete (*ji).second;
2012 for (ti = _tex_tab.begin(); ti != _tex_tab.end(); ++ti) {
2013 delete (*ti).second;
2015 for (ei = _anim_tab.begin(); ei != _anim_tab.end(); ++ei) {
2016 delete (*ei).second;
2022 mayaloader_cat.info() <<
"Egg import successful\n";
2028 if (mayaloader_cat.is_spam()) {
2029 mayaloader_cat.spam() <<
"Mesh: " << mesh->_name << endl;
2030 mayaloader_cat.spam() <<
"num vertexArray: " << mesh->_vertexArray.length() << endl;
2032 for (
unsigned int i=0; i < mesh->_vertexArray.length(); ++i) {
2033 stream3 <<
"[" << mesh->_vertexArray[i].x <<
" " << mesh->_vertexArray[i].y <<
" " << mesh->_vertexArray[i].z <<
"]" << endl;
2036 mayaloader_cat.spam() <<
"vertexArray: \n" << stream3.str() << endl;
2037 mayaloader_cat.spam() <<
"num polygonConnects: " << mesh->_polygonConnects.length() << endl;
2038 mayaloader_cat.spam() <<
"num uvCounts: " << mesh->_polygonCounts.length() << endl;
2039 mayaloader_cat.spam() <<
"num uvIds: " << mesh->_uvIds.length() << endl;
2042 for (
unsigned int i=0; i < mesh->_polygonCounts.length(); ++i) {
2043 stream1 << mesh->_polygonCounts[i] <<
":->";
2044 stream4 << mesh->_polygonCounts[i] <<
":->";
2045 for (
int j=0; j < mesh->_polygonCounts[i]; ++j, ++k) {
2046 stream1 << mesh->_uvIds[k] <<
",";
2047 stream4 << mesh->_polygonConnects[k] <<
",";
2052 mayaloader_cat.spam() <<
"uvCounts:->uvIds " << endl << stream1.str() << endl;
2053 mayaloader_cat.spam() <<
"vertexCount:->polygonConnects" << endl << stream4.str() << endl;
2057 void MayaEggLoader::ParseFrameInfo(
string comment)
2062 pos = comment.find(
"-fri");
2063 if (pos != string::npos) {
2064 ls = comment.find(
" ", pos+4);
2065 le = comment.find(
" ", ls+1);
2066 if (mayaloader_cat.is_debug()) {
2067 mayaloader_cat.debug() << comment.substr(ls+1, le-ls-1) << endl;
2069 _frame_rate = atoi(comment.substr(ls+1,le-ls-1).data());
2072 switch (_frame_rate) {
2074 _timeUnit = MTime::kGames;
2077 _timeUnit = MTime::kFilm;
2080 _timeUnit = MTime::kPALFrame;
2083 _timeUnit = MTime::kNTSCFrame;
2086 _timeUnit = MTime::kShowScan;
2089 _timeUnit = MTime::kPALField;
2092 _timeUnit = MTime::kNTSCField;
2095 _timeUnit = MTime::k2FPS;
2098 _timeUnit = MTime::k3FPS;
2101 _timeUnit = MTime::k4FPS;
2104 _timeUnit = MTime::k5FPS;
2107 _timeUnit = MTime::k6FPS;
2110 _timeUnit = MTime::k8FPS;
2113 _timeUnit = MTime::k10FPS;
2116 _timeUnit = MTime::k12FPS;
2119 _timeUnit = MTime::k16FPS;
2122 _timeUnit = MTime::k20FPS;
2125 _timeUnit = MTime::k40FPS;
2128 _timeUnit = MTime::k75FPS;
2131 _timeUnit = MTime::k80FPS;
2134 _timeUnit = MTime::k100FPS;
2137 _timeUnit = MTime::kFilm;
2142 pos = comment.find(
"-sf");
2143 if (pos != string::npos) {
2144 ls = comment.find(
" ", pos+3);
2145 le = comment.find(
" ", ls+1);
2146 if (mayaloader_cat.is_debug()) {
2147 mayaloader_cat.debug() << comment.substr(ls+1, le-ls-1) << endl;
2149 if (le == string::npos) {
2150 _start_frame = atoi(comment.substr(ls+1,le).data());
2152 _start_frame = atoi(comment.substr(ls+1,le-ls-1).data());
2156 pos = comment.find(
"-ef");
2157 if (pos != string::npos) {
2158 ls = comment.find(
" ", pos+3);
2159 le = comment.find(
" ", ls+1);
2160 if (mayaloader_cat.is_debug()) {
2161 mayaloader_cat.debug() << comment.substr(ls+1, le-ls-1) << endl;
2163 if (le == string::npos) {
2164 _end_frame = atoi(comment.substr(ls+1,le).data());
2166 _end_frame = atoi(comment.substr(ls+1,le-ls-1).data());
2174 bool MayaEggLoader::ConvertEggFile(
const char *name,
bool merge,
bool model,
bool anim,
bool respect_normals)
2178 if (!data.
read(datafn)) {
2179 mayaloader_cat.error() <<
"Cannot read Egg file for import\n";
2182 return ConvertEggData(&data, merge, model, anim, respect_normals);
2185 MObject MayaEggLoader::GetDependencyNode(
string givenName)
2187 MObject node = MObject::kNullObj;
2191 pos = givenName.find(
":");
2192 if (pos != string::npos) {
2193 name = givenName.substr(pos+1);
2218 JointTable::const_iterator ji;
2219 for (ji = _joint_tab.begin(); ji != _joint_tab.end(); ++ji) {
2221 if (mayaloader_cat.is_spam()) {
2222 mayaloader_cat.spam() <<
"traversing a joint: " << joint->_egg_joint->get_name() << endl;
2224 string jointName = joint->_egg_joint->get_name();
2225 if (jointName == name)
2227 node = joint->_joint;
2241 bool MayaLoadEggData(
EggData *data,
bool merge,
bool model,
bool anim,
bool respect_normals)
2244 bool temp = loader.ConvertEggData(data, merge, model, anim, respect_normals);
2248 bool MayaLoadEggFile(
const char *name,
bool merge,
bool model,
bool anim,
bool respect_normals)
2251 return loader.ConvertEggFile(name, merge, model, anim, respect_normals);
GroupRef::const_iterator gref_end() const
Returns an iterator that can, in conjunction with gref_begin(), be used to traverse the entire set of...
virtual bool is_joint() const
Returns true if this particular node represents a <Joint> entry or not.
This is a 4-by-4 transform matrix.
static int size()
Returns 2: the number of components of a LVecBase2.
int get_u_degree() const
Returns the degree of the surface in the U direction.
int get_num_v_knots() const
Returns the number of knots in the V direction.
int get_num_u_cvs() const
Returns the number of control vertices that should be present in the U direction. ...
int compare_to(const LVecBase2d &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
Specifies parameters that may be passed to the loader.
A base class for nodes in the hierarchy that are not leaf nodes.
LTexCoordd get_uv() const
Returns the unnamed UV coordinate pair on the vertex.
Defines a texture map that may be applied to geometry.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
double get_u_knot(int k) const
Returns the nth knot value defined in the U direction.
int get_vertex_index(int ui, int vi) const
Returns the index number within the EggPrimitive's list of the control vertex at position ui...
EggTexture * get_texture() const
Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive...
This is a two-component point in space.
GroupRef::const_iterator gref_begin() const
Returns an iterator that can, in conjunction with gref_end(), be used to traverse the entire set of g...
LVertexd get_pos3() const
Valid if get_num_dimensions() returns 3 or 4.
This is the primary interface into all the egg data, and the root of the egg file structure...
LColor get_color() const
Returns the color set on this particular attribute.
bool is_closed_v() const
Returns true if the surface appears to be closed in the V direction.
size_t get_hash() const
Returns a suitable hash for phash_map.
int get_num_v_cvs() const
Returns the number of control vertices that should be present in the V direction. ...
void set_coordinate_system(CoordinateSystem coordsys)
Changes the coordinate system of the EggData.
virtual bool cleanup()
Cleans up modeling errors in whatever context this makes sense.
double length() const
Returns the length of the vector, by the Pythagorean theorem.
bool normalize()
Normalizes the vector in place.
The main glue of the egg hierarchy, this corresponds to the <Group>, <Instance>, and <Joint> type nod...
This is a 3-by-3 transform matrix.
int get_index() const
Returns the index number of the vertex within its pool.
The name of a file, such as a texture file or an Egg file.
Any one-, two-, three-, or four-component vertex, possibly with attributes such as a normal...
This corresponds to an <Xfm$Anim_S$> entry, which is a collection of up to nine <S$Anim> entries that...
bool read(Filename filename, string display_name=string())
Opens the indicated filename and reads the egg data contents from it.
LVecBase3d get_row3(int row) const
Retrieves the row column of the matrix as a 3-component vector, ignoring the last column...
bool has_uv() const
Returns true if the vertex has an unnamed UV coordinate pair, false otherwise.
double get_vertex_membership(const EggVertex *vert) const
Returns the amount of membership of the indicated vertex in this group.
bool has_texture() const
Returns true if the primitive has any textures specified, false otherwise.
static Texture * load_texture(const Filename &filename, int primary_file_num_channels=0, bool read_mipmaps=false, const LoaderOptions &options=LoaderOptions())
Loads the given filename up into a texture, if it has not already been loaded, and returns the new te...
const Filename & get_fullpath() const
Returns the full pathname to the file, if it is known; otherwise, returns the same thing as get_filen...
bool is_closed_u() const
Returns true if the surface appears to be closed in the U direction.
This is the base class for all three-component vectors and points.
void get_value(int row, LMatrix4d &mat) const
Returns the value of the aggregate row of the table as a matrix.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
double get_cell(int row, int col) const
Returns a particular element of the matrix.
int get_num_rows() const
Returns the effective number of rows in the table.
A base class for things that may be directly added into the egg hierarchy.
A parametric NURBS surface.
double get_v_knot(int k) const
Returns the nth knot value defined in the V direction.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
static const LMatrix3d & ident_mat()
Returns an identity matrix.
int compare_to(const LVecBase3d &other) const
This flavor of compare_to uses a default threshold value based on the numeric type.
bool get_bface_flag() const
Retrieves the backfacing flag of the polygon.
int get_v_degree() const
Returns the degree of the surface in the V direction.
int get_num_u_knots() const
Returns the number of knots in the U direction.
string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
A collection of vertices.
EggVertexPool * get_pool() const
Returns the vertex pool associated with the vertices of the primitive, or NULL if the primitive has n...
EggVertex * get_vertex(int index) const
Returns a particular index based on its index number.
const LMatrix4d & get_vertex_to_node() const
Returns the transformation matrix suitable for converting the vertices as read from the egg file into...
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).
size_t add_hash(size_t hash) const
Adds the vector into the running hash.