void ExtractAttribute(MFnDependencyNode& fn, std::string name, SMatAttrib& attrib) { MPlug p; // extract attribute color std::string r = name + "R"; std::string g = name + "G"; std::string b = name + "B"; p = fn.findPlug(r.c_str()); p.getValue(attrib.color[0]); p = fn.findPlug(g.c_str()); p.getValue(attrib.color[1]); p = fn.findPlug(b.c_str()); p.getValue(attrib.color[2]); // extract attribute texture MString texname; p = fn.findPlug(name.c_str()); MPlugArray plugs; p.connectedTo(plugs,true,true); for(int i = 0; i != plugs.length(); ++i) { if (plugs[i].node().apiType() == MFn::kFileTexture) { MFnDependencyNode fnDep(plugs[i].node()); texname = fnDep.name(); break; } } attrib.textureID = GetTextureID( texname ); }
// finds the texture file or the color of the texture for a given surface // the following does not allow for multiple texture blending!!!! int Material::colorTexture(ostream &fout) const { MStatus status; int texcolor; MPlug colorPlug = MFnDependencyNode(shaderNode).findPlug("color"); MItDependencyGraph dgIt(colorPlug, MFn::kFileTexture, MItDependencyGraph::kUpstream, MItDependencyGraph::kBreadthFirst, MItDependencyGraph::kNodeLevel, &status); dgIt.disablePruningOnFilter(); if (!dgIt.isDone()) { // use a texture value MObject textureNode = dgIt.thisNode(); MPlug filenamePlug = MFnDependencyNode(textureNode).findPlug("fileTextureName"); MString textureName; filenamePlug.getValue(textureName); texcolor = ++textureNum; fout << "Texture \"" << texcolor << "\" \"color\" \"imagemap\" \"string filename\" [\"" << textureName.asChar() << "\"]" << endl; } else { // use a numerical value for the color MObject object; status = colorPlug.getValue(object); if (status != MStatus::kSuccess) { MGlobal::displayWarning("Could not get color value out"); return 0; } MFnNumericData colorData(object, &status); if (status != MStatus::kSuccess) { MGlobal::displayWarning("Could not get color value out (2)"); return 0; } if (colorData.numericType() == MFnNumericData::k3Float) { float r,g,b; colorData.getData(r,g,b); texcolor = ++textureNum; fout << "Texture \"" << texcolor << "\" \"color\" \"constant\" \"color value\" [" << r << " " << g << " " << b << "]" << endl; } else if (colorData.numericType() == MFnNumericData::k3Double) { double r,g,b; colorData.getData(r,g,b); texcolor = ++textureNum; fout << "Texture \"" << texcolor << "\" \"color\" \"constant\" \"color value\" [" << r << " " << g << " " << b << "]" << endl; } else { MGlobal::displayWarning("Invalid data tuple"); return 0; } } return texcolor; }
void curvedArrows::draw( M3dView & view, const MDagPath & /*path*/, M3dView::DisplayStyle style, M3dView::DisplayStatus status ) { // Get the size // MObject thisNode = thisMObject(); MPlug tPlug = MPlug( thisNode, aTransparency ); MPlug cPlug = MPlug( thisNode, aTheColor ); float r, g, b, a; MObject color; cPlug.getValue( color ); MFnNumericData data( color ); data.getData( r, g, b ); tPlug.getValue( a ); view.beginGL(); if( (style == M3dView::kFlatShaded) || (style == M3dView::kGouraudShaded) ) { // Push the color settings // glPushAttrib( GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | GL_PIXEL_MODE_BIT ); if ( a < 1.0f ) { glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); } glColor4f( r, g, b, a ); glBegin( GL_TRIANGLES ); unsigned int i; for ( i = 0; i < fsFaceListSize; i ++ ) { unsigned int *vid = fsFaceList[i]; unsigned int *nid = fsFaceVertexNormalList[i]; for ( unsigned int j = 0; j < 3; j ++ ) { glNormal3d( fsNormalList[nid[j]-1][0], fsNormalList[nid[j]-1][1], fsNormalList[nid[j]-1][2] ); glVertex3d( fsVertexList[vid[j]-1][0], fsVertexList[vid[j]-1][1], fsVertexList[vid[j]-1][2] ); } } glEnd(); glPopAttrib(); drawEdgeLoop( view, status ); } else { drawEdgeLoop( view, status ); } view.endGL(); }
void Exporter::extractColor(Color& tempcolor, MFnDependencyNode& fn, MString name) { MPlug p; MString r = name; r += "R"; MString g = name; g += "G"; MString b = name; b += "B"; MString a = name; a += "A"; p = fn.findPlug(r.asChar()); p.getValue(tempcolor.r); p = fn.findPlug(g.asChar()); p.getValue(tempcolor.g); p = fn.findPlug(b.asChar()); p.getValue(tempcolor.b); p = fn.findPlug(a.asChar()); p.getValue(tempcolor.a); p = fn.findPlug(name.asChar()); MPlugArray connections; p.connectedTo(connections, true, false); int debug = connections.length(); for (int i = 0; i != connections.length(); ++i) { // if file texture found if (connections[i].node().apiType() == MFn::kFileTexture) { // bind a function set to it .... MFnDependencyNode fnDep(connections[i].node()); // to get the node name tempcolor.texfileInternal = fnDep.name().asChar(); MPlug filename = fnDep.findPlug("ftn"); //sparar hela s�kv�gen till texturen tempcolor.texfileExternal = filename.asString().asChar(); //kopierar texturfiler std::string base_filename = tempcolor.texfileExternal.substr(tempcolor.texfileExternal.find_last_of("/\\") + 1); CopyFile(tempcolor.texfileExternal.c_str(), base_filename.c_str(), false); // stop looping break; } } }
//--------------------------------------------------------------- String EffectTextureExporter::exportImage ( const MObject &texture ) { // Retrieve the texture filename MFnDependencyNode textureNode ( texture ); MString mayaName = textureNode.name(); MPlug filenamePlug = textureNode.findPlug ( ATTR_FILE_TEXTURE_NAME ); // Get the maya image id. String mayaImageId = DocumentExporter::mayaNameToColladaName ( textureNode.name() ); // Generate a COLLADA id for the new light object String colladaImageId; // Check if there is an extra attribute "colladaId" and use this as export id. MString attributeValue; DagHelper::getPlugValue ( texture, COLLADA_ID_ATTRIBUTE_NAME, attributeValue ); if ( attributeValue != EMPTY_CSTRING ) { // Generate a valid collada name, if necessary. colladaImageId = mDocumentExporter->mayaNameToColladaName ( attributeValue, false ); } else { // Generate a COLLADA id for the new light object colladaImageId = DocumentExporter::mayaNameToColladaName ( textureNode.name() ); } // Make the id unique and store it in a map for refernences. colladaImageId = mImageIdList.addId ( colladaImageId ); mMayaIdColladaImageId [mayaImageId] = colladaImageId; // Get the maya filename with the path to the file. MString mayaFileName; filenamePlug.getValue ( mayaFileName ); if ( mayaFileName.length () == 0 ) return NULL; String sourceFile = mayaFileName.asChar (); COLLADASW::URI sourceFileUri ( COLLADASW::URI::nativePathToUri ( sourceFile ) ); if ( sourceFileUri.getScheme ().empty () ) sourceFileUri.setScheme ( COLLADASW::URI::SCHEME_FILE ); COLLADASW::Image* colladaImage = exportImage ( mayaImageId, colladaImageId, sourceFileUri ); if ( colladaImage == NULL ) return NULL; // Export the node type, because PSD textures don't behave the same as File textures. String nodeType = texture.hasFn ( MFn::kPsdFileTexture ) ? MAYA_TEXTURE_PSDTEXTURE : MAYA_TEXTURE_FILETEXTURE; colladaImage->addExtraTechniqueParameter ( PROFILE_MAYA, MAYA_TEXTURE_NODETYPE, nodeType ); // Export whether this image is in fact an image sequence MPlug imgSeqPlug = textureNode.findPlug ( ATTR_IMAGE_SEQUENCE ); bool isImgSeq = false; imgSeqPlug.getValue ( isImgSeq ); colladaImage->addExtraTechniqueParameter ( PROFILE_MAYA, MAYA_TEXTURE_IMAGE_SEQUENCE, isImgSeq ); return colladaImage->getImageId(); }
bool BasicLocator::getCirclePoints( MPointArray &pts ) const { MStatus stat; MObject thisNode = thisMObject(); MFnDagNode dagFn( thisNode ); MPlug xWidthPlug = dagFn.findPlug( xWidth, &stat ); float xWidthValue; xWidthPlug.getValue( xWidthValue ); MPlug zWidthPlug = dagFn.findPlug( zWidth, &stat ); float zWidthValue; zWidthPlug.getValue( zWidthValue ); MPlug typePlug = dagFn.findPlug( dispType, &stat ); short typeValue; typePlug.getValue( typeValue ); unsigned int nCirclePts; switch( typeValue ) { case 0: nCirclePts = 4; break; case 1: nCirclePts = 5; break; default: nCirclePts = 20; break; } pts.clear(); pts.setSizeIncrement( nCirclePts ); MPoint pt; pt.y = 0.0; const double angleIncr = M_2PI / (nCirclePts - 1); double angle = 0.0; unsigned int i=0; for( ; i < nCirclePts; i++, angle+=angleIncr ) { pt.x = xWidthValue * cos( angle ); pt.z = zWidthValue * sin( angle ); pts.append( pt ); } return true; }
void Uber::Insert(std::ostream& fout) const { int texcolor=0, texbump=0; texcolor = colorTexture(fout); texbump = bumpTexture(fout); MStatus status; MObject object; MPlug reflectivityPlug = MFnDependencyNode(shaderNode).findPlug("reflectivity"); MPlug translucencePlug = MFnDependencyNode(shaderNode).findPlug("translucence"); MPlug specularPlug = MFnDependencyNode(shaderNode).findPlug("specularColor"); status = specularPlug.getValue(object); if (status != MStatus::kSuccess) { MGlobal::displayWarning("Could not get specular color value out"); } MFnNumericData specularData(object, &status); if (status != MStatus::kSuccess) { MGlobal::displayWarning("Could not get specular color data"); } if (texcolor) { fout << "Material \"uber\" \"texture Kd\" \"" << texcolor << "\" "; if (texbump) fout << "\"texture bumpmap\" \"" << texbump << "\" "; float r; status = reflectivityPlug.getValue(r); if (status == MStatus::kSuccess) fout << "\"color Kr\" [" << r << " " << r << " " << r << "] "; if (specularData.numericType() == MFnNumericData::k3Float) { float r,g,b; specularData.getData(r,g,b); fout << "\"color Ks\" [" << r << " " << g << " " << b << "] "; } else if (specularData.numericType() == MFnNumericData::k3Double) { double r,g,b; specularData.getData(r,g,b); fout << "\"color Ks\" [" << r << " " << g << " " << b << "] "; } float opacity; status = translucencePlug.getValue(opacity); opacity = 1.f - opacity; if (status == MStatus::kSuccess) fout << "\"color opacity\" [" << opacity << " " << opacity << " " << opacity << "] "; fout << std::endl; } }
// ------------------------------------------------------------ void EffectTextureExporter::addAngleParameter ( COLLADASW::Texture* colladaTexture, const char* plugName, MFnDependencyNode &placement2d ) { MStatus status; MPlug plug = placement2d.findPlug ( plugName, &status ); if ( status == MStatus::kSuccess ) { float angleRad; plug.getValue ( angleRad ); float angleDeg = COLLADABU::Math::Utils::radToDegF ( angleRad ); // The target id for the animation String targetSid = mAnimationTargetPath + plugName; // Create the animation AnimationExporter* animationExporter = mDocumentExporter->getAnimationExporter(); bool animated = animationExporter->addPlugAnimation ( plug, targetSid, kBoolean ); // Add the parameter String paramSid = EMPTY_STRING; if ( animated ) paramSid = plugName; colladaTexture->addExtraTechniqueParameter ( PROFILE_MAYA, plugName, angleDeg, paramSid ); } }
MStatus lrutils::getMetaChildByRigId(MObject metaNodeObj, MString rigId, MObject& metaChildObj) { MStatus status = MS::kFailure; MFnDependencyNode metaNodeFn( metaNodeObj ); MPlug metaChildrenPlug = metaNodeFn.findPlug( "metaChildren", true, &status ); MyCheckStatusReturn(status, "MFnDependencyNode.findPlug() failed"); //follow the plug connection to the connected plug on the other object MPlugArray connectedChildPlugs; metaChildrenPlug.connectedTo(connectedChildPlugs,false,true,&status); MyCheckStatusReturn(status,"MPlug.connectedTo() failed"); for (unsigned int i = 0; i < connectedChildPlugs.length(); i++) { MPlug connectedPlug = connectedChildPlugs[i]; MObject connectedNodeObj = connectedPlug.node(&status); MyCheckStatusReturn(status, "MPlug.node() failed"); MFnDependencyNode connectedNodeFn( connectedNodeObj ); //get the rigId number held in the rigId attribute MPlug rigIdPlug = connectedNodeFn.findPlug(MString("rigId"),true,&status); MyCheckStatusReturn(status,"findPlug failed"); MString childRigId; rigIdPlug.getValue(childRigId); //if rigId is in childRigId then return the object if( childRigId.indexW(rigId) != -1 ) { metaChildObj = connectedNodeObj; status = MS::kSuccess; break; } } return status; }
ConstObjectPtr SceneShape::readSceneShapeAttribute( const MDagPath &p, SceneInterface::Name attributeName ) { MDagPath dagPath; SceneShape *sceneShape = findScene( p, false, &dagPath ); if ( !sceneShape ) { return 0; } MFnDagNode fnChildDag( dagPath ); if( attributeName == LinkedScene::linkAttribute ) { if( !fnChildDag.isIntermediateObject() ) { return readSceneShapeLink(p); } } ConstSceneInterfacePtr scene = sceneShape->getSceneInterface(); if ( !scene ) { return 0; } MPlug timePlug = fnChildDag.findPlug( aTime ); MTime time; timePlug.getValue( time ); return scene->readAttribute( attributeName, time.as( MTime::kSeconds ) ); }
MBoundingBox kgLocator::boundingBox() const { MBoundingBox bbox; MPoint pt; MStatus stat; MObject thisNode = thisMObject(); MFnDagNode dagFn( thisNode ); MPlug heightPlug = dagFn.findPlug( height, &stat ); float heightValue; heightPlug.getValue( heightValue ); for(unsigned int i=0; i < pts.length(); ++i ) { pt.x = pts[i].x; pt.y = pts[i].y; pt.z = pts[i].z; bbox.expand( pt ); } //account for the vertical spindle pt.x=0.0; pt.y = 0.0f; pt.z = 0.0f; bbox.expand( pt ); pt.x=0.0; pt.y = heightValue; pt.z = 0.0f; bbox.expand( pt ); return bbox; }
void kgLocator::draw( M3dView & view, const MDagPath & path, M3dView::DisplayStyle style, M3dView::DisplayStatus status ) { MStatus stat; //First get the value of the height attribute //of the assocuated locator MObject thisNode = thisMObject(); MFnDagNode dagFn( thisNode ); MPlug heightPlug = dagFn.findPlug( height, &stat ); float heightValue; heightPlug.getValue( heightValue ); view.beginGL(); glPushAttrib( GL_CURRENT_BIT ); glBegin( GL_LINES ); //Draw a cross for(unsigned int i=0; i < pts.length(); i+= 2 ) { glVertex3f(pts[i].x, pts[i].y, pts[i].z ); glVertex3f(pts[i+1].x, pts[i+1].y, pts[i+1].z ); } //And a vertical spindle //of the same height as //the height attribute glVertex3f( 0.0f, 0.0f, 0.0f ); glVertex3f( 0.0f, heightValue, 0.0f ); glEnd(); glPopAttrib(); view.endGL(); }
int Material::bumpTexture(ostream& fout) const { MStatus status; int texbump = 0; MPlug bumpPlug = MFnDependencyNode(shaderNode).findPlug("normalCamera"); MItDependencyGraph dgIt(bumpPlug, MFn::kFileTexture, MItDependencyGraph::kUpstream, MItDependencyGraph::kBreadthFirst, MItDependencyGraph::kNodeLevel, &status); dgIt.disablePruningOnFilter(); if (!dgIt.isDone()) { // use a texture value MObject textureNode = dgIt.thisNode(); MPlug filenamePlug = MFnDependencyNode(textureNode).findPlug("fileTextureName"); MString textureName; filenamePlug.getValue(textureName); texbump = ++textureNum; fout << "Texture \"" << texbump << "\" \"float\" \"imagemap\" \"string filename\" [\"" << textureName.asChar() << "\"]" << endl; } return texbump; }
MStatus polyModifierCmd::cacheMeshData() { MStatus status = MS::kSuccess; MFnDependencyNode depNodeFn; MFnDagNode dagNodeFn; MObject meshNode = fDagPath.node(); MObject dupMeshNode; MPlug dupMeshNodeOutMeshPlug; // Duplicate the mesh // dagNodeFn.setObject( meshNode ); dupMeshNode = dagNodeFn.duplicate(); MDagPath dupMeshDagPath; MDagPath::getAPathTo( dupMeshNode, dupMeshDagPath ); dupMeshDagPath.extendToShape(); depNodeFn.setObject( dupMeshDagPath.node() ); dupMeshNodeOutMeshPlug = depNodeFn.findPlug( "outMesh", &status ); MCheckStatus( status, "Could not retrieve outMesh" ); // Retrieve the meshData // status = dupMeshNodeOutMeshPlug.getValue( fMeshData ); MCheckStatus( status, "Could not retrieve meshData" ); // Delete the duplicated node // MGlobal::deleteNode( dupMeshNode ); return status; }
//--------------------------------------------------- bool DagHelper::getPlugValue ( const MPlug& plug, MVector& value ) { MObject obj; plug.getValue ( obj ); MStatus status = plug.getValue ( obj ); COLLADABU_ASSERT ( status ); MFnNumericData data ( obj ); double x, y, z; status = data.getData ( x, y, z ); COLLADABU_ASSERT ( status ); value = MVector ( x,y,z ); return true; }
bool PxrUsdMayaWriteUtil::ReadMayaAttribute( const MFnDependencyNode& depNode, const MString& name, VtVec3fArray* val) { MStatus status; depNode.attribute(name, &status); if (status == MS::kSuccess) { MPlug plug = depNode.findPlug(name); MObject dataObj; if ( (plug.getValue(dataObj) == MS::kSuccess) && (dataObj.hasFn(MFn::kVectorArrayData)) ) { MFnVectorArrayData dData(dataObj, &status); if (status == MS::kSuccess) { MVectorArray arrayValues = dData.array(); size_t numValues = arrayValues.length(); val->resize(numValues); for (size_t i = 0; i < numValues; ++i) { (*val)[i].Set( arrayValues[i][0], arrayValues[i][1], arrayValues[i][2]); } return true; } } } return false; }
MStatus MeshParameterHandler::doSetValue( const MPlug &plug, IECore::ParameterPtr parameter ) const { IECore::ObjectParameterPtr p = IECore::runTimeCast<IECore::ObjectParameter>( parameter ); if( !p ) { return MS::kFailure; } MObject v; MStatus result = plug.getValue( v ); if( result ) { /// \todo Pull in userData from parameter to set up conversion parameters FromMayaMeshConverterPtr converter = boost::dynamic_pointer_cast< FromMayaMeshConverter > ( FromMayaObjectConverter::create( v, IECoreScene::MeshPrimitive::staticTypeId() ) ); assert(converter); converter->spaceParameter()->setNumericValue( (int)FromMayaMeshConverter::World ); p->setValue( converter->convert() ); return MS::kSuccess; } else { // technically we should be returning the error status here, but we don't // as this case appears to be pretty common, and the resulting errors tend to be // annoying rather than helpful. // // the failure to get the plug value appears to be because we don't save // empty mesh values to file (see ParameterisedHolder::shouldSave). // this means that when the file is loaded again the plug.getValue() // method will fail and we end up here. the best thing we can do in this // case seems to be to assume that the value should be an empty mesh. p->setValue( new IECoreScene::MeshPrimitive() ); return MS::kSuccess; } }
void ShaderFXShaderExporter::exportSamplerAndSurface(const MFnDependencyNode & node, const MObject & attr) { MStatus status; if (!attr.hasFn(MFn::kTypedAttribute)) return; MFnTypedAttribute fnTypedAttr(attr, &status); if (!status) return; MFnData::Type type = fnTypedAttr.attrType(&status); if (!status) return; if (type != MFnData::kString) return; MPlug plug = node.findPlug(attr, &status); MString value; status = plug.getValue(value); if (!status) return; if (value.length() == 0) return; bool isUsedAsFilename = MFnAttribute(attr).isUsedAsFilename(&status); if (!status) return; // Filename are treated as texture filenames. if (!isUsedAsFilename) return; exportSamplerAndSurfaceInner(value); }
void mpBox::draw( M3dView & view, const MDagPath & path, M3dView::DisplayStyle style, M3dView::DisplayStatus status ) { float xsize, ysize, zsize; MObject thisNode = thisMObject(); float r, g, b, a; float rotx, roty, rotz, ba; int lw, dt; MObject color; MObject rotate; _COMMON_ATTR_READ_; //zsize MPlug xsPlug = MPlug( thisNode, aXsize ); xsPlug.getValue( xsize ); //ysize MPlug ysPlug = MPlug( thisNode, aYsize ); ysPlug.getValue( ysize ); //zsize MPlug zsPlug = MPlug( thisNode, aZsize ); zsPlug.getValue( zsize ); //drawType MPlug drPlug = MPlug( thisNode, aDrawType ); drPlug.getValue( dt ); view.beginGL(); glPushMatrix(); glRotatef(rotx ,1.0,0.0,0.0); glRotatef(roty ,0.0,1.0,0.0); glRotatef(rotz ,0.0,0.0,1.0); glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); //draw Infront glDepthFunc(GL_LESS); glColor4f( r, g, b, a ); drawStyle(style, dt, lw); drawCube(xsize, ysize, zsize); //draw Behind glDepthFunc(GL_GREATER); glColor4f( r, g, b, ba ); drawStyle(style, dt, lw); drawCube(xsize, ysize, zsize); glPopAttrib(); glPopMatrix(); view.endGL(); }
AwVector ik2Bsolver::poleVectorFromHandle(const MDagPath &handlePath) // // This method returns the pole vector of the IK handle. // { MStatus stat; MFnIkHandle handleFn(handlePath, &stat); MPlug pvxPlug = handleFn.findPlug("pvx"); MPlug pvyPlug = handleFn.findPlug("pvy"); MPlug pvzPlug = handleFn.findPlug("pvz"); double pvxValue, pvyValue, pvzValue; pvxPlug.getValue(pvxValue); pvyPlug.getValue(pvyValue); pvzPlug.getValue(pvzValue); AwVector poleVector(pvxValue, pvyValue, pvzValue); return poleVector; }
//--------------------------------------------------- bool DagHelper::getPlugValue ( const MObject& node, const String attributeName, MString& value ) { MStatus status; MPlug plug = MFnDependencyNode ( node ).findPlug ( attributeName.c_str(), &status ); if ( status != MStatus::kSuccess ) return false; return plug.getValue ( value ); }
//--------------------------------------------------- bool DagHelper::getPlugValue ( const MPlug& plug, uint8& value ) { MStatus status; char temp; status = plug.getValue ( temp ); value = static_cast<uint8> ( temp ); return status == MStatus::kSuccess; }
//--------------------------------------------------- bool DagHelper::getPlugValue ( const MPlug& plug, bool& value ) { MStatus status; status = plug.getValue ( value ); if ( status != MStatus::kSuccess ) return false; return true; }
//--------------------------------------------------- bool DagHelper::getPlugValue ( const MPlug& plug, int& value ) { MDGContext context = MDGContext::fsNormal; MStatus status; status = plug.getValue ( value ); return status == MStatus::kSuccess; }
void AttributeParser::parseUnitAttribute(MFnDependencyNode & node, MObject & attr) { MStatus status; MFnUnitAttribute fnAttr(attr, &status); if (!status) return; MFnUnitAttribute::Type unitType = fnAttr.unitType(&status); if (!status) return; MPlug plug = node.findPlug(attr, &status); if (!status) return; MString name = fnAttr.name(&status); if (!status) return; switch (unitType) { case MFnUnitAttribute::kAngle: { MAngle angle; status = plug.getValue(angle); if (!status) return; onAngle(plug, name, angle); } break; case MFnUnitAttribute::kDistance: { MDistance distance; status = plug.getValue(distance); if (!status) return; onDistance(plug, name, distance); } break; case MFnUnitAttribute::kTime: { MTime time; status = plug.getValue(time); if (!status) return; onTime(plug, name, time); } break; } }
MBoundingBox mpBox::boundingBox() const { MObject thisNode = thisMObject(); float x, y, z; MPlug xsize = MPlug( thisNode, aXsize ); xsize.getValue(x); MPlug ysize = MPlug( thisNode, aYsize ); ysize.getValue(y); MPlug zsize = MPlug( thisNode, aZsize ); zsize.getValue(z); MPoint corner1(x, y, z); MPoint corner2(-x, -y, -z); MBoundingBox bbox = MBoundingBox( corner1, corner2 ); return bbox; }
MStatus ObjectParameterHandler::doSetValue( const MPlug &plug, IECore::ParameterPtr parameter ) const { IECore::ObjectParameterPtr p = IECore::runTimeCast<IECore::ObjectParameter>( parameter ); if( !p ) { return MS::kFailure; } /// Keep trying all the available handlers until we find one that works for (IECore::ObjectParameter::TypeIdSet::const_iterator it = p->validTypes().begin(); it != p->validTypes().end(); ++it) { ConstParameterHandlerPtr h = ParameterHandler::create( *it ); if (h) { if ( h->doSetValue( plug, parameter ) ) { return MS::kSuccess; } } } MStatus s; MObject plugData; s = plug.getValue( plugData ); if (!s) { // We might be here as the attribute isn't storable, // in that case we set the parameter to its default value. // If it is storable, then something has gone awry. MFnAttribute fnA( plug.attribute() ); bool isStorable = fnA.isStorable( &s ); if( s && !isStorable ) { parameter->setValue( parameter->defaultValue()->copy() ); return MS::kSuccess; } else { return MS::kFailure; } } MFnPluginData fnData( plugData, &s ); if (!s) { return MS::kFailure; } ObjectData *data = dynamic_cast<ObjectData *>( fnData.data( &s ) ); if (!data || !s) { return MS::kFailure; } parameter->setValue( data->getObject() ); return MS::kSuccess; }
void AttributeParser::parseMessageAttribute(MFnDependencyNode & node, MObject & attr) { MStatus status; MFnMessageAttribute fnMessageAttribute(attr, &status); if (!status) return; MPlug plug = node.findPlug(attr, &status); if (!status) return; MString str; status = plug.getValue(str); MObject obj; status = plug.getValue(obj); // TODO, see parseMatrixAttribute? }
// This function is a utility that can be used to extract vector values from // plugs. // MVector vectorPlugValue(const MPlug& plug) { if (plug.numChildren() == 3) { double x,y,z; MPlug rx = plug.child(0); MPlug ry = plug.child(1); MPlug rz = plug.child(2); rx.getValue(x); ry.getValue(y); rz.getValue(z); MVector result(x,y,z); return result; } else { MGlobal::displayError("Expected 3 children for plug "+MString(plug.name())); MVector result(0,0,0); return result; } }
MStatus unShowAvailableSystems::findAvailableSystems(std::string& str,MDagPath& dagPath) { MStatus stat = MS::kSuccess; if(dagPath.hasFn(MFn::kJoint)) { MFnIkJoint jointFn(dagPath); std::string name = dagPath.partialPathName().asChar(); MPlug plug = jointFn.findPlug("unRibbonEnabled"); if(!plug.isNull()) { bool enabled; plug.getValue(enabled); char s[256]; sprintf(s,"%s RibbonSystem %s\n",name.c_str(),enabled ? "True" : "False"); str += s; } plug = jointFn.findPlug("unParticleEnabled"); if(!plug.isNull()) { bool enabled; plug.getValue(enabled); char s[256]; sprintf(s,"%s ParticleSystem %s\n",name.c_str(),enabled ? "True" : "False"); str += s; } } for (unsigned int i = 0; i < dagPath.childCount(); i++) { MObject child = dagPath.child(i); MDagPath childPath; stat = MDagPath::getAPathTo(child,childPath); if (MS::kSuccess != stat) { return MS::kFailure; } stat = findAvailableSystems(str,childPath); if (MS::kSuccess != stat) return MS::kFailure; } return MS::kSuccess; }