UNPKG

me-webgpu-react

Version:

React wrapper for **MatrixEngine WebGPU** โ€” a lightweight WebGPU 3D engine for meshes, physics, and more.

159 lines (120 loc) โ€ข 3.76 kB
# ๐Ÿš€ me-webgpu-react React wrapper for **MatrixEngine WebGPU** โ€” a lightweight WebGPU 3D engine for meshes, physics, and more. [![NPM Version](https://img.shields.io/npm/v/me-webgpu-react.svg?style=flat-square)](https://www.npmjs.com/package/me-webgpu-react) [![GitHub Stars](https://img.shields.io/github/stars/zlatnaspirala/matrix-engine-wgpu?style=social)](https://github.com/zlatnaspirala/matrix-engine-wgpu) --- #### ๐Ÿ–ผ๏ธ Logo <img width="320" height="320" src="https://github.com/zlatnaspirala/matrix-engine-wgpu/blob/main/public/res/icons/512.png?raw=true" /> > Logo includes the official WebGPU logo. > **WebGPU logo by [W3C](https://www.w3.org/)** > Licensed under [Creative Commons Attribution 4.0](https://www.w3.org/2023/02/webgpu-logos.html) --- ## โœ… Supported Features ๐ŸŽฏ **Mesh rendering** from `.obj` files ๐Ÿ”ท Built-in primitives: `Cube`, `Ball`, and generic `Mesh` ๐Ÿงฒ Basic **physics support** via [Ammo.js](https://github.com/kripken/ammo.js) ๐ŸŽฏ **Raycasting** support โ€” click to detect 3D object intersections ๐ŸŽฎ Easy access to the raw engine object โš™๏ธ Flexible control of transforms, rotation, scaling, and textures --- ## ๐Ÿ“ฆ Installation ```bash npm install me-webgpu-react ``` or ```bash yarn add me-webgpu-react ``` โšก Usage Example ```tsx import React from "react"; import {MatrixEngineCanvas, Mesh} from "me-webgpu-react"; function App() { const handleEngineReady = (engine: any) => { console.log("Main app object [engine]:", engine); // Access the raw engine here }; return ( <MatrixEngineCanvas onReady={handleEngineReady} canvasSize={{w: 256, h: 256}} clearColor={"black"}> <Mesh position={[0, -2, -10]} rotation={[0, 0, 0]} rotationSpeed={[0, 0, 0]} physics={{enabled: false}} texture={"/res/meshes/cube.png"} meshPath="/res/my-meshes/swat.obj" scale={[5, 5, 5]} /> </MatrixEngineCanvas> ); } export default App; ``` ๐Ÿง  Access the engine from anywhere ```ts const engine = useMatrixEngineWGPU(); ``` Use this hook inside any component to access the engine instance, including raycast utilities and scene graph control. ๐Ÿ” Raycasting Support You can cast rays from the camera into the 3D scene to detect intersections with objects. โœ… Ideal for building object interaction systems like: Object click / selection Highlighting UI placement in 3D Physics-based triggers ๐Ÿ“š Related Projects ๐Ÿ”ง Core engine: matrix-engine-wgpu ๐Ÿงช Physics: ammo.js ๐Ÿงช๐Ÿ Concept "From code" Objects (obj) sequence animation example : ```tsx downloadMeshes( makeObjSeqArg({ id: "swat-walk-pistol", path: "res/my-meshes/objs-sequence/swat-walk-pistol", from: 1, to: 20, }), (m: any) => { setMeshData(m["swat-walk-pistol"]); engine.addMeshObj({ position: {x: 0, y: 0, z: -5}, rotation: {x: 0, y: 0, z: 0}, rotationSpeed: {x: 0, y: 0, z: 0}, texturesPaths: ["./res/meshes/cube.png"], name: "swat-walk-pistol", mesh: m["swat-walk-pistol"], physics: {enabled: false}, objAnim: { id: "swat-walk-pistol", meshList: m, currentAni: 1, animations: { active: "walk", walk: { from: 1, to: 20, speed: 3, }, // walkPistol: { JUST FOR EXAMPLE ... // from: 36, // to: 60, // speed: 3 // } }, }, }); }, {scale: [1, 1, 1]} ); ``` ๐ŸŒ Live demo link: https://maximumroulette.com/apps/webgpu/react/index.html ๐Ÿ“„ License MIT License Created by Nikola Lukiฤ‡ โœ‰๏ธ zlatnaspirala@gmail.com ๐ŸŒ maximumroulette.com