
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
A growing collection of useful helpers and abstractions for react-three-fiber, saving you some boilerplate.
If you find yourself repeating set-up code often and if it's generic enough, add it here, everyone benefits!
yarn add drei
import { ... } from 'drei'
<PerspectiveCamera />
<OrthographicCamera />
<OrbitControls />
<MapControls />
<TrackballControls />
<TransformControls />
<Text />
<Detailed />
<PositionalAudio />
<StandardEffects />
<Sky />
softShadows()
<HTML />
<Shadow />
<Stats />
draco()
meshBounds()
useCamera()
useHelper()
<PerspectiveCamera />
A responsive THREE.PerspectiveCamera that sets itself as the default.
<PerspectiveCamera
makeDefault // Registers it as the default camera system-wide (default=true)
{...props} // All THREE.PerspectiveCamera props are valid
>
<mesh />
</PerspectiveCamera>
<OrthographicCamera />
A responsive THREE.OrthographicCamera that sets itself as the default.
If available controls have damping enabled by default, they manage their own updates, remove themselves on unmount, are compatible with the invalidateFrameloop
canvas-flag. They inherit all props from their underlying THREE controls.
<OrbitControls />
<MapControls />
<TrackballControls />
<TransformControls />
<Text />
Hi-quality text rendering w/ signed distance fields (SDF) and antialiasing, using troika-3d-text. All of troikas props are valid!
<Text>hello world!</Text>
<Detailed
> A wrapper around THREE.LOD (Level of detail).
<Detailed
distances={[0, 10, 20]} // Camera distances, correspends to the # of the children
{...props} // All THREE.LOD props are valid
>
<mesh geometry={highDetail} />
<mesh geometry={mediumDetail} />
<mesh geometry={lowDetail} />
</Detailed>
<PositionalAudio />
A wrapper around THREE.PositionalAudio. Add this to groups or meshes to tie them to a sound that plays when the camera comes near.
<PositionalAudio
url="/sound.mp3" // Url of the sound file
distance={1} // Camera distance (default=1)
loop // Repat play (default=true)
{...props} // All THREE.PositionalAudio props are valid
/>
<StandardEffects />
Adds ambient-occlusion, bloom and SMAA using the postprocessing library.
⚠️ AO relies on the depthbuffer! Make sure your near and far clipping planes are narrow enough, or use <Canvas gl={{ logarithmicDepthBuffer: true }} ... />
.
<StandardEffects
smaa // Can be a boolean (default=true)
ao // Can be a boolean or all valid postprocessing AO props (default=true)
bloom // Can be a boolean or all valid postprocessing Bloom props (default=true)
edgeDetection={0.1} // SMAA precision (default=0.1)
bloomOpacity={1} // Bloom blendMode opacity (default=1)
effects={() => [...fx]} // Define your own: ([smaa, ao, bloom]) => [...effects] (default=undefined)
/>
<Sky />
Adds a sky to your scene.
<Sky
distance={450000} // Camera distance (default=450000)
sunPosition={[0, 1, 0]} // Sun position normal (default=[0, 1, 0])
{...props} // All three/examples/jsm/objects/Sky props are valid
/>
softShadows()
Injects percent closer soft shadows (pcss) into threes shader chunk.
softShadows({
frustrum: 3.75, // Frustrum width (default: 3.75)
size: 0.005, // World size (default: 0.005)
near: 9.5, // Near plane (default: 9.5)
samples: 17, // Samples (default: 17)
rings: 11, // Rings (default: 11)
})
<HTML />
Allows you to tie HTML content to any object of your scene. It will be projected to the objects whereabouts automatically.
<HTML
prepend // Project content behind the canvas (default: false)
center // Adds a -50%/-50% css transform (default: false)
fullscreen // Aligns to the upper-left corner, fills the screen (default:false)
scaleFactor={10} // Scales children if set to a number (default=undefined)
zIndexRange={[100, 0]} // Z-order range (default=[16777271, 0])
portal={domnodeRef} // Reference to target container (default=undefined)
{...groupProps} // All THREE.Group props are valid
{...divProps} // All HTMLDivElement props are valid
>
<h1>hello</h1>
<p>world</p>
</HTML>
<Shadow />
A cheap canvas-texture-based circular gradient.
<Shadow
color="black" // Color (default:black)
colorStop={0} // First gradient-stop (default:0)
opacity={0.5} // Alpha (default:0.5)
fog={false} // Reacts to fog (default=false)
/>
<Stats />
Adds stats to document.body. It takes over the render-loop!
<Stats
showPanel={0} // Start-up panel (default=0)
{...props} // All stats.js props are valid
/>
draco()
Adds the Draco extension to your GLTFLoader.
useLoader(
GLTFLoader,
url,
draco(
'/draco-gtltf/' // Path to the Draco binaries (default='/draco-gtltf/')
)
)
meshBounds()
A very fast, but often good-enough bounds-only raycast for meshes. You can use this if performance has precidence over pointer precision.
<mesh raycast={meshBounds} />
useCamera()
A hook for the rare case when you are using non-default cameras for heads-up-displays or portals, and you need events/raytracing to function properly (raycasting uses the default camera otherwise).
<mesh raycast={useCamera(customCamera)} />
useHelper()
A hook for a quick way to add helpers to existing nodes in the scene. It handles removal of the helper on unmount and auto-updates it by default.
const mesh = useRef()
useHelper(mesh, BoxHelper, "cyan")
FAQs
useful add-ons for react-three-fiber
We found that drei demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.