Skip to content

@fibbojs / 3d / FGLTF

Class: FGLTF

A GLTF model in Fibbo.

Example

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

const scene = new FScene()

const gltf = new FGLTF(scene, {
  path: 'model.glb',
})
scene.addComponent(gltf)

Extends

Extended by

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

FModel.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

FModel.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

FModel.rotationDegree

Defined in

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


rotationDegreeX

get rotationDegreeX(): number

set rotationDegreeX(x): void

Parameters

x: number

Returns

number

Inherited from

FModel.rotationDegreeX

Defined in

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


rotationDegreeY

get rotationDegreeY(): number

set rotationDegreeY(y): void

Parameters

y: number

Returns

number

Inherited from

FModel.rotationDegreeY

Defined in

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


rotationDegreeZ

get rotationDegreeZ(): number

set rotationDegreeZ(z): void

Parameters

z: number

Returns

number

Inherited from

FModel.rotationDegreeZ

Defined in

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


rotationX

get rotationX(): number

set rotationX(x): void

Parameters

x: number

Returns

number

Inherited from

FModel.rotationX

Defined in

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


rotationY

get rotationY(): number

set rotationY(y): void

Parameters

y: number

Returns

number

Inherited from

FModel.rotationY

Defined in

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


rotationZ

get rotationZ(): number

set rotationZ(z): void

Parameters

z: number

Returns

number

Inherited from

FModel.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

FModel.scale

Defined in

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


scaleX

get scaleX(): number

set scaleX(x): void

Parameters

x: number

Returns

number

Inherited from

FModel.scaleX

Defined in

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


scaleY

get scaleY(): number

set scaleY(y): void

Parameters

y: number

Returns

number

Inherited from

FModel.scaleY

Defined in

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


scaleZ

get scaleZ(): number

set scaleZ(z): void

Parameters

z: number

Returns

number

Inherited from

FModel.scaleZ

Defined in

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


x

get x(): number

set x(x): void

Parameters

x: number

Returns

number

Inherited from

FModel.x

Defined in

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


y

get y(): number

set y(y): void

Parameters

y: number

Returns

number

Inherited from

FModel.y

Defined in

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


z

get z(): number

set z(z): void

Parameters

z: number

Returns

number

Inherited from

FModel.z

Defined in

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

Constructors

new FGLTF()

new FGLTF(scene, options): FGLTF

Parameters

scene: FScene

options: FModelOptions

Returns

FGLTF

Overrides

FModel.constructor

Defined in

3d/src/model/FGLTF.ts:37

Methods

defineMeshTransforms()

defineMeshTransforms(): void

Define mesh transforms (used after loading the model).

Returns

void

Inherited from

FModel.defineMeshTransforms

Defined in

3d/src/model/FModel.ts:133


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

FModel.emitCollisionWith

Defined in

core/dist/index.d.ts:116


emitOnLoaded()

emitOnLoaded(): void

Emit the onLoaded callbacks.

Returns

void

Inherited from

FModel.emitOnLoaded

Defined in

3d/src/model/FModel.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
})

Inherited from

FModel.initCollider

Defined in

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


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
})

Inherited from

FModel.initRigidBody

Defined in

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


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

FModel.initSensor

Defined in

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


loadTextureForMesh()

loadTextureForMesh(mesh): void

Load the texture for a given mesh.

Parameters

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

The mesh.

Returns

void

Example

ts
model.loadTextureFor(material)

Inherited from

FModel.loadTextureForMesh

Defined in

3d/src/model/FModel.ts:159


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

FModel.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

Inherited from

FModel.onFrame

Defined in

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


onLoaded()

onLoaded(callback): void

Add a callback to be called when the model is loaded.

Parameters

callback

The callback function.

Returns

void

Inherited from

FModel.onLoaded

Defined in

3d/src/model/FModel.ts:109


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

FModel.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

FModel.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

FModel.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

FModel.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

FModel.__CALLBACKS_ON_COLLISION__

Defined in

core/dist/index.d.ts:56


__CALLBACKS_ON_LOADED__

__CALLBACKS_ON_LOADED__: () => void[] = []

Callbacks for when the model is loaded

Inherited from

FModel.__CALLBACKS_ON_LOADED__

Defined in

3d/src/model/FModel.ts:21


__ID__

__ID__: number

Unique identifier for the component. It is generated automatically.

Inherited from

FModel.__ID__

Defined in

core/dist/index.d.ts:51


__IS_2D__

__IS_2D__: boolean

Inherited from

FModel.__IS_2D__

Defined in

core/dist/index.d.ts:46


__IS_3D__

__IS_3D__: boolean = true

Internal flags

Inherited from

FModel.__IS_3D__

Defined in

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


collider?

optional collider: FCollider

Collider

Inherited from

FModel.collider

Defined in

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


controller?

optional controller: FController

The controller attached to the component.

Inherited from

FModel.controller

Defined in

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


fileExtension

fileExtension: string

The file extension of the model. Default is 'obj'.

Inherited from

FModel.fileExtension

Defined in

3d/src/model/FModel.ts:52


mesh?

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

Mesh

Inherited from

FModel.mesh

Defined in

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


name

name: string

The name of the model. Shouldn't contain file extensions.

Inherited from

FModel.name

Defined in

3d/src/model/FModel.ts:27


path

path: string

The path to the model file. Will be interpreted as a URL if it starts with http. Will be interpreted as an absolute path if it starts with /. Otherwise, it will be treated as a relative path to the models folder.

Inherited from

FModel.path

Defined in

3d/src/model/FModel.ts:35


rigidBody?

optional rigidBody: FRigidBody

RigidBody

Inherited from

FModel.rigidBody

Defined in

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


scene

scene: FScene

The scene which the component is in.

Inherited from

FModel.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

FModel.sensor

Defined in

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


textures

textures: Record<string, string>

A record containing texture path for each material.

Example

json
{
  "default": "/models/my-model/my-model.png"
}

Inherited from

FModel.textures

Defined in

3d/src/model/FModel.ts:46


transform

transform: FTransform

Transforms

Inherited from

FModel.transform

Defined in

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