Skip to content

Commit c4a0471

Browse files
committed
new branch
1 parent 9ec19d9 commit c4a0471

25 files changed

+265
-106
lines changed

assets/glsl/transitions/camera.frag

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
uniform float uAlpha;
2+
3+
void main() {
4+
gl_FragColor = vec4(0.0, 0.0, 0.0, uAlpha);
5+
}

assets/glsl/transitions/camera.vert

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
void main() {
2+
vec3 nPos = position;
3+
nPos.z = -1.;
4+
gl_Position = vec4(nPos, 1.0);
5+
}

classes/Animations.ts

Lines changed: 126 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,72 @@
1-
//import { getProject } from '@theatre/core';
1+
import { getProject, types as t } from '@theatre/core'
2+
import { ObjectType } from '@/classes/interfaces/ObjectType';
3+
24
//import studio from '@theatre/studio';
35
import gsap from 'gsap'
46

57

68
export default class Animations {
7-
constructor() {
89

10+
webgl: any
11+
vector3D: any
912

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+
};
1025

11-
// studio.initialize();
12-
// console.log(studio);
26+
if(window.location.pathname === "/studio") {
1327

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+
1635
}
1736

37+
38+
// gsap shit
1839
createTimeline() {
1940
const tl = gsap.timeline({ onUpdate: this.onUpdate })
2041
return tl;
2142
}
2243

44+
45+
46+
2347
start(camera, target) {
24-
const tl = gsap.timeline({
25-
onUpdate: ()=> {
26-
camera.lookAt(target)
27-
}
28-
})
2948

3049

31-
tl.to('.button-start', { y: -10, opacity: 0, duration: 0.4})
32-
tl.to('canvas', { opacity: 1, duration: 0.8, ease: 'power4.inOut'})
3350

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)
4370

4471

4572

@@ -59,32 +86,96 @@ export default class Animations {
5986

6087
if(audio_number === 1) {
6188

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)
6794

6895
}
6996

7097
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)
73100
// tl.to(camera.position, { x: 4.6, y: 1.2, z: 0.95, ease: 'power2.inOut', duration: 4})
74101
}
75102
}
76103

77104

78105

79106
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;
84110
}
85111

86-
createSheet(project, sheet_name) {
112+
createSheet(project, sheet_name, audio) {
87113
// 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 }))
89180
}
90181
}

classes/Camera.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default class Camera {
1313
coordinates: any
1414
lookTarget: any
1515
controls: any
16+
1617

1718
constructor(fov: number, width: number, near: number, far: number, height?: number) {
1819
this.instance = new PerspectiveCamera(fov, width, near, far);
@@ -21,13 +22,13 @@ export default class Camera {
2122
this.instance.position.z = 0
2223

2324
//this.instance = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, 0, 10000 );
24-
//this.animations = useAnimations()
25-
26-
2725
}
2826

27+
resize(cam) {
28+
cam.aspect = window.innerWidth / window.innerHeight;
29+
cam.updateProjectionMatrix();
30+
}
2931

30-
3132
tweak() {
3233
const debug = useDebug();
3334

@@ -36,10 +37,9 @@ export default class Camera {
3637
expanded: false,
3738
});
3839

39-
4040
camera_page.addInput(this.instance, 'position')
41+
camera_page.addInput(this.instance, 'rotation')
4142

42-
4343
}
4444

4545

classes/Cameras.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

classes/PostProcessing.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class PostProcess {
1919
this.webgl = scene.webgl;
2020
this.camera = scene.camera;
2121
this.composer = new EffectComposer(this.renderer)
22+
2223
this.params = {
2324
blendFunction: BlendFunction.ADD,
2425
blendFunctionNoise: BlendFunction.COLOR_BURN, // substract // MULTIPLY // Overlay
@@ -48,7 +49,8 @@ export default class PostProcess {
4849
const smaa = new SMAAEffect()
4950

5051
this.effect.inverted = true;
51-
//const effectPass = new EffectPass(this.camera, this.effect);
52+
53+
//const effectPass = new EffectPass(this.camera, this.effect);
5254
//this.composer.addPass(effectPass);
5355
this.composer.addPass(new EffectPass(this.camera, smaa, this.effect, noise));
5456

classes/Scene.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as THREE from 'three';
2-
import Controls from './Controls';
2+
import Controls from '@/classes/Controls';
33
import PostProcess from '@/classes/PostProcessing';
4-
import Smoke from '@/classes/Smoke';
4+
import TransitionCamera from '@/classes/managers/TransitionCamera';
55

66
export default class Scene {
77
renderer: any;
@@ -19,7 +19,7 @@ export default class Scene {
1919
lights: any
2020
postProcess: any
2121
clock: any
22-
smoke: any
22+
transition: any
2323

2424
constructor(webgl) {
2525

@@ -36,13 +36,12 @@ export default class Scene {
3636
this.camera = webgl.camera.instance;
3737
this.webgl = webgl;
3838

39-
// this.smoke = new Smoke({ webgl: this.webgl, scene: this })
40-
4139
this.clock = new THREE.Clock();
4240
this.postProcess = new PostProcess({ scene: this })
4341

4442
this.createFog();
4543
this.controls = new Controls(this.camera, this.renderer);
44+
this.transition = new TransitionCamera({ webgl: this.webgl, scene: this })
4645
console.log(this.controls)
4746

4847
// this.changeFog('green')
@@ -105,15 +104,12 @@ export default class Scene {
105104

106105
const camera_h = this.camera.position.y * 0.8;
107106
// console.log(camera_h)
108-
109107
// console.log(this.camera.position)
110-
111-
// this.smoke.update()
112-
113108
this.instance.fog.near = camera_h + 4;
114109
this.instance.fog.far = camera_h * 0.6 + 24;
115110

116111
this.webgl.materials.update(elapsedTime);
112+
this.transition.update()
117113

118114
// console.log(this.camera.position.x, this.camera.position.y, this.camera.position.z)
119115
// this.controls.update();

0 commit comments

Comments
 (0)