Showing the changes to libraries/entities/src/EntityScriptingInterface.cpp (1 of 66 files). Show all
Unified · Split
| @@ -72,12 +72,15 @@ EntityItemProperties convertLocationToScriptSemantics(const EntityItemProperties · 71 unmodified lines | ||
| 72 | 72 | scriptSideProperties.setLocalPosition(entitySideProperties.getPosition()); |
| 73 | 73 | scriptSideProperties.setLocalRotation(entitySideProperties.getRotation()); |
| 74 | 74 | |
| 75 | + bool success; | |
| 75 | 76 | glm::vec3 worldPosition = SpatiallyNestable::localToWorld(entitySideProperties.getPosition(), |
| 76 | 77 | entitySideProperties.getParentID(), |
| 77 | − entitySideProperties.getParentJointIndex()); | |
| 78 | + entitySideProperties.getParentJointIndex(), | |
| 79 | + success); | |
| 78 | 80 | glm::quat worldRotation = SpatiallyNestable::localToWorld(entitySideProperties.getRotation(), |
| 79 | 81 | entitySideProperties.getParentID(), |
| 80 | − entitySideProperties.getParentJointIndex()); | |
| 82 | + entitySideProperties.getParentJointIndex(), | |
| 83 | + success); | |
| 81 | 84 | scriptSideProperties.setPosition(worldPosition); |
| 82 | 85 | scriptSideProperties.setRotation(worldRotation); |
| 83 | 86 | |
| @@ -89,13 +92,15 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti · 5 unmodified lines | ||
| 89 | 92 | // convert position and rotation properties from world-space to local, unless localPosition and localRotation |
| 90 | 93 | // are set. If they are set, they overwrite position and rotation. |
| 91 | 94 | EntityItemProperties entitySideProperties = scriptSideProperties; |
| 95 | + bool success; | |
| 92 | 96 | |
| 93 | 97 | if (scriptSideProperties.localPositionChanged()) { |
| 94 | 98 | entitySideProperties.setPosition(scriptSideProperties.getLocalPosition()); |
| 95 | 99 | } else if (scriptSideProperties.positionChanged()) { |
| 96 | 100 | glm::vec3 localPosition = SpatiallyNestable::worldToLocal(entitySideProperties.getPosition(), |
| 97 | 101 | entitySideProperties.getParentID(), |
| 98 | − entitySideProperties.getParentJointIndex()); | |
| 102 | + entitySideProperties.getParentJointIndex(), | |
| 103 | + success); | |
| 99 | 104 | entitySideProperties.setPosition(localPosition); |
| 100 | 105 | } |
| 101 | 106 | |
| @@ -104,7 +109,8 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti · 2 unmodified lines | ||
| 104 | 109 | } else if (scriptSideProperties.rotationChanged()) { |
| 105 | 110 | glm::quat localRotation = SpatiallyNestable::worldToLocal(entitySideProperties.getRotation(), |
| 106 | 111 | entitySideProperties.getParentID(), |
| 107 | − entitySideProperties.getParentJointIndex()); | |
| 112 | + entitySideProperties.getParentJointIndex(), | |
| 113 | + success); | |
| 108 | 114 | entitySideProperties.setRotation(localRotation); |
| 109 | 115 | } |
| 110 | 116 | |
| @@ -128,6 +134,10 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 17 unmodified lines | ||
| 128 | 134 | auto nodeList = DependencyManager::get<NodeList>(); |
| 129 | 135 | const QUuid myNodeID = nodeList->getSessionUUID(); |
| 130 | 136 | propertiesWithSimID.setSimulationOwner(myNodeID, SCRIPT_EDIT_SIMULATION_PRIORITY); |
| 137 | + if (propertiesWithSimID.parentRelatedPropertyChanged()) { | |
| 138 | + // due to parenting, the server may not know where something is in world-space, so include the bounding cube. | |
| 139 | + propertiesWithSimID.setQueryAACube(entity->getQueryAACube()); | |
| 140 | + } | |
| 131 | 141 | |
| 132 | 142 | // and make note of it now, so we can act on it right away. |
| 133 | 143 | entity->setSimulationOwner(myNodeID, SCRIPT_EDIT_SIMULATION_PRIORITY); |
| @@ -193,16 +203,15 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 59 unmodified lines | ||
| 193 | 203 | QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& scriptSideProperties) { |
| 194 | 204 | EntityItemProperties properties = scriptSideProperties; |
| 195 | 205 | EntityItemID entityID(id); |
| 196 | − // If we have a local entity tree set, then also update it. | |
| 197 | 206 | if (!_entityTree) { |
| 198 | 207 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); |
| 199 | 208 | return id; |
| 200 | 209 | } |
| 210 | + // If we have a local entity tree set, then also update it. | |
| 201 | 211 | |
| 202 | 212 | bool updatedEntity = false; |
| 203 | 213 | _entityTree->withWriteLock([&] { |
| 204 | − if (scriptSideProperties.parentDependentPropertyChanged() || | |
| 205 | − scriptSideProperties.parentIDChanged() || scriptSideProperties.parentJointIndexChanged()) { | |
| 214 | + if (scriptSideProperties.parentRelatedPropertyChanged()) { | |
| 206 | 215 | // All of parentID, parentJointIndex, position, rotation are needed to make sense of any of them. |
| 207 | 216 | // If any of these changed, pull any missing properties from the entity. |
| 208 | 217 | EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID); |
| @@ -265,7 +274,24 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 56 unmodified lines | ||
| 265 | 274 | entity->flagForOwnership(); |
| 266 | 275 | } |
| 267 | 276 | } |
| 277 | + if (properties.parentRelatedPropertyChanged() && entity->computePuffedQueryAACube()) { | |
| 278 | + properties.setQueryAACube(entity->getQueryAACube()); | |
| 279 | + } | |
| 268 | 280 | entity->setLastBroadcast(usecTimestampNow()); |
| 281 | + | |
| 282 | + // if we've moved an entity with children, check/update the queryAACube of all descendents and tell the server | |
| 283 | + // if they've changed. | |
| 284 | + entity->forEachDescendant([&](SpatiallyNestablePointer descendant) { | |
| 285 | + if (descendant->getNestableType() == NestableType::Entity) { | |
| 286 | + if (descendant->computePuffedQueryAACube()) { | |
| 287 | + EntityItemPointer entityDescendant = std::static_pointer_cast<EntityItem>(descendant); | |
| 288 | + EntityItemProperties newQueryCubeProperties; | |
| 289 | + newQueryCubeProperties.setQueryAACube(descendant->getQueryAACube()); | |
| 290 | + queueEntityMessage(PacketType::EntityEdit, descendant->getID(), newQueryCubeProperties); | |
| 291 | + entityDescendant->setLastBroadcast(usecTimestampNow()); | |
| 292 | + } | |
| 293 | + } | |
| 294 | + }); | |
| 269 | 295 | } |
| 270 | 296 | }); |
| 271 | 297 | queueEntityMessage(PacketType::EntityEdit, entityID, properties); |