mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 17:03:58 +02:00
adding logic to check points of line are inside bounds
This commit is contained in:
parent
db56e15410
commit
2b4146125f
6 changed files with 59 additions and 2 deletions
|
@ -442,6 +442,40 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) {
|
||||
if (_entityTree) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
|
||||
if (!entity) {
|
||||
qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
|
||||
}
|
||||
|
||||
EntityTypes::EntityType entityType = entity->getType();
|
||||
if (entityType != EntityTypes::Line) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto now = usecTimestampNow();
|
||||
|
||||
LineEntityItem* lineEntity = static_cast<LineEntityItem*>(entity.get());
|
||||
_entityTree->lockForWrite();
|
||||
bool success = actor(*lineEntity);
|
||||
entity->setLastEdited(now);
|
||||
entity->setLastBroadcast(now);
|
||||
_entityTree->unlock();
|
||||
|
||||
_entityTree->lockForRead();
|
||||
EntityItemProperties properties = entity->getProperties();
|
||||
_entityTree->unlock();
|
||||
|
||||
properties.setLastEdited(now);
|
||||
|
||||
queueEntityMessage(PacketTypeEntityEdit, entityID, properties);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) {
|
||||
return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) {
|
||||
polyVoxEntity.setSphere(center, radius, value);
|
||||
|
@ -460,6 +494,13 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) {
|
|||
});
|
||||
}
|
||||
|
||||
bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) {
|
||||
return setPoints(entityID, [points](LineEntityItem& lineEntity) -> bool
|
||||
{
|
||||
return lineEntity.setLinePoints(points);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
bool EntityScriptingInterface::actionWorker(const QUuid& entityID,
|
||||
std::function<bool(EntitySimulation*, EntityItemPointer)> actor) {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <OctreeScriptingInterface.h>
|
||||
#include <RegisteredMetaTypes.h>
|
||||
#include "PolyVoxEntityItem.h"
|
||||
#include "LineEntityItem.h"
|
||||
|
||||
#include "EntityEditPacketSender.h"
|
||||
|
||||
|
@ -121,6 +122,8 @@ public slots:
|
|||
Q_INVOKABLE bool setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value);
|
||||
Q_INVOKABLE bool setVoxel(QUuid entityID, const glm::vec3& position, int value);
|
||||
Q_INVOKABLE bool setAllVoxels(QUuid entityID, int value);
|
||||
|
||||
Q_INVOKABLE bool setAllPoints(QUuid entityID, const QVector<glm::vec3>& points);
|
||||
|
||||
Q_INVOKABLE void dumpTree() const;
|
||||
|
||||
|
@ -157,6 +160,7 @@ signals:
|
|||
private:
|
||||
bool actionWorker(const QUuid& entityID, std::function<bool(EntitySimulation*, EntityItemPointer)> actor);
|
||||
bool setVoxels(QUuid entityID, std::function<void(PolyVoxEntityItem&)> actor);
|
||||
bool setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor);
|
||||
void queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties);
|
||||
|
||||
/// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode
|
||||
|
|
|
@ -85,7 +85,7 @@ bool LineEntityItem::setProperties(const EntityItemProperties& properties) {
|
|||
return somethingChanged;
|
||||
}
|
||||
|
||||
void LineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
|
||||
bool LineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
|
||||
QVector<glm::vec3> sanitizedPoints;
|
||||
int invalidPoints = 0;
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
|
@ -103,6 +103,7 @@ void LineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
|
|||
}
|
||||
_points = sanitizedPoints;
|
||||
_pointsChanged = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
int LineEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
|
||||
|
|
|
@ -54,7 +54,7 @@ class LineEntityItem : public EntityItem {
|
|||
void setLineWidth(float lineWidth){ _lineWidth = lineWidth; }
|
||||
float getLineWidth() const{ return _lineWidth; }
|
||||
|
||||
void setLinePoints(const QVector<glm::vec3>& points);
|
||||
bool setLinePoints(const QVector<glm::vec3>& points);
|
||||
|
||||
const QVector<glm::vec3>& getLinePoints() const{ return _points; }
|
||||
|
||||
|
|
|
@ -93,6 +93,16 @@ QVector<glm::vec3> qVectorVec3FromScriptValue(const QScriptValue& array){
|
|||
return newVector;
|
||||
}
|
||||
|
||||
void qVectorVec3FromScriptValue(const QScriptValue& array, QVector<glm::vec3>& vector ) {
|
||||
int length = array.property("length").toInteger();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
glm::vec3 newVec3 = glm::vec3();
|
||||
vec3FromScriptValue(array.property(i), newVec3);
|
||||
vector << newVec3;
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue vec2toScriptValue(QScriptEngine* engine, const glm::vec2 &vec2) {
|
||||
QScriptValue obj = engine->newObject();
|
||||
obj.setProperty("x", vec2.x);
|
||||
|
|
|
@ -58,6 +58,7 @@ void qURLFromScriptValue(const QScriptValue& object, QUrl& url);
|
|||
|
||||
QScriptValue qVectorVec3ToScriptValue(QScriptEngine* engine, const QVector<glm::vec3>& vector);
|
||||
QVector<glm::vec3> qVectorVec3FromScriptValue( const QScriptValue& array);
|
||||
void qVectorVec3FromScriptValue( const QScriptValue& array, QVector<glm::vec3> vector);
|
||||
|
||||
class PickRay {
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue