-> Fix for warnings in FLT exporter and Palette Manager
Removed buffer overflow masking warnings from the FLT exporter and Palette Manager.
This commit is contained in:
@@ -25,7 +25,7 @@ http://wiki.blender.org/index.php/Scripts/Manual/FLTools
|
||||
"""
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# flt_palettemanager.py version 0.1 2005/04/08
|
||||
# flt_palettemanager.py version 1.0 2005/04/08
|
||||
# --------------------------------------------------------------------------
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
@@ -55,6 +55,75 @@ import flt_properties
|
||||
import flt_defaultp as defaultp
|
||||
from flt_properties import *
|
||||
|
||||
def RGBtoHSV( r, g, b):
|
||||
minc = min( r, g, b )
|
||||
maxc = max( r, g, b )
|
||||
v = maxc
|
||||
|
||||
delta = maxc - minc
|
||||
|
||||
if( max != 0 ):
|
||||
s = delta / maxc
|
||||
else:
|
||||
s = 0
|
||||
h = -1
|
||||
return (h,s,v)
|
||||
|
||||
if( r == maxc ):
|
||||
h = ( g - b ) / delta
|
||||
elif( g == maxc ):
|
||||
h = 2 + ( b - r ) / delta
|
||||
else:
|
||||
h = 4 + ( r - g ) / delta
|
||||
|
||||
h *= 60
|
||||
if( h < 0 ):
|
||||
h += 360
|
||||
|
||||
return(h,s,v)
|
||||
|
||||
def HSVtoRGB(h,s,v):
|
||||
|
||||
if( s == 0 ):
|
||||
return (v,v,v)
|
||||
|
||||
|
||||
h /= 60
|
||||
i = math.floor( h)
|
||||
f = h - i
|
||||
p = v * ( 1 - s )
|
||||
q = v * ( 1 - s * f )
|
||||
t = v * ( 1 - s * ( 1 - f ) )
|
||||
|
||||
if i == 0:
|
||||
r = v
|
||||
g = t
|
||||
b = p
|
||||
elif i == 1:
|
||||
r = q
|
||||
g = v
|
||||
b = p
|
||||
|
||||
elif i== 2:
|
||||
r = p
|
||||
g = v
|
||||
b = t
|
||||
elif i==3:
|
||||
r = p
|
||||
g = q
|
||||
b = v
|
||||
elif i==4:
|
||||
r = t
|
||||
g = p
|
||||
b = v
|
||||
|
||||
else:
|
||||
r = v
|
||||
g = p
|
||||
b = q
|
||||
|
||||
return(r,g,b)
|
||||
|
||||
|
||||
palette_size = 12
|
||||
palette_x = 0
|
||||
@@ -68,6 +137,14 @@ cinc = 1.0 / 1024.0
|
||||
cstep = 0.0
|
||||
picker = None
|
||||
ptt = ""
|
||||
|
||||
|
||||
ts1=None
|
||||
ts2=None
|
||||
ts3=None
|
||||
ts4=None
|
||||
ts5=None
|
||||
|
||||
for i in xrange(1024):
|
||||
colors.append([cstep,cstep,cstep])
|
||||
cstep = cstep + cinc
|
||||
@@ -128,7 +205,7 @@ def event(evt,val):
|
||||
Draw.Redraw(1)
|
||||
|
||||
#copy current color and intensity to selected faces.
|
||||
elif evt == Draw.CKEY:
|
||||
elif evt == Draw.VKEY:
|
||||
|
||||
if Blender.Window.EditMode():
|
||||
Blender.Window.EditMode(0)
|
||||
@@ -136,7 +213,7 @@ def event(evt,val):
|
||||
state = update_state()
|
||||
|
||||
#retrieve color from palette
|
||||
color = struct.unpack('>BBBB',struct.pack('>I',colors[curswatch]))
|
||||
color = struct.unpack('>BBBB',struct.pack('>i',colors[curswatch]))
|
||||
actmesh = state["activeMesh"]
|
||||
if actmesh:
|
||||
if(Blender.Window.GetKeyQualifiers() != Blender.Window.Qual["CTRL"]):
|
||||
@@ -182,7 +259,7 @@ def event(evt,val):
|
||||
Blender.Window.RedrawAll()
|
||||
|
||||
#grab color and intensity from active face
|
||||
elif evt == Draw.VKEY:
|
||||
elif evt == Draw.CKEY:
|
||||
if Blender.Window.EditMode():
|
||||
Blender.Window.EditMode(0)
|
||||
editmode = 1
|
||||
@@ -211,6 +288,23 @@ def event(evt,val):
|
||||
Blender.Window.EditMode(1)
|
||||
|
||||
Blender.Window.RedrawAll()
|
||||
|
||||
elif evt == Draw.GKEY:
|
||||
if Blender.Window.EditMode():
|
||||
Blender.Window.EditMode(0)
|
||||
editmode =1
|
||||
state = update_state()
|
||||
|
||||
actmesh = state["activeMesh"]
|
||||
activeFace = state["activeFace"]
|
||||
|
||||
if activeFace and "FLT_COL" in actmesh.faces.properties:
|
||||
(index,intensity) = unpack_face_index(activeFace.getProperty("FLT_COL"))
|
||||
for face in actmesh.faces:
|
||||
(index2, intensity2) = unpack_face_index(face.getProperty("FLT_COL"))
|
||||
if index == index2:
|
||||
face.sel = 1
|
||||
|
||||
|
||||
elif evt == Draw.ESCKEY:
|
||||
Draw.Exit()
|
||||
@@ -225,11 +319,11 @@ def update_all():
|
||||
for object in state["activeScene"].objects:
|
||||
if object.type == "Mesh":
|
||||
mesh = object.getData(mesh=True)
|
||||
if 'FLT_COL' in mesh.faces.properties:
|
||||
if 'FLT_COL' in mesh.faces.properties and "FLT_Fcol" in mesh.getColorLayerNames():
|
||||
mesh.activeColorLayer = "FLT_Fcol"
|
||||
for face in mesh.faces:
|
||||
(index,intensity) = unpack_face_index(face.getProperty('FLT_COL'))
|
||||
color = struct.unpack('>BBBB',struct.pack('>I',colors[index]))
|
||||
color = struct.unpack('>BBBB',struct.pack('>i',colors[index]))
|
||||
#update the vertex colors for this face
|
||||
for col in face.col:
|
||||
col.r = int(color[0] * intensity)
|
||||
@@ -284,8 +378,13 @@ def draw_palette():
|
||||
global colors
|
||||
global curint
|
||||
global curswatch
|
||||
global picker
|
||||
|
||||
global picker
|
||||
global ts1
|
||||
global ts2
|
||||
global ts3
|
||||
global ts4
|
||||
global ts5
|
||||
|
||||
state = update_state()
|
||||
init_pal()
|
||||
|
||||
@@ -297,7 +396,7 @@ def draw_palette():
|
||||
for x in xrange(32):
|
||||
ypos = palette_y
|
||||
for y in xrange(32):
|
||||
color = struct.unpack('>BBBB',struct.pack('>I',colors[cid]))
|
||||
color = struct.unpack('>BBBB',struct.pack('>i',colors[cid]))
|
||||
glColor3f(color[0]/255.0,color[1]/255.0,color[2]/255.0)
|
||||
glBegin(GL_POLYGON)
|
||||
glVertex2i(xpos,ypos)
|
||||
@@ -328,7 +427,7 @@ def draw_palette():
|
||||
xpos = xpos + ssize
|
||||
|
||||
#draw intensity gradient
|
||||
color = struct.unpack('>BBBB',struct.pack('>I',colors[curswatch]))
|
||||
color = struct.unpack('>BBBB',struct.pack('>i',colors[curswatch]))
|
||||
color = [color[0]/255.0,color[1]/255.0,color[2]/255.0]
|
||||
colsteps = [color[0]/255.0,color[1]/255.0,color[2]/255.0]
|
||||
stripwidth = (palette_size * 32.0) / 256
|
||||
@@ -355,15 +454,15 @@ def draw_palette():
|
||||
xpos = ((palette_size*32) * (1.0 - curint)) + palette_x
|
||||
glColor3f(1.0,1.0,1.0)
|
||||
glBegin(GL_LINE_LOOP)
|
||||
glVertex2i(xpos-6,grady-1)
|
||||
glVertex2i(xpos+6,grady-1)
|
||||
glVertex2i(xpos+6,grady+palette_size+1)
|
||||
glVertex2i(xpos-6,grady+palette_size+1)
|
||||
glVertex2i(int(xpos-6),int(grady-1))
|
||||
glVertex2i(int(xpos+6),int(grady-1))
|
||||
glVertex2i(int(xpos+6),int(grady+palette_size+1))
|
||||
glVertex2i(int(xpos-6),int(grady+palette_size+1))
|
||||
#glVertex2i(xpos-6,grady+7)
|
||||
glEnd()
|
||||
|
||||
#draw color picker
|
||||
color = struct.unpack('>BBBB',struct.pack('>I',colors[curswatch]))
|
||||
color = struct.unpack('>BBBB',struct.pack('>i',colors[curswatch]))
|
||||
pickcol = (color[0]/255.0,color[1]/255.0,color[2]/255.0)
|
||||
picker = Blender.Draw.ColorPicker(1,highlight[0][0]+1,highlight[0][1]+1,ssize-2,ssize-2,pickcol,ptt)
|
||||
|
||||
@@ -377,6 +476,24 @@ def draw_palette():
|
||||
glVertex2i(highlight[0][0],highlight[0][1])
|
||||
glEnd()
|
||||
|
||||
#draw text string explanations
|
||||
xpos = palette_size*32+20
|
||||
ypos = palette_size*32+10
|
||||
glRasterPos2d(xpos,ypos)
|
||||
ts1 = Blender.Draw.Text("FLT Palette Manager V 1.0")
|
||||
ypos = ypos - 20
|
||||
glRasterPos2d(xpos,ypos)
|
||||
ts3 = Blender.Draw.Text("CKEY - Copy Active Face Color*")
|
||||
ypos = ypos - 20
|
||||
glRasterPos2d(xpos,ypos)
|
||||
ts2 = Blender.Draw.Text("VKEY - Paste Color to Selected Faces")
|
||||
ypos = ypos - 20
|
||||
glRasterPos2d(xpos,ypos)
|
||||
ts4 = Blender.Draw.Text("GKEY - Select Faces With Same Color")
|
||||
ypos = ypos - 15
|
||||
glRasterPos2d(xpos,ypos)
|
||||
ts5 = Blender.Draw.Text("(*Requires mesh with UV coordinates)", 'small')
|
||||
|
||||
def gui():
|
||||
glClearColor(0.5,0.5,0.5,1.0)
|
||||
glClear(GL_COLOR_BUFFER_BIT)
|
||||
@@ -385,4 +502,4 @@ def gui():
|
||||
|
||||
init_pal()
|
||||
Draw.Register(gui,event,but_event)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user