Skip to content

@fibbojs / 3d / FOBJ

Class: FOBJ

An OBJ model in Fibbo.

Example

ts
import { FOBJ } from '@fibbojs/3d'

const obj = new FOBJ({
  path: 'model.obj',
})

Extends

Constructors

new FOBJ()

new FOBJ(options): FOBJ

Parameters

options: FModelOptions

Returns

FOBJ

Overrides

FModel.constructor

Defined in

3d/src/model/FOBJ.ts:19

Methods

__SET_POSITION__()

__SET_POSITION__(position): void

Parameters

position: FVector3

Returns

void

Inherited from

FModel.__SET_POSITION__

Defined in

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


__SET_ROTATION__()

__SET_ROTATION__(rotation): void

Parameters

rotation: FVector3

Returns

void

Inherited from

FModel.__SET_ROTATION__

Defined in

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


__SET_SCALE__()

__SET_SCALE__(scale): void

Parameters

scale: FVector3

Returns

void

Inherited from

FModel.__SET_SCALE__

Defined in

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


__UPDATE_POSITION__()

__UPDATE_POSITION__(initiator): void

Update the position of the component according to the transform. This method should be called after updating the transform properties.

Parameters

initiator: boolean = false

By default (false), the component won't be considered as the initiator of the position update. Set this to true to propagate the position update to the rigidBody, collider and sensor.

Returns

void

Inherited from

FModel.__UPDATE_POSITION__

Defined in

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


__UPDATE_ROTATION__()

__UPDATE_ROTATION__(initiator): void

Update the rotation of the component according to the transform. This method should be called after updating the transform properties.

Parameters

initiator: boolean = false

By default (false), the component won't be considered as the initiator of the rotation update. Set this to true to propagate the rotation update to the rigidBody, collider and sensor.

Returns

void

Inherited from

FModel.__UPDATE_ROTATION__

Defined in

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


__UPDATE_SCALE__()

__UPDATE_SCALE__(initiator): void

Update the scale of the component according to the transform. This method should be called after updating the transform properties.

Parameters

initiator: boolean = false

By default (false), the component won't be considered as the initiator of the scale update. Set this to true to propagate the scale update to the rigidBody, collider and sensor.

Returns

void

Inherited from

FModel.__UPDATE_SCALE__

Defined in

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


addController()

addController(controller): void

Add a controller to the component.

Parameters

controller: FController

The controller to add.

Returns

void

Inherited from

FModel.addController

Defined in

core/dist/index.d.ts:418


defineMeshTransforms()

defineMeshTransforms(): void

Define mesh transforms (used after loading the model).

Returns

void

Inherited from

FModel.defineMeshTransforms

Defined in

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


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


emitOnLoaded()

emitOnLoaded(): void

Emit the onLoaded callbacks. It was overridden to add shadow support.

Returns

void

Inherited from

FModel.emitOnLoaded

Defined in

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


frame()

frame(delta): void

Update the component. Should be called every frame. The purpose of this method is to render the component, its mesh/sprite, and its properties.

Parameters

delta: number

The time since the last frame.

Returns

void

Inherited from

FModel.frame

Defined in

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


initCollider()

initCollider(options?): void

Parameters

options?: FColliderOptions

Returns

void

Inherited from

FModel.initCollider

Defined in

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


initRigidBody()

initRigidBody(options?): void

Parameters

options?: FRigidBodyOptions

Returns

void

Inherited from

FModel.initRigidBody

Defined in

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


initSensor()

initSensor(options?): void

Parameters

options?: FRigidBodyOptions

Returns

void

Inherited from

FModel.initSensor

Defined in

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


loadTextureForMesh()

loadTextureForMesh(mesh): void

Load the texture for a given mesh.

Parameters

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

The mesh to load the texture for.

Returns

void

Example

ts
model.loadTextureFor(mesh)

Inherited from

FModel.loadTextureForMesh

Defined in

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


onCollisionWith()

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

Add a callback to be called when a collision occurs.

Parameters

classOrObject: any

The class or object to observe for collisions. Should inherit from FComponent.

callback

The callback to add to the collision event.

Returns

Function

A function to remove the callback.

Returns

void

Examples

typescript
const player = new Player()
const enemy = new Enemy()
player.onCollisionWith(Enemy, ({ component }) => {
  console.log('Player collided with an Enemy!')
  console.log('The enemy is:', component)
})
typescript
const player = new Player()
const enemy = new Enemy()
player.onCollisionWith(enemy, () => {
  console.log('Player collided with the enemy!')
})
typescript
const player = new Player()
const enemy = new Enemy()
const removeThisCallback = player.onCollisionWith(enemy, () => {
 console.log('Player collided with the enemy!')
})
// To remove the callback, call the function returned by onCollisionWith
removeThisCallback()

#### Inherited from

