Skip to content

@fibbojs / 3d / FScene

Class: FScene

A scene which contains the models, the Three.js scene and the Rapier world.

Example

ts
import { FCuboid, FGameCamera, FScene } from '@fibbojs/3d'

(async () => {
  // Initialize the scene
  const scene = new FScene()
  scene.init()
  await scene.initPhysics()

  // Create a ground
  const ground = new FCuboid(scene)
  ground.setScale(15, 0.1, 15)
  ground.setPosition(0, -0.1, 0)
  ground.initCollider()
  ground.setColor(0x1F1F1F)
  scene.addComponent(ground)

  // Create a cube
  const cube = new FCuboid(scene)
  cube.initRigidBody()
  scene.addComponent(cube)

  // Attach a camera to the cube
  scene.camera = new FGameCamera(cube)
})()

Extends

  • FScene

Constructors

new FScene()

new FScene(options?): FScene

Parameters

options?: FSceneOptions

Returns

FScene

Overrides

FSceneCore.constructor

Defined in

3d/src/core/FScene.ts:71

Methods

addComponent()

addComponent(component): void

Add a component to the scene.

Parameters

component: FComponent

Returns

void

Overrides

FSceneCore.addComponent

Defined in

3d/src/core/FScene.ts:183


addLight()

addLight(light): void

Add a light to the scene.

Parameters

light: FLight

Returns

void

Overrides

FSceneCore.addLight

Defined in

3d/src/core/FScene.ts:236


handleCollision()

handleCollision(handle1, handle2, start): void

Handle a collision event between two colliders.

Parameters

handle1: number

The handle of the first collider

handle2: number

The handle of the second collider

start: boolean

If the collision has started or ended

Returns

void

Defined in

3d/src/core/FScene.ts:159


init()

init(): void

Returns

void

Defined in

3d/src/core/FScene.ts:95


initPhysics()

initPhysics(): Promise<void>

Returns

Promise<void>

Defined in

3d/src/core/FScene.ts:130


onComponentAdded()

onComponentAdded(callback): void

Add a callback to be called when a component is added to the scene.

Parameters

callback

Returns

void

Inherited from

FSceneCore.onComponentAdded

Defined in

core/dist/index.d.ts:269


onComponentRemoved()

onComponentRemoved(callback): void

Add a callback to be called when a component is removed from the scene.

Parameters

callback

Returns

void

Inherited from

FSceneCore.onComponentRemoved

Defined in

core/dist/index.d.ts:273


onFrame()

onFrame(callback): void

Add a callback to be called when a frame is rendered.

Parameters

callback

Returns

void

Inherited from

FSceneCore.onFrame

Defined in

core/dist/index.d.ts:265


onLightAdded()

onLightAdded(callback): void

Add a callback to be called when a light is added to the scene.

Parameters

callback

Returns

void

Inherited from

FSceneCore.onLightAdded

Defined in

core/dist/index.d.ts:282


onLightRemoved()

onLightRemoved(callback): void

Add a callback to be called when a light is removed from the scene.

Parameters

callback

Returns

void

Inherited from

FSceneCore.onLightRemoved

Defined in

core/dist/index.d.ts:286


onReady()

onReady(callback): void

Add a callback to be called when the scene is ready. The scene is ready when the init method has finished.

Parameters

callback

Returns

void

Inherited from

FSceneCore.onReady

Defined in

core/dist/index.d.ts:278


removeComponent()

removeComponent(component): void

Remove a component from the scene.

Parameters

component: FComponent

Returns

void

Overrides

FSceneCore.removeComponent

Defined in

3d/src/core/FScene.ts:214


removeLight()

removeLight(light): void

Remove a light from the scene.

Parameters

light: FLight

Returns

void

Overrides

FSceneCore.removeLight

Defined in

3d/src/core/FScene.ts:243

Properties

THREE

THREE: __module

Defined in

3d/src/core/FScene.ts:60


