1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); camera.position.set(0, -5, 2); camera.lookAt(scene.position);
var renderer = new THREE.WebGLRenderer(); renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement);
function initFloor() { var floorGeo = new THREE.PlaneBufferGeometry(12, 8, 1, 1); var floorMaterial = new THREE.MeshBasicMaterial({ color: '#aaaaaa' }); var floor = new THREE.Mesh(floorGeo, floorMaterial); floor.position.set(0, 0, -1); scene.add(floor); } initFloor();
function initCube(imageUrl) { var geometry = new THREE.BoxGeometry(1, 1, 1); var material; if (imageUrl) { material = new THREE.MeshLambertMaterial({ map: THREE.ImageUtils.loadTexture(imageUrl) }); } else { material = new THREE.MeshLambertMaterial(); } var cube = new THREE.Mesh(geometry, material); scene.add(cube); return cube; }
var cube1 = initCube('./img/1.jpg'); var cube2 = initCube('./img/2.png'); var cube3 = initCube(); var cube4 = initCube(); cube1.position.set(2, 0, 0); cube2.position.set(-2, 0, 0); cube3.position.set(0, -2, 1); cube4.position.set(1, 1, 3);
function render() { requestAnimationFrame(render);
cube1.rotation.x += 0.03; cube1.rotation.y += 0.03;
cube2.rotation.x += 0.02; cube3.rotation.y += 0.01; cube4.rotation.x -= 0.04;
renderer.render(scene, camera); }; render();
|