-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
407 lines (336 loc) · 8.28 KB
/
script.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
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
// clearing the console (just a CodePen thing)
console.clear();
// there are 3 parts to this
//
// Scene: Setups and manages threejs rendering
// loadModel: Loads the 3d obj file
// setupAnimation: Creates all the GSAP
// animtions and scroll triggers
//
// first we call loadModel, once complete we call
// setupAnimation which creates a new Scene
class Scene {
constructor(model) {
this.views = [
{ bottom: 0, height: 1 },
{ bottom: 0, height: 0 }
];
this.renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true
});
this.renderer.setSize(window.innerWidth, window.innerHeight);
this.renderer.shadowMap.enabled = true;
this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
this.renderer.setPixelRatio(window.devicePixelRatio);
document.body.appendChild(this.renderer.domElement);
// scene
this.scene = new THREE.Scene();
for (var ii = 0; ii < this.views.length; ++ii) {
var view = this.views[ii];
var camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
1,
2000
);
camera.position.fromArray([0, 0, 180]);
camera.layers.disableAll();
camera.layers.enable(ii);
view.camera = camera;
camera.lookAt(new THREE.Vector3(0, 5, 0));
}
//light
this.light = new THREE.PointLight(0xffffff, 0.75);
this.light.position.z = 150;
this.light.position.x = 70;
this.light.position.y = -20;
this.scene.add(this.light);
this.softLight = new THREE.AmbientLight(0xffffff, 1.5);
this.scene.add(this.softLight);
// group
this.onResize();
window.addEventListener("resize", this.onResize, false);
var edges = new THREE.EdgesGeometry(model.children[0].geometry);
let line = new THREE.LineSegments(edges);
line.material.depthTest = false;
line.material.opacity = 0.5;
line.material.transparent = true;
line.position.x = 0.5;
line.position.z = -1;
line.position.y = 0.2;
this.modelGroup = new THREE.Group();
model.layers.set(0);
line.layers.set(1);
this.modelGroup.add(model);
this.modelGroup.add(line);
this.scene.add(this.modelGroup);
}
render = () => {
for (var ii = 0; ii < this.views.length; ++ii) {
var view = this.views[ii];
var camera = view.camera;
var bottom = Math.floor(this.h * view.bottom);
var height = Math.floor(this.h * view.height);
this.renderer.setViewport(0, 0, this.w, this.h);
this.renderer.setScissor(0, bottom, this.w, height);
this.renderer.setScissorTest(true);
camera.aspect = this.w / this.h;
this.renderer.render(this.scene, camera);
}
};
onResize = () => {
this.w = window.innerWidth;
this.h = window.innerHeight;
for (var ii = 0; ii < this.views.length; ++ii) {
var view = this.views[ii];
var camera = view.camera;
camera.aspect = this.w / this.h;
let camZ = (screen.width - this.w * 1) / 3;
camera.position.z = camZ < 180 ? 180 : camZ;
camera.updateProjectionMatrix();
}
this.renderer.setSize(this.w, this.h);
this.render();
};
}
function loadModel() {
gsap.registerPlugin(ScrollTrigger);
gsap.registerPlugin(DrawSVGPlugin);
gsap.set("#line-length", { drawSVG: 0 });
gsap.set("#line-wingspan", { drawSVG: 0 });
gsap.set("#circle-phalange", { drawSVG: 0 });
var object;
function onModelLoaded() {
object.traverse(function (child) {
let mat = new THREE.MeshPhongMaterial({
color: 0x171511,
specular: 0xd0cbc7,
shininess: 5,
flatShading: true
});
child.material = mat;
});
setupAnimation(object);
}
var manager = new THREE.LoadingManager(onModelLoaded);
manager.onProgress = (item, loaded, total) => console.log(item, loaded, total);
var loader = new THREE.OBJLoader(manager);
loader.load(
"https://assets.codepen.io/557388/1405+Plane_1.obj",
function (obj) {
object = obj;
}
);
}
function setupAnimation(model) {
let scene = new Scene(model);
let plane = scene.modelGroup;
gsap.fromTo(
"canvas",
{ x: "50%", autoAlpha: 0 },
{ duration: 1, x: "0%", autoAlpha: 1 }
);
gsap.to(".loading", { autoAlpha: 0 });
gsap.to(".scroll-cta", { opacity: 1 });
gsap.set("svg", { autoAlpha: 1 });
let tau = Math.PI * 2;
gsap.set(plane.rotation, { y: tau * -0.25 });
gsap.set(plane.position, { x: 80, y: -32, z: -60 });
scene.render();
var sectionDuration = 1;
gsap.fromTo(
scene.views[1],
{ height: 1, bottom: 0 },
{
height: 0,
bottom: 1,
ease: "none",
scrollTrigger: {
trigger: ".blueprint",
scrub: true,
start: "bottom bottom",
end: "bottom top"
}
}
);
gsap.fromTo(
scene.views[1],
{ height: 0, bottom: 0 },
{
height: 1,
bottom: 0,
ease: "none",
scrollTrigger: {
trigger: ".blueprint",
scrub: true,
start: "top bottom",
end: "top top"
}
}
);
gsap.to(".ground", {
y: "30%",
scrollTrigger: {
trigger: ".ground-container",
scrub: true,
start: "top bottom",
end: "bottom top"
}
});
gsap.from(".clouds", {
y: "25%",
scrollTrigger: {
trigger: ".ground-container",
scrub: true,
start: "top bottom",
end: "bottom top"
}
});
gsap.to("#line-length", {
drawSVG: 100,
scrollTrigger: {
trigger: ".length",
scrub: true,
start: "top bottom",
end: "top top"
}
});
gsap.to("#line-wingspan", {
drawSVG: 100,
scrollTrigger: {
trigger: ".wingspan",
scrub: true,
start: "top 25%",
end: "bottom 50%"
}
});
gsap.to("#circle-phalange", {
drawSVG: 100,
scrollTrigger: {
trigger: ".phalange",
scrub: true,
start: "top 50%",
end: "bottom 100%"
}
});
gsap.to("#line-length", {
opacity: 0,
drawSVG: 0,
scrollTrigger: {
trigger: ".length",
scrub: true,
start: "top top",
end: "bottom top"
}
});
gsap.to("#line-wingspan", {
opacity: 0,
drawSVG: 0,
scrollTrigger: {
trigger: ".wingspan",
scrub: true,
start: "top top",
end: "bottom top"
}
});
gsap.to("#circle-phalange", {
opacity: 0,
drawSVG: 0,
scrollTrigger: {
trigger: ".phalange",
scrub: true,
start: "top top",
end: "bottom top"
}
});
let tl = new gsap.timeline({
onUpdate: scene.render,
scrollTrigger: {
trigger: ".content",
scrub: true,
start: "top top",
end: "bottom bottom"
},
defaults: { duration: sectionDuration, ease: "power2.inOut" }
});
let delay = 0;
tl.to(".scroll-cta", { duration: 0.25, opacity: 0 }, delay);
tl.to(plane.position, { x: -10, ease: "power1.in" }, delay);
delay += sectionDuration;
tl.to(
plane.rotation,
{ x: tau * 0.25, y: 0, z: -tau * 0.05, ease: "power1.inOut" },
delay
);
tl.to(plane.position, { x: -40, y: 0, z: -60, ease: "power1.inOut" }, delay);
delay += sectionDuration;
tl.to(
plane.rotation,
{ x: tau * 0.25, y: 0, z: tau * 0.05, ease: "power3.inOut" },
delay
);
tl.to(plane.position, { x: 40, y: 0, z: -60, ease: "power2.inOut" }, delay);
delay += sectionDuration;
tl.to(
plane.rotation,
{ x: tau * 0.2, y: 0, z: -tau * 0.1, ease: "power3.inOut" },
delay
);
tl.to(plane.position, { x: -40, y: 0, z: -30, ease: "power2.inOut" }, delay);
delay += sectionDuration;
tl.to(plane.rotation, { x: 0, z: 0, y: tau * 0.25 }, delay);
tl.to(plane.position, { x: 0, y: -10, z: 50 }, delay);
delay += sectionDuration;
delay += sectionDuration;
tl.to(
plane.rotation,
{ x: tau * 0.25, y: tau * 0.5, z: 0, ease: "power4.inOut" },
delay
);
tl.to(plane.position, { z: 30, ease: "power4.inOut" }, delay);
delay += sectionDuration;
tl.to(
plane.rotation,
{ x: tau * 0.25, y: tau * 0.5, z: 0, ease: "power4.inOut" },
delay
);
tl.to(plane.position, { z: 60, x: 30, ease: "power4.inOut" }, delay);
delay += sectionDuration;
tl.to(
plane.rotation,
{ x: tau * 0.35, y: tau * 0.75, z: tau * 0.6, ease: "power4.inOut" },
delay
);
tl.to(plane.position, { z: 100, x: 20, y: 0, ease: "power4.inOut" }, delay);
delay += sectionDuration;
tl.to(
plane.rotation,
{ x: tau * 0.15, y: tau * 0.85, z: -tau * 0, ease: "power1.in" },
delay
);
tl.to(plane.position, { z: -150, x: 0, y: 0, ease: "power1.inOut" }, delay);
delay += sectionDuration;
tl.to(
plane.rotation,
{
duration: sectionDuration,
x: -tau * 0.05,
y: tau,
z: -tau * 0.1,
ease: "none"
},
delay
);
tl.to(
plane.position,
{ duration: sectionDuration, x: 0, y: 30, z: 320, ease: "power1.in" },
delay
);
tl.to(
scene.light.position,
{ duration: sectionDuration, x: 0, y: 0, z: 0 },
delay
);
}
loadModel();