Jump to content

Issue with pickWithRay and scaling


iiceman
 Share

Recommended Posts

Howdy,

 

http://www.babylonjs-playground.com/#11DXRI

 

This is the main problem from the other thread about moving with collisions. Ray casting just doesn't seem to work right as soon as the mesh is scaled (along the y axis?). This really seems like a bug to me ... or I am doing something horribly wrong here :-/

 

Can that be fixed somehow?

Link to comment
Share on other sites

Yeah, weird, eh? I think I tried that, too. Well, it works if you reference the pickedMesh... but for pickedPoint to really get the point on the surface it's somehow messed up. Would be cool if you find a reason for that :D Thanks for the help!

Link to comment
Share on other sites

The problem is in the abstractMesh intersects function - line 837 :

var worldDirection = BABYLON.Vector3.TransformNormal(direction, world);

actually, the direction vector is already correct (And I believe,already in world coordinates, as it is being calculated using the actual distance between the points), this shouldn't be calculated. If you remove this line (or skip it in the debugger :-) ) everything works as expected. 

So, a quick fix would be removing all references to worldDirection and changing them to direction, or changing this line to:

var worldDirection = direction;

Which is kind'a redundant :-) 

 

As this is the first time this error appears, I am not sure this is a bug (well, it is, but is removing this line of code leaves everything else intact?).

 

This requires further testing.

Link to comment
Share on other sites

Isn't the ray being transformed to world coordinates in the pickWithRay function (actually inverted)?

world.invertToRef(this._pickWithRayInverseMatrix);return Ray.Transform(ray, this._pickWithRayInverseMatrix);

because the direction the the scaled case was actually 0,-2,0 and not the given 0,-1,0. This is why I thought it is in world coordinates. The direction variable is also being recalculated using the distance from the intersection function (which is correct) as a scale.

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...