History

merge from upstream

Seth Alves committed 10 years ago

Commit 942e7712 parents afc1757 047389166 files · +1076 −386Browse files

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

Unified · Split

libraries/entities/src/EntityScriptingInterface.cpp+33−7
@@ -72,12 +72,15 @@ EntityItemProperties convertLocationToScriptSemantics(const EntityItemProperties · 71 unmodified lines
7272 scriptSideProperties.setLocalPosition(entitySideProperties.getPosition());
7373 scriptSideProperties.setLocalRotation(entitySideProperties.getRotation());
7474
75+ bool success;
7576 glm::vec3 worldPosition = SpatiallyNestable::localToWorld(entitySideProperties.getPosition(),
7677 entitySideProperties.getParentID(),
77− entitySideProperties.getParentJointIndex());
78+ entitySideProperties.getParentJointIndex(),
79+ success);
7880 glm::quat worldRotation = SpatiallyNestable::localToWorld(entitySideProperties.getRotation(),
7981 entitySideProperties.getParentID(),
80− entitySideProperties.getParentJointIndex());
82+ entitySideProperties.getParentJointIndex(),
83+ success);
8184 scriptSideProperties.setPosition(worldPosition);
8285 scriptSideProperties.setRotation(worldRotation);
8386
@@ -89,13 +92,15 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti · 5 unmodified lines
8992 // convert position and rotation properties from world-space to local, unless localPosition and localRotation
9093 // are set. If they are set, they overwrite position and rotation.
9194 EntityItemProperties entitySideProperties = scriptSideProperties;
95+ bool success;
9296
9397 if (scriptSideProperties.localPositionChanged()) {
9498 entitySideProperties.setPosition(scriptSideProperties.getLocalPosition());
9599 } else if (scriptSideProperties.positionChanged()) {
96100 glm::vec3 localPosition = SpatiallyNestable::worldToLocal(entitySideProperties.getPosition(),
97101 entitySideProperties.getParentID(),
98− entitySideProperties.getParentJointIndex());
102+ entitySideProperties.getParentJointIndex(),
103+ success);
99104 entitySideProperties.setPosition(localPosition);
100105 }
101106
@@ -104,7 +109,8 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti · 2 unmodified lines
104109 } else if (scriptSideProperties.rotationChanged()) {
105110 glm::quat localRotation = SpatiallyNestable::worldToLocal(entitySideProperties.getRotation(),
106111 entitySideProperties.getParentID(),
107− entitySideProperties.getParentJointIndex());
112+ entitySideProperties.getParentJointIndex(),
113+ success);
108114 entitySideProperties.setRotation(localRotation);
109115 }
110116
@@ -128,6 +134,10 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 17 unmodified lines
128134 auto nodeList = DependencyManager::get<NodeList>();
129135 const QUuid myNodeID = nodeList->getSessionUUID();
130136 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+ }
131141
132142 // and make note of it now, so we can act on it right away.
133143 entity->setSimulationOwner(myNodeID, SCRIPT_EDIT_SIMULATION_PRIORITY);
@@ -193,16 +203,15 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 59 unmodified lines
193203 QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& scriptSideProperties) {
194204 EntityItemProperties properties = scriptSideProperties;
195205 EntityItemID entityID(id);
196− // If we have a local entity tree set, then also update it.
197206 if (!_entityTree) {
198207 queueEntityMessage(PacketType::EntityEdit, entityID, properties);
199208 return id;
200209 }
210+ // If we have a local entity tree set, then also update it.
201211
202212 bool updatedEntity = false;
203213 _entityTree->withWriteLock([&] {
204− if (scriptSideProperties.parentDependentPropertyChanged() ||
205− scriptSideProperties.parentIDChanged() || scriptSideProperties.parentJointIndexChanged()) {
214+ if (scriptSideProperties.parentRelatedPropertyChanged()) {
206215 // All of parentID, parentJointIndex, position, rotation are needed to make sense of any of them.
207216 // If any of these changed, pull any missing properties from the entity.
208217 EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
@@ -265,7 +274,24 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 56 unmodified lines
265274 entity->flagForOwnership();
266275 }
267276 }
277+ if (properties.parentRelatedPropertyChanged() && entity->computePuffedQueryAACube()) {
278+ properties.setQueryAACube(entity->getQueryAACube());
279+ }
268280 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+ });
269295 }
270296 });
271297 queueEntityMessage(PacketType::EntityEdit, entityID, properties);