Can python script draw something like OOPS window?

The interface, modeling, 3d editing tools, import/export, feature requests, etc

Moderators: jesterKing, stiv

Post Reply
oyster
Posts: 0
Joined: Sat Mar 29, 2003 4:41 pm
Contact:

Can python script draw something like OOPS window?

Post by oyster » Wed Jun 09, 2004 7:02 am

Can python script draw something like OOPS window? That is movable shapes linked by lines, not the shapes drawn by Blender.BGL.

When I did the character animation tut by otothecleaner, I found it is tedious and in low efficiency during checking vertex groups. So I need a script, which can draw a diagram of the 3D-vertex group by rendering floods of vertices as a circle, a rectangle, etc shape in 2D dimension. Image says the concept: all the shapes are created automatically, for example, the center of rectangle is the center of vertices of Arm.L, and its width and height cover all the vertices. The rectangle can be resized, rotated and moved either by HOTKEY or pop-up menu. The name ("Arm.L") is extracted from this vertex group.

There is no double that it is easy to select vertex group from the diagram other than from the faint text items in EDIT window: you can select by click the big and consise rectangle or by "Re selecttion". When the Arm.L group is selected in the EDIT window, the Arm.L rectangle in diagram is selected too and vice versa (well it depends on "Selection" and "Select at" buttons). At least, the diagram saves half of mouse clicks ;) --- 50 times in my project minimally.

Further more, this kind of OOPS-window-like gizmo is also needed by Image, the new mat system described by Monkeyboi.

Well, perhaps this is just a feature request currently :)

p.s. the words on pic is "difficult to locate and select in that many items"

ideasman
Posts: 0
Joined: Tue Feb 25, 2003 2:37 pm

Post by ideasman » Wed Jun 09, 2004 7:59 am

iM BONE RIGGING RIGHT NOW aND SEE YOUR POINT, BUT DONT KNOW THAT AN oops TYPE WINDOW IS APPROPRIATE.

yES iT COULD BE DONE IN bpYTHON- bUT SINCE VERT GROUPS ARE NOT ON OR OFF. RATHER DIFFERENT WEIGHTS IT COULD BE TRICKY TO DEFINE SPEFIFIC AREA.

btw WHY NOT USE bgl? IT WOULD WORK-

Monkeyboi
Posts: 251
Joined: Tue Nov 26, 2002 1:24 pm
Location: Copenhagen, Denmark
Contact:

Post by Monkeyboi » Wed Jun 09, 2004 12:13 pm

Looks very useful. This is pretty inbuilt in Softimage XSI, and is very useful. Good luck coding it!

ideasman
Posts: 0
Joined: Tue Feb 25, 2003 2:37 pm

Post by ideasman » Fri Jun 11, 2004 7:58 am

Why not add vertex groups to the oops window.

I have alredy added 'Object Locations to oops locations Front/Side/Top/Bottom'

An average posetion could be made by looking at eavh vert of a group and taking into account its weight and position.

After that the vert weight oops boxes could be placed about the mesh with there relative positions. Size and shape would not be taken into account, like in your example

oyster
Posts: 0
Joined: Sat Mar 29, 2003 4:41 pm
Contact:

Post by oyster » Sun Jun 13, 2004 5:36 pm

ideasman wrote:Why not add vertex groups to the oops window.

I have alredy added 'Object Locations to oops locations Front/Side/Top/Bottom'
How to by hand and by Python script respectively? Sorry, I have not used oops window before.
ideasman wrote: An average posetion could be made by looking at eavh vert of a group and taking into account its weight and position.
Another problem: it seems that there are no interface that can perform

Code: Select all

GetVertexInMesh(Object=Selected, VertexGroup=All)
Am I right?

ideasman
Posts: 0
Joined: Tue Feb 25, 2003 2:37 pm

Post by ideasman » Mon Jun 14, 2004 12:51 am

Have a go at the oops window, mabe we could add vert groups.

About the non existing function you mention- no its not there but you can do the same thing another way

Code: Select all

from Blender import *
mesh = NMesh.GetRaw(Object.Get()[0]) # Gets the first object

for v in mesh.verts:
  if v.sel == 1:
    print v.co # some text to see we have a vert


if you only wanted selected objects then you could use Object.GetSelected()[0]

