Skip to content

Commit

Permalink
feat: add light system + automate API Reference generation (#19)
Browse files Browse the repository at this point in the history
* feat: add basic 3d lights + automatic helpers in debug

* feat: add directional light in 3d

* chore: fix playground

* feat: improve 3d lights

* feat: add 3d hemisphere light

* feat: add 3d light probe + reorganize 3d imports

* feat: add spot light and polish classes

* feat: prepare 2d lights

* docs: automate API Reference generation + clean TypeDoc

* docs: update lights documentation

* feat: fix default camera values and playground
  • Loading branch information
Gugustinette authored Sep 24, 2024
1 parent 2fb8ab4 commit 452022c
Show file tree
Hide file tree
Showing 175 changed files with 8,162 additions and 2,556 deletions.
47 changes: 28 additions & 19 deletions apps/playground-3d/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as THREE from 'three'
import { FCapsule, FComponentEmpty, FCuboid, FFBX, FGLB, FGameCamera, FOBJ, FScene, FShapes, FSphere } from '@fibbojs/3d'
import { FAmbientLight, FCapsule, FComponentEmpty, FCuboid, FDirectionalLight, FFBX, FGLB, FGameCamera, FOBJ, FScene, FShapes, FSphere, FSpotLight } from '@fibbojs/3d'
import { fDebug } from '@fibbojs/devtools'
import { FKeyboard } from '@fibbojs/event'
import RAPIER from '@dimforge/rapier3d'
Expand All @@ -20,18 +19,26 @@ import Character from './classes/Character'
if (import.meta.env.DEV)
fDebug(scene)

// Add directional light
const color = 0xFFFFFF
const intensity = 2000
const light = new THREE.PointLight(color, intensity)
light.castShadow = true
light.position.set(0, 20, 0)
scene.scene.add(light as any)
const helper = new THREE.PointLightHelper(light)
scene.scene.add(helper as any)
// Add directional light to represent the sun
scene.addLight(new FDirectionalLight(scene, {
position: { x: 20, y: 20, z: 0 },
color: 0xFFFFFF,
intensity: 2,
}))
// Add spot light
scene.addLight(new FSpotLight(scene, {
position: { x: 4, y: 4, z: 4 },
angle: 1,
distance: 8,
color: 0xFFFFFF,
intensity: 20,
lookAt: { x: 8, y: 0, z: 8 },
}))
// Add ambient light
const ambientLight = new THREE.AmbientLight(0x404040, 10)
scene.scene.add(ambientLight as any)
scene.addLight(new FAmbientLight(scene, {
color: 0x404040,
intensity: 20,
}))

// Create a death zone
const deathZone = new FComponentEmpty(scene, {
Expand Down Expand Up @@ -145,7 +152,7 @@ import Character from './classes/Character'
* Create other objects
*/
const sphere = new FSphere(scene, {
position: { x: 2, y: 4, z: -2 },
position: { x: 2, y: 5, z: -2 },
})
sphere.initRigidBody()
scene.addComponent(sphere)
Expand All @@ -158,7 +165,7 @@ import Character from './classes/Character'
scene.addComponent(capsule)

const duck = new Duck(scene)
duck.setPosition({ x: -5, y: 1, z: -5 })
duck.setPosition({ x: -5, y: 5, z: -5 })
duck.initRigidBody()
scene.addComponent(duck)

Expand All @@ -178,16 +185,18 @@ import Character from './classes/Character'
let cube
if (i === 0) {
// First one is an instance of MyCustomCube
cube = new MyCustomCube(scene)
cube.setPosition({ x, y: 3, z: z - 17 })
cube = new MyCustomCube(scene, {
position: { x, y: 10, z: z - 17 },
})
cube.initRigidBody({
// First one gets a sphere collider, the others get a cube collider
shape: FShapes.SPHERE,
})
}
else {
cube = new FCuboid(scene)
cube.setPosition({ x, y: 3, z: z - 17 })
cube = new FCuboid(scene, {
position: { x, y: 10, z: z - 17 },
})
cube.initRigidBody()
}
scene.addComponent(cube)
Expand Down
258 changes: 134 additions & 124 deletions docs/.vitepress/config.ts

Large diffs are not rendered by default.

24 changes: 9 additions & 15 deletions docs/api/2d/classes/FAttachedCamera.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

# Class: FAttachedCamera

## Description

A camera attached to a given target.

## Extends
Expand All @@ -20,7 +18,7 @@ A camera attached to a given target.

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

**options**: `FAttachedCameraOptions`
**options**: [`FAttachedCameraOptions`](../interfaces/FAttachedCameraOptions.md)

#### Returns

Expand All @@ -32,7 +30,7 @@ A camera attached to a given target.

#### Defined in

[2d/src/cameras/FAttachedCamera.ts:20](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FAttachedCamera.ts#L20)
[2d/src/cameras/FAttachedCamera.ts:20](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FAttachedCamera.ts#L20)

## Methods

Expand All @@ -50,7 +48,7 @@ A camera attached to a given target.

#### Defined in

[2d/src/cameras/FAttachedCamera.ts:33](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FAttachedCamera.ts#L33)
[2d/src/cameras/FAttachedCamera.ts:33](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FAttachedCamera.ts#L33)

***

Expand Down Expand Up @@ -188,7 +186,7 @@ Any changes on its transform should be done on the controller, not here.

#### Defined in

[2d/src/cameras/FAttachedCamera.ts:25](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FAttachedCamera.ts#L25)
[2d/src/cameras/FAttachedCamera.ts:25](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FAttachedCamera.ts#L25)

***

Expand All @@ -214,7 +212,7 @@ Set the zoom of the camera.

#### Defined in

[2d/src/cameras/FCamera.ts:57](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FCamera.ts#L57)
[2d/src/cameras/FCamera.ts:57](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FCamera.ts#L57)

## Properties

Expand Down Expand Up @@ -272,7 +270,7 @@ Internal flags

#### Defined in

[2d/src/cameras/FCamera.ts:16](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FCamera.ts#L16)
[2d/src/cameras/FCamera.ts:16](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FCamera.ts#L16)

***

Expand Down Expand Up @@ -328,16 +326,14 @@ Position of the camera.

#### Defined in

[2d/src/cameras/FCamera.ts:27](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FCamera.ts#L27)
[2d/src/cameras/FCamera.ts:27](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FCamera.ts#L27)

***

### scene

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

The scene the camera is in.

#### Inherited from
Expand All @@ -346,18 +342,16 @@ The scene the camera is in.

#### Defined in

[2d/src/cameras/FCamera.ts:21](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FCamera.ts#L21)
[2d/src/cameras/FCamera.ts:21](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FCamera.ts#L21)

***

### target

> **target**: [`FComponent`](FComponent.md)
#### Description

The target to follow.

#### Defined in

[2d/src/cameras/FAttachedCamera.ts:18](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FAttachedCamera.ts#L18)
[2d/src/cameras/FAttachedCamera.ts:18](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FAttachedCamera.ts#L18)
24 changes: 9 additions & 15 deletions docs/api/2d/classes/FCamera.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

# Class: `abstract` FCamera

## Description

The base class for 2D cameras in Fibbo.

## Extends
Expand All @@ -22,6 +20,8 @@ The base class for 2D cameras in Fibbo.

> **new FCamera**(`scene`, `options`?): [`FCamera`](FCamera.md)
Create a new 2D camera.

#### Parameters

**scene**: [`FScene`](FScene.md)
Expand All @@ -36,17 +36,13 @@ The options for the camera.

[`FCamera`](FCamera.md)

#### Description

Create a new 2D camera.

#### Overrides

`FCameraCore.constructor`

#### Defined in

[2d/src/cameras/FCamera.ts:34](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FCamera.ts#L34)
[2d/src/cameras/FCamera.ts:34](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FCamera.ts#L34)

## Methods

Expand All @@ -60,7 +56,7 @@ Create a new 2D camera.

#### Defined in

[2d/src/cameras/FCamera.ts:55](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FCamera.ts#L55)
[2d/src/cameras/FCamera.ts:55](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FCamera.ts#L55)

***

Expand Down Expand Up @@ -198,7 +194,7 @@ Any changes on its transform should be done on the controller, not here.

#### Defined in

[2d/src/cameras/FCamera.ts:53](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FCamera.ts#L53)
[2d/src/cameras/FCamera.ts:53](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FCamera.ts#L53)

***

Expand All @@ -224,7 +220,7 @@ Set the zoom of the camera.

#### Defined in

[2d/src/cameras/FCamera.ts:57](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FCamera.ts#L57)
[2d/src/cameras/FCamera.ts:57](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FCamera.ts#L57)

## Properties

Expand Down Expand Up @@ -282,7 +278,7 @@ Internal flags

#### Defined in

[2d/src/cameras/FCamera.ts:16](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FCamera.ts#L16)
[2d/src/cameras/FCamera.ts:16](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FCamera.ts#L16)

***

Expand Down Expand Up @@ -334,18 +330,16 @@ Position of the camera.
#### Defined in

[2d/src/cameras/FCamera.ts:27](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FCamera.ts#L27)
[2d/src/cameras/FCamera.ts:27](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FCamera.ts#L27)

***

### scene

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

The scene the camera is in.

#### Defined in

[2d/src/cameras/FCamera.ts:21](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/cameras/FCamera.ts#L21)
[2d/src/cameras/FCamera.ts:21](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/cameras/FCamera.ts#L21)
12 changes: 5 additions & 7 deletions docs/api/2d/classes/FCharacterController.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

# Class: `abstract` FCharacterController

## Description

An abstract pre-defined character controller.

## Extends
Expand Down Expand Up @@ -37,7 +35,7 @@ An abstract pre-defined character controller.

#### Defined in

[2d/src/controllers/FCharacterController.ts:42](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/controllers/FCharacterController.ts#L42)
[2d/src/controllers/FCharacterController.ts:42](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/controllers/FCharacterController.ts#L42)

## Methods

Expand Down Expand Up @@ -84,7 +82,7 @@ It is redefined here to get the correct type (with 2D properties).

#### Defined in

[2d/src/controllers/FController.ts:17](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/controllers/FController.ts#L17)
[2d/src/controllers/FController.ts:17](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/controllers/FController.ts#L17)

***

Expand Down Expand Up @@ -112,7 +110,7 @@ The inputs that will be used to move the character.
#### Defined in

[2d/src/controllers/FCharacterController.ts:25](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/controllers/FCharacterController.ts#L25)
[2d/src/controllers/FCharacterController.ts:25](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/controllers/FCharacterController.ts#L25)

***

Expand All @@ -124,7 +122,7 @@ The scene where the character is.

#### Defined in

[2d/src/controllers/FCharacterController.ts:40](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/controllers/FCharacterController.ts#L40)
[2d/src/controllers/FCharacterController.ts:40](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/controllers/FCharacterController.ts#L40)

***

Expand All @@ -136,4 +134,4 @@ The speed of the character.

#### Defined in

[2d/src/controllers/FCharacterController.ts:35](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/controllers/FCharacterController.ts#L35)
[2d/src/controllers/FCharacterController.ts:35](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/controllers/FCharacterController.ts#L35)
14 changes: 6 additions & 8 deletions docs/api/2d/classes/FCharacterControllerD.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

# Class: FCharacterControllerD

## Description

A pre-defined character controller based on a Dynamic RigidBody.

## Example
Expand Down Expand Up @@ -44,7 +42,7 @@ scene.addComponent(capsule)

#### Defined in

[2d/src/controllers/FCharacterControllerD.ts:22](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/controllers/FCharacterControllerD.ts#L22)
[2d/src/controllers/FCharacterControllerD.ts:22](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/controllers/FCharacterControllerD.ts#L22)

## Methods

Expand Down Expand Up @@ -72,7 +70,7 @@ Any rendering process should be done on the component, not here.

#### Defined in

[2d/src/controllers/FCharacterControllerD.ts:38](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/controllers/FCharacterControllerD.ts#L38)
[2d/src/controllers/FCharacterControllerD.ts:38](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/controllers/FCharacterControllerD.ts#L38)

## Properties

Expand All @@ -89,7 +87,7 @@ It is redefined here to get the correct type (with 2D properties).

#### Defined in

[2d/src/controllers/FController.ts:17](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/controllers/FController.ts#L17)
[2d/src/controllers/FController.ts:17](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/controllers/FController.ts#L17)

***

Expand Down Expand Up @@ -121,7 +119,7 @@ The inputs that will be used to move the character.

#### Defined in

[2d/src/controllers/FCharacterController.ts:25](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/controllers/FCharacterController.ts#L25)
[2d/src/controllers/FCharacterController.ts:25](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/controllers/FCharacterController.ts#L25)

***

Expand All @@ -137,7 +135,7 @@ The scene where the character is.

#### Defined in

[2d/src/controllers/FCharacterController.ts:40](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/controllers/FCharacterController.ts#L40)
[2d/src/controllers/FCharacterController.ts:40](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/controllers/FCharacterController.ts#L40)

***

Expand All @@ -153,4 +151,4 @@ The speed of the character.

#### Defined in

[2d/src/controllers/FCharacterController.ts:35](https://github.com/fibbojs/fibbo/blob/c87e9de577b4352e4b6a8336cf19cf678868439d/packages/2d/src/controllers/FCharacterController.ts#L35)
[2d/src/controllers/FCharacterController.ts:35](https://github.com/fibbojs/fibbo/blob/fc0b9ae1dcd24855b80ad46a69cb7005bbcce7f4/packages/2d/src/controllers/FCharacterController.ts#L35)
Loading

0 comments on commit 452022c

Please sign in to comment.