console
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(80, innerWidth / innerHeight, 1, 1000);
camera.position.set(50, 0, 50);
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 loader = new THREE.CubeTextureLoader();
let textureCube = loader.load(['https://threejs.org/examples/textures/cube/Bridge2/posx.jpg', 'https://threejs.org/examples/textures/cube/Bridge2/negx.jpg', 'https://threejs.org/examples/textures/cube/Bridge2/posy.jpg', 'https://threejs.org/examples/textures/cube/Bridge2/negy.jpg', 'https://threejs.org/examples/textures/cube/Bridge2/posz.jpg', 'https://threejs.org/examples/textures/cube/Bridge2/negz.jpg']);
scene.background = textureCube;
scene.environment = textureCube;
const gui = new dat.GUI();
let settings = {
'设置环境纹理': true,
}
var cGui = gui.addFolder('控制操作');
cGui.open();
cGui.add(settings, '设置环境纹理').onChange((visibility) => {
if (visibility) {
scene.environment = textureCube;
} else {
scene.environment = null;
}
});
const sphereGeometry = new THREE.SphereGeometry(30, 32, 16);
const standardMaterial = new THREE.MeshStandardMaterial({
metalness: 1,
roughness: 0.0,
});
const sphere = new THREE.Mesh(sphereGeometry, standardMaterial);
scene.add(sphere)
const controls = new THREE.OrbitControls(camera, renderer.domElement);
const ambientLight = new THREE.AmbientLight(0xffffff);
ambientLight.castShadow = true
scene.add(ambientLight)
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>