@@ -4,28 +4,71 @@ import {
4
4
BufferGeometryLoader ,
5
5
Mesh ,
6
6
DoubleSide ,
7
+ Texture ,
8
+ RepeatWrapping ,
9
+ NearestFilter ,
7
10
} from 'three' ;
11
+ import { TweenMax , Elastic } from 'gsap/all' ;
8
12
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' ;
10
16
11
17
export default class extends component ( Object3D ) {
12
18
init ( ) {
13
19
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 ) ;
14
23
24
+
15
25
this . material = new MagicShader ( {
16
26
name : 'Cube' ,
17
27
vertexShader : require ( './cube.vert' ) ,
18
28
fragmentShader : require ( './cube.frag' ) ,
29
+ uniforms : {
30
+ uTex : { value : new Texture ( ) } ,
31
+ uTime : { value : 0 } ,
32
+ } ,
19
33
side : DoubleSide ,
20
34
} ) ;
21
35
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
+ } ) ;
23
57
58
+ this . mesh = new Mesh ( this . geometry , this . material ) ;
24
59
this . add ( this . mesh ) ;
60
+
61
+ gui . destroy ( ) ;
62
+ }
63
+
64
+ onResize ( ) {
65
+ // this.unitWidth
66
+ this . scale . setScalar ( camera . unitWidth * 0.04 ) ;
25
67
}
26
68
27
69
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;
30
73
}
31
74
}
0 commit comments