console
const scene = new THREE.Scene();
var width = window.innerWidth;
var height = window.innerHeight;
var k = width / height;
const camera = new THREE.PerspectiveCamera(90, k, 1, 1000);
camera.position.set(0, 0, -200);
camera.lookAt(0, 0, 0);
scene.add(camera);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(width, height);
document.body.appendChild(renderer.domElement);
renderer.setClearColor(0x000000);
const geometry = new THREE.BoxGeometry(100, 100, 100);
const material = new THREE.MeshBasicMaterial({ color: 0xb01ff0 });
var cube = new THREE.Mesh(geometry, material);
scene.add(cube);
const controls = new THREE.OrbitControls(camera, renderer.domElement);
const gui = new dat.GUI();
let attrs = {
x: 5,
y: 5,
z: 5,
opacity: 1
}
gui.add(attrs, "x", 1,20,1).name('X轴位置').onChange((val)=>{
cube.position.x = val;
});
gui.add(attrs, "y", 1, 20, 1).name('Y轴位置').onChange((val)=>{
cube.position.y = val;
});
gui.add(attrs, "z").onChange((val)=>{
cube.position.z = val;
});
gui.add(attrs, "opacity").min(0).max(1).step(0.1).name("透明度")
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>