o3d.Client Class Reference
List of all members.
Detailed Description
The Client class is the main point of entry to O3D. It defines methods
for creating and deleting packs. Each new object created by the Client is
assigned a unique ID.
The Client has a root transform for the transform graph and a root render
node for the render graph.
Public Types
Public Member Functions
Public Properties
Public Types Documentation
| enum o3d.Client.RenderMode |
RENDERMODE_CONTINUOUS, Draw as often as possible up to refresh rate.
RENDERMODE_ON_DEMAND, Draw once then only when the OS requests it
(like uncovering part of a window.)
Member Function Documentation
| Client.cancelFullscreenDisplay |
( |
|
|
) |
|
Cancels full-screen display, reverting to displaying content only in the
plugin region. If the plugin is already not in full-screen mode, this has
no effect. This does not deactivate the plugin click region--if the user
clicks there again, we'll go back to full-screen display.
Call this function from window.onunload to ensure the browser does not
continue to call callbacks (like the render callback) after the page is
unloaded. It is possible that during unload the browser unloads all the
javascript code, but then, after that, still asks the plugin to render. The
browser then calls javascript functions that no longer exist which causes an
error. To prevent that situation you need to clear all your callbacks on
unload. cleanup handles that for you so you don't have to dispose each and
every callback by hand.
| Client.clearErrorCallback |
( |
|
|
) |
|
Clears the Error callback
NOTE: The client takes ownership of the ErrorCallback you
pass in. It will be deleted if you call SetErrorCallback a second
time or if you call ClearErrorCallback.
| Client.clearEventCallback |
( |
string |
type |
) |
|
Removes the previously-registered callback for an event of the given type.
- Parameters:
-
| type |
Type of event to clear callback for. |
| Client.clearFullscreenClickRegion |
( |
|
|
) |
|
Deactivates the plugin click region that was previously created with
SetFullscreenClickRegion().
| Client.clearLastError |
( |
|
|
) |
|
Clears the error returned in lastError.
| Client.clearLostResourcesCallback |
( |
|
|
) |
|
Clears the lost resources callback.
| Client.clearPostRenderCallback |
( |
|
|
) |
|
Clears the post render callback.
| Client.clearRenderCallback |
( |
|
|
) |
|
Clears the per frame render callback.
| Client.clearTickCallback |
( |
|
|
) |
|
Clears the tick callback
NOTE: The client takes ownership of the TickCallback you
pass in. It will be deleted if you call SetTickCallback a second
time or if you call ClearTickCallback
Creates a pack object.
- Returns:
-
!o3d.Pack.A pack object.
| Client.getDisplayModes |
( |
|
|
) |
|
Returns an array of DisplayModes which are available for use in full-screen
mode.
- Returns:
-
!Array.<!o3d.DisplayMode>.An array of DisplayModes.
| Client.getMessageQueueAddress |
( |
|
|
) |
|
Returns the socket address of the IMC message queue associated with the
Client.
- Returns:
-
string.The socket address.
Searches the Client for an object matching the given id.
- Parameters:
-
| id |
The id of the object to look for. |
- Returns:
-
o3d.ObjectBase.The object or null if a object with the given id is not found.
| !Array.<!o3d.ObjectBase> Client.getObjects |
( |
string |
name |
|
|
|
|
string |
className |
) |
|
Searches the Client for objects of a particular name and type.
- Parameters:
-
| name |
name of object to look for. |
| className |
name of class to look for. |
- Returns:
-
!Array.<!o3d.ObjectBase>.Array of objects found.
| !Array.<!o3d.ObjectBase> Client.getObjectsByClassName |
( |
string |
className |
) |
|
Searches the Client for objects of a particular type.
- Parameters:
-
| className |
name of class to look for. |
- Returns:
-
!Array.<!o3d.ObjectBase>.Array of objects found.
| Client.invalidateAllParameters |
( |
|
|
) |
|
Makes all parameters get re-evaluated.
Resets the profiling information.
| Client.profileToString |
( |
|
|
) |
|
Returns the profiling information as a string.
- Returns:
-
string.The profiling info.
Forces a render of the current scene if the current render mode is
RENDERMODE_ON_DEMAND.
Renders a render graph.
Normally the client calls this function automatically for you effectively
doing a client.renderTree(client.renderGraphRoot) but there are cases
where it is beneficial to be able to call this yourself and pass it
different roots when you need to manipulate something between calls.
This function can only be called from inside a render callback. If you call
it the client will not do its default call as mentioned above.
- Parameters:
-
| renderNode |
root RenderNode to start rendering from. |
| Client.setErrorCallback |
( |
function(string): void |
errorCallback |
) |
|
Sets a callback for when the client gets an error. For example when a shader
is compiled and there is an error or if you attempt to bind a param to a
param of an incompatible type.
NOTE: The client takes ownership of the ErrorCallback you
pass in. It will be deleted if you call SetErrorCallback a
second time or if you call ClearErrorCallback.
NOTE: The callback will not be called recursively. If you are in a
callback, and do something that causes another error before you have
returned from the callback, your callback will not be called a second time.
NOTE: If you put up an alert in response to an error it is best if you
clear the error callback before you put up the alert. Otherwise you'll get
an alert everytime the client tries to render which is every time you close
the current alert which means you'll be in an infinite loop of alerts.
- Parameters:
-
| errorCallback |
ErrorCallback to call when the Client gets an error. |
Sets the texture to use when a Texture or Sampler is missing while
rendering. The default is a red texture with a yellow no symbol.
Ø.
If you set it to null you'll get an error if you try to render something
that is missing a needed Texture, Sampler or ParamSampler.
For example if you don't care about missing textures, setting it to a black
texture would be one option. Another example is if you want to write all
your shaders to expect a texture then set this to a white texture. If you
want to make sure you are not missing any textures set it null and see if
you get any errors using Client.setErrorCallback or Client.lastError.
// Set the error texture to black.
var t = g_pack.createTexture2D('', 1, 1, g_o3d.Texture.XRGB8, 1);
t.set(0, [0, 0, 0]);
g_client.setErrorTexture(t);
- Parameters:
-
| texture |
texture to use for missing textures or null. |
| Client.setEventCallback |
( |
string |
type |
|
|
|
|
function(!o3d.Event): void |
handler |
) |
|
Sets a callback for a given event type.
types.
There can be only one callback for a given event type at a time; setting a
new one deletes the old one.
- Parameters:
-
| type |
Type of event to set callback for. |
| handler |
Function to call on event. |
See Also:
| Client.setFullscreenClickRegion |
( |
number |
x |
|
|
|
|
number |
y |
|
|
|
|
number |
width |
|
|
|
|
number |
height |
|
|
|
|
number |
modeId |
) |
|
Makes a region of the plugin area that will invoke full-screen mode if
clicked. The developer is responsible for communicating this to the user,
as this region has no visible marker. The developer is also responsible for
updating this region if the plugin gets resized, as we don't know whether or
how to scale it. There can be only one full-screen click region at a time;
calling this again will override any previous call.
- Parameters:
-
| x |
x position in pixels. |
| y |
y position in pixels. |
| width |
width in pixels. |
| height |
height in pixels. |
| modeId |
Id of mode to use. |
| Client.setLostResourcesCallback |
( |
function(): void |
lostResourcesCallback |
) |
|
Sets the lost resources callback.
The contents of certain resources, RenderSurfaces, can get discarded by the
system under certain circumstances. If you application needs that contents
to be in a certain state then you can set a callback giving your program the
opportunity to restore that state if and when it is lost.
- Parameters:
-
| lostResourcesCallback |
The callback when resources are lost. |
| Client.setPostRenderCallback |
( |
function(!o3d.RenderEvent): void |
postRenderCallback |
) |
|
Sets a render callback to be called at the end of the
rendering cycle of each frame.
Note: The callback will not be called recursively. When your callback is
called if you somehow manage to cause the client to render more frames
before you've returned from the callback you will not be called for those
frames.
g_client.setPostRenderCallback(onpostrender);
function onpostrender(render_event) {
var elapsedTime = render_event.elapsedTime;
// elapsedTime is the time elasped since the last callback.
// You can use this value to make your application frame rate independent.
// For example:
// position = position + velocity_in_units_per_second * elapsedTime;
}
- Parameters:
-
| postRenderCallback |
The callback to call each frame. |
| Client.setRenderCallback |
( |
function(!o3d.RenderEvent): void |
renderCallback |
) |
|
Sets the per frame render callback.
Note: The callback will not be called recursively. When your callback is
called if you somehow manage to cause the client to render more frames
before you've returned from the callback you will not be called for those
frames.
g_client.setRenderCallback(onrender);
function onrender(render_event) {
var elapsedTime = render_event.elapsedTime;
// elapsedTime is the time elasped since the last callback.
// You can use this value to make your application frame rate independent.
// For example:
// position = position + velocity_in_units_per_second * elapsedTime;
}
- Parameters:
-
| renderCallback |
The callback to call each frame. |
| Client.setTickCallback |
( |
function(!o3d.TickEvent): void |
tickCallback |
) |
|
Sets a callback for when the client ticks. The client processes some things
like animation timers at up to 100hz. This callback will get called before
each of those process ticks.
NOTE: The client takes ownership of the TickCallback you
pass in. It will be deleted if you call SetTickCallback a
second time or if you call ClearTickCallback.
Note: The callback will not be called recursively.
- Parameters:
-
| tickCallback |
TickCallback to call when the Client ticks. |
| string Client.toDataURL |
( |
string |
opt_param1 |
) |
|
Gets a copy of the current backbuffer of O3D as a data: url.
NOTE: Calling it will cause a render to happen.
- Parameters:
-
| opt_param1 |
The type of data url you want. Currently O3D only supports
image/png. See HTML5 canvas tag for info about toDataURL. |
- Returns:
-
string.A Data URL for the backbuffer.
Member Property Documentation
A unique id for this client.
This property is read-only.
Gets info about the client.
This property is read-only.
Gets / Sets the cursor's shape.
Default = DEFAULT.
| boolean Client.fullscreen
|
Whether content is displayed in full-screen mode or in a plugin window. The
default is false [not full-screen].
This property is read-only.
Returns the height of the current drawing area [plugin or full-screen] in
pixels.
This property is read-only.
The last error reported by the plugin.
This property is read-only.
All the objects managed by this client.
Each access to this field gets the entire list so it is best to get it
just once. For example:
var objects = client.objects;
for (var i = 0; i < objects.length; i++) {
var object = objects[i];
}
Note that modifications to this array [e.g. push()] will not affect
the underlying Client, while modifications to the array's members
will affect them.
This property is read-only.
Returns the status of initializing the renderer so we can display the
appropriate message. We require a certain minimum set of graphics
capabilities. If the user's computer does not have his minimum
set this will be GPU_NOT_UP_TO_SPEC. If the user is out of graphics
resources this will be OUT_OF_RESOURCES. If some other error happened this
will be INITIALIZATION_ERROR. Otherwise it will be SUCCESS.
This property is read-only.
The root of the render graph.
This property is read-only.
The current render mode. The default mode is RENDERMODE_CONTINUOUS.\n
Valid values are:
- RENDERMODE_CONTINUOUS, Draw as often as possible up to refresh rate.
- RENDERMODE_ON_DEMAND, Draw when the OS requests it (like uncovering
part of a window.)
The transform graph root Transform
This property is read-only.
Returns the width of the current drawing area [plugin or full-screen] in
pixels.
This property is read-only.
|