Home Technical Talk

Blender Python 2.79: Get Selected Polygon Index From Model Inside of Modal Operator?

polycounter lvl 6
Offline / Send Message
MrQuetch polycounter lvl 6
I'm trying to get the index of a selected polygon from a model (from the viewport) in a modal operator. I am using an event type to return the selected index.

Whenever I run the script and select the modal operator it gives me the correct index the first time. But, any other time, I have to re-run my script and the modal operator to update the selected index. This becomes really annoying very fast - as I don't want to have to keep re-running my script and modal operator. I want to be able to select different triangles at a time and return the correct indices without having to redo this.

I've looked into event timers a little bit, but will this actually help for what I want? I've been stuck on this for a few hours, but figured it'd just be better to get help.

Replies

  • MrQuetch
    Offline / Send Message
    MrQuetch polycounter lvl 6
    For anyone who has read this or will read this, I've managed to find a solution to my problem - though it's quite unconventional; it works for my custom purposes. I've decided to ditch getting a triangle index from an object in edit mode. The reason for this is that I'm drawing a duplicate of the selected object in Blender with "bgl". Now, what I'm doing is converting each triangle's vertices from world space to screen space and checking the barycentric coordinates on the triangles to see where the mouse cursor lies - ultimately returning the "ith" index of the highlighted triangle... My only problem now is that I need to check the distance from the viewport camera to the first currently highlighted triangle because more can actually be highlighted at once - since I'm only checking triangles in 2D and not 3D.
  • MrQuetch
    Offline / Send Message
    MrQuetch polycounter lvl 6
    I'm getting closer in figuring out how to solve the above problem. One way I have managed to progress is by checking the dot product of the viewport's camera position and the currently highlighted triangle - which clears up some things. I just need to fix the drawing order of the triangles (probably using the distance from the camera's position to the currently highlighted triangle) and this thread should be good to close!
Sign In or Register to comment.