Remember attachment parameters per joint (as well as the last joint used) so

that the gun script correctly allows both guns' positions to be tweaked.
This commit is contained in:
Andrzej Kapolka 2014-05-12 12:16:30 -07:00
parent 47268fef32
commit 8541df9c32
5 changed files with 77 additions and 26 deletions

View file

@ -520,8 +520,9 @@ void MyAvatar::saveAttachmentData(const AttachmentData& attachment) const {
settings->beginGroup("savedAttachmentData"); settings->beginGroup("savedAttachmentData");
settings->beginGroup(_skeletonModel.getURL().toString()); settings->beginGroup(_skeletonModel.getURL().toString());
settings->beginGroup(attachment.modelURL.toString()); settings->beginGroup(attachment.modelURL.toString());
settings->setValue("jointName", attachment.jointName); settings->setValue("jointName", attachment.jointName);
settings->beginGroup(attachment.jointName);
settings->setValue("translation_x", attachment.translation.x); settings->setValue("translation_x", attachment.translation.x);
settings->setValue("translation_y", attachment.translation.y); settings->setValue("translation_y", attachment.translation.y);
settings->setValue("translation_z", attachment.translation.z); settings->setValue("translation_z", attachment.translation.z);
@ -534,10 +535,11 @@ void MyAvatar::saveAttachmentData(const AttachmentData& attachment) const {
settings->endGroup(); settings->endGroup();
settings->endGroup(); settings->endGroup();
settings->endGroup(); settings->endGroup();
settings->endGroup();
Application::getInstance()->unlockSettings(); Application::getInstance()->unlockSettings();
} }
AttachmentData MyAvatar::loadAttachmentData(const QUrl& modelURL) const { AttachmentData MyAvatar::loadAttachmentData(const QUrl& modelURL, const QString& jointName) const {
QSettings* settings = Application::getInstance()->lockSettings(); QSettings* settings = Application::getInstance()->lockSettings();
settings->beginGroup("savedAttachmentData"); settings->beginGroup("savedAttachmentData");
settings->beginGroup(_skeletonModel.getURL().toString()); settings->beginGroup(_skeletonModel.getURL().toString());
@ -545,20 +547,30 @@ AttachmentData MyAvatar::loadAttachmentData(const QUrl& modelURL) const {
AttachmentData attachment; AttachmentData attachment;
attachment.modelURL = modelURL; attachment.modelURL = modelURL;
attachment.jointName = settings->value("jointName").toString(); if (jointName.isEmpty()) {
attachment.translation.x = loadSetting(settings, "translation_x", 0.0f); attachment.jointName = settings->value("jointName").toString();
attachment.translation.y = loadSetting(settings, "translation_y", 0.0f); } else {
attachment.translation.z = loadSetting(settings, "translation_z", 0.0f); attachment.jointName = jointName;
glm::vec3 eulers; }
eulers.x = loadSetting(settings, "rotation_x", 0.0f); settings->beginGroup(attachment.jointName);
eulers.y = loadSetting(settings, "rotation_y", 0.0f); if (settings->contains("translation_x")) {
eulers.z = loadSetting(settings, "rotation_z", 0.0f); attachment.translation.x = loadSetting(settings, "translation_x", 0.0f);
attachment.rotation = glm::quat(eulers); attachment.translation.y = loadSetting(settings, "translation_y", 0.0f);
attachment.scale = loadSetting(settings, "scale", 1.0f); attachment.translation.z = loadSetting(settings, "translation_z", 0.0f);
glm::vec3 eulers;
eulers.x = loadSetting(settings, "rotation_x", 0.0f);
eulers.y = loadSetting(settings, "rotation_y", 0.0f);
eulers.z = loadSetting(settings, "rotation_z", 0.0f);
attachment.rotation = glm::quat(eulers);
attachment.scale = loadSetting(settings, "scale", 1.0f);
} else {
attachment = AttachmentData();
}
settings->endGroup(); settings->endGroup();
settings->endGroup(); settings->endGroup();
settings->endGroup(); settings->endGroup();
settings->endGroup();
Application::getInstance()->unlockSettings(); Application::getInstance()->unlockSettings();
return attachment; return attachment;
@ -650,8 +662,8 @@ void MyAvatar::attach(const QString& modelURL, const QString& jointName, const g
return; return;
} }
if (useSaved) { if (useSaved) {
AttachmentData attachment = loadAttachmentData(modelURL); AttachmentData attachment = loadAttachmentData(modelURL, jointName);
if (!attachment.jointName.isEmpty()) { if (attachment.isValid()) {
Avatar::attach(modelURL, attachment.jointName, attachment.translation, Avatar::attach(modelURL, attachment.jointName, attachment.translation,
attachment.rotation, attachment.scale, allowDuplicates, useSaved); attachment.rotation, attachment.scale, allowDuplicates, useSaved);
return; return;

View file

@ -67,7 +67,7 @@ public:
void loadData(QSettings* settings); void loadData(QSettings* settings);
void saveAttachmentData(const AttachmentData& attachment) const; void saveAttachmentData(const AttachmentData& attachment) const;
AttachmentData loadAttachmentData(const QUrl& modelURL) const; AttachmentData loadAttachmentData(const QUrl& modelURL, const QString& jointName = QString()) const;
// Set what driving keys are being pressed to control thrust levels // Set what driving keys are being pressed to control thrust levels
void setDriveKeys(int key, float val) { _driveKeys[key] = val; }; void setDriveKeys(int key, float val) { _driveKeys[key] = val; };

View file

@ -97,7 +97,8 @@ static QDoubleSpinBox* createRotationBox(AttachmentPanel* panel, float value) {
} }
AttachmentPanel::AttachmentPanel(AttachmentsDialog* dialog, const AttachmentData& data) : AttachmentPanel::AttachmentPanel(AttachmentsDialog* dialog, const AttachmentData& data) :
_dialog(dialog) { _dialog(dialog),
_applying(false) {
setFrameStyle(QFrame::StyledPanel); setFrameStyle(QFrame::StyledPanel);
QFormLayout* layout = new QFormLayout(); QFormLayout* layout = new QFormLayout();
@ -121,7 +122,7 @@ AttachmentPanel::AttachmentPanel(AttachmentsDialog* dialog, const AttachmentData
} }
} }
_jointName->setCurrentText(data.jointName); _jointName->setCurrentText(data.jointName);
connect(_jointName, SIGNAL(currentIndexChanged(int)), SLOT(updateAttachmentData())); connect(_jointName, SIGNAL(currentIndexChanged(int)), SLOT(jointNameChanged()));
QHBoxLayout* translationBox = new QHBoxLayout(); QHBoxLayout* translationBox = new QHBoxLayout();
translationBox->addWidget(_translationX = createTranslationBox(this, data.translation.x)); translationBox->addWidget(_translationX = createTranslationBox(this, data.translation.x));
@ -171,25 +172,57 @@ void AttachmentPanel::setModelURL(const QString& url) {
void AttachmentPanel::modelURLChanged() { void AttachmentPanel::modelURLChanged() {
// check for saved attachment data // check for saved attachment data
if (_modelURL->text().isEmpty()) {
_dialog->updateAttachmentData();
return;
}
AttachmentData attachment = Application::getInstance()->getAvatar()->loadAttachmentData(_modelURL->text()); AttachmentData attachment = Application::getInstance()->getAvatar()->loadAttachmentData(_modelURL->text());
if (!attachment.jointName.isEmpty()) { if (attachment.isValid()) {
_applying = true;
_jointName->setCurrentText(attachment.jointName); _jointName->setCurrentText(attachment.jointName);
_translationX->setValue(attachment.translation.x); applyAttachmentData(attachment);
_translationY->setValue(attachment.translation.y);
_translationZ->setValue(attachment.translation.z);
glm::vec3 eulers = glm::degrees(safeEulerAngles(attachment.rotation));
_rotationX->setValue(eulers.x);
_rotationY->setValue(eulers.y);
_rotationZ->setValue(eulers.z);
_scale->setValue(attachment.scale);
} }
_dialog->updateAttachmentData(); _dialog->updateAttachmentData();
} }
void AttachmentPanel::jointNameChanged() {
if (_applying) {
return;
}
// check for saved attachment data specific to this joint
if (_modelURL->text().isEmpty()) {
_dialog->updateAttachmentData();
return;
}
AttachmentData attachment = Application::getInstance()->getAvatar()->loadAttachmentData(
_modelURL->text(), _jointName->currentText());
if (attachment.isValid()) {
applyAttachmentData(attachment);
}
updateAttachmentData();
}
void AttachmentPanel::updateAttachmentData() { void AttachmentPanel::updateAttachmentData() {
if (_applying) {
return;
}
// save the attachment data under the model URL (if any) // save the attachment data under the model URL (if any)
if (!_modelURL->text().isEmpty()) { if (!_modelURL->text().isEmpty()) {
Application::getInstance()->getAvatar()->saveAttachmentData(getAttachmentData()); Application::getInstance()->getAvatar()->saveAttachmentData(getAttachmentData());
} }
_dialog->updateAttachmentData(); _dialog->updateAttachmentData();
} }
void AttachmentPanel::applyAttachmentData(const AttachmentData& attachment) {
_applying = true;
_translationX->setValue(attachment.translation.x);
_translationY->setValue(attachment.translation.y);
_translationZ->setValue(attachment.translation.z);
glm::vec3 eulers = glm::degrees(safeEulerAngles(attachment.rotation));
_rotationX->setValue(eulers.x);
_rotationY->setValue(eulers.y);
_rotationZ->setValue(eulers.z);
_scale->setValue(attachment.scale);
_applying = false;
_dialog->updateAttachmentData();
}

View file

@ -61,10 +61,13 @@ private slots:
void chooseModelURL(); void chooseModelURL();
void setModelURL(const QString& url); void setModelURL(const QString& url);
void modelURLChanged(); void modelURLChanged();
void jointNameChanged();
void updateAttachmentData(); void updateAttachmentData();
private: private:
void applyAttachmentData(const AttachmentData& attachment);
AttachmentsDialog* _dialog; AttachmentsDialog* _dialog;
QLineEdit* _modelURL; QLineEdit* _modelURL;
QComboBox* _jointName; QComboBox* _jointName;
@ -75,6 +78,7 @@ private:
QDoubleSpinBox* _rotationY; QDoubleSpinBox* _rotationY;
QDoubleSpinBox* _rotationZ; QDoubleSpinBox* _rotationZ;
QDoubleSpinBox* _scale; QDoubleSpinBox* _scale;
bool _applying;
}; };
#endif // hifi_AttachmentsDialog_h #endif // hifi_AttachmentsDialog_h

View file

@ -352,6 +352,8 @@ public:
AttachmentData(); AttachmentData();
bool isValid() const { return modelURL.isValid(); }
bool operator==(const AttachmentData& other) const; bool operator==(const AttachmentData& other) const;
}; };