Blender-VR API Documentation¶
The documentation of the Blender-VR project includes the part that is exposed to the user to be used in the processor file, as well as the core code of Blender-VR.
Processor File¶
Examples¶
For more examples, check the processor
files in the Samples Repository of the Blender-VR project.
Basic Example¶
This is a basic processor
file which can be considered a barebone and a start point for your own. All it does is to syncronize all the objects between the master and the slaves machines.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import blendervr
if blendervr.is_console():
class Processor(blendervr.processor.getProcessor()):
def __init__(self, console):
global try_wait_user_name, try_chooser, try_console_arc_balls
super(Processor, self).__init__(console)
def useLoader(self):
return True
elif blendervr.is_creating_loader():
import bpy
class Processor(blendervr.processor.getProcessor()):
def __init__(self, creator):
super(Processor, self).__init__(creator)
elif blendervr.is_virtual_environment():
import bge
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)
|
The file is split in three parts:
The processor
file is called three times, and each time a section of it is called.
Console¶
The console part of the code is called first by the console
.
This runs before your .blend
file is even loaded.
The useLoader()
determines if you need Blender-VR to modify your .blend
on-the-fly.
Most of the time this won’t need to change. The exception is when the file being loaded was already modified to work with Blender-VR (e.g., the file generated on-the-fly after running it once).
if blendervr.is_console():
class Processor(blendervr.processor.getProcessor()):
def __init__(self, console):
global try_wait_user_name, try_chooser, try_console_arc_balls
super(Processor, self).__init__(console)
def useLoader(self):
return True
Update Loader¶
If a project requires specific changes in the .blend
file they are introduced here.
This is the place where a specific Actuator
can be added for a Head-Mounted display for example.
elif blendervr.is_creating_loader():
import bpy
class Processor(blendervr.processor.getProcessor()):
def __init__(self, creator):
super(Processor, self).__init__(creator)
Virtual Environment¶
This part of the code is called when the .blend
file is loaded in the Blender Game Engine.
The most basic usage is to syncronize all the scene objects, as it’s being done here.
elif blendervr.is_virtual_environment():
import bge
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)
OSC API¶
How to use the OSC API integrated in blenderVR.
Introduction¶
OSC is integrated as a BlenderVR plugin, to be defined in the .xml configuration file. The OSC API is e.g. used for BlenderVR synchornization with the Max/MSP based Sound Rendering Engine.
As a start, you’ll want to adapt BlenderVR configuration file to your architecture, process detailed in the how to use OSC section.
For the sake of illustration, say you’re using a configuration file which <osc>
subsection looks like:
<plugins>
<osc host='localhost' port='3819' configuration='Laptop SPAT' max_audio_objects='8'>
<user listener='Binaural 1' viewer='user A' />
<user listener='Ambisonic' />
<user listener='Stereo' />
</osc>
</plugins>
Every parameter defined in these lines will be sent to the OSC client at BlenderVR startup (but for osc host and port), see the how to use OSC section for more details on each flag.
Received by the OSC client at BlenderVR start:
/global configuration Laptop SPAT
/global max_audio_objects 8
/user 0 name Binaural 1
/user 1 name Ambisonic
/user 2 name Stereo
OSC = self.blenderVR.getPlugin('osc')
with self
representing the BlenderVR processor object, granting access to BlenderVR OSC module and its API (OSC
in python code bellow refers to this module).
From there, BlenderVR OSC API proposes 4 different class of messages: global
, user
, object
and objectUser
.
Global Messages¶
Global messages can be used for global configuration of the Sound Engine (e.g. global volume
, start
, etc.).
osc_global = OSC.getGlobal()
osc_global.start(True)
osc_global.mute(True)
osc_global.volume('%45')
will send the following messages to the Sound Engine:
/global start 1
/global mute 1
/global volume %45
with volume being either absolute balue (e.g. %45) or +/- relative add (e.g. +3 or -7).
User Messages¶
User messages can be used for user specific configuration of the Sound Engine (e.g. user volume
, ``user start`, etc.).
See OSC users as listeners, or rather as the media + rendering technique that produces a sound (speakers set + ambisonic, headset + binaural, etc.).
osc_user = OSC.getUser('Binaural 1')
# or equivalently
bvr_user = self.blenderVR.getUserByName('user A')
osc_user = OSC.getUser(bvr_user)
# --
osc_user.start(True)
osc_user.mute(True)
osc_user.volume('%45')
The first line grants access to the OSC user named Binaural 1
in the configuration file (attached to BlenderVR ``user A`, see above). Thanks to the definition of user / listener in the configuration file, each BlenderVR user position/orientation (‘user A’ here) will be synchronized form BlenderVR to the sound rendering engine.
The next lines will send the following messages to the Sound Engine:
/user 1 start 1
/user 1 mute 1
/user 1 volume %45
and BlenderVR will constantly update osc user position with messages like:
/user 1 position 1. 0. 0. 0. 0. -1. -0. 0. 0. 0. -1. 0. 0. 0. 0. 1.
where the 16 floats represent the 4x4 homogeneous Matrix of user position/orientation in the virtual world.
Object Messages¶
Object messages can be used for object specific configuration of the Sound Engine (e.g. object volume, object start, etc.). See OSC objects as a virtual sound source instantiated in the Sound Engine, that will be attached to a BlenderVR object (e.g. a Blender KX_Game_Object) in the scene and eventually heard by one/many OSC user/listener (see objectUser messages bellow).
scene = bge.logic.getCurrentScene()
kx_object = scene.objects['Cube']
osc_object = OSC.getObject(kx_object)
osc_object.sound('HeyPachuco.wav')
osc_object.start(True)
osc_object.mute(False)
osc_object.volume('%45')
The first line grants access to the OSC object that will be attached to the KX_GameObject Cube
in the blender scene. This first line triggers a callback that
will synchronize the object position in the
The next lines will send the following messages to the Sound Engine:
/object 1 sound HeyPachuco.wav
/object 1 start 1
/object 1 mute 0
/object 1 volume %45
and BlenderVR will constantly update osc object position with messages like:
/object 1 position 0.54156 0.132934 -0.830085 0. -0.840592 0.07291 -0.536739 0. -0.01083 0.98844 0.151228 0. -11.07954 0.250764 -14.501128 1.
ObjectUser Messages¶
This class of messages allow to dynamically route object sounds to osc users (listeners) audio input. basically, sending:
/objectUser 1 0 mute 0
will tell the sound engine to route osc object 1
to osc user 0
(Binaural 1 here, see above), hence the listener Binaural 1
will hear the sound of kx_object 1
.
The line SC.getObjectUser(osc_object, osc_user)` grants access to the OSC objectUser that will control the link between the sound from the osc object
(attached to the blender object ``Cube
) to the osc user ``Binaural 1`.
The next two lines will send the following messages to the Sound Engine:
/objectUser 1 0 mute 0
/objectUser 1 0 volume %50
Example¶
The basic-osc.blend in the BlenderVR samples will send the following OSC messages to the Sound Engine (it’s actually the code in the basic-osc.processor.py along with the osc plugin definition in the ``//blender-vr/configuration/main.xml` configuration file that will send the following messages):
/global configuration Laptop SPAT
/global max_audio_objects 20
/global volume %40
/global start 1
/global mute 0
/object 1 sound HeyPachuco.wav
/object 1 loop 1
/object 1 volume %45
/object 1 start 1
/object 1 position 0.54156 0.132934 -0.830085 0. -0.840592 0.07291 -0.536739 0. -0.01083 0.98844 0.151228 0. -11.07954 0.250764 -14.501128 1.
/object 1 mute 0
/user 2 name Ambisonic
/user 2 hrtf 0
/user 2 volume %50
/user 2 position
/user 2 start 0
/user 2 mute 0
/user 2 warmth 0
/user 2 brightness 0
/user 2 presence 0
/user 2 reverb_volume 0
/user 2 running_reverb 0
/user 2 late_reverb 0
/user 2 envelop 0
/user 2 heavyness 0
/user 2 livelyness 0
/user 0 name Binaural 1
/user 0 hrtf 0
/user 0 volume %80
/user 0 position 1. 0. 0. 0. 0. -1. -0. 0. 0. 0. -1. 0. 0. 0. 0. 1.
/user 0 start 1
/user 0 mute 0
/user 0 warmth 0
/user 0 brightness 0
/user 0 presence 0
/user 0 reverb_volume 0
/user 0 running_reverb 0
/user 0 late_reverb 0
/user 0 envelop 0
/user 0 heavyness 0
/user 0 livelyness 0
/user 1 name Binaural 2
/user 1 hrtf 0
/user 1 volume %50
/user 1 position 1. 0. 0. 0. 0. -1. -0. 0. 0. 0. -1. 0. 0. 0. 0. 1.
/user 1 start 0
/user 1 mute 0
/user 1 warmth 0
/user 1 brightness 0
/user 1 presence 0
/user 1 reverb_volume 0
/user 1 running_reverb 0
/user 1 late_reverb 0
/user 1 envelop 0
/user 1 heavyness 0
/user 1 livelyness 0
/user 3 name Stereo
/user 3 hrtf 0
/user 3 volume %50
/user 3 position
/user 3 start 0
/user 3 mute 0
/user 3 warmth 0
/user 3 brightness 0
/user 3 presence 0
/user 3 reverb_volume 0
/user 3 running_reverb 0
/user 3 late_reverb 0
/user 3 envelop 0
/user 3 heavyness 0
/user 3 livelyness 0
/objectUser 1 0 volume %50
/objectUser 1 0 mute 0
/object 1 position 0.529771 0.133939 -0.837498 0. -0.848072 0.071046 -0.525097 0. -0.01083 0.98844 0.151228 0. -11.182952 0.225004 -14.340163 1.
/object 1 position 0.517878 0.134918 -0.844748 0. -0.855386 0.069169 -0.513353 0. -0.01083 0.98844 0.151228 0. -11.284078 0.199052 -14.177782 1.
(... moving objects / users position updates ...)
Source Code¶
Utils¶
Files to support the Blender VR application.
Daemon¶
This script runs in the clients and is responsible for spawning the Blender Player.
-
class
daemon.
Daemon
(BlenderVR_modules)¶ Bases:
object
Background management of the Blender Player and related stuff.
-
main
()¶ Start the Daemon, quits any instance of BlenderPlayer running.
-
processCommand
(command, argument)¶ Run the received commands
Parameters: - command (str) – Command to execute in the client machine
- argument – Value depends on the command
-
write
(*messages)¶ Send message to the client
Parameters: messages (list) – all the messages to send to the client (i.e., console commands)
-
-
daemon.
main
()¶ Main function to start the daemon.
Prepare execution (daemonize if necessary), then build a Daemon and call its main() method to manage background communications.
Update Loader¶
Script that runs in Blender in background mode to transform the .blend
file into a Blender-VR ready file.
A few Logic Bricks are created among other changes in the initial scene.
Modules¶
Main modules for the Blender-VR application.
blendervr package¶
Subpackages¶
blendervr.console package¶
-
class
blendervr.console.logic.console.
Logic
¶ Bases:
object
-
compile_BC
()¶
-
get_blender_player_state
()¶
-
load_configuration_file
()¶
-
quit
()¶
-
receivedFromVirtualEnvironment
(message)¶
-
sendToVirtualEnvironment
(command, argument)¶
-
set_screen_set
()¶
-
start
()¶
-
start_simulation
()¶
-
stop_simulation
()¶
-
update_user_files
(force=False)¶
-
-
class
blendervr.console.logic.screen.
Logic
(net_console)¶ Bases:
object
-
adapt_simulation_files_to_screen
(loader_file, blender_file, processor_files)¶
-
ask_blender_player_to_quit
()¶
-
daemon_is_running
()¶
-
getHostname
()¶
-
get_blender_player_state
()¶
-
is_master
()¶
-
quit
()¶
-
restartDaemon
()¶
-
send_to_blender_player
(command, argument='')¶
-
setConfiguration
(configuration, complements)¶
-
setHierarchy
(informations)¶
-
setNetworkClient
(origin, client, addr)¶
-
set_BlenderVR_state
(state)¶
-
start
()¶
-
-
class
blendervr.console.logic.screens.
Logic
¶ Bases:
object
-
adapt_simulation_files_to_screen
(loader_file, blender_file, processor_files)¶
-
getMaster
()¶
-
getScreen
(screen_name)¶
-
getScreensNumber
()¶
-
getStates
()¶
-
quit
()¶
-
send_to_blender_player
(command, message)¶
-
set_screens
(configurations, net_console, master_name, port, complements)¶
-
start
()¶
-
start_simulation
()¶
-
stop_simulation
()¶
-
-
class
blendervr.console.qt.console.
GUI
¶ Bases:
blendervr.console.gui.console.GUI
-
addListenTo
(socket, callback, data=None)¶
-
addTimeout
(time, callback)¶
-
cb_add_configuration_path
()¶
-
cb_close
()¶
-
cb_load_configuration_file
()¶
-
cb_processor_window
()¶
-
cb_remove_configuration_path
(*args)¶
-
cb_set_blender_file
()¶
-
cb_set_configuration_file
()¶
-
cb_set_current_tab
()¶
-
cb_set_link_processor_to_blender
()¶
-
cb_set_processor_file
()¶
-
cb_set_screen_set
()¶
-
cb_start
()¶
-
cb_stop
()¶
-
cb_update_liste_paths
(*args)¶
-
display_screen_sets
(screenSets)¶
-
getWindow
()¶
-
main
()¶
-
quit
()¶
-
removeListenTo
(tag)¶
-
start
()¶
-
updateStatus
(message, state=None)¶
-
update_processor
()¶
-
-
class
blendervr.console.qt.console.
MainWindow
(owner, profile, profile_indices)¶ Bases:
blendervr.tools.gui.qt.Common
,dummy.PyQt4.QMainWindow
-
blendervr.console.qt.console.
quit
()¶
-
class
blendervr.console.qt.logger.
Logger
(parent, config_index, window, log_level_selector)¶ Bases:
blendervr.console.gui.logger.Logger
-
cb_set_log_level
()¶
-
clear
()¶
-
-
class
blendervr.console.xml.device.base.
Base
(parent, name, attrs)¶
-
class
blendervr.console.xml.device.planovision.
Device
(parent, name, attrs)¶
-
class
blendervr.console.xml.device.screen.
Screen
(parent, name, attrs)¶ Bases:
blendervr.console.xml.device.base.Base
-
characters
(string)¶
-
endElement
(name)¶
-
-
class
blendervr.console.xml.base.
XML
(parent, name, attrs)¶ Bases:
xml.sax.handler.ContentHandler
,blendervr.console.base.Base
-
endElement
(name)¶
-
getBoolean
(value)¶
-
getConfiguration
()¶
-
getMain
()¶
-
getParser
()¶
-
getVector
(vector, size, none_value=None)¶
-
getXML_FileName
()¶
-
getXML_LineNumber
()¶
-
getXML_Position
()¶
-
is_exe
(filename)¶
-
print_warning
(msg)¶
-
raise_error
(msg)¶
-
startElement
(name, attrs)¶
-
which
(filename)¶
-
-
class
blendervr.console.xml.base.
mono
(parent, name, attrs)¶ Bases:
blendervr.console.xml.base.XML
-
characters
(string)¶
-
endElement
(name)¶
-
startElement
(name, attrs)¶
-
-
class
blendervr.console.xml.base.
single
(parent, name, attrs)¶ Bases:
blendervr.console.xml.base.XML
-
characters
(string)¶
-
endElement
(name)¶
-
startElement
(name, attrs)¶
-
-
class
blendervr.console.xml.behavior.
XML
(parent, name, attrs)¶ Bases:
blendervr.console.xml.reusable.XML
-
characters
(string)¶
-
endElement
(name)¶
-
-
class
blendervr.console.xml.blendervr.
XML
(parent, name, attrs)¶
-
class
blendervr.console.xml.common_system.
XML
(parent, name, attrs)¶
-
class
blendervr.console.xml.computer.
container
(parent, name, attrs)¶
-
class
blendervr.console.xml.computer.
main
(parent, name, attrs)¶
-
class
blendervr.console.xml.display.
XML
(parent, name, attrs)¶ Bases:
blendervr.console.xml.reusable.XML
-
characters
(string)¶
-
endElement
(name)¶
-
-
class
blendervr.console.xml.display.
graphic_buffer
(parent, name, attrs)¶
-
class
blendervr.console.xml.processors.
XML
(parent, name, attrs)¶ Bases:
blendervr.console.xml.base.single
-
characters
(string)¶
-
getConfiguration
()¶
-
-
class
blendervr.console.xml.reusable.
XML
(parent, name, attrs)¶
-
class
blendervr.console.xml.root.
XML
(parent)¶ Bases:
blendervr.console.xml.base.XML
-
getConfiguration
()¶
-
-
class
blendervr.console.xml.screen.
container
(parent, name, attrs)¶
-
class
blendervr.console.xml.screen.
main
(parent, name, attrs)¶
-
class
blendervr.console.xml.starter.
XML
(parent, name, attrs)¶ Bases:
blendervr.console.xml.common_system.XML
-
characters
(string)¶
-
-
class
blendervr.console.xml.system.
Library
(parent, name, attrs)¶
-
class
blendervr.console.xml.system.
XML
(parent, name, attrs)¶
-
class
blendervr.console.xml.system.
blenderplayer
(parent, name, attrs)¶ Bases:
blendervr.console.xml.base.single
-
characters
(string)¶
-
-
class
blendervr.console.xml.system.
daemon
(parent, name, attrs)¶ Bases:
blendervr.console.xml.base.single
-
characters
(string)¶
-
-
class
blendervr.console.xml.system.
log
(parent, name, attrs)¶
-
class
blendervr.console.xml.system.
login
(parent, name, attrs)¶
-
class
blendervr.console.xml.
Configure
(parent, config_paths, config_file)¶ Bases:
xml.sax.handler.ContentHandler
,xml.sax.handler.EntityResolver
,blendervr.console.base.Base
-
getConfiguration
()¶
-
resolveEntity
(publicID, systemID)¶
-
-
class
blendervr.console.base.
Base
(parent)¶ Bases:
blendervr.base.Base
-
getConsole
()¶
-
profile
¶
-
quit
()¶
-
-
class
blendervr.console.console.
Console
(profile_file)¶ Bases:
blendervr.console.logic.console.Logic
,blendervr.console.qt.console.GUI
-
logger
¶
-
plugins
¶
-
profile
¶
-
quit
()¶
-
start
()¶
-
-
class
blendervr.console.screen.
Screen
(screens, name, net_console)¶ Bases:
blendervr.console.base.Base
,blendervr.console.logic.screen.Logic
,blendervr.console.qt.screen.GUI
-
getName
()¶
-
logger
¶
-
main_logger
¶
-
quit
()¶
-
start
()¶
-
-
class
blendervr.console.screens.
Screens
(parent)¶ Bases:
blendervr.console.base.Base
,blendervr.console.logic.screens.Logic
,blendervr.console.qt.screens.GUI
-
quit
()¶
-
start
()¶
-
blendervr.loader package¶
blendervr.player package¶
-
class
blendervr.player.buffer.
Buffer
¶ Bases:
object
-
addPrefix
(prefix)¶
-
boolean
(data=None)¶
-
command
(data=None)¶
-
float
(data=None)¶
-
integer
(data=None)¶
-
isEmpty
()¶
-
itemID
(data=None)¶
-
matrix_3x3
(data=None)¶
-
matrix_4x4
(data=None)¶
-
size
(data=None)¶
-
string
(data=None)¶
-
subBuffer
(data=None)¶
-
unsigned_char
(data=None)¶
-
vector_3
(data=None)¶
-
vector_4
(data=None)¶
-
-
blendervr.player.buffer.
data_size
(data_type)¶
-
exception
blendervr.player.exceptions.
Common
(reason)¶ Bases:
Exception
-
exception
blendervr.player.exceptions.
Controller
(reason)¶
-
exception
blendervr.player.exceptions.
Main
(reason)¶
-
exception
blendervr.player.exceptions.
Processor
(reason)¶
-
exception
blendervr.player.exceptions.
Processor_Invalid_Device
(reason)¶
-
exception
blendervr.player.exceptions.
Processor_Invalid_Device_Method
(reason)¶
-
exception
blendervr.player.exceptions.
Synchronizer
(reason)¶
-
exception
blendervr.player.exceptions.
User
(reason)¶
-
exception
blendervr.player.exceptions.
VirtualEnvironment
(reason)¶
blendervr.plugins package¶
blendervr.tools package¶
-
class
blendervr.tools.connector.
Client
(controller, module, screen_name)¶
-
class
blendervr.tools.connector.
Common
¶ Bases:
object
-
BUFFER_LEN
= 1024¶
-
SIZE_LEN
= 10¶
-
close
()¶
-
fileno
()¶
-
getClient
()¶
-
run
()¶
-
send
(command, argument='')¶
-
setCallback
(callback)¶
-
setClient
(client, callback=None)¶
-
setWait
(block)¶
-
-
class
blendervr.tools.connector.
Server
(client)¶ Bases:
blendervr.tools.connector.Common
-
getClientInformation
()¶
-
Handle all the errors, warnings and debug info
-
class
blendervr.tools.logger.
Logger
(name)¶ Bases:
logging.Logger
-
addLoginWindow
(login_window, addName=False)¶
-
getVerbosities
()¶
-
get_position
()¶
-
log_position
()¶
-
log_traceback
(error)¶
-
setLevel
(verbosity)¶
-
-
blendervr.tools.logger.
getLogger
(name)¶
Submodules¶
blendervr.base module¶
-
class
blendervr.base.
Base
(parent)¶ Bases:
object
Main struct for the blender vr environment
Parameters: parent (module or class) – -
getMainRunningModule
()¶ Return type: module
-
getParent
()¶ Returns the module that inherits the Base class
Return type: module or class
-
logger
¶ Logger of the main running module
Return type: callback function
-
quit
()¶
-
Module contents¶
Main module of the BlenderVR application
-
blendervr.
is_console
()¶ Check if it is in console mode.
Return type: bool
-
blendervr.
is_creating_loader
()¶ Check if BPY is available.
Return type: bool
-
blendervr.
is_virtual_environment
()¶ Check if the Blender Game Engine is available.
Return type: bool
-
blendervr.
main
()¶
-
blendervr.
run
()¶