// // Description: // // Component/attribute matching method. // This method validates component names and indices which are // specified as a string and adds the corresponding component // to the passed in selection list. // // For instance, select commands such as "select shape1.vtx[0:7]" // are validated with this method and the corresponding component // is added to the selection list. // // Arguments // // item - DAG selection item for the object being matched // spec - attribute specification object // list - list to add components to // // Returns // // the result of the match // public override MatchResult matchComponent(MSelectionList item, MAttributeSpecArray spec, MSelectionList list) { MatchResult result = MatchResult.kMatchOk; MAttributeSpec attrSpec = spec[0]; int dim = attrSpec.dimensions; // Look for attributes specifications of the form : // vtx[ index ] // vtx[ lower:upper ] // if ( (1 == spec.length) && (dim > 0) && (attrSpec.name == "vtx") ) { int numVertices = (int)meshGeom().vertices.length; MAttributeIndex attrIndex = attrSpec[0]; int upper = 0; int lower = 0; if ( attrIndex.hasLowerBound ) { attrIndex.getLower( out lower ); } if ( attrIndex.hasUpperBound ) { attrIndex.getUpper( out upper ); } // Check the attribute index range is valid // if ( (lower > upper) || (upper >= numVertices) ) { result = MatchResult.kMatchInvalidAttributeRange; } else { MDagPath path = new MDagPath(); item.getDagPath( 0, path ); MFnSingleIndexedComponent fnVtxComp = new MFnSingleIndexedComponent(); MObject vtxComp = fnVtxComp.create( MFn.Type.kMeshVertComponent ); for ( int i=lower; i<=upper; i++ ) { fnVtxComp.addElement( i ); } list.add( path, vtxComp ); } } else { // Pass this to the parent class return base.matchComponent( item, spec, list ); } return result; }
public override MatchResult matchComponent(MSelectionList item, MAttributeSpecArray spec, MSelectionList list) // // Description: // // Component/attribute matching method. // This method validates component names and indices which are // specified as a string and adds the corresponding component // to the passed in selection list. // // For instance, select commands such as "select shape1.vtx[0:7]" // are validated with this method and the corresponding component // is added to the selection list. // // Arguments // // item - DAG selection item for the object being matched // spec - attribute specification object // list - list to add components to // // Returns // // the result of the match // { MatchResult result = MatchResult.kMatchOk; MAttributeSpec attrSpec = spec[0]; int dim = attrSpec.dimensions; // Look for attributes specifications of the form : // vtx[ index ] // vtx[ lower:upper ] // if ( (1 == spec.length) && (dim > 0) && (attrSpec.name == "vtx") ) { int numVertices = (int)meshGeom().vertices.length; MAttributeIndex attrIndex = attrSpec[0]; int upper = 0; int lower = 0; if ( attrIndex.hasLowerBound ) { attrIndex.getLower( out lower ); } if ( attrIndex.hasUpperBound ) { attrIndex.getUpper( out upper ); } // Check the attribute index range is valid // if ( (lower > upper) || (upper >= numVertices) ) { result = MatchResult.kMatchInvalidAttributeRange; } else { MDagPath path = new MDagPath(); item.getDagPath( 0, path ); MFnSingleIndexedComponent fnVtxComp = new MFnSingleIndexedComponent(); MObject vtxComp = fnVtxComp.create( MFn.Type.kMeshVertComponent ); for ( int i=lower; i<=upper; i++ ) { fnVtxComp.addElement( i ); } list.add( path, vtxComp ); } } else { // Pass this to the parent class return base.matchComponent( item, spec, list ); } return result; }