Skip to content

Commit 8666f76

Browse files
committed
landing
1 parent e83fac0 commit 8666f76

File tree

9 files changed

+104
-17
lines changed

9 files changed

+104
-17
lines changed

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"glsl-fxaa": "^3.0.0",
2525
"glslify-bundle": "^5.1.1",
2626
"glslify-deps": "^1.3.1",
27+
"gsap": "^2.1.3",
2728
"magicshader": "^0.1.2",
29+
"math-toolbox": "^1.12.0",
2830
"orbit-controls-es6": "^2.0.0",
2931
"parcel-bundler": "^1.12.3",
3032
"resource-loader": "^2.2.4",

src/assets/texture.png

57.1 KB
Loading

src/js/assets.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import deferred from './utils/deferred';
44

55
const Resource = Loader.Resource;
66
const RESOURCES = [
7-
// {
8-
// name: 'photo',
9-
// url: require('/assets/photo.jpg')
10-
// },
7+
{
8+
name: 'texture',
9+
url: require('/assets/texture.png')
10+
},
1111

1212
// {
1313
// name: 'photo',

src/js/camera.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@ import { PerspectiveCamera, Vector3 } from 'three';
22
import { component } from 'bidello';
33
import OrbitControls from 'orbit-controls-es6';
44
import renderer from './renderer';
5+
import { map, lerp } from 'math-toolbox';
56

67
class Camera extends component(PerspectiveCamera) {
78
constructor() {
89
super(35, 0, 0.1, 500);
910

1011
this.position.set(0, 0, -10);
1112
this.lookAt(new Vector3(0, 0, 0));
12-
this.initOrbitControl();
13+
// this.initOrbitControl();
14+
15+
this.x = 0;
16+
this.y = 0;
17+
18+
document.addEventListener('mousemove', e => {
19+
this.x = map(e.clientX, 0, window.innerWidth, -7, 7);
20+
this.y = map(e.clientY, 0, window.innerHeight, -5, 5);
21+
})
1322
}
1423

1524
initOrbitControl() {
@@ -23,6 +32,20 @@ class Camera extends component(PerspectiveCamera) {
2332
onResize({ ratio }) {
2433
this.aspect = ratio;
2534
this.updateProjectionMatrix();
35+
this.calculateUnitSize(ratio);
36+
}
37+
38+
calculateUnitSize(ratio) {
39+
const vFov = this.fov * Math.PI / 180;
40+
41+
this.unitHeight = 2 * Math.tan(vFov / 2) * 20; // 15 was the original pos
42+
this.unitWidth = this.unitHeight * ratio;
43+
}
44+
45+
onRaf({ delta }) {
46+
this.position.x = lerp(this.position.x, this.x, .06);
47+
this.position.y = lerp(this.position.y, this.y, .06);
48+
this.lookAt(new Vector3(0, 0, 0));
2649
}
2750
}
2851

src/js/cube/cube.frag

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
precision highp float;
22

3+
uniform sampler2D uTex;
34
uniform vec3 color; // ms({ value: '#ff0000' })
45
uniform float xAlpha; // ms({ value: 0, step: 0.01, range: [0, 1] })
56

@@ -9,13 +10,15 @@ varying float vDelay;
910
void main(){
1011
// float alpha = step(xAlpha, vUv.x);
1112

12-
// if (vUv.x<=.001||vUv.x>=.998){
13+
// if (vUv.x <=.001 || vUv.x>=.998){
1314
// discard;
1415
// }
16+
17+
vec3 color = texture2D(uTex, vUv).rgb;
1518

16-
if (vUv.x<1.-xAlpha){
19+
if (vUv.x > xAlpha){
1720
discard;
1821
}
1922

20-
gl_FragColor = vec4(vUv,1.,1.);
23+
gl_FragColor = vec4(color, 1.);
2124
}

src/js/cube/cube.js

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,71 @@ import {
44
BufferGeometryLoader,
55
Mesh,
66
DoubleSide,
7+
Texture,
8+
RepeatWrapping,
9+
NearestFilter,
710
} from 'three';
11+
import { TweenMax, Elastic } from 'gsap/all';
812
import cubeData from './cube.json';
9-
import MagicShader from 'magicshader';
13+
import MagicShader, { gui } from 'magicshader';
14+
import assets from '../assets';
15+
import camera from '../camera';
1016

1117
export default class extends component(Object3D) {
1218
init() {
1319
this.geometry = new BufferGeometryLoader().parse(cubeData);
20+
this.geometry.rotateX(Math.PI / 2);
21+
this.geometry.rotateZ(Math.PI / 2);
22+
this.geometry.rotateX(-Math.PI / 2);
1423

24+
1525
this.material = new MagicShader({
1626
name: 'Cube',
1727
vertexShader: require('./cube.vert'),
1828
fragmentShader: require('./cube.frag'),
29+
uniforms: {
30+
uTex: { value: new Texture() },
31+
uTime: { value: 0 },
32+
},
1933
side: DoubleSide,
2034
});
2135

22-
this.mesh = new Mesh(this.geometry, this.material);
36+
assets.resources.texture.loading.then(() => {
37+
this.material.uniforms.uTex.value = new Texture(assets.resources.texture.meta.data);
38+
this.material.uniforms.uTex.value.anisotropy = 16;
39+
this.material.uniforms.uTex.value.wrapS = RepeatWrapping;
40+
this.material.uniforms.uTex.value.wrapT = RepeatWrapping;
41+
// this.material.uniforms.uTex.value.minFilter = NearestFilter;
42+
// this.material.uniforms.uTex.value.magFilter = NearestFilter;
43+
this.material.uniforms.uTex.value.needsUpdate = true;
44+
});
45+
46+
TweenMax.to(this.material.uniforms.xAlpha, 2, {
47+
// delay: 2,
48+
value: 1,
49+
ease: 'Power4.easeInOut',
50+
});
51+
52+
TweenMax.to(this.material.uniforms.uForce, 2, {
53+
delay: 2.4,
54+
value: 0.32,
55+
ease: Elastic.easeOut.config(1, 0.3),
56+
});
2357

58+
this.mesh = new Mesh(this.geometry, this.material);
2459
this.add(this.mesh);
60+
61+
gui.destroy();
62+
}
63+
64+
onResize() {
65+
// this.unitWidth
66+
this.scale.setScalar(camera.unitWidth * 0.04);
2567
}
2668

2769
onRaf({ delta }) {
28-
this.mesh.rotation.x += 0.3 * delta;
29-
this.mesh.rotation.y += 0.3 * delta;
70+
this.material.uniforms.uTime.value += delta;
71+
// this.mesh.rotation.x += 0.3 * delta;
72+
// this.mesh.rotation.y += 0.3 * delta;
3073
}
3174
}

src/js/cube/cube.vert

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ attribute float delay;
77

88
uniform mat4 modelViewMatrix;
99
uniform mat4 projectionMatrix;
10-
uniform float uSpeed;// ms({ value: 0.0, step: 0.001, range: [-10, 10] })
11-
uniform float uForce;// ms({ value: 0.0, step: 0.001, range: [-10, 10] })
12-
uniform float uRotation;// ms({ value: -0.35, step: 0.001, range: [-1, 1] })
10+
uniform float uSpeed; // ms({ value: 0.0, step: 0.001, range: [-10, 10] })
11+
uniform float uForce; // ms({ value: 0.0, step: 0.001, range: [-10, 10] })
12+
uniform float uRotation; // ms({ value: -0.35, step: 0.001, range: [-1, 1] })
13+
uniform float uTime;
1314

1415
varying vec2 vUv;
1516
varying float vDelay;
@@ -48,11 +49,11 @@ void main(){
4849
float force=pos.x*uForce;
4950

5051
pos.xyz+=pivot;
51-
pos=pos*rotateX(force+uSpeed);
52+
pos=pos*rotateX(force+uTime * 3.0);
5253
// vNormal = vNormal * rotateX(-(force + speed));
5354
pos.xyz-=pivot;
5455

55-
pos=pos*rotateZ(uRotation);
56+
// pos=pos*rotateZ(uRotation);
5657

5758
pos+=offset;
5859

src/js/renderer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { WebGLRenderer } from 'three';
22
import { component } from 'bidello';
3+
import settings from './settings';
34

45
class Renderer extends component(WebGLRenderer) {
56
constructor() {
67
super({
78
powerPreference: 'high-performance',
89
antialiasing: false,
910
})
11+
12+
this.setPixelRatio(settings.dpr);
1013
}
1114

1215
onResize({ width, height }) {

0 commit comments

Comments
 (0)