Skip to content
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

Use .isSphere instead of "instanceof Sphere" #510

Closed
bhouston opened this issue May 30, 2024 · 2 comments
Closed

Use .isSphere instead of "instanceof Sphere" #510

bhouston opened this issue May 30, 2024 · 2 comments

Comments

@bhouston
Copy link

Describe the bug

Using instanceof can be quite problematic:

https://github.com/yomotsu/camera-controls/blob/dev/src/CameraControls.ts#L1987

If you ever have more than one Three.js included or based on how the bundler works, instanceof may not work.

Instead I recommend using .isSphere, which is provided here in the Three.js Sphere API:

https://github.com/mrdoob/three.js/blob/dev/src/math/Sphere.js#L12

To Reproduce

If you ever have more than one Three.js included or based on how the bundler works, instanceof may not work.

Code

I would recommend that we just change it to:


const isSphere = 'isSphere' in sphereOrMesh;


### Live example

_No response_

### Expected behavior

CameraControls should work whether or not instanceof works on Sphere correctly.

### Screenshots or Video

_No response_

### Device

_No response_

### OS

_No response_

### Browser

_No response_
@yomotsu
Copy link
Owner

yomotsu commented May 30, 2024

Whoa, you are one of the contributors to three.js!
It's an honor to receive your comment.

You are absolutely right.
I've fixed it in #511. Thank you for pointing that out.

@bhouston
Copy link
Author

bhouston commented Jun 4, 2024

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants