mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
Migration vers le nouveau Hud
This commit is contained in:
parent
7fd7566656
commit
161b3305b8
@ -1,10 +1,7 @@
|
||||
import importlib
|
||||
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
||||
import twin # Bibliothèque l'environnement 3D des jumeaux numériques
|
||||
import math
|
||||
import time
|
||||
import sys
|
||||
import webbrowser
|
||||
import threading # Multithreading
|
||||
|
||||
###############################################################################
|
||||
# porcou.py
|
||||
@ -17,15 +14,12 @@ import threading # Multithreading
|
||||
#
|
||||
# Commandes déclenchées par le simulateur (sml) pour le modèle du portail coulissant (sml_*)
|
||||
#
|
||||
# Ce simulateur est un environnement 3D programmable en Python.
|
||||
# Il est destiné à la découverte de la programmation de système pluritechnique.
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
# Import dynamique du fichier Python élève
|
||||
sys.setrecursionlimit(10**5) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender
|
||||
importlib.invalidate_caches()
|
||||
porcou_cmd = importlib.import_module('porcou_cmd')
|
||||
# # Import dynamique du fichier Python élève
|
||||
# sys.setrecursionlimit(10**5) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender
|
||||
# importlib.invalidate_caches()
|
||||
# porcou_cmd = importlib.import_module('porcou_cmd')
|
||||
|
||||
# Récupérer la scène UPBGE
|
||||
scene = bge.logic.getCurrentScene()
|
||||
@ -38,10 +32,10 @@ couleur_orange = [0.799, 0.130, 0.063,1] # bouton activable : orange
|
||||
couleur_blanc = [0.8, 0.8, 0.8, 1] # bouton focus : blanc
|
||||
couleur_jaune = [0.8, 0.619, 0.021, 1] # bouton activé : jaune
|
||||
|
||||
couleur_cmd = [0.8, 0.8, 0.8, 1] # blanc
|
||||
couleur_cmd_hl = [0.8, 0.619, 0.021, 1] # jaune
|
||||
couleur_lien = [0.024, 0.006, 0.8, 1] # bleu
|
||||
couleur_lien_hl = [0.8, 0.005, 0.315, 1] # majenta
|
||||
# couleur_cmd = [0.8, 0.8, 0.8, 1] # blanc
|
||||
# couleur_cmd_hl = [0.8, 0.619, 0.021, 1] # jaune
|
||||
# couleur_lien = [0.024, 0.006, 0.8, 1] # bleu
|
||||
# couleur_lien_hl = [0.8, 0.005, 0.315, 1] # majenta
|
||||
|
||||
# Constantes UPBGE
|
||||
|
||||
@ -50,13 +44,31 @@ JUST_RELEASED = bge.logic.KX_INPUT_JUST_RELEASED
|
||||
ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
||||
# JUST_DEACTIVATED = bge.logic.KX_SENSOR_JUST_DEACTIVATED
|
||||
|
||||
###############################################################################
|
||||
# Initialisation
|
||||
###############################################################################
|
||||
|
||||
def init(cont):
|
||||
twin.manip_init() # Manipulation du modèle 3D
|
||||
twin.cmd_init() # Commandes
|
||||
|
||||
# Mémorisation de la position et orientation des composants du système
|
||||
scene.objects['Portail']['init_lx']=scene.objects['Portail'].worldPosition.x
|
||||
scene.objects['Portail']['init_ly']=scene.objects['Portail'].worldPosition.y
|
||||
scene.objects['Portail']['init_lz']=scene.objects['Portail'].worldPosition.z
|
||||
scene.objects['Engrenage']['init_rx']=scene.objects['Engrenage'].worldOrientation.to_euler().x
|
||||
scene.objects['Engrenage']['init_ry']=scene.objects['Engrenage'].worldOrientation.to_euler().y
|
||||
scene.objects['Engrenage']['init_rz']=scene.objects['Engrenage'].worldOrientation.to_euler().z
|
||||
|
||||
system_init() # Initialisation du système
|
||||
|
||||
###############################################################################
|
||||
# Actionneurs
|
||||
###############################################################################
|
||||
|
||||
# Action du simulateur pour le clignotant
|
||||
def sml_clignotant (cont):
|
||||
if scene.objects['Systeme']['run']:
|
||||
if scene.objects['System']['run']:
|
||||
obj = cont.owner
|
||||
if obj['actif'] and scene.objects['Led allumee'].visible == False:
|
||||
scene.objects['Led allumee'].setVisible(True,False)
|
||||
@ -69,7 +81,7 @@ def sml_clignotant (cont):
|
||||
|
||||
# Action du simulateur pour le moteur
|
||||
def sml_moteur (cont):
|
||||
if scene.objects['Systeme']['run']:
|
||||
if scene.objects['System']['run']:
|
||||
obj = cont.owner
|
||||
pas_rot = math.pi/7 # z = 14
|
||||
pas = 2.35619/0.3 # pas echelle 1:1 = 2.35619 -> pas à l'échelle de la maquette (0,3) : 2.35619/0.3 = 7,85396
|
||||
@ -92,7 +104,7 @@ def sml_moteur (cont):
|
||||
|
||||
# Etat capteur fin de course portail ouvert
|
||||
def sml_fdc_ouvert (cont):
|
||||
if scene.objects['Systeme']['run'] :
|
||||
if scene.objects['System']['run'] :
|
||||
obj = cont.owner
|
||||
obj_etat=obj['actif']
|
||||
obj_microrupteur=scene.objects['Microrupteur fdc ouvert']
|
||||
@ -115,7 +127,7 @@ def sml_fdc_ouvert (cont):
|
||||
|
||||
# Etat capteur fin de course portail fermé
|
||||
def sml_fdc_ferme (cont):
|
||||
if scene.objects['Systeme']['run'] :
|
||||
if scene.objects['System']['run'] :
|
||||
obj = cont.owner
|
||||
obj_etat=obj['actif']
|
||||
obj_microrupteur=scene.objects['Microrupteur fdc ferme']
|
||||
@ -138,7 +150,7 @@ def sml_fdc_ferme (cont):
|
||||
|
||||
# Forçage capteur fin de course avec la souris
|
||||
def sml_microrupteur (cont):
|
||||
if scene.objects['Systeme']['run'] :
|
||||
if scene.objects['System']['run'] :
|
||||
sml_click(cont, cont.owner)
|
||||
|
||||
###############################################################################
|
||||
@ -147,7 +159,7 @@ def sml_microrupteur (cont):
|
||||
|
||||
# Emetteur IR
|
||||
def sml_emet_ir (cont):
|
||||
if scene.objects['Systeme']['run'] :
|
||||
if scene.objects['System']['run'] :
|
||||
obj = cont.owner
|
||||
obj_emetteur_ir=scene.objects['Emetteur IR']
|
||||
obj_recepteur_ir=scene.objects['Recepteur IR']
|
||||
@ -164,7 +176,7 @@ def sml_emet_ir (cont):
|
||||
|
||||
# Recepteur IR
|
||||
def sml_recep_ir (cont):
|
||||
if scene.objects['Systeme']['run'] and scene.objects['Module emetteur IR']['actif'] :
|
||||
if scene.objects['System']['run'] and scene.objects['Module emetteur IR']['actif'] :
|
||||
obj = cont.owner
|
||||
sml_click(cont, scene.objects['Module recepteur IR'])
|
||||
if scene.objects['Module recepteur IR']['actif']==True :
|
||||
@ -181,7 +193,7 @@ def sml_click(cont, obj_activation):
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED :
|
||||
obj.color = couleur_blanc
|
||||
obj['MO']=True
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and scene.objects['Systeme']['manip_mode']==0:
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and scene.objects['System']['manip_mode']==0:
|
||||
if obj['MO']:
|
||||
obj_activation['actif'] = True
|
||||
obj.color = couleur_jaune
|
||||
@ -199,21 +211,21 @@ def sml_click(cont, obj_activation):
|
||||
|
||||
# Bouton pousssoir coté rue
|
||||
def sml_bp_rue (cont):
|
||||
if scene.objects['Systeme']['run'] :
|
||||
if scene.objects['System']['run'] :
|
||||
sml_click(cont, scene.objects['Module bouton cote rue'])
|
||||
|
||||
# Bouton pousssoir coté cour
|
||||
def sml_bp_cour (cont):
|
||||
if scene.objects['Systeme']['run'] :
|
||||
if scene.objects['System']['run'] :
|
||||
sml_click(cont, scene.objects['Module bouton cote cour'])
|
||||
|
||||
###############################################################################
|
||||
# Cycle
|
||||
# Système
|
||||
###############################################################################
|
||||
|
||||
# Initialisation du cycle de fonctionnement normal
|
||||
# Initialisation du système
|
||||
# Le moteur est géré en continue.
|
||||
def cycle_init (cont):
|
||||
def system_init ():
|
||||
|
||||
# Clignotant
|
||||
scene.objects['Module led']['actif']=False
|
||||
@ -227,45 +239,11 @@ def cycle_init (cont):
|
||||
scene.objects['Emetteur IR'].color = couleur_magenta
|
||||
scene.objects['Recepteur IR'].color = couleur_magenta
|
||||
|
||||
# Mise en route et pause du cycle
|
||||
def cycle_run (cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Systeme']['manip_mode']==0:
|
||||
|
||||
# Pause
|
||||
if scene.objects['Systeme']['run'] == True:
|
||||
scene.objects['Systeme']['run']=False
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Run-Hl'].setVisible(True,False)
|
||||
else:
|
||||
|
||||
# Run
|
||||
scene.objects['Systeme']['run']=True
|
||||
scene.objects['Run'].setVisible(False,False)
|
||||
scene.objects['Run-Hl'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(True,False)
|
||||
if scene.objects['Systeme']['thread_run']==False: # Lancement du thread utilisateur
|
||||
scene.objects['Stop'].setVisible(True,False)
|
||||
importlib.reload(porcou_cmd) # Lecture dynamique du script python (risque de Segfault de Blender)
|
||||
porcou_cmd.start()
|
||||
|
||||
# Arrêt et réinitialisation du cycle
|
||||
def cycle_stop (cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Systeme']['manip_mode']==0:
|
||||
|
||||
# Arrêt du thread utilisateur
|
||||
scene.objects['Systeme']['run']=False
|
||||
scene.objects['Systeme']['thread_run']=False
|
||||
porcou_cmd.stop()
|
||||
|
||||
# Commandes
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Run'].setVisible(True,False)
|
||||
scene.objects['Stop'].setVisible(False,False)
|
||||
scene.objects['Stop-Hl'].setVisible(False,False)
|
||||
# Réinitialisation du système
|
||||
def system_reset ():
|
||||
|
||||
# Grille à l'état initial
|
||||
# applyRotationTo(scene.objects['Systeme'], 0, 0, 0)
|
||||
# applyRotationTo(scene.objects['System'], 0, 0, 0)
|
||||
scene.objects['Portail'].worldPosition.x = scene.objects['Portail']['init_lx']
|
||||
scene.objects['Portail'].worldPosition.y = scene.objects['Portail']['init_ly']
|
||||
scene.objects['Portail'].worldPosition.z = scene.objects['Portail']['init_lz']
|
||||
@ -298,438 +276,3 @@ def cycle_stop (cont):
|
||||
scene.objects['Module recepteur IR']['actif'] =False
|
||||
scene.objects['Module bouton cote rue']['actif'] =False
|
||||
scene.objects['Module bouton cote cour']['actif'] =False
|
||||
|
||||
# Fin naturelle du cycle
|
||||
def cycle_fin (cont):
|
||||
|
||||
# Arrêt du thread utilisateur
|
||||
scene.objects['Systeme']['run']=False
|
||||
scene.objects['Systeme']['thread_run']=False
|
||||
porcou_cmd.stop()
|
||||
|
||||
# Commandes
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Run'].setVisible(True,False)
|
||||
scene.objects['Stop'].setVisible(False,False)
|
||||
scene.objects['Stop-Hl'].setVisible(False,False)
|
||||
|
||||
# Grille à l'état initial
|
||||
# applyRotationTo(scene.objects['Systeme'], 0, 0, 0)
|
||||
scene.objects['Portail'].worldPosition.x = scene.objects['Portail']['init_lx']
|
||||
scene.objects['Portail'].worldPosition.y = scene.objects['Portail']['init_ly']
|
||||
scene.objects['Portail'].worldPosition.z = scene.objects['Portail']['init_lz']
|
||||
|
||||
# Moteur à l'état initial
|
||||
rres=0.001 # resolution rotation
|
||||
obj1=scene.objects['Engrenage']
|
||||
while (obj1.localOrientation.to_euler().y) > 1.1*rres :
|
||||
obj1.applyRotation((0, 0, -rres), True)
|
||||
while (obj1.localOrientation.to_euler().y) < -1.1*rres :
|
||||
obj1.applyRotation((0, 0, rres), True)
|
||||
|
||||
# Led à l'état initial
|
||||
scene.objects['Led'].setVisible(True,False)
|
||||
scene.objects['Led allumee'].setVisible(False,False)
|
||||
|
||||
# Capteur barrage IR
|
||||
scene.objects['Emetteur IR Led'].setVisible(True,False)
|
||||
scene.objects['Emetteur IR Led allumee'].setVisible(False,False)
|
||||
scene.objects['Emetteur IR'].color = couleur_magenta
|
||||
scene.objects['Recepteur IR'].color = couleur_magenta
|
||||
|
||||
# I/O à l'état initial
|
||||
scene.objects['Module led']['actif']=False
|
||||
scene.objects['Ensemble moteur']['actif_ouvrir']=False
|
||||
scene.objects['Ensemble moteur']['actif_fermer']=False
|
||||
scene.objects['Capteur fdc ouvert']['actif'] =True
|
||||
scene.objects['Capteur fdc ferme']['actif'] =False
|
||||
scene.objects['Module emetteur IR']['actif'] =False
|
||||
scene.objects['Module recepteur IR']['actif'] =False
|
||||
scene.objects['Module bouton cote rue']['actif'] =False
|
||||
scene.objects['Module bouton cote cour']['actif'] =False
|
||||
|
||||
|
||||
# Arret du thread zombie par forçage des entrées
|
||||
# def cfn_thread_zombie (cont):
|
||||
# obj = cont.owner
|
||||
# forcg=obj['thread_forcg']
|
||||
# if obj['thread_run'] == False and obj['thread_alive'] == True:
|
||||
# print ("Thread zombie : forçage ", forcg)
|
||||
# porcou_cmd.stop()
|
||||
|
||||
# # 0001
|
||||
# if forcg ==0:
|
||||
# scene.objects['Capteur fdc ouvert']['actif']=True
|
||||
# scene.objects['Capteur fdc ferme']['actif']=False
|
||||
# scene.objects['Module bouton cote rue']['actif']=False
|
||||
# scene.objects['Module bouton cote cour']['actif']=False
|
||||
|
||||
# # 0010
|
||||
# if forcg ==1:
|
||||
# scene.objects['Capteur fdc ouvert']['actif']=False
|
||||
# scene.objects['Capteur fdc ferme']['actif']=True
|
||||
# scene.objects['Module bouton cote rue']['actif']=False
|
||||
# scene.objects['Module bouton cote cour']['actif']=False
|
||||
|
||||
# # 0100
|
||||
# if forcg ==2:
|
||||
# scene.objects['Capteur fdc ouvert']['actif']=False
|
||||
# scene.objects['Capteur fdc ferme']['actif']=False
|
||||
# scene.objects['Module bouton cote rue']['actif']=True
|
||||
# scene.objects['Module bouton cote cour']['actif']=False
|
||||
|
||||
# # 1000
|
||||
# if forcg ==3:
|
||||
# scene.objects['Capteur fdc ouvert']['actif']=False
|
||||
# scene.objects['Capteur fdc ferme']['actif']=False
|
||||
# scene.objects['Module bouton cote rue']['actif']=False
|
||||
# scene.objects['Module bouton cote cour']['actif']=True
|
||||
|
||||
# # Combinaison suivante
|
||||
# forcg +=1
|
||||
# if forcg==4:
|
||||
# forcg=0
|
||||
# obj['thread_forcg']= forcg
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Commandes
|
||||
###############################################################################
|
||||
|
||||
# Init
|
||||
def cmd_init():
|
||||
scene.objects['Systeme']['run']=False
|
||||
scene.objects['Run-Hl'].setVisible(False,False)
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Stop'].setVisible(False,False)
|
||||
scene.objects['Stop-Hl'].setVisible(False,False)
|
||||
scene.objects['Raz-vue-Hl'].setVisible(False,False)
|
||||
scene.objects['Aide-cmd-Hl'].setVisible(False,False)
|
||||
|
||||
# Le highlight des commandes
|
||||
def cmd_hl(cont):
|
||||
obj = cont.owner
|
||||
|
||||
# Activation
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['Systeme']['manip_mode']==0:
|
||||
if obj.name!="Run" and obj.name!="Pause" and obj.name!="Run-Hl" and obj.name!="Pause-Hl" and obj.name!="Stop" and obj.name!="Stop-Hl":
|
||||
obj.setVisible(False,True)
|
||||
scene.objects[obj.name+'-Hl'].setVisible(True,True)
|
||||
|
||||
# Run et pause
|
||||
if obj.name=="Pause" or obj.name=="Run":
|
||||
if scene.objects['Systeme']['run'] == True:
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(True,False)
|
||||
else:
|
||||
scene.objects['Run'].setVisible(False,False)
|
||||
scene.objects['Run-Hl'].setVisible(True,False)
|
||||
|
||||
# Stop
|
||||
if obj.name=="Stop":
|
||||
if scene.objects['Systeme']['thread_run']==True:
|
||||
scene.objects['Stop'].setVisible(False,False)
|
||||
scene.objects['Stop-Hl'].setVisible(True,False)
|
||||
|
||||
# Désactivation
|
||||
if cont.sensors['MO'].status == JUST_RELEASED and scene.objects['Systeme']['manip_mode']==0:
|
||||
if obj.name!="Run" and obj.name!="Pause" and obj.name!="Run-Hl" and obj.name!="Pause-Hl" and obj.name!="Stop" and obj.name!="Stop-Hl":
|
||||
scene.objects[obj.name+'-Hl'].setVisible(False,True)
|
||||
obj.setVisible(True,True)
|
||||
|
||||
# Run et pause
|
||||
if obj.name=="Pause" or obj.name=="Run":
|
||||
if scene.objects['Systeme']['run'] == True:
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Pause'].setVisible(True,False)
|
||||
else:
|
||||
scene.objects['Run-Hl'].setVisible(False,False)
|
||||
scene.objects['Run'].setVisible(True,False)
|
||||
|
||||
# Stop
|
||||
if obj.name=="Stop":
|
||||
if scene.objects['Systeme']['thread_run']==True:
|
||||
scene.objects['Stop-Hl'].setVisible(False,False)
|
||||
scene.objects['Stop'].setVisible(True,False)
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Gestion du clavier
|
||||
###############################################################################
|
||||
|
||||
# Mode : Pan(1) avec Shift, Zoom (2) avec Ctrl, Orbit (0),
|
||||
def mode(cont):
|
||||
obj = cont.owner
|
||||
keyboard = bge.logic.keyboard
|
||||
|
||||
# Shift -> mode 1 : Pan (clic milieu)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.LEFTSHIFTKEY].queue:
|
||||
obj['manip_mode']=1
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.RIGHTSHIFTKEY].queue:
|
||||
obj['manip_mode']=1
|
||||
|
||||
# Ctrl -> mode 2 : Zoom (clic milieu)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.LEFTCTRLKEY].queue:
|
||||
obj['manip_mode']=2
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.RIGHTCTRLKEY].queue:
|
||||
obj['manip_mode']=2
|
||||
|
||||
# Pas de modificateur -> mode 0 : Orbit (clic milieu)
|
||||
if JUST_RELEASED in keyboard.inputs[bge.events.LEFTSHIFTKEY].queue:
|
||||
obj['manip_mode']=0
|
||||
if JUST_RELEASED in keyboard.inputs[bge.events.RIGHTSHIFTKEY].queue:
|
||||
obj['manip_mode']=0
|
||||
if JUST_RELEASED in keyboard.inputs[bge.events.LEFTCTRLKEY].queue:
|
||||
obj['manip_mode']=0
|
||||
if JUST_RELEASED in keyboard.inputs[bge.events.RIGHTCTRLKEY].queue:
|
||||
obj['manip_mode']=0
|
||||
|
||||
# Touche Home -> Reset de la vue
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.HOMEKEY].queue:
|
||||
scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['init_lx']
|
||||
scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly']
|
||||
scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz']
|
||||
applyRotationTo(scene.objects['Systeme'], 0, 0, 0)
|
||||
|
||||
# Touche F5 -> Run et Pause
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.F5KEY].queue:
|
||||
if scene.objects['Systeme']['run'] == True:
|
||||
scene.objects['Systeme']['run']=False
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Run'].setVisible(True,False)
|
||||
else:
|
||||
scene.objects['Systeme']['run']=True
|
||||
scene.objects['Run'].setVisible(False,False)
|
||||
scene.objects['Pause'].setVisible(True,False)
|
||||
if scene.objects['Systeme']['thread_run']==False: # Lancement du thread utilisateur
|
||||
scene.objects['Stop'].setVisible(True,False)
|
||||
importlib.reload(porcou_cmd) # Lecture dynamique du script python
|
||||
porcou_cmd.start()
|
||||
|
||||
# Touche F6 -> Stop / Init
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.F6KEY].queue:
|
||||
if scene.objects['Systeme']['thread_run']==True:
|
||||
|
||||
# Arrêt du thread utilisateur
|
||||
scene.objects['Systeme']['run']=False
|
||||
scene.objects['Systeme']['thread_run']=False
|
||||
porcou_cmd.stop()
|
||||
|
||||
# Commandes
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Run'].setVisible(True,False)
|
||||
scene.objects['Stop'].setVisible(False,False)
|
||||
scene.objects['Stop-Hl'].setVisible(False,False)
|
||||
|
||||
# Grille à l'état initial
|
||||
# applyRotationTo(scene.objects['Systeme'], 0, 0, 0)
|
||||
scene.objects['Portail'].worldPosition.x = scene.objects['Portail']['init_lx']
|
||||
scene.objects['Portail'].worldPosition.y = scene.objects['Portail']['init_ly']
|
||||
scene.objects['Portail'].worldPosition.z = scene.objects['Portail']['init_lz']
|
||||
|
||||
# Moteur à l'état initial
|
||||
rres=0.001 # resolution rotation
|
||||
obj1=scene.objects['Engrenage']
|
||||
while (obj1.localOrientation.to_euler().y) > 1.1*rres :
|
||||
obj1.applyRotation((0, 0, -rres), True)
|
||||
while (obj1.localOrientation.to_euler().y) < -1.1*rres :
|
||||
obj1.applyRotation((0, 0, rres), True)
|
||||
|
||||
# Led à l'état initial
|
||||
scene.objects['Led'].setVisible(True,False)
|
||||
scene.objects['Led allumee'].setVisible(False,False)
|
||||
|
||||
# Capteur barrage IR
|
||||
scene.objects['Emetteur IR Led'].setVisible(True,False)
|
||||
scene.objects['Emetteur IR Led allumee'].setVisible(False,False)
|
||||
scene.objects['Emetteur IR'].color = couleur_magenta
|
||||
scene.objects['Recepteur IR'].color = couleur_magenta
|
||||
|
||||
# I/O à l'état initial
|
||||
scene.objects['Module led']['actif']=False
|
||||
scene.objects['Ensemble moteur']['actif_ouvrir']=False
|
||||
scene.objects['Ensemble moteur']['actif_fermer']=False
|
||||
scene.objects['Capteur fdc ouvert']['actif'] =True
|
||||
scene.objects['Capteur fdc ferme']['actif'] =False
|
||||
scene.objects['Module emetteur IR']['actif'] =False
|
||||
scene.objects['Module recepteur IR']['actif'] =False
|
||||
scene.objects['Module bouton cote rue']['actif'] =False
|
||||
scene.objects['Module bouton cote cour']['actif'] =False
|
||||
|
||||
# Touche F7 -> Mode pas à pas (FIXME)
|
||||
# if JUST_ACTIVATED in keyboard.inputs[bge.events.F7KEY].queue:
|
||||
# if scene.objects['Systeme']['run'] == False:
|
||||
# scene.objects['Systeme']['run']=True
|
||||
# # porcou_cmd.main()
|
||||
# scene.objects['Systeme']['run']=False
|
||||
|
||||
###############################################################################
|
||||
# Manipulation 3D du système
|
||||
###############################################################################
|
||||
|
||||
# Mémorisation de la position et orientation initiales du modèle 3D et de la caméra
|
||||
def manip_init(cont):
|
||||
scene.objects['Camera']['init_lx']=scene.objects['Camera'].worldPosition.x
|
||||
scene.objects['Camera']['init_ly']=scene.objects['Camera'].worldPosition.y
|
||||
scene.objects['Camera']['init_lz']=scene.objects['Camera'].worldPosition.z
|
||||
scene.objects['Systeme']['init_lx']=scene.objects['Systeme'].worldPosition.x
|
||||
scene.objects['Systeme']['init_ly']=scene.objects['Systeme'].worldPosition.y
|
||||
scene.objects['Systeme']['init_lz']=scene.objects['Systeme'].worldPosition.z
|
||||
scene.objects['Systeme']['init_rx']=scene.objects['Systeme'].worldOrientation.to_euler().x
|
||||
scene.objects['Systeme']['init_ry']=scene.objects['Systeme'].worldOrientation.to_euler().y
|
||||
scene.objects['Systeme']['init_rz']=scene.objects['Systeme'].worldOrientation.to_euler().z
|
||||
scene.objects['Portail']['init_lx']=scene.objects['Portail'].worldPosition.x
|
||||
scene.objects['Portail']['init_ly']=scene.objects['Portail'].worldPosition.y
|
||||
scene.objects['Portail']['init_lz']=scene.objects['Portail'].worldPosition.z
|
||||
scene.objects['Engrenage']['init_rx']=scene.objects['Engrenage'].worldOrientation.to_euler().x
|
||||
scene.objects['Engrenage']['init_ry']=scene.objects['Engrenage'].worldOrientation.to_euler().y
|
||||
scene.objects['Engrenage']['init_rz']=scene.objects['Engrenage'].worldOrientation.to_euler().z
|
||||
|
||||
# Atteindre une orientation (bas niveau)
|
||||
def applyRotationTo(obj, rx=None, ry=None, rz=None, Local=True):
|
||||
rres=0.001 # resolution rotation
|
||||
|
||||
# x
|
||||
if rx is not None:
|
||||
while (abs(rx-obj.worldOrientation.to_euler().x) > rres) :
|
||||
if obj.worldOrientation.to_euler().x-rx > rres:
|
||||
obj.applyRotation((-rres, 0, 0), Local)
|
||||
if rx-obj.worldOrientation.to_euler().x > rres:
|
||||
obj.applyRotation((rres, 0, 0), Local)
|
||||
# print ("delta x ",rx-obj.worldOrientation.to_euler().x)
|
||||
|
||||
# y
|
||||
if ry is not None:
|
||||
while (abs(ry-obj.worldOrientation.to_euler().y) > rres) :
|
||||
if obj.worldOrientation.to_euler().y-ry > rres:
|
||||
obj.applyRotation((0, -rres, 0), Local)
|
||||
if ry-obj.worldOrientation.to_euler().y > rres:
|
||||
obj.applyRotation((0, rres, 0), Local)
|
||||
# print ("delta y ",ry-obj.worldOrientation.to_euler().y)
|
||||
|
||||
# z
|
||||
if rz is not None:
|
||||
while (abs(rz-obj.worldOrientation.to_euler().z) > rres) :
|
||||
if obj.worldOrientation.to_euler().z-rz > rres:
|
||||
obj.applyRotation((0, 0, -rres), Local)
|
||||
if rz-obj.worldOrientation.to_euler().z > rres:
|
||||
obj.applyRotation((0, 0, rres), Local)
|
||||
# print ("delta z ",rz-obj.worldOrientation.to_euler().z)
|
||||
|
||||
# Reset de la manipulation de la vue
|
||||
def manip_reset(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Systeme']['manip_mode']==0:
|
||||
scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['init_lx']
|
||||
scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly']
|
||||
scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz']
|
||||
applyRotationTo(scene.objects['Systeme'], 0, 0, 0)
|
||||
|
||||
# Position de départ pour la manipulation de la vue
|
||||
def manip_start(cont):
|
||||
obj = cont.owner
|
||||
obj['click_x']=cont.sensors['ClickM'].position[0]
|
||||
obj['click_y']=cont.sensors['ClickM'].position[1]
|
||||
|
||||
# Cacher le cercle de la manipulation Orbit
|
||||
def manip_stop(cont):
|
||||
scene.objects['Orbit'].setVisible(False,False)
|
||||
|
||||
# Manipulation du modèle ou de la caméra
|
||||
def manip(cont):
|
||||
obj = cont.owner
|
||||
sensibilite_orbit=0.0005
|
||||
sensibilite_pan=0.005
|
||||
sensibilite_zoom=0.01
|
||||
delta_x=cont.sensors['DownM'].position[0]-obj['click_x']
|
||||
delta_y=cont.sensors['DownM'].position[1]-obj['click_y']
|
||||
|
||||
# Orbit (1280 * 720 px)
|
||||
if obj['manip_mode']==0:
|
||||
scene.objects['Orbit'].color=couleur_cmd
|
||||
scene.objects['Orbit'].setVisible(True,False)
|
||||
dist_orbit = math.sqrt(((1280/2)-obj['click_x'])**2+((720/2)-obj['click_y'])**2)
|
||||
if dist_orbit<235 : # Orbit sur x et z
|
||||
n=10
|
||||
pas_x=(delta_x*40*sensibilite_orbit)/n
|
||||
pas_y=(((1280/2)-cont.sensors['DownM'].position[0])+((720/2)-cont.sensors['DownM'].position[1]))*0.005
|
||||
pas_z=(delta_y*40*sensibilite_orbit)/n
|
||||
for i in range (n):
|
||||
bge.render.drawLine([scene.objects['Orbit'].worldPosition.x+pas_x*i, scene.objects['Orbit'].worldPosition.y+abs(pas_y*math.sin((3.14*i)/n)), scene.objects['Orbit'].worldPosition.z-pas_z*i],
|
||||
[scene.objects['Orbit'].worldPosition.x+pas_x*(i+1), scene.objects['Orbit'].worldPosition.y+abs(pas_y*math.sin((3.14*(i+1))/n)), scene.objects['Orbit'].worldPosition.z-pas_z*(i+1)],
|
||||
[0.8, 0.619, 0.021])
|
||||
scene.objects['Systeme'].applyRotation((delta_y*sensibilite_orbit, 0, delta_x*sensibilite_orbit), True)
|
||||
else: # Orbit sur y
|
||||
scene.objects['Orbit'].color=couleur_cmd_hl
|
||||
if abs(delta_x) >= abs(delta_y):
|
||||
scene.objects['Systeme'].applyRotation((0, delta_x*sensibilite_orbit, 0), True)
|
||||
else:
|
||||
scene.objects['Systeme'].applyRotation((0, delta_y*sensibilite_orbit, 0), True)
|
||||
|
||||
# Pan
|
||||
if obj['manip_mode']==1: # Shift
|
||||
scene.objects['Camera'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan, 0), True)
|
||||
|
||||
# Zoom
|
||||
if obj['manip_mode']==2: # Ctrl
|
||||
scene.objects['Camera'].applyMovement((0, 0, (delta_x+delta_y)*sensibilite_zoom), True)
|
||||
|
||||
# Manipulation du modèle ou de la caméra
|
||||
def manip_wheel(cont):
|
||||
obj = cont.owner
|
||||
sensibilite_wheel = 20
|
||||
if cont.sensors['WheelUp'].positive:
|
||||
scene.objects['Camera'].applyMovement((0, 0, -sensibilite_wheel), True)
|
||||
if cont.sensors['WheelDown'].positive:
|
||||
scene.objects['Camera'].applyMovement((0, 0, sensibilite_wheel), True)
|
||||
|
||||
###############################################################################
|
||||
# Aide
|
||||
###############################################################################
|
||||
|
||||
# Ouvrir la page d'aide
|
||||
def aide(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
||||
# scene.replace('Scene-Aide') # Bug Eevee -> même scene mais camera différente
|
||||
scene.active_camera=scene.objects['Aide-Camera']
|
||||
scene.objects['Apropos-Lien_projet'].color= couleur_lien
|
||||
scene.objects['Apropos-Lien_maquette'].color= couleur_lien
|
||||
scene.objects['Apropos-Lien_a4'].color= couleur_lien
|
||||
scene.objects['Apropos-Lien_blender'].color= couleur_lien
|
||||
scene.objects['Apropos-Lien_upbge'].color= couleur_lien
|
||||
scene.objects['Apropos-Lien_cc'].color= couleur_lien
|
||||
scene.objects['Apropos-Lien_gpl'].color= couleur_lien
|
||||
|
||||
# Fermer la page d'aide
|
||||
def aide_fermer(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
||||
# bge.logic.addScene('Scene') # Bug Eevee -> même scene mais camera différente
|
||||
scene.active_camera=scene.objects['Camera']
|
||||
|
||||
# Aller sur les liens
|
||||
def aide_apropos(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
||||
obj = cont.owner
|
||||
if obj.name == "Apropos-Lien_maquette" :
|
||||
webbrowser.open('https://www.a4.fr/wiki/')
|
||||
if obj.name == "Apropos-Lien_projet" :
|
||||
webbrowser.open('https://gitlab.com/blender-edutech')
|
||||
if obj.name == "Apropos-Lien_a4" :
|
||||
webbrowser.open('https://www.a4.fr')
|
||||
if obj.name == "Apropos-Lien_blender" :
|
||||
webbrowser.open('https://blender.org')
|
||||
if obj.name == "Apropos-Lien_upbge" :
|
||||
webbrowser.open('https://upbge.org')
|
||||
if obj.name == "Apropos-Lien_cc" :
|
||||
webbrowser.open('https://creativecommons.org/licenses/by-sa/4.0/')
|
||||
if obj.name == "Apropos-Lien_gpl" :
|
||||
webbrowser.open('https://www.gnu.org/licenses/gpl-3.0.html')
|
||||
|
||||
# Le highlight des liens
|
||||
def aide_apropos_hl(cont):
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED :
|
||||
obj = cont.owner
|
||||
obj.color = couleur_lien_hl
|
||||
if cont.sensors['MO'].status == JUST_RELEASED :
|
||||
obj = cont.owner
|
||||
obj.color = couleur_lien
|
||||
|
@ -4,6 +4,9 @@ import trace
|
||||
import sys
|
||||
import time
|
||||
|
||||
# import serial # Liaison série (jumeau numérique)
|
||||
# from serial.tools.list_ports import comports # Détection du port automatique
|
||||
|
||||
###############################################################################
|
||||
# porcou_lib.py
|
||||
# @title: Bibliothèque utilisateur du portail coulissant (pcl_*)
|
||||
@ -15,9 +18,22 @@ import time
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
# Récupérer l'objet portail coulissant
|
||||
scene = bge.logic.getCurrentScene()
|
||||
# print("Objets de la scene : ", scene.objects)
|
||||
debug_mvt = scene.objects['System']['debug_mvt']
|
||||
|
||||
# Threads
|
||||
threads_cmd=[]
|
||||
threads_gostore=[]
|
||||
debug_thread = scene.objects['System']['debug_thread']
|
||||
|
||||
# Jumeau numérique
|
||||
# twins_serial = None
|
||||
|
||||
# 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
|
||||
|
||||
###############################################################################
|
||||
# Méthode kill pour les tâches (threads)
|
||||
@ -57,34 +73,68 @@ class thread_with_trace(threading.Thread):
|
||||
# Start et stop des tâches (threads)
|
||||
###############################################################################
|
||||
|
||||
def thread_start(threads, commandes):
|
||||
threads.append(thread_with_trace(target = commandes))
|
||||
def thread_start(threads, type_txt, fct):
|
||||
threads.append(thread_with_trace(target = fct))
|
||||
threads[len(threads)-1].start()
|
||||
scene.objects['Systeme']['thread_run']=True
|
||||
scene.objects['Systeme']['thread_alive']=True
|
||||
print ("Thread #", len(threads)-1, "ouvert.")
|
||||
if (debug_thread):
|
||||
print ("Thread",type_txt, "#", len(threads)-1, "open.")
|
||||
|
||||
def thread_stop(threads):
|
||||
def thread_stop(threads, type_txt):
|
||||
i=0
|
||||
zombie_flag=False
|
||||
for t in threads:
|
||||
if not t.is_alive():
|
||||
print ("Thread #",i,"fermé.")
|
||||
if (debug_thread):
|
||||
print ("Thread",type_txt, "#",i,"closed.")
|
||||
else:
|
||||
print ("Thread #",i,"encore ouvert ...")
|
||||
if (debug_thread):
|
||||
print ("Thread",type_txt, "#",i,"still open ...")
|
||||
t.kill()
|
||||
t.join()
|
||||
if not t.is_alive():
|
||||
print ("Thread #",i,"tué.")
|
||||
if (debug_thread):
|
||||
print ("Thread",type_txt, "#",i,"killed.")
|
||||
else:
|
||||
print ("Thread #",i,"zombie ...")
|
||||
if (debug_thread):
|
||||
print ("Thread",type_txt, "#",i,"zombie...")
|
||||
zombie_flag=True
|
||||
i +=1
|
||||
if zombie_flag==False:
|
||||
scene.objects['Systeme']['thread_alive']=False
|
||||
print ("Tous les threads sont fermés.")
|
||||
if (debug_thread):
|
||||
print ("All threads",type_txt, "are closed.")
|
||||
scene.objects['System']['thread_cmd']=False
|
||||
return True
|
||||
else:
|
||||
print ("Il reste des threads zombies.")
|
||||
if (debug_thread):
|
||||
print ("There are zombies threads",type_txt, ".")
|
||||
return False
|
||||
|
||||
def thread_cmd_start(fct):
|
||||
thread_start(threads_cmd, "commands", fct)
|
||||
|
||||
def thread_cmd_stop():
|
||||
thread_stop(threads_cmd, "commands")
|
||||
|
||||
def porcou_end():
|
||||
|
||||
# Jumeau numérique
|
||||
# if scene.objects['Commands']['twins']:
|
||||
# serial_msg = "FI\n"
|
||||
# twins_serial.write(serial_msg.encode()) # Communication série : modele 3d -> carte communication ( arduino | micro:bit )
|
||||
# rp_jumeau_close()
|
||||
|
||||
# Thread
|
||||
if (debug_thread):
|
||||
print ("Thread commands is arrived.")
|
||||
time.sleep(0.125)
|
||||
scene.objects['System']['thread_cmd']=False
|
||||
time.sleep(0.125)
|
||||
|
||||
def porcou_fin():
|
||||
porcou_end()
|
||||
|
||||
def porcou_quit():
|
||||
porcou_end()
|
||||
|
||||
###############################################################################
|
||||
# Actionneurs
|
||||
|
Binary file not shown.
239
twin.py
239
twin.py
@ -1,15 +1,17 @@
|
||||
import bge # Blender Game Engine (UPBGE)
|
||||
import bpy # Blender
|
||||
import webbrowser
|
||||
import sys
|
||||
import math
|
||||
import xml.etree.ElementTree as ET # Creating/parsing XML file
|
||||
import runpy # Exécution de script Python légère (sans import)
|
||||
from pylint import epylint as lint # Mesure de la qualité d'un code Python
|
||||
|
||||
import twin_doc # Documentation
|
||||
import twin_about # About
|
||||
|
||||
###############################################################################
|
||||
# twin.py
|
||||
# @title: Bibliothèque générale du l'environnement 3D pour le développement de jumeau numérique
|
||||
# @title: Bibliothèque générale de l'environnement 3D pour le développement de jumeau numérique
|
||||
# @project: Blender-EduTech
|
||||
# @lang: fr
|
||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
@ -21,9 +23,15 @@ import twin_about # About
|
||||
###############################################################################
|
||||
|
||||
# UPBGE scene
|
||||
eevee = bpy.context.scene.eevee
|
||||
scene = bge.logic.getCurrentScene()
|
||||
# print("Objets de la scene : ", scene.objects)
|
||||
# scene.objects['Commands']['debug_fps']=False
|
||||
|
||||
# Memory
|
||||
sys.setrecursionlimit(10**5) # Limite sur la récursivité (valeur par défaut : 1000) -> segfault de Blender
|
||||
|
||||
# EEVEE
|
||||
eevee = bpy.context.scene.eevee
|
||||
# fps_time=0.0
|
||||
|
||||
# Config file
|
||||
twin_config = ET.parse('twin_config.xml')
|
||||
@ -32,8 +40,6 @@ twin_config_tree = twin_config.getroot()
|
||||
# Couleurs
|
||||
color_cmd = [0.8, 0.8, 0.8, 1] # Blanc
|
||||
color_cmd_hl = [0.8, 0.619, 0.021, 1] # Jaune
|
||||
color_rep_enabled = [0.8, 0.8, 0.8, 1] # Blanc
|
||||
color_rep_disabled = [0, 0, 0, 1] # Noir
|
||||
|
||||
# Constantes
|
||||
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
||||
@ -91,16 +97,13 @@ def keyboard(cont):
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.HOMEKEY].queue:
|
||||
manip_reset()
|
||||
|
||||
# Touche Space -> Play et Pause
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.SPACEKEY].queue:
|
||||
if scene.objects['System']['anim'] == True:
|
||||
# anim_pause()
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Play'].setVisible(True,False)
|
||||
else:
|
||||
# anim_play()
|
||||
scene.objects['Play'].setVisible(False,False)
|
||||
scene.objects['Pause'].setVisible(True,False)
|
||||
# Touche F5 -> Run et Pause
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.F5KEY].queue:
|
||||
cycle_run ()
|
||||
|
||||
# Touche F6 -> Stop / Init
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.F6KEY].queue:
|
||||
cycle_stop ()
|
||||
|
||||
###############################################################################
|
||||
# Commandes
|
||||
@ -113,9 +116,9 @@ def keyboard(cont):
|
||||
def cmd_init():
|
||||
# Fichier de config (screen size : data/config/screen/width-> [0][0].text, height-> [0][1].text)
|
||||
bge.render.setWindowSize(int(twin_config_tree[0][0].text),int(twin_config_tree[0][1].text))
|
||||
scene.objects['Play-Hl'].setVisible(False,False)
|
||||
scene.objects['Run-Hl'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Reset-view-Hl'].setVisible(False,False)
|
||||
scene.objects['ResetView-Hl'].setVisible(False,False)
|
||||
scene.objects['Doc-cmd-Hl'].setVisible(False,False)
|
||||
scene.objects['About-cmd-Hl'].setVisible(False,False)
|
||||
|
||||
@ -128,34 +131,75 @@ def cmd_hl(cont):
|
||||
|
||||
# Activation
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['System']['manip_mode']==0:
|
||||
if obj.name!="Play" and obj.name!="Pause" and obj.name!="Play-Hl" and obj.name!="Pause-Hl":
|
||||
if obj.name!="Run" and obj.name!="Pause" and obj.name!="Run-Hl" and obj.name!="Pause-Hl":
|
||||
obj.setVisible(False,True)
|
||||
scene.objects[obj.name+'-Hl'].setVisible(True,True)
|
||||
# obj.color = color_cmd_hl
|
||||
|
||||
# Play et pause
|
||||
if obj.name=="Pause" or obj.name=="Play":
|
||||
if scene.objects['System']['anim'] == True:
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(True,False)
|
||||
# Run et pause
|
||||
if obj.name=="Pause" or obj.name=="Run":
|
||||
if scene.objects['System']['run'] == True:
|
||||
pass
|
||||
# scene.objects['Pause'].setVisible(False,False) FIXME pause pas implémenté
|
||||
# scene.objects['Pause-Hl'].setVisible(True,False) FIXME pause pas implémenté
|
||||
else:
|
||||
scene.objects['Play'].setVisible(False,False)
|
||||
scene.objects['Play-Hl'].setVisible(True,False)
|
||||
scene.objects['Run'].setVisible(False,False)
|
||||
scene.objects['Run-Hl'].setVisible(True,False)
|
||||
|
||||
# Stop
|
||||
if obj.name=="Stop":
|
||||
scene.objects['Stop'].setVisible(False,False)
|
||||
scene.objects['Stop-Hl'].setVisible(True,False)
|
||||
|
||||
# Doc
|
||||
if obj.name=="Doc-cmd-colbox":
|
||||
scene.objects['Doc-cmd'].setVisible(False,False)
|
||||
scene.objects['Doc-cmd-Hl'].setVisible(True,False)
|
||||
|
||||
# Text
|
||||
# text_hl ={"Run":"Exécuter (F5)",
|
||||
# "Stop":"Stop et initialisation (F6)",
|
||||
# "Pause":"Pause (F5)",
|
||||
# "Aim-cmd":"Afficher/cacher l'objectif",
|
||||
# "Doc-cmd-colbox":"Documentation",
|
||||
# "Store-cmd":"Boutique",
|
||||
# "Task-cmd":"Liste des tâches",
|
||||
# "Task_close-cmd":"Fermer la liste des tâches",
|
||||
# "ResetView": "Reset de la vue (Touche Début)",
|
||||
# "About-cmd": "A propos",
|
||||
# "Speed_down": "Moins vite (-)",
|
||||
# "Speed_up": "Plus vite (+)",
|
||||
# "Sound-cmd": "Muet",
|
||||
# "NoSound-cmd": "Rétablir le son"}
|
||||
# scene.objects['Cmd-text']['Text']= text_hl[obj.name]
|
||||
# scene.objects['Cmd-text'].setVisible(True,False)
|
||||
|
||||
# Désactivation
|
||||
if cont.sensors['MO'].status == JUST_RELEASED and scene.objects['System']['manip_mode']==0:
|
||||
if obj.name!="Play" and obj.name!="Pause" and obj.name!="Play-Hl" and obj.name!="Pause-Hl":
|
||||
if cont.sensors['MO'].status == JUST_RELEASED and (scene.objects['System']['manip_mode']==0 or scene.objects['System']['manip_mode']==9):
|
||||
# scene.objects['Cmd-text']['Text']= ""
|
||||
# scene.objects['Cmd-text'].setVisible(False,False)
|
||||
if obj.name!="Run" and obj.name!="Pause" and obj.name!="Stop" and obj.name!="Doc-cmd-colbox":
|
||||
scene.objects[obj.name+'-Hl'].setVisible(False,True)
|
||||
obj.setVisible(True,True)
|
||||
|
||||
# Play et pause
|
||||
if obj.name=="Pause" or obj.name=="Play":
|
||||
if scene.objects['System']['anim'] == True:
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Pause'].setVisible(True,False)
|
||||
# Run et pause
|
||||
if obj.name=="Pause" or obj.name=="Run":
|
||||
if scene.objects['System']['run'] == True:
|
||||
pass
|
||||
# scene.objects['Pause-Hl'].setVisible(False,False) FIXME pause pas implémenté
|
||||
# scene.objects['Pause'].setVisible(True,False) FIXME pause pas implémenté
|
||||
else:
|
||||
scene.objects['Play-Hl'].setVisible(False,False)
|
||||
scene.objects['Play'].setVisible(True,False)
|
||||
scene.objects['Run-Hl'].setVisible(False,False)
|
||||
scene.objects['Run'].setVisible(True,False)
|
||||
|
||||
# Stop
|
||||
if obj.name=="Stop":
|
||||
scene.objects['Stop-Hl'].setVisible(False,False)
|
||||
scene.objects['Stop'].setVisible(True,False)
|
||||
|
||||
# Doc
|
||||
if obj.name=="Doc-cmd-colbox":
|
||||
scene.objects['Doc-cmd-Hl'].setVisible(False,False)
|
||||
scene.objects['Doc-cmd'].setVisible(True,False)
|
||||
|
||||
##
|
||||
# Click sur les commandes
|
||||
@ -167,43 +211,22 @@ def cmd_click(cont):
|
||||
|
||||
# Play et pause
|
||||
if obj.name=="Pause" or obj.name=="Run":
|
||||
# Pause
|
||||
if scene.objects['System']['anim'] == True:
|
||||
anim_pause()
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Play-Hl'].setVisible(True,False)
|
||||
else:
|
||||
# Play
|
||||
anim_play()
|
||||
scene.objects['Play'].setVisible(False,False)
|
||||
scene.objects['Play-Hl'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(True,False)
|
||||
cycle_run ()
|
||||
|
||||
# Reset-colors
|
||||
if obj.name=="Reset-colors" :
|
||||
color_reset()
|
||||
# Stop
|
||||
if obj.name=="Stop":
|
||||
cycle_stop ()
|
||||
|
||||
# Reset-view
|
||||
if obj.name=="Reset-view" :
|
||||
if obj.name=="ResetView" :
|
||||
manip_reset()
|
||||
|
||||
# About
|
||||
if obj.name=="About-cmd" :
|
||||
# if scene.objects['System']['anim'] == True: # Rendu meilleur en pause
|
||||
# scene.objects['About']['anim']= True
|
||||
# anim_pause()
|
||||
# else:
|
||||
# scene.objects['About']['anim'] = False
|
||||
twin_about.open()
|
||||
|
||||
# Aide
|
||||
if obj.name=="Help-cmd" :
|
||||
# if scene.objects['System']['anim'] == True: # Rendu meilleur en pause
|
||||
# scene.objects['Doc']['anim']= True
|
||||
# anim_pause()
|
||||
# else:
|
||||
# scene.objects['Doc']['anim'] = False
|
||||
twin_doc.open()
|
||||
|
||||
###############################################################################
|
||||
@ -241,19 +264,6 @@ def manip_init():
|
||||
scene.objects['About'].setVisible(False,True)
|
||||
scene.objects['Doc'].setVisible(False,True)
|
||||
|
||||
# Mémorisation de la position des composants
|
||||
for objet in scene.objects['System']['objects'] :
|
||||
scene.objects[objet]['init_lx']=scene.objects[objet].worldPosition.x
|
||||
scene.objects[objet]['init_ly']=scene.objects[objet].worldPosition.y
|
||||
scene.objects[objet]['init_lz']=scene.objects[objet].worldPosition.z
|
||||
|
||||
if 'init_rx' in scene.objects[objet]:
|
||||
scene.objects[objet]['init_rx'] = scene.objects[objet].worldOrientation.to_euler().x
|
||||
if 'init_ry' in scene.objects[objet]:
|
||||
scene.objects[objet]['init_ry'] = scene.objects[objet].worldOrientation.to_euler().y
|
||||
if 'init_rz' in scene.objects[objet]:
|
||||
scene.objects[objet]['init_rz'] = scene.objects[objet].worldOrientation.to_euler().z
|
||||
|
||||
# Mémorisation de la position de la caméra
|
||||
scene.objects['Camera']['init_lx']=scene.objects['Camera'].worldPosition.x
|
||||
scene.objects['Camera']['init_ly']=scene.objects['Camera'].worldPosition.y
|
||||
@ -395,3 +405,82 @@ def manip_wheel(cont):
|
||||
scene.objects['Camera'].applyMovement((0, 0, -sensibilite_wheel), True)
|
||||
if cont.sensors['WheelDown'].positive:
|
||||
scene.objects['Camera'].applyMovement((0, 0, sensibilite_wheel), True)
|
||||
|
||||
###############################################################################
|
||||
# Cycle
|
||||
###############################################################################
|
||||
|
||||
|
||||
##
|
||||
# Mise en route et pause du cycle
|
||||
##
|
||||
|
||||
def python_validation():
|
||||
(pylint_stdout, pylint_stderr) = lint.py_run('porcou_cmd.py --disable=C --disable=W --disable=R', return_std=True)
|
||||
stdout = pylint_stdout.read()
|
||||
stderr = pylint_stderr.read()
|
||||
if " error (" in stdout: # Présence d'erreur
|
||||
print(stdout)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def cycle_run ():
|
||||
|
||||
# Pause
|
||||
if scene.objects['System']['run'] == True:
|
||||
scene.objects['System']['run']=False
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Pause'].suspendPhysics()
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Run'].restorePhysics()
|
||||
scene.objects['Run-Hl'].setVisible(True,False)
|
||||
|
||||
# Run
|
||||
else :
|
||||
scene.objects['System']['run']=True
|
||||
scene.objects['Run'].setVisible(False,False)
|
||||
scene.objects['Run'].suspendPhysics()
|
||||
scene.objects['Run-Hl'].setVisible(False,False)
|
||||
# scene.objects['Pause']. restorePhysics() # FIXME pause pas implémentée
|
||||
# scene.objects['Pause'].setVisible(True,False) # FIXME pause pas implémentée
|
||||
|
||||
# Démarrage du cycle
|
||||
if scene.objects['System']['thread_cmd']==False:
|
||||
time.sleep(0.125)
|
||||
scene.objects['System']['thread_cmd']=True
|
||||
rp_map.map_reset()
|
||||
time.sleep(0.125)
|
||||
if python_validation():
|
||||
runpy.run_module('porcou_cmd', run_name='start') # Execution du script utilisateur
|
||||
|
||||
# Arrêt de la pause
|
||||
else:
|
||||
# FIXME : Relancer Ropy
|
||||
pass
|
||||
|
||||
##
|
||||
# Arrêt et réinitialisation du cycle (forçage)
|
||||
##
|
||||
|
||||
def cycle_stop ():
|
||||
scene.objects['System']['thread_cmd']=False
|
||||
porcou.system_reset()
|
||||
|
||||
##
|
||||
# Fin naturelle du cycle
|
||||
##
|
||||
|
||||
def cycle_end (cont):
|
||||
if cont.sensors['End cycle'].positive:
|
||||
scene.objects['System']['run']=False
|
||||
if python_validation():
|
||||
runpy.run_module('porcou_cmd', run_name='stop') # Fin du script utilisateur
|
||||
|
||||
# Commandes
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Pause'].suspendPhysics()
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Run'].setVisible(True,False)
|
||||
scene.objects['Run'].restorePhysics()
|
||||
|
||||
|
@ -60,20 +60,6 @@ def open():
|
||||
|
||||
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)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<data>
|
||||
<screen>
|
||||
<width>1280</width>
|
||||
<height>720</height>
|
||||
<width>1375</width>
|
||||
<height>774</height>
|
||||
</screen>
|
||||
</data>
|
14
twin_doc.py
14
twin_doc.py
@ -35,20 +35,6 @@ def open():
|
||||
|
||||
def close(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
||||
# if scene.objects['Doc']['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['Doc']['anim'] == False
|
||||
scene.active_camera = scene.objects["Camera"]
|
||||
scene.objects['Doc'].setVisible(False,True)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user