2
$\begingroup$

How to draw custom faces/lines/points in 3D space with python?

Like this addon.

I need just a simple example of how to draw these elements.

$\endgroup$
  • $\begingroup$ Take a look at the Github page: github.com/CGCookie/retopology-contours/blob/master/… $\endgroup$ – someonewithpc Dec 6 '14 at 17:59
  • $\begingroup$ Possibly off topic because involves external addon? $\endgroup$ – Scalia Dec 6 '14 at 18:17
  • 2
    $\begingroup$ @VinceScalia I think the OP mentioned the addon as an example of functionality, not because they were asking how to use it. IMO it's a perfectly good question. $\endgroup$ – gandalf3 Dec 6 '14 at 18:26
  • $\begingroup$ Okay then. Just wondering. $\endgroup$ – Scalia Dec 6 '14 at 18:29
4
$\begingroup$

Blender provides opengl access through python with the bgl module which allows you to use opengl calls to draw to screen. Any opengl reference should help.

An example from the contours addon - countour_utilities.py

def draw_outline_or_region(mode, points, color):
        '''  
        arg: 
        mode - either bgl.GL_POLYGON or bgl.GL_LINE_LOOP
        color - will need to be set beforehand using theme colors. eg
        bgl.glColor4f(self.ri, self.gi, self.bi, self.ai)
        '''

        bgl.glColor4f(color[0],color[1],color[2],color[3])
        if mode == 'GL_LINE_LOOP':
            bgl.glBegin(bgl.GL_LINE_LOOP)
        else:
            bgl.glBegin(bgl.GL_POLYGON)

        # start with corner right-bottom
        for i in range(0,len(points)):
            bgl.glVertex2f(points[i][0],points[i][1])

        bgl.glEnd()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.