Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  SDK Support    Animator and Events
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Member
Posted
I have a keyframe animation that, for the sake of argument, moves an instance from one place in the scene to another. So over a period of time, the object's coordinates (loc_ property) are changing.

Is it possible with the SDK to somehow get notifed whenever the location changes. Like an event or callback?

I need to report the coordinates over time, but they are being generated by the keys and interpolators in the animation. I don't want to have to calculate them myself.

TIA, Loz.
 
Posts: 13 | Location: Abingdon, Oxfordshire, UK | Registered: March 26, 2003Reply With QuoteEdit or Delete MessageReport This Post
<Niko>
Posted
Well, I see two wy of doing what you want.
the one you already thought about and by far the simplest one, would be to use a timer get the properties value of objects and refresh corresponding widgets.
I think this is the best solution.

There would be another way to do it, but may cause some problems. and it is harder to implement. The idea would be to attach a property to the object with the same name than the property you want to listen. This 'user' property can then do any action you decide:
- notify yourself
- redispatch to the 'real' property.
the problem here is that 'loc_' is what, internally, we call an 'old type' property. it means that you cannot really override it.
the property "Translation" is equivalent to 'loc_'. the problem is that only newer (311 and up i think) version of the plugin knows about "Translation".
so if your goal is to publish a scene for 308 (AOL) it won't work either.

let's say you don't care about 308 compatibility, then you can do it this way:
NIK_Property p = NIK_Attribute(instance, "Translation");
// at this point 'p' points directly on the property named "Translation"
all you need then is to implement the interface NIK_IPropertyInfo (defined in "NIK_DOM.h") doing something like that :
class MyPropertyNotifier : public NIK_IPropertyInfo
{
public:
NIK_Property p; // the property we redispatch too (the 'real' one)
// all me need is to redispatch the calls
const char* Name() const { return p.GetPropertyInfo()->Name(); }
uint32 RuntimeCode() const { return p.GetPropertyInfo()->RuntimeCode(); }
const NIK_ITypeInformation* Type() const { return p.GetPropertyInfo()->Type(); }
uint32 Flags() const { return p.GetPropertyInfo()->Flags(); }
boolean Get(NIK_IObjectInfo* obj, void* p) const { return p.GetPropertyInfo()->Get(obj, p); };
boolean Set(NIK_IObjectInfo* obj, const void* p)
{
// place your notification code here
FunctionHeySomeoneModifiedMyself(.........);
// p points on the new value to be set on the object
// for a point3d, for example, you can cast p to CXPPoint3d*
// if the type of the property is point3d (Type()->BaseType()==ePoint3d)
CXPPoint3d& point3d = *(CXPPoint3d*)p;

return p.GetPropertyInfo()->Set(obj, p);
}
};

NIK_Property p = NIK_Attribute(instance, "Translation");
if (p.Test())
{
CXPRefPtr myProp = new CXPCOMObj;
if (!myProp.Test()) { CXPAssert(0); ... return false.... }
myProp->p = p;
// we attach our wrapper to the object.....
NIK_AttachAttribute(instance, "Translation", myProp);
}

you may want to do that right after the creation of the object, since for speed issues we cache the properties. So if the animator already got the pointer on the property, attaching a new property with the same name won't have any effect. (unless you set again the target on the animator)
...
 
Reply With QuoteEdit or Delete MessageReport This Post
<Niko>
Posted
the brackets have been removed....
the line:
CXPRefPtr myProp = new CXPCOMObj;

should be ssen like:
CXPRefPtr[MyPropertyNotifier] myProp = new CXPCOMObj[MyPropertyNotifier];

where '[' and ']' are the lessthan and morethan signs
 
Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Niko,

First of all, I had to add:

BEGIN_CXPCOM_MAP()
END_CXPCOM_MAP()

to the MyPropertyNotifier class to get it to compile. But then I was getting another compiler error on the last line of the example you gave to me:

NIK_AttachAttribute(instance, "Translation", myProp);

There is no function signiture that matches that in Client.h. The closest I found was:

NIK_AttachAttribute(instance, myProp);

When I set the property's value, using:

NIK_Attribute(...).Set(...);

*my* Set routine is called. Perfect!!!!

But, in my animator I need to reference the property that is going to be updated in the base animator's SetTargetAndProperty method. But that only accepts an old style property id ('loc_'). How do I tell it to change "Translation" instead?

I tried getting the code for my new property using RuntimeCode() but when it delegated the call to the real "Translation" property the returned value was 0xCCCCCCCC, which doesn't work. Am I going down the right line of thinking?

Thanks a lot for your help,

Loz.
 
Posts: 13 | Location: Abingdon, Oxfordshire, UK | Registered: March 26, 2003Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Update....

The animator *is* calling the new class routines. The id returned from RuntimeCode() is 0xFF000002, I think.

But I get a stack problem when the following happens (the first time Set() is called with a CXPPoint3d):

1. New code (as you described) in the Set() method:
return p.GetPropertyInfo()->Set(obj, p);

2. New code (as you described) in the RuntimeCode() method:
return p.GetPropertyInfo()->RuntimeCode();

3. Valid id returned (0xFF000002)... but later the system returns *to* an invalid address... like the stack got overwritten. I didn't call RuntimeCode() this time, the NIK logic did.

Any ideas?

TIA, Loz.
 
Posts: 13 | Location: Abingdon, Oxfordshire, UK | Registered: March 26, 2003Reply With QuoteEdit or Delete MessageReport This Post
<Niko>
Posted
i am not sure if i follow.
what is 1,2 and 3 ?
you placed some breakpoints and it is were you stop ?
if your "Set" fuinction is called by the animator (and now that i think about it, it should) i really don't see what could be a problem.
try:
return p.GetPropertyInfo()->Set(p.GetObjectInfo(), p);
now that i see that, maybe there is a mix up with the 'p' (actually i am surprised it would compile)
can you change the NIK_Property p; data member to something called, let's say, mP;
and then try with mP.GetPropertyInfo->Set(mP.GetObjectInfo(), p);
 
Reply With QuoteEdit or Delete MessageReport This Post
<Niko>
Posted
other question, are you sure you are doing:
NIK_Property p = NIK_Attribute(instance, "Translation");
myProp->mP = p;
before:
NIK_AttachAttribute(instance, myProp);
?
because if you inverse the lines, you will end up in an infinite loop, since you will keep redispatching to yourself
 
Reply With QuoteEdit or Delete MessageReport This Post
Member
Posted Hide Post
Niko,

I had already spotted the mix up with the p variables !!!

It turned out that my overridden Set() method was causing the problem. It was like this:

boolean CxyzProp::Set(
NIK_IObjectInfo *pIOInfo,
const void *pValue)
{
return(pProp.GetPropertyInfo()->Set(pIOInfo, pValue));
}

but should have been like this:

boolean CxyzProp::Set(
NIK_IObjectInfo *pIOInfo,
const void *pValue)
{
return(pProp.GetPropertyInfo()->Set(pProp.GetObjectInfo(), pValue));
}

The object information pointer being used was refering to the new property, instead of the original property. But of course, because it just delegates calls to the original, its own internal state had never been initialized. The wrong pointer caused the stack to get overwritten with the new CXPPoint3d Frown

Everything works fine now.... thanks for all your help and ideas.

Loz.
 
Posts: 13 | Location: Abingdon, Oxfordshire, UK | Registered: March 26, 2003Reply With QuoteEdit or Delete MessageReport This Post
  Powered by Eve Community  
 

Viewpoint Developer Central    Viewpoint Forums    Viewpoint Forums  Hop To Forum Categories  SDK Support    Animator and Events