[`FModel`](FModel.md).[`onCollisionWith`](FModel.md#oncollisionwith)

#### Defined in

[3d/src/core/FComponent.ts:318](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/core/FComponent.ts#L318)

***

### onFrame()

> **onFrame**(`callback`): `void`

Add a callback to be called every frame.

#### Parameters

**callback**

The callback function.

#### Returns

`void`

#### Inherited from

[`FModel`](FModel.md).[`onFrame`](FModel.md#onframe)

#### Defined in

core/dist/index.d.ts:434

***

### onLoaded()

> **onLoaded**(`callback`): `void`

Add a callback to be called when the component is loaded (could be a texture, a 3D model, etc).

#### Parameters

**callback**

The callback function.

#### Returns

`void`

#### Inherited from

[`FModel`](FModel.md).[`onLoaded`](FModel.md#onloaded)

#### Defined in

core/dist/index.d.ts:439

***

### removeController()

> **removeController**(`controller`): `void`

Remove a controller from the component.

#### Parameters

**controller**: `FController`

The controller to remove.

#### Returns

`void`

#### Inherited from

[`FModel`](FModel.md).[`removeController`](FModel.md#removecontroller)

#### Defined in

core/dist/index.d.ts:423

***

### render()

> **render**(`delta`): `void`

#### Parameters

**delta**: `number`

#### Returns

`void`

#### Inherited from

[`FModel`](FModel.md).[`render`](FModel.md#render)

#### Defined in

[3d/src/core/FComponent.ts:114](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/core/FComponent.ts#L114)

## 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`](FModel.md).[`__CALLBACKS_ON_COLLISION__`](FModel.md#__callbacks_on_collision__)

#### Defined in

core/dist/index.d.ts:402

***

### \_\_CALLBACKS\_ON\_FRAME\_\_

> **\_\_CALLBACKS\_ON\_FRAME\_\_**: () => `void`[]

Callbacks for when a frame is rendered.

#### Inherited from

[`FModel`](FModel.md).[`__CALLBACKS_ON_FRAME__`](FModel.md#__callbacks_on_frame__)

#### Defined in

core/dist/index.d.ts:393

***

### \_\_CALLBACKS\_ON\_LOADED\_\_

> **\_\_CALLBACKS\_ON\_LOADED\_\_**: () => `void`[]

Callbacks for when the component is loaded (could be a texture, a 3D model, etc).

#### Inherited from

[`FModel`](FModel.md).[`__CALLBACKS_ON_LOADED__`](FModel.md#__callbacks_on_loaded__)

#### Defined in

core/dist/index.d.ts:397

***

### \_\_ID\_\_

> **\_\_ID\_\_**: `number`

Unique identifier for the component.
It is generated automatically.

#### Inherited from

[`FModel`](FModel.md).[`__ID__`](FModel.md#__id__)

#### Defined in

core/dist/index.d.ts:389

***

### \_\_IS\_2D\_\_

> **\_\_IS\_2D\_\_**: `boolean`

#### Inherited from

[`FModel`](FModel.md).[`__IS_2D__`](FModel.md#__is_2d__)

#### Defined in

core/dist/index.d.ts:384

***

### \_\_IS\_3D\_\_

> **\_\_IS\_3D\_\_**: `boolean` = `true`

Internal flags

#### Inherited from

[`FModel`](FModel.md).[`__IS_3D__`](FModel.md#__is_3d__)

#### Defined in

[3d/src/core/FComponent.ts:30](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/core/FComponent.ts#L30)

***

### \_\_MESH\_\_?

> `optional` **\_\_MESH\_\_**: `Mesh`\<`BufferGeometry`\<`NormalBufferAttributes`\>, `Material` \| `Material`[], `Object3DEventMap`\> \| `Group`\<`Object3DEventMap`\>

Mesh

#### Inherited from

[`FModel`](FModel.md).[`__MESH__`](FModel.md#__mesh__)

#### Defined in

[3d/src/core/FComponent.ts:43](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/core/FComponent.ts#L43)

***

### collider?

> `optional` **collider**: [`FCollider`](FCollider.md)

Collider

#### Inherited from

[`FModel`](FModel.md).[`collider`](FModel.md#collider)

#### Defined in

[3d/src/core/FComponent.ts:58](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/core/FComponent.ts#L58)

***

### controllers

> **controllers**: [`FController`](FController.md)[]

The controllers attached to the component.

#### Inherited from

[`FModel`](FModel.md).[`controllers`](FModel.md#controllers)

#### Defined in

[3d/src/core/FComponent.ts:38](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/core/FComponent.ts#L38)

***

### fileExtension

> **fileExtension**: `string`

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

#### Inherited from

[`FModel`](FModel.md).[`fileExtension`](FModel.md#fileextension)

#### Defined in

[3d/src/model/FModel.ts:47](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/model/FModel.ts#L47)

***

### name

> **name**: `string`

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

#### Inherited from

[`FModel`](FModel.md).[`name`](FModel.md#name)

#### Defined in

[3d/src/model/FModel.ts:22](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/model/FModel.ts#L22)

***

### 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`](FModel.md).[`path`](FModel.md#path)

#### Defined in

[3d/src/model/FModel.ts:30](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/model/FModel.ts#L30)

***

### rigidBody?

> `optional` **rigidBody**: [`FRigidBody`](FRigidBody.md)

RigidBody

#### Inherited from

[`FModel`](FModel.md).[`rigidBody`](FModel.md#rigidbody)

#### Defined in

[3d/src/core/FComponent.ts:54](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/core/FComponent.ts#L54)

***

### scene

> **scene**: [`FScene`](FScene.md)

The scene the component is attached to.

#### Inherited from

[`FModel`](FModel.md).[`scene`](FModel.md#scene)

#### Defined in

[3d/src/core/FComponent.ts:34](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/core/FComponent.ts#L34)

***

### sensor?

> `optional` **sensor**: [`FRigidBody`](FRigidBody.md)

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

#### Inherited from

[`FModel`](FModel.md).[`sensor`](FModel.md#sensor)

#### Defined in

[3d/src/core/FComponent.ts:62](https://github.com/fibbojs/fibbo/blob/65626b456ab47d7e61b23a8dd1be9f399238b0f1/packages/3d/src/core/FComponent.ts#L62)

***

### 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:41


transform

transform: FTransform

Transforms

Inherited from

FModel.transform

Defined in

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