From 8cd101ac57a3cdeae4f253477e3a5fde04bdbd11 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 28 May 2014 15:57:38 -0700 Subject: [PATCH 01/11] Added getJointCombinedRotation to Models --- interface/src/renderer/Model.cpp | 12 ++++++++++-- interface/src/renderer/Model.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 678a4b09c0..91c14d7758 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -641,8 +641,16 @@ bool Model::getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind) return false; } rotation = _jointStates[jointIndex].combinedRotation * - (fromBind ? _geometry->getFBXGeometry().joints[jointIndex].inverseBindRotation : - _geometry->getFBXGeometry().joints[jointIndex].inverseDefaultRotation); + (fromBind ? _geometry->getFBXGeometry().joints[jointIndex].inverseBindRotation : + _geometry->getFBXGeometry().joints[jointIndex].inverseDefaultRotation); + return true; +} + +bool Model::getJointCombinedRotation(int jointIndex, glm::quat& rotation) const { + if (jointIndex == -1 || _jointStates.isEmpty()) { + return false; + } + rotation = _jointStates[jointIndex].combinedRotation; return true; } diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index a4e45287dd..91429a3677 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -123,6 +123,7 @@ public: bool getJointPosition(int jointIndex, glm::vec3& position) const; bool getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind = false) const; + bool getJointCombinedRotation(int jointIndex, glm::quat& rotation) const; QStringList getJointNames() const; From b4deed775e224d99e1f8b19d1a59e16ba9d2c392 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 28 May 2014 15:59:42 -0700 Subject: [PATCH 02/11] Added joints position and combined rotation to scripting interface --- interface/src/avatar/Avatar.cpp | 25 +++++++++++++++++++++++++ interface/src/avatar/Avatar.h | 7 ++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 306dc0194e..55c0830dfb 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -705,6 +705,30 @@ QStringList Avatar::getJointNames() const { return _skeletonModel.isActive() ? _skeletonModel.getGeometry()->getFBXGeometry().getJointNames() : QStringList(); } +glm::vec3 Avatar::getJointPosition(int index) const { + glm::vec3 position(0,0,0); + _skeletonModel.getJointPosition(index, position); + return position; +} + +glm::vec3 Avatar::getJointPosition(const QString& name) const { + glm::vec3 position(0,0,0); + _skeletonModel.getJointPosition(getJointIndex(name), position); + return position; +} + +glm::quat Avatar::getJointCombinedRotation(int index) const { + glm::quat rotation; + _skeletonModel.getJointCombinedRotation(index, rotation); + return rotation; +} + +glm::quat Avatar::getJointCombinedRotation(const QString& name) const { + glm::quat rotation; + _skeletonModel.getJointCombinedRotation(getJointIndex(name), rotation); + return rotation; +} + void Avatar::setFaceModelURL(const QUrl& faceModelURL) { AvatarData::setFaceModelURL(faceModelURL); const QUrl DEFAULT_FACE_MODEL_URL = QUrl::fromLocalFile(Application::resourcesPath() + "meshes/defaultAvatar_head.fst"); @@ -725,6 +749,7 @@ void Avatar::setAttachmentData(const QVector& attachmentData) { // make sure we have as many models as attachments while (_attachmentModels.size() < attachmentData.size()) { Model* model = new Model(this); + model->setSnapModelToCenter(true); model->init(); _attachmentModels.append(model); } diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index db13656546..f928881068 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -152,7 +152,12 @@ public: quint32 getCollisionGroups() const { return _collisionGroups; } virtual void setCollisionGroups(quint32 collisionGroups) { _collisionGroups = (collisionGroups & VALID_COLLISION_GROUPS); } - + + Q_INVOKABLE glm::vec3 getJointPosition(int index) const; + Q_INVOKABLE glm::vec3 getJointPosition(const QString& name) const; + Q_INVOKABLE glm::quat getJointCombinedRotation(int index) const; + Q_INVOKABLE glm::quat getJointCombinedRotation(const QString& name) const; + public slots: void updateCollisionGroups(); From 372ddc92fdd27de5c5adb0c634eb97a70a068a5f Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 28 May 2014 16:00:37 -0700 Subject: [PATCH 03/11] Added attaching of model to MyAvatar when close enough --- examples/editModels.js | 109 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/examples/editModels.js b/examples/editModels.js index 30d1e4edf4..cf9b9abbdc 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -40,6 +40,17 @@ var modelURLs = [ var toolBar; + +var jointList = MyAvatar.getJointNames(); +//print("\n# Joint list start"); +//for (var i = 0; i < jointList.length; i++) { +// Vec3.print("jointIndex = " + jointList[i] + " = " + i, MyAvatar.getJointPosition(jointList[i])); +//} +//print("# Joint list end"); + + + + function isLocked(properties) { // special case to lock the ground plane model in hq. if (location.hostname == "hq.highfidelity.io" && @@ -81,6 +92,7 @@ function controller(wichSide) { this.grabbing = false; this.modelID = { isKnownID: false }; + this.modelURL = ""; this.oldModelRotation; this.oldModelPosition; this.oldModelRadius; @@ -134,6 +146,7 @@ function controller(wichSide) { this.grabbing = true; this.modelID = modelID; + this.modelURL = properties.modelURL; this.oldModelPosition = properties.position; this.oldModelRotation = properties.modelRotation; @@ -142,6 +155,39 @@ function controller(wichSide) { } this.release = function () { + if (this.grabbing) { + var closestJointIndex = -1; + var closestJointDistance = 10; + for (var i = 0; i < jointList.length; i++) { + var distance = Vec3.distance(MyAvatar.getJointPosition(jointList[i]), this.oldModelPosition); + if (distance < closestJointDistance) { + closestJointDistance = distance; + closestJointIndex = i; + } + } + + print("closestJointIndex: " + closestJointIndex); + print("closestJointDistance: " + closestJointDistance); + + if (closestJointDistance < 0.1) { + print("Attaching to " + jointList[closestJointIndex]); + var jointPosition = MyAvatar.getJointPosition(jointList[closestJointIndex]); + var jointRotation = MyAvatar.getJointCombinedRotation(jointList[closestJointIndex]); + + var attachmentOffset = Vec3.multiply(Vec3.subtract(this.oldModelPosition, jointPosition), 2); + attachmentOffset = Vec3.multiplyQbyV(Quat.inverse(jointRotation), attachmentOffset); + var attachmentRotation = Quat.multiply(Quat.inverse(jointRotation), this.oldModelRotation); + + MyAvatar.attach(this.modelURL, jointList[closestJointIndex], + attachmentOffset, attachmentRotation, 0.75, + true, false); + Vec3.print("offset: ", attachmentOffset); + Vec3.print("joint: ", Quat.safeEulerAngles(jointRotation)); + Vec3.print("model: ", Quat.safeEulerAngles(this.oldModelRotation)); + Vec3.print("delta: ", Quat.safeEulerAngles(attachmentRotation)); + } + } + this.grabbing = false; this.modelID.isKnownID = false; } @@ -259,6 +305,20 @@ function controller(wichSide) { this.oldModelRotation = newRotation; this.oldModelPosition = newPosition; + + + var closestJointIndex = -1; + var closestJointDistance = 10; + for (var i = 0; i < jointList.length; i++) { + var distance = Vec3.distance(MyAvatar.getJointPosition(jointList[i]), newPosition); + if (distance < closestJointDistance) { + closestJointDistance = distance; + closestJointIndex = i; + } + } +// +// print("closestJointIndex: " + closestJointIndex); +// print("closestJointDistance: " + closestJointDistance); } } @@ -408,8 +468,51 @@ function checkController(deltaTime) { } moveOverlays(); + + + + leftController.hideLaser(); + rightController.hideLaser(); + var jointPos = MyAvatar.getJointPosition("RightHand"); + var jointRot = MyAvatar.getJointCombinedRotation("RightHand"); + + Overlays.editOverlay(r, { + position: jointPos, + end: Vec3.sum(jointPos, Vec3.multiplyQbyV(jointRot, { x:1, y:0, z:0 })) + }); + Overlays.editOverlay(g, { + position: jointPos, + end: Vec3.sum(jointPos, Vec3.multiplyQbyV(jointRot, { x:0, y:1, z:0 })) + }); + Overlays.editOverlay(b, { + position: jointPos, + end: Vec3.sum(jointPos, Vec3.multiplyQbyV(jointRot, { x:0, y:0, z:1 })) + }); } - +var r = Overlays.addOverlay("line3d", { + position: { x: 0, y: 0, z: 0 }, + end: { x: 0, y: 0, z: 0 }, + color: { red: 255, green: 0, blue: 0 }, + alpha: 1, + visible: true, + lineWidth: LASER_WIDTH + }); +var g = Overlays.addOverlay("line3d", { + position: { x: 0, y: 0, z: 0 }, + end: { x: 0, y: 0, z: 0 }, + color: { red: 0, green: 255, blue: 0 }, + alpha: 1, + visible: true, + lineWidth: LASER_WIDTH + }); +var b = Overlays.addOverlay("line3d", { + position: { x: 0, y: 0, z: 0 }, + end: { x: 0, y: 0, z: 0 }, + color: { red: 0, green: 0, blue: 255 }, + alpha: 1, + visible: true, + lineWidth: LASER_WIDTH + }); function initToolBar() { @@ -686,6 +789,10 @@ function scriptEnding() { rightController.cleanup(); toolBar.cleanup(); cleanupModelMenus(); + + Overlays.deleteOverlay(r); + Overlays.deleteOverlay(g); + Overlays.deleteOverlay(b); } Script.scriptEnding.connect(scriptEnding); From b91fd19f39a270761dd1e21520a04fa59e4323c0 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 29 May 2014 14:30:28 -0700 Subject: [PATCH 04/11] snapped attachment to center and scale them to fit --- interface/src/avatar/Avatar.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 55c0830dfb..ac6718dcc8 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -378,10 +378,10 @@ void Avatar::simulateAttachments(float deltaTime) { model->setLODDistance(getLODDistance()); } if (_skeletonModel.getJointPosition(jointIndex, jointPosition) && - _skeletonModel.getJointRotation(jointIndex, jointRotation)) { + _skeletonModel.getJointCombinedRotation(jointIndex, jointRotation)) { model->setTranslation(jointPosition + jointRotation * attachment.translation * _scale); model->setRotation(jointRotation * attachment.rotation); - model->setScale(_skeletonModel.getScale() * attachment.scale); + model->setScaleToFit(true, _scale * attachment.scale); model->simulate(deltaTime); } } @@ -749,7 +749,6 @@ void Avatar::setAttachmentData(const QVector& attachmentData) { // make sure we have as many models as attachments while (_attachmentModels.size() < attachmentData.size()) { Model* model = new Model(this); - model->setSnapModelToCenter(true); model->init(); _attachmentModels.append(model); } @@ -759,6 +758,8 @@ void Avatar::setAttachmentData(const QVector& attachmentData) { // update the urls for (int i = 0; i < attachmentData.size(); i++) { + _attachmentModels[i]->setSnapModelToCenter(true); + _attachmentModels[i]->setScaleToFit(true, _scale * _attachmentData.at(i).scale); _attachmentModels[i]->setURL(attachmentData.at(i).modelURL); } } From b34453647b37cee3b0e8ceaf43df716684e23a64 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 29 May 2014 14:34:10 -0700 Subject: [PATCH 05/11] editModels click/drag/attach tweaks --- examples/editModels.js | 69 +++++------------------------------------- 1 file changed, 8 insertions(+), 61 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index cf9b9abbdc..7cf78d592e 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -40,16 +40,7 @@ var modelURLs = [ var toolBar; - var jointList = MyAvatar.getJointNames(); -//print("\n# Joint list start"); -//for (var i = 0; i < jointList.length; i++) { -// Vec3.print("jointIndex = " + jointList[i] + " = " + i, MyAvatar.getJointPosition(jointList[i])); -//} -//print("# Joint list end"); - - - function isLocked(properties) { // special case to lock the ground plane model in hq. @@ -156,6 +147,10 @@ function controller(wichSide) { this.release = function () { if (this.grabbing) { + if (jointList.length <= 0) { + jointList = MyAvatar.getJointNames(); + } + var closestJointIndex = -1; var closestJointDistance = 10; for (var i = 0; i < jointList.length; i++) { @@ -169,22 +164,19 @@ function controller(wichSide) { print("closestJointIndex: " + closestJointIndex); print("closestJointDistance: " + closestJointDistance); - if (closestJointDistance < 0.1) { + if (closestJointDistance < this.oldModelRadius) { print("Attaching to " + jointList[closestJointIndex]); var jointPosition = MyAvatar.getJointPosition(jointList[closestJointIndex]); var jointRotation = MyAvatar.getJointCombinedRotation(jointList[closestJointIndex]); - var attachmentOffset = Vec3.multiply(Vec3.subtract(this.oldModelPosition, jointPosition), 2); + var attachmentOffset = Vec3.subtract(this.oldModelPosition, jointPosition); attachmentOffset = Vec3.multiplyQbyV(Quat.inverse(jointRotation), attachmentOffset); var attachmentRotation = Quat.multiply(Quat.inverse(jointRotation), this.oldModelRotation); MyAvatar.attach(this.modelURL, jointList[closestJointIndex], - attachmentOffset, attachmentRotation, 0.75, + attachmentOffset, attachmentRotation, 2.0 * this.oldModelRadius, true, false); - Vec3.print("offset: ", attachmentOffset); - Vec3.print("joint: ", Quat.safeEulerAngles(jointRotation)); - Vec3.print("model: ", Quat.safeEulerAngles(this.oldModelRotation)); - Vec3.print("delta: ", Quat.safeEulerAngles(attachmentRotation)); + Models.deleteModel(this.modelID); } } @@ -468,52 +460,7 @@ function checkController(deltaTime) { } moveOverlays(); - - - - leftController.hideLaser(); - rightController.hideLaser(); - var jointPos = MyAvatar.getJointPosition("RightHand"); - var jointRot = MyAvatar.getJointCombinedRotation("RightHand"); - - Overlays.editOverlay(r, { - position: jointPos, - end: Vec3.sum(jointPos, Vec3.multiplyQbyV(jointRot, { x:1, y:0, z:0 })) - }); - Overlays.editOverlay(g, { - position: jointPos, - end: Vec3.sum(jointPos, Vec3.multiplyQbyV(jointRot, { x:0, y:1, z:0 })) - }); - Overlays.editOverlay(b, { - position: jointPos, - end: Vec3.sum(jointPos, Vec3.multiplyQbyV(jointRot, { x:0, y:0, z:1 })) - }); } -var r = Overlays.addOverlay("line3d", { - position: { x: 0, y: 0, z: 0 }, - end: { x: 0, y: 0, z: 0 }, - color: { red: 255, green: 0, blue: 0 }, - alpha: 1, - visible: true, - lineWidth: LASER_WIDTH - }); -var g = Overlays.addOverlay("line3d", { - position: { x: 0, y: 0, z: 0 }, - end: { x: 0, y: 0, z: 0 }, - color: { red: 0, green: 255, blue: 0 }, - alpha: 1, - visible: true, - lineWidth: LASER_WIDTH - }); -var b = Overlays.addOverlay("line3d", { - position: { x: 0, y: 0, z: 0 }, - end: { x: 0, y: 0, z: 0 }, - color: { red: 0, green: 0, blue: 255 }, - alpha: 1, - visible: true, - lineWidth: LASER_WIDTH - }); - function initToolBar() { toolBar = new ToolBar(0, 0, ToolBar.VERTICAL); From 980e873a1350bd8dac5bc36713ff4f59442eab6d Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 29 May 2014 15:02:09 -0700 Subject: [PATCH 06/11] Better prints in editModels --- examples/editModels.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index 7cf78d592e..89be4089a0 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -161,8 +161,8 @@ function controller(wichSide) { } } - print("closestJointIndex: " + closestJointIndex); - print("closestJointDistance: " + closestJointDistance); + print("closestJoint: " + jojntList[closestJointIndex]); + print("closestJointDistance (attach max distance): " + closestJointDistance + " (" + this.oldModelRadius + ")"); if (closestJointDistance < this.oldModelRadius) { print("Attaching to " + jointList[closestJointIndex]); From 3e207f9452ade9ac88408a73ba1fc7739d0faa30 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 29 May 2014 15:09:42 -0700 Subject: [PATCH 07/11] fixed display error in editVoxels with new boundaries --- examples/editVoxels.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/editVoxels.js b/examples/editVoxels.js index 14bea50bb0..22df8604e1 100644 --- a/examples/editVoxels.js +++ b/examples/editVoxels.js @@ -28,8 +28,10 @@ var NEW_VOXEL_SIZE = 1.0; var NEW_VOXEL_DISTANCE_FROM_CAMERA = 3.0; var PIXELS_PER_EXTRUDE_VOXEL = 16; var WHEEL_PIXELS_PER_SCALE_CHANGE = 100; -var MAX_VOXEL_SCALE = 16.0; -var MIN_VOXEL_SCALE = 1.0 / Math.pow(2.0, 8.0); +var MAX_VOXEL_SCALE_POWER = 4; +var MIN_VOXEL_SCALE_POWER = -8; +var MAX_VOXEL_SCALE = Math.pow(2.0, MAX_VOXEL_SCALE_POWER); +var MIN_VOXEL_SCALE = Math.pow(2.0, MIN_VOXEL_SCALE_POWER); var WHITE_COLOR = { red: 255, green: 255, blue: 255 }; var MAX_PASTE_VOXEL_SCALE = 256; @@ -330,6 +332,13 @@ function ScaleSelector() { visible: false }); this.setScale = function(scale) { + if (scale > MAX_VOXEL_SCALE) { + scale = MAX_VOXEL_SCALE; + } + if (scale < MIN_VOXEL_SCALE) { + scale = MIN_VOXEL_SCALE; + } + this.scale = scale; this.power = Math.floor(Math.log(scale) / Math.log(2)); rescaleImport(); @@ -391,12 +400,9 @@ function ScaleSelector() { this.incrementScale = function() { copyScale = false; - if (this.power < 13) { + if (this.power < MAX_VOXEL_SCALE_POWER) { ++this.power; this.scale *= 2.0; - if (this.scale > MAX_VOXEL_SCALE) { - this.scale = MAX_VOXEL_SCALE; - } this.update(); rescaleImport(); resizeVoxelSound.play(voxelSizePlus); @@ -405,7 +411,7 @@ function ScaleSelector() { this.decrementScale = function() { copyScale = false; - if (-4 < this.power) { + if (MIN_VOXEL_SCALE_POWER < this.power) { --this.power; this.scale /= 2.0; this.update(); From c7b636365c1ef352d74cc3573b9304a3f6f71f5d Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 29 May 2014 15:50:23 -0700 Subject: [PATCH 08/11] Don't attach to joints in range when I grab --- examples/editModels.js | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index 89be4089a0..6857ed18cf 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -88,6 +88,8 @@ function controller(wichSide) { this.oldModelPosition; this.oldModelRadius; + this.jointsIntersectingFronStart = []; + this.laser = Overlays.addOverlay("line3d", { position: { x: 0, y: 0, z: 0 }, end: { x: 0, y: 0, z: 0 }, @@ -142,6 +144,14 @@ function controller(wichSide) { this.oldModelPosition = properties.position; this.oldModelRotation = properties.modelRotation; this.oldModelRadius = properties.radius; + + this.jointsIntersectingFronStart = []; + for (var i = 0; i < jointList.length; i++) { + var distance = Vec3.distance(MyAvatar.getJointPosition(jointList[i]), this.oldModelPosition); + if (distance < this.oldModelRadius) { + this.jointsIntersectingFronStart.push(i); + } + } } } @@ -161,27 +171,33 @@ function controller(wichSide) { } } - print("closestJoint: " + jojntList[closestJointIndex]); + print("closestJoint: " + jointList[closestJointIndex]); print("closestJointDistance (attach max distance): " + closestJointDistance + " (" + this.oldModelRadius + ")"); if (closestJointDistance < this.oldModelRadius) { - print("Attaching to " + jointList[closestJointIndex]); - var jointPosition = MyAvatar.getJointPosition(jointList[closestJointIndex]); - var jointRotation = MyAvatar.getJointCombinedRotation(jointList[closestJointIndex]); - var attachmentOffset = Vec3.subtract(this.oldModelPosition, jointPosition); - attachmentOffset = Vec3.multiplyQbyV(Quat.inverse(jointRotation), attachmentOffset); - var attachmentRotation = Quat.multiply(Quat.inverse(jointRotation), this.oldModelRotation); - - MyAvatar.attach(this.modelURL, jointList[closestJointIndex], - attachmentOffset, attachmentRotation, 2.0 * this.oldModelRadius, - true, false); - Models.deleteModel(this.modelID); + if (this.jointsIntersectingFronStart.indexOf(closestJointIndex) != -1) { + // Do nothing + } else { + print("Attaching to " + jointList[closestJointIndex]); + var jointPosition = MyAvatar.getJointPosition(jointList[closestJointIndex]); + var jointRotation = MyAvatar.getJointCombinedRotation(jointList[closestJointIndex]); + + var attachmentOffset = Vec3.subtract(this.oldModelPosition, jointPosition); + attachmentOffset = Vec3.multiplyQbyV(Quat.inverse(jointRotation), attachmentOffset); + var attachmentRotation = Quat.multiply(Quat.inverse(jointRotation), this.oldModelRotation); + + MyAvatar.attach(this.modelURL, jointList[closestJointIndex], + attachmentOffset, attachmentRotation, 2.0 * this.oldModelRadius, + true, false); + Models.deleteModel(this.modelID); + } } } this.grabbing = false; this.modelID.isKnownID = false; + this.jointsIntersectingFronStart = []; } this.checkTrigger = function () { From fd0c19513209d2ec40a509d2df68e30d2586c6bb Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 29 May 2014 15:55:17 -0700 Subject: [PATCH 09/11] Code cleanup --- examples/editModels.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index 6857ed18cf..deada7e1aa 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -305,28 +305,9 @@ function controller(wichSide) { position: newPosition, modelRotation: newRotation }); -// print("Moving " + this.modelID.id); -// Vec3.print("Old Position: ", this.oldModelPosition); -// Vec3.print("Sav Position: ", newPosition); -// Quat.print("Old Rotation: ", this.oldModelRotation); -// Quat.print("New Rotation: ", newRotation); this.oldModelRotation = newRotation; this.oldModelPosition = newPosition; - - - var closestJointIndex = -1; - var closestJointDistance = 10; - for (var i = 0; i < jointList.length; i++) { - var distance = Vec3.distance(MyAvatar.getJointPosition(jointList[i]), newPosition); - if (distance < closestJointDistance) { - closestJointDistance = distance; - closestJointIndex = i; - } - } -// -// print("closestJointIndex: " + closestJointIndex); -// print("closestJointDistance: " + closestJointDistance); } } From b89d0a292cc7a25ae9b0ea4151055ebd7d7a9262 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 29 May 2014 15:56:46 -0700 Subject: [PATCH 10/11] code cleanup --- examples/editModels.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index deada7e1aa..d07ca4c282 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -733,10 +733,6 @@ function scriptEnding() { rightController.cleanup(); toolBar.cleanup(); cleanupModelMenus(); - - Overlays.deleteOverlay(r); - Overlays.deleteOverlay(g); - Overlays.deleteOverlay(b); } Script.scriptEnding.connect(scriptEnding); From 17e3bd6110ff95c8f4f77c2733074b2c34fcc9bb Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 29 May 2014 18:24:21 -0700 Subject: [PATCH 11/11] CR comments --- examples/editModels.js | 10 +++++----- interface/src/avatar/Avatar.cpp | 28 ++++++++++++++++++++++++++-- interface/src/renderer/Model.cpp | 4 ++-- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index d07ca4c282..1db6901e23 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -88,7 +88,7 @@ function controller(wichSide) { this.oldModelPosition; this.oldModelRadius; - this.jointsIntersectingFronStart = []; + this.jointsIntersectingFromStart = []; this.laser = Overlays.addOverlay("line3d", { position: { x: 0, y: 0, z: 0 }, @@ -145,11 +145,11 @@ function controller(wichSide) { this.oldModelRotation = properties.modelRotation; this.oldModelRadius = properties.radius; - this.jointsIntersectingFronStart = []; + this.jointsIntersectingFromStart = []; for (var i = 0; i < jointList.length; i++) { var distance = Vec3.distance(MyAvatar.getJointPosition(jointList[i]), this.oldModelPosition); if (distance < this.oldModelRadius) { - this.jointsIntersectingFronStart.push(i); + this.jointsIntersectingFromStart.push(i); } } } @@ -176,7 +176,7 @@ function controller(wichSide) { if (closestJointDistance < this.oldModelRadius) { - if (this.jointsIntersectingFronStart.indexOf(closestJointIndex) != -1) { + if (this.jointsIntersectingFromStart.indexOf(closestJointIndex) != -1) { // Do nothing } else { print("Attaching to " + jointList[closestJointIndex]); @@ -197,7 +197,7 @@ function controller(wichSide) { this.grabbing = false; this.modelID.isKnownID = false; - this.jointsIntersectingFronStart = []; + this.jointsIntersectingFromStart = []; } this.checkTrigger = function () { diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index ac6718dcc8..870d5b1a53 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -706,24 +706,48 @@ QStringList Avatar::getJointNames() const { } glm::vec3 Avatar::getJointPosition(int index) const { - glm::vec3 position(0,0,0); + if (QThread::currentThread() != thread()) { + glm::vec3 position; + QMetaObject::invokeMethod(const_cast(this), "getJointPosition", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(glm::vec3, position), Q_ARG(const int, index)); + return position; + } + glm::vec3 position; _skeletonModel.getJointPosition(index, position); return position; } glm::vec3 Avatar::getJointPosition(const QString& name) const { - glm::vec3 position(0,0,0); + if (QThread::currentThread() != thread()) { + glm::vec3 position; + QMetaObject::invokeMethod(const_cast(this), "getJointPosition", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(glm::vec3, position), Q_ARG(const QString&, name)); + return position; + } + glm::vec3 position; _skeletonModel.getJointPosition(getJointIndex(name), position); return position; } glm::quat Avatar::getJointCombinedRotation(int index) const { + if (QThread::currentThread() != thread()) { + glm::quat rotation; + QMetaObject::invokeMethod(const_cast(this), "getJointCombinedRotation", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(glm::quat, rotation), Q_ARG(const int, index)); + return rotation; + } glm::quat rotation; _skeletonModel.getJointCombinedRotation(index, rotation); return rotation; } glm::quat Avatar::getJointCombinedRotation(const QString& name) const { + if (QThread::currentThread() != thread()) { + glm::quat rotation; + QMetaObject::invokeMethod(const_cast(this), "getJointCombinedRotation", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(glm::quat, rotation), Q_ARG(const QString&, name)); + return rotation; + } glm::quat rotation; _skeletonModel.getJointCombinedRotation(getJointIndex(name), rotation); return rotation; diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index b41d440e16..ee774c183a 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -634,8 +634,8 @@ bool Model::getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind) return false; } rotation = _jointStates[jointIndex]._combinedRotation * - (fromBind ? _geometry->getFBXGeometry().joints[jointIndex].inverseBindRotation : - _geometry->getFBXGeometry().joints[jointIndex].inverseDefaultRotation); + (fromBind ? _geometry->getFBXGeometry().joints[jointIndex].inverseBindRotation : + _geometry->getFBXGeometry().joints[jointIndex].inverseDefaultRotation); return true; }