Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 13 files). Show all
Unified · Split
| @@ -442,6 +442,43 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 441 unmodified lines | |||
| 442 | return true; | 442 | return true; |
| 443 | } | 443 | } |
| 444 | 444 | ||
| 445 | bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) { | ||
| 446 | if (!_entityTree) { | ||
| 447 | return false; | ||
| 448 | } | ||
| 449 | |||
| 450 | EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | ||
| 451 | if (!entity) { | ||
| 452 | qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; | ||
| 453 | } | ||
| 454 | |||
| 455 | EntityTypes::EntityType entityType = entity->getType(); | ||
| 456 | |||
| 457 | if (entityType != EntityTypes::Line) { | ||
| 458 | return false; | ||
| 459 | } | ||
| 460 | |||
| 461 | auto now = usecTimestampNow(); | ||
| 462 | |||
| 463 | LineEntityItem* lineEntity = static_cast<LineEntityItem*>(entity.get()); | ||
| 464 | _entityTree->lockForWrite(); | ||
| 465 | bool success = actor(*lineEntity); | ||
| 466 | entity->setLastEdited(now); | ||
| 467 | entity->setLastBroadcast(now); | ||
| 468 | _entityTree->unlock(); | ||
| 469 | |||
| 470 | _entityTree->lockForRead(); | ||
| 471 | EntityItemProperties properties = entity->getProperties(); | ||
| 472 | _entityTree->unlock(); | ||
| 473 | |||
| 474 | properties.setLinePointsDirty(); | ||
| 475 | properties.setLastEdited(now); | ||
| 476 | |||
| 477 | |||
| 478 | queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | ||
| 479 | return success; | ||
| 480 | } | ||
| 481 | |||
| 445 | bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { | 482 | bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { |
| 446 | return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) { | 483 | return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) { |
| 447 | polyVoxEntity.setSphere(center, radius, value); | 484 | polyVoxEntity.setSphere(center, radius, value); |
| @@ -460,6 +497,21 @@ bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { · 12 unmodified lines | |||
| 460 | }); | 497 | }); |
| 461 | } | 498 | } |
| 462 | 499 | ||
| 500 | bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::vec3>& points) { | ||
| 501 | return setPoints(entityID, [points](LineEntityItem& lineEntity) -> bool | ||
| 502 | { | ||
| 503 | return lineEntity.setLinePoints(points); | ||
| 504 | }); | ||
| 505 | } | ||
| 506 | |||
| 507 | bool EntityScriptingInterface::appendPoint(QUuid entityID, const glm::vec3& point) { | ||
| 508 | return setPoints(entityID, [point](LineEntityItem& lineEntity) -> bool | ||
| 509 | { | ||
| 510 | return lineEntity.appendPoint(point); | ||
| 511 | }); | ||
| 512 | |||
| 513 | } | ||
| 514 | |||
| 463 | 515 | ||
| 464 | bool EntityScriptingInterface::actionWorker(const QUuid& entityID, | 516 | bool EntityScriptingInterface::actionWorker(const QUuid& entityID, |
| 465 | std::function<bool(EntitySimulation*, EntityItemPointer)> actor) { | 517 | std::function<bool(EntitySimulation*, EntityItemPointer)> actor) { |