-> Updated FLT scripts
Blender FLT I/O scripts have been updated to have more features.In addition several utility scripts/applets have been added to aid in working with FLT databases within Blender. Documentation can be found here: http://wiki.blender.org/index.php/Scripts/Manual/Import/openflight_flt http://wiki.blender.org/index.php/Scripts/Manual/Export/openflight_flt http://wiki.blender.org/index.php/Scripts/Manual/FLTools
This commit is contained in:
1
release/scripts/flt_defaultp.py
Normal file
1
release/scripts/flt_defaultp.py
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,11 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
__bpydoc__ ="""\
|
||||
File read/write module used by OpenFlight I/O and tool scripts. OpenFlight is a
|
||||
registered trademark of MultiGen-Paradigm, Inc.
|
||||
"""
|
||||
|
||||
import Blender
|
||||
from struct import *
|
||||
import re
|
||||
@@ -199,7 +204,9 @@ class FltOut:
|
||||
self.file.close()
|
||||
|
||||
def __init__(self, filename):
|
||||
self.file = open(filename, 'wb')
|
||||
self.file = open(filename, 'wb')
|
||||
self.filename = filename
|
||||
|
||||
|
||||
class FileFinder:
|
||||
def add_file_to_search_path(self, filename):
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
388
release/scripts/flt_palettemanager.py
Normal file
388
release/scripts/flt_palettemanager.py
Normal file
@@ -0,0 +1,388 @@
|
||||
#!BPY
|
||||
|
||||
"""
|
||||
Name: 'FLT Palette Manager'
|
||||
Blender: 240
|
||||
Group: 'Misc'
|
||||
Tooltip: 'Manage FLT colors'
|
||||
"""
|
||||
|
||||
__author__ = "Geoffrey Bantle"
|
||||
__version__ = "1.0 11/21/2007"
|
||||
__email__ = ('scripts', 'Author, ')
|
||||
__url__ = ('blender', 'elysiun')
|
||||
|
||||
__bpydoc__ ="""\
|
||||
|
||||
This script manages colors in OpenFlight databases. OpenFlight is a
|
||||
registered trademark of MultiGen-Paradigm, Inc.
|
||||
|
||||
Todo:
|
||||
-Figure out whats causing the PC speaker to beep when initializing...
|
||||
|
||||
Feature overview and more availible at:
|
||||
http://wiki.blender.org/index.php/Scripts/Manual/FLTools
|
||||
"""
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# flt_palettemanager.py version 0.1 2005/04/08
|
||||
# --------------------------------------------------------------------------
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# Copyright (C) 2007: Blender Foundation
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
import Blender.Draw as Draw
|
||||
from Blender.BGL import *
|
||||
import Blender
|
||||
import flt_properties
|
||||
import flt_defaultp as defaultp
|
||||
from flt_properties import *
|
||||
|
||||
|
||||
palette_size = 12
|
||||
palette_x = 0
|
||||
palette_y = 0
|
||||
|
||||
colors = list()
|
||||
curint = 1.0
|
||||
curswatch = 0
|
||||
#make a default palette, not very useful.
|
||||
cinc = 1.0 / 1024.0
|
||||
cstep = 0.0
|
||||
picker = None
|
||||
ptt = ""
|
||||
for i in xrange(1024):
|
||||
colors.append([cstep,cstep,cstep])
|
||||
cstep = cstep + cinc
|
||||
def update_state():
|
||||
state = dict()
|
||||
state["activeScene"] = Blender.Scene.getCurrent()
|
||||
state["activeObject"] = state["activeScene"].getActiveObject()
|
||||
state["activeMesh"] = None
|
||||
if state["activeObject"] and state["activeObject"].type == 'Mesh':
|
||||
state["activeMesh"] = state["activeObject"].getData(mesh=True)
|
||||
|
||||
state["activeFace"] = None
|
||||
if state["activeMesh"]:
|
||||
if state["activeMesh"].faceUV and state["activeMesh"].activeFace != None:
|
||||
state["activeFace"] = state["activeMesh"].faces[state["activeMesh"].activeFace]
|
||||
|
||||
return state
|
||||
|
||||
def pack_face_index(index, intensity):
|
||||
return ((127*intensity)+(128*index))
|
||||
def unpack_face_index(face_index):
|
||||
index = face_index / 128
|
||||
intensity = float(face_index - 128.0 * index) / 127.0
|
||||
return(index,intensity)
|
||||
|
||||
def event(evt,val):
|
||||
global palette_size
|
||||
global palette_x
|
||||
global palette_y
|
||||
global colors
|
||||
global curint
|
||||
global curswatch
|
||||
|
||||
areas = Blender.Window.GetScreenInfo()
|
||||
curarea = Blender.Window.GetAreaID()
|
||||
curRect = None
|
||||
editmode = 0
|
||||
|
||||
for area in areas:
|
||||
if area['id'] == curarea:
|
||||
curRect = area['vertices']
|
||||
break
|
||||
|
||||
if evt == Draw.LEFTMOUSE:
|
||||
mval = Blender.Window.GetMouseCoords()
|
||||
rastx = mval[0] - curRect[0]
|
||||
rasty = mval[1] - curRect[1]
|
||||
|
||||
swatchx = (rastx -palette_x) / palette_size #+state["palette_x"]
|
||||
swatchy = (rasty -palette_y) / palette_size #+state["palette_y"]
|
||||
if rastx > palette_x and rastx < (palette_x + palette_size * 32) and rasty > palette_y and rasty < (palette_y+ palette_size* 32):
|
||||
if swatchx < 32 and swatchy < 32:
|
||||
curswatch = (swatchx * 32) + swatchy
|
||||
Draw.Redraw(1)
|
||||
|
||||
elif swatchy < 34 and swatchx < 32:
|
||||
curint = 1.0 - (float(rastx-palette_x)/(palette_size*32.0))
|
||||
Draw.Redraw(1)
|
||||
|
||||
#copy current color and intensity to selected faces.
|
||||
elif evt == Draw.CKEY:
|
||||
|
||||
if Blender.Window.EditMode():
|
||||
Blender.Window.EditMode(0)
|
||||
editmode = 1
|
||||
state = update_state()
|
||||
|
||||
#retrieve color from palette
|
||||
color = struct.unpack('>BBBB',struct.pack('>I',colors[curswatch]))
|
||||
actmesh = state["activeMesh"]
|
||||
if actmesh:
|
||||
if(Blender.Window.GetKeyQualifiers() != Blender.Window.Qual["CTRL"]):
|
||||
selfaces = list()
|
||||
for face in actmesh.faces:
|
||||
if face.sel:
|
||||
selfaces.append(face)
|
||||
|
||||
if not "FLT_COL" in actmesh.faces.properties:
|
||||
actmesh.faces.addPropertyLayer("FLT_COL",Blender.Mesh.PropertyTypes["INT"])
|
||||
for face in actmesh.faces:
|
||||
face.setProperty("FLT_COL",127) #default
|
||||
try:
|
||||
actmesh.activeColorLayer = "FLT_Fcol"
|
||||
except:
|
||||
actmesh.addColorLayer("FLT_Fcol")
|
||||
actmesh.activeColorLayer = "FLT_Fcol"
|
||||
|
||||
|
||||
for face in selfaces:
|
||||
#First append packed index + color and store in face property
|
||||
face.setProperty("FLT_COL",int(pack_face_index(curswatch,curint)))
|
||||
#Save baked color to face vertex colors
|
||||
for col in face.col:
|
||||
col.r = int(color[0] * curint)
|
||||
col.g = int(color[1] * curint)
|
||||
col.b = int(color[2] * curint)
|
||||
col.a = int(color[3] * curint)
|
||||
else:
|
||||
if Blender.Mesh.Mode() == Blender.Mesh.SelectModes['VERTEX']:
|
||||
if not 'FLT_VCOL' in actmesh.verts.properties:
|
||||
actmesh.verts.addPropertyLayer("FLT_VCOL",Blender.Mesh.PropertyTypes["INT"])
|
||||
for vert in actmesh.verts:
|
||||
vert.setProperty("FLT_VCOL",127)
|
||||
else:
|
||||
for vert in actmesh.verts:
|
||||
if vert.sel:
|
||||
vert.setProperty("FLT_VCOL",int(pack_face_index(curswatch,curint)))
|
||||
|
||||
if editmode:
|
||||
Blender.Window.EditMode(1)
|
||||
|
||||
Blender.Window.RedrawAll()
|
||||
|
||||
#grab color and intensity from active face
|
||||
elif evt == Draw.VKEY:
|
||||
if Blender.Window.EditMode():
|
||||
Blender.Window.EditMode(0)
|
||||
editmode = 1
|
||||
state = update_state()
|
||||
|
||||
actmesh = state["activeMesh"]
|
||||
activeFace = state["activeFace"]
|
||||
|
||||
|
||||
if activeFace:
|
||||
if not "FLT_COL" in actmesh.faces.properties:
|
||||
actmesh.faces.addPropertyLayer("FLT_COL",Blender.Mesh.PropertyTypes["INT"])
|
||||
for face in actmesh.faces:
|
||||
face.setProperty("FLT_COL",127) #default
|
||||
try:
|
||||
actmesh.activeColorLayer = "FLT_Fcol"
|
||||
except:
|
||||
actmesh.addColorLayer("FLT_Fcol")
|
||||
actmesh.activeColorLayer = "FLT_Fcol"
|
||||
tcol = activeFace.getProperty("FLT_COL")
|
||||
(index,intensity) = unpack_face_index(tcol)
|
||||
curswatch = index
|
||||
curint = intensity
|
||||
|
||||
if editmode:
|
||||
Blender.Window.EditMode(1)
|
||||
|
||||
Blender.Window.RedrawAll()
|
||||
|
||||
elif evt == Draw.ESCKEY:
|
||||
Draw.Exit()
|
||||
|
||||
if editmode:
|
||||
Blender.Window.EditMode(1)
|
||||
|
||||
def update_all():
|
||||
global colors
|
||||
state = update_state()
|
||||
#update the baked FLT colors for all meshes.
|
||||
for object in state["activeScene"].objects:
|
||||
if object.type == "Mesh":
|
||||
mesh = object.getData(mesh=True)
|
||||
if 'FLT_COL' in mesh.faces.properties:
|
||||
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]))
|
||||
#update the vertex colors for this face
|
||||
for col in face.col:
|
||||
col.r = int(color[0] * intensity)
|
||||
col.g = int(color[1] * intensity)
|
||||
col.b = int(color[2] * intensity)
|
||||
col.a = 255
|
||||
|
||||
|
||||
def but_event(evt):
|
||||
global palette_size
|
||||
global palette_x
|
||||
global palette_y
|
||||
global colors
|
||||
global curint
|
||||
global curswatch
|
||||
global picker
|
||||
state = update_state()
|
||||
|
||||
if evt == 1:
|
||||
if picker.val:
|
||||
rval = (int(picker.val[0]*255),int(picker.val[1]*255),int(picker.val[2]*255),255)
|
||||
rval = struct.pack('>BBBB',rval[0],rval[1],rval[2],rval[3])
|
||||
rval = struct.unpack('>i',rval)
|
||||
colors[curswatch] = rval[0]
|
||||
#go cd through all meshes and update their FLT colors
|
||||
update_all()
|
||||
|
||||
Draw.Redraw(1)
|
||||
def init_pal():
|
||||
global palette_size
|
||||
global palette_x
|
||||
global palette_y
|
||||
global colors
|
||||
global curint
|
||||
global curswatch
|
||||
|
||||
state = update_state()
|
||||
|
||||
if not state["activeScene"].properties.has_key('FLT'):
|
||||
state["activeScene"].properties['FLT'] = dict()
|
||||
|
||||
try:
|
||||
colors = state["activeScene"].properties['FLT']['Color Palette']
|
||||
except:
|
||||
state["activeScene"].properties['FLT']['Color Palette'] = defaultp.pal
|
||||
colors = state["activeScene"].properties['FLT']['Color Palette']
|
||||
|
||||
def draw_palette():
|
||||
global palette_size
|
||||
global palette_x
|
||||
global palette_y
|
||||
global colors
|
||||
global curint
|
||||
global curswatch
|
||||
global picker
|
||||
|
||||
state = update_state()
|
||||
init_pal()
|
||||
|
||||
ssize = palette_size
|
||||
xpos = palette_x
|
||||
cid = 0
|
||||
|
||||
highlight = [(palette_x,palette_y),(palette_x+palette_size,palette_y),(palette_x+palette_size,palette_y+palette_size),(palette_x,palette_y+palette_size)]
|
||||
for x in xrange(32):
|
||||
ypos = palette_y
|
||||
for y in xrange(32):
|
||||
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)
|
||||
glVertex2i(xpos+ssize,ypos)
|
||||
glVertex2i(xpos+ssize,ypos+ssize)
|
||||
glVertex2i(xpos,ypos+ssize)
|
||||
glEnd()
|
||||
|
||||
if curswatch == cid:
|
||||
highlight[0] = (xpos,ypos)
|
||||
highlight[1] = (xpos+ssize,ypos)
|
||||
highlight[2] = (xpos+ssize,ypos+ssize)
|
||||
highlight[3] = (xpos,ypos+ssize)
|
||||
|
||||
glColor3f(0.0,0.0,0.0)
|
||||
glBegin(GL_LINE_LOOP)
|
||||
glVertex2i(xpos,ypos)
|
||||
glVertex2i(xpos+ssize,ypos)
|
||||
glVertex2i(xpos+ssize,ypos+ssize)
|
||||
glVertex2i(xpos,ypos+ssize)
|
||||
glVertex2i(xpos,ypos)
|
||||
glEnd()
|
||||
|
||||
|
||||
cid = cid + 1
|
||||
ypos = ypos + ssize
|
||||
|
||||
xpos = xpos + ssize
|
||||
|
||||
#draw intensity gradient
|
||||
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
|
||||
strippad = palette_size / 2.0
|
||||
|
||||
xpos = palette_x
|
||||
grady = (palette_y + (palette_size * 32.0)) + strippad
|
||||
for x in xrange(256):
|
||||
color[0] = color[0] - colsteps[0]
|
||||
color[1] = color[1] - colsteps[1]
|
||||
color[2] = color[2] - colsteps[2]
|
||||
|
||||
glColor3f(color[0], color[1] ,color[2])
|
||||
glBegin(GL_POLYGON)
|
||||
glVertex2f(xpos,grady)
|
||||
glVertex2f(xpos+stripwidth,grady)
|
||||
glVertex2f(xpos+stripwidth,grady+palette_size)
|
||||
glVertex2f(xpos,grady+palette_size)
|
||||
glEnd()
|
||||
xpos = xpos + stripwidth
|
||||
|
||||
#draw intensity slider bar
|
||||
#xposition == 512 - ((curint) * 512)
|
||||
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(xpos-6,grady+7)
|
||||
glEnd()
|
||||
|
||||
#draw color picker
|
||||
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)
|
||||
|
||||
#draw highlight swatch
|
||||
glColor3f(1.0,1.0,1.0)
|
||||
glBegin(GL_LINE_LOOP)
|
||||
glVertex2i(highlight[0][0],highlight[0][1])
|
||||
glVertex2i(highlight[1][0],highlight[1][1])
|
||||
glVertex2i(highlight[2][0],highlight[2][1])
|
||||
glVertex2i(highlight[3][0],highlight[3][1])
|
||||
glVertex2i(highlight[0][0],highlight[0][1])
|
||||
glEnd()
|
||||
|
||||
def gui():
|
||||
glClearColor(0.5,0.5,0.5,1.0)
|
||||
glClear(GL_COLOR_BUFFER_BIT)
|
||||
draw_palette()
|
||||
|
||||
|
||||
init_pal()
|
||||
Draw.Register(gui,event,but_event)
|
||||
|
||||
619
release/scripts/flt_properties.py
Normal file
619
release/scripts/flt_properties.py
Normal file
@@ -0,0 +1,619 @@
|
||||
#!BPY
|
||||
# flt_properties.py. For setting default OpenFLight ID property types
|
||||
# Copyright (C) 2007 Blender Foundation
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
__bpydoc__ ="""\
|
||||
Utility functions and data defintions used by OpenFlight I/O and tool scripts. OpenFlight is a
|
||||
registered trademark of MultiGen-Paradigm, Inc.
|
||||
"""
|
||||
|
||||
|
||||
import struct
|
||||
|
||||
bitsLSB = [2147483648]
|
||||
for i in xrange(31):
|
||||
bitsLSB.append(bitsLSB[-1]/2)
|
||||
bitsRSB = bitsLSB[:]
|
||||
bitsRSB.reverse()
|
||||
|
||||
def pack_color(col):
|
||||
return struct.pack('>B',col[3]) + struct.pack('>B',col[2]) + struct.pack('>B',col[1]) + struct.pack('>B',col[0])
|
||||
|
||||
def unpack_color(col):
|
||||
string = struct.pack('>I', col)
|
||||
r = struct.unpack('>B',string[3:4])
|
||||
g = struct.unpack('>B',string[2:3])
|
||||
b = struct.unpack('>B',string[1:2])
|
||||
a = struct.unpack('>B',string[0:1])
|
||||
return [r,g,b,a]
|
||||
|
||||
def reverse_bits(len,num):
|
||||
bitbucket = list()
|
||||
rval = 0
|
||||
|
||||
for i in xrange(len):
|
||||
if num & bitsRSB[i]:
|
||||
bitbucket.append(1)
|
||||
else:
|
||||
bitbucket.append(0)
|
||||
|
||||
bitbucket.reverse()
|
||||
|
||||
for i, bit in enumerate(bitbucket):
|
||||
if bit:
|
||||
rval |= bitsLSB[i]
|
||||
|
||||
return rval
|
||||
|
||||
|
||||
opcode_name = { 0: 'db',
|
||||
1: 'head',
|
||||
2: 'grp',
|
||||
4: 'obj',
|
||||
5: 'face',
|
||||
10: 'push',
|
||||
11: 'pop',
|
||||
14: 'dof',
|
||||
19: 'push sub',
|
||||
20: 'pop sub',
|
||||
21: 'push ext',
|
||||
22: 'pop ext',
|
||||
23: 'cont',
|
||||
31: 'comment',
|
||||
32: 'color pal',
|
||||
33: 'long id',
|
||||
49: 'matrix',
|
||||
50: 'vector',
|
||||
52: 'multi-tex',
|
||||
53: 'uv lst',
|
||||
55: 'bsp',
|
||||
60: 'rep',
|
||||
61: 'inst ref',
|
||||
62: 'inst def',
|
||||
63: 'ext ref',
|
||||
64: 'tex pal',
|
||||
67: 'vert pal',
|
||||
68: 'vert w col',
|
||||
69: 'vert w col & norm',
|
||||
70: 'vert w col, norm & uv',
|
||||
71: 'vert w col & uv',
|
||||
72: 'vert lst',
|
||||
73: 'lod',
|
||||
74: 'bndin box',
|
||||
76: 'rot edge',
|
||||
78: 'trans',
|
||||
79: 'scl',
|
||||
80: 'rot pnt',
|
||||
81: 'rot and/or scale pnt',
|
||||
82: 'put',
|
||||
83: 'eyepoint & trackplane pal',
|
||||
84: 'mesh',
|
||||
85: 'local vert pool',
|
||||
86: 'mesh prim',
|
||||
87: 'road seg',
|
||||
88: 'road zone',
|
||||
89: 'morph vert lst',
|
||||
90: 'link pal',
|
||||
91: 'snd',
|
||||
92: 'rd path',
|
||||
93: 'snd pal',
|
||||
94: 'gen matrix',
|
||||
95: 'txt',
|
||||
96: 'sw',
|
||||
97: 'line styl pal',
|
||||
98: 'clip reg',
|
||||
100: 'ext',
|
||||
101: 'light src',
|
||||
102: 'light src pal',
|
||||
103: 'reserved',
|
||||
104: 'reserved',
|
||||
105: 'bndin sph',
|
||||
106: 'bndin cyl',
|
||||
107: 'bndin hull',
|
||||
108: 'bndin vol cntr',
|
||||
109: 'bndin vol orient',
|
||||
110: 'rsrvd',
|
||||
111: 'light pnt',
|
||||
112: 'tex map pal',
|
||||
113: 'mat pal',
|
||||
114: 'name tab',
|
||||
115: 'cat',
|
||||
116: 'cat dat',
|
||||
117: 'rsrvd',
|
||||
118: 'rsrvd',
|
||||
119: 'bounding hist',
|
||||
120: 'rsrvd',
|
||||
121: 'rsrvd',
|
||||
122: 'push attrib',
|
||||
123: 'pop attrib',
|
||||
124: 'rsrvd',
|
||||
125: 'rsrvd',
|
||||
126: 'curv',
|
||||
127: 'road const',
|
||||
128: 'light pnt appear pal',
|
||||
129: 'light pnt anim pal',
|
||||
130: 'indexed lp',
|
||||
131: 'lp sys',
|
||||
132: 'indx str',
|
||||
133: 'shdr pal'}
|
||||
|
||||
|
||||
typecodes = ['c','C','s','S','i','I','f','d','t']
|
||||
|
||||
FLT_GRP = 2
|
||||
FLT_OBJ = 4
|
||||
FLT_LOD = 73
|
||||
FLT_XRF = 63
|
||||
FLT_DOF = 14
|
||||
FLT_ILP = 111
|
||||
FLT_DB = 1
|
||||
FLT_FCE = 5
|
||||
|
||||
#not actual opcodes
|
||||
FLT_NUL = 0
|
||||
FLT_EXP = -1
|
||||
|
||||
#valid childtypes for each FLT node type
|
||||
FLT_CHILDTYPES = {
|
||||
FLT_GRP : [111,2,73,4,14,63],
|
||||
FLT_OBJ : [111],
|
||||
FLT_LOD : [111,2,73,4,14,63],
|
||||
FLT_XRF : [],
|
||||
FLT_DOF : [111,2,73,4,14,63],
|
||||
FLT_ILP : []
|
||||
}
|
||||
|
||||
#List of nodes that can have faces as children
|
||||
FLT_FACETYPES = [
|
||||
FLT_GRP,
|
||||
FLT_OBJ,
|
||||
FLT_LOD,
|
||||
FLT_DOF
|
||||
]
|
||||
|
||||
def write_prop(fw,type,value,length):
|
||||
if type == 'c':
|
||||
fw.write_char(value)
|
||||
elif type == 'C':
|
||||
fw.write_uchar(value)
|
||||
elif type == 's':
|
||||
fw.write_short(value)
|
||||
elif type == 'S':
|
||||
fw.write_ushort(value)
|
||||
elif type == 'i':
|
||||
fw.write_int(value)
|
||||
elif type == 'I':
|
||||
fw.write_uint(value)
|
||||
elif type == 'd':
|
||||
fw.write_double(value)
|
||||
elif type == 'f':
|
||||
fw.write_float(value)
|
||||
elif type == 't':
|
||||
fw.write_string(value,length)
|
||||
|
||||
def read_prop(fw,type,length):
|
||||
rval = None
|
||||
if type == 'c':
|
||||
rval = fw.read_char()
|
||||
elif type == 'C':
|
||||
rval = fw.read_uchar()
|
||||
elif type == 's':
|
||||
rval = fw.read_short()
|
||||
elif type == 'S':
|
||||
rval = fw.read_ushort()
|
||||
elif type == 'i':
|
||||
rval = fw.read_int()
|
||||
elif type == 'I':
|
||||
rval = fw.read_uint()
|
||||
elif type == 'd':
|
||||
rval = fw.read_double()
|
||||
elif type == 'f':
|
||||
rval = fw.read_float()
|
||||
elif type == 't':
|
||||
rval = fw.read_string(length)
|
||||
return rval
|
||||
|
||||
FLTGroup = {
|
||||
'3t8!id' : 'G',
|
||||
'4s!priority' : 0,
|
||||
'5s!reserved1' : 0,
|
||||
'6i!flags' : 0,
|
||||
'7s!special1' : 0,
|
||||
'8s!special2' : 0,
|
||||
'9s!significance' : 0,
|
||||
'10c!layer code' : 0,
|
||||
'11c!reserved2' : 0,
|
||||
'12i!reserved3' : 0,
|
||||
'13i!loop count' : 0,
|
||||
'14f!loop duration' : 0,
|
||||
'15f!last frame duration' : 0
|
||||
}
|
||||
FLTGroupDisplay = [5,11,12]
|
||||
|
||||
FLTObject = {
|
||||
'3t8!id' : 'O',
|
||||
'4I!flags' : 0,
|
||||
'5s!priority' : 0,
|
||||
'6S!transp' : 0,
|
||||
'7s!SFX1' : 0,
|
||||
'8s!SFX2' : 0,
|
||||
'9s!significance' : 0,
|
||||
'10s!reserved' : 0
|
||||
}
|
||||
FLTObjectDisplay = [10]
|
||||
|
||||
FLTLOD = {
|
||||
'3t8!id' : 'L',
|
||||
'4i!reserved' : 0,
|
||||
'5d!switch in' : 0,
|
||||
'6d!switch out' : 0,
|
||||
'7s!sfx ID1' : 0,
|
||||
'8s!sfx ID2' : 0,
|
||||
'9I!flags' : 0,
|
||||
'10d!X co' : 0,
|
||||
'11d!Y co' : 0,
|
||||
'12d!Z co' : 0,
|
||||
'13d!Transition' : 0,
|
||||
'14d!Sig Size' : 0
|
||||
}
|
||||
FLTLODDisplay = [4]
|
||||
|
||||
FLTInlineLP = {
|
||||
'3t8!id' : 'Lp',
|
||||
'4s!smc' : 0,
|
||||
'5s!fid' : 0,
|
||||
'6C!back color: a' : 255,
|
||||
'7C!back color: b' : 255,
|
||||
'8C!back color: g' : 255,
|
||||
'9C!back color: r' : 255,
|
||||
'10i!display mode' : 255,
|
||||
'11f!intensity' : 1.0,
|
||||
'12f!back intensity' : 0.0,
|
||||
'13f!minimum defocus' : 0.0,
|
||||
'14f!maximum defocus' : 1.0,
|
||||
'15i!fading mode' : 0,
|
||||
'16i!fog punch mode' : 0,
|
||||
'17i!directional mode' : 1,
|
||||
'18i!range mode' : 0,
|
||||
'19f!min pixel size' : 1.0,
|
||||
'20f!max pixel size' : 1024,
|
||||
'21f!actual size' : 0.25,
|
||||
'22f!trans falloff pixel size' : 0.25,
|
||||
'23f!trans falloff exponent' : 1.0,
|
||||
'24f!trans falloff scalar' : 1.0,
|
||||
'25f!trans falloff clamp' : 1.0,
|
||||
'26f!fog scalar' : 0.25,
|
||||
'27f!fog intensity' : 1.0,
|
||||
'28f!size threshold' : 0.1,
|
||||
'29i!directionality' : 0,
|
||||
'30f!horizontal lobe angle' : 180.0,
|
||||
'31f!vertical lobe angle' : 180.0,
|
||||
'32f!lobe roll angle' : 0.0,
|
||||
'33f!dir falloff exponent' : 1.0,
|
||||
'34f!dir ambient intensity' : 0.1,
|
||||
'35f!anim period' : 0,
|
||||
'36f!anim phase' : 0,
|
||||
'37f!anim enabled' : 0,
|
||||
'38f!significance' : 0.0,
|
||||
'39i!draw order' : 0,
|
||||
'40I!flags' : 813875616,
|
||||
'41f!roti' : 0,
|
||||
'42f!rotj' : 0,
|
||||
'43f!rotk' : 0
|
||||
}
|
||||
|
||||
FLTInlineLPDisplay = [35,36,37,41,42,43]
|
||||
|
||||
FLTXRef = {
|
||||
'3t200!filename' : '', #we dont actually use this value on export
|
||||
'4i!reserved' : 0,
|
||||
'5I!flag' : -478150656,
|
||||
'6s!bbox' : 0,
|
||||
'7s!reserved' : 0
|
||||
}
|
||||
|
||||
FLTXRefDisplay = [4,7,3]
|
||||
|
||||
FLTDOF = {
|
||||
'3t8!id' : 'D',
|
||||
'4i!reserved' : 0,
|
||||
'5d!ORIGX' : 0.0,
|
||||
'6d!ORIGY' : 0.0,
|
||||
'7d!ORIGZ' : 0.0,
|
||||
'8d!XAXIS-X' : 10.0,
|
||||
'9d!XAXIS-Y' : 0.0,
|
||||
'10d!XAXIS-Z' : 0.0,
|
||||
'11d!XYPLANE-X' : 0.0,
|
||||
'12d!XYPLANE-Y' : 10.0,
|
||||
'13d!XZPLANE-Z' : 0.0,
|
||||
'14d!ZMIN' : 0.0,
|
||||
'15d!ZMAX' : 0.0,
|
||||
'16d!ZCUR' : 0.0,
|
||||
'17d!ZSTEP' : 0.0,
|
||||
'18d!YMIN' : 0.0,
|
||||
'19d!YMAX' : 0.0,
|
||||
'20d!YCUR' : 0.0,
|
||||
'21d!YSTEP' : 0.0,
|
||||
'22d!XMIN' : 0.0,
|
||||
'23d!XMAX' : 0.0,
|
||||
'24d!XCUR' : 0.0,
|
||||
'25d!XSTEP' : 0.0,
|
||||
'26d!PITCH-MIN' : 0.0,
|
||||
'27d!PITCH-MAX' : 0.0,
|
||||
'28d!PITCH-CUR' : 0.0,
|
||||
'29d!PITCH-STEP' : 0.0,
|
||||
'30d!ROLL-MIN' : 0.0,
|
||||
'31d!ROLL-MAX' : 0.0,
|
||||
'32d!ROLL-CUR' : 0.0,
|
||||
'33d!ROLL-STEP' : 0.0,
|
||||
'34d!YAW-MIN' : 0.0,
|
||||
'35d!YAW-MAX' : 0.0,
|
||||
'36d!YAW-CUR' : 0.0,
|
||||
'37d!YAW-STEP' : 0.0,
|
||||
'38d!ZSIZE-MIN' : 0.0,
|
||||
'39d!ZSIZE-MAX' : 0.0,
|
||||
'40d!ZSIZE-CUR' : 1.0,
|
||||
'41d!ZSIZE-STEP' : 0.0,
|
||||
'42d!YSIZE-MIN' : 0.0,
|
||||
'43d!YSIZE-MAX' : 0.0,
|
||||
'44d!YSIZE-CUR' : 1.0,
|
||||
'45d!YSIZE-STEP' : 0.0,
|
||||
'46d!XSIZE-MIN' : 0.0,
|
||||
'47d!XSIZE-MAX' : 0.0,
|
||||
'48d!XSIZE-CUR' : 1.0,
|
||||
'49d!XSIZE-STEP' : 0.0,
|
||||
'50I!FLAG' : 1897582,
|
||||
'51i!reserved2' : 0
|
||||
}
|
||||
|
||||
FLTDOFDisplay = [4]
|
||||
|
||||
FLTImage = {
|
||||
'3i!RealU Direction' : 0,
|
||||
'4i!RealV Direction' : 0,
|
||||
'5i!UpX' : 0,
|
||||
'6i!UpY' : 0,
|
||||
'7i!File Format' : 0,
|
||||
'8i!Min Filter' : 1,
|
||||
'9i!Mag Filter' : 1,
|
||||
'10i!Wrap' : 0,
|
||||
'11i!WrapU' : 0,
|
||||
'12i!WrapV' : 0,
|
||||
'13i!Modified' : 0,
|
||||
'14i!PivotX' : 0,
|
||||
'15i!PivotY' : 0,
|
||||
'16i!Enviorment' : 0,
|
||||
'17i!WhiteAlpha' : 0,
|
||||
'18i!reserved1' : 0,
|
||||
'19i!reserved2' : 0,
|
||||
'20i!reserved3' : 0,
|
||||
'21i!reserved4' : 0,
|
||||
'22i!reserved5' : 0,
|
||||
'23i!reserved6' : 0,
|
||||
'24i!reserved7' : 0,
|
||||
'25i!reserved8' : 0,
|
||||
'26i!reserved9' : 0,
|
||||
'27d!RealU Direction' : 0,
|
||||
'28d!RealV Direction' : 0,
|
||||
'29i!Origin' : 0,
|
||||
'30i!Kernel no.' : 0,
|
||||
'31i!Internal Format' : 0,
|
||||
'32i!External Format' : 0,
|
||||
'33i!MipMap Filter?' : 0,
|
||||
'34f!MMF1' : 0.0,
|
||||
'35f!MMF2' : 0.0,
|
||||
'36f!MMF3' : 0.0,
|
||||
'37f!MMF4' : 0.0,
|
||||
'38f!MMF5' : 0.0,
|
||||
'39f!MMF6' : 0.0,
|
||||
'40f!MMF7' : 0.0,
|
||||
'41f!MMF8' : 0.0,
|
||||
'42i!Tex CPs?' : 0,
|
||||
'43f!LOD0 CP' : 0.0,
|
||||
'44f!Scale0 CP' : 0.0,
|
||||
'45f!LOD1 CP' : 0.0,
|
||||
'46f!Scale1 CP' : 0.0,
|
||||
'47f!LOD2 CP' : 0.0,
|
||||
'48f!Scale2 CP' : 0.0,
|
||||
'49f!LOD3 CP' : 0.0,
|
||||
'50f!Scale3 CP' : 0.0,
|
||||
'51f!LOD4 CP' : 0.0,
|
||||
'52f!Scale4 CP' : 0.0,
|
||||
'53f!LOD5 CP' : 0.0,
|
||||
'54f!Scale5 CP' : 0.0,
|
||||
'55f!LOD6 CP' : 0.0,
|
||||
'56f!Scale6 CP' : 0.0,
|
||||
'57f!LOD7 CP' : 0.0,
|
||||
'58f!Scale7 CP' : 0.0,
|
||||
'59f!Control Clamp' : 0.0,
|
||||
'60i!Mag Alpha Filter' : 0,
|
||||
'61i!Mag Color Filter' : 0,
|
||||
'62f!reserved10' : 0,
|
||||
'63f!reserved11' : 0,
|
||||
'64f!reserved12' : 0,
|
||||
'65f!reserved13' : 0,
|
||||
'66f!reserved14' : 0,
|
||||
'67f!reserved15' : 0,
|
||||
'68f!reserved16' : 0,
|
||||
'69f!reserved17' : 0,
|
||||
'70f!reserved18' : 0,
|
||||
'71d!Lambert Central' : 0.0,
|
||||
'72d!Lambert Upper' : 0.0,
|
||||
'73d!Lambert Lower' : 0.0,
|
||||
'74d!reserved19' : 0,
|
||||
'75f!reserved20' : 0,
|
||||
'76f!reserved21' : 0,
|
||||
'77f!reserved22' : 0,
|
||||
'78f!reserved23' : 0,
|
||||
'79f!reserved24' : 0,
|
||||
'80i!Tex Detail?' : 0,
|
||||
'81i!Tex J' : 0,
|
||||
'82i!Tex K' : 0,
|
||||
'83i!Tex M' : 0,
|
||||
'84i!Tex N' : 0,
|
||||
'85i!Tex Scramble' : 0,
|
||||
'86i!Tex Tile?' : 0,
|
||||
'87f!Tex Tile LLU' : 0.0,
|
||||
'88f!Tex Tile LLV' : 0.0,
|
||||
'89f!Tex Tile URU' : 0.0,
|
||||
'90f!Tex Tile URV' : 0.0,
|
||||
'91i!Projection' : 0,
|
||||
'92i!Earth Model' : 0,
|
||||
'93i!reserved25' : 0,
|
||||
'94i!UTM Zone' : 0,
|
||||
'95i!Image Origin' : 0,
|
||||
'96i!GPU' : 0,
|
||||
'97i!reserved26' : 0,
|
||||
'98i!reserved27' : 0,
|
||||
'99i!GPU Hemi' : 0,
|
||||
'100i!reserved41' : 0,
|
||||
'101i!reserved42' : 0,
|
||||
'102i!reserved43' : 0,
|
||||
'103i!Cubemap' : 0,
|
||||
'104t588!reserved44' : '',
|
||||
'105t512!Comments' : '',
|
||||
'106i!reserved28' : 0,
|
||||
'107i!reserved29' : 0,
|
||||
'108i!reserved30' : 0,
|
||||
'109i!reserved31' : 0,
|
||||
'110i!reserved32' : 0,
|
||||
'111i!reserved33' : 0,
|
||||
'112i!reserved34' : 0,
|
||||
'113i!reserved35' : 0,
|
||||
'114i!reserved36' : 0,
|
||||
'115i!reserved37' : 0,
|
||||
'116i!reserved38' : 0,
|
||||
'117i!reserved39' : 0,
|
||||
'118i!reserved40' : 0,
|
||||
'119i!reserved45' : 0,
|
||||
'120i!Format Version' : 0,
|
||||
'121i!GPU num' : 0,
|
||||
}
|
||||
|
||||
FLTImageDisplay = [18,19,29,21,22,23,24,25,26,62,63,64,65,66,67,68,69,70,74,75,76,77,78,79,93,97,98,102,114]
|
||||
|
||||
FLTHeader = {
|
||||
'3t8!id' : 'db',
|
||||
'4i!version' : 1620,
|
||||
'5i!editversion' : 0,
|
||||
'6t32!date' : 0,
|
||||
'7s!NGID' : 0,
|
||||
'8s!NLID' : 0,
|
||||
'9s!NOID' : 0,
|
||||
'10s!NFID' : 0,
|
||||
'11s!UMULT' : 1,
|
||||
'12c!units' : 0,
|
||||
'13c!set white' : 0,
|
||||
'14I!flags' : 0x80000000,
|
||||
'15i!reserved1' : 0,
|
||||
'16i!reserved2' : 0,
|
||||
'17i!reserved3' : 0,
|
||||
'18i!reserved4' : 0,
|
||||
'19i!reserved5' : 0,
|
||||
'20i!reserved6' : 0,
|
||||
'21i!projection type' : 0,
|
||||
'22i!reserved7' : 0,
|
||||
'23i!reserved8' : 0,
|
||||
'24i!reserved9' : 0,
|
||||
'25i!reserved10' : 0,
|
||||
'26i!reserved11' : 0,
|
||||
'27i!reserved12' : 0,
|
||||
'28i!reserved13' : 0,
|
||||
'29s!NDID' : 0,
|
||||
'30s!vstore' : 1,
|
||||
'31i!origin' : 0,
|
||||
'32d!sw x' : 0,
|
||||
'33d!sw y' : 0,
|
||||
'34d!dx' : 0,
|
||||
'35d!dy' : 0,
|
||||
'36s!NSID' : 0,
|
||||
'37s!NPID' : 0,
|
||||
'38i!reserved14' : 0,
|
||||
'39i!reserved15' : 0,
|
||||
'40s!NCID' : 0,
|
||||
'41s!NTID' : 0,
|
||||
'42s!NBID' : 0,
|
||||
'43s!NWID' : 0,
|
||||
'44i!reserved14' : 0,
|
||||
'45d!sw lat' : 0,
|
||||
'46d!sw lon' : 0,
|
||||
'47d!ne lat' : 0,
|
||||
'48d!ne lon' : 0,
|
||||
'49d!origin lat' : 0,
|
||||
'50d!origin lon' : 0,
|
||||
'51d!lambert lat1' : 0,
|
||||
'52d!lambert lat2' : 0,
|
||||
'53s!NLSID' : 0,
|
||||
'54s!NLPID' : 0,
|
||||
'55s!NRID' : 0,
|
||||
'56s!NCATID' : 0,
|
||||
'57s!reserved15' : 0,
|
||||
'58s!reserved16' : 0,
|
||||
'59s!reserved17' : 0,
|
||||
'60s!reserved18' : 0,
|
||||
'61i!ellipsoid model' : 1,
|
||||
'62s!NAID' : 0,
|
||||
'63s!NCVID' : 0,
|
||||
'64s!utm zone' : 0,
|
||||
'65t6!reserved19' : 0,
|
||||
'66d!dz' : 0,
|
||||
'67d!radius' : 0,
|
||||
'68S!NMID' : 0,
|
||||
'69S!NLPSID' : 0,
|
||||
'70i!reserved20' : 0,
|
||||
'71d!major axis' : 0,
|
||||
'72d!minor axis' : 0,
|
||||
}
|
||||
|
||||
FLT_Records = {
|
||||
2 : FLTGroup,
|
||||
4 : FLTObject,
|
||||
73 : FLTLOD,
|
||||
63 : FLTXRef,
|
||||
14 : FLTDOF,
|
||||
1 : FLTHeader,
|
||||
111 : FLTInlineLP,
|
||||
'Image' : FLTImage
|
||||
}
|
||||
|
||||
def process_recordDefs():
|
||||
records = dict()
|
||||
for record in FLT_Records:
|
||||
props = dict()
|
||||
for prop in FLT_Records[record]:
|
||||
position = ''
|
||||
slice = 0
|
||||
(format,name) = prop.split('!')
|
||||
for i in format:
|
||||
if i not in typecodes:
|
||||
position = position + i
|
||||
slice = slice + 1
|
||||
else:
|
||||
break
|
||||
type = format[slice:]
|
||||
length = type[1:]
|
||||
if len(length) == 0:
|
||||
length = 1
|
||||
else:
|
||||
type = type[0]
|
||||
length = int(length)
|
||||
|
||||
props[int(position)] = (type,length,prop)
|
||||
records[record] = props
|
||||
return records
|
||||
|
||||
|
||||
594
release/scripts/flt_toolbar.py
Normal file
594
release/scripts/flt_toolbar.py
Normal file
@@ -0,0 +1,594 @@
|
||||
#!BPY
|
||||
|
||||
"""
|
||||
Name: 'FLT Toolbar'
|
||||
Blender: 240
|
||||
Group: 'Misc'
|
||||
Tooltip: 'Tools for working with FLT databases'
|
||||
"""
|
||||
|
||||
__author__ = "Geoffrey Bantle"
|
||||
__version__ = "1.0 11/21/07"
|
||||
__email__ = ('scripts', 'Author, ')
|
||||
__url__ = ('blender', 'elysiun')
|
||||
|
||||
__bpydoc__ ="""\
|
||||
This script provides tools for working with OpenFlight databases in Blender. OpenFlight is a
|
||||
registered trademark of MultiGen-Paradigm, Inc.
|
||||
|
||||
Feature overview and more availible at:
|
||||
http://wiki.blender.org/index.php/Scripts/Manual/FLTools
|
||||
"""
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
# flt_palettemanager.py version 0.1 2005/04/08
|
||||
# --------------------------------------------------------------------------
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# Copyright (C) 2007: Blender Foundation
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
import Blender.Draw as Draw
|
||||
from Blender.BGL import *
|
||||
import Blender
|
||||
import flt_properties
|
||||
reload(flt_properties)
|
||||
from flt_properties import *
|
||||
|
||||
xrefprefix = ""
|
||||
xrefstack = list()
|
||||
vofsstack = list()
|
||||
vquatstack = list()
|
||||
prop_w = 256
|
||||
prop_h = 256
|
||||
|
||||
|
||||
#event codes
|
||||
evcode = {
|
||||
"XREF_MAKE" : 100,
|
||||
"XREF_EDIT" : 101,
|
||||
"XREF_FILE" : 102,
|
||||
"XREF_PICK" : 103,
|
||||
"XREF_SELECT" : 104,
|
||||
"XREF_POP" : 105,
|
||||
"XREF_PREFIX" : 106,
|
||||
"FACE_NAME" : 200,
|
||||
"FACE_MAKESUB" : 201,
|
||||
"FACE_KILLSUB" : 202,
|
||||
"FACE_SELSUB" : 203,
|
||||
"SCENE_UPDATE" : 303,
|
||||
"IDPROP_COPY" : 501,
|
||||
"IDPROP_KILL" : 502,
|
||||
"CLIGHT_MAKE" : 700
|
||||
}
|
||||
|
||||
XREF_PREFIX = None
|
||||
XREF_MAKE = None
|
||||
XREF_EDIT = None
|
||||
XREF_SELECT = None
|
||||
XREF_POP = None
|
||||
FACE_MAKESUB = None
|
||||
FACE_SELSUB = None
|
||||
FACE_KILLSUB = None
|
||||
IDPROP_KILL = None
|
||||
IDPROP_COPY = None
|
||||
SCENE_UPDATE = None
|
||||
CLIGHT_MAKE = None
|
||||
|
||||
def update_state():
|
||||
state = dict()
|
||||
state["activeScene"] = Blender.Scene.getCurrent()
|
||||
state["activeObject"] = state["activeScene"].getActiveObject()
|
||||
if state["activeObject"] and not state["activeObject"].sel:
|
||||
state["activeObject"] = None
|
||||
state["activeMesh"] = None
|
||||
if state["activeObject"] and state["activeObject"].type == 'Mesh':
|
||||
state["activeMesh"] = state["activeObject"].getData(mesh=True)
|
||||
|
||||
state["activeFace"] = None
|
||||
if state["activeMesh"]:
|
||||
if state["activeMesh"].faceUV and state["activeMesh"].activeFace != None:
|
||||
state["activeFace"] = state["activeMesh"].faces[state["activeMesh"].activeFace]
|
||||
|
||||
#update editmode
|
||||
state["editmode"] = Blender.Window.EditMode()
|
||||
|
||||
return state
|
||||
def pack_face_index(index, intensity):
|
||||
return ((127*intensity)+(128*index))
|
||||
def unpack_face_index(face_index):
|
||||
index = face_index / 128
|
||||
intensity = float(face_index - 128.0 * index) / 127.0
|
||||
return(index,intensity)
|
||||
|
||||
def idprops_append(object, typecode, props):
|
||||
object.properties["FLT"] = dict()
|
||||
object.properties["FLT"]['type'] = typecode
|
||||
for prop in props:
|
||||
object.properties["FLT"][prop] = props[prop]
|
||||
object.properties["FLT"]['3t8!id'] = object.name
|
||||
|
||||
def idprops_kill(object):
|
||||
state = update_state()
|
||||
if object and object.properties.has_key('FLT'):
|
||||
object.properties.pop('FLT')
|
||||
|
||||
def idprops_copy(source):
|
||||
state = update_state()
|
||||
if source.properties.has_key('FLT'):
|
||||
for object in state["activeScene"].objects:
|
||||
if object.sel and object != source and (state["activeScene"].Layers & object.Layers):
|
||||
idprops_kill(object)
|
||||
object.properties['FLT'] = dict()
|
||||
for key in source.properties['FLT']:
|
||||
object.properties['FLT'][key] = source.properties['FLT'][key]
|
||||
|
||||
def update_all():
|
||||
state = update_state()
|
||||
#update the baked FLT colors for all meshes.
|
||||
for object in state["activeScene"].objects:
|
||||
if object.type == "Mesh":
|
||||
mesh = object.getData(mesh=True)
|
||||
if 'FLT_COL' in mesh.faces.properties:
|
||||
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',state["colors"][index]))
|
||||
#update the vertex colors for this face
|
||||
for col in face.col:
|
||||
col.r = int(color[0] * intensity)
|
||||
col.g = int(color[1] * intensity)
|
||||
col.b = int(color[2] * intensity)
|
||||
col.a = 255
|
||||
|
||||
|
||||
#Change this to find the deep parent
|
||||
def xref_create():
|
||||
global xrefprefix
|
||||
global xrefstack
|
||||
global vofsstack
|
||||
global vquatstack
|
||||
global prop_w
|
||||
global prop_h
|
||||
|
||||
state = update_state()
|
||||
|
||||
def findchildren(object):
|
||||
children = list()
|
||||
for candidate in state["activeScene"].objects:
|
||||
if candidate.parent == object:
|
||||
children.append(candidate)
|
||||
retlist = list(children)
|
||||
for child in children:
|
||||
retlist = retlist + findchildren(child)
|
||||
return retlist
|
||||
|
||||
actObject = state["activeObject"]
|
||||
if actObject and xrefprefix:
|
||||
scenenames = list()
|
||||
for scene in Blender.Scene.Get():
|
||||
scenenames.append(scene.name)
|
||||
|
||||
if xrefprefix in scenenames:
|
||||
#build a unique name for the xref...
|
||||
suffix = 1
|
||||
found = False
|
||||
while not found:
|
||||
candidate = xrefprefix + str(suffix)
|
||||
if not candidate in scenenames:
|
||||
xrefname = candidate
|
||||
found = True
|
||||
suffix+=1
|
||||
else:
|
||||
xrefname = xrefprefix
|
||||
#create our XRef node
|
||||
xnode = state["activeScene"].objects.new('Empty')
|
||||
xnode.name = 'X:' + xrefname
|
||||
xnode.properties['FLT'] = dict()
|
||||
for prop in FLTXRef:
|
||||
xnode.properties['FLT'][prop] = FLTXRef[prop]
|
||||
xnode.properties['FLT']['3t200!filename'] = xrefname + '.flt'
|
||||
xnode.properties['FLT']['type'] = 63
|
||||
xnode.enableDupGroup = True
|
||||
xnode.DupGroup = Blender.Group.New(xrefname) #this is dangerous... be careful!
|
||||
|
||||
#copy rot and loc of actObject
|
||||
xnode.setLocation(actObject.getLocation())
|
||||
xnode.setEuler(actObject.getEuler())
|
||||
|
||||
#build the new scene
|
||||
xrefscene = Blender.Scene.New(xrefname)
|
||||
xrefscene.properties['FLT'] = dict()
|
||||
xrefscene.properties['FLT']['Filename'] = xrefname
|
||||
xrefscene.properties['FLT']['Main'] = 0
|
||||
|
||||
#find the children of actObject so that we can add them to the group
|
||||
linkobjects = findchildren(actObject)
|
||||
linkobjects.append(actObject)
|
||||
for object in linkobjects:
|
||||
xrefscene.objects.link(object)
|
||||
state["activeScene"].objects.unlink(object)
|
||||
xnode.DupGroup.objects.link(object)
|
||||
#clear rotation of actObject and location
|
||||
actObject.setLocation(0.0,0.0,0.0)
|
||||
actObject.setEuler(0.0,0.0,0.0)
|
||||
|
||||
xrefscene.update(1)
|
||||
state["activeScene"].update(1)
|
||||
|
||||
def xref_edit():
|
||||
global xrefprefix
|
||||
global xrefstack
|
||||
global vofsstack
|
||||
global vquatstack
|
||||
global prop_w
|
||||
global prop_h
|
||||
|
||||
state = update_state()
|
||||
|
||||
actObject = state["activeObject"]
|
||||
|
||||
if actObject and actObject.type == 'Empty' and actObject.DupGroup:
|
||||
# if actObject.properties.has_key('FLT') and actObject.properties['FLT']['type'] == 63:
|
||||
for FLTscene in Blender.Scene.Get():
|
||||
if FLTscene.properties.has_key('FLT') and FLTscene.name == actObject.DupGroup.name:
|
||||
actObject.sel = 0
|
||||
xrefstack.append(state["activeScene"])
|
||||
vofsstack.append(Blender.Window.GetViewOffset())
|
||||
vquatstack.append(Blender.Window.GetViewQuat())
|
||||
FLTscene.makeCurrent()
|
||||
Blender.Window.SetViewOffset(0.0,0.0,0.0)
|
||||
|
||||
def xref_finish():
|
||||
global xrefprefix
|
||||
global xrefstack
|
||||
global vofsstack
|
||||
global vquatstack
|
||||
global prop_w
|
||||
global prop_h
|
||||
|
||||
state = update_state()
|
||||
if xrefstack:
|
||||
scene = xrefstack.pop()
|
||||
Blender.Window.SetViewQuat(vquatstack.pop())
|
||||
Blender.Window.SetViewOffset(vofsstack.pop())
|
||||
scene.makeCurrent()
|
||||
|
||||
|
||||
def sortSub(a,b):
|
||||
aindex = a.getProperty("FLT_ORIGINDEX")
|
||||
bindex = b.getProperty("FLT_ORIGINDEX")
|
||||
|
||||
if aindex > bindex:
|
||||
return 1
|
||||
elif aindex < bindex:
|
||||
return -1
|
||||
return 0
|
||||
|
||||
def subface_make():
|
||||
global xrefprefix
|
||||
global xrefstack
|
||||
global vofsstack
|
||||
global vquatstack
|
||||
global prop_w
|
||||
global prop_h
|
||||
|
||||
editmode = 0
|
||||
if Blender.Window.EditMode():
|
||||
Blender.Window.EditMode(0)
|
||||
editmode = 1
|
||||
|
||||
state = update_state()
|
||||
|
||||
actmesh = state["activeMesh"]
|
||||
activeFace = state["activeFace"]
|
||||
if actmesh:
|
||||
if not "FLT_ORIGINDEX" in actmesh.faces.properties:
|
||||
actmesh.faces.addPropertyLayer("FLT_ORIGINDEX",Blender.Mesh.PropertyTypes["INT"])
|
||||
for i, face in enumerate(actmesh.faces):
|
||||
face.setProperty("FLT_ORIGINDEX",i)
|
||||
if not "FLT_SFLEVEL" in actmesh.faces.properties:
|
||||
actmesh.faces.addPropertyLayer("FLT_SFLEVEL",Blender.Mesh.PropertyTypes["INT"])
|
||||
|
||||
#attach the subfaces to the active face. Note, this doesnt really work 100 percent properly yet, just enough for one level!
|
||||
if activeFace:
|
||||
#steps:
|
||||
#remove actface and selected faces from the facelist
|
||||
#quicksort facelist
|
||||
#append actface and subfaces to end of facelist.
|
||||
#generate new indices
|
||||
facelist = list()
|
||||
sublist = list()
|
||||
for face in actmesh.faces:
|
||||
facelist.append(face)
|
||||
for face in facelist:
|
||||
if face == activeFace:
|
||||
face.setProperty("FLT_SFLEVEL",0)
|
||||
sublist.insert(0,face)
|
||||
elif face.sel:
|
||||
face.setProperty("FLT_SFLEVEL",1)
|
||||
sublist.append(face)
|
||||
for face in sublist:
|
||||
facelist.remove(face)
|
||||
facelist.sort(sortSub)
|
||||
for face in sublist:
|
||||
facelist.append(face)
|
||||
for i, face in enumerate(facelist):
|
||||
face.setProperty("FLT_ORIGINDEX",i)
|
||||
else:
|
||||
pass
|
||||
|
||||
if editmode:
|
||||
Blender.Window.EditMode(1)
|
||||
|
||||
def subface_kill():
|
||||
global xrefprefix
|
||||
global xrefstack
|
||||
global vofsstack
|
||||
global vquatstack
|
||||
global prop_w
|
||||
global prop_h
|
||||
|
||||
editmode = 0
|
||||
if Blender.Window.EditMode():
|
||||
Blender.Window.EditMode(0)
|
||||
editmode = 1
|
||||
state = update_state()
|
||||
|
||||
actmesh = state["activeMesh"]
|
||||
if actmesh:
|
||||
if "FLT_ORIGINDEX" in actmesh.faces.properties and "FLT_SFLEVEL" in actmesh.faces.properties:
|
||||
for i,face in enumerate(actmesh.faces):
|
||||
face.setProperty("FLT_ORIGINDEX",i)
|
||||
face.setProperty("FLT_SFLEVEL",0)
|
||||
if editmode:
|
||||
Blender.Window.EditMode(1)
|
||||
|
||||
def subface_select():
|
||||
global xrefprefix
|
||||
global xrefstack
|
||||
global vofsstack
|
||||
global vquatstack
|
||||
global prop_w
|
||||
global prop_h
|
||||
|
||||
editmode = 0
|
||||
if Blender.Window.EditMode():
|
||||
Blender.Window.EditMode(0)
|
||||
editmode = 1
|
||||
state = update_state()
|
||||
|
||||
actmesh = state["activeMesh"]
|
||||
activeFace = state["activeFace"]
|
||||
if actmesh and activeFace:
|
||||
if "FLT_ORIGINDEX" in actmesh.faces.properties and "FLT_SFLEVEL" in actmesh.faces.properties:
|
||||
facelist = list()
|
||||
actIndex = None
|
||||
sublevel = None
|
||||
for face in actmesh.faces:
|
||||
facelist.append(face)
|
||||
facelist.sort(sortSub)
|
||||
for i, face in enumerate(facelist):
|
||||
if face == activeFace:
|
||||
actIndex = i
|
||||
sublevel = face.getProperty("FLT_SFLEVEL")+1
|
||||
break
|
||||
leftover = facelist[actIndex+1:]
|
||||
for face in leftover:
|
||||
if face.getProperty("FLT_SFLEVEL") == sublevel:
|
||||
face.sel = 1
|
||||
else:
|
||||
break
|
||||
if editmode:
|
||||
Blender.Window.EditMode(1)
|
||||
|
||||
def select_by_typecode(typecode):
|
||||
global xrefprefix
|
||||
global xrefstack
|
||||
global vofsstack
|
||||
global vquatstack
|
||||
global prop_w
|
||||
global prop_h
|
||||
|
||||
state = update_state()
|
||||
|
||||
for object in state["activeScene"].objects:
|
||||
if object.properties.has_key('FLT') and object.properties['FLT']['type'] == typecode and state["activeScene"].Layers & object.Layers:
|
||||
object.select(1)
|
||||
def clight_make():
|
||||
state = update_state()
|
||||
actmesh = state["activeMesh"]
|
||||
actobj = state["activeObject"]
|
||||
|
||||
if actobj and actmesh:
|
||||
actobj.properties['FLT'] = dict()
|
||||
actobj.properties['FLT']['type'] = 111
|
||||
for prop in FLTInlineLP:
|
||||
actobj.properties['FLT'][prop] = FLTInlineLP[prop]
|
||||
|
||||
actmesh.verts.addPropertyLayer("FLT_VCOL", Blender.Mesh.PropertyTypes["INT"])
|
||||
for v in actmesh.verts:
|
||||
v.setProperty("FLT_VCOL", 67295)
|
||||
|
||||
def event(evt,val):
|
||||
if evt == Draw.ESCKEY:
|
||||
Draw.Exit()
|
||||
|
||||
def but_event(evt):
|
||||
global xrefprefix
|
||||
global xrefstack
|
||||
global vofsstack
|
||||
global vquatstack
|
||||
global prop_w
|
||||
global prop_h
|
||||
global evcode
|
||||
|
||||
state = update_state()
|
||||
|
||||
#do Xref buttons
|
||||
if evt == evcode["XREF_PREFIX"]:
|
||||
xrefprefix = XREF_PREFIX.val
|
||||
if evt == evcode["XREF_EDIT"]:
|
||||
xref_edit()
|
||||
if evt == evcode["XREF_SELECT"]:
|
||||
select_by_typecode(63)
|
||||
if evt == evcode["XREF_MAKE"]:
|
||||
xref_create()
|
||||
#do scene buttons
|
||||
if evt == evcode["SCENE_UPDATE"]:
|
||||
update_all()
|
||||
#do face buttons
|
||||
if evt == evcode["FACE_MAKESUB"]:
|
||||
subface_make()
|
||||
if evt== evcode["FACE_KILLSUB"]:
|
||||
subface_kill()
|
||||
if evt== evcode["FACE_SELSUB"]:
|
||||
subface_select()
|
||||
#common buttons
|
||||
if evt == evcode["IDPROP_KILL"]:
|
||||
if state["activeObject"]:
|
||||
idprops_kill(state["activeObject"])
|
||||
if evt == evcode["IDPROP_COPY"]:
|
||||
if state["activeObject"]:
|
||||
idprops_copy(state["activeObject"])
|
||||
if evt == evcode["XREF_POP"]:
|
||||
xref_finish()
|
||||
if evt == evcode["CLIGHT_MAKE"]:
|
||||
clight_make()
|
||||
Draw.Redraw(1)
|
||||
Blender.Window.RedrawAll()
|
||||
|
||||
|
||||
def box(x,y,w,h,c,mode):
|
||||
glColor3f(c[0],c[1],c[2])
|
||||
if mode == "outline":
|
||||
glBegin(GL_LINE_LOOP)
|
||||
else:
|
||||
glBegin(GL_POLYGON)
|
||||
glVertex2i(x,y)
|
||||
glVertex2i(x+w,y)
|
||||
glVertex2i(x+w,y+h)
|
||||
glVertex2i(x,y+h)
|
||||
glEnd()
|
||||
|
||||
def draw_postcommon(x,y,finaly):
|
||||
global sheetlabel
|
||||
global xrefprefix
|
||||
global xrefstack
|
||||
global vofsstack
|
||||
global vquatstack
|
||||
global prop_w
|
||||
global prop_h
|
||||
global evcode
|
||||
|
||||
state = update_state()
|
||||
|
||||
width = prop_w
|
||||
height = prop_h
|
||||
|
||||
#draw the header
|
||||
glColor3f(0.15,0.15,0.15)
|
||||
glBegin(GL_POLYGON)
|
||||
glVertex2i(x-1,y)
|
||||
glVertex2i(x+width+1,y)
|
||||
glVertex2i(x+width+1,y-25)
|
||||
glVertex2i(x-1,y-25)
|
||||
glEnd()
|
||||
glColor3f(1,1,1)
|
||||
glRasterPos2i(x,y-20)
|
||||
sheetlabel = Blender.Draw.Text("FLT Tools Panel")
|
||||
#draw the box outline
|
||||
glColor3f(0,0,0)
|
||||
glBegin(GL_LINE_LOOP)
|
||||
glVertex2i(x-1,y)
|
||||
glVertex2i(x+1+width,y)
|
||||
glVertex2i(x+1+width,finaly-1)
|
||||
glVertex2i(x-1,finaly-1)
|
||||
glEnd()
|
||||
return finaly
|
||||
|
||||
|
||||
def draw_propsheet(x,y):
|
||||
global XREF_PREFIX
|
||||
global XREF_MAKE
|
||||
global XREF_EDIT
|
||||
global XREF_SELECT
|
||||
global XREF_POP
|
||||
global FACE_MAKESUB
|
||||
global FACE_SELSUB
|
||||
global FACE_KILLSUB
|
||||
global IDPROP_KILL
|
||||
global IDPROP_COPY
|
||||
global SCENE_UPDATE
|
||||
global CLIGHT_MAKE
|
||||
global xrefprefix
|
||||
global xrefstack
|
||||
global vofsstack
|
||||
global vquatstack
|
||||
global prop_w
|
||||
global prop_h
|
||||
global evcode
|
||||
|
||||
state = update_state()
|
||||
|
||||
width = prop_w
|
||||
height = prop_h
|
||||
origx = x
|
||||
origy = y
|
||||
|
||||
#draw Xref tools
|
||||
y = y-20
|
||||
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")
|
||||
y = y-20
|
||||
XREF_MAKE = Blender.Draw.PushButton("Make XRef",evcode["XREF_MAKE"],x,y,width,20,"Make External Reference")
|
||||
y = y-20
|
||||
XREF_EDIT = Blender.Draw.PushButton("Edit XRef",evcode["XREF_EDIT"],x,y,width,20,"Edit External Reference")
|
||||
y = y-20
|
||||
XREF_SELECT = Blender.Draw.PushButton("Select XRefs",evcode["XREF_SELECT"],x,y,width,20,"Select External References")
|
||||
y = y - 20
|
||||
XREF_POP = Blender.Draw.PushButton("Return to previous scene",evcode["XREF_POP"],x,y,width,20,"Go up one level in xref hierarchy")
|
||||
|
||||
#Draw facetools
|
||||
y = y-20
|
||||
FACE_MAKESUB = Blender.Draw.PushButton("Make Subfaces",evcode["FACE_MAKESUB"],x,y,width,20,"Make subfaces")
|
||||
y = y-20
|
||||
FACE_SELSUB = Blender.Draw.PushButton("Select Subfaces",evcode["FACE_SELSUB"],x,y,width,20,"Select subfaces")
|
||||
y = y-20
|
||||
FACE_KILLSUB = Blender.Draw.PushButton("Kill Subfaces",evcode["FACE_KILLSUB"],x,y,width,20,"Kill subfaces")
|
||||
|
||||
#Draw ID Property tools
|
||||
y = y - 20
|
||||
IDPROP_KILL = Blender.Draw.PushButton("Delete ID props",evcode["IDPROP_KILL"],x,y,width,20,"Delete ID props")
|
||||
y = y - 20
|
||||
IDPROP_COPY = Blender.Draw.PushButton("Copy to selected",evcode["IDPROP_COPY"],x,y,width,20, "Copy from active to all selected")
|
||||
|
||||
y= y - 20
|
||||
CLIGHT_MAKE = Blender.Draw.PushButton("Make Light Point", evcode["CLIGHT_MAKE"],x,y,width,20,"Create inline light points from current mesh")
|
||||
#General tools
|
||||
y = y-20
|
||||
SCENE_UPDATE = Blender.Draw.PushButton("Update All",evcode["SCENE_UPDATE"],x,y,width,20,"Update all vertex colors")
|
||||
draw_postcommon(origx, origy,y)
|
||||
|
||||
def gui():
|
||||
#draw the propsheet/toolbox.
|
||||
psheety = 256
|
||||
#psheetx = psheety + 10
|
||||
draw_propsheet(0,psheety)
|
||||
Draw.Register(gui,event,but_event)
|
||||
|
||||
Reference in New Issue
Block a user