Skip to content

editorGlobalsBackgroundParts

Class: BackgroundParts

Helper class that can load and store parts (THREE objects, config, physics engine bodys) of a certain background ToDo: assetize background (load everything from an asset), see general-issues#791

Hierarchy

  • BackgroundParts

Index

Constructors

Properties

Methods

Constructors

constructor

+ new BackgroundParts(backgroundName: string, physicsScaleFactor: number, physicsContext: PhysicsContext): BackgroundParts

Defined in src/renderContext/BackgroundParts.ts:121

Parameters:

Name Type Default Description
backgroundName string - The folder name for the background assets to load
physicsScaleFactor number - -
physicsContext PhysicsContext null -

Returns: BackgroundParts

Properties

Private allowDynamicWalls

allowDynamicWalls: boolean = true

Defined in src/renderContext/BackgroundParts.ts:118


Private Readonly backgroundName

backgroundName: string

Defined in src/renderContext/BackgroundParts.ts:101


Private Readonly dynamicWalls

dynamicWalls: CANNON.Body[] = []

Defined in src/renderContext/BackgroundParts.ts:106


Private Readonly externalObjectDescriptors

externalObjectDescriptors: ExternalObjectDescriptor[] = []

Defined in src/renderContext/BackgroundParts.ts:105


Private Readonly externalObjects

externalObjects: ExternalObject[] = []

Defined in src/renderContext/BackgroundParts.ts:104


Private Readonly lightContainer

lightContainer: Object3D‹› = (() => { const lightContainer = new Object3D(); lightContainer.name = "lightContainer"; return lightContainer; })()

Defined in src/renderContext/BackgroundParts.ts:107


Private Readonly modelContainer

modelContainer: Object3D‹› = (() => { const modelContainer = new Object3D(); modelContainer.name = "modelContainer"; return modelContainer; })()

Defined in src/renderContext/BackgroundParts.ts:112


Private Readonly physicsBodies

physicsBodies: CANNON.Body[] = []

Defined in src/renderContext/BackgroundParts.ts:103


Private Readonly physicsContext

physicsContext: PhysicsContext

Defined in src/renderContext/BackgroundParts.ts:121


Private Readonly physicsScaleFactor

physicsScaleFactor: number

Defined in src/renderContext/BackgroundParts.ts:120


Private properties

properties: IBackgroundProperties = null

Defined in src/renderContext/BackgroundParts.ts:102

Methods

Private _addDynamicWalls

_addDynamicWalls(camera?: PerspectiveCamera): void

Defined in src/renderContext/BackgroundParts.ts:576

Add all five dynamic walls (left, right, top, front, near)

Parameters:

Name Type
camera? PerspectiveCamera

Returns: void


Private _applyDynamicWalls

_applyDynamicWalls(physicsContext: PhysicsContext): void

Defined in src/renderContext/BackgroundParts.ts:372

Parameters:

Name Type
physicsContext PhysicsContext

Returns: void


Private _applyMaterialToTree

_applyMaterialToTree(object: Mesh, material: Material): void

Defined in src/renderContext/BackgroundParts.ts:357

Applies a material to the object and all its children

Parameters:

Name Type
object Mesh
material Material

Returns: void


Private _calculateNearWallFromCameraPosition

_calculateNearWallFromCameraPosition(camera: PerspectiveCamera): CANNON.Body

Defined in src/renderContext/BackgroundParts.ts:558

Calculate and add the near Wall

Parameters:

Name Type
camera PerspectiveCamera

Returns: CANNON.Body


Private _configureDirectionalLightShadowSize

_configureDirectionalLightShadowSize(directionalLight: DirectionalLight, shadowMapSize: number): void

Defined in src/renderContext/BackgroundParts.ts:505

Configures the specified directional light to cast shadows

Parameters:

Name Type
directionalLight DirectionalLight
shadowMapSize number

Returns: void


Private _createLight

_createLight(lightConfig: LightConfig): Light

Defined in src/renderContext/BackgroundParts.ts:484

Parameters:

Name Type
lightConfig LightConfig

Returns: Light


Private _createPhysicsPlane

_createPhysicsPlane(planePosition: CANNON.Vec3, planeRotation?: Quaternion, margin: number): CANNON.Body

Defined in src/renderContext/BackgroundParts.ts:689

Parameters:

Name Type Default
planePosition CANNON.Vec3 -
planeRotation? Quaternion -
margin number 0

Returns: CANNON.Body


Private _createPlane

_createPlane(camera: PerspectiveCamera, vec1: Vector3, vec2: Vector3, margin: number): CANNON.Body

Defined in src/renderContext/BackgroundParts.ts:531

Calculate plane with camera and two screen points

Parameters:

Name Type
camera PerspectiveCamera
vec1 Vector3
vec2 Vector3
margin number

Returns: CANNON.Body


Private _getAssetPath

_getAssetPath(): string

Defined in src/renderContext/BackgroundParts.ts:368

Returns: string

The full asset path of the current background


Private _getCameraFrustumPoints

_getCameraFrustumPoints(camera: PerspectiveCamera): Vector3[]

Defined in src/renderContext/BackgroundParts.ts:515

Parameters:

Name Type
camera PerspectiveCamera

Returns: Vector3[]

The corners of the passed camera's view frustum


