本文整理汇总了C++中MItGeometry::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ MItGeometry::reset方法的具体用法?C++ MItGeometry::reset怎么用?C++ MItGeometry::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MItGeometry
的用法示例。
在下文中一共展示了MItGeometry::reset方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: _deform_on_one_mesh
void TestDeformer::_deform_on_one_mesh(MDataBlock& data,
MItGeometry& iter,
const MMatrix& localToWorldMatrix,
unsigned int mIndex,
MObject &driver_mesh,
const MDataHandle &envelopeHandle, MArrayDataHandle &vertMapArrayData, MPointArray &tempOutputPts)
{
MStatus status;
float env = envelopeHandle.asFloat();
// use driver_meshVertIter to walk through the vertex of the current driver mesh
MItMeshVertex driver_meshVertIter( driver_mesh, &status );
CHECK_MSTATUS( status );
int i = 0;
iter.reset();
while( !iter.isDone(&status) )
{
CHECK_MSTATUS( status );
// get the weight
float weight = weightValue( data, mIndex, iter.index() ); //painted weight
float ww = weight * env;
if ( fabs(ww) > FLT_EPSILON )//if ( ww != 0 )
{
__debug("%s(), vertMapArrayData.elementCount()=%d, iter.index()=%d",
__FUNCTION__, vertMapArrayData.elementCount(), iter.index());
// get index_mapped to which the currrent vertex vI is mapped
CHECK_MSTATUS(vertMapArrayData.jumpToElement(iter.index()));
int index_mapped = vertMapArrayData.inputValue(&status).asInt();
CHECK_MSTATUS( status );
if( index_mapped >= 0 )
{
__debug("index_mapped=%d", index_mapped);
int prevInt;
CHECK_MSTATUS( driver_meshVertIter.setIndex(index_mapped, prevInt) );
// vertex wrold position on driver mesh
MPoint mappedPt = driver_meshVertIter.position( MSpace::kWorld, &status );
CHECK_MSTATUS( status );
// vertex wrold position on driven mesh
MPoint iterPt = iter.position(MSpace::kObject, &status) * localToWorldMatrix;
CHECK_MSTATUS( status );
// use ww to interpolate between mappedPt and iterPt
MPoint pt = iterPt + ((mappedPt - iterPt) * ww );
pt = pt * localToWorldMatrix.inverse();
/// put the deform points to tempOutputPts
tempOutputPts[i] += pt;
}
}//if
CHECK_MSTATUS(iter.next());
++i;
}//while
}
示例3: initVertMapping
void TestDeformer::initVertMapping(MDataBlock& data,
MItGeometry& iter,
const MMatrix& localToWorldMatrix,
unsigned int mIndex)
{
MStatus status;
MArrayDataHandle vertMapOutArrayData = data.outputArrayValue( vert_map, &status );
CHECK_MSTATUS( status );
// use vertMapOutArrayBuilder to modify vertMapOutArrayData
iter.reset();
int count = iter.count();
MArrayDataBuilder vertMapOutArrayBuilder( vert_map, count, &status );
CHECK_MSTATUS( status );
MPointArray allPts;// world vertex position of the driven mesh
allPts.clear();
// walk through the driven mesh
/// copy MItGeometry's vertex to vertMapOutArrayData
int i = 0;
while( !iter.isDone(&status) )
{
CHECK_MSTATUS( status );
MDataHandle initIndexDataHnd = vertMapOutArrayBuilder.addElement( i, &status );
CHECK_MSTATUS( status );
int negIndex = -1;
initIndexDataHnd.setInt( negIndex );
initIndexDataHnd.setClean();
// append a vertex position(world coordination) to allPts
CHECK_MSTATUS(allPts.append( iter.position() * localToWorldMatrix ));
i = i+1;
iter.next();
}
CHECK_MSTATUS(vertMapOutArrayData.set( vertMapOutArrayBuilder ));
/// Append more vertex from each driver mesh to vertMapOutArrayData
MArrayDataHandle meshAttrHandle = data.inputArrayValue( driver_mesh, &status );
CHECK_MSTATUS( status );
int numMeshes = meshAttrHandle.elementCount();
__debug("%s(), numMeshes=%d", __FUNCTION__, numMeshes);
CHECK_MSTATUS(meshAttrHandle.jumpToElement(0));
for( int meshIndex=0; meshIndex < numMeshes; ++meshIndex )
{
__debug("%s(), meshIndex=%d", __FUNCTION__, meshIndex);
MDataHandle currentMesh = meshAttrHandle.inputValue(&status);
CHECK_MSTATUS(status);
MObject meshMobj = currentMesh.asMesh();
__debug("%s(), meshMobj.apiTypeStr()=%s", __FUNCTION__, meshMobj.apiTypeStr());
__debugMeshInfo(__FUNCTION__, meshMobj);
{
_initVertMapping_on_one_mesh(meshMobj, vertMapOutArrayBuilder, allPts);// Note: vertMapOutArrayBuilder is updated in this function!
//CHECK_MSTATUS(vertMapOutArrayData.set( vertMapOutArrayBuilder ));
}
if( !meshAttrHandle.next() )
{
break;
}
}// for (mesh
CHECK_MSTATUS(vertMapOutArrayData.set( vertMapOutArrayBuilder ));
}
示例4: deform
MStatus TestDeformer::deform(MDataBlock& data,
MItGeometry& iter,
const MMatrix& localToWorldMatrix,
unsigned int mIndex)
{
MStatus status;
// get the current node state
short initialized_mapping = data.inputValue( initialized_data, &status).asShort();
CHECK_MSTATUS(status);
__debug("%s(), initialized_mapping=%d, mIndex=%d", __FUNCTION__, initialized_mapping, mIndex);
if( initialized_mapping == 1 )
{
initVertMapping(data, iter, localToWorldMatrix, mIndex);
// set initialized_data to 2 automatically. User don't have to set it manully.
MObject tObj = thisMObject();
MPlug setInitMode = MPlug( tObj, initialized_data );
setInitMode.setShort( 2 );
// and sync initialized_mapping from initialized_data
// so, the code section:
// if (initialized_mapping == 2)
// {
// ...
// }
// will be executed when this deform() function is called next time.
initialized_mapping = data.inputValue( initialized_data, &status ).asShort();
CHECK_MSTATUS(status);
}
if( initialized_mapping == 2 )
{
envelope = MPxDeformerNode::envelope;
MDataHandle envelopeHandle = data.inputValue( envelope, &status );
CHECK_MSTATUS( status );
MArrayDataHandle vertMapArrayData = data.inputArrayValue( vert_map, &status );
CHECK_MSTATUS( status );
MArrayDataHandle meshAttrHandle = data.inputArrayValue( driver_mesh, &status );
CHECK_MSTATUS( status );
/// 1. init tempOutputPts to zero points
MPointArray tempOutputPts;
iter.reset();
while( !iter.isDone(&status) )
{
CHECK_MSTATUS(tempOutputPts.append(MPoint(0, 0, 0)));
CHECK_MSTATUS(iter.next());
}
assert(tempOutputPts.length() == iter.count());
/// 2. set tempOutputPts to deform values which comes from each driver mesh
iter.reset();
int numMeshes = meshAttrHandle.elementCount();
__debug("%s(), numMeshes=%d", __FUNCTION__, numMeshes);
CHECK_MSTATUS(meshAttrHandle.jumpToElement(0));
// for each driver mesh
for( int count=0; count < numMeshes; ++count )
{
__debug("%s(), count=%d", __FUNCTION__, count);
// for one driver mesh: currentMesh
MDataHandle currentMesh = meshAttrHandle.inputValue(&status);
CHECK_MSTATUS( status );
MObject meshMobj = currentMesh.asMesh();
__debugMeshInfo(__FUNCTION__, meshMobj);
// accumulate deform values of currentMesh to tempOutputPts
_deform_on_one_mesh(data, iter, localToWorldMatrix, mIndex,
meshMobj,
envelopeHandle, vertMapArrayData, tempOutputPts );
if( !meshAttrHandle.next() )
{
break;
}
}// for each driver mesh
/// 3. add deform value to this geometry(driven mesh)
int i = 0;
iter.reset();
while( !iter.isDone(&status) )
{
MPoint p = iter.position(MSpace::kObject, &status);
CHECK_MSTATUS(status);
// add the deform value to this vertex
CHECK_MSTATUS(iter.setPosition( p + tempOutputPts[i]/numMeshes ));
CHECK_MSTATUS(iter.next());
++i;
//.........这里部分代码省略.........
示例5: deform
MStatus snapDeformer::deform(MDataBlock &data, MItGeometry &iter, const MMatrix &mat, unsigned int multiIndex) {
MStatus stat;
//lets see if we need to do anything
MDataHandle DataHandle = data.inputValue(envelope, &stat);
float env = DataHandle.asFloat();
if (env == 0)
return stat;
DataHandle = data.inputValue(weight, &stat);
const float weight = DataHandle.asFloat();
if (weight == 0)
return stat;
env = (env*weight);
//space target
DataHandle = data.inputValue(space, &stat);
int SpaceInt = DataHandle.asInt();
//space source
DataHandle = data.inputValue(spaceSource, &stat);
int SpaceSourceInt = DataHandle.asInt();
//pointlist
MArrayDataHandle pointArrayHandle = data.inputArrayValue(pointList);
//snapMesh
MFnMesh SnapMesh;
DataHandle = data.inputValue(snapMesh, &stat);
if (!stat)
return Err(stat,"Can't get mesh to snap to");
MObject SnapMeshObj = DataHandle.asMesh();
SnapMesh.setObject(SnapMeshObj);
MPointArray snapPoints;
if (SpaceSourceInt==0)
SnapMesh.getPoints(snapPoints, MSpace::kWorld);
else
SnapMesh.getPoints(snapPoints, MSpace::kObject);
iter.reset();
for ( ; !iter.isDone(); iter.next()) {
//check for painted weights
float currEnv = env * weightValue(data, multiIndex, iter.index());
//get point to snap to
unsigned int index;
stat = pointArrayHandle.jumpToElement(iter.index());
if (!stat)
index = 0;
else {
DataHandle = pointArrayHandle.outputValue();
index = DataHandle.asInt();
}
if (index != -1) {
//calc point location
MPoint currPoint;
if (snapPoints.length() > index)
currPoint = snapPoints[index];
if (SpaceInt == 0)
currPoint *= mat.inverse();
if (currEnv !=1)
{
MPoint p = (currPoint- iter.position());
currPoint = iter.position() + (p*currEnv);
}
//set point location
iter.setPosition(currPoint);
}
}
return stat;
}
示例6: deform
MStatus AlembicCurvesDeformNode::deform(MDataBlock &dataBlock,
MItGeometry &iter,
const MMatrix &localToWorld,
unsigned int geomIndex)
{
// get the envelope data
float env = dataBlock.inputValue(envelope).asFloat();
if (env == 0.0f) { // deformer turned off
return MStatus::kSuccess;
}
// update the frame number to be imported
double inputTime =
dataBlock.inputValue(mTimeAttr).asTime().as(MTime::kSeconds);
MString &fileName = dataBlock.inputValue(mFileNameAttr).asString();
MString &identifier = dataBlock.inputValue(mIdentifierAttr).asString();
// check if we have the file
if (fileName != mFileName || identifier != mIdentifier) {
mSchema.reset();
if (fileName != mFileName) {
delRefArchive(mFileName);
mFileName = fileName;
addRefArchive(mFileName);
}
mIdentifier = identifier;
// get the object from the archive
Abc::IObject iObj = getObjectFromArchive(mFileName, identifier);
if (!iObj.valid()) {
MGlobal::displayWarning("[ExocortexAlembic] Identifier '" + identifier +
"' not found in archive '" + mFileName + "'.");
return MStatus::kFailure;
}
AbcG::ICurves obj(iObj, Abc::kWrapExisting);
if (!obj.valid()) {
MGlobal::displayWarning("[ExocortexAlembic] Identifier '" + identifier +
"' in archive '" + mFileName +
"' is not a Curves.");
return MStatus::kFailure;
}
mSchema = obj.getSchema();
}
if (!mSchema.valid()) {
return MStatus::kFailure;
}
{
ESS_PROFILE_SCOPE("AlembicCurvesDeformNode::deform readProps");
Alembic::Abc::ICompoundProperty arbProp = mSchema.getArbGeomParams();
Alembic::Abc::ICompoundProperty userProp = mSchema.getUserProperties();
readProps(inputTime, arbProp, dataBlock, thisMObject());
readProps(inputTime, userProp, dataBlock, thisMObject());
// Set all plugs as clean
// Even if one of them failed to get set,
// trying again in this frame isn't going to help
for (unsigned int i = 0; i < mGeomParamPlugs.length(); i++) {
dataBlock.outputValue(mGeomParamPlugs[i]).setClean();
}
for (unsigned int i = 0; i < mUserAttrPlugs.length(); i++) {
dataBlock.outputValue(mUserAttrPlugs[i]).setClean();
}
}
// get the sample
SampleInfo sampleInfo = getSampleInfo(inputTime, mSchema.getTimeSampling(),
mSchema.getNumSamples());
// check if we have to do this at all
if (mLastSampleInfo.floorIndex == sampleInfo.floorIndex &&
mLastSampleInfo.ceilIndex == sampleInfo.ceilIndex) {
return MStatus::kSuccess;
}
mLastSampleInfo = sampleInfo;
// access the camera values
AbcG::ICurvesSchema::Sample sample;
AbcG::ICurvesSchema::Sample sample2;
mSchema.get(sample, sampleInfo.floorIndex);
if (sampleInfo.alpha != 0.0) {
mSchema.get(sample2, sampleInfo.ceilIndex);
}
Abc::P3fArraySamplePtr samplePos = sample.getPositions();
Abc::P3fArraySamplePtr samplePos2;
if (sampleInfo.alpha != 0.0) {
samplePos2 = sample2.getPositions();
}
// iteration should not be necessary. the iteration is only
// required if the same mesh is attached to the same deformer
// several times
float blend = (float)sampleInfo.alpha;
float iblend = 1.0f - blend;
unsigned int index = 0;
for (iter.reset(); !iter.isDone(); iter.next()) {
//.........这里部分代码省略.........
示例7: deform
//.........这里部分代码省略.........
currPlug.setValue(geometryType);
SYS_ERROR_CHECK(status, "error setting aCurrGeometryType value\n");
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// execute the mel script
//
MString melCmd = script+"(\"" +name()+"\","+count+")";
MCommandResult melResult;
status = MGlobal::executeCommand(melCmd,melResult);
// if the command did not work, then try to resource the script
// (might have been that we were in a fresh scene and nothing was ready yet
if (status != MS::kSuccess)
{
dh = block.inputValue(aScript,&status);
SYS_ERROR_CHECK(status, "Error getting aCmdBaseName handle\n");
MString scriptFile = dh.asString();
// try to source the script
MString cmd = "source \"" + scriptFile+"\"";
MCommandResult melResult;
status = MGlobal::executeCommand(cmd,melResult);
// if successfull, retry the command
if (!status.error())
{
status = MGlobal::executeCommand(melCmd,melResult);
}
}
USER_ERROR_CHECK(status, "Error executing mel command, please check the function you provided is valid, error free and has the appropriate parameters!");
// check the result type
if ((melResult.resultType()) != (MCommandResult::kDoubleArray))
{
USER_ERROR_CHECK(MS::kFailure, "result of mel command has wrong type, should be doubleArray (which will be interpreted as vectorArray)!");
}
// get the result as a double array
MDoubleArray newP;
status = melResult.getResult(newP);
USER_ERROR_CHECK(status, "Error getting result of mel command!");
int newCount = newP.length()/3;
// size check
if (newCount != count)
{
USER_ERROR_CHECK(MS::kFailure, "the size of the result does not match the size of the input!");
}
// convert the double array into a vector array
MPointArray newPoints(newCount);
for(int i=0;i<newCount;i++)
newPoints[i]=MPoint(newP[i*3],newP[i*3+1],newP[i*3+2]);
/////////////////////////////////////////////////////////////////////////////////////////////////
//
// interprete and apply the result
//
// do the envelope and weights
if ((defEnvelope == MSD_ENVELOPE_AUTO)||((defWeights == MSD_WEIGHTS_AUTO)))
{
MDoubleArray envPP(count, env);
if (defWeights == MSD_WEIGHTS_AUTO)
{
for (int i = 0;i<count;i++)
envPP[i] *= weights[i];
}
// linear interpolation between old and new points
for (int i = 0;i<count;i++)
newPoints[i] = (points[i] * (1-envPP[i])) + (newPoints[i] * envPP[i]);
}
// retransform the result if it was in world space
if ( defSpace == MSD_SPACE_WORLD )
{
MMatrix worldMatrixInv = worldMatrix.inverse();
for (int i = 0;i<count;i++)
newPoints[i] *= worldMatrixInv;
}
// set the points
iter.reset();
for ( ; !iter.isDone(); iter.next())
iter.setPosition(newPoints[iter.index()]);
return status;
}
示例8: checkHRBFHereNow
//.........这里部分代码省略.........
std::cout << "instructed to export HRBF samples: " << exportHRBFSamplesStatusNow.c_str() << std::endl;
exportHRBFSamplesStatus = exportHRBFSamplesStatusNow;
// TODO: handle exporting HRBFs to the text file format
hrbfMan->debugSamplesToConsole(exportHRBFSamplesStatus);
}
// print HRBF values if requested
if (exportHRBFValuesStatusNow != exportHRBFValuesStatus) {
std::cout << "instructed to export HRBF values: " << exportHRBFValuesStatusNow.c_str() << std::endl;
exportHRBFValuesStatus = exportHRBFValuesStatusNow;
// TODO: handle exporting HRBFs to the text file format
hrbfMan->debugValuesToConsole(exportHRBFValuesStatus);
}
// print HRBF composition if requested
if (exportCompositionStatusNow != exportCompositionStatus) {
std::cout << "instructed to export HRBF composition." << std::endl;
exportCompositionStatus = exportCompositionStatusNow;
// TODO: handle exporting HRBFs to the text file format
hrbfMan->debugCompositionToConsole(boneTFs, numTransforms);
}
// check the HRBF value if the new point is significantly different
MPoint checkHRBFHereNow(data[0], data[1], data[2]);
if ((checkHRBFHereNow - checkHRBFHere).length() > 0.0001) {
if (hrbfMan->m_HRBFs.size() == numTransforms) {
std::cout << "checking HRBF at x:" << data[0] << " y: " << data[1] << " z: " << data[2] << std::endl;
hrbfMan->compose(boneTFs);
float val = 0.0f;
float dx = 0.0f;
float dy = 0.0f;
float dz = 0.0f;
float grad = 0.0f;
hrbfMan->mf_vals->trilinear(data[0], data[1], data[2], val);
hrbfMan->mf_gradX->trilinear(data[0], data[1], data[2], dx);
hrbfMan->mf_gradY->trilinear(data[0], data[1], data[2], dy);
hrbfMan->mf_gradZ->trilinear(data[0], data[1], data[2], dz);
hrbfMan->mf_gradMag->trilinear(data[0], data[1], data[2], grad);
std::cout << "val: " << val << " dx: " << dx << " dy: " << dy << " dz: " << dz << " grad: " << grad << std::endl;
checkHRBFHere = checkHRBFHereNow;
}
}
// rebuild HRBFs if needed
if (signalRebuildHRBF) {
std::cout << "instructed to rebuild HRBFs" << std::endl;
rebuildHRBFStatus = rebuildHRBFStatusNow;
MArrayDataHandle parentIDCsHandle = block.inputArrayValue(jointParentIdcs); // tell block what we want
std::vector<int> jointParentIndices(numTransforms);
if (parentIDCsHandle.elementCount() > 0) {
for (int i = 0; i<numTransforms; ++i) {
jointParentIndices[i] = parentIDCsHandle.inputValue().asInt();
parentIDCsHandle.next();
}
}
MArrayDataHandle jointNamesHandle = block.inputArrayValue(jointNames); // tell block what we want
std::vector<std::string> jointNames(numTransforms);
if (jointNamesHandle.elementCount() > 0) {
for (int i = 0; i<numTransforms; ++i) {
jointNames[i] = jointNamesHandle.inputValue().asString().asChar();
jointNamesHandle.next();
}
}
// debug
//std::cout << "got joint hierarchy info! it's:" << std::endl;
//for (int i = 0; i < numTransforms; ++i) {
// std::cout << i << ": " << jointNames[i].c_str() << " : " << jointParentIndices[i] << std::endl;
//}
std::cout << "rebuilding HRBFs... " << std::endl;
hrbfMan->buildHRBFs(jointParentIndices, jointNames, bindTFs, boneTFs,
weightListHandle, iter, weights);
std::cout << "done rebuilding!" << std::endl;
weightListHandle.jumpToElement(0); // reset this, it's an iterator. trust me.
iter.reset(); // reset this iterator so we can go do normal skinning
}
// perform traditional skinning
if (useDQNow != 0) {
returnStatus = skinDQ(transforms, numTransforms, weightListHandle, iter);
}
else {
returnStatus = skinLB(transforms, numTransforms, weightListHandle, iter);
}
// do HRBF corrections
if (useHRBFnow != 0) {
if (hrbfMan->m_HRBFs.size() == numTransforms) {
hrbfMan->compose(boneTFs);
iter.reset();
hrbfMan->correct(iter);
}
}
return returnStatus;
}