[sldev] name of an object?
Able Whitman
able.whitman at gmail.com
Fri Jul 27 23:49:34 PDT 2007
Ahhh, the problem of trying to get object name information for a bunch of
viewer objects.
Your code is on the right track, but it's missing an important step. The
viewer doesn't cache object details like object name, description, creator,
etc. In order to get this information, you need to have the viewer select
the object first.
Selecting an object causes the viewer to send an ObjectSelect message to the
sim, which then replies with an ObjectProperties message, which contains
(among other things) the object name.
The most straightforward way to get an object's name on demand would be to
try something like this (although read on before actually using this code):
LLUUID id = <Insert ID of Object to Lookup Here>;
LLString name;
LLViewerObject* vobj = gObjectList.findObject(id);
if (vobj)
{
gSelectMgr->deselectAll();
gSelectMgr->selectObjectAndFamily(vobj);
LLSelectNode* snode =
gSelectMgr->getSelection()->getFirstRootNode();
if (snode && snode->mValid)
{
name = snode->mName;
}
}
Now, there's (at least) one problem with this code, particularly if you're
trying to look up the names of lots of objects. This code suffers from a
race condition which, unfortunately, is relatively easy to aggravate, and
using this code as-is will probably not work.
The race condition results from the fact that the call to
selectObjectAndFamily() triggers the sending of an ObjectSelect message, but
there is no guarantee that the viewer has received and processed the reply
ObjectProperties message by the time the call to getFirstRootNode() occurs.
(The "mValid" field of the LLSelectNode will be FALSE until the
ObjectProperties message is received.)
One simple (but ugly) solution is putting in a hard-coded delay and polling
the "mValid" field. The problem is that if the thread you're polling /
sleeping on is the same thread that processes incoming network packets, this
just makes the problem worse. Since the lookup of object names is inherently
asynchronous, there's no really quick fix.
Another, entirely cosmetic, problem with this code is that having the viewer
select an object programmatically results in your avatar pointing and
(maybe) sending a particle stream towards whatever object is selected. Doing
this in rapid succession is likely to make your avatar look rather...
confused. :)
This isn't a perfect solution, but hopefully it helps get you a bit closer
to what you want.
--Able
On 7/27/07, Eelke Folmer <eelke.folmer at gmail.com> wrote:
>
> Hi,
>
> How can you get the name of an object? (I just need it for debug purposes)
>
> I got the name of an avatar by looking at the code for muting in
> lltoolpie.cpp.
>
> if (object->isAvatar()) { // avatar
> LLVOAvatar* avatar = (LLVOAvatar*)object;
> LLString name = avatar->getFullname();
> }
>
> This works but when I use the following code (which is listed below to
> mute objects) to get the name of an object name:
>
> LLSelectNode* node = gSelectMgr->getSelection()->getFirstRootNode();
> if (node) name = node->mName;
>
> it doesn't work. I have tried to call:
> LLToolSelect::handleObjectSelection(object, mask, FALSE, TRUE);
> gMenuHolder->setObjectSelection(gSelectMgr->getSelection());
>
> which does make the node to be true, but still I'm not able to get the
> object name.
>
> I tried to find out why it doesn't work by trying to mute objects in
> SL but I can't find any objects (except) avatars in SL that can be
> muted (except when you do it manually) there is no right click mute
> for objects?
>
> Anyone have any suggestions?
>
> Cheers Eelke
> _______________________________________________
> Click here to unsubscribe or manage your list subscription:
> /index.html
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.secondlife.com/pipermail/sldev/attachments/20070728/9f98f629/attachment-0001.htm
More information about the SLDev
mailing list