1

I made a custom gizmo with OpenGL

enter image description here

I want to do something after clicking on points like print("Hello World") and change the color of selected point.

enter image description here

import bpy
import gpu
from gpu_extras import batch
import bgl
from random import random

positions = ( (-1, -1, -1), (+1, -1, -1), (-1, +1, -1), (+1, +1, -1), (-1, -1, +1), (+1, -1, +1), (-1, +1, +1), (+1, +1, +1))

colors = ( (1, 1, 1,1), (1, 1, 1,1), (1, 1, 1,1), (1, 1, 1,1), (1, 1, 1,1), (1, 1, 1,1), (1, 1, 1,1), (1, 1, 1,1))

shader = gpu.shader.from_builtin("3D_FLAT_COLOR") batch = batch.batch_for_shader(shader, "POINTS", {"pos": positions, "color": colors})

def draw(): shader.bind() bgl.glPointSize(5) batch.draw(shader)

bpy.types.SpaceView3D.draw_handler_add(draw, (), "WINDOW", "POST_VIEW")

  • 1
    Related https://blender.stackexchange.com/questions/193145/how-can-i-make-a-custom-gizmos-to-set-the-origin – batFINGER Sep 03 '20 at 23:33
  • Hi @batFINGER this question is different I just want to know is it possible to use raycast to select the OpenGL points? – Seyed Morteza Kamali Sep 04 '20 at 04:28
  • A solution with no raycast is effectivelly in the code indicated by @batFINGER. lines 105/110. – lemon Sep 04 '20 at 05:22
  • @lemon hmmm do you mean Find the closest corner using a dot product from the view. I actually confused by that code because it was complex so I tried to find the easy way. – Seyed Morteza Kamali Sep 04 '20 at 05:31
  • @SeyedMortezaKamali, yes dot product: the bigger, the closest. Then just tune the limit (ie 0.999). And raycast means creating surfaces (so more code to do it). – lemon Sep 04 '20 at 05:34
  • 1
    @SeyedMortezaKamali similarly as if your point shares the same 2d coord as the mouse (or close enough) Can see no evidence in question re it being about raycasting, Is it supposed to be easy? Have offered this advice before, for say an hour, disconnect from the internet and resist the urge to ask another question here (or via comment) until you understand how something works. If need be add some print statements to see the values. Resist the urge on getting an error and posting "I tried .... It doesn't work". The fine line between seeking answers and just wanting them given to you. – batFINGER Sep 04 '20 at 06:31
  • @batFINGER you are right I shouldn't ask what I want. I should try harder to solve the problem myself because when I solve the problem my self I will learn a lot but if someone solve my problem I won't learn.I'm really sorry. thank you for the advice you're great! – Seyed Morteza Kamali Sep 04 '20 at 06:38

0 Answers0