5.1 Prototype Definition
5.1.1 Interface
The prototype definition defines exactly what the prototype does in terms of the built-in nodes or of the instances of other prototypes. Here is the syntax for a prototype definition:
PROTO protoName [ protoInterface ] { protoBody } |
The interface is a sequence of field declarations which specify the types, names and default values for the prototype's fields. A field declaration has this syntax:
field fieldType fieldName defaultValue |
where field is a reserved keyword, fieldType is one of: SFColor, SFFloat, SFInt32, SFString, SFVec2f, SFVec3f, SFRotation, SFBool, MFNode, MFColor, MFFloat, MFInt32, MFString, MFVec2f and MFVec3f (SFNode is currently not implemented). fieldName is a freely chosen name for this field and defaultValue is a literal default value that depends on fieldType.
Here is an example of prototype definition:
PROTO MyProto [ |
The type of the root node in the body of the prototype definition (a Solid node in this example) is called the base type of the prototype. The base type determines where instantiations of the prototype can be placed in the scene tree. For example, if the base type of a prototype is Material, then instantiations of the prototype can be used wherever a Material mode can be used.
5.1.2 IS Statements
Nodes in the prototype definition may have their fields associated with the fields of the prototype interface. This is accomplished using IS statements in the body of the node. An IS statement consists of the name of a field from a built-in node followed by the keyword IS followed by the name of one of the fields of the prototype interface:
For example:
PROTO Bicycle [ |
IS statements may appear inside the prototype definition wherever fields may appear. IS statements shall refer to fields defined in the prototype declaration. Multiple IS statements for the same field in the prototype interface declaration is valid.
It is an error for an IS statement to refer to a non-existent interface field. It is an error if the type of the field being associated does not match the type declared in the prototype's interface. For example, it is illegal to associate an SFColor with an SFVec3f. It is also illegal to associate a SFColor with a MFColor or vice versa. Results are undefined if a field of a node in the prototype body is associated with more than one field in the prototype's interface.