diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index d5c19995..4d16a420 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -48,20 +48,9 @@ export default defineConfig({ { text: 'FModel', link: '/api/classes/FModel' }, { text: 'FSphere', link: '/api/classes/FSphere' }, ] }, - { text: 'Functions', items: [ - { text: 'useLookAt', link: '/api/functions/useLookAt' }, - { text: 'usePosition', link: '/api/functions/usePosition' }, - { text: 'useRigidBody', link: '/api/functions/useRigidBody' }, - { text: 'useRotation', link: '/api/functions/useRotation' }, - { text: 'useRotationDegree', link: '/api/functions/useRotationDegree' }, - { text: 'useScale', link: '/api/functions/useScale' }, - ] }, { text: 'Enumerations', items: [ { text: 'F3dShapes', link: '/api/enums/F3dShapes' }, ] }, - { text: 'Interfaces', items: [ - { text: 'FVector3', link: '/api/interfaces/FVector3' }, - ] }, ], }, ], diff --git a/docs/api/classes/FAttachedCamera.md b/docs/api/classes/FAttachedCamera.md index 1aa8992c..82d5c1f4 100644 --- a/docs/api/classes/FAttachedCamera.md +++ b/docs/api/classes/FAttachedCamera.md @@ -80,10 +80,13 @@ export default class MyAttachedCamera extends FAttachedCamera { - [rotateZ](FAttachedCamera.md#rotatez) - [setFocalLength](FAttachedCamera.md#setfocallength) - [setLens](FAttachedCamera.md#setlens) +- [setPosition](FAttachedCamera.md#setposition) +- [setRotation](FAttachedCamera.md#setrotation) - [setRotationFromAxisAngle](FAttachedCamera.md#setrotationfromaxisangle) - [setRotationFromEuler](FAttachedCamera.md#setrotationfromeuler) - [setRotationFromMatrix](FAttachedCamera.md#setrotationfrommatrix) - [setRotationFromQuaternion](FAttachedCamera.md#setrotationfromquaternion) +- [setScale](FAttachedCamera.md#setscale) - [setViewOffset](FAttachedCamera.md#setviewoffset) - [toJSON](FAttachedCamera.md#tojson) - [translateOnAxis](FAttachedCamera.md#translateonaxis) @@ -174,7 +177,7 @@ export default class MyAttachedCamera extends FAttachedCamera { #### Defined in -src/cameras/FAttachedCamera.ts:33 +[src/cameras/FAttachedCamera.ts:33](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FAttachedCamera.ts#L33) ## Methods @@ -1186,7 +1189,7 @@ ___ #### Defined in -src/cameras/FAttachedCamera.ts:38 +[src/cameras/FAttachedCamera.ts:38](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FAttachedCamera.ts#L38) ___ @@ -1543,6 +1546,66 @@ node_modules/@types/three/src/cameras/PerspectiveCamera.d.ts:222 ___ +### setPosition + +▸ **setPosition**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the position of the camera. + +#### Overrides + +[FCamera](FCamera.md).[setPosition](FCamera.md#setposition) + +#### Defined in + +[src/cameras/FAttachedCamera.ts:50](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FAttachedCamera.ts#L50) + +___ + +### setRotation + +▸ **setRotation**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the camera. + +#### Inherited from + +[FCamera](FCamera.md).[setRotation](FCamera.md#setrotation) + +#### Defined in + +[src/cameras/FCamera.ts:32](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L32) + +___ + ### setRotationFromAxisAngle ▸ **setRotationFromAxisAngle**(`axis`, `angle`): `void` @@ -1652,6 +1715,36 @@ node_modules/@types/three/src/core/Object3D.d.ts:370 ___ +### setScale + +▸ **setScale**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the scale of the camera. + +#### Inherited from + +[FCamera](FCamera.md).[setScale](FCamera.md#setscale) + +#### Defined in + +[src/cameras/FCamera.ts:25](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L25) + +___ + ### setViewOffset ▸ **setViewOffset**(`fullWidth`, `fullHeight`, `x`, `y`, `width`, `height`): `void` @@ -2122,7 +2215,7 @@ ___ #### Defined in -src/cameras/FAttachedCamera.ts:26 +[src/cameras/FAttachedCamera.ts:26](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FAttachedCamera.ts#L26) ___ @@ -2707,11 +2800,11 @@ ___ ### offset -• **offset**: [`FVector3`](../interfaces/FVector3.md) +• **offset**: `Vector3` #### Defined in -src/cameras/FAttachedCamera.ts:28 +[src/cameras/FAttachedCamera.ts:28](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FAttachedCamera.ts#L28) ___ diff --git a/docs/api/classes/FCamera.md b/docs/api/classes/FCamera.md index a2aba5a7..9d6c6d3e 100644 --- a/docs/api/classes/FCamera.md +++ b/docs/api/classes/FCamera.md @@ -73,10 +73,13 @@ The base class for cameras in FibboJS. - [rotateZ](FCamera.md#rotatez) - [setFocalLength](FCamera.md#setfocallength) - [setLens](FCamera.md#setlens) +- [setPosition](FCamera.md#setposition) +- [setRotation](FCamera.md#setrotation) - [setRotationFromAxisAngle](FCamera.md#setrotationfromaxisangle) - [setRotationFromEuler](FCamera.md#setrotationfromeuler) - [setRotationFromMatrix](FCamera.md#setrotationfrommatrix) - [setRotationFromQuaternion](FCamera.md#setrotationfromquaternion) +- [setScale](FCamera.md#setscale) - [setViewOffset](FCamera.md#setviewoffset) - [toJSON](FCamera.md#tojson) - [translateOnAxis](FCamera.md#translateonaxis) @@ -159,7 +162,7 @@ THREE.PerspectiveCamera.constructor #### Defined in -src/cameras/FCamera.ts:9 +[src/cameras/FCamera.ts:9](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L9) ## Methods @@ -1171,7 +1174,7 @@ ___ #### Defined in -src/cameras/FCamera.ts:13 +[src/cameras/FCamera.ts:13](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L13) ___ @@ -1528,6 +1531,66 @@ node_modules/@types/three/src/cameras/PerspectiveCamera.d.ts:222 ___ +### setPosition + +▸ **setPosition**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the position of the camera. + +#### Implementation of + +[FComponent](FComponent.md).[setPosition](FComponent.md#setposition) + +#### Defined in + +[src/cameras/FCamera.ts:18](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L18) + +___ + +### setRotation + +▸ **setRotation**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the camera. + +#### Implementation of + +[FComponent](FComponent.md).[setRotation](FComponent.md#setrotation) + +#### Defined in + +[src/cameras/FCamera.ts:32](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L32) + +___ + ### setRotationFromAxisAngle ▸ **setRotationFromAxisAngle**(`axis`, `angle`): `void` @@ -1637,6 +1700,36 @@ node_modules/@types/three/src/core/Object3D.d.ts:370 ___ +### setScale + +▸ **setScale**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the scale of the camera. + +#### Implementation of + +[FComponent](FComponent.md).[setScale](FComponent.md#setscale) + +#### Defined in + +[src/cameras/FCamera.ts:25](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L25) + +___ + ### setViewOffset ▸ **setViewOffset**(`fullWidth`, `fullHeight`, `x`, `y`, `width`, `height`): `void` diff --git a/docs/api/classes/FComponent.md b/docs/api/classes/FComponent.md index 78be2415..ef514200 100644 --- a/docs/api/classes/FComponent.md +++ b/docs/api/classes/FComponent.md @@ -20,6 +20,9 @@ The base class for all 3D components in FibboJS. ### Methods - [onFrame](FComponent.md#onframe) +- [setPosition](FComponent.md#setposition) +- [setRotation](FComponent.md#setrotation) +- [setScale](FComponent.md#setscale) ## Constructors @@ -33,7 +36,7 @@ The base class for all 3D components in FibboJS. #### Defined in -src/core/FComponent.ts:6 +[src/core/FComponent.ts:6](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FComponent.ts#L6) ## Methods @@ -53,4 +56,82 @@ src/core/FComponent.ts:6 #### Defined in -src/core/FComponent.ts:9 +[src/core/FComponent.ts:9](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FComponent.ts#L9) + +___ + +### setPosition + +▸ **setPosition**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the position of the component. + +#### Defined in + +[src/core/FComponent.ts:14](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FComponent.ts#L14) + +___ + +### setRotation + +▸ **setRotation**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the component. + +#### Defined in + +[src/core/FComponent.ts:24](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FComponent.ts#L24) + +___ + +### setScale + +▸ **setScale**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the scale of the component. + +#### Defined in + +[src/core/FComponent.ts:19](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FComponent.ts#L19) diff --git a/docs/api/classes/FCube.md b/docs/api/classes/FCube.md index 693979d9..276a3a45 100644 --- a/docs/api/classes/FCube.md +++ b/docs/api/classes/FCube.md @@ -37,7 +37,12 @@ export class MyCube extends FCube { ### Methods +- [initRigidBody](FCube.md#initrigidbody) - [onFrame](FCube.md#onframe) +- [setPosition](FCube.md#setposition) +- [setRotation](FCube.md#setrotation) +- [setRotationDegree](FCube.md#setrotationdegree) +- [setScale](FCube.md#setscale) ### Properties @@ -71,10 +76,41 @@ export class MyCube extends FCube { #### Defined in -src/model/FCube.ts:31 +[src/model/FCube.ts:31](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FCube.ts#L31) ## Methods +### initRigidBody + +▸ **initRigidBody**(`position?`, `scale?`, `rotation?`, `shape?`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `position?` | `Vector3` | +| `scale?` | `Vector3` | +| `rotation?` | `Vector3` | +| `shape?` | [`F3dShapes`](../enums/F3dShapes.md) | + +#### Returns + +`void` + +**`Description`** + +Init a rigid body for the model. + +#### Inherited from + +[FModel](FModel.md).[initRigidBody](FModel.md#initrigidbody) + +#### Defined in + +[src/model/FModel.ts:96](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L96) + +___ + ### onFrame ▸ **onFrame**(`_delta`): `void` @@ -95,7 +131,127 @@ src/model/FCube.ts:31 #### Defined in -src/model/FCube.ts:39 +[src/model/FCube.ts:39](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FCube.ts#L39) + +___ + +### setPosition + +▸ **setPosition**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the position of the model. + +#### Inherited from + +[FModel](FModel.md).[setPosition](FModel.md#setposition) + +#### Defined in + +[src/model/FModel.ts:49](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L49) + +___ + +### setRotation + +▸ **setRotation**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the model. + +#### Inherited from + +[FModel](FModel.md).[setRotation](FModel.md#setrotation) + +#### Defined in + +[src/model/FModel.ts:69](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L69) + +___ + +### setRotationDegree + +▸ **setRotationDegree**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the model from degrees. + +#### Inherited from + +[FModel](FModel.md).[setRotationDegree](FModel.md#setrotationdegree) + +#### Defined in + +[src/model/FModel.ts:78](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L78) + +___ + +### setScale + +▸ **setScale**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the scale of the model. + +#### Inherited from + +[FModel](FModel.md).[setScale](FModel.md#setscale) + +#### Defined in + +[src/model/FModel.ts:60](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L60) ## Properties @@ -109,7 +265,7 @@ src/model/FCube.ts:39 #### Defined in -src/model/FModel.ts:20 +[src/model/FModel.ts:22](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L22) ___ @@ -126,7 +282,7 @@ directly available after the constructor, as the cube is created synchronously. #### Defined in -src/model/FCube.ts:29 +[src/model/FCube.ts:29](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FCube.ts#L29) ___ @@ -140,7 +296,7 @@ ___ #### Defined in -src/model/FModel.ts:13 +[src/model/FModel.ts:15](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L15) ___ @@ -154,7 +310,7 @@ ___ #### Defined in -src/model/FModel.ts:19 +[src/model/FModel.ts:21](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L21) ___ @@ -168,7 +324,7 @@ ___ #### Defined in -src/model/FModel.ts:15 +[src/model/FModel.ts:17](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L17) ___ @@ -182,7 +338,7 @@ ___ #### Defined in -src/model/FModel.ts:14 +[src/model/FModel.ts:16](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L16) ___ @@ -196,4 +352,4 @@ ___ #### Defined in -src/model/FModel.ts:12 +[src/model/FModel.ts:14](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L14) diff --git a/docs/api/classes/FFixedCamera.md b/docs/api/classes/FFixedCamera.md index 1dffc052..92dec0b2 100644 --- a/docs/api/classes/FFixedCamera.md +++ b/docs/api/classes/FFixedCamera.md @@ -9,13 +9,13 @@ A fixed camera that does not move. **`Example`** ```ts -import { FFixedCamera, usePosition, useLookAt } from '@fibbojs/fibbo' +import { FFixedCamera, } from '@fibbojs/fibbo' -@useLookAt({ x: 0, y: 0, z: 0 }) -@usePosition({ x: 5, y: 5, z: 5 }) export default class MyCamera extends FFixedCamera { constructor() { super() + this.setPosition(5, 5, 5) + this.lookAt(0, 0, 0) } onFrame(delta: number) { @@ -81,10 +81,13 @@ export default class MyCamera extends FFixedCamera { - [rotateZ](FFixedCamera.md#rotatez) - [setFocalLength](FFixedCamera.md#setfocallength) - [setLens](FFixedCamera.md#setlens) +- [setPosition](FFixedCamera.md#setposition) +- [setRotation](FFixedCamera.md#setrotation) - [setRotationFromAxisAngle](FFixedCamera.md#setrotationfromaxisangle) - [setRotationFromEuler](FFixedCamera.md#setrotationfromeuler) - [setRotationFromMatrix](FFixedCamera.md#setrotationfrommatrix) - [setRotationFromQuaternion](FFixedCamera.md#setrotationfromquaternion) +- [setScale](FFixedCamera.md#setscale) - [setViewOffset](FFixedCamera.md#setviewoffset) - [toJSON](FFixedCamera.md#tojson) - [translateOnAxis](FFixedCamera.md#translateonaxis) @@ -167,7 +170,7 @@ export default class MyCamera extends FFixedCamera { #### Defined in -src/cameras/FFixedCamera.ts:24 +[src/cameras/FFixedCamera.ts:24](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FFixedCamera.ts#L24) ## Methods @@ -1179,7 +1182,7 @@ ___ #### Defined in -src/cameras/FFixedCamera.ts:28 +[src/cameras/FFixedCamera.ts:28](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FFixedCamera.ts#L28) ___ @@ -1536,6 +1539,66 @@ node_modules/@types/three/src/cameras/PerspectiveCamera.d.ts:222 ___ +### setPosition + +▸ **setPosition**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the position of the camera. + +#### Inherited from + +[FCamera](FCamera.md).[setPosition](FCamera.md#setposition) + +#### Defined in + +[src/cameras/FCamera.ts:18](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L18) + +___ + +### setRotation + +▸ **setRotation**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the camera. + +#### Inherited from + +[FCamera](FCamera.md).[setRotation](FCamera.md#setrotation) + +#### Defined in + +[src/cameras/FCamera.ts:32](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L32) + +___ + ### setRotationFromAxisAngle ▸ **setRotationFromAxisAngle**(`axis`, `angle`): `void` @@ -1645,6 +1708,36 @@ node_modules/@types/three/src/core/Object3D.d.ts:370 ___ +### setScale + +▸ **setScale**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the scale of the camera. + +#### Inherited from + +[FCamera](FCamera.md).[setScale](FCamera.md#setscale) + +#### Defined in + +[src/cameras/FCamera.ts:25](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L25) + +___ + ### setViewOffset ▸ **setViewOffset**(`fullWidth`, `fullHeight`, `x`, `y`, `width`, `height`): `void` diff --git a/docs/api/classes/FGLTF.md b/docs/api/classes/FGLTF.md index eb1c51db..355bf1cf 100644 --- a/docs/api/classes/FGLTF.md +++ b/docs/api/classes/FGLTF.md @@ -38,8 +38,13 @@ export class MyGltfModel extends FGLTF { ### Methods - [emitOnLoaded](FGLTF.md#emitonloaded) +- [initRigidBody](FGLTF.md#initrigidbody) - [onFrame](FGLTF.md#onframe) - [onLoaded](FGLTF.md#onloaded) +- [setPosition](FGLTF.md#setposition) +- [setRotation](FGLTF.md#setrotation) +- [setRotationDegree](FGLTF.md#setrotationdegree) +- [setScale](FGLTF.md#setscale) ### Properties @@ -76,7 +81,7 @@ export class MyGltfModel extends FGLTF { #### Defined in -src/model/FGLTF.ts:48 +[src/model/FGLTF.ts:48](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FGLTF.ts#L48) ## Methods @@ -90,7 +95,38 @@ src/model/FGLTF.ts:48 #### Defined in -src/model/FGLTF.ts:93 +[src/model/FGLTF.ts:102](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FGLTF.ts#L102) + +___ + +### initRigidBody + +▸ **initRigidBody**(`position?`, `scale?`, `rotation?`, `shape?`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `position?` | `Vector3` | +| `scale?` | `Vector3` | +| `rotation?` | `Vector3` | +| `shape?` | [`F3dShapes`](../enums/F3dShapes.md) | + +#### Returns + +`void` + +**`Description`** + +Init a rigid body for the model. + +#### Inherited from + +[FModel](FModel.md).[initRigidBody](FModel.md#initrigidbody) + +#### Defined in + +[src/model/FModel.ts:96](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L96) ___ @@ -114,7 +150,7 @@ ___ #### Defined in -src/model/FGLTF.ts:86 +[src/model/FGLTF.ts:94](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FGLTF.ts#L94) ___ @@ -134,7 +170,127 @@ ___ #### Defined in -src/model/FGLTF.ts:89 +[src/model/FGLTF.ts:98](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FGLTF.ts#L98) + +___ + +### setPosition + +▸ **setPosition**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the position of the model. + +#### Inherited from + +[FModel](FModel.md).[setPosition](FModel.md#setposition) + +#### Defined in + +[src/model/FModel.ts:49](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L49) + +___ + +### setRotation + +▸ **setRotation**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the model. + +#### Inherited from + +[FModel](FModel.md).[setRotation](FModel.md#setrotation) + +#### Defined in + +[src/model/FModel.ts:69](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L69) + +___ + +### setRotationDegree + +▸ **setRotationDegree**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the model from degrees. + +#### Inherited from + +[FModel](FModel.md).[setRotationDegree](FModel.md#setrotationdegree) + +#### Defined in + +[src/model/FModel.ts:78](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L78) + +___ + +### setScale + +▸ **setScale**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the scale of the model. + +#### Inherited from + +[FModel](FModel.md).[setScale](FModel.md#setscale) + +#### Defined in + +[src/model/FModel.ts:60](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L60) ## Properties @@ -148,7 +304,7 @@ src/model/FGLTF.ts:89 #### Defined in -src/model/FModel.ts:20 +[src/model/FModel.ts:22](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L22) ___ @@ -162,7 +318,7 @@ ___ #### Defined in -src/model/FModel.ts:17 +[src/model/FModel.ts:19](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L19) ___ @@ -172,7 +328,7 @@ ___ #### Defined in -src/model/FGLTF.ts:41 +[src/model/FGLTF.ts:41](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FGLTF.ts#L41) ___ @@ -186,7 +342,7 @@ ___ #### Defined in -src/model/FModel.ts:13 +[src/model/FModel.ts:15](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L15) ___ @@ -200,7 +356,7 @@ ___ #### Defined in -src/model/FModel.ts:19 +[src/model/FModel.ts:21](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L21) ___ @@ -214,7 +370,7 @@ ___ #### Defined in -src/model/FModel.ts:15 +[src/model/FModel.ts:17](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L17) ___ @@ -228,7 +384,7 @@ ___ #### Defined in -src/model/FModel.ts:14 +[src/model/FModel.ts:16](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L16) ___ @@ -242,7 +398,7 @@ ___ #### Defined in -src/model/FModel.ts:12 +[src/model/FModel.ts:14](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L14) ___ @@ -252,4 +408,4 @@ ___ #### Defined in -src/model/FGLTF.ts:40 +[src/model/FGLTF.ts:40](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FGLTF.ts#L40) diff --git a/docs/api/classes/FGameCamera.md b/docs/api/classes/FGameCamera.md index 545df344..b2fef4a2 100644 --- a/docs/api/classes/FGameCamera.md +++ b/docs/api/classes/FGameCamera.md @@ -80,10 +80,13 @@ export default class MyGameCamera extends FGameCamera { - [rotateZ](FGameCamera.md#rotatez) - [setFocalLength](FGameCamera.md#setfocallength) - [setLens](FGameCamera.md#setlens) +- [setPosition](FGameCamera.md#setposition) +- [setRotation](FGameCamera.md#setrotation) - [setRotationFromAxisAngle](FGameCamera.md#setrotationfromaxisangle) - [setRotationFromEuler](FGameCamera.md#setrotationfromeuler) - [setRotationFromMatrix](FGameCamera.md#setrotationfrommatrix) - [setRotationFromQuaternion](FGameCamera.md#setrotationfromquaternion) +- [setScale](FGameCamera.md#setscale) - [setViewOffset](FGameCamera.md#setviewoffset) - [toJSON](FGameCamera.md#tojson) - [translateOnAxis](FGameCamera.md#translateonaxis) @@ -176,7 +179,7 @@ export default class MyGameCamera extends FGameCamera { #### Defined in -src/cameras/FGameCamera.ts:33 +[src/cameras/FGameCamera.ts:33](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FGameCamera.ts#L33) ## Methods @@ -1188,7 +1191,7 @@ ___ #### Defined in -src/cameras/FGameCamera.ts:38 +[src/cameras/FGameCamera.ts:38](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FGameCamera.ts#L38) ___ @@ -1545,6 +1548,66 @@ node_modules/@types/three/src/cameras/PerspectiveCamera.d.ts:222 ___ +### setPosition + +▸ **setPosition**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the position of the camera. + +#### Inherited from + +[FOrbitCamera](FOrbitCamera.md).[setPosition](FOrbitCamera.md#setposition) + +#### Defined in + +[src/cameras/FOrbitCamera.ts:51](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FOrbitCamera.ts#L51) + +___ + +### setRotation + +▸ **setRotation**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the camera. + +#### Inherited from + +[FOrbitCamera](FOrbitCamera.md).[setRotation](FOrbitCamera.md#setrotation) + +#### Defined in + +[src/cameras/FCamera.ts:32](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L32) + +___ + ### setRotationFromAxisAngle ▸ **setRotationFromAxisAngle**(`axis`, `angle`): `void` @@ -1654,6 +1717,36 @@ node_modules/@types/three/src/core/Object3D.d.ts:370 ___ +### setScale + +▸ **setScale**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the scale of the camera. + +#### Inherited from + +[FOrbitCamera](FOrbitCamera.md).[setScale](FOrbitCamera.md#setscale) + +#### Defined in + +[src/cameras/FCamera.ts:25](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L25) + +___ + ### setViewOffset ▸ **setViewOffset**(`fullWidth`, `fullHeight`, `x`, `y`, `width`, `height`): `void` @@ -2128,7 +2221,7 @@ ___ #### Defined in -src/cameras/FOrbitCamera.ts:27 +[src/cameras/FOrbitCamera.ts:27](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FOrbitCamera.ts#L27) ___ @@ -2186,7 +2279,7 @@ ___ #### Defined in -src/cameras/FOrbitCamera.ts:29 +[src/cameras/FOrbitCamera.ts:29](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FOrbitCamera.ts#L29) ___ @@ -2775,7 +2868,7 @@ ___ #### Defined in -src/cameras/FGameCamera.ts:27 +[src/cameras/FGameCamera.ts:27](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FGameCamera.ts#L27) ___ diff --git a/docs/api/classes/FModel.md b/docs/api/classes/FModel.md index acde744b..dbef6063 100644 --- a/docs/api/classes/FModel.md +++ b/docs/api/classes/FModel.md @@ -28,7 +28,12 @@ The base class for all models in FibboJS. ### Methods +- [initRigidBody](FModel.md#initrigidbody) - [onFrame](FModel.md#onframe) +- [setPosition](FModel.md#setposition) +- [setRotation](FModel.md#setrotation) +- [setRotationDegree](FModel.md#setrotationdegree) +- [setScale](FModel.md#setscale) ### Properties @@ -58,10 +63,37 @@ The base class for all models in FibboJS. #### Defined in -src/model/FModel.ts:25 +[src/model/FModel.ts:27](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L27) ## Methods +### initRigidBody + +▸ **initRigidBody**(`position?`, `scale?`, `rotation?`, `shape?`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `position?` | `Vector3` | +| `scale?` | `Vector3` | +| `rotation?` | `Vector3` | +| `shape?` | [`F3dShapes`](../enums/F3dShapes.md) | + +#### Returns + +`void` + +**`Description`** + +Init a rigid body for the model. + +#### Defined in + +[src/model/FModel.ts:96](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L96) + +___ + ### onFrame ▸ **onFrame**(`_delta`): `void` @@ -82,7 +114,123 @@ src/model/FModel.ts:25 #### Defined in -src/model/FModel.ts:38 +[src/model/FModel.ts:36](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L36) + +___ + +### setPosition + +▸ **setPosition**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the position of the model. + +#### Implementation of + +[FComponent](FComponent.md).[setPosition](FComponent.md#setposition) + +#### Defined in + +[src/model/FModel.ts:49](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L49) + +___ + +### setRotation + +▸ **setRotation**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the model. + +#### Implementation of + +[FComponent](FComponent.md).[setRotation](FComponent.md#setrotation) + +#### Defined in + +[src/model/FModel.ts:69](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L69) + +___ + +### setRotationDegree + +▸ **setRotationDegree**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the model from degrees. + +#### Defined in + +[src/model/FModel.ts:78](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L78) + +___ + +### setScale + +▸ **setScale**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the scale of the model. + +#### Implementation of + +[FComponent](FComponent.md).[setScale](FComponent.md#setscale) + +#### Defined in + +[src/model/FModel.ts:60](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L60) ## Properties @@ -92,7 +240,7 @@ src/model/FModel.ts:38 #### Defined in -src/model/FModel.ts:20 +[src/model/FModel.ts:22](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L22) ___ @@ -102,7 +250,7 @@ ___ #### Defined in -src/model/FModel.ts:17 +[src/model/FModel.ts:19](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L19) ___ @@ -112,7 +260,7 @@ ___ #### Defined in -src/model/FModel.ts:13 +[src/model/FModel.ts:15](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L15) ___ @@ -122,7 +270,7 @@ ___ #### Defined in -src/model/FModel.ts:19 +[src/model/FModel.ts:21](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L21) ___ @@ -132,7 +280,7 @@ ___ #### Defined in -src/model/FModel.ts:15 +[src/model/FModel.ts:17](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L17) ___ @@ -142,7 +290,7 @@ ___ #### Defined in -src/model/FModel.ts:14 +[src/model/FModel.ts:16](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L16) ___ @@ -152,4 +300,4 @@ ___ #### Defined in -src/model/FModel.ts:12 +[src/model/FModel.ts:14](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L14) diff --git a/docs/api/classes/FOrbitCamera.md b/docs/api/classes/FOrbitCamera.md index cf5494b7..bc11dc90 100644 --- a/docs/api/classes/FOrbitCamera.md +++ b/docs/api/classes/FOrbitCamera.md @@ -82,10 +82,13 @@ export default class MyOrbitCamera extends FOrbitCamera { - [rotateZ](FOrbitCamera.md#rotatez) - [setFocalLength](FOrbitCamera.md#setfocallength) - [setLens](FOrbitCamera.md#setlens) +- [setPosition](FOrbitCamera.md#setposition) +- [setRotation](FOrbitCamera.md#setrotation) - [setRotationFromAxisAngle](FOrbitCamera.md#setrotationfromaxisangle) - [setRotationFromEuler](FOrbitCamera.md#setrotationfromeuler) - [setRotationFromMatrix](FOrbitCamera.md#setrotationfrommatrix) - [setRotationFromQuaternion](FOrbitCamera.md#setrotationfromquaternion) +- [setScale](FOrbitCamera.md#setscale) - [setViewOffset](FOrbitCamera.md#setviewoffset) - [toJSON](FOrbitCamera.md#tojson) - [translateOnAxis](FOrbitCamera.md#translateonaxis) @@ -177,7 +180,7 @@ export default class MyOrbitCamera extends FOrbitCamera { #### Defined in -src/cameras/FOrbitCamera.ts:35 +[src/cameras/FOrbitCamera.ts:35](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FOrbitCamera.ts#L35) ## Methods @@ -1189,7 +1192,7 @@ ___ #### Defined in -src/cameras/FOrbitCamera.ts:43 +[src/cameras/FOrbitCamera.ts:43](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FOrbitCamera.ts#L43) ___ @@ -1546,6 +1549,66 @@ node_modules/@types/three/src/cameras/PerspectiveCamera.d.ts:222 ___ +### setPosition + +▸ **setPosition**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the position of the camera. + +#### Overrides + +[FCamera](FCamera.md).[setPosition](FCamera.md#setposition) + +#### Defined in + +[src/cameras/FOrbitCamera.ts:51](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FOrbitCamera.ts#L51) + +___ + +### setRotation + +▸ **setRotation**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the camera. + +#### Inherited from + +[FCamera](FCamera.md).[setRotation](FCamera.md#setrotation) + +#### Defined in + +[src/cameras/FCamera.ts:32](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L32) + +___ + ### setRotationFromAxisAngle ▸ **setRotationFromAxisAngle**(`axis`, `angle`): `void` @@ -1655,6 +1718,36 @@ node_modules/@types/three/src/core/Object3D.d.ts:370 ___ +### setScale + +▸ **setScale**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the scale of the camera. + +#### Inherited from + +[FCamera](FCamera.md).[setScale](FCamera.md#setscale) + +#### Defined in + +[src/cameras/FCamera.ts:25](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FCamera.ts#L25) + +___ + ### setViewOffset ▸ **setViewOffset**(`fullWidth`, `fullHeight`, `x`, `y`, `width`, `height`): `void` @@ -2125,7 +2218,7 @@ ___ #### Defined in -src/cameras/FOrbitCamera.ts:27 +[src/cameras/FOrbitCamera.ts:27](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FOrbitCamera.ts#L27) ___ @@ -2179,7 +2272,7 @@ ___ #### Defined in -src/cameras/FOrbitCamera.ts:29 +[src/cameras/FOrbitCamera.ts:29](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/cameras/FOrbitCamera.ts#L29) ___ diff --git a/docs/api/classes/FScene.md b/docs/api/classes/FScene.md index 11a04484..a0af2e92 100644 --- a/docs/api/classes/FScene.md +++ b/docs/api/classes/FScene.md @@ -32,7 +32,6 @@ scene.addModel(cube) ### Properties - [camera](FScene.md#camera) -- [cameraOffset](FScene.md#cameraoffset) - [controls](FScene.md#controls) - [debugCamera](FScene.md#debugcamera) - [gravity](FScene.md#gravity) @@ -59,7 +58,7 @@ scene.addModel(cube) #### Defined in -src/core/FScene.ts:36 +[src/core/FScene.ts:34](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L34) ## Methods @@ -73,7 +72,7 @@ src/core/FScene.ts:36 #### Defined in -src/core/FScene.ts:166 +[src/core/FScene.ts:164](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L164) ___ @@ -93,7 +92,7 @@ ___ #### Defined in -src/core/FScene.ts:150 +[src/core/FScene.ts:148](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L148) ___ @@ -107,7 +106,7 @@ ___ #### Defined in -src/core/FScene.ts:294 +[src/core/FScene.ts:294](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L294) ## Properties @@ -117,17 +116,7 @@ src/core/FScene.ts:294 #### Defined in -src/core/FScene.ts:28 - -___ - -### cameraOffset - -• **cameraOffset**: [`FVector3`](../interfaces/FVector3.md) - -#### Defined in - -src/core/FScene.ts:29 +[src/core/FScene.ts:27](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L27) ___ @@ -137,7 +126,7 @@ ___ #### Defined in -src/core/FScene.ts:31 +[src/core/FScene.ts:29](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L29) ___ @@ -147,7 +136,7 @@ ___ #### Defined in -src/core/FScene.ts:30 +[src/core/FScene.ts:28](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L28) ___ @@ -165,7 +154,7 @@ ___ #### Defined in -src/core/FScene.ts:33 +[src/core/FScene.ts:31](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L31) ___ @@ -175,7 +164,7 @@ ___ #### Defined in -src/core/FScene.ts:24 +[src/core/FScene.ts:23](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L23) ___ @@ -185,7 +174,7 @@ ___ #### Defined in -src/core/FScene.ts:27 +[src/core/FScene.ts:26](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L26) ___ @@ -195,7 +184,7 @@ ___ #### Defined in -src/core/FScene.ts:26 +[src/core/FScene.ts:25](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L25) ___ @@ -205,4 +194,4 @@ ___ #### Defined in -src/core/FScene.ts:34 +[src/core/FScene.ts:32](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/core/FScene.ts#L32) diff --git a/docs/api/classes/FSphere.md b/docs/api/classes/FSphere.md index 4491e56b..6cfc631a 100644 --- a/docs/api/classes/FSphere.md +++ b/docs/api/classes/FSphere.md @@ -37,7 +37,12 @@ export class MySphere extends FSphere { ### Methods +- [initRigidBody](FSphere.md#initrigidbody) - [onFrame](FSphere.md#onframe) +- [setPosition](FSphere.md#setposition) +- [setRotation](FSphere.md#setrotation) +- [setRotationDegree](FSphere.md#setrotationdegree) +- [setScale](FSphere.md#setscale) ### Properties @@ -71,10 +76,41 @@ export class MySphere extends FSphere { #### Defined in -src/model/FSphere.ts:31 +[src/model/FSphere.ts:32](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FSphere.ts#L32) ## Methods +### initRigidBody + +▸ **initRigidBody**(`position?`, `scale?`, `rotation?`, `shape?`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `position?` | `Vector3` | +| `scale?` | `Vector3` | +| `rotation?` | `Vector3` | +| `shape?` | [`F3dShapes`](../enums/F3dShapes.md) | + +#### Returns + +`void` + +**`Description`** + +Init a rigid body for the model. + +#### Overrides + +[FModel](FModel.md).[initRigidBody](FModel.md#initrigidbody) + +#### Defined in + +[src/model/FSphere.ts:44](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FSphere.ts#L44) + +___ + ### onFrame ▸ **onFrame**(`_delta`): `void` @@ -95,7 +131,127 @@ src/model/FSphere.ts:31 #### Defined in -src/model/FSphere.ts:39 +[src/model/FSphere.ts:40](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FSphere.ts#L40) + +___ + +### setPosition + +▸ **setPosition**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the position of the model. + +#### Inherited from + +[FModel](FModel.md).[setPosition](FModel.md#setposition) + +#### Defined in + +[src/model/FModel.ts:49](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L49) + +___ + +### setRotation + +▸ **setRotation**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the model. + +#### Inherited from + +[FModel](FModel.md).[setRotation](FModel.md#setrotation) + +#### Defined in + +[src/model/FModel.ts:69](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L69) + +___ + +### setRotationDegree + +▸ **setRotationDegree**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the rotation of the model from degrees. + +#### Inherited from + +[FModel](FModel.md).[setRotationDegree](FModel.md#setrotationdegree) + +#### Defined in + +[src/model/FModel.ts:78](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L78) + +___ + +### setScale + +▸ **setScale**(`x`, `y`, `z`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `x` | `number` | +| `y` | `number` | +| `z` | `number` | + +#### Returns + +`void` + +**`Description`** + +Set the scale of the model. + +#### Inherited from + +[FModel](FModel.md).[setScale](FModel.md#setscale) + +#### Defined in + +[src/model/FModel.ts:60](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L60) ## Properties @@ -109,7 +265,7 @@ src/model/FSphere.ts:39 #### Defined in -src/model/FModel.ts:20 +[src/model/FModel.ts:22](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L22) ___ @@ -126,7 +282,7 @@ directly available after the constructor, as the cube is created synchronously. #### Defined in -src/model/FSphere.ts:29 +[src/model/FSphere.ts:30](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FSphere.ts#L30) ___ @@ -140,7 +296,7 @@ ___ #### Defined in -src/model/FModel.ts:13 +[src/model/FModel.ts:15](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L15) ___ @@ -154,7 +310,7 @@ ___ #### Defined in -src/model/FModel.ts:19 +[src/model/FModel.ts:21](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L21) ___ @@ -168,7 +324,7 @@ ___ #### Defined in -src/model/FModel.ts:15 +[src/model/FModel.ts:17](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L17) ___ @@ -182,7 +338,7 @@ ___ #### Defined in -src/model/FModel.ts:14 +[src/model/FModel.ts:16](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L16) ___ @@ -196,4 +352,4 @@ ___ #### Defined in -src/model/FModel.ts:12 +[src/model/FModel.ts:14](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/model/FModel.ts#L14) diff --git a/docs/api/enums/F3dShapes.md b/docs/api/enums/F3dShapes.md index fa949b9c..c05d156a 100644 --- a/docs/api/enums/F3dShapes.md +++ b/docs/api/enums/F3dShapes.md @@ -17,7 +17,7 @@ #### Defined in -src/types/F3dShapes.ts:3 +[src/types/F3dShapes.ts:3](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/types/F3dShapes.ts#L3) ___ @@ -27,4 +27,4 @@ ___ #### Defined in -src/types/F3dShapes.ts:4 +[src/types/F3dShapes.ts:4](https://github.com/fibbojs/fibbo/blob/4d4543b0732388b4480d2785a954ccaf7d85811f/src/types/F3dShapes.ts#L4) diff --git a/docs/api/functions/useLookAt.md b/docs/api/functions/useLookAt.md deleted file mode 100644 index e0658658..00000000 --- a/docs/api/functions/useLookAt.md +++ /dev/null @@ -1,41 +0,0 @@ -[@fibbojs/fibbo](/api/index) / useLookAt - -# Function: useLookAt - -▸ **useLookAt**(`position?`): `Function` - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `position` | [`FVector3`](../interfaces/FVector3.md) | The position to look at. | - -#### Returns - -`Function` - -The class with the look at behavior added. - -**`Description`** - -This decorator is used to make a camera look at a specific position. - -**`Example`** - -```ts -import { FFixedCamera, useLookAt } from '@fibbojs/fibbo' - -@useLookAt({ x: 1, y: 1, z: 1 }) -export class MyCamera extends FFixedCamera { - constructor() { - super() - } - - onFrame(_delta: number) { - } -} -``` - -#### Defined in - -[src/decorators/useLookAt.ts:23](https://github.com/fibbojs/fibbo/blob/5920737a801142e4f9dd76a2bdfcee7b009224d4/src/decorators/useLookAt.ts#L23) diff --git a/docs/api/functions/usePosition.md b/docs/api/functions/usePosition.md deleted file mode 100644 index 092c073f..00000000 --- a/docs/api/functions/usePosition.md +++ /dev/null @@ -1,44 +0,0 @@ -[@fibbojs/fibbo](/api/index) / usePosition - -# Function: usePosition - -▸ **usePosition**(`position?`): `Function` - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `position` | [`FVector3`](../interfaces/FVector3.md) | The position to be applied. | - -#### Returns - -`Function` - -The FComponent with the position altered. - -**`Description`** - -This decorator is used to alter the position of a FComponent (like a FModel or a FCamera). -It must be placed before useRigidBody. - -**`Example`** - -```ts -import { FCube, usePosition } from '@fibbojs/fibbo' -import type { FScene } from '@fibbojs/fibbo' - -@usePosition({ x: 1, y: 1, z: 1 }) -export class MyCube extends FCube { - constructor(scene: FScene) { - super(scene) - } - - onFrame(delta: number) { - super.onFrame(delta) - } -} -``` - -#### Defined in - -[src/decorators/usePosition.ts:30](https://github.com/fibbojs/fibbo/blob/5920737a801142e4f9dd76a2bdfcee7b009224d4/src/decorators/usePosition.ts#L30) diff --git a/docs/api/functions/useRigidBody.md b/docs/api/functions/useRigidBody.md deleted file mode 100644 index 55f81f39..00000000 --- a/docs/api/functions/useRigidBody.md +++ /dev/null @@ -1,50 +0,0 @@ -[@fibbojs/fibbo](/api/index) / useRigidBody - -# Function: useRigidBody - -▸ **useRigidBody**(`position?`, `scale?`, `rotation?`, `shape?`): `Function` - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `position?` | [`FVector3`](../interfaces/FVector3.md) | Position of the rigid body. | -| `scale?` | [`FVector3`](../interfaces/FVector3.md) | Scale of the rigid body. | -| `rotation?` | [`FVector3`](../interfaces/FVector3.md) | Rotation of the rigid body. | -| `shape?` | [`F3dShapes`](../enums/F3dShapes.md) | Shape of the rigid body. | - -#### Returns - -`Function` - -The class with the rigid body added. - -**`Description`** - -This decorator is used to add a rigid body to a FModel (like FCube, FGLTF, etc). - -If no position, scale or rotation is provided, the default values of the FModel will be used. - -If no shape is provided, the decorator will try to detect a supported polygonal shape, otherwise it will default to a cube. - -**`Example`** - -```ts -import { FCube, useRigidBody } from '@fibbojs/fibbo' -import type { FScene } from '../FScene' - -@useRigidBody() -export class MyCube extends FCube { - constructor(scene: FScene) { - super(scene) - } - - onFrame(delta: number) { - super.onFrame(delta) - } -} -``` - -#### Defined in - -[src/decorators/useRigidBody.ts:37](https://github.com/fibbojs/fibbo/blob/5920737a801142e4f9dd76a2bdfcee7b009224d4/src/decorators/useRigidBody.ts#L37) diff --git a/docs/api/functions/useRotation.md b/docs/api/functions/useRotation.md deleted file mode 100644 index 2bb98f12..00000000 --- a/docs/api/functions/useRotation.md +++ /dev/null @@ -1,44 +0,0 @@ -[@fibbojs/fibbo](/api/index) / useRotation - -# Function: useRotation - -▸ **useRotation**(`rotation?`): `Function` - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `rotation` | [`FVector3`](../interfaces/FVector3.md) | The rotation to be applied. | - -#### Returns - -`Function` - -The class with the rotation altered. - -**`Description`** - -This decorator is used to alter the rotation of a FModel (like FCube, FGLTF, etc). -It must be placed before useRigidBody. - -**`Example`** - -```ts -import { FCube, useRotation } from '@fibbojs/fibbo' -import type { FScene } from '@fibbojs/fibbo' - -@useRotation({ x: 1, y: 0, z: 0 }) -export class MyCube extends FCube { - constructor(scene: FScene) { - super(scene) - } - - onFrame(delta: number) { - super.onFrame(delta) - } -} -``` - -#### Defined in - -[src/decorators/useRotation.ts:27](https://github.com/fibbojs/fibbo/blob/5920737a801142e4f9dd76a2bdfcee7b009224d4/src/decorators/useRotation.ts#L27) diff --git a/docs/api/functions/useRotationDegree.md b/docs/api/functions/useRotationDegree.md deleted file mode 100644 index 715b8904..00000000 --- a/docs/api/functions/useRotationDegree.md +++ /dev/null @@ -1,44 +0,0 @@ -[@fibbojs/fibbo](/api/index) / useRotationDegree - -# Function: useRotationDegree - -▸ **useRotationDegree**(`rotation?`): `Function` - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `rotation` | [`FVector3`](../interfaces/FVector3.md) | The rotation to be applied. | - -#### Returns - -`Function` - -The class with the rotation altered. - -**`Description`** - -This decorator is used to alter the rotation of a FModel (like FCube, FGLTF, etc), using degrees. -It must be placed before useRigidBody. - -**`Example`** - -```ts -import { FCube, useRotationDegree } from '@fibbojs/fibbo' -import type { FScene } from '@fibbojs/fibbo' - -@useRotationDegree({ x: 90, y: 0, z: 0 }) -export class MyCube extends FCube { - constructor(scene: FScene) { - super(scene) - } - - onFrame(delta: number) { - super.onFrame(delta) - } -} -``` - -#### Defined in - -[src/decorators/useRotationDegree.ts:27](https://github.com/fibbojs/fibbo/blob/5920737a801142e4f9dd76a2bdfcee7b009224d4/src/decorators/useRotationDegree.ts#L27) diff --git a/docs/api/functions/useScale.md b/docs/api/functions/useScale.md deleted file mode 100644 index a76c0bd0..00000000 --- a/docs/api/functions/useScale.md +++ /dev/null @@ -1,44 +0,0 @@ -[@fibbojs/fibbo](/api/index) / useScale - -# Function: useScale - -▸ **useScale**(`scale?`): `Function` - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `scale` | [`FVector3`](../interfaces/FVector3.md) | The scale to be applied. | - -#### Returns - -`Function` - -The class with the scale altered. - -**`Description`** - -This decorator is used to alter the scale of a FModel (like FCube, FGLTF, etc). -It must be placed before useRigidBody. - -**`Example`** - -```ts -import { FCube, useScale } from '@fibbojs/fibbo' -import type { FScene } from '@fibbojs/fibbo' - -@useScale({ x: 1, y: 1, z: 1 }) -export class MyCube extends FCube { - constructor(scene: FScene) { - super(scene) - } - - onFrame(delta: number) { - super.onFrame(delta) - } -} -``` - -#### Defined in - -[src/decorators/useScale.ts:27](https://github.com/fibbojs/fibbo/blob/5920737a801142e4f9dd76a2bdfcee7b009224d4/src/decorators/useScale.ts#L27) diff --git a/docs/api/index.md b/docs/api/index.md index 6be5cf11..056bbd31 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -24,19 +24,6 @@ - [FModel](classes/FModel.md) - [FSphere](classes/FSphere.md) -### Functions - -- [useLookAt](functions/useLookAt.md) -- [usePosition](functions/usePosition.md) -- [useRigidBody](functions/useRigidBody.md) -- [useRotation](functions/useRotation.md) -- [useRotationDegree](functions/useRotationDegree.md) -- [useScale](functions/useScale.md) - ### Enumerations - [F3dShapes](enums/F3dShapes.md) - -### Interfaces - -- [FVector3](interfaces/FVector3.md) diff --git a/docs/api/interfaces/FVector3.md b/docs/api/interfaces/FVector3.md deleted file mode 100644 index 788949d1..00000000 --- a/docs/api/interfaces/FVector3.md +++ /dev/null @@ -1,41 +0,0 @@ -[@fibbojs/fibbo](/api/index) / FVector3 - -# Interface: FVector3 - -## Table of contents - -### Properties - -- [x](FVector3.md#x) -- [y](FVector3.md#y) -- [z](FVector3.md#z) - -## Properties - -### x - -• **x**: `number` - -#### Defined in - -src/types/FVector3.ts:3 - -___ - -### y - -• **y**: `number` - -#### Defined in - -src/types/FVector3.ts:4 - -___ - -### z - -• **z**: `number` - -#### Defined in - -src/types/FVector3.ts:5 diff --git a/playground/src/cameras/MyAttachedCamera.ts b/playground/src/cameras/MyAttachedCamera.ts index a984b2e4..841a64bd 100644 --- a/playground/src/cameras/MyAttachedCamera.ts +++ b/playground/src/cameras/MyAttachedCamera.ts @@ -1,10 +1,10 @@ -import { FAttachedCamera, usePosition } from '@fibbojs/fibbo' +import { FAttachedCamera } from '@fibbojs/fibbo' import type { FModel } from '@fibbojs/fibbo' -@usePosition({ x: 0, y: 5, z: 5 }) export default class MyAttachedCamera extends FAttachedCamera { constructor(attachedModel: FModel) { super(attachedModel) + this.setPosition(0, 5, 5) } onFrame(delta: number) { diff --git a/playground/src/cameras/MyCamera.ts b/playground/src/cameras/MyCamera.ts index 372fdc9f..302bf1d7 100644 --- a/playground/src/cameras/MyCamera.ts +++ b/playground/src/cameras/MyCamera.ts @@ -1,10 +1,10 @@ -import { FFixedCamera, useLookAt, usePosition } from '@fibbojs/fibbo' +import { FFixedCamera } from '@fibbojs/fibbo' -@useLookAt({ x: 0, y: 0, z: 0 }) -@usePosition({ x: 5, y: 5, z: 5 }) export default class MyCamera extends FFixedCamera { constructor() { super() + this.setPosition(5, 5, 5) + this.lookAt(0, 0, 0) } onFrame(delta: number) { diff --git a/playground/src/cameras/MyGameCamera.ts b/playground/src/cameras/MyGameCamera.ts index 2e5d5b48..1c3d2513 100644 --- a/playground/src/cameras/MyGameCamera.ts +++ b/playground/src/cameras/MyGameCamera.ts @@ -1,10 +1,10 @@ -import { FGameCamera, usePosition } from '@fibbojs/fibbo' +import { FGameCamera } from '@fibbojs/fibbo' import type { FModel, FScene } from '@fibbojs/fibbo' -@usePosition({ x: 0, y: 5, z: 5 }) export default class MyGameCamera extends FGameCamera { constructor(attachedModel: FModel, scene: FScene) { super(attachedModel, scene) + this.setPosition(0, 5, 5) } onFrame(delta: number) { diff --git a/playground/src/classes/GltfCube.ts b/playground/src/classes/GltfCube.ts index 7a3228fc..b2faff72 100644 --- a/playground/src/classes/GltfCube.ts +++ b/playground/src/classes/GltfCube.ts @@ -1,13 +1,13 @@ -import { FGLTF, usePosition, useRigidBody, useRotationDegree, useScale } from '@fibbojs/fibbo' +import { FGLTF } from '@fibbojs/fibbo' import type { FScene } from '@fibbojs/fibbo' -@useRigidBody() -@usePosition({ x: -4, y: 5, z: 2 }) -@useScale({ x: 2, y: 0.25, z: 2 }) -@useRotationDegree({ x: 20, y: 0, z: 0 }) export default class GltfCube extends FGLTF { constructor(scene: FScene) { super(scene, 'Cube.gltf') + this.setPosition(-4, 5, 2) + this.setScale(2, 0.25, 2) + this.setRotationDegree(20, 0, 0) + this.initRigidBody() } onFrame(delta: number) { diff --git a/playground/src/classes/MyCube.ts b/playground/src/classes/MyCube.ts index b256bf7b..1cdfe9a2 100644 --- a/playground/src/classes/MyCube.ts +++ b/playground/src/classes/MyCube.ts @@ -1,13 +1,13 @@ -import { FCube, usePosition, useRigidBody, useRotationDegree, useScale } from '@fibbojs/fibbo' +import { FCube } from '@fibbojs/fibbo' import type { FScene } from '@fibbojs/fibbo' -@useRigidBody() -@usePosition({ x: 4, y: 5, z: -2 }) -@useScale({ x: 2, y: 0.5, z: 1 }) -@useRotationDegree({ x: 60, y: 0, z: 0 }) export default class MyCube extends FCube { constructor(scene: FScene) { super(scene) + this.setPosition(4, 5, -2) + this.setScale(2, 0.5, 1) + this.setRotationDegree(60, 0, 0) + this.initRigidBody() } onFrame(delta: number) { diff --git a/playground/src/classes/MySphere.ts b/playground/src/classes/MySphere.ts index ec13b3f8..9db84da6 100644 --- a/playground/src/classes/MySphere.ts +++ b/playground/src/classes/MySphere.ts @@ -1,11 +1,11 @@ -import { FSphere, usePosition, useRigidBody } from '@fibbojs/fibbo' +import { FSphere } from '@fibbojs/fibbo' import type { FScene } from '@fibbojs/fibbo' -@useRigidBody() -@usePosition({ x: -2, y: 3, z: -2 }) export default class MySphere extends FSphere { constructor(scene: FScene) { super(scene) + this.setPosition(-2, 3, -2) + this.initRigidBody() } onFrame(delta: number) { diff --git a/playground/src/main.ts b/playground/src/main.ts index 56f16837..efc11c5b 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -1,5 +1,5 @@ import './style.css' -import { FScene } from '@fibbojs/fibbo' +import { FCube, FScene } from '@fibbojs/fibbo' import MyCube from './classes/MyCube' import MySphere from './classes/MySphere' import Duck from './classes/Duck' @@ -20,6 +20,17 @@ scene.addModel(duck) const gltfCube = new GltfCube(scene) scene.addModel(gltfCube) +// Create 8 cubes dynamically in circle from 0 to 2PI +for (let i = 0; i < 8; i++) { + const angle = i * Math.PI / 4 + const x = Math.cos(angle) * 4 + const z = Math.sin(angle) * 4 + const cube = new FCube(scene) + cube.setPosition(x, 1, z) + cube.initRigidBody() + scene.addModel(cube) +} + scene.camera = new MyGameCamera(gltfCube, scene) // Detect inputs to move the cube @@ -39,7 +50,7 @@ document.addEventListener('keydown', (event) => { impulse.x = 1 break case ' ': - impulse.y = 5 + gltfCube.rigidBody?.applyImpulse({ x: 0, y: 5, z: 0 }, true) break } gltfCube.rigidBody?.applyImpulse(impulse, true) diff --git a/src/cameras/FAttachedCamera.ts b/src/cameras/FAttachedCamera.ts index 3a89289b..58ba95a2 100644 --- a/src/cameras/FAttachedCamera.ts +++ b/src/cameras/FAttachedCamera.ts @@ -1,4 +1,4 @@ -import type { FVector3 } from '../types/FVector3' +import * as THREE from 'three' import type { FModel } from '../model/FModel' import { FCamera } from './FCamera' @@ -25,7 +25,7 @@ export class FAttachedCamera extends FCamera { // Model that the camera is attached to attachedModel: FModel // Offset from the model's position - offset: FVector3 = { x: 0, y: 5, z: 5 } + offset: THREE.Vector3 = new THREE.Vector3(0, 5, 5) /** * @param attachedModel Model that the camera is attached to @@ -46,4 +46,9 @@ export class FAttachedCamera extends FCamera { // Make the camera look at the model this.lookAt(this.attachedModel.object3D.position.x, this.attachedModel.object3D.position.y, this.attachedModel.object3D.position.z) } + + setPosition(x: number, y: number, z: number): void { + super.setPosition(x, y, z) + this.offset = new THREE.Vector3(x, y, z) + } } diff --git a/src/cameras/FCamera.ts b/src/cameras/FCamera.ts index fbd33058..8b9dff03 100644 --- a/src/cameras/FCamera.ts +++ b/src/cameras/FCamera.ts @@ -11,4 +11,25 @@ export abstract class FCamera extends THREE.PerspectiveCamera implements FCompon } abstract onFrame(_delta: number): void + + /** + * @description Set the position of the camera. + */ + setPosition(x: number, y: number, z: number): void { + this.position.set(x, y, z) + } + + /** + * @description Set the scale of the camera. + */ + setScale(x: number, y: number, z: number): void { + this.scale.set(x, y, z) + } + + /** + * @description Set the rotation of the camera. + */ + setRotation(x: number, y: number, z: number): void { + this.rotation.set(x, y, z) + } } diff --git a/src/cameras/FFixedCamera.ts b/src/cameras/FFixedCamera.ts index 489cb255..a84ce88f 100644 --- a/src/cameras/FFixedCamera.ts +++ b/src/cameras/FFixedCamera.ts @@ -5,13 +5,13 @@ import { FCamera } from './FCamera' * @category Camera * @example * ```ts - * import { FFixedCamera, usePosition, useLookAt } from '@fibbojs/fibbo' + * import { FFixedCamera, } from '@fibbojs/fibbo' * - * @useLookAt({ x: 0, y: 0, z: 0 }) - * @usePosition({ x: 5, y: 5, z: 5 }) * export default class MyCamera extends FFixedCamera { * constructor() { * super() + * this.setPosition(5, 5, 5) + * this.lookAt(0, 0, 0) * } * * onFrame(delta: number) { diff --git a/src/cameras/FOrbitCamera.ts b/src/cameras/FOrbitCamera.ts index 0798c290..4f83e63a 100644 --- a/src/cameras/FOrbitCamera.ts +++ b/src/cameras/FOrbitCamera.ts @@ -47,4 +47,12 @@ export class FOrbitCamera extends FCamera { this.controls.target = this.attachedModel.object3D.position this.controls.update() } + + setPosition(x: number, y: number, z: number): void { + super.setPosition(x, y, z) + // Set the position of the camera relative to the attached model + this.position.set(this.attachedModel.position.x + x, this.attachedModel.position.y + y, this.attachedModel.position.z + z) + // Set the target of the camera to the attached model + this.lookAt(this.attachedModel.position) + } } diff --git a/src/core/FComponent.ts b/src/core/FComponent.ts index 65ac4b84..6d7a4f2e 100644 --- a/src/core/FComponent.ts +++ b/src/core/FComponent.ts @@ -7,4 +7,19 @@ export abstract class FComponent { } abstract onFrame(_delta: number): void + + /** + * @description Set the position of the component. + */ + abstract setPosition(x: number, y: number, z: number): void + + /** + * @description Set the scale of the component. + */ + abstract setScale(x: number, y: number, z: number): void + + /** + * @description Set the rotation of the component. + */ + abstract setRotation(x: number, y: number, z: number): void } diff --git a/src/core/FScene.ts b/src/core/FScene.ts index 712f0867..e2919043 100644 --- a/src/core/FScene.ts +++ b/src/core/FScene.ts @@ -2,7 +2,6 @@ import * as THREE from 'three' import * as RAPIER from '@dimforge/rapier3d' import { OrbitControls } from 'three/addons/controls/OrbitControls.js' import type { World } from '@dimforge/rapier3d' -import type { FVector3 } from '../types/FVector3' import type { FModel } from '../model/FModel' import { FGLTF } from '../model/FGLTF' import { FCamera } from '../cameras/FCamera' @@ -26,7 +25,6 @@ export class FScene { scene: THREE.Scene renderer: THREE.WebGLRenderer camera: THREE.Camera - cameraOffset: FVector3 = { x: -5, y: 5, z: 5 } debugCamera: THREE.PerspectiveCamera controls: OrbitControls | undefined // Rapier @@ -207,6 +205,8 @@ export class FScene { border: 1px solid white; border-radius: 10px; color: white; + max-height: 90vh; + overflow-y: auto; } #camera-panel { diff --git a/src/decorators/useLookAt.ts b/src/decorators/useLookAt.ts deleted file mode 100644 index f917aabe..00000000 --- a/src/decorators/useLookAt.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { FCamera } from '../cameras/FCamera' -import type { FVector3 } from '../types/FVector3' - -/** - * @description This decorator is used to make a camera look at a specific position. - * @param position The position to look at. - * @returns {Function} The class with the look at behavior added. - * @example - * ```ts - * import { FFixedCamera, useLookAt } from '@fibbojs/fibbo' - * - * @useLookAt({ x: 1, y: 1, z: 1 }) - * export class MyCamera extends FFixedCamera { - * constructor() { - * super() - * } - * - * onFrame(_delta: number) { - * } - * } - * ``` - */ -export function useLookAt( - // Default position - position: FVector3 = { x: 1, y: 1, z: 1 }, -): Function { - return function (constructor: T) { - // Store original onFrame method - const originalOnFrame = constructor.prototype.onFrame - - // Return a new class with the rigid body added - const newClass = class extends constructor { - constructor(...args: any[]) { - super(...args) - - // Make the camera look at the position - this.lookAt(position.x, position.y, position.z) - } - - onFrame(_delta: number) { - // Call the original onFrame method - originalOnFrame.call(this, _delta) - } - } - - // Define constructor name - Object.defineProperty(newClass, 'name', { value: constructor.name }) - - return newClass - } -} diff --git a/src/decorators/usePosition.ts b/src/decorators/usePosition.ts deleted file mode 100644 index c7d3c62c..00000000 --- a/src/decorators/usePosition.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { FAttachedCamera } from '../cameras/FAttachedCamera' -import { FCamera } from '../cameras/FCamera' -import { FOrbitCamera } from '../cameras/FOrbitCamera' -import type { FComponent } from '../core/FComponent' -import { FModel } from '../model/FModel' -import type { FVector3 } from '../types/FVector3' - -/** - * @description This decorator is used to alter the position of a FComponent (like a FModel or a FCamera). - * It must be placed before useRigidBody. - * @param position The position to be applied. - * @returns {Function} The FComponent with the position altered. - * @example - * ```ts - * import { FCube, usePosition } from '@fibbojs/fibbo' - * import type { FScene } from '@fibbojs/fibbo' - * - * @usePosition({ x: 1, y: 1, z: 1 }) - * export class MyCube extends FCube { - * constructor(scene: FScene) { - * super(scene) - * } - * - * onFrame(delta: number) { - * super.onFrame(delta) - * } - * } - * ``` - */ -export function usePosition( - // Default position - position: FVector3 = { x: 1, y: 1, z: 1 }, -): Function { - return function (constructor: T) { - // Store original onFrame method - const originalOnFrame = constructor.prototype.onFrame - - // Return a new class with the rigid body added - const newClass = class extends constructor { - constructor(...args: any[]) { - super(...args) - - /** - * On FModel - */ - if (this instanceof FModel) { - // If the object3D exists, apply the position - if (this.object3D) - this.object3D.position.set(position.x, position.y, position.z) - - // Store the position - this.position.x = position.x - this.position.y = position.y - this.position.z = position.z - } - - /** - * On FCamera - */ - else if (this instanceof FCamera) { - // Store the position - this.position.x = position.x - this.position.y = position.y - this.position.z = position.z - - // On FAttachedCamera - if (this instanceof FAttachedCamera) { - // Define the offset using the position given - this.offset = { x: position.x, y: position.y, z: position.z } - } - // On FOrbitCamera - else if (this instanceof FOrbitCamera) { - // Set the position of the camera relative to the attached model - this.position.set(this.attachedModel.position.x + position.x, this.attachedModel.position.y + position.y, this.attachedModel.position.z + position.z) - // Set the target of the camera to the attached model - this.lookAt(this.attachedModel.position) - } - } - } - - onFrame(_delta: number) { - // Call the original onFrame method - originalOnFrame.call(this, _delta) - } - } - - // Define constructor name - Object.defineProperty(newClass, 'name', { value: constructor.name }) - - return newClass - } -} diff --git a/src/decorators/useRigidBody.ts b/src/decorators/useRigidBody.ts deleted file mode 100644 index c5160d1a..00000000 --- a/src/decorators/useRigidBody.ts +++ /dev/null @@ -1,129 +0,0 @@ -import * as THREE from 'three' -import * as RAPIER from '@dimforge/rapier3d' -import type { FModel } from '../model/FModel' -import type { FVector3 } from '../types/FVector3' -import { F3dShapes } from '../types/F3dShapes' -import { FSphere } from '../model/FSphere' - -/** - * @description - * This decorator is used to add a rigid body to a FModel (like FCube, FGLTF, etc). - * - * If no position, scale or rotation is provided, the default values of the FModel will be used. - * - * If no shape is provided, the decorator will try to detect a supported polygonal shape, otherwise it will default to a cube. - * @param position Position of the rigid body. - * @param scale Scale of the rigid body. - * @param rotation Rotation of the rigid body. - * @param shape Shape of the rigid body. - * @returns {Function} The class with the rigid body added. - * @example - * ```ts - * import { FCube, useRigidBody } from '@fibbojs/fibbo' - * import type { FScene } from '../FScene' - * - * @useRigidBody() - * export class MyCube extends FCube { - * constructor(scene: FScene) { - * super(scene) - * } - * - * onFrame(delta: number) { - * super.onFrame(delta) - * } - * } - * ``` - */ -export function useRigidBody( - position?: FVector3, - scale?: FVector3, - rotation?: FVector3, - shape?: F3dShapes, -): Function { - return function (constructor: T) { - // Store original onFrame method - const originalOnFrame = constructor.prototype.onFrame - - let rigidBodyPosition: FVector3 | undefined = position - let rigidBodyScale: FVector3 | undefined = scale - let rigidBodyRotation: FVector3 | undefined = rotation - - // Return a new class with the rigid body added - const newClass = class extends constructor { - constructor(...args: any[]) { - super(...args) - - // If position is not defined - if (!rigidBodyPosition) { - // Use default position of the FModel - rigidBodyPosition = { x: this.position.x, y: this.position.y, z: this.position.z } - } - - // If scale is not defined - if (!rigidBodyScale) { - // Use default scale of the FModel - rigidBodyScale = { x: this.scale.x, y: this.scale.y, z: this.scale.z } - } - - // Devide scale by 2 (RAPIER uses half-extents) - if (rigidBodyScale) { - rigidBodyScale.x /= 2 - rigidBodyScale.y /= 2 - rigidBodyScale.z /= 2 - } - - // If rotation is not defined - if (!rigidBodyRotation) { - // Use default rotation of the FModel - rigidBodyRotation = { x: this.rotation.x, y: this.rotation.y, z: this.rotation.z } - } - - // If a shape wasn't defined - if (!shape) { - // Detect if the model is a sphere, and set the shape to sphere - if (this instanceof FSphere) { - shape = F3dShapes.SPHERE - // Add 0.005 to scale so the collider looks better when debugging a ball - rigidBodyScale.x += 0.005 - } - else - // Default to cube - { shape = F3dShapes.CUBE } - } - - // Create a dynamic rigid-body. - const rigidBodyDesc = RAPIER.RigidBodyDesc.dynamic() - .setTranslation(rigidBodyPosition.x, rigidBodyPosition.y, rigidBodyPosition.z) - .setRotation( - // Create quaternion from Euler angles - new THREE.Quaternion().setFromEuler(new THREE.Euler(rigidBodyRotation.x, rigidBodyRotation.y, rigidBodyRotation.z)), - ) - - this.rigidBody = this.scene.world.createRigidBody(rigidBodyDesc) - - // Create a cuboid collider attached to the dynamic rigidBody. - const colliderDesc = shape === F3dShapes.CUBE - ? RAPIER.ColliderDesc.cuboid(rigidBodyScale.x, rigidBodyScale.y, rigidBodyScale.z) - : RAPIER.ColliderDesc.ball(rigidBodyScale.x) - this.collider = this.scene.world.createCollider(colliderDesc, this.rigidBody) - } - - onFrame(_delta: number) { - if (this.rigidBody && this.object3D) { - const newRigidBodyPosition = this.rigidBody.translation() - this.object3D.position.set(newRigidBodyPosition.x, newRigidBodyPosition.y, newRigidBodyPosition.z) - const newRigidBodyRotation = this.rigidBody.rotation() - this.object3D.setRotationFromQuaternion(new THREE.Quaternion(newRigidBodyRotation.x, newRigidBodyRotation.y, newRigidBodyRotation.z, newRigidBodyRotation.w)) - } - - // Call the original onFrame method - originalOnFrame.call(this, _delta) - } - } - - // Define constructor name - Object.defineProperty(newClass, 'name', { value: constructor.name }) - - return newClass - } -} diff --git a/src/decorators/useRotation.ts b/src/decorators/useRotation.ts deleted file mode 100644 index a7463377..00000000 --- a/src/decorators/useRotation.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as THREE from 'three' -import type { FModel } from '../model/FModel' -import type { FVector3 } from '../types/FVector3' - -/** - * @description This decorator is used to alter the rotation of a FModel (like FCube, FGLTF, etc). - * It must be placed before useRigidBody. - * @param rotation The rotation to be applied. - * @returns {Function} The class with the rotation altered. - * @example - * ```ts - * import { FCube, useRotation } from '@fibbojs/fibbo' - * import type { FScene } from '@fibbojs/fibbo' - * - * @useRotation({ x: 1, y: 0, z: 0 }) - * export class MyCube extends FCube { - * constructor(scene: FScene) { - * super(scene) - * } - * - * onFrame(delta: number) { - * super.onFrame(delta) - * } - * } - * ``` - */ -export function useRotation( - // Default rotation - rotation: FVector3 = { x: 1, y: 1, z: 1 }, -): Function { - return function (constructor: T) { - // Store original onFrame method - const originalOnFrame = constructor.prototype.onFrame - - // Return a new class with the rigid body added - const newClass = class extends constructor { - constructor(...args: any[]) { - super(...args) - - // If the object3D exists, apply the rotation - if (this.object3D) - this.object3D.rotation.set(rotation.x, rotation.y, rotation.z) - - // Store the rotation - this.rotation = new THREE.Vector3(rotation.x, rotation.y, rotation.z) - } - - onFrame(_delta: number) { - // Call the original onFrame method - originalOnFrame.call(this, _delta) - } - } - - // Define constructor name - Object.defineProperty(newClass, 'name', { value: constructor.name }) - - return newClass - } -} diff --git a/src/decorators/useRotationDegree.ts b/src/decorators/useRotationDegree.ts deleted file mode 100644 index fe27d095..00000000 --- a/src/decorators/useRotationDegree.ts +++ /dev/null @@ -1,39 +0,0 @@ -import * as THREE from 'three' -import type { FVector3 } from '../types/FVector3' -import { useRotation } from './useRotation' - -/** - * @description This decorator is used to alter the rotation of a FModel (like FCube, FGLTF, etc), using degrees. - * It must be placed before useRigidBody. - * @param rotation The rotation to be applied. - * @returns {Function} The class with the rotation altered. - * @example - * ```ts - * import { FCube, useRotationDegree } from '@fibbojs/fibbo' - * import type { FScene } from '@fibbojs/fibbo' - * - * @useRotationDegree({ x: 90, y: 0, z: 0 }) - * export class MyCube extends FCube { - * constructor(scene: FScene) { - * super(scene) - * } - * - * onFrame(delta: number) { - * super.onFrame(delta) - * } - * } - * ``` - */ -export function useRotationDegree( - // Default rotation - rotation: FVector3 = { x: 1, y: 1, z: 1 }, -): Function { - // Convert degrees to radians - const radRotation = { - x: THREE.MathUtils.degToRad(rotation.x), - y: THREE.MathUtils.degToRad(rotation.y), - z: THREE.MathUtils.degToRad(rotation.z), - } - - return useRotation(radRotation) -} diff --git a/src/decorators/useScale.ts b/src/decorators/useScale.ts deleted file mode 100644 index 96bf2437..00000000 --- a/src/decorators/useScale.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as THREE from 'three' -import type { FModel } from '../model/FModel' -import type { FVector3 } from '../types/FVector3' - -/** - * @description This decorator is used to alter the scale of a FModel (like FCube, FGLTF, etc). - * It must be placed before useRigidBody. - * @param scale The scale to be applied. - * @returns {Function} The class with the scale altered. - * @example - * ```ts - * import { FCube, useScale } from '@fibbojs/fibbo' - * import type { FScene } from '@fibbojs/fibbo' - * - * @useScale({ x: 1, y: 1, z: 1 }) - * export class MyCube extends FCube { - * constructor(scene: FScene) { - * super(scene) - * } - * - * onFrame(delta: number) { - * super.onFrame(delta) - * } - * } - * ``` - */ -export function useScale( - // Default scale - scale: FVector3 = { x: 1, y: 1, z: 1 }, -): Function { - return function (constructor: T) { - // Store original onFrame method - const originalOnFrame = constructor.prototype.onFrame - - // Return a new class with the rigid body added - const newClass = class extends constructor { - constructor(...args: any[]) { - super(...args) - - // If the object3D exists, apply the scale - if (this.object3D) - this.object3D.scale.set(scale.x, scale.y, scale.z) - - // Store the scale - this.scale = new THREE.Vector3(scale.x, scale.y, scale.z) - } - - onFrame(_delta: number) { - // Call the original onFrame method - originalOnFrame.call(this, _delta) - } - } - - // Define constructor name - Object.defineProperty(newClass, 'name', { value: constructor.name }) - - return newClass - } -} diff --git a/src/index.ts b/src/index.ts index ac93af2d..2a30d811 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,13 +9,6 @@ export { FModel } from './model/FModel' export { FCube } from './model/FCube' export { FSphere } from './model/FSphere' export { FGLTF } from './model/FGLTF' -// Decorators -export { usePosition } from './decorators/usePosition' -export { useScale } from './decorators/useScale' -export { useRotation } from './decorators/useRotation' -export { useRotationDegree } from './decorators/useRotationDegree' -export { useRigidBody } from './decorators/useRigidBody' -export { useLookAt } from './decorators/useLookAt' // Cameras export { FCamera } from './cameras/FCamera' export { FFixedCamera } from './cameras/FFixedCamera' @@ -24,5 +17,4 @@ export { FOrbitCamera } from './cameras/FOrbitCamera' export { FGameCamera } from './cameras/FGameCamera' // Types -export type { FVector3 } from './types/FVector3' export { F3dShapes } from './types/F3dShapes' diff --git a/src/model/FCube.ts b/src/model/FCube.ts index e5cc23cb..4bcef012 100644 --- a/src/model/FCube.ts +++ b/src/model/FCube.ts @@ -37,5 +37,6 @@ export class FCube extends FModel { } onFrame(_delta: number): void { + super.onFrame(_delta) } } diff --git a/src/model/FGLTF.ts b/src/model/FGLTF.ts index 2644f6b2..ec1f4340 100644 --- a/src/model/FGLTF.ts +++ b/src/model/FGLTF.ts @@ -65,10 +65,18 @@ export class FGLTF extends FModel { // Add the object to the scene this.object3D = gltf.scene + // If a position is defined, apply it + if (this.position) + this.object3D.position.set(this.position.x, this.position.y, this.position.z) + // If a scale is defined, apply it if (this.scale) this.object3D.scale.set(this.scale.x / 2, this.scale.y / 2, this.scale.z / 2) + // If a rotation is defined, apply it + if (this.rotation) + this.object3D.rotation.set(this.rotation.x, this.rotation.y, this.rotation.z) + // Call the onLoaded method this.emitOnLoaded() }, @@ -84,6 +92,7 @@ export class FGLTF extends FModel { } onFrame(_delta: number) { + super.onFrame(_delta) } onLoaded(fn: () => void) { diff --git a/src/model/FModel.ts b/src/model/FModel.ts index a49edbb0..f462a46c 100644 --- a/src/model/FModel.ts +++ b/src/model/FModel.ts @@ -1,7 +1,9 @@ import * as THREE from 'three' import type { Collider, RigidBody } from '@dimforge/rapier3d' +import * as RAPIER from '@dimforge/rapier3d' import type { FScene } from '../core/FScene' import type { FComponent } from '../core/FComponent' +import { F3dShapes } from '../types/F3dShapes' /** * @description The base class for all models in FibboJS. @@ -25,15 +27,131 @@ export abstract class FModel implements FComponent { constructor(scene: FScene) { this.scene = scene - // Check if the world exists - if (!this.scene.world) - throw new Error('FScene must have a world to create a FCube') - // Define default values for position, scale and rotation this.position = new THREE.Vector3(0, 1, 0) this.scale = new THREE.Vector3(1, 1, 1) this.rotation = new THREE.Vector3(0, 0, 0) } - abstract onFrame(_delta: number): void + onFrame(_delta: number): void { + // If the rigid body and object3D exist, update the object3D position and rotation according to the rigid body + if (this.rigidBody && this.object3D) { + const newRigidBodyPosition = this.rigidBody.translation() + this.object3D.position.set(newRigidBodyPosition.x, newRigidBodyPosition.y, newRigidBodyPosition.z) + const newRigidBodyRotation = this.rigidBody.rotation() + this.object3D.setRotationFromQuaternion(new THREE.Quaternion(newRigidBodyRotation.x, newRigidBodyRotation.y, newRigidBodyRotation.z, newRigidBodyRotation.w)) + } + } + + /** + * @description Set the position of the model. + */ + setPosition(x: number, y: number, z: number): void { + this.position.set(x, y, z) + if (this.object3D) + this.object3D.position.set(x, y, z) + if (this.rigidBody) + this.rigidBody.setTranslation({ x, y, z }, true) + } + + /** + * @description Set the scale of the model. + */ + setScale(x: number, y: number, z: number): void { + this.scale.set(x, y, z) + if (this.object3D) + this.object3D.scale.set(x, y, z) + } + + /** + * @description Set the rotation of the model. + */ + setRotation(x: number, y: number, z: number): void { + this.rotation.set(x, y, z) + if (this.object3D) + this.object3D.rotation.set(x, y, z) + } + + /** + * @description Set the rotation of the model from degrees. + */ + setRotationDegree( + x: number, + y: number, + z: number, + ): void { + // Convert degrees to radians + const radRotation = { + x: THREE.MathUtils.degToRad(x), + y: THREE.MathUtils.degToRad(y), + z: THREE.MathUtils.degToRad(z), + } + + this.setRotation(radRotation.x, radRotation.y, radRotation.z) + } + + /** + * @description Init a rigid body for the model. + */ + initRigidBody( + position?: THREE.Vector3, + scale?: THREE.Vector3, + rotation?: THREE.Vector3, + shape?: F3dShapes, + ): void { + // Check if the world exists + if (!this.scene.world) + throw new Error('FScene must have a world to create a rigid body') + + let rigidBodyPosition: THREE.Vector3 | undefined = position + let rigidBodyScale: THREE.Vector3 | undefined = scale + let rigidBodyRotation: THREE.Vector3 | undefined = rotation + + // If position is not defined + if (!rigidBodyPosition) { + // Use default position of the FModel + rigidBodyPosition = new THREE.Vector3(this.position.x, this.position.y, this.position.z) + } + + // If scale is not defined + if (!rigidBodyScale) { + // Use default scale of the FModel + rigidBodyScale = new THREE.Vector3(this.scale.x, this.scale.y, this.scale.z) + } + + // Devide scale by 2 (RAPIER uses half-extents) + if (rigidBodyScale) { + rigidBodyScale.x /= 2 + rigidBodyScale.y /= 2 + rigidBodyScale.z /= 2 + } + + // If rotation is not defined + if (!rigidBodyRotation) { + // Use default rotation of the FModel + rigidBodyRotation = new THREE.Vector3(this.rotation.x, this.rotation.y, this.rotation.z) + } + + // If a shape wasn't defined + if (!shape) { + // Default to cube + shape = F3dShapes.CUBE + } + + // Create a dynamic rigid-body. + const rigidBodyDesc = RAPIER.RigidBodyDesc.dynamic() + .setTranslation(rigidBodyPosition.x, rigidBodyPosition.y, rigidBodyPosition.z) + .setRotation( + // Create quaternion from Euler angles + new THREE.Quaternion().setFromEuler(new THREE.Euler(rigidBodyRotation.x, rigidBodyRotation.y, rigidBodyRotation.z)), + ) + + this.rigidBody = this.scene.world.createRigidBody(rigidBodyDesc) + + // Create a cuboid collider attached to the dynamic rigidBody. + const colliderDesc = shape === F3dShapes.CUBE + ? RAPIER.ColliderDesc.cuboid(rigidBodyScale.x, rigidBodyScale.y, rigidBodyScale.z) + : RAPIER.ColliderDesc.ball(rigidBodyScale.x) + this.collider = this.scene.world.createCollider(colliderDesc, this.rigidBody) + } } diff --git a/src/model/FSphere.ts b/src/model/FSphere.ts index 35012fdd..36b4733b 100644 --- a/src/model/FSphere.ts +++ b/src/model/FSphere.ts @@ -1,5 +1,6 @@ import * as THREE from 'three' import type { FScene } from '../core/FScene' +import { F3dShapes } from '../types/F3dShapes' import { FModel } from './FModel' /** @@ -37,5 +38,17 @@ export class FSphere extends FModel { } onFrame(_delta: number): void { + super.onFrame(_delta) + } + + initRigidBody( + position?: THREE.Vector3, + scale?: THREE.Vector3, + rotation?: THREE.Vector3, + shape?: F3dShapes, + ): void { + if (!shape) + shape = F3dShapes.SPHERE + super.initRigidBody(position, scale, rotation, shape) } } diff --git a/src/types/FVector3.ts b/src/types/FVector3.ts deleted file mode 100644 index 3e47f20e..00000000 --- a/src/types/FVector3.ts +++ /dev/null @@ -1,6 +0,0 @@ -// FVector3 type -export interface FVector3 { - x: number - y: number - z: number -}