RifPlugin
Blobby2Volume


return to main index



Introduction

Although Maya and Houdini can output a particle system as a RenderMan Blobby neither can "mark" the Blobby they create as a volume primitive. A Blobby is rendered as a volume if its list of opcodes begins with an "8". For example, the first Blobby defines a iso-surface.

    Blobby 3
        [1001 0
         1001 16
         1001 32
         0 3   0 1 2]
        [1 0 0 0  0 1 0 0  0 0 1 0 -0.5  0.2  0.0 1
         1 0 0 0  0 1 0 0  0 0 1 0  0.9  0.5  0.0 1
         1 0 0 0  0 1 0 0  0 0 1 0  0.5 -0.5  0.0 1]
        [""] "Cs" [1 0 1  0 1 1   1 1 0]


Figure 1 - Blobby rendered as a (iso) surface


The second Blobby has the opcode "8" and consequently is rendered volumetrically - figure 2.

    Blobby 3
        [8
         1001 0
         1001 16
         1001 32
         0 3   0 1 2]
        [1 0 0 0  0 1 0 0  0 0 1 0 -0.5  0.2  0.0 1
         1 0 0 0  0 1 0 0  0 0 1 0  0.9  0.5  0.0 1
         1 0 0 0  0 1 0 0  0 0 1 0  0.5 -0.5  0.0 1]
        [""] "Cs" [1 0 1  0 1 1   1 1 0]


Figure 2 - Blobby rendered as a volume


The rif given in listing 1 merely adds the "8" opcode to the list of existing opcodes for each Blobby it "processes".


Listing 1 (Blobby2Volume.cpp)


#include <RifPlugin.h>
#include <RifFilter.h>
  
class Blobby2Volume : public RifPlugin {
    public:
             Blobby2Volume();
    virtual ~Blobby2Volume() { }    
    virtual RifFilter &GetFilter() { return m_filter; }
    
    private:
        RifFilter   m_filter;
        static RtVoid blobbyV(RtInt nleaf, RtInt ncode, RtInt code[], 
                        RtInt nfloats, RtFloat floats[], RtInt nstr, RtToken str[], 
                        RtInt paramNum, RtToken paramNames[], RtPointer paramVals[]);
    };
  
RifPlugin *RifPluginManufacture(int argc, char **argv) {
    return new Blobby2Volume();
    }
    
// Constructor
Blobby2Volume::Blobby2Volume() {
    m_filter.BlobbyV = blobbyV;  // install our custom callback
    m_filter.Filtering = RifFilter::k_Continue;
    }
  
RtVoid Blobby2Volume::blobbyV(RtInt nleaf, RtInt ncode, RtInt code[], 
                                RtInt nfloats, RtFloat floats[], RtInt nstr, RtToken str[], 
                                RtInt paramNum, RtToken paramNames[], RtPointer paramVals[]) {
    RtInt newcode[ncode + 1];
    // Begin a new array of opcode starting with "8" then add 
    // the original opcodes.
    newcode[0] = 8;
    for(int n = 0; n < ncode; n++)
        newcode[n+1] = code[n];
    if(paramNum == 0)
        RiBlobby(nleaf, ncode + 1, newcode, nfloats, floats, nstr, str, RI_NULL);
    else
        RiBlobbyV(nleaf, ncode + 1, newcode, nfloats, floats, nstr, str, paramNum, paramNames, paramVals);
    }


Creating Blobby2Volume.so

1   Save the source code as Blobby2Volume.cpp.
2   Open the document in Cutter.
3   Use alt+e, control+e or apple+e to compile and link the .so file.






© 2002- Malcolm Kesson. All rights reserved.