Class: World

(abstract) World(params)

Basic world, intended to be overridden. Provides function placeholders for implementations, and safe implementation of basic functions, like loading of world file(s) and XR support. A world may contain one or more scene files. Defaults are set for one file loaded from scene.gltf file, as it is, from current directory. To load multiple files, use this.worldObjects structure or objectsFile file, that along the name allow to specifiy position, rotation and scale for each object. (the structure is the same one that is also used by AssetLoader and WorldEditor)

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

World

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:

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:

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:

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) dispose()

Disposes of all objects returned by createLights, createCamera, createShadows, createSkybox
Source:

(async) entered()

Optional, empty implementation, notification that the user has entered a multiuser world.
Source:

getFloorMeshes()

Returns this.floorMeshes or this.ground if exist, or empty array.
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.
Parameters:
Name Type Description
vrHelper optional existing vrHelper
Source:

isSelectableMesh()

Used in mesh selection predicate. 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:

setMeshCollisions(mesh, state)

Enable or disable collisions for a mesh. Override to fine-tune collisions.
Parameters:
Name Type Description
mesh
state
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: