コード例 #1
0
MStatus arrowLocator::initialize()
{
	//Here we create a new attribute type that handles units: angle, distance or time
	MFnUnitAttribute uAttr;
	windDirection = uAttr.create("windDirection", "wd", MFnUnitAttribute::kAngle, 0.0);
	uAttr.setStorable(true);
	uAttr.setWritable(true);
	uAttr.setReadable(true);
	uAttr.setKeyable(true);

	uAttr.setDefault(MAngle(0.0, MAngle::kDegrees));

	addAttribute(windDirection);

	//- TODO: To make connection between your custom node and your custom 
	//- TODO: manipulator node, you need to name your custom manipulator 
	//- TODO: after your custom node type name, also in your custom node's initialize()
	//- TODO: function, you need to call MPxManipContainer::addToManipConnectTable().
	//- TODO: This method adds the user defined node as an entry in the manipConnectTable 
	//- TODO: so that when this node is selected the user can use the show manip tool to 
	//- TODO: get the user defined manipulator associated with this node.
	//...

	return MS::kSuccess;
}
コード例 #2
0
ファイル: ropeGenerator.cpp プロジェクト: skarone/PipeL
MMatrix ropeGenerator::getMatrixFromParamCurve( MFnNurbsCurve &curveFn, float param, float twist, MAngle divTwist )
{
	MPoint pDivPos;
	//Here we control the tangent of the rope
	curveFn.getPointAtParam( param, pDivPos, MSpace::kWorld );
	MVector vTangent( curveFn.tangent( param, MSpace::kWorld ).normal() );
	MVector vNormal( curveFn.normal( param, MSpace::kWorld ).normal() );
	if ( MAngle( PrevNormal.angle( vNormal ) ).asDegrees() > 90 )
		//fprintf(stderr, "Angle = %g\n",MAngle( PrevNormal.angle( vNormal )).asDegrees());
		vNormal = vNormal * -1;
	PrevNormal = vNormal;
	//if ( vNormal.angle(  ) )
	MQuaternion qTwist( twist * divTwist.asRadians(), vTangent );
	vNormal = vNormal.rotateBy( qTwist );
	MVector vExtra( vNormal ^ vTangent );
	vNormal.normalize();
	vTangent.normalize();
	vExtra.normalize();
	double dTrans[4][4] ={
						{vNormal.x, vNormal.y, vNormal.z, 0.0f},
						{vTangent.x, vTangent.y, vTangent.z, 0.0f},
						{vExtra.x, vExtra.y, vExtra.z, 0.0f},
						{pDivPos.x,pDivPos.y,pDivPos.z, 1.0f}};
	MMatrix mTrans( dTrans );
	return mTrans;
}
コード例 #3
0
ファイル: ropeGenerator.cpp プロジェクト: skarone/PipeL
void ropeGenerator::createCircleUvs( int pointsCount, float uvCapSize, MFloatArray &uArray, MFloatArray &vArray, float direction)
{
	MPoint baseVector( 0.5 * uvCapSize,0,0 );
	uArray.append( baseVector.x + 0.5 );
	vArray.append( baseVector.z + 0.5 );
	for ( int d = 1; d < pointsCount; d++ )
	{
		MVector vVector( baseVector );
		vVector = vVector.rotateBy( MVector::kYaxis, 
			MAngle(( 360.0 * direction / float( pointsCount )) * float( d ),MAngle::kDegrees).asRadians() );
		uArray.append( vVector.x + 0.5 );
		vArray.append( vVector.z + 0.5 );
	}
}
コード例 #4
0
//- The initialize method is called to create and initialize all of the 
//- attributes and attribute dependencies for this node type. This is 
//- only called once when the node type is registered with Maya.
//- Return Values: MS::kSuccess / MS::kFailure
//-
/*static*/ MStatus arrowLocator::initialize()
{
	//- Here we create a new attribute type that handles units: angle, distance or time
	MFnUnitAttribute uAttr;
	windDirection = uAttr.create("windDirection", "wd", MFnUnitAttribute::kAngle, 0.0);
	uAttr.setStorable(true);
	uAttr.setWritable(true);
	uAttr.setReadable(true);
	uAttr.setKeyable(true);
	uAttr.setMin(0.0);
	uAttr.setMax(2*PI);
	uAttr.setDefault(MAngle(0.0, MAngle::kRadians));
	addAttribute(windDirection);

	return MS::kSuccess;
}
コード例 #5
0
bool					
DX11ResourceManager::translateCamera( const MDagPath &cameraPath )
//
// Description:
//		Translate Maya's camera 
//
{
	bool translatedCamera = false;
	if (cameraPath.isValid())
	{
		MStatus status;
		MFnCamera camera (cameraPath, &status);
		if ( !status ) {
			status.perror("MFnCamera constructor");
		}
		else
		{
			translatedCamera = true;

			MPoint eyePoint = camera.eyePoint( MSpace::kWorld );
			MPoint lookAtPt	= camera.centerOfInterestPoint( MSpace::kWorld );
			MVector	upDirection = camera.upDirection ( MSpace::kWorld );
			MFloatMatrix projMatrix = camera.projectionMatrix();

			double horizontalFieldOfView = MAngle( /* camera.verticalFieldOfView() / */ camera.horizontalFieldOfView()
				).asDegrees();
			double nearClippingPlane = camera.nearClippingPlane();
			double farClippingPlane = camera.farClippingPlane();

			// Convert API values to internal native storage.
			//
			m_camera.m_vEyePt = XMFLOAT3((float)eyePoint.x, (float)eyePoint.y, (float)eyePoint.z);
			m_camera.m_vLookatPt = XMFLOAT3((float)lookAtPt.x, (float)lookAtPt.y, (float)lookAtPt.z);
			m_camera.m_vUpVec = XMFLOAT3((float)upDirection.x, (float)upDirection.y, (float)upDirection.z);
			m_camera.m_FieldOfView = (float)horizontalFieldOfView;
			m_camera.m_nearClip = (float)nearClippingPlane;
			m_camera.m_farClip = (float)farClippingPlane;
			m_camera.m_isOrtho = camera.isOrtho();
		}
	}
	else
	{
		initializeDefaultCamera();
	}
	return translatedCamera;
}
コード例 #6
0
ファイル: ropeGenerator.cpp プロジェクト: skarone/PipeL
void ropeGenerator::createCriclePoints( int pointsCount, MMatrix bMatrix, MFloatPointArray &points, float radius )
{
	MPoint baseVector2( radius,0,0 );
	baseVector2 = baseVector2 * bMatrix;
	points.append( MFloatPoint( baseVector2.x, baseVector2.y, baseVector2.z, 1.0 ) );
	float baseAngle = 360.0f / float( pointsCount );
	for (int d = 1; d < pointsCount; d++ )
	{
		MVector vVector( radius,0,0 );
		vVector = vVector.rotateBy( MVector::kYaxis, 
							MAngle( baseAngle * float( d ),MAngle::kDegrees).asRadians() );
		MPoint point( vVector.x, vVector.y, vVector.z );
		point = point * bMatrix;
		points.append( MFloatPoint( point.x, point.y, point.z, 1.0 ));
	}

}
コード例 #7
0
//- The initialize method is called to create and initialize all of the 
//- attributes and attribute dependencies for this node type. This is 
//- only called once when the node type is registered with Maya.
//- Return Values: MS::kSuccess / MS::kFailure
//-
/*static*/ MStatus arrowLocator::initialize()
{
	//- Here we create a new attribute type that handles units: angle, distance or time
	MFnUnitAttribute uAttr;
	//- TODO: Create a angle attribute with long name "windDirection" and short name "wd"
	windDirection = //...
	uAttr.setStorable(true);
	uAttr.setWritable(true);
	uAttr.setReadable(true);
	uAttr.setKeyable(true);
	//- TODO: Set the min and max value this attribute can have 0, 2PI
	//...
	//...
	uAttr.setDefault(MAngle(0.0, MAngle::kRadians));
	addAttribute(windDirection);

	return MS::kSuccess;
}
コード例 #8
0
ファイル: move_manipulator.cpp プロジェクト: jonntd/mannequin
void MannequinMoveManipulator::glDrawCone(GLUquadricObj* quadric,
  MPoint pos,
  MVector dir,
  float height,
  float radius) const {
  MQuaternion zToDir = MVector::zAxis.rotateTo(dir);

  MVector axis;
  double rotateRad;
  zToDir.getAxisAngle(axis, rotateRad);

  double rotateDeg = MAngle(rotateRad).as(MAngle::kDegrees);

  glPushMatrix();
    glTranslated(pos.x, pos.y, pos.z);
    glRotated(rotateDeg, axis.x, axis.y, axis.z);
    gluCylinder(quadric, radius, 0.0, height, 8, 1);
  glPopMatrix();
}
コード例 #9
0
ファイル: ropeGenerator.cpp プロジェクト: skarone/PipeL
void ropeGenerator::createRopesRings( int ropesCount, MMatrix bMatrix, MFloatPointArray &points, int pointsCount, float ropeStrength, float radius )
{
	MAngle angle( (180.0/ ropesCount ), MAngle::kDegrees );
	float distanceToMoveRope = cos( angle.asRadians() );
	float singleRopeRadius = sin( angle.asRadians() );
	float baseAngle = 360.0f / float( ropesCount ); 
	for ( int d = 1; d < ropesCount + 1; d++)
	{
		MFloatPointArray ropePoints( createHalfRope( pointsCount, singleRopeRadius ) );
		for ( int ropP = 0; ropP < ropePoints.length(); ropP++)
		{
			MFloatPoint ropPoint( ropePoints[ropP] );
			MVector ropV( ropPoint.x, ropPoint.y, ropPoint.z * ropeStrength );
			ropV = ropV + MVector( 0,0,-distanceToMoveRope );
			ropV = ropV.rotateBy( MVector::kYaxis, MAngle( baseAngle * float( d ), MAngle::kDegrees).asRadians() );
			MPoint ropFinalPoint( ropV * radius );
			ropFinalPoint = ropFinalPoint * bMatrix;
			points.append( MFloatPoint( ropFinalPoint.x, ropFinalPoint.y, ropFinalPoint.z ) );
		}
	}
}
コード例 #10
0
ファイル: ropeGenerator.cpp プロジェクト: skarone/PipeL
void ropeGenerator::createRopesUvs( int ropesCount, int pointsCount, float ropeStrength, float uvCapSize,MFloatArray &uArray, MFloatArray &vArray, float direction )
{
	MAngle angle( (180.0/ ropesCount ), MAngle::kDegrees );
	float distanceToMoveRope = cos( angle.asRadians() );
	float singleRopeRadius = sin( angle.asRadians() );
	float baseAngle = 360.0f / float( ropesCount ); 
	for ( int d = 1; d < ropesCount + 1; d++)
	{
		MFloatPointArray ropePoints( createHalfRope( pointsCount, singleRopeRadius ) );
		for ( int ropP = 0; ropP < ropePoints.length(); ropP++)
		{
			MFloatPoint ropPoint( ropePoints[ropP] );
			MVector ropV( ropPoint.x, ropPoint.y, ropPoint.z * ropeStrength );
			ropV = ropV + MVector( 0,0,-distanceToMoveRope );
			ropV = ropV.rotateBy( MVector::kYaxis, MAngle( baseAngle * float( d ), MAngle::kDegrees).asRadians() );
			ropV = ropV * 0.5 * uvCapSize;
			uArray.append( (( ropV.x * direction) + 0.5 ) );
			vArray.append( ropV.z + 0.5 );
		}
	}

}
コード例 #11
0
ファイル: Convert.cpp プロジェクト: AtomicFiction/cortex
MAngle convert( const float &from )
{
	return MAngle( from, MAngle::kRadians );
}
コード例 #12
0
ファイル: Convert.cpp プロジェクト: AtomicFiction/cortex
MAngle convert( const double &from )
{
	return MAngle( from, MAngle::kRadians );
}
コード例 #13
0
MStatus CVstAimCmd::redoIt()
{
	MStatus mStatus;

	if ( !mStatus )
	{
		setResult( MString( "Cannot parse command line" ) + mStatus.errorString() );
		return MS::kFailure;
	}

	if ( m_mArgDatabase->isFlagSet( kHelp ) )
	{
		PrintHelp();
	}
	else
	{
		// See if there are two object specified

		MDagPath mDagPath;
		MSelectionList optSelectionList;

		// Validate specified items to whole dag nodes
		{
			MSelectionList tmpSelectionList;
			m_mArgDatabase->getObjects( tmpSelectionList );
			for ( MItSelectionList sIt( tmpSelectionList, MFn::kDagNode ); !sIt.isDone(); sIt.next() )
			{
				if ( sIt.getDagPath( mDagPath ) )
				{
					optSelectionList.add( mDagPath, MObject::kNullObj, true );
				}
			}
		}

		if ( m_mArgDatabase->isFlagSet( "create" ) || optSelectionList.length() >= 2 && m_mArgDatabase->numberOfFlagsUsed() == 0 )
		{
			// Error if there aren't at least two
			if ( optSelectionList.length() < 2 )
			{
				displayError( GetName() + " needs at least two objects specified or selected when -create is used" );
				return MS::kFailure;
			}

			// Get name command line arg
			MString optName;
			if ( m_mArgDatabase->isFlagSet( "name" ) )
			{
				m_mArgDatabase->getFlagArgument( "name", 0, optName );
			}

			m_undoable = true;
			m_mDagModifier = new MDagModifier;

			MObject vstAimObj( m_mDagModifier->MDGModifier::createNode( GetName() ) );
			if ( m_mDagModifier->doIt() != MS::kSuccess )
			{
				displayError( MString( "Couldn't create " ) + GetName() + " node" );
				m_mDagModifier->undoIt();
				delete m_mDagModifier;
				m_mDagModifier = NULL;
				m_undoable = false;

				return MS::kFailure;
			}

			m_mDagModifier->renameNode( vstAimObj, optName.length() ? optName : GetName() );
			if ( m_mDagModifier->doIt() != MS::kSuccess )
			{
				if ( optName.length() )
				{
					displayWarning( MString( "Couldn't rename newly created vstNode \"" ) + optName + "\"" );
				}
			}

			// Set options on the newly create vstAim node

			MFnDependencyNode vstAimFn( vstAimObj );

			MPlug sP;
			MPlug dP;

			if ( m_mArgDatabase->isFlagSet( kAim ) )
			{
				MVector aim;
				m_mArgDatabase->getFlagArgument( kAim, 0, aim.x );
				m_mArgDatabase->getFlagArgument( kAim, 1, aim.y );
				m_mArgDatabase->getFlagArgument( kAim, 2, aim.z );

				sP = vstAimFn.findPlug( "aimX" );
				sP.setValue( aim.x );

				sP = vstAimFn.findPlug( "aimY" );
				sP.setValue( aim.y );

				sP = vstAimFn.findPlug( "aimZ" );
				sP.setValue( aim.z );
			}

			if ( m_mArgDatabase->isFlagSet( kUp ) )
			{
				MVector up;
				m_mArgDatabase->getFlagArgument( kUp, 0, up.x );
				m_mArgDatabase->getFlagArgument( kUp, 1, up.y );
				m_mArgDatabase->getFlagArgument( kUp, 2, up.z );

				sP = vstAimFn.findPlug( "upX" );
				sP.setValue( up.x );

				sP = vstAimFn.findPlug( "upY" );
				sP.setValue( up.y );

				sP = vstAimFn.findPlug( "upZ" );
				sP.setValue( up.z );
			}

			// Now connect up the newly created vstAim node

			MDagPath toAim;
			optSelectionList.getDagPath( 1, toAim );
			const MFnDagNode toAimFn( toAim );

			if ( toAim.hasFn( MFn::kJoint ) )
			{
				MPlug joP( toAimFn.findPlug( "jointOrient" ) );
				if ( !joP.isNull() )
				{
					MAngle jox, joy, joz;
					joP.child( 0 ).getValue( jox );
					joP.child( 1 ).getValue( joy );
					joP.child( 2 ).getValue( joz );
					if ( abs( jox.value() ) > FLT_EPSILON || abs( joy.value() ) > FLT_EPSILON || abs( joz.value() ) > FLT_EPSILON )
					{
						mwarn << "Joint orient on node being constrained is non-zero ( " << jox.asDegrees() << " " << joy.asDegrees() << " " << joz.asDegrees() << " ), setting to 0" << std::endl;
						joP.child( 0 ).setValue( MAngle( 0.0 ) );
						joP.child( 1 ).setValue( MAngle( 0.0 ) );
						joP.child( 2 ).setValue( MAngle( 0.0 ) );
					}
				}
			}

			if ( toAim.hasFn( MFn::kTransform ) )
			{
				MPlug mP( toAimFn.findPlug( "rotateAxis" ) );
				if ( !mP.isNull() )
				{
					MAngle rx, ry, rz;
					mP.child( 0 ).getValue( rx );
					mP.child( 1 ).getValue( ry );
					mP.child( 2 ).getValue( rz );
					if ( abs( rx.value() ) > FLT_EPSILON || abs( ry.value() ) > FLT_EPSILON || abs( rz.value() ) > FLT_EPSILON )
					{
						mwarn << "Rotate Axis on node being constrained is non-zero ( " << rx.asDegrees() << " " << ry.asDegrees() << " " << rz.asDegrees() << " ), setting to 0" << std::endl;
						mP.child( 0 ).setValue( MAngle( 0.0 ) );
						mP.child( 1 ).setValue( MAngle( 0.0 ) );
						mP.child( 2 ).setValue( MAngle( 0.0 ) );
					}
				}
			}

			MDagPath aimAt;
			optSelectionList.getDagPath( 0, aimAt );
			const MFnDagNode aimAtFn( aimAt );

			// toAim.rotateOrder -> vstAim.rotateOrder
			sP = toAimFn.findPlug( "rotateOrder" );
			dP = vstAimFn.findPlug( "rotateOrder" );
			m_mDagModifier->connect( sP, dP );

			// toAim.translate -> vstAim.translate
			sP = toAimFn.findPlug( "translate" );
			dP = vstAimFn.findPlug( "translate" );
			m_mDagModifier->connect( sP, dP );

			// toAim.parentMatrix[ instance ] -> vstAim.parentSpace
			sP = toAimFn.findPlug( "parentMatrix" );
			sP = sP.elementByLogicalIndex( toAim.instanceNumber() );
			dP = vstAimFn.findPlug( "parentSpace" );
			m_mDagModifier->connect( sP, dP );

			// aimAt.worldMatrix[ instance ] -> vstAim.aimSpace
			sP = aimAtFn.findPlug( "worldMatrix" );
			sP = sP.elementByLogicalIndex( aimAt.instanceNumber() );
			dP = vstAimFn.findPlug( "aimSpace" );
			m_mDagModifier->connect( sP, dP );

			// vstAim.rotation -> toAim.rotation
			// These have to be connected individually because Maya plays stupid tricks
			// with rotateOrder if they aren't
			sP = vstAimFn.findPlug( "rotateX" );
			dP = toAimFn.findPlug( "rotateX" );
			m_mDagModifier->connect( sP, dP );

			sP = vstAimFn.findPlug( "rotateY" );
			dP = toAimFn.findPlug( "rotateY" );
			m_mDagModifier->connect( sP, dP );

			sP = vstAimFn.findPlug( "rotateZ" );
			dP = toAimFn.findPlug( "rotateZ" );
			m_mDagModifier->connect( sP, dP );

			if ( m_mDagModifier->doIt() != MS::kSuccess )
			{
				displayWarning( MString( GetName() ) + ": Couldn't connect everything when creating" );
			}

			// Save the current selection just in case we want to undo stuff
			MGlobal::getActiveSelectionList( m_mSelectionList );

			MGlobal::select( vstAimObj, MGlobal::kReplaceList );
			setResult( vstAimFn.name() );
		}
		else if ( m_mArgDatabase->isFlagSet( "select" ) )
		{
			MSelectionList mSelectionList;
			MDagPath mDagPath;

			for ( MItDag dagIt; !dagIt.isDone(); dagIt.next() )
			{
				if ( MFnDependencyNode( dagIt.item() ).typeName() == GetName() )
				{
					dagIt.getPath( mDagPath );
					mSelectionList.add( mDagPath, MObject::kNullObj, true );
				}
			}

			if ( mSelectionList.length() )
			{
				m_undoable = true;
				// Save the current selection just in case we want to undo stuff
				MGlobal::getActiveSelectionList( m_mSelectionList );
				MGlobal::setActiveSelectionList( mSelectionList, MGlobal::kReplaceList );
			}
		}
		else
		{
			displayError( GetName() + ": No valid operation specified via command line arguments\n" );
		}
	}

	return MS::kSuccess;
}
コード例 #14
0
ファイル: splineSolverNode.cpp プロジェクト: skarone/PipeL
MStatus splineSolverNode::doSimpleSolver()
//
// Solve single joint in the x-y plane
//
// - first it calculates the angle between the handle and the end-effector.
// - then it determines which way to rotate the joint.
//
{
    //Do Real Solve
    //
    MStatus stat;
    float curCurveLength = curveFn.length();
    MPlug crvLengPlug = fnHandle.findPlug("cvLen");
    double initCurveLength = crvLengPlug.asDouble();
    //Twist
    MPlug twistRamp = fnHandle.findPlug("twistRamp");
    MRampAttribute curveAttribute( twistRamp, &stat );
    MPlug startTwistPlug = fnHandle.findPlug("strtw");
    double startTwist = startTwistPlug.asDouble();
    MPlug endTwistPlug = fnHandle.findPlug("endtw");
    double endTwist = endTwistPlug.asDouble();
    //Scale Ramp
    MPlug scaleRamp = fnHandle.findPlug("scaleRamp");
    MRampAttribute curveScaleAttribute( scaleRamp, &stat );
    //Roll
    MPlug rollPlug = fnHandle.findPlug("roll");
    double roll = rollPlug.asDouble();
    MPlug strPlug = fnHandle.findPlug("str");
    float stretchRatio = strPlug.asDouble();
    float normCrvLength = curCurveLength / initCurveLength;
    double scale[3] = {1 +stretchRatio*(normCrvLength -1), 1, 1};
    //Get Anchor Position
    MPlug ancPosPlug = fnHandle.findPlug("ancp");
    double anchorPos = ancPosPlug.asDouble();
    MPlug jointsTotLengthPlug = fnHandle.findPlug("jsLen");
    double jointsTotalLength = jointsTotLengthPlug.asDouble();
    double difLengthCurveJoints = curCurveLength - (jointsTotalLength * scale[0]);
    float startLength = 0.0 + anchorPos*( difLengthCurveJoints );
    float parm = curveFn.findParamFromLength( startLength );
    MPoint pBaseJoint, pEndJoint;
    curveFn.getPointAtParam( parm, pBaseJoint );
    //get Init normal
    MPlug initNormalPlug = fnHandle.findPlug("norm");
    double nx = initNormalPlug.child(0).asDouble();
    double ny = initNormalPlug.child(1).asDouble();
    double nz = initNormalPlug.child(2).asDouble();
    MVector eyeUp( nx, ny, nz );
    //get Init Tangent
    MPlug initTangentPlug = fnHandle.findPlug("tang");
    double tx = initTangentPlug.child(0).asDouble();
    double ty = initTangentPlug.child(1).asDouble();
    double tz = initTangentPlug.child(2).asDouble();
    MVector eyeV( tx, ty, tz );

    MFnIkJoint j( joints[0] );
    j.setTranslation( MVector( pBaseJoint ), MSpace::kWorld );
    float jointRotPercent = 1.0/joints.size();
    float currJointRot = 0;
    float prevTwist = 0;
    double angle;
    //j.setScale(scale);
    for (int i = 0; i < joints.size(); i++)
    {
        MFnIkJoint j( joints[i]);
        pBaseJoint = j.rotatePivot(MSpace::kWorld);
        //Calculate Scale
        float scaleValue;
        curveScaleAttribute.getValueAtPosition(currJointRot, scaleValue, &stat);
        //if ( scale[0] >= 1 ) // Stretch
        scale[1] = 1 + scaleValue * ( 1 - scale[0] );
        /*
        else //Squash
        	scale[1] = 1 + scaleValue * ( 1.0 - scale[0] );
        */
        if (scale[1] < 0)
            scale[1] = 0;
        scale[2] = scale[1];
        j.setScale(scale);
        //j.setRotation( rot, j.rotationOrder()  );
        if( i == joints.size() - 1)
            //Effector Position
            pEndJoint = tran.rotatePivot(MSpace::kWorld);
        else
        {
            //get position of next joint
            MFnIkJoint j2( joints[i + 1]);
            pEndJoint = j2.rotatePivot(MSpace::kWorld);
        }
        MVector vBaseJoint(pBaseJoint[0]-pEndJoint[0], pBaseJoint[1]-pEndJoint[1], pBaseJoint[2]-pEndJoint[2]);
        startLength += vBaseJoint.length();
        MVector eyeAim(1.0,0.0,0.0);
        MPoint pFinalPos;
        float parm = curveFn.findParamFromLength( startLength );
        //Aim to final Pos
        curveFn.getPointAtParam( parm, pFinalPos, MSpace::kWorld );
        MVector eyeU(pBaseJoint[0]-pFinalPos[0], pBaseJoint[1]-pFinalPos[1], pBaseJoint[2]-pFinalPos[2]);
        eyeU.normalize();
        MVector eyeW( eyeU ^ eyeV );
        eyeW.normalize();
        eyeV = eyeW ^ eyeU;
        MQuaternion qU( -eyeAim, eyeU );

        MVector upRotated( eyeUp.rotateBy( qU ));
        angle = acos( upRotated*eyeV );

        //Calculate Twist
        {
            float twistValue;
            curveAttribute.getValueAtPosition(currJointRot, twistValue, &stat);
            double rotVal = (1-twistValue)*startTwist + twistValue*endTwist;
            angle += MAngle(rotVal, MAngle::kDegrees).asRadians();
            currJointRot += jointRotPercent;
        }
        //Calculate Roll
        angle += roll;

        MQuaternion qV(angle, eyeU);

        MQuaternion q(qU*qV);

        j.setRotation( q, MSpace::kWorld );
    }

    return MS::kSuccess;
}
コード例 #15
0
ファイル: ropeGenerator.cpp プロジェクト: skarone/PipeL
MStatus ropeGenerator::compute( const MPlug& plug, MDataBlock& data )
{
	MStatus status;

	if ( plug == outMesh )
	{
		//Get Curve
		MDataHandle inCurve_Hdl = data.inputValue( inCurve, &status );
		if (status != MS::kSuccess ){
			MGlobal::displayError( "Node ropeGenerator needs an Input Curve" );
			return MS::kSuccess;
		}
		MObject inCurveObj = inCurve_Hdl.asNurbsCurve();
		MFnNurbsCurve curveFn( inCurveObj );
		
		//Get Attributes
		int inDiv = data.inputValue( divisions ).asInt();
		bool inCreateRope = data.inputValue( createRope ).asBool();
		int inRopesCount = data.inputValue( ropesCount ).asInt();
		int inPointsPerRope = data.inputValue( pointsPerRope ).asInt();
		int inPointsCount = data.inputValue( pointsCount ).asInt();
		float inRopesStrength = data.inputValue( ropesStrength ).asFloat();
		float inRadius = data.inputValue( radius ).asFloat();
		MRampAttribute inRadRamp( thisMObject(), taperRamp );
		float inTwist = data.inputValue( twist ).asFloat();
		MRampAttribute inTwistRamp( thisMObject(), twistRamp );
		float inUvWidth = data.inputValue( uvWidth ).asFloat();
		float inUvHeight = data.inputValue( uvHeight ).asFloat();
		float inUvCapSize = data.inputValue( uvCapSize ).asFloat();

		MFnMesh fnMesh;
		MFnMeshData dataCreator;
		MObject outMeshData;
		outMeshData = dataCreator.create();
		MDataHandle outputHandle = data.outputValue(outMesh);
		//createBase 
		MIntArray faceCounts, faceConnects, uvIds;
		MFloatArray uArray, vArray;
		MFloatPointArray points;
		faceCounts.clear();
		faceConnects.clear();
		points.clear();
		if (inCreateRope)
			inPointsCount = ( inPointsPerRope + 2 ) * inRopesCount;
		int numVertices = ( inDiv + 1 ) * inPointsCount;
		int numFaces = ( inPointsCount * inDiv ) + 2;
		float param;
		float lengPerDiv = curveFn.length() / inDiv;
		PrevNormal = MVector( curveFn.normal( 0.0, MSpace::kWorld ).normal() );
		float baseLeng = lengPerDiv;
		float baseParamForRamp = 0;
		float paramForRamp = 1.0 / float( inDiv );
		float uDivNumber = inUvWidth / float( inPointsCount );
		float vDivNumber = inUvHeight / float( inDiv );
		for (int d = 0; d < inDiv + 1; d++)
		{
			if (d == 0)
			{
				param = 0;
				faceCounts.append( inPointsCount );
				for ( int i = inPointsCount - 1; i >= 0; i-- )
				{
					faceConnects.append( i );
				}
				for ( int i = 0; i < inPointsCount; i++ )
				{
					uvIds.append( i );
				}
				MFloatArray uTmpArray, vTmpArray;
				if (inCreateRope)
					createRopesUvs( inRopesCount, inPointsPerRope, inRopesStrength, inUvCapSize, uTmpArray, vTmpArray, 1.0 );
				else
					createCircleUvs( inPointsCount, inUvCapSize, uTmpArray, vTmpArray, 1.0 );
				for ( int u = uTmpArray.length() - 1; u >= 0 ; u-- )
				{
					uArray.append( uTmpArray[u] + 1.0 );
					vArray.append( vTmpArray[u] );
				}
				for ( int i = 0; i < inPointsCount + 1; i++ )
				{
					uArray.append( uDivNumber * float( i ) );
					vArray.append( vDivNumber * float( d ) );
				}
			}else{
				param = curveFn.findParamFromLength( baseLeng );
				for ( int i = 0; i < inPointsCount + 1; i++ )
				{
					uArray.append( uDivNumber * float( i ) );
					vArray.append( vDivNumber * float( d ) );
				}
				for ( int f = 0; f < inPointsCount; f++ )
				{
					faceCounts.append( 4 );
					if( f == ( inPointsCount - 1 ))
					{
						faceConnects.append( ( f + 1 + ( d * inPointsCount ) ) - inPointsCount - inPointsCount );
						faceConnects.append( ( f + 1 + ( d * inPointsCount ) - inPointsCount ) );
						faceConnects.append( f + 1 + ( d * inPointsCount )  - 1 );
						faceConnects.append( f + 1 + ( d * inPointsCount ) - inPointsCount - 1 );
						uvIds.append( inPointsCount + (( inPointsCount + 1 ) * float( d - 1 )) + 1 + f );
						uvIds.append( inPointsCount + (( inPointsCount + 1 ) * float( d )) + 1 + f);
						uvIds.append( inPointsCount + (( inPointsCount + 1 ) * float( d )) + f);
						uvIds.append( inPointsCount + (( inPointsCount + 1 ) * float( d - 1 )) + f);
					}else{
						faceConnects.append( ( f + ( d * inPointsCount ) ) - inPointsCount );
						faceConnects.append( f + 1 + ( d * inPointsCount ) - inPointsCount );
						faceConnects.append( f + 1 + ( d * inPointsCount ) );
						faceConnects.append( ( f + ( d * inPointsCount )) );
						uvIds.append( inPointsCount + (( inPointsCount + 1 ) * float( d - 1 )) + f);
						uvIds.append( inPointsCount + (( inPointsCount + 1 ) * float( d - 1 )) + 1 + f );
						uvIds.append( inPointsCount + (( inPointsCount + 1 ) * float( d )) + 1 + f);
						uvIds.append( inPointsCount + (( inPointsCount + 1 ) * float( d )) + f);
					}
				}
				if ( d == inDiv )
				{
					faceCounts.append( inPointsCount );
					for ( int i = 0; i <  inPointsCount; i++ )
					{
						faceConnects.append( ( inPointsCount * inDiv ) + i );
						uvIds.append( ( inPointsCount * ( inDiv + 2)) + i + inDiv + 1 );
					}
					MFloatArray uTmpArray, vTmpArray;
					if (inCreateRope)
						createRopesUvs( inRopesCount, inPointsPerRope, inRopesStrength, inUvCapSize, uTmpArray, vTmpArray, -1.0 );
					else
						createCircleUvs( inPointsCount, inUvCapSize, uTmpArray, vTmpArray, -1.0 );
					for ( int u = 0; u < uTmpArray.length(); u++ )
					{
						uArray.append( uTmpArray[u] + 2.0 );
						vArray.append( vTmpArray[u] );
					}
				}
				baseLeng += lengPerDiv;
			}
			float divTwist;
			inTwistRamp.getValueAtPosition( baseParamForRamp, divTwist );
			float divTaper;
			inRadRamp.getValueAtPosition( baseParamForRamp, divTaper );
			baseParamForRamp += paramForRamp;
			if (inCreateRope)
				createRopesRings( inRopesCount, 
								getMatrixFromParamCurve( curveFn, param, inTwist, MAngle( divTwist, MAngle::kDegrees )  ),
								points, inPointsPerRope, inRopesStrength, inRadius * divTaper);
			else
				createCriclePoints( inPointsCount, 
									getMatrixFromParamCurve( curveFn, param, inTwist, MAngle( divTwist, MAngle::kDegrees ) ),
									points, inRadius * divTaper );
		}
		fnMesh.create( numVertices, numFaces, points, faceCounts, faceConnects, uArray, vArray, outMeshData );
		fnMesh.assignUVs( faceCounts, uvIds );
		outputHandle.set(outMeshData);
		outputHandle.setClean();
	}
	return MS::kSuccess;
}