dooropen
with orbitControls, XZgrid, info
by Alan Lin
HTML
<div id="info">door
<br />
<a href="javascript:transform();">open/close</a>
</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/3587259/Code/Threejs/OrbitControls.js">
</script>
CSS
#info {
position: absolute;
top: 0px;
width: 100%;
padding: 10px;
text-align: center;
color: #ffff00
}
body {
overflow: hidden;
}
JavaScript
var camera, scene, renderer, geometry, material, sun, light, earth, angle = 0, controls ;
var Doorframe, columnGeom ,platformGeom, material, latchfrme, state = false, open = true;
init();
animate();
function init() {
scene = new THREE.Scene();
//設置視角
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.y = 100;
camera.position.x = 150;
camera.position.z = 200;
scene.add(camera);
columnGeom = new THREE.BoxGeometry(5, 50, 5);
platformGeom = new THREE.BoxGeometry(35, 5, 5);
material = new THREE.MeshBasicMaterial({color:0x0000ff});
//設置門框
Doorframe = new THREE.Object3D();
// an empty "Doorframe" for group the meshes, centered at origin
scene.add(Doorframe);
var mesh = new THREE.Mesh(columnGeom, material);
var mesh2 = mesh.clone();
mesh.position.set(0, 25, 0);
mesh2.position.set( 30, 25, 0);
var mesh1 = new THREE.Mesh(platformGeom, material);
mesh1.position.set(15, 50, 0);
Doorframe.add(mesh);
Doorframe.add(mesh1);
Doorframe.add(mesh2);
//設置門閂
var latch = new THREE.Mesh(new THREE.BoxGeometry( 2, 10, 1),new THREE.MeshBasicMaterial({color:0x00ff00}));
var latch2 = new THREE.Mesh(new THREE.BoxGeometry( 2, 10, 1),new THREE.MeshBasicMaterial({color:0x00ff00}));
latch.position.set(2.5, 15, 0);
latch2.position.set(2.5, 35, 0);
scene.add(latch);
scene.add(latch2);
//設置門
var door = new THREE.Mesh(new THREE.BoxGeometry(24, 47.4, 2),new THREE.MeshBasicMaterial({color:0xff0000}));
door.position.set(15, 23.7, 0);
scene.add(door);
//設置門閂物件
var handle = new THREE.Mesh(new THREE.SphereGeometry( 1.5, 30, 30), material);
handle.position.set(25, 25 , 0);
latchfrme = new THREE.Object3D();
scene.add(latchfrme);
latchfrme.add(latch);
latchfrme.add(latch2);
latchfrme.add(door);
latchfrme.add(handle);
//設置光線
light = new THREE.PointLight(0xffffff);
...