lecteur-3d-cinematique/cine_about.py

171 lines
6.7 KiB
Python

import bge # Bibliothèque Blender Game Engine (UPBGE)
import webbrowser
import numpy as np
###############################################################################
# cine_about.py
# @title: A propos du player 3D d'analyse de cinématique
# @project: Blender-EduTech
# @lang: fr
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
# @copyright: Copyright (C) 2020-2022 Philippe Roy
# @license: GNU GPL
###############################################################################
# UPBGE scene
scene = bge.logic.getCurrentScene()
# Colors
color_link = [0.051, 0.270, 0.279,1] # Turquoise
# color_link = [0.024, 0.006, 0.8, 1] # Bleu
color_link_hl = [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
##
# Ouverture
##
def open():
scene.active_camera = scene.objects["Camera-About"]
scene.objects['About_close'].color= color_link
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_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)
# 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()
def close(cont):
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
if scene.objects['About']['anim'] == True:
start = scene.objects['Mecanism']['anim_frame']
end = 250
layer = 0
priority = 1
blendin = 1.0
mode = bge.logic.KX_ACTION_MODE_PLAY
layerWeight = 0.0
ipoFlags = 0
speed = 1.0
for objet in scene.objects['Mecanism']['objects_anim'] :
scene.objects[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
scene.objects['Mecanism']['anim'] = True
scene.objects['About']['anim'] == False
scene.active_camera = scene.objects["Camera"]
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://gitlab.com/blender-edutech/kinematic_player',
'About_link-gpl' : 'https://www.gnu.org/licenses/gpl-3.0.html',
'About_link-upbge' : 'https://www.upbge.org'}
webbrowser.open(link [name])
##
# Configuration de l'écran
##
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()