forked from bartvdbraak/blender
-> 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:
parent
c58e27d070
commit
1d425f8da2
@ -525,8 +525,8 @@ class FaceDesc:
|
||||
def __init__(self):
|
||||
self.vertex_index_lst = []
|
||||
self.mface = None
|
||||
self.texture_index = -1
|
||||
self.material_index = -1
|
||||
self.texture_index = 65535
|
||||
self.material_index = 65535
|
||||
self.color_index = 127
|
||||
self.renderstyle = 0
|
||||
self.twoside = 0
|
||||
@ -979,8 +979,14 @@ class FLTNode(Node):
|
||||
self.header.fw.write_char(0) # Reserved
|
||||
self.header.fw.write_char(alpha) # Template
|
||||
self.header.fw.write_short(-1) # Detail tex pat index
|
||||
self.header.fw.write_short(face_desc.texture_index) # Tex pattern index
|
||||
self.header.fw.write_short(face_desc.material_index) # material index
|
||||
if face_desc.texture_index == -1:
|
||||
self.header.fw.write_ushort(65535)
|
||||
else:
|
||||
self.header.fw.write_ushort(face_desc.texture_index) # Tex pattern index
|
||||
if face_desc.material_index == -1:
|
||||
self.header.fw.write_ushort(65535)
|
||||
else:
|
||||
self.header.fw.write_ushort(face_desc.material_index) # material index
|
||||
self.header.fw.write_short(0) # SMC code
|
||||
self.header.fw.write_short(0) # Feature code
|
||||
self.header.fw.write_int(0) # IR material code
|
||||
@ -1015,6 +1021,9 @@ class FLTNode(Node):
|
||||
self.header.fw.write_ushort(8 + (mtex * 8)) # Length
|
||||
self.header.fw.write_uint(uvmask) # UV mask
|
||||
for i in xrange(mtex):
|
||||
if face_desc.images[i] == -1:
|
||||
self.header.fw.write_ushort(65535)
|
||||
else:
|
||||
self.header.fw.write_ushort(face_desc.images[i]) # Tex pattern index
|
||||
self.header.fw.write_ushort(0) # Tex effect
|
||||
self.header.fw.write_ushort(0) # Tex Mapping index
|
||||
@ -1092,7 +1101,7 @@ class FLTNode(Node):
|
||||
write_prop(self.header.fw,ftype,self.object.properties['FLT']['EXT'][propname],length)
|
||||
#write extension data
|
||||
for i in xrange(datalen):
|
||||
self.header.fw.write_char(self.object.properties['FLT']['EXT']['data'][i])
|
||||
self.header.fw.write_uchar(struct.unpack('>B', struct.pack('>B', self.object.properties['FLT']['EXT']['data'][i]))[0])
|
||||
self.write_pop_extension()
|
||||
|
||||
|
||||
@ -1181,7 +1190,7 @@ class Database(Node):
|
||||
self.fw.write_short(70) # Vertex with color normal and uv opcode.
|
||||
self.fw.write_ushort(64) # Length of record
|
||||
self.fw.write_ushort(0) # Color name index
|
||||
self.fw.write_short(0x20000000) # Flags
|
||||
self.fw.write_short(1 << 14) # Frozen Normal
|
||||
self.fw.write_double(desc.x)
|
||||
self.fw.write_double(desc.y)
|
||||
self.fw.write_double(desc.z)
|
||||
@ -1199,7 +1208,7 @@ class Database(Node):
|
||||
print 'Writing texture palette.'
|
||||
# Write record for texture palette
|
||||
for i, img in enumerate(self.GRR.texture_lst):
|
||||
filename = tex_files[img.name].replace("\\", "/")
|
||||
filename = tex_files[img.name]
|
||||
self.fw.write_short(64) # Texture palette opcode.
|
||||
self.fw.write_short(216) # Length of record
|
||||
self.fw.write_string(filename, 200) # Filename
|
||||
@ -1245,7 +1254,7 @@ class Database(Node):
|
||||
cpalette = defaultp.pal
|
||||
count = len(cpalette)
|
||||
for i in xrange(count):
|
||||
color = struct.unpack('>BBBB',struct.pack('>I',cpalette[i]))
|
||||
color = struct.unpack('>BBBB',struct.pack('>i',cpalette[i]))
|
||||
self.fw.write_uchar(color[3]) # alpha
|
||||
self.fw.write_uchar(color[2]) # b
|
||||
self.fw.write_uchar(color[1]) # g
|
||||
|
@ -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
|
||||
@ -212,6 +289,23 @@ def event(evt,val):
|
||||
|
||||
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)
|
||||
@ -285,6 +379,11 @@ def draw_palette():
|
||||
global curint
|
||||
global curswatch
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user