MCPcopy Create free account
hub / github.com/SuboptimalEng/three-js-tutorials / App

Function App

11-shaders-part-02/src/App.jsx:7–157  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import SceneInit from './lib/SceneInit';
6
7function App() {
8 useEffect(() => {
9 const test = new SceneInit('myThreeJsCanvas');
10 test.initialize();
11 test.animate();
12
13 const axesHelper = new THREE.AxesHelper(16);
14 test.scene.add(axesHelper);
15
16 // part 1 - boilerplate code
17 // const boxGeometry = new THREE.BoxGeometry(24, 4, 24, 24, 4, 24);
18 // const boxMaterial = new THREE.MeshStandardMaterial({
19 // color: 0xff0000,
20 // wireframe: true,
21 // });
22 // const boxMesh = new THREE.Mesh(boxGeometry, boxMaterial);
23 // test.scene.add(boxMesh);
24
25 // refactor glsl shader code
26 // const boxGeometry = new THREE.BoxGeometry(24, 4, 24, 24, 4, 24);
27 // const boxMaterial = new THREE.ShaderMaterial({
28 // wireframe: true,
29 // vertexShader: `
30 // void main() {
31 // vec4 result;
32 // result = vec4(position.x, position.y, position.z, 1.0);
33 // gl_Position = projectionMatrix
34 // * modelViewMatrix
35 // * result;
36 // }
37 // `,
38 // fragmentShader: `
39 // // varying vec3 pos;
40 // void main() {
41 // gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
42 // }
43 // `,
44 // });
45 // const boxMesh = new THREE.Mesh(boxGeometry, boxMaterial);
46 // test.scene.add(boxMesh);
47
48 // define uniform data
49 const uniformData = {
50 u_time: {
51 type: 'f',
52 value: test.clock.getElapsedTime(),
53 },
54 };
55 const render = () => {
56 uniformData.u_time.value = test.clock.getElapsedTime();
57 window.requestAnimationFrame(render);
58 };
59 render();
60
61 // glsl shader with uniform variables
62 // const boxGeometry = new THREE.BoxGeometry(24, 4, 24, 24, 4, 24);
63 // const boxMaterial = new THREE.ShaderMaterial({
64 // wireframe: true,

Callers

nothing calls this directly

Calls 3

initializeMethod · 0.95
animateMethod · 0.95
renderFunction · 0.70

Tested by

no test coverage detected