import bge # Bibliothèque Blender Game Engine (UPBGE) import bpy # Blender import sys import webbrowser ############################################################################### # twin_about.py # @title: A propos de l'environnement 3D pour jumeau numérique # @project: Blender-EduTech # @lang: fr # @authors: Philippe Roy # @copyright: Copyright (C) 2020-2023 Philippe Roy # @license: GNU GPL ############################################################################### # UPBGE scene scene = bge.logic.getCurrentScene() eevee = bpy.context.scene.eevee # Colors color_link = (0.198, 0.109, 0.8, 1) # Violet color_link_hl = (0.8, 0.005, 0.315, 1) # Magenta # color_link = (0.051, 0.270, 0.279,1) # Turquoise # color_link = (0.024, 0.006, 0.8, 1) # Bleu # color_link = (0.8, 0.005, 0.315, 1) # Magenta # UPBGE constants JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED ACTIVATE = bge.logic.KX_INPUT_ACTIVE # JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED ############################################################################### # Crédits ############################################################################### credits_description = { 'Blender' : ["Blender","Plateforme de modélisation et d\"animation 3D","https://blender.org", "GNU GPL"], 'UPBGE' : ["UPBGE","Moteur de jeu 3D","https://upbge.org", "GNU GPL"], 'Python' : ["Python","Langage de programmation","https://python.org", "PSFL"], 'Pylint' : ["Pylint","Bibliothèque de vérification d\"un code Python","https://pylint.pycqa.org", "GNU GPL"], 'pySerial' : ["pySerial","Bibliothèque de communication série","https://pyserial.readthedocs.io", "BSD-3-Clause"], 'pyFirmata' : ["pyFirmata","Bibliothèque du protocole Firmata","https://pyfirmata.readthedocs.io", "MIT Licence"], 'Matplotlib' : ["Matplotlib","Bibliothèque de visualisation graphique de données","https://matplotlib.org", "BSD"], 'wxWidgets' : ["wxWidgets","Bibliothèque GUI","https://www.wxwidgets.org", "wxWindows Library Licence"], 'wxPython' : ["wxPython","API Python de wxWidgets","https://www.wxpython.org", "GNU GPL"], 'Qt5' : ["Qt5","Bibliothèque GUI","https://www.qt.io", "GNU LGPL-3"], 'PyQt' : ["PyQt","API Python de Qt5","https://www.riverbankcomputing.com/software/pyqt","GNU GPL"], 'Game-icons.net' : ["Game-icons.net","Icônes","https://game-icons.net/","CC BY 3.0"], 'Kenney' : ["Kenney","Icônes","https://www.kenney.nl/","CC0 1.0"], 'EspressoDolce' : ["Espresso Dolce","Police de caractères","https://www.dafont.com/fr/espresso-dolce.font", "OFL"]} ############################################################################### # Interface ############################################################################### ## # Ouverture ## def open(): scene.objects['System']['manip_mode']=9 # Fenêtre modale About scene.active_camera = scene.objects["Camera-About"] # scene.removeOverlayCollection(bpy.data.collections['Hud']) # Crash de UPBGE sur la supression de l'Overlay scene.objects['Twins-icon'].setVisible(False,True) # Crash de UPBGE sur la supression de l'Overlay scene.objects['Twins-text'].setVisible(False,True) # Crash de UPBGE sur la supression de l'Overlay scene.objects['Script-icon'].setVisible(False,True) # Crash de UPBGE sur la supression de l'Overlay scene.objects['Script-text'].setVisible(False,True) # Crash de UPBGE sur la supression de l'Overlay scene.objects['About_close'].color= color_link scene.objects['About_credits'].color= color_link scene.objects['Credits_close'].color= color_link # Mémorisation de la position des pages scene.objects["About"]['init_lx']=scene.objects["About"].worldPosition.x scene.objects["About"]['init_ly']=scene.objects["About"].worldPosition.y scene.objects["About"]['init_lz']=scene.objects["About"].worldPosition.z scene.objects["Credits"]['init_lx']=scene.objects["Credits"].worldPosition.x scene.objects["Credits"]['init_ly']=scene.objects["Credits"].worldPosition.y scene.objects["Credits"]['init_lz']=scene.objects["Credits"].worldPosition.z # Configuration scene.objects['About_screen-up'].color= color_link scene.objects['About_screen-down'].color= color_link scene.objects['About_screen']['Text']= "Taille écran : "+str(bge.render.getWindowWidth()) +" x "+str(bge.render.getWindowHeight()) scene.objects['About_quality-up'].color= color_link scene.objects['About_quality-down'].color= color_link quality_txt=("Inconvenant", "Basse", "Moyenne", "Haute", "Épique") scene.objects['About_quality']['Text']= "Qualité : "+quality_txt[scene.objects['About']['quality']] # Liens scene.objects['About_link-git'].color= color_link scene.objects['About_link-git']['Text'] = "Dépôt des sources" # Pas de ô dans Blender scene.objects['About_link-gpl'].color= color_link scene.objects['About_link-upbge'].color= color_link scene.objects['About'].setVisible(True,True) # Taille de l'écran : Boutons < et > ("640x360", "960x540", "1280x720", "1920x1080") if bge.render.getWindowWidth() <=640: scene.objects['About_screen-down'].setVisible(False,True) scene.objects['About_screen-down-colbox'].suspendPhysics (True) else: scene.objects['About_screen-down'].setVisible(True,True) scene.objects['About_screen-down-colbox'].restorePhysics() if bge.render.getWindowWidth() >= 1920: scene.objects['About_screen-up'].setVisible(False,True) scene.objects['About_screen-up-colbox'].suspendPhysics (True) else: scene.objects['About_screen-up'].setVisible(True,True) scene.objects['About_screen-up-colbox'].restorePhysics() # Qualité du rendu : Boutons < et > if scene.objects['About']['quality']==4: scene.objects['About_quality-up'].setVisible(False,True) scene.objects['About_quality-up-colbox'].suspendPhysics (True) else: scene.objects['About_quality-up'].setVisible(True,True) scene.objects['About_quality-up-colbox'].restorePhysics() if scene.objects['About']['quality']==0: scene.objects['About_quality-down'].setVisible(False,True) scene.objects['About_quality-down-colbox'].suspendPhysics (True) else: scene.objects['About_quality-down'].setVisible(True,True) scene.objects['About_quality-down-colbox'].restorePhysics() ## # Fermer ## def close(cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : scene.objects['System']['manip_mode']=0 # Enlever la fenêtre modale scene.active_camera = scene.objects["Camera"] # scene.addOverlayCollection(scene.cameras['Camera-Hud'], bpy.data.collections['Hud']) # Crash de UPBGE sur la supression de l'Overlay scene.objects['Twins-icon'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay scene.objects['Twins-text'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay scene.objects['Script-icon'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay scene.objects['Script-text'].setVisible(True,True) # Crash de UPBGE sur la supression de l'Overlay bpy.context.view_layer.update() # Bug de mise à jour # scene.objects['Cmd-text']['Text']= " " # Redraw pour afficher scene.objects['Twins-icon'] et scene.objects['Twins-text'] scene.objects['About'].setVisible(False,True) ## # Highlight ## def hl(cont): if cont.sensors['MO'].status == JUST_ACTIVATED: obj = cont.owner name=obj.name[:-7] scene.objects[name].color = color_link_hl if cont.sensors['MO'].status == JUST_RELEASED: obj = cont.owner name=obj.name[:-7] scene.objects[name].color = color_link ## # Liens ## def link(cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : obj = cont.owner name=obj.name[:-7] link={ 'About_link-git' : 'https://forge.aeif.fr/blender-edutech/jumeau-numerique', 'About_link-gpl' : 'https://www.gnu.org/licenses/gpl-3.0.html', 'About_link-upbge' : 'https://www.upbge.org'} webbrowser.open(link [name]) ############################################################################### # Crédits ############################################################################### def credits(cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : # Afficher la page Crédits scene.objects["Credits"].worldPosition.x = scene.objects["About"]['init_lx'] scene.objects["Credits"].worldPosition.y = scene.objects["About"]['init_ly'] scene.objects["Credits"].worldPosition.z = scene.objects["About"]['init_lz'] scene.objects["About"].worldPosition.x = scene.objects["Credits"]['init_lx'] scene.objects["About"].worldPosition.y = scene.objects["Credits"]['init_ly'] scene.objects["About"].worldPosition.z = scene.objects["Credits"]['init_lz'] scene.objects['About'].setVisible(False,True) scene.objects['Credits'].setVisible(True,True) # Afficher les descriptions credits_description_list=list (credits_description) for i in range(len(credits_description_list)): scene.objects["Credits_url-"+str(i+1)]['Text']= credits_description[credits_description_list[i]][0] scene.objects["Credits_url-"+str(i+1)].color= color_link scene.objects["Credits_text-"+str(i+1)]['Text']= credits_description[credits_description_list[i]][1] scene.objects["Credits_license-"+str(i+1)]['Text']= credits_description[credits_description_list[i]][3] def credits_close(cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : # Revenir à la page About scene.objects["Credits"].worldPosition.x = scene.objects["Credits"]['init_lx'] scene.objects["Credits"].worldPosition.y = scene.objects["Credits"]['init_ly'] scene.objects["Credits"].worldPosition.z = scene.objects["Credits"]['init_lz'] scene.objects["About"].worldPosition.x = scene.objects["About"]['init_lx'] scene.objects["About"].worldPosition.y = scene.objects["About"]['init_ly'] scene.objects["About"].worldPosition.z = scene.objects["About"]['init_lz'] scene.objects['Credits'].setVisible(False,True) scene.objects['About'].setVisible(True,True) def credits_link(cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : obj = cont.owner idx=int(obj.name[12:-7]) webbrowser.open(credits_description[list(credits_description)[idx-1]][2]) ############################################################################### # Configuration ############################################################################### ## # Taille de l'écran ## def get_near_pos(value_list,value): delta=[] for i in range (len(value_list)): delta.append(abs(value-value_list[i])) return delta.index(min(delta)) # Taille de l'écran + def screen_up(cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : screen_width_mode=[640, 960, 1280, 1920] screen_height_mode=[360, 540, 720,1080] screen_mode_txt=["640x360", "960x540", "1280x720", "1920x1080"] i = get_near_pos(screen_width_mode, bge.render.getWindowWidth()) if i>=0 and i<3 : if bge.render.getWindowWidth() if screen_width <=640: scene.objects['About_screen-down'].setVisible(False,True) scene.objects['About_screen-down-colbox'].suspendPhysics (True) else: scene.objects['About_screen-down'].setVisible(True,True) scene.objects['About_screen-down-colbox'].restorePhysics() if screen_width >= 1920: scene.objects['About_screen-up'].setVisible(False,True) scene.objects['About_screen-up-colbox'].suspendPhysics (True) else: scene.objects['About_screen-up'].setVisible(True,True) scene.objects['About_screen-up-colbox'].restorePhysics() # Taille de l'écran - def screen_down(cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : screen_width_mode=[640, 960, 1280, 1920] screen_height_mode=[360, 540, 720,1080] screen_mode_txt=["640x360", "960x540", "1280x720", "1920x1080"] i = get_near_pos(screen_width_mode, bge.render.getWindowWidth()) if i>0 and i<=3 : if bge.render.getWindowWidth()>screen_width_mode[i]: screen_width=screen_width_mode[i] screen_height=screen_height_mode[i] else: screen_width=screen_width_mode[i-1] screen_height=screen_height_mode[i-1] scene.objects['About_screen']['Text']= "Taille écran : "+str(screen_width) +" x "+str(screen_height) bge.render.setWindowSize(screen_width,screen_height) # Boutons < et > if screen_width <=640: scene.objects['About_screen-down'].setVisible(False,True) scene.objects['About_screen-down-colbox'].suspendPhysics (True) else: scene.objects['About_screen-down'].setVisible(True,True) scene.objects['About_screen-down-colbox'].restorePhysics() if screen_width >= 1920: scene.objects['About_screen-up'].setVisible(False,True) scene.objects['About_screen-up-colbox'].suspendPhysics (True) else: scene.objects['About_screen-up'].setVisible(True,True) scene.objects['About_screen-up-colbox'].restorePhysics() ## # Qualité du rendu ## def quality_up(cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : quality_txt=("Inconvenant", "Basse", "Moyenne", "Haute", "Épique") quality_eevee=('NOSMAA', 'LOW', 'MEDIUM','HIGH','ULTRA') scene.objects['About']['quality'] +=1 scene.objects['About_quality']['Text']= "Qualité : "+quality_txt[scene.objects['About']['quality']] if quality_eevee[scene.objects['About']['quality']] == 'NOSMAA': eevee.smaa_quality= 'LOW' eevee.use_eevee_smaa = False else: eevee.use_eevee_smaa = True # print (sys.platform) if sys.platform=="linux": # Plantage sur Windows eevee.smaa_quality= quality_eevee[scene.objects['About']['quality']] # Boutons < et > if scene.objects['About']['quality']==4: scene.objects['About_quality-up'].setVisible(False,True) scene.objects['About_quality-up-colbox'].suspendPhysics (True) if scene.objects['About']['quality']==1: scene.objects['About_quality-down'].setVisible(True,True) scene.objects['About_quality-down-colbox'].restorePhysics() def quality_down(cont): if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive : quality_txt=("Inconvenant", "Basse", "Moyenne", "Haute", "Épique") quality_eevee=('NOSMAA', 'LOW', 'MEDIUM','HIGH','ULTRA') scene.objects['About']['quality'] -=1 scene.objects['About_quality']['Text']= "Qualité : "+quality_txt[scene.objects['About']['quality']] if quality_eevee[scene.objects['About']['quality']] == 'NOSMAA': eevee.smaa_quality= 'LOW' eevee.use_eevee_smaa = False else: eevee.use_eevee_smaa = True if sys.platform=="Linux": # Plantage sur Windows eevee.smaa_quality= quality_eevee[scene.objects['About']['quality']] # Boutons < et > if scene.objects['About']['quality']==0: scene.objects['About_quality-down'].setVisible(False,True) scene.objects['About_quality-down-colbox'].suspendPhysics (True) if scene.objects['About']['quality']==3: scene.objects['About_quality-up'].setVisible(True,True) scene.objects['About_quality-up-colbox'].restorePhysics()