Skip to content

Commit fc5a7bb

Browse files
committed
Add animations for plant and description
1 parent 35dd48b commit fc5a7bb

9 files changed

+221
-24
lines changed

package-lock.json

+56-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@testing-library/react": "^13.4.0",
1515
"@testing-library/user-event": "^13.5.0",
1616
"@types/three": "^0.139.0",
17-
"@types/webgi": "https://storage.googleapis.com/dist.pixotronics.com/webgi/runtime/bundle-types-0.5.5.tgz",
17+
"@types/webgi": "https://storage.googleapis.com/dist.pixotronics.com/webgi/runtime/bundle-types-0.9.0.tgz",
1818
"axios": "^1.7.2",
1919
"gsap": "^3.11.4",
2020
"postcss-flexbugs-fixes": "^5.0.2",
@@ -23,16 +23,16 @@
2323
"react": "^18.2.0",
2424
"react-dom": "^18.2.0",
2525
"web-vitals": "^2.1.4",
26-
"webgi": "https://storage.googleapis.com/dist.pixotronics.com/webgi/runtime/bundle-0.5.8.tgz"
26+
"webgi": "https://storage.googleapis.com/dist.pixotronics.com/webgi/runtime/bundle-0.9.0.tgz"
2727
},
2828
"devDependencies": {
2929
"@types/react": "^18.0.27",
3030
"@types/react-dom": "^18.0.10",
3131
"@types/three": "^0.139.0",
32-
"@types/webgi": "https://storage.googleapis.com/dist.pixotronics.com/webgi/runtime/bundle-types-0.5.5.tgz",
32+
"@types/webgi": "https://storage.googleapis.com/dist.pixotronics.com/webgi/runtime/bundle-types-0.9.0.tgz",
3333
"@vitejs/plugin-react": "^3.1.0",
3434
"cross-env": "^7.0.3",
3535
"vite": "^4.1.0",
36-
"webgi": "https://storage.googleapis.com/dist.pixotronics.com/webgi/runtime/bundle-0.5.5.tgz"
36+
"webgi": "https://storage.googleapis.com/dist.pixotronics.com/webgi/runtime/bundle-0.9.0.tgz"
3737
}
3838
}

public/scene-black.glb

-589 KB
Binary file not shown.

public/scene-second.glb

376 KB
Binary file not shown.

public/scene.glb

-228 KB
Binary file not shown.

src/App.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Footer from "./components/Footer";
77
import FirstPlant from "./components/Plant";
88
import SecondPlant from "./components/Plant2";
99
import ThirdPlant from "./components/Plant3";
10+
import WebgiViewer from "./components/WebgiViewer";
1011

1112
function App() {
1213

@@ -21,6 +22,7 @@ function App() {
2122
<ThirdPlant />
2223
<About />
2324
<Footer />
25+
<WebgiViewer />
2426
</div>
2527
);
2628
}

