mirror of
https://forge.apps.education.fr/blender-edutech/lecteur-3d-cinematique.git
synced 2024-01-27 09:43:12 +01:00
Migration de la serrure et le l'hémomixer
This commit is contained in:
parent
8fd03b52a2
commit
348c4df304
BIN
hemomixer/hemomixer-12.blend
Normal file
BIN
hemomixer/hemomixer-12.blend
Normal file
Binary file not shown.
@ -1,10 +1,9 @@
|
||||
import bge # Bibliothèque Blender Game Engine (BGE)
|
||||
import webbrowser
|
||||
import math
|
||||
import cine # Bibliothèque du player 3d d'analyse de cinématique
|
||||
|
||||
###############################################################################
|
||||
# batoncolle.py
|
||||
# @title: Commandes pour le player 3D de l'hémomixer (système de clampage)
|
||||
# hemomixer.py
|
||||
# @title: Player 3D cinématique du système de clampage de l'hémomixer
|
||||
# @project: Blender-EduTech
|
||||
# @lang: fr
|
||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
@ -20,34 +19,77 @@ import math
|
||||
|
||||
# Récupérer la scène 3D
|
||||
scene = bge.logic.getCurrentScene()
|
||||
# print("Objets de la scene : ", scene.objects)
|
||||
|
||||
# Objets 3D
|
||||
###############################################################################
|
||||
# Mécanisme
|
||||
###############################################################################
|
||||
|
||||
objets=['Bloc clampeur', 'Disque', 'Moteur', 'Réducteur', 'Tige clampeur', 'Axe 1', 'Ressort', 'Palonnier', 'Axe réducteur', 'Sabot', 'Support moteur', 'Support clampeur',
|
||||
'Maillon droite', 'Maillon gauche', 'Maillon axe 1', 'Maillon axe 2', 'Guide palonnier', 'Bague 2', 'Bague 1', 'Ecrou 1', 'Ecrou 2', 'Ecrou 3', 'Ecrou 4', 'Ecrou 5', 'Ecrou 6',
|
||||
'Goujon', 'Rondelle 1', 'Rondelle 4', 'Rondelle 2', 'Rondelle 3', 'Vis 5', 'Vis 1', 'Vis 2', 'Vis 3', 'Vis 4', 'Axe 2', 'Circlips 1', 'Circlips 2', 'Circlips 3']
|
||||
# objets_couleur=['VioletF', 'TurquoiseF', 'Couleur7', 'MagentaF', 'Couleur4', 'GrisF', 'Couleur6', 'VertF', 'MagentaF', 'Couleur5', 'Couleur2', 'Couleur1', 'RougeF', 'Couleur3', 'GrisF', 'GrisF',
|
||||
# 'Gris', 'GrisC', 'GrisC', 'Gris', 'Gris', 'Gris', 'Gris', 'Gris', 'Gris', 'GrisF', 'GrisC', 'GrisC', 'GrisC', 'GrisC', 'Gris', 'Gris', 'Gris', 'Gris', 'Gris', 'GrisF', 'Gris', 'Gris', 'Gris']
|
||||
|
||||
objets_anim=['Disque', 'Ressort', 'Palonnier', 'Axe réducteur', 'Maillon gauche', 'Maillon axe 1']
|
||||
# objets=['Bloc clampeur', 'Disque', 'Moteur', 'Réducteur', 'Tige clampeur', 'Axe 1', 'Ressort', 'Palonnier', 'Axe réducteur', 'Sabot', 'Support moteur', 'Support clampeur',
|
||||
# 'Maillon droite', 'Maillon gauche', 'Maillon axe 1', 'Maillon axe 2', 'Guide palonnier', 'Bague 2', 'Bague 1', 'Ecrou 1', 'Ecrou 2', 'Ecrou 3', 'Ecrou 4', 'Ecrou 5', 'Ecrou 6',
|
||||
# 'Goujon', 'Rondelle 1', 'Rondelle 4', 'Rondelle 2', 'Rondelle 3', 'Vis 5', 'Vis 1', 'Vis 2', 'Vis 3', 'Vis 4', 'Axe 2', 'Circlips 1', 'Circlips 2', 'Circlips 3']
|
||||
|
||||
objets_couleur=['VioletF', 'TurquoiseF', 'Couleur7', 'MagentaF', 'Couleur4', 'GrisF', 'Couleur6', 'VertF', 'MagentaF', 'Couleur5', 'Couleur2', 'Couleur1', 'RougeF', 'Couleur3', 'GrisF', 'GrisF',
|
||||
'Gris', 'GrisC', 'GrisC', 'Gris', 'Gris', 'Gris', 'Gris', 'Gris', 'Gris', 'GrisF', 'GrisC', 'GrisC', 'GrisC', 'GrisC', 'Gris', 'Gris', 'Gris', 'Gris', 'Gris', 'GrisF', 'Gris', 'Gris', 'Gris']
|
||||
objects=['Bloc clampeur', 'Disque', 'Moteur', 'Palonnier', 'Ressort', 'Reducteur', 'Sabot',
|
||||
'Support clampeur','Support moteur','Tige clampeur', 'Goujon','Guide palonnier','Axe 1', 'Axe 2','Circlips 1', 'Circlips 2', 'Circlips 3',
|
||||
'Maillon axe 1', 'Maillon axe 2','Maillon droite', 'Maillon gauche','Vis 1', 'Vis 2', 'Vis 3', 'Vis 4', 'Vis 5',
|
||||
'Ecrou 1', 'Ecrou 2', 'Ecrou 3', 'Ecrou 4', 'Ecrou 5', 'Ecrou 6','Rondelle 1', 'Rondelle 2', 'Rondelle 3', 'Rondelle 4','Bague 1','Bague 2', 'Axe reducteur']
|
||||
|
||||
objets_rep=[] # Objet avec un repère
|
||||
objets_rep_dict={}
|
||||
objects_anim=['Disque', 'Ressort', 'Palonnier', 'Axe reducteur', 'Maillon gauche', 'Maillon axe 1']
|
||||
|
||||
objects_dict={'Bloc clampeur' : [1, '1 : Bloc clampeur', 'VioletF', []],
|
||||
'Disque' : [2, '2 : Disque', 'TurquoiseF', []],
|
||||
'Moteur' : [3, '3 : Moteur', 'Couleur7', []],
|
||||
'Palonnier' : [4, '4 : Palonnier', 'VertF', []],
|
||||
'Ressort' : [5, '5 : Ressort', 'Couleur6', []],
|
||||
'Reducteur' : [6, '6 : Réducteur', 'MagentaF', []],
|
||||
'Sabot' : [7, '7 : Sabot', 'Couleur5', []],
|
||||
'Support clampeur' : [8, '8 : Support clampeur', 'Couleur1', []],
|
||||
'Support moteur' : [9, '9 : Support moteur', 'Couleur2', []],
|
||||
'Tige clampeur': [10, '10 : Tige clampeur', 'Couleur4', []],
|
||||
'Goujon': [11, '11 : Goujon', 'GrisF', []],
|
||||
'Guide palonnier': [12, '12 : Guide palonnier', 'Gris', []],
|
||||
'Axe 1': [13, '13 : Axe 1', 'GrisF', []],
|
||||
'Axe 2': [14, '14 : Axe 2', 'GrisF', []],
|
||||
'Circlips 1' : [15, '15 : Circlips 1', 'Gris', []],
|
||||
'Circlips 2': [16, '16 : Circlips 2', 'Gris', []],
|
||||
'Circlips 3': [17, '17 : Circlips 3', 'Gris', []],
|
||||
'Maillon axe 1' : [18, '18 : Maillon axe 1', 'GrisF', []],
|
||||
'Maillon axe 2': [19, '19 : Maillon axe 2', 'GrisF', []],
|
||||
'Maillon droite' : [20, '20 : Maillon droite', 'RougeF', []],
|
||||
'Maillon gauche' : [21, '21 : Maillon gauche', 'Couleur3', []],
|
||||
'Vis 1' : [22, '22 : Vis 1', 'Gris', []],
|
||||
'Vis 2' : [23, '23 : Vis 2', 'Gris', []],
|
||||
'Vis 3' : [24, '24 : Vis 3', 'Gris', []],
|
||||
'Vis 4' : [25, '25 : Vis 4', 'Gris', []],
|
||||
'Vis 5' : [26, '26 : Vis 5', 'Gris', []],
|
||||
'Ecrou 1' : [27, '27 : Ecrou 1', 'Gris', []],
|
||||
'Ecrou 2' : [28, '28 : Ecrou 2', 'Gris', []],
|
||||
'Ecrou 3' : [29, '29 : Ecrou 3', 'Gris', []],
|
||||
'Ecrou 4' : [30, '30 : Ecrou 4', 'Gris', []],
|
||||
'Ecrou 5' : [31, '31 : Ecrou 5', 'Gris', []],
|
||||
'Ecrou 6' : [32, '32 : Ecrou 6', 'Gris', []],
|
||||
'Rondelle 1' : [33, '33 : Rondelle 1', 'GrisC', []],
|
||||
'Rondelle 2' : [34, '34 : Rondelle 2', 'GrisC', []],
|
||||
'Rondelle 3' : [35, '35 : Rondelle 3', 'GrisC', []],
|
||||
'Rondelle 4' : [36, '36 : Rondelle 4', 'GrisC', []],
|
||||
'Bague 1' : [37, '37 : Bague 1', 'GrisC', []],
|
||||
'Bague 2' : [38, '38 : Bague 2', 'GrisC', []],
|
||||
'Axe reducteur' : [39, '39 : Axe réducteur', 'GrisF', []]}
|
||||
|
||||
# Couleurs
|
||||
|
||||
couleurs=[['Couleur1', [0.202, 0.114, 0.512,1]],
|
||||
['Couleur2', [0.051, 0.270, 0.279,1]],
|
||||
['Couleur3', [0.799, 0.031, 0.038,1]],
|
||||
['Couleur4', [0.799, 0.130, 0.063,1]],
|
||||
['Couleur5', [0.8, 0.619, 0.021,1]],
|
||||
['Couleur6', [0.246, 0.687, 0.078,1]],
|
||||
['Couleur7', [0.800, 0.005, 0.315,1]],
|
||||
['Couleur8', [0.75,0.751, 0.75,0]]]
|
||||
colors=[['Couleur1', [0.202, 0.114, 0.512, 1]],
|
||||
['Couleur2', [0.051, 0.270, 0.279, 1]],
|
||||
['Couleur3', [0.799, 0.031, 0.038, 1]],
|
||||
['Couleur4', [0.799, 0.130, 0.063, 1]],
|
||||
['Couleur5', [0.8, 0.619, 0.021, 1]],
|
||||
['Couleur6', [0.246, 0.687, 0.078, 1]],
|
||||
['Couleur7', [0.800, 0.005, 0.315, 1]],
|
||||
['Couleur8', [0.75,0.75, 0.75, 0]]]
|
||||
|
||||
couleurs_dict={'Couleur1' : [0.202, 0.114, 0.512, 1],
|
||||
colors_dict={'Couleur1' : [0.202, 0.114, 0.512, 1],
|
||||
'Couleur2' : [0.051, 0.270, 0.279, 1],
|
||||
'Couleur3' : [0.799, 0.031, 0.038, 1],
|
||||
'Couleur4' : [0.799, 0.130, 0.063, 1],
|
||||
@ -65,635 +107,14 @@ couleurs_dict={'Couleur1' : [0.202, 0.114, 0.512, 1],
|
||||
'GrisC' : [0.501,0.534, 0.621, 1],
|
||||
'Blanc' : [0.8, 0.8, 0.8, 1]}
|
||||
|
||||
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] # bleu
|
||||
|
||||
# Constantes
|
||||
|
||||
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
|
||||
|
||||
###############################################################################
|
||||
# Gestion du clavier
|
||||
###############################################################################
|
||||
|
||||
# Mode : Pan(1) avec Shift, Zoom (2) avec Ctrl, Orbit (0), Eclaté avec Shift
|
||||
def mode(cont):
|
||||
obj = cont.owner
|
||||
keyboard = bge.logic.keyboard
|
||||
|
||||
# Shift -> mode 1 : Pan (clic milieu) ou Eclaté (clic gauche)
|
||||
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['Mecanisme'], 0, 0, 0)
|
||||
for objet in objets :
|
||||
scene.objects[objet].setVisible(True,False)
|
||||
scene.objects[objet+"_Lines.GP"].setVisible(True,False)
|
||||
|
||||
# Retour après éclatement
|
||||
if scene.objects['Mecanisme']['eclate'] ==True:
|
||||
scene.objects['Mecanisme']['eclate'] = False
|
||||
ecla_val = scene.objects['Mecanisme']['ecla_val'] # Retour après éclatement avec la valeur d'éclatement
|
||||
sensibilite=0.005
|
||||
for objet in objets :
|
||||
ecla_x, ecla_y,ecla_z = 0,0,0
|
||||
if 'ecla_x' in scene.objects[objet]:
|
||||
ecla_x = scene.objects[objet]['ecla_x']
|
||||
if 'ecla_y' in scene.objects[objet]:
|
||||
ecla_y = scene.objects[objet]['ecla_y']
|
||||
if 'ecla_z' in scene.objects[objet]:
|
||||
ecla_z = scene.objects[objet]['ecla_z']
|
||||
scene.objects[objet].applyMovement((-ecla_val*sensibilite*ecla_x, -ecla_val*sensibilite*ecla_y , -ecla_val*sensibilite*ecla_z), False)
|
||||
scene.objects['Mecanisme']['ecla_val'] = 0.00
|
||||
if scene.objects['Mecanisme']['anim'] == False: # Play d'une frame
|
||||
anim_play1frame()
|
||||
|
||||
# Touche Space -> Play et Pause
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.SPACEKEY].queue:
|
||||
if scene.objects['Mecanisme']['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 H -> Cacher l'objet
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.HKEY].queue:
|
||||
couleur_choix_num(8)
|
||||
|
||||
# Touche de 1 à 8 -> Couleur de 1 à 8
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.ONEKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD1].queue:
|
||||
couleur_choix_num(1)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.TWOKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD2].queue:
|
||||
couleur_choix_num(2)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.THREEKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD3].queue:
|
||||
couleur_choix_num(3)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.FOURKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD4].queue:
|
||||
couleur_choix_num(4)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.FIVEKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD5].queue:
|
||||
couleur_choix_num(5)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.SIXKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD6].queue:
|
||||
couleur_choix_num(6)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.SEVENKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD7].queue:
|
||||
couleur_choix_num(7)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.EIGHTKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD8].queue:
|
||||
couleur_choix_num(8)
|
||||
|
||||
###############################################################################
|
||||
# Commandes
|
||||
###############################################################################
|
||||
|
||||
# Init
|
||||
def cmd_init():
|
||||
scene.objects['Aide-cmd-Hl'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Play-Hl'].setVisible(False,False)
|
||||
scene.objects['Raz-couleurs-Hl'].setVisible(False,False)
|
||||
scene.objects['Raz-vue-Hl'].setVisible(False,False)
|
||||
for i in range (1, 9):
|
||||
scene.objects['Couleur'+str(i)+"-Hl"].setVisible(False,True)
|
||||
|
||||
# Le highlight des commandes
|
||||
def cmd_hl(cont):
|
||||
obj = cont.owner
|
||||
|
||||
# Activation
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
if obj.name!="Play" and obj.name!="Pause" and obj.name!="Play-Hl" and obj.name!="Pause-Hl":
|
||||
obj.setVisible(False,True)
|
||||
scene.objects[obj.name+'-Hl'].setVisible(True,True)
|
||||
# obj.color = couleur_cmd_hl
|
||||
|
||||
# Play et pause
|
||||
if obj.name=="Pause" or obj.name=="Play":
|
||||
if scene.objects['Mecanisme']['anim'] == True:
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(True,False)
|
||||
else:
|
||||
scene.objects['Play'].setVisible(False,False)
|
||||
scene.objects['Play-Hl'].setVisible(True,False)
|
||||
|
||||
# Désactivation
|
||||
if cont.sensors['MO'].status == JUST_RELEASED and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
if obj.name!="Play" and obj.name!="Pause" and obj.name!="Play-Hl" and obj.name!="Pause-Hl":
|
||||
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['Mecanisme']['anim'] == True:
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Pause'].setVisible(True,False)
|
||||
else:
|
||||
scene.objects['Play-Hl'].setVisible(False,False)
|
||||
scene.objects['Play'].setVisible(True,False)
|
||||
|
||||
###############################################################################
|
||||
# Animation
|
||||
###############################################################################
|
||||
|
||||
# Initialisation de l'animation -> Play
|
||||
def anim_init(cont):
|
||||
start = 1
|
||||
end = 250
|
||||
layer = 0
|
||||
priority = 1
|
||||
blendin = 1.0
|
||||
mode = bge.logic.KX_ACTION_MODE_LOOP
|
||||
layerWeight = 0.0
|
||||
ipoFlags = 0
|
||||
speed = 1.0
|
||||
for objet in objets_anim :
|
||||
scene.objects[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
||||
scene.objects['Play'].setVisible(False,False)
|
||||
scene.objects['Pause'].setVisible(True,False)
|
||||
scene.objects['Mecanisme']['anim'] = True
|
||||
|
||||
# Animation en pause (bas niveau)
|
||||
def anim_pause():
|
||||
layer = 0
|
||||
for objet in objets_anim :
|
||||
scene.objects['Mecanisme']['anim_frame'] = scene.objects[objet].getActionFrame(layer)
|
||||
scene.objects[objet].stopAction(layer)
|
||||
scene.objects['Mecanisme']['anim'] = False
|
||||
|
||||
# Animation en pseudo-pause
|
||||
# Play d'une frame pour remettre les pièces en place
|
||||
def anim_play1frame():
|
||||
start = scene.objects['Mecanisme']['anim_frame']
|
||||
end = scene.objects['Mecanisme']['anim_frame']+1
|
||||
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 objets_anim :
|
||||
scene.objects[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
||||
scene.objects['Mecanisme']['anim_frame'] = end
|
||||
|
||||
# Reprise de l'animation (bas niveau)
|
||||
def anim_play():
|
||||
start = scene.objects['Mecanisme']['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 objets_anim :
|
||||
scene.objects[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
||||
scene.objects['Mecanisme']['anim'] = True
|
||||
|
||||
# Pause et replay par les commandes
|
||||
def anim_cmd(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
|
||||
# Pause
|
||||
if scene.objects['Mecanisme']['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)
|
||||
|
||||
# Play en continu
|
||||
def anim_boucle(cont):
|
||||
if scene.objects['Mecanisme']['anim'] == True and scene.objects[objets_anim[0]].isPlayingAction(0) == False:
|
||||
# scene.objects['Mecanisme']['anim_frame']=1
|
||||
start = 1
|
||||
end = 250
|
||||
layer = 0
|
||||
priority = 1
|
||||
blendin = 1.0
|
||||
mode = bge.logic.KX_ACTION_MODE_LOOP
|
||||
layerWeight = 0.0
|
||||
ipoFlags = 0
|
||||
speed = 1.0
|
||||
for objet in objets_anim :
|
||||
scene.objects[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
||||
|
||||
###############################################################################
|
||||
# Manipulation du mécanisme
|
||||
###############################################################################
|
||||
|
||||
# Mémorisation de la position et orientation initiales du modèle et de la caméra
|
||||
def manip_init(cont):
|
||||
for objet in objets :
|
||||
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
|
||||
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['Mecanisme']['init_lx']=scene.objects['Mecanisme'].worldPosition.x
|
||||
scene.objects['Mecanisme']['init_ly']=scene.objects['Mecanisme'].worldPosition.y
|
||||
scene.objects['Mecanisme']['init_lz']=scene.objects['Mecanisme'].worldPosition.z
|
||||
scene.objects['Mecanisme']['init_rx']=scene.objects['Mecanisme'].worldOrientation.to_euler().x
|
||||
scene.objects['Mecanisme']['init_ry']=scene.objects['Mecanisme'].worldOrientation.to_euler().y
|
||||
scene.objects['Mecanisme']['init_rz']=scene.objects['Mecanisme'].worldOrientation.to_euler().z
|
||||
|
||||
# def applyMovemenTo(obj, lx,ly,lz,rx,ry,rz):
|
||||
# lres=0.001 # resolution location
|
||||
# rres=0.001 # resolution rotation
|
||||
# while (obj.worldPosition.x-lx > lres) or (obj.worldPosition.y-ly > lres) or (obj.worldPosition.z-lz > lres) or (obj.worldOrientation.to_euler().x-rx > rres) or (obj.worldOrientation.to_euler().y-ry > rres) or (obj.worldOrientation.to_euler().z-rz > rres):
|
||||
# if obj.worldPosition.x-lx > lres:
|
||||
# obj. applyMovement(lres,0,0)
|
||||
# if obj.worldPosition.y-ly > lres:
|
||||
# obj. applyMovement(0,lres,0 )
|
||||
# if obj.worldPosition.z-lz > lres:
|
||||
# obj. applyMovement(0,0,lres)
|
||||
# if obj.worldOrientation.to_euler().x-rx > rres:
|
||||
# obj.applyRotation(rres,0,0)
|
||||
# if obj.worldOrientation.to_euler().y-ry > rres:
|
||||
# obj.applyRotation(0,rres,0)
|
||||
# if obj.worldOrientation.to_euler().z-ry > rres:
|
||||
# obj.applyRotation(0,0,rres)
|
||||
|
||||
# def applyTranslationTo(obj, lx,ly,lz):
|
||||
# lres=0.001 # resolution location
|
||||
# while (obj.worldPosition.x-lx > lres) or (obj.worldPosition.y-ly > lres) or (obj.worldPosition.z-lz > lres):
|
||||
# if obj.worldPosition.x-lx > lres:
|
||||
# obj. applyMovement(lres,0,0)
|
||||
# if obj.worldPosition.y-ly > lres:
|
||||
# obj. applyMovement(0,lres,0 )
|
||||
# if obj.worldPosition.z-lz > lres:
|
||||
# obj. applyMovement(0,0,lres)
|
||||
|
||||
# Atteindre une orientation (bas niveau)
|
||||
def applyRotationTo(obj, rx=None, ry=None, rz=None):
|
||||
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), True)
|
||||
if rx-obj.worldOrientation.to_euler().x > rres:
|
||||
obj.applyRotation((rres, 0, 0), True)
|
||||
# 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), True)
|
||||
if ry-obj.worldOrientation.to_euler().y > rres:
|
||||
obj.applyRotation((0, rres, 0), True)
|
||||
# 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), True)
|
||||
if rz-obj.worldOrientation.to_euler().z > rres:
|
||||
obj.applyRotation((0, 0, rres), True)
|
||||
# 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['Mecanisme']['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['Mecanisme'], 0, 0, 0)
|
||||
for objet in objets :
|
||||
scene.objects[objet].setVisible(True,False)
|
||||
scene.objects[objet+"_Lines.GP"].setVisible(True,False)
|
||||
|
||||
# Retour après éclatement
|
||||
if scene.objects['Mecanisme']['eclate'] ==True:
|
||||
scene.objects['Mecanisme']['eclate'] = False
|
||||
ecla_val = scene.objects['Mecanisme']['ecla_val'] # Retour après éclatement avec la valeur d'éclatement
|
||||
sensibilite=0.005
|
||||
for objet in objets :
|
||||
ecla_x, ecla_y,ecla_z = 0,0,0
|
||||
if 'ecla_x' in scene.objects[objet]:
|
||||
ecla_x = scene.objects[objet]['ecla_x']
|
||||
if 'ecla_y' in scene.objects[objet]:
|
||||
ecla_y = scene.objects[objet]['ecla_y']
|
||||
if 'ecla_z' in scene.objects[objet]:
|
||||
ecla_z = scene.objects[objet]['ecla_z']
|
||||
scene.objects[objet].applyMovement((-ecla_val*sensibilite*ecla_x, -ecla_val*sensibilite*ecla_y , -ecla_val*sensibilite*ecla_z), False)
|
||||
scene.objects['Mecanisme']['ecla_val'] = 0.00
|
||||
if scene.objects['Mecanisme']['anim'] == False: # Play d'une frame
|
||||
anim_play1frame()
|
||||
|
||||
# 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['Mecanisme'].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['Mecanisme'].applyRotation((0, delta_x*sensibilite_orbit, 0), True)
|
||||
else:
|
||||
scene.objects['Mecanisme'].applyRotation((0, delta_y*sensibilite_orbit, 0), True)
|
||||
# if obj['manip_mode']==0:
|
||||
# scene.objects['Mecanisme'].applyRotation((delta_y*sensibilite_orbit, 0, delta_x*sensibilite_orbit), 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)
|
||||
|
||||
###############################################################################
|
||||
# Eclaté
|
||||
###############################################################################
|
||||
|
||||
# Position de départ pour l'éclatement de la vue
|
||||
def eclate_start(cont):
|
||||
if scene.objects['Mecanisme']['manip_mode']==1:
|
||||
obj = cont.owner
|
||||
obj['click_x']=cont.sensors['Click'].position[0]
|
||||
obj['click_y']=cont.sensors['Click'].position[1]
|
||||
|
||||
# Déplacement des composants en vue éclatée
|
||||
def eclate(cont):
|
||||
obj = cont.owner
|
||||
sensibilite=0.005
|
||||
delta=(cont.sensors['Down'].position[0]-obj['click_x'])+(cont.sensors['Down'].position[1]-obj['click_y'])
|
||||
if obj['manip_mode']==1: # Shift
|
||||
scene.objects['Mecanisme']['eclate'] =True
|
||||
scene.objects['Mecanisme']['ecla_val'] =scene.objects['Mecanisme']['ecla_val']+delta
|
||||
|
||||
# Déplacement dans le repère du mécanisme
|
||||
x_axis = scene.objects['Mecanisme'].orientation.col[0]
|
||||
y_axis = scene.objects['Mecanisme'].orientation.col[1]
|
||||
z_axis = scene.objects['Mecanisme'].orientation.col[2]
|
||||
for objet in objets :
|
||||
ecla_x, ecla_y,ecla_z = 0,0,0
|
||||
if 'ecla_x' in scene.objects[objet]:
|
||||
ecla_x = scene.objects[objet]['ecla_x']
|
||||
if 'ecla_y' in scene.objects[objet]:
|
||||
ecla_y = scene.objects[objet]['ecla_y']
|
||||
if 'ecla_z' in scene.objects[objet]:
|
||||
ecla_z = scene.objects[objet]['ecla_z']
|
||||
scene.objects[objet].applyMovement((delta*sensibilite*ecla_x*x_axis[0], delta*sensibilite*ecla_x*x_axis[1] , delta*sensibilite*ecla_x*x_axis[2]), False)
|
||||
scene.objects[objet].applyMovement((delta*sensibilite*ecla_y*y_axis[0], delta*sensibilite*ecla_y*y_axis[1] , delta*sensibilite*ecla_y*y_axis[2]), False)
|
||||
scene.objects[objet].applyMovement((delta*sensibilite*ecla_z*z_axis[0], delta*sensibilite*ecla_z*z_axis[1] , delta*sensibilite*ecla_z*z_axis[2]), False)
|
||||
|
||||
###############################################################################
|
||||
# Couleur
|
||||
###############################################################################
|
||||
|
||||
# Initialisation des couleurs du mécanisme
|
||||
def couleur_init():
|
||||
# print("Objets de la scene : ", scene.objects)
|
||||
i=0
|
||||
for objet in objets :
|
||||
scene.objects[objet].color = couleurs_dict[objets_couleur[i]]
|
||||
scene.objects[objet].setVisible(True,False)
|
||||
scene.objects[objet+"_Lines.GP"].setVisible(True,False)
|
||||
scene.objects[objet+"-Nom"].color = couleurs_dict[objets_couleur[i]]
|
||||
scene.objects[objet+"-Nom-Hl"].color = couleurs_dict[objets_couleur[i]]
|
||||
scene.objects[objet+"-Nom-Hl"].setVisible(False,False)
|
||||
i +=1
|
||||
|
||||
# Reset des couleurs du mécanisme
|
||||
def couleur_reset(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
couleur_init()
|
||||
|
||||
# Sélection couleur dans la palette avec son numéro de couleur (bas niveau)
|
||||
def couleur_choix_num(num):
|
||||
for i in range (1, 9):
|
||||
scene.objects['Couleur'+str(i)].worldScale=[3, 3, 3]
|
||||
scene.objects['Couleur'+str(i)+"-Hl"].worldScale=[3, 3, 3]
|
||||
scene.objects['Couleur'+str(num)].worldScale=[4, 4, 4]
|
||||
scene.objects['Couleur'+str(num)+'-Hl'].worldScale=[4, 4, 4]
|
||||
scene.objects['Couleurs']['couleur_select']=num
|
||||
|
||||
# Sélection couleur dans la palette
|
||||
def couleur_choix(cont):
|
||||
obj = cont.owner
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None and "-Hl" not in hitObject .name:
|
||||
couleur_choix_num(int(hitObject .name[7]))
|
||||
|
||||
# Le highlight de 'couleur_choix'
|
||||
def couleur_choix_hl(cont):
|
||||
if cont.sensors['MO'].positive and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None and "-Hl" not in hitObject .name:
|
||||
hitObject.setVisible(False,True)
|
||||
scene.objects[hitObject.name+'-Hl'].setVisible(True,True)
|
||||
# obj.color = couleur_cmd_hl
|
||||
if cont.sensors['MO'].status == JUST_RELEASED:
|
||||
for i in range (1, 9):
|
||||
scene.objects['Couleur'+str(i)].setVisible(True,True)
|
||||
scene.objects['Couleur'+str(i)+"-Hl"].setVisible(False,True)
|
||||
|
||||
# Colorisation de la pièce
|
||||
def couleur_objet(cont):
|
||||
if cont.sensors['Click'].positive and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None and hitObject.visible:
|
||||
couleur_select = scene.objects['Couleurs']['couleur_select']
|
||||
if couleur_select != 0 and couleur_select != 8:
|
||||
hitObject.color = couleurs[couleur_select-1][1]
|
||||
scene.objects[hitObject.name+"-Nom"].color = couleurs[couleur_select-1][1]
|
||||
scene.objects[hitObject.name+"-Nom-Hl"].color = couleurs[couleur_select-1][1]
|
||||
if couleur_select == 8: # Couleur transparente -> disparition
|
||||
hitObject.setVisible(False,False)
|
||||
scene.objects[hitObject.name+"_Lines.GP"].setVisible(False,False)
|
||||
|
||||
# Le highlight de 'couleur_objet'
|
||||
def couleur_objet_hl(cont):
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None and hitObject.visible:
|
||||
scene.objects[hitObject.name+"-Nom"].setVisible(False,False)
|
||||
scene.objects[hitObject.name+"-Nom-Hl"].setVisible(True,False)
|
||||
if cont.sensors['MO'].status == JUST_RELEASED:
|
||||
for objet in objets :
|
||||
scene.objects[objet+"-Nom"].setVisible(True,False)
|
||||
scene.objects[objet+"-Nom-Hl"].setVisible(False,False)
|
||||
|
||||
###############################################################################
|
||||
# Nomenclature
|
||||
###############################################################################
|
||||
|
||||
# Click sur la nomeclature
|
||||
def nom(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None:
|
||||
|
||||
# Afficher/cacher les repères de la pièce
|
||||
if "-Nom-Rep" in hitObject.name:
|
||||
obj=hitObject.name[:len(hitObject.name)-8]
|
||||
if scene.objects[obj]['rep']==False:
|
||||
scene.objects[obj]['rep']=True
|
||||
hitObject.color=couleur_rep_actif
|
||||
for rep in objets_rep_dict[obj]:
|
||||
scene.objects[rep].setVisible(True,False)
|
||||
else:
|
||||
scene.objects[obj]['rep']=False
|
||||
hitObject.color=couleur_rep_pasactif
|
||||
for rep in objets_rep_dict[obj]:
|
||||
scene.objects[rep].setVisible(False,False)
|
||||
|
||||
# Colorisation de la pièce par la nomenclature
|
||||
else:
|
||||
couleur_select = scene.objects['Couleurs']['couleur_select']
|
||||
if couleur_select != 0 and couleur_select != 8:
|
||||
hitObject.color = couleurs[couleur_select-1][1]
|
||||
scene.objects[hitObject.name+"-Hl"].color = couleurs[couleur_select-1][1]
|
||||
scene.objects[hitObject.name[0:len(hitObject.name)-4]].setVisible(True,False)
|
||||
scene.objects[hitObject.name[0:len(hitObject.name)-4]].color = couleurs[couleur_select-1][1]
|
||||
|
||||
if couleur_select == 8: # Couleur transparente -> disparition / apparition
|
||||
obj=scene.objects[hitObject.name[0:len(hitObject.name)-4]]
|
||||
obj_GP=scene.objects[hitObject.name[0:len(hitObject.name)-4]+"_Lines.GP"]
|
||||
if obj.visible==True:
|
||||
obj.setVisible(False,False)
|
||||
obj_GP.setVisible(False,False)
|
||||
else:
|
||||
obj.setVisible(True,False)
|
||||
obj_GP.setVisible(True,False)
|
||||
# if couleur_select == 8: # Couleur transparente -> disparition
|
||||
# scene.objects[hitObject.name[0:len(hitObject.name)-4]].setVisible(False,False)
|
||||
|
||||
# Le highlight de la nomenclature
|
||||
def nom_hl(cont):
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None:
|
||||
hitObject.setVisible(False,False)
|
||||
scene.objects[hitObject.name+'-Hl'].setVisible(True,False)
|
||||
# obj.color = couleur_cmd_hl
|
||||
if cont.sensors['MO'].status == JUST_RELEASED and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
for objet in objets :
|
||||
scene.objects[objet+"-Nom"].setVisible(True,False)
|
||||
scene.objects[objet+"-Nom-Hl"].setVisible(False,False)
|
||||
for objet in objets_rep :
|
||||
scene.objects[objet+'-Nom-Rep'].setVisible(True,False)
|
||||
scene.objects[objet+'-Nom-Rep-Hl'].setVisible(False,False)
|
||||
|
||||
###############################################################################
|
||||
# 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_blender'].color= couleur_lien
|
||||
scene.objects['Apropos-Lien_upbge'].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_projet" :
|
||||
webbrowser.open('https://gitlab.com/blender-edutech')
|
||||
if obj.name == "Apropos-Lien_blender" :
|
||||
webbrowser.open('https://blender.org')
|
||||
if obj.name == "Apropos-Lien_upbge" :
|
||||
webbrowser.open('https://upbge.org')
|
||||
|
||||
# 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
|
||||
# Initialisation
|
||||
def init(cont):
|
||||
scene.objects['Mecanism']['objects'] = objects
|
||||
scene.objects['Mecanism']['objects_anim'] = objects_anim
|
||||
scene.objects['Mecanism']['objects_dict'] = objects_dict
|
||||
scene.objects['Mecanism']['colors'] = colors
|
||||
scene.objects['Mecanism']['colors_dict'] = colors_dict
|
||||
cine.manip_init() # Manipulation du modèle 3D
|
||||
cine.objects_init() # Mécanisme
|
||||
cine.cmd_init() # Commandes
|
||||
cine.anim_init() # Animation
|
||||
|
Binary file not shown.
@ -1,5 +1,4 @@
|
||||
import bge # Bibliothèque Blender Game Engine (BGE)
|
||||
import math
|
||||
import cine # Bibliothèque du player 3d d'analyse de cinématique
|
||||
|
||||
###############################################################################
|
||||
@ -11,7 +10,7 @@ import cine # Bibliothèque du player 3d d'analyse de cinématique
|
||||
# @copyright: Copyright (C) 2020-2022 Philippe Roy
|
||||
# @license: GNU GPL
|
||||
#
|
||||
# Commandes déclenchées par UPBGE pour le modèle du baton de colle
|
||||
# Commandes déclenchées par UPBGE pour le modèle de la pince schrader
|
||||
#
|
||||
# Ce player 3D est un environnement léger et spécifique pour la colorisation des solides d'un mécanisme en mouvement.
|
||||
# Il sert principalement pour l'apprentissage de la détection des classes d'équivalence d'un mécanisme afin de pouvoir faire sa modélisation cinématique.
|
||||
|
@ -1,17 +1,16 @@
|
||||
import bge # Bibliothèque Blender Game Engine (BGE)
|
||||
import webbrowser
|
||||
import math
|
||||
import cine # Bibliothèque du player 3d d'analyse de cinématique
|
||||
|
||||
###############################################################################
|
||||
# serrbio.py
|
||||
# @title: Commandes pour le player 3D de la serrure biométrique
|
||||
# @title: Player 3D cinématique de la serrure biométrique
|
||||
# @project: Blender-EduTech
|
||||
# @lang: fr
|
||||
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
# @copyright: Copyright (C) 2020-2022 Philippe Roy
|
||||
# @license: GNU GPL
|
||||
#
|
||||
# # Commandes déclenchées par UPBGE pour le modèle de la serrure biométrique
|
||||
# Commandes déclenchées par UPBGE pour le modèle de la serrure biométrique
|
||||
#
|
||||
# Ce player 3D est un environnement léger et spécifique pour la colorisation des solides d'un mécanisme en mouvement.
|
||||
# Il sert principalement pour l'apprentissage de la détection des classes d'équivalence d'un mécanisme afin de pouvoir faire sa modélisation cinématique.
|
||||
@ -20,659 +19,51 @@ import math
|
||||
|
||||
# Récupérer la scène 3D
|
||||
scene = bge.logic.getCurrentScene()
|
||||
# print("Objets de la scene : ", scene.objects)
|
||||
|
||||
# Objets 3D
|
||||
###############################################################################
|
||||
# Mécanisme
|
||||
###############################################################################
|
||||
|
||||
objets=['Carre', 'Coffre', 'Noix', 'Pene', 'Plaque', 'Poignee', 'Tetiere']
|
||||
objets_couleur=[2, 0, 4, 1, 6, 3, 5] # Couleur des objets par défaut
|
||||
objects=['Coffre', 'Poignee', 'Carre', 'Noix', 'Plaque', 'Tetiere', 'Pene']
|
||||
objects_anim=['Poignee', 'Carre', 'Noix', 'Pene', 'Plaque', 'Pene']
|
||||
|
||||
objets_anim=['Carre', 'Noix', 'Pene', 'Plaque', 'Poignee'] # Objet animé
|
||||
|
||||
objets_rep=['Coffre', 'Noix', 'Pene', 'Plaque', 'Poignee'] # Objet avec une repère
|
||||
objets_rep_dict={'Coffre' : ['Repere O'],
|
||||
'Noix' : ['Repere A', 'Repere D'],
|
||||
'Pene' : ['Repere C', 'Repere E'],
|
||||
'Plaque' : ['Repere B'],
|
||||
'Poignee' : ['Repere F']}
|
||||
objects_dict={'Coffre' : [1, '1 : Coffre', 'Color-1', ['Repere O']],
|
||||
'Poignee' : [2, '2 : Poignée', 'Color-4', ['Repere F']],
|
||||
'Carre' : [3, '3 : Carré', 'Color-3', []],
|
||||
'Noix' : [4, '4 : Noix', 'Color-5', ['Repere A', 'Repere D']],
|
||||
'Plaque' : [5, '5 : Plaque', 'Color-7', ['Repere B']],
|
||||
'Tetiere' : [6, '6 : Têtière', 'Color-6', []],
|
||||
'Pene' : [7, '7 : Pêne', 'Color-2', ['Repere C', 'Repere E']]}
|
||||
|
||||
# Couleurs
|
||||
|
||||
couleurs=[['Couleur1', [0.202, 0.114, 0.512,1]],
|
||||
['Couleur2', [0.051, 0.270, 0.279,1]],
|
||||
['Couleur3', [0.799, 0.031, 0.038,1]],
|
||||
['Couleur4', [0.799, 0.130, 0.063,1]],
|
||||
['Couleur5', [0.8, 0.619, 0.021,1]],
|
||||
['Couleur6', [0.246, 0.687, 0.078,1]],
|
||||
['Couleur7', [0.800, 0.005, 0.315,1]],
|
||||
['Couleur8', [0.75,0.751, 0.75,0]]]
|
||||
|
||||
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] # bleu
|
||||
|
||||
couleur_rep_actif = [0.8, 0.8, 0.8, 1] # blanc
|
||||
couleur_rep_pasactif = [0, 0, 0, 1] # noir
|
||||
|
||||
# Constantes
|
||||
|
||||
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
|
||||
|
||||
###############################################################################
|
||||
# Gestion du clavier
|
||||
###############################################################################
|
||||
|
||||
# Mode : Pan(1) avec Shift, Zoom (2) avec Ctrl, Orbit (0), Eclaté avec Shift
|
||||
def mode(cont):
|
||||
obj = cont.owner
|
||||
keyboard = bge.logic.keyboard
|
||||
|
||||
# Shift -> mode 1 : Pan (clic milieu) ou Eclaté (clic gauche)
|
||||
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['Mecanisme'], 0, 0, 0)
|
||||
for objet in objets :
|
||||
scene.objects[objet].setVisible(True,False)
|
||||
scene.objects[objet+"_Lines.GP"].setVisible(True,False)
|
||||
if scene.objects['Mecanisme']['eclate'] ==True:
|
||||
scene.objects['Mecanisme']['eclate'] = False
|
||||
for objet in objets :
|
||||
scene.objects[objet].worldPosition.x =scene.objects[objet]['init_lx']
|
||||
scene.objects[objet].worldPosition.y = scene.objects[objet]['init_ly']
|
||||
scene.objects[objet].worldPosition.z = scene.objects[objet]['init_lz']
|
||||
if scene.objects['Mecanisme']['anim'] == False: # Play d'une frame
|
||||
anim_play1frame()
|
||||
|
||||
# Touche Space -> Play et Pause
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.SPACEKEY].queue:
|
||||
if scene.objects['Mecanisme']['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 H -> Cacher l'objet
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.HKEY].queue:
|
||||
couleur_choix_num(8)
|
||||
|
||||
# Touche de 1 à 8 -> Couleur de 1 à 8
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.ONEKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD1].queue:
|
||||
couleur_choix_num(1)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.TWOKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD2].queue:
|
||||
couleur_choix_num(2)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.THREEKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD3].queue:
|
||||
couleur_choix_num(3)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.FOURKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD4].queue:
|
||||
couleur_choix_num(4)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.FIVEKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD5].queue:
|
||||
couleur_choix_num(5)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.SIXKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD6].queue:
|
||||
couleur_choix_num(6)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.SEVENKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD7].queue:
|
||||
couleur_choix_num(7)
|
||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.EIGHTKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD8].queue:
|
||||
couleur_choix_num(8)
|
||||
|
||||
###############################################################################
|
||||
# Commandes
|
||||
###############################################################################
|
||||
|
||||
# Init
|
||||
def cmd_init():
|
||||
scene.objects['Aide-cmd-Hl'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Play-Hl'].setVisible(False,False)
|
||||
scene.objects['Raz-couleurs-Hl'].setVisible(False,False)
|
||||
scene.objects['Raz-vue-Hl'].setVisible(False,False)
|
||||
for i in range (1, 9):
|
||||
scene.objects['Couleur'+str(i)+"-Hl"].setVisible(False,False)
|
||||
for objet in objets_rep :
|
||||
scene.objects[objet+'-Nom-Rep-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['Mecanisme']['manip_mode']==0:
|
||||
if obj.name!="Play" and obj.name!="Pause" and obj.name!="Play-Hl" and obj.name!="Pause-Hl":
|
||||
obj.setVisible(False,True)
|
||||
scene.objects[obj.name+'-Hl'].setVisible(True,True)
|
||||
# obj.color = couleur_cmd_hl
|
||||
|
||||
# Play et pause
|
||||
if obj.name=="Pause" or obj.name=="Play":
|
||||
if scene.objects['Mecanisme']['anim'] == True:
|
||||
scene.objects['Pause'].setVisible(False,False)
|
||||
scene.objects['Pause-Hl'].setVisible(True,False)
|
||||
else:
|
||||
scene.objects['Play'].setVisible(False,False)
|
||||
scene.objects['Play-Hl'].setVisible(True,False)
|
||||
|
||||
# Désactivation
|
||||
if cont.sensors['MO'].status == JUST_RELEASED and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
if obj.name!="Play" and obj.name!="Pause" and obj.name!="Play-Hl" and obj.name!="Pause-Hl":
|
||||
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['Mecanisme']['anim'] == True:
|
||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||
scene.objects['Pause'].setVisible(True,False)
|
||||
else:
|
||||
scene.objects['Play-Hl'].setVisible(False,False)
|
||||
scene.objects['Play'].setVisible(True,False)
|
||||
|
||||
###############################################################################
|
||||
# Animation
|
||||
###############################################################################
|
||||
|
||||
# Initialisation de l'animation -> Play
|
||||
def anim_init(cont):
|
||||
start = 1
|
||||
end = 200
|
||||
layer = 0
|
||||
priority = 1
|
||||
blendin = 1.0
|
||||
mode = bge.logic.KX_ACTION_MODE_LOOP
|
||||
layerWeight = 0.0
|
||||
ipoFlags = 0
|
||||
speed = 1.0
|
||||
for objet in objets_anim :
|
||||
scene.objects[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
||||
scene.objects['Play'].setVisible(False,False)
|
||||
scene.objects['Pause'].setVisible(True,False)
|
||||
scene.objects['Mecanisme']['anim'] = True
|
||||
|
||||
# Animation en pause (bas niveau)
|
||||
def anim_pause():
|
||||
layer = 0
|
||||
for objet in objets_anim :
|
||||
scene.objects['Mecanisme']['anim_frame'] = scene.objects[objet].getActionFrame(layer)
|
||||
scene.objects[objet].stopAction(layer)
|
||||
scene.objects['Mecanisme']['anim'] = False
|
||||
|
||||
# Animation en pseudo-pause
|
||||
# Play d'une frame pour remettre les pièces en place
|
||||
def anim_play1frame():
|
||||
start = scene.objects['Mecanisme']['anim_frame']
|
||||
end = scene.objects['Mecanisme']['anim_frame']+1
|
||||
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 objets_anim :
|
||||
scene.objects[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
||||
scene.objects['Mecanisme']['anim_frame'] = end
|
||||
|
||||
# Reprise de l'animation (bas niveau)
|
||||
def anim_play():
|
||||
start = scene.objects['Mecanisme']['anim_frame']
|
||||
end = 200
|
||||
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 objets_anim :
|
||||
scene.objects[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
||||
scene.objects['Mecanisme']['anim'] = True
|
||||
|
||||
# Pause et replay par les commandes
|
||||
def anim_cmd(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
|
||||
# Pause
|
||||
if scene.objects['Mecanisme']['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)
|
||||
|
||||
# Play en continu
|
||||
def anim_boucle(cont):
|
||||
if scene.objects['Mecanisme']['anim'] == True and scene.objects['Carre'].isPlayingAction(0) == False:
|
||||
# scene.objects['Mecanisme']['anim_frame']=1
|
||||
start = 1
|
||||
end = 200
|
||||
layer = 0
|
||||
priority = 1
|
||||
blendin = 1.0
|
||||
mode = bge.logic.KX_ACTION_MODE_LOOP
|
||||
layerWeight = 0.0
|
||||
ipoFlags = 0
|
||||
speed = 1.0
|
||||
for objet in objets_anim :
|
||||
scene.objects[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
||||
|
||||
###############################################################################
|
||||
# Manipulation du mécanisme
|
||||
###############################################################################
|
||||
|
||||
# Initialisation de la vue 3D
|
||||
def manip_init(cont):
|
||||
|
||||
# Mémorisation de la position des composants
|
||||
for objet in objets :
|
||||
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
|
||||
scene.objects['Camera']['init_lz']=scene.objects['Camera'].worldPosition.z
|
||||
|
||||
# Mémorisation de la position du modèle
|
||||
scene.objects['Mecanisme']['init_lx']=scene.objects['Mecanisme'].worldPosition.x
|
||||
scene.objects['Mecanisme']['init_ly']=scene.objects['Mecanisme'].worldPosition.y
|
||||
scene.objects['Mecanisme']['init_lz']=scene.objects['Mecanisme'].worldPosition.z
|
||||
scene.objects['Mecanisme']['init_rx']=scene.objects['Mecanisme'].worldOrientation.to_euler().x
|
||||
scene.objects['Mecanisme']['init_ry']=scene.objects['Mecanisme'].worldOrientation.to_euler().y
|
||||
scene.objects['Mecanisme']['init_rz']=scene.objects['Mecanisme'].worldOrientation.to_euler().z
|
||||
|
||||
# Cacher les repères
|
||||
for objet in objets_rep :
|
||||
scene.objects[objet]['rep']=False
|
||||
scene.objects[objet+"-Nom-Rep"].color=couleur_rep_pasactif
|
||||
for rep in objets_rep_dict[objet]:
|
||||
scene.objects[rep].setVisible(False,False)
|
||||
|
||||
# def applyMovemenTo(obj, lx,ly,lz,rx,ry,rz):
|
||||
# lres=0.001 # resolution location
|
||||
# rres=0.001 # resolution rotation
|
||||
# while (obj.worldPosition.x-lx > lres) or (obj.worldPosition.y-ly > lres) or (obj.worldPosition.z-lz > lres) or (obj.worldOrientation.to_euler().x-rx > rres) or (obj.worldOrientation.to_euler().y-ry > rres) or (obj.worldOrientation.to_euler().z-rz > rres):
|
||||
# if obj.worldPosition.x-lx > lres:
|
||||
# obj. applyMovement(lres,0,0)
|
||||
# if obj.worldPosition.y-ly > lres:
|
||||
# obj. applyMovement(0,lres,0 )
|
||||
# if obj.worldPosition.z-lz > lres:
|
||||
# obj. applyMovement(0,0,lres)
|
||||
# if obj.worldOrientation.to_euler().x-rx > rres:
|
||||
# obj.applyRotation(rres,0,0)
|
||||
# if obj.worldOrientation.to_euler().y-ry > rres:
|
||||
# obj.applyRotation(0,rres,0)
|
||||
# if obj.worldOrientation.to_euler().z-ry > rres:
|
||||
# obj.applyRotation(0,0,rres)
|
||||
|
||||
# def applyTranslationTo(obj, lx,ly,lz):
|
||||
# lres=0.001 # resolution location
|
||||
# while (obj.worldPosition.x-lx > lres) or (obj.worldPosition.y-ly > lres) or (obj.worldPosition.z-lz > lres):
|
||||
# if obj.worldPosition.x-lx > lres:
|
||||
# obj. applyMovement(lres,0,0)
|
||||
# if obj.worldPosition.y-ly > lres:
|
||||
# obj. applyMovement(0,lres,0 )
|
||||
# if obj.worldPosition.z-lz > lres:
|
||||
# obj. applyMovement(0,0,lres)
|
||||
|
||||
# Atteindre une orientation (bas niveau)
|
||||
def applyRotationTo(obj, rx=None, ry=None, rz=None):
|
||||
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), True)
|
||||
if rx-obj.worldOrientation.to_euler().x > rres:
|
||||
obj.applyRotation((rres, 0, 0), True)
|
||||
# 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), True)
|
||||
if ry-obj.worldOrientation.to_euler().y > rres:
|
||||
obj.applyRotation((0, rres, 0), True)
|
||||
# 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), True)
|
||||
if rz-obj.worldOrientation.to_euler().z > rres:
|
||||
obj.applyRotation((0, 0, rres), True)
|
||||
# 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['Mecanisme']['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['Mecanisme'], 0, 0, 0)
|
||||
for objet in objets :
|
||||
scene.objects[objet].setVisible(True,False)
|
||||
scene.objects[objet+"_Lines.GP"].setVisible(True,False)
|
||||
if scene.objects['Mecanisme']['eclate'] ==True:
|
||||
scene.objects['Mecanisme']['eclate'] = False
|
||||
for objet in objets :
|
||||
scene.objects[objet].worldPosition.x =scene.objects[objet]['init_lx']
|
||||
scene.objects[objet].worldPosition.y = scene.objects[objet]['init_ly']
|
||||
scene.objects[objet].worldPosition.z = scene.objects[objet]['init_lz']
|
||||
if scene.objects['Mecanisme']['anim'] == False: # Play d'une frame
|
||||
anim_play1frame()
|
||||
|
||||
# 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['Mecanisme'].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['Mecanisme'].applyRotation((0, delta_x*sensibilite_orbit, 0), True)
|
||||
else:
|
||||
scene.objects['Mecanisme'].applyRotation((0, delta_y*sensibilite_orbit, 0), True)
|
||||
# if obj['manip_mode']==0:
|
||||
# scene.objects['Mecanisme'].applyRotation((delta_y*sensibilite_orbit, 0, delta_x*sensibilite_orbit), 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)
|
||||
|
||||
###############################################################################
|
||||
# Eclaté
|
||||
###############################################################################
|
||||
|
||||
# Position de départ pour l'éclatement de la vue
|
||||
def eclate_start(cont):
|
||||
if scene.objects['Mecanisme']['manip_mode']==1:
|
||||
obj = cont.owner
|
||||
obj['click_x']=cont.sensors['Click'].position[0]
|
||||
obj['click_y']=cont.sensors['Click'].position[1]
|
||||
|
||||
# Déplacement des composants en vue éclatée
|
||||
def eclate(cont):
|
||||
obj = cont.owner
|
||||
sensibilite=0.005
|
||||
delta=(cont.sensors['Down'].position[0]-obj['click_x'])+(cont.sensors['Down'].position[1]-obj['click_y'])
|
||||
if obj['manip_mode']==1: # Shift
|
||||
scene.objects['Mecanisme']['eclate'] =True
|
||||
for objet in objets :
|
||||
ecla_x, ecla_y,ecla_z = 0,0,0
|
||||
if 'ecla_x' in scene.objects[objet]:
|
||||
ecla_x = scene.objects[objet]['ecla_x']
|
||||
if 'ecla_y' in scene.objects[objet]:
|
||||
ecla_y = scene.objects[objet]['ecla_y']
|
||||
if 'ecla_z' in scene.objects[objet]:
|
||||
ecla_z = scene.objects[objet]['ecla_z']
|
||||
|
||||
# Déplacement dans le repère du mécanisme
|
||||
x_axis = scene.objects['Mecanisme'].orientation.col[0]
|
||||
y_axis = scene.objects['Mecanisme'].orientation.col[1]
|
||||
z_axis = scene.objects['Mecanisme'].orientation.col[2]
|
||||
scene.objects[objet].applyMovement((delta*sensibilite*ecla_x*x_axis[0], delta*sensibilite*ecla_x*x_axis[1] , delta*sensibilite*ecla_x*x_axis[2]), False)
|
||||
scene.objects[objet].applyMovement((delta*sensibilite*ecla_y*y_axis[0], delta*sensibilite*ecla_y*y_axis[1] , delta*sensibilite*ecla_y*y_axis[2]), False)
|
||||
scene.objects[objet].applyMovement((delta*sensibilite*ecla_z*z_axis[0], delta*sensibilite*ecla_z*z_axis[1] , delta*sensibilite*ecla_z*z_axis[2]), False)
|
||||
|
||||
###############################################################################
|
||||
# Couleur
|
||||
###############################################################################
|
||||
|
||||
# Initialisation des couleurs du mécanisme
|
||||
def couleur_init():
|
||||
i=0
|
||||
for objet in objets :
|
||||
scene.objects[objet].color = couleurs[objets_couleur[i]][1]
|
||||
scene.objects[objet].setVisible(True,False)
|
||||
scene.objects[objet+"_Lines.GP"].setVisible(True,False)
|
||||
scene.objects[objet+"-Nom"].color = couleurs[objets_couleur[i]][1]
|
||||
scene.objects[objet+"-Nom-Hl"].color = couleurs[objets_couleur[i]][1]
|
||||
scene.objects[objet+"-Nom-Hl"].setVisible(False,False)
|
||||
i +=1
|
||||
|
||||
# Reset des couleurs du mécanisme
|
||||
def couleur_reset(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
couleur_init()
|
||||
|
||||
# Sélection couleur dans la palette avec son numéro de couleur (bas niveau)
|
||||
def couleur_choix_num(num):
|
||||
for i in range (1, 9):
|
||||
scene.objects['Couleur'+str(i)].worldScale=[3, 3, 3]
|
||||
scene.objects['Couleur'+str(i)+"-Hl"].worldScale=[3, 3, 3]
|
||||
scene.objects['Couleur'+str(num)].worldScale=[4, 4, 4]
|
||||
scene.objects['Couleur'+str(num)+'-Hl'].worldScale=[4, 4, 4]
|
||||
scene.objects['Couleurs']['couleur_select']=num
|
||||
|
||||
# Sélection couleur dans la palette
|
||||
def couleur_choix(cont):
|
||||
obj = cont.owner
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None and "-Hl" not in hitObject .name:
|
||||
couleur_choix_num(int(hitObject .name[7]))
|
||||
|
||||
# Le highlight de 'couleur_choix'
|
||||
def couleur_choix_hl(cont):
|
||||
if cont.sensors['MO'].positive and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None and "-Hl" not in hitObject .name:
|
||||
hitObject.setVisible(False,False)
|
||||
scene.objects[hitObject.name+'-Hl'].setVisible(True,False)
|
||||
# obj.color = couleur_cmd_hl
|
||||
if cont.sensors['MO'].status == JUST_RELEASED:
|
||||
for i in range (1, 9):
|
||||
scene.objects['Couleur'+str(i)].setVisible(True,False)
|
||||
scene.objects['Couleur'+str(i)+"-Hl"].setVisible(False,False)
|
||||
|
||||
# Colorisation de la pièce
|
||||
def couleur_objet(cont):
|
||||
if cont.sensors['Click'].positive and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None and hitObject.visible:
|
||||
couleur_select = scene.objects['Couleurs']['couleur_select']
|
||||
if couleur_select != 0 and couleur_select != 8:
|
||||
hitObject.color = couleurs[couleur_select-1][1]
|
||||
scene.objects[hitObject.name+"-Nom"].color = couleurs[couleur_select-1][1]
|
||||
scene.objects[hitObject.name+"-Nom-Hl"].color = couleurs[couleur_select-1][1]
|
||||
if couleur_select == 8: # Couleur transparente -> disparition / apparition
|
||||
hitObject.setVisible(False,False)
|
||||
scene.objects[hitObject.name+"_Lines.GP"].setVisible(False,False)
|
||||
|
||||
# Le highlight de 'couleur_objet'
|
||||
def couleur_objet_hl(cont):
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None and hitObject.visible:
|
||||
scene.objects[hitObject.name+"-Nom"].setVisible(False,False)
|
||||
scene.objects[hitObject.name+"-Nom-Hl"].setVisible(True,False)
|
||||
if cont.sensors['MO'].status == JUST_RELEASED:
|
||||
for objet in objets :
|
||||
scene.objects[objet+"-Nom"].setVisible(True,False)
|
||||
scene.objects[objet+"-Nom-Hl"].setVisible(False,False)
|
||||
|
||||
###############################################################################
|
||||
# Nomenclature
|
||||
###############################################################################
|
||||
|
||||
# Click sur la nomeclature
|
||||
def nom(cont):
|
||||
if cont.sensors['Click'].status == JUST_ACTIVATED and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None:
|
||||
|
||||
# Afficher/cacher les repères de la pièce
|
||||
if "-Nom-Rep" in hitObject.name:
|
||||
obj=hitObject.name[:len(hitObject.name)-8]
|
||||
print (scene.objects[obj]['rep'])
|
||||
if scene.objects[obj]['rep']==False:
|
||||
scene.objects[obj]['rep']=True
|
||||
hitObject.color=couleur_rep_actif
|
||||
for rep in objets_rep_dict[obj]:
|
||||
scene.objects[rep].setVisible(True,False)
|
||||
else:
|
||||
scene.objects[obj]['rep']=False
|
||||
hitObject.color=couleur_rep_pasactif
|
||||
for rep in objets_rep_dict[obj]:
|
||||
scene.objects[rep].setVisible(False,False)
|
||||
|
||||
# Colorisation de la pièce par la nomenclature
|
||||
else:
|
||||
couleur_select = scene.objects['Couleurs']['couleur_select']
|
||||
if couleur_select != 0 and couleur_select != 8:
|
||||
hitObject.color = couleurs[couleur_select-1][1]
|
||||
scene.objects[hitObject.name+"-Hl"].color = couleurs[couleur_select-1][1]
|
||||
scene.objects[hitObject.name[0:len(hitObject.name)-4]].setVisible(True,False)
|
||||
scene.objects[hitObject.name[0:len(hitObject.name)-4]].color = couleurs[couleur_select-1][1]
|
||||
|
||||
if couleur_select == 8: # Couleur transparente -> disparition / apparition
|
||||
obj=scene.objects[hitObject.name[0:len(hitObject.name)-4]]
|
||||
obj_GP=scene.objects[hitObject.name[0:len(hitObject.name)-4]+"_Lines.GP"]
|
||||
if obj.visible==True:
|
||||
obj.setVisible(False,False)
|
||||
obj_GP.setVisible(False,False)
|
||||
else:
|
||||
obj.setVisible(True,False)
|
||||
obj_GP.setVisible(True,False)
|
||||
# if couleur_select == 8: # Couleur transparente -> disparition
|
||||
# scene.objects[hitObject.name[0:len(hitObject.name)-4]].setVisible(False,False)
|
||||
|
||||
# Le highlight de la nomenclature
|
||||
def nom_hl(cont):
|
||||
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
hitObject = cont.sensors['MO'].hitObject
|
||||
if hitObject is not None:
|
||||
hitObject.setVisible(False,False)
|
||||
scene.objects[hitObject.name+'-Hl'].setVisible(True,False)
|
||||
# obj.color = couleur_cmd_hl
|
||||
if cont.sensors['MO'].status == JUST_RELEASED and scene.objects['Mecanisme']['manip_mode']==0:
|
||||
for objet in objets :
|
||||
scene.objects[objet+"-Nom"].setVisible(True,False)
|
||||
scene.objects[objet+"-Nom-Hl"].setVisible(False,False)
|
||||
for objet in objets_rep :
|
||||
scene.objects[objet+'-Nom-Rep'].setVisible(True,False)
|
||||
scene.objects[objet+'-Nom-Rep-Hl'].setVisible(False,False)
|
||||
|
||||
###############################################################################
|
||||
# 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_blender'].color= couleur_lien
|
||||
scene.objects['Apropos-Lien_upbge'].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_projet" :
|
||||
webbrowser.open('https://gitlab.com/blender-edutech')
|
||||
if obj.name == "Apropos-Lien_blender" :
|
||||
webbrowser.open('https://blender.org')
|
||||
if obj.name == "Apropos-Lien_upbge" :
|
||||
webbrowser.open('https://upbge.org')
|
||||
|
||||
# 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
|
||||
colors=[['Color-1', [0.202, 0.114, 0.512,1]],
|
||||
['Color-2', [0.051, 0.270, 0.279,1]],
|
||||
['Color-3', [0.799, 0.031, 0.038,1]],
|
||||
['Color-4', [0.799, 0.130, 0.063,1]],
|
||||
['Color-5', [0.8, 0.619, 0.021,1]],
|
||||
['Color-6', [0.246, 0.687, 0.078,1]],
|
||||
['Color-7', [0.800, 0.005, 0.315,1]],
|
||||
['Color-8', [0.75,0.751, 0.75,0]]]
|
||||
|
||||
colors_dict={'Color-1' : [0.202, 0.114, 0.512, 1],
|
||||
'Color-2' : [0.051, 0.270, 0.279, 1],
|
||||
'Color-3' : [0.799, 0.031, 0.038, 1],
|
||||
'Color-4' : [0.799, 0.130, 0.063, 1],
|
||||
'Color-5' : [0.8, 0.619, 0.021, 1],
|
||||
'Color-6' : [0.246, 0.687, 0.078, 1],
|
||||
'Color-7' : [0.800, 0.005, 0.315, 1],
|
||||
'Color-8' : [0.75,0.75, 0.75, 0],
|
||||
'White' : [0.8, 0.8, 0.8, 1]}
|
||||
|
||||
# Initialisation
|
||||
def init(cont):
|
||||
scene.objects['Mecanism']['objects'] = objects
|
||||
scene.objects['Mecanism']['objects_anim'] = objects_anim
|
||||
scene.objects['Mecanism']['objects_dict'] = objects_dict
|
||||
scene.objects['Mecanism']['colors'] = colors
|
||||
scene.objects['Mecanism']['colors_dict'] = colors_dict
|
||||
cine.manip_init() # Manipulation du modèle 3D
|
||||
cine.objects_init() # Mécanisme
|
||||
cine.cmd_init() # Commandes
|
||||
cine.anim_init() # Animation
|
||||
|
BIN
serrure_biometrique/serrure_biometrique-37.blend
Normal file
BIN
serrure_biometrique/serrure_biometrique-37.blend
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user