PDA

View Full Version : GizmoHandler - can't quite get it going



adamredwoods
12-17-2007, 04:13 PM
The new GizmoHandler class, does anyone have any suggestions why my Gizmo isn't showing up? This is very minimal code, I just want to view the gizmo handle so I know it's working and I'm on the right track.

I didn't include the other displacement handler stuff, no need, it's working.

Thanks for your help.



void GizmoDraw(MainData *mData, const LWCustomObjAccess *custobj) {
int i;
LWFVector vec[] = { {0,0,0}, {0,0,1} ,
{0,0,1}, {1,0,1} ,
{1,0,1}, {1,0,0},
{1,0,0}, {0,0,0}};

for (i=0; i<=3; i++) {
custobj->line( custobj->dispData, vec[i],vec[i+1], LWCSYS_ICON );
}
return;
}
XCALL_(int) GizmoDirty(MainData *mData)
{
XCALL_INIT;
return mData->gizDirty;
}


XCALL_(int) GizmoCount(MainData *mData, LWToolEvent *eve)
{
XCALL_INIT;
return mData->gizCount;
}

XCALL_(int)
Gizmo( MainData *mData, LWGizmoFuncs *gizmo) {

gizmo->draw = GizmoDraw;
//gizmo->help = NULL;
gizmo->dirty = GizmoDirty;
gizmo->count = GizmoCount;
//gizmo->handle = NULL;
//gizmo->start = NULL;
//gizmo->adjust = NULL;
//gizmo->down = NULL;
//gizmo->move = NULL;
//gizmo->up = NULL;

mData->gizCount =1;

return 1;
}

ServerRecord ServerDesc[] = {
{ LWDISPLACEMENT_HCLASS, "bendplus", Handler },
{ LWDISPLACEMENT_ICLASS, "bendplus", Interface },
{ LWDISPLACEMENT_GCLASS, "bendplus", Gizmo },
{ NULL }
};

tischbein3
12-17-2007, 05:01 PM
Mhmm, not, sure just some proposals:

