def move(contr): """ Read the keys for specific combinations that will make the camera move in 3D space. """ # get the object this script is attached to camera = contr.owner scene = blenderapi.scene() # Do not move the camera if the current view is using another camera if camera != scene.active_camera: return if 'Human' in scene.objects: human = scene.objects['Human'] if not human['move_cameraFP']: return # set the movement speed speed = camera['Speed'] # Get Blender keyboard sensor keyboard = contr.sensors['All_Keys'] # Default movement speed move_speed = [0.0, 0.0, 0.0] keylist = keyboard.events for key in keylist: if key[1] == blenderapi.input_active(): # Also add the corresponding key for an AZERTY keyboard if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY: move_speed[2] = -speed elif key[0] == blenderapi.SKEY: move_speed[2] = speed # Also add the corresponding key for an AZERTY keyboard elif key[0] == blenderapi.AKEY or key[0] == blenderapi.QKEY: move_speed[0] = -speed elif key[0] == blenderapi.DKEY: move_speed[0] = speed elif key[0] == blenderapi.RKEY: move_speed[1] = speed elif key[0] == blenderapi.FKEY: move_speed[1] = -speed else: move_speed[0] = 0 move_speed[1] = 0 move_speed[2] = 0 # The second parameter of 'applyMovement' determines # a movement with respect to the object's local # coordinate system camera.applyMovement( move_speed, True ) elif key[1] == blenderapi.input_just_activated(): # Other actions activated with the keyboard # Reset camera to center if key[0] == blenderapi.F8KEY and keyboard.positive: reset_position(contr)
def set_human_animation(contr): """ Toggle the animation actions (walking, standing still...) of the armature. """ # Get sensor named Mouse armature = contr.owner # get the suffix of the human to reference the right objects suffix = armature.name[-4:] if armature.name[-4] == "." else "" scene = blenderapi.scene() active_camera = scene.active_camera human = scene.objects[armature.parent.name] # if the human is external, do nothing if human.get('External_Robot_Tag') or human['disable_keyboard_control']: return keyboard = contr.sensors['All_Keys'] keylist = keyboard.events pressed = [] #all keys that are currently pressed for key in keylist: # key[0] == blenderapi.keycode, key[1] = status if key[1] == blenderapi.input_just_activated(): pressed.append(key[0]) # Keys for moving forward or turning """ if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY: armature['movingForward'] = True elif key[0] == blenderapi.SKEY: armature['movingBackward'] = True """ # TEST: Read the rotation of the bones in the armature if key[0] == blenderapi.BKEY: read_pose(contr) #elif key[0] == blenderapi.VKEY: #reset_pose(contr) #elif key[1] == blenderapi.input_just_released(): """ if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY: armature['movingForward'] = False elif key[0] == blenderapi.SKEY: armature['movingBackward'] = False """ elif key[1] == blenderapi.input_active(): pressed.append(key[0]) if human['move_cameraFP'] and active_camera.name != 'Human_Camera': return if (FORWARDS in pressed or LEFT in pressed or BACKWARDS in pressed or RIGHT in pressed): armature['movingForward'] = True else: armature['movingForward'] = False
def test(contr): """ Show which objects are interactable """ keylist = keyboard.events for key in keylist: if key[0] == blenderapi.LEFTALTKEY: if key[1] == blenderapi.input_just_activated(): #show text over all objects scene.post_draw.append(write) elif key[1] == blenderapi.input_just_released(): #hide text of all objects scene.post_draw.remove(write)
def lock_movement(contr): human = contr.owner keyboard = contr.sensors['All_Keys'] scene = blenderapi.scene() if scene.active_camera.name != 'CameraFP': return keylist = keyboard.events for key in keylist: # key[0] == blenderapi.keycode, key[1] = status if key[1] == blenderapi.input_just_activated(): if key[0] == blenderapi.F5KEY: human['move_cameraFP'] = not human['move_cameraFP'] if human['move_cameraFP']: logger.info("Moving CameraFP") else: logger.info("Moving Human")
def move(contr): """ Read the keys for specific combinations that will make the camera move in 3D space. """ # get the object this script is attached to camera = contr.owner scene = blenderapi.scene() if not scene: # not ready, main reload(blenderapi) return # Do not move the camera if the current view is using another camera if camera != scene.active_camera: return # Do not move the camera if another object has set move_cameraFP for obj in keyboard_ctrl_objects: if not obj['move_cameraFP']: return # set camera position increment from the movement speed pos_inc = camera['Speed'] / blenderapi.getfrequency() # Get Blender keyboard sensor keyboard = contr.sensors['All_Keys'] # Default movement move_translation = [0.0, 0.0, 0.0] keylist = keyboard.events for key in keylist: if key[1] == blenderapi.input_active(): # Also add the corresponding key for an AZERTY keyboard if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY: move_translation[2] = -pos_inc elif key[0] == blenderapi.SKEY: move_translation[2] = pos_inc # Also add the corresponding key for an AZERTY keyboard elif key[0] == blenderapi.AKEY or key[0] == blenderapi.QKEY: move_translation[0] = -pos_inc elif key[0] == blenderapi.DKEY: move_translation[0] = pos_inc elif key[0] == blenderapi.RKEY: move_translation[1] = pos_inc elif key[0] == blenderapi.FKEY: move_translation[1] = -pos_inc else: move_translation[0] = 0 move_translation[1] = 0 move_translation[2] = 0 # The second parameter of 'applyMovement' determines # a movement with respect to the object's local # coordinate system camera.applyMovement(move_translation, True) elif key[1] == blenderapi.input_just_activated(): # Other actions activated with the keyboard # Reset camera to center if key[0] == blenderapi.F8KEY and keyboard.positive: reset_position(contr)
def move(contr): """ Read the keys for specific combinations that will make the camera move in 3D space. """ # Get the currently active camera to adapt control method scene = blenderapi.scene() active_camera = scene.active_camera # get the object this script is attached to human = contr.owner # if the human is external, do nothing if human.get('External_Robot_Tag') or human['disable_keyboard_control']: return # get the suffix of the human to reference the right objects suffix = human.name[-4:] if human.name[-4] == "." else "" # set the movement speed speed = human['Speed'] # Get sensor named Mouse keyboard = contr.sensors['All_Keys'] # Default movement speed move_speed = [0.0, 0.0, 0.0] rotation_speed = [0.0, 0.0, 0.0] human_camera = "Human_Camera" + suffix if human['move_cameraFP'] and active_camera.name != human_camera: return keylist = keyboard.events for key in keylist: # key[0] == blenderapi.keycode, key[1] = status if key[1] == blenderapi.input_active(): if human['Manipulate']: if key[0] == FORWARDS: move_speed[0] = speed elif key[0] == BACKWARDS: move_speed[0] = -speed elif key[0] == TURN_LEFT: rotation_speed[2] = speed elif key[0] == TURN_RIGHT: rotation_speed[2] = -speed elif key[0] == RIGHT: if active_camera.name == human_camera: move_speed[1] = -speed else: rotation_speed[2] = -speed elif key[0] == LEFT: if active_camera.name == human_camera: move_speed[1] = speed else: rotation_speed[2] = speed else: if key[0] in (FORWARDS, BACKWARDS, LEFT, RIGHT): move_speed[0] = speed if active_camera.name != human_camera and key[ 0] == BACKWARDS: move_speed[0] = -speed # The second parameter of 'applyMovement' determines # a movement with respect to the object's local # coordinate system human.applyMovement(move_speed, True) human.applyRotation(rotation_speed, True) """ if key[0] == blenderapi.UPARROWKEY: move_speed[0] = speed elif key[0] == blenderapi.DOWNARROWKEY: move_speed[0] = -speed elif key[0] == blenderapi.LEFTARROWKEY: rotation_speed[2] = speed elif key[0] == blenderapi.RIGHTARROWKEY: rotation_speed[2] = -speed elif key[0] == blenderapi.AKEY: move_speed[2] = speed elif key[0] == blenderapi.EKEY: move_speed[2] = -speed """ elif key[1] == blenderapi.input_just_activated(): # Other actions activated with the keyboard # Reset camera to center if key[0] == blenderapi.NKEY and keyboard.positive: reset_view(contr) # Switch between look and manipulate elif key[0] == blenderapi.XKEY: toggle_manipulate(contr)
def move(contr): """ Read the keys for specific combinations that will make the camera move in 3D space. """ # Get the currently active camera to adapt control method scene = blenderapi.scene() active_camera = scene.active_camera # get the object this script is attached to human = contr.owner # if the human is external, do nothing if human.get('External_Robot_Tag') or human['disable_keyboard_control']: return # get the suffix of the human to reference the right objects suffix = human.name[-4:] if human.name[-4] == "." else "" # set the movement speed speed = human['Speed'] # Get sensor named Mouse keyboard = contr.sensors['All_Keys'] # Default movement speed move_speed = [0.0, 0.0, 0.0] rotation_speed = [0.0, 0.0, 0.0] human_camera = "Human_Camera" + suffix if human['move_cameraFP'] and active_camera.name != human_camera: return keylist = keyboard.events for key in keylist: # key[0] == blenderapi.keycode, key[1] = status if key[1] == blenderapi.input_active(): if human['Manipulate']: if key[0] == FORWARDS: move_speed[0] = speed elif key[0] == BACKWARDS: move_speed[0] = -speed elif key[0] == TURN_LEFT: rotation_speed[2] = speed elif key[0] == TURN_RIGHT: rotation_speed[2] = -speed elif key[0] == RIGHT: if active_camera.name == human_camera: move_speed[1] = -speed else: rotation_speed[2] = -speed elif key[0] == LEFT: if active_camera.name == human_camera: move_speed[1] = speed else: rotation_speed[2] = speed else: if key[0] in (FORWARDS, BACKWARDS, LEFT, RIGHT): move_speed[0] = speed if active_camera.name != human_camera and key[0] == BACKWARDS: move_speed[0] = -speed # The second parameter of 'applyMovement' determines # a movement with respect to the object's local # coordinate system human.applyMovement( move_speed, True ) human.applyRotation( rotation_speed, True ) """ if key[0] == blenderapi.UPARROWKEY: move_speed[0] = speed elif key[0] == blenderapi.DOWNARROWKEY: move_speed[0] = -speed elif key[0] == blenderapi.LEFTARROWKEY: rotation_speed[2] = speed elif key[0] == blenderapi.RIGHTARROWKEY: rotation_speed[2] = -speed elif key[0] == blenderapi.AKEY: move_speed[2] = speed elif key[0] == blenderapi.EKEY: move_speed[2] = -speed """ elif key[1] == blenderapi.input_just_activated(): # Other actions activated with the keyboard # Reset camera to center if key[0] == blenderapi.NKEY and keyboard.positive: reset_view(contr) # Switch between look and manipulate elif key[0] == blenderapi.XKEY: toggle_manipulate(contr)
def move(contr): """ Read the keys for specific combinations that will make the camera move in 3D space. """ # get the object this script is attached to camera = contr.owner scene = blenderapi.scene() if not scene: # not ready, main reload(blenderapi) return # Do not move the camera if the current view is using another camera if camera != scene.active_camera: return # Do not move the camera if another object has set move_cameraFP for obj in keyboard_ctrl_objects: if not obj['move_cameraFP']: return # set camera position increment from the movement speed pos_inc = camera['Speed'] / blenderapi.getfrequency() # Get Blender keyboard sensor keyboard = contr.sensors['All_Keys'] # Default movement move_translation = [0.0, 0.0, 0.0] keylist = keyboard.events for key in keylist: if key[1] == blenderapi.input_active(): # Also add the corresponding key for an AZERTY keyboard if key[0] == blenderapi.WKEY or key[0] == blenderapi.ZKEY: move_translation[2] = -pos_inc elif key[0] == blenderapi.SKEY: move_translation[2] = pos_inc # Also add the corresponding key for an AZERTY keyboard elif key[0] == blenderapi.AKEY or key[0] == blenderapi.QKEY: move_translation[0] = -pos_inc elif key[0] == blenderapi.DKEY: move_translation[0] = pos_inc elif key[0] == blenderapi.RKEY: move_translation[1] = pos_inc elif key[0] == blenderapi.FKEY: move_translation[1] = -pos_inc else: move_translation[0] = 0 move_translation[1] = 0 move_translation[2] = 0 # The second parameter of 'applyMovement' determines # a movement with respect to the object's local # coordinate system camera.applyMovement( move_translation, True ) elif key[1] == blenderapi.input_just_activated(): # Other actions activated with the keyboard # Reset camera to center if key[0] == blenderapi.F8KEY and keyboard.positive: reset_position(contr)