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
415415 }
416416
417417 bool EntityScriptingInterface::setVoxels(QUuid entityID,
418− std::function<void(PolyVoxEntityItem&)> actor) {
418+ std::function<bool(PolyVoxEntityItem&)> actor) {
419419 if (!_entityTree) {
420420 return false;
421421 }
@@ -435,7 +435,7 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 13 unmodified lines
435435
436436 auto polyVoxEntity = std::dynamic_pointer_cast<PolyVoxEntityItem>(entity);
437437 _entityTree->lockForWrite();
438− actor(*polyVoxEntity);
438+ bool result = actor(*polyVoxEntity);
439439 entity->setLastEdited(now);
440440 entity->setLastBroadcast(now);
441441 _entityTree->unlock();
@@ -448,42 +448,41 @@ bool EntityScriptingInterface::setVoxels(QUuid entityID, · 6 unmodified lines
448448 properties.setLastEdited(now);
449449
450450 queueEntityMessage(PacketType::EntityEdit, entityID, properties);
451− return true;
451+ return result;
452452 }
453453
454454 bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(LineEntityItem&)> actor) {
455455 if (!_entityTree) {
456456 return false;
457457 }
458−
458+
459459 EntityItemPointer entity = static_cast<EntityItemPointer>(_entityTree->findEntityByEntityItemID(entityID));
460460 if (!entity) {
461461 qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
462462 }
463−
463+
464464 EntityTypes::EntityType entityType = entity->getType();
465−
465+
466466 if (entityType != EntityTypes::Line) {
467467 return false;
468468 }
469−
469+
470470 auto now = usecTimestampNow();
471−
471+
472472 auto lineEntity = std::static_pointer_cast<LineEntityItem>(entity);
473473 _entityTree->lockForWrite();
474474 bool success = actor(*lineEntity);
475475 entity->setLastEdited(now);
476476 entity->setLastBroadcast(now);
477477 _entityTree->unlock();
478−
478+
479479 _entityTree->lockForRead();
480480 EntityItemProperties properties = entity->getProperties();
481481 _entityTree->unlock();
482−
482+
483483 properties.setLinePointsDirty();
484484 properties.setLastEdited(now);
485−
486−
485+
487486 queueEntityMessage(PacketType::EntityEdit, entityID, properties);
488487 return success;
489488 }
@@ -491,19 +490,19 @@ bool EntityScriptingInterface::setPoints(QUuid entityID, std::function<bool(Line · 1 unmodified line
491490
492491 bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) {
493492 return setVoxels(entityID, [center, radius, value](PolyVoxEntityItem& polyVoxEntity) {
494− polyVoxEntity.setSphere(center, radius, value);
493+ return polyVoxEntity.setSphere(center, radius, value);
495494 });
496495 }
497496
498497 bool EntityScriptingInterface::setVoxel(QUuid entityID, const glm::vec3& position, int value) {
499498 return setVoxels(entityID, [position, value](PolyVoxEntityItem& polyVoxEntity) {
500− polyVoxEntity.setVoxelInVolume(position, value);
499+ return polyVoxEntity.setVoxelInVolume(position, value);
501500 });
502501 }
503502
504503 bool EntityScriptingInterface::setAllVoxels(QUuid entityID, int value) {
505504 return setVoxels(entityID, [value](PolyVoxEntityItem& polyVoxEntity) {
506− polyVoxEntity.setAll(value);
505+ return polyVoxEntity.setAll(value);
507506 });
508507 }
509508
@@ -512,16 +511,16 @@ bool EntityScriptingInterface::setAllPoints(QUuid entityID, const QVector<glm::v · 2 unmodified lines
512511 if (!entity) {
513512 qCDebug(entities) << "EntityScriptingInterface::setPoints no entity with ID" << entityID;
514513 }
515−
514+
516515 EntityTypes::EntityType entityType = entity->getType();
517−
516+
518517 if (entityType == EntityTypes::Line) {
519518 return setPoints(entityID, [points](LineEntityItem& lineEntity) -> bool
520519 {
521520 return (LineEntityItem*)lineEntity.setLinePoints(points);
522521 });
523522 }
524−
523+
525524 return false;
526525 }
527526
@@ -658,3 +657,43 @@ QVariantMap EntityScriptingInterface::getActionArguments(const QUuid& entityID, · 130 unmodified lines
658657 });
659658 return result;
660659 }
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+}

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