Guest mantragora Posted August 29, 2013 Share Posted August 29, 2013 (edited) In case you missed topic on SESI forum, http://www.sidefx.co...ewtopic&t=29374 Prim Tetra example contains 11 files and is for custom primitives so I could miss something there when I was stripping the code, but as I understand documentation about it - for native primitives - all i have to do is: register hook generate new GR_Primitive that will override standard rendering once the hook detects correct primitive and it should work. To my understanding that's what I'm doing there, but it looks that it doesn't even register itself. Have I missed something ? I can go thru all the files again but maybe someone have example that works with native primitives instead of custom ones? EDIT: fixed documentation link Edited September 7, 2013 by mantragora Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted September 12, 2013 Share Posted September 12, 2013 Helloo! So, I still don't have working version. I moved a little with the code thanks to twod on SESI forum but the hook still refuses to work with me. It does successfully register but the createPrimitive() method is never reached. I tried to detect couple basic types that are specified in this enum and it doesn't call createPrimitive() for any of them. There is no other info in documentation, which definitely should be updated , that mentions why this may happen. The only thing that I think may be the reason is priority parameter that we pass to newRenderHook() that doesn't force my hook to take over rendering of nativePrimitive from default Houdini hook. Below is a working version of the code with updated newRenderHook() method. Anyone have any ideas why it doesn't reach createPrimitive() ? GR_GUIPrimitiveHook_template.h #ifndef __GR_GUI_PRIMITIVE_HOOK_H_ #define __GR_GUI_PRIMITIVE_HOOK_H_ #include <UT/UT_DSOVersion.h> #include <GUI/GUI_PrimitiveHook.h> #include <GR/GR_Primitive.h> //#include <GR/GR_RenderHook.h> //#include <GR/GR_RenderTable.h> #include <GT/GT_GEOPrimitive.h> #include <DM/DM_RenderTable.h> #include <RE/RE_ElementArray.h> #include <RE/RE_Geometry.h> #include <RE/RE_LightList.h> #include <RE/RE_ShaderHandle.h> #include <RE/RE_VertexArray.h> #define THIS_HOOK_NAME "GR_GUIPrimitiveHook_Template" #define THIS_PRIMITIVE_NAME "GR_Primitive_Template" namespace Mantragora { namespace Viewport { // primitive class GR_Primitive_Template : public GR_Primitive { public: GR_Primitive_Template(const GR_RenderInfo* info, const char* cache_name, const GEO_Primitive* prim); virtual ~GR_Primitive_Template(); virtual const char* className() const; virtual GR_PrimAcceptResult acceptPrimitive(GT_PrimitiveType t, int geo_type, const GT_PrimitiveHandle& ph, const GEO_Primitive* prim); virtual void resetPrimitives(); virtual void update(RE_Render* r, const GT_PrimitiveHandle& primh, const GR_UpdateParms& p); virtual void render(RE_Render* r, GR_RenderMode render_mode, GR_RenderFlags flags, const GR_DisplayOption* opt, const RE_MaterialList* materials); private: int _myID; RE_Geometry* _myGeo; bool _ogl3; }; // hook class GR_GUIPrimitiveHook_Template : public GUI_PrimitiveHook { public: GR_GUIPrimitiveHook_Template(); virtual ~GR_GUIPrimitiveHook_Template(); virtual GR_Primitive* createPrimitive(const GT_PrimitiveHandle& gt_prim, const GEO_Primitive* geo_prim, const GR_RenderInfo* info, const char* cache_name, GR_PrimAcceptResult& processed); }; } } #endif GR_GUIPrimitiveHook_template.c #include "GR_GUIPrimitiveHook_template.h" #include <ostream> using namespace Mantragora::Viewport; using std::cout; using std::endl; // hook registration ------------------------------------------------------------------------ void newRenderHook(GR_RenderTable *table) { cout << "registering hook" << endl; const int prim_hook_priority = 1; bool test = static_cast<DM_RenderTable*>(table)->registerGEOHook(new GR_GUIPrimitiveHook_Template, GA_PrimitiveTypeId(GEO_PRIMPOLY), prim_hook_priority); cout << "hook registering result: " << test << endl; } // hook initialization ------------------------------------------------------------------------ GR_GUIPrimitiveHook_Template::GR_GUIPrimitiveHook_Template(): GUI_PrimitiveHook(THIS_HOOK_NAME) { cout << "hook constructor!" << endl; } GR_GUIPrimitiveHook_Template::~GR_GUIPrimitiveHook_Template() {} GR_Primitive* GR_GUIPrimitiveHook_Template::createPrimitive(const GT_PrimitiveHandle& gt_prim, const GEO_Primitive* geo_prim, const GR_RenderInfo* info, const char* cache_name, GR_PrimAcceptResult& processed) { cout << "creating primitive!" << endl; return new GR_Primitive_Template(info, cache_name, geo_prim); } // primitive initialization ------------------------------------------------------------------------ GR_Primitive_Template::GR_Primitive_Template(const GR_RenderInfo* info, const char* cache_name, const GEO_Primitive* prim): GR_Primitive(info, cache_name, GA_PrimCompat::TypeMask(0)) { cout << "primitive constructor" << endl; _myID = prim->getTypeId().get(); _myGeo = NULL; } GR_Primitive_Template::~GR_Primitive_Template() { delete _myGeo; } const char* GR_Primitive_Template::className() const { return THIS_PRIMITIVE_NAME; } GR_PrimAcceptResult GR_Primitive_Template::acceptPrimitive(GT_PrimitiveType t, int geo_type, const GT_PrimitiveHandle& ph, const GEO_Primitive* prim) { cout << "accept primitive!" << endl; if (geo_type == _myID) { cout << "processing primitive" << endl; return GR_PROCESSED; } return GR_NOT_PROCESSED; } void GR_Primitive_Template::resetPrimitives() {} // main() ------------------------------------------------------------------------ void GR_Primitive_Template::update(RE_Render* r, const GT_PrimitiveHandle& primh, const GR_UpdateParms& p) { cout << "update!" << endl; } void GR_Primitive_Template::render(RE_Render* r, GR_RenderMode render_mode, GR_RenderFlags flags, const GR_DisplayOption* opt, const RE_MaterialList* materials) { cout << "render!" << endl; } Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted September 14, 2013 Share Posted September 14, 2013 I made couple more tests with Tetra example. 1. Modified GU_PrimTetra::registerMyself() method by moving DM_RenderTable::getTable()->registerGEOHook() to newRenderHook() that I added to GR_PrimTetra.C. 2. Instead of PrimTetra id I passed GA_PrimitiveTypeId(GEO_PRIMPOLY) to registerGEOHook() Questions: As I understand, by passing different ID to registerGEOHook(), it should now react to any polygonal geometry that I place because of GEO_PRIMPOLY passed instead of PrimTetra ID, but it still reacts only when I place PrimTetra node. Why is that? I uncommented TETRA_GR_PRIMITIVE and TETRA_GR_PRIM_COLLECTION in tetra example so it should use Hook for rendering and creating primitive, but it doesn't look like it because it also never reaches createPrimitive() method and after primitive detection jumps to GU_PrimTetra::build() method. Why? Isn' I really would be very grateful for native primitive example. 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.