Jump to content

Picking with fastcheck is broken


jschwuch
 Share

Recommended Posts

I just found out that picking with fastcheck set to true doesn't work as expected. It won't give you the closest mesh but the one added to the scene first! The problem is inside _internalPick function. I added a comment where it literally breaks the search for the closest hit.

 private _internalPick(rayFunction: (world: Matrix) => Ray, predicate: (mesh: AbstractMesh) => boolean, fastCheck?: boolean): PickingInfo {
            var pickingInfo = null;

            for (var meshIndex = 0; meshIndex < this.meshes.length; meshIndex++) {
                var mesh = this.meshes[meshIndex];

                if (predicate) {
                    if (!predicate(mesh)) {
                        continue;
                    }
                } else if (!mesh.isEnabled() || !mesh.isVisible || !mesh.isPickable) {
                    continue;
                }

                var world = mesh.getWorldMatrix();
                var ray = rayFunction(world);

                var result = mesh.intersects(ray, fastCheck);
                if (!result || !result.hit)
                    continue;

                if (!fastCheck && pickingInfo != null && result.distance >= pickingInfo.distance)
                    continue;

                pickingInfo = result;

                // This breaks the search for the closest hit when anything is hit.
                if (fastCheck) {
                    break;
                }
            }

Or is this actually intended @Deltakosh?

Link to comment
Share on other sites

@Temechon ok, if that's what it should do than that's ok, thought I read somewhere that it should use bounding boxes instead of actual meshs when using fastcheck but nothing about it returning the first mesh.

Maybe I should file a feature request for a check against only the bounding box but with filtering the closest mesh then, as this is what I'd like to have.

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