MObject lrutils::createJointFromLocation(MVectorArray location, MString prefix, unsigned int num, MObject parent) {
    MStatus status = MS::kFailure;
    MObject jointObj;

    //make joint object
    MDagModifier dagMod;
    jointObj = dagMod.createNode( "joint", MObject::kNullObj, &status );
    MyCheckStatus(status, "MDagModifier.createNode() failed");
    dagMod.doIt();
    //set position
    lrutils::setLocation(jointObj, location, MFnTransform::MFnTransform(), true, false, false);
    //set name        
    MString jointName = prefix + "_Skel" + boost::lexical_cast<string>(num).c_str() + "_JNT";
    dagMod.renameNode(jointObj, jointName);
    dagMod.doIt();
    MFnTransform jointFn(jointObj);
    
    //parent the joint to its parent, if not null
    if(parent != MObject::kNullObj) {
        MFnTransform parentFn(parent);
        MGlobal::executeCommand("parent " + jointFn.fullPathName() + " " + parentFn.fullPathName() + ";");
    }

    return jointObj;
}
void lrutils::createFKCtlFromLocation(MVectorArray location, MObject joint, MString prefix, unsigned int num, MString icon, MString color, MObject parent, MObject& fkCtlObj, MObject& fkCtlGroupObj, MString layerName, MObject metaDataNode) {
    MStatus status;
    MDGModifier dgMod;
    //used for holding results from executed commands
    MStringArray result;
    MFnDependencyNode depMetaDataNodeFn(metaDataNode);
    //used for creating metaParent attributes for objects
    MFnMessageAttribute mAttr;
    MFnTransform jointFn(joint);
    
    //create the control object and set its color
    status = MGlobal::executeCommand( "python(\"control = rig101().rig101WCGetByName('" + icon + "')\");" );
    status = MGlobal::executeCommand( "python(\"Utils.setControllerColor(control, '" + color + "')\");" );
    status = MGlobal::executeCommand( MString("python(\"control.fullPath()\");"), result );
    //get the MObject for the controller
    status = lrutils::getObjFromName(result[0], fkCtlObj);
    MyCheckStatus(status, "lrutils::getObjFromName() failed");
    MFnTransform fkCtlFn( fkCtlObj );
    lrutils::setLocation(fkCtlObj, location, MFnTransform::MFnTransform(), false, false, true);
    //set controller name
    MString fkCtlName = prefix + "_FK_"+num+"_CTL";
    dgMod.renameNode(fkCtlObj, fkCtlName);
    //add the metaParent attribute to the controller
    MObject controlAttr = mAttr.create("metaParent", "metaParent");
    fkCtlFn.addAttribute(controlAttr);
    //connect the controller's metaParent to the MDSpine node
    status = dgMod.connect( depMetaDataNodeFn.findPlug("FKControllers"), fkCtlFn.findPlug("metaParent") );
    dgMod.doIt();
    
    //create the fk control null
    lrutils::makeHomeNull(fkCtlObj, MFnTransform(), fkCtlGroupObj);
    lrutils::setLocation(fkCtlGroupObj, location, MFnTransform::MFnTransform(), true, true, false);
    MFnTransform fkCtlGroupFn( fkCtlGroupObj );
    if(!parent.isNull()) {
        MFnTransform parentFn(parent);
        MGlobal::executeCommand("parent " + fkCtlGroupFn.fullPathName() + " " + parentFn.fullPathName() + ";");
    }
    //add the metaParent attribute to the controller group
    fkCtlGroupFn.addAttribute(mAttr.create("metaParent", "metaParent"));
    //connect the controller group's metaParent to the MDGlobal node
    status = dgMod.connect( depMetaDataNodeFn.findPlug("FKControllerGroups"), fkCtlGroupFn.findPlug("metaParent") );
    MyCheckStatus(status, "connect failed"); 
    dgMod.doIt();

    MGlobal::executeCommand("parentConstraint -mo " + fkCtlFn.fullPathName() + " " + jointFn.fullPathName() + ";",result);
    MObject jointParentConstraintObj;
    status = lrutils::getObjFromName(result[0], jointParentConstraintObj);
    MyCheckStatus(status, "lrutils::getObjFromName() failed");
    MFnTransform jointParentConstraintFn(jointParentConstraintObj);
    jointParentConstraintFn.addAttribute(mAttr.create("metaParent", "metaParent"));
    status = dgMod.connect( depMetaDataNodeFn.findPlug("FKJointParentConstraints"), jointParentConstraintFn.findPlug("metaParent"));
    dgMod.doIt();

    //set the display layers for the controller and controller group
    MGlobal::executeCommand("editDisplayLayerMembers -noRecurse "+ layerName+" "+ fkCtlFn.fullPathName()+";");
    MGlobal::executeCommand("editDisplayLayerMembers -noRecurse "+ layerName+" "+ fkCtlGroupFn.fullPathName()+";");
    MGlobal::executeCommand("select -cl;");
}
std::vector<MObject> lrutils::buildSkeletonFromGuide(std::vector<MVectorArray> locations, MString prefix, MPlug metaDataPlug, MObject metaParentJoint, MString layerName) {
    MDGModifier dgMod;
    MStatus status;
    std::vector<MObject> joints;
    MFnMessageAttribute mAttr;

    MObject parentJoint;
    unsigned int jointNum = 0;

    for (std::vector<MVectorArray>::iterator it = locations.begin(); it != locations.end(); ++it) {
        MVectorArray location = *it;
        MObject joint = createJointFromLocation(location, prefix, jointNum, parentJoint);
        joints.push_back(joint);

        MFnTransform jointFn( joint );
        //add metaParent attributes to joint
        if(!metaDataPlug.isNull()) {
            MObject jointAttr = mAttr.create("metaParent", "metaParent");
            jointFn.addAttribute(jointAttr);
            //connect the metaparent attribute to the MDSpine node
            status = dgMod.connect( metaDataPlug, jointFn.findPlug("metaParent") );
            MyCheckStatus(status, "connect failed");
            dgMod.doIt();
        }

        //if layer name is provided, add the joint to that display layer
        if(layerName != "") {
            MGlobal::executeCommand("editDisplayLayerMembers -noRecurse "+ layerName+" "+ jointFn.name()+";");
        }

        parentJoint = joint;
        jointNum++;
    }
    //orient the joint chain
    MFnTransform topJointFn(joints.at(0));
    MGlobal::executeCommand("joint -e -zso -oj \"xyz\" -sao \"yup\" -ch " + topJointFn.fullPathName() + ";");

    //if meta parent joint is not null, parent first joint to it
    if(!metaParentJoint.isNull()) {
        MFnTransform firstJointFn(joints.at(0));

        MFnTransform metaParentJointFn(metaParentJoint);
        MGlobal::executeCommand("parent " + firstJointFn.fullPathName() + " " + metaParentJointFn.fullPathName() + ";");
        //orient the parent joint
        MGlobal::executeCommand("joint -e -zso -oj \"xyz\" -sao \"yup\" -ch " + metaParentJointFn.fullPathName() + ";");
    }

    return joints;
}
Пример #4
0
MStatus unShowAvailableSystems::findAvailableSystems(std::string& str,MDagPath& dagPath)
{
	MStatus stat = MS::kSuccess;

	if(dagPath.hasFn(MFn::kJoint))
	{
		MFnIkJoint jointFn(dagPath);
		std::string name = dagPath.partialPathName().asChar();
		MPlug plug = jointFn.findPlug("unRibbonEnabled");
		if(!plug.isNull())
		{
			bool enabled;
			plug.getValue(enabled);
			char s[256];
			sprintf(s,"%s RibbonSystem %s\n",name.c_str(),enabled ? "True" : "False");
			str += s;
		}
		plug = jointFn.findPlug("unParticleEnabled");
		if(!plug.isNull())
		{
			bool enabled;
			plug.getValue(enabled);
			char s[256];
			sprintf(s,"%s ParticleSystem %s\n",name.c_str(),enabled ? "True" : "False");
			str += s;
		}
	}

	for (unsigned int i = 0; i < dagPath.childCount(); i++)
	{
		MObject child = dagPath.child(i);
		MDagPath childPath;
		stat = MDagPath::getAPathTo(child,childPath);
		if (MS::kSuccess != stat)
		{
			return MS::kFailure;
		}
		stat = findAvailableSystems(str,childPath);
		if (MS::kSuccess != stat)
			return MS::kFailure;
	}
	return MS::kSuccess;
}
Пример #5
0
// 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);
	}

}
Пример #6
0
// Load an animation clip
MStatus skeleton::loadClip(MString clipName,int start,int stop,int rate)
{
	uint fps = getFps();
	float frameTime = 1000.0f / fps;

	MStatus stat;
	int i,j;
	std::vector<int> times;
	if (m_joints.size() < 0)
		return MS::kFailure;

	times.clear();
	for (int t=start; t<stop; t+=rate)
		times.push_back(t);
	times.push_back(stop);

	// create the animation
	animation a;
	a.name = clipName.asChar();
	
	if(m_animations.size() == 0)
	{
		a.startTime = 0;
		a.endTime = times[times.size()-1] - times[0];
	}
	else
	{
		a.startTime = m_animations[m_animations.size()-1].endTime + 1;
		a.endTime = a.startTime + times[times.size()-1] - times[0];
	}

	m_animations.push_back(a);
	int animIdx = m_animations.size() - 1;

	for (i=0; i<times.size(); i++)
	{
		MAnimControl::setCurrentTime(MTime(times[i],MTime::uiUnit()));
		for (j=0; j<m_joints.size(); j++)
		{
			keyframeTranslation translation;
			keyframeRotation rotation;
			keyframeScale scale;

			joint &jt = m_joints[j];
			int time = times[i] - times[0] + a.startTime;
			loadKeyframe(m_joints[j],time,translation,rotation,scale);
			translation.time *= frameTime;
			rotation.time *= frameTime;
			scale.time *= frameTime;

			size_t size = jt.keyframesTranslation.size();
			if(size > 0)
			{
				keyframeTranslation& t = jt.keyframesTranslation[size - 1];
				if(!equal(translation.v[0],t.v[0]) || !equal(translation.v[1],t.v[1]) || !equal(translation.v[2],t.v[2]))
				{
					//如果跟上一次不一样,并且跨越了桢,那么需要补一桢
					int lastTime = Round(t.time / frameTime);
					if(time - 1 > lastTime)
					{
						keyframeTranslation temp = t;
						temp.time = (time - 1) * frameTime;
						jt.keyframesTranslation.push_back(temp);
					}
					jt.keyframesTranslation.push_back(translation);
				}
			}
			else
			{
				jt.keyframesTranslation.push_back(translation);
			}

			MFnIkJoint jn(jt.jointDag);
			if(jn.name() == "Hips")
			{
//				breakable;
			}
			size = jt.keyframesRotation.size();
			if(size > 0)
			{
				keyframeRotation& r = jt.keyframesRotation[size - 1];
				if(!equal(rotation.q[0],r.q[0]) || !equal(rotation.q[1],r.q[1]) || !equal(rotation.q[2],r.q[2]) || !equal(rotation.q[3],r.q[3]))
				{
					//如果跟上一次不一样,并且跨越了桢,那么需要补一桢
					int lastTime = Round(r.time / frameTime);
					if(time - 1 > lastTime)
					{
						keyframeRotation temp = r;
						temp.time = (time - 1) * frameTime;
						jt.keyframesRotation.push_back(temp);
					}
					jt.keyframesRotation.push_back(rotation);
				}
			}
			else
			{
				jt.keyframesRotation.push_back(rotation);
			}
			size = jt.keyframesScale.size();
			if(size > 0)
			{
				keyframeScale& s = jt.keyframesScale[size - 1];
				if(!equal(scale.v[0],s.v[0]) || !equal(scale.v[1],s.v[1]) || !equal(scale.v[2],s.v[2]))
				{
					//如果跟上一次不一样,并且跨越了桢,那么需要补一桢
					int lastTime = Round(s.time / frameTime);
					if(time - 1 > lastTime)
					{
						keyframeScale temp = s;
						temp.time = (time - 1) * frameTime;
						jt.keyframesScale.push_back(temp);
					}
					jt.keyframesScale.push_back(scale);
				}
			}
			else
			{
				jt.keyframesScale.push_back(scale);
			}

			if(jt.hasRibbonSystem)
			{
				keyframeT<bool> keyframeVisible;
				keyframeT<float> keyframeAbove;
				keyframeT<float> keyframeBelow;
				keyframeT<short> keyframeSlot;
				keyframeT<float3> keyframeColor;
				keyframeT<float> keyframeAlpha;

				MFnIkJoint jointFn(jt.jointDag);
				MPlug plug;

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

				keyframeVisible.time = time * frameTime;
				keyframeAbove.time = time * frameTime;
				keyframeBelow.time = time * frameTime;
				keyframeSlot.time = time * frameTime;
				keyframeColor.time = time * frameTime;
				keyframeAlpha.time = time * frameTime;

				keyframeVisible.data = visible;
				keyframeAbove.data = above;
				keyframeBelow.data = below;
				keyframeSlot.data = slot;
				keyframeColor.data[0] = r;
				keyframeColor.data[1] = g;
				keyframeColor.data[2] = b;
				keyframeAlpha.data = alpha;

				addKeyFramesBool(&jt.ribbon.keyframesVisible,&keyframeVisible);
				addKeyFramesFloat(&jt.ribbon.keyframeAbove,&keyframeAbove);
				addKeyFramesFloat(&jt.ribbon.keyframeBelow,&keyframeBelow);
				size = jt.ribbon.keyframeSlot.size();
				if(size > 0)
				{
					keyframeT<short>& s = jt.ribbon.keyframeSlot[size - 1];
					if(s.data == slot)
					{
						jt.ribbon.keyframeSlot.push_back(keyframeSlot);
					}
				}
				else
				{
					jt.ribbon.keyframeSlot.push_back(keyframeSlot);
				}
				size = jt.ribbon.keyframeColor.size();
				if(size > 0)
				{
					keyframeT<float3>& s = jt.ribbon.keyframeColor[size - 1];
					if(!equal(s.data[0],r) || !equal(s.data[1],g) || !equal(s.data[2],b))
					{
						jt.ribbon.keyframeColor.push_back(keyframeColor);
					}
				}
				else
				{
					jt.ribbon.keyframeColor.push_back(keyframeColor);
				}
				addKeyFramesFloat(&jt.ribbon.keyframeAlpha,&keyframeAlpha);
			}
			if(jt.hasParticleSystem)
			{
				keyframeT<bool> keyframeVisible;
				keyframeT<float> keyframeSpeed;
				keyframeT<float> keyframeVariation;
				keyframeT<float> keyframeConeAngle;
				keyframeT<float> keyframeGravity;
				keyframeT<float> keyframeExplosiveForce;
				keyframeT<float> keyframeEmissionRate;
				keyframeT<float> keyframeWidth;
				keyframeT<float> keyframeLength;
				keyframeT<float> keyframeHeight;

				MFnIkJoint jointFn(jt.jointDag);
				MPlug plug;

				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("unParticleEmissionRate");
				float emissionRate;
				plug.getValue(emissionRate);
				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);
				}

				keyframeVisible.time = time * frameTime;
				keyframeSpeed.time = time * frameTime;
				keyframeVariation.time = time * frameTime;
				keyframeConeAngle.time = time * frameTime;
				keyframeGravity.time = time * frameTime;
				keyframeExplosiveForce.time = time * frameTime;
				keyframeEmissionRate.time = time * frameTime;
				keyframeWidth.time = time * frameTime;
				keyframeLength.time = time * frameTime;
				keyframeHeight.time = time * frameTime;

				keyframeVisible.data = visible;
				keyframeSpeed.data = speed;
				keyframeVariation.data = variation / 100.0f;
				keyframeConeAngle.data = coneAngle;
				keyframeGravity.data = gravity;
				keyframeExplosiveForce.data = explosiveForce;
				keyframeEmissionRate.data = emissionRate;
				keyframeWidth.data = width;
				keyframeLength.data = length;
				keyframeHeight.data = height;

				addKeyFramesBool(&jt.particle.keyframesVisible,&keyframeVisible);
				addKeyFramesFloat(&jt.particle.keyframesSpeed,&keyframeSpeed);
				addKeyFramesFloat(&jt.particle.keyframesVariation,&keyframeVariation);
				addKeyFramesFloat(&jt.particle.keyframesConeAngle,&keyframeConeAngle);
				addKeyFramesFloat(&jt.particle.keyframesGravity,&keyframeGravity);
				addKeyFramesFloat(&jt.particle.keyframesExplosiveForce,&keyframeExplosiveForce);
				addKeyFramesFloat(&jt.particle.keyframesEmissionRate,&keyframeEmissionRate);
				addKeyFramesFloat(&jt.particle.keyframesWidth,&keyframeWidth);
				addKeyFramesFloat(&jt.particle.keyframesLength,&keyframeLength);
				addKeyFramesFloat(&jt.particle.keyframesHeight,&keyframeHeight);
			}
		}
	}

	return MS::kSuccess;
}