This WebSharper™ Extension provides a set of classes and functions almost identical to the ones documented in the O3D API, version 20100829. When used in WebSharper™ projects, these stub classes delegate the work to the actual classes implemented by the browser.
After adding the reference to the project all the classes can be found
The standard distribution of O3DJS requires you to use the function
o3djs.require to include the functionality you need, and to set
o3djs.base.o3d object. This extension, however, includes a
minified version of the complete O3D and O3DJS source and sets
o3djs.base.o3d. Therefore, the only initialization code needed
is the following:
1 2 3 4 5 6 7 8 9
O3D manipulates vectors and quaternions as arrays of numbers, and matrices as arrays of arrays. This implies that it uses the same functions to manipulate all data sizes. This allows for some hard-to-debug errors such as taking the dot-product of two vectors of different sizes.
some extra safety by manipulating mathematical data as tuples. All
functions in the module
O3DJS.Math are overloaded to accept tuples
as arguments. They also have overloads accepting arrays, if you need
to work without this added safety, for example if you need to multiply
Moreover, we also use F#'s support for function overloading to shorten
distinguish between eg.
therefore both are merged in a single
Math.Add function with
As an example, the following code from the Pool sample:
1 2 3 4 5
var Vr = o3djs.math.subVector( o3djs.math.addVector(o3djs.math.cross(w2, r2), v2), o3djs.math.addVector(o3djs.math.cross(w1, r1), v1)); var Vrn = o3djs.math.mulScalarVector(o3djs.math.dot(Vn, N), N); var Vrt = o3djs.math.subVector(Vr, Vrn);
is translated into WebSharper as:
1 2 3 4 5
let Vr = O3DJS.Math.Sub( O3DJS.Math.Add(O3DJS.Math.Cross(w2, r2), v2), O3DJS.Math.Add(O3DJS.Math.Cross(w1, r1), v1)) let Vrn = O3DJS.Math.Mul(O3DJS.Math.Dot(Vn, N), N) let Vrt = O3DJS.Math.Sub(Vr, Vrn)
In O3D, the methods
ParamObject.createParam return an object whose type depends on the
argument passed. This is not suitable for use in F#. Therefore, these
methods have been translated into series of individual methods, each
of which handles one of the possible return types.
1 2 3
var transform = pack.createObject('Transform'); transform.parent = root; var myParam = transform.createParam('objectCenter', 'ParamFloat2');
1 2 3
let transform = pack.CreateTransform() transform.Parent <- root let myParam = transform.CreateParamFloat2 "objectCenter"
ParamFloat2. In WebSharper, we
use a parameterized type: the type of
Param<float * float>.
Note also that you can use property assignment to shorten the construction
transform into a single line:
let transform = pack.CreateTransform(Parent = root) let myParam = transform.CreateParamFloat2 "objectCenter"