-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
340 lines (249 loc) · 10.6 KB
/
app.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
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
function createPoint({ x, y, z , size }) {
const pointGeometry = new THREE.Geometry();
pointGeometry.vertices.push(new THREE.Vector3(x, y, z));
const pointMaterial = new THREE.PointsMaterial({ size, sizeAttenuation: false });
const point = new THREE.Points(pointGeometry, pointMaterial);
return point;
}
function createLine({ x0, y0, z0, x1, y1, z1 }) {
const lineGeometry = new THREE.Geometry();
lineGeometry.vertices.push(new THREE.Vector3(x0, y0, z0)); // TODO: switch to a BufferGeometry for performance
lineGeometry.vertices.push(new THREE.Vector3(x1, y1, z1));
const lineMaterial = new THREE.LineBasicMaterial({ color: 0xffffff });
const line = new THREE.Line(lineGeometry, lineMaterial);
return line;
}
function createPlane({ width, height, widthSegments, heightSegments }) {
const planeGeometry = new THREE.PlaneGeometry(width, height, widthSegments, heightSegments);
planeMaterial = new THREE.MeshBasicMaterial({ color: (Math.random() * 0xffffff), side: THREE.DoubleSide });
// const imageTexture = new THREE.TextureLoader().load('photographs/eye.jpg');
// const planeMaterial = new THREE.MeshBasicMaterial({ map: imageTexture, side: THREE.DoubleSide });
const plane = new THREE.Mesh(planeGeometry, planeMaterial);
return plane;
}
function columnIK(column, circumference) {
// To start, distrubute the bend evenly across all images in the column
const base = column[0][0];
let tgt = { x: 1, y: 2 };
for (let i = 0; i < column.length - 1; i++) {
const currentXY = { x: column[i][0].geometry.vertices[0].x, y: column[i][0].geometry.vertices[0].y };
const nextXY = { x: column[i + 1][0].geometry.vertices[0].x, y: column[i + 1][0].geometry.vertices[0].y };
const r = reach(currentXY, nextXY, tgt);
column[i][0].geometry.vertices[0].x = r[0].x;
column[i][0].geometry.vertices[0].y = r[0].y;
tgt = r[1];
}
column[column.length - 1][0] = tgt;
tgt = base;
for (let i = column.length - 1; i > 0; i -= 1) {
console.log(i);
console.log(column[i][0]);
const currentXY = { x: column[i][0].geometry.vertices[0].x, y: column[i][0].geometry.vertices[0].y };
const nextXY = { x: column[i - 1][0].geometry.vertices[0].x, y: column[i - 1][0].geometry.vertices[0].y };
const r = reach(currentXY, nextXY, tgt);
column[i][0].geometry.vertices[0].x = r[0].x;
column[i][0].geometry.vertices[0].y = r[0].y;
tgt = r[1];
}
column[0][0].geometry.vertices[0].x = tgt.x;
column[0][0].geometry.vertices[0].y = tgt.y;
/*
let belowImage = Math.floor(column.length / 2);
let aboveImage;
if ((column.length % 2) > 0) {
aboveImage = belowImage + 2; // skip the middle image so it remains parallel with the screen
} else {
aboveImage = belowImage + 1;
}
const numImagesAbove = column.length - aboveImage;
const radius = circumference / (2 * Math.PI);
*/
/*
let lastTopLeftX = column[aboveImage - 1][3].geometry.vertices[0].x;
let lastTopLeftY = column[aboveImage - 1][3].geometry.vertices[0].y;
let lastTopRightX = column[aboveImage - 1][3].geometry.vertices[0].x;
let lastTopRightY = column[aboveImage - 1][3].geometry.vertices[0].y;
console.log(lastTopLeftX, column[aboveImage][0].geometry.vertices[0].x);
column[aboveImage][0].geometry.vertices[0].x = lastTopLeftX;
column[aboveImage][0].geometry.vertices[0].y = lastTopLeftY;
column[aboveImage][1].geometry.vertices[0].x = lastTopRightX;
column[aboveImage][1].geometry.vertices[0].y = lastTopRightY;
const angle = 2 * Math.PI / column.length;
const newTopLeftX = lastTopLeftX + Math.cos(angle) * radius;
const newTopLeftY = lastTopLeftY + Math.sin(angle) * radius;
const newTopRightX = lastTopRightX + Math.cos(angle) * radius;
const newTopRightY = lastTopRightY + Math.sin(angle) * radius;
column[aboveImage][2].geometry.vertices[0].x = newTopLeftX;
column[aboveImage][2].geometry.vertices[0].y = newTopLeftY;
column[aboveImage][3].geometry.vertices[0].x = newTopRightX;
column[aboveImage][3].geometry.vertices[0].y = newTopRightY;
*/
/*
for (let i = 0; i < numImagesAbove; i += 1) {
const angle = 2 * Math.PI / column.length;
const x = originX + cos(angle)*radius;
const y = originY + sin(angle)*radius;
aboveImage += 1;
}
*/
}
function launchViz(numImages) {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 5;
renderer = new THREE.WebGLRenderer(antialias = true);
renderer.setSize(window.innerWidth, window.innerHeight);
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
// each image consists of 4 points and a plane
// Images are distributed into one of 3 columns
const leftColumn = [];
const middleColumn = [];
const rightColumn = [];
const leftColumnWidth = 1;
const middleColumnWidth = 1;
const rightColumnWidth = 1;
const leftColumnImageHeight = 1;
const middleColumnImageHeight = 1;
const rightColumnImageHeight = 1;
const leftColumnStart = 0;
const leftColumnEnd = Math.floor(numImages/3);
const middleColumnStart = leftColumnEnd;
const middleColumnEnd = Math.ceil(numImages/3) * 2;
const rightColumnStart = middleColumnEnd;
const rightColumnEnd = numImages;
const spacingGap = 0.2;
// create points
/*
for(let i = middleColumnStart; i < middleColumnEnd; i += 1) {
const n = i - middleColumnStart;
middleColumn[n] = [];
const xLeft = -middleColumnWidth / 2;
const xRight = middleColumnWidth / 2;
let heightShift = 0;
if (((middleColumnEnd - middleColumnStart) % 2) > 0) {
heightShift = (middleColumnImageHeight / 2)
}
const middleHeight = Math.floor((middleColumnEnd - middleColumnStart) / 2) * middleColumnImageHeight;
const yBottom = n * middleColumnImageHeight - middleHeight - heightShift;
const yTop = (n + 1) * middleColumnImageHeight - middleHeight - heightShift;
const point0 = createPoint({ x: xLeft, y: yBottom, z: 0, size: 3 });
middleColumn[n][0] = point0;
scene.add(point0);
const point1 = createPoint({ x: xRight, y: yBottom, z: 0, size: 3 });
middleColumn[n][1] = point1;
scene.add(point1);
const point2 = createPoint({ x: xLeft, y: yTop, z: 0, size: 3 });
middleColumn[n][2] = point2;
scene.add(point2);
const point3 = createPoint({ x: xRight, y: yTop, z: 0, size: 3 });
middleColumn[n][3] = point3;
scene.add(point3);
}
*/
/*
for(let i = leftColumnStart; i < leftColumnEnd; i += 1) {
const n = i - leftColumnStart;
leftColumn[n] = [];
const xLeft = (-middleColumnWidth / 2) - leftColumnWidth - spacingGap;
const xRight = (-middleColumnWidth / 2) - spacingGap;
let heightShift = 0;
if (((leftColumnEnd - leftColumnStart) % 2) > 0) {
heightShift = (leftColumnImageHeight / 2)
}
const middleHeight = Math.floor((leftColumnEnd - leftColumnStart) / 2) * leftColumnImageHeight;
const yBottom = n * leftColumnImageHeight - middleHeight - heightShift;
const yTop = (n + 1) * leftColumnImageHeight - middleHeight - heightShift;
const point0 = createPoint({ x: xLeft, y: yBottom, z: 0, size: 3 });
leftColumn[n][0] = point0;
scene.add(point0);
const point1 = createPoint({ x: xRight, y: yBottom, z: 0, size: 3 });
leftColumn[n][1] = point1;
scene.add(point1);
const point2 = createPoint({ x: xLeft, y: yTop, z: 0, size: 3 });
leftColumn[n][2] = point2;
scene.add(point2);
const point3 = createPoint({ x: xRight, y: yTop, z: 0, size: 3 });
leftColumn[n][3] = point3;
scene.add(point3);
}
*/
/*
for(let i = rightColumnStart; i < rightColumnEnd; i += 1) {
const n = i - rightColumnStart;
rightColumn[n] = [];
const xLeft = (middleColumnWidth / 2) + spacingGap;
const xRight = (middleColumnWidth / 2) + rightColumnWidth + spacingGap;
let heightShift = 0;
if (((rightColumnEnd - rightColumnStart) % 2) > 0) {
heightShift = (rightColumnImageHeight / 2)
}
const middleHeight = Math.floor((rightColumnEnd - rightColumnStart) / 2) * rightColumnImageHeight;
const yBottom = ((n * rightColumnImageHeight) - middleHeight) - heightShift;
const yTop = ((n + 1) * rightColumnImageHeight - middleHeight) - heightShift;
const point0 = createPoint({ x: xLeft, y: yBottom, z: 0, size: 3 });
rightColumn[n][0] = point0;
scene.add(point0);
const point1 = createPoint({ x: xRight, y: yBottom, z: 0, size: 3 });
rightColumn[n][1] = point1;
scene.add(point1);
const point2 = createPoint({ x: xLeft, y: yTop, z: 0, size: 3 });
rightColumn[n][2] = point2;
scene.add(point2);
const point3 = createPoint({ x: xRight, y: yTop, z: 0, size: 3 });
rightColumn[n][3] = point3;
scene.add(point3);
}
*/
//const line = createLine({ x0: 0, y0: 0, z0: 0, x1: 2, y1: 2, z1: 2 });
//scene.add(line);
/*
let leftColumnCircumference = 0;
leftColumn.forEach((points) => {
const plane = createPlane({ width: 1, height: 1, widthSegments: 1, heightSegments: 1 });
// scene.add(plane);
const planeX = points[0].geometry.vertices[0].x + (leftColumnWidth / 2);
const planeY = points[0].geometry.vertices[0].y + (leftColumnImageHeight / 2);
const planeZ = points[0].geometry.vertices[0].z;
plane.position.x = planeX;
plane.position.y = planeY;
plane.position.z = planeZ;
points[0][4] = plane;
leftColumnCircumference += leftColumnImageHeight;
});
*/
// columnIK(leftColumn, leftColumnCircumference);
/*
let middleColumnCircumference = 0;
middleColumn.forEach((points) => {
const plane = createPlane({ width: 1, height: 1, widthSegments: 1, heightSegments: 1 });
scene.add(plane);
const planeX = points[0].geometry.vertices[0].x + (middleColumnWidth / 2);
const planeY = points[0].geometry.vertices[0].y + (middleColumnImageHeight / 2);
const planeZ = points[0].geometry.vertices[0].z;
plane.position.x = planeX;
plane.position.y = planeY;
plane.position.z = planeZ;
points[0][4] = plane;
middleColumnCircumference += middleColumnImageHeight;
});
let rightColumnCircumference = 0;
rightColumn.forEach((points) => {
const plane = createPlane({ width: 1, height: 1, widthSegments: 1, heightSegments: 1 });
scene.add(plane);
const planeX = points[0].geometry.vertices[0].x + (rightColumnWidth / 2);
const planeY = points[0].geometry.vertices[0].y + (rightColumnImageHeight / 2);
const planeZ = points[0].geometry.vertices[0].z;
plane.position.x = planeX;
plane.position.y = planeY;
plane.position.z = planeZ;
points[0][4] = plane;
rightColumnCircumference += rightColumnImageHeight;
});
*/
document.body.appendChild(renderer.domElement);
animate();
}
launchViz(6);