本文整理汇总了C++中MDataHandle::asString方法的典型用法代码示例。如果您正苦于以下问题:C++ MDataHandle::asString方法的具体用法?C++ MDataHandle::asString怎么用?C++ MDataHandle::asString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDataHandle
的用法示例。
在下文中一共展示了MDataHandle::asString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
bool
OpenSubdivShader::setInternalValueInContext(const MPlug &plug, const MDataHandle &handle, MDGContext &)
{
if (plug == aLevel) {
_hbrMeshDirty = true;
_level = handle.asLong();
} else if (plug == aTessFactor) {
_tessFactor = handle.asLong();
} else if (plug == aScheme) {
_hbrMeshDirty = true;
_scheme = (OsdMeshData::SchemeType)handle.asShort();
} else if (plug == aKernel) {
_hbrMeshDirty = true;
_kernel = (OsdMeshData::KernelType)handle.asShort();
} else if (plug == aInterpolateBoundary) {
_hbrMeshDirty = true;
_interpolateBoundary = (OsdMeshData::InterpolateBoundaryType)handle.asShort();
} else if (plug == aAdaptive) {
_hbrMeshDirty = true;
_adaptiveDirty = true;
_adaptive = handle.asBool();
} else if (plug == aDiffuseMapFile) {
_diffuseMapDirty = true;
_diffuseMapFile = handle.asString();
} else if (plug == aUVSet) {
_hbrMeshDirty = true;
_uvSet = handle.asString();
} else if (plug == aInterpolateUVBoundary) {
_hbrMeshDirty = true;
_interpolateUVBoundary = (OsdMeshData::InterpolateBoundaryType)handle.asShort();
} else if (plug == aShaderSource) {
_shaderSourceFilename = handle.asString();
std::ifstream ifs;
ifs.open(_shaderSourceFilename.asChar());
if (ifs.fail()) {
printf("Using default shader\n");
_shaderSource.clear();
_shaderSourceFilename.clear();
} else {
printf("Using %s shader\n", _shaderSourceFilename.asChar());
std::stringstream buffer;
buffer << ifs.rdbuf();
_shaderSource = buffer.str();
}
ifs.close();
_shaderSourceDirty = true;
}
return false;
}
示例2: setInternalValueInContext
// Cache the plug arrays for use in setDependentsDirty
bool AlembicCurvesDeformNode::setInternalValueInContext(const MPlug & plug,
const MDataHandle & dataHandle,
MDGContext &)
{
if (plug == mGeomParamsList) {
MString geomParamsStr = dataHandle.asString();
getPlugArrayFromAttrList(geomParamsStr, thisMObject(), mGeomParamPlugs);
}
else if (plug == mUserAttrsList) {
MString userAttrsStr = dataHandle.asString();
getPlugArrayFromAttrList(userAttrsStr, thisMObject(), mUserAttrPlugs);
}
return false;
}
示例3: 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;
}
示例4: compute
MStatus LSystemNode::compute(const MPlug& plug, MDataBlock& data)
{
MStatus returnStatus;
if (plug == outputMesh) {
//angle
MDataHandle angleData = data.inputValue(angle,&returnStatus);
McheckErr(returnStatus, "Error getting angle data handle\n");
double angle = angleData.asDouble();
//step
MDataHandle stepData = data.inputValue(step,&returnStatus);
McheckErr(returnStatus, "Error getting step data handle\n");
double step = stepData.asDouble();
//grammar
MDataHandle grammarData = data.inputValue(grammar,&returnStatus);
McheckErr(returnStatus, "Error getting grammar data handle\n");
MString grammar = grammarData.asString();
/* Get time */
MDataHandle timeData = data.inputValue( time, &returnStatus );
McheckErr(returnStatus, "Error getting time data handle\n");
MTime time = timeData.asTime();
/* 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");
createMesh(angle, step, grammar, time, newOutputData, returnStatus);
McheckErr(returnStatus, "ERROR creating new Cube");
outputHandle.set(newOutputData);
data.setClean( plug );
} else
return MS::kUnknownParameter;
return MS::kSuccess;
}
示例5: compute
MStatus stringFormat::compute (const MPlug& plug, MDataBlock& data)
{
MStatus status;
// Check that the requested recompute is one of the output values
//
if (plug == attrOutput) {
// Read the input values
//
MDataHandle inputData = data.inputValue (attrFormat, &status);
CHECK_MSTATUS( status );
MString format = inputData.asString();
// Get input data handle, use outputArrayValue since we do not
// want to evaluate all inputs, only the ones related to the
// requested multiIndex. This is for efficiency reasons.
//
MArrayDataHandle vals = data.outputArrayValue(attrValues, &status);
CHECK_MSTATUS( status );
int indx = 0;
int param;
char letter;
while ((indx = findNextMatch(format, indx, param, letter)) > 0) {
double val = 0.;
status = vals.jumpToElement(param);
if (status == MStatus::kSuccess) {
MDataHandle thisVal = vals.inputValue( &status );
if (status == MStatus::kSuccess) {
val = thisVal.asDouble();
}
}
MString replace;
bool valid = false;
switch (letter) {
case 'd': // Integer
val = floor(val+.5);
// No break here
case 'f': // Float
replace.set(val);
valid = true;
break;
case 't': // Timecode
{
const char * sign = "";
if (val<0) {
sign = "-";
val = -val;
}
int valInt = (int)(val+.5);
int sec = valInt / 24;
int frame = valInt - sec * 24;
int min = sec / 60;
sec -= min * 60;
int hour = min / 60;
min -= hour * 60;
char buffer[90];
if (hour>0)
sprintf(buffer, "%s%d:%02d:%02d.%02d",
sign, hour, min, sec, frame);
else
sprintf(buffer, "%s%02d:%02d.%02d",
sign, min, sec, frame);
replace = buffer;
}
valid = true;
break;
}
if (valid) {
format = format.substring(0, indx-2) +
replace + format.substring(indx+2, format.length()-1);
indx += replace.length() - 3;
}
}
// Store the result
//
MDataHandle output = data.outputValue(attrOutput, &status );
CHECK_MSTATUS( status );
output.set( format );
} else {
return MS::kUnknownParameter;
}
return MS::kSuccess;
}
示例6: if
bool
OpenSubdivPtexShader::setInternalValueInContext(const MPlug &plug, const MDataHandle &handle, MDGContext &)
{
if (plug == aLevel) {
_hbrMeshDirty = true;
_level = handle.asLong();
} else if (plug == aTessFactor) {
_tessFactor = handle.asLong();
} else if (plug == aScheme) {
_hbrMeshDirty = true;
_scheme = (OsdPtexMeshData::SchemeType)handle.asShort();
} else if (plug == aKernel) {
_hbrMeshDirty = true;
_kernel = (OsdPtexMeshData::KernelType)handle.asShort();
} else if (plug == aInterpolateBoundary) {
_hbrMeshDirty = true;
_interpolateBoundary = (OsdPtexMeshData::InterpolateBoundaryType)handle.asShort();
} else if (plug == aAdaptive) {
_hbrMeshDirty = true;
_adaptiveDirty = true;
_adaptive = handle.asBool();
} else if (plug == aShaderSource) {
_shaderSourceFilename = handle.asString();
std::ifstream ifs;
ifs.open(_shaderSourceFilename.asChar());
if (ifs.fail()) {
printf("Using default shader\n");
_shaderSource.clear();
_shaderSourceFilename.clear();
} else {
printf("Using %s shader\n", _shaderSourceFilename.asChar());
std::stringstream buffer;
buffer << ifs.rdbuf();
_shaderSource = buffer.str();
}
ifs.close();
_shaderSourceDirty = true;
} else if (plug == aDiffuseEnvironmentMapFile) {
_diffEnvMapDirty = true;
_diffEnvMapFile = handle.asString();
} else if (plug == aSpecularEnvironmentMapFile) {
_specEnvMapDirty = true;
_specEnvMapFile = handle.asString();
} else if (plug == aColorFile) {
_ptexColorDirty = true;
_colorFile = handle.asString();
} else if (plug == aDisplacementFile) {
_ptexDisplacementDirty = true;
_displacementFile = handle.asString();
} else if (plug == aOcclusionFile) {
_ptexOcclusionDirty = true;
_occlusionFile = handle.asString();
} else if (plug == aEnableColor) {
_enableColor = handle.asBool();
} else if (plug == aEnableDisplacement) {
_enableDisplacement = handle.asBool();
} else if (plug == aEnableOcclusion) {
_enableOcclusion = handle.asBool();
} else if (plug == aEnableNormal) {
_enableNormal = handle.asBool();
}
return false;
}
示例7: compute
MStatus AlembicNode::compute(const MPlug & plug, MDataBlock & dataBlock)
{
MStatus status;
// update the frame number to be imported
MDataHandle speedHandle = dataBlock.inputValue(mSpeedAttr, &status);
double speed = speedHandle.asDouble();
MDataHandle offsetHandle = dataBlock.inputValue(mOffsetAttr, &status);
double offset = offsetHandle.asDouble();
MDataHandle timeHandle = dataBlock.inputValue(mTimeAttr, &status);
MTime t = timeHandle.asTime();
double inputTime = t.as(MTime::kSeconds);
double fps = getFPS();
// scale and offset inputTime.
inputTime = computeAdjustedTime(inputTime, speed, offset/fps);
// this should be done only once per file
if (mFileInitialized == false)
{
mFileInitialized = true;
MDataHandle dataHandle = dataBlock.inputValue(mAbcFileNameAttr);
MFileObject fileObject;
fileObject.setRawFullName(dataHandle.asString());
MString fileName = fileObject.resolvedFullName();
// TODO, make sure the file name, or list of files create a valid
// Alembic IArchive
// initialize some flags for plug update
mSubDInitialized = false;
mPolyInitialized = false;
// When an alembic cache will be imported at the first time using
// AbcImport, we need to set mIncludeFilterAttr (filterHandle) to be
// mIncludeFilterString for later use. When we save a maya scene(.ma)
// mIncludeFilterAttr will be saved. Then when we load the saved
// .ma file, mIncludeFilterString will be set to be mIncludeFilterAttr.
MDataHandle includeFilterHandle =
dataBlock.inputValue(mIncludeFilterAttr, &status);
MString& includeFilterString = includeFilterHandle.asString();
if (mIncludeFilterString.length() > 0)
{
includeFilterHandle.set(mIncludeFilterString);
dataBlock.setClean(mIncludeFilterAttr);
}
else if (includeFilterString.length() > 0)
{
mIncludeFilterString = includeFilterString;
}
MDataHandle excludeFilterHandle =
dataBlock.inputValue(mExcludeFilterAttr, &status);
MString& excludeFilterString = excludeFilterHandle.asString();
if (mExcludeFilterString.length() > 0)
{
excludeFilterHandle.set(mExcludeFilterString);
dataBlock.setClean(mExcludeFilterAttr);
}
else if (excludeFilterString.length() > 0)
{
mExcludeFilterString = excludeFilterString;
}
MFnDependencyNode dep(thisMObject());
MPlug allSetsPlug = dep.findPlug("allColorSets");
CreateSceneVisitor visitor(inputTime, !allSetsPlug.isNull(),
MObject::kNullObj, CreateSceneVisitor::NONE, "",
mIncludeFilterString, mExcludeFilterString);
{
mData.getFrameRange(mSequenceStartTime, mSequenceEndTime);
MDataHandle startFrameHandle = dataBlock.inputValue(mStartFrameAttr,
&status);
startFrameHandle.set(mSequenceStartTime*fps);
MDataHandle endFrameHandle = dataBlock.inputValue(mEndFrameAttr,
&status);
endFrameHandle.set(mSequenceEndTime*fps);
}
}
// Retime
MDataHandle cycleHandle = dataBlock.inputValue(mCycleTypeAttr, &status);
short playType = cycleHandle.asShort();
inputTime = computeRetime(inputTime, mSequenceStartTime, mSequenceEndTime,
playType);
clamp<double>(mSequenceStartTime, mSequenceEndTime, inputTime);
// update only when the time lapse is big enough
if (fabs(inputTime - mCurTime) > 0.00001)
{
mOutRead = std::vector<bool>(mOutRead.size(), false);
//.........这里部分代码省略.........
示例8: if
/* virtual */
bool
hwColorPerVertexShader::setInternalValueInContext( const MPlug& plug,
const MDataHandle& handle,
MDGContext&)
{
bool handledAttribute = false;
if (plug == aNormalsPerVertex)
{
handledAttribute = true;
mNormalsPerVertex = (unsigned int) handle.asInt();
}
else if (plug == aColorsPerVertex)
{
handledAttribute = true;
mColorsPerVertex = (unsigned int) handle.asInt();
}
else if (plug == aColorSetName)
{
handledAttribute = true;
mColorSetName = (MString) handle.asString();
}
else if (plug == aTexRotateX)
{
handledAttribute = true;
mTexRotateX = handle.asFloat();
}
else if (plug == aTexRotateY)
{
handledAttribute = true;
mTexRotateY = handle.asFloat();
}
else if (plug == aTexRotateZ)
{
handledAttribute = true;
mTexRotateZ = handle.asFloat();
}
else if (plug == aColorGain)
{
handledAttribute = true;
float3 & val = handle.asFloat3();
if (val[0] != mColorGain[0] ||
val[1] != mColorGain[1] ||
val[2] != mColorGain[2])
{
mColorGain[0] = val[0];
mColorGain[1] = val[1];
mColorGain[2] = val[2];
mAttributesChanged = true;
}
}
else if (plug == aColorBias)
{
handledAttribute = true;
float3 &val = handle.asFloat3();
if (val[0] != mColorBias[0] ||
val[1] != mColorBias[1] ||
val[2] != mColorBias[2])
{
mColorBias[0] = val[0];
mColorBias[1] = val[1];
mColorBias[2] = val[2];
mAttributesChanged = true;
}
}
else if (plug == aTranspGain)
{
handledAttribute = true;
float val = handle.asFloat();
if (val != mTranspGain)
{
mTranspGain = val;
mAttributesChanged = true;
}
}
else if (plug == aTranspBias)
{
handledAttribute = true;
float val = handle.asFloat();
if (val != mTranspBias)
{
mTranspBias = val;
mAttributesChanged = true;
}
}
return handledAttribute;
}
示例9: compute
MStatus NBuddyEMPSaverNode::compute( const MPlug& plug, MDataBlock& data )
{
MStatus status;
if (plug == _outTrigger)
{
MDataHandle outputPathHdl = data.inputValue( _empOutputPath, &status );
NM_CheckMStatus( status, "Failed to get the output path handle");
MString outputPath = outputPathHdl.asString();
// Get the input time
MDataHandle timeHdl = data.inputValue( _time, &status );
NM_CheckMStatus( status, "Failed to get time handle");
MTime time = timeHdl.asTime();
// Get the frame padding
MDataHandle framePaddingHdl = data.inputValue( _framePadding, &status );
NM_CheckMStatus( status, "Failed to get the framePadding handle");
int numPad = framePaddingHdl.asInt();
// Get the frame padding
MDataHandle timeStepHdl = data.inputValue( _timeStep, &status );
NM_CheckMStatus( status, "Failed to get the timeStep handle");
int timeStep = timeStepHdl.asInt();
// Get the time in frames
int frameNr = (int)floor( time.as( time.uiUnit() ) );
//Create the writer, givin it the time index in seconds
Nb::EmpWriter* writer =
new Nb::EmpWriter(
"",
outputPath.asChar(), // absolute fullpath of emp
frameNr, // frame
timeStep, // timestep
numPad, // zero-padding
time.as( MTime::kSeconds ) // emp timestamp
);
// Then get the inputBodies
MArrayDataHandle inBodyArrayData = data.inputArrayValue( _inBodies, &status );
NM_CheckMStatus( status, "Failed to create get inBodyArrayData handle");
// Loop the input in the inBody multi plug
unsigned int numBodies = inBodyArrayData.elementCount();
if ( numBodies > 0 )
{
//Jump to the first element in the array
inBodyArrayData.jumpToArrayElement(0);
//Loop all the body inputs and add them to the empWriter
for ( unsigned int i(0); i < numBodies; ++i)
{
MDataHandle bodyDataHnd = inBodyArrayData.inputValue( &status );
MFnPluginData dataFn(bodyDataHnd.data());
//Get naiad body from datatype
naiadBodyData * bodyData = (naiadBodyData*)dataFn.data( &status );
if ( bodyData && bodyData->nBody() )
{
//Add body to writer
try{
Nb::String channels("*.*");
writer->write(bodyData->nBody(),channels);
}
catch(std::exception& e) {
std::cerr << "NBuddyEMPSaverNode::compute() " << e.what() << std::endl;
}
}
else
std::cerr << "NBuddyEMPSaverNode::compute() :: No body in input " << inBodyArrayData.elementIndex() << std::endl;
//Next body in the input multi
inBodyArrayData.next();
}
}
try{
writer->close();
// Get rid of the writer object
delete writer;
}
catch(std::exception& e) {
std::cerr << "NBuddyEMPSaverNode::compute() " << e.what() << std::endl;
}
//Set the output to be clean indicating that we have saved out the file
MDataHandle outTriggerHnd = data.outputValue( _outTrigger, &status );
outTriggerHnd.set(true);
data.setClean( plug );
}
return status;
}
示例10: 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;
}
示例11: compute
MStatus PtexColorNode::compute(const MPlug& plug, MDataBlock& block)
{
if( ( plug != aOutColor ) && ( plug.parent() != aOutColor ) )
{
return MS::kUnknownParameter;
}
if ( m_ptex_cache == NULL )
{
m_ptex_cache = PtexCache::create( 0, 1024 * 1024 );
}
if ( m_ptex_cache && m_ptex_texture == 0 )
{
MDataHandle fileNameHnd = block.inputValue( aPtexFileName );
MDataHandle filterTypeHnd = block.inputValue( aPtexFilterType );
MString fileNameStr = fileNameHnd.asString();
int filterTypeValue = filterTypeHnd.asInt();
const float &filterSize = block.inputValue( aPtexFilterSize ).asFloat();
if ( fileNameStr.length() )
{
Ptex::String error;
m_ptex_texture = m_ptex_cache->get( fileNameStr.asChar(), error );
}
if ( m_ptex_texture == 0 )
{
MDataHandle outColorHandle = block.outputValue( aOutColor );
MFloatVector& outColor = outColorHandle.asFloatVector();
outColor.x = 1.0f;
outColor.y = 0.0f;
outColor.z = 1.0f;
return MS::kSuccess;
}
m_ptex_num_channels = m_ptex_texture->numChannels();
PtexFilter::FilterType ptexFilterType = PtexFilter::f_point;
switch ( filterTypeValue )
{
case 0: ptexFilterType = PtexFilter::f_point; break;
case 1: ptexFilterType = PtexFilter::f_bilinear; break;
case 2: ptexFilterType = PtexFilter::f_box; break;
case 3: ptexFilterType = PtexFilter::f_gaussian; break;
case 4: ptexFilterType = PtexFilter::f_bicubic; break;
case 5: ptexFilterType = PtexFilter::f_bspline; break;
case 6: ptexFilterType = PtexFilter::f_catmullrom; break;
case 7: ptexFilterType = PtexFilter::f_mitchell; break;
}
PtexFilter::Options opts( ptexFilterType, 0, filterSize );
m_ptex_filter = PtexFilter::getFilter( m_ptex_texture, opts );
}
const float2 &uv = block.inputValue( aUVPos ).asFloat2();
const float2 &duv = block.inputValue( aUVSize ).asFloat2();
int f = (int)uv[ 0 ];
float u = uv[ 0 ] - (float)f;
float v = uv[ 1 ];
float result[4];
m_critical_section.lock();
m_ptex_filter->eval( result, 0, m_ptex_num_channels, f, u, v, duv[ 0 ], 0, 0, duv[ 1 ] );
m_critical_section.unlock();
// set ouput color attribute
MFloatVector resultColor( result[ 0 ], result[ 1 ], result[ 2 ] );
MDataHandle outColorHandle = block.outputValue( aOutColor );
MFloatVector& outColor = outColorHandle.asFloatVector();
outColor = resultColor;
outColorHandle.setClean();
return MS::kSuccess;
}
示例12: deform
MStatus puttyNode::deform( MDataBlock& block, MItGeometry& iter, const MMatrix& worldMatrix, unsigned int multiIndex)
{
// MGlobal::displayInfo("deform");
MStatus status = MS::kSuccess;
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// get inputs
//
// get the node ready flag
MDataHandle dh = block.inputValue(aScriptSourced,&status);
SYS_ERROR_CHECK(status, "Error getting aScriptSourced data handle\n");
bool scriptSourced = dh.asBool();
if (!scriptSourced)
return MS::kSuccess;
dh = block.inputValue(aNodeReady,&status);
SYS_ERROR_CHECK(status, "Error getting node ready data handle\n");
bool nodeReady = dh.asBool();
// if it's not ready, don't do anything
if (!nodeReady)
return MS::kSuccess;
dh = block.inputValue(aDefSpace,&status);
SYS_ERROR_CHECK(status, "Error getting defSpace data handle\n");
short defSpace = dh.asShort();
dh = block.inputValue(aDefWeights,&status);
SYS_ERROR_CHECK(status, "Error getting defWeights data handle\n");
short defWeights = dh.asShort();
dh = block.inputValue(aDefEnvelope,&status);
SYS_ERROR_CHECK(status, "Error getting defEnvelope data handle\n");
short defEnvelope = dh.asShort();
// get the command
dh = block.inputValue(aCmdBaseName,&status);
SYS_ERROR_CHECK(status, "Error getting aCmdBaseName handle\n");
MString script = dh.asString();
/* if (script == "")
{
status = MS::kFailure;
USER_ERROR_CHECK(status, "no script provided!\n");
}
*/
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// build mel cmd string
//
// check if it's a valid cmd
// get the envelope
//
double env = 1;
if (defEnvelope == MSD_ENVELOPE_AUTO)
{
dh = block.inputValue(envelope,&status);
SYS_ERROR_CHECK(status, "Error getting envelope data handle\n");
env = double(dh.asFloat());
// early stop 'cause there is nothing more to do
if (env == 0.0)
return MS::kSuccess;
}
// get the points, transform them into the right space if needed
//
int count = iter.count();
MVectorArray points(count);
for ( ; !iter.isDone(); iter.next())
points[iter.index()] = iter.position();
if ( defSpace == MSD_SPACE_WORLD )
{
for (int i = 0;i<count;i++)
points[i] = MPoint(points[i]) * worldMatrix;
}
// get the weights
//
MDoubleArray weights;
if ( defWeights == MSD_WEIGHTS_AUTO)
{
weights.setLength(count);
for (int i = 0;i<count;i++)
weights[i] = weightValue(block,multiIndex,i);
}
//.........这里部分代码省略.........
示例13: if
MStatus puttyNode::compute( const MPlug& plug, MDataBlock& block )
{
MStatus status;
if ( plug == aNodeReady )
{
// MGlobal::displayInfo("compute");
bool result =false;
MString cmdBaseName;
// get the source flag
MDataHandle dh = block.inputValue(aSource,&status);
SYS_ERROR_CHECK(status, "Error getting source data handle\n");
bool source = dh.asBool();
// get the command
dh = block.inputValue(aScript,&status);
SYS_ERROR_CHECK(status, "Error getting reload script handle\n");
MString script = dh.asString();
if (script == "")
{
MGlobal::displayError("no script provided!\n");
}
else
{
// chech if script is sourced
dh = block.inputValue(aScriptSourced,&status);
SYS_ERROR_CHECK(status, "Error getting aScriptSourced data handle\n");
bool scriptSourced = dh.asBool();
// if it's not ready, don't do anything
if (!scriptSourced)
return MS::kSuccess;
else
{
MCommandResult melResult;
// now get the real name of the function and store it in a separate attribute
MString cmd="basenameEx \"" + script+"\"";
status = MGlobal::executeCommand(cmd,melResult);
melResult.getResult(cmdBaseName);
result = true;
MDataHandle dhCBN = block.outputValue(aCmdBaseName,&status);
SYS_ERROR_CHECK(status, "Error getting aCmdBaseName data handle\n");
dhCBN.set(cmdBaseName);
dhCBN.setClean();
// see if an interface function is present, if yes, execute it
cmd= "if(exists(\"" + cmdBaseName +".interface\")) {";
cmd+= "string $attr[] = `deleteAttr -q " +name()+"`; string $a;";
cmd+="for($a in $attr) deleteAttr (\""+name()+".\"+$a);";
cmd+= cmdBaseName +".interface(\"" +name()+"\");}";
status = MGlobal::executeCommand(cmd);
}
}
// check the current status
// set the result
MDataHandle dhNodeReady = block.outputValue(aNodeReady,&status);
SYS_ERROR_CHECK(status, "Error getting reload data handle\n");
dhNodeReady.set(result);
dhNodeReady.setClean();
return MS::kSuccess;
}
else if (plug==aScriptSourced)
{
// this part of the function sources the script
// try to source the script
// cerr << "\nsource";
MStatus status;
bool result = true;
// get the source flag
MDataHandle dh = block.inputValue(aSource,&status);
SYS_ERROR_CHECK(status, "Error getting source data handle\n");
bool source = dh.asBool();
// get the script
dh = block.inputValue(aScript,&status);
SYS_ERROR_CHECK(status, "Error getting reload script handle\n");
MString script = dh.asString();
MString cmd = "source \"" + script+"\"";
MCommandResult melResult;
status = MGlobal::executeCommand(cmd,melResult);
if (status.error())
{
MGlobal::displayError( "Error sourcing mel script, please check the function you provided is valid!");
result = false;
}
//.........这里部分代码省略.........
示例14: 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 );
//.........这里部分代码省略.........
示例15: checkHRBFHereNow
MStatus
HRBFSkinCluster::deform( MDataBlock& block,
MItGeometry& iter,
const MMatrix& m,
unsigned int multiIndex)
//
// Method: deform1
//
// Description: Deforms the point with a simple smooth skinning 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;
// get HRBF status
MDataHandle HRBFstatusData = block.inputValue(rebuildHRBF, &returnStatus);
McheckErr(returnStatus, "Error getting rebuildHRBF handle\n");
int rebuildHRBFStatusNow = HRBFstatusData.asInt();
// handle signaling to the rest of deform that HRBFs must be rebuild
bool signalRebuildHRBF = false;
signalRebuildHRBF = (rebuildHRBFStatus != rebuildHRBFStatusNow);
MMatrixArray bindTFs; // store just the bind transforms in here.
MMatrixArray boneTFs; // ALWAYS store just the bone transforms in here.
// get HRBF export status
MDataHandle exportCompositionData = block.inputValue(exportComposition, &returnStatus);
McheckErr(returnStatus, "Error getting exportComposition handle\n");
int exportCompositionStatusNow = exportCompositionData.asInt();
MDataHandle HRBFExportSamplesData = block.inputValue(exportHRBFSamples, &returnStatus);
McheckErr(returnStatus, "Error getting exportHRBFSamples handle\n");
std::string exportHRBFSamplesStatusNow = HRBFExportSamplesData.asString().asChar();
MDataHandle HRBFExportValuesData = block.inputValue(exportHRBFValues, &returnStatus);
McheckErr(returnStatus, "Error getting exportHRBFValues handle\n");
std::string exportHRBFValuesStatusNow = HRBFExportValuesData.asString().asChar();
// get skinning type
MDataHandle useDQData = block.inputValue(useDQ, &returnStatus);
McheckErr(returnStatus, "Error getting useDQ handle\n");
int useDQNow = useDQData.asInt();
// determine if we're using HRBF
MDataHandle useHRBFData = block.inputValue(useHRBF, &returnStatus);
McheckErr(returnStatus, "Error getting useHRBFData handle\n");
int useHRBFnow = useHRBFData.asInt();
// get envelope because why not
MDataHandle envData = block.inputValue(envelope, &returnStatus);
float env = envData.asFloat();
// get point in space for evaluating HRBF
MDataHandle checkHRBFAtData = block.inputValue(checkHRBFAt, &returnStatus);
McheckErr(returnStatus, "Error getting useDQ handle\n");
double* data = checkHRBFAtData.asDouble3();
// get the influence transforms
//
MArrayDataHandle transformsHandle = block.inputArrayValue( matrix ); // tell block what we want
int numTransforms = transformsHandle.elementCount();
if ( numTransforms == 0 ) { // no transforms, no problems
return MS::kSuccess;
}
MMatrixArray transforms; // fetch transform matrices -> actual joint matrices
for ( int i=0; i<numTransforms; ++i ) {
MMatrix worldTF = MFnMatrixData(transformsHandle.inputValue().data()).matrix();
transforms.append(worldTF);
boneTFs.append(worldTF);
transformsHandle.next();
}
// inclusive matrices inverse of the driving transform at time of bind
// matrices for transforming vertices to joint local space
MArrayDataHandle bindHandle = block.inputArrayValue( bindPreMatrix ); // tell block what we want
if ( bindHandle.elementCount() > 0 ) {
for ( int i=0; i<numTransforms; ++i ) {
MMatrix bind = MFnMatrixData(bindHandle.inputValue().data()).matrix();
transforms[i] = bind * transforms[i];
bindHandle.next();
if (signalRebuildHRBF) bindTFs.append(bind);
}
}
MArrayDataHandle weightListHandle = block.inputArrayValue(weightList);
if (weightListHandle.elementCount() == 0) {
// no weights - nothing to do
std::cout << "no weights!" << std::endl;
//rebuildHRBFStatus = rebuildHRBFStatusNow - 1; // HRBFs will need to rebuilt no matter what
return MS::kSuccess;
}
// print HRBF samples if requested
if (exportHRBFSamplesStatusNow != exportHRBFSamplesStatus) {
std::cout << "instructed to export HRBF samples: " << exportHRBFSamplesStatusNow.c_str() << std::endl;
exportHRBFSamplesStatus = exportHRBFSamplesStatusNow;
//.........这里部分代码省略.........