Boilerplate to create a minimal React & WebGL app.
It is made using rollup-react-app. The WebGL code is an heavily modified example from Mozilla.
- Create a minimal from scratch React + WebGL app.
- No Three.js
- use React's hook
It will be enhanced with more examples and an article.
GLVIew
component renders a <canvas />
element. GLView iis using the React Effect Hook to make the animation works. The code is very simple:
const GLView = ({ width, height, scene }) => {
const ref = useRef();
useEffect(() => {
const canvas = ref.current;
const webGL = new WebGL(canvas, width, height);
webGL.init(scene);
return () => {
webGL.close();
};
});
return <canvas ref={ref} width={width} height={height} />;
};
WebGL
is the engine where WebGL, shaders, model are intialized.
The rendering animation is done using:
this.render = this.render.bind(this);
this.requestId = requestAnimationFrame(this.render);
scene.js
All the model, shaders, are here and also the scene rendering.
Don't hesitate to test, use, contribute, ...
Made by Mik BRY