ThreeJS-Addons
Introduction
This project is a collection of ThreeJS Addons to speedup productivity when working with ThreeJS projects.
The Project comprises of the following:
Installation
You can get the package via npm:
npm i --save @threejs-addons/threejs-addons
Usage
To begin using the addons, simply import them into your project
import {
CameraController,
RapierColliderController,
TranslationController,
} from '@threejs-addons/threejs-addons';
import { utils } from '@threejs-addons/threejs-addons';
const { DEFAULT_OPTIONS } = utils;
const CCC = new CameraController({ scene: scene });
const offset = 0.5;
const RCC = new RapierColliderController({ world: world as RAPIER.World, offset, options: DEFAULT_OPTIONS });
const TCC = new TranslationController({ options: DEFAULT_OPTIONS });
TCC.setCCC(CCC);
TCC.set(RCC);
window.addEventListener('keydown', (e) => {
if(e.key === 'w'){
RCC.setTranslateZDirection(true, 1)
}
if(e.key === 's'){
RCC.setTranslateZDirection(true, -1)
}
if(e.key === 'a'){
RCC.setTranslateXDirection(true, 1);
}
if(e.key === 'd'){
RCC.setTranslateXDirection(true, -1);
}
if(e.key === 'ArrowLeft'){
CCC.switchControlTypeNext(null);
}
if(e.key === 'ArrowRight'){
CCC.switchControlTypeNext(null);
}
if(e.key === 'c'){
CCC.switchControllerNext(null);
}
})
window.addEventListener('keyup', (e) => {
if(e.key === 'w'){
RCC.setTranslateZDirection(false, null)
}
if(e.key === 's'){
RCC.setTranslateZDirection(false, null)
}
if(e.key === 'a'){
RCC.setTranslateXDirection(false, null)
}
if(e.key === 'd'){
RCC.setTranslateXDirection(false, null)
}
})
function animate(){
TCC.update(delta, true);
}
API Documentation
The controllers are documented in the following links:
- Camera Controller Class(CCC) .
- Rapier Collider Controller Class(RCC) .
- Translation Controller Class(TCC) .
Contributing
@todo
License
This project is licensed under the MIT License.