The XVR project – Rapid development of VR applications
Franco Tecchia PERCRO Scuola Superiore S.Anna (ex-UCL)
The XVR project Rapid development of VR applications Franco - - PowerPoint PPT Presentation
The XVR project Rapid development of VR applications Franco Tecchia PERCRO Scuola Superiore S.Anna (ex-UCL) Background / Recap 03/26/07 What is a state for a VR application? In theory: a collection of information about the
Franco Tecchia PERCRO Scuola Superiore S.Anna (ex-UCL)
03/26/07
03/26/07 3
VR World “state”
03/26/07 4
03/26/07 5
03/26/07 6
03/26/07 7
03/26/07 8
Sutherland, Ivan E., 1968 "A Head-Mounted Three Dimensional Display"
03/26/07 9
03/26/07 10
03/26/07 11
03/26/07 12
03/26/07 13
needed for motion calculation
needed for collision detection
03/26/07 14
03/26/07 15
03/26/07 16
03/26/07 17
03/26/07 18
03/26/07 19
03/26/07 20
03/26/07 21
03/26/07 22
VR_EVENT_1 VR_EVENT_1 VR_EVENT_3 VR_EVENT_3 VR_EVENT_2 VR_EVENT_2 VR_EVENT_4 VR_EVENT_4
03/26/07 23
~ 60 Hz 100-200 Hz >1kHz ~10Hz ~30Hz ~ 60 Hz 100-200 Hz >1kHz ~10Hz ~30Hz ~ 60 Hz 100-200 Hz >1kHz ~10Hz ~30Hz
03/26/07 24
03/26/07
03/26/07 26
03/26/07 27
03/26/07 28
03/26/07 29
03/26/07 30
03/26/07 31
03/26/07 32
Compiler
Interpreter (Virtual Machine) Dedicated scripting language Output Binary ByteCode
03/26/07 33
03/26/07 34
03/26/07 35
03/26/07 36
Virtual Machine Bytecode execution (Multi-Threaded) Virtual Machine Bytecode execution (Multi-Threaded) HI- Performance Real-Time Scene-Graph Audio – Video Library VR Device Handling Real-Time Physics Network Renderer Network Manager
03/26/07 37
Virtual Machine Virtual Machine
IP
bytecode bytecode
OP1 OP2 OP3 BS STACK
Function Class Lib Class decl Const Function
GLOBAL VAR
SP
03/26/07 38
03/26/07 39
LEXER PARSER Semantic Analyzer ASM Generator Code Generator Optimizer S Y M B O L T A B L E SOURCE File .bin
A Symbol Table keeps all the information about variables, functions and so on variables, functions and so on
Parser and a semantic analyser interpret the code and check its consistency check its consistency
A virtual processor ASM code is generated
An optimiser try to get the best performances from loops and recurrent constructs loops and recurrent constructs
The ASM code is transformed in bytecode (compressed)(compressed)
The result of the compilation process is the .bin file
03/26/07 40
function Fibonacci( n ) { if( n < 0) return 0; if( n ==1) return 1; return Fibonacci( n - 1) + Fibonacci( n - 2 ); } function Main() { return Fibonacci(10); }
03/26/07 41 Function Main Function Fibonacci 0: PUSHN 1: RET 2: PUSHN 2 3: JGEQ BP(-1) Quad:5 4: RET 5: JNEQ BP(-1) 1 Quad:7 6: RET 1 7: SUB BP(-1) 1 BP(1) 8: PUSH BP(1) 9: CALL Quad:2 (func FIBONACCI) 10: POP BP(1) 11: POPN 1 12: SUB BP(-1) 2 BP(2) 13: PUSH BP(2) 14: CALL Quad:2 (func FIBONACCI) 15: POP BP(2) 16: POPN 1 17: ADD BP(2) BP(1) 18: RET BP(1) 19: PUSHN 1 20: PUSH 10 21: CALL Quad:2 (func FIBONACCI) 22: POP BP(1) 23: POPN 1 24: RET BP(1) Reserve 2 Stack Slots for BS(1) e BS(2) Temporary VAR Fibonacci(n-1)
25 intruction
03/26/07 42
1 L__ RET 160 1 I__ POPN 154 1 L__ POP 150 8 I__ CALL 144 10 I__ PUSH 138 1 I__ PUSHN 132 1 L__ RET 128 1 2 L_L ADD 122 1 I__ POPN 116 2 L__ POP 112 8 I__ CALL 106 2 L__ PUSH 102 2 2
LIL SUB 88 1 I__ POPN 82 1 L__ POP 78 8 I__ CALL 72 1 L__ PUSH 68 1 1
LIL SUB 54 1 I__ RET 48 54 1
LII JNEQ 34 I__ RET 28 34
LII JGEQ 14 2 I__ PUSHN 8 ___ RET 6 I__ PUSHN
Total byte
03/26/07 43
03/26/07 44
Legend:
17fps 3fps 4fps 5fps 5fps 6fps 40000 35fps 6fps 8fps 11fps 10fps 12fps 20000 40fps 12fps 15fps 20fps 19fps 23fps 10000 53fps
AVM JS JS PY Wine S3D Wine PY S3D Number of Particles 17fps 3fps 4fps 5fps 5fps 6fps 40000 35fps 6fps 8fps 11fps 10fps 12fps 20000 40fps 12fps 15fps 20fps 19fps 23fps 10000 53fps
AVM JS JS PY Wine S3D Wine PY S3D Number of Particles
03/26/07 45
03/26/07 46
IF..ELSE WHILE DO..WHILE FOR BREAK CONTINUE SWITCH..CASE SET
SCENE_FOV Field of view SCENE_NEAR Near clipping plane distance SCENE_FAR Far clipping plane distance AUDIO_MODE 3d Audio Setup mode
03/26/07 47
VAR i; VAR i; VAR j,k; VAR j,k; VAR x = 2; VAR x = 2; VAR y = 3.1; VAR y = 3.1; VAR s = “Don’t panic !!!” VAR s = “Don’t panic !!!” k = 4.3; k = 4.3; i = 8; i = 8; i = 9.2; i = 9.2; VAR v = [0.0, 1.0, 0.0]; VAR v = [0.0, 1.0, 0.0];
static var a = 10; … a = 7; … reset a; // a = 10
03/26/07 48
03/26/07 49
class COutput { print(p1); println(p1); }; class Engine: COutput { var m_fuel; var m_power; Init( f, p); Info(); ShowPower(); }; function Engine::Engine( f, p ) { Init(f,p); } function Engine::~Engine( f, p ) { m_fuel = m_power = void; } function Engine::Init( f, p ) { m_fuel = f; m_power = p; }
Classes use a C++-like sintax Simple declaration Declaration with inheritance
Constructor (Optional) Destructor (Optional) Method implementation
03/26/07 50
Class Veicle: Engine, Bodywork { var m_Desc; var m_NumWeels; var m_MaxVel; Info(); }; function Veicle::Veicle( Desc, Weels, MaxVel, EngineFuel, EngineHP, BodyColor, BodyStuff ) { m_Desc = Desc; m_NumWeels = Weels; m_MaxVel = MaxVel; Engine::this.Init( EngineFuel, EngineHP ); Bodywork::this.Init( BodyColor, BodyStuff ); }
Multiple inheritance, comma separated Calling a base class method
03/26/07 51
03/26/07 52
Swizzles allow to access the single components of a vector or to generate a new vector with the components exchanged. <VECTOR NAME>.<SWIZZLE> x : first component y : second component z : third component w : fourth component _ or 0 : ignore component v1 = [ 1, 100, -10, -100]; v1.zwx corresponds to [ -10, -100, 1] v1.xxxy corresponds to [ 1, 1, 1, 100 ] v1.x_z or v1.x0z correspond to [ 1, 0, -10 ] v2 = [ -2, 20, 200, -20 ]
v2.x = 5 --> v2 = [ 5, 20, 200, -20 ] multiple components change: v2.wy = [ 3,4 ] --> v2 = [ -2, 4, 200, 3 ] multiple components change with no changes on some of them: v2.x_z = [ 3,4,5 ] --> v2 = [ 3, 20, 5, -20 ]
03/26/07 53
03/26/07 54
#DEFINE #IFDEF #ENDIF #ELSE #INCLUDE #PRAGMA Preprocessor directives, such as #define and #ifdef, are typically used tomake source programs easy to change and easy to compile in different execution environments. Directives in the source file tell the preprocessor to perform specific actions. For example, the preprocessor can replace tokens in the text, insert the contents of other files into the source file, or suppress compilation of part of the file by removing sections of text. Preprocessor lines are recognized and carried out before macro expansion.
03/26/07 55
multiple source files
compiled separately
03/26/07 56
includes the others
“#define”s
03/26/07 57
multiple compilations
03/26/07 58
03/26/07 59
Any application is based on 6 fundamental function (built in in fundamental function (built in in all the scripts) all the scripts)
Currently there are 2 threads calling these functions. There calling these functions. There could be more in the future. could be more in the future.
Atomicity of the operations is
properly shared between properly shared between threads threads
03/26/07 60
Every time an XVR script is executed it creates a temporary executed it creates a temporary working directory (inside the user working directory (inside the user temp) temp)
OnDownload is used to move files from their original location to the from their original location to the working directory working directory
Zip Files are automatically exploded
Generic code can be executed inside OnDownload inside OnDownload
03/26/07 61
Once the download is complete, this is the right place for initialization code is the right place for initialization code
Please note that OnInit accept a “params” value. This is the “params” value. This is the “UserParam” string reported in the “UserParam” string reported in the HTML code HTML code
There is an implicit OpenGL “SwapBuffer” when OnInit ends “SwapBuffer” when OnInit ends
03/26/07 62
Function dedicated to rendering. By default it gets called after each screen default it gets called after each screen refresh (60 Hz). refresh (60 Hz).
Desired framerate can be changed using SetFramerate(Value) using SetFramerate(Value)
It’s the ONLY function that has access to the OpenGL frame buffer access to the OpenGL frame buffer
All the rendering code must be inside this function (or inside functions called this function (or inside functions called by OnFrame) by OnFrame)
The maximum Frame Rate allowed is 100 Hz 100 Hz
03/26/07 63
Function normally dedicated to mange an high speed loop. By default mange an high speed loop. By default it gets called at 100Hz it gets called at 100Hz
Desired time-
step can be changed using SetTimestep(Value) using SetTimestep(Value)
Minimum time-
step = 1ms
Independent from framerate (unless the system is overloaded) the system is overloaded)
Excellent place for updating objects positions, sound, real time physics, positions, sound, real time physics, haptic interfaces and network haptic interfaces and network programming. programming.
It has no access to the framebuffer
03/26/07 64
03/26/07 65
common XVR graphical construct useful for multipass rendering, picture in picture, stereo rendering
rendering
03/26/07 66
03/26/07 67
Obj Obj Obj
Mesh Mesh Mesh
Obj Obj Obj
Billboard Billboard Billboard
Obj Obj Obj Obj Obj Obj Obj Obj Obj
Mesh Mesh Mesh
Obj Obj Obj
Callback Callback Callback
CVmObj
03/26/07 68
Obj Obj Obj
Mesh Mesh Mesh Material Material Material Texture Texture Texture Subset Subset Subset Subset Subset Subset Subset Subset Subset
Material Material Material
Material Material Material Texture Texture Texture
CVmMesh/NewMesh
Polygonal meshes loaded from VRML/AAM files. Bounding box Material list Subset list Vertex animation
Shader Shader Shader
03/26/07 69
Obj Obj Obj Obj Obj Obj … …
3D Modeling Tools 3D Modeling Tools Exporters
AAM data AAM data VRML data VRML data IDASF data IDASF data
03/26/07 70
XVR native format for the description of triangular meshes:
Originally created to overcome VRML limitations S
imple sintax, easy to parse
Pixel and Vertex shaders can be embedded
S upport to:
moothing Groups
kinning Exporters: Max, GMax, Maya and Blender
03/26/07 71
Fully featured version
for 3DS tudioMax
Also available (with
limitations) for:
Maya Blender GMax
03/26/07 72
SetPosition() SetRotation() SetScale() Translate() Rotate() / RotateABS() SetRotationMatrix() SetPivotPoint()
( int flags, int x, int y );
Draw
Obj Obj Obj Obj Obj Obj Obj Obj Obj
Mesh Mesh Mesh
AddChild
( CVmObj child, float posx, float posy, float posz );
LinkToXXX
( CVmNewMesh mesh ) ( CVmBillboard bboard ) ( CVmHtmlPage hpage ) ( CVmText bboard ) ( string callback )
03/26/07 73
Hide() / HideAll() UnHide() / UnHideAll() GetSubsetIndex() GetSubsetDescription() GetSubBoundingSphere() Get__()
( int flags, int x, int y );
VR_FRAMENUMBER for vertex animation
Draw
Translate() Scale() Normalize() CenterBoundingBox() Mirror() GetBoundingBox() ForceMaterial() ModulateMaterials() ModulateSubsetMaterial() ChangeTextureParams() CheckTransparency() Add/RemoveShader() …