H3D API Training  Part 3.3: Python – H3D integration.

Slides:



Advertisements
Similar presentations
Games in Python – the easy way
Advertisements

Computer Science 112 Fundamentals of Programming II User Interfaces
Lilian Blot Announcements Teaching Evaluation Form week 9 practical session Formative Assessment week 10 during usual practical sessions group 1 Friday.
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Lecture 04 – Classes.  Python has a number of classes built-in  lists, dictionaries, sets, int, float, boolean, strings  We can define our own classes.
Python Mini-Course University of Oklahoma Department of Psychology Lesson 26 Classes and Objects 6/16/09 Python Mini-Course: Lesson 26 1.
Viewpoint { eventIn SFBool set_bind exposedField SFFloat fieldOfView # (0,  ) exposedField SFBool jump TRUE exposedField SFRotation orientation.
Adding Functionality To Web-Based VR Basic Concepts Client – server model Client-side static Client-side scripting Server-side scripting.
© De Montfort University, D Graphics and VRML Howell Istance and Chris Hand* De Montfort University * now at
Cse591 Spring 981 VRML Basics The basic elements of VRML files are nodes. Every type of node has a set of fields associated with it. –Common single-valued.
VRML Virtual Reality Modeling Language. What Are We Going to See? What is VRML? Syntax of the language Features Examples.
Sentinel Logic Assumes while loops and input statements.
Guide to Programming with Python
Chapter 5 - Making Music: An On-Screen Piano
© TMC Computer School HC20203 VRML HIGHER DIPLOMA IN COMPUTING Chapter 3 – Object Definition in VRML.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Automatic Generation Tools UNICOS Application Builder Overview 11/02/2014 Ivan Prieto Barreiro - EN-ICE1.
CSC1018F: Object Orientation, Exceptions and File Handling Diving into Python Ch. 5&6 Think Like a Comp. Scientist Ch
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
Python File Handling. In all the programs you have made so far when program is closed all the data is lost, but what if you want to keep the data to use.
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
1 Virtual Reality Modeling Language (VRML97) ©Anthony Steed
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Computer Science 111 Fundamentals of Programming I Model/View/Controller and Data model design.
1 Classes and Controls CE-105 Spring 2007 By: Engr. Faisal ur Rehman.
Classes 1 COMPSCI 105 S Principles of Computer Science.
Computer Science 112 Fundamentals of Programming II Command Buttons and Responding to Events.
Computer Graphics Group Script node Jiří Žára. Computer Graphics Group Contents 1.Script node 2.Motion generators 2Script node.
H3D API Training Part 2.1: X3D. Outline  Scene graphs  X3D – XML syntax  X3D components overview.
Interactive Textures as Spatial User Interfaces in X3D Web3D 2010 Symposium Sabine Webel Y. Jung, M. Olbrich, T. Drevensek, T. Franke, M.Roth, D.Fellner,
111/16/ :14 UML Instance Transformation x y z x y z x y z x y z SRT Model Coordinates.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
H3D API Training Part 3.2: Fields; Event Handling.
Web Development 101 Presented by John Valance
111/22/ :40 UML VRML 2.0 Scene Graph Structure Group Transformation Shape Nodes.
Guide to Programming with Python Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
VRML Anthony Steed Department of Computer Science University College London ©Anthony Steed
Guide to Programming with Python Week 15 Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
Module 14 Application Settings, State, and Life Cycle.
Intro to VRML Let’s build something! The source code examples in this tutorial WORK!
Define WSDL from LDAP Server. Create BPEL Module File -> New Project File -> New Project Choose SOA Choose SOA Choose BPEL Module Choose BPEL Module.
Random Logic l Forum.NET l State Machine Mechanism Forum.NET 1 st Meeting ● December 27, 2005.
Dictionaries and File I/O George Mason University.
Build your own 2D Game Engine and Create Great Web Games using HTML5, JavaScript, and WebGL. Sung, Pavleas, Arnez, and Pace, Chapter 4 Implementing.
Indentations makes the scope/block Function definition def print_message (): print “hello” Function usages print_message () hubo.move ()// hubo is a class.
CE-105 Spring 2007 By: Engr. Faisal ur Rehman
DLP for Virtual Environments (I)
3D Slicer module programming
MPEG-4 Binary Information for Scenes (BIFS)
WITH PYGAME ON THE RASPBERRY PI
Let’s Learn 2. Installing Pygame
8. Installing Pygame
Computer Programming Fundamentals
Python: Control Structures
IST256 : Applications Programming for Information Systems

More on Graphical User Interfaces
This week's classes Connect 4 aiMove
Fundamentals of Python: From First Programs Through Data Structures
8. Starting Pygame Let's Learn Python and Pygame
I210 review.
Blender API: Part 2: Game Engine
CSC1018F: Intermediate Python
Fundamentals of Programming I Windows, Labels, and Command Buttons
Computer Science 111 Fundamentals of Programming I Text Areas
Ensure the cursor is in cell A1 of the ‘Output worksheet.
Lecture 3. Virtual Worlds : Representation,Creation and Simulation
Challenge Guide Grade Code Type Slides
Selamat Datang di “Programming Essentials in Python”
Presentation transcript:

H3D API Training  Part 3.3: Python – H3D integration

H3D Python  Python module H3DInterface: ◦ C++ module defining core H3D types (Vec2f, Vec4f, Node, etc) ◦ Defining Fields and Field base class ◦ Functions to create nodes and access to bindable nodes from H3DInterface import *

H3DInterface module  H3D types in Python: ◦ Node ◦ Vec2f Vec2d (x, y) ◦ Vec3f Vec3d (x, y, z) ◦ Vec4f Vec4d (x, y, z, w) ◦ Rotation (x, y, z, a) ◦ Quaternion (x, y, z, w) ◦ Matrix3f, Matrix4f, Matrix3d, Matrix4d

H3DInterface module  Functions for creating new nodes from X3D ◦ createX3DNodeFromURL( url ) ◦ createX3DNodeFromString( string )  Returns node and dictionary of DEFed nodes node, dn = createX3DNodeFromString( “test.x3d” ) # Access the node with DEF-name SPHERE in test.x3d sphere = dn[“SPHERE”]

H3DInterface module  Functions for accessing bindable nodes: ◦ getActiveDeviceInfo() ◦ getActiveViewpoint() ◦ getActiveNavigationInfo() ◦ getActiveStereoInfo() ◦ getActiveBackground()

H3DInterface module  Scene instance access ◦ getCurrentScenes() - returns a list of all currently instantiated Scene instances.  Special global fields ◦ time - Python access to Scene::time ◦ eventSink - Python access to Scene::eventSink

Special functions  initialize() ◦ Called once upon initialization  traverseSG() ◦ Called once per scene graph loop

H3D Python - Using Fields  Creating field instances: ◦ field_a = SFFloat() ◦ field_b = SFFloat(5) #default value  Routing field instances: ◦ field_a.route( field_b )

H3D Python - Using Fields  Setting field values: ◦ field_a.setValue( 5 ) ◦ my_vec.setValue( Vec3f(1,2,3) )  Getting field values: ◦ a = field_b.getValue() ◦ b = my_vec.getValue().x

H3D Python - TypedField  Definition of new fields ◦ TypedField( base, ( input type ) ) ◦ Logic in update() function class MyVec3f( TypedField( SFVec3f, SFFloat ) ): def update(self, event): f = event.getValue() return Vec3f( math.cos(f),math.sin(f), 0 )

H3D Python - X3D Files  Can load up external X3D files using the function createX3DFromURL()  Returns a group node containing the nodes loaded and a dictionary with the DEFed nodes.

H3D Python - Sphere.x3d <ROUTE fromNode=”MS” fromField=”leftButton” toNode=”PS” toField=”color” /> <ROUTE fromNode=”PS” fromField=”color” toNode=”MATERIAL” toField=”diffuseColor” />

H3D Python - Sphere.py from H3DInterface import * class Color( TypedField( SFColor, SFBool ) ): def update( self, event ): if( event.getValue() ): return RGB( 1, 0, 0 ) else: return RGB( 0, 0, 1 ) color = Color()

H3D Python – Sphere2.x3d  GetRoutesIn() example <ROUTE fromNode=”MS” fromField=”leftButton” toNode=”PS” toField=”color” /> <ROUTE fromNode=”MS” fromField=”rightButton” toNode=”PS” toField=”color” /> <ROUTE fromNode=”PS” fromField=”color” toNode=”MATERIAL” toField=”diffuseColor” />

H3D Python – Sphere2.py from H3DInterface import * class Color( TypedField( SFColor, (SFBool, SFBool) ) ): def update( self, event ): routes_in = self.getRoutesIn() left_button = routes_in[0].getValue() right_button = routes_in[1].getValue() if( left_button and right_button ): return RGB( 1, 1, 0 ) elif( left_button ): return RGB( 0, 0, 1 ) elif ( right_button ): return RGB( 0, 1, 0 ) else: return RGB( 1, 0, 0 ) color = Color()

Exercise 1  Create a program with a sphere. ◦ The color of the sphere should change from white to red depending on how hard the user presses on it. ◦ Useful fields on a in geometry nodes are the “force” and “isTouched” fields.

Exercise 2  Create a program which handles keyboard presses.  E.g. ◦ Add a box to the scene when pressing “b” ◦ Add a cylinder when pressing “c” ◦ Change the background color when pressing “w”