Jump to content

Gizmo Get Distance in Local Space


inxs
 Share

Recommended Posts

I tried this so far:

this.parentMesh.computeWorldMatrix();
 
console.log('Parent: ' + this.parentMesh.position);
console.log('Origin: ' + this.origin);
 
const mat = new Matrix();
 
const diff = this.parentMesh.position.subtract(this.origin);
 
if (diff) {
console.log('Diff: ' + diff);
 
const quat = Helper.QuaternionToBabylon(this.assemblyItem.quaternion);
 
quat.toRotationMatrix(mat);
 
const trans = BABYLON.Vector3.TransformCoordinates(diff, mat);
 
console.log('Transformed: ' + trans);
}

But X Value is correct but also there is a difference in Y, even If i didnt drag Y.

image.png.1502edc65de8b2663d066ae493d6c019.png

Link to comment
Share on other sites

On 8/31/2018 at 6:01 PM, babbleon said:

The difference in Y is very small though. If you rounded to, say, 8 decimal places it would = 0.

The diff is 4.6 and it should be 0 because in local space I only moved on X Axis.

On 8/31/2018 at 6:49 PM, trevordev said:

Which gizmo are you using? Do you have playground code I can look at?

The PositionGizmo with updateGizmoRotationToMatchAttachedMesh = true;

When I rotate the Mesh for 30 degrees and move it to with the x direction, then I want the distance I move on this axis.

I will create a PG and post it here.

Link to comment
Share on other sites

Ok already got the solution after browsing git repo

const tmpMatrix = new BABYLON.Matrix();
const localDelta = new BABYLON.Vector3();
 
this.parentMesh.computeWorldMatrix().invertToRef(tmpMatrix);
tmpMatrix.setTranslationFromFloats(0, 0, 0);
Vector3.TransformCoordinatesToRef(diff, tmpMatrix, localDelta);
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...