-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
470 lines (292 loc) · 10.3 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="controller/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<script src="lib/three.min.js"></script>
<script src="lib/stats.min.js"></script>
<script src="lib/leap.min.js"></script>
<script src="lib/dat.gui.min.js"></script>
<script src="lib/jquery-1.7.1.min.js"></script>
<script src="lib/Detector.js"></script>
<style>
body{
position:fixed;
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size:14px;
top:0px;
left:0px;
}
#container{
position:fixed;
top:0px;
left:0px;
}
p{
color:#fff;
position:fixed;
top:0px;
left:15px;
}
a{
color:#FFF;
}
</style>
<body>
<div id="container"><p>
Made by <a href="http://cabbibo.com">Cabbibo</a> using <a target="_blank" href="http://mrdoob.github.com/three.js/">Three.js</a> and <a target="_blank" href="https://code.google.com/p/dat-gui/">dat.gui</a><br/><br/>
Make a 'V' with a fingers to grab a point<br/>
To let go, close the 'V' your fingers make. <br/><br/>
Press 'x' to hide interface.
</p></div>
<script>
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
$(document).keypress(function(event){
var whichKey=String.fromCharCode(event.which)
if(whichKey=='x'){
//$(".ui").fadeToggle()
toggleInterface()
}
})
function toggleInterface(){
$("#container p").toggle()
$(".ac").toggle()
$("#stats").toggle()
}
var PARAMS = function(){
//SENSITIVIT FOR PLUCKING
this.sensitivity = 10
this.rotationConstant = 100
this.movementConstant = 10
this.rotationX = 0
this.rotationY = 0
this.rotationZ = 0
this.constantRotation = false
this.rotationSpeedX = 0
this.rotationSpeedY = 10
this.rotationSpeedZ = 0
this.cameraDistance = 500
this.vertexMarkers = true
this.toggleVertexMarkers = function(){
if(this.vertexMarkers == true){
for(var i =0;i< vertBoxArray.length;i++){
rotatable.remove(vertBoxArray[i])
}
this.vertexMarkers = false
}else{
for(var i =0;i< vertBoxArray.length;i++){
rotatable.add(vertBoxArray[i])
}
this.vertexMarkers = true
}
}
}
window.params = new PARAMS()
var gui = new dat.GUI();
gui.add(params, 'sensitivity', 1, 40);
gui.add(params, 'rotationX', 0, 360);
gui.add(params, 'rotationY', 0, 360);
gui.add(params, 'rotationZ', 0, 360);
gui.add(params, 'constantRotation');
gui.add(params, 'rotationSpeedX', 0, 100);
gui.add(params, 'rotationSpeedY', 0, 100);
gui.add(params, 'rotationSpeedZ', 0, 100);
gui.add(params, 'cameraDistance', 0, 1000);
gui.add(params, 'toggleVertexMarkers');
/*
Global Cariables / Objects / Scenes , etc
*/
mouseIsDown = false
//camera for the scene, VERY large distance!
camera = new THREE.PerspectiveCamera(70,window.innerWidth/window.innerHeight,1,8000)
//Creates a clock, mostly for use with controls
clock = new THREE.Clock();
//creates the scene for this galaxy
scene=new THREE.Scene();
camera.position.x = 500
camera.lookAt(scene.position)
//creates renderer for this galaxy
window.renderer=new THREE.WebGLRenderer( { clearColor: 0x000000, clearAlpha: 1 } )
renderer.setSize( window.innerWidth, window.innerHeight );
//Creates Stats
/*TAKE OUT FOR PRODUCTION*/
window.stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.bottom = '0px';
stats.domElement.style.visibility= 'hidden';
//adds stats to document
window.container=document.getElementById( 'container' )
container.appendChild(renderer.domElement )
container.appendChild(stats.domElement )
window.addEventListener( 'resize', onWindowResize, false );
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
/*
FUNSTUFF
*/
//using normal material, because it takes the least set up
var material = new THREE.MeshNormalMaterial()
material.side=THREE.DoubleSide
material.transparent = true
material.opacity = 1
// This is the geometry we will be altering
var geom = new THREE.SphereGeometry(200,20,20);
//object that is manipulated
var sphere = new THREE.Mesh(geom, material)
//This is the 'scene' that our mesh will lie within
var rotatable = new THREE.Object3D()
scene.add(rotatable)
//add our object to the rotatable scene
rotatable.add(sphere)
//Function that animates everything!
window.animate = function(){
geom.verticesNeedUpdate = true;
stats.update();
renderer.render( scene, camera );
}
//Setting up our pointables
var pointGeo = new THREE.CubeGeometry(20,20,20)
var pointable1 = new THREE.Mesh(pointGeo,material)
var pointable2 = new THREE.Mesh(pointGeo, material)
scene.add(pointable1)
scene.add(pointable2)
//array to keep all of the box markers for the geometry
vertBoxArray = []
//sets up box for vertex markers
var smallBox = new THREE.CubeGeometry(1,1,1)
//Creates a new box at ever vertex of the geom
for(var i = 0; i<geom.vertices.length; i++){
//creates vertex markers
var vertBox = new THREE.Mesh(smallBox, material)
vertBox.position = new THREE.Vector3(geom.vertices[i].x,geom.vertices[i].y,geom.vertices[i].z)
vertBox.beingPulled = false
//adds to rotatable scene
rotatable.add(vertBox)
//adds to an array that is easier to access
vertBoxArray.push(vertBox)
}
var connection = {
x:0,
y:0,
z:0
}
connector = new THREE.Mesh(new THREE.CubeGeometry(1,1,1),material)
scene.add(connector)
var checkVec
//checks to see if a vertex is being pulled
function checkPull(){
//console.log(checkVec)
//console.log(checkVec)
for(var i =0;i< vertBoxArray.length;i++){
checkVec = new THREE.Vector3(vertBoxArray[i].position.x, vertBoxArray[i].position.y,vertBoxArray[i].position.z)
checkVec.applyMatrix4(rotatable.matrixWorld)
//checkVec.applyMatrix4(scene.matrixWorld)
var checkX = Math.abs(connector.position.x - checkVec.x)
var checkY = Math.abs(connector.position.y - checkVec.y)
var checkZ = Math.abs(connector.position.z - checkVec.z)
if(checkX < params.sensitivity && checkY < params.sensitivity && checkZ < params.sensitivity){
//check to make sure that no other boxes are being pulled
var anyPulled = false
for(var j =0;j< vertBoxArray.length;j++){
if(vertBoxArray[j].beingPulled == true){
anyPulled = true
break
}
}
//if there are no other verticies being pulled, grab this one!
if(anyPulled == false){
vertBoxArray[i].beingPulled = true
}
}
if(vertBoxArray[i].beingPulled == true){
var mInverse = new THREE.Matrix4().getInverse(rotatable.matrixWorld );
connectorCopy = new THREE.Vector3(connector.position.x,connector.position.y, connector.position.z)
connectorCopy.applyMatrix4( mInverse );
//moves the vertex to the right position
sphere.geometry.vertices[i].x = connectorCopy.x
sphere.geometry.vertices[i].y = connectorCopy.y
sphere.geometry.vertices[i].z = connectorCopy.z
//updates teh geometery
sphere.geometry.verticesNeedUpdate = true;
}
}
}
//sets all verticies to false for being pulled
function clearPull(){
for(var i =0;i< vertBoxArray.length;i++){
vertBoxArray[i].beingPulled = false
}
}
window.latestFrame
Leap.loop(function(frame) {
if(!frame.pointables[0]){
//move pointable2 / connector out of the frame
pointable1.position.x = 2000000
pointable2.position.x = 2000000
connector.position.x = 20000000
}
if(frame.pointables[0]){
pointable1.position.z = -frame.pointables[0].tipPosition[0]*2
pointable1.position.y = (frame.pointables[0].tipPosition[1]-250)*2
pointable1.position.x = frame.pointables[0].tipPosition[2]*2
//if the second pointable is removed, then clear all being pulleds
if(latestFrame.pointables[1] && !frame.pointables[1]){
clearPull()
//move pointable2 / connector out of the frame
pointable2.position.x = 2000000
connector.position.x = 20000000
}
}
//if there are two pointables, get the midpoint between them, and assign the 'connector to this position
if(frame.pointables[1]){
pointable2.position.z = -frame.pointables[1].tipPosition[0]*2
pointable2.position.y = (frame.pointables[1].tipPosition[1]-250)*2
pointable2.position.x = frame.pointables[1].tipPosition[2]*2
//check to see if any verticies are being pulled
checkPull()
connector.position.x = pointable1.position.x + (pointable2.position.x -pointable1.position.x)/2
connector.position.y = pointable1.position.y + (pointable2.position.y -pointable1.position.y)/2
connector.position.z = pointable1.position.z + (pointable2.position.z -pointable1.position.z)/2
}
//pull the verticies
update();
animate();
//rotatable.rotation.y += 0.001
/*for(var i =0;i< vertBoxArray.length;i++){
//how close the connector is to the vertex
sphere.geometry.vertices[i].applyMatrix4( rotatable.matrixWorld );
vertBoxArray[i].position.applyMatrix4( rotatable.matrixWorld );
}*/
latestFrame = frame
});
var update = function (){
if (params.vertexMarkers == true){
for(var i =0; i < vertBoxArray.length;i++){
vertBoxArray[i].position.x = sphere.geometry.vertices[i].x
vertBoxArray[i].position.y = sphere.geometry.vertices[i].y
vertBoxArray[i].position.z = sphere.geometry.vertices[i].z
vertBoxArray[i].scale.x = vertBoxArray[i].scale.y = vertBoxArray[i].scale.z = params.sensitivity
}
}
connector.scale.x = connector.scale.y = connector.scale.z = params.sensitivity
camera.position.x = params.cameraDistance
if(params.constantRotation == true){
rotatable.rotation.x += params.rotationSpeedX/1000
rotatable.rotation.y += params.rotationSpeedY/1000
rotatable.rotation.z += params.rotationSpeedZ/1000
}else{
rotatable.rotation.x =(params.rotationX/180) * Math.PI
rotatable.rotation.y =(params.rotationY/180) * Math.PI
rotatable.rotation.z =(params.rotationZ/180) * Math.PI
}
}
</script>
</body>
</html>
</script>
</body>
</html>