__CALLBACKS_ON_COMPONENT_ADDED__

__CALLBACKS_ON_COMPONENT_ADDED__: (component) => void[]

Callbacks for when a component is added to the scene. It is an array of functions that take the component as an argument.

Inherited from

FSceneCore.__CALLBACKS_ON_COMPONENT_ADDED__

Defined in

core/dist/index.d.ts:225


__CALLBACKS_ON_COMPONENT_REMOVED__

__CALLBACKS_ON_COMPONENT_REMOVED__: (component) => void[]

Callbacks for when a component is remove from the scene. It is an array of functions that take the component as an argument.

Inherited from

FSceneCore.__CALLBACKS_ON_COMPONENT_REMOVED__

Defined in

core/dist/index.d.ts:230


__CALLBACKS_ON_FRAME__

__CALLBACKS_ON_FRAME__: (delta) => void[]

Callbacks for when a frame is rendered. It is an array of functions that take the delta time as an argument.

Inherited from

FSceneCore.__CALLBACKS_ON_FRAME__

Defined in

core/dist/index.d.ts:220


__CALLBACKS_ON_LIGHT_ADDED__

__CALLBACKS_ON_LIGHT_ADDED__: (light) => void[]

Callbacks for when a light is added to the scene. It is an array of functions that take the light as an argument.

Inherited from

FSceneCore.__CALLBACKS_ON_LIGHT_ADDED__

Defined in

core/dist/index.d.ts:239


__CALLBACKS_ON_LIGHT_REMOVED__

__CALLBACKS_ON_LIGHT_REMOVED__: (light) => void[]

Callbacks for when a light is added to the scene. It is an array of functions that take the light as an argument.

Inherited from

FSceneCore.__CALLBACKS_ON_LIGHT_REMOVED__

Defined in

core/dist/index.d.ts:244


__CALLBACKS_ON_READY__

__CALLBACKS_ON_READY__: () => void[]

Callbacks for when the scene is ready.

Inherited from

FSceneCore.__CALLBACKS_ON_READY__

Defined in

core/dist/index.d.ts:234


__DOM_NODE__

__DOM_NODE__: HTMLElement

DOM element that the renderer will be appended to

Inherited from

FSceneCore.__DOM_NODE__

Defined in

core/dist/index.d.ts:196


__ENABLE_SHADOWS__

__ENABLE_SHADOWS__: boolean

Defined in

3d/src/core/FScene.ts:52


__IS_2D__

__IS_2D__: boolean

Inherited from

FSceneCore.__IS_2D__

Defined in

core/dist/index.d.ts:192


__IS_3D__

__IS_3D__: boolean = true

Internal flags

Overrides

FSceneCore.__IS_3D__

Defined in

3d/src/core/FScene.ts:51


__RAPIER_TO_COMPONENT__

__RAPIER_TO_COMPONENT__: Map<number, FComponent>

Overrides

FSceneCore.__RAPIER_TO_COMPONENT__

Defined in

3d/src/core/FScene.ts:69


camera

camera: FCamera

Defined in

3d/src/core/FScene.ts:63


components

components: FComponent[]

The components in the scene.

Overrides

FSceneCore.components

Defined in

3d/src/core/FScene.ts:55


eventQueue

eventQueue: EventQueue

Overrides

FSceneCore.eventQueue

Defined in

3d/src/core/FScene.ts:68


gravity

gravity: object

x

x: number

y

y: number

z

z: number

Overrides

FSceneCore.gravity

Defined in

3d/src/core/FScene.ts:66


lights

lights: FLight[]

The lights in the scene.

Overrides

FSceneCore.lights

Defined in

3d/src/core/FScene.ts:57


renderer

renderer: WebGLRenderer

Defined in

3d/src/core/FScene.ts:62


scene

scene: Scene

Defined in

3d/src/core/FScene.ts:61


world

world: World

Overrides

FSceneCore.world

Defined in

3d/src/core/FScene.ts:67