Microsoft anticipates that it will release a reference implementation in object and source code form. Microsoft expects to license this code in the following manner:
ActiveVRML is intended to provide a framework for constructing models that manipulate media including sound, 2D images, and 3D geometry. There are two characteristics that make ActiveVRML unique and especially well suited for this task: all values in ActiveVRML potentially vary with time, and values may change in reaction to events.
Every value in ActiveVRML may change with time. For example, there is an image type in ActiveVRML. An image object is not like a static photograph, but more like a video, continuously changing with time. Similarly, geometry in ActiveVRML is not like a static geometry model, but is (potentially) animated, moving, and reacting to events. This is an important principle in ActiveVRML; every value may change with time. Even simple objects, like numbers, may change with time. Values that can vary with time are called behaviors in ActiveVRML. A reactive behavior is one that (potentially) varies in response to events.
One way that values change with time is in response to particular events. For example, a user input event, or a mouse event. Events may be caused by internal events (to the ActiveVRML model) as well. For example, a particular number value being zero may cause an event.
Finally, ActiveVRML is a language for describing media via reactive behaviors. The language part of ActiveVRML is actually very small. The bulk of this paper is spent describing a large collection of useful library functions for manipulating media types.
Examples include 17 which represents a literal number, and [1, 2, 3], which uses the constructor form for lists to build a list of numbers. Allowable constructor forms are defined below in the sections defining each type.
ActiveVRML is strict; that is, it obeys call by value semantics for argument evaluation. The order of the evaluation of arguments is not specified. Argument application associates left; for example, f(x)(y) equates to (f(x))(y).
if expression1 then expression2 else expression3is an IF expression. It represents the value computed by evaluating the boolean test of expression1 and selecting expression2 or expression3 depending upon the true value of expression1. The types of the two branches of the IF expression are required to match (or unify). There is no corresponding IF THEN statement; all IF statements have both branches. Since ActiveVRML is functional (operations do not have side effects), such one-armed IF statements would not be very useful.
let declaration1; . . . declarationn[;] in expressionis a LET expression. It represents the value of an expression when evaluated in a context that includes the bindings for declaration1 through declarationn. The LET expression is used to introduce a local scope. The declarations are evaluated simultaneously. The names are in scope of the right hand sides of the declarations, allowing for forward declarations and mutual recursion automatically. All of the declared identifiers are required to be distinct. The scope of the declarations is limited to the LET expression itself. The semicolon following the last declaration is optional.
identifier = expressionOr, they declare a function:
identifier(identifier, ..., identifier) = expressionThe following is an example function declaration:
swizzle(seed) = if seed = 1 then 1 else if odd(seed) then swizzle(seed * 3 + 1) + seed else swizzle(seed / 2) + seedThis declares a function, swizzle, that takes one formal argument, seed. The function is recursive. All function declarations are assumed to be recursive. When you use the name of the function you are declaring within the expression, you are referring to the function itself, not a new or different function.
The following is an example variable declaration:
swizit = swizzle(27)This declares the variable swizit to be the evaluation of the expression swizzle(27). We can illustrate scoping in LET expressions by combining these declarations along with a declaration for the predicate odd used in the declaration of swizzle:
let swizzle(seed) = if seed = 1 then 1 else if odd(seed) then swizzle(seed * 3 + 1) + seed else swizzle(seed / 2) + seed; odd(i) = (mod(i, 2) = 1); swizit = swizzle(27) in swizitNotice that the declaration for odd comes after its use in the declaration of swizzle. Since all of the declarations within a LET expression are assumed to be mutually recursive, this is legal. However, for better readability and because the declarations are not truly mutually recursive, the definition of odd should probably appear first.
Within the scope of the LET expression, three identifiers are declared, swizzle, odd, and swizit. Beyond the scope of this expression, the three declarations are not available. The value of the LET expression is the value of swizit which evaluates to 101440.
In addition to these simple forms of variable and function declarations, it is also possible to use pattern matching to specify the destructuring of values within a declaration. This is described later in this document.
successor(nat) = nat + 1ActiveVRML assigns successor the type number->number, meaning it will map any value of type number to another value of type number. This typing is strong in the sense that ActiveVRML will catch all type errors during authoring. It is also convenient; the user did not have to explicitly give the type as the system inferred it.
Finally, types are polymorphic, meaning that a given type may stand for many different type instances. Consider the following declaration:
nada(val) = valWhen applied, nada will return its actual argument unchanged. Thus nada(3) evaluates to the number 3 and nada("hello") evaluates to the string "hello". The type that ActiveVRML infers for nada is polymorphic: a->a. Here a is a type identifier and may be replaced everywhere uniformly to create an instance of a polymorphic type. Thus, number->number is an instance of a->a, and so is string->string.
Note that number->string is not an instance of a->a, since one a was replaced by a number and the other by a string (not uniformly). A polymorphic type can contain more than one type identifier, for example, a->b. In this case, each identifier can be replaced separately. Thus, number->b, a->string, number->string, number->number, and g->string are all instances of the polymorphic type a->b.
Every expression and declaration in ActiveVRML is assigned a type by the system using a standard Milner-Damas polymorphic type checker. Except to improve exposition and occasionally to resolve ambiguity with an overloaded operator, it is not necessary for the programmer to explicitly give types. An expression may be qualified with a type using the syntax like the following:
For example, the following syntax can be used to restrict nada to a particular type (desirable for clarity):
nada(val: string) = val
This will assign nada the monomorphic type string->string. The following sections define the basic types for ActiveVRML and list the constructor forms and functions for these types. Later sections define types for reactivity and for modeling (geometry, images, and associated types).
function pattern . expression
f (x, y) = x * y + 1can be thought of as an abbreviation for:
f = function (x, y). x * y + 1Function declarations are value declarations where the value is a function value.
infix o: (a -> b) * (b -> g) -> (a -> g)
first: a * b -> a
head: a list -> a
fun(e1, fun(e2, fun(...,fun(en-1, fun(en, base))...)))nth: a list * number -> a
infix and: boolean * boolean -> boolean
infix or: boolean * boolean -> boolean
infix not: boolean -> boolean
infix =: a * a -> boolean
infix <>: a * a -> boolean
digit+ (‘.’ digit*)? ([’e’ ‘E’] [’+’ ‘-‘]?digit+)?
infix +: number * number -> number
infix *: number * number -> number
infix -: number * number -> number
infix /: number * number -> number
prefix -: number -> number
prefix +: number -> number
infix <: number * number -> boolean
infix <=: number * number -> boolean
infix >: number * number -> boolean
infix >=: number * number -> boolean
abs: number -> number
sqrt: number -> number
mod: number * number -> number
ceiling: number -> number
floor: number -> number
round: number -> number
radiansToDegrees: number -> number
degreesToRadians: number -> number
asin: number -> number
acos: number -> number
atan: number * number -> number
atan: number -> number
cos: number -> number
sin: number -> number
tan: number -> number
infix ^: number * number -> number
exp: number -> number
ln: number -> number
log10: number -> number
seededRandom: number -> number
red until leftButtonPress => green
In this expression, UNTIL is the main operator. The expression is parsed into the following:
red until (leftButtonPress => green)
The reactive behavior changes the color from red to green when the mouse button is pressed.
The subexpression leftButtonPress => green is called a handler. It pairs up an event, leftButtonPress, with a value, green. The value is the action taken when the event occurs.
The UNTIL construct can also be used to watch for more than one event, reacting to the first one that occurs. For example:
red until leftButtonPress => green | rightButtonPress => yellow
This is parsed into the following:
red until ( (leftButtonPress => green) | (rightButtonPress => yellow) )
The color remains red until either the left or right mouse buttons are pressed. If the left button is pressed, the color changes to green. If the right button is pressed, the color changes to yellow.
In general, the logic of the UNTIL operator follows this pattern:
b0 until e1 => b1 | e2 => b2 . . . | en => bn
The reactive behavior is b0 until any one of the events occurs, e1 through en. The first event to occur, ei, results in the behavior, bi.
A more advanced form of events uses event data to produce the next behavior. For example:
0 until numEvent => function x. x + 1
In this case, numEvent is an event that produces a number. The value of this behavior is zero until the event occurs, and then becomes the value associated with the event plus 1.
The type checking of an UNTIL expression is as follows: If b is an a behavior and e is an a event, then b until e is a reactive behavior with type a behavior.
The next section describes events in more detail.
Events are constructed from one of the following types of events.
u leftButtonPress: unit event u rightButtonPress: unit event u keyPress: character event
0 until snapshot(xComponent(mousePosition), leftButtonPress,)
is the static behavior 0 until the left mouse button is pressed, and then becomes the static value of the x coordinate of the mouse position at the time of the press. The behavior
0 until leftButtonPress => xComponent(mousePosition)is different in that it produces a behavior that continues to vary with time and track the x coordinate of the mouse after the button event occurs. The following subsections define the types and operators used in constructing reactive values.
b = time until leftButtonPress => end
This behavior varies with time until the leftButtonPress event occurs. Then it terminates.
A behavior will also terminate if one of its defining behaviors terminates. For example, consider
b’ = f(b, 3)
If behavior b terminates, then b’ terminates at the same time.
The DONE construct is a unit event that can be used to detect when a behavior has terminated and react accordingly. Consider the following:
repeat(b) = b until done => repeat(b)
This function takes behavior b and runs it until it terminates. Then it starts b again. (Note: This a built-in function in ActiveVRML.)
b until e => b’
When b is performed, there are two times to consider, the system time and the local time for b. Let the system time be tg. Whatever the value of tg is, at the time b is performed, it represents time zero for b. Event e occurs some time after tg. Let this time be te. This behavior can then be broken down by time: Do behavior b from time tg to te. Then do behavior b’. The local time for b is zero to (te - tg). When b’ starts, its local time is zero as well.
Here is a simple behavior that uses the local time as its events:
green until time = 2 => (blue until time = 1 => red)
This behavior makes the color green for 2 seconds, blue for 1 second, and then red.
doubleSpeed = time * 2; b = playVideo(video); doubleVideo = timeTransform(b, doubleSpeed)
In this example, the video is played at twice its original speed. From the perspective of global time, each 1 second interval corresponds to 2 seconds of local time. The effects of time transformation are cumulative. For example:
This line would play the video at four times its original speed.
To be consistent and predictable, the number argument (n) for the time transformation must satisfy two rules:
u Monotone -- For all times t0 and t1 when t0 is less than t1, n at time t0 must be less than n at time t1. u Nonnegative -- For all times t, n at time t is nonnegative.
Monotonicity is required to make event reaction sensible (event transitions cannot be undone). Nonnegativity is required to prevent definition of a behavior before local time zero; that is, it may not make sense to sample a behavior like a video before local zero.
Certain behaviors, principally those defined by system or user input devices, may not be transformed in time in the same way that artificial behaviors can be. Such devices ignore user-defined time transformations when they are sampled.
Constructors done : unit event
infix | : a event * a event -> a event
predicate: boolean -> unit event
infix => : a event * (a -> b) -> b event
infix => : a event * b -> b event
suchThat : a event * (a -> boolean) -> a event
andEvent : a event * b event -> a*b event
snapshot: a * unit event -> a event
infix until : a * a event -> a
repeat : a -> a
ActiveVRML uses the following conventions:
u Time is specified in seconds. u Angles are specified in radians. u Distances, when necessary, are specified in meters. u A right-handed coordinate system is used with positive x to the right, positive y up, and negative z into the screen.
point2Xy: number * number -> point2
point2Polar: number * number -> point2
addVector: point2 * vector2 -> point2
subtractVector: point2 * vector2 -> point2
infix -: point2 * point2 -> vector2
distance: vector2 * vector2 -> number
distanceSquared: vector2 * vector2 -> number
xComponent: point2 -> number
yComponent: point2 -> number
apply: transform2 * point2 -> point2
thetaComponent: point2 -> number
phiComponent: point2 -> number
vector2Xy: number * number -> vector2
vector2Polar: number * number -> vector2
length: vector2 -> number
lengthSquared: vector2 -> number
infix +: vector2 * vector2 -> vector2
infix -: vector2 * vector2 -> vector2
scaleVector2: vector2 * number -> vector2
dot: vector2 * vector2 -> number
xComponent: vector2 -> number
yComponent: vector2 -> number
apply: transform2 * vector2 -> vector2
thetaComponent: vector2 -> number
rhoComponent: vector2 -> number
Constructors identityTransform2: transform2
translate: number * number -> transform2
translate: vector2 -> transform2
scale: number * number -> transform2
scale: vector2 -> transform2
scale2: number -> transform2
rotate2: number -> transform2
shear2: number -> transform2
transform3x2: number * number * number * number * number * number -> transform2
inverse: transform2 -> transform2
isSingular: transform2 -> boolean
import(pathname.[bmp | jpeg | gif]): image * vector2 * number
renderedImage: geometry * camera -> image
infix over: image * image -> image
opacity2: number -> (image -> image)
crop: point2 * point2 -> (image -> image)
apply: transform2 * image -> image
imageMontage: image * number -> montage
infix union: montage * montage -> montage
renderedImage: montage -> image
point3Xyz: number * number * number -> point3
point3Spherical: number * number * number -> point3
infix -: point3 * point3 -> vector3
distance: point3 * point3 -> number
addVector: point3 * vector3 -> number
subtractVector: point3 * vector3 -> number
distanceSquared: point3 * point3 -> number
apply: transform3 * point3 -> point3
xComponent: point3 -> number
yComponent: point3 -> number
zComponent: point3 -> number
thetaComponent: point3 -> number
phiComponent: point3 -> number
rhoComponent: point3 -> number
vector3Xyz: number * number * number -> vector3
vector3Spherical: number * number * number -> vector3
vector3Spherical(theta, phi, rho)
normal: vector3 -> vector3
length: vector3 -> number
lengthSquared: vector3 -> number
infix +: vector3 * vector3 -> vector3
infix -: vector3 * vector3 -> vector3
scaleVector3: vector3 * number -> vector3
dot: vector3 * vector3 -> number
cross: vector3 * vector3 -> vector3
apply: transform3 * vector3 -> vector3
xComponent: vector3 -> number
yComponent: vector3 -> number
zComponent: vector3 -> number
thetaComponent: vector3 -> number
phiComponent: vector3 -> number
rhoComponent: vector3 -> number
translateXyz: number * number * number -> transform3
translate: vector3 -> transform3
scale: number * number * number -> transform3
scale: vector3 -> transform3
scale3: number -> transform3
rotate: vector3 * number -> transform3
xyShear: number -> transform3
zyShear: number -> transform3
xzShear: number -> transform3
transform4x4: number * number * number * number * number * number * number * number * number * number * number * number * number * number * number * number -> transform3
lookAtFrom: point3 * point3 * vector3 -> transform3
inverse: transform3 -> transform3
isSingular: transform3 -> boolean
import(filename.[wrl]): geometry * point3 * point3 In the import constructor, geometry is the result of importing the specified file. The two points returned are the minimum and maximum extents of the tightest axis-aligned, rectangular bounding volume containing the geometry.
infix union: geometry * geometry -> geometry The union function aggregates two geometries into their geometric union.
soundSource3: sound -> geometry The soundSource3 function allows sounds to be embedded into a geometry. It creates a geometry with the specified sound positioned at the local coordinate system origin. The resultant geometry may be transformed in space, and has no visible presence when rendered. The function renderedSound, described in the Sound section below, takes a geometry and a microphone, and creates a sound by spatializing all of the sounds embedded into that geometry with respect to the microphone.
apply: transform3 * geometry -> geometry
opacity3: number -> (geometry -> geometry) The opacity3(value)(geo) function, given a value from 0.0 to 1.0, creates a new geometry identical to geo, but (value * 100) percent opaque. These compose multiplicatively, making opacity3(0.5)(opacity3(0.2)(myOpaqueGeo) result in a geometry with opacity of 0.1 (or 90% transparent).
texture: image -> (geometry -> geometry) The texture function is the means by which texture mapping onto geometry is specified. The coordinates of the image are mapped onto the texture map coordinates associated with the vertices of the primitive geometries comprising the geometry being mapped, resulting in textured geometry. If the primitive geometries have no texture coordinates, texturing is ignored.
The following functions create light geometries, all of which having no visible appearance themselves; but, they do cast light onto other objects they are aggregated with.
ambientLight: color -> geometry
directionalLight: color -> geometry
pointLight: color -> geometry
spotLight: color * number * number * number -> geometry
The following functions allow for attributing geometry with standard Lambertian shading characteristics. The outermost applied attribute overrides other attributes of the same kind; that is, diffuseColor(red)(diffuseColor(blue)(geo)) results in a red geometry.
diffuseColor: color -> (geometry -> geometry)
ambientColor: color -> (geometry -> geometry)
specularColor: color -> (geometry -> geometry)
emissiveColor: color -> (geometry -> geometry)
specularExponent: number -> (geometry -> geometry)
simpleCamera: number -> camera
apply: transform3 * camera -> camera
Note that sound is always considered to be single channel. Stereo is supported by constructing two separate sounds.
Certain audio effects can be achieved by using the general time transformation mechanism. For example, both phase shift and rate control can be achieved by time transformations.
import(pathname.[wav | au | aiff]): sound * sound
infix mix: sound * sound -> sound
renderedSound: geometry * microphone -> sound
gain: number -> (sound -> sound)
apply: transform3 * microphone -> microphone
colorRgb: number * number * number -> color
colorHsl: number * number * number -> color
redComponent: color -> number
greenComponent: color -> number
blueComponent: color -> number
hueComponent: color -> number
saturationComponent: color -> number
lightnessComponent: color -> number
Escape Code Result \n Newline \t Tab \’ Apostrophe \" Quote \\ Backslash \integer The ASCII character with this value
ord: char -> number
chr: number -> char
infix &: string * string -> string
implode: char list -> string
explode: string -> char list
numberToString: number * number -> string
simpleText: string -> text
textScale: number -> (text -> text)
textColor: color -> (text -> text)
textFamily: fontFamily -> (text -> text)
bold: text -> text
italic: text -> text
renderedImage: text -> image * vector
The resultant image is transparent in all places other than where the text is actually rendered.
There are explicitly no alignment operators (align left, right, center, etc.), as these can be achieved by transformation of the resultant image.
Type Derivative number number point2 vector2 vector2 vector2 point3 vector3 vector3 vector3 derivative: T -> DT integral: DT -> DTNote that the derivative of a point is a vector, but the integral of a vector is a vector.
blendLinear: T * T * number -> T
leftButtonPress: unit event
leftButtonRelease: unit event
rightButtonPress: unit event
rightButtonRelease: unit event
keyDown: character -> boolean
keyPress: character event
keyRelease: character event
Occlusion is taken into account. That is, probing rays do not pass through one nontransparent image and into another image, or through one nontransparent geometry into another.
For a 2D probe, consider the following:
probe: image -> (point2 * vector2) event
The specified image is interpreted as being in local coordinates. The returned event data consists of pointPicked and offset,where pointPicked is the static point on the image that was picked, in local coordinates (local to the image), and offset is the 2D vector-valued behavior that tracks the probe as it moves relative to the picked point (also in coordinates local to the specified image).
For a 3D probe, consider the following:
probe: geometry -> (point3 * vector3) event
Similar to the 2D case, the event produces a static point on the geometry where the pick occurred and a vector-valued behavior that tracks the probe as it moves relative to this point. Both return values are local to the specified geometry.
pattern = expression
The general syntax for a function declaration is as follows:
identifier pattern = expression
Patterns may be used to destructure values and specify bindings for (potentially) more than one identifier. Patterns are denoted in one of the following forms:
The following are a few example declarations:
x = 3
(x, y) = (4, 17)
(x, y) = p
(x, y) = 3
f() = 5
g(x) = x + 1
h(x, y) = x + y
k(x, y, z) = x + y / z
(int, (int, int))
An application of k could look like k(1, 2, 3), k(1, (2, 3)), k(1, p) where p is a pair, or k(t) where t is a triple of type int*int*int. The application k((1,2),3) will report an error.
Pattern matching can also be used to specify the formals for a function expression. The following is an anonymous addition function:
function (x, y). x + y
And, this function returns the first element of a pair:
function (x, y). x
ActiveVRML 1.0 models should contain the following comment as their first source line:
// ActiveVRML 1.0 ASCII
An ActiveVRML model consists of a list of top-level declarations.
An external entry point will be a declaration with type geometry or image*sound*sound. These are the only behaviors that may be indexed from a uniform resource locator (URL). The former will cause the browser to enable a 3D navigational user interface to allow the user to navigate the geometry, and have the embedded sounds rendered (played). The latter form allows the creator of the model to use their own camera, and to directly specify the sounds to play to the left and right speakers.
This will create an active link to the model myModel in the file model.av on the server www.microsoft.com. The entry point for the model, mainEntry, must be type geometry or image*sound*sound. The former is for geometries that will use the default camera from the view (including embedded sound). The latter is for images with stereo sound.
When the user clicks the URL, an ActiveVRML 1.0 capable viewer will begin executing the ActiveVRML (at local time 0).
It is also possible to embed an ActiveVRML model within an HTML page. To do so, use the following syntax:
<embed clsid=ActiveVRML.ActiveVRMLView1 width=300 height=300 props="URL=http://www.microsoft.com/model.av#mainEntry">
This instructs the viewer to display the model in a window within the HTML page. The height and width are specified in pixels to be consistent with other embedded types in HTML.
hyperlink3: string -> (geometry -> geometry) hyperlink2: string -> (image -> image)
These act as attributers for geometries and images. For example:
im2 = hyperlink2("http://www.microsoft.com")(im1)
The variable im2 is now an image that when selected will be noticed by the browser, causing a jump to the specified URL. Note that the URL can be any valid web content type, not just ActiveVRML.
The resolution of the view in pixels per meter. In general, this number will be an approximation, as, among other things, monitor size varies.
The dimensions of the view in meters. This will be an approximation of the display dimensions.
/* This is a comment. */ // This is a comment.where the first form encloses any characters up to the first */ pattern and the latter form ignores everything until the end of line. Nested comments are handled correctly.
and else event function if import in let list mix not o or over then union until
Operator Associativity -> Right * (product type) Left list event Non Associative , (comma) Right .(dot in function) else in Non Associative until Right | (or event) Left => (event handler) Left o union over mix Left :: (list cons) Right or Left and Left not Non Associative = < <= > >= <> Left + - (binary) & Left * / Left ^ Right + - (unary) Non Associative : (type qualification) Non Associative
program: declarations | epsilon declarations: declaration | declaration ; | declaration ; declarations declaration: pattern = commaexpression | identifier pattern = commaexpression pattern: () | identifier | pattern , pattern | (pattern) | pattern: typeexp expressionlist: nonemptyexpressionlist | epsilon nonemptyexpressionlist: expression , nonemptyexpressionlist | expression commaexpression: expression , commaexpression | expression expression: if expression then expression else expression | let declarations in expression | function pattern . expression | expression binaryoperator expression | unaryoperator expression | applyterm binaryoperator: + | - | * | / | ^ | = | > | >= | < | <= |:: | & | and | or | until | | | union | over | mix | o unaryoperator: + | - | not applyterm: applyterm term | term term: numberliteral | characterliteral | stringliteral | identifier | () | (commaexpression ) | [ expressionlist] | term: typeexp typeexp: typeidentifier | identifier | typeexp * typeexp | typeexp -> typeexp | typeexp identifier | (typeexp) epsilon: /* empty */