Example #1
0
def init():
    """
    Sets the camera on load
    """
    co = blenderapi.controller()
    ow = co.owner

    # get the suffix of the human to reference the right objects
    suffix = ow.name[-4:] if ow.name[-4] == "." else ""

    camAct = co.actuators['Set_Camera']
    sobList = blenderapi.scene().objects

    human = ow

    # if the Human is external, do not use his camera initially
    if human.get('External_Robot_Tag') or human['disable_keyboard_control']:
        return

    humCam = sobList['Human_Camera' + suffix]

    try:
        worldCam = sobList['CameraFP']
        #check if there is a Camera displaying the world in the scene
    except KeyError:
        worldCam = None

    if ow['WorldCamera'] and worldCam:
        camAct.camera = worldCam
    else:
        camAct.camera = humCam
        blenderapi.mousepointer(visible=False)
    # set Camera following the human or displaying the world

    co.activate(camAct)
Example #2
0
def init():
    """
    Sets the camera on load
    """
    co = blenderapi.controller()
    ow = co.owner

    # get the suffix of the human to reference the right objects
    suffix = ow.name[-4:] if ow.name[-4] == "." else ""

    camAct = co.actuators["Set_Camera"]
    sobList = blenderapi.scene().objects

    human = ow

    # if the Human is external, do not use his camera initially
    if human.get("External_Robot_Tag") or human["disable_keyboard_control"]:
        return

    humCam = sobList["Human_Camera" + suffix]

    try:
        worldCam = sobList["CameraFP"]
        # check if there is a Camera displaying the world in the scene
    except KeyError:
        worldCam = None

    if ow["WorldCamera"] and worldCam:
        camAct.camera = worldCam
    else:
        camAct.camera = humCam
        blenderapi.mousepointer(visible=False)
    # set Camera following the human or displaying the world

    co.activate(camAct)
Example #3
0
def rotate(contr):
    """ Read the movements of the mouse and apply them
        as a rotation to the camera. """
    # 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

    # Get sensor named Mouse
    mouse = contr.sensors['Mouse']
    # Get Blender keyboard sensor
    keyboard = contr.sensors['All_Keys']

    # Show the cursor
    mouse_visible = True

    keylist = keyboard.events
    for key in keylist:
        if key[1] == blenderapi.input_active():
            # Left CTRL key allow to rotate the camera
            if key[0] == blenderapi.LEFTCTRLKEY:
                # Hide the cursor while we control the camera
                mouse_visible = False
                if mouse.positive:
                    # get width and height of game window
                    width = blenderapi.render().getWindowWidth()
                    height = blenderapi.render().getWindowHeight()

                    # get mouse movement from function
                    move = mouse_move(camera, mouse, width, height)

                    # set mouse sensitivity
                    sensitivity = camera['Sensitivity']

                    # Amount, direction and sensitivity
                    leftRight = move[0] * sensitivity
                    upDown = move[1] * sensitivity

                    # set the values
                    camera.applyRotation([0.0, 0.0, leftRight], 0)
                    camera.applyRotation([upDown, 0.0, 0.0], 1)

                    # Center mouse in game window
                    # Using the '//' operator (floor division) to produce an integer result
                    blenderapi.render().setMousePosition(
                        width // 2, height // 2)

    # Set the cursor visibility
    blenderapi.mousepointer(visible=mouse_visible)
Example #4
0
def rotate(contr):
    """ Read the movements of the mouse and apply them
        as a rotation to the camera. """
    # 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

    # Get sensor named Mouse
    mouse = contr.sensors['Mouse']
    # Get Blender keyboard sensor
    keyboard = contr.sensors['All_Keys']

    # Show the cursor
    mouse_visible = True

    keylist = keyboard.events
    for key in keylist:
        if key[1] == blenderapi.input_active():
            # Left CTRL key allow to rotate the camera
            if key[0] == blenderapi.LEFTCTRLKEY:
                # Hide the cursor while we control the camera
                mouse_visible = False
                if mouse.positive:
                    # get width and height of game window
                    width = blenderapi.render().getWindowWidth()
                    height = blenderapi.render().getWindowHeight()

                    # get mouse movement from function
                    move = mouse_move(camera, mouse, width, height)

                    # set mouse sensitivity
                    sensitivity = camera['Sensitivity']

                    # Amount, direction and sensitivity
                    leftRight = move[0] * sensitivity
                    upDown = move[1] * sensitivity

                    # set the values
                    camera.applyRotation( [0.0, 0.0, leftRight], 0 )
                    camera.applyRotation( [upDown, 0.0, 0.0], 1 )

                    # Center mouse in game window
                    # Using the '//' operator (floor division) to produce an integer result
                    blenderapi.render().setMousePosition(width//2, height//2)

    # Set the cursor visibility
    blenderapi.mousepointer(visible = mouse_visible)
Example #5
0
 def switch_cameras(self):
     """ Change between the main camera view in MORSE and the first person camera """
     scene = blenderapi.scene()
     index = blenderapi.persistantstorage().current_camera_index
     next_camera = scene.cameras[index]
     scene.active_camera = next_camera
     logger.info("Showing view from camera: '%s'" % next_camera.name)
     # Disable mouse cursor for Human camera
     if next_camera.name == "Human_Camera":
         blenderapi.mousepointer(visible=False)
     else:
         blenderapi.mousepointer(visible=True)
     # Update the index for the next call
     index = (index + 1) % len(scene.cameras)
     blenderapi.persistantstorage().current_camera_index = index
Example #6
0
 def switch_cameras(self):
     """ Change between the main camera view in MORSE and the first person camera """
     scene = blenderapi.scene()
     index = blenderapi.persistantstorage().current_camera_index
     next_camera = scene.cameras[index]
     scene.active_camera = next_camera
     logger.info("Showing view from camera: '%s'" % next_camera.name)
     # Disable mouse cursor for Human camera
     if next_camera.name == "Human_Camera":
         blenderapi.mousepointer(visible = False)
     else:
         blenderapi.mousepointer(visible = True)
     # Update the index for the next call
     index = (index + 1) % len(scene.cameras)
     blenderapi.persistantstorage().current_camera_index = index
Example #7
0
def switch_camera(contr):
    """ Cycle through the cameras in the scene during the game.
    """
    sensor = contr.sensors['F9_KEY']
    # Activate only once for each key press
    if sensor.positive and sensor.triggered:
        scene = morse.core.blenderapi.scene()
        index = persistantstorage.current_camera_index
        next_camera = scene.cameras[index]
        scene.active_camera = next_camera
        logger.info("Showing view from camera: '%s'" % next_camera.name)
        # Disable mouse cursor for Human camera
        if next_camera.name == "Human_Camera":
            blenderapi.mousepointer(visible = False)
        else:
            blenderapi.mousepointer(visible = True)
        # Update the index for the next call
        index = (index + 1) % len(scene.cameras)
        persistantstorage.current_camera_index = index