console
const scene = new THREE.Scene();
scene.background = new THREE.Color( 0xff0000 );
const camera = new THREE.PerspectiveCamera(80, innerWidth / innerHeight, 1, 1000);
camera.position.set(0, 10, 20);
camera.lookAt(0, 0, 0);
scene.add(camera);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
renderer.setClearColor(0x000000);
const geometry = new THREE.BoxGeometry(1, 1, 1);
for (var i = 0; i < 100; i++) {
const material = new THREE.MeshBasicMaterial({ color: 0xffaa00 });
material.color = new THREE.Color(Math.random(), Math.random(), Math.random())
var cube = new THREE.Mesh(geometry, material);
cube.position.set(Math.random() * 20 - 10, 3, Math.random() * 20 - 10)
scene.add(cube);
}
const controls = new THREE.OrbitControls(camera, renderer.domElement);
const gui = new dat.GUI();
var palette = {
color: '#FF0000',
};
gui.addColor(palette, 'color').name('CSS颜色值').onChange((val)=>{
scene.background= new THREE.Color(val);
});
function render() {
requestAnimationFrame(render);
renderer.render(scene, camera);
}
render()
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body style="margin:0;">
</body>
</html>