本文整理汇总了C++中MDataHandle::set方法的典型用法代码示例。如果您正苦于以下问题:C++ MDataHandle::set方法的具体用法?C++ MDataHandle::set怎么用?C++ MDataHandle::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDataHandle
的用法示例。
在下文中一共展示了MDataHandle::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute
MStatus resetVtxRemapNode::compute( const MPlug& plug, MDataBlock& data )
//
// Description:
// This method computes the value of the given output plug based
// on the values of the input attributes.
//
// Arguments:
// plug - the plug to compute
// data - object that provides access to the attributes for this node
//
{
MStatus status = MS::kSuccess;
MDataHandle stateData = data.outputValue( state, &status );
MCheckStatus( status, "ERROR getting state" );
// Check for the HasNoEffect/PassThrough flag on the node.
//
// (stateData is an enumeration standard in all depend nodes - stored as short)
//
// (0 = Normal)
// (1 = HasNoEffect/PassThrough)
// (2 = Blocking)
// ...
//
if( stateData.asShort() == 1 )
{
MDataHandle inputData = data.inputValue( inMesh, &status );
MCheckStatus(status,"ERROR getting inMesh");
MDataHandle outputData = data.outputValue( outMesh, &status );
MCheckStatus(status,"ERROR getting outMesh");
// Simply redirect the inMesh to the outMesh for the PassThrough effect
//
outputData.set(inputData.asMesh());
}
else
{
// Check which output attribute we have been asked to
// compute. If this node doesn't know how to compute it,
// we must return MS::kUnknownParameter
//
if (plug == outMesh)
{
MDataHandle inputData = data.inputValue( inMesh, &status );
MCheckStatus(status,"ERROR getting inMesh");
MDataHandle outputData = data.outputValue( outMesh, &status );
MCheckStatus(status,"ERROR getting outMesh");
// Copy the inMesh to the outMesh, and now you can
// perform operations in-place on the outMesh
//
outputData.set(inputData.asMesh());
MObject mesh = outputData.asMesh();
fresetVtxRemapFactory.setMesh( mesh );
status = fresetVtxRemapFactory.doIt();
outputData.setClean();
}
else
{
status = MS::kUnknownParameter;
}
}
return status;
}
示例2: compute
//.........这里部分代码省略.........
vertArray[v+1] = mpoint.y;
vertArray[v+2] = mpoint.z;
}
MFnIntArrayData restEleArrayData(restElementsData.data());
MIntArray ele = restEleArrayData.array();
int eleArrayLen = ele.length();
int *eleArray = new int[eleArrayLen];
ele.get(eleArray);
MFnIntArrayData selectedConstraintVertsArrayData(selectedConstraintVertsData.data());
MIntArray sv = selectedConstraintVertsArrayData.array();
// building selectedConstraintVerts
vector<int> selectedConstraintVertIndices;
for (int i = 0 ; i < sv.length() ; i++)
{
selectedConstraintVertIndices.push_back(sv[i]);
}
MFnIntArrayData selectedForceVertsArrayData(selectedForceVertsData.data());
MIntArray sf = selectedForceVertsArrayData.array();
vector<int> selectedForceVertIndices;
for (int i = 0 ; i < sf.length() ; i++)
{
selectedForceVertIndices.push_back(sf[i]);
}
// temporarily create force direction vector
double *forceDir = forceDirectionData.asDouble3();
vector<double> dir;
dir.push_back(forceDir[0]); dir.push_back(forceDir[1]);dir.push_back(forceDir[2]);
prevDeformed = 0;
double youngsModulusDouble = youngsModulusData.asDouble();
double poissonRatioDouble = poissonRatioData.asDouble();
double objectDensityDouble = objectDensityData.asDouble();
double frictionDouble = frictionData.asDouble();
double restitutionDouble = restitutionData.asDouble();
double dampingDouble = dampingData.asDouble();
double userSuppliedDtDouble = userSuppliedDtData.asDouble();
double forceMagnitudeDouble = forceMagnitudeData.asDouble();
int fAppT = forceApplicationTimeData.asInt();
int fReleasedT = forceReleasedTimeData.asInt();
int fIncT = forceIncrementTimeData.asInt();
int fStartT = forceStartTimeData.asInt();
int fStopT = forceStopTimeData.asInt();
int integrationTypeInt = integrationTypeData.asShort();
int forceModelTypeInt = forceModelTypeData.asShort();
bool useSuppliedForceBool = useSuppliedForceData.asBool();
bool useSuppliedConstraintsBool = useSuppliedConstraintsData.asBool();
double contactKs = contactKsData.asDouble();
double contactKd = contactKdData.asDouble();
if( sm)
{
delete sm;
}
sm = new SoftBodySim(youngsModulusDouble,poissonRatioDouble,objectDensityDouble,
frictionDouble,restitutionDouble,dampingDouble, eleArrayLen, eleArray, vertArrayLen, vertArray,integrationTypeInt,forceModelTypeInt);
sm->setContactAttributes(contactKs,contactKd);
if (useSuppliedConstraintsBool)
sm->initialize("",userSuppliedDtDouble, selectedConstraintVertIndices);
else
{
vector<int> empty;
sm->initialize("",userSuppliedDtDouble, empty);
}
if (useSuppliedForceBool)
sm->setUserForceAttributes(forceMagnitudeDouble, dir,selectedForceVertIndices,fAppT,fReleasedT,fIncT,fStartT,fStopT);
}
else
{
sm->update();
}
MFnMesh surfFn(rs,&stat);
McheckErr( stat, "compute - MFnMesh error" );
MFnMeshData ouputMeshDataCreator;
MObject oMesh = ouputMeshDataCreator.create(&stat);
buildOutputMesh(surfFn, sm->m_vertices,oMesh);
outputMeshData.set(oMesh);
data.setClean(plug);
}
else
stat = MS::kUnknownParameter;
return stat;
}
示例3: compute
MStatus closestPointOnCurveNode::compute(const MPlug &plug, MDataBlock &data)
{
// DO THE COMPUTE ONLY FOR THE *OUTPUT* PLUGS THAT ARE DIRTIED:
if ((plug == aPosition) || (plug == aPositionX) || (plug == aPositionY) || (plug == aPositionZ)
|| (plug == aNormal) || (plug == aNormalX) || (plug == aNormalY) || (plug == aNormalZ)
|| (plug == aTangent) || (plug == aTangentX) || (plug == aTangentY) || (plug == aTangentZ)
|| (plug == aParamU) || (plug == aDistance))
{
// READ IN ".inCurve" DATA:
MDataHandle inCurveDataHandle = data.inputValue(aInCurve);
MObject inCurve = inCurveDataHandle.asNurbsCurve();
// READ IN ".inPositionX" DATA:
MDataHandle inPositionXDataHandle = data.inputValue(aInPositionX);
double inPositionX = inPositionXDataHandle.asDouble();
// READ IN ".inPositionY" DATA:
MDataHandle inPositionYDataHandle = data.inputValue(aInPositionY);
double inPositionY = inPositionYDataHandle.asDouble();
// READ IN ".inPositionZ" DATA:
MDataHandle inPositionZDataHandle = data.inputValue(aInPositionZ);
double inPositionZ = inPositionZDataHandle.asDouble();
// GET THE CLOSEST POSITION, NORMAL, TANGENT, PARAMETER-U AND DISTANCE:
MPoint inPosition(inPositionX, inPositionY, inPositionZ), position;
MVector normal, tangent;
double paramU, distance;
MDagPath dummyDagPath;
closestTangentUAndDistance(dummyDagPath, inPosition, position, normal, tangent, paramU, distance, inCurve);
// WRITE OUT ".position" DATA:
MDataHandle positionDataHandle = data.outputValue(aPosition);
positionDataHandle.set(position.x, position.y, position.z);
data.setClean(plug);
// WRITE OUT ".normal" DATA:
MDataHandle normalDataHandle = data.outputValue(aNormal);
normalDataHandle.set(normal.x, normal.y, normal.z);
data.setClean(plug);
// WRITE OUT ".tangent" DATA:
MDataHandle tangentDataHandle = data.outputValue(aTangent);
tangentDataHandle.set(tangent.x, tangent.y, tangent.z);
data.setClean(plug);
// WRITE OUT ".paramU" DATA:
MDataHandle paramUDataHandle = data.outputValue(aParamU);
paramUDataHandle.set(paramU);
data.setClean(plug);
//.........这里部分代码省略.........
示例4: 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;
}
示例5: compute
MStatus updateTCCDataNode::compute( const MPlug& plug, MDataBlock& data )
//
// Description:
// This method computes the value of the given output plug based
// on the values of the input attributes.
//
// Arguments:
// plug - the plug to compute
// data - object that provides access to the attributes for this node
//
{
MStatus status = MS::kSuccess;
MDataHandle stateData = data.outputValue( state, &status );
MCheckStatus( status, "ERROR getting state" );
// Check for the HasNoEffect/PassThrough flag on the node.
//
// (stateData is an enumeration standard in all depend nodes - stored as short)
//
// (0 = Normal)
// (1 = HasNoEffect/PassThrough)
// (2 = Blocking)
// ...
//
if( stateData.asShort() == 1 )
{
MDataHandle inputData = data.inputValue( inMesh, &status );
MCheckStatus(status,"ERROR getting inMesh");
MDataHandle outputData = data.outputValue( outMesh, &status );
MCheckStatus(status,"ERROR getting outMesh");
// Simply redirect the inMesh to the outMesh for the PassThrough effect
//
outputData.set(inputData.asMesh());
}
else
{
// Check which output attribute we have been asked to
// compute. If this node doesn't know how to compute it,
// we must return MS::kUnknownParameter
//
if (plug == outMesh)
{
MDataHandle inputData = data.inputValue( inMesh, &status );
MCheckStatus(status,"ERROR getting inMesh");
MDataHandle outputData = data.outputValue( outMesh, &status );
MCheckStatus(status,"ERROR getting outMesh");
MIntArray vR = MFnIntArrayData( data.inputValue( vtxRemap ).data() ).array(&status);
MCheckStatus(status,"ERROR getting vtxRemap");
MIntArray pO = MFnIntArrayData( data.inputValue( polyOrder ).data() ).array(&status);
MCheckStatus(status,"ERROR getting polyOrder");
MIntArray cS = MFnIntArrayData( data.inputValue( cShift ).data() ).array(&status);
MCheckStatus(status,"ERROR getting cShift");
MIntArray dnFV = MFnIntArrayData( data.inputValue( delta_nFV ).data() ).array(&status);
MCheckStatus(status,"ERROR getting deltanFV");
MIntArray dF = MFnIntArrayData( data.inputValue( delta_F ).data() ).array(&status);
MCheckStatus(status,"ERROR getting deltaF");
int nVtx = data.inputValue( nV ).asInt();
MCheckStatus(status,"ERROR getting nV");
// Copy the inMesh to the outMesh, and now you can
// perform operations in-place on the outMesh
//
outputData.set(inputData.asMesh());
MObject mesh = outputData.asMesh();
fupdateTCCDataFactory.setMesh( mesh );
fupdateTCCDataFactory.setVtxRemap( vR );
fupdateTCCDataFactory.setPolyOrder( pO );
fupdateTCCDataFactory.setCShift( cS );
fupdateTCCDataFactory.setDelta_nFV( dnFV );
fupdateTCCDataFactory.setDelta_F( dF );
fupdateTCCDataFactory.setnV( nVtx );
// Now, perform the updateTCCData
//
status = fupdateTCCDataFactory.doIt();
// Mark the output mesh as clean
//
outputData.setClean();
}
else
{
status = MS::kUnknownParameter;
}
}
return status;
}
示例6: compute
//.........这里部分代码省略.........
OpenSubdiv::OsdCpuComputeController::ComputeContext *computeContext =
OpenSubdiv::OsdCpuComputeController::ComputeContext::Create(farMesh);
OpenSubdiv::OsdCpuVertexBuffer *vertexBuffer =
OpenSubdiv::OsdCpuVertexBuffer::Create(numVertexElements, numFarVerts );
OpenSubdiv::OsdCpuVertexBuffer *varyingBuffer =
(numVaryingElements) ? OpenSubdiv::OsdCpuVertexBuffer::Create(numVaryingElements, numFarVerts) : NULL;
// == UPDATE VERTICES (can be done after farMesh generated from topology) ==
float const * vertex3fArray = inMeshFn.getRawPoints(&returnStatus);
vertexBuffer->UpdateData(vertex3fArray, 0, numVertices );
// Hbr dupes singular vertices during Mesh::Finish() - we need
// to duplicate their positions in the vertex buffer.
if (ncoarseverts > numVertices) {
MIntArray polyverts;
for (int i=numVertices; i<ncoarseverts; ++i) {
HVertex const * v = hbrMesh->GetVertex(i);
HFace const * f = v->GetIncidentEdge()->GetFace();
int vidx = -1;
for (int j=0; j<f->GetNumVertices(); ++j) {
if (f->GetVertex(j)==v) {
vidx = j;
break;
}
}
assert(vidx>-1);
inMeshFn.getPolygonVertices(f->GetID(), polyverts);
int vert = polyverts[vidx];
vertexBuffer->UpdateData(&vertex3fArray[0]+vert*numVertexElements, i, 1);
}
}
// == Delete HBR
// Can now delete the hbrMesh as we will only be referencing the farMesh from this point on
delete hbrMesh;
hbrMesh = NULL;
// == Subdivide OpenSubdiv mesh ==========================
computeController.Refine(computeContext, farMesh->GetKernelBatches(), vertexBuffer, varyingBuffer);
computeController.Synchronize();
// == Convert subdivided OpenSubdiv mesh to MFnMesh Data outputMesh =============
// Create New Mesh Data Object
MFnMeshData newMeshData;
MObject newMeshDataObj = newMeshData.create(&returnStatus);
MCHECKERR(returnStatus, "ERROR creating outputData");
// Create out mesh
returnStatus = convertOsdFarToMayaMeshData(farMesh, vertexBuffer, subdivisionLevel, inMeshFn, newMeshDataObj);
MCHECKERR(returnStatus, "ERROR convertOsdFarToMayaMesh");
// Propagate objectGroups from inMesh to outMesh (for per-facet shading, etc)
returnStatus = createSmoothMesh_objectGroups(inMeshDat, subdivisionLevel, newMeshData );
// Write to output plug
MDataHandle outMeshH = data.outputValue(a_output, &returnStatus);
MCHECKERR(returnStatus, "ERROR getting polygon data handle\n");
outMeshH.set(newMeshDataObj);
// == Cleanup OSD ============================================
// REVISIT: Re-add these deletes
delete(vertexBuffer);
delete(varyingBuffer);
delete(computeContext);
delete(farMesh);
// note that the subd mesh was created (see the section below if !createdSubdMesh)
createdSubdMesh = true;
}
}
// Pass-through inMesh to outMesh if not created the subd mesh
if (!createdSubdMesh) {
MDataHandle outMeshH = data.outputValue(a_output, &returnStatus);
returnStatus = outMeshH.copy(data.outputValue(a_inputPolymesh, &returnStatus));
MCHECKERR(returnStatus, "ERROR getting polygon data handle\n");
}
// Clean up Maya Plugs
data.setClean(plug);
}
else {
// Unhandled parameter in this compute function, so return MS::kUnknownParameter
// so it is handled in a parent compute() function.
return MS::kUnknownParameter;
}
return MS::kSuccess;
}
示例7: compute
MStatus LSystemNode::compute(const MPlug& plug, MDataBlock& data)
{
MStatus returnStatus;
if (plug == outputMesh) {
/* Get time */
MDataHandle timeData = data.inputValue( time, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
MTime time = timeData.asTime();
MDataHandle angleData = data.inputValue( angle, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
double angle_value = angleData.asDouble();
MDataHandle stepsData = data.inputValue( steps, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
double steps_value = stepsData.asDouble();
MDataHandle grammarData = data.inputValue( grammar, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
MString grammar_value = grammarData.asString();
/* Get output object */
MDataHandle outputHandle = data.outputValue(outputMesh, &returnStatus);
McheckErr(returnStatus, "ERROR getting polygon data handle\n");
MFnMeshData dataCreator;
MObject newOutputData = dataCreator.create(&returnStatus);
McheckErr(returnStatus, "ERROR creating outputData");
MFnMesh myMesh;
MPointArray points;
MIntArray faceCounts;
MIntArray faceConnects;
//MString grammar = ("F\\nF->F[+F]F[-F]F");
CylinderMesh *cm;
LSystem system;
system.loadProgramFromString(grammar_value.asChar());
system.setDefaultAngle(angle_value);
system.setDefaultStep(steps_value);
std::vector<LSystem::Branch> branches;
system.process(time.value(), branches);
int k = branches.size();
for(int j = 0; j < branches.size(); j++)
{
//1. find the position for start and end point of current branch
//2. generate a cylinder
MPoint start(branches[j].first[0],branches[j].first[1],branches[j].first[2]);
MPoint end(branches[j].second[0],branches[j].second[1],branches[j].second[2]);
cm = new CylinderMesh(start, end);
cm->appendToMesh(points, faceCounts, faceConnects);
}
MObject newMesh = myMesh.create(points.length(), faceCounts.length(),
points, faceCounts, faceConnects,
newOutputData, &returnStatus);
McheckErr(returnStatus, "ERROR creating new mesh");
outputHandle.set(newOutputData);
data.setClean( plug );
} else
return MS::kUnknownParameter;
return MS::kSuccess;
}
示例8: compute
MStatus latticeNoiseNode::compute( const MPlug& plug, MDataBlock& data )
{
MStatus returnStatus;
float noiseAmplitude;
float noiseFreq;
if( plug == output )
{
// Get the lattice data from the input attribute. First get the
// data object, and then use the lattice data function set to extract
// the actual lattice.
//
// Get the data handle
//
MDataHandle inputData = data.inputValue( input, &returnStatus );
McheckErr( returnStatus, "ERROR getting lattice data handle\n" );
// Get the data object
//
MObject latticeData = inputData.data();
MFnLatticeData dataFn( latticeData );
// Get the actual geometry
//
MObject lattice = dataFn.lattice();
MFnLattice lattFn( lattice, &returnStatus );
McheckErr( returnStatus, "ERROR getting lattice geometry\n" );
// Do the same for the output lattice
//
MDataHandle outputData = data.outputValue( output, &returnStatus );
McheckErr( returnStatus, "ERROR getting lattice data handle\n" );
// Get the data object
//
latticeData = outputData.data();
if ( latticeData.isNull() ) {
// The data object for this attribute has not been created yet, so
// we'll create it
//
latticeData = dataFn.create();
} else {
// Use the data object that is already there
//
dataFn.setObject( latticeData );
}
// Get the actual geometry
//
MObject outLattice = dataFn.lattice();
MFnLattice outLattFn( outLattice, &returnStatus );
McheckErr( returnStatus, "ERROR getting lattice geometry\n" );
// Get the amplitude and frequency
//
MDataHandle ampData = data.inputValue( amplitude, &returnStatus );
McheckErr( returnStatus, "ERROR getting amplitude\n" );
noiseAmplitude = ampData.asFloat();
MDataHandle freqData = data.inputValue( frequency, &returnStatus );
McheckErr( returnStatus, "ERROR getting frequency\n" );
noiseFreq = freqData.asFloat();
// Get the time.
//
MDataHandle timeData = data.inputValue( time, &returnStatus );
McheckErr( returnStatus, "ERROR getting time data handle\n" );
MTime time = timeData.asTime();
float seconds = (float)time.as( MTime::kSeconds );
// Easiest way to modify frequency is by modifying the time
//
seconds = seconds * noiseFreq;
// We have the information we need now. We'll apply noise to the
// points upon the lattice
//
unsigned s, t, u;
lattFn.getDivisions( s, t, u );
// match up the divisions in the lattices
//
outLattFn.setDivisions( s, t, u );
for ( unsigned i = 0; i < s; i++ ) {
for ( unsigned j = 0; j < t; j++ ) {
for ( unsigned k = 0; k < u; k++ ) {
MPoint & point = lattFn.point( i, j, k );
MPoint & outPoint = outLattFn.point( i, j, k );
pnt noisePnt = noise::atPointAndTime( (float)point.x, (float)point.y,
(float)point.z, seconds );
// Make noise between -1 and 1 instead of 0 and 1
//
noisePnt.x = ( noisePnt.x * 2.0F ) - 1.0F;
noisePnt.y = ( noisePnt.y * 2.0F ) - 1.0F;
noisePnt.z = ( noisePnt.z * 2.0F ) - 1.0F;
outPoint.x = point.x + ( noisePnt.x * noiseAmplitude );
outPoint.y = point.y + ( noisePnt.y * noiseAmplitude );
outPoint.z = point.z + ( noisePnt.z * noiseAmplitude );
}
}
//.........这里部分代码省略.........
示例9: compute
MStatus weightControllerNode::compute( const MPlug& plug, MDataBlock& dataBlock){
MObject thisNode = thisMObject();
MStatus status;
if(plug != aOutputs || ! plug.isElement()){ return MS::kSuccess; }
float3 &uu = dataBlock.inputValue(aLocator).asFloat3();
Vector3f loc(uu[0],uu[1],uu[2]);
MArrayDataHandle hVertices=dataBlock.inputArrayValue(aVertices);
int num=hVertices.elementCount();
if(num==0){return MS::kSuccess; }
// compute the weight
std::vector< Vector3f > v(num);
std::vector< float > r(num);
for(int i=0;i<num;i++){
float3 &uu=hVertices.inputValue().asFloat3();
Vector3f u(uu[0],uu[1],uu[2]);
v[i] = u-loc;
r[i] = v[i].norm();
if(i<num-1){ hVertices.next(); }
}
std::vector<float> w(num, 0.0f), A(num), D(num);
for(int i=0;i<num;i++){
int j=(i+1)% num;
A[i]=(v[i].cross(v[j])).norm();
D[i]=v[i].dot(v[j]);
}
bool flag=true;
// check if it is on the boundary
for(int i=0;i<num;i++){
if(r[i]<EPSILON){ // at a vertex
w[i]=1.0;
flag=false;
break;
}else if(abs(A[i])<EPSILON && D[i] < 0){ // on an edge
int j=(i+1) % num;
w[i]=r[j];
w[j]=r[i];
flag=false;
break;
}
}
// if it is not on the boundary
if(flag){
for(int i=0;i<num;i++){
int k=(i-1+num)% num;
if(fabs(A[k])>EPSILON)
w[i]+=(r[k]-D[k]/r[i])/A[k];
if(fabs(A[i])>EPSILON)
w[i]+=(r[(i+1)% num]-D[i]/r[i])/A[i];
}
}
float sum=0.0;
for(unsigned int i=0;i<num;i++)
sum += w[i];
for(unsigned int i=0;i<num;i++)
w[i] /= sum;
// writing output
MPlug wPlug(thisNode, aOutputs);
MDataHandle wHandle = wPlug.constructHandle(dataBlock);
MArrayDataHandle arrayHandle(wHandle, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);
MArrayDataBuilder arrayBuilder = arrayHandle.builder(&status);
CHECK_MSTATUS_AND_RETURN_IT(status);
for(unsigned int i = 0; i < num; i++) {
MDataHandle handle = arrayBuilder.addElement(i,&status);
CHECK_MSTATUS_AND_RETURN_IT(status);
handle.set(w[i]);
}
status = arrayHandle.set(arrayBuilder);
CHECK_MSTATUS_AND_RETURN_IT(status);
wPlug.setValue(wHandle);
dataBlock.setClean(plug);
return MS::kSuccess;
}
示例10: compute
MStatus sgIkSmoothStretch::compute( const MPlug& plug, MDataBlock& data )
{
MStatus stat;
if ( plug == aOutputDistance )
{
MArrayDataHandle hArrInputDistance = data.inputArrayValue( aInputDistance );
MDataHandle hStretchAble = data.inputValue( aStretchAble );
MDataHandle hSmoothArea = data.inputValue( aSmoothArea );
float stretchAble = hStretchAble.asFloat();
double allDistance = 0.0;
int arrayCount = hArrInputDistance.elementCount();
double* outputDistances = new double[arrayCount];
int multMinus = 1;
for( int i=0; i<arrayCount; i++ )
{
MDataHandle hInputDistance = hArrInputDistance.inputValue();
double inputDistance = hInputDistance.asDouble();
if( inputDistance < 0 )
{
multMinus = -1;
outputDistances[i] = -inputDistance;
}
else
{
outputDistances[i] = inputDistance;
}
allDistance += outputDistances[i];
hArrInputDistance.next();
}
MDataHandle hInPosition = data.inputValue( aInPosition );
MDataHandle hInPositionX = hInPosition.child( aInPositionX );
MDataHandle hInPositionY = hInPosition.child( aInPositionY );
MDataHandle hInPositionZ = hInPosition.child( aInPositionZ );
double smoothArea = hSmoothArea.asDouble()*0.1;
double poseDistance = sqrt( pow( hInPositionX.asDouble(), 2 )+pow( hInPositionY.asDouble(), 2 )+pow( hInPositionZ.asDouble(), 2 ) ) ;
allDistance = fabs( allDistance );
double stretchRate = getSmoothStretchRate( outputDistances[0], outputDistances[1], poseDistance, smoothArea );
double smoothRate = getSmoothRate( outputDistances[0], outputDistances[1], poseDistance, smoothArea );
double currentRate = ( 1-stretchAble )*smoothRate + stretchAble*stretchRate;
outputDistances[0] *= currentRate*multMinus;
outputDistances[1] *= currentRate*multMinus;
MArrayDataHandle hArrOutputDistance = data.outputArrayValue( aOutputDistance );
MArrayDataBuilder bArrOutputDistance( aOutputDistance, arrayCount, &stat );
for( int i=0; i<arrayCount; i++ )
{
MDataHandle hOutputDistance = bArrOutputDistance.addElement( i );
hOutputDistance.set( outputDistances[i] );
}
hArrOutputDistance.set( bArrOutputDistance );
hArrOutputDistance.setAllClean();
data.setClean( plug );
}
return MS::kSuccess;
}
示例11: compute
//.........这里部分代码省略.........
// splitting inbetween angle into X Y Z rotation
//converting axis from node into vector class
float xAxisArray[3] = {xAxisData[0],xAxisData[1],xAxisData[2]};
vector<float> xAxisVec = makeVector(xAxisArray) ;
float yAxisArray[3] = {yAxisData[0],yAxisData[1],yAxisData[2]};
vector<float> yAxisVec = makeVector(yAxisArray) ;
float zAxisArray[3] = {zAxisData[0],zAxisData[1],zAxisData[2]};
vector<float> zAxisVec = makeVector(zAxisArray) ;
float angleProjXYDeg=0 ;
float angleProjYZDeg=0 ;
float angleProjXZDeg=0 ;
// angle Z
vector<float> projectedV1;
vector<float> projectedV2;
projectedV1= projectVectorOnPlane(vec1,xAxisVec,yAxisVec);
projectedV2= projectVectorOnPlane(vec2,xAxisVec,yAxisVec);
angleProjXYDeg=angleInbetweenVector(projectedV1,projectedV2);
// angle X
projectedV1= projectVectorOnPlane(vec1,zAxisVec,yAxisVec);
projectedV2= projectVectorOnPlane(vec2,zAxisVec,yAxisVec);
angleProjYZDeg=angleInbetweenVector(projectedV1,projectedV2);
// angle Y
projectedV1= projectVectorOnPlane(vec1,zAxisVec,xAxisVec);
projectedV2= projectVectorOnPlane(vec2,zAxisVec,xAxisVec);
angleProjXZDeg=angleInbetweenVector(projectedV1,projectedV2);
//Setting output values
MDataHandle output = dataBlock.outputValue(dotProductA);
MDataHandle outputMax = dataBlock.outputValue(dotProductMax);
MDataHandle projV1Output = dataBlock.outputValue(proj1on2);
MDataHandle projV2Output = dataBlock.outputValue(proj2on1);
MDataHandle angleInBetweenOutput = dataBlock.outputValue(angleInBetweenAttr);
MDataHandle angleXout = dataBlock.outputValue(angleX);
MDataHandle angleYout = dataBlock.outputValue(angleY);
MDataHandle angleZout = dataBlock.outputValue(angleZ);
output.set(dotResult);
outputMax.set(maxValue);
projV1Output.set(v1Vec[0],v1Vec[1],v1Vec[2]);
projV2Output.set(v2Vec[0],v2Vec[1],v2Vec[2]);
angleInBetweenOutput.set(angleDeg);
angleXout.set(angleProjYZDeg);
angleYout.set(angleProjXZDeg);
angleZout.set(angleProjXYDeg);
//SetClean tells maya attribute is update
outputMax.setClean();
output.setClean();
projV1Output.setClean();
projV2Output.setClean();
angleInBetweenOutput.setClean();
angleXout.setClean();
angleYout.setClean();
angleZout.setClean();
}
return MS::kSuccess;
}
示例12: compute
MStatus splitUVNode::compute( const MPlug& plug, MDataBlock& data )
//
// Description:
// This method computes the value of the given output plug based
// on the values of the input attributes.
//
// Arguments:
// plug - the plug to compute
// data - object that provides access to the attributes for this node
//
{
MStatus status = MS::kSuccess;
MDataHandle stateData = data.outputValue( state, &status );
MCheckStatus( status, "ERROR getting state" );
// Check for the HasNoEffect/PassThrough flag on the node.
//
// (stateData is an enumeration standard in all depend nodes - stored as short)
//
// (0 = Normal)
// (1 = HasNoEffect/PassThrough)
// (2 = Blocking)
// ...
//
if( stateData.asShort() == 1 )
{
MDataHandle inputData = data.inputValue( inMesh, &status );
MCheckStatus(status,"ERROR getting inMesh");
MDataHandle outputData = data.outputValue( outMesh, &status );
MCheckStatus(status,"ERROR getting outMesh");
// Simply redirect the inMesh to the outMesh for the PassThrough effect
//
outputData.set(inputData.asMesh());
}
else
{
// Check which output attribute we have been asked to
// compute. If this node doesn't know how to compute it,
// we must return MS::kUnknownParameter
//
if (plug == outMesh)
{
MDataHandle inputData = data.inputValue( inMesh, &status );
MCheckStatus(status,"ERROR getting inMesh");
MDataHandle outputData = data.outputValue( outMesh, &status );
MCheckStatus(status,"ERROR getting outMesh");
// Now, we get the value of the uvList and use it to perform
// the operation on this mesh
//
MDataHandle inputUVs = data.inputValue( uvList, &status);
MCheckStatus(status,"ERROR getting uvList");
// Copy the inMesh to the outMesh, and now you can
// perform operations in-place on the outMesh
//
outputData.set(inputData.asMesh());
MObject mesh = outputData.asMesh();
// Retrieve the UV list from the component list.
//
// Note, we use a component list to store the components
// because it is more compact memory wise. (ie. comp[81:85]
// is smaller than comp[81], comp[82],...,comp[85])
//
MObject compList = inputUVs.data();
MFnComponentListData compListFn( compList );
unsigned i;
int j;
MIntArray uvIds;
for( i = 0; i < compListFn.length(); i++ )
{
MObject comp = compListFn[i];
if( comp.apiType() == MFn::kMeshMapComponent )
{
MFnSingleIndexedComponent uvComp( comp );
for( j = 0; j < uvComp.elementCount(); j++ )
{
int uvId = uvComp.element(j);
uvIds.append( uvId );
}
}
}
// Set the mesh object and uvList on the factory
//
fSplitUVFactory.setMesh( mesh );
fSplitUVFactory.setUVIds( uvIds );
// Now, perform the splitUV
//
status = fSplitUVFactory.doIt();
// Mark the output mesh as clean
//.........这里部分代码省略.........
示例13: compute
MStatus VmIslandNode::compute( const MPlug& i_plug, MDataBlock& io_dataBlock )
{
MStatus status;
fprintf( stderr, "VmIslandNode::compute()...\n" );
//Check plugs
if( i_plug == oa_update )
{
//Make sure all internal structures are up to date with attributes
fprintf( stderr, "VmIslandNode::compute(oa_update)\n" );
MDataHandle seedHandle = io_dataBlock.inputValue( ia_seed, & status);
const long seed = seedHandle.asLong();
CHECK_MSTATUS( status );
MDataHandle roughnessHandle = io_dataBlock.inputValue( ia_roughness, & status);
const float roughness = roughnessHandle.asFloat();
CHECK_MSTATUS( status );
MDataHandle planeHeightHandle = io_dataBlock.inputValue( ia_planeHeight, & status);
const long planeHeight = planeHeightHandle.asLong();
CHECK_MSTATUS( status );
MDataHandle smoothHandle = io_dataBlock.inputValue( ia_smooth, & status);
const long smooth = smoothHandle.asLong();
CHECK_MSTATUS( status );
MDataHandle resolutionHandle = io_dataBlock.inputValue( ia_resolution, & status);
const long resolution = resolutionHandle.asLong();
CHECK_MSTATUS( status );
MDataHandle planeSizeHandle = io_dataBlock.inputValue( ia_planeSize, & status);
const long planeSize = planeSizeHandle.asLong();
CHECK_MSTATUS( status );
MDataHandle gridSizeHandle = io_dataBlock.inputValue( ia_gridSize, & status);
const long gridSize = gridSizeHandle.asLong();
m_gridSize = (int) gridSize;
CHECK_MSTATUS( status );
//Grass
//--------------
MDataHandle baseWidthHandle = io_dataBlock.inputValue( ia_baseWidth, & status);
const float baseWidth = baseWidthHandle.asFloat();
CHECK_MSTATUS( status );
MDataHandle grassMultiplierHandle = io_dataBlock.inputValue( ia_grassMultiplier, & status);
const long grassMultiplier = grassMultiplierHandle.asLong();
CHECK_MSTATUS( status );
MDataHandle grassSegmentLengthHandle = io_dataBlock.inputValue( ia_grassSegmentLength, & status);
const float grassSegmentLength = grassSegmentLengthHandle.asFloat();
CHECK_MSTATUS( status );
MDataHandle grassNumSegmentsHandle = io_dataBlock.inputValue( ia_grassNumSegments, & status);
const long grassNumSegments = grassNumSegmentsHandle.asLong();
CHECK_MSTATUS( status );
//MDataHandle windDirectionHandle = io_dataBlock.inputValue( ia_windDirection, & status);
MFloatVector& windDirVec = io_dataBlock.inputValue( ia_windDirection, & status).asFloatVector();
const Vcore::Vec3 windDirection = Vec3(windDirVec.x, windDirVec.y, windDirVec.z);
CHECK_MSTATUS( status );
MDataHandle grassBendAmountHandle = io_dataBlock.inputValue( ia_grassBendAmount, & status);
const float grassBendAmount = grassBendAmountHandle.asFloat();
CHECK_MSTATUS( status );
MDataHandle windSpreadHandle = io_dataBlock.inputValue( ia_windSpread, & status);
const float windSpread = windSpreadHandle.asFloat();
CHECK_MSTATUS( status );
MDataHandle clockHandle = io_dataBlock.inputValue( ia_clock, & status);
const float clock = clockHandle.asLong();
CHECK_MSTATUS( status );
//Colours
//-----------------
MFloatVector& grassBaseColour1Vec = io_dataBlock.inputValue( ia_grassBaseColour1, & status).asFloatVector();
const Vcore::Vec3 grassBaseColour1 = Vec3(grassBaseColour1Vec.x, grassBaseColour1Vec.y, grassBaseColour1Vec.z);
CHECK_MSTATUS( status );
MFloatVector& grassTipColour1Vec = io_dataBlock.inputValue( ia_grassTipColour1, & status).asFloatVector();
const Vcore::Vec3 grassTipColour1 = Vec3(grassTipColour1Vec.x, grassTipColour1Vec.y, grassTipColour1Vec.z);
CHECK_MSTATUS( status );
MFloatVector& grassBaseColour2Vec = io_dataBlock.inputValue( ia_grassBaseColour2, & status).asFloatVector();
const Vcore::Vec3 grassBaseColour2 = Vec3(grassBaseColour2Vec.x, grassBaseColour2Vec.y, grassBaseColour2Vec.z);
CHECK_MSTATUS( status );
MFloatVector& grassTipColour2Vec = io_dataBlock.inputValue( ia_grassTipColour2, & status).asFloatVector();
const Vcore::Vec3 grassTipColour2 = Vec3(grassTipColour2Vec.x, grassTipColour2Vec.y, grassTipColour2Vec.z);
CHECK_MSTATUS( status );
//Update paramters of external lib system and rebuild
m_island.setPlaneParameters(
//.........这里部分代码省略.........
示例14: compute
MStatus meshOpNode::compute( const MPlug& plug, MDataBlock& data )
//
// Description:
// This method computes the value of the given output plug based
// on the values of the input attributes.
//
// Arguments:
// plug - the plug to compute
// data - object that provides access to the attributes for this node
//
{
MStatus status = MS::kSuccess;
MDataHandle stateData = data.outputValue( state, &status );
MCheckStatus( status, "ERROR getting state" );
// Check for the HasNoEffect/PassThrough flag on the node.
//
// (stateData is an enumeration standard in all depend nodes)
//
// (0 = Normal)
// (1 = HasNoEffect/PassThrough)
// (2 = Blocking)
// ...
//
if( stateData.asShort() == 1 )
{
MDataHandle inputData = data.inputValue( inMesh, &status );
MCheckStatus(status,"ERROR getting inMesh");
MDataHandle outputData = data.outputValue( outMesh, &status );
MCheckStatus(status,"ERROR getting outMesh");
// Simply redirect the inMesh to the outMesh for the PassThrough effect
//
outputData.set(inputData.asMesh());
}
else
{
// Check which output attribute we have been asked to
// compute. If this node doesn't know how to compute it,
// we must return MS::kUnknownParameter
//
if (plug == outMesh)
{
MDataHandle inputData = data.inputValue( inMesh, &status );
MCheckStatus(status,"ERROR getting inMesh");
MDataHandle outputData = data.outputValue( outMesh, &status );
MCheckStatus(status,"ERROR getting outMesh");
// Now, we get the value of the component list and the operation
// type and use it to perform the mesh operation on this mesh
//
MDataHandle inputIDs = data.inputValue( cpList, &status);
MCheckStatus(status,"ERROR getting componentList");
MDataHandle opTypeData = data.inputValue( opType, &status);
MCheckStatus(status,"ERROR getting opType");
// Copy the inMesh to the outMesh, so you can
// perform operations directly on outMesh
//
outputData.set(inputData.asMesh());
MObject mesh = outputData.asMesh();
// Retrieve the ID list from the component list.
//
// Note, we use a component list to store the components
// because it is more compact memory wise. (ie. comp[81:85]
// is smaller than comp[81], comp[82],...,comp[85])
//
MObject compList = inputIDs.data();
MFnComponentListData compListFn( compList );
// Get what operation is requested and
// what type of component is expected for this operation.
MeshOperation operationType = (MeshOperation) opTypeData.asShort();
MFn::Type componentType =
meshOpFty::getExpectedComponentType(operationType);
unsigned i;
int j;
MIntArray cpIds;
for( i = 0; i < compListFn.length(); i++ )
{
MObject comp = compListFn[i];
if( comp.apiType() == componentType )
{
MFnSingleIndexedComponent siComp( comp );
for( j = 0; j < siComp.elementCount(); j++ )
cpIds.append( siComp.element(j) );
}
}
// Set the mesh object and component List on the factory
//
fmeshOpFactory.setMesh( mesh );
fmeshOpFactory.setComponentList( compList );
//.........这里部分代码省略.........
示例15: validateAndSetValue
//
// A very simple implementation of validAndSetValue(). No lock
// or limit checking on the rocking attribute is done in this method.
// If you wish to apply locks and limits to the rocking attribute, you
// would follow the approach taken in the rockingTransformCheck example.
// Meaning you would implement methods similar to:
// * applyRotationLocks();
// * applyRotationLimits();
// * checkAndSetRotation();
// but for the rocking attribute. The method checkAndSetRotation()
// would be called below rather than updating the rocking attribute
// directly.
//
MStatus rockingTransformNode::validateAndSetValue(const MPlug& plug,
const MDataHandle& handle,
const MDGContext& context)
{
MStatus status = MS::kSuccess;
// Make sure that there is something interesting to process.
//
if (plug.isNull())
return MS::kFailure;
MDataBlock block = forceCache(*(MDGContext *)&context);
MDataHandle blockHandle = block.outputValue(plug, &status);
ReturnOnError(status);
MString cachename = block.inputValue( acachename ).asString();
MString meshname = block.inputValue( ameshname ).asString();
/*
if ( plug == aRockInX )
{
// Update our new rock in x value
double rockInX = handle.asDouble();
blockHandle.set(rockInX);
rockXValue = rockInX;
// Update the custom transformation matrix to the
// right rock value.
rockingTransformMatrix *ltm = getRockingTransformMatrix();
if (ltm)
ltm->setRockInX(rockXValue);
else
MGlobal::displayError("Failed to get rock transform matrix");
blockHandle.setClean();
// Mark the matrix as dirty so that DG information
// will update.
dirtyMatrix();
}
*/
if ( plug == aframe )
{
// Update our new rock in x value
double rockInX = handle.asDouble();
blockHandle.set(rockInX);
rockXValue = rockInX;
// Update the custom transformation matrix to the
// right rock value.
rockingTransformMatrix *ltm = getRockingTransformMatrix();
if (ltm)
ltm->setRockInX(rockXValue, cachename, meshname);
else
MGlobal::displayError("Failed to get rock transform matrix");
blockHandle.setClean();
// Mark the matrix as dirty so that DG information
// will update.
dirtyMatrix();
}
// Allow processing for other attributes
return ParentClass::validateAndSetValue(plug, handle, context);
}