Titania X3D Editor

Bring Colours to Your Life.

Titania v4.3.0

Bring Colours to Your Life.

X3D Reference

Creating new node types

Motivation

You can create new node types that encapsulate:

  • Shapes
  • Sensors
  • Interpolators
  • Scripts
  • anything else ...

This creates high-level nodes:

  • Robots, menus, new shapes, etc.

Syntax: PROTO

A PROTO statement declares a new node type (a prototype):

  • name - the new node type name
  • fields, inputs, and outputs - interface to the prototype

Defining prototype bodies

PROTO defines:

  • body - nodes and routes for the new node type

Syntax: IS

The IS syntax connects a prototype interface field, input, or output to the body:

  • Like an assignment statement
  • Assigns interface field or input to body
  • Assigns body outputs to interface

Interface items connected by IS need not have the same name as an item in the body, but often do:

Using IS

May IS to ...

Interface initializeOnly inputOnly outputOnly inputOutput
initializeOnly yes no no yes
inputOnly no yes no yes
outputOnly no no yes yes
inputOutput no no no yes

Using prototyped nodes

The new node type can be used like any other type

Controlling usage rules

Recall that node use must be appropriate for the context:

  • A Shape node specifies shape, not color
  • A Material node specifies color, not shape
  • A Box node specifies geometry, not shape or color

The context for a new node type depends upon the first node in the PROTO body.

For example, if the first node is a geometry node:

  • The prototype creates a new geometry node type

The new node type can be used wherever the first node of the prototype body can be used.

A sample prototype use

Create a BouncingBall node type that:

  • Builds a beachball
    • Creates an animation clock
    • Using a PROTO field to select the cycle interval
  •  Bounces the beachball
    • Using the bouncing ball program script
    • Using a PROTO field to select the bounce height

Fields needed:

  • Bounce height
  • Cycle interval

Inputs and outputs needed:

  • None - a TimeSensor node is built in to the new node

Body needed:

  • A ball shape inside a transform
  • An animation clock
  • A bouncing ball program script
  • Routes connecting it all together

Changing a prototype

If you change a prototype, all uses of that prototype change as well

  • Prototypes enable world modularity
  • Large worlds make heavy use of prototypes

For the BouncingBall prototype, adding a shadow to the prototype makes all balls have a shadow.

Syntax: EXTERNPROTO

Prototypes are typically in a separate external file, referenced by an EXTERNPROTO

  • name, fields, events - as from PROTO, minus initial values
  • url - the URL of the prototype file
  • #name - name of PROTO in file

Summary

  • PROTO declares a new node type and defines its node body
  • EXTERNPROTO declares a new node type, specified by URL