Private _loadExternalObjects

_loadExternalObjects(externalObjectSpecs: any): Array‹Promise‹void››

Defined in src/renderContext/BackgroundParts.ts:384

Loads external objects

Parameters:

Name Type
externalObjectSpecs any

Returns: Array‹Promise‹void››


Private _loadLight

_loadLight(lightConfig: LightConfig): void

Defined in src/renderContext/BackgroundParts.ts:479

Loads an creates an individual light

Parameters:

Name Type Description
lightConfig LightConfig The configuration for the given light

Returns: void


Private _loadLights

_loadLights(lightProperties: LightConfig[]): void

Defined in src/renderContext/BackgroundParts.ts:470

Creates THREE lights and adds them to the scene

Parameters:

Name Type Description
lightProperties LightConfig[] The 'lights' part of the backgroundProperties, array

Returns: void


Private _loadModels

_loadModels(modelNames: string[], modelSettings: IModelSettings): Promise‹void›

Defined in src/renderContext/BackgroundParts.ts:428

Loads models (model + textures)

Parameters:

Name Type Default
modelNames string[] -
modelSettings IModelSettings {}

Returns: Promise‹void›


Private _loadPhysicsObjects

_loadPhysicsObjects(objectsDefinitions: PhysicsObject[]): void

Defined in src/renderContext/BackgroundParts.ts:632

Adds custom objects, e.g the coffeemug to the physics engine

Parameters:

Name Type
objectsDefinitions PhysicsObject[]

Returns: void


Private _loadPhysicsWalls

_loadPhysicsWalls(wallDefinitions: IPhysicsWall[]): void

Defined in src/renderContext/BackgroundParts.ts:598

Add (invisible) walls to the physics engine

Parameters:

Name Type
wallDefinitions IPhysicsWall[]

Returns: void


Private _removeDynamicWalls

_removeDynamicWalls(physicsContext: PhysicsContext): void

Defined in src/renderContext/BackgroundParts.ts:376

Parameters:

Name Type
physicsContext PhysicsContext

Returns: void


apply

apply(threeContainer: Object3D, physicsContext: PhysicsContext): void

Defined in src/renderContext/BackgroundParts.ts:196

Applies the loaded objects to the scene / physics context

Parameters:

Name Type Default
threeContainer Object3D -
physicsContext PhysicsContext null

Returns: void


applyPhysicalObjects

applyPhysicalObjects(compositeModel: CompositeModel): void

Defined in src/renderContext/BackgroundParts.ts:213

Applies loaded physical objects. needs to be done separately, since the composite model may be changed during rendering

Parameters:

Name Type
compositeModel CompositeModel

Returns: void


getLightContainer

getLightContainer(): Object3D

Defined in src/renderContext/BackgroundParts.ts:149

Returns: Object3D


getModelContainer

getModelContainer(): Object3D

Defined in src/renderContext/BackgroundParts.ts:153

Returns: Object3D


getProperties

getProperties(): IBackgroundProperties

Defined in src/renderContext/BackgroundParts.ts:145

Returns: IBackgroundProperties


load

load(): Promise‹void›

Defined in src/renderContext/BackgroundParts.ts:160

Loads and instantiates all needed parts from the server

Returns: Promise‹void›


loadMaterial

loadMaterial(textureUrl: string, isTransparent: boolean, isRepeated: boolean, repeatX: number, repeatY: number): Promise‹MeshPhongMaterial›

Defined in src/renderContext/BackgroundParts.ts:324

Loads a texture and creates a Material with it

Parameters:

Name Type Default
textureUrl string -
isTransparent boolean false
isRepeated boolean false
repeatX number 1
repeatY number 1

Returns: Promise‹MeshPhongMaterial›


loadObj

loadObj(objectUrl: string): Promise‹Object3D›

Defined in src/renderContext/BackgroundParts.ts:350

Loads an obj file into an object (texture needs to be applied manually)

Parameters:

Name Type
objectUrl string

Returns: Promise‹Object3D›


remove

remove(threeContainer: Object3D, physicsContext: PhysicsContext): void

Defined in src/renderContext/BackgroundParts.ts:243

Removes the loaded objects from the scene / physics context

Parameters:

Name Type
threeContainer Object3D
physicsContext PhysicsContext

Returns: void


removePhysicalObjects

removePhysicalObjects(compositeModel: CompositeModel): void

Defined in src/renderContext/BackgroundParts.ts:251

Parameters:

Name Type
compositeModel CompositeModel

Returns: void


resetExternalObjects

resetExternalObjects(): void

Defined in src/renderContext/BackgroundParts.ts:258

Resets position and rotation of the background-specific external objects to their default values

Returns: void


stageSizeHasChanged

stageSizeHasChanged(backgroundObjectContainer: Object3D, camera: PerspectiveCamera): void

Defined in src/renderContext/BackgroundParts.ts:313

Parameters:

Name Type
backgroundObjectContainer Object3D
camera PerspectiveCamera

Returns: void


updateLights

updateLights(camera?: PerspectiveCamera): void

Defined in src/renderContext/BackgroundParts.ts:285

Updates the directional lights in the scene, so that the entire view frustum of the camera is within the directional lights' shadow cameras.

Parameters:

Name Type Description
camera? PerspectiveCamera The camera to use as a reference

Returns: void