Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
79f2436
added _keyboard_calibration method (manual calibration in bge) to .pr…
PyrApple Jun 29, 2015
ad6606a
added method to simulate VRPN inputs via Keyboard (_keyboard_vrpn_proxy)
PyrApple Jun 29, 2015
7823014
added model-Eve-calibration (screen size fit Eve and VR scene is basi…
PyrApple Jun 29, 2015
e3f7b38
Merge remote-tracking branch 'origin/master' into calibration
dfelinto Jun 29, 2015
c203a3c
Change mapping of debugging keys
dfelinto Jun 29, 2015
275d813
Set initial position for vprn proxy system
dfelinto Jun 29, 2015
ecdfbfc
Rename camera_position > head_position
dfelinto Jun 29, 2015
2c36eb0
Apply transformations to Plane.ceiling AND change Scene.VR cameras
dfelinto Jun 29, 2015
1763990
BLEND: Update Scene.VR rotation cameras
dfelinto Jun 29, 2015
ec5204b
Cube Map code refactored
dfelinto Jun 29, 2015
8c47996
Remove left over from scale debugging
dfelinto Jun 29, 2015
82ed6c6
Remove comment
dfelinto Jun 29, 2015
fa37ceb
Add HEAD proxy
dfelinto Jun 29, 2015
9b8869d
Updated main model.blend with HEAD proxy
dfelinto Jun 29, 2015
90d0412
Orientate both scenes in model-Eve-calibration (VR and projection, so…
dfelinto Jun 30, 2015
18164c6
WASD debug keys should be mapped based on Scene.Projection world axis
dfelinto Jun 30, 2015
73aefc9
Rotate Camera.Parent so that the Scene.VR and Scene.Camera cameras ar…
dfelinto Jun 30, 2015
10c9cf1
swizzled coordinates in model.processor.py to match EVE's VRPN.
PyrApple Jun 30, 2015
6074f71
Added 3D objects to calibration scene for tracking/parallax assessment.
PyrApple Jun 30, 2015
e895983
renamed mode-Eve-calibration.blend into model-calibration.blend
PyrApple Aug 24, 2015
86d6151
removed model.blend from calibration branch to prepare
PyrApple Aug 24, 2015
253747b
Merge branch 'calibration'
PyrApple Aug 24, 2015
86d9a59
ERRATUM: re-added model.processor.py, somehow removed during
PyrApple Aug 24, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added model-calibration.blend
Binary file not shown.
294 changes: 294 additions & 0 deletions model-calibration.processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
import blendervr

VRPN_DEBUG = False

if blendervr.is_virtual_environment():
import bge
from mathutils import Vector, Matrix
from blendervr.player import device
from math import radians

from bge import logic, events

class Processor(blendervr.processor.getProcessor()):

def __init__(self, parent):
super(Processor, self).__init__(parent)

if self.BlenderVR.isMaster():
self.BlenderVR.getSceneSynchronizer().getItem(bge.logic).activate(True, True)

self._all_loaded = False
self._matrix = Matrix.Identity(4)

def _checkScenes(self):
"""
check if all the objects required are in the loaded scenes
"""
if self._all_loaded:
return True

if not self.BlenderVR.isMaster():
return False

if not hasattr(logic, 'scenes'):
return False

scene_vr = logic.scenes.get('Scene.VR')
scene_projection = logic.scenes.get('Scene.Projection')

if not scene_vr or not scene_projection:
return False

objects = scene_vr.objects
self._headtrack_vr_origin = objects.get('HEADTRACK.VR.ORIGIN')
self._headtrack_vr_head = objects.get('HEADTRACK.VR.HEAD')

objects = scene_projection.objects
self._headtrack_projection_origin = objects.get('HEADTRACK.PROJECTION.ORIGIN')
self._headtrack_projection_head = objects.get('HEADTRACK.PROJECTION.HEAD')

if \
self._headtrack_vr_origin and \
self._headtrack_vr_head and \
self._headtrack_projection_origin and \
self._headtrack_projection_head \
:
self._all_loaded = True
self._vrpn_proxy_init()
return True
else:
return False

def run(self):
"""
run every frame
"""

self._keyboard_calibration()
self._keyboard_vrpn_proxy()

if not self._checkScenes():
return

self._keyboard()

def _keyboard_calibration(self):
"""handle keyboard events"""

"""
Keyboard controls the camera representing the projector in the scene
(logic.scenes['Scene.Projection'].objects['Camera.Projector'])
with UJ/IK/OL (y,x,z) + Shift to switch from translation to rotation
and P/M to incr./decr. camera.lens
"""
_events = logic.keyboard.events

x = y = z = 0
SPEED = 0.005
zoom = 0
SPEED_ZOOM = 0.05
log = False

if _events[events.UKEY]:
y -= SPEED

elif _events[events.JKEY]:
y += SPEED

if _events[events.IKEY]:
x += SPEED

elif _events[events.KKEY]:
x -= SPEED

if _events[events.OKEY]:
z += SPEED

elif _events[events.LKEY]:
z -= SPEED

if _events[events.PKEY]:
zoom += SPEED_ZOOM


elif _events[events.MKEY]:
zoom -= SPEED_ZOOM

if _events[events.SPACEKEY]:
log = True

if x or y or z or zoom or log:
try:
if hasattr(logic, 'scenes'):
scene = logic.getCurrentScene()
camera_projector = scene.objects['Camera.Projector']

if _events[events.LEFTSHIFTKEY]: # camera rotation
gain = 1.0
camera_projector.applyRotation([gain*x, gain*y, gain*z], 0)

else: # camera translation / lens
gain = 1.0
camera_projector.applyMovement([gain*x, gain*y, gain*z], 0)
camera_projector.lens += zoom

if log:
from math import degrees as d

pos = camera_projector.position
ori = camera_projector.localOrientation.to_euler()

self.logger.info('\n Current Camera.Projector parameters:')
self.logger.info('Pos >> x: {0:.2f}, y: {1:.2f}, z: {2:.2f}'.format(pos.x, pos.y, pos.z))
self.logger.info('Ori >> x: {0:.2f}, y: {1:.2f}, z: {2:.2f}'.format(d(ori.x), d(ori.y), d(ori.z)))
self.logger.info('FoV >> {0:.2f} \n'.format(camera_projector.lens))

except Exception as E:
self.logger.log_traceback(E)



def _keyboard(self):
"""handle keyboard events"""

"""
arrow controls the navigation of the main camera
(logic.scenes['Scene.VR'].objects['Camera.Parent'])

but at the moment this is set in the file itself
the function here is for those without a real head-tracking
system to try with WASD
"""

_events = logic.keyboard.events

x = y = z = 0
SPEED = 0.005

if _events[events.WKEY]:
x += SPEED

elif _events[events.SKEY]:
x -= SPEED

if _events[events.AKEY]:
y += SPEED

elif _events[events.DKEY]:
y -= SPEED

if _events[events.QKEY]:
z -= SPEED

elif _events[events.EKEY]:
z += SPEED

if x or y or z:
try:
self._matrix = Matrix.Translation((y, z, x)) * self._matrix
info = {}
info['matrix'] = self._matrix
self.user_position(info)

except Exception as E:
self.logger.log_traceback(E)

def _vrpn_proxy_init(self):
"""
initialize fake vrpn inputs based on initial proxy positions
"""
if not VRPN_DEBUG:
return

position = self._headtrack_projection_head.worldPosition - self._headtrack_projection_origin.worldPosition
x,y,z = position.xyz

self._matrix = Matrix.Translation((-x, z, -y))
self._headtrack_vr_head.worldPosition = position + self._headtrack_vr_origin.worldPosition


def _keyboard_vrpn_proxy(self):

"""
Keyboard controls the player (hacking VRPN messages)
with XCV (x,y,z) and Shift+XCV (-x,-y,-z)
"""
if not VRPN_DEBUG:
return

_events = logic.keyboard.events

x = y = z = 0
SPEED = 0.01

if _events[events.XKEY]:
x += SPEED

if _events[events.CKEY]:
y += SPEED

if _events[events.VKEY]:
z += SPEED


if x or y or z:
try:
if _events[events.LEFTSHIFTKEY]: # camera rotation
x = -x
y = -y
z = -z

self._matrix = Matrix.Translation((-x, z, -y)) * self._matrix
info = {}
info['matrix'] = self._matrix
self.user_position(info)

except Exception as E:
self.logger.log_traceback(E)

def user_position(self, info):
"""
Callback defined in the XML config file to one of the VRPN Tracker devices
"""
if not self._checkScenes():
return

try:
#highjack regular head-tracking function
# do not call: super(Processor, self).user_position(info)

x, y, z = info['matrix'].translation

if abs(x)>=0.01 or abs(y)>=0.01 or abs(z)>=0.01:
# to remove: mockup as VRPN sever kept sending me (0,0,0) packets in between real (x,y,z) (DPQ)

# leaving here for debugging, I need to refresh myself on what is the swizzle needed in BlenderVR
#self.logger.info('Raw Data >> x: {0:.2f}, y: {1:.2f}, z: {2:.2f}'.format(x, y, z))

position = Matrix.Translation((-z, -x, y)).translation

self._headtrack_vr_head.worldPosition = position + self._headtrack_vr_origin.worldPosition
self.logger.info(self._headtrack_vr_head.worldPosition)
self._headtrack_projection_head.worldPosition = position + self._headtrack_projection_origin.worldPosition

except Exception as E:
self.logger.log_traceback(E)


elif blendervr.is_creating_loader():
import bpy

class Processor(blendervr.processor.getProcessor()):
def __init__(self, creator):
super(Processor, self).__init__(creator)


elif blendervr.is_console():
class Processor(blendervr.processor.getProcessor()):
def __init__(self, console):
super(Processor, self).__init__(console)

def useLoader(self):
return True

2 changes: 0 additions & 2 deletions model.processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def _keyboard(self):
"""
arrow controls the navigation of the main camera
(logic.scenes['Scene.VR'].objects['Camera.Parent'])

but at the moment this is set in the file itself
the function here is for those without a real head-tracking
system to try with WASD
Expand Down Expand Up @@ -148,4 +147,3 @@ def __init__(self, console):

def useLoader(self):
return True