Tool Button

Implementing tool button is described in the previous tutorial. The only difference is in the R3TOOLM_ACTION method, which should create a deformer object instead of a sphere.

Extension Method

The code would look as follows:


    #include <real/layer/r3prilay.h>

    static void geomdeformem_new(R3OBJ *primlayer, void *p1, void *p2, void *p3)
    {
        R3OBJ *gd = R3New(R3CLID_GEOMDEFORM,
                          R3RA_Name, "my geom deform",
                          R3TAG_END);
        if(gd) 
            R3Do(primlayer, R3OLAYM_INSERT, gd);
    }

    R3ClassAddExtensionMethod(R3CLID_PRIMLAYER, "geomdeform_new", geomdeformem_new);

The R3TOOLM_ACTION method should then look something like below:


    static void *r3toolm_action(R3CLASS *cl, R3OBJ *obj)
    {
        R3IDATA *self = R3CL_IADDR(cl, obj);
        R3OBJ *layer, *primlayer;

        R3GetAttrs(obj, R3TOOLA_Layer, &layer, R3TAG_END);
        if (layer) {
            R3GetAttrs(layer, R3LAYA_Prims, &prims, R3TAG_END);
	    if(prims) {
	        R3DoA(prims, R3OLAYM_LOCKEXCLUSIVE, NULL);
                R3DoE3(prims, "geomdeformem_new", NULL, NULL, NULL);
                R3DoA(prims, R3OLAYM_RELEASE);
            }
        }
    }

Note that the layer must be locked with exclusive lock, because we are modifying the layer.

It is highly recommended that you support also the macro system. The only change you have to do to achieve this is by calling the layer methods through the macro system, as follows:


    #iclude <real/code/r3maccl.h>

    static void *r3toolm_action(R3CLASS *cl, R3OBJ *obj, R3INT event)
    {
        R3IDATA *self = R3CL_IADDR(cl, obj);
        R3OBJ *layer, *primlayer;

        R3GetAttrs(obj, R3TOOLA_Layer, &layer, R3TAG_END);
        if (layer) {
            R3GetAttrs(layer, R3LAYA_Prims, &prims, R3TAG_END);
            if(prims) {
                R3MAC_SNDMSGA(app, "R3CurrentPrims", prims, R3OLAYM_LOCKEXCLUSIVE, NULL, R3MCTP_INT);
                R3MAC_SNDEMSGA3(app, "R3CurrentPrims", prims, "geomdeforem_new",
                                0, R3MCTP_INT,  // p1
                                0, R3MCTP_INT,  // p2 
                                0, R3MCTP_INT); // p3
                R3MAC_SNDMSGA(app, "R3CurrentPrims", prims, R3OLAYM_RELEASE, NULL, R3MCTP_INT);
            }
        }
        return (void*)TRUE;
    }

This way the user will be record a macro that executes your tool.