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
72 scriptSideProperties.setLocalPosition(entitySideProperties.getPosition());72 scriptSideProperties.setLocalPosition(entitySideProperties.getPosition());
73 scriptSideProperties.setLocalRotation(entitySideProperties.getRotation());73 scriptSideProperties.setLocalRotation(entitySideProperties.getRotation());
74 74
75 bool success;
75 glm::vec3 worldPosition = SpatiallyNestable::localToWorld(entitySideProperties.getPosition(),76 glm::vec3 worldPosition = SpatiallyNestable::localToWorld(entitySideProperties.getPosition(),
76 entitySideProperties.getParentID(),77 entitySideProperties.getParentID(),
77 entitySideProperties.getParentJointIndex());78 entitySideProperties.getParentJointIndex(),
79 success);
78 glm::quat worldRotation = SpatiallyNestable::localToWorld(entitySideProperties.getRotation(),80 glm::quat worldRotation = SpatiallyNestable::localToWorld(entitySideProperties.getRotation(),
79 entitySideProperties.getParentID(),81 entitySideProperties.getParentID(),
80 entitySideProperties.getParentJointIndex());82 entitySideProperties.getParentJointIndex(),
83 success);
81 scriptSideProperties.setPosition(worldPosition);84 scriptSideProperties.setPosition(worldPosition);
82 scriptSideProperties.setRotation(worldRotation);85 scriptSideProperties.setRotation(worldRotation);
83 86
@@ -89,13 +92,15 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti · 5 unmodified lines
89 // convert position and rotation properties from world-space to local, unless localPosition and localRotation92 // convert position and rotation properties from world-space to local, unless localPosition and localRotation
90 // are set. If they are set, they overwrite position and rotation.93 // are set. If they are set, they overwrite position and rotation.
91 EntityItemProperties entitySideProperties = scriptSideProperties;94 EntityItemProperties entitySideProperties = scriptSideProperties;
95 bool success;
92 96
93 if (scriptSideProperties.localPositionChanged()) {97 if (scriptSideProperties.localPositionChanged()) {
94 entitySideProperties.setPosition(scriptSideProperties.getLocalPosition());98 entitySideProperties.setPosition(scriptSideProperties.getLocalPosition());
95 } else if (scriptSideProperties.positionChanged()) {99 } else if (scriptSideProperties.positionChanged()) {
96 glm::vec3 localPosition = SpatiallyNestable::worldToLocal(entitySideProperties.getPosition(),100 glm::vec3 localPosition = SpatiallyNestable::worldToLocal(entitySideProperties.getPosition(),
97 entitySideProperties.getParentID(),101 entitySideProperties.getParentID(),
98 entitySideProperties.getParentJointIndex());102 entitySideProperties.getParentJointIndex(),
103 success);
99 entitySideProperties.setPosition(localPosition);104 entitySideProperties.setPosition(localPosition);
100 }105 }
101 106
@@ -104,7 +109,8 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti · 2 unmodified lines
104 } else if (scriptSideProperties.rotationChanged()) {109 } else if (scriptSideProperties.rotationChanged()) {
105 glm::quat localRotation = SpatiallyNestable::worldToLocal(entitySideProperties.getRotation(),110 glm::quat localRotation = SpatiallyNestable::worldToLocal(entitySideProperties.getRotation(),
106 entitySideProperties.getParentID(),111 entitySideProperties.getParentID(),
107 entitySideProperties.getParentJointIndex());112 entitySideProperties.getParentJointIndex(),
113 success);
108 entitySideProperties.setRotation(localRotation);114 entitySideProperties.setRotation(localRotation);
109 }115 }
110 116
@@ -128,6 +134,10 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties · 17 unmodified lines
128 auto nodeList = DependencyManager::get<NodeList>();134 auto nodeList = DependencyManager::get<NodeList>();
129 const QUuid myNodeID = nodeList->getSessionUUID();135 const QUuid myNodeID = nodeList->getSessionUUID();
130 propertiesWithSimID.setSimulationOwner(myNodeID, SCRIPT_EDIT_SIMULATION_PRIORITY);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 // and make note of it now, so we can act on it right away.142 // and make note of it now, so we can act on it right away.
133 entity->setSimulationOwner(myNodeID, SCRIPT_EDIT_SIMULATION_PRIORITY);143 entity->setSimulationOwner(myNodeID, SCRIPT_EDIT_SIMULATION_PRIORITY);
@@ -193,16 +203,15 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit · 59 unmodified lines
193QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& scriptSideProperties) {203QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& scriptSideProperties) {
194 EntityItemProperties properties = scriptSideProperties;204 EntityItemProperties properties = scriptSideProperties;
195 EntityItemID entityID(id);205 EntityItemID entityID(id);
196 // If we have a local entity tree set, then also update it.
197 if (!_entityTree) {206 if (!_entityTree) {
198 queueEntityMessage(PacketType::EntityEdit, entityID, properties);207 queueEntityMessage(PacketType::EntityEdit, entityID, properties);
199 return id;208 return id;
200 }209 }
210 // If we have a local entity tree set, then also update it.
201 211
202 bool updatedEntity = false;212 bool updatedEntity = false;
203 _entityTree->withWriteLock([&] {213 _entityTree->withWriteLock([&] {
204 if (scriptSideProperties.parentDependentPropertyChanged() ||214 if (scriptSideProperties.parentRelatedPropertyChanged()) {
205 scriptSideProperties.parentIDChanged() || scriptSideProperties.parentJointIndexChanged()) {
206 // All of parentID, parentJointIndex, position, rotation are needed to make sense of any of them.215 // All of parentID, parentJointIndex, position, rotation are needed to make sense of any of them.
207 // If any of these changed, pull any missing properties from the entity.216 // If any of these changed, pull any missing properties from the entity.
208 EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);217 EntityItemPointer entity = _entityTree->findEntityByEntityItemID(entityID);
@@ -265,7 +274,24 @@ QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& · 56 unmodified lines
265 entity->flagForOwnership();274 entity->flagForOwnership();
266 }275 }
267 }276 }
277 if (properties.parentRelatedPropertyChanged() && entity->computePuffedQueryAACube()) {
278 properties.setQueryAACube(entity->getQueryAACube());
279 }
268 entity->setLastBroadcast(usecTimestampNow());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 queueEntityMessage(PacketType::EntityEdit, entityID, properties);297 queueEntityMessage(PacketType::EntityEdit, entityID, properties);