History

have functions that change polyvox voxes return true if they changed anything, else false. added voxelCoordsToWorldCoords and worldCoordsToVoxelCoords

Seth Alves committed 11 years ago

Commit 5ecdbaa1 parent 09a9dea6 files · +128 −60Browse files

Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 6 files). Show all

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+57−18
@@ -415,7 +415,7 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra · 414 unmodified lines
415}415}
416 416
417bool EntityScriptingInterface::setVoxels(QUuid entityID,417bool EntityScriptingInterface::setVoxels(QUuid entityID,
418 std::function<void(PolyVoxEntityItem&)> actor) {418 std::function<bool(PolyVoxEntityItem&)> actor) {
419 if (!_entityTree) {419 if (!_entityTree) {
420 return false;420 return false;
421 }421 }
@@ -435,7 +435,7 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 13 unmodified lines
435 435
436 auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);436 auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
437 _entityTree->lockForWrite();437 _entityTree->lockForWrite();
438 actor(*polyVoxEntity);438 bool result = actor(*polyVoxEntity);
439 entity->setLastEdited(now);439 entity->setLastEdited(now);
440 entity->setLastBroadcast(now);440 entity->setLastBroadcast(now);
441 _entityTree->unlock();441 _entityTree->unlock();
@@ -448,42 +448,41 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 6 unmodified lines
448 properties.setLastEdited(now);448 properties.setLastEdited(now);
449 449
450 queueEntityMessage(PacketType::EntityEdit, entityID, properties);450 queueEntityMessage(PacketType::EntityEdit, entityID, properties);
451 return true;451 return result;
452}452}
453 453
454bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) {454bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) {
455 if (!_entityTree) {455 if (!_entityTree) {
456 return false;456 return false;
457 }457 }
458 458
459 EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));459 EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
460 if (!entity) {460 if (!entity) {
461 qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;461 qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
462 }462 }
463 463
464 EntityTypes::EntityType entityType = entity->getType();464 EntityTypes::EntityType entityType = entity->getType();
465 465
466 if (entityType != EntityTypes::Line) {466 if (entityType != EntityTypes::Line) {
467 return false;467 return false;
468 }468 }
469 469
470 auto now = usecTimestampNow();470 auto now = usecTimestampNow();
471 471
472 auto lineEntity = std::static_pointer_cast<LineEntityItem>(entity);472 auto lineEntity = std::static_pointer_cast<LineEntityItem>(entity);
473 _entityTree->lockForWrite();473 _entityTree->lockForWrite();
474 bool success = actor(*lineEntity);474 bool success = actor(*lineEntity);
475 entity->setLastEdited(now);475 entity->setLastEdited(now);
476 entity->setLastBroadcast(now);476 entity->setLastBroadcast(now);
477 _entityTree->unlock();477 _entityTree->unlock();
478 478
479 _entityTree->lockForRead();479 _entityTree->lockForRead();
480 EntityItemProperties properties = entity->getProperties();480 EntityItemProperties properties = entity->getProperties();
481 _entityTree->unlock();481 _entityTree->unlock();
482 482
483 properties.setLinePointsDirty();483 properties.setLinePointsDirty();
484 properties.setLastEdited(now);484 properties.setLastEdited(now);
485 485
486
487 queueEntityMessage(PacketType::EntityEdit, entityID, properties);486 queueEntityMessage(PacketType::EntityEdit, entityID, properties);
488 return success;487 return success;
489}488}
@@ -491,19 +490,19 @@ bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(Line · 1 unmodified line
491 490
492bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) {491bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) {
493 return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) {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
498bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) {497bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) {
499 return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) {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
504bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) {503bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) {
505 return setVoxels(entityID, [value](PolyVoxEntityItem& polyVoxEntity) {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 if (!entity) {511 if (!entity) {
513 qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;512 qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
514 }513 }
515 514
516 EntityTypes::EntityType entityType = entity->getType();515 EntityTypes::EntityType entityType = entity->getType();
517 516
518 if (entityType == EntityTypes::Line) {517 if (entityType == EntityTypes::Line) {
519 return setPoints(entityID, [points](LineEntityItem& lineEntity) -> bool518 return setPoints(entityID, [points](LineEntityItem& lineEntity) -> bool
520 {519 {
521 return (LineEntityItem*)lineEntity.setLinePoints(points);520 return (LineEntityItem*)lineEntity.setLinePoints(points);
522 });521 });
523 }522 }
524 523
525 return false;524 return false;
526}525}
527 526
@@ -658,3 +657,43 @@ QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, · 130 unmodified lines
658 });657 });
659 return result;658 return result;
660}659}
660
661glm::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
681glm::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}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t