Class: WorldManager

WorldManager(world, fps)

Manages world events: tracks local user events and sends them to the server, and tracks network events and applies them to local scene. Loads avatars of other users and maps network events to their avatars, including user video and audio streams.

Constructor

new WorldManager(world, fps)

Creates world manager with default values and connection, scene, camera listeners.
Parameters:
Name Type Description
world
fps network framerate, default 5 (send up to 5 events per second)
Source:

Classes

WorldManager

Members

avatarFactory

Avatar factory, default this.createAvatar
Source:

changeListeners

Change listeners receive changes applied to all shared objects
Source:

createAnimations

Create animations for movement of avatars, default true. Recommended for low fps.
Source:

customAnimations

Custom avatar animations
Source:

customOptions

Custom avatar options, applied to avatars after loading. Currently video avatars only
Source:

debug

Enable debug output
Source:

defaultPosition

Default position applied after an avatar loads
Source:

defaultRotation

Default rotation applied after an avatar loads
Source:

fps

Network frames per second, default 5
Source:

leftArmPos

Current left arm position
Source:

leftArmRot

Current left arm rotation
Source:

loadCallback

Optionally called after an avatar has loaded. Callback is passed VRObject and avatar object as parameters. Avatar object can be either Avatar or VideoAvatar instance, or an AssetContainer.
Source:

loadErrorHandler

Called when loading fails, default null.
Source:

mediaStreams

This is set once we connect to streaming server
Source:

myChangeListeners

Listeners notified after own avatar property (e.g. position) has changed and published
Source:

pos

Current position
Source:

remoteLogging

Mobile browsers don't have javascript console, and USB debugging is next to useless. Enable to redirect all console output to the server log. Sure, it starts only after connection to the server is established.
Source:

resolution

Movement resolution, default 1 cm/3.6 deg. Any movement less than this will be ignored.
Source:

rightArmPos

Current right arm position
Source:

rightArmRot

Current right arm rotation
Source:

rot

Current rotation
Source:

scene

the scene
Source:

tokens

client tokens
Source:

trackedMesh

In 3rd person view, we're not tracking and publishing position and orientation camera, but of this mesh
Source:

trackRotation

Whether to track user rotation, default true.
Source:

userHeight

User height in real world, default 1.8
Source:

world

the world
Source:

Methods

(static) myId()

Returns VRSPACE.me if available, null otherwise
Source:

addChangeListener()

Add a listener to remote events
Source:

addMyChangeListener()

Add a listener to own events
Source:

bBoxMax()

Utility method, calculates bounding box for an AssetContainer and returns maximum of x,y,z. Works only for meshes already rendered
Source:

boundingBox()

Utility method, calculates bounding box for an AssetContainer.
Source:
Returns:
Vector3 bounding box

changeAvatar()

Apply remote changes to an avatar (VRObject listener)
Source:

changeObject()

Apply remote changes to an object.
Source:

checkChange()

Check if a value has changed, and update change array if so.
Source:

createAvatar()

Default video avatar factory method
Source:

(async) createAvatarFromUrl(url)

Creates new Avatar instance from the URL
Parameters:
Name Type Description
url URL to load avatar from
Source:

(async) enter(properties)

Enter the world specified by world.name. If not already connected, first connect to world.serverUrl and set own properties, then start the session. World and WorldListeners are notified by calling entered methods.
Parameters:
Name Type Description
properties own properties to set before starting the session
Source:
Returns:
Welcome promise

(async) enterAs()

Enter the world as avatar. Creates propererties by taking user name, height and avatar url from given Avatar, then calls enter( properties ).
Source:

entered()

Called after user enters a world, calls world.entered() wrapped in try/catch
Source:

(async) enterWith(avatarUrl, userName)

Quick enter, with avatar url and optionally user name.
Parameters:
Name Type Description
avatarUrl URL to load avatar from
userName login name of the user
Source:
Returns:
own Avatar instance

isChanged()

Return true if a value is ouside of given range.
Source:

isOnline()

Returns true if connected to the server and session is active
Source:

(async) loadAvatar(obj)

Load a 3D avatar, attach a listener to it
Parameters:
Name Type Description
obj VRObject that represents the user
Source:

(async) loadMesh()

Load an object and attach a listener.
Source:

loadMeshAvatar()

Any 3d object can be an avatar
Source:

loadScript()

Load a script, call it's constructor with the VRObject, then calls init(), and adds the listener. See basic-script.js and web-portal.js.
Source:

loadStream()

Load a video avatar, attach a listener to it.
Source:

log()

Optionally log something
Source:

notifyListeners()

Notify listeners of remote changes
Source:

publishChanges(changes)

Publish changes to the server (if online) and local change listeners
Parameters:
Name Type Description
changes array of objects with field-value pairs
Source:

pubSub(user, autoPublishVideo)

Publish and subscribe
Parameters:
Name Type Description
user Client Client object of the local user
autoPublishVideo boolean should webcam video be published as soon as possible
Source:

removeChangeListener()

Remove listener to remote events
Source:

removeMyChangeListener()

Remove listener to own events
Source:

removeObject()

Remove an object: remove the mesh from the scene (scene listener), and dispose of everything.
Source:

routeEvent(obj, field)

Called when applying changes other than rotation and translation: executes a method if such a method exists, passing it a current instance of associated VRObject.
Parameters:
Name Type Description
obj VRObject to apply change to
field member field to set or method to execute
Source:

sceneChanged(e)

Called when scene has changed (scene listener). If an object was added, calls either loadAvatar, loadStream or loadMesh, as appropriate. If an object was removed, calls removeObject. Any WorldListeners on the world are notified after changes are performed, by calling added and removed methods.
Parameters:
Name Type Description
e SceneEvent containing the change
Source:

sendMy(obj)

Send own event.
Parameters:
Name Type Description
obj object containing changes to be sent, i.e. name-value pair(s).
Source:

setSessionStatus()

Called when connection to the server is established (connection listener)
Source:

trackCamera()

Tracks active camera
Source:

trackChanges()

Periodically executed, as specified by fps. Tracks changes to camera and XR controllers. Calls checkChange, and if anything has changed, changes are sent to server, and to myChangeListeners.
Source:

trackMesh()

Track a mesh, used in 3rd person view
Source:

write()

Local user wrote something - send it over and notify local listener(s)
Source: