2.快速学习Three.js,可以从官网https://threejs.org/ 下载源码,查阅常用API,关注threejs分享案例。中文手册http://techbrood.com/threejs/docs/
<!DOCTYPE html>
<html>
<head>
<title>My first three.js 框架</title>
<script src="./lib/three.js"></script>
<style type="text/css">
body {
margin: 0px;
border: none;
cursor: pointer;
width: 100%;
height: 100vh;/* //800px */
overflow: hidden;
}
</style>
<script>
var renderer,scene,camera,cube;
function Init(){
scene= new THREE.Scene();
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);//可自定义画布大小
renderer.setClearColor(0x000000, 1.0);//设置画布背景色
document.body.appendChild(renderer.domElement);//画布
camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 1000);//透视相机
camera.position.set(0,4,10);
camera.up = { x: 0, y: 1, z: 0 };//自身up向量的朝向
camera.lookAt({ x: 0, y: 0, z: 0 });//聚焦
var pointlight = new THREE.PointLight(0xffffff);
pointlight.position.set(0, 0, 0);
scene.add(pointlight);
var cubegeometry = new THREE.BoxGeometry(1, 1, 1);//保存顶点数据
var cubematerial = new THREE.MeshBasicMaterial({color:0x00ff00});//材质对象
cube = new THREE.Mesh(cubegeometry, cubematerial);//网格对象
cube.rotation.x = 1.57;
scene.add(cube);
}
function update() {
cube.rotation.y += 0.05;//弧度 自身旋转 但自身轴向不变
renderer.render(scene, camera);//每一帧的渲染
requestAnimationFrame(update);//下一帧执行一次参数中的函数
}
function start(){
Init();
update();
}
</script>
</head>
<body onload="start()">
</body>
</html>