Jump to content

Did anyone write sop_mycircle code?


Recommended Posts

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
Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

  • 2 weeks later...
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...