<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>three.js从入门到精通系列教程010 - three.js创建旋转圆柱体</title>
<script src="ThreeJS/three.js"></script>
<script src="ThreeJS/jquery.js"></script>
</head>
<body>
<center id="myContainer"></center>
<script>
var myWidth = 480, myHeight = 320, k = myWidth / myHeight, s = 120;
//创建渲染器
var myRenderer = new THREE.WebGLRenderer();
myRenderer.setSize(myWidth, myHeight);
myRenderer.setClearColor("white", 1);
$("#myContainer").append(myRenderer.domElement);
var myScene = new THREE.Scene();
var myLight = new THREE.PointLight("white");
myLight.position.set(400, 800, 300);
myScene.add(myLight);
var myCamera = new THREE.OrthographicCamera(-s * k, s * k, s, -s, 1, 1000);
myCamera.position.set(400, 300, 200);
myCamera.lookAt(myScene.position);
//创建圆柱体
//80,80表示圆柱上下两个底面的半径,参数三100表示圆柱高度,参数四25表示圆柱圆周方向细分数即光滑度
var myGeometry = new THREE.CylinderGeometry(80, 80, 100, 25);
var myMaterial = new THREE.MeshBasicMaterial({
color: 'gray',
wireframe: true
});
var myMesh = new THREE.Mesh(myGeometry, myMaterial);
myScene.add(myMesh);
//渲染(旋转)圆柱体
var T0 = new Date(); //上次时间
animate();
function animate() {
var T1 = new Date(); //本次时间
var t = T1 - T0; //两次时间差
T0 = T1; //把本次时间赋值给上次时间
myMesh.rotateY(0.001 * t); //旋转角速度0.001弧度每毫秒
myRenderer.render(myScene, myCamera); //执行渲染操作
window.requestAnimationFrame(animate); //请求再次执行渲染
};
</script>
</body>
</html>
three.js从入门到精通系列教程010 - three.js创建旋转圆柱体
于 2024-01-20 09:09:55 首次发布