@@ -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' ;
812import 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
1117export 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}
0 commit comments