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

Raycaster bug : wrong face index #4443

Closed
ArpegorPSGH opened this issue Apr 28, 2022 · 4 comments · Fixed by #4444
Closed

Raycaster bug : wrong face index #4443

ArpegorPSGH opened this issue Apr 28, 2022 · 4 comments · Fixed by #4444
Labels

Comments

@ArpegorPSGH
Copy link
Contributor

In one of my node trees when veryfying proper working, I found out that when hitting the first polygon of the mesh, -1 gets returned instead of 0, while everything else is normal. Attached is a MWE.
Bug raycaster_2022_04_28_17_11.zip

@zeffii
Copy link
Collaborator

zeffii commented Apr 28, 2022

interestingly - in this scenario

        if I.is_linked:
            I.sv_set([[r[2] if r[2] else -1 for r in L] for L in RL])

r[2] must be evaluating to False. RL is [[(Vector((0.0, 0.0, -1.0)), Vector((0.0, 0.0, 1.0)), 0, 1.0)]]

from mathutils import Vector

RL = [[(Vector((0.0, 0.0, -1.0)), Vector((0.0, 0.0, 1.0)), 0, 1.0)]]
F = [[r[2] if r[2] else -1 for r in L] for L in RL]
print(F)
>>> [[-1]]

https://docs.blender.org/api/current/mathutils.bvhtree.html?highlight=mathutils%20bvhtree#mathutils.bvhtree.BVHTree.ray_cast
ray_cast returns tuple( Vector location, Vector normal, int index, float distance )
and the first polygon's index being 0, results in r[2] evaluating to False. and therefore is replaced by -1 .

we will have to check against None explicitly.

@zeffii
Copy link
Collaborator

zeffii commented Apr 28, 2022

nice catch @ArpegorPSGH

@Durman
Copy link
Collaborator

Durman commented Apr 29, 2022

If we stick to pep8 - https://pep8.org/#programming-recommendations
It should be something is not None

@zeffii
Copy link
Collaborator

zeffii commented Apr 29, 2022

even better

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

Successfully merging a pull request may close this issue.

3 participants