Jump to content
Sign in to follow this  
vfxdli

Did anyone write sop_mycircle code?

Recommended Posts

Posted (edited)

I can follow the code written in Tutorial and can be compiled. Parameter can be created. However, there is no way to create an attribute.

mycircle.h

#include <SOP\SOP_Circle.h>
#include <OP/OP_Parameters.h>
class SOP_MyCircle : public SOP_Circle {
public:
    SOP_MyCircle(OP_Network *net, const char *, OP_Operator *op);
    static OP_Node *MyConstructor(OP_Network *net, const char *name, OP_Operator *op);
    static OP_TemplatePair *buildTemplatePair();

protected:
    OP_ERROR cookMySop(OP_Context &context);
private:
    fpreal    COLORX(fpreal t) { return evalFloat("color", 0, 0); }
    fpreal    COLORY(fpreal t) { return evalFloat("color", 1, 0); }
    fpreal    COLORZ(fpreal t) { return evalFloat("color", 2, 0); }
};

mycircle.cpp

#include <UT/UT_DSOVersion.h>
#include <OP/OP_OperatorTable.h>
#include <OP/OP_Operator.h>
#include <OP/OP_Context.h>
#include <OP/OP_Network.h>
#include <SOP/SOP_Node.h>
#include "mycircle.h"
#include <stdio.h>
static PRM_Name        colorName("color", "Color");

static PRM_Default    colorDefaults[] = {
    PRM_Default(1),    //r
    PRM_Default(0),    //g
    PRM_Default(2) //b
};
static PRM_Template newParmsTemplates[] = {
    PRM_Template(PRM_RGB, 3, &colorName, colorDefaults),
    PRM_Template()
};
OP_Node *SOP_MyCircle::MyConstructor(OP_Network *net, const char *name, OP_Operator *op)
{
    return new SOP_MyCircle(net, name, op);
}
SOP_MyCircle::SOP_MyCircle(OP_Network *net, const char *name, OP_Operator *op):SOP_Circle(net, name, op)
{
}
OP_TemplatePair *SOP_MyCircle::buildTemplatePair() {
    OP_TemplatePair *old, *my;
    my = new OP_TemplatePair(newParmsTemplates, 0);
    old = new OP_TemplatePair(SOP_Circle::myTemplateList, my);
    return old;
}
OP_ERROR 
SOP_MyCircle::cookMySop(OP_Context &context) {
    SOP_Circle::cookMySop(context);
    fpreal now = context.getTime();
    fpreal clr_r = COLORX(now);
    fpreal clr_g = COLORY(now);
    fpreal clr_b = COLORZ(now);

    GA_Attribute *cd_attr = gdp->addFloatTuple(GA_ATTRIB_PRIMITIVE,"Cd",3);
    GA_RWHandleV3 h(cd_attr);
    GA_Offset off = 0;
    h.set(off, UT_Vector3(clr_r, clr_g, clr_b));

    return error(); 
}
void newSopOperator(OP_OperatorTable *table)
{
    table->addOperator(
        new OP_Operator("myCircle",
        "myCircle",
        SOP_MyCircle::myConstructor,
        SOP_MyCircle::buildTemplatePair(),
        0,
        0)
        );
}

mycircle.cpp

Edited by vfxdli

Share this post


Link to post
Share on other sites

You call SOP_Circle::cookMySop in your SOP_myCircle::cookMySop method. It's a virtual method, so you just have to override it. So remove your call to the baseclass cookMySop and I think you should be done and get your attribute.

Share this post


Link to post
Share on other sites
On 2018/6/23 at 5:09 AM, Yannci said:

You call SOP_Circle::cookMySop in your SOP_myCircle::cookMySop method. It's a virtual method, so you just have to override it. So remove your call to the baseclass cookMySop and I think you should be done and get your attribute.

  • Thank you very much for solving my problem

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×