Class: World

(abstract) World()

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. There is no constructor, so subclasses are free to add any world specifics to their own constructors. A world can also define defaults in the constructor, like baseUrl or file.

Constructor

(abstract) new World()

Source:

Classes

World

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 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 ""
file scene file to load, default scene.gltf
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:

load(callback)

Load the world, then execute given callback passing self as argument. Loads an AssetContainer, and adds it to the scene. Takes care of loading progress. Calls loadingStart, loaded, loadingStop, collisions, optimizeScene - each may be overridden.
Parameters:
Name Type Description
callback to execute after the content has loaded
Source:

(async) loadAsset(relativePath, file, scene)

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
scene
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:

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:

optimizeScene()

Optimize the scene
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: