Detecting click on entity how?


#1

Looked in editmodels.js , digged around in some other examples. It looks like controller. ??? is needed. But theres so much hydra style code that i cannot figure out howto detect if you clicked some entity and how to get the entityID from it.

So, how do you get by clicking on entity the entityID ? Or wich command is doing it.


#2

You got several ways to go about it, here are all the “Entities” methods:

EntityItemID addEntity(const EntityItemProperties& properties);
EntityItemID identifyEntity(EntityItemID entityID);
EntityItemProperties getEntityProperties(EntityItemID entityID);
EntityItemID editEntity(EntityItemID entityID, const EntityItemProperties& properties);
void deleteEntity(EntityItemID entityID);
EntityItemID findClosestEntity(const glm::vec3& center, float radius) const;
QVector<EntityItemID> findEntities(const glm::vec3& center, float radius) const
RayToEntityIntersectionResult findRayIntersection(const PickRay& ray);
RayToEntityIntersectionResult findRayIntersectionBlocking(const PickRay& ray);

For clicks on an entity I recommend findRayIntersection().
Sample code:

function mousePressEvent(event) {
        var pickRay = Camera.computePickRay(event.x, event.y);
        var intersection = Entities.findRayIntersection(pickRay);
        ...
}
Controller.mousePressEvent.connect(mousePressEvent);

The intersection contains the following properties:

class RayToEntityIntersectionResult {
    bool intersects;
    bool accurate;
    EntityItemID entityID;
    EntityItemProperties properties;
    float distance;
    BoxFace face;
    glm::vec3 intersection;
};
class EntityItemID {
    QUuid id;
    uint32_t creatorTokenID;
    bool isKnownID;
}
clas EntityProperties {
    QUuid _id;
    bool _idSet;
    quint64 _lastEdited;
    quint64 _created;

    EntityTypes::EntityType _type;

    xColor _color;
    QString _modelURL;
    QString _animationURL;
    bool _animationIsPlaying;
    float _animationFrameIndex;
    float _animationFPS;
    float _glowLevel;
    QVector<SittingPoint> _sittingPoints;
    glm::vec3 _naturalDimensions;

    glm::vec3 _position;
    glm::vec3 _dimensions;
    glm::quat _rotation;
    float _mass;
    glm::vec3 _velocity;
    glm::vec3 _gravity;
    float _damping;
    float _lifetime;
    QString _script;
    glm::vec3 _registrationPoint;
    glm::vec3 _angularVelocity;
    float _angularDamping;
    bool _visible;
}

Different types will not support all properties
Types : Model, Box, Sphere


#3

@Atlante45 Super :smiley:
I can now read the entity id, how other things are done i can see in editmodels.js


#4

Hi @Atlante45 - Will take you up on your offer for help the other day!

I’m starting to have a look at voxel plane following for an avatar’s feet for better animation. I’m looking at different approaches, and wondered if Voxels.findRayIntersection could be used.

If so, I’m a little confused on how to specify a pickRay from my avatar to the voxel, as unlike Camera, MyAvatar has no computePickRay function.

Or perhaps my approach is completely wrong - any help would be appreciated…

  • davedub