本文整理汇总了C++中MDataBlock::setClean方法的典型用法代码示例。如果您正苦于以下问题:C++ MDataBlock::setClean方法的具体用法?C++ MDataBlock::setClean怎么用?C++ MDataBlock::setClean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDataBlock
的用法示例。
在下文中一共展示了MDataBlock::setClean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute
MStatus fullLoft::compute( const MPlug& plug, MDataBlock& data )
{
MStatus stat;
if ( plug == outputSurface ) // loft inputCurves into surface
{
MArrayDataHandle inputArrayData = data.inputArrayValue( inputCurve,
&stat );
PERRORfail("fullLoft::compute getting input array data");
MDataHandle surfHandle = data.outputValue( fullLoft::outputSurface );
PERRORfail("fullLoft::compute getting output data handle");
MFnNurbsSurfaceData dataCreator;
MObject newSurfData = dataCreator.create( &stat );
PERRORfail("fullLoft::compute creating new nurbs surface data block");
/* MObject newSurf = */ loft(inputArrayData, newSurfData, stat );
// No error message is needed - fullLoft::loft will output one
if (!stat)
return stat;
// newSurf is the new surface object, but it has been packed
// into the datablock we created for it, and the data block
// is what we must put onto the plug.
stat = surfHandle.set( newSurfData );
PERRORfail("fullLoft::compute setting surface handle");
stat = data.setClean( plug );
PERRORfail("fullLoft::compute cleaning outputSurface plug");
}
else
{
return MS::kUnknownParameter;
}
return MS::kSuccess;
}
示例2: compute
MStatus octreeVizNode::compute( const MPlug& plug, MDataBlock& data )
{
MStatus status;
if(plug == aoutput) {
double time = data.inputValue(acurrenttime).asTime().value();
int frame_lo = time + 0.005;
if(frame_lo < 3) frame_lo = 3;
if(frame_lo >60) frame_lo = 60;
MString sname = data.inputValue(aHDRName).asString();
sname = "/Users/jianzhang/Documents/maya/projects/default/data/untitled";
char filename[512];
sprintf( filename, "%s.%d.pmap", sname.asChar(), frame_lo );
sname = filename;
MGlobal::displayInfo(sname);
if(sname != m_gridname) {
m_gridname = sname;
if(m_pTex) delete m_pTex;
m_pTex = new Z3DTexture;
if(m_pTex->load(m_gridname.asChar())) {
zDisplayFloat(m_pTex->getNumGrid());
zDisplayFloat(m_pTex->getNumVoxel());
zDisplayFloat(m_pTex->getMaxLevel());
m_pTex->setDraw();
}
}
data.setClean(plug);
}
return MS::kUnknownParameter;
}
示例3: 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;
}
示例4: computeConstraint
//standard attributes
void sixdofConstraintNode::computeConstraint(const MPlug& plug, MDataBlock& data)
{
// std::cout << "sixdofConstraintNode::computeConstraint" << std::endl;
MObject thisObject(thisMObject());
MPlug plgRigidBodyA(thisObject, ia_rigidBodyA);
MPlug plgRigidBodyB(thisObject, ia_rigidBodyB);
MObject update;
//force evaluation of the rigidBody
plgRigidBodyA.getValue(update);
plgRigidBodyB.getValue(update);
rigid_body_t::pointer rigid_bodyA;
if(plgRigidBodyA.isConnected()) {
MPlugArray connections;
plgRigidBodyA.connectedTo(connections, true, true);
if(connections.length() != 0) {
MFnDependencyNode fnNodeA(connections[0].node());
if(fnNodeA.typeId() == boingRBNode::typeId) {
boingRBNode *pRigidBodyNodeA = static_cast<boingRBNode*>(fnNodeA.userNode());
rigid_bodyA = pRigidBodyNodeA->rigid_body();
} else {
std::cout << "sixdofConstraintNode connected to a non-rigidbody node!" << std::endl;
}
}
}
rigid_body_t::pointer rigid_bodyB;
if(plgRigidBodyB.isConnected()) {
MPlugArray connections;
plgRigidBodyB.connectedTo(connections, true, true);
if(connections.length() != 0) {
MFnDependencyNode fnNodeB(connections[0].node());
if(fnNodeB.typeId() == boingRBNode::typeId) {
boingRBNode *pRigidBodyNodeB = static_cast<boingRBNode*>(fnNodeB.userNode());
rigid_bodyB = pRigidBodyNodeB->rigid_body();
} else {
std::cout << "sixdofConstraintNode connected to a non-rigidbody node!" << std::endl;
}
}
}
vec3f pivInA, pivInB;
if((rigid_bodyA != NULL) && (rigid_bodyB != NULL))
{
constraint_t::pointer constraint = static_cast<constraint_t::pointer>(m_constraint);
solver_t::remove_constraint(constraint);
float3& mPivInA = data.inputValue(ia_pivotInA).asFloat3();
float3& mPivInB = data.inputValue(ia_pivotInB).asFloat3();
for(int i = 0; i < 3; i++)
{
pivInA[i] = (float)mPivInA[i];
pivInB[i] = (float)mPivInB[i];
}
float3& mRotInA = data.inputValue(ia_rotationInA).asFloat3();
MEulerRotation meulerA(deg2rad(mRotInA[0]), deg2rad(mRotInA[1]), deg2rad(mRotInA[2]));
MQuaternion mquatA = meulerA.asQuaternion();
quatf rotA((float)mquatA.w, (float)mquatA.x, (float)mquatA.y, (float)mquatA.z);
float3& mRotInB = data.inputValue(ia_rotationInB).asFloat3();
MEulerRotation meulerB(deg2rad(mRotInB[0]), deg2rad(mRotInB[1]), deg2rad(mRotInB[2]));
MQuaternion mquatB = meulerB.asQuaternion();
quatf rotB((float)mquatB.w, (float)mquatB.x, (float)mquatB.y, (float)mquatB.z);
m_constraint = solver_t::create_sixdof_constraint(rigid_bodyA, pivInA, rotA, rigid_bodyB, pivInB, rotB);
constraint = static_cast<constraint_t::pointer>(m_constraint);
solver_t::add_constraint(constraint, data.inputValue(ia_disableCollide).asBool());
}
else if(rigid_bodyA != NULL)
{
//not connected to a rigid body, put a default one
constraint_t::pointer constraint = static_cast<constraint_t::pointer>(m_constraint);
solver_t::remove_constraint(constraint);
float3& mPivInA = data.inputValue(ia_pivotInA).asFloat3();
for(int i = 0; i < 3; i++)
{
pivInA[i] = (float)mPivInA[i];
}
float3& mRotInA = data.inputValue(ia_rotationInA).asFloat3();
MEulerRotation meuler(deg2rad(mRotInA[0]), deg2rad(mRotInA[1]), deg2rad(mRotInA[2]));
MQuaternion mquat = meuler.asQuaternion();
quatf rotA((float)mquat.w, (float)mquat.x, (float)mquat.y, (float)mquat.z);
m_constraint = solver_t::create_sixdof_constraint(rigid_bodyA, pivInA, rotA);
constraint = static_cast<constraint_t::pointer>(m_constraint);
solver_t::add_constraint(constraint, data.inputValue(ia_disableCollide).asBool());
}
if (m_constraint)
{
m_constraint->get_local_frameA(m_PivInA, m_RotInA);
m_constraint->get_local_frameB(m_PivInB, m_RotInB);
}
data.outputValue(ca_constraint).set(true);
data.setClean(plug);
}
示例5: reComputeConstraint
//.........这里部分代码省略.........
solver_t::remove_constraint(constraint);
m_constraint = solver_t::create_sixdof_constraint(rigid_bodyA, m_PivInA, m_RotInA, rigid_bodyB, m_PivInB, m_RotInB);
constraint = static_cast<constraint_t::pointer>(m_constraint);
solver_t::add_constraint(constraint, m_disableCollision);
}
else if(rigid_bodyA != NULL)
{
//not connected to a rigid body, put a default one
constraint_t::pointer constraint = static_cast<constraint_t::pointer>(m_constraint);
bt_sixdof_constraint_t* sixdof_impl = dynamic_cast<bt_sixdof_constraint_t*>(constraint->pubImpl());
rigid_bodyA->remove_constraint(sixdof_impl);
solver_t::remove_constraint(constraint);
m_constraint = solver_t::create_sixdof_constraint(rigid_bodyA, m_PivInB, m_RotInB);
constraint = static_cast<constraint_t::pointer>(m_constraint);
solver_t::add_constraint(constraint, m_disableCollision);
}else if(rigid_bodyB != NULL)
{
//not connected to a rigid body, put a default one
constraint_t::pointer constraint = static_cast<constraint_t::pointer>(m_constraint);
bt_sixdof_constraint_t* sixdof_impl = dynamic_cast<bt_sixdof_constraint_t*>(constraint->pubImpl());
rigid_bodyB->remove_constraint(sixdof_impl);
solver_t::remove_constraint(constraint);
m_constraint = solver_t::create_sixdof_constraint(rigid_bodyB, m_PivInA, m_RotInA);
constraint = static_cast<constraint_t::pointer>(m_constraint);
solver_t::add_constraint(constraint, m_disableCollision);
}
float val = 0.f;
MPlug(thisObject, sixdofConstraintNode::ia_damping).getValue(val);
m_constraint->set_damping(val);
MPlug(thisObject, sixdofConstraintNode::ia_breakThreshold).getValue(val);
m_constraint->set_breakThreshold(val);
vec3f lowLin, uppLin, lowAng, uppAng;
for (int i=0;i<3;i++)
{
lowLin[i] = 0.f;
uppLin[i] = 0.f;
lowAng[i] = 0.f;
uppAng[i] = 0.f;
}
{
MPlug ll(thisObject, sixdofConstraintNode::ia_lowerLinLimit);
if (ll.isCompound())
{
for (int i=0;i<3;i++)
{
ll.child(i).getValue(lowLin[i]);
}
}
}
{
MPlug ul(thisObject, sixdofConstraintNode::ia_upperLinLimit);
if (ul.isCompound())
{
for (int i=0;i<3;i++)
{
ul.child(i).getValue(uppLin[i]);
}
}
}
{
MPlug all(thisObject, sixdofConstraintNode::ia_lowerAngLimit);
if (all.isCompound())
{
for (int i=0;i<3;i++)
{
float f;
all.child(i).getValue(f);
lowAng[i] = deg2rad(f);
}
}
}
{
MPlug aul(thisObject, sixdofConstraintNode::ia_upperAngLimit);
if (aul.isCompound())
{
for (int i=0;i<3;i++)
{
float f;
aul.child(i).getValue(f);
uppAng[i] = deg2rad(f);
}
}
}
m_constraint->set_LinLimit(lowLin, uppLin);
m_constraint->set_AngLimit(lowAng, uppAng);
data1.outputValue(ca_constraint).set(true);
data1.setClean(plug);
}
示例6: compute
MStatus HesMeshNode::compute( const MPlug& plug, MDataBlock& data )
{
MStatus stat;
MPlug pnames(thisMObject(), ameshname);
const unsigned numMeshes = pnames.numElements();
MString cacheName = data.inputValue( input ).asString();
std::string substitutedCacheName(cacheName.asChar());
EnvVar::replace(substitutedCacheName);
MArrayDataHandle meshNameArray = data.inputArrayValue( ameshname );
MArrayDataHandle meshArry = data.outputArrayValue(outMesh, &stat);
bool hesStat = false;
if( plug.array() == outMesh ) {
const unsigned idx = plug.logicalIndex();
if(BaseUtil::IsImporting)
hesStat = true;
else {
if(idx == 0)
AHelper::Info<std::string>(" hes mesh open file ", substitutedCacheName );
hesStat = BaseUtil::OpenHes(substitutedCacheName, HDocument::oReadOnly);
}
if(!hesStat) {
AHelper::Info<std::string >("hes mesh cannot open file ", substitutedCacheName);
return MS::kFailure;
}
meshNameArray.jumpToElement(idx);
const MString meshName = meshNameArray.inputValue().asString();
if(!BaseUtil::HesDoc->find(meshName.asChar())) {
AHelper::Info<MString>(" hes cannot find mesh ", meshName );
return MS::kFailure;
}
meshArry.jumpToElement(idx);
MDataHandle hmesh = meshArry.outputValue();
HPolygonalMesh entryMesh(meshName.asChar() );
APolygonalMesh dataMesh;
entryMesh.load(&dataMesh);
entryMesh.close();
MFnMeshData dataCreator;
MObject outMeshData = dataCreator.create(&stat);
if( !stat ) {
MGlobal::displayWarning("hes mesh cannot create " + meshName);
return MS::kFailure;
}
AHelper::Info<MString>(" hes init mesh ", meshName);
HesperisPolygonalMeshCreator::create(&dataMesh, outMeshData);
hmesh.set(outMeshData);
data.setClean(plug);
if( (idx+1)>=numMeshes ) {
if(!BaseUtil::IsImporting) {
AHelper::Info<std::string>(" hes mesh close file ", substitutedCacheName );
BaseUtil::CloseHes();
}
}
}
else {
return MS::kUnknownParameter;
}
return MS::kSuccess;
}
示例7: compute
MStatus retargetLocator::compute( const MPlug& plug, MDataBlock& data )
{
MStatus status;
MDataHandle hDiscMatrix = data.inputValue( aDiscMatrix );
MDataHandle hDiscAxis = data.inputValue( aDiscAxis );
MDataHandle hDiscAngle = data.inputValue( aDiscAngle );
MDataHandle hDiscDivision = data.inputValue( aDiscDivision );
MDataHandle hDiscOffset = data.inputValue( aDiscOffset );
MDataHandle hDiscSize = data.inputValue( aDiscSize );
MDataHandle hDiscActiveColor = data.inputValue( aDiscActiveColor );
MDataHandle hDiscLeadColor = data.inputValue( aDiscLeadColor );
MDataHandle hDiscDefaultColor = data.inputValue( aDiscDefaultColor );
MDataHandle hDiscFillAlpha = data.inputValue( aDiscFillAlpha );
MDataHandle hDiscLineAlpha = data.inputValue( aDiscLineAlpha );
discAxis = hDiscAxis.asInt();
discDivision = hDiscDivision.asInt();
discAngle = hDiscAngle.asDouble();
discSize = hDiscSize.asVector();
discOffset = hDiscOffset.asVector();
discActiveColor = hDiscActiveColor.asFloat3();
discLeadColor = hDiscLeadColor.asFloat3();
discDefaultColor = hDiscDefaultColor.asFloat3();
discFillAlpha = hDiscFillAlpha.asFloat();
discLineAlpha = hDiscLineAlpha.asFloat();
MArrayDataHandle hArrArrow = data.inputArrayValue( aArrow );
arrowNum = hArrArrow.elementCount();
inheritMatrix.setLength( arrowNum );
aimMatrix.setLength( arrowNum );
inputMeshObj.setLength( arrowNum );
startSize.setLength( arrowNum );
size.setLength( arrowNum );
activeColor.setLength( arrowNum );
leadColor.setLength( arrowNum );
defaultColor.setLength( arrowNum );
fillAlpha.setLength( arrowNum );
lineAlpha.setLength( arrowNum );
offset.setLength( arrowNum );
for( int i =0; i < arrowNum; i++ )
{
MDataHandle hArrow = hArrArrow.inputValue();
MDataHandle hInheritMatrix = hArrow.child( aInheritMatrix );
MDataHandle hAimMatrix = hArrow.child( aAimMatrix );
MDataHandle hInputMesh = hArrow.child( aInputMesh );
MDataHandle hStartSize = hArrow.child( aStartSize );
MDataHandle hSize = hArrow.child( aSize );
MDataHandle hActiveColor = hArrow.child( aActiveColor );
MDataHandle hLeadColor = hArrow.child( aLeadColor );
MDataHandle hDefaultColor = hArrow.child( aDefaultColor );
MDataHandle hFillAlpha = hArrow.child( aFillAlpha );
MDataHandle hLineAlpha = hArrow.child( aLineAlpha );
MDataHandle hOffset = hArrow.child( aOffset );
inheritMatrix[i] = hInheritMatrix.asBool();
aimMatrix[i] = hAimMatrix.asMatrix()*hDiscMatrix.asMatrix().inverse();
inputMeshObj[i] = hInputMesh.asMesh();
startSize[i] = hStartSize.asFloat();
size[i] = hSize.asFloat();
activeColor[i] = hActiveColor.asFloat3();
leadColor[i] = hLeadColor.asFloat3();
defaultColor[i] = hDefaultColor.asFloat3();
fillAlpha[i] = hFillAlpha.asFloat();
lineAlpha[i] = hLineAlpha.asFloat();
offset[i] = hOffset.asVector();
hArrArrow.next();
}
MDataHandle hOutput = data.outputValue( aOutput );
hOutput.set( 1.0 );
data.setClean( plug );
return MS::kSuccess;
}
示例8: computeCollisionShape
//.........这里部分代码省略.........
int type;
plgType.getValue(type);
switch(type) {
case 0:
{
//convex hull
MPlugArray plgaConnectedTo;
plgInShape.connectedTo(plgaConnectedTo, true, true);
if(plgaConnectedTo.length() > 0) {
MObject node = plgaConnectedTo[0].node();
if(node.hasFn(MFn::kMesh)) {
MDagPath dagPath;
MDagPath::getAPathTo(node, dagPath);
MFnMesh fnMesh(dagPath);
MFloatPointArray mpoints;
MFloatVectorArray mnormals;
MIntArray mtrianglecounts;
MIntArray mtrianglevertices;
fnMesh.getPoints(mpoints, MSpace::kObject);
fnMesh.getNormals(mnormals, MSpace::kObject);
fnMesh.getTriangles(mtrianglecounts, mtrianglevertices);
std::vector<vec3f> vertices(mpoints.length());
std::vector<vec3f> normals(mpoints.length());
std::vector<unsigned int> indices(mtrianglevertices.length());
for(size_t i = 0; i < vertices.size(); ++i) {
vertices[i] = vec3f(mpoints[i].x, mpoints[i].y, mpoints[i].z);
normals[i] = vec3f(mnormals[i].x, mnormals[i].y, mnormals[i].z);
}
for(size_t i = 0; i < indices.size(); ++i) {
indices[i] = mtrianglevertices[i];
}
m_collision_shape = solver_t::create_convex_hull_shape(&(vertices[0]), vertices.size(), &(normals[0]),
&(indices[0]), indices.size());
}
}
}
break;
case 1:
//mesh
{
//convex hull
MPlugArray plgaConnectedTo;
plgInShape.connectedTo(plgaConnectedTo, true, true);
if(plgaConnectedTo.length() > 0) {
MObject node = plgaConnectedTo[0].node();
if(node.hasFn(MFn::kMesh)) {
MDagPath dagPath;
MDagPath::getAPathTo(node, dagPath);
MFnMesh fnMesh(dagPath);
MFloatPointArray mpoints;
MFloatVectorArray mnormals;
MIntArray mtrianglecounts;
MIntArray mtrianglevertices;
fnMesh.getPoints(mpoints, MSpace::kObject);
fnMesh.getNormals(mnormals, MSpace::kObject);
fnMesh.getTriangles(mtrianglecounts, mtrianglevertices);
std::vector<vec3f> vertices(mpoints.length());
std::vector<vec3f> normals(mpoints.length());
std::vector<unsigned int> indices(mtrianglevertices.length());
for(size_t i = 0; i < vertices.size(); ++i) {
vertices[i] = vec3f(mpoints[i].x, mpoints[i].y, mpoints[i].z);
normals[i] = vec3f(mnormals[i].x, mnormals[i].y, mnormals[i].z);
}
for(size_t i = 0; i < indices.size(); ++i) {
indices[i] = mtrianglevertices[i];
}
m_collision_shape = solver_t::create_mesh_shape(&(vertices[0]), vertices.size(), &(normals[0]),
&(indices[0]), indices.size());
}
}
}
break;
case 2:
//cylinder
break;
case 3:
//capsule
break;
case 4:
//box
m_collision_shape = solver_t::create_box_shape();
break;
case 5:
//sphere
m_collision_shape = solver_t::create_sphere_shape();
break;
case 6:
//plane
m_collision_shape = solver_t::create_plane_shape();
break;
}
assert(m_collision_shape);
data.setClean(plug);
}
示例9: compute
//.........这里部分代码省略.........
// McheckErr(status, "ERROR in fnMass.array(), not find masses.\n");
// The attribute mInputPPData contains the attribute in an array form
// parpared by the particleShape if the particleShape has per particle
// attribute fieldName_attrName.
//
// Suppose a field with the name dynExprField1 is connecting to
// particleShape1, and the particleShape1 has per particle float attribute
// dynExprField1_magnitude and vector attribute dynExprField1_direction,
// then hInputPPArray will contains a MdoubleArray with the corresponding
// name "magnitude" and a MvectorArray with the name "direction". This
// is a mechanism to allow the field attributes being driven by dynamic
// expression.
MArrayDataHandle mhInputPPData = block.inputArrayValue( mInputPPData, &status );
McheckErr(status,"ERROR in mhInputPPData = block.inputArrayValue().\n");
status = mhInputPPData.jumpToElement( multiIndex );
McheckErr(status, "ERROR: mhInputPPArray.jumpToElement failed.\n");
MDataHandle hInputPPData = mhInputPPData.inputValue( &status );
McheckErr(status, "ERROR in hInputPPData = mhInputPPData.inputValue\n");
MObject dInputPPData = hInputPPData.data();
MFnArrayAttrsData inputPPArray( dInputPPData );
MDataHandle hOwnerPPData = block.inputValue( mOwnerPPData, &status );
McheckErr(status, "ERROR in hOwnerPPData = block.inputValue\n");
MObject dOwnerPPData = hOwnerPPData.data();
MFnArrayAttrsData ownerPPArray( dOwnerPPData );
const MString magString("magnitude");
MFnArrayAttrsData::Type doubleType(MFnArrayAttrsData::kDoubleArray);
bool arrayExist;
MDoubleArray magnitudeArray;
arrayExist = inputPPArray.checkArrayExist(magString, doubleType, &status);
// McheckErr(status, "ERROR in checkArrayExist(magnitude)\n");
if(arrayExist) {
magnitudeArray = inputPPArray.getDoubleData(magString, &status);
// McheckErr(status, "ERROR in inputPPArray.doubleArray(magnitude)\n");
}
MDoubleArray magnitudeOwnerArray;
arrayExist = ownerPPArray.checkArrayExist(magString, doubleType, &status);
// McheckErr(status, "ERROR in checkArrayExist(magnitude)\n");
if(arrayExist) {
magnitudeOwnerArray = ownerPPArray.getDoubleData(magString, &status);
// McheckErr(status, "ERROR in ownerPPArray.doubleArray(magnitude)\n");
}
const MString dirString("direction");
MFnArrayAttrsData::Type vectorType(MFnArrayAttrsData::kVectorArray);
arrayExist = inputPPArray.checkArrayExist(dirString, vectorType, &status);
MVectorArray directionArray;
// McheckErr(status, "ERROR in checkArrayExist(direction)\n");
if(arrayExist) {
directionArray = inputPPArray.getVectorData(dirString, &status);
// McheckErr(status, "ERROR in inputPPArray.vectorArray(direction)\n");
}
arrayExist = ownerPPArray.checkArrayExist(dirString, vectorType, &status);
MVectorArray directionOwnerArray;
// McheckErr(status, "ERROR in checkArrayExist(direction)\n");
if(arrayExist) {
directionOwnerArray = ownerPPArray.getVectorData(dirString, &status);
// McheckErr(status, "ERROR in ownerPPArray.vectorArray(direction)\n");
}
// Compute the output force.
//
MVectorArray forceArray;
apply( block, points.length(), magnitudeArray, magnitudeOwnerArray,
directionArray, directionOwnerArray, forceArray );
// get output data handle
//
MArrayDataHandle hOutArray = block.outputArrayValue( mOutputForce, &status);
McheckErr(status, "ERROR in hOutArray = block.outputArrayValue.\n");
MArrayDataBuilder bOutArray = hOutArray.builder( &status );
McheckErr(status, "ERROR in bOutArray = hOutArray.builder.\n");
// get output force array from block.
//
MDataHandle hOut = bOutArray.addElement(multiIndex, &status);
McheckErr(status, "ERROR in hOut = bOutArray.addElement.\n");
MFnVectorArrayData fnOutputForce;
MObject dOutputForce = fnOutputForce.create( forceArray, &status );
McheckErr(status, "ERROR in dOutputForce = fnOutputForce.create\n");
// update data block with new output force data.
//
hOut.set( dOutputForce );
block.setClean( plug );
return( MS::kSuccess );
}
示例10: compute
MStatus ProxyViz::compute( const MPlug& plug, MDataBlock& block )
{
if(!m_enableCompute) return MS::kSuccess;
if( plug == outValue ) {
updateWorldSpace(thisMObject() );
MStatus status;
ExampVox * defBox = plantExample(0);
defBox->setGeomSizeMult(block.inputValue(aradiusMult).asFloat() );
defBox->setGeomBox(block.inputValue(abboxminx).asFloat(),
block.inputValue(abboxminy).asFloat(),
block.inputValue(abboxminz).asFloat(),
block.inputValue(abboxmaxx).asFloat(),
block.inputValue(abboxmaxy).asFloat(),
block.inputValue(abboxmaxz).asFloat());
float grdsz = defBox->geomExtent() * 32.f ;
if(grdsz < 32.f) {
AHelper::Info<float>(" ProxyViz input box is too small", grdsz);
grdsz = 32.f;
AHelper::Info<float>(" trancated to", grdsz);
}
if(m_toSetGrid) {
m_toSetGrid = false;
resetGrid(grdsz);
}
if(_firstLoad) {
/// internal cache only, initializing from external cache is obsolete
if(!loadInternal(block) )
std::cout<<"\n ERROR proxviz cannot load internal cache";
_firstLoad = 0;
}
if(!m_toCheckVisibility) {
MArrayDataHandle groundMeshArray = block.inputArrayValue(agroundMesh );
MArrayDataHandle groundSpaceArray = block.inputArrayValue(agroundSpace );
/// in case no ground is connected
if(updateGround(groundMeshArray, groundSpaceArray )) {
moveWithGround();
AHelper::Info<std::string>(" ProxyViz ground ", groundBuildLog() );
}
}
if(!m_hasParticle) {
block.setClean(plug);
return MS::kSuccess;
}
const int ngroups = block.inputValue(agroupcount).asInt();
MDataHandle hdata = block.inputValue(outPositionPP, &status);
MFnVectorArrayData farray(hdata.data(), &status);
if(!status) {
MGlobal::displayInfo("proxy viz is not properly connected to a particle system");
block.setClean(plug);
return MS::kSuccess;
}
MDataHandle scaledata = block.inputValue(outScalePP, &status);
MFnVectorArrayData scalearray(scaledata.data(), &status);
if(!status) {
MGlobal::displayInfo("proxy viz is not properly connected to a particle system");
block.setClean(plug);
return MS::kSuccess;
}
MDataHandle rotatedata = block.inputValue(outRotationPP, &status);
MFnVectorArrayData rotatearray(rotatedata.data(), &status);
if(!status) {
MGlobal::displayInfo("proxy viz is not properly connected to a particle system");
block.setClean(plug);
return MS::kSuccess;
}
MDataHandle replaceData = block.inputValue(outReplacePP, &status);
MFnDoubleArrayData replaceArrayFn(replaceData.data(), &status);
if(!status) {
MGlobal::displayInfo("proxy viz is not properly connected to a particle system, needs userScalarPP");
block.setClean(plug);
return MS::kSuccess;
}
MVectorArray outPosArray = farray.array();
MVectorArray outScaleArray = scalearray.array();
MVectorArray outRotateArray = rotatearray.array();
MDoubleArray outReplaceArray = replaceArrayFn.array();
if( outPosArray.length() < 1) {
block.setClean(plug);
return MS::kSuccess;
}
computePPAttribs(outPosArray, outRotateArray, outScaleArray, outReplaceArray,
//.........这里部分代码省略.........
示例11: fnOutputCurve
MStatus clusterControledCurve::compute( const MPlug& plug, MDataBlock& data )
{
//MFnDependencyNode thisNode( thisMObject() );
//cout << thisNode.name() << ", start" << endl;
MStatus status;
MDataHandle hInputCurve = data.inputValue( aInputCurve, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MDataHandle hInputCurveMatrix = data.inputValue( aInputCurveMatrix, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MDataHandle hOutputCurve = data.outputValue( aOutputCurve, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MArrayDataHandle hArrBindPreMatrix = data.inputArrayValue( aBindPreMatrix, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MArrayDataHandle hArrMatrix = data.inputArrayValue( aMatrix, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MArrayDataHandle hArrWeightList = data.inputArrayValue( aWeightList, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MDataHandle hUpdate = data.inputValue( aUpdate, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
MObject oInputCurve = hInputCurve.asNurbsCurve();
int bindPreMatrixLength = hArrBindPreMatrix.elementCount();
int matrixLength = hArrMatrix.elementCount();
MFnNurbsCurve fnInputCurve = oInputCurve;
int numCVs = fnInputCurve.numCVs();
int weightListLength = hArrWeightList.elementCount();
if( weightListLength > 100 )
{
cout << "WeightList Count Error : " << weightListLength << endl;
return MS::kFailure;
}
MPointArray inputCvPoints;
MPointArray outputCvPoints;
fnInputCurve.getCVs( inputCvPoints );
outputCvPoints.setLength( numCVs );
MMatrix matrix;
MMatrix inputCurveMatrix = hInputCurveMatrix.asMatrix();
MMatrix inputCurveMatrixInverse = inputCurveMatrix.inverse();
if( requireUpdate )
CHECK_MSTATUS_AND_RETURN_IT( updateBindPreMatrix( oInputCurve, inputCurveMatrixInverse,
hArrMatrix, hArrBindPreMatrix, hUpdate.asBool() ) );
for( int i=0; i< numCVs; i++ )
{
inputCvPoints[i] *= inputCurveMatrix;
}
for( int i=0; i< numCVs; i++ )
{
outputCvPoints[i] = MPoint( 0,0,0 );
double weight;
for( int j=0; j< matrixLength; j++ )
{
weight = setWeights[i][j];
hArrMatrix.jumpToElement( j );
matrix = hArrMatrix.inputValue().asMatrix();
outputCvPoints[i] += inputCvPoints[i]*bindPreMatrix[j]*matrix*weight;
}
}
for( int i=0; i< numCVs; i++ )
{
outputCvPoints[i] *= inputCurveMatrixInverse;
}
MFnNurbsCurveData outputCurveData;
MObject oOutputCurve = outputCurveData.create();
fnInputCurve.copy( oInputCurve, oOutputCurve );
MFnNurbsCurve fnOutputCurve( oOutputCurve, &status );
CHECK_MSTATUS_AND_RETURN_IT( status );
fnOutputCurve.setCVs( outputCvPoints );
hOutputCurve.set( oOutputCurve );
data.setClean( plug );
//cout << thisNode.name() << ", end" << endl;
return status;
}
示例12: compute
//.........这里部分代码省略.........
MFloatVector half = calcHalfVector( viewDirection, lightDirection );
// Beckmann function
MFloatVector nA;
if( fabs(1.0-fabs(N*ca)) <= 0.0001f ){
MFloatPoint oo( 0.0,0.0,0.0 );
MFloatPoint ow = oo * matrixOToW;
MFloatPoint oc = ow * matrixWToC;
MFloatVector origin( oc[0], oc[1], oc[2] );
nA = origin - surfacePoint;
nA.normalize();
}else{
nA = ca;
}
MFloatVector x = N ^ nA;
x.normalize();
MFloatVector y = N ^ x;
y.normalize();
MFloatVector azimuthH = N ^ half;
azimuthH = N ^ azimuthH;
azimuthH.normalize();
float cos_phai = x * azimuthH;
float sin_phai = 0.0;
if( fabs(1 - cos_phai*cos_phai) < 0.0001 ){
sin_phai = 0.0;
}else{
sin_phai = sqrtf( 1.0f - cos_phai*cos_phai );
}
double co = pow( (half * N), 4.0f );
double t = tan( acos(half*N) );
t *= -t;
float rough1 = block.inputValue( aRoughness1 ).asFloat();
float rough2 = block.inputValue( aRoughness2 ).asFloat();
double aaa = cos_phai / rough1;
double bbb = sin_phai / rough2;
t = t * ( aaa*aaa + bbb*bbb );
double D = pow( (1.0/((double)rough1*(double)rough2 * co)), t );
double aa = (2.0 * (N*half) * (N*viewDirection) ) / (viewDirection*half);
double bb = (2.0 * (N*half) * (N*lightDirection) ) / (viewDirection*half);
double cc = 1.0;
double G = 0.0;
G = MIN( aa, bb );
G = MIN( G, cc );
float s = (float) (D * G /
(double)((N*lightDirection) * (N*viewDirection)));
MFloatVector& specColor = block.inputValue( aSpecColor ).asFloatVector();
specularColor[0] += lightIntensity[0] * specColor[0] *
s * specularCoeff;
specularColor[1] += lightIntensity[1] * specColor[1] *
s * specularCoeff;
specularColor[2] += lightIntensity[2] * specColor[2] *
s * specularCoeff;
}
}
if( !lightData.next() ){
break;
}
}
// result = specular + diffuse + ambient;
resultColor = diffuseColor + specularColor + ambientColor;
MFloatVector& transparency = block.inputValue( aInTransparency ).asFloatVector();
resultColor[0] *= ( 1.0f - transparency[0] );
resultColor[1] *= ( 1.0f - transparency[1] );
resultColor[2] *= ( 1.0f - transparency[2] );
// set ouput color attribute
MDataHandle outColorHandle = block.outputValue( aOutColor );
MFloatVector& outColor = outColorHandle.asFloatVector();
outColor = resultColor;
outColorHandle.setClean();
block.setClean( plug );
}
else if ((plug == aOutTransparency) || (plug.parent() == aOutTransparency))
{
MFloatVector& tr = block.inputValue( aInTransparency ).asFloatVector();
// set ouput color attribute
MDataHandle outTransHandle = block.outputValue( aOutTransparency );
MFloatVector& outTrans = outTransHandle.asFloatVector();
outTrans = tr;
block.setClean( plug );
} else
return MS::kUnknownParameter;
return MS::kSuccess;
}
示例13: compute
MStatus sgHair_controlJoint::compute( const MPlug& plug, MDataBlock& data )
{
MStatus status;
MDataHandle hStaticRotation = data.inputValue( aStaticRotation );
m_bStaticRotation = hStaticRotation.asBool();
if( m_isDirtyMatrix )
{
MDataHandle hInputBaseCurveMatrix = data.inputValue( aInputBaseCurveMatrix );
m_mtxBaseCurve = hInputBaseCurveMatrix.asMatrix();
}
if( m_isDirtyParentMatrixBase )
{
MDataHandle hJointParenBasetMatrix = data.inputValue( aJointParentBaseMatrix );
m_mtxJointParentBase = hJointParenBasetMatrix.asMatrix();
}
if( m_isDirtyCurve || m_isDirtyParentMatrixBase )
{
MDataHandle hInputBaseCurve = data.inputValue( aInputBaseCurve );
MFnNurbsCurve fnCurve = hInputBaseCurve.asNurbsCurve();
fnCurve.getCVs( m_cvs );
getJointPositionBaseWorld();
}
if( m_isDirtyGravityOption || m_isDirtyCurve || m_isDirtyParentMatrixBase )
{
MDataHandle hGravityParam = data.inputValue( aGravityParam );
MDataHandle hGravityRange = data.inputValue( aGravityRange );
MDataHandle hGravityWeight = data.inputValue( aGravityWeight );
MDataHandle hGravityOffsetMatrix = data.inputValue( aGravityOffsetMatrix );
m_paramGravity = hGravityParam.asDouble();
m_rangeGravity = hGravityRange.asDouble();
m_weightGravity = hGravityWeight.asDouble();
m_mtxGravityOffset = hGravityOffsetMatrix.asMatrix();
m_mtxGravityOffset( 3,0 ) = 0.0;
m_mtxGravityOffset( 3,1 ) = 0.0;
m_mtxGravityOffset( 3,2 ) = 0.0;
setGravityJointPositionWorld();
}
setOutput();
MArrayDataHandle hArrOutput = data.outputValue( aOutput );
MArrayDataBuilder builderOutput( aOutput, m_cvs.length() );
for( int i=0; i< m_cvs.length(); i++ )
{
MDataHandle hOutput = builderOutput.addElement( i );
MDataHandle hOutTrans = hOutput.child( aOutTrans );
MDataHandle hOutOrient = hOutput.child( aOutOrient );
hOutTrans.set( m_vectorArrTransJoint[i] );
hOutOrient.set( m_vectorArrRotateJoint[i] );
}
hArrOutput.set( builderOutput );
hArrOutput.setAllClean();
data.setClean( plug );
m_isDirtyMatrix = false;
m_isDirtyCurve = false;
m_isDirtyGravityOption = false;
m_isDirtyParentMatrixBase = false;
return MS::kSuccess;
}
示例14: compute
MStatus 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;
}
示例15: 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;
}