Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 8 files). Show all
Unified · Split
| @@ -420,3 +420,40 @@ bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& c · 419 unmodified lines | |||
| 420 | queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | 420 | queueEntityMessage(PacketTypeEntityEdit, entityID, properties); |
| 421 | return true; | 421 | return true; |
| 422 | } | 422 | } |
| 423 | |||
| 424 | |||
| 425 | bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { | ||
| 426 | if (!_entityTree) { | ||
| 427 | return false; | ||
| 428 | } | ||
| 429 | |||
| 430 | EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); | ||
| 431 | if (!entity) { | ||
| 432 | qCDebug(entities) << "EntityScriptingInterface::setVoxelSphere no entity with ID" << entityID; | ||
| 433 | return false; | ||
| 434 | } | ||
| 435 | |||
| 436 | EntityTypes::EntityType entityType = entity->getType(); | ||
| 437 | if (entityType != EntityTypes::PolyVox) { | ||
| 438 | return false; | ||
| 439 | } | ||
| 440 | |||
| 441 | auto now = usecTimestampNow(); | ||
| 442 | |||
| 443 | PolyVoxEntityItem* polyVoxEntity = static_cast<PolyVoxEntityItem*>(entity.get()); | ||
| 444 | _entityTree->lockForWrite(); | ||
| 445 | polyVoxEntity->setAll(value); | ||
| 446 | entity->setLastEdited(now); | ||
| 447 | entity->setLastBroadcast(now); | ||
| 448 | _entityTree->unlock(); | ||
| 449 | |||
| 450 | _entityTree->lockForRead(); | ||
| 451 | EntityItemProperties properties = entity->getProperties(); | ||
| 452 | _entityTree->unlock(); | ||
| 453 | |||
| 454 | properties.setVoxelDataDirty(); | ||
| 455 | properties.setLastEdited(now); | ||
| 456 | |||
| 457 | queueEntityMessage(PacketTypeEntityEdit, entityID, properties); | ||
| 458 | return true; | ||
| 459 | } | ||