コード例 #1
0
EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID entityID) {
    EntityItemProperties results;
    EntityItemID identity = identifyEntity(entityID);
    if (_entityTree) {
        _entityTree->lockForRead();
        EntityItem* entity = const_cast<EntityItem*>(_entityTree->findEntityByEntityItemID(identity));
        
        if (entity) {
            results = entity->getProperties();

            // TODO: improve sitting points and naturalDimensions in the future, 
            //       for now we've included the old sitting points model behavior for entity types that are models
            //        we've also added this hack for setting natural dimensions of models
            if (entity->getType() == EntityTypes::Model) {
                const FBXGeometry* geometry = _entityTree->getGeometryForEntity(entity);
                if (geometry) {
                    results.setSittingPoints(geometry->sittingPoints);
                    Extents meshExtents = geometry->getUnscaledMeshExtents();
                    results.setNaturalDimensions(meshExtents.maximum - meshExtents.minimum);
                }
            }

        } else {
            results.setIsUnknownID();
        }
        _entityTree->unlock();
    }
    
    return results;
}
コード例 #2
0
EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) {
    EntityItemID actualID = entityID;
    // if the entity is unknown, attempt to look it up
    if (!entityID.isKnownID) {
        actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID);
        if (actualID.id != UNKNOWN_ENTITY_ID) {
            entityID.id = actualID.id;
            entityID.isKnownID = true;
        }
    }
    
    // If we have a local entity tree set, then also update it. We can do this even if we don't know
    // the actual id, because we can edit out local entities just with creatorTokenID
    if (_entityTree) {
        _entityTree->lockForWrite();
        _entityTree->updateEntity(entityID, properties);
        _entityTree->unlock();
    }

    // if at this point, we know the id, send the update to the entity server
    if (entityID.isKnownID) {
        // make sure the properties has a type, so that the encode can know which properties to include
        if (properties.getType() == EntityTypes::Unknown) {
            EntityItem* entity = _entityTree->findEntityByEntityItemID(entityID);
            if (entity) {
                EntityItemProperties tempProperties = properties;
                tempProperties.setType(entity->getType());
                queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, tempProperties);
                return entityID;
            }
        }
        
        // if the properties already includes the type, then use it as is
        queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties);
    }
    
    return entityID;
}