Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 6 files). Show all
Unified · Split
| @@ -415,7 +415,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra · 414 unmodified lines | ||
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | bool EntityScriptingInterface::setVoxels(QUuid entityID, |
| 418 | − std::function<void(PolyVoxEntityItem&)> actor) { | |
| 418 | + std::function<bool(PolyVoxEntityItem&)> actor) { | |
| 419 | 419 | if (!_entityTree) { |
| 420 | 420 | return false; |
| 421 | 421 | } |
| @@ -435,7 +435,7 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 13 unmodified lines | ||
| 435 | 435 | |
| 436 | 436 | auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); |
| 437 | 437 | _entityTree->lockForWrite(); |
| 438 | − actor(*polyVoxEntity); | |
| 438 | + bool result = actor(*polyVoxEntity); | |
| 439 | 439 | entity->setLastEdited(now); |
| 440 | 440 | entity->setLastBroadcast(now); |
| 441 | 441 | _entityTree->unlock(); |
| @@ -448,42 +448,41 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 6 unmodified lines | ||
| 448 | 448 | properties.setLastEdited(now); |
| 449 | 449 | |
| 450 | 450 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); |
| 451 | − return true; | |
| 451 | + return result; | |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) { |
| 455 | 455 | if (!_entityTree) { |
| 456 | 456 | return false; |
| 457 | 457 | } |
| 458 | − | |
| 458 | + | |
| 459 | 459 | EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID)); |
| 460 | 460 | if (!entity) { |
| 461 | 461 | qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; |
| 462 | 462 | } |
| 463 | − | |
| 463 | + | |
| 464 | 464 | EntityTypes::EntityType entityType = entity->getType(); |
| 465 | − | |
| 465 | + | |
| 466 | 466 | if (entityType != EntityTypes::Line) { |
| 467 | 467 | return false; |
| 468 | 468 | } |
| 469 | − | |
| 469 | + | |
| 470 | 470 | auto now = usecTimestampNow(); |
| 471 | − | |
| 471 | + | |
| 472 | 472 | auto lineEntity = std::static_pointer_cast<LineEntityItem>(entity); |
| 473 | 473 | _entityTree->lockForWrite(); |
| 474 | 474 | bool success = actor(*lineEntity); |
| 475 | 475 | entity->setLastEdited(now); |
| 476 | 476 | entity->setLastBroadcast(now); |
| 477 | 477 | _entityTree->unlock(); |
| 478 | − | |
| 478 | + | |
| 479 | 479 | _entityTree->lockForRead(); |
| 480 | 480 | EntityItemProperties properties = entity->getProperties(); |
| 481 | 481 | _entityTree->unlock(); |
| 482 | − | |
| 482 | + | |
| 483 | 483 | properties.setLinePointsDirty(); |
| 484 | 484 | properties.setLastEdited(now); |
| 485 | − | |
| 486 | − | |
| 485 | + | |
| 487 | 486 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); |
| 488 | 487 | return success; |
| 489 | 488 | } |
| @@ -491,19 +490,19 @@ bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(Line · 1 unmodified line | ||
| 491 | 490 | |
| 492 | 491 | bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { |
| 493 | 492 | return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) { |
| 494 | − polyVoxEntity.setSphere(center, radius, value); | |
| 493 | + return polyVoxEntity.setSphere(center, radius, value); | |
| 495 | 494 | }); |
| 496 | 495 | } |
| 497 | 496 | |
| 498 | 497 | bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) { |
| 499 | 498 | return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) { |
| 500 | − polyVoxEntity.setVoxelInVolume(position, value); | |
| 499 | + return polyVoxEntity.setVoxelInVolume(position, value); | |
| 501 | 500 | }); |
| 502 | 501 | } |
| 503 | 502 | |
| 504 | 503 | bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) { |
| 505 | 504 | return setVoxels(entityID, [value](PolyVoxEntityItem& polyVoxEntity) { |
| 506 | − polyVoxEntity.setAll(value); | |
| 505 | + return polyVoxEntity.setAll(value); | |
| 507 | 506 | }); |
| 508 | 507 | } |
| 509 | 508 | |
| @@ -512,16 +511,16 @@ bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::v · 2 unmodified lines | ||
| 512 | 511 | if (!entity) { |
| 513 | 512 | qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID; |
| 514 | 513 | } |
| 515 | − | |
| 514 | + | |
| 516 | 515 | EntityTypes::EntityType entityType = entity->getType(); |
| 517 | − | |
| 516 | + | |
| 518 | 517 | if (entityType == EntityTypes::Line) { |
| 519 | 518 | return setPoints(entityID, [points](LineEntityItem& lineEntity) -> bool |
| 520 | 519 | { |
| 521 | 520 | return (LineEntityItem*)lineEntity.setLinePoints(points); |
| 522 | 521 | }); |
| 523 | 522 | } |
| 524 | − | |
| 523 | + | |
| 525 | 524 | return false; |
| 526 | 525 | } |
| 527 | 526 | |
| @@ -658,3 +657,43 @@ QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, · 130 unmodified lines | ||
| 658 | 657 | }); |
| 659 | 658 | return result; |
| 660 | 659 | } |
| 660 | + | |
| 661 | +glm::vec3 EntityScriptingInterface::voxelCoordsToWorldCoords(const QUuid& entityID, glm::vec3 voxelCoords) { | |
| 662 | + if (!_entityTree) { | |
| 663 | + return glm::vec3(0.0f); | |
| 664 | + } | |
| 665 | + | |
| 666 | + EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | |
| 667 | + if (!entity) { | |
| 668 | + qCDebug(entities) << "EntityScriptingInterface::voxelCoordsToWorldCoords no entity with ID" << entityID; | |
| 669 | + return glm::vec3(0.0f); | |
| 670 | + } | |
| 671 | + | |
| 672 | + EntityTypes::EntityType entityType = entity->getType(); | |
| 673 | + if (entityType != EntityTypes::PolyVox) { | |
| 674 | + return glm::vec3(0.0f); | |
| 675 | + } | |
| 676 | + | |
| 677 | + auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | |
| 678 | + return polyVoxEntity->voxelCoordsToWorldCoords(voxelCoords); | |
| 679 | +} | |
| 680 | + | |
| 681 | +glm::vec3 EntityScriptingInterface::worldCoordsToVoxelCoords(const QUuid& entityID, glm::vec3 worldCoords) { | |
| 682 | + if (!_entityTree) { | |
| 683 | + return glm::vec3(0.0f); | |
| 684 | + } | |
| 685 | + | |
| 686 | + EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); | |
| 687 | + if (!entity) { | |
| 688 | + qCDebug(entities) << "EntityScriptingInterface::worldCoordsToVoxelCoords no entity with ID" << entityID; | |
| 689 | + return glm::vec3(0.0f); | |
| 690 | + } | |
| 691 | + | |
| 692 | + EntityTypes::EntityType entityType = entity->getType(); | |
| 693 | + if (entityType != EntityTypes::PolyVox) { | |
| 694 | + return glm::vec3(0.0f); | |
| 695 | + } | |
| 696 | + | |
| 697 | + auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity); | |
| 698 | + return polyVoxEntity->worldCoordsToVoxelCoords(worldCoords); | |
| 699 | +} | |