Normals Material
Torus knot with MeshNormalMaterial for quick debugging.
What this code does
- MeshNormalMaterial: colors each face based on its surface normal direction.
- TorusKnotGeometry: complex parametric geometry with varying surface curvature.
- Visual Debugging: normal colors help identify geometry issues and topology.
- Animation: dual-axis rotation reveals all surface angles and normal vectors.
- No Lighting: normal material ignores lights, making it perfect for debugging.
JavaScript (plain)
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(75, width / height, 0.1, 1000)
camera.position.z = 3
const renderer = new THREE.WebGLRenderer({ antialias: true })
renderer.setSize(width, height)
document.querySelector('#app').appendChild(renderer.domElement)
const controls = new OrbitControls(camera, renderer.domElement)
const mesh = new THREE.Mesh(
new THREE.TorusKnotGeometry(0.7, 0.25, 128, 32),
new THREE.MeshNormalMaterial()
)
scene.add(mesh)
function animate() {
requestAnimationFrame(animate)
mesh.rotation.x += 0.01
mesh.rotation.y += 0.01
controls.update()
renderer.render(scene, camera)
}
animate()