Skip to content

@fibbojs / 3d / FCapsule

Class: FCapsule

A simple capsule model in Fibbo.

Example

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

const scene = new FScene()

const capsule = new FCapsule(scene)
scene.addComponent(capsule)

Extends

Accessors

position

get position(): object

Setters & getters for transform properties

set position(position): void

Parameters

position

position.x: number

position.y: number

position.z: number

Returns

object

x

x: number

y

y: number

z

z: number

Inherited from

FPolyhedron.position

Defined in

3d/src/core/FComponent.ts:407


rotation

get rotation(): object

set rotation(rotation): void

Parameters

rotation

rotation.x: number

rotation.y: number

rotation.z: number

Returns

object

x

x: number

y

y: number

z

z: number

Inherited from

FPolyhedron.rotation

Defined in

3d/src/core/FComponent.ts:439


rotationDegree

get rotationDegree(): object

set rotationDegree(rotationDegree): void

Parameters

rotationDegree

rotationDegree.x: number

rotationDegree.y: number

rotationDegree.z: number

Returns

object

x

x: number

y

y: number

z

z: number

Inherited from

FPolyhedron.rotationDegree

Defined in

3d/src/core/FComponent.ts:471


rotationDegreeX

get rotationDegreeX(): number

set rotationDegreeX(x): void

Parameters

x: number

Returns

number

Inherited from

FPolyhedron.rotationDegreeX

Defined in

3d/src/core/FComponent.ts:483


rotationDegreeY

get rotationDegreeY(): number

set rotationDegreeY(y): void

Parameters

y: number

Returns

number

Inherited from

FPolyhedron.rotationDegreeY

Defined in

3d/src/core/FComponent.ts:491


rotationDegreeZ

get rotationDegreeZ(): number

set rotationDegreeZ(z): void

Parameters

z: number

Returns

number

Inherited from

FPolyhedron.rotationDegreeZ

Defined in

3d/src/core/FComponent.ts:499


rotationX

get rotationX(): number

set rotationX(x): void

Parameters

x: number

Returns

number

Inherited from

FPolyhedron.rotationX

Defined in

3d/src/core/FComponent.ts:447


rotationY

get rotationY(): number

set rotationY(y): void

Parameters

y: number

Returns

number

Inherited from

FPolyhedron.rotationY

Defined in

3d/src/core/FComponent.ts:455


rotationZ

get rotationZ(): number

set rotationZ(z): void

Parameters

z: number

Returns

number

Inherited from

FPolyhedron.rotationZ

Defined in

3d/src/core/FComponent.ts:463


scale

get scale(): object

set scale(scale): void

Parameters

scale

scale.x: number

scale.y: number

scale.z: number

Returns

object

x

x: number

y

y: number

z

z: number

Inherited from

FPolyhedron.scale

Defined in

3d/src/core/FComponent.ts:507


scaleX

get scaleX(): number

set scaleX(x): void

Parameters

x: number

Returns

number

Inherited from

FPolyhedron.scaleX

Defined in

3d/src/core/FComponent.ts:515


scaleY

get scaleY(): number

set scaleY(y): void

Parameters

y: number

Returns

number

Inherited from

FPolyhedron.scaleY

Defined in

3d/src/core/FComponent.ts:523


scaleZ

get scaleZ(): number

set scaleZ(z): void

Parameters

z: number

Returns

number

Inherited from

FPolyhedron.scaleZ

Defined in

3d/src/core/FComponent.ts:531


x

get x(): number

set x(x): void

Parameters

x: number

Returns

number

Inherited from

FPolyhedron.x

Defined in

3d/src/core/FComponent.ts:415


y

get y(): number

set y(y): void

Parameters

y: number

Returns

number

Inherited from

FPolyhedron.y

Defined in

3d/src/core/FComponent.ts:423


z

get z(): number

set z(z): void

Parameters

z: number

Returns

number

Inherited from

FPolyhedron.z

Defined in

