[Maya C++ API] paint weights with MPxDeformer

/* Weight map
 * ==========
 *
 * MPxDeformerNode provide scalar weight maps through the attribute
 * `.weightList[index].weights`
 * this allows the user to partially apply the deformer.
*/


MStatus My_custome_MPxDeformerNode::initialize()
{
    try
    {
        // -------
        // By default MPxDeformerNode provide per vertex weights through the
        // built in attribute weight. The following makes those weights paintable
        MString cmd = "makePaintable -attrType multiFloat -sm deformer ";
        cmd += _s_name;
        cmd += " weights;";
        MGlobal::executeCommand(cmd, true);
    }
    catch (std::exception& e)
    {
        maya_print_error( e );
        return MS::kFailure;
    }
    return MStatus::kSuccess;
}

// --------------------------------------

MStatus Dfm_node::deform(
        MDataBlock& block,
        MItGeometry& geom_it,
        const MMatrix& object_matrix,
        unsigned int multi_index)
{
    try
    {
        MStatus status;        

        while( !geom_it.isDone() )
        {
            int idx = geom_it.index(&status);
            mayaCheck(status);
            // Increment the point along the vertex normal.
            MPoint point = geom_it.position() * object_matrix;
            _vertex_buffer[idx] = to_vec3( point );
            float f = weightValue(block, multi_index, geom_it.index() );
            _weight_buffer[idx] = f;
            geom_it.next();
        }

        process_vertices(_vertex_buffer, _weight_buffer);

        MMatrix object_inv_matrix = object_matrix.inverse();
        mayaCheck( geom_it.reset() );
        while( !geom_it.isDone() )
        {            
            MPoint point = geom_it.position() * object_matrix;
            double t = double(envelope_val);
            MPoint new_point = to_MPoint( _vertex_buffer[geom_it.index()] ) * t + point * (1.0-t);
            geom_it.setPosition(new_point * object_inv_matrix);
            geom_it.next();
        }

    }
    catch (std::exception& e)
    {
        maya_print_error( e );
        return MS::kFailure;
    }

    return MStatus::kSuccess;
}


To switch to paint mode in maya, select the mesh create the deformer and call the mel procedure ArtPaintAttrTool();

No comments

All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.
Spam bot question: