-> Color Fixing tool in FLT toolbar
[blender.git] / release / scripts / flt_toolbar.py
1 #!BPY
2
3 """
4 Name: 'FLT Toolbar'
5 Blender: 240
6 Group: 'Misc'
7 Tooltip: 'Tools for working with FLT databases'
8 """
9
10 __author__ = "Geoffrey Bantle"
11 __version__ = "1.0 11/21/07"
12 __email__ = ('scripts', 'Author, ')
13 __url__ = ('blender', 'elysiun')
14
15 __bpydoc__ ="""\
16 This script provides tools for working with OpenFlight databases in Blender. OpenFlight is a
17 registered trademark of MultiGen-Paradigm, Inc.
18
19 Feature overview and more availible at:
20 http://wiki.blender.org/index.php/Scripts/Manual/FLTools
21 """
22
23 # --------------------------------------------------------------------------
24 # flt_palettemanager.py version 0.1 2005/04/08
25 # --------------------------------------------------------------------------
26 # ***** BEGIN GPL LICENSE BLOCK *****
27 #
28 # Copyright (C) 2007: Blender Foundation
29 #
30 # This program is free software; you can redistribute it and/or
31 # modify it under the terms of the GNU General Public License
32 # as published by the Free Software Foundation; either version 2
33 # of the License, or (at your option) any later version.
34 #
35 # This program is distributed in the hope that it will be useful,
36 # but WITHOUT ANY WARRANTY; without even the implied warranty of
37 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38 # GNU General Public License for more details.
39 #
40 # You should have received a copy of the GNU General Public License
41 # along with this program; if not, write to the Free Software Foundation,
42 # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
43 #
44 # ***** END GPL LICENCE BLOCK *****
45 # --------------------------------------------------------------------------
46
47 import Blender.Draw as Draw
48 from Blender.BGL import *
49 import Blender
50 import flt_properties
51 reload(flt_properties)
52 from flt_properties import *
53
54 xrefprefix = ""
55 xrefstack = list()
56 vofsstack = list()
57 vquatstack = list()
58 prop_w = 256
59 prop_h = 256
60
61
62 #event codes
63 evcode = {
64         "XREF_MAKE" : 100,
65         "XREF_EDIT" : 101,
66         "XREF_FILE" : 102,
67         "XREF_PICK" : 103,
68         "XREF_SELECT" : 104,
69         "XREF_POP" : 105,
70         "XREF_PREFIX" : 106,
71         "FACE_NAME" : 200,
72         "FACE_MAKESUB" : 201,
73         "FACE_KILLSUB" : 202,
74         "FACE_SELSUB" : 203,
75         "SCENE_UPDATE" : 303,
76         "IDPROP_COPY" : 501,
77         "IDPROP_KILL" : 502,
78         "CLIGHT_MAKE" : 700,
79         "DFROMACT" : 701,
80         "FIXCOL" : 702
81 }
82
83 XREF_PREFIX = None
84 XREF_MAKE = None
85 XREF_EDIT = None
86 XREF_SELECT = None
87 XREF_POP = None
88 FACE_MAKESUB = None
89 FACE_SELSUB = None
90 FACE_KILLSUB = None
91 IDPROP_KILL = None
92 IDPROP_COPY = None
93 SCENE_UPDATE = None
94 CLIGHT_MAKE = None
95 DFROMACT = None
96 FIXCOL = None
97
98
99 def RGBtoHSV( r, g, b):
100         cmin = min( r, g, b )
101         cmax = max( r, g, b )
102         v = cmax                                
103
104         if(cmax!=0.0):
105                 s = (cmax-cmin)/cmax
106         else:
107                 s = 0.0
108                 h = 0.0
109         
110         if(s == 0.0):
111                 h = -1.0
112         else:
113                 cdelta = cmax-cmin
114                 rc = (cmax-r)/cdelta
115                 gc = (cmax-g)/cdelta
116                 bc = (cmax-b)/cdelta
117                 if(r==cmax):
118                         h = bc-gc
119                 else:
120                         if(g==cmax):
121                                 h = 2.0+rc-bc
122                         else:
123                                 h = 4.0+gc-rc
124                 h = h*60.0
125                 if(h<0.0):
126                         h += 360.0
127                         
128                 
129         h = h/360.0
130         if(h < 0.0): 
131                 h = 0.0
132         return (h,s,v)
133
134
135 def update_state():
136         state = dict()
137         state["activeScene"] = Blender.Scene.getCurrent()
138         state["activeObject"] = state["activeScene"].getActiveObject()
139         if state["activeObject"] and not state["activeObject"].sel:
140                 state["activeObject"] = None
141         state["activeMesh"] = None
142         if state["activeObject"] and state["activeObject"].type == 'Mesh':
143                 state["activeMesh"] = state["activeObject"].getData(mesh=True)
144         
145         state["activeFace"] = None
146         if state["activeMesh"]:
147                 if state["activeMesh"].faceUV and state["activeMesh"].activeFace != None:
148                         state["activeFace"] = state["activeMesh"].faces[state["activeMesh"].activeFace]
149                 
150         #update editmode
151         state["editmode"]       = Blender.Window.EditMode()
152
153         return state
154 def pack_face_index(index, intensity):
155         return ((127*intensity)+(128*index))
156 def unpack_face_index(face_index):
157         index = face_index / 128
158         intensity = float(face_index - 128.0 * index) / 127.0
159         return(index,intensity)
160         
161 def idprops_append(object, typecode, props):
162         object.properties["FLT"] = dict()
163         object.properties["FLT"]['type'] = typecode 
164         for prop in props:
165                 object.properties["FLT"][prop] = props[prop]
166         object.properties["FLT"]['3t8!id'] = object.name
167
168 def idprops_kill(object):
169         state = update_state()
170         if object and object.properties.has_key('FLT'):
171                 object.properties.pop('FLT')
172
173 def idprops_copy(source):
174         state = update_state()
175         if source.properties.has_key('FLT'):
176                 for object in state["activeScene"].objects:
177                         if object.sel and object != source and (state["activeScene"].Layers & object.Layers):
178                                 idprops_kill(object)
179                                 object.properties['FLT'] = dict()
180                                 for key in source.properties['FLT']:
181                                         object.properties['FLT'][key] = source.properties['FLT'][key]
182
183 def unpack_color(color):
184         return struct.unpack('>BBBB',struct.pack('>I',color))
185
186
187 def findColorKey(colordict, hsv):
188         hdelta = 0.001
189         for key in colordict:
190                 if not (((hsv[0] < (key[0] + hdelta)) and (hsv[0] > (key[0] - hdelta))) and ((hsv[1] < (key[1] + hdelta)) and (hsv[1] > (key[1] - hdelta)))):
191                         return key
192         return None
193
194 def hsvsort(a, b):
195         (index1, mag1) = a
196         (index2, mag2) = b
197         if mag1 > mag2:
198                 return 1
199         elif mag1 < mag2:
200                 return -1
201         return 0
202
203 def fix_colors():
204         
205         editmode = 0
206         if Blender.Window.EditMode():
207                 Blender.Window.EditMode(0)
208                 editmode = 1
209         state = update_state()
210         
211         scene = state["activeScene"]
212         colors = None
213         if state["activeScene"].properties.has_key('FLT'):
214                 try:
215                         colors = state["activeScene"].properties['FLT']['Color Palette']
216                 except:
217                         pass
218         if not colors:
219                 return
220         
221         #first build a HSV version of our palette
222         hsvpalette = list()
223         for swatch in colors:
224                 color = unpack_color(swatch)
225                 hsv = RGBtoHSV(color[0] / 255.0, color[1] / 255.0, color[2] / 255.0)
226                 hsvpalette.append(hsv)
227                 
228         #collect all of our meshes
229         meshes = list()
230         for object in scene.objects.context:
231                 if object.sel and object.type == 'Mesh':
232                         mesh = object.getData(mesh=True)
233                         if "FLT_COL" in mesh.faces.properties:
234                                 meshes.append(mesh)
235                                 
236                                 
237         #Now go through our meshes, and build a dictionary of face lists keyed according to (hue,saturation) of the baked color
238         colordict = dict()
239         for mesh in meshes:
240                 for face in mesh.faces:
241                         hsv = RGBtoHSV(face.col[0].r/255.0, face.col[0].g/255.0, face.col[0].b/255.0) #retrieve baked color
242                         if colordict.has_key((hsv[0],hsv[1])):
243                                 colordict[(hsv[0],hsv[1])].append(face)
244                         else:
245                                 colordict[(hsv[0],hsv[1])] = [face]                             
246         
247
248         #for each color key in the color dict, build a list of distances from it to the values in hsvpalette and then quicksort them for closest match
249         for key in colordict:
250                 maglist = list()
251                 for i, hsv in enumerate(hsvpalette):
252                         norm = Blender.Mathutils.Vector(hsv[0], hsv[1]) - Blender.Mathutils.Vector(key[0],key[1])
253                         maglist.append((i,norm.length))
254                 maglist.sort(hsvsort)
255                 print maglist[0]
256                 for face in colordict[key]:
257                         (index, intensity) = unpack_face_index(face.getProperty("FLT_COL"))
258                         newfindex = pack_face_index(maglist[0][0],intensity)
259                         face.setProperty("FLT_COL", int(newfindex))
260         
261         for mesh in meshes:
262                 update_mesh_colors(colors,mesh) 
263         
264         if editmode:
265                 Blender.Window.EditMode(1)      
266         
267
268 def update_mesh_colors(colors, mesh):
269         if 'FLT_COL' in mesh.faces.properties:
270                 mesh.activeColorLayer = "FLT_Fcol"
271                 for face in mesh.faces:
272                         (index,intensity) = unpack_face_index(face.getProperty('FLT_COL'))
273                         color = struct.unpack('>BBBB',struct.pack('>I',colors[index]))
274                         
275                         if index == 0 and intensity == 0:
276                                 color = (255,255,255)
277                                 intensity  = 1.0
278                         #update the vertex colors for this face
279                         for col in face.col:
280                                 col.r = int(color[0] * intensity)
281                                 col.g = int(color[1] * intensity)
282                                 col.b = int(color[2] * intensity)
283                                 col.a = 255
284         
285                 
286 def update_all():
287         
288         editmode = 0
289         if Blender.Window.EditMode():
290                 Blender.Window.EditMode(0)
291                 editmode = 1
292         state = update_state()
293         
294         if state["activeScene"].properties.has_key('FLT'):
295                 try:
296                         colors = state["activeScene"].properties['FLT']['Color Palette']
297                 except:
298                         colors = None
299         if colors:
300                 #update the baked FLT colors for all meshes.
301                 for object in state["activeScene"].objects:
302                         if object.type == "Mesh":
303                                 mesh = object.getData(mesh=True)
304                                 update_mesh_colors(colors,mesh)
305         if editmode:
306                 Blender.Window.EditMode(1)
307
308 #Change this to find the deep parent
309 def xref_create():
310         global xrefprefix
311         global xrefstack
312         global vofsstack
313         global vquatstack
314         global prop_w
315         global prop_h
316         
317         state = update_state()
318         
319         def findchildren(object):
320                 children = list()
321                 for candidate in state["activeScene"].objects:
322                         if candidate.parent == object:
323                                 children.append(candidate)
324                 retlist = list(children)
325                 for child in children:
326                         retlist = retlist + findchildren(child)
327                 return retlist
328                 
329         actObject = state["activeObject"]
330         if actObject and xrefprefix:
331                 scenenames = list()
332                 for scene in Blender.Scene.Get():
333                         scenenames.append(scene.name)
334
335                 if xrefprefix in scenenames:
336                         #build a unique name for the xref...
337                         suffix = 1
338                         found = False
339                         while not found:
340                                 candidate = xrefprefix + str(suffix)
341                                 if not candidate in scenenames:
342                                         xrefname = candidate
343                                         found = True
344                                 suffix+=1
345                 else:
346                         xrefname = xrefprefix
347                 #create our XRef node
348                 xnode = state["activeScene"].objects.new('Empty')
349                 xnode.name = 'X:' + xrefname
350                 xnode.properties['FLT'] = dict()
351                 for prop in FLTXRef:
352                         xnode.properties['FLT'][prop] = FLTXRef[prop]
353                 xnode.properties['FLT']['3t200!filename'] = xrefname + '.flt'
354                 xnode.properties['FLT']['type'] = 63
355                 xnode.enableDupGroup = True
356                 xnode.DupGroup = Blender.Group.New(xrefname) #this is dangerous... be careful!
357
358                 #copy rot and loc of actObject
359                 xnode.setLocation(actObject.getLocation())
360                 xnode.setEuler(actObject.getEuler())         
361                 
362                 #build the new scene
363                 xrefscene = Blender.Scene.New(xrefname)
364                 xrefscene.properties['FLT'] = dict()
365                 xrefscene.properties['FLT']['Filename'] = xrefname
366                 xrefscene.properties['FLT']['Main'] = 0
367
368                 #find the children of actObject so that we can add them to the group
369                 linkobjects = findchildren(actObject)
370                 linkobjects.append(actObject)
371                 for object in linkobjects:
372                         xrefscene.objects.link(object)
373                         state["activeScene"].objects.unlink(object)
374                         xnode.DupGroup.objects.link(object)
375                 #clear rotation of actObject and location
376                 actObject.setLocation(0.0,0.0,0.0)
377                 actObject.setEuler(0.0,0.0,0.0)
378
379                 xrefscene.update(1)
380                 state["activeScene"].update(1)
381
382 def xref_select():
383         state = update_state()
384         candidates = list()
385         scenelist = [scene.name for scene in Blender.Scene.Get()]
386         for object in state["activeScene"].objects:
387                 if object.type == 'Empty' and object.enableDupGroup == True and object.DupGroup:
388                         candidates.append(object)
389                 
390         for object in candidates:
391                 if object.DupGroup.name in scenelist:
392                         object.sel = 1
393
394 def xref_edit():
395         global xrefprefix
396         global xrefstack
397         global vofsstack
398         global vquatstack
399         global prop_w
400         global prop_h
401         
402         state = update_state()
403
404         actObject = state["activeObject"]
405
406         if actObject and actObject.type == 'Empty' and actObject.DupGroup:
407 #               if actObject.properties.has_key('FLT') and actObject.properties['FLT']['type'] == 63:
408                 for FLTscene in Blender.Scene.Get():
409                         if FLTscene.properties.has_key('FLT') and FLTscene.name == actObject.DupGroup.name:
410                                 actObject.sel = 0
411                                 xrefstack.append(state["activeScene"])
412                                 vofsstack.append(Blender.Window.GetViewOffset())
413                                 vquatstack.append(Blender.Window.GetViewQuat())
414                                 FLTscene.makeCurrent()
415                                 Blender.Window.SetViewOffset(0.0,0.0,0.0)
416
417 def xref_finish():
418         global xrefprefix
419         global xrefstack
420         global vofsstack
421         global vquatstack
422         global prop_w
423         global prop_h
424         
425         state = update_state() 
426         if xrefstack:
427                 scene = xrefstack.pop()
428                 Blender.Window.SetViewQuat(vquatstack.pop())
429                 Blender.Window.SetViewOffset(vofsstack.pop())
430                 scene.makeCurrent()
431                 
432
433 def sortSub(a,b):
434         aindex = a.getProperty("FLT_ORIGINDEX")
435         bindex = b.getProperty("FLT_ORIGINDEX")
436         
437         if aindex > bindex:
438                 return 1
439         elif aindex < bindex:
440                 return -1
441         return 0
442
443 def subface_make():
444         global xrefprefix
445         global xrefstack
446         global vofsstack
447         global vquatstack
448         global prop_w
449         global prop_h
450         
451         editmode = 0
452         if Blender.Window.EditMode():
453                 Blender.Window.EditMode(0)
454                 editmode = 1
455
456         state = update_state()
457         
458         actmesh = state["activeMesh"]
459         activeFace = state["activeFace"]
460         if actmesh:
461                 if not "FLT_ORIGINDEX" in actmesh.faces.properties:
462                         actmesh.faces.addPropertyLayer("FLT_ORIGINDEX",Blender.Mesh.PropertyTypes["INT"])
463                         for i, face in enumerate(actmesh.faces):
464                                 face.setProperty("FLT_ORIGINDEX",i)
465                 if not "FLT_SFLEVEL" in actmesh.faces.properties:
466                         actmesh.faces.addPropertyLayer("FLT_SFLEVEL",Blender.Mesh.PropertyTypes["INT"])
467                         
468                 #attach the subfaces to the active face. Note, this doesnt really work 100 percent properly yet, just enough for one level!
469                 if activeFace:
470                         #steps:
471                         #remove actface and selected faces from the facelist
472                         #quicksort facelist
473                         #append actface and subfaces to end of facelist.
474                         #generate new indices
475                         facelist = list()
476                         sublist = list()
477                         for face in actmesh.faces:
478                                 facelist.append(face)
479                         for face in facelist:   
480                                 if face == activeFace:
481                                         face.setProperty("FLT_SFLEVEL",0)
482                                         sublist.insert(0,face)
483                                 elif face.sel:
484                                         face.setProperty("FLT_SFLEVEL",1)
485                                         sublist.append(face)
486                         for face in sublist:
487                                 facelist.remove(face)
488                         facelist.sort(sortSub)
489                         for face in sublist:
490                                 facelist.append(face)
491                         for i, face in enumerate(facelist):
492                                 face.setProperty("FLT_ORIGINDEX",i)
493                 else:
494                         pass
495         
496         if editmode:
497                 Blender.Window.EditMode(1)
498
499 def subface_kill():
500         global xrefprefix
501         global xrefstack
502         global vofsstack
503         global vquatstack
504         global prop_w
505         global prop_h
506         
507         editmode = 0
508         if Blender.Window.EditMode():
509                 Blender.Window.EditMode(0)
510                 editmode = 1
511         state = update_state()
512         
513         actmesh = state["activeMesh"]
514         if actmesh:
515                 if "FLT_ORIGINDEX" in actmesh.faces.properties and "FLT_SFLEVEL" in actmesh.faces.properties:
516                         for i,face in enumerate(actmesh.faces):
517                                 face.setProperty("FLT_ORIGINDEX",i)
518                                 face.setProperty("FLT_SFLEVEL",0)
519         if editmode:
520                 Blender.Window.EditMode(1)
521
522 def subface_select():
523         global xrefprefix
524         global xrefstack
525         global vofsstack
526         global vquatstack
527         global prop_w
528         global prop_h
529         
530         editmode = 0
531         if Blender.Window.EditMode():
532                 Blender.Window.EditMode(0)
533                 editmode = 1
534         state = update_state()
535         
536         actmesh = state["activeMesh"]
537         activeFace = state["activeFace"]
538         if actmesh and activeFace:
539                 if "FLT_ORIGINDEX" in actmesh.faces.properties and "FLT_SFLEVEL" in actmesh.faces.properties:
540                         facelist = list()
541                         actIndex = None
542                         sublevel = None
543                         for face in actmesh.faces:
544                                 facelist.append(face)
545                                 facelist.sort(sortSub)
546                         for i, face in enumerate(facelist):
547                                 if face == activeFace:
548                                         actIndex = i
549                                         sublevel = face.getProperty("FLT_SFLEVEL")+1
550                                         break
551                         leftover = facelist[actIndex+1:]
552                         for face in leftover:
553                                 if face.getProperty("FLT_SFLEVEL") == sublevel:
554                                         face.sel = 1
555                                 else:
556                                         break
557         if editmode:
558                 Blender.Window.EditMode(1)
559
560 def select_by_typecode(typecode):
561         global xrefprefix
562         global xrefstack
563         global vofsstack
564         global vquatstack
565         global prop_w
566         global prop_h
567         
568         state = update_state()
569         
570         for object in state["activeScene"].objects:
571                 if object.properties.has_key('FLT') and object.properties['FLT']['type'] == typecode and state["activeScene"].Layers & object.Layers:
572                                 object.select(1)
573 def clight_make():
574         state = update_state()
575         actmesh = state["activeMesh"]
576         actobj = state["activeObject"]
577         
578         if actobj and actmesh:
579                 actobj.properties['FLT'] = dict()
580                 actobj.properties['FLT']['type'] = 111
581                 for prop in FLTInlineLP:
582                         actobj.properties['FLT'][prop] = FLTInlineLP[prop]
583         
584                 actmesh.verts.addPropertyLayer("FLT_VCOL", Blender.Mesh.PropertyTypes["INT"])
585                 for v in actmesh.verts:
586                         v.setProperty("FLT_VCOL", 83815)
587                         
588 def dfromact():
589         state = update_state()
590         actobj = state["activeObject"]
591         actscene = state["activeScene"]
592         dof = None
593         
594         for object in actscene.objects.context:
595                 if object.sel and (object != actobj):
596                         if not dof:
597                                 dof = object
598                         else:
599                                 return 
600         
601         if 'FLT' not in dof.properties:
602                 dof.properties['FLT'] = dict()  
603         
604         #Warning! assumes 1 BU == 10 meters.
605         #do origin
606         dof.properties['FLT']['5d!ORIGX'] = actobj.getLocation('worldspace')[0]*10.0
607         dof.properties['FLT']['6d!ORIGY'] = actobj.getLocation('worldspace')[1]*10.0
608         dof.properties['FLT']['7d!ORIGZ'] = actobj.getLocation('worldspace')[2]*10.0
609         #do X axis
610         x = Blender.Mathutils.Vector(1.0,0.0,0.0)
611         x = x * actobj.getMatrix('worldspace')
612         x = x * 10.0
613         dof.properties['FLT']['8d!XAXIS-X'] = x[0]
614         dof.properties['FLT']['9d!XAXIS-Y'] = x[1]
615         dof.properties['FLT']['10d!XAXIS-Z'] = x[2]
616         #do X/Y plane
617         x = Blender.Mathutils.Vector(1.0,1.0,0.0)
618         x.normalize()
619         x = x * actobj.getMatrix('worldspace')
620         x = x * 10.0
621         dof.properties['FLT']['11d!XYPLANE-X'] = x[0]
622         dof.properties['FLT']['12d!XYPLANE-Y'] = x[1]
623         dof.properties['FLT']['13d!XZPLANE-Z'] = x[2]
624         
625         
626         
627         
628         
629 def event(evt,val):
630         if evt == Draw.ESCKEY:
631                 Draw.Exit()
632                 
633 def but_event(evt):
634         global xrefprefix
635         global xrefstack
636         global vofsstack
637         global vquatstack
638         global prop_w
639         global prop_h
640         global evcode
641         
642         state = update_state()
643         
644         #do Xref buttons
645         if evt == evcode["XREF_PREFIX"]:
646                 xrefprefix = XREF_PREFIX.val
647         if evt == evcode["XREF_EDIT"]:
648                 xref_edit()
649         if evt == evcode["XREF_SELECT"]:
650                 xref_select()
651         if evt == evcode["XREF_MAKE"]:
652                 xref_create()
653         #do scene buttons                               
654         if evt == evcode["SCENE_UPDATE"]:
655                 update_all()
656         #do face buttons
657         if evt == evcode["FACE_MAKESUB"]:
658                 subface_make()
659         if evt== evcode["FACE_KILLSUB"]:
660                 subface_kill()
661         if evt== evcode["FACE_SELSUB"]:
662                 subface_select()
663         #common buttons
664         if evt == evcode["IDPROP_KILL"]:
665                 if state["activeObject"]:
666                         idprops_kill(state["activeObject"])
667         if evt == evcode["IDPROP_COPY"]:
668                 if state["activeObject"]:
669                         idprops_copy(state["activeObject"])
670         if evt == evcode["XREF_POP"]:
671                 xref_finish()
672         if evt == evcode["CLIGHT_MAKE"]:
673                 clight_make()
674         if evt == evcode["DFROMACT"]:
675                 dfromact()
676         if evt == evcode["FIXCOL"]:
677                 fix_colors()
678         Draw.Redraw(1)
679         Blender.Window.RedrawAll()
680
681
682 def box(x,y,w,h,c,mode):
683         glColor3f(c[0],c[1],c[2])
684         if mode == "outline":
685                 glBegin(GL_LINE_LOOP)
686         else:
687                 glBegin(GL_POLYGON)
688         glVertex2i(x,y)
689         glVertex2i(x+w,y)
690         glVertex2i(x+w,y+h)
691         glVertex2i(x,y+h)
692         glEnd()
693
694 def draw_postcommon(x,y,finaly):
695         global sheetlabel
696         global xrefprefix
697         global xrefstack
698         global vofsstack
699         global vquatstack
700         global prop_w
701         global prop_h
702         global evcode
703         
704         state = update_state()
705         
706         width = prop_w
707         height = prop_h
708         
709         #draw the header
710         glColor3f(0.15,0.15,0.15)
711         glBegin(GL_POLYGON)
712         glVertex2i(x-1,y)
713         glVertex2i(x+width+1,y)
714         glVertex2i(x+width+1,y-25)
715         glVertex2i(x-1,y-25)
716         glEnd()
717         glColor3f(1,1,1)
718         glRasterPos2i(x,y-20)
719         sheetlabel = Blender.Draw.Text("FLT Tools Panel")
720         #draw the box outline
721         glColor3f(0,0,0)
722         glBegin(GL_LINE_LOOP)
723         glVertex2i(x-1,y)
724         glVertex2i(x+1+width,y)
725         glVertex2i(x+1+width,finaly-1)
726         glVertex2i(x-1,finaly-1)
727         glEnd()
728         return finaly
729
730
731 def draw_propsheet(x,y):
732         global XREF_PREFIX
733         global XREF_MAKE
734         global XREF_EDIT
735         global XREF_SELECT
736         global XREF_POP
737         global FACE_MAKESUB
738         global FACE_SELSUB
739         global FACE_KILLSUB
740         global IDPROP_KILL
741         global IDPROP_COPY
742         global SCENE_UPDATE
743         global DFROMACT
744         global FIXCOL
745                 
746         global CLIGHT_MAKE
747         global xrefprefix
748         global xrefstack
749         global vofsstack
750         global vquatstack
751         global prop_w
752         global prop_h
753         global evcode
754         
755         state = update_state()
756
757         width = prop_w
758         height = prop_h
759         origx = x
760         origy = y
761         
762          #draw Xref tools
763         y = y-20
764         XREF_PREFIX = Blender.Draw.String("XRef Name:",evcode["XREF_PREFIX"],x,y,width,20,xrefprefix,18,"Xref prefix name, Actual name is generated from this")
765         y = y-20
766         XREF_MAKE = Blender.Draw.PushButton("Make XRef",evcode["XREF_MAKE"],x,y,width,20,"Make External Reference")
767         y = y-20
768         XREF_EDIT = Blender.Draw.PushButton("Edit XRef",evcode["XREF_EDIT"],x,y,width,20,"Edit External Reference")
769         y = y-20
770         XREF_SELECT = Blender.Draw.PushButton("Select XRefs",evcode["XREF_SELECT"],x,y,width,20,"Select External References")
771         y = y - 20
772         XREF_POP = Blender.Draw.PushButton("Return to previous scene",evcode["XREF_POP"],x,y,width,20,"Go up one level in xref hierarchy")
773
774         #Draw facetools
775         y = y-20
776         FACE_MAKESUB = Blender.Draw.PushButton("Make Subfaces",evcode["FACE_MAKESUB"],x,y,width,20,"Make subfaces")
777         y = y-20
778         FACE_SELSUB = Blender.Draw.PushButton("Select Subfaces",evcode["FACE_SELSUB"],x,y,width,20,"Select subfaces")
779         y = y-20
780         FACE_KILLSUB = Blender.Draw.PushButton("Kill Subfaces",evcode["FACE_KILLSUB"],x,y,width,20,"Kill subfaces")
781
782         #Draw ID Property tools
783         y = y - 20
784         IDPROP_KILL = Blender.Draw.PushButton("Delete ID props",evcode["IDPROP_KILL"],x,y,width,20,"Delete ID props")
785         y = y - 20
786         IDPROP_COPY = Blender.Draw.PushButton("Copy to selected",evcode["IDPROP_COPY"],x,y,width,20, "Copy from active to all selected")
787         
788         y= y - 20
789         CLIGHT_MAKE = Blender.Draw.PushButton("Make Light Point", evcode["CLIGHT_MAKE"],x,y,width,20,"Create inline light points from current mesh")
790         #General tools
791         y = y-20
792         SCENE_UPDATE = Blender.Draw.PushButton("Update All",evcode["SCENE_UPDATE"],x,y,width,20,"Update all vertex colors")
793         
794         y=y-20
795         DFROMACT = Blender.Draw.PushButton("Dof from Active", evcode["DFROMACT"],x,y,width,20,"Get Dof origin from active object")
796         y=y-20
797         FIXCOL = Blender.Draw.PushButton("Fix Colors", evcode["FIXCOL"],x,y,width,20,"Fix baked FLT colors of selected meshes")         
798         draw_postcommon(origx, origy,y)
799                 
800 def gui():
801         #draw the propsheet/toolbox.
802         psheety = 300
803         #psheetx = psheety + 10
804         draw_propsheet(0,psheety)
805 Draw.Register(gui,event,but_event)
806