<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="http://www.yanhuangxueyuan.com/versions/threejsR92/build/three.js"></script>
<script src="http://www.yanhuangxueyuan.com/threejs/examples/js/controls/OrbitControls.js"></script>
</head>
<style>
body { margin: 0;overflow:hidden}
canvas { width: 100%; height: 100% }
</style>
<body>
</body>
<script>
var scene=new THREE.Scene();
var camera= new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,0.1,1000);
var renderer =new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth,window.innerHeight)
document.body.append(renderer.domElement)
var geometry =new THREE.BoxGeometry(1,1,1)
var material= new THREE.MeshBasicMaterial({color:0x00ff00});
var mesh=new THREE.Mesh(geometry,material)
scene.add(mesh)
camera.position.z = 5;
function render(){
renderer.render(scene,camera);//执行渲染操作
requestAnimationFrame(render);//请求再次执行渲染函数render
}
render();
var controls = new THREE.OrbitControls(camera,renderer.domElement);//创建控件对象
// controls.addEventListener('change', render);//监听鼠标、键盘事件
</script>
</html>
Three.js零基础入门教程(郭隆邦)鼠标操作三维场景旋转缩放代码
最新推荐文章于 2024-09-13 10:00:00 发布