src/components/WebgiViewer.jsx

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import React, {
2+
useRef,
3+
useState,
4+
useCallback,
5+
forwardRef,
6+
useImperativeHandle,
7+
useEffect,
8+
} from "react";
9+
import {
10+
ViewerApp,
11+
AssetManagerPlugin,
12+
GBufferPlugin,
13+
ProgressivePlugin,
14+
TonemapPlugin,
15+
SSRPlugin,
16+
SSAOPlugin,
17+
GLTFAnimationPlugin,
18+
BloomPlugin,
19+
GammaCorrectionPlugin,
20+
mobileAndTabletCheck,
21+
} from "webgi";
22+
import gsap from "gsap";
23+
import { ScrollTrigger } from "gsap/src/ScrollTrigger";
24+
import { scrollAnimation } from "../lib/scroll-animation";
25+
26+
gsap.registerPlugin(ScrollTrigger);
27+
28+
const WebgiViewer = () => {
29+
const canvasRef = useRef(null);
30+
31+
const memoizedScrollAnimation = useCallback(
32+
(position, target, onUpdate) => {
33+
if (position && target && onUpdate) {
34+
scrollAnimation(position, target, onUpdate);
35+
}
36+
}, []
37+
)
38+
39+
const setupViewer = useCallback(async () => {
40+
const viewer = new ViewerApp({
41+
canvas: canvasRef.current,
42+
});
43+
44+
const assetManager = await viewer.addPlugin(AssetManagerPlugin);
45+
46+
const camera = viewer.scene.activeCamera;
47+
const position = camera.position;
48+
const target = camera.target;
49+
50+
await viewer.addPlugin(GBufferPlugin);
51+
await viewer.addPlugin(new ProgressivePlugin(32));
52+
await viewer.addPlugin(new TonemapPlugin(true));
53+
await viewer.addPlugin(GammaCorrectionPlugin);
54+
await viewer.addPlugin(SSRPlugin);
55+
await viewer.addPlugin(SSAOPlugin);
56+
await viewer.addPlugin(GLTFAnimationPlugin)
57+
await viewer.addPlugin(BloomPlugin);
58+
59+
viewer.renderer.refreshPipeline();
60+
61+
await assetManager.addFromPath("scene.glb");
62+
63+
const gltfAnims = viewer.getPlugin(GLTFAnimationPlugin);
64+
65+
const resetOnEnd = true
66+
await gltfAnims.playClip('Take 001', resetOnEnd)
67+
68+
viewer.getPlugin(TonemapPlugin).config.clipBackground = true;
69+
70+
viewer.scene.activeCamera.setCameraOptions({ controlsEnabled: false });
71+
72+
window.scrollTo(0, 0);
73+
74+
let needsUpdate = true;
75+
const onUpdate = () => {
76+
needsUpdate = true;
77+
viewer.setDirty();
78+
}
79+
80+
viewer.addEventListener("preFrame", () => {
81+
if (needsUpdate) {
82+
camera.positionTargetUpdated(true);
83+
needsUpdate = false;
84+
}
85+
});
86+
memoizedScrollAnimation(position, target, onUpdate)
87+
}, []);
88+
89+
useEffect(() => {
90+
setupViewer();
91+
}, []);
92+
93+
return (
94+
<div id="webgi-canvas-container">
95+
<canvas id="webgi-canvas" ref={canvasRef} />
96+
</div>
97+
);
98+
};
99+
100+
export default WebgiViewer;

src/index.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ nav .link-styled {
259259
display: flex;
260260
align-items: center;
261261
flex-direction: column;
262-
z-index: 1;
262+
z-index: 0;
263263
position: relative;
264264
}
265265

@@ -570,7 +570,7 @@ nav .link-styled {
570570
background-color: #fbfbfd;
571571
height: auto;
572572
position: relative;
573-
z-index: 1;
573+
z-index: 0;
574574
margin-top: -70px;
575575
/*opacity: 0;*/
576576
}

src/lib/scroll-animation.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import gsap from "gsap";
2+
3+
export const scrollAnimation = (position, target, onUpdate) => {
4+
const tl = gsap.timeline();
5+
6+
tl.to(position, {
7+
x: 8.2617479743,
8+
y: 0.0262229300,
9+
z: 4.8205182659,
10+
scrollTrigger: {
11+
trigger: '.first-plant',
12+
start: 'top 75%',
13+
end: 'top top',
14+
scrub: 2,
15+
immediateRender: false
16+
},
17+
onUpdate
18+
})
19+
.to(target, {
20+
x: 3.50,
21+
y: 0.00,
22+
z: 0.00,
23+
scrollTrigger: {
24+
trigger: '.first-plant',
25+
start: 'top 75%',
26+
end: 'top top',
27+
scrub: 2,
28+
immediateRender: false
29+
},
30+
})
31+
.to(position, {
32+
x: -1.8849842312,
33+
y: -8.957473565,
34+
z: 0.4051478909,
35+
scrollTrigger: {
36+
trigger: '.description-section',
37+
start: 'top 75%',
38+
end: 'top top',
39+
scrub: 2,
40+
immediateRender: false
41+
},
42+
onUpdate
43+
})
44+
.to(target, {
45+
x: -1.90,
46+
y: 0.36,
47+
z: 0.00,
48+
scrollTrigger: {
49+
trigger: '.description-section',
50+
start: 'top 75%',
51+
end: 'top top',
52+
scrub: 2,
53+
immediateRender: false
54+
},
55+
})
56+
57+
}

0 commit comments

Comments
 (0)