本文整理汇总了C++中MDataHandle::asFloat方法的典型用法代码示例。如果您正苦于以下问题:C++ MDataHandle::asFloat方法的具体用法?C++ MDataHandle::asFloat怎么用?C++ MDataHandle::asFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDataHandle
的用法示例。
在下文中一共展示了MDataHandle::asFloat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
/* virtual */
bool
wingVizNode::setInternalValueInContext( const MPlug& plug,
const MDataHandle& handle,
MDGContext&)
{
bool handledAttribute = false;
if (plug == acachename)
{
handledAttribute = true;
m_cachename = (MString) handle.asString();
}
else if(plug == aratio)
{
handledAttribute = true;
m_scale = handle.asFloat();
}
else if(plug == awind)
{
handledAttribute = true;
m_wind = handle.asFloat();
}
return handledAttribute;
}
示例2: compute
MStatus blendTwoMatrixDecompose::compute( const MPlug& plug, MDataBlock& block )
{
MStatus stat;
MDataHandle hMatrix1 = block.inputValue( aMatrix1, &stat );
MDataHandle hMatrix2 = block.inputValue( aMatrix2, &stat );
MDataHandle hBlender = block.inputValue( aBlender );
MMatrix matrix = hMatrix1.asMatrix()*( 1-hBlender.asFloat() ) + hMatrix2.asMatrix()*hBlender.asFloat();
MPxTransformationMatrix trMtx( matrix );
MDataHandle hOutputTranslate = block.outputValue( aOutputTranslate );
MDataHandle hOutputRotate = block.outputValue( aOutputRotate );
MDataHandle hOutputScale = block.outputValue( aOutputScale );
MDataHandle hOutputShear = block.outputValue( aOutputShear );
MVector translate = trMtx.translation();
hOutputTranslate.set( translate );
MVector rotate = trMtx.eulerRotation().asVector();
hOutputRotate.set( rotate );
MVector scale = trMtx.scale();
hOutputScale.set( scale );
MVector shear = trMtx.shear();
hOutputShear.set( shear );
block.setClean( plug );
return MS::kSuccess;
}
示例3: 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;
}
示例4: q
MStatus Cell3D::compute(const MPlug& plug, MDataBlock& block)
{
if ( (plug != aOutColor) && (plug.parent() != aOutColor) &&
(plug != aOutAlpha) &&
(plug != aOutBorderDist) &&
(plug != aOutF0) && (plug != aOutF1) && (plug != aOutN0)
)
return MS::kUnknownParameter;
const float3& worldPos = block.inputValue(aPointWorld).asFloat3();
const MFloatMatrix& m = block.inputValue(aPlaceMat).asFloatMatrix();
const MFloatVector& cGain = block.inputValue(aColorGain).asFloatVector();
const MFloatVector& cOff = block.inputValue(aColorOffset).asFloatVector();
MFloatPoint q(worldPos[0], worldPos[1], worldPos[2]);
q *= m; // Convert into solid space
float n0, f0, f1;
cellFunc(R3(q.x, q.y, q.z), n0, f0, f1);
MDataHandle outHandle = block.outputValue(aOutF0);
outHandle.asFloat() = f0;
outHandle.setClean();
outHandle = block.outputValue(aOutF1);
outHandle.asFloat() = f1;
outHandle.setClean();
outHandle = block.outputValue(aOutN0);
outHandle.asFloat() = n0;
outHandle.setClean();
outHandle = block.outputValue(aOutBorderDist);
outHandle.asFloat() = 0.5f*(f1 - f0);
outHandle.setClean();
outHandle = block.outputValue( aOutColor );
MFloatVector & outColor = outHandle.asFloatVector();
outColor = cGain * f0 + cOff;
outHandle.setClean();
outHandle = block.outputValue(aOutAlpha);
outHandle.asFloat() = f0;
outHandle.setClean();
return MS::kSuccess;
}
示例5: compute
// The compute method is called by Maya when the input values
// change and the output values need to be recomputed.
// The input values are read then using sinf() and cosf()
// the output values are stored on the output plugs.
//
MStatus circle::compute (const MPlug& plug, MDataBlock& data)
{
MStatus returnStatus;
// Check that the requested recompute is one of the output values
//
if (plug == sOutput || plug == cOutput) {
// Read the input values
//
MDataHandle inputData = data.inputValue (input, &returnStatus);
CHECK_MSTATUS( returnStatus );
MDataHandle scaleData = data.inputValue (scale, &returnStatus);
CHECK_MSTATUS( returnStatus );
MDataHandle framesData = data.inputValue (frames, &returnStatus);
CHECK_MSTATUS( returnStatus );
// Compute the output values
//
float currentFrame = inputData.asFloat();
float scaleFactor = scaleData.asFloat();
float framesPerCircle = framesData.asFloat();
float angle = 6.2831853f * (currentFrame/framesPerCircle);
float sinResult = sinf (angle) * scaleFactor;
float cosResult = cosf (angle) * scaleFactor;
// Store them on the output plugs
//
MDataHandle sinHandle = data.outputValue( circle::sOutput,
&returnStatus );
CHECK_MSTATUS( returnStatus );
MDataHandle cosHandle = data.outputValue( circle::cOutput,
&returnStatus );
CHECK_MSTATUS( returnStatus );
sinHandle.set( sinResult );
cosHandle.set( cosResult );
CHECK_MSTATUS( data.setClean( plug ) );
} else {
return MS::kUnknownParameter;
}
return MS::kSuccess;
}
示例6: 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;
}
示例7: deform
MStatus DucttapeMergeDeformer::deform( MDataBlock& block,
MItGeometry& iter,
const MMatrix& m,
unsigned int multiIndex)
{
MStatus status;
MDataHandle envData = block.inputValue(envelope,&status);
const float env = envData.asFloat();
if(env < 1e-3f) return status;
if(multiIndex == 0) {
if(m_inputGeomIter) {
delete m_inputGeomIter;
m_inputGeomIter = NULL;
}
MDataHandle hmesh = block.inputValue(ainmesh);
MItGeometry * aiter = new MItGeometry( hmesh, true, &status );
if(!status) {
AHelper::Info<int>("DucttapeMergeDeformer error no geom it", 0);
return status;
}
m_inputGeomIter = aiter;
}
if(!m_inputGeomIter) return status;
MPoint pd;
MVector dv;
for (; !iter.isDone(); iter.next()) {
if(m_inputGeomIter->isDone() ) return status;
float wei = env * weightValue(block, multiIndex, iter.index() );
if(wei > 1e-3f) {
pd = iter.position();
dv = m_inputGeomIter->position() - pd;
pd = pd + dv * wei;
iter.setPosition(pd);
}
m_inputGeomIter->next();
}
return status;
}
示例8: compute
//
// DESCRIPTION:
///////////////////////////////////////////////////////
MStatus DispNode::compute(
const MPlug& plug,
MDataBlock& block )
{
if ((plug == aOutColor) || (plug.parent() == aOutColor) ||
(plug == aOutDisplacement))
{
MFloatVector resultColor(0.0,0.0,0.0);
MFloatVector& InputColor = block.inputValue( aColor ).asFloatVector();
float MultValue = block.inputValue( aInputValue ).asFloat();
resultColor = InputColor;
float scalar = resultColor[0] + resultColor[1] + resultColor[2];
if (scalar != 0.0) {
scalar /= 3.0;
scalar *= MultValue;
}
// set ouput color attribute
MDataHandle outColorHandle = block.outputValue( aOutColor );
MFloatVector& outColor = outColorHandle.asFloatVector();
outColor = resultColor;
outColorHandle.setClean();
MDataHandle outDispHandle = block.outputValue( aOutDisplacement );
float& outDisp = outDispHandle.asFloat();
outDisp = scalar;
outDispHandle.setClean( );
}
else if ((plug == aOutTransparency) || (plug.parent() == aOutTransparency))
{
// set output transparency to be opaque
MFloatVector transparency(0.0,0.0,0.0);
MDataHandle outTransHandle = block.outputValue( aOutTransparency );
MFloatVector& outTrans = outTransHandle.asFloatVector();
outTrans = transparency;
outTransHandle.setClean( );
}
else
return MS::kUnknownParameter;
return MS::kSuccess;
}
示例9: compute
//- 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 simpleNode::compute( const MPlug& plug, MDataBlock& data )
{
//- Check which output attribute we have been asked to compute. If this
//- node doesn't know how to compute it, you must return MS::kUnknownParameter.
if( plug == simpleNode::output )
{
//- Get a handle to the input attribute that we will need for the
//- computation. If the value is being supplied via a connection
//- in the dependency graph, then this call will cause all upstream
//- connections to be evaluated so that the correct value is supplied.
MDataHandle inputData = data.inputValue( simpleNode::input );
//- Read the input value from the handle.
float result = inputData.asFloat();
//- Get a handle to the output attribute. This is similar to the
//- "inputValue" call above except that no dependency graph
//- computation will be done as a result of this call.
//- Get a handle on the output attribute
MDataHandle outputHandle = data.outputValue( simpleNode::output );
//- Set the new output value to the handle.
outputHandle.set( result * 2 );
//- Mark the destination plug as being clean. This will prevent the
//- dependency graph from repeating this calculation until an input
//- attribute of this node which affects this output attribute changes.
//- Tell Maya the plug is now clean
data.setClean(plug);
//- Return success to Maya
return MS::kSuccess;
}
//- Tell Maya that we do not know how to handle this plug, but let give a chance
//- to our parent class to evaluate it.
return MS::kUnknownParameter;
}
示例10: compute
MStatus myComp::compute(const MPlug& plug, MDataBlock& block)
{
// outColor or individial R, G, B channel
if((plug != aOutColor) && (plug.parent() != aOutColor) &&
(plug != aOutAlpha))
return MS::kUnknownParameter;
MFloatVector resultColor;
MFloatVector& fore = block.inputValue( aForegroundColor ).asFloatVector();
MFloatVector& back = block.inputValue( aBackgroundColor ).asFloatVector();
MFloatVector& bclr = block.inputValue( aBackColor ).asFloatVector();
float& alpha = block.inputValue( aMask ).asFloat();
if ( alpha > 0.99999f ) alpha = 1.f;
else if ( alpha < 0.00001 ) alpha = 0.f;
resultColor = fore + ((bclr - back) * (1.0f - alpha));
// normalize output color
if (resultColor[0] < 0.f ) resultColor[0] = 0.f;
if (resultColor[1] < 0.f ) resultColor[1] = 0.f;
if (resultColor[2] < 0.f ) resultColor[2] = 0.f;
if (resultColor[0] > 1.f ) resultColor[0] = 1.f;
if (resultColor[1] > 1.f ) resultColor[1] = 1.f;
if (resultColor[2] > 1.f ) resultColor[2] = 1.f;
// set ouput color attribute
MDataHandle outColorHandle = block.outputValue( aOutColor );
MFloatVector& outColor = outColorHandle.asFloatVector();
outColor = resultColor;
outColorHandle.setClean();
MDataHandle outAlphaHandle = block.outputValue( aOutAlpha );
float& outAlpha = outAlphaHandle.asFloat();
outAlpha = ( resultColor.x + resultColor.y + resultColor.z ) / 3.0f;
outAlphaHandle.setClean();
return MS::kSuccess;
}
示例11: compute
//
// This function gets called by Maya to evaluate the texture.
//
MStatus mySChecker::compute(const MPlug& plug, MDataBlock& block)
{
// outColor or individial R, G, B channel, or alpha
if((plug != aOutColor) && (plug.parent() != aOutColor) &&
(plug != aOutAlpha))
return MS::kUnknownParameter;
MFloatVector resultColor;
float3 & worldPos = block.inputValue(aPointWorld).asFloat3();
MFloatMatrix& mat = block.inputValue(aPlaceMat).asFloatMatrix();
float3 & bias = block.inputValue(aBias).asFloat3();
MFloatPoint pos(worldPos[0], worldPos[1], worldPos[2]);
pos *= mat; // Convert into solid space
// normalize the point
int count = 0;
if (pos.x - floor(pos.x) < bias[0]) count++;
if (pos.y - floor(pos.y) < bias[1]) count++;
if (pos.z - floor(pos.z) < bias[2]) count++;
if (count & 1)
resultColor = block.inputValue(aColor2).asFloatVector();
else
resultColor = block.inputValue(aColor1).asFloatVector();
// Set ouput color attribute
MDataHandle outColorHandle = block.outputValue( aOutColor );
MFloatVector& outColor = outColorHandle.asFloatVector();
outColor = resultColor;
outColorHandle.setClean();
// Set ouput alpha attribute
MDataHandle outAlphaHandle = block.outputValue( aOutAlpha );
float& outAlpha = outAlphaHandle.asFloat();
outAlpha = ( count & 1) ? 1.0f : 0.0f;
outAlphaHandle.setClean();
return MS::kSuccess;
}
示例12: compute
MStatus simpleEvaluationNode::compute( const MPlug& plug, MDataBlock& data )
{
MStatus returnStatus;
if( plug == output )
{
MDataHandle inputData = data.inputValue( input, &returnStatus );
if( returnStatus != MS::kSuccess )
{
cerr << "ERROR getting data" << endl;
}
else
{
MDataHandle inputTimeData = data.inputValue( aTimeInput, &returnStatus );
if( returnStatus != MS::kSuccess )
{
cerr << "ERROR getting data" << endl;
}
else
{
if ( ! cachedValueIsValid )
{
MTime time = inputTimeData.asTime();
cachedValue = doExpensiveCalculation( inputData.asFloat() , (float) time.value() );
cachedValueIsValid = true;
}
MDataHandle outputHandle = data.outputValue( simpleEvaluationNode::output );
outputHandle.set( cachedValue );
data.setClean(plug);
}
}
} else {
return MS::kUnknownParameter;
}
return MS::kSuccess;
}
示例13: solidPos
//
// This function gets called by Maya to evaluate the texture.
//
MStatus noise3::compute(const MPlug& plug, MDataBlock& block)
{
// outColor or individial R, G, B channel, or alpha
if((plug != aOutColor) && (plug.parent() != aOutColor) &&
(plug != aOutAlpha))
return MS::kUnknownParameter;
MFloatVector resultColor;
MFloatVector & col1 = block.inputValue(aColor1).asFloatVector();
MFloatVector & col2 = block.inputValue(aColor2).asFloatVector();
float3 & worldPos = block.inputValue( aPointWorld ).asFloat3();
MFloatMatrix& mat = block.inputValue( aPlaceMat ).asFloatMatrix();
float& sc = block.inputValue( aScale ).asFloat();
float& bi = block.inputValue( aBias ).asFloat();
MFloatPoint solidPos(worldPos[0], worldPos[1], worldPos[2]);
solidPos *= mat; // Convert into solid space
float val = fabsf( pnoise3( solidPos ) * sc + bi );
if (val < 0.) val = 0.;
if (val > 1.) val = 1.;
resultColor = col1 * val + col2*(1-val);
// Set output color attribute
MDataHandle outColorHandle = block.outputValue( aOutColor );
MFloatVector& outColor = outColorHandle.asFloatVector();
outColor = resultColor;
outColorHandle.setClean();
MDataHandle outAlphaHandle = block.outputValue( aOutAlpha );
float& outAlpha = outAlphaHandle.asFloat();
outAlpha = val;
outAlphaHandle.setClean();
return MS::kSuccess;
}
示例14: compute
MStatus CheckerNode::compute(
const MPlug& plug,
MDataBlock& block )
{
// outColor or individial R, G, B channel, or alpha
if((plug != aOutColor) && (plug.parent() != aOutColor) &&
(plug != aOutAlpha))
return MS::kUnknownParameter;
MFloatVector resultColor;
float2 & uv = block.inputValue( aUVCoord ).asFloat2();
float2 & bias = block.inputValue( aBias ).asFloat2();
int count = 0;
if (uv[0] - floorf(uv[0]) < bias[0]) count++;
if (uv[1] - floorf(uv[1]) < bias[1]) count++;
if (count & 1)
resultColor = block.inputValue( aColor2 ).asFloatVector();
else
resultColor = block.inputValue( aColor1 ).asFloatVector();
// Set ouput color attribute
MDataHandle outColorHandle = block.outputValue( aOutColor );
MFloatVector& outColor = outColorHandle.asFloatVector();
outColor = resultColor;
outColorHandle.setClean();
// Set ouput alpha attribute
MDataHandle outAlphaHandle = block.outputValue( aOutAlpha );
float& outAlpha = outAlphaHandle.asFloat();
outAlpha = (count & 1) ? 1.f : 0.f;
outAlphaHandle.setClean();
return MS::kSuccess;
}
示例15: compute
MStatus sine::compute( const MPlug& plug, MDataBlock& data )
{
MStatus returnStatus;
if( plug == output )
{
MDataHandle inputData = data.inputValue( input, &returnStatus );
if( returnStatus != MS::kSuccess )
cerr << "ERROR getting data" << endl;
else
{
float result = sinf( inputData.asFloat() ) * 10.0f;
MDataHandle outputHandle = data.outputValue( sine::output );
outputHandle.set( result );
data.setClean(plug);
}
} else {
return MS::kUnknownParameter;
}
return MS::kSuccess;
}