-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
188 lines (161 loc) · 6.61 KB
/
index.html
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Clock Demo Example</title>
<style type="text/css">
body { overflow: hidden; background-color:#000000}
</style>
</head>
<script src="http://www.myleia.com/threejs/js/three.min.js"></script>
<script src="http://www.myleia.com/threejs/js/helvetiker_regular.typeface.js"></script>
<script src="http://www.myleia.com/threejs/js/helvetiker_bold.typeface.js"></script>
<script src="http://www.myleia.com/threejs/js/LeiaCore.js"></script>
<script src="http://www.myleia.com/threejs/js/LeiaKeystrokeHandler.js"></script>
<script src="http://www.myleia.com/threejs/js/LeiaCookieHandler.js"></script>
<body style="margin:0 0 0 0; padding:0 0 0 0; -webkit-transform:rotate(0deg);"></body>
<script>
var leiaHoloScreen, leiaRenderer, leiaDisplayInfo, scene, lks;
var q=0;
var group;
var g_hour = -1, g_minute = -1, g_AMPM = -1;
var isAnimating = true;
var delta = 0;
var touchX = 0;
var touchY = 0;
var hoverState = 0;
var lastHoverState = 0;
var lastX = -Math.PI;
var lastY = -Math.PI;
var useHover = false;
window.onload = function () {
init();
animate();
};
function init() {
// Initialize Everything that LEIA needs
leiaDisplayInfo = new LeiaDisplayInfo('http://www.myleia.com/threejs/config/displayPrototypeDevKit.json');
leiaHoloScreen = new LeiaHoloScreen(leiaDisplayInfo);
leiaHoloScreen.setBaseline(0.8);
leiaRenderer = new LeiaRenderer(leiaDisplayInfo, leiaHoloScreen);
// Three.JS scene initializations
scene = new THREE.Scene();
group = new THREE.Object3D();
scene.add(group);
addObjectsToScene();
addLights();
addEvents();
document.body.appendChild(leiaRenderer.renderer.domElement);
}
function addEvents() {
lks = new LeiaKeystrokeHandler(scene, leiaHoloScreen, leiaRenderer, true);
lks.addKeyHandler("h", function(event) {
console.log((!useHover ? "Enabling" : "Disabling") + " pTouch Hover Control");
useHover = !useHover;
if(!useHover && !isAnimating) {
startAnimation();
}
});
}
function animate() {
requestAnimationFrame(animate);
if(isAnimating) {
group.rotation.set(0.7*Math.sin(5.0*leiaRenderer.timer), 0.1, 0.8*Math.sin(3.0*leiaRenderer.timer));
}
leiaRenderer.render(scene, leiaHoloScreen);
}
function stopAnimation() {
isAnimating = false;
if(lastHoverState == 0) {
console.log("Being touched");
group.rotation.x = 0;
group.rotation.y = 0;
group.rotation.z = 0;
}
}
function startAnimation() {
isAnimating = true;
}
function addTextGeometry(textString, fontSize, posx, posy, posz, gid) {
var textGeometry = new THREE.TextGeometry(textString,
{
size: fontSize,
height: 2,
font: "helvetiker",
bevelThickness: 1.5,
bevelSize: 1.0,
bevelEnabled: true,
extrudeMaterial: 1,
curveSegments: 2
});
textGeometry.computeBoundingBox();
textGeometry.computeVertexNormals();
var dx = textGeometry.boundingBox.max.x - textGeometry.boundingBox.min.x;
var dy = textGeometry.boundingBox.max.y - textGeometry.boundingBox.min.y;
var dz = textGeometry.boundingBox.max.z - textGeometry.boundingBox.min.z;
var textMaterial = new THREE.MeshFaceMaterial([
new THREE.MeshPhongMaterial({ color: 0xffffff, shading: THREE.FlatShading }), // front
new THREE.MeshPhongMaterial({ color: 0x000000, shading: THREE.SmoothShading }) // side
]);
var textMesh = new THREE.Mesh(textGeometry, textMaterial);
var sc = 0.8;
var grot = -0.6;
if (gid == undefined) {
textMesh.position.set(posx - 0.5 * dx, posy - 0.5 * dy, posz - 0.5 * dz);
textMesh.castShadow = true;
textMesh.receiveShadow = true;
group.add(textMesh);
}
}
function UpateTimeObject() {
var date = new Date(Date.now());
var minute = date.getMinutes();
var hour = date.getHours();
if (!(g_hour == hour && g_minute == minute)) {
scene.remove(group);
group = new THREE.Object3D();
g_hour = hour;
g_minute = minute;
var AMPMHH = (hour > 12) ? (hour - 12) : hour;
var strAMPM = (hour < 12) ? "AM" : "PM";
var strHour = (AMPMHH < 10) ? ("0" + AMPMHH.toString()) : AMPMHH.toString();
var strMinutes = (minute < 10) ? ("0" + minute.toString()) : minute.toString();
addTextGeometry(strHour, 18, -12, 0, 0);
addTextGeometry(strMinutes, 9, 12, -4, 0);
addTextGeometry(strAMPM, 5, 13, 6, 0);
var sc = 0.54;
group.scale.set(sc, sc, sc);
//group.rotation.set(0.6, -0.4, 0.0);
scene.add(group);
}
}
function addObjectsToScene() { // Add your objects here
UpateTimeObject();
//setBackgroundPlane('../assets/brickwall_900x600_small.jpg');
setBackgroundPlane('assets/brickwall_900x600_small.jpg');
}
function addLights() {
var light = new THREE.SpotLight(0xFFFFFF);
light.position.set(-100, -50, 100);
light.shadowCameraVisible = false;
light.castShadow = true;
light.shadowMapWidth = light.shadowMapHeight = 512;
light.shadowDarkness = 0.7;
scene.add(light);
var ambientLight = new THREE.AmbientLight(0x888888);
scene.add(ambientLight);
}
function setBackgroundPlane(filename) {
THREE.ImageUtils.crossOrigin = '';
var backgroundPlaneTexture = THREE.ImageUtils.loadTexture(filename);
backgroundPlaneTexture.wrapS = backgroundPlaneTexture.wrapT = THREE.RepeatWrapping;
backgroundPlaneTexture.repeat.set(1, 1);
var planeMaterial = new THREE.MeshPhongMaterial({ map: backgroundPlaneTexture });
var planeGeometry = new THREE.PlaneGeometry(60, 40);
var plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.position.z = -6;
plane.castShadow = true;
plane.receiveShadow = true;
scene.add(plane);
}
</script>
</html>