Support for adding soft attachments from script.

Also, bug fixes for setting MyAvatar.attachmentData property.
This commit is contained in:
Anthony J. Thibault 2016-01-07 16:12:36 -08:00
parent 01c9de4f9d
commit 031f59b7b5
5 changed files with 50 additions and 26 deletions

View file

@ -940,7 +940,7 @@ static std::shared_ptr<Model> allocateAttachmentModel(bool isSoft, RigPointer ri
void Avatar::setAttachmentData(const QVector<AttachmentData>& attachmentData) { void Avatar::setAttachmentData(const QVector<AttachmentData>& attachmentData) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "setAttachmentData", Qt::DirectConnection, QMetaObject::invokeMethod(this, "setAttachmentData", Qt::BlockingQueuedConnection,
Q_ARG(const QVector<AttachmentData>, attachmentData)); Q_ARG(const QVector<AttachmentData>, attachmentData));
return; return;
} }

View file

@ -1022,12 +1022,12 @@ void MyAvatar::useFullAvatarURL(const QUrl& fullAvatarURL, const QString& modelN
} }
void MyAvatar::setAttachmentData(const QVector<AttachmentData>& attachmentData) { void MyAvatar::setAttachmentData(const QVector<AttachmentData>& attachmentData) {
Avatar::setAttachmentData(attachmentData);
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "setAttachmentData", Qt::DirectConnection, QMetaObject::invokeMethod(this, "setAttachmentData", Qt::BlockingQueuedConnection,
Q_ARG(const QVector<AttachmentData>, attachmentData)); Q_ARG(const QVector<AttachmentData>, attachmentData));
return; return;
} }
Avatar::setAttachmentData(attachmentData);
_billboardValid = false; _billboardValid = false;
} }
@ -1165,21 +1165,25 @@ void MyAvatar::setCollisionSoundURL(const QString& url) {
} }
} }
void MyAvatar::attach(const QString& modelURL, const QString& jointName, const glm::vec3& translation, void MyAvatar::attach(const QString& modelURL, const QString& jointName,
const glm::quat& rotation, float scale, bool allowDuplicates, bool useSaved) { const glm::vec3& translation, const glm::quat& rotation,
float scale, bool isSoft,
bool allowDuplicates, bool useSaved) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
Avatar::attach(modelURL, jointName, translation, rotation, scale, allowDuplicates, useSaved); Avatar::attach(modelURL, jointName, translation, rotation, scale, isSoft, allowDuplicates, useSaved);
return; return;
} }
if (useSaved) { if (useSaved) {
AttachmentData attachment = loadAttachmentData(modelURL, jointName); AttachmentData attachment = loadAttachmentData(modelURL, jointName);
if (attachment.isValid()) { if (attachment.isValid()) {
Avatar::attach(modelURL, attachment.jointName, attachment.translation, Avatar::attach(modelURL, attachment.jointName,
attachment.rotation, attachment.scale, allowDuplicates, useSaved); attachment.translation, attachment.rotation,
attachment.scale, attachment.isSoft,
allowDuplicates, useSaved);
return; return;
} }
} }
Avatar::attach(modelURL, jointName, translation, rotation, scale, allowDuplicates, useSaved); Avatar::attach(modelURL, jointName, translation, rotation, scale, isSoft, allowDuplicates, useSaved);
} }
void MyAvatar::renderBody(RenderArgs* renderArgs, ViewFrustum* renderFrustum, float glowLevel) { void MyAvatar::renderBody(RenderArgs* renderArgs, ViewFrustum* renderFrustum, float glowLevel) {

View file

@ -295,7 +295,8 @@ private:
void setScriptedMotorTimescale(float timescale); void setScriptedMotorTimescale(float timescale);
void setScriptedMotorFrame(QString frame); void setScriptedMotorFrame(QString frame);
virtual void attach(const QString& modelURL, const QString& jointName = QString(), virtual void attach(const QString& modelURL, const QString& jointName = QString(),
const glm::vec3& translation = glm::vec3(), const glm::quat& rotation = glm::quat(), float scale = 1.0f, const glm::vec3& translation = glm::vec3(), const glm::quat& rotation = glm::quat(),
float scale = 1.0f, bool isSoft = false,
bool allowDuplicates = false, bool useSaved = true) override; bool allowDuplicates = false, bool useSaved = true) override;
//void beginFollowingHMD(); //void beginFollowingHMD();

View file

@ -1085,12 +1085,15 @@ void AvatarData::setAttachmentData(const QVector<AttachmentData>& attachmentData
_attachmentData = attachmentData; _attachmentData = attachmentData;
} }
void AvatarData::attach(const QString& modelURL, const QString& jointName, const glm::vec3& translation, void AvatarData::attach(const QString& modelURL, const QString& jointName,
const glm::quat& rotation, float scale, bool allowDuplicates, bool useSaved) { const glm::vec3& translation, const glm::quat& rotation,
float scale, bool isSoft,
bool allowDuplicates, bool useSaved) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "attach", Q_ARG(const QString&, modelURL), Q_ARG(const QString&, jointName), QMetaObject::invokeMethod(this, "attach", Q_ARG(const QString&, modelURL), Q_ARG(const QString&, jointName),
Q_ARG(const glm::vec3&, translation), Q_ARG(const glm::quat&, rotation), Q_ARG(const glm::vec3&, translation), Q_ARG(const glm::quat&, rotation),
Q_ARG(float, scale), Q_ARG(bool, allowDuplicates), Q_ARG(bool, useSaved)); Q_ARG(float, scale), Q_ARG(bool, isSoft),
Q_ARG(bool, allowDuplicates), Q_ARG(bool, useSaved));
return; return;
} }
QVector<AttachmentData> attachmentData = getAttachmentData(); QVector<AttachmentData> attachmentData = getAttachmentData();
@ -1107,6 +1110,7 @@ void AvatarData::attach(const QString& modelURL, const QString& jointName, const
data.translation = translation; data.translation = translation;
data.rotation = rotation; data.rotation = rotation;
data.scale = scale; data.scale = scale;
data.isSoft = isSoft;
attachmentData.append(data); attachmentData.append(data);
setAttachmentData(attachmentData); setAttachmentData(attachmentData);
} }
@ -1334,7 +1338,7 @@ QDataStream& operator>>(QDataStream& in, AttachmentData& attachment) {
attachment.translation >> attachment.rotation >> attachment.scale >> attachment.isSoft; attachment.translation >> attachment.rotation >> attachment.scale >> attachment.isSoft;
} }
void AttachmentDataObject::setModelURL(const QString& modelURL) const { void AttachmentDataObject::setModelURL(const QString& modelURL) {
AttachmentData data = qscriptvalue_cast<AttachmentData>(thisObject()); AttachmentData data = qscriptvalue_cast<AttachmentData>(thisObject());
data.modelURL = modelURL; data.modelURL = modelURL;
thisObject() = engine()->toScriptValue(data); thisObject() = engine()->toScriptValue(data);
@ -1344,7 +1348,7 @@ QString AttachmentDataObject::getModelURL() const {
return qscriptvalue_cast<AttachmentData>(thisObject()).modelURL.toString(); return qscriptvalue_cast<AttachmentData>(thisObject()).modelURL.toString();
} }
void AttachmentDataObject::setJointName(const QString& jointName) const { void AttachmentDataObject::setJointName(const QString& jointName) {
AttachmentData data = qscriptvalue_cast<AttachmentData>(thisObject()); AttachmentData data = qscriptvalue_cast<AttachmentData>(thisObject());
data.jointName = jointName; data.jointName = jointName;
thisObject() = engine()->toScriptValue(data); thisObject() = engine()->toScriptValue(data);
@ -1354,7 +1358,7 @@ QString AttachmentDataObject::getJointName() const {
return qscriptvalue_cast<AttachmentData>(thisObject()).jointName; return qscriptvalue_cast<AttachmentData>(thisObject()).jointName;
} }
void AttachmentDataObject::setTranslation(const glm::vec3& translation) const { void AttachmentDataObject::setTranslation(const glm::vec3& translation) {
AttachmentData data = qscriptvalue_cast<AttachmentData>(thisObject()); AttachmentData data = qscriptvalue_cast<AttachmentData>(thisObject());
data.translation = translation; data.translation = translation;
thisObject() = engine()->toScriptValue(data); thisObject() = engine()->toScriptValue(data);
@ -1364,7 +1368,7 @@ glm::vec3 AttachmentDataObject::getTranslation() const {
return qscriptvalue_cast<AttachmentData>(thisObject()).translation; return qscriptvalue_cast<AttachmentData>(thisObject()).translation;
} }
void AttachmentDataObject::setRotation(const glm::quat& rotation) const { void AttachmentDataObject::setRotation(const glm::quat& rotation) {
AttachmentData data = qscriptvalue_cast<AttachmentData>(thisObject()); AttachmentData data = qscriptvalue_cast<AttachmentData>(thisObject());
data.rotation = rotation; data.rotation = rotation;
thisObject() = engine()->toScriptValue(data); thisObject() = engine()->toScriptValue(data);
@ -1374,7 +1378,7 @@ glm::quat AttachmentDataObject::getRotation() const {
return qscriptvalue_cast<AttachmentData>(thisObject()).rotation; return qscriptvalue_cast<AttachmentData>(thisObject()).rotation;
} }
void AttachmentDataObject::setScale(float scale) const { void AttachmentDataObject::setScale(float scale) {
AttachmentData data = qscriptvalue_cast<AttachmentData>(thisObject()); AttachmentData data = qscriptvalue_cast<AttachmentData>(thisObject());
data.scale = scale; data.scale = scale;
thisObject() = engine()->toScriptValue(data); thisObject() = engine()->toScriptValue(data);
@ -1384,6 +1388,16 @@ float AttachmentDataObject::getScale() const {
return qscriptvalue_cast<AttachmentData>(thisObject()).scale; return qscriptvalue_cast<AttachmentData>(thisObject()).scale;
} }
void AttachmentDataObject::setIsSoft(bool isSoft) {
AttachmentData data = qscriptvalue_cast<AttachmentData>(thisObject());
data.isSoft = isSoft;
thisObject() = engine()->toScriptValue(data);
}
bool AttachmentDataObject::getIsSoft() const {
return qscriptvalue_cast<AttachmentData>(thisObject()).isSoft;
}
void registerAvatarTypes(QScriptEngine* engine) { void registerAvatarTypes(QScriptEngine* engine) {
qScriptRegisterSequenceMetaType<QVector<AttachmentData> >(engine); qScriptRegisterSequenceMetaType<QVector<AttachmentData> >(engine);
engine->setDefaultPrototype(qMetaTypeId<AttachmentData>(), engine->newQObject( engine->setDefaultPrototype(qMetaTypeId<AttachmentData>(), engine->newQObject(

View file

@ -304,8 +304,9 @@ public:
Q_INVOKABLE virtual void setAttachmentData(const QVector<AttachmentData>& attachmentData); Q_INVOKABLE virtual void setAttachmentData(const QVector<AttachmentData>& attachmentData);
Q_INVOKABLE virtual void attach(const QString& modelURL, const QString& jointName = QString(), Q_INVOKABLE virtual void attach(const QString& modelURL, const QString& jointName = QString(),
const glm::vec3& translation = glm::vec3(), const glm::quat& rotation = glm::quat(), float scale = 1.0f, const glm::vec3& translation = glm::vec3(), const glm::quat& rotation = glm::quat(),
bool allowDuplicates = false, bool useSaved = true); float scale = 1.0f, bool isSoft = false,
bool allowDuplicates = false, bool useSaved = true);
Q_INVOKABLE void detachOne(const QString& modelURL, const QString& jointName = QString()); Q_INVOKABLE void detachOne(const QString& modelURL, const QString& jointName = QString());
Q_INVOKABLE void detachAll(const QString& modelURL, const QString& jointName = QString()); Q_INVOKABLE void detachAll(const QString& modelURL, const QString& jointName = QString());
@ -468,23 +469,27 @@ class AttachmentDataObject : public QObject, protected QScriptable {
Q_PROPERTY(glm::vec3 translation READ getTranslation WRITE setTranslation) Q_PROPERTY(glm::vec3 translation READ getTranslation WRITE setTranslation)
Q_PROPERTY(glm::quat rotation READ getRotation WRITE setRotation) Q_PROPERTY(glm::quat rotation READ getRotation WRITE setRotation)
Q_PROPERTY(float scale READ getScale WRITE setScale) Q_PROPERTY(float scale READ getScale WRITE setScale)
Q_PROPERTY(bool isSoft READ getIsSoft WRITE setIsSoft)
public: public:
Q_INVOKABLE void setModelURL(const QString& modelURL) const; Q_INVOKABLE void setModelURL(const QString& modelURL);
Q_INVOKABLE QString getModelURL() const; Q_INVOKABLE QString getModelURL() const;
Q_INVOKABLE void setJointName(const QString& jointName) const; Q_INVOKABLE void setJointName(const QString& jointName);
Q_INVOKABLE QString getJointName() const; Q_INVOKABLE QString getJointName() const;
Q_INVOKABLE void setTranslation(const glm::vec3& translation) const; Q_INVOKABLE void setTranslation(const glm::vec3& translation);
Q_INVOKABLE glm::vec3 getTranslation() const; Q_INVOKABLE glm::vec3 getTranslation() const;
Q_INVOKABLE void setRotation(const glm::quat& rotation) const; Q_INVOKABLE void setRotation(const glm::quat& rotation);
Q_INVOKABLE glm::quat getRotation() const; Q_INVOKABLE glm::quat getRotation() const;
Q_INVOKABLE void setScale(float scale) const; Q_INVOKABLE void setScale(float scale);
Q_INVOKABLE float getScale() const; Q_INVOKABLE float getScale() const;
Q_INVOKABLE void setIsSoft(bool scale);
Q_INVOKABLE bool getIsSoft() const;
}; };
void registerAvatarTypes(QScriptEngine* engine); void registerAvatarTypes(QScriptEngine* engine);