平面直角坐标
程序员文章站
2022-03-02 11:54:30
...
更多有趣示例 尽在 知屋安砖社区
示例
HTML
<!DOCTYPE html>
<html>
<title>Threejs</title>
<body>
</body>
</html>
CSS
body {
margin: 0;
overflow: hidden;
}
JS
function init() {
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(0, 0, 10);
camera.lookAt(0, 0, 0);
const renderer = new THREE.WebGLRenderer();
const axes = new THREE.AxesHelper(5);
scene.add(axes);
// 输入代码
document.body.appendChild(renderer.domElement);
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener('resize', resize);
resize();
function renderScene() {
requestAnimationFrame(renderScene);
renderer.render(scene, camera);
}
renderScene();
}
window.onload = init;
上一篇: js 手机号码验证