If you're in charge of rendering the scene yourself and have access to the raw three.js geometry, instead of tessellated triangles, you can simply create lines along the edges of the geometry:
// Setting up box geometry and material
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({color: '#ffc32a'});
// Creating the box and adding it to the scene
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
// Generating box edges and incorporating them into the scene
const edges = new THREE.EdgesGeometry(geometry);
const line = new THREE.LineSegments(
edges,
new THREE.LineBasicMaterial({color: '#000000'})
);
scene.add(line);
No need for complicated custom shaders or complex operations.
However, due to GPU limitations, this approach will only produce a one-pixel line. For thicker lines, consider using LineMaterial
, LineSegments2
, and LineSegmentsGeometry
found in examples.