Using EXTERNPROTO in VRML

Introduction

PROTOs are an easy way of making new commands in vrml. EXTERNPROTO is the way to use a PROTO which is stored in a seperate file.

Simple EXTERNPROTO

This is an example usage of PROTO and EXTERNPROTO. This is only used for PROTOs which contain geometry or self contained animations etc.


EXTERNPROTO Example1 [
]
["proto1.wrl"]

using the PROTO

Example1 { }

The file proto1.wrl contains

PROTO Example1 [
]
{
}

EXTERNPROTO with eventOut and eventIn

This is a simple example. notice how the field and exposedField values are present in the PROTO but not the EXTERNPROTO. This example also shows how multiple URLs can be used.

EXTERNPROTO Example4 [
 eventIn SFBool set_bind
 field SFString description
 eventOut SFBool bind_changed
 exposedField SFVec3f position
]
[
"exampleproto.wrl"
"http://www.example.org/exampleproto.wrl"
]

The PROTO itself 'exampleproto.wrl'

PROTO Example4 [
 eventIn SFBool set_bind
 field SFString description "Viewpoint"
 eventOut SFBool bind_changed
 exposedField SFVec3f position 0 0 0
]
{
 Viewpoint {
  set_bind IS set_bind
  description IS description
  position IS position
 }
}

EXTERNPROTO when multiple PROTOs in the same file.

In the above examples only one (1) PROTO is stored in the seperate wrl.
When there are multiple PROTOs involved the method is slightly different.

EXTERNPROTO Tree1 [
 field SFVec3f location
]
["treeprotos.wrl#Tree1"]

EXTERNPROTO Tree2 [
 field SFVec3f location
]
["treeprotos.wrl#Tree2"]

As you can see we need to add #'proto name' after the filename. It should be noted this doesn't work in Cosmo Player due to a known bug, it does however work in most other VRML plugins including the major ones.

Notes

None at this time.