neil
Posts: 21
Joined: Fri Oct 18, 2002 1:54 pm
Location: Scotland
Contact:

Post by neil » Wed Jun 16, 2004 7:20 pm

In terms of the initial question, python has complete access to the open GL commands so you can in theory draw any sort of interface you like - but it is pretty low level so will be complex.

Neil

oyster
Posts: 0
Joined: Sat Mar 29, 2003 4:41 pm
Contact:

Post by oyster » Sat Jun 19, 2004 10:43 am

To draw the vertices group box is easy, for there exists mesh.getVertGroupNames and mesh.getVertsFromGroup.
Image
Following the instructions of NEHE and redbook, I adapted a script for Blender. But I can't use mouse to select the triangle , change its outline color, and then move/scale/rotate it (because gluPickMatrix is missing?), and I donno how to draw a pop-up menu in a easy way.
I am not a real programmer, so I need your help with the BGL part :idea: . thx.

Code: Select all

import Blender
from Blender.BGL import *
from Blender import Draw

'''
Ex12_2
'''

def drawTriangle (x1, y1, x2, y2, x3, y3, z):
    glBegin (GL_TRIANGLES)
    glVertex3f (x1, y1, z)
    glVertex3f (x2, y2, z)
    glVertex3f (x3, y3, z)
    glEnd ()

def drawViewVolume (x1, x2, y1, y2, z1, z2):
    glColor3f (1.0, 1.0, 1.0)
    glBegin (GL_LINE_LOOP)
    glVertex3f (x1, y1, -z1)
    glVertex3f (x2, y1, -z1)
    glVertex3f (x2, y2, -z1)
    glVertex3f (x1, y2, -z1)
    glEnd ()

    glBegin (GL_LINE_LOOP)
    glVertex3f (x1, y1, -z2)
    glVertex3f (x2, y1, -z2)
    glVertex3f (x2, y2, -z2)
    glVertex3f (x1, y2, -z2)
    glEnd ()

    glBegin (GL_LINES);   #/*  4 lines   */
    glVertex3f (x1, y1, -z1)
    glVertex3f (x1, y1, -z2)
    glVertex3f (x1, y2, -z1)
    glVertex3f (x1, y2, -z2)
    glVertex3f (x2, y1, -z1)
    glVertex3f (x2, y1, -z2)
    glVertex3f (x2, y2, -z1)
    glVertex3f (x2, y2, -z2)
    glEnd ()


def show_win ():
    glMatrixMode (GL_PROJECTION)
    glLoadIdentity ()
    #gluPerspective (40.0, 4.0/3.0, 0.01, 100.0)

    glMatrixMode (GL_MODELVIEW)
    glLoadIdentity ()
    #gluLookAt (7.5, 7.5, 12.5, 2.5, 2.5, -5.0, 0.0, 1.0, 0.0)
    glColor3f (0.0, 1.0, 0.0);     #/*  green triangle */
    #drawTriangle (*map(lambda e:e/10,(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0)))
    drawTriangle (*map(lambda e:e/10,(1.0, 7.0, 2.0, 7.0, 1.5, 8.0, -5.0)))
    glColor3f (1.0, 0.0, 0.0);     #/*  red triangle */
    drawTriangle (*map(lambda e:e/10,(2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0)))
    glColor3f (1.0, 1.0, 0.0);     #/*  yellow triangles */
    #drawTriangle (*map(lambda e:e/10,(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0)))
    drawTriangle (*map(lambda e:e/10,(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0)))
    drawViewVolume (*map(lambda e:e/10,(0.0, 5.0, 0.0, 5.0, 0.0, 10.0)))

def processHits (hits, buffer):
    print "hits = %s\n"% hits
    print "buffer = %s\n"% buffer

    '''
    ptr = buffer
    for i in range(hits):       #/* for each hit */
        names = ptr
        print(" number of names for hit = %d\n"% names); 
        #ptr++
        print ("  z1 is %u;"% *ptr); 
        #ptr++
        print (" z2 is %u\n"% *ptr); 
        #ptr++
        print ("   the name is ")
        '''
    '''    
    for (j = 0; j < names; j++) {      /* for each name */
            printf ("%d ", *ptr); ptr++
        }
       
        print ("\n")

	'''
	
