#!BPY # -------------------------------------------------- # ++++++++++++++++++++++++++++++++++++++++++++++++++ # ================================================== """ Name: 't3d format (*.t3g)' Blender: 125 Group: 'Export' Tooltip: 't3g file' """ # ------------------------------------ # ++++++++++++++++++++++++++++++++++++ # ==================================== __author__ = ["SYT 2008"] __url__ = ("http://starworld.syt.ru") __version__ = "4.1" __bpydoc__ = """\ T3g export script. """ # ----------------------- # +++++++++++++++++++++++ # ======================= import Blender # -------------------------- # ++++++++++++++++++++++++++ # ========================== def getrgb(xcol): #result = 0 tclt =0.0 tclt = ((round(((xcol *1000) /3.92156862745)/64))*64) #print 'reselt(tclt)= %f' % tclt return tclt # -------------------------------------------- # ++++++++++++++++++++++++++++++++++++++++++++ # ============================================ def getcolor(mcolor): #result = 0.0 tRcol = getrgb(mcolor[0]) tGcol = getrgb(mcolor[1]) tBcol = getrgb(mcolor[2]) print 'tBcol= %f' % tBcol print 'tRcol= %f' % tRcol print 'tGcol= %f' % tGcol tTcol = 7.0 if (tBcol == 64.0) : tBcol = 0 if (tGcol == 64.0) : tGcol = 0.0 if (tRcol == 64.0) : tRcol = 0.0 if (tRcol == 0.0) & (tGcol == 0.0) & (tBcol == 0.0) : tTcol = 0.0 if (tRcol == 0.0) & (tGcol == 0.0) & (tBcol == 128.0) & (tBcol <= 192.0) : tTcol = 1.0 if (tRcol == 0.0) & (tGcol == 128.0) & (tGcol <= 128.0) & (tBcol == 0.0) : tTcol = 2.0 if (tRcol == 0.0) & (tGcol == 128.0) & (tBcol == 128.0) & (tGcol <= 192.0) & (tBcol <= 192.0) : tTcol = 3.0 if (tRcol == 128.0) & (tRcol <= 192.0) & (tGcol == 0.0) & (tBcol == 0.0) : tTcol = 4.0 if (tRcol == 128.0) & (tRcol <= 192.0) & (tGcol == 0.0) & (tBcol == 128.0) & (tBcol <= 192.0) : tTcol = 5.0 if (tRcol >= 128.0) & (tGcol >= 128.0) & (tRcol <> 0.0) & (tGcol <> 0.0) & (tBcol == 0.0) : tTcol = 6.0 if (tRcol == 192.0) & (tGcol == 192.0) & (tBcol == 192.0) : tTcol = 7.0 if (tRcol >= 128.0) & (tGcol >= 128.0) & (tBcol >= 128.0) : tTcol = 8.0 if (tRcol <= 192.0) & (tGcol <= 192.0) & (tBcol >= 192.0) : tTcol = 9.0 if (tRcol <= 192.0) & (tGcol >= 192.0) & (tBcol <= 192.0) : tTcol = 10.0 if (tRcol <= 192.0) & (tGcol >= 192.0) & (tBcol >= 192.0) : tTcol = 11.0 if (tRcol >= 192.0) & (tGcol <= 192.0) & (tBcol <= 192.0) : tTcol = 12.0 if (tRcol >= 192.0) & (tGcol <= 192.0) & (tBcol >= 192.0) : tTcol = 13.0 if (tRcol >= 192.0) & (tGcol >= 192.0) & (tBcol <= 192.0) : tTcol = 14.0 if (tRcol >= 192.0) & (tGcol >= 192.0) & (tBcol >= 192.0) : tTcol = 15.0 #print 'reselt= %f' % tTcol #result = tTcol return tTcol # -------------------------------------------- # ++++++++++++++++++++++++++++++++++++++++++++ # ============================================ def my_export(filename): # -=((( Otrkoem file dlya zapisi )))=- myfile = open(filename + '.t3g', 'w') #myfile.write('123') myfile.write('. T3g export script. http://starworld.syt.ru \n') myfile.write('. SYT 2008 \n') myfile.write('. Version 4.0 beta \n')' # -=((( Poluchim spisok obyektov tekushey sceni )))=- MYOBJECTS = Blender.Scene.GetCurrent().getChildren() # -=((( Proydemsa po vsem objektam )))=- # export Meshey myfile.write(" 1 ") kol=0 for object in MYOBJECTS: if object.getType() != 'Mesh': continue mesh = object.getData(); faces = mesh.faces for face in faces: kol=kol +1 kol=kol +1 myfile.write("%i " % kol) myfile.write(" 0 0 0 0 0 0 \n") myfile.write(" 2 1 10 1 0 0 0 . center \n") for object in MYOBJECTS: # myfile.write(". ypa!! %s \n" % object.name) if object.getType() == 'Texture': myfile.write(". Texture %s \n" % object.name) if object.getType() != 'Mesh': continue print 'mesh:' + object.name mesh = object.getData(); material = mesh.materials #mesh.transform(object.matrix, True) mesh.transform(object.matrixWorld) #print mesh.center faces = mesh.faces myfile.write(". %s \n" % object.name) dTcol = 7.0 if (not material) : #myfile.write("7") dTcol = 7.0 else : if object.getType() == 'Material': myfile.write(". Material %s \n" % material[0].name) mcol = material[0].rgbCol dtcol=getcolor(mcol) print 'tcol= %f' % dtcol Tcol=7.0 for face in faces: fm=face.mat #material=fm if (not material[fm]) : myfile.write(" 2 4 %i " % (DTcol)) #Tcol=Dtcol else: if object.getType() == 'Material': myfile.write(". Material %s \n" % material[fm].name) #tcol=getcolor(material[fm-1].rgbCol) myfile.write(" 2 4 %i " % (getcolor(material[fm].rgbCol))) #print 'write= %i ' % tcol myfile.write("%i " % len(face.v)) K=len(face.v) II=0 while K>0: X=face.v[II].co[0]*20 Y=face.v[II].co[1]*20 Z=face.v[II].co[2]*20 myfile.write("%f %f %f " % ((X),(Y),(Z))) K=K-1 II=II+1 myfile.write("\n") # export Lamp for object in MYOBJECTS: if object.getType() != 'Lamp': continue print 'lamp:' + object.name # export Camer for object in MYOBJECTS: if object.getType() != 'Camera': continue print 'camera:' + object.name # myfile.write(". ny bse ok") for object in MYOBJECTS: myfile.write(". %s \n" % object.name) myfile.close() # -------------------------------------------- # ++++++++++++++++++++++++++++++++++++++++++++ # ============================================ Blender.Window.FileSelector(my_export, "Export to t3g file")