-
Notifications
You must be signed in to change notification settings - Fork 0
/
pimvr.js
118 lines (110 loc) · 4.32 KB
/
pimvr.js
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
var PIMVR = (function(){
// adding a page from the graph to the 3D scene
function PositionPage(dictionary, PIMPage, position, tweening){
if (!position) {
var boundary = -5;
var position = new THREE.Vector3(Math.random() * 2 * (-boundary) + boundary,
Math.random() * 2 * (-boundary) + boundary,
Math.random() * 2 * (-boundary) + boundary);
}
var mygeometry = new THREE.CubeGeometry(pagesize, pagesize, pagesize * PIMPage.Rev / 100);
var textureUrl = "./MyRenderedPages/fabien.benetou.fr_" + PIMPage.Id.replace(".", "_") + ".png";
var mytexture = THREE.ImageUtils.loadTexture(textureUrl);
// consider instead http://threejs.org/docs/#Reference/Loaders/TextureLoader
var mymaterial = new THREE.MeshBasicMaterial({map: mytexture, transparent: false, opacity: 0.2, });
newpage = new THREE.Mesh( mygeometry, mymaterial );
newpage.lookAt(camera.position);
if (!tweening){
newpage.position.copy(position);
} else {
var pageInitialTweenPosition = new TWEEN.Tween(newpage.position).to(position, 5*1000).start();
}
scene.add(newpage);
PIMPage.ThreeD = newpage;
newpage.ongazeover = function() {
PIMPage.ThreeD.lookAt(camera.position);
$.ajax ({
type: "POST",
url: "//vatelier.net:9876",
crossDomain:true,
dataType: "json",
//data:JSON.stringify({ PIMPage : PIMPage })
data:JSON.stringify({"name" : PIMPage.Id, "x" : PIMPage.ThreeD.position.x, "y" : PIMPage.ThreeD.position.y, "z" : PIMPage.ThreeD.position.z })
}).done(function ( data ) {
console.log("ajax callback response:"+JSON.stringify(data));
});
}
reticle.add_collider(newpage);
return dictionary;
}
// add a button on the top right corner of a positionned page
function PositionPageJumpButton(dictionary, PIMPage) {
var pageproportion = pagesize/5;
var geometry = new THREE.CubeGeometry(pageproportion, pageproportion, pageproportion);
var material = new THREE.MeshBasicMaterial({color: 0x00FFFF, transparent: true, opacity: 0.5 });
var jumpbutton = new THREE.Mesh(geometry, material);
jumpbutton.position = PIMPage.ThreeD.position;
jumpbutton.position.setX(pagesize/2 + pagesize/10);
jumpbutton.position.setY(pagesize/2 - pagesize/10);
PIMPage.ThreeD.add(jumpbutton);
jumpbutton.ongazelong = function() {
PositionPageTargets(dictionary, PIMPage);
}
jumpbutton.ongazeover = function() {
jumpbutton.scale.set(2,2,2);
}
jumpbutton.ongazeout = function() {
jumpbutton.scale.set(1,1,1);
}
reticle.add_collider(jumpbutton);
return PIMPage;
}
// Display the targets of a page (linked item)
function PositionPageTargets(dictionary, PIMPage){
var backgroundPosition = new THREE.Vector3();
backgroundPosition.copy(PIMPage.ThreeD.position);
backgroundPosition.z = -5;
var maxDisplayedTargets = 5;
var displayedTargets = 0;
for (targetPage in PIMPage.Targets){
var targetPageObj = dictionary[keys[targetPage]];
// can display a lot, in fact enough to crash the browser
if (displayedTargets < maxDisplayedTargets) {
PositionPage(dictionary, targetPageObj, backgroundPosition);
PositionPageJumpButton(dictionary, targetPageObj);
backgroundPosition.y += pagesize + pagesize/10;
displayedTargets++;
}
}
return dictionary;
}
function PositionPagesAsSphere(dictionary, startingkey, limit){
// Display the first pages (no specific order)
if (!limit){
var limit = 5;
}
if (!startingkey){
var startingkey = 0;
}
for (var i=startingkey;i<startingkey+limit;i++){
var PIMPage = dictionary[keys[i]];
var radius = 3;
var x = Math.random() - 0.5;
var y = Math.random() - 0.5;
var z = Math.random() - 0.5;
var pageposition = new THREE.Vector3(x,y,z);
pageposition.normalize();
pageposition.multiplyScalar( radius );
//PositionPage(dictionary, PIMPage, pageposition);
PositionPage(dictionary, PIMPage, pageposition, true);
PositionPageJumpButton(dictionary, PIMPage);
}
}
var publicAPI = {
PositionPage : function (dictionary, PIMPage, position, tweening) { PositionPage(dictionary, PIMPage, position, tweening); },
PositionPageJumpButton : function (dictionary, PIMPage) { PositionPageJumpButton(dictionary, PIMPage); },
PositionPageTargets : function (dictionary, PIMPage) { PositionPageTargets(dictionary, PIMPage); },
PositionPagesAsSphere : function (dictionary, startingkey, limit) { PositionPagesAsSphere(dictionary, startingkey, limit); }
};
return publicAPI;
})();