3d/src/core/FComponent.ts:431

Constructors

new FCapsule()

new FCapsule(scene, options?): FCapsule

Parameters

scene: FScene

options?: FComponentOptions

Returns

FCapsule

Overrides

FPolyhedron.constructor

Defined in

3d/src/polyhedrons/FCapsule.ts:23

Methods

emitCollisionWith()

emitCollisionWith(options): void

Emit a collision event with a given class or object.

Parameters

options

The options for the collision event.

options.class?: any

The class to emit the collision event with.

options.component?: FComponent

The component to emit the collision event with.

Returns

void

Examples

typescript
const player = new Player()
const enemy = new Enemy()
player.emitCollisionWith({
  class: Enemy
})
typescript
const player = new Player()
const enemy = new Enemy()
player.emitCollisionWith({
  object: enemy
})

Inherited from

FPolyhedron.emitCollisionWith

Defined in

core/dist/index.d.ts:116


initCollider()

initCollider(options?): void

Only init a collider for the component, without a rigid body. This is useful for static objects.

Parameters

options?: FColliderOptions

The options for the collider.

Returns

void

Example

ts
component.initCollider({
  position: { x: 0, y: 0, z: 0 },
  scale: { x: 1, y: 1, z: 1 },
  rotation: { x: 0, y: 0, z: 0 },
  shape: FShapes.CUBE
})

Overrides

FPolyhedron.initCollider

Defined in

3d/src/polyhedrons/FCapsule.ts:47


initRigidBody()

initRigidBody(options?): void

Init a rigid body for the component.

Parameters

options?: FRigidBodyOptions

The options for the rigid body.

Returns

void

Example

ts
component.initRigidBody({
  position: { x: 0, y: 0, z: 0 },
  scale: { x: 1, y: 1, z: 1 },
  rotation: { x: 0, y: 0, z: 0 },
  shape: FShapes.CUBE
})

Overrides

FPolyhedron.initRigidBody

Defined in

3d/src/polyhedrons/FCapsule.ts:40


initSensor()

initSensor(options?): void

Init a sensor for the component. This is useful for triggerings events when the component collides with other components.

Parameters

options?: FColliderOptions

The options for the collider.

Returns

void

Example

ts
component.initSensor({
  position: { x: 0, y: 0, z: 0 },
  scale: { x: 1, y: 1, z: 1 },
  rotation: { x: 0, y: 0, z: 0 },
  shape: FShapes.CUBE
})

Inherited from

FPolyhedron.initSensor

Defined in

3d/src/core/FComponent.ts:385


onCollisionWith()

onCollisionWith(classOrObject, callback): () => void

Add a callback to be called when a collision occurs.

Parameters

classOrObject: any

The class or object to add the callback to.

callback

The callback to add.

Returns

Function

A function to remove the callback.

Returns

void

Examples

typescript
const player = new Player()
const enemy = new Enemy()
player.onCollisionWith(Enemy, () => {
  console.log('Player collided with an Enemy!')
})
typescript
const player = new Player()
const enemy = new Enemy()
player.onCollisionWith(enemy, () => {
  console.log('Player collided with the enemy!')
})

Inherited from

FPolyhedron.onCollisionWith

Defined in

3d/src/core/FComponent.ts:394


onFrame()

onFrame(_delta): void

Update the component. Should be called every frame. The purpose of onFrame on FComponent is really to render the component, its mesh/sprite and its properties. Any changes on its transform should be done on the controller, not here.

Parameters

_delta: number

Returns

void

Overrides

FPolyhedron.onFrame

Defined in

3d/src/polyhedrons/FCapsule.ts:36


setColor()

setColor(color): void

Change the color of the polyhedron.

Parameters

color: number

The color of the polyhedron.

Returns

void

Example

ts
cube.setColor(0xFF0000)

Inherited from

FPolyhedron.setColor

Defined in

3d/src/polyhedrons/FPolyhedron.ts:47


setPosition()

setPosition(options): void

