mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
Suite de la migration
This commit is contained in:
parent
cc021ff3a0
commit
471b6e0246
464
jumeau.py
464
jumeau.py
@ -16,7 +16,7 @@ import jumeau_about # About
|
|||||||
# @copyright: Copyright (C) 2020-2022 Philippe Roy
|
# @copyright: Copyright (C) 2020-2022 Philippe Roy
|
||||||
# @license: GNU GPL
|
# @license: GNU GPL
|
||||||
#
|
#
|
||||||
# Cette environnement 3D est programmable en Python. Il est destiné à la découverte de la programmation de système pluritechnologique.
|
# Cet environnement 3D est programmable en Python. Il est destiné à la découverte de la programmation de système pluritechnologique.
|
||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
@ -26,8 +26,8 @@ scene = bge.logic.getCurrentScene()
|
|||||||
# print("Objets de la scene : ", scene.objects)
|
# print("Objets de la scene : ", scene.objects)
|
||||||
|
|
||||||
# Config file
|
# Config file
|
||||||
cine_config = ET.parse('cine_config.xml')
|
jumeau_config = ET.parse('jumeau_config.xml')
|
||||||
cine_config_tree = cine_config.getroot()
|
jumeau_config_tree = jumeau_config.getroot()
|
||||||
|
|
||||||
# Couleurs
|
# Couleurs
|
||||||
color_cmd = [0.8, 0.8, 0.8, 1] # Blanc
|
color_cmd = [0.8, 0.8, 0.8, 1] # Blanc
|
||||||
@ -47,7 +47,7 @@ ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
|||||||
|
|
||||||
# Mode : Orbit(0) par défaut, Pan(1) avec Shift, Zoom (2) avec Ctrl, Eclaté (1) avec Shift
|
# Mode : Orbit(0) par défaut, Pan(1) avec Shift, Zoom (2) avec Ctrl, Eclaté (1) avec Shift
|
||||||
def keyboard(cont):
|
def keyboard(cont):
|
||||||
obj = scene.objects['Mecanism']
|
obj = scene.objects['System']
|
||||||
keyboard = bge.logic.keyboard
|
keyboard = bge.logic.keyboard
|
||||||
|
|
||||||
# Touche ESC
|
# Touche ESC
|
||||||
@ -56,10 +56,10 @@ def keyboard(cont):
|
|||||||
# Maj du fichier de config (screen size : data/config/screen/width-> [0][0].text)
|
# Maj du fichier de config (screen size : data/config/screen/width-> [0][0].text)
|
||||||
screen_width = bge.render.getWindowWidth()
|
screen_width = bge.render.getWindowWidth()
|
||||||
screen_height = bge.render.getWindowHeight()
|
screen_height = bge.render.getWindowHeight()
|
||||||
cine_config_tree[0][0].text=str(screen_width)
|
jumeau_config_tree[0][0].text=str(screen_width)
|
||||||
cine_config_tree[0][1].text=str(screen_height)
|
jumeau_config_tree[0][1].text=str(screen_height)
|
||||||
buffer_xml = ET.tostring(cine_config_tree)
|
buffer_xml = ET.tostring(jumeau_config_tree)
|
||||||
with open("cine_config.xml", "wb") as f:
|
with open("jumeau_config.xml", "wb") as f:
|
||||||
f.write(buffer_xml)
|
f.write(buffer_xml)
|
||||||
|
|
||||||
# Sortir
|
# Sortir
|
||||||
@ -93,37 +93,15 @@ def keyboard(cont):
|
|||||||
|
|
||||||
# Touche Space -> Play et Pause
|
# Touche Space -> Play et Pause
|
||||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.SPACEKEY].queue:
|
if JUST_ACTIVATED in keyboard.inputs[bge.events.SPACEKEY].queue:
|
||||||
if scene.objects['Mecanism']['anim'] == True:
|
if scene.objects['System']['anim'] == True:
|
||||||
anim_pause()
|
# anim_pause()
|
||||||
scene.objects['Pause'].setVisible(False,False)
|
scene.objects['Pause'].setVisible(False,False)
|
||||||
scene.objects['Play'].setVisible(True,False)
|
scene.objects['Play'].setVisible(True,False)
|
||||||
else:
|
else:
|
||||||
anim_play()
|
# anim_play()
|
||||||
scene.objects['Play'].setVisible(False,False)
|
scene.objects['Play'].setVisible(False,False)
|
||||||
scene.objects['Pause'].setVisible(True,False)
|
scene.objects['Pause'].setVisible(True,False)
|
||||||
|
|
||||||
# Touche H -> Cacher l'objet (hide)
|
|
||||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.HKEY].queue:
|
|
||||||
color_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:
|
|
||||||
color_num(1)
|
|
||||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.TWOKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD2].queue:
|
|
||||||
color_num(2)
|
|
||||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.THREEKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD3].queue:
|
|
||||||
color_num(3)
|
|
||||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.FOURKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD4].queue:
|
|
||||||
color_num(4)
|
|
||||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.FIVEKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD5].queue:
|
|
||||||
color_num(5)
|
|
||||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.SIXKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD6].queue:
|
|
||||||
color_num(6)
|
|
||||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.SEVENKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD7].queue:
|
|
||||||
color_num(7)
|
|
||||||
if JUST_ACTIVATED in keyboard.inputs[bge.events.EIGHTKEY].queue or JUST_ACTIVATED in keyboard.inputs[bge.events.PAD8].queue:
|
|
||||||
color_num(8)
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Commandes
|
# Commandes
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -134,15 +112,12 @@ def keyboard(cont):
|
|||||||
|
|
||||||
def cmd_init():
|
def cmd_init():
|
||||||
# Fichier de config (screen size : data/config/screen/width-> [0][0].text, height-> [0][1].text)
|
# Fichier de config (screen size : data/config/screen/width-> [0][0].text, height-> [0][1].text)
|
||||||
bge.render.setWindowSize(int(cine_config_tree[0][0].text),int(cine_config_tree[0][1].text))
|
bge.render.setWindowSize(int(jumeau_config_tree[0][0].text),int(jumeau_config_tree[0][1].text))
|
||||||
scene.objects['Play-Hl'].setVisible(False,False)
|
scene.objects['Play-Hl'].setVisible(False,False)
|
||||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||||
scene.objects['Reset-colors-Hl'].setVisible(False,False)
|
|
||||||
scene.objects['Reset-view-Hl'].setVisible(False,False)
|
scene.objects['Reset-view-Hl'].setVisible(False,False)
|
||||||
scene.objects['Help-cmd-Hl'].setVisible(False,False)
|
scene.objects['Doc-cmd-Hl'].setVisible(False,False)
|
||||||
scene.objects['About-cmd-Hl'].setVisible(False,False)
|
scene.objects['About-cmd-Hl'].setVisible(False,False)
|
||||||
for i in range (1, 9):
|
|
||||||
scene.objects['Color-'+str(i)+"-Hl"].setVisible(False,False)
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Highlight des commandes
|
# Highlight des commandes
|
||||||
@ -152,7 +127,7 @@ def cmd_hl(cont):
|
|||||||
obj = cont.owner
|
obj = cont.owner
|
||||||
|
|
||||||
# Activation
|
# Activation
|
||||||
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['Mecanism']['manip_mode']==0:
|
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!="Play" and obj.name!="Pause" and obj.name!="Play-Hl" and obj.name!="Pause-Hl":
|
||||||
obj.setVisible(False,True)
|
obj.setVisible(False,True)
|
||||||
scene.objects[obj.name+'-Hl'].setVisible(True,True)
|
scene.objects[obj.name+'-Hl'].setVisible(True,True)
|
||||||
@ -160,7 +135,7 @@ def cmd_hl(cont):
|
|||||||
|
|
||||||
# Play et pause
|
# Play et pause
|
||||||
if obj.name=="Pause" or obj.name=="Play":
|
if obj.name=="Pause" or obj.name=="Play":
|
||||||
if scene.objects['Mecanism']['anim'] == True:
|
if scene.objects['System']['anim'] == True:
|
||||||
scene.objects['Pause'].setVisible(False,False)
|
scene.objects['Pause'].setVisible(False,False)
|
||||||
scene.objects['Pause-Hl'].setVisible(True,False)
|
scene.objects['Pause-Hl'].setVisible(True,False)
|
||||||
else:
|
else:
|
||||||
@ -168,14 +143,14 @@ def cmd_hl(cont):
|
|||||||
scene.objects['Play-Hl'].setVisible(True,False)
|
scene.objects['Play-Hl'].setVisible(True,False)
|
||||||
|
|
||||||
# Désactivation
|
# Désactivation
|
||||||
if cont.sensors['MO'].status == JUST_RELEASED and scene.objects['Mecanism']['manip_mode']==0:
|
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 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)
|
scene.objects[obj.name+'-Hl'].setVisible(False,True)
|
||||||
obj.setVisible(True,True)
|
obj.setVisible(True,True)
|
||||||
|
|
||||||
# Play et pause
|
# Play et pause
|
||||||
if obj.name=="Pause" or obj.name=="Play":
|
if obj.name=="Pause" or obj.name=="Play":
|
||||||
if scene.objects['Mecanism']['anim'] == True:
|
if scene.objects['System']['anim'] == True:
|
||||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||||
scene.objects['Pause'].setVisible(True,False)
|
scene.objects['Pause'].setVisible(True,False)
|
||||||
else:
|
else:
|
||||||
@ -188,12 +163,12 @@ def cmd_hl(cont):
|
|||||||
|
|
||||||
def cmd_click(cont):
|
def cmd_click(cont):
|
||||||
obj = cont.owner
|
obj = cont.owner
|
||||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Mecanism']['manip_mode']==0:
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['System']['manip_mode']==0:
|
||||||
|
|
||||||
# Play et pause
|
# Play et pause
|
||||||
if obj.name=="Pause" or obj.name=="Run":
|
if obj.name=="Pause" or obj.name=="Run":
|
||||||
# Pause
|
# Pause
|
||||||
if scene.objects['Mecanism']['anim'] == True:
|
if scene.objects['System']['anim'] == True:
|
||||||
anim_pause()
|
anim_pause()
|
||||||
scene.objects['Pause'].setVisible(False,False)
|
scene.objects['Pause'].setVisible(False,False)
|
||||||
scene.objects['Pause-Hl'].setVisible(False,False)
|
scene.objects['Pause-Hl'].setVisible(False,False)
|
||||||
@ -215,7 +190,7 @@ def cmd_click(cont):
|
|||||||
|
|
||||||
# About
|
# About
|
||||||
if obj.name=="About-cmd" :
|
if obj.name=="About-cmd" :
|
||||||
if scene.objects['Mecanism']['anim'] == True: # Rendu meilleur en pause
|
if scene.objects['System']['anim'] == True: # Rendu meilleur en pause
|
||||||
scene.objects['About']['anim']= True
|
scene.objects['About']['anim']= True
|
||||||
anim_pause()
|
anim_pause()
|
||||||
else:
|
else:
|
||||||
@ -224,88 +199,13 @@ def cmd_click(cont):
|
|||||||
|
|
||||||
# Aide
|
# Aide
|
||||||
if obj.name=="Help-cmd" :
|
if obj.name=="Help-cmd" :
|
||||||
if scene.objects['Mecanism']['anim'] == True: # Rendu meilleur en pause
|
if scene.objects['System']['anim'] == True: # Rendu meilleur en pause
|
||||||
scene.objects['Doc']['anim']= True
|
scene.objects['Doc']['anim']= True
|
||||||
anim_pause()
|
anim_pause()
|
||||||
else:
|
else:
|
||||||
scene.objects['Doc']['anim'] = False
|
scene.objects['Doc']['anim'] = False
|
||||||
cine_doc.open()
|
cine_doc.open()
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Animation
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
# Initialisation de l'animation -> Play
|
|
||||||
def anim_init():
|
|
||||||
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 scene.objects['Mecanism']['objects_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['Mecanism']['anim'] = True
|
|
||||||
|
|
||||||
# Animation en pause (bas niveau)
|
|
||||||
def anim_pause():
|
|
||||||
layer = 0
|
|
||||||
for objet in scene.objects['Mecanism']['objects_anim'] :
|
|
||||||
scene.objects['Mecanism']['anim_frame'] = scene.objects[objet].getActionFrame(layer)
|
|
||||||
scene.objects[objet].stopAction(layer)
|
|
||||||
scene.objects['Mecanism']['anim'] = False
|
|
||||||
|
|
||||||
# Animation en pseudo-pause
|
|
||||||
# Play d'une frame pour remettre les pièces en place (après-éclatement)
|
|
||||||
def anim_play1frame():
|
|
||||||
start = scene.objects['Mecanism']['anim_frame']
|
|
||||||
end = scene.objects['Mecanism']['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 scene.objects['Mecanism']['objects_anim'] :
|
|
||||||
scene.objects[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
|
||||||
scene.objects['Mecanism']['anim_frame'] = end
|
|
||||||
|
|
||||||
# Reprise de l'animation (bas niveau)
|
|
||||||
def anim_play():
|
|
||||||
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
|
|
||||||
|
|
||||||
# Play en continu
|
|
||||||
def anim_boucle(cont):
|
|
||||||
if scene.objects['Mecanism']['anim'] == True and scene.objects[scene.objects['Mecanism']['objects_anim'][0]].isPlayingAction(0) == False:
|
|
||||||
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 scene.objects['Mecanism']['objects_anim'] :
|
|
||||||
scene.objects[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Manipulation du mécanisme
|
# Manipulation du mécanisme
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -327,21 +227,6 @@ def circle (center, radius, color):
|
|||||||
bge.render.drawLine([x0,y0,z0],[x1,y1,z1],color)
|
bge.render.drawLine([x0,y0,z0],[x1,y1,z1],color)
|
||||||
ang += ang_step
|
ang += ang_step
|
||||||
|
|
||||||
# def circle (center, radius, color):
|
|
||||||
# ang = 0
|
|
||||||
# ang_step = 0.1
|
|
||||||
# ang_cam = (25.1 * 2 * math.pi)*(1/360)
|
|
||||||
# while ang< 2 * math.pi:
|
|
||||||
# x0 = center[0]+float(radius*math.cos(ang))
|
|
||||||
# y0 = center[1] +float(radius*math.sin(ang_cam)*math.cos(ang))
|
|
||||||
# z0 = center[2]+float(radius*math.sin(ang) - y0*math.tan(ang_cam))
|
|
||||||
# x1 = center[0]+float(radius*math.cos(ang+ang_step))
|
|
||||||
# y1 = center[1] +float(radius*math.sin(ang_cam)*math.cos(ang+ang_step))
|
|
||||||
# z1 = center[2]+float(radius*math.sin(ang+ang_step) - y1*math.tan(ang_cam))
|
|
||||||
# bge.render.drawLine([x0,y0,z0],[x1,y1,z1],color)
|
|
||||||
# ang += ang_step
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Initialisation de la vue 3D
|
# Initialisation de la vue 3D
|
||||||
##
|
##
|
||||||
@ -357,7 +242,7 @@ def manip_init():
|
|||||||
scene.objects['Doc'].setVisible(False,True)
|
scene.objects['Doc'].setVisible(False,True)
|
||||||
|
|
||||||
# Mémorisation de la position des composants
|
# Mémorisation de la position des composants
|
||||||
for objet in scene.objects['Mecanism']['objects'] :
|
for objet in scene.objects['System']['objects'] :
|
||||||
scene.objects[objet]['init_lx']=scene.objects[objet].worldPosition.x
|
scene.objects[objet]['init_lx']=scene.objects[objet].worldPosition.x
|
||||||
scene.objects[objet]['init_ly']=scene.objects[objet].worldPosition.y
|
scene.objects[objet]['init_ly']=scene.objects[objet].worldPosition.y
|
||||||
scene.objects[objet]['init_lz']=scene.objects[objet].worldPosition.z
|
scene.objects[objet]['init_lz']=scene.objects[objet].worldPosition.z
|
||||||
@ -375,12 +260,12 @@ def manip_init():
|
|||||||
scene.objects['Camera']['init_lz']=scene.objects['Camera'].worldPosition.z
|
scene.objects['Camera']['init_lz']=scene.objects['Camera'].worldPosition.z
|
||||||
|
|
||||||
# Mémorisation de la position du modèle
|
# Mémorisation de la position du modèle
|
||||||
scene.objects['Mecanism']['init_lx']=scene.objects['Mecanism'].worldPosition.x
|
scene.objects['System']['init_lx']=scene.objects['System'].worldPosition.x
|
||||||
scene.objects['Mecanism']['init_ly']=scene.objects['Mecanism'].worldPosition.y
|
scene.objects['System']['init_ly']=scene.objects['System'].worldPosition.y
|
||||||
scene.objects['Mecanism']['init_lz']=scene.objects['Mecanism'].worldPosition.z
|
scene.objects['System']['init_lz']=scene.objects['System'].worldPosition.z
|
||||||
scene.objects['Mecanism']['init_rx']=scene.objects['Mecanism'].worldOrientation.to_euler().x
|
scene.objects['System']['init_rx']=scene.objects['System'].worldOrientation.to_euler().x
|
||||||
scene.objects['Mecanism']['init_ry']=scene.objects['Mecanism'].worldOrientation.to_euler().y
|
scene.objects['System']['init_ry']=scene.objects['System'].worldOrientation.to_euler().y
|
||||||
scene.objects['Mecanism']['init_rz']=scene.objects['Mecanism'].worldOrientation.to_euler().z
|
scene.objects['System']['init_rz']=scene.objects['System'].worldOrientation.to_euler().z
|
||||||
|
|
||||||
##
|
##
|
||||||
# Atteindre une orientation (bas niveau)
|
# Atteindre une orientation (bas niveau)
|
||||||
@ -424,36 +309,16 @@ def manip_reset():
|
|||||||
scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['init_lx']
|
scene.objects['Camera'].worldPosition.x = scene.objects['Camera']['init_lx']
|
||||||
scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly']
|
scene.objects['Camera'].worldPosition.y = scene.objects['Camera']['init_ly']
|
||||||
scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz']
|
scene.objects['Camera'].worldPosition.z = scene.objects['Camera']['init_lz']
|
||||||
applyRotationTo(scene.objects['Mecanism'], 0, 0, 0)
|
applyRotationTo(scene.objects['System'], 0, 0, 0)
|
||||||
scene.objects['Mecanism'].worldPosition.x = scene.objects['Mecanism']['init_lx']
|
scene.objects['System'].worldPosition.x = scene.objects['System']['init_lx']
|
||||||
scene.objects['Mecanism'].worldPosition.y = scene.objects['Mecanism']['init_ly']
|
scene.objects['System'].worldPosition.y = scene.objects['System']['init_ly']
|
||||||
scene.objects['Mecanism'].worldPosition.z = scene.objects['Mecanism']['init_lz']
|
scene.objects['System'].worldPosition.z = scene.objects['System']['init_lz']
|
||||||
for objet in scene.objects['Mecanism']['objects'] :
|
for objet in scene.objects['System']['objects'] :
|
||||||
scene.objects[objet].setVisible(True,False)
|
scene.objects[objet].setVisible(True,False)
|
||||||
scene.objects[objet].restorePhysics()
|
scene.objects[objet].restorePhysics()
|
||||||
if objet+"_Lines.GP" in scene.objects:
|
if objet+"_Lines.GP" in scene.objects:
|
||||||
scene.objects[objet+"_Lines.GP"].setVisible(True,False)
|
scene.objects[objet+"_Lines.GP"].setVisible(True,False)
|
||||||
|
|
||||||
# Retour après éclatement
|
|
||||||
if scene.objects['Mecanism']['expld'] ==True:
|
|
||||||
print ("retour explod")
|
|
||||||
scene.objects['Mecanism']['expld'] = False
|
|
||||||
expld_val = scene.objects['Mecanism']['expld_val'] # Retour après éclatement avec la valeur d'éclatement
|
|
||||||
sensibilite=0.005
|
|
||||||
objects = scene.objects['Mecanism']['objects']
|
|
||||||
for object in objects :
|
|
||||||
ecla_x, ecla_y,ecla_z = 0,0,0
|
|
||||||
if 'ecla_x' in scene.objects[object]:
|
|
||||||
ecla_x = scene.objects[object]['ecla_x']
|
|
||||||
if 'ecla_y' in scene.objects[object]:
|
|
||||||
ecla_y = scene.objects[object]['ecla_y']
|
|
||||||
if 'ecla_z' in scene.objects[object]:
|
|
||||||
ecla_z = scene.objects[object]['ecla_z']
|
|
||||||
scene.objects[object].applyMovement((-expld_val*sensibilite*ecla_x, -expld_val*sensibilite*ecla_y , -expld_val*sensibilite*ecla_z), False)
|
|
||||||
scene.objects['Mecanism']['expld_val'] = 0.00
|
|
||||||
if scene.objects['Mecanism']['anim'] == False: # Play d'une frame
|
|
||||||
anim_play1frame()
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Position de départ pour la manipulation de la vue
|
# Position de départ pour la manipulation de la vue
|
||||||
##
|
##
|
||||||
@ -501,45 +366,17 @@ def manip(cont):
|
|||||||
bge.render.drawLine([x0+pas_x*i, y0+abs(pas_y*math.sin((3.14*i)/n)), z0-pas_z*i],
|
bge.render.drawLine([x0+pas_x*i, y0+abs(pas_y*math.sin((3.14*i)/n)), z0-pas_z*i],
|
||||||
[x0+pas_x*(i+1), y0+abs(pas_y*math.sin((3.14*(i+1))/n)), z0-pas_z*(i+1)],
|
[x0+pas_x*(i+1), y0+abs(pas_y*math.sin((3.14*(i+1))/n)), z0-pas_z*(i+1)],
|
||||||
[0.8, 0.619, 0.021])
|
[0.8, 0.619, 0.021])
|
||||||
scene.objects['Mecanism'].applyRotation((delta_y*sensibilite_orbit, 0, delta_x*sensibilite_orbit), False)
|
scene.objects['System'].applyRotation((delta_y*sensibilite_orbit, 0, delta_x*sensibilite_orbit), False)
|
||||||
else: # Orbit sur y
|
else: # Orbit sur y
|
||||||
circle ([x0,y0,z0], 5, color_cmd_hl)
|
circle ([x0,y0,z0], 5, color_cmd_hl)
|
||||||
if abs(delta_x) >= abs(delta_y):
|
if abs(delta_x) >= abs(delta_y):
|
||||||
scene.objects['Mecanism'].applyRotation((0, delta_x*sensibilite_orbit, 0), False)
|
scene.objects['System'].applyRotation((0, delta_x*sensibilite_orbit, 0), False)
|
||||||
else:
|
else:
|
||||||
scene.objects['Mecanism'].applyRotation((0, delta_y*sensibilite_orbit, 0), False)
|
scene.objects['System'].applyRotation((0, delta_y*sensibilite_orbit, 0), False)
|
||||||
|
|
||||||
|
|
||||||
# FIXME : Détecter le sens (trigo ou horaire)
|
|
||||||
# print ("cont.sensors['DownM'].position[0]", cont.sensors['DownM'].position[0])
|
|
||||||
# print ("cont.sensors['DownM'].position[1]", cont.sensors['DownM'].position[1])
|
|
||||||
# print ("delta_x", delta_x)
|
|
||||||
# print ("delta_y", delta_y)
|
|
||||||
# # if delta_x != 0 and delta_y != 0:
|
|
||||||
# # print ("delta :", math.sqrt(abs(delta_x*delta_y))*sensibilite_orbit*(delta_x/abs(delta_x))*(delta_y/abs(delta_y)))
|
|
||||||
# # scene.objects['Mecanism'].applyRotation((0, math.sqrt(abs(delta_x*delta_y))*sensibilite_orbit*(delta_x/abs(delta_x))*(delta_y/abs(delta_y)), 0), False)
|
|
||||||
# # elif delta_y != 0:
|
|
||||||
# # print ("delta :", math.sqrt(abs(delta_x*delta_y))*sensibilite_orbit*(delta_y/abs(delta_y)))
|
|
||||||
# # scene.objects['Mecanism'].applyRotation((0, math.sqrt(abs(delta_x*delta_y))*sensibilite_orbit*(delta_y/abs(delta_y)), 0), False)
|
|
||||||
# # elif delta_x != 0:
|
|
||||||
# # print ("delta :", math.sqrt(abs(delta_x*delta_y))*sensibilite_orbit*(delta_x/abs(delta_x)))
|
|
||||||
# # scene.objects['Mecanism'].applyRotation((0, math.sqrt(abs(delta_x*delta_y))*sensibilite_orbit*(delta_x/abs(delta_x)), 0), False)
|
|
||||||
# if abs(delta_x) >= abs(delta_y):
|
|
||||||
# scene.objects['Mecanism'].applyRotation((0, delta_x*sensibilite_orbit, 0), False)
|
|
||||||
# # if cont.sensors['DownM'].position[1] > height /2:
|
|
||||||
# # scene.objects['Mecanism'].applyRotation((0, delta_x*sensibilite_orbit, 0), False)
|
|
||||||
# # else:
|
|
||||||
# # scene.objects['Mecanism'].applyRotation((0, -delta_x*sensibilite_orbit, 0), False)
|
|
||||||
# else:
|
|
||||||
# scene.objects['Mecanism'].applyRotation((0, delta_y*sensibilite_orbit, 0), False)
|
|
||||||
# # if cont.sensors['DownM'].position[0] > width /2:
|
|
||||||
# # scene.objects['Mecanism'].applyRotation((0, delta_y*sensibilite_orbit, 0), False)
|
|
||||||
# # else:
|
|
||||||
# # scene.objects['Mecanism'].applyRotation((0, -delta_y*sensibilite_orbit, 0), False)
|
|
||||||
|
|
||||||
# Pan
|
# Pan
|
||||||
if obj['manip_mode']==1: # Shift
|
if obj['manip_mode']==1: # Shift
|
||||||
scene.objects['Mecanism'].applyMovement((delta_x*sensibilite_pan, -delta_y*sensibilite_pan, -delta_y*sensibilite_pan), False)
|
scene.objects['System'].applyMovement((delta_x*sensibilite_pan, -delta_y*sensibilite_pan, -delta_y*sensibilite_pan), False)
|
||||||
# scene.objects['Camera'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan, 0), True)
|
# scene.objects['Camera'].applyMovement((delta_x*-sensibilite_pan, delta_y*sensibilite_pan, 0), True)
|
||||||
|
|
||||||
# Zoom
|
# Zoom
|
||||||
@ -558,230 +395,3 @@ def manip_wheel(cont):
|
|||||||
scene.objects['Camera'].applyMovement((0, 0, -sensibilite_wheel), True)
|
scene.objects['Camera'].applyMovement((0, 0, -sensibilite_wheel), True)
|
||||||
if cont.sensors['WheelDown'].positive:
|
if cont.sensors['WheelDown'].positive:
|
||||||
scene.objects['Camera'].applyMovement((0, 0, sensibilite_wheel), True)
|
scene.objects['Camera'].applyMovement((0, 0, sensibilite_wheel), True)
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Eclaté
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
# Position de départ pour l'éclatement de la vue
|
|
||||||
def expld_start(cont):
|
|
||||||
if scene.objects['Mecanism']['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 eclatée
|
|
||||||
def expld(cont):
|
|
||||||
obj = cont.owner
|
|
||||||
sensibilite=0.005
|
|
||||||
delta=(cont.sensors['Down'].position[0]-obj['click_x'])+(cont.sensors['Down'].position[1]-obj['click_y'])
|
|
||||||
objects = scene.objects['Mecanism']['objects']
|
|
||||||
if obj['manip_mode']==1: # Shift
|
|
||||||
scene.objects['Mecanism']['expld'] =True
|
|
||||||
scene.objects['Mecanism']['expld_val'] =scene.objects['Mecanism']['expld_val']+delta
|
|
||||||
|
|
||||||
# Déplacement dans le repère du mécanisme
|
|
||||||
x_axis = scene.objects['Mecanism'].orientation.col[0]
|
|
||||||
y_axis = scene.objects['Mecanism'].orientation.col[1]
|
|
||||||
z_axis = scene.objects['Mecanism'].orientation.col[2]
|
|
||||||
for object in objects :
|
|
||||||
ecla_x, ecla_y,ecla_z = 0,0,0
|
|
||||||
if 'ecla_x' in scene.objects[object]:
|
|
||||||
ecla_x = scene.objects[object]['ecla_x']
|
|
||||||
if 'ecla_y' in scene.objects[object]:
|
|
||||||
ecla_y = scene.objects[object]['ecla_y']
|
|
||||||
if 'ecla_z' in scene.objects[object]:
|
|
||||||
ecla_z = scene.objects[object]['ecla_z']
|
|
||||||
scene.objects[object].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[object].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[object].applyMovement((delta*sensibilite*ecla_z*z_axis[0], delta*sensibilite*ecla_z*z_axis[1] , delta*sensibilite*ecla_z*z_axis[2]), False)
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Couleur
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
# Reset des couleurs du mécanisme
|
|
||||||
def color_reset():
|
|
||||||
colors_dict = scene.objects['Mecanism']['colors_dict']
|
|
||||||
for object in scene.objects['Mecanism']['objects'] :
|
|
||||||
scene.objects[object].color = colors_dict[scene.objects['Mecanism']['objects_dict'][object][2]]
|
|
||||||
scene.objects['Nomenclature-'+str(scene.objects['Mecanism']['objects_dict'][object][0])].color = colors_dict[scene.objects['Mecanism']['objects_dict'][object][2]]
|
|
||||||
scene.objects['Nomenclature-'+str(scene.objects['Mecanism']['objects_dict'][object][0])+'-Hl'].color = colors_dict[scene.objects['Mecanism']['objects_dict'][object][2]]
|
|
||||||
|
|
||||||
# Sélection couleur dans la palette avec son numéro de couleur (bas niveau)
|
|
||||||
def color_num(num):
|
|
||||||
for i in range (1, 9):
|
|
||||||
scene.objects['Color-'+str(i)].worldScale=[0.125, 0.125, 0.125]
|
|
||||||
scene.objects['Color-'+str(i)+"-Hl"].worldScale=[0.125, 0.125, 0.125]
|
|
||||||
scene.objects['Color-'+str(num)].worldScale=[0.156, 0.156, 0.156]
|
|
||||||
scene.objects['Color-'+str(num)+'-Hl'].worldScale=[0.156, 0.156, 0.156]
|
|
||||||
scene.objects['Colors']['color_current']=num
|
|
||||||
|
|
||||||
# Clic sur la palette
|
|
||||||
def color_click(cont):
|
|
||||||
obj = cont.owner
|
|
||||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Mecanism']['manip_mode']==0:
|
|
||||||
color_num(int(obj.name[6]))
|
|
||||||
|
|
||||||
# Highlight de la palette
|
|
||||||
def color_hl(cont):
|
|
||||||
if cont.sensors['MO'].positive and scene.objects['Mecanism']['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 = color_cmd_hl
|
|
||||||
if cont.sensors['MO'].status == JUST_RELEASED:
|
|
||||||
for i in range (1, 9):
|
|
||||||
scene.objects['Color-'+str(i)].setVisible(True,True)
|
|
||||||
scene.objects['Color-'+str(i)+"-Hl"].setVisible(False,True)
|
|
||||||
|
|
||||||
# Colorisation de la pièce
|
|
||||||
def color_object(cont):
|
|
||||||
if cont.sensors['Click'].positive and scene.objects['Mecanism']['manip_mode']==0:
|
|
||||||
hitObject = cont.sensors['MO'].hitObject
|
|
||||||
if hitObject is not None and hitObject.visible:
|
|
||||||
color_select = scene.objects['Colors']['color_current']
|
|
||||||
if color_select != 0 and color_select != 8:
|
|
||||||
colors = scene.objects['Mecanism']['colors']
|
|
||||||
hitObject.color = colors[color_select-1][1]
|
|
||||||
scene.objects['Nomenclature-'+str(scene.objects['Mecanism']['objects_dict'][hitObject.name][0])].color = colors[color_select-1][1]
|
|
||||||
scene.objects['Nomenclature-'+str(scene.objects['Mecanism']['objects_dict'][hitObject.name][0])+'-Hl'].color = colors[color_select-1][1]
|
|
||||||
if color_select == 8: # Couleur transparente -> disparition
|
|
||||||
hitObject.setVisible(False,False)
|
|
||||||
hitObject.suspendPhysics (True)
|
|
||||||
if hitObject.name+"_Lines.GP" in scene.objects:
|
|
||||||
scene.objects[hitObject.name+"_Lines.GP"].setVisible(False,False)
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Objets
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
# Initialisation du mécanisme
|
|
||||||
def objects_init():
|
|
||||||
|
|
||||||
objects = scene.objects['Mecanism']['objects']
|
|
||||||
objects_dict = scene.objects['Mecanism']['objects_dict']
|
|
||||||
colors_dict = scene.objects['Mecanism']['colors_dict']
|
|
||||||
|
|
||||||
i=1
|
|
||||||
for object in objects:
|
|
||||||
|
|
||||||
# Couleurs
|
|
||||||
scene.objects[object].color = colors_dict[objects_dict[object][2]]
|
|
||||||
|
|
||||||
# Nomenclature
|
|
||||||
scene.objects['Nomenclature-'+str(i)]['Text'] = objects_dict[object][1]
|
|
||||||
scene.objects['Nomenclature-'+str(i)]['Object'] = objects[i-1]
|
|
||||||
scene.objects['Nomenclature-'+str(i)].color = colors_dict[objects_dict[object][2]]
|
|
||||||
scene.objects['Nomenclature-'+str(i)+'-Hl'].setVisible(False,False)
|
|
||||||
scene.objects['Nomenclature-'+str(i)+'-Hl']['Text'] = objects_dict[object][1]
|
|
||||||
scene.objects['Nomenclature-'+str(i)+'-Hl'].color = colors_dict[objects_dict[object][2]]
|
|
||||||
scene.objects['Nomenclature-'+str(i)+'-Ot']['Text'] = objects_dict[object][1]
|
|
||||||
scene.objects['Nomenclature-'+str(i)+'-Ot2']['Text'] = objects_dict[object][1]
|
|
||||||
scene.objects['Nomenclature-'+str(i)+'-Ot2'].setVisible(False,False)
|
|
||||||
|
|
||||||
# Repères
|
|
||||||
if len(objects_dict[object][3])>0:
|
|
||||||
scene.objects['Rep-'+str(i)]['Object'] = objects[i-1]
|
|
||||||
scene.objects['Rep-'+str(i)].color = color_rep_disabled
|
|
||||||
scene.objects['Rep-'+str(i)+'-Hl'].setVisible(False,False)
|
|
||||||
for j in range (len (objects_dict[object][3])):
|
|
||||||
scene.objects[objects_dict[object][3][j]].setVisible(False,True)
|
|
||||||
|
|
||||||
i +=1
|
|
||||||
|
|
||||||
# Highlight de la pièce dans la nomenclature
|
|
||||||
def object_hl(cont):
|
|
||||||
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['Mecanism']['manip_mode']==0:
|
|
||||||
hitObject = cont.sensors['MO'].hitObject
|
|
||||||
if hitObject is not None and hitObject.visible:
|
|
||||||
scene.objects['Nomenclature-'+str(scene.objects['Mecanism']['objects_dict'][hitObject.name][0])].setVisible(False,False)
|
|
||||||
scene.objects['Nomenclature-'+str(scene.objects['Mecanism']['objects_dict'][hitObject.name][0])+'-Hl'].setVisible(True,False)
|
|
||||||
scene.objects['Nomenclature-'+str(scene.objects['Mecanism']['objects_dict'][hitObject.name][0])+'-Ot2'].setVisible(True,False)
|
|
||||||
if cont.sensors['MO'].status == JUST_RELEASED:
|
|
||||||
for objet in scene.objects['Mecanism']['objects'] :
|
|
||||||
scene.objects['Nomenclature-'+str(scene.objects['Mecanism']['objects_dict'][objet][0])].setVisible(True,False)
|
|
||||||
scene.objects['Nomenclature-'+str(scene.objects['Mecanism']['objects_dict'][objet][0])+'-Hl'].setVisible(False,False)
|
|
||||||
scene.objects['Nomenclature-'+str(scene.objects['Mecanism']['objects_dict'][objet][0])+'-Ot2'].setVisible(False,False)
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Nomenclature
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
# Clic sur la nomenclature
|
|
||||||
def nom_click(cont):
|
|
||||||
name=cont.owner.name[:-7]
|
|
||||||
obj = scene.objects[name]
|
|
||||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Mecanism']['manip_mode']==0:
|
|
||||||
color_select = scene.objects['Colors']['color_current']
|
|
||||||
|
|
||||||
# Colorisation de la pièce par la nomenclature
|
|
||||||
if color_select != 0 and color_select != 8:
|
|
||||||
colors = scene.objects['Mecanism']['colors']
|
|
||||||
obj.color = colors[color_select-1][1]
|
|
||||||
scene.objects[name+'-Hl'].color = colors[color_select-1][1]
|
|
||||||
scene.objects[obj['Object']].color = colors[color_select-1][1]
|
|
||||||
if scene.objects[obj['Object']].visible==False:
|
|
||||||
scene.objects[obj['Object']].setVisible(True,False)
|
|
||||||
scene.objects[obj['Object']].restorePhysics()
|
|
||||||
if obj['Object']+"_Lines.GP" in scene.objects:
|
|
||||||
scene.objects[obj['Object']+"_Lines.GP"].setVisible(True,False)
|
|
||||||
|
|
||||||
# Couleur transparente -> disparition / apparition
|
|
||||||
if color_select == 8:
|
|
||||||
if scene.objects[obj['Object']].visible==True:
|
|
||||||
scene.objects[obj['Object']].setVisible(False,False)
|
|
||||||
scene.objects[obj['Object']].suspendPhysics (True)
|
|
||||||
if obj['Object']+"_Lines.GP" in scene.objects:
|
|
||||||
scene.objects[obj['Object']+"_Lines.GP"].setVisible(False,False)
|
|
||||||
else:
|
|
||||||
scene.objects[obj['Object']].setVisible(True,False)
|
|
||||||
scene.objects[obj['Object']].restorePhysics()
|
|
||||||
if obj['Object']+"_Lines.GP" in scene.objects:
|
|
||||||
scene.objects[obj['Object']+"_Lines.GP"].setVisible(True,False)
|
|
||||||
|
|
||||||
# Highlight de la nomenclature
|
|
||||||
def nom_hl(cont):
|
|
||||||
name=cont.owner.name[:-7]
|
|
||||||
obj = scene.objects[name]
|
|
||||||
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['Mecanism']['manip_mode']==0:
|
|
||||||
obj.setVisible(False,False)
|
|
||||||
scene.objects[name+'-Hl'].setVisible(True,False)
|
|
||||||
scene.objects[name+'-Ot2'].setVisible(True,False)
|
|
||||||
if cont.sensors['MO'].status == JUST_RELEASED and scene.objects['Mecanism']['manip_mode']==0:
|
|
||||||
obj.setVisible(True,False)
|
|
||||||
scene.objects[name+'-Hl'].setVisible(False,False)
|
|
||||||
scene.objects[name+'-Ot2'].setVisible(False,False)
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
# Repères
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
# Click sur un repère
|
|
||||||
def rep_click(cont):
|
|
||||||
name=cont.owner.name[:-7]
|
|
||||||
obj = scene.objects[name]
|
|
||||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Mecanism']['manip_mode']==0:
|
|
||||||
objects_dict = scene.objects['Mecanism']['objects_dict']
|
|
||||||
if obj['enabled']:
|
|
||||||
for i in range (len (objects_dict[obj['Object']][3])):
|
|
||||||
scene.objects[objects_dict[obj['Object']][3][i]].setVisible(False,True)
|
|
||||||
obj.color = color_rep_disabled
|
|
||||||
obj['enabled']=False
|
|
||||||
else:
|
|
||||||
for i in range (len (objects_dict[obj['Object']][3])):
|
|
||||||
scene.objects[objects_dict[obj['Object']][3][i]].setVisible(True,True)
|
|
||||||
obj.color = color_rep_enabled
|
|
||||||
obj['enabled']=True
|
|
||||||
|
|
||||||
# Highlight sur un repère
|
|
||||||
def rep_hl(cont):
|
|
||||||
name=cont.owner.name[:-7]
|
|
||||||
obj = scene.objects[name]
|
|
||||||
if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['Mecanism']['manip_mode']==0:
|
|
||||||
obj.setVisible(False,False)
|
|
||||||
scene.objects[name+'-Hl'].setVisible(True,False)
|
|
||||||
if cont.sensors['MO'].status == JUST_RELEASED and scene.objects['Mecanism']['manip_mode']==0:
|
|
||||||
obj.setVisible(True,False)
|
|
||||||
scene.objects[name+'-Hl'].setVisible(False,False)
|
|
||||||
|
@ -60,20 +60,20 @@ def open():
|
|||||||
|
|
||||||
def close(cont):
|
def close(cont):
|
||||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
||||||
if scene.objects['About']['anim'] == True:
|
# if scene.objects['About']['anim'] == True:
|
||||||
start = scene.objects['Mecanism']['anim_frame']
|
# start = scene.objects['Mecanism']['anim_frame']
|
||||||
end = 250
|
# end = 250
|
||||||
layer = 0
|
# layer = 0
|
||||||
priority = 1
|
# priority = 1
|
||||||
blendin = 1.0
|
# blendin = 1.0
|
||||||
mode = bge.logic.KX_ACTION_MODE_PLAY
|
# mode = bge.logic.KX_ACTION_MODE_PLAY
|
||||||
layerWeight = 0.0
|
# layerWeight = 0.0
|
||||||
ipoFlags = 0
|
# ipoFlags = 0
|
||||||
speed = 1.0
|
# speed = 1.0
|
||||||
for objet in scene.objects['Mecanism']['objects_anim'] :
|
# 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[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
||||||
scene.objects['Mecanism']['anim'] = True
|
# scene.objects['Mecanism']['anim'] = True
|
||||||
scene.objects['About']['anim'] == False
|
# scene.objects['About']['anim'] == False
|
||||||
scene.active_camera = scene.objects["Camera"]
|
scene.active_camera = scene.objects["Camera"]
|
||||||
scene.objects['About'].setVisible(False,True)
|
scene.objects['About'].setVisible(False,True)
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ def link(cont):
|
|||||||
obj = cont.owner
|
obj = cont.owner
|
||||||
name=obj.name[:-7]
|
name=obj.name[:-7]
|
||||||
link={
|
link={
|
||||||
'About_link-git' : 'https://gitlab.com/blender-edutech/kinematic_player',
|
'About_link-git' : 'https://gitlab.com/blender-edutech/digital_twin',
|
||||||
'About_link-gpl' : 'https://www.gnu.org/licenses/gpl-3.0.html',
|
'About_link-gpl' : 'https://www.gnu.org/licenses/gpl-3.0.html',
|
||||||
'About_link-upbge' : 'https://www.upbge.org'}
|
'About_link-upbge' : 'https://www.upbge.org'}
|
||||||
webbrowser.open(link [name])
|
webbrowser.open(link [name])
|
||||||
@ -115,40 +115,6 @@ def get_near_pos(array,value):
|
|||||||
idx = (np.abs(array-value)).argmin()
|
idx = (np.abs(array-value)).argmin()
|
||||||
return idx
|
return idx
|
||||||
|
|
||||||
|
|
||||||
# def about_screen_up(cont):
|
|
||||||
# if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
|
||||||
# screen_width_mode=[640, 960, 1280, 1920]
|
|
||||||
# screen_height_mode=[360, 540, 720,1080]
|
|
||||||
# screen_mode_txt=["640x360", "960x540", "1280x720", "1920x1080"]
|
|
||||||
# i = get_near_pos(screen_width_mode, bge.render.getWindowWidth())
|
|
||||||
# if i>=0 and i<3 :
|
|
||||||
# screen_width=screen_width_mode[i+1]
|
|
||||||
# screen_height=screen_height_mode[i+1]
|
|
||||||
# scene.objects['About_screen']['Text']= "SCREEN SIZE : "+str(screen_width) +" x "+str(screen_height)
|
|
||||||
# bge.render.setWindowSize(screen_width,screen_height)
|
|
||||||
|
|
||||||
# # Boutons < et >
|
|
||||||
# if screen_width <=640:
|
|
||||||
# scene.objects['About_screen-down'].setVisible(False,True)
|
|
||||||
# scene.objects['About_screen-down-colbox'].suspendPhysics (True)
|
|
||||||
# else:
|
|
||||||
# scene.objects['About_screen-down'].setVisible(True,True)
|
|
||||||
# scene.objects['About_screen-down-colbox'].restorePhysics()
|
|
||||||
# if screen_width >= 1920:
|
|
||||||
# scene.objects['About_screen-up'].setVisible(False,True)
|
|
||||||
# scene.objects['About_screen-up-colbox'].suspendPhysics (True)
|
|
||||||
# else:
|
|
||||||
# scene.objects['About_screen-up'].setVisible(True,True)
|
|
||||||
# scene.objects['About_screen-up-colbox'].restorePhysics()
|
|
||||||
|
|
||||||
# # Maj du fichier de config (screen size : data/config/screen/width-> [0][3][0].text)
|
|
||||||
# rp_config_tree[0][3][0].text=str(screen_width)
|
|
||||||
# rp_config_tree[0][3][1].text=str(screen_height)
|
|
||||||
# buffer_xml = ET.tostring(rp_config_tree)
|
|
||||||
# with open("rp_config.xml", "wb") as f:
|
|
||||||
# f.write(buffer_xml)
|
|
||||||
|
|
||||||
# Taille de l'écran +
|
# Taille de l'écran +
|
||||||
def screen_up(cont):
|
def screen_up(cont):
|
||||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
||||||
@ -176,40 +142,6 @@ def screen_up(cont):
|
|||||||
scene.objects['About_screen-up'].setVisible(True,True)
|
scene.objects['About_screen-up'].setVisible(True,True)
|
||||||
scene.objects['About_screen-up-colbox'].restorePhysics()
|
scene.objects['About_screen-up-colbox'].restorePhysics()
|
||||||
|
|
||||||
|
|
||||||
# def about_screen_down(cont):
|
|
||||||
# if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
|
||||||
# screen_width_mode=[640, 960, 1280, 1920]
|
|
||||||
# screen_height_mode=[360, 540, 720,1080]
|
|
||||||
# screen_mode_txt=["640x360", "960x540", "1280x720", "1920x1080"]
|
|
||||||
# i = get_near_pos(screen_width_mode, bge.render.getWindowWidth())
|
|
||||||
# if i>0 and i<=3 :
|
|
||||||
# screen_width=screen_width_mode[i-1]
|
|
||||||
# screen_height=screen_height_mode[i-1]
|
|
||||||
# scene.objects['About_screen']['Text']= "SCREEN SIZE : "+str(screen_width) +" x "+str(screen_height)
|
|
||||||
# bge.render.setWindowSize(screen_width,screen_height)
|
|
||||||
|
|
||||||
# # Boutons < et >
|
|
||||||
# if screen_width <=640:
|
|
||||||
# scene.objects['About_screen-down'].setVisible(False,True)
|
|
||||||
# scene.objects['About_screen-down-colbox'].suspendPhysics (True)
|
|
||||||
# else:
|
|
||||||
# scene.objects['About_screen-down'].setVisible(True,True)
|
|
||||||
# scene.objects['About_screen-down-colbox'].restorePhysics()
|
|
||||||
# if screen_width >= 1920:
|
|
||||||
# scene.objects['About_screen-up'].setVisible(False,True)
|
|
||||||
# scene.objects['About_screen-up-colbox'].suspendPhysics (True)
|
|
||||||
# else:
|
|
||||||
# scene.objects['About_screen-up'].setVisible(True,True)
|
|
||||||
# scene.objects['About_screen-up-colbox'].restorePhysics()
|
|
||||||
|
|
||||||
# # Maj du fichier de config (screen size : data/config/screen/width-> [0][3][0].text)
|
|
||||||
# rp_config_tree[0][3][0].text=str(screen_width)
|
|
||||||
# rp_config_tree[0][3][1].text=str(screen_height)
|
|
||||||
# buffer_xml = ET.tostring(rp_config_tree)
|
|
||||||
# with open("rp_config.xml", "wb") as f:
|
|
||||||
# f.write(buffer_xml)
|
|
||||||
|
|
||||||
# Taille de l'écran -
|
# Taille de l'écran -
|
||||||
def screen_down(cont):
|
def screen_down(cont):
|
||||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
||||||
|
@ -35,20 +35,20 @@ def open():
|
|||||||
|
|
||||||
def close(cont):
|
def close(cont):
|
||||||
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive :
|
||||||
if scene.objects['Doc']['anim'] == True:
|
# if scene.objects['Doc']['anim'] == True:
|
||||||
start = scene.objects['Mecanism']['anim_frame']
|
# start = scene.objects['Mecanism']['anim_frame']
|
||||||
end = 250
|
# end = 250
|
||||||
layer = 0
|
# layer = 0
|
||||||
priority = 1
|
# priority = 1
|
||||||
blendin = 1.0
|
# blendin = 1.0
|
||||||
mode = bge.logic.KX_ACTION_MODE_PLAY
|
# mode = bge.logic.KX_ACTION_MODE_PLAY
|
||||||
layerWeight = 0.0
|
# layerWeight = 0.0
|
||||||
ipoFlags = 0
|
# ipoFlags = 0
|
||||||
speed = 1.0
|
# speed = 1.0
|
||||||
for objet in scene.objects['Mecanism']['objects_anim'] :
|
# 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[objet].playAction(objet+'-Action', start, end, layer, priority, blendin, mode, layerWeight, ipoFlags, speed)
|
||||||
scene.objects['Mecanism']['anim'] = True
|
# scene.objects['Mecanism']['anim'] = True
|
||||||
scene.objects['Doc']['anim'] == False
|
# scene.objects['Doc']['anim'] == False
|
||||||
scene.active_camera = scene.objects["Camera"]
|
scene.active_camera = scene.objects["Camera"]
|
||||||
scene.objects['Doc'].setVisible(False,True)
|
scene.objects['Doc'].setVisible(False,True)
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
/home/phroy/Bureau/seriousgames/blender-edutech/git/digital_twin/jumeau.py
|
/home/phroy/Documents/blender-edutech/git/digital_twin/jumeau.py
|
@ -1 +1 @@
|
|||||||
/home/phroy/Bureau/seriousgames/blender-edutech/git/digital_twin/jumeau_about.py
|
/home/phroy/Documents/blender-edutech/git/digital_twin/jumeau_about.py
|
@ -1 +1 @@
|
|||||||
/home/phroy/Bureau/seriousgames/blender-edutech/git/digital_twin/jumeau_config.xml
|
/home/phroy/Documents/blender-edutech/git/digital_twin/jumeau_config.xml
|
@ -1 +1 @@
|
|||||||
/home/phroy/Bureau/seriousgames/blender-edutech/git/digital_twin/jumeau_doc.py
|
/home/phroy/Documents/blender-edutech/git/digital_twin/jumeau_doc.py
|
55
portail_coulissant/porcou_cmd.py
Normal file
55
portail_coulissant/porcou_cmd.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
from porcou_lib import * # Bibliothèque portail coulissant
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# porcou_cmd.py
|
||||||
|
# @title: Commandes du portail coulissant
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Instructions élémentaires pour le portail coulissant
|
||||||
|
#
|
||||||
|
# Actions (ordre = True ou False) :
|
||||||
|
# - Gyrophare : gyr (True|False)
|
||||||
|
# - Ouvrir le portail (moteur sens trigo) : mot_o (True|False)
|
||||||
|
# - Fermer le portail (moteur sens horaire) : mot_f (True|False)
|
||||||
|
# - Emetteur pour le capteur barrage IR : ir_emet(True|False)
|
||||||
|
#
|
||||||
|
# Capteurs (valeur retournée = True ou False) :
|
||||||
|
# - Capteur fin de course portail ouvert : fc_o()
|
||||||
|
# - Capteur fin de course portail fermé : fc_f()
|
||||||
|
# - Capteur barrage IR (absence d'obstacle) : ir_recep()
|
||||||
|
#
|
||||||
|
# Pupitre (valeur retournée = True ou False) :
|
||||||
|
# - Bouton poussoir coté rue : bp_ext()
|
||||||
|
# - Bouton poussoir coté cour : bp_int()
|
||||||
|
#
|
||||||
|
# Gestion du temps :
|
||||||
|
# - Temporisation en seconde : tempo(duree)
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Fonctions
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Commandes
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
def commandes():
|
||||||
|
|
||||||
|
# Ecrire votre code ici ...
|
||||||
|
gyr(True) # Activer le gyrophare
|
||||||
|
|
||||||
|
porcou_fin() # A garder
|
||||||
|
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# En: External call << DONT CHANGE THIS SECTION >>
|
||||||
|
# Fr: Appel externe << NE PAS MODIFIER CETTE SECTION >>
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
if __name__=='start':
|
||||||
|
thread_cmd_start(commandes)
|
||||||
|
if __name__=='stop':
|
||||||
|
thread_cmd_stop()
|
52
portail_coulissant/porcou_cmd.py.~1~
Normal file
52
portail_coulissant/porcou_cmd.py.~1~
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
||||||
|
from porcou_lib import * # Bibliothèque portail coulissant
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# porcou_cmd.py
|
||||||
|
# @title: Commandes du portail coulissant
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Gestion des tâches (threads) << NE PAS MODIFIER CETTE SECTION >>
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
threads=[]
|
||||||
|
scene = bge.logic.getCurrentScene()
|
||||||
|
|
||||||
|
def start():
|
||||||
|
thread_start(threads, commandes)
|
||||||
|
|
||||||
|
def stop():
|
||||||
|
thread_stop(threads)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Instructions élémentaires pour le portail coulissant
|
||||||
|
#
|
||||||
|
# Actions (ordre = True ou False) :
|
||||||
|
# - Gyrophare : gyr (True|False)
|
||||||
|
# - Ouvrir le portail (moteur sens trigo) : mot_o (True|False)
|
||||||
|
# - Fermer le portail (moteur sens horaire) : mot_f (True|False)
|
||||||
|
# - Emetteur pour le capteur barrage IR : ir_emet(True|False)
|
||||||
|
#
|
||||||
|
# Capteurs (valeur retournée = True ou False) :
|
||||||
|
# - Capteur fin de course portail ouvert : fc_o()
|
||||||
|
# - Capteur fin de course portail fermé : fc_f()
|
||||||
|
# - Capteur barrage IR (absence d'obstacle) : ir_recep()
|
||||||
|
#
|
||||||
|
# Pupitre (valeur retournée = True ou False) :
|
||||||
|
# - Bouton poussoir coté rue : bp_ext()
|
||||||
|
# - Bouton poussoir coté cour : bp_int()
|
||||||
|
#
|
||||||
|
# Gestion du temps :
|
||||||
|
# - Temporisation en seconde : tempo(duree)
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
def commandes():
|
||||||
|
|
||||||
|
# Coder vos commandes ici ...
|
||||||
|
|
||||||
|
gyr(True) # Activer le gyrophare
|
||||||
|
|
||||||
|
print ("Thread #", len(threads)-1, "arrivé au bout -> fermeture.") # Tâche close (thread) << NE PAS MODIFIER CETTE LIGNE >>
|
||||||
|
scene.objects['Systeme']['thread_run']=False # Fin du cycle << NE PAS MODIFIER CETTE LIGNE >>
|
144
portail_coulissant/porcou_lib.py
Normal file
144
portail_coulissant/porcou_lib.py
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
||||||
|
import threading # Multithreading
|
||||||
|
import trace
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# porcou_lib.py
|
||||||
|
# @title: Bibliothèque utilisateur du portail coulissant (pcl_*)
|
||||||
|
# @project: Blender-EduTech
|
||||||
|
# @lang: fr
|
||||||
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||||
|
# @copyright: Copyright (C) 2020-2022 Philippe Roy
|
||||||
|
# @license: GNU GPL
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# Récupérer l'objet portail coulissant
|
||||||
|
scene = bge.logic.getCurrentScene()
|
||||||
|
# print("Objets de la scene : ", scene.objects)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Méthode kill pour les tâches (threads)
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
class thread_with_trace(threading.Thread):
|
||||||
|
def __init__(self, *args, **keywords):
|
||||||
|
threading.Thread.__init__(self, *args, **keywords)
|
||||||
|
self.killed = False
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
self.__run_backup = self.run
|
||||||
|
self.run = self.__run
|
||||||
|
threading.Thread.start(self)
|
||||||
|
|
||||||
|
def __run(self):
|
||||||
|
sys.settrace(self.globaltrace)
|
||||||
|
self.__run_backup()
|
||||||
|
self.run = self.__run_backup
|
||||||
|
|
||||||
|
def globaltrace(self, frame, event, arg):
|
||||||
|
if event == 'call':
|
||||||
|
return self.localtrace
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def localtrace(self, frame, event, arg):
|
||||||
|
if self.killed:
|
||||||
|
if event == 'line':
|
||||||
|
raise SystemExit()
|
||||||
|
return self.localtrace
|
||||||
|
|
||||||
|
def kill(self):
|
||||||
|
self.killed = True
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Start et stop des tâches (threads)
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
def thread_start(threads, commandes):
|
||||||
|
threads.append(thread_with_trace(target = commandes))
|
||||||
|
threads[len(threads)-1].start()
|
||||||
|
scene.objects['Systeme']['thread_run']=True
|
||||||
|
scene.objects['Systeme']['thread_alive']=True
|
||||||
|
print ("Thread #", len(threads)-1, "ouvert.")
|
||||||
|
|
||||||
|
def thread_stop(threads):
|
||||||
|
i=0
|
||||||
|
zombie_flag=False
|
||||||
|
for t in threads:
|
||||||
|
if not t.is_alive():
|
||||||
|
print ("Thread #",i,"fermé.")
|
||||||
|
else:
|
||||||
|
print ("Thread #",i,"encore ouvert ...")
|
||||||
|
t.kill()
|
||||||
|
t.join()
|
||||||
|
if not t.is_alive():
|
||||||
|
print ("Thread #",i,"tué.")
|
||||||
|
else:
|
||||||
|
print ("Thread #",i,"zombie ...")
|
||||||
|
zombie_flag=True
|
||||||
|
i +=1
|
||||||
|
if zombie_flag==False:
|
||||||
|
scene.objects['Systeme']['thread_alive']=False
|
||||||
|
print ("Tous les threads sont fermés.")
|
||||||
|
else:
|
||||||
|
print ("Il reste des threads zombies.")
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Actionneurs
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# Ordres utilisateur du clignotant
|
||||||
|
def gyr (ordre):
|
||||||
|
scene.objects['Module led']['actif']=ordre
|
||||||
|
|
||||||
|
# Ordres utilisateur du moteur
|
||||||
|
def mot_o (ordre):
|
||||||
|
scene.objects['Ensemble moteur']['actif_ouvrir']=ordre
|
||||||
|
|
||||||
|
def mot_f (ordre):
|
||||||
|
scene.objects['Ensemble moteur']['actif_fermer']=ordre
|
||||||
|
|
||||||
|
# Ordre utilisateur du capteur barrage IR
|
||||||
|
def ir_emet(ordre):
|
||||||
|
scene.objects['Module emetteur IR']['actif']=ordre
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Capteurs
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# Compte-rendu utilisateur du capteur fin de course portail ouvert
|
||||||
|
def fc_o ():
|
||||||
|
return scene.objects['Capteur fdc ouvert']['actif']
|
||||||
|
|
||||||
|
# Compte-rendu utilisateur du capteur fin de course portail ouvert
|
||||||
|
def fc_f ():
|
||||||
|
return scene.objects['Capteur fdc ferme']['actif']
|
||||||
|
|
||||||
|
# Compte-rendu utilisateur du capteur barrage IR
|
||||||
|
def ir_recep ():
|
||||||
|
if scene.objects['Module recepteur IR']['actif'] :
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Boutons poussoirs
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# Compte-rendu utilisateur du bouton pousssoir coté rue
|
||||||
|
def bp_ext ():
|
||||||
|
return scene.objects['Module bouton cote rue']['actif']
|
||||||
|
|
||||||
|
# Compte-rendu utilisateur du bouton pousssoir coté cour
|
||||||
|
def bp_int ():
|
||||||
|
return scene.objects['Module bouton cote cour']['actif']
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Temporisation
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
def tempo (duree):
|
||||||
|
time.sleep(duree)
|
147
portail_coulissant/porcou_lib.py.~1~
Normal file
147
portail_coulissant/porcou_lib.py.~1~
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
import bge # Bibliothèque Blender Game Engine (UPBGE)
|
||||||
|
import threading # Multithreading
|
||||||
|
import trace
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# porcou_lib.py
|
||||||
|
# @title: Bibliothèque utilisateur du portail coulissant (pcl_*)
|
||||||
|
# @project: Blender-EduTech
|
||||||
|
# @lang: fr
|
||||||
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||||
|
# @copyright: Copyright (C) 2020-2022 Philippe Roy
|
||||||
|
# @license: GNU GPL
|
||||||
|
#
|
||||||
|
# Ce simulateur est un environnement 3D programmable en Python.
|
||||||
|
# Il est destiné à la découverte de la programmation de système pluritechnique.
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# Récupérer l'objet portail coulissant
|
||||||
|
scene = bge.logic.getCurrentScene()
|
||||||
|
# print("Objets de la scene : ", scene.objects)
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Méthode kill pour les tâches (threads)
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
class thread_with_trace(threading.Thread):
|
||||||
|
def __init__(self, *args, **keywords):
|
||||||
|
threading.Thread.__init__(self, *args, **keywords)
|
||||||
|
self.killed = False
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
self.__run_backup = self.run
|
||||||
|
self.run = self.__run
|
||||||
|
threading.Thread.start(self)
|
||||||
|
|
||||||
|
def __run(self):
|
||||||
|
sys.settrace(self.globaltrace)
|
||||||
|
self.__run_backup()
|
||||||
|
self.run = self.__run_backup
|
||||||
|
|
||||||
|
def globaltrace(self, frame, event, arg):
|
||||||
|
if event == 'call':
|
||||||
|
return self.localtrace
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def localtrace(self, frame, event, arg):
|
||||||
|
if self.killed:
|
||||||
|
if event == 'line':
|
||||||
|
raise SystemExit()
|
||||||
|
return self.localtrace
|
||||||
|
|
||||||
|
def kill(self):
|
||||||
|
self.killed = True
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Start et stop des tâches (threads)
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
def thread_start(threads, commandes):
|
||||||
|
threads.append(thread_with_trace(target = commandes))
|
||||||
|
threads[len(threads)-1].start()
|
||||||
|
scene.objects['Systeme']['thread_run']=True
|
||||||
|
scene.objects['Systeme']['thread_alive']=True
|
||||||
|
print ("Thread #", len(threads)-1, "ouvert.")
|
||||||
|
|
||||||
|
def thread_stop(threads):
|
||||||
|
i=0
|
||||||
|
zombie_flag=False
|
||||||
|
for t in threads:
|
||||||
|
if not t.is_alive():
|
||||||
|
print ("Thread #",i,"fermé.")
|
||||||
|
else:
|
||||||
|
print ("Thread #",i,"encore ouvert ...")
|
||||||
|
t.kill()
|
||||||
|
t.join()
|
||||||
|
if not t.is_alive():
|
||||||
|
print ("Thread #",i,"tué.")
|
||||||
|
else:
|
||||||
|
print ("Thread #",i,"zombie ...")
|
||||||
|
zombie_flag=True
|
||||||
|
i +=1
|
||||||
|
if zombie_flag==False:
|
||||||
|
scene.objects['Systeme']['thread_alive']=False
|
||||||
|
print ("Tous les threads sont fermés.")
|
||||||
|
else:
|
||||||
|
print ("Il reste des threads zombies.")
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Actionneurs
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# Ordres utilisateur du clignotant
|
||||||
|
def gyr (ordre):
|
||||||
|
scene.objects['Module led']['actif']=ordre
|
||||||
|
|
||||||
|
# Ordres utilisateur du moteur
|
||||||
|
def mot_o (ordre):
|
||||||
|
scene.objects['Ensemble moteur']['actif_ouvrir']=ordre
|
||||||
|
|
||||||
|
def mot_f (ordre):
|
||||||
|
scene.objects['Ensemble moteur']['actif_fermer']=ordre
|
||||||
|
|
||||||
|
# Ordre utilisateur du capteur barrage IR
|
||||||
|
def ir_emet(ordre):
|
||||||
|
scene.objects['Module emetteur IR']['actif']=ordre
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Capteurs
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# Compte-rendu utilisateur du capteur fin de course portail ouvert
|
||||||
|
def fc_o ():
|
||||||
|
return scene.objects['Capteur fdc ouvert']['actif']
|
||||||
|
|
||||||
|
# Compte-rendu utilisateur du capteur fin de course portail ouvert
|
||||||
|
def fc_f ():
|
||||||
|
return scene.objects['Capteur fdc ferme']['actif']
|
||||||
|
|
||||||
|
# Compte-rendu utilisateur du capteur barrage IR
|
||||||
|
def ir_recep ():
|
||||||
|
if scene.objects['Module recepteur IR']['actif'] :
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Boutons poussoirs
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
# Compte-rendu utilisateur du bouton pousssoir coté rue
|
||||||
|
def bp_ext ():
|
||||||
|
return scene.objects['Module bouton cote rue']['actif']
|
||||||
|
|
||||||
|
# Compte-rendu utilisateur du bouton pousssoir coté cour
|
||||||
|
def bp_int ():
|
||||||
|
return scene.objects['Module bouton cote cour']['actif']
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Temporisation
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
def tempo (duree):
|
||||||
|
time.sleep(duree)
|
Binary file not shown.
BIN
portail_coulissant/portail_coulissant-12.blend1
Normal file
BIN
portail_coulissant/portail_coulissant-12.blend1
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user