// initializes attribute information MStatus shiftNode::initialize() { MStatus stat; MFnNumericAttribute nAttr; // shift aShift = nAttr.create( "shift", "sh", MFnNumericData::kBoolean, false ); stat = addAttribute( aShift ); PERRORfail( stat, "addAttribute shift" ); // distance aDist = nAttr.create( "distance", "dis", MFnNumericData::kFloat, 0.0 ); stat = addAttribute( aDist ); PERRORfail( stat, "addAttribute dist" ); // inColor aColor = nAttr.createColor( "color", "c" ); nAttr.setStorable(false); stat = addAttribute( aColor ); PERRORfail( stat, "addAttribute inColor" ); // refPointCamera aRefPointCamera = nAttr.createPoint( "refPointCamera", "rpc" ); nAttr.setStorable(false); nAttr.setWritable(true); nAttr.setRenderSource(true); nAttr.setHidden(true); stat = addAttribute( aRefPointCamera ); PERRORfail( stat, "addAttribute refPointCamera" ); // uv MObject u = nAttr.create( "uCoord", "u", MFnNumericData::kFloat, 0.0 ); MObject v = nAttr.create( "vCoord", "v", MFnNumericData::kFloat, 0.0 ); aUv = nAttr.create( "uvCoord", "uv", u, v ); nAttr.setStorable(false); nAttr.setWritable(true); nAttr.setRenderSource(true); nAttr.setHidden(true); stat = addAttribute( aUv ); PERRORfail( stat, "addAttribute uv" ); // create output attributes here aOutColor = nAttr.createColor( "outColor", "oc" ); PERRORfail(stat, "initialize create outColor attribute"); nAttr.setReadable( true ); nAttr.setWritable( false ); stat = addAttribute( aOutColor ); PERRORfail(stat, "addAttribute(outColor)"); // attribute affects attributeAffects ( aShift, aOutColor ); attributeAffects ( aDist, aOutColor ); attributeAffects ( aColor, aOutColor ); attributeAffects ( aRefPointCamera, aOutColor ); attributeAffects ( aUv, aOutColor ); // we need to do the followings to cause other input attributes // to evaluate with the new values we set attributeAffects ( aUv, aUv ); attributeAffects ( aRefPointCamera, aRefPointCamera ); return MS::kSuccess; }
bool DXMAnchor::AddAnchor(MObject& site, const MString& longAnchorName, const MString& shortAnchorName, DXMAnchor* anchor) { DXCC_ASSERT( DXMAnchor::GetAnchor(site, shortAnchorName) == NULL ); DXCC_ASSERT(anchor != NULL); DXCC_ASSERT(anchor->GetSite().isNull()); DXCC_ASSERT(anchor->GetPoint().length() == 0); DXCC_ASSERT(longAnchorName.length() > 0); DXCC_ASSERT(shortAnchorName.length() > 0); DXCC_ASSERT(!site.isNull()); MFnDependencyNode depNode(site); MString name= depNode.name(); #ifdef DEBUG anchor->Name= name.asChar(); #endif if( g_DebugBasic ) { DXCC_DPFA_REPORT("%s", name.asChar()); } //this attribute may exist if you had asked for this node to be duplicated or instanced :( if( depNode.attribute( shortAnchorName ).isNull() ) { MFnNumericAttribute numeric; MObject anchorAttrib= numeric.create(longAnchorName, shortAnchorName, MFnNumericData::kInt, 0); numeric.setReadable(false); numeric.setWritable(false); numeric.setConnectable(false); numeric.setStorable(false); numeric.setCached(true); numeric.setArray(false); numeric.setKeyable(false); numeric.setHidden(true); numeric.setUsedAsColor(false); numeric.setIndeterminant(true); numeric.setRenderSource(false); numeric.setInternal(false); DXCC_ASSERT(!anchorAttrib.isNull()); DXCHECK_MSTATUS( depNode.addAttribute(anchorAttrib) ); } MPlug anchorPlug= depNode.findPlug( shortAnchorName ); DXCC_ASSERT(!anchorPlug.isNull()); anchorPlug.setValue( *reinterpret_cast<int*>(&anchor) ); anchor->AnchorSite= site; anchor->AnchorPoint= shortAnchorName; // anchor->NodeDestroyedCID= MNodeMessage::addNodeDestroyedCallback(site, DXMAnchor::DispatchNodeDestroyed, anchor); // anchor->AboutToDeleteCID= MNodeMessage::addNodeAboutToDeleteCallback(site, DXMAnchor::DispatchAboutToDelete, anchor); anchor->OnPostAddAnchor(longAnchorName, shortAnchorName); return true; }
static MStatus initialize() { // set up uder-defined attribute MFnNumericAttribute numericAttrFn; MFnGenericAttribute genericAttrFn; // enable thie node aEnable = numericAttrFn.create( "enbale", "e", MFnNumericData::kBoolean, 0, &status ); CHECK_MSTATUS(status); numericAttrFn.setDefault(0); numericAttrFn.setKeyable(true); addAttribute(aEnable); // enable when rendering aEnableRender = numericAttrFn.create( "enbaleAsRendering", "er", MFnNumericData::kBoolean, 0, &status ); CHECK_MSTATUS(status); numericAttrFn.setDefault(0); numericAttrFn.setKeyable(true); addAttribute(aEnableRender); // Inputs // // input color aColor = numericAttrFn.createColor( "Color", "c", &status ); CHECK_MSTATUS(status); numericAttrFn.setDefault( 0.0, 0.5, 0.0); addAttribute(aColor); // enable supersampling aIsSpuersampling = numericAttrFn.create( "supersampling", "ssp", MFnNumericData::kBoolean, 0, &status ); CHECK_MSTATUS(status); numericAttrFn.setDefault(1); numericAttrFn.setKeyable(true); addAttribute(aIsSpuersampling); // filter size /* aFSize = numericAttrFn.create( "filterSize", "fs", MFnNumericData::k3Float, 0.0, &status ); CHECK_MSTATUS(status); numericAttrFn.setMin( 0.0, 0.0, 0.0 ); numericAttrFn.setMax( 10.0, 10.0, 10.0 ); numericAttrFn.setDefault( 1.0, 1.0, 1.0 ); addAttribute(aFSize); */ // filter size aFilterSize = numericAttrFn.create( "filterSizes", "fls", MFnNumericData::k2Int, 0, &status ); CHECK_MSTATUS(status); numericAttrFn.setMin( 0, 0 ); numericAttrFn.setMax( 10, 10 ); numericAttrFn.setDefault( 0, 0 ); addAttribute(aFilterSize); // sample offset aOffsetSample = numericAttrFn.create( "sampleOffset", "ao", MFnNumericData::kFloat, 0.0 , &status ); CHECK_MSTATUS(status); numericAttrFn.setSoftMin( 0.0f ); numericAttrFn.setSoftMax( 0.1f ); numericAttrFn.setDefault( 0.01f); addAttribute(aOffsetSample); // UV coordinate MObject uCoord = numericAttrFn.create( "uCoord", "u", MFnNumericData::kDouble ); MObject vCoord = numericAttrFn.create( "vCoord", "v", MFnNumericData::kDouble ); aUVCoord = numericAttrFn.create( "uvCoord", "uv", uCoord, vCoord, MObject::kNullObj, &status); CHECK_MSTATUS(status); numericAttrFn.setHidden(true); numericAttrFn.setRenderSource(true); addAttribute(aUVCoord); // UV filter size MObject sUVFilterSizeX = numericAttrFn.create( "uvFilterSizeX", "ufx", MFnNumericData::kFloat ); MObject sUVFilterSizeY = numericAttrFn.create( "uvFilterSizeY", "ufy", MFnNumericData::kFloat ); aUVFilterSize = numericAttrFn.create( "uvFilterSize", "uf", sUVFilterSizeX, sUVFilterSizeY, MObject::kNullObj, &status ); CHECK_MSTATUS(status); numericAttrFn.setHidden(true); addAttribute(aUVFilterSize); // World-space position aPointWorld = numericAttrFn.createPoint( "pointWorld", "pw", &status ); CHECK_MSTATUS(status); numericAttrFn.setHidden(true); addAttribute(aPointWorld); // input Shape as the source aShape = genericAttrFn.create( "sourceShape", "s", &status ); //genericAttrFn.addDataAccept( MFnData::kNurbsSurface ); genericAttrFn.addAccept( MFnData::kNurbsSurface ); genericAttrFn.addAccept( MFnData::kMesh ); CHECK_MSTATUS(status); addAttribute(aShape); // target shape aTargetShape = genericAttrFn.create( "targetShape", "ts", &status ); //genericAttrFn.addDataAccept( MFnData::kNurbsSurface ); genericAttrFn.addAccept( MFnData::kNurbsSurface ); genericAttrFn.addAccept( MFnData::kMesh ); CHECK_MSTATUS(status); addAttribute(aTargetShape); // output // // output color aOutColor = numericAttrFn.createColor( "outColor", "oc", &status); CHECK_MSTATUS(status); numericAttrFn.setWritable(false); addAttribute(aOutColor); // affect Attribute //attributeAffects( aFSize, aOutColor ); attributeAffects( aEnable, aOutColor ); attributeAffects( aEnableRender, aOutColor ); attributeAffects( aColor, aOutColor ); attributeAffects( aIsSpuersampling, aOutColor ); attributeAffects( aFilterSize, aOutColor ); attributeAffects( aOffsetSample, aOutColor ); attributeAffects( aUVCoord, aOutColor ); attributeAffects( aUVFilterSize, aOutColor ); attributeAffects( aPointWorld, aOutColor ); attributeAffects( aShape, aOutColor ); attributeAffects( aTargetShape, aOutColor ); attributeAffects( aUVCoord, aUVCoord ); return MS::kSuccess; }