Set the position of the component.

Parameters

options

The options for the position.

options.x: number

The position on the x-axis.

options.y: number

The position on the y-axis.

options.z: number

The position on the z-axis.

Returns

void

Example

ts
component.setPosition({ x: 0, y: 1, z: 0 })

Inherited from

FPolyhedron.setPosition

Defined in

3d/src/core/FComponent.ts:204


setRotation()

setRotation(options): void

Set the rotation of the component from radians.

Parameters

options

The options for the rotation.

options.x: number

The rotation on the x-axis.

options.y: number

The rotation on the y-axis.

options.z: number

The rotation on the z-axis.

Returns

void

Example

ts
component.setRotation({ x: 0, y: 0, z: 0 })

Inherited from

FPolyhedron.setRotation

Defined in

3d/src/core/FComponent.ts:269


setRotationDegree()

setRotationDegree(options): void

Set the rotation of the component from degrees.

Parameters

options

The options for the rotation.

options.x: number

The rotation in degrees on the x-axis.

options.y: number

The rotation in degrees on the y-axis.

options.z: number

The rotation in degrees on the z-axis.

Returns

void

Example

ts
component.setRotationDegree({ x: 0, y: 90, z: 0 })

Inherited from

FPolyhedron.setRotationDegree

Defined in

3d/src/core/FComponent.ts:293


setScale()

setScale(options): void

Set the scale of the component.

Parameters

options

The options for the scale.

options.x: number

The scale on the x-axis.

options.y: number

The scale on the y-axis.

options.z: number

The scale on the z-axis.

Returns

void

Example

ts
component.setScale({ x: 1, y: 1, z: 1 })

Inherited from

FPolyhedron.setScale

Defined in

3d/src/core/FComponent.ts:228

Properties

__CALLBACKS_ON_COLLISION__

__CALLBACKS_ON_COLLISION__: object

Callbacks for when a collision occurs with a given class or object. It is a dictionary where the key is the class name or object id and the value is an array of callbacks.

Index Signature

[key: string]: (data) => void[]

Inherited from

FPolyhedron.__CALLBACKS_ON_COLLISION__

Defined in

core/dist/index.d.ts:56


__ID__

__ID__: number

Unique identifier for the component. It is generated automatically.

Inherited from

FPolyhedron.__ID__

Defined in

core/dist/index.d.ts:51


__IS_2D__

__IS_2D__: boolean

Inherited from

FPolyhedron.__IS_2D__

Defined in

core/dist/index.d.ts:46


__IS_3D__

__IS_3D__: boolean = true

Internal flags

Inherited from

FPolyhedron.__IS_3D__

Defined in

3d/src/core/FComponent.ts:28


collider?

optional collider: FCollider

Collider

Inherited from

FPolyhedron.collider

Defined in

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


controller?

optional controller: FController

The controller attached to the component.

Inherited from

FPolyhedron.controller

Defined in

3d/src/core/FComponent.ts:37


mesh

mesh: Mesh<BufferGeometry<NormalBufferAttributes>, Material | Material[], Object3DEventMap>

mesh is redefined from FComponent without the ? because it is directly available after the constructor, as a polyhedron is created synchronously.

Inherited from

FPolyhedron.mesh

Defined in

3d/src/polyhedrons/FPolyhedron.ts:16


rigidBody?

optional rigidBody: FRigidBody

RigidBody

Inherited from

FPolyhedron.rigidBody

Defined in

3d/src/core/FComponent.ts:53


scene

scene: FScene

The scene which the component is in.

Inherited from

FPolyhedron.scene

Defined in

3d/src/core/FComponent.ts:33


sensor?

optional sensor: FRigidBody

Sensor (a collider that doesn't collide with other colliders, but still triggers events)

Inherited from

FPolyhedron.sensor

Defined in

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


transform

transform: FTransform

Transforms

Inherited from

FPolyhedron.transform

Defined in

3d/src/core/FComponent.ts:47