RifPlugin C++
Quick Reference I


return to main index



Querying ?

identifier:name
getMayaProjPath
getting the scene name

Editing E

Adding +

Attribute (camera vis)
Attribute (user)
Patch (bilinear)
Comments

Removing -

##rifcontrol
__handleid




?    Attribute "identifier" "string name" ["KeyLightShape"]


#include <string>
#include <RixInterfaces.h>
// Returns the name of the transform or shape that is currently
// in scope. For example,
//     Attribute "identifier" "string name" ["KeyLightShape"]
// would be returned as "KeyLightShape".
std::string ExportLook::getIdentifierName() {
    char    *resultStr = 0;
    RtInt    resultCount, resultError, resultLen = sizeof(char*);
    RixRenderState::Type resultType;
    resultError = m_rstate->GetAttribute("identifier:name", &resultStr, resultLen,
                        &resultType, &resultCount);
    if(resultStr == NULL)
        return std::string("");
    std::string str(resultStr);
    return str;
    }

?    Option "user" "string RMSPROJ" ["/home/jdoe/maya/projects/rif_dev/"]


#include <string>
#include <RixInterfaces.h>
// Returns "/home/jdoe/maya" or, one Windows, "H:/maya".
std::string ExportLook::getMayaProjPath() {
    char    *resultStr = 0;
    RtInt    resultCount, resultError, resultLen = sizeof(char*);
    RixRenderState::Type resultType;
    resultError = m_rstate->GetOption("user:RMSPROJ", &resultStr, resultLen, 
                                   &resultType, &resultCount);
    if(resultStr == NULL)
        return std::string("");
    std::string str(resultStr);
    return str;
    }

?    Getting the Scene Name


#include <string>
//-----------------------------------------------------
// displayV
//-----------------------------------------------------
// Callback version of "RiDisplayV". Only the first arg is of interest because it
// contains the name of the scene immediately after "renderman".
std::string    ExportLook::displayV(char *name, RtToken type, RtToken mode, RtInt num, RtToken tokens[], RtPointer params[]) {
    // Pass through...
    RiDisplayV(name, type, mode, num, tokens, params);
    ExportLook *self = static_cast<ExportLook*> (RifGetCurrentPlugin());
    
    std::vector <std::string> parts = self->tokenize(name, RtToken("/"));
    if(parts.size() >= 2)
        return parts[1];
    else
        return std::string("unknown_scene_name");
    }
  
//-----------------------------------------------------
// Utility - tokenize
//-----------------------------------------------------
std::vector <std::string> ExportLook::tokenize(char *input, RtToken sep) {
    std::vector <std::string> out;
    char *ptr = strtok(input, sep);
    while(ptr) {
        out.push_back(std::string(ptr));
        ptr = strtok(NULL, sep);
        }
    return out;
    }


+    Attribute "visibility" "camera" [0]


#include <ri.h>
#include <rx.h>
#include <RixInterfaces.h>
// Adds a camera visibility attribute to the output rib stream.
// Note the use of the RI_VISIBILITY token.
RixContext      *rix = RxGetRixContext();
RixTokenStorage *tok_store = static_cast<RixTokenStorage*>(
                 rix->GetRixInterface(k_RixGlobalTokenData));
  
RtToken   tok = (char*)tok_store->GetToken("int camera");
RtToken   visToken[] = {tok};
RtInt     visFlag = 0;
RtPointer visValue[] = { &visFlag };
RiAttributeV(RI_VISIBILITY, 1, visToken, visValue);


+    Attribute "user" "color tint" [1 1 0]


#include <ri.h>
#include <rx.h>
#include <RixInterfaces.h>
// Adds a color user attribute to the output rib stream.
// Note the use of the RI_USER token.
RixContext      *rix = RxGetRixContext();
RixTokenStorage *tok_store = static_cast<RixTokenStorage*>(
                 rix->GetRixInterface(k_RixGlobalTokenData));
 
RtToken   tok = (char*)tok_store->GetToken("color tint");
RtToken   userToken[] = { tok };
RtColor   userRGB = { 1,1,0 };
RtPointer userValue[] = { &userRGB };
RiAttributeV(RI_USER, 1, userToken, userValue);


+    Patch "bilinear" "P" [0.5 -0.5 0 0.5 0.5 0 -0.5 -0.5 0 -0.5 0.5 0]


#include <ri.h>
// Adds a 1 x 1 bilinear patch to the output rib stream.
// Note the use of the RI_P and RI_BILINEAR tokens.
RtPoint   p[] = {{0.5,-0.5,0},{0.5,0.5,0},{-0.5,-0.5,0},{-0.5,0.5,0}};
RtPointer data[] = { &p };    
RtToken   t[] = {RI_P};
RiPatchV(RI_BILINEAR, 1, t, data); 


+    Comments


#include <ri.h>
// Inserting a comment only makes sense when catrib'ing ie. 
//    prman -rif "PATH_TO_DSO" -rifargs "SOME_ARGS" -rifend "PATH_TO_RIB"
// Declare the methods as follows,
//    static RtVoid  insertComment(const char *str);
//    static RtVoid  insertComment(std::string str);
void YOUR_RIF::insertComment(const char *str) { 
    RiArchiveRecord(RI_COMMENT, (char*)str); 
    }
void YOUR_RIF::insertComment(std::string str) { 
    RiArchiveRecord(RI_COMMENT, (char*)str.c_str()); 
    }


--    ##rifcontrol insert begin -rif RLFInjector -rifend


    [See StripRifControl.cpp]


#include <ri.h>
  
RtVoid RifBase::archiverecord(RtToken type, char* format, va_list vlist) {
    char buffer[512];
    vsnprintf(buffer, 512, format, vlist);
    if(type == RI_STRUCTURE || strcmp(type, RI_STRUCTURE) == 0)
        if(strncmp(buffer, RI_RIFCONTROL, 10) == 0)
            return;
    RiArchiveRecord(type, format, buffer);
    }


-- Removing a Shader Parameter


#include <ri.h>
// Declare this method as follows,
//    static RtLightHandle  lightsource(RtToken name, RtInt, RtToken[], RtPointer[]);
// In the constructor of your rif class assign it to your filter as follows,
//    m_filter.LightSourceV = lightsource;
RtLightHandle YOUR_RIF::lightsource(RtToken name, RtInt num, 
                                                  RtToken names[], 
                                                  RtPointer values[]) {    
    char        target[] = "__handleid";
    RtToken     tokCopies[num];
    RtPointer   tokValues[num];
    int         index = 0;
    
    // Get copies of the lightsource parameters except "__handleid".
    for (int i = 0; i < num; ++i) {
        // First compare their pointer addresses then their values as strings
        if(names[i] != RI_HANDLEID || strcmp(names[i], target) != 0) {
            tokCopies[index] = names[i];
            tokValues[index] = values[i];
            index++;
            }
        }
    // Other code omitted
    }



© 2002- Malcolm Kesson. All rights reserved.