4
$\begingroup$

Is it possible to draw and clear grease pencil real-time during/over blender game engine gameplay?

$\endgroup$
  • $\begingroup$ no, using the grease pencil in a game is not possible. $\endgroup$ – David Jun 23 '15 at 13:32
2
$\begingroup$

Since the game engine does not support drawing with grease pencil while the game engine is running, I made a script to draw on the camera in the game engine.

To use the script, enter it into the text editor and name it grease_pencil.py. You could call it anything, but it must end in .py to work as a module.

Text editor

Add a Python controller to an Always sensor, with true level triggering enabled, on any object. Change the python controller's Execution Method to Module and set its source to grease_pencil.draw or whatever you named it only without the .py and followed by .draw (draw is the name of the function we are calling).

Always sensor and Python controller

Press P, in the game engine, and click and drag to draw.

Drawing in the game engine

The complete script.

import bge

color = (.9, 0, 0)
lines = []

def position():
    scene = bge.logic.getCurrentScene()
    camera = scene.active_camera

    x, y = bge.logic.mouse.position

    vec = camera.worldPosition - camera.getScreenVect(x, y)
    vec = vec * camera.worldOrientation * camera.world_to_camera

    return vec

def mouse_just_down():
    return bge.logic.mouse.events[bge.events.LEFTMOUSE] == bge.logic.KX_INPUT_JUST_ACTIVATED

def mouse_down():
    return bge.logic.mouse.events[bge.events.LEFTMOUSE] == bge.logic.KX_INPUT_ACTIVE

def mouse_moving():
    return bge.logic.mouse.events[bge.events.MOUSEX] == bge.logic.KX_INPUT_ACTIVE or \
        bge.logic.mouse.events[bge.events.MOUSEY] == bge.logic.KX_INPUT_ACTIVE

def draw():
    if mouse_just_down():
        lines.append([position()])

    if mouse_down() and mouse_moving():
        lines[-1].append(position())

    for line in lines:
        prev = None
        for vec in line:
            if prev:
                bge.render.drawLine(prev, vec, color)                
            prev = vec
| improve this answer | |
$\endgroup$
0
$\begingroup$

upbge 0.3.0 branch has this capability (real 3d grease pencil strikes)

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.