Hello,
I’m new to the forum, and have had a look round but couldn’t find what I was looking for so I thought I’d ask. Sorry if this is in the wrong section or anything.
I have a python script that creates a cube and you can set the RGB values with sliders, but to see the effect of this you have to press the ok button. My query is that is it possible to see the effects of changing a slider instantaneously on the cube rather than having to press another button?
I’ve included the code if I didn’t explain what I meant very well, but I’m not sure if I put it in correctly (every forum has different rules about including scripts). Also the formatting doesn’t seem to work so all the indents are missing I’m afraid, but you can get the idea from reading it!
Any help would be most appreciated!
Thanks,
Mel
import Blender
from Blender import NMesh, Scene, Object, Material, Draw, BGL
sliderR = Draw.Create(0.756)
sliderG = Draw.Create(0.756)
sliderB = Draw.Create(0.756)
cur = Scene.getCurrent()
def MakeCube():
list_of_vertices=[
[-1,-1,-1],
[-1,+1,-1],
[+1,+1,-1],
[+1,-1,-1],
[-1,-1,+1],
[-1,+1,+1],
[+1,+1,+1],
[+1,-1,+1]
]
list_of_faces=[
[0,1,2,3],
[4,5,6,7],
[0,4,7,3],
[1,2,6,5],
[0,1,5,4],
[3,7,6,2]
]
CubeMeshData=NMesh.GetRaw()
mat=Material.New('Material')
CubeMeshData.materials.append(mat)
print mat.rgbCol
mat.rgbCol=[sliderR.val, sliderG.val, sliderB.val]
mat.setAlpha(1.0)
mat.setRef(0.8)
mat.setSpec(0.5)
mat.setHardness(50)
for component in list_of_vertices:
vertex=NMesh.Vert(component[0], component[1], component[2])
CubeMeshData.verts.append(vertex)
for face_current in list_of_faces:
face=NMesh.Face()
for number_vertex in face_current:
face.append(CubeMeshData.verts[number_vertex])
CubeMeshData.faces.append(face)
NMesh.PutRaw(CubeMeshData, 'Cube', 1)
EV_BT_OK = 1
EV_BT_CANCEL = 2
EV_SL_R = 3
EV_SL_G = 4
EV_SL_B = 5
line = [None, None, None, None, None, None, None, None, None, None]
line[0] = 5
line[1] = 50
line[2] = 80
line[3] = 110
def draw_gui():
global sliderR, sliderG, sliderB
sliderR = Draw.Slider("R: ", EV_SL_R, 5, line[3], 100, 25, sliderR.val, 0.00, 1.00, 1, "Red component of the colour")
sliderG = Draw.Slider("G: ", EV_SL_G, 5, line[2], 100, 25, sliderG.val, 0.00, 1.00, 1, "Green component of the colour")
sliderB = Draw.Slider("B: ", EV_SL_B, 5, line[1], 100, 25, sliderB.val, 0.00, 1.00, 1, "Blue component of the colour")
Draw.PushButton("ok", EV_BT_OK, 5, line[0], 60, 25, "confirm")
Draw.PushButton("cancel", EV_BT_CANCEL, 80, line[0], 60, 25, "cancel")
def event(event, val):
if event == Draw.ESCKEY or event == Draw.QKEY:
stop = Draw.Pupmenu("OK?%t|Stop the script %x1")
if stop == 1:
Draw.Exit()
if event == Draw.CKEY:
make = Draw.Pupmenu("create cube?%t|Construct the cube %x1")
if make == 1:
MakeCube()
Blender.Redraw()
def button_event(evt):
if evt==EV_BT_OK:
MakeCube()
Blender.Redraw()
elif evt==EV_BT_CANCEL:
Draw.Exit()
Draw.Register(draw_gui, event, button_event)