component
GlassRail
A straight glass balustrade: a pane in a steel shoe with a round handrail, matching CurvedWall's glass. One cuboid collider the rail's height, so a player can't walk off an edge.
⌖ Explore the library in 3D → · View as Markdown
Add it
npx @runek/cli add glass-rail
Pulls @react-three/rapier@^2.2.0, @runek/core@^0.18.0.
Use it
import { GlassRail } from './runek/GlassRail'
<GlassRail position={[0, 0, 0]} width={3} />
Or as a node in a world file (worlds as data):
{ "type": "GlassRail", "props": { "position": [0, 0, 0], "width": 3 } }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
width |
number |
2 |
Length along local X, in units, centred on the origin. |
height |
number |
1.05 |
To the top of the handrail, in units. |
glassColor |
color |
"#b7d8e8" |
Glass tint. |
color |
color |
palette metal |
Shoe and handrail. Defaults to the world palette’s metal slot. |
position |
[x, y, z] |
[0, 0, 0] |
Position [x, y, z] in units (1 unit = 1 m, Y-up). |
rotation |
[x, y, z] |
[0, 0, 0] |
Euler rotation [x, y, z] in radians. |
seed |
number |
Accepted for the component contract; this component has no seeded variation yet. |
Registry manifest
registry manifest /r/components/glass-rail.json Self-contained JSON: inlined source plus resolved dependencies, exactly whatrunek add glass-rail fetches.
Browse the whole catalog in the gallery →.
Source (GlassRail.tsx)
import { CuboidCollider, RigidBody } from '@react-three/rapier'
import { useMaterials, useWorld, type WorldComponentProps } from '@runek/core'
export interface GlassRailProps extends WorldComponentProps {
/** Length along local X, in units, centred on the origin. */
width?: number
/** To the top of the handrail, in units. */
height?: number
/** Glass tint. */
glassColor?: string
/** Shoe and handrail. Defaults to the world palette's `metal` slot. */
color?: string
}
/**
* A straight glass balustrade for a gallery or a mezzanine: a pane standing in a steel shoe
* along local X, with a round handrail along its top. Its glass matches `CurvedWall`'s, so the
* two run on from each other. One cuboid collider the height of the rail, so a player can't
* walk off the edge it guards.
*/
export function GlassRail({
position = [0, 0, 0],
rotation = [0, 0, 0],
width = 2,
height = 1.05,
glassColor = '#b7d8e8',
color,
}: GlassRailProps) {
const { unit, palette } = useWorld()
const m = useMaterials({
glass: { slot: 'glass', color: glassColor, transparent: true, opacity: 0.28, roughness: 0.08 },
steel: { slot: 'metal.painted', color: color ?? palette.metal, roughness: 0.6 },
})
const W = width * unit
const H = height * unit
const shoeH = 0.1 * unit
const shoeD = 0.06 * unit
const rail = 0.025 * unit
const paneH = H - shoeH * 0.6 - rail * 2.2
return (
<RigidBody type="fixed" colliders={false} position={position} rotation={rotation}>
<CuboidCollider args={[W / 2, H / 2, 0.05 * unit]} position={[0, H / 2, 0]} />
<mesh material={m.steel} castShadow receiveShadow position={[0, shoeH / 2, 0]}>
<boxGeometry args={[W, shoeH, shoeD]} />
</mesh>
<mesh material={m.glass} position={[0, shoeH * 0.6 + paneH / 2, 0]}>
<boxGeometry args={[W - rail, paneH, 0.015 * unit]} />
</mesh>
<mesh material={m.steel} position={[0, H - rail * 1.6, 0]}>
<boxGeometry args={[W, rail * 0.6, 0.03 * unit]} />
</mesh>
<mesh
material={m.steel}
castShadow
position={[0, H - rail, 0]}
rotation={[0, 0, Math.PI / 2]}
>
<cylinderGeometry args={[rail, rail, W, 12]} />
</mesh>
</RigidBody>
)
}
GlassRail.groundSitting = true