BUFSIZE = 512
def ev(evt, val): 
    if evt == Draw.ESCKEY or evt == Draw.QKEY:
      Draw.Exit()                        # this quits the script
    elif evt ==Draw.MOUSEX:
      mouse_x=Draw.MOUSEX
    elif evt ==Draw.MOUSEY:
      mouse_y=Draw.MOUSEY
    else:
      print 'else'
      selectBuf=Buffer(GL_INT, BUFSIZE)
      hits=0
      viewport=Buffer(GL_INT, 4)

      glSelectBuffer (BUFSIZE, selectBuf)
      glGetIntegerv(GL_VIEWPORT, viewport);
      
      glRenderMode (GL_SELECT)

      glInitNames()
      glPushName(0)

      glMatrixMode (GL_PROJECTION)      
      glPushMatrix ()
      
      glLoadIdentity ()      
      #NameError: global name 'gluPickMatrix' is not defined
      #gluPickMatrix(mouse_x, (viewport[3]-mouse_y), 1.0, 1.0, viewport);      

      glMatrixMode (GL_PROJECTION)
      
      glOrtho (0.0, 5.0, 0.0, 5.0, 0.0, 10.0)
      #gluPerspective(45.0f, (GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]), 0.1f, 100.0f);
      
      glMatrixMode(GL_MODELVIEW);	      
      
      glLoadIdentity ()
      glLoadName(1)
      glColor3f (1.0, 1.0, 0.0)
      drawTriangle (*map(lambda e:e/10,(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -5.0)))
      glLoadName(2)
      glColor3f (0.0, 1.0, 1.0)
      drawTriangle (*map(lambda e:e/10,(2.0, 7.0, 3.0, 7.0, 2.5, 8.0, -5.0)))
      glLoadName(3)
      glColor3f (1.0, 1.0, 1.0)
      drawTriangle (*map(lambda e:e/10,(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, 0.0)))
      drawTriangle (*map(lambda e:e/10,(2.0, 2.0, 3.0, 2.0, 2.5, 3.0, -10.0)))
      glPopMatrix ()
      glFlush ()

      hits = glRenderMode (GL_RENDER)
      processHits (hits, selectBuf)


Draw.Register(show_win, ev, None)     # start the main loop
BTW: if the line with gluPickMatrix is uncommneted, the blender will halt. How to quit the script without killing the Blender (CRTL+SHIFT+ALT does not work)

Money_YaY!
Posts: 442
Joined: Wed Oct 23, 2002 2:47 pm

Post by Money_YaY! » Thu Jun 24, 2004 1:43 am

Is there any update to this ?
It kinda works, I get a bunch of triangles. But hey it is a start.

It could be a great tool if it could be made into a real tool .

oyster
Posts: 0
Joined: Sat Mar 29, 2003 4:41 pm
Contact:

Post by oyster » Thu Jun 24, 2004 3:14 pm

I am quite a newbie to OpenGL. I don't know how to select a shape, how to change the color of the selected shape, and more. The Opengl redbook/bluebook, NeHe tut are all fine, but I don't think they are good enough in guiding to assmble a real project other than to show off one or two specific functions -- maybe because I am not a real programmer. Furthermore I am in a very, very bad mood. So the project will stay where it is. Sorry.
I will be glad to see somebody turn my conception into a working script. If you need my codelet, let me know.

Money_YaY!
Posts: 442
Joined: Wed Oct 23, 2002 2:47 pm

Post by Money_YaY! » Thu Jun 24, 2004 4:42 pm

oyster wrote:I am quite a newbie to OpenGL. I don't know how to select a shape, how to change the color of the selected shape, and more. The Opengl redbook/bluebook, NeHe tut are all fine, but I don't think they are good enough in guiding to assmble a real project other than to show off one or two specific functions -- maybe because I am not a real programmer. Furthermore I am in a very, very bad mood. So the project will stay where it is. Sorry.
I will be glad to see somebody turn my conception into a working script. If you need my codelet, let me know.
In elysiun ( i will look ) there was a thing that had a body and you could select the peices of it in the python gui, but it did nothing. But that would solve have of the problem.

Sorry to hear your in a bad mood, wish I could send a bear :twisted:

Post Reply