pyrochlore Posted March 24, 2014 Share Posted March 24, 2014 Hi all, This is a double post from the official forum because I got no response after one week there. I want to make a custom SHOP in HDK. The SHOP should be able to accept a series of custom VOP (limited in this context) and retrieve the information from the network of children VOP. Then the retrieved information could be acquired by SOHO program called by custom ROP. In Short, it is like "Material Shader Builder" in Mantra. Is there any example or instruction on this topic? I have searched HDK and only find headers about SHOP, there are so many virtual function not fully explained inside. I really need some advises. Thanks. Quote Link to comment Share on other sites More sharing options...
pyrochlore Posted March 24, 2014 Author Share Posted March 24, 2014 (edited) Hi all, Let me start from scratch.I made a simplest SHOP node. -------- code start ---------In header file test.h class My_Surface_Shader_Builder : public SHOP_Node { public: static OP_Node *myConstructor( OP_Network *net, const char *name, OP_Operator *entry); static PRM_Template myTemplateList[]; virtual OP_ERROR cookMe(OP_Context &context); protected: My_Surface_Shader_Builder( OP_Network *net, const char *name, OP_Operator *entry, SHOP_TYPE shop_type); virtual ~My_Surface_Shader_Builder(); }; in test.C file voidnewShopOperator(OP_OperatorTable *table){ cout<<"adding My_Surface_Shader_Builder to operator table\n"; OP_Operator *op; op = new OP_Operator("my_vopsurface", // internal name"My Surface Shader Builder", // UI labelMy_Surface_Shader_Builder::myConstructor, // class factoryMy_Surface_Shader_Builder::myTemplateList, // parm definitions0, 0); table->addOperator(op); cout<<"My_Surface_Shader_Builder added\n";} // SHOP ImplementationOP_Node *My_Surface_Shader_Builder::myConstructor(OP_Network *net, const char *name, OP_Operator *entry){ cout<<"In myConstructor of SHOP\n"; return new My_Surface_Shader_Builder(net, name, entry, SHOP_SURFACE);} PRM_TemplateMy_Surface_Shader_Builder::myTemplateList[] = { PRM_Template() // List terminator}; My_Surface_Shader_Builder::My_Surface_Shader_Builder(OP_Network *net, const char *name, OP_Operator *entry, SHOP_TYPE shader_type) : SHOP_Node(net, name, entry, shader_type){ myRenderMask = "*"; cout<<"Constructing SHOP_Cycles_Surface_Shader_Builder\n"; } My_Surface_Shader_Builder::~My_Surface_Shader_Builder(){ cout<<"In Destructor of SHOP\n";} OP_ERRORMy_Surface_Shader_Builder::cookMe(OP_Context &context){ // Do evaluation of the custom VOP network here. return error();} -------- code end --------- The code could be compiled successfully. As usual, I put it into my dso path and start houdini, then I got messages below: -------- message start --------- The Houdini 12.5.469 environment has been initialized. adding My_Surface_Shader_Builder to operator table <---- this means the registration of the SHOP begun My_Surface_Shader_Builder added <----- this means the registration of the SHOP is done Could not create the default HDA shelf tool for 'my_vopsurface': Traceback (most recent call last): File "<stdin>", line 5, in <module> File "/opt/Houdini/hfs12.5.469/houdini/python2.6libs/defaulttools.py", line 253, in createDefaultHDATool keywords) File "/opt/Houdini/hfs12.5.469/houdini/python2.6libs/defaulttools.py", line 151, in addShopNodeTypeLocationsAndKeywords rendermask = nodetype.renderMask() File "/opt/Houdini/hfs12.5.469/houdini/python2.6libs/hou.py", line 29614, in renderMask return _hou.ShopNodeType_renderMask(*args) ObjectWasDeleted: Attempt to access an object that no longer exists in Houdini. -------- message end --------- Anyone know how to solve this? I don't even know where and how to give a right render mask? The constructor of my SHOP not executed yet ...... Thanks. ps. you can compile the attached file and test it. Just remove the .txt extension and execute hcustom test.C test.C.txt test.h.txt Edited March 24, 2014 by pyrochlore Quote Link to comment Share on other sites More sharing options...
edward Posted March 26, 2014 Share Posted March 26, 2014 I think your installShopOperator might need to be more like this (untested): void newShopOperator(OP_OperatorTable *table) { cout<<"adding My_Surface_Shader_Builder to operator table\n"; SHOP_Operator *op; op = new SHOP_Operator( "my_vopsurface", // internal name "My Surface Shader Builder", // UI label My_Surface_Shader_Builder::myConstructor, // class factory My_Surface_Shader_Builder::myTemplateList, // parm definitions 0, 0); table->addOperator(op); SHOP_OperatorInfo *info = (SHOP_OperatorInfo *)shop->getOpSpecificData(); info->setShaderType(SHOP_SURFACE); info->setRenderMask("*"); cout<<"My_Surface_Shader_Builder added\n"; } Quote Link to comment Share on other sites More sharing options...
pyrochlore Posted March 26, 2014 Author Share Posted March 26, 2014 It works! At least I can add an empty SHOP into SHOP Network. Many Thanks to Edward. Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted April 13, 2014 Share Posted April 13, 2014 (edited) You can also set it in the constructor: SHOP_Template::SHOP_Template(OP_Network* net, const char* name, OP_Operator* entry, SHOP_TYPE shader_type) : SHOP_Node(net, name, entry, shader_type) { entry->setIconName(SHOP_TEMPLATE_ICON_NAME); auto info = (SHOP_OperatorInfo *)entry->getOpSpecificData(); info->setShaderType(SHOP_SURFACE); info->setRenderMask("*"); } Thanks to this, if you register more than one SHOP in newShopOperator(), you will have cleaner and simpler code there. Why to put operator specific code in some outside function? BTW: You don't need to specify SHOP_SURFACE there because you already specify it in you static creator method(in your case it's called "myConstructor") when you pass it to the constructor. auto SHOP_Template::CreateSHOP(OP_Network* net, const char* name, OP_Operator* entry) -> OP_Node* { return new SHOP_Template(net, name, entry, SHOP_SURFACE); } Edited April 13, 2014 by mantragora Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.