本文整理汇总了C++中MDataHandle::asMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ MDataHandle::asMatrix方法的具体用法?C++ MDataHandle::asMatrix怎么用?C++ MDataHandle::asMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDataHandle
的用法示例。
在下文中一共展示了MDataHandle::asMatrix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute
MStatus transRotateCombineMatrix::compute( const MPlug& plug, MDataBlock& data )
{
MStatus status;
MDataHandle hOutputMatrix = data.outputValue( aOutputMatrix, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MDataHandle hOutputInverseMatrix = data.outputValue( aOutputInverseMatrix, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MDataHandle hTransMatrix = data.inputValue( aInputTransMatrix, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MDataHandle hRotateMatrix = data.inputValue( aInputRotateMatrix, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MMatrix transMatrix = hTransMatrix.asMatrix();
MMatrix rotateMatrix = hRotateMatrix.asMatrix();
double buildMatrix[4][4] = { rotateMatrix( 0,0 ), rotateMatrix( 0,1 ), rotateMatrix( 0,2 ), 0,
rotateMatrix( 1,0 ), rotateMatrix( 1,1 ), rotateMatrix( 1,2 ), 0,
rotateMatrix( 2,0 ), rotateMatrix( 2,1 ), rotateMatrix( 2,2 ), 0,
transMatrix( 3,0 ), transMatrix( 3,1 ), transMatrix( 3,2 ), 1 };
MMatrix buildMtx = buildMatrix;
if( plug == aOutputMatrix )
hOutputMatrix.set( buildMtx );
if( plug == aOutputInverseMatrix )
hOutputInverseMatrix.set( buildMtx.inverse() );
data.setClean( plug );
return status;
}
示例2: compute
MStatus sgLockAngleMatrix::compute( const MPlug& plug, MDataBlock& data )
{
MStatus status;
MDataHandle hBaseMatrix = data.inputValue( aBaseMatrix );
m_baseMatrix = hBaseMatrix.asMatrix();
MDataHandle hInputMatrix = data.inputValue( aInputMatrix );
m_inputMatrix = hInputMatrix.asMatrix();
MDataHandle hAngleAxis = data.inputValue( aAngleAxis );
m_angleAxis = hAngleAxis.asUChar();
MDataHandle hInputAngle = data.inputValue( aInputAngle );
m_inputAngle = hInputAngle.asDouble();
m_mtxResult = getsgLockAngleMatrix( m_inputMatrix*m_baseMatrix.inverse(), m_angleAxis, m_inputAngle );
MDataHandle hOutputMatrix = data.outputValue( aOutputMatrix );
hOutputMatrix.set( m_mtxResult * m_baseMatrix );
data.setClean( plug );
return MS::kSuccess;
}
示例3: compute
MStatus matrixFromPolygon::compute( const MPlug& plug, MDataBlock& data )
{
MStatus status;
//MFnDependencyNode thisNode( thisMObject() );
//cout << thisNode.name() << ", start" << endl;
if( plug == aOutputMatrix )
{
MDataHandle hInputMesh = data.inputValue( aInputMesh, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MDataHandle hInputMeshMatrix = data.inputValue( aInputMeshMatrix, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MDataHandle hPolygonIndex = data.inputValue( aPolygonIndex, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MDataHandle hU = data.inputValue( aU, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MDataHandle hV = data.inputValue( aV, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MDataHandle hOutputMatrix = data.outputValue( aOutputMatrix, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MMatrix outMatrix;
getMatrixByPoints( outMatrix, hPolygonIndex.asInt(), hU.asDouble(), hV.asDouble(), hInputMesh.asMesh() );
outMatrix *= hInputMeshMatrix.asMatrix();
hOutputMatrix.set( outMatrix );
data.setClean( plug );
}
//cout << thisNode.name() << ", end" << endl;
return MS::kSuccess;
}
示例4: deform
MStatus SwirlDeformer::deform( MDataBlock& block, MItGeometry &iter,
const MMatrix &localToWorld, unsigned int geomIndex )
{
MStatus stat;
MDataHandle envData = block.inputValue( envelope );
float env = envData.asFloat();
if( env == 0.0 ) // Deformer has no effect
return MS::kSuccess;
MDataHandle matData = block.inputValue( deformSpace );
MMatrix mat = matData.asMatrix();
MMatrix invMat = mat.inverse();
MDataHandle startDistHnd = block.inputValue( startDist );
double startDist = startDistHnd.asDouble();
MDataHandle endDistHnd = block.inputValue( endDist );
double endDist = endDistHnd.asDouble();
MPoint pt;
float weight;
double dist;
double ang;
double cosAng;
double sinAng;
double x;
double distFactor;
for( iter.reset(); !iter.isDone(); iter.next() )
{
weight = weightValue( block, geomIndex, iter.index() );
if( weight == 0.0f )
continue;
pt = iter.position();
pt *= invMat;
dist = sqrt( pt.x * pt.x + pt.z * pt.z );
if( dist < startDist || dist > endDist )
continue;
distFactor = 1 - ((dist - startDist) / (endDist - startDist));
ang = distFactor * M_PI * 2.0 * env * weight;
if( ang == 0.0 )
continue;
cosAng = cos( ang );
sinAng = sin( ang );
x = pt.x * cosAng - pt.z * sinAng;
pt.z = pt.x * sinAng + pt.z * cosAng;
pt.x = x;
pt *= mat;
iter.setPosition( pt );
}
return stat;
}
示例5: compute
MStatus sgMeshIntersect::compute( const MPlug& plug, MDataBlock& data )
{
MStatus status;
if( m_isDirtyMeshMatrix )
{
MDataHandle hInputMeshMatrix = data.inputValue( aInputMeshMatrix );
m_mtxMesh = hInputMeshMatrix.asMatrix();
m_mtxInvMesh = m_mtxMesh.inverse();
}
if( m_isDirtyMesh )
{
MDataHandle hInputMesh = data.inputValue( aInputMesh );
m_fnMesh.setObject( hInputMesh.asMesh() );
}
if( m_isDirtyPointDest )
{
MDataHandle hPointDest = data.inputValue( aPointDest );
m_pointDest = MPoint( hPointDest.asVector() ) * m_mtxInvMesh;
}
if( m_isDirtyPointSrc )
{
MDataHandle hPointSource = data.inputValue( aPointSource );
m_pointSource = MPoint( hPointSource.asVector() ) * m_mtxInvMesh;
}
m_rayDirection = m_pointDest - m_pointSource;
m_fnMesh.intersect( m_pointSource, m_rayDirection, m_pointsIntersect, &status );
if( !status ) return MS::kSuccess;
MDataHandle hParentInverse = data.inputValue( aParentInverseMatrix );
m_mtxParentInverse = hParentInverse.asMatrix();
MDataHandle hOutPoint = data.outputValue( aOutPoint );
hOutPoint.setMVector( m_pointsIntersect[0]*m_mtxMesh*m_mtxParentInverse );
return MS::kSuccess;
}
示例6: compute
MStatus MG_curve::compute(const MPlug& plug,MDataBlock& dataBlock)
{
if (plug==output)
{
//MStatus
MStatus stat;
//Point array for the curve
MPointArray pointArray ;
//Get data from inputs
MDataHandle degreeH = dataBlock.inputValue(degree);
int degreeValue = degreeH.asInt();
MDataHandle tmH = dataBlock.inputValue(transformMatrix);
MMatrix tm = tmH.asMatrix();
MArrayDataHandle inputMatrixH = dataBlock.inputArrayValue(inputMatrix);
inputMatrixH.jumpToArrayElement(0);
//Loop to get matrix data and convert in points
for (int unsigned i=0;i<inputMatrixH.elementCount();i++,inputMatrixH.next())
{
MMatrix currentMatrix = inputMatrixH.inputValue(&stat).asMatrix() ;
//Compensate the locator matrix
MMatrix fixedMatrix = currentMatrix*tm.inverse();
MPoint matrixP (fixedMatrix[3][0],fixedMatrix[3][1],fixedMatrix[3][2]);
pointArray.append(matrixP);
}
MFnNurbsCurve curveFn;
MFnNurbsCurveData curveDataFn;
MObject curveData= curveDataFn.create();
curveFn.createWithEditPoints(pointArray,degreeValue,MFnNurbsCurve::kOpen,0,0,0,curveData,&stat);
MDataHandle outputH = dataBlock.outputValue(output);
outputH.set(curveData);
outputH.setClean();
}
return MS::kSuccess;
}
示例7: weightValue
MStatus
offset::deform( MDataBlock& block,
MItGeometry& iter,
const MMatrix& /*m*/,
unsigned int multiIndex)
//
// Method: deform
//
// Description: Deform the point with a squash algorithm
//
// Arguments:
// block : the datablock of the node
// iter : an iterator for the geometry to be deformed
// m : matrix to transform the point into world space
// multiIndex : the index of the geometry that we are deforming
//
//
{
MStatus returnStatus;
// Envelope data from the base class.
// The envelope is simply a scale factor.
//
MDataHandle envData = block.inputValue(envelope, &returnStatus);
if (MS::kSuccess != returnStatus) return returnStatus;
float env = envData.asFloat();
// Get the matrix which is used to define the direction and scale
// of the offset.
//
MDataHandle matData = block.inputValue(offsetMatrix, &returnStatus );
if (MS::kSuccess != returnStatus) return returnStatus;
MMatrix omat = matData.asMatrix();
MMatrix omatinv = omat.inverse();
// iterate through each point in the geometry
//
for ( ; !iter.isDone(); iter.next()) {
MPoint pt = iter.position();
pt *= omatinv;
float weight = weightValue(block,multiIndex,iter.index());
// offset algorithm
//
pt.y = pt.y + env*weight;
//
// end of offset algorithm
pt *= omat;
iter.setPosition(pt);
}
return returnStatus;
}
示例8: compute
MStatus retargetLocator::compute( const MPlug& plug, MDataBlock& data )
{
MStatus status;
MDataHandle hDiscMatrix = data.inputValue( aDiscMatrix );
MDataHandle hDiscAxis = data.inputValue( aDiscAxis );
MDataHandle hDiscAngle = data.inputValue( aDiscAngle );
MDataHandle hDiscDivision = data.inputValue( aDiscDivision );
MDataHandle hDiscOffset = data.inputValue( aDiscOffset );
MDataHandle hDiscSize = data.inputValue( aDiscSize );
MDataHandle hDiscActiveColor = data.inputValue( aDiscActiveColor );
MDataHandle hDiscLeadColor = data.inputValue( aDiscLeadColor );
MDataHandle hDiscDefaultColor = data.inputValue( aDiscDefaultColor );
MDataHandle hDiscFillAlpha = data.inputValue( aDiscFillAlpha );
MDataHandle hDiscLineAlpha = data.inputValue( aDiscLineAlpha );
discAxis = hDiscAxis.asInt();
discDivision = hDiscDivision.asInt();
discAngle = hDiscAngle.asDouble();
discSize = hDiscSize.asVector();
discOffset = hDiscOffset.asVector();
discActiveColor = hDiscActiveColor.asFloat3();
discLeadColor = hDiscLeadColor.asFloat3();
discDefaultColor = hDiscDefaultColor.asFloat3();
discFillAlpha = hDiscFillAlpha.asFloat();
discLineAlpha = hDiscLineAlpha.asFloat();
MArrayDataHandle hArrArrow = data.inputArrayValue( aArrow );
arrowNum = hArrArrow.elementCount();
inheritMatrix.setLength( arrowNum );
aimMatrix.setLength( arrowNum );
inputMeshObj.setLength( arrowNum );
startSize.setLength( arrowNum );
size.setLength( arrowNum );
activeColor.setLength( arrowNum );
leadColor.setLength( arrowNum );
defaultColor.setLength( arrowNum );
fillAlpha.setLength( arrowNum );
lineAlpha.setLength( arrowNum );
offset.setLength( arrowNum );
for( int i =0; i < arrowNum; i++ )
{
MDataHandle hArrow = hArrArrow.inputValue();
MDataHandle hInheritMatrix = hArrow.child( aInheritMatrix );
MDataHandle hAimMatrix = hArrow.child( aAimMatrix );
MDataHandle hInputMesh = hArrow.child( aInputMesh );
MDataHandle hStartSize = hArrow.child( aStartSize );
MDataHandle hSize = hArrow.child( aSize );
MDataHandle hActiveColor = hArrow.child( aActiveColor );
MDataHandle hLeadColor = hArrow.child( aLeadColor );
MDataHandle hDefaultColor = hArrow.child( aDefaultColor );
MDataHandle hFillAlpha = hArrow.child( aFillAlpha );
MDataHandle hLineAlpha = hArrow.child( aLineAlpha );
MDataHandle hOffset = hArrow.child( aOffset );
inheritMatrix[i] = hInheritMatrix.asBool();
aimMatrix[i] = hAimMatrix.asMatrix()*hDiscMatrix.asMatrix().inverse();
inputMeshObj[i] = hInputMesh.asMesh();
startSize[i] = hStartSize.asFloat();
size[i] = hSize.asFloat();
activeColor[i] = hActiveColor.asFloat3();
leadColor[i] = hLeadColor.asFloat3();
defaultColor[i] = hDefaultColor.asFloat3();
fillAlpha[i] = hFillAlpha.asFloat();
lineAlpha[i] = hLineAlpha.asFloat();
offset[i] = hOffset.asVector();
hArrArrow.next();
}
MDataHandle hOutput = data.outputValue( aOutput );
hOutput.set( 1.0 );
data.setClean( plug );
return MS::kSuccess;
}
示例9: deform
MStatus inverseSkinCluster::deform(MDataBlock& data,
MItGeometry& itGeo,
const MMatrix& localToWorldMatrix,
unsigned int geomIndex)
{
MStatus status;
MMatrix geomMatrix;
bool updateSkinInfo;
MDataHandle hInMesh = data.inputValue( aInMesh, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MObject oInMesh = hInMesh.asMesh();
if( oInMesh.isNull() )
return MS::kFailure;
MFnMesh inMesh = oInMesh;
inMesh.getPoints( m_meshPoints );
if( originalMeshUpdated )
{
itGeo.allPositions( pTaskData->basePoints );
originalMeshUpdated = false;
}
MDataHandle hGeomMatrix = data.inputValue( aGeomMatrix );
geomMatrix = hGeomMatrix.asMatrix();
MDataHandle hUpdateWeightList = data.inputValue( aUpdateWeightList );
updateSkinInfo = hUpdateWeightList.asBool();
MDataHandle hEnvelop = data.inputValue( envelope );
envelopValue = hEnvelop.asFloat();
pTaskData->envelop = envelopValue;
pTaskData->invEnv = 1.0f - envelopValue;
pTaskData->beforePoints = m_meshPoints;
if( updateSkinInfo )
{
MDataHandle hUpdateSkinInfoOutput = data.outputValue( aUpdateWeightList );
hUpdateSkinInfoOutput.set( false );
weightListUpdated = false;
}
if( logicalIndexArray.length() == 0 )
updateLogicalIndexArray();
MDataHandle hUpdateMatrix = data.inputValue( aUpdateMatrix );
if( hUpdateMatrix.asBool() )
{
matrixAttrUpdated = false;
matrixInfoUpdated = false;
}
MArrayDataHandle hArrMatrix = data.inputArrayValue( aMatrix );
MArrayDataHandle hArrBindPreMatrix = data.inputArrayValue( aBindPreMatrix );
updateMatrixAttribute( hArrMatrix, hArrBindPreMatrix );
if( !matrixInfoUpdated )
{
updateMatrixInfo( hArrMatrix, hArrBindPreMatrix );
}
if( !weightListUpdated )
{
pTaskData->afterPoints.setLength( m_meshPoints.length() );
pTaskData->envPoints.setLength( m_meshPoints.length() );
updateWeightList();
}
if( !matrixInfoUpdated || !weightListUpdated )
{
if( pSkinInfo->weightsArray.size() > 0 )
getWeightedMatrices( geomMatrix );
else
return MS::kFailure;
matrixInfoUpdated = true;
weightListUpdated = true;
}
if( envelopValue )
{
setThread();
MThreadPool::newParallelRegion( parallelCompute, pThread );
endThread();
itGeo.setAllPositions( pTaskData->envPoints );
}
else
{
itGeo.setAllPositions( pTaskData->basePoints );
}
return MS::kSuccess;
}
示例10: compute
/*! Compute function, gets the input surface, determines what type it is and calls the appropriate conversion function
Encapsulates an cowpointer to the body into the naiadBodyData type and outputs it */
MStatus NBuddySurfaceToBodyNode::compute( const MPlug& plug, MDataBlock& data )
{
MStatus status;
if (plug == _outBody)
{
//Get the body name
MDataHandle bodyNameHndl = data.inputValue( _bodyName, &status );
MString bodyName = bodyNameHndl.asString();
//Create the MFnPluginData for the naiadBody
MFnPluginData dataFn;
dataFn.create( MTypeId( naiadBodyData::id ), &status);
NM_CheckMStatus( status, "Failed to create naiadBodyData in MFnPluginData");
//Get subdivision info from plugs so better approximations of meshes can be done
int divisions = data.inputValue( _subDivide, &status ).asBool();
//Getting genericAttribute handle containing the surface and pick the correct conversion function
MObject meshObj;
MDataHandle inSurfaceHdl = data.inputValue( _inSurface, &status );
if (inSurfaceHdl.type() == MFnData::kNurbsSurface)
{
MFnNurbsSurface nurbsFn(inSurfaceHdl.asNurbsSurface());
// Create the data holder for the tesselated mesh
MFnMeshData dataCreator;
MObject newOutputData = dataCreator.create(&status);
//Setup the tesselation parameters
MTesselationParams tParams;
tParams.setOutputType( MTesselationParams::kTriangles );
tParams.setFormatType( MTesselationParams::kGeneralFormat );
tParams.setUIsoparmType( MTesselationParams::kSpanEquiSpaced );
tParams.setVIsoparmType( MTesselationParams::kSpanEquiSpaced );
tParams.setUNumber( divisions+1 );
tParams.setVNumber( divisions+1 );
// Tesselate and get the returned mesh
meshObj = nurbsFn.tesselate( tParams, newOutputData, &status );
NM_CheckMStatus( status, "NBuddySurfaceToBodyNode::compute Failed to tesselate nurbs surface to poly");
}
else if (inSurfaceHdl.type() == MFnData::kMesh)
{
meshObj = inSurfaceHdl.asMesh();
if ( divisions > 0 )
{
MFnMeshData dataCreator;
MObject newOutputData = dataCreator.create(&status);
MFnMesh meshFn(meshObj);
MIntArray faceIds;
for ( unsigned int i(0); i < meshFn.numPolygons(); ++i )
faceIds.append(i);
meshFn.subdivideFaces( faceIds , divisions );
}
}
else if (inSurfaceHdl.type() == MFnData::kSubdSurface)
{
// Create the subd function set so we can tesselate
MFnSubd subDfn(inSurfaceHdl.asSubdSurface());
// Create the data holder for the tesselated mesh
MFnMeshData dataCreator;
MObject newOutputData = dataCreator.create(&status);
// Tesselate the subD surface
meshObj = subDfn.tesselate(true, 1 , divisions , newOutputData, &status );
NM_CheckMStatus( status, "NBuddySurfaceToBodyNode::compute Failed to tesselate SubD surface to poly");
}
else
return status ;
//Get the handle for the input transform
MDataHandle inTransformHdl = data.inputValue( _inTransform, &status );
NM_CheckMStatus( status, "Failed to get inTransform handle");
MDataHandle useTransformHdl = data.inputValue( _useTransform, &status);
NM_CheckMStatus( status, "Failed to get worldSpaceHdl ");
bool useTransform = useTransformHdl.asBool();
//Get a new naiadBodyData
naiadBodyData * newBodyData = (naiadBodyData*)dataFn.data( &status );
NM_CheckMStatus( status, "Failed to get naiadBodyData handle from MFnPluginData");
try {
newBodyData->nBody = mayaMeshToNaiadBody( meshObj, std::string(bodyName.asChar()), useTransform, inTransformHdl.asMatrix() );
}
catch(std::exception& ex) {
NM_ExceptionPlugDisplayError("NBuddySurfaceToBodyNode::compute ", plug, ex );
}
//Give the data to the output handle and set it clean
MDataHandle bodyDataHnd = data.outputValue( _outBody, &status );
NM_CheckMStatus( status, "Failed to get outputData handle for outBody");
bodyDataHnd.set( newBodyData );
data.setClean( plug );
//.........这里部分代码省略.........
示例11: compute
MStatus BCIViz::compute( const MPlug& plug, MDataBlock& block )
{
if( plug == outValue ) {
MStatus status;
MDagPath path;
MDagPath::getAPathTo(thisMObject(), path);
MMatrix worldInverseSpace = path.inclusiveMatrixInverse();
MDataHandle inputdata = block.inputValue(ainput, &status);
if(status) {
const MMatrix drvSpace = inputdata.asMatrix();
fDriverPos.x = drvSpace(3, 0);
fDriverPos.y = drvSpace(3, 1);
fDriverPos.z = drvSpace(3, 2);
fDriverPos *= worldInverseSpace;
}
fTargetPositions.clear();
MArrayDataHandle htarget = block.inputArrayValue( atargets );
unsigned numTarget = htarget.elementCount();
fTargetPositions.setLength(numTarget);
for(unsigned i = 0; i<numTarget; i++) {
MDataHandle tgtdata = htarget.inputValue(&status);
if(status) {
const MMatrix tgtSpace = tgtdata.asMatrix();
MPoint tgtPos(tgtSpace(3,0), tgtSpace(3,1), tgtSpace(3,2));
tgtPos *= worldInverseSpace;
MVector disp = tgtPos;
disp.normalize();
tgtPos = disp;
fTargetPositions[i] = tgtPos;
}
htarget.next();
}
m_hitTriangle = 0;
neighbourId[0] = 0;
neighbourId[1] = 1;
neighbourId[2] = 2;
if(!checkTarget())
{
MGlobal::displayWarning("convex hull must have no less than 4 targes.");
return MS::kSuccess;
}
if(!checkFirstFour(fTargetPositions))
{
MGlobal::displayWarning("first 4 targes cannot sit on the same plane.");
return MS::kSuccess;
}
if(!constructHull())
{
MGlobal::displayWarning("convex hull failed on construction.");
return MS::kSuccess;
}
findNeighbours();
calculateWeight();
MArrayDataHandle outputHandle = block.outputArrayValue( outValue );
int numWeight = fTargetPositions.length();
m_resultWeights.setLength(numWeight);
for(int i=0; i < numWeight; i++)
m_resultWeights[i] = 0.0;
m_resultWeights[neighbourId[0]] = fAlpha;
m_resultWeights[neighbourId[1]] = fBeta;
m_resultWeights[neighbourId[2]] = fGamma;
MArrayDataBuilder builder(outValue, numWeight, &status);
for(int i=0; i < numWeight; i++) {
MDataHandle outWeightHandle = builder.addElement(i);
outWeightHandle.set( m_resultWeights[i] );
//MGlobal::displayInfo(MString("wei ") + i + " " + weights[i]);
}
outputHandle.set(builder);
outputHandle.setAllClean();
}
return MS::kSuccess;
}
示例12: compute
MStatus geometrySurfaceConstraint::compute( const MPlug& plug, MDataBlock& block )
{
MStatus returnStatus;
if(plug == constraintTranslateX || plug == constraintTranslateY || plug == constraintTranslateZ) {
if(!m_isInitd) {
// read rest position
MDataHandle htgo = block.inputValue(targetRestP);
double3 & tgo = htgo.asDouble3();
MGlobal::displayInfo(MString("target rest p ")+tgo[0]+" "+tgo[1]+" "+tgo[2]);
m_restPos = MPoint(tgo[0],tgo[1],tgo[2]);
m_isInitd = true;
}
MArrayDataHandle targetArray = block.inputArrayValue( compoundTarget );
const unsigned int targetArrayCount = targetArray.elementCount();
MMatrix tm;
tm.setToIdentity();
unsigned int i;
for ( i = 0; i < targetArrayCount; i++ ) {
MDataHandle targetElement = targetArray.inputValue(&returnStatus);
if(!returnStatus) {
MGlobal::displayInfo("failed to get input value target element");
}
MDataHandle htm = targetElement.child(targetTransform);
MFnMatrixData ftm(htm.data(), &returnStatus);
if(!returnStatus) {
MGlobal::displayInfo("failed to get matrix data");
}
tm = ftm.matrix();
targetArray.next();
}
MDataHandle hparentInvMat = block.inputValue(constraintParentInverseMatrix);
MMatrix parentInvMat = hparentInvMat.asMatrix();
// world position
MPoint curPos(tm(3,0), tm(3,1), tm(3,2));
// offset in local space
m_offsetToRest = m_restPos - curPos;
// object position in world space
MPoint localP = m_offsetToRest * tm + curPos;
// in local space
localP *= parentInvMat;
MDataHandle hout;
if(plug == constraintTranslateX) {
hout = block.outputValue(constraintTranslateX);
hout.set(localP.x);
}
else if(plug == constraintTranslateY) {
hout = block.outputValue(constraintTranslateY);
hout.set(localP.y);
}
else if(plug == constraintTranslateZ) {
hout = block.outputValue(constraintTranslateZ);
hout.set(localP.z);
}
//MPlug pgTx(thisMObject(), constraintTargetX);
//pgTx.setValue(m_lastPos.x);
//MPlug pgTy(thisMObject(), constraintTargetY);
//pgTy.setValue(m_lastPos.y);
//MPlug pgTz(thisMObject(), constraintTargetZ);
//pgTz.setValue(m_lastPos.z);
MPlug pgOx(thisMObject(), constraintObjectX);
pgOx.setValue(m_offsetToRest.x);
MPlug pgOy(thisMObject(), constraintObjectY);
pgOy.setValue(m_offsetToRest.y);
MPlug pgOz(thisMObject(), constraintObjectZ);
pgOz.setValue(m_offsetToRest.z);
// MFnNumericData nd;
//MObject offsetData = nd.create( MFnNumericData::k3Double);
//nd.setData3Double(m_lastPos.x, m_lastPos.y, m_lastPos.z);
//MPlug pgTgo(thisMObject(), targetOffset);
//pgTgo.setValue(offsetData);
}
else
return MS::kUnknownParameter;
return MS::kSuccess;
}
示例13: compute
MStatus sgHair_controlJoint::compute( const MPlug& plug, MDataBlock& data )
{
MStatus status;
MDataHandle hStaticRotation = data.inputValue( aStaticRotation );
m_bStaticRotation = hStaticRotation.asBool();
if( m_isDirtyMatrix )
{
MDataHandle hInputBaseCurveMatrix = data.inputValue( aInputBaseCurveMatrix );
m_mtxBaseCurve = hInputBaseCurveMatrix.asMatrix();
}
if( m_isDirtyParentMatrixBase )
{
MDataHandle hJointParenBasetMatrix = data.inputValue( aJointParentBaseMatrix );
m_mtxJointParentBase = hJointParenBasetMatrix.asMatrix();
}
if( m_isDirtyCurve || m_isDirtyParentMatrixBase )
{
MDataHandle hInputBaseCurve = data.inputValue( aInputBaseCurve );
MFnNurbsCurve fnCurve = hInputBaseCurve.asNurbsCurve();
fnCurve.getCVs( m_cvs );
getJointPositionBaseWorld();
}
if( m_isDirtyGravityOption || m_isDirtyCurve || m_isDirtyParentMatrixBase )
{
MDataHandle hGravityParam = data.inputValue( aGravityParam );
MDataHandle hGravityRange = data.inputValue( aGravityRange );
MDataHandle hGravityWeight = data.inputValue( aGravityWeight );
MDataHandle hGravityOffsetMatrix = data.inputValue( aGravityOffsetMatrix );
m_paramGravity = hGravityParam.asDouble();
m_rangeGravity = hGravityRange.asDouble();
m_weightGravity = hGravityWeight.asDouble();
m_mtxGravityOffset = hGravityOffsetMatrix.asMatrix();
m_mtxGravityOffset( 3,0 ) = 0.0;
m_mtxGravityOffset( 3,1 ) = 0.0;
m_mtxGravityOffset( 3,2 ) = 0.0;
setGravityJointPositionWorld();
}
setOutput();
MArrayDataHandle hArrOutput = data.outputValue( aOutput );
MArrayDataBuilder builderOutput( aOutput, m_cvs.length() );
for( int i=0; i< m_cvs.length(); i++ )
{
MDataHandle hOutput = builderOutput.addElement( i );
MDataHandle hOutTrans = hOutput.child( aOutTrans );
MDataHandle hOutOrient = hOutput.child( aOutOrient );
hOutTrans.set( m_vectorArrTransJoint[i] );
hOutOrient.set( m_vectorArrRotateJoint[i] );
}
hArrOutput.set( builderOutput );
hArrOutput.setAllClean();
data.setClean( plug );
m_isDirtyMatrix = false;
m_isDirtyCurve = false;
m_isDirtyGravityOption = false;
m_isDirtyParentMatrixBase = false;
return MS::kSuccess;
}
示例14: compute
MStatus LSSolverNode::compute(const MPlug& plug, MDataBlock& data)
{
MStatus stat;
if( plug == deformed)
{
MDataHandle tetWorldMatrixData = data.inputValue(tetWorldMatrix, &returnStatus);
McheckErr(returnStatus, "Error getting tetWorldMatrix data handle\n");
MDataHandle restShapeData = data.inputValue(restShape, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle restVerticesData = data.inputValue(restVertices, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle restElementsData = data.inputValue(restElements, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle selectedConstraintVertsData = data.inputValue(selectedConstraintVerts, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle selectedForceVertsData = data.inputValue(selectedForceVerts, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle timeData = data.inputValue(time, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle outputMeshData = data.outputValue(deformed, &returnStatus);
McheckErr(returnStatus, "Error getting outputMesh data handle\n");
MMatrix twmat = tetWorldMatrixData.asMatrix();
MObject rs = restShapeData.asMesh();
double t = timeData.asDouble();
MDataHandle poissonRatioData = data.inputValue(poissonRatio, &returnStatus);
McheckErr(returnStatus, "Error getting poissonRatio data handle\n");
MDataHandle youngsModulusData = data.inputValue(youngsModulus, &returnStatus);
McheckErr(returnStatus, "Error getting youngsmodulus data handle\n");
MDataHandle objectDensityData = data.inputValue(objectDensity, &returnStatus);
McheckErr(returnStatus, "Error getting objectDensity data handle\n");
MDataHandle frictionData = data.inputValue(friction, &returnStatus);
McheckErr(returnStatus, "Error getting friction data handle\n");
MDataHandle restitutionData = data.inputValue(restitution, &returnStatus);
McheckErr(returnStatus, "Error getting restitution data handle\n");
MDataHandle dampingData = data.inputValue(damping, &returnStatus);
McheckErr(returnStatus, "Error getting damping data handle\n");
MDataHandle userSuppliedDtData = data.inputValue(userSuppliedDt, &returnStatus);
McheckErr(returnStatus, "Error getting user supplied dt data handle\n");
MDataHandle integrationTypeData = data.inputValue(integrationType, &returnStatus);
McheckErr(returnStatus, "Error getting user integrationTypeData\n");
MDataHandle forceModelTypeData = data.inputValue(forceModelType, &returnStatus);
McheckErr(returnStatus, "Error getting user forceModelTypeData\n");
MDataHandle forceApplicationTimeData = data.inputValue(forceApplicationTime, &returnStatus);
McheckErr(returnStatus, "Error getting user forceApplicationTime\n");
MDataHandle forceReleasedTimeData = data.inputValue(forceReleasedTime, &returnStatus);
McheckErr(returnStatus, "Error getting user forceReleasedTime\n");
MDataHandle forceIncrementTimeData = data.inputValue(forceIncrementTime, &returnStatus);
McheckErr(returnStatus, "Error getting user forceIncrementTime\n");
MDataHandle forceStartTimeData = data.inputValue(forceStartTime, &returnStatus);
McheckErr(returnStatus, "Error getting user forceStartTime\n");
MDataHandle forceStopTimeData = data.inputValue(forceStopTime, &returnStatus);
McheckErr(returnStatus, "Error getting user forceStopTime\n");
MDataHandle forceMagnitudeData = data.inputValue(forceMagnitude, &returnStatus);
McheckErr(returnStatus, "Error getting user forceIdleTime\n");
MDataHandle useSuppliedForceData = data.inputValue(useSuppliedForce, &returnStatus);
McheckErr(returnStatus, "Error getting user forceIdleTime\n");
MDataHandle useSuppliedConstraintsData = data.inputValue(useSuppliedConstraints, &returnStatus);
McheckErr(returnStatus, "Error getting user forceIdleTime\n");
MDataHandle forceDirectionData = data.inputValue(forceDirection, &returnStatus);
McheckErr(returnStatus, "Error getting user forceDirection\n");
MDataHandle contactKsData = data.inputValue(contactKs, &returnStatus);
McheckErr(returnStatus, "Error getting user forceDirection\n");
MDataHandle contactKdData = data.inputValue(contactKd, &returnStatus);
McheckErr(returnStatus, "Error getting user forceDirection\n");
MTime currentTime, maxTime;
currentTime = MAnimControl::currentTime();
maxTime = MAnimControl::maxTime();
if (currentTime == MAnimControl::minTime())
//.........这里部分代码省略.........
示例15: compute
MStatus LSSolverNode::compute(const MPlug& plug, MDataBlock& data)
{
MStatus stat;
if( plug == deformed)
{
MDataHandle tetWorldMatrixData = data.inputValue(tetWorldMatrix, &returnStatus);
McheckErr(returnStatus, "Error getting tetWorldMatrix data handle\n");
MDataHandle restShapeData = data.inputValue(restShape, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle restVerticesData = data.inputValue(restVertices, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle restElementsData = data.inputValue(restElements, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle selectedConstraintVertsData = data.inputValue(selectedConstraintVerts, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle selectedForceVertsData = data.inputValue(selectedForceVerts, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle timeData = data.inputValue(time, &returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
MDataHandle outputMeshData = data.outputValue(deformed, &returnStatus);
McheckErr(returnStatus, "Error getting outputMesh data handle\n");
MMatrix twmat = tetWorldMatrixData.asMatrix();
MObject rs = restShapeData.asMesh();
double t = timeData.asDouble();
MDataHandle poissonRatioData = data.inputValue(poissonRatio, &returnStatus);
McheckErr(returnStatus, "Error getting poissonRatio data handle\n");
MDataHandle youngsModulusData = data.inputValue(youngsModulus, &returnStatus);
McheckErr(returnStatus, "Error getting youngsmodulus data handle\n");
MDataHandle objectDensityData = data.inputValue(objectDensity, &returnStatus);
McheckErr(returnStatus, "Error getting objectDensity data handle\n");
MDataHandle frictionData = data.inputValue(friction, &returnStatus);
McheckErr(returnStatus, "Error getting friction data handle\n");
MDataHandle restitutionData = data.inputValue(restitution, &returnStatus);
McheckErr(returnStatus, "Error getting restitution data handle\n");
MDataHandle dampingData = data.inputValue(damping, &returnStatus);
McheckErr(returnStatus, "Error getting damping data handle\n");
MDataHandle userSuppliedDtData = data.inputValue(userSuppliedDt, &returnStatus);
McheckErr(returnStatus, "Error getting user supplied dt data handle\n");
MDataHandle integrationTypeData = data.inputValue(integrationType, &returnStatus);
McheckErr(returnStatus, "Error getting user integrationTypeData\n");
MDataHandle forceModelTypeData = data.inputValue(forceModelType, &returnStatus);
McheckErr(returnStatus, "Error getting user forceModelTypeData\n");
MDataHandle forceApplicationTimeData = data.inputValue(forceApplicationTime, &returnStatus);
McheckErr(returnStatus, "Error getting user forceApplicationTime\n");
MDataHandle forceReleasedTimeData = data.inputValue(forceReleasedTime, &returnStatus);
McheckErr(returnStatus, "Error getting user forceReleasedTime\n");
MDataHandle forceIncrementTimeData = data.inputValue(forceIncrementTime, &returnStatus);
McheckErr(returnStatus, "Error getting user forceIncrementTime\n");
MDataHandle forceStartTimeData = data.inputValue(forceStartTime, &returnStatus);
McheckErr(returnStatus, "Error getting user forceStartTime\n");
MDataHandle forceStopTimeData = data.inputValue(forceStopTime, &returnStatus);
McheckErr(returnStatus, "Error getting user forceStopTime\n");
MDataHandle forceMagnitudeData = data.inputValue(forceMagnitude, &returnStatus);
McheckErr(returnStatus, "Error getting user forceIdleTime\n");
MDataHandle useSuppliedForceData = data.inputValue(useSuppliedForce, &returnStatus);
McheckErr(returnStatus, "Error getting user forceIdleTime\n");
MDataHandle useSuppliedConstraintsData = data.inputValue(useSuppliedConstraints, &returnStatus);
McheckErr(returnStatus, "Error getting user forceIdleTime\n");
MDataHandle forceDirectionData = data.inputValue(forceDirection, &returnStatus);
McheckErr(returnStatus, "Error getting user forceDirection\n");
MDataHandle contactKsData = data.inputValue(contactKs, &returnStatus);
McheckErr(returnStatus, "Error getting user forceDirection\n");
MDataHandle contactKdData = data.inputValue(contactKd, &returnStatus);
McheckErr(returnStatus, "Error getting user forceDirection\n");
MTime currentTime, maxTime;
currentTime = MAnimControl::currentTime();
maxTime = MAnimControl::maxTime();
if (currentTime == MAnimControl::minTime())
//.........这里部分代码省略.........