|
@@ -0,0 +1,169 @@
|
|
|
|
+<!DOCTYPE HTML>
|
|
|
|
+<html lang="en">
|
|
|
|
+ <head>
|
|
|
|
+ <title>three.js - geometry - cube</title>
|
|
|
|
+ <meta charset="utf-8">
|
|
|
|
+ <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
|
|
|
|
+ <style type="text/css">
|
|
|
|
+ body
|
|
|
|
+ {
|
|
|
|
+ background-color: #ffffff;
|
|
|
|
+ margin: 0px;
|
|
|
|
+ overflow: hidden;
|
|
|
|
+ }
|
|
|
|
+ </style>
|
|
|
|
+ </head>
|
|
|
|
+ <body>
|
|
|
|
+
|
|
|
|
+ <script type="text/javascript" src="../../build/three.js"></script>
|
|
|
|
+ <script type="text/javascript" src="http://github.com/mrdoob/stats.js/raw/master/build/stats.js"></script>
|
|
|
|
+
|
|
|
|
+ <script type="text/javascript">
|
|
|
|
+
|
|
|
|
+ var SCREEN_WIDTH = window.innerWidth;
|
|
|
|
+ var SCREEN_HEIGHT = window.innerHeight;
|
|
|
|
+ var AMOUNT = 100;
|
|
|
|
+
|
|
|
|
+ var container;
|
|
|
|
+ var stats;
|
|
|
|
+
|
|
|
|
+ var camera;
|
|
|
|
+ var scene;
|
|
|
|
+ var renderer;
|
|
|
|
+
|
|
|
|
+ var cube, plane;
|
|
|
|
+
|
|
|
|
+ var targetRotation = 0;
|
|
|
|
+ var targetRotationOnMouseDown = 0;
|
|
|
|
+
|
|
|
|
+ var mouseX = 0;
|
|
|
|
+ var mouseXOnMouseDown = 0;
|
|
|
|
+
|
|
|
|
+ var windowHalfX = window.innerWidth / 2;
|
|
|
|
+ var windowHalfY = window.innerHeight / 2;
|
|
|
|
+
|
|
|
|
+ init();
|
|
|
|
+ setInterval(loop, 1000/60);
|
|
|
|
+
|
|
|
|
+ function init()
|
|
|
|
+ {
|
|
|
|
+ container = document.createElement('div');
|
|
|
|
+ document.body.appendChild(container);
|
|
|
|
+
|
|
|
|
+ camera = new Camera(0, 150, 300);
|
|
|
|
+ camera.focus = 300;
|
|
|
|
+ camera.target.y = 150;
|
|
|
|
+ camera.updateMatrix();
|
|
|
|
+
|
|
|
|
+ scene = new Scene();
|
|
|
|
+
|
|
|
|
+ // Cube
|
|
|
|
+
|
|
|
|
+ geometry = new Cube(200, 200, 200);
|
|
|
|
+
|
|
|
|
+ for (var i = 0; i < geometry.faces.length; i++)
|
|
|
|
+ geometry.faces[i].color.setRGBA( Math.floor( Math.random() * 128), Math.floor( Math.random() * 128 + 128), Math.floor( Math.random() * 128 + 128), 255 );
|
|
|
|
+
|
|
|
|
+ cube = new Mesh(geometry, new FaceColorMaterial());
|
|
|
|
+ cube.position.y = 150;
|
|
|
|
+ cube.updateMatrix();
|
|
|
|
+ scene.add(cube);
|
|
|
|
+
|
|
|
|
+ // Plane
|
|
|
|
+
|
|
|
|
+ plane = new Mesh(new Plane(200, 200), new ColorMaterial(0xeeeeee));
|
|
|
|
+ plane.rotation.x = 90 * (Math.PI / 180);
|
|
|
|
+ plane.updateMatrix();
|
|
|
|
+ scene.add(plane);
|
|
|
|
+
|
|
|
|
+ renderer = new CanvasRenderer();
|
|
|
|
+ renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
|
|
+
|
|
|
|
+ container.appendChild(renderer.viewport);
|
|
|
|
+
|
|
|
|
+ stats = new Stats();
|
|
|
|
+ container.appendChild(stats.getDisplayElement());
|
|
|
|
+
|
|
|
|
+ document.addEventListener('mousedown', onDocumentMouseDown, false);
|
|
|
|
+ document.addEventListener('touchstart', onDocumentTouchStart, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+
|
|
|
|
+ function onDocumentMouseDown( event )
|
|
|
|
+ {
|
|
|
|
+ document.addEventListener('mousemove', onDocumentMouseMove, false);
|
|
|
|
+ document.addEventListener('mouseup', onDocumentMouseUp, false);
|
|
|
|
+
|
|
|
|
+ mouseXOnMouseDown = event.clientX - windowHalfX;
|
|
|
|
+ targetRotationOnMouseDown = targetRotation;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onDocumentMouseMove( event )
|
|
|
|
+ {
|
|
|
|
+ mouseX = event.clientX - windowHalfX;
|
|
|
|
+
|
|
|
|
+ targetRotation = targetRotationOnMouseDown + (mouseX - mouseXOnMouseDown) * 0.05;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onDocumentMouseUp( event )
|
|
|
|
+ {
|
|
|
|
+ document.removeEventListener('mousemove', onDocumentMouseMove, false);
|
|
|
|
+ document.removeEventListener('mouseup', onDocumentMouseUp, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onDocumentTouchStart( event )
|
|
|
|
+ {
|
|
|
|
+ if(event.touches.length > 1)
|
|
|
|
+ {
|
|
|
|
+ event.preventDefault();
|
|
|
|
+
|
|
|
|
+ mouseXOnMouseDown = event.touches[0].pageX - windowHalfX;
|
|
|
|
+ targetRotationOnMouseDown = targetRotation;
|
|
|
|
+
|
|
|
|
+ document.addEventListener('touchmove', onDocumentTouchMove, false);
|
|
|
|
+ document.addEventListener('touchend', onDocumentTouchEnd, false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onDocumentTouchMove( event )
|
|
|
|
+ {
|
|
|
|
+ if(event.touches.length == 1)
|
|
|
|
+ {
|
|
|
|
+ event.preventDefault();
|
|
|
|
+
|
|
|
|
+ mouseX = event.touches[0].pageX - windowHalfX;
|
|
|
|
+
|
|
|
|
+ targetRotation = targetRotationOnMouseDown + (mouseX - mouseXOnMouseDown) * 0.05;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function onDocumentTouchEnd( event )
|
|
|
|
+ {
|
|
|
|
+ if(event.touches.length == 0)
|
|
|
|
+ {
|
|
|
|
+ event.preventDefault();
|
|
|
|
+
|
|
|
|
+ document.removeEventListener('touchmove', onDocumentTouchMove, false);
|
|
|
|
+ document.removeEventListener('touchend', onDocumentTouchEnd, false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+
|
|
|
|
+ function loop()
|
|
|
|
+ {
|
|
|
|
+ cube.rotation.y += (targetRotation - cube.rotation.y) * 0.05;
|
|
|
|
+ cube.updateMatrix();
|
|
|
|
+
|
|
|
|
+ plane.rotation.z = -cube.rotation.y;
|
|
|
|
+ plane.updateMatrix();
|
|
|
|
+
|
|
|
|
+ renderer.render(scene, camera);
|
|
|
|
+ stats.update();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ </script>
|
|
|
|
+
|
|
|
|
+ </body>
|
|
|
|
+</html>
|