-Try to include the most of the other callbacks (especially help/start / down / move/ up).. (don't know if this helps: but the layouttool class wich do have a similar structure is very picky on these things)

- Try to use a different coordinate system inside the draw funtion. (The world thingy)

- Last but definitve not least, the major trap: Did you imported your plugin with the gizmo class already part of it ?

tischbein3
12-17-2007, 05:11 PM
...and of course: try to change the LWFvector into double

Jarno
12-17-2007, 06:25 PM
And the handler should return an AFUNC_* value, like AFUNC_OK, not 1 (which is equivalent to AFUNC_BADVERSION, which is probably why your gizmo drawing is never called in the first place).

---JvdL---

MiniFireDragon
12-17-2007, 08:15 PM
Isn't a done(); needed?

Jarno
12-17-2007, 09:51 PM
As per the documentation (in the Handlers section of the LWSDK docs), done() is ignored for gizmos.

---JvdL---

adamredwoods
12-18-2007, 01:47 PM
Thanks for your input, everyone! The AFUNC_OK has gotten it to wake up but....
But now, it only crashes. I think there's something else amiss with the activation function.
The rest of my displacement function works, because if I remove the server activation for the gizmo class (GCLASS), it works. If I comment out everything in the activation function except the return AFUNC_OK it crashes.

You'll also notice that Ive tried to mimic the LayoutTool Acitvation function (replacing LWLayoutTool with LWGizmoFuncs), but still the crash.

Here's the snippet, again, without the rest. I'm open to any suggestions.
Your help has been indespensible.

//===========================
// GIZMO
//
XCALL_(void) GizmoDraw(MainData *mData, LWCustomObjAccess *custobj) {
int i;
LWDVector vec[] = { {0,0,0}, {0,0,1} ,
{0,0,1}, {1,0,1} ,
{1,0,1}, {1,0,0},
{1,0,0}, {0,0,0}};

for (i=0; i<=3; i++) {
custobj->line( custobj->dispData, vec[i],vec[i+1], LWCSYS_OBJECT );
}
return;
}
XCALL_(int) GizmoDirty(MainData *mData)
{

return mData->gizDirty;
}


XCALL_(int) GizmoCount(MainData *mData, LWToolEvent *eve)
{
//XCALL_INIT;
return mData->gizCount;
}
XCALL_(int) GizmoHelp(MainData *mData, LWToolEvent *eve)
{
//XCALL_INIT;
return ;
}
XCALL_(int) GizmoHandle(MainData *mData, LWToolEvent *eve, int i, LWDVector pos)
{
//XCALL_INIT;
return ;
}
XCALL_(void) GizmoD(MainData *mData, LWToolEvent *eve)
{
//XCALL_INIT;
return ;
}
XCALL_(void) GizmoM(MainData *mData, LWToolEvent *eve)
{
//XCALL_INIT;
return ;
}
XCALL_(void) GizmoU(MainData *mData, LWToolEvent *eve)
{
//XCALL_INIT;
return ;
}
XCALL_(int) GizmoStart(MainData *mData, LWToolEvent *eve)
{
//XCALL_INIT;
return ;
}
XCALL_(int) GizmoAdjust(MainData *mData, LWToolEvent *eve, int i)
{
//XCALL_INIT;
return ;
}
XCALL_(int)
Gizmo( MainData *mData, LWGizmoFuncs *gizmo ) {
//int version, GlobalFunc *global, LWLayoutTool *local, void *serverData
//MainData *mData, LWGizmoFuncs *gizmo

if(!gizmo || !LWGIZMO_VERSION) return AFUNC_BADVERSION;

gizmo->draw = GizmoDraw;
gizmo->help = GizmoHelp;
gizmo->dirty = GizmoDirty;
gizmo->count = GizmoCount;
gizmo->handle = GizmoHandle;
gizmo->start = GizmoStart;
gizmo->adjust = GizmoAdjust;
gizmo->down = GizmoD;
gizmo->move = GizmoM;
gizmo->up = GizmoU;

//mData->gizCount =1;

return AFUNC_OK;
}

ServerRecord ServerDesc[] = {
{ LWDISPLACEMENT_HCLASS, "bendplus", (ActivateFunc*)Handler },
{ LWDISPLACEMENT_ICLASS, "bendplus", (ActivateFunc*)Interface },
{ LWDISPLACEMENT_GCLASS, "bendplus", (ActivateFunc*)Gizmo },
{ NULL }
};

Jarno
12-18-2007, 08:56 PM
That actually compiled? Your compiler must be screaming lots of warnings at you.


XCALL_(int) Gizmo( MainData *mData, LWGizmoFuncs *gizmo )
That is not the correct form for a handler function. It should be:

XCALL_(int) Gizmo( int version, GlobalFunc *global, void *local, void *serverdata )
{
LWGizmo *gizmo = (LWGizmo *)local;

if(version != LWGIZMO_VERSION)
return AFUNC_BADVERSION;

gizmo->gizmo->draw = GizmoDraw;
[...]


Also, the callbacks which return a value (like GizmoHandle, GizmoStart, GizmoAdjust) MUST return a value.

The return type for GizmoDown is int, not void. The return type for GizmoHelp is const char*, not int.

---JvdL---

adamredwoods
12-19-2007, 01:38 AM
Jarno,

Thank you so much! The handler function was the key that wasn't working, and that was the part I wasn't sure about. It works now.

Yes, my code was done lazily, I just wanted to test out the basic gizmo shell. I'll clean it up. :)

On a side note for anyone working with Gizmos, I think the SDK documentation is slightly confusing re: Gizmo Handlers.

The gizmo activation function receives the instance data
as the first field of an LWGizmo structure.
seems to be referring to something else, unless I'm getting my LW Terminology wrong (Activation function != handler function).

Thanks again.

//Adam

adamredwoods
12-26-2007, 03:31 PM
Update:

So the CustomObj is working, but it seems that the GizmoHandler is intercepting all mouse functions when it is activated.

Does anyone know how to let other mouse functions pass through when it the gizmo is not in use?

Many thanks!

tischbein3
12-26-2007, 04:49 PM
Inside the down callback check if mouse input is needed and return 0 for handle processing (with no handle hitted, the input isn't "caught" by the plugin itself)

hope this brings you on the right track.

adamredwoods
12-26-2007, 07:19 PM
Thank you for the suggestion. :) I will work on implementing it.

As a side note, The MouseDown callback (GizmoD), in my code is



XCALL_(int) GizmoD(MainData *mData, LWToolEvent *eve)
{
XCALL_INIT;
mData->gizDirty = LWT_DIRTY_WIREFRAME;
return 0;
}


I was doing this way so I could work on getting the CustomObj to display, and not have any interaction at this point. But the result is that the gizmo doesn't allow ANY interaction with ANYTHING. In other words, it wont allow me to select other objects, move, rotate, etc. If I do select a different object (by using the popup menu) it still wont allow any interaction with the viewport. If I turn off the plugin, normal behavior is returned. So it seems the plugin is always active and always intercepting mouse interactions.

My end result I envision is, add plugin to object, select plugin handle, move handle. If not on handle, revert mouse function back to Lightwave (move, rotate, scale or select).

I have also set the other callbacks to return a value of "0", if the callback expects an INT. I have also tried "1" and "-1" all to no avail.

very strange. Also note if I remove the gizmo activation completely, the plug works as expected.