bool getDagPathByChildName(MDagPath & ioDagPath, const std::string & iChildName) { unsigned int numChildren = ioDagPath.childCount(); std::string strippedName = stripPathAndNamespace(iChildName); MObject closeMatch; for (unsigned int i = 0; i < numChildren; ++i) { MObject child = ioDagPath.child(i); MFnDagNode dagChild(child); std::string name = dagChild.partialPathName().asChar(); if (name == iChildName) { ioDagPath.push(child); return true; } if (closeMatch.isNull()) { if (strippedName == stripPathAndNamespace(name)) { closeMatch = child; } } } if (!closeMatch.isNull()) { ioDagPath.push(closeMatch); return true; } return false; }
void LiveScene::getChildDags( const MDagPath& dagPath, MDagPathArray& paths ) const { for( unsigned i=0; i < dagPath.childCount(); ++i ) { MDagPath childPath = dagPath; childPath.push( dagPath.child( i ) ); if( dagPath.length() == 0 ) { // bizarrely, this iterates through things like the translate manipulator and // the view cube too, so lets skip them so they don't show up: if( childPath.node().hasFn( MFn::kManipulator3D ) ) { continue; } // looks like it also gives us the ground plane, so again, lets skip that: if( childPath.fullPathName() == "|groundPlane_transform" ) { continue; } } paths.append( childPath ); } }
MStatus GetShapeNode(MDagPath& path, bool intermediate) { MStatus status; if (IsShapeNode(path)) { // Start at the transform so we can honor the intermediate flag. path.pop(); } if (path.hasFn(MFn::kTransform)) { unsigned int shapeCount = path.childCount(); for (unsigned int i = 0; i < shapeCount; ++i) { status = path.push(path.child(i)); CHECK_MSTATUS_AND_RETURN_IT(status); if (!IsShapeNode(path)) { path.pop(); continue; } MFnDagNode fnNode(path, &status); CHECK_MSTATUS_AND_RETURN_IT(status); if ((!fnNode.isIntermediateObject() && !intermediate) || (fnNode.isIntermediateObject() && intermediate)) { return MS::kSuccess; } // Go to the next shape path.pop(); } } // No valid shape node found. return MS::kFailure; }
// ------------------------------------------------------------ void SceneGraph::findForcedNodes() { MStatus status; if ( mExportSelectedOnly ) { MSelectionList selectedItems; MGlobal::getActiveSelectionList ( selectedItems ); uint selectedCount = selectedItems.length(); MDagPathArray queue; for ( uint i = 0; i < selectedCount; ++i ) { MDagPath selectedPath; status = selectedItems.getDagPath ( i, selectedPath ); if ( status == MStatus::kSuccess ) queue.append ( selectedPath ); } while ( queue.length() > 0 ) { MDagPath selectedPath = queue[queue.length() - 1]; queue.remove ( queue.length() - 1 ); // Queue up the children. uint childCount = selectedPath.childCount(); for ( uint i = 0; i < childCount; ++i ) { MObject node = selectedPath.child ( i ); MDagPath childPath = selectedPath; childPath.push ( node ); queue.append ( childPath ); } // Look for a mesh if ( selectedPath.node().hasFn ( MFn::kMesh ) ) { // export forced nodes in path addForcedNodes ( selectedPath ); } } } else { for ( MItDag dagIt ( MItDag::kBreadthFirst ); !dagIt.isDone(); dagIt.next() ) { MDagPath currentPath; status = dagIt.getPath ( currentPath ); if ( status == MStatus::kSuccess ) { MFnDagNode node ( currentPath ); String nodeName = node.name().asChar(); if ( currentPath.node().hasFn ( MFn::kMesh ) ) { // export forced nodes in path addForcedNodes ( currentPath ); } } } } }
// todo: extend with own light extensions. bool isLightTransform(MDagPath& dagPath) { uint numChilds = dagPath.childCount(); for (uint chId = 0; chId < numChilds; chId++) { MDagPath childPath = dagPath; MStatus stat = childPath.push(dagPath.child(chId)); if (!stat) { continue; } if (childPath.node().hasFn(MFn::kLight)) return true; } return false; }
bool findCamera(MDagPath& dagPath) { if (dagPath.node().hasFn(MFn::kCamera)) return true; uint numChilds = dagPath.childCount(); for (uint chId = 0; chId < numChilds; chId++) { MDagPath childPath = dagPath; MStatus stat = childPath.push(dagPath.child(chId)); if (!stat) { continue; } MString childName = childPath.fullPathName(); return findCamera(childPath); } return false; }
// ------------------------------------------------------------ bool SceneGraph::createChildSceneElements ( SceneElement* sceneElement ) { // Get the current path MDagPath dagPath = sceneElement->getPath(); // Now, whip through this node's DAG children MFnDagNode dagFn ( dagPath ); uint childCount = dagFn.childCount(); for ( uint i = 0; i < childCount; ++i ) { MObject child = dagFn.child ( i ); MDagPath childDagPath = dagPath; childDagPath.push ( child ); SceneElement* childSceneElement = createSceneElement ( childDagPath, sceneElement ); // Recursive call to take the children createChildSceneElements ( childSceneElement ); } return true; }
void DMPDSExporter::traverseSubSkeleton( DMPParameters* param, const MDagPath& dagPath ) { MStatus stat; fillSubSkeleton(param, dagPath); // look for meshes and cameras within the node's children for (unsigned int i=0; i<dagPath.childCount(); i++) { MObject child = dagPath.child(i); MDagPath childPath = dagPath; stat = childPath.push(child); if (MStatus::kSuccess != stat) { std::cout << "Error retrieving path to child " << i << " of: " << dagPath.fullPathName().asChar(); std::cout.flush(); return; } fillSubSkeleton(param, childPath); if (MStatus::kSuccess != stat) { return; } } }
// -------------------------------------- void ReferenceManager::processReference ( const MObject& referenceNode ) { MStatus status; MFnDependencyNode referenceNodeFn ( referenceNode, &status ); if (status != MStatus::kSuccess) return; #if MAYA_API_VERSION >= 600 MString referenceNodeName = MFnDependencyNode( referenceNode ).name(); Reference* reference = new Reference(); reference->referenceNode = referenceNode; mReferences.push_back ( reference ); // Get the paths of the root transforms included in this reference MObjectArray subReferences; getRootObjects ( referenceNode, reference->paths, subReferences ); uint pathCount = reference->paths.length(); // Process the sub-references first uint subReferenceCount = subReferences.length(); for (uint i = 0; i < subReferenceCount; ++i) { MObject& subReference = subReferences[i]; if ( subReference != MObject::kNullObj ) processReference ( subReference ); } // Retrieve the reference node's filename MString command = MString("reference -rfn \"") + referenceNodeFn.name() + MString("\" -q -filename;"); MString filename; status = MGlobal::executeCommand ( command, filename ); if (status != MStatus::kSuccess || filename.length() == 0) return; // Strip the filename of the multiple file token int stripIndex = filename.index('{'); if (stripIndex != -1) filename = filename.substring(0, stripIndex - 1); // Avoid transform look-ups on COLLADA references. int extLocation = filename.rindex('.'); if (extLocation > 0) { MString ext = filename.substring(extLocation + 1, filename.length() - 1).toLowerCase(); if (ext == "dae" || ext == "xml") return; } // Check for already existing file information // Otherwise create a new file information sheet with current node names for ( ReferenceFileList::iterator it = mFiles.begin(); it != mFiles.end(); ++it ) { if ((*it)->filename == filename) { reference->file = (*it); break; } } if ( reference->file == NULL ) reference->file = processReferenceFile(filename); // Get the list of the root transform's first child's unreferenced parents. // This is a list of the imported nodes! for (uint j = 0; j < pathCount; ++j) { MDagPath path = reference->paths[j]; if (path.childCount() > 0) { path.push ( path.child(0) ); MFnDagNode childNode ( path ); if (!childNode.object().hasFn(MFn::kTransform)) continue; uint parentCount = childNode.parentCount(); for (uint k = 0; k < parentCount; ++k) { MFnDagNode parentNode(childNode.parent(k)); if (parentNode.object() == MObject::kNullObj || parentNode.isFromReferencedFile()) continue; MDagPath parentPath = MDagPath::getAPathTo(parentNode.object()); if (parentPath.length() > 0) { ReferenceRootList::iterator it = reference->reroots.insert( reference->reroots.end(), ReferenceRoot() ); (*it).index = j; (*it).reroot = parentPath; } } } } #endif }
void DMPDSExporter::fillBones( DMPSkeletonData::SubSkeletonStruct* subSkel, string parent, DMPParameters* param, MDagPath& jointDag ) { MStatus status; if (jointDag.apiType() != MFn::kJoint) { return; // early out. } DMPSkeletonData::BoneStruct newBone; newBone.boneHandle = (unsigned int)subSkel->bones.size(); newBone.name = jointDag.partialPathName().asUTF8(); newBone.parentName = parent; MFnIkJoint fnJoint(jointDag, &status); // matrix = [S] * [RO] * [R] * [JO] * [IS] * [T] /* These matrices are defined as follows: •[S] : scale •[RO] : rotateOrient (attribute name is rotateAxis) •[R] : rotate •[JO] : jointOrient •[IS] : parentScaleInverse •[T] : translate The methods to get the value of these matrices are: •[S] : getScale •[RO] : getScaleOrientation •[R] : getRotation •[JO] : getOrientation •[IS] : (the inverse of the getScale on the parent transformation matrix) •[T] : translation */ MVector trans = fnJoint.getTranslation(MSpace::kTransform); double scale[3]; fnJoint.getScale(scale); MQuaternion R, RO, JO; fnJoint.getScaleOrientation(RO); fnJoint.getRotation(R); fnJoint.getOrientation(JO); MQuaternion rot = RO * R * JO; newBone.translate[0] = trans.x * param->lum; newBone.translate[1] = trans.y * param->lum; newBone.translate[2] = trans.z * param->lum; newBone.orientation[0] = rot.w; newBone.orientation[1] = rot.x; newBone.orientation[2] = rot.y; newBone.orientation[3] = rot.z; newBone.scale[0] = scale[0]; newBone.scale[1] = scale[1]; newBone.scale[2] = scale[2]; subSkel->bones.push_back(newBone); // Load child joints for (unsigned int i=0; i<jointDag.childCount();i++) { MObject child; child = jointDag.child(i); MDagPath childDag = jointDag; childDag.push(child); fillBones(subSkel, newBone.name, param, childDag); } // now go for animations if (param->bExportSkelAnimation) { for (unsigned int i = 0; i < subSkel->animations.size(); ++i) { DMPSkeletonData::TransformAnimation& anim = subSkel->animations[i]; DMPSkeletonData::TransformTrack subTrack; subTrack.targetBone = newBone.name; MPlug plugT; // translate MPlug plugR; // R MPlug plugRO; // RO MPlug plugJO; // JO MPlug plugS; // scale double dataT[3]; double dataR[3]; double dataRO[3]; double dataJO[3]; double dataS[3]; MFnDependencyNode fnDependNode( jointDag.node(), &status ); plugT = fnDependNode.findPlug("translate", false, &status); plugR = fnDependNode.findPlug("rotate", false, &status); plugRO = fnDependNode.findPlug("rotateAxis", false, &status); plugJO = fnDependNode.findPlug("jointOrient", false, &status); plugS = fnDependNode.findPlug("scale", false, &status); float timeStep = param->samplerRate; if (param->animSampleType == DMPParameters::AST_Frame) { timeStep /= param->fps; } for (float curTime = anim.startTime; curTime <= anim.endTime; curTime += timeStep) { MTime mayaTime; DMPSkeletonData::TransformKeyFrame keyframe; keyframe.time = curTime - anim.startTime; mayaTime.setUnit(MTime::kSeconds); mayaTime.setValue(curTime); // Get its value at the specified Time. plugT.child(0).getValue(dataT[0], MDGContext(mayaTime)); plugT.child(1).getValue(dataT[1], MDGContext(mayaTime)); plugT.child(2).getValue(dataT[2], MDGContext(mayaTime)); plugR.child(0).getValue(dataR[0], MDGContext(mayaTime)); plugR.child(1).getValue(dataR[1], MDGContext(mayaTime)); plugR.child(2).getValue(dataR[2], MDGContext(mayaTime)); plugRO.child(0).getValue(dataRO[0], MDGContext(mayaTime)); plugRO.child(1).getValue(dataRO[1], MDGContext(mayaTime)); plugRO.child(2).getValue(dataRO[2], MDGContext(mayaTime)); plugJO.child(0).getValue(dataJO[0], MDGContext(mayaTime)); plugJO.child(1).getValue(dataJO[1], MDGContext(mayaTime)); plugJO.child(2).getValue(dataJO[2], MDGContext(mayaTime)); plugS.child(0).getValue(dataS[0], MDGContext(mayaTime)); plugS.child(1).getValue(dataS[1], MDGContext(mayaTime)); plugS.child(2).getValue(dataS[2], MDGContext(mayaTime)); // fill the frame. keyframe.translate[0] = dataT[0] * param->lum; keyframe.translate[1] = dataT[1] * param->lum; keyframe.translate[2] = dataT[2] * param->lum; // calculate quaternion. MEulerRotation rotR(dataR[0], dataR[1], dataR[2]); MEulerRotation rotRO(dataRO[0], dataRO[1], dataRO[2]); MEulerRotation rotJO(dataJO[0], dataJO[1], dataJO[2]); MQuaternion finalRot = rotRO.asQuaternion()*rotR.asQuaternion()*rotJO.asQuaternion(); keyframe.orientation[0] = finalRot.w; keyframe.orientation[1] = finalRot.x; keyframe.orientation[2] = finalRot.y; keyframe.orientation[3] = finalRot.z; keyframe.scale[0] = dataS[0]; keyframe.scale[1] = dataS[1]; keyframe.scale[2] = dataS[2]; subTrack.frames.push_back(keyframe); } anim.tracks.push_back(subTrack); } } }
// Load a joint void skeleton::loadJoint(MDagPath& jointDag,joint* parent) { int i; joint newJoint; joint* parentJoint = parent; if (jointDag.hasFn(MFn::kJoint)) { MFnIkJoint jointFn(jointDag); // Get parent index int idx=-1; if (parent) { idx = parent->id; } // Get joint matrix MMatrix worldMatrix = jointDag.inclusiveMatrix(); /*float translation1[3]; float rotation1[4]; float scale1[3]; extractTranMatrix(worldMatrix,translation1,rotation1,scale1); Quaternion q(rotation1[0],rotation1[1],rotation1[2],rotation1[3]); float angle; Vector3 axis; q.ToAngleAxis(angle,axis); Vector3 x,y,z; q.ToAxes(x,y,z);*/ //printMatrix(worldMatrix); // Calculate scaling factor inherited by parent // Calculate Local Matrix MMatrix localMatrix = worldMatrix; if (parent) localMatrix = worldMatrix * parent->worldMatrix.inverse(); float translation2[3]; float rotation2[4]; float scale2[3]; extractTranMatrix(worldMatrix,translation2,rotation2,scale2); //printMatrix(localMatrix); // Set joint info newJoint.name = jointFn.partialPathName(); newJoint.id = m_joints.size(); newJoint.parentIndex = idx; newJoint.jointDag = jointDag; newJoint.worldMatrix = worldMatrix; newJoint.localMatrix = localMatrix; for (int iRow = 0; iRow < 4; iRow++) for (int iCol = 0; iCol < 3; iCol++) newJoint.tran.m_mat[iRow][iCol] = (FLOAT)worldMatrix[iRow][iCol]; //printMatrix(worldMatrix); /*MQuaternion q; q = worldMatrix; newJoint.tran.q[0] = (float)q.x; newJoint.tran.q[1] = (float)q.y; newJoint.tran.q[2] = (float)q.z; newJoint.tran.q[3] = (float)q.w; newJoint.tran.t[0] = (float)worldMatrix[3][0]; newJoint.tran.t[1] = (float)worldMatrix[3][1]; newJoint.tran.t[2] = (float)worldMatrix[3][2];*/ MPlug plug = jointFn.findPlug("unRibbonEnabled"); if(!plug.isNull()) { bool enabled; plug.getValue(enabled); if(enabled) { plug = jointFn.findPlug("unRibbonVisible"); bool visible; plug.getValue(visible); plug = jointFn.findPlug("unRibbonAbove"); float above; plug.getValue(above); plug = jointFn.findPlug("unRibbonBelow"); float below; plug.getValue(below); plug = jointFn.findPlug("unRibbonEdgesPerSecond"); short edgePerSecond; plug.getValue(edgePerSecond); plug = jointFn.findPlug("unRibbonEdgeLife"); float edgeLife; plug.getValue(edgeLife); plug = jointFn.findPlug("unRibbonGravity"); float gravity; plug.getValue(gravity); plug = jointFn.findPlug("unRibbonTextureRows"); short rows; plug.getValue(rows); plug = jointFn.findPlug("unRibbonTextureCols"); short cols; plug.getValue(cols); plug = jointFn.findPlug("unRibbonTextureSlot"); short slot; plug.getValue(slot); plug = jointFn.findPlug("unRibbonVertexColor"); MObject object; plug.getValue(object); MFnNumericData data(object); float r,g,b; data.getData(r,g,b); plug = jointFn.findPlug("unRibbonVertexAlpha"); float alpha; plug.getValue(alpha); plug = jointFn.findPlug("unRibbonBlendMode"); short blendMode; plug.getValue(blendMode); plug = jointFn.findPlug("unRibbonTextureFilename"); MItDependencyGraph dgIt(plug, MFn::kFileTexture, MItDependencyGraph::kUpstream, MItDependencyGraph::kBreadthFirst, MItDependencyGraph::kNodeLevel); dgIt.disablePruningOnFilter(); MString textureName; if (!dgIt.isDone()) { MObject textureNode = dgIt.thisNode(); MPlug filenamePlug = MFnDependencyNode(textureNode).findPlug("fileTextureName"); filenamePlug.getValue(textureName); } else { char str[256]; sprintf(str,"%s ribbon system must has file-texture",newJoint.name.asChar()); MessageBox(0,str,0,0); } newJoint.hasRibbonSystem = true; newJoint.ribbon.visible = visible; newJoint.ribbon.above = above; newJoint.ribbon.below = below; newJoint.ribbon.gravity = gravity; newJoint.ribbon.edgePerSecond = edgePerSecond; newJoint.ribbon.edgeLife = edgeLife; newJoint.ribbon.rows = rows; newJoint.ribbon.cols = cols; newJoint.ribbon.slot = slot; newJoint.ribbon.color[0] = r; newJoint.ribbon.color[1] = g; newJoint.ribbon.color[2] = b; newJoint.ribbon.alpha = alpha; newJoint.ribbon.blendMode = blendMode; newJoint.ribbon.textureFilename = textureName.asChar(); } } plug = jointFn.findPlug("unParticleEnabled"); if(!plug.isNull()) { bool enabled; plug.getValue(enabled); if(enabled) { newJoint.hasParticleSystem = true; plug = jointFn.findPlug("unParticleVisible"); bool visible; plug.getValue(visible); plug = jointFn.findPlug("unParticleSpeed"); float speed; plug.getValue(speed); plug = jointFn.findPlug("unParticleVariationPercent"); float variation; plug.getValue(variation); plug = jointFn.findPlug("unParticleConeAngle"); float coneAngle; plug.getValue(coneAngle); plug = jointFn.findPlug("unParticleGravity"); float gravity; plug.getValue(gravity); plug = jointFn.findPlug("unParticleExplosiveForce"); float explosiveForce = 0.0f; if(!plug.isNull()) { plug.getValue(explosiveForce); } plug = jointFn.findPlug("unParticleLife"); float life; plug.getValue(life); plug = jointFn.findPlug("unParticleLifeVariation"); float lifeVar; if(plug.isNull()) { lifeVar = 0.0f; } else { plug.getValue(lifeVar); } plug = jointFn.findPlug("unParticleEmissionRate"); float emissionRate; plug.getValue(emissionRate); plug = jointFn.findPlug("unParticleLimitNum"); short limitNum; plug.getValue(limitNum); plug = jointFn.findPlug("unParticleInitialNum"); short initialNum = 0; if(!plug.isNull())plug.getValue(initialNum); plug = jointFn.findPlug("unParticleAttachToEmitter"); bool attachToEmitter; plug.getValue(attachToEmitter); plug = jointFn.findPlug("unParticleMoveWithEmitter"); bool moveWithEmitter = false; if(!plug.isNull())plug.getValue(moveWithEmitter); //23 plug = jointFn.findPlug("unParticleForTheSword"); bool forTheSword = false; if(!plug.isNull())plug.getValue(forTheSword); //24 plug = jointFn.findPlug("unParticleForTheSwordInitialAngle"); float forTheSwordInitialAngle = 0; if(!plug.isNull())plug.getValue(forTheSwordInitialAngle); //25 plug = jointFn.findPlug("unParticleWander"); bool wander = false; if(!plug.isNull())plug.getValue(wander); //25 plug = jointFn.findPlug("unParticleWanderRadius"); float wanderRadius = 0.0f; if(!plug.isNull())plug.getValue(wanderRadius); //25 plug = jointFn.findPlug("unParticleWanderSpeed"); float wanderSpeed = 0.0f; if(!plug.isNull())plug.getValue(wanderSpeed); plug = jointFn.findPlug("unParticleAspectRatio"); float aspectRatio; if(plug.isNull()) { aspectRatio = 1.0f; } else { plug.getValue(aspectRatio); } plug = jointFn.findPlug("unParticleInitialAngleBegin"); float angleBegin; if(plug.isNull()) { angleBegin = 0.0f; } else { plug.getValue(angleBegin); } plug = jointFn.findPlug("unParticleInitialAngleEnd"); float angleEnd; if(plug.isNull()) { angleEnd = 0.0f; } else { plug.getValue(angleEnd); } plug = jointFn.findPlug("unParticleRotationSpeed"); float rotationSpeed; if(plug.isNull()) { rotationSpeed = 0; } else { plug.getValue(rotationSpeed); } plug = jointFn.findPlug("unParticleRotationSpeedVar"); float rotationSpeedVar; if(plug.isNull()) { rotationSpeedVar = 0; } else { plug.getValue(rotationSpeedVar); } plug = jointFn.findPlug("unParticleEmitterWidth"); float width; plug.getValue(width); plug = jointFn.findPlug("unParticleEmitterLength"); float length; plug.getValue(length); plug = jointFn.findPlug("unParticleEmitterHeight"); float height = 0.0f; if(!plug.isNull()) { plug.getValue(height); } plug = jointFn.findPlug("unParticleBlendMode"); short blendMode; plug.getValue(blendMode); plug = jointFn.findPlug("unParticleTextureFilename"); MItDependencyGraph dgIt(plug, MFn::kFileTexture, MItDependencyGraph::kUpstream, MItDependencyGraph::kBreadthFirst, MItDependencyGraph::kNodeLevel); dgIt.disablePruningOnFilter(); MString textureName; if (!dgIt.isDone()) { MObject textureNode = dgIt.thisNode(); MPlug filenamePlug = MFnDependencyNode(textureNode).findPlug("fileTextureName"); filenamePlug.getValue(textureName); } else { char str[256]; sprintf(str,"%s particle system must has file-texture",newJoint.name.asChar()); MessageBox(0,str,0,0); } plug = jointFn.findPlug("unParticleTextureRows"); short rows; plug.getValue(rows); plug = jointFn.findPlug("unParticleTextureCols"); short cols; plug.getValue(cols); plug = jointFn.findPlug("unParticleTextureChangeStyle"); short changeStyle; if(plug.isNull()) { //0 - 顺序 //1 - 随机 changeStyle = 0; } else { plug.getValue(changeStyle); } plug = jointFn.findPlug("unParticleTextureChangeInterval"); short changeInterval; if(plug.isNull()) { //默认30ms换一个 changeInterval = 30; } else { plug.getValue(changeInterval); } plug = jointFn.findPlug("unParticleTailLength"); float tailLength; plug.getValue(tailLength); plug = jointFn.findPlug("unParticleTimeMiddle"); float timeMiddle; plug.getValue(timeMiddle); plug = jointFn.findPlug("unParticleColorStart"); MObject object; plug.getValue(object); MFnNumericData dataS(object); float colorStart[3]; dataS.getData(colorStart[0],colorStart[1],colorStart[2]); plug = jointFn.findPlug("unParticleColorMiddle"); plug.getValue(object); MFnNumericData dataM(object); float colorMiddle[3]; dataM.getData(colorMiddle[0],colorMiddle[1],colorMiddle[2]); plug = jointFn.findPlug("unParticleColorEnd"); plug.getValue(object); MFnNumericData dataE(object); float colorEnd[3]; dataE.getData(colorEnd[0],colorEnd[1],colorEnd[2]); plug = jointFn.findPlug("unParticleAlpha"); plug.getValue(object); MFnNumericData dataAlpha(object); float alpha[3]; dataAlpha.getData(alpha[0],alpha[1],alpha[2]); //Scale plug = jointFn.findPlug("unParticleScale"); plug.getValue(object); MFnNumericData dataScale(object); float scale[3]; dataScale.getData(scale[0],scale[1],scale[2]); //ScaleVar plug = jointFn.findPlug("unParticleScaleVar"); float scaleVar[3] = {0.0f,0.0f,0.0f}; if(!plug.isNull()) { plug.getValue(object); MFnNumericData dataScaleVar(object); dataScaleVar.getData(scaleVar[0],scaleVar[1],scaleVar[2]); } //FixedSize plug = jointFn.findPlug("unParticleFixedSize"); bool fixedSize = false; if(!plug.isNull()) { plug.getValue(fixedSize); } //HeadLifeSpan plug = jointFn.findPlug("unParticleHeadLifeSpan"); plug.getValue(object); MFnNumericData dataHeadLifeSpan(object); short headLifeSpan[3]; dataHeadLifeSpan.getData(headLifeSpan[0],headLifeSpan[1],headLifeSpan[2]); plug = jointFn.findPlug("unParticleHeadDecay"); plug.getValue(object); MFnNumericData dataHeadDecay(object); short headDecay[3]; dataHeadDecay.getData(headDecay[0],headDecay[1],headDecay[2]); plug = jointFn.findPlug("unParticleTailLifeSpan"); plug.getValue(object); MFnNumericData dataTailLifeSpan(object); short tailLifeSpan[3]; dataTailLifeSpan.getData(tailLifeSpan[0],tailLifeSpan[1],tailLifeSpan[2]); plug = jointFn.findPlug("unParticleTailDecay"); plug.getValue(object); MFnNumericData dataTailDecay(object); short tailDecay[3]; dataTailDecay.getData(tailDecay[0],tailDecay[1],tailDecay[2]); plug = jointFn.findPlug("unParticleHead"); bool head; plug.getValue(head); plug = jointFn.findPlug("unParticleTail"); bool tail; plug.getValue(tail); plug = jointFn.findPlug("unParticleUnShaded"); bool unshaded; plug.getValue(unshaded); plug = jointFn.findPlug("unParticleUnFogged"); bool unfogged; plug.getValue(unfogged); plug = jointFn.findPlug("unParticleBlockByY0"); bool blockByY0 = false; if(!plug.isNull()) plug.getValue(blockByY0); newJoint.particle.visible = visible; newJoint.particle.speed = speed; newJoint.particle.variation = variation / 100.0f; newJoint.particle.coneAngle = coneAngle; newJoint.particle.gravity = gravity; newJoint.particle.explosiveForce = explosiveForce; newJoint.particle.life = life; newJoint.particle.lifeVar = lifeVar; newJoint.particle.emissionRate = emissionRate; newJoint.particle.initialNum = initialNum; newJoint.particle.limitNum = limitNum; newJoint.particle.attachToEmitter = attachToEmitter; newJoint.particle.moveWithEmitter = moveWithEmitter; newJoint.particle.forTheSword = forTheSword; newJoint.particle.forTheSwordInitialAngle = forTheSwordInitialAngle; newJoint.particle.wander = wander; newJoint.particle.wanderRadius = wanderRadius; newJoint.particle.wanderSpeed = wanderSpeed; newJoint.particle.aspectRatio = aspectRatio; newJoint.particle.initialAngleBegin = angleBegin; newJoint.particle.initialAngleEnd = angleEnd; newJoint.particle.rotationSpeed = rotationSpeed; newJoint.particle.rotationSpeedVar = rotationSpeedVar; newJoint.particle.width = width; newJoint.particle.length = length; newJoint.particle.height = height; newJoint.particle.blendMode = blendMode; newJoint.particle.textureFilename = textureName.asChar(); newJoint.particle.textureRows = rows; newJoint.particle.textureCols = cols; newJoint.particle.changeStyle = changeStyle; newJoint.particle.changeInterval = changeInterval; newJoint.particle.tailLength = tailLength; newJoint.particle.timeMiddle = timeMiddle; newJoint.particle.colorStart[0] = colorStart[0]; newJoint.particle.colorStart[1] = colorStart[1]; newJoint.particle.colorStart[2] = colorStart[2]; newJoint.particle.colorMiddle[0] = colorMiddle[0]; newJoint.particle.colorMiddle[1] = colorMiddle[1]; newJoint.particle.colorMiddle[2] = colorMiddle[2]; newJoint.particle.colorEnd[0] = colorEnd[0]; newJoint.particle.colorEnd[1] = colorEnd[1]; newJoint.particle.colorEnd[2] = colorEnd[2]; newJoint.particle.alpha[0] = alpha[0]; newJoint.particle.alpha[1] = alpha[1]; newJoint.particle.alpha[2] = alpha[2]; newJoint.particle.scale[0] = scale[0]; newJoint.particle.scale[1] = scale[1]; newJoint.particle.scale[2] = scale[2]; newJoint.particle.scaleVar[0] = scaleVar[0]; newJoint.particle.scaleVar[1] = scaleVar[1]; newJoint.particle.scaleVar[2] = scaleVar[2]; newJoint.particle.fixedSize = fixedSize; newJoint.particle.headLifeSpan[0] = headLifeSpan[0]; newJoint.particle.headLifeSpan[1] = headLifeSpan[1]; newJoint.particle.headLifeSpan[2] = headLifeSpan[2]; newJoint.particle.headDecay[0] = headDecay[0]; newJoint.particle.headDecay[1] = headDecay[1]; newJoint.particle.headDecay[2] = headDecay[2]; newJoint.particle.tailLifeSpan[0] = tailLifeSpan[0]; newJoint.particle.tailLifeSpan[1] = tailLifeSpan[1]; newJoint.particle.tailLifeSpan[2] = tailLifeSpan[2]; newJoint.particle.tailDecay[0] = tailDecay[0]; newJoint.particle.tailDecay[1] = tailDecay[1]; newJoint.particle.tailDecay[2] = tailDecay[2]; newJoint.particle.head = head; newJoint.particle.tail = tail; newJoint.particle.unshaded = unshaded; newJoint.particle.unfogged = unfogged; newJoint.particle.blockByY0 = blockByY0; } } m_joints.push_back(newJoint); // Get pointer to newly created joint parentJoint = &newJoint; } // Load children joints for (i=0; i<jointDag.childCount();i++) { MObject child; child = jointDag.child(i); MDagPath childDag = jointDag; childDag.push(child); loadJoint(childDag,parentJoint); } }
// Method for iterating over nodes in a dependency graph from top to bottom MStatus OgreExporter::translateNode(MDagPath& dagPath) { if (m_params.exportAnimCurves) { MObject dagPathNode = dagPath.node(); MItDependencyGraph animIter( dagPathNode, MFn::kAnimCurve, MItDependencyGraph::kUpstream, MItDependencyGraph::kDepthFirst, MItDependencyGraph::kNodeLevel, &stat ); if (stat) { for (; !animIter.isDone(); animIter.next()) { MObject anim = animIter.thisNode(&stat); MFnAnimCurve animFn(anim,&stat); std::cout << "Found animation curve: " << animFn.name().asChar() << "\n"; std::cout << "Translating animation curve: " << animFn.name().asChar() << "...\n"; std::cout.flush(); stat = writeAnim(animFn); if (MS::kSuccess == stat) { std::cout << "OK\n"; std::cout.flush(); } else { std::cout << "Error, Aborting operation\n"; std::cout.flush(); return MS::kFailure; } } } } if (dagPath.hasFn(MFn::kMesh)&&(m_params.exportMesh||m_params.exportMaterial||m_params.exportSkeleton) && (dagPath.childCount() == 0)) { // we have found a mesh shape node, it can't have any children, and it contains // all the mesh geometry data MDagPath meshDag = dagPath; MFnMesh meshFn(meshDag); if (!meshFn.isIntermediateObject()) { std::cout << "Found mesh node: " << meshDag.fullPathName().asChar() << "\n"; std::cout << "Loading mesh node " << meshDag.fullPathName().asChar() << "...\n"; std::cout.flush(); stat = m_pMesh->load(meshDag,m_params); if (MS::kSuccess == stat) { std::cout << "OK\n"; std::cout.flush(); } else { std::cout << "Error, mesh skipped\n"; std::cout.flush(); } } } else if (dagPath.hasFn(MFn::kCamera)&&(m_params.exportCameras) && (!dagPath.hasFn(MFn::kShape))) { // we have found a camera shape node, it can't have any children, and it contains // all information about the camera MFnCamera cameraFn(dagPath); if (!cameraFn.isIntermediateObject()) { std::cout << "Found camera node: "<< dagPath.fullPathName().asChar() << "\n"; std::cout << "Translating camera node: "<< dagPath.fullPathName().asChar() << "...\n"; std::cout.flush(); stat = writeCamera(cameraFn); if (MS::kSuccess == stat) { std::cout << "OK\n"; std::cout.flush(); } else { std::cout << "Error, Aborting operation\n"; std::cout.flush(); return MS::kFailure; } } } else if ( ( dagPath.apiType() == MFn::kParticle ) && m_params.exportParticles ) { // we have found a set of particles MFnDagNode fnNode(dagPath); if (!fnNode.isIntermediateObject()) { std::cout << "Found particles node: "<< dagPath.fullPathName().asChar() << "\n"; std::cout << "Translating particles node: "<< dagPath.fullPathName().asChar() << "...\n"; std::cout.flush(); Particles particles; particles.load(dagPath,m_params); stat = particles.writeToXML(m_params); if (MS::kSuccess == stat) { std::cout << "OK\n"; std::cout.flush(); } else { std::cout << "Error, Aborting operation\n"; std::cout.flush(); return MS::kFailure; } } } // look for meshes and cameras within the node's children for (uint i=0; i<dagPath.childCount(); i++) { MObject child = dagPath.child(i); MDagPath childPath = dagPath; stat = childPath.push(child); if (MS::kSuccess != stat) { std::cout << "Error retrieving path to child " << i << " of: " << dagPath.fullPathName().asChar(); std::cout.flush(); return MS::kFailure; } stat = translateNode(childPath); if (MS::kSuccess != stat) return MS::kFailure; } return MS::kSuccess; }