Various useful nodes

From H3D.org

Jump to: navigation, search

Contents

Useful nodes

The UsefulNodes library in the downloads section contains a collection of various nodes that hopefully can be useful for other people. I have decided to list the contents here with some simple examples for the usage to give you an idea how they work.

WebCameraTexture

Screen shot using camera with view from SenseGraphics office
Enlarge
Screen shot using camera with view from SenseGraphics office

The WebCameraTexture node makes it possible to use real-time video from a web camera as a texture on any shape in H3D API. It uses PTLib to grab images from the camera and is very simple to use.

 
  <Shape>
    <Appearance>
	<Material />
	<WebCameraTexture frameRate="10"/>
	<TextureTransform scale = "-1 -1" />
    </Appearance>
    <Rectangle2D size="0.3 0.3" />
  </Shape>
 

PaintableTexture

Showing off great painting skills
Enlarge
Showing off great painting skills

The PaintableTexture node allows for real-time updates of a texture, by changing the pixel values at specified texture coordinates. It is a simple implementation that only sets the pixel at a texture coordinate but can be easily extended to perform more advanded painting operations. A tutorial explaining the c++ code for the node is also available. An example usage where the haptics device is used to paint in the texture can be found below.

paintabletexture.x3d

 
<Group>
  <Shape>
     <Appearance>
       <Material />
       <PaintableTexture DEF="TEXTURE" />
       <SmoothSurface />
     </Appearance>
     <Rectangle2D DEF="GEOM" size="0.3 0.3" />
  </Shape>
  <PythonScript DEF="PS" url="paintabletexture.py" />
  <ROUTE fromNode="GEOM" fromField="contactTexCoord" toNode="PS" toField="firstTexCoord" />
  <ROUTE_NO_EVENT fromNode="PS" fromField="firstTexCoord" toNode="TEXTURE" toField="paintAtTexCoord" />
</Group>
 

paintabletexture.py

 
from H3DInterface import *
 
# This field class just takes the first value of its input MField 
# and uses it as output
class FirstTouchTexCoord( TypedField( SFVec3f, MFVec3f ) ):
  def update( self, event ):
    tex_coords = event.getValue()
    if( len(tex_coords) > 0 ):
      return tex_coords[0]
    else:
      return Vec3f( 0, 0, 0 )
 
firstTexCoord = FirstTouchTexCoord()
 

GraspTransform

The GraspTransform node makes it easier to perform a grasp and examine paradigm using a 6-DOF input haptics device. You can grasp an object, look at it from different angles using the haptics device and leave it in a new position/orientation. Following is an example how to use a button of a haptics device to grab and hold on to an object.

 
<Group>
  <IMPORT inlineDEF='H3D_EXPORTS' exportedDEF='HDEV' AS='HDEV' />  
  <GraspTransform DEF="GT" >
    <Shape>
      <Appearance>
        <Material />
      </Appearance>
      <Box size="0.1 0.1 0.1" />
    </Shape>
  </GraspTransform>
  <ROUTE fromNode="HDEV" fromField="mainButton" toNode="GT" toField="grasp" />
  <ROUTE fromNode="HDEV" fromField="trackerPosition" toNode="GT" toField="graspPosition" />
  <ROUTE fromNode="HDEV" fromField="trackerOrientation" toNode="GT" toField="graspOrientation" />
</Group>
 

NetworkSender/NetworkReceiver

The NetworkSender and NetworkReceiver nodes helps making simple network communication at the X3D level to send field values over a network. It allows you to set up arbitrary fields and then route to them in a normal manner to transfer it to the other side. E.g. sending the position and orientation of the haptics device to be drawn on another computer can be done by the following.

sender.x3d

 
<Group>
  <NetworkSender DEF="SENDER" 
		 port="90"  
  		 receiverAddress="192.168.2.104" 
		 receiverPort="89" 
		 protocol="UDP" >
    <field type="SFVec3f" name="pos" accessType="inputOnly" /> 
    <field type="SFRotation" name="orn" accessType="inputOnly" /> 
  </NetworkSender>
 
  <IMPORT inlineDEF='H3D_EXPORTS' exportedDEF='HDEV' AS='HDEV' />  
 
  <ROUTE fromNode="HDEV" fromField="trackerPosition" toNode="SENDER" toField="pos" />
  <ROUTE fromNode="HDEV" fromField="trackerOrientation" toNode="SENDER" toField="orn" />
</Group>
 

receiver.x3d

 
<Group>
  <Transform DEF="REMOTE_STYLUS_XF" >
    <Shape >
      <Appearance>
        <Material diffuseColor="0.815686 0.592157 0.513726" />
      </Appearance>
      <Sphere radius="0.01" />
    </Shape>
    <Transform translation="0 0 0.08" rotation="1 0 0 1.570796" >
      <Shape>
        <Appearance>
          <Material/>
        </Appearance>
        <Cylinder radius="0.005" height="0.1"/>
      </Shape>
    </Transform>
  </Transform>
 
  <NetworkReceiver DEF="RECEIVER" port="89"  protocol="UDP" >
    <field type="SFVec3f" name="pos" accessType="inputOnly" /> 
    <field type="SFRotation" name="orn" accessType="inputOnly" /> 
  </NetworkReceiver>>
 
  <ROUTE fromNode="RECEIVER" fromField="pos" toNode="REMOTE_STYLUS_XF" toField="translation" />
  <ROUTE fromNode="RECEIVER" fromField="orn" toNode="REMOTE_STYLUS_XF" toField="rotation" />
</Group>
 

Torus

Screen shot of Torus geometry
Enlarge
Screen shot of Torus geometry

The Torus node provides a torus geometry using the glut library to generate it. There is a tutorial available here that explains the c++-code used for the node.

 
  <Shape>
    <Appearance>
	<Material diffuseColor="1 0 0"  
                  shininess="0.4" 
                  specularColor="1 1 1"/>
	<SmoothSurface />
    </Appearance>
    <Torus innerRadius="0.05" outerRadius="0.1" />
  </Shape>
 

Shadow nodes

Screen shot shadow nodes in use
Enlarge
Screen shot shadow nodes in use

The shadow nodes is a collection of nodes(ShadowCaster, ShadowBox, ShadowSphere) that let objects cast shadows. It uses shadow volumes and the stencil buffer to accomplish this. Currently only boxes and spheres can cast shadows but other volumes can be added by creating new nodes that support other shapes.

Personal tools
go to