import bge # Blender Game Engine (UPBGE) import bpy # Blender import webbrowser import math import xml.etree.ElementTree as ET # Creating/parsing XML file import cine_doc # Documentation import cine_about # About ############################################################################### # cine.py # @title: Bibliothèque générale du player 3D d'analyse de cinématique # @project: Blender-EduTech # @lang: fr # @authors: Philippe Roy # @copyright: Copyright (C) 2020-2022 Philippe Roy # @license: GNU GPL # # 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. # ############################################################################### # UPBGE scene eevee = bpy.context.scene.eevee scene = bge.logic.getCurrentScene() # print("Objets de la scene : ", scene.objects) # Config file cine_config = ET.parse('cine_config.xml') cine_config_tree = cine_config.getroot() # Couleurs color_cmd = [0.8, 0.8, 0.8, 1] # Blanc color_cmd_hl = [0.8, 0.619, 0.021, 1] # Jaune color_rep_enabled = [0.8, 0.8, 0.8, 1] # Blanc color_rep_disabled = [0, 0, 0, 1] # Noir # Constantes JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED 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 : Orbit(0) par défaut, Pan(1) avec Shift, Zoom (2) avec Ctrl, Eclaté (1) avec Shift def keyboard(cont): obj = scene.objects['Mecanism'] keyboard = bge.logic.keyboard # Touche ESC if JUST_ACTIVATED in keyboard.inputs[bge.events.ESCKEY].queue: # Maj du fichier de config (screen size : data/config/screen/width-> [0][0].text) screen_width = bge.render.getWindowWidth() screen_height = bge.render.getWindowHeight() cine_config_tree[0][0].text=str(screen_width) cine_config_tree[0][1].text=str(screen_height) buffer_xml = ET.tostring(cine_config_tree) with open("cine_config.xml", "wb") as f: f.write(buffer_xml) # Sortir bge.logic.endGame() # 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: manip_reset() # Touche Space -> Play et Pause if JUST_ACTIVATED in keyboard.inputs[bge.events.SPACEKEY].queue: if scene.objects['Mecanism']['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 (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 ############################################################################### ## # Initialisation des commandes ## def cmd_init(): # 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)) scene.objects['Play-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['Help-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 ## def cmd_hl(cont): obj = cont.owner # Activation if cont.sensors['MO'].status == JUST_ACTIVATED and scene.objects['Mecanism']['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 = color_cmd_hl # Play et pause if obj.name=="Pause" or obj.name=="Play": if scene.objects['Mecanism']['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['Mecanism']['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['Mecanism']['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) ## # Click sur les commandes ## def cmd_click(cont): obj = cont.owner if cont.sensors['Click'].status == JUST_ACTIVATED and cont.sensors['MO'].positive and scene.objects['Mecanism']['manip_mode']==0: # Play et pause if obj.name=="Pause" or obj.name=="Run": # Pause if scene.objects['Mecanism']['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) # Reset-colors if obj.name=="Reset-colors" : color_reset() # Reset-view if obj.name=="Reset-view" : manip_reset() # About if obj.name=="About-cmd" : if scene.objects['Mecanism']['anim'] == True: # Rendu meilleur en pause scene.objects['About']['anim']= True anim_pause() else: scene.objects['About']['anim'] = False cine_about.open() # Aide if obj.name=="Help-cmd" : if scene.objects['Mecanism']['anim'] == True: # Rendu meilleur en pause scene.objects['Doc']['anim']= True anim_pause() else: scene.objects['Doc']['anim'] = False 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 ############################################################################### ## # Dessiner une cercle (bas niveau) ## def circle (center, radius, color): ang = 0 ang_step = 0.1 while ang< 2 * math.pi: x0 = center[0]+float(radius*math.cos(ang)*0.95) y0 = center[1] z0 = center[2]+float(radius*math.sin(ang)) x1 = center[0]+float(radius*math.cos(ang+ang_step)*0.95) y1 = center[1] z1 = center[2]+float(radius*math.sin(ang+ang_step)) bge.render.drawLine([x0,y0,z0],[x1,y1,z1],color) 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 ## # def manip_init(cont): def manip_init(): # Configuration du moteur de rendu eevee.use_eevee_smaa = True # Fenêtres scene.objects['About'].setVisible(False,True) scene.objects['Doc'].setVisible(False,True) # Mémorisation de la position des composants for objet in scene.objects['Mecanism']['objects'] : scene.objects[objet]['init_lx']=scene.objects[objet].worldPosition.x scene.objects[objet]['init_ly']=scene.objects[objet].worldPosition.y scene.objects[objet]['init_lz']=scene.objects[objet].worldPosition.z if 'init_rx' in scene.objects[objet]: scene.objects[objet]['init_rx'] = scene.objects[objet].worldOrientation.to_euler().x if 'init_ry' in scene.objects[objet]: scene.objects[objet]['init_ry'] = scene.objects[objet].worldOrientation.to_euler().y if 'init_rz' in scene.objects[objet]: scene.objects[objet]['init_rz'] = scene.objects[objet].worldOrientation.to_euler().z # Mémorisation de la position de la caméra scene.objects['Camera']['init_lx']=scene.objects['Camera'].worldPosition.x scene.objects['Camera']['init_ly']=scene.objects['Camera'].worldPosition.y scene.objects['Camera']['init_lz']=scene.objects['Camera'].worldPosition.z # Mémorisation de la position du modèle scene.objects['Mecanism']['init_lx']=scene.objects['Mecanism'].worldPosition.x scene.objects['Mecanism']['init_ly']=scene.objects['Mecanism'].worldPosition.y scene.objects['Mecanism']['init_lz']=scene.objects['Mecanism'].worldPosition.z scene.objects['Mecanism']['init_rx']=scene.objects['Mecanism'].worldOrientation.to_euler().x scene.objects['Mecanism']['init_ry']=scene.objects['Mecanism'].worldOrientation.to_euler().y scene.objects['Mecanism']['init_rz']=scene.objects['Mecanism'].worldOrientation.to_euler().z ## # 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(): 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['Mecanism'], 0, 0, 0) scene.objects['Mecanism'].worldPosition.x = scene.objects['Mecanism']['init_lx'] scene.objects['Mecanism'].worldPosition.y = scene.objects['Mecanism']['init_ly'] scene.objects['Mecanism'].worldPosition.z = scene.objects['Mecanism']['init_lz'] for objet in scene.objects['Mecanism']['objects'] : scene.objects[objet].setVisible(True,False) scene.objects[objet].restorePhysics() if objet+"_Lines.GP" in scene.objects: 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 ## def manip_start(cont): obj = cont.owner obj['click_x']=cont.sensors['ClickM'].position[0] obj['click_y']=cont.sensors['ClickM'].position[1] ## # 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 if obj['manip_mode']==0: x0 = scene.objects['Orbit'].worldPosition.x y0 =scene.objects['Orbit'].worldPosition.y z0 =scene.objects['Orbit'].worldPosition.z width = bge.render.getWindowWidth() height = bge.render.getWindowHeight() dist_orbit_y_base=200 # Pour 1280 x 720 radius_orbit_y_base=5 diag_base= math.sqrt(1280**2+720**2) diag= math.sqrt(width**2+height**2) dist_orbit_y = dist_orbit_y_base*(diag/diag_base) radius_orbit_y=radius_orbit_y_base*(diag/diag_base) dist_orbit = math.sqrt(((width/2)-obj['click_x'])**2+((height/2)-obj['click_y'])**2) if obj['click_y']> height/2 : dist_orbit = dist_orbit+((math.sqrt(((height/2)-obj['click_y'])**2)/175)*25) # Correction des Y sous le centre ? if dist_orbit= abs(delta_y): scene.objects['Mecanism'].applyRotation((0, delta_x*sensibilite_orbit, 0), False) else: scene.objects['Mecanism'].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 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['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) scene.objects['Camera'].applyMovement((0, 0, (delta_x+delta_y)*sensibilite_zoom), True) ## # Zoom ## 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 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)