# /^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\ # | script made by : Levak | # | for ? : Blender 2.48 and more | # | with ? : Python 2.5 | # | when ? : March the 7th, 2009 | # |what does it do ?: Convert Active selected mesh data into Pascal language | # | with a points matrix and a faces matrix, and thoses only | # | can be runned on the TI Npsire handheld with Make3D. | # | | # \............................................................................/ import Blender from Blender import Mesh, Draw, BGL print "\n\n" ############################################################# # Fonction prise sur le net permettant d'arrondir un resultat # #################################################################### # Round = lambda x, n: eval('"%.' + str(int(n)) + 'f" % ' + repr(x)) # # ######### ############################################################# # Fonction pour récupérer le dossier et le nom du fichier # #################################################################### # import BPyMessages # def save_txt(filename): # '''Enregistrer l'objet selectionné au format txt.''' # # if not filename.lower().endswith('.txt'): # filename += '.txt' # # if not BPyMessages.Warning_SaveOver(filename): # return # ExportCube(filename) # ######### # ################################## # / ________________________________ \ #<-- On commence le script d'export --> # \ -------------------------------- / # def ExportCube(filename): # # ############################# ### # On initialise les variables # ############################# lobjet = Blender.Object.GetSelected()[0] lemesh = lobjet.getData () print "Il y a ", len(lemesh.verts), " vertices et", len(lemesh.faces),"faces dans l'objet" assign_p = ":=" resultat = "" matrice = [0,0,0,0] mat_x = mat_y = mat_z = mat_h = [] mat_f = [] numverts=0 f_name = str(stringName) f_name = f_name.replace("'","") # # ########################################################## ### # Boucle pour lister tous les verticles et leurs positions # ########################################################## for vertice in lemesh.verts: mat_x = mat_x + [Round(vertice.co[0], str(sliderFloat))] mat_y = mat_y + [Round(vertice.co[1], str(sliderFloat))] mat_z = mat_z + [Round(vertice.co[2], str(sliderFloat))] mat_h = mat_h + [1] numverts+=numverts # On compile le tout dans une variable matrice[0], matrice[1], matrice[2], matrice[3] = mat_x, mat_y, mat_z, mat_h resultat = f_name+assign_p+str(matrice) resultat = resultat.replace("'","") resultat = resultat.replace(" ","") print "\n",resultat # # ########################################################## ### # Boucle pour lister toutes les faces et leurs références # ########################################################## for face in lemesh.faces: mat_fa = [] for vert in face.v: fa = ( ' %i' % (vert.index + 1) ) mat_fa.append(fa) # Export en Quads if ExportMod == 1: # Ohh un quad, génial if len(mat_fa) == 4: mat_f.append(mat_fa) # Zut c'est un tri donc on s'arrange pour le passer dans la matrice 4x4 pour éviter les erreurs elif len(mat_fa) == 3: mat_fa.append(fa) mat_f.append(mat_fa) # Export en Tris elif ExportMod == 0: # Ohh un tri, génial if len(mat_fa) == 3: mat_f.append(mat_fa) # Zut c'est un quad donc on s'arrange pour le passer dans la matrice 3*3 elif len(mat_fa) == 4: tri_temp_1 = mat_fa[0]+mat_fa[1]+mat_fa[2] tri_temp_2 = mat_fa[0]+mat_fa[2]+mat_fa[3] mat_f.append(tri_temp_1) mat_f.append(tri_temp_2) # On compile le tout dans une variable resultat2 = f_name+"_edge"+assign_p+str(mat_f) resultat2 = resultat2.replace("'","") resultat2 = resultat2.replace(" ","") print "\n",resultat2 # # ################################## ### # On stock le tout dans un fichier # ################################## logfile = open(filename, 'w') logfile.write(resultat+":"+resultat2) logfile.close() # / ________________________ \ #<-- fin du script d'export --> # \ ------------------------ / # ########################### # ############################### # / _____________________________ \ #<-- On commence l'interface GUI --> # \ ----------------------------- / # # # ############################# ### # On initialise les variables # ############################# stringName = Draw.Create(Blender.Object.GetSelected()[0].getName()) sliderFloat = Draw.Create(1) ExportMod = Draw.Create(1) m_menu = "Mode %t | Triangles %x0 | Quadrilatères %x1" ligne = [5,35,65,95,125,155,185] # # ###################################### ### # Assignation des numeros des boutons: # ###################################### EV_BT_OK = 1 EV_BT_CANCEL = 2 EV_SL_MENU = 3 EV_SL_FLOAT = 4 EV_ST_NAME = 5 # # ###################################### ### # On affiche tous les zolis boutons !! # ###################################### def draw_gui(): global stringName, sliderFloat, ExportMod BGL.glRasterPos2i(5,ligne[6]) Draw.Text("Choisissez le nom de l'objet à exporter:") stringName = Draw.String("Nom: ", EV_ST_NAME, 5, ligne[5], 310, 25, stringName.val, 32, "Nom de l'objet") BGL.glRasterPos2i(5,ligne[4]) Draw.Text("Choisissez le nombre de chiffres significatifs:") sliderFloat = Draw.Slider("Arrondir à : ", EV_SL_FLOAT, 5, ligne[3], 310, 25, sliderFloat.val, 0, 8, 1, "Float") BGL.glRasterPos2i(5,ligne[2]) Draw.Text("Choisissez les dimensions de la matrice de sortie (n*4 ou n*3):") ExportMod = Draw.Menu(m_menu, EV_SL_MENU, 5,ligne[1], 100, 25 , ExportMod.val, "Selectionner le mode d'export.") Draw.PushButton("Exporter sous...", EV_BT_OK, 5, ligne[0], 110, 25, "Valider") Draw.PushButton("Annuler", EV_BT_CANCEL, 130, ligne[0], 80, 25, "Annuler") def event(event, val) : # fonctions definissant les evenements lies a la souris ou au clavier if event == Draw.ESCKEY or event == Draw.QKEY: stop = Draw.PupMenu("OK?%t|Stopper le script %x1") if stop == 1: Draw.Exit() def button_event(evt) : # fonctions definissant les evenements lies aux boutons if evt==EV_BT_OK: Draw.Exit() Blender.Window.FileSelector(save_txt, "Export TXT", Blender.sys.makename(ext='')) elif evt==EV_BT_CANCEL: stop = Draw.PupMenu("OK?%t|Stopper le script %x1") if stop == 1: Draw.Exit() Draw.Register(draw_gui, event, button_event) # / ___________________ \ #<-- Fin du script GUI --> # \ ------------------- / # ##################### #_______________m # fin du script \ #()\ -` #] ###\