Three
RaycasterHelper
yarn add @gsimone/three-raycaster-helper
Visualize a Raycaster (ray and near/far) and, optionally, its hits.
import { RaycasterHelper } from '@gsimone/three-raycaster-helper'
const raycaster = new Raycaster(origin, direction, 0.5, 10)
const helper = new RaycasterHelper(raycaster)
const hits = raycaster.intersectObjects( scene.children )
helper.hits = hits
Smoothdamp
yarn add @gsimone/smoothdamp
Port of Unity's SmoothDamp.
import { SmoothDamp } from '@gsimone/smoothdamp'
import { SmoothDampVectors } from '@gsimone/smoothdamp/three'
const smoothDamp = new SmoothDamp(0.5, 10)
const x = smoothDamp.get( 10, deltaTime )
// using with three.js Vectors
const mySmoothDampV = new SmoothDampVectors(0.5, 10)
const target = new Vector3(0, 0, 0)
const dest = new Vector3(10, 0, 0)
target.copy(
mySmoothDampV.get( target, dest, deltaTime )
)
React Three Fiber
Layers
yarn add @gsimone/r3f-layers
Simple helper for three's Layers, lets you set an object's layers in a declarative manner:
<mesh>
<Layers layers={[0, 1, 3]} /> {/* will set layers 0, 1 and 3 exclusively */}
</mesh>
Leva
bitmask plugin
yarn add @gsimone/leva-plugin-bitmask
Plugin to add a bitmask-type input. Returns a bitmask object from bitmaskjs with an additional layersArray
property to get an array compatible with the
const { layers } = useControls({
layers: bitmask({
value: [1, 0, 1], // sets first bit to 1, second to 0, third to 1
size: 16,
}),
layers2: bitmask({
value: 3, // sets the integer of the bitmask to 3, equivalent to [1, 1]
}),
});
layers.layersArray; // [0]
TODO
Add alternative APIs to set the initial value.
Vanilla
Bitmask
yarn add @gsimone/bitmask
Tiny library for bitmasks.
const bitmask = new Bitmask([1, 0, 1], 16);
bitmask.setBit(1, 1).clearBit(2).getBits();