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

Add overload from the docs to MeshBVHHelper type #729

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pailhead
Copy link

@pailhead pailhead commented Nov 21, 2024

I was trying to construct a MeshBVHHelper via a MeshBVH that i constructed via BufferGeometry not a Mesh. The type doesn't support the overload thats listed in the docs.

constructor(
	mesh = null : THREE.Mesh,
	bvh = null : MeshBVH,
	depth = 10 : Number
)

With this change, i seem to be able to pass these three arguments without TS complaining and i see the results. I'm also confused with the default parameters of null since the type doesnt seem to be nullable. This makes it sound like its mesh?: THREE.Mesh | null.

However, if i try to construct this with MeshBVH instead of THREE.Mesh

constructor(
	meshOrBvh: THREE.Mesh | MeshBVH,
	depth = 10 : Number
)

I run into an issue here:
image

Because of this i believe:

If you provide MeshBVH instead, it will set this.mesh = null and then accessing a property on it fails.

I couldn't dig deeper into this at this point. The quickest thing may be to remove the Mesh|BVHMesh from the first argument in that signature and update the docs accordingly.

@gkjohnson
Copy link
Owner

Hey! Thanks for the catch - this looks like bug introduced in #703 since this line is not checking whether or not mesh is defined. The constructor signatures in the README should be correct.

Can we:

  • Add a check for whether or not mesh is defined in the above condition, and
  • Adjust the typescript definitions to align with the ones specified in the README

Thanks again!

@pailhead
Copy link
Author

Makes sense. If it isn’t super urgent I could address this in a couple of weeks. I erm, just lost access to a computer.

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

Successfully merging this pull request may close these issues.

2 participants