2022-12-10 18:44:20 +01:00
|
|
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
2022-12-24 04:43:14 +01:00
|
|
|
import bpy # Blender
|
2022-12-10 18:44:20 +01:00
|
|
|
import webbrowser
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
###############################################################################
|
2022-12-11 10:28:41 +01:00
|
|
|
# twin_about.py
|
2022-12-13 02:42:31 +01:00
|
|
|
# @title: A propos de l'environnement 3D pour jumeau numérique
|
2022-12-10 18:44:20 +01:00
|
|
|
# @project: Blender-EduTech
|
|
|
|
# @lang: fr
|
|
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
2023-01-01 17:34:01 +01:00
|
|
|
# @copyright: Copyright (C) 2020-2023 Philippe Roy
|
2022-12-10 18:44:20 +01:00
|
|
|
# @license: GNU GPL
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
# UPBGE scene
|
|
|
|
scene = bge.logic.getCurrentScene()
|
2022-12-24 04:43:14 +01:00
|
|
|
eevee = bpy.context.scene.eevee
|
2022-12-10 18:44:20 +01:00
|
|
|
|
|
|
|
# Colors
|
2022-12-15 06:20:48 +01:00
|
|
|
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
|
|
|
|
|
2022-12-10 18:44:20 +01:00
|
|
|
# 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
|
|
|
|
|
2022-12-24 04:43:14 +01:00
|
|
|
###############################################################################
|
|
|
|
# Interface
|
|
|
|
###############################################################################
|
|
|
|
|
2022-12-10 18:44:20 +01:00
|
|
|
##
|
|
|
|
# Ouverture
|
|
|
|
##
|
|
|
|
|
|
|
|
def open():
|
2022-12-22 05:02:33 +01:00
|
|
|
scene.objects['System']['manip_mode']=9 # Fenêtre modale About
|
2022-12-10 18:44:20 +01:00
|
|
|
scene.active_camera = scene.objects["Camera-About"]
|
2022-12-21 05:43:56 +01:00
|
|
|
# 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
|
2022-12-10 18:44:20 +01:00
|
|
|
scene.objects['About_close'].color= color_link
|
2022-12-24 04:43:14 +01:00
|
|
|
|
|
|
|
# Configuration
|
2022-12-10 18:44:20 +01:00
|
|
|
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())
|
2022-12-24 04:43:14 +01:00
|
|
|
scene.objects['About_quality-up'].color= color_link
|
|
|
|
scene.objects['About_quality-down'].color= color_link
|
2022-12-31 16:48:54 +01:00
|
|
|
quality_txt=("Inconvenant", "Basse", "Moyenne", "Haute", "Épique")
|
|
|
|
scene.objects['About_quality']['Text']= "Qualité : "+quality_txt[scene.objects['About']['quality']]
|
2022-12-10 18:44:20 +01:00
|
|
|
|
2022-12-24 04:43:14 +01:00
|
|
|
# Liens
|
2022-12-10 18:44:20 +01:00
|
|
|
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)
|
|
|
|
|
2022-12-24 04:43:14 +01:00
|
|
|
# Taille de l'écran : Boutons < et > ("640x360", "960x540", "1280x720", "1920x1080")
|
2022-12-10 18:44:20 +01:00
|
|
|
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()
|
|
|
|
|
2022-12-24 04:43:14 +01:00
|
|
|
# Qualité du rendu : Boutons < et >
|
2022-12-31 16:48:54 +01:00
|
|
|
if scene.objects['About']['quality']==4:
|
2022-12-24 04:43:14 +01:00
|
|
|
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()
|
|
|
|
|
2022-12-16 00:37:11 +01:00
|
|
|
##
|
|
|
|
# Fermer
|
|
|
|
##
|
|
|
|
|
2022-12-10 18:44:20 +01:00
|
|
|
def close(cont):
|
|
|
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
2022-12-22 05:02:33 +01:00
|
|
|
scene.objects['System']['manip_mode']=0 # Enlever la fenêtre modale
|
2022-12-10 18:44:20 +01:00
|
|
|
scene.active_camera = scene.objects["Camera"]
|
2022-12-21 05:43:56 +01:00
|
|
|
# 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
|
2022-12-10 18:44:20 +01:00
|
|
|
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={
|
2022-12-11 08:40:31 +01:00
|
|
|
'About_link-git' : 'https://gitlab.com/blender-edutech/digital_twin',
|
2022-12-10 18:44:20 +01:00
|
|
|
'About_link-gpl' : 'https://www.gnu.org/licenses/gpl-3.0.html',
|
|
|
|
'About_link-upbge' : 'https://www.upbge.org'}
|
|
|
|
webbrowser.open(link [name])
|
|
|
|
|
2022-12-24 04:43:14 +01:00
|
|
|
###############################################################################
|
|
|
|
# Configuration
|
|
|
|
###############################################################################
|
|
|
|
|
2022-12-10 18:44:20 +01:00
|
|
|
##
|
2022-12-24 04:43:14 +01:00
|
|
|
# Taille de l'écran
|
2022-12-10 18:44:20 +01:00
|
|
|
##
|
|
|
|
|
|
|
|
def get_near_pos(array,value):
|
|
|
|
array = np.asarray(array)
|
|
|
|
idx = (np.abs(array-value)).argmin()
|
|
|
|
return idx
|
|
|
|
|
|
|
|
# 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 :
|
|
|
|
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()
|
|
|
|
|
|
|
|
# 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 :
|
|
|
|
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()
|
|
|
|
|
2022-12-24 04:43:14 +01:00
|
|
|
##
|
|
|
|
# Qualité du rendu
|
|
|
|
##
|
|
|
|
|
|
|
|
def quality_up(cont):
|
|
|
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
2022-12-31 16:48:54 +01:00
|
|
|
quality_txt=("Inconvenant", "Basse", "Moyenne", "Haute", "Épique")
|
|
|
|
quality_eevee=('NOSMAA', 'LOW', 'MEDIUM','HIGH','ULTRA')
|
2022-12-24 04:43:14 +01:00
|
|
|
scene.objects['About']['quality'] +=1
|
2022-12-31 16:48:54 +01:00
|
|
|
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
|
|
|
|
eevee.smaa_quality= quality_eevee[scene.objects['About']['quality']]
|
2022-12-24 04:43:14 +01:00
|
|
|
|
|
|
|
# Boutons < et >
|
2022-12-31 16:48:54 +01:00
|
|
|
if scene.objects['About']['quality']==4:
|
2022-12-24 04:43:14 +01:00
|
|
|
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 :
|
2022-12-31 16:48:54 +01:00
|
|
|
quality_txt=("Inconvenant", "Basse", "Moyenne", "Haute", "Épique")
|
|
|
|
quality_eevee=('NOSMAA', 'LOW', 'MEDIUM','HIGH','ULTRA')
|
2022-12-24 04:43:14 +01:00
|
|
|
scene.objects['About']['quality'] -=1
|
2022-12-31 16:48:54 +01:00
|
|
|
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
|
|
|
|
eevee.smaa_quality= quality_eevee[scene.objects['About']['quality']]
|
2022-12-24 04:43:14 +01:00
|
|
|
|
|
|
|
# Boutons < et >
|
|
|
|
if scene.objects['About']['quality']==0:
|
|
|
|
scene.objects['About_quality-down'].setVisible(False,True)
|
|
|
|
scene.objects['About_quality-down-colbox'].suspendPhysics (True)
|
2022-12-31 16:48:54 +01:00
|
|
|
if scene.objects['About']['quality']==3:
|
2022-12-24 04:43:14 +01:00
|
|
|
scene.objects['About_quality-up'].setVisible(True,True)
|
|
|
|
scene.objects['About_quality-up-colbox'].restorePhysics()
|