New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprite: Fix raycast bug #8424

Merged
merged 1 commit into from Mar 21, 2016

Conversation

Projects
None yet
4 participants
@WestLangley
Collaborator

WestLangley commented Mar 21, 2016

Raycasting with sprites is an approximation in that the sprite is treated as a disk. In addition, sprites can be non-square, and can be rotated.

With this change, if the sprite is square, the "clickable" region is inside the inscribed circle. If the sprite is non-square, the approximation is not very good, but it is better than before.

ref: http://stackoverflow.com/questions/36123458/three-raycaster-not-working-properly-with-scaled-three-sprite

Sprite: Fix raycast bug
Raycasting with sprites is an approximation in that the sprite is treated as a disk. In addition, sprites can be non-square, and can be rotated.

With this change, if the sprite is square, the "clickable" region is inside the inscribed circle. If the sprite is non-square, the approximation is not very good, but it is better than before.
@mrdoob

This comment has been minimized.

Show comment
Hide comment
@mrdoob

mrdoob Mar 21, 2016

Owner

The corners of the sprite will be missed, as the sprite is treated as a disk.

Not sure this is a good thing...

Owner

mrdoob commented Mar 21, 2016

The corners of the sprite will be missed, as the sprite is treated as a disk.

Not sure this is a good thing...

@WestLangley

This comment has been minimized.

Show comment
Hide comment
@WestLangley

WestLangley Mar 21, 2016

Collaborator

The corners of the sprite will be missed, as the sprite is treated as a disk.

Not sure this is a good thing...

The current implementation treats the sprite as a disk. So the only free parameter is the disk radius. With this implementation, the clickable region is pi / 4 ~ 80% of the area -- only the corners are missed. If the sprite has a disk-shaped texture, this implementation is exact.

If the radius is large enough to cover the entire sprite, the clickable region is 2pi / 4 ~ 160% of the area. This leads to a lot of false positives, and can select the wrong sprite.

I would consider this a stop-gap measure.

Collaborator

WestLangley commented Mar 21, 2016

The corners of the sprite will be missed, as the sprite is treated as a disk.

Not sure this is a good thing...

The current implementation treats the sprite as a disk. So the only free parameter is the disk radius. With this implementation, the clickable region is pi / 4 ~ 80% of the area -- only the corners are missed. If the sprite has a disk-shaped texture, this implementation is exact.

If the radius is large enough to cover the entire sprite, the clickable region is 2pi / 4 ~ 160% of the area. This leads to a lot of false positives, and can select the wrong sprite.

I would consider this a stop-gap measure.

@WestLangley WestLangley referenced this pull request Mar 21, 2016

Closed

Raycaster not working properly with scaled Sprites #8430

3 of 11 tasks complete
@mrdoob

This comment has been minimized.

Show comment
Hide comment
@mrdoob

mrdoob Mar 21, 2016

Owner

The current implementation treats the sprite as a disk.

True... Sounds good then! 😅

Owner

mrdoob commented Mar 21, 2016

The current implementation treats the sprite as a disk.

True... Sounds good then! 😅

mrdoob added a commit that referenced this pull request Mar 21, 2016

@mrdoob mrdoob merged commit da7d047 into dev Mar 21, 2016

@mrdoob

This comment has been minimized.

Show comment
Hide comment
@mrdoob

mrdoob Mar 21, 2016

Owner

Thanks!

Owner

mrdoob commented Mar 21, 2016

Thanks!

@mrdoob mrdoob deleted the dev-sprite branch Mar 21, 2016

@mrdoob

This comment has been minimized.

Show comment
Hide comment
@mrdoob

mrdoob Mar 22, 2016

Owner

We probably should add an example that covers this. Or add some code to one of the interaction examples.

Owner

mrdoob commented Mar 22, 2016

We probably should add an example that covers this. Or add some code to one of the interaction examples.

@WestLangley

This comment has been minimized.

Show comment
Hide comment
@WestLangley

WestLangley Mar 22, 2016

Collaborator

@mrdoob ...or properly fix Sprite.raycast().

Collaborator

WestLangley commented Mar 22, 2016

@mrdoob ...or properly fix Sprite.raycast().

@WestLangley

This comment has been minimized.

Show comment
Hide comment
@WestLangley

WestLangley Mar 24, 2016

Collaborator

or properly fix Sprite.raycast().

Sprites are just two triangles. So it seems it would be easy to properly recast against them -- ignoring the sprites' transparent regions, if any.

Thing is, sprites always face the camera. So it is probably easiest to raycast in camera space, instead of world or local space. But that means the raycaster ray needs to be mapped to camera space, and our current design does not allow for that.

So a refactoring is in order, if someone is interested in tackling this.

Collaborator

WestLangley commented Mar 24, 2016

or properly fix Sprite.raycast().

Sprites are just two triangles. So it seems it would be easy to properly recast against them -- ignoring the sprites' transparent regions, if any.

Thing is, sprites always face the camera. So it is probably easiest to raycast in camera space, instead of world or local space. But that means the raycaster ray needs to be mapped to camera space, and our current design does not allow for that.

So a refactoring is in order, if someone is interested in tackling this.

@stevensanborn

This comment has been minimized.

Show comment
Hide comment
@stevensanborn

stevensanborn Jan 25, 2017

Im seeing non square sprites having very poor ray casting results. For instance sprite.scale.set(100,5,1) will miss the sprite except the center.

Im seeing non square sprites having very poor ray casting results. For instance sprite.scale.set(100,5,1) will miss the sprite except the center.

@WestLangley

This comment has been minimized.

Show comment
Hide comment
@WestLangley

WestLangley Jan 25, 2017

Collaborator

I'm seeing non-square sprites having very poor ray-casting results. For instance sprite.scale.set(100,5,1) will miss the sprite, except for the center.

Correct. This was stated in the original post.

Collaborator

WestLangley commented Jan 25, 2017

I'm seeing non-square sprites having very poor ray-casting results. For instance sprite.scale.set(100,5,1) will miss the sprite, except for the center.

Correct. This was stated in the original post.

@zwcloud

This comment has been minimized.

Show comment
Hide comment
@zwcloud

zwcloud May 18, 2018

ignoring the sprites' transparent regions, if any.

@WestLangley Any progress on this?

zwcloud commented May 18, 2018

ignoring the sprites' transparent regions, if any.

@WestLangley Any progress on this?

@WestLangley

This comment has been minimized.

Show comment
Hide comment
@WestLangley

WestLangley May 18, 2018

Collaborator

ignoring the sprites' transparent regions, if any.

@WestLangley Any progress on this?

Not that I am aware of.

Collaborator

WestLangley commented May 18, 2018

ignoring the sprites' transparent regions, if any.

@WestLangley Any progress on this?

Not that I am aware of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment