Merge pull request #8992 from AndrewMeadows/fix-autoresize

fix autoresize of Entities.addEntity() and fix Quat.lookAtSimple()
This commit is contained in:
Brad Hefta-Gaub 2016-11-03 13:41:47 -07:00 committed by GitHub
commit f10e43d148
2 changed files with 32 additions and 21 deletions

View file

@ -55,7 +55,10 @@ void RenderableModelEntityItem::setModelURL(const QString& url) {
auto& currentURL = getParsedModelURL(); auto& currentURL = getParsedModelURL();
ModelEntityItem::setModelURL(url); ModelEntityItem::setModelURL(url);
if (currentURL != getParsedModelURL() || !_model) { if (currentURL != getParsedModelURL()) {
_needsModelReload = true;
}
if (_needsModelReload || !_model) {
EntityTreePointer tree = getTree(); EntityTreePointer tree = getTree();
if (tree) { if (tree) {
QMetaObject::invokeMethod(tree.get(), "callLoader", Qt::QueuedConnection, Q_ARG(EntityItemID, getID())); QMetaObject::invokeMethod(tree.get(), "callLoader", Qt::QueuedConnection, Q_ARG(EntityItemID, getID()));
@ -523,17 +526,24 @@ bool RenderableModelEntityItem::needsToCallUpdate() const {
} }
void RenderableModelEntityItem::update(const quint64& now) { void RenderableModelEntityItem::update(const quint64& now) {
if (!_dimensionsInitialized && _model && _model->isActive()) { if (!_dimensionsInitialized) {
if (_model->isLoaded()) { if (_model) {
EntityItemProperties properties; if (_model->isActive() && _model->isLoaded()) {
properties.setLastEdited(usecTimestampNow()); // we must set the edit time since we're editing it EntityItemProperties properties;
auto extents = _model->getMeshExtents(); properties.setLastEdited(usecTimestampNow()); // we must set the edit time since we're editing it
properties.setDimensions(extents.maximum - extents.minimum); auto extents = _model->getMeshExtents();
qCDebug(entitiesrenderer) << "Autoresizing:" << (!getName().isEmpty() ? getName() : getModelURL()); properties.setDimensions(extents.maximum - extents.minimum);
QMetaObject::invokeMethod(DependencyManager::get<EntityScriptingInterface>().data(), "editEntity", qCDebug(entitiesrenderer) << "Autoresizing:" << (!getName().isEmpty() ? getName() : getModelURL());
Qt::QueuedConnection, QMetaObject::invokeMethod(DependencyManager::get<EntityScriptingInterface>().data(), "editEntity",
Q_ARG(QUuid, getEntityItemID()), Qt::QueuedConnection,
Q_ARG(EntityItemProperties, properties)); Q_ARG(QUuid, getEntityItemID()),
Q_ARG(EntityItemProperties, properties));
}
} else if (_needsModelReload) {
EntityTreePointer tree = getTree();
if (tree) {
QMetaObject::invokeMethod(tree.get(), "callLoader", Qt::QueuedConnection, Q_ARG(EntityItemID, getID()));
}
} }
} }

View file

@ -37,29 +37,30 @@ glm::quat Quat::lookAt(const glm::vec3& eye, const glm::vec3& center, const glm:
glm::quat Quat::lookAtSimple(const glm::vec3& eye, const glm::vec3& center) { glm::quat Quat::lookAtSimple(const glm::vec3& eye, const glm::vec3& center) {
auto dir = glm::normalize(center - eye); auto dir = glm::normalize(center - eye);
// if the direction is nearly aligned with the Y axis, then use the X axis for 'up' // if the direction is nearly aligned with the Y axis, then use the X axis for 'up'
if (dir.x < 0.001f && dir.z < 0.001f) { const float MAX_ABS_Y_COMPONENT = 0.9999991f;
if (fabsf(dir.y) > MAX_ABS_Y_COMPONENT) {
return lookAt(eye, center, Vectors::UNIT_X); return lookAt(eye, center, Vectors::UNIT_X);
} }
return lookAt(eye, center, Vectors::UNIT_Y); return lookAt(eye, center, Vectors::UNIT_Y);
} }
glm::quat Quat::multiply(const glm::quat& q1, const glm::quat& q2) { glm::quat Quat::multiply(const glm::quat& q1, const glm::quat& q2) {
return q1 * q2; return q1 * q2;
} }
glm::quat Quat::fromVec3Degrees(const glm::vec3& eulerAngles) { glm::quat Quat::fromVec3Degrees(const glm::vec3& eulerAngles) {
return glm::quat(glm::radians(eulerAngles)); return glm::quat(glm::radians(eulerAngles));
} }
glm::quat Quat::fromVec3Radians(const glm::vec3& eulerAngles) { glm::quat Quat::fromVec3Radians(const glm::vec3& eulerAngles) {
return glm::quat(eulerAngles); return glm::quat(eulerAngles);
} }
glm::quat Quat::fromPitchYawRollDegrees(float pitch, float yaw, float roll) { glm::quat Quat::fromPitchYawRollDegrees(float pitch, float yaw, float roll) {
return glm::quat(glm::radians(glm::vec3(pitch, yaw, roll))); return glm::quat(glm::radians(glm::vec3(pitch, yaw, roll)));
} }
glm::quat Quat::fromPitchYawRollRadians(float pitch, float yaw, float roll) { glm::quat Quat::fromPitchYawRollRadians(float pitch, float yaw, float roll) {
return glm::quat(glm::vec3(pitch, yaw, roll)); return glm::quat(glm::vec3(pitch, yaw, roll));
} }