-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop.js
More file actions
97 lines (86 loc) · 2.52 KB
/
Copy pathloop.js
File metadata and controls
97 lines (86 loc) · 2.52 KB
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
//wrappers assuming natural parent is scene
function establishAttachment(child, intendedParent)
{
if(child.parent !== intendedParent)
{
if(child.parent !== scene)
{
THREE.SceneUtils.detach( child, child.parent, scene );
}
THREE.SceneUtils.attach( child, scene, intendedParent );
if(intendedParent === child.ordinaryParent && child.onLetGo)
{
child.onLetGo();
}
if(intendedParent !== child.ordinaryParent && child.onGrab)
{
child.onGrab();
}
}
}
function loop( visiBox )
{
frameDelta = ourClock.getDelta();
frameCount++;
readHandInput();
updatePanel();
if( handControllers[0].grippingSide && handControllers[1].grippingSide )
{
var handSeparationDifferential =
handControllers[0].position.distanceTo( handControllers[1].position ) /
handControllers[0].oldPosition.distanceTo( handControllers[1].oldPosition );
assemblage.position.multiplyScalar( 1 / assemblage.scale.x );
assemblage.scale.multiplyScalar( handSeparationDifferential );
assemblage.position.multiplyScalar(assemblage.scale.x);
var bothAttachedController = RIGHT_CONTROLLER_INDEX;
establishAttachment(assemblage, handControllers[bothAttachedController]);
}
else
{
for(var i = 0; i < handControllers.length; i++)
{
if( handControllers[i].grippingSide && !handControllers[i].grippingSideOld )
{
if( holdables.indexOf( handControllers[i].children[handControllers[i].children.length-1] ) )
{
var distanceOfClosestObject = Infinity;
for(var j = 0; j < holdables.length; j++ )
{
if( handControllers[i].overlappingHoldable(holdables[j]) )
{
//ok so actually holding the assemblage is probably an awful idea because many things will assume its parent is scene
establishAttachment(holdables[j], handControllers[i]);
break;
}
}
}
}
}
}
for(var i = 0; i < handControllers.length; i++)
{
if( !handControllers[i].grippingSide && handControllers[i].grippingSideOld )
{
for(var j = 0; j < holdables.length; j++ )
{
if( holdables[j].parent === handControllers[i])
{
establishAttachment( holdables[j], holdables[j].ordinaryParent );
}
}
}
}
for( var i = 0; i < objectsToBeUpdated.length; i++)
{
objectsToBeUpdated[i].update();
}
// for(var i = 0; i < maps.length; i++)
// {
// for(var j = 0; j < maps[i].children.length; j++)
// {
// maps[i].children[j].material.linewidth = 0.2 / assemblage.position.distanceTo(camera.position);
// maps[i].children[j].material.needsUpdate = true;
// }
// }
socket.update();
}