Constructor
(abstract) new World(params)
Constructor takes parems that allow to override default values.
Parameters:
Name | Type | Description |
---|---|---|
params |
object to override world defaults - all properties are copied to world properties |
- Source:
Classes
Members
baseUrl
Base URL of related content, default "" (current location)
- Source:
collisionsEnabled
Wheter collisions are enabled, default true
- Source:
file
World scene file name to load, default scene.gltf
- Source:
gravityEnabled
Wheter gravity is enabled, default true
- Source:
indicator
Progress indicator
- Source:
inXR
WebXR mode indicator, set by VRHelper
- Source:
name
World name, default null
- Source:
objectsFile
World objects json file, as saved by WorldEditor and AssetLoader, default null
- Source:
onProgress
Progress indicator functon
- Source:
VRSPACEUI
Handy reference to VRSpaceUI
- Source:
worldListeners
List of world listeners.
WorldManager executes enter(Welcome) method once user enters the world, after World.enter() method.
Methods added(VRObject) and removed(VRObject) are executed whenever scene changes.
- Source:
worldManager
Reference to worldManager, set by WorldManager once that user goes online
- Source:
worldObjects
World objects to load, default null
- Source:
Methods
_collisions(meshes, state)
Utility method, enables or disables collisions on the given set of meshes.
Parameters:
Name | Type | Description |
---|---|---|
meshes |
array of meshes | |
state |
true or false |
- Source:
addSelectionPredicate()
Add a selection predicate. It takes a mesh and returns true if it can be selected by the pointer.
- Source:
assetPath(relativePath)
Utility method, returns baseUrl+relativePath
Parameters:
Name | Type | Description |
---|---|---|
relativePath |
path relative to current world directory |
- Source:
attachControl()
Attach the control to the camera, called from createScene.
- Source:
collisions(state)
Enables or disables collisions in the world. This includes floorMeshes, sceneMeshes, and also applying gravity to camera.
Parameters:
Name | Type | Description |
---|---|---|
state |
true or false |
- Source:
(async) createCamera()
An implementation must override this method and define at least one camera
- Source:
(async) createEffects()
Optional, empty implementation, called from createScene
- Source:
(async) createGround()
Optional, empty implementation, called from createScene. Should return a mesh.
- Source:
(async) createLights()
Optional, empty implementation, called from createScene. May return a Light
- Source:
(async) createPhysics()
Optional, empty implementation, called from createScene
- Source:
(async) createScene()
Called from init.
If the scene does not exist, creates the scene first.
Then calls methods in this order:
createCamera, attachControl, createLights, createShadows, createSkybox, createGround, createEffects, createPhysics.
- Source:
(async) createShadows()
Optional, empty implementation, called from createScene. Should return a ShadowGenerator.
- Source:
(async) createSkyBox()
Optional, empty implementation, called from createScene. Should return a sky Box.
- Source:
(async) createTerrain()
Optional, empty implementation, called from createScene
- Source:
(async) createUI()
Optional, empty implementation, called from createScene
- Source:
(async) dispose()
Disposes of all objects returned by createLights, createCamera, createShadows, createSkybox
- Source:
(async) entered(welcome)
Called by WorldManager after the user has entered a multiuser world.
Default implementation creates a ChatLog and binds it to the HUD, then it registers remoteEvent() method
as a change listener with WorldManager to process remote events.
Note that at this point world geometry may not have been loaded.
Parameters:
Name | Type | Description |
---|---|---|
welcome |
message containing users Client object and array of permanent objects |
- Source:
enterXR()
Called by VR helper after entering XR mode. Default implementation enables virtual keyboard in ChatLog.
- Source:
exitXR()
Called by VR helper after exiting XR. Default implementation turns off ChatLog virtual keyboard.
- Source:
getFloorMeshes()
Returns this.floorMeshes or this.ground if exist, or empty array.
Used for movement in XR.
- Source:
(async) init(engine, name, scene, callback, baseUrl, file)
Create, load and and show the world.
Enables gravity and collisions, then executes createScene method, optionally creates load indicator,
registers render loop, crates terrain, and finally, executes load method. Every method executed can be overridden.
Parameters:
Name | Type | Description |
---|---|---|
engine |
babylonjs engine | |
name |
world name | |
scene |
babylonjs scene, optional | |
callback |
to execute after the world has loaded | |
baseUrl |
folder to load scene from, default "", used only if not defined in constructor | |
file |
scene file to load, default scene.gltf, used only if not defined in constructor |
- Source:
Returns:
final scene
initXR(vrHelper)
Creates a VRHelper if needed, and initializes it with the current world.
Normally called after world is loaded, safe to call elsewhere, or call multiple times.
Parameters:
Name | Type | Description |
---|---|---|
vrHelper |
optional existing vrHelper |
- Source:
isOnline()
Utility method, returns true if the world is online, i.e. the client is connected to the server.
- Source:
isSelectableMesh()
Used in mesh selection predicate in XR. Default implementation returns true for members of this.floorMeshes.
- Source:
(async) load(callback)
Load the world, then execute given callback passing self as argument.
Loads an AssetContainer from file specified by this.file, if any (by default scene.gltf), and adds it to the scene.
Then loads all world objects specified in this.objectsFile or this.worldObjects, if any - file takes precedence.
Takes care of loading progress.
Calls loadingStart, loaded, loadingStop, collisions - each may be overridden.
Parameters:
Name | Type | Description |
---|---|---|
callback |
to execute after the content has loaded |
- Source:
Returns:
world object
(async) loadAsset(relativePath, file)
Utility method to fix the path and load the file, executes LoadAssetContainerAsync.
Parameters:
Name | Type | Description |
---|---|---|
relativePath |
path relative to current world directory | |
file |
file name to load |
- Source:
loaded(file, mesh)
Called after assets are loaded. By default calls initXR().
Subclasses typically override this with some spatial manipulations, e.g. scaling the world.
Subclasses may, but are not required, call super.loaded()
Parameters:
Name | Type | Description |
---|---|---|
file |
world file that has loaded | |
mesh |
root mesh of the world |
- Source:
loadFailed(exception)
Called if loading the world fails. Passes the exception to this.onFailure handler if it exists,
otherwise logs it to the console.
Parameters:
Name | Type | Description |
---|---|---|
exception |
whatever caused loading to fail |
- Source:
loadingStart(name)
Called when loading starts. Calls this.indicator.add if available.
Parameters:
Name | Type | Description |
---|---|---|
name |
- Source:
loadingStop(name)
Called when loading finishes. Calls this.indicator.remove if available.
Parameters:
Name | Type | Description |
---|---|---|
name |
- Source:
loadProgress(evt, name)
Called on loading progress, executes whatever this.onProgress contains, by default LoadProgressListener.
Parameters:
Name | Type | Description |
---|---|---|
evt |
||
name |
- Source:
registerRenderLoop()
Register render loop.
- Source:
remoteEvent(obj, field, node)
Receives a remote event. Default implementation handles only 'wrote' event, and sends it to the ChatLog.
Parameters:
Name | Type | Description |
---|---|---|
obj |
a VRObject that has changed | |
field |
a field that has changed, obj[field] contains the actual value | |
node |
root node in the scene that has received event, may be null |
- Source:
removeSelectionPredicate()
Remove a selection predicate function
- Source:
setMeshCollisions(mesh, state)
Enable or disable collisions for a mesh. Override to fine-tune collisions.
Parameters:
Name | Type | Description |
---|---|---|
mesh |
||
state |
- Source:
trackXrDevices()
Called by VRHelper once XR devices are initialized. Default implementation does nothing.
- Source:
universalCamera(pos, name)
Utility method, creates a UniversalCamera and sets defaults: gravity, collisions, ellipsoid, keys.
Parameters:
Name | Type | Description |
---|---|---|
pos |
Vector3 to position camera at | |
name |
optional camera name, default UniversalCamera |
- Source:
write(text)
Write some text to world chat. Usually text appears above avatar's head and/or in chat log,
but this method only sends own 'wrote' event.
Parameters:
Name | Type | Description |
---|---|---|
text |
something to say |
- Source: