-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreeHelpFuncs.js
More file actions
201 lines (169 loc) · 5.63 KB
/
threeHelpFuncs.js
File metadata and controls
201 lines (169 loc) · 5.63 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
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
//File that contains helpful funcs with/using THREE.js
//Restarts camera :V (sic!)
function restartCamera() {
cameraFocusPos = new THREE.Vector3(spreadSize / 2, spreadSize / 2, spreadSize / 2);
cameraCenterPos = new THREE.Vector3(spreadSize / 2, spreadSize / 2, spreadSize / 2);
theta = Math.PI / 4;
phi = Math.PI / 4;
radius = 30;
if (lastLogHash != 0) {
addLogEntry("Camera", "Camera position and rotation reset.");
}
}
//Clears the scene, for the loading purposes
function clearScene() {
if (parsedData != null) {
var obj = null;
for(var i = 0; i < parsedData.length; ++i) {
parsedData[i].mesh.material.dispose();
parsedData[i].mesh.geometry.dispose();
scene.remove(parsedData[i].mesh);
parsedData[i].mesh = null;
}
parsedData = null;
raycastable = null;
addLogEntry("Scene", "Cleared successfully.");
}
}
//Raycast processing to let you see what you are targeting
function processRay(object) {
if (object == null) {
document.getElementById('ray_info').style.display = "none";
return;
}
if (object.name.substring(0, 6) != "POINT_") {
document.getElementById('ray_info').style.display = "none";
return;
}
var content = "<table>";
content += "<tr>";
content += "<td>Position: </td>";
content += "<td class='framed'>X: " + object.orgPos.x + "</td>";
content += "<td class='framed'>Y: " + object.orgPos.y + "</td>";
content += "<td class='framed'>Z: " + object.orgPos.z + "</td>";
content += "</tr>";
content += "<tr>";
content += "<td>Color: </td>";
content += "<td class='framed'>R: " + Math.floor(object.material.color.r * 255) + "</td>";
content += "<td class='framed'>G: " + Math.floor(object.material.color.g * 255) + "</td>";
content += "<td class='framed'>B: " + Math.floor(object.material.color.b * 255) + "</td>";
content += "</tr>";
content += "</table>";
document.getElementById('ray_info').style.position = "fixed";
document.getElementById('ray_info').style.display = "block";
document.getElementById('ray_info').style.left = (20 + mouse.x) + "px";
document.getElementById('ray_info').style.top = (20 + mouse.y) + "px";
document.getElementById('ray_info').innerHTML = content;
}
//Log handling
function addLogEntry(title, msg) {
if ((title + msg).hashCode() != lastLogHash) {
logEntries.push([
"[" + title + "]", msg
]);
lastLogHash = (title + msg).hashCode();
var content = "<table>";
for(var i = Math.max(0, logEntries.length - 10); i < logEntries.length; ++i) {
content += "<tr>";
content += "<td>" + logEntries[i][0] + "</td>";
content += "<td>" + logEntries[i][1] + "</td>";
content += "</tr>";
}
content += "</table>";
document.getElementById("log").innerHTML = content;
}
}
//Spread size of grid... I know used once...
//...but idea was to let it modify by user.
//Zoom in/out does the job.
function setSpreadSize(size) {
spreadSize = size;
grid = new THREE.GridHelper(spreadSize, spreadSize);
grid.position.x = spreadSize / 2;
grid.position.z = spreadSize / 2;
grid.name = "GRID";
scene.remove("GRID");
scene.add(grid);
localGrid = new THREE.GridHelper(spreadSize / 5, spreadSize);
localGrid.position.x = spreadSize / 2;
localGrid.position.z = spreadSize / 2;
localGrid.name = "LOCALGRID";
scene.remove("LOCALGRID");
scene.add(localGrid);
axes = new THREE.AxesHelper(spreadSize);
axes.position.set(0, 0.05, 0);
axes.name = "AXES";
scene.remove("AXES");
scene.add(axes);
}
//Debug purposes, I wont explain this!
function generateRandomSet(amount) {
clearScene();
var tempData = new Array();
raycastable = new Array();
var success = 0;
var fail = 0;
var max = new Array(3);
var min = new Array(3);
for(var l = 0; l < amount; ++l) {
var geometry = new THREE.SphereGeometry(spreadSize / amount, 6, 5);
var material = new THREE.MeshBasicMaterial({
color: 0xFFFFFF
});
material.color = new THREE.Color(Math.random(), Math.random(), Math.random());
var sphere = new THREE.Mesh(geometry, material);
var orgPos = new THREE.Vector3(
(Math.floor(Math.random() * 1000) / 1000),
(Math.floor(Math.random() * 1000) / 1000),
(Math.floor(Math.random() * 1000) / 1000)
);
sphere.orgPos = orgPos;
sphere.position.x = orgPos.x * spreadSize;
sphere.position.y = orgPos.y * spreadSize;
sphere.position.z = orgPos.z * spreadSize;
sphere.name = "POINT_" + sphere.position.x + ";" + sphere.position.y + ";" + sphere.position.z;
tempData.push({
mesh: sphere,
wire: null,//wireframe,
added: false
});
raycastable.push(sphere);
success += 1;
if (success == 1) {
max[0] = orgPos.x;
max[1] = orgPos.y;
max[2] = orgPos.z;
min[0] = orgPos.x;
min[1] = orgPos.y;
min[2] = orgPos.z;
} else {
max[0] = Math.max(max[0], orgPos.x);
max[1] = Math.max(max[1], orgPos.y);
max[2] = Math.max(max[2], orgPos.z);
min[0] = Math.min(min[0], orgPos.x);
min[1] = Math.min(min[1], orgPos.y);
min[2] = Math.min(min[2], orgPos.z);
}
}
addLogEntry("RandomSet", "Generated points: " + amount);
var _msg = "<table>";
_msg += "<tr>";
_msg += "<td><b>Total amount: </b></td><td><b>" + success + "</b></td></td>";
_msg += "</tr>";
_msg += "<tr>";
_msg += "<td>Failed amount: </b></td><td>0 (sic!)</td>";
_msg += "</tr>";
_msg += "<tr>";
_msg += "<td>Success amount: </b></td><td>" + success + "</td>";
_msg += "</tr>";
_msg += "<tr></tr>";
_msg += "<tr>";
_msg += "<td>Minimals: </b></td><td>" + min[0] + ";" + min[1] + ";" + min[2] + "</td>";
_msg += "</tr>";
_msg += "<tr>";
_msg += "<td>Maximals: </b></td><td>" + max[0] + ";" + max[1] + ";" + max[2] + "</td>";
_msg += "</tr>";
_msg += "</table>";
document.getElementById("parse_info").innerHTML = _msg;
return tempData;
}