1
- //import { getProject } from '@theatre/core';
1
+ import { getProject , types as t } from '@theatre/core'
2
+ import { ObjectType } from '@/classes/interfaces/ObjectType' ;
3
+
2
4
//import studio from '@theatre/studio';
3
5
import gsap from 'gsap'
4
6
5
7
6
8
export default class Animations {
7
- constructor ( ) {
8
9
10
+ webgl : any
11
+ vector3D : any
9
12
13
+ constructor ( webgl ) {
14
+
15
+ this . webgl = webgl
16
+
17
+
18
+ const nudgableNumber = ( defaultValue ) => t . number ( defaultValue , { nudgeMultiplier : 0.01 } ) ;
19
+
20
+ this . vector3D = {
21
+ x : nudgableNumber ( 0 ) ,
22
+ y : nudgableNumber ( 0 ) ,
23
+ z : nudgableNumber ( 0 )
24
+ } ;
10
25
11
- // studio.initialize();
12
- // console.log(studio);
26
+ if ( window . location . pathname === "/studio" ) {
13
27
14
- //const project = this.createProject('THREE.js x Theatre.js');
15
- //const sheet = this.createSheet(project, 'Animated scene');
28
+ import ( '@theatre/studio' ) . then ( studio => {
29
+ studio . default . initialize ( ) //.initialize()
30
+ } ) ;
31
+
32
+
33
+ }
34
+
16
35
}
17
36
37
+
38
+ // gsap shit
18
39
createTimeline ( ) {
19
40
const tl = gsap . timeline ( { onUpdate : this . onUpdate } )
20
41
return tl ;
21
42
}
22
43
44
+
45
+
46
+
23
47
start ( camera , target ) {
24
- const tl = gsap . timeline ( {
25
- onUpdate : ( ) => {
26
- camera . lookAt ( target )
27
- }
28
- } )
29
48
30
49
31
- tl . to ( '.button-start' , { y : - 10 , opacity : 0 , duration : 0.4 } )
32
- tl . to ( 'canvas' , { opacity : 1 , duration : 0.8 , ease : 'power4.inOut' } )
33
50
34
- tl . to ( camera . position , { x : 12 , y : 0.5 , z : - 6 , ease : 'power2.inOut' , duration : 5 } )
35
- tl . to ( camera . position , { x : 11 , y : 3 , z : 8 , ease : 'power2.out' , duration : 10 } , 7 )
36
- tl . to ( camera . position , { z : "-=5" , ease : 'power2.out' , duration : 4 } , 18 )
37
- tl . to ( camera . position , { z : "+=5" , ease : 'power2.out' , duration : 4 } , 22 )
38
- tl . to ( camera . position , { x : 12 , y : 0.5 , z : - 6 , ease : 'power2.out' , duration : 4 } , 24 )
39
- tl . to ( camera . position , { x : 10 , y : 1 , z : - 3 , ease : 'power2.out' , duration : 4 } , 26 )
40
- //tl.to(camera.rotation, { x: 0.612, y: 1.41, z: 0.60, ease: 'power4.inOut', duration: 4})
41
- // tl.to(camera.quaternion, { x: 0.612, y: 1.41, z: 0.60, w: 0 ease: 'power4.inOut', duration: 4})
42
- tl . to ( '.ui' , { display : 'none' } , 2 )
51
+ // const tl = gsap.timeline({
52
+ // onUpdate: ()=> {
53
+ // camera.lookAt(target)
54
+ // }
55
+ // })
56
+
57
+
58
+ // tl.to('.button-start', { y: -10, opacity: 0, duration: 0.4})
59
+ // tl.to('canvas', { opacity: 1, duration: 0.8, ease: 'power4.inOut'})
60
+
61
+ // tl.to(camera.position, { x: 12, y: 0.5, z: -6, ease: 'power2.inOut', duration: 5 })
62
+ // tl.to(camera.position, { x: 11, y: 3, z: 8, ease: 'power2.out', duration: 10 }, 7)
63
+ // tl.to(camera.position, { z: "-=5", ease: 'power2.out', duration: 4 }, 18)
64
+ // tl.to(camera.position, { z: "+=5", ease: 'power2.out', duration: 4 }, 22)
65
+ // tl.to(camera.position, { x: 12, y: 0.5, z: -6, ease: 'power2.out', duration: 4 }, 24)
66
+ // tl.to(camera.position, { x: 10, y: 1, z: -3, ease: 'power2.out', duration: 4 }, 26)
67
+ // //tl.to(camera.rotation, { x: 0.612, y: 1.41, z: 0.60, ease: 'power4.inOut', duration: 4})
68
+ // // tl.to(camera.quaternion, { x: 0.612, y: 1.41, z: 0.60, w: 0 ease: 'power4.inOut', duration: 4})
69
+ // tl.to('.ui', { display: 'none'}, 2)
43
70
44
71
45
72
@@ -59,32 +86,96 @@ export default class Animations {
59
86
60
87
if ( audio_number === 1 ) {
61
88
62
- tl . to ( camera . position , { z : "+=11" , y : "+=1" , x : "-=3" , ease : 'power2.inOut' , duration : 5 } , 0 )
63
- tl . to ( camera . position , { z : "-=11" , y : "+=2" , x : "+=3" , ease : 'power2.out' , duration : 5 } , 5 )
64
- tl . to ( camera . position , { x : 7.7231 , y : 1.294 , z : - 2.2 , ease : 'power2.out' , duration : 5 } , 10 )
65
- tl . to ( camera . position , { z : "-=4.2" , y : 1.2 , ease : 'power2.out' , duration : 5 } , 15 )
66
- tl . to ( camera . position , { x :7.98 , y : 1.981 , z :1 , ease : 'power2.out' , duration : 3 } , 20 )
89
+ // tl.to(camera.position, { z: "+=11", y: "+=1", x: "-=3", ease: 'power2.inOut', duration: 5 }, 0)
90
+ // tl.to(camera.position, { z: "-=11", y: "+=2", x: "+=3", ease: 'power2.out', duration: 5 }, 5)
91
+ // tl.to(camera.position, { x: 7.7231, y: 1.294, z: -2.2, ease: 'power2.out', duration: 5}, 10)
92
+ // tl.to(camera.position, { z: "-=4.2", y: 1.2, ease: 'power2.out', duration: 5}, 15)
93
+ // tl.to(camera.position, { x:7.98, y: 1.981, z:1, ease: 'power2.out', duration: 3}, 20)
67
94
68
95
}
69
96
70
97
if ( audio_number === 2 ) {
71
- tl . to ( camera . position , { x : 6.762 , y : 1.2 , z : 4.3 , ease : 'power2.inOut' , duration : 4 } )
72
- tl . to ( camera . position , { x : 12 , y : 4.3 , z : 0.5 , ease : 'power2.inOut' , duration : 12 } , 4 )
98
+ // tl.to(camera.position, { x: 6.762, y: 1.2, z: 4.3, ease: 'power2.inOut', duration: 4})
99
+ // tl.to(camera.position, { x: 12, y: 4.3, z: 0.5, ease: 'power2.inOut', duration: 12}, 4)
73
100
// tl.to(camera.position, { x: 4.6, y: 1.2, z: 0.95, ease: 'power2.inOut', duration: 4})
74
101
}
75
102
}
76
103
77
104
78
105
79
106
createProject ( project_name ) {
80
- // Create a project for the animation
81
- // const project = getProject(project_name);
82
-
83
- //return project;
107
+ // Create a project for the animation
108
+ const project = getProject ( project_name ) ;
109
+ return project ;
84
110
}
85
111
86
- createSheet ( project , sheet_name ) {
112
+ createSheet ( project , sheet_name , audio ) {
87
113
// Create a sheet
88
- //const sheet = project.sheet(sheet_name);
114
+ const sheet = project . sheet ( sheet_name ) ;
115
+
116
+ if ( audio ) {
117
+ this . attachAudio ( sheet , audio )
118
+ }
119
+ return sheet ;
120
+ }
121
+
122
+ createIntroduction ( ) {
123
+ const project = this . createProject ( 'Introduction' )
124
+ const sheet = this . createSheet ( project , 'Camera Animation' , '/sounds/initialisation.mp3' )
125
+
126
+ this . createTheatreObject ( sheet , "camera" , this . webgl . camera . instance , {
127
+
128
+ transforms : {
129
+ position : this . vector3D ,
130
+ rotation : this . vector3D
131
+ } ,
132
+
133
+ target : {
134
+ position : { x : 0 , y : 2 , z : 1 } ,
135
+ }
136
+ } )
137
+ }
138
+
139
+ createTheatreObject ( sheet , object_name , mesh , object_properties ) {
140
+
141
+ const object = sheet . object ( object_name , object_properties )
142
+
143
+ this . attachOnValueChange ( object , object_name , mesh )
144
+ }
145
+
146
+ attachOnValueChange ( object , object_name , mesh ) {
147
+
148
+
149
+ object . onValuesChange ( ( values ) => {
150
+
151
+ // position // rotation
152
+ for ( const [ transform , value ] of Object . entries ( values . transforms ) ) {
153
+ //@ts -ignore
154
+ mesh [ transform ] . set ( value . x , value . y , value . z ) ;
155
+ }
156
+
157
+ if ( object_name === "camera" ) {
158
+ for ( const [ transform , value ] of Object . entries ( values . target ) ) {
159
+ //@ts -ignore
160
+ mesh . lookAt ( value . x , value . y , value . z ) ;
161
+ }
162
+ }
163
+ } )
164
+ }
165
+
166
+
167
+ attachAudio ( sheet , source ) {
168
+
169
+ sheet . sequence . attachAudio ( {
170
+ source : source
171
+ } ) . then ( ( ) => {
172
+ sheet . sequence . play ( { iterationCount : 1 } )
173
+ } ) ;
174
+
175
+ }
176
+
177
+
178
+ playAnimations ( project , sheet , iterationCount : number ) {
179
+ project . ready . then ( ( ) => sheet . sequence . play ( { iterationCount : iterationCount } ) )
89
180
}
90
181
}
0 commit comments