# @polygonjs/react

> React component for the node-based WebGL Polygonjs design tool

Latest version **1.2.30** (published 2022-10-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install @polygonjs/react
pnpm add @polygonjs/react
yarn add @polygonjs/react
bun add @polygonjs/react
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.30 |
| Published | 2022-10-02 |
| First published | 2022-05-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 87.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | @polygonjs |
| Maintainers | polygonjs |
| Keywords | webgl, design, animation, threejs, polygonjs, glsl, 3D |

## Links

- npm: https://www.npmjs.com/package/@polygonjs/react
- npm.io page: https://npm.io/package/@polygonjs/react

## Dependencies (4)

- [react](https://npm.io/package/react.md) ^18.1.0
- [typescript](https://npm.io/package/typescript.md) ^4.6.4
- [@types/react](https://npm.io/package/@types/react.md) ^18.0.8
- [@polygonjs/polygonjs](https://npm.io/package/@polygonjs/polygonjs.md) ^1.2.30

## Alternatives

- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [persona-harness](https://npm.io/package/persona-harness.md) — 4.7K weekly downloads
- [@tsparticles/effect-bubble](https://npm.io/package/@tsparticles/effect-bubble.md) — 4.6K weekly downloads
- [f3d](https://npm.io/package/f3d.md) — 730 weekly downloads
- [spark-html-motion](https://npm.io/package/spark-html-motion.md) — 298 weekly downloads

## Recent versions

- 1.2.30 (latest) — 2022-10-02
- 1.2.23 — 2022-09-20
- 1.2.21 — 2022-09-19
- 1.1.258-2 — 2022-05-11
- 1.1.258 — 2022-05-09

## README

<p align="center">
<img src="https://github.com/polygonjs/polygonjs-assets/blob/master/tutorials/react/logos.png?raw=true" alt="React + Polygonjs"></img>
</p>

<p align="center">
<a href="https://polygonjs.com/react">Live Demo</a> |
<a href="https://polygonjs.com">Polygonjs</a> |
<a href="https://polygonjs.com/forum">Forum</a> |
<a href="https://polygonjs.com/discord">Discord</a>
</p>

# React Component for Polygonjs

This is a react component to easily import WebGL scenes created with the node-based editor [Polygonjs](https://polygonjs.com).

Polygonjs allows you to create complex and procedural scenes with a visual editor, and you can import them with react, and benefit from its reactive states. You can then update the 3D scene from anything in your react setup.

<table style="margin:0px;padding:0px">
	<tr style="margin:0px;padding:0px">
		<td style="margin:0px;padding:0px"><img src="https://github.com/polygonjs/polygonjs-assets/blob/master/tutorials/react/scene_01.gif?raw=true"></img></td>
		<td style="margin:0px;padding:0px"><img src="https://github.com/polygonjs/polygonjs-assets/blob/master/tutorials/react/scene_02.gif?raw=true"></img></td>
	</tr>
	<tr style="margin:0px;padding:0px">
		<td style="margin:0px;padding:0px"><img src="https://github.com/polygonjs/polygonjs-assets/blob/master/tutorials/react/scene_03.gif?raw=true"></img></td>
		<td style="margin:0px;padding:0px"><img src="https://github.com/polygonjs/polygonjs-assets/blob/master/tutorials/react/react_example.gif?raw=true"></img></td>
	</tr>
</table>

[Live Demo >>](https://polygonjs.com/react)

# Install

```bash
yarn add @polygonjs/react
```

or

```bash
npm install @polygonjs/react
```

# How to use

The only 2 required properties to give to the component are:

-   `loadFunction`, which is the function that loads your 3D scene. That function is autogenerated by [polygonjs visual editor](https://polygonjs.com/docs/getting_started).
-   `sceneName`, which is a string to set the scene name (which is used to find the loading image, if used)

```tsx
<PolygonjsScene
	sceneName={"scene_01"}
	loadFunction={loadSceneAsync_scene_01}
/>
```

Once you've saved a scene, you will have a .js file created with a path like `./src/polygonjs/scenes/<sceneName>/autogenerated/loadSceneAsync.js` inside your project, which exports a function called `loadSceneAsync_<sceneName>`.

So assuming you have already created a scene called `scene_01` in your project, the file will be `./src/polygonjs/scenes/scene_01/autogenerated/loadSceneAsync.js` and the exported function will be called `loadSceneAsync_scene_01`.

With that in mind, a minimal render function to load a scene will look like this:

```ts
import {loadSceneAsync_scene_01} from 'src/polygonjs/scenes/scene_01/autogenerated/loadSceneAsync';

export const MyComponent = () => {
	return <PolygonjsScene
				sceneName={"scene_01"}
				loadFunction={loadSceneAsync_scene_01}
			/>;
};
```

This will load your scene asynchronously. This means that the rest of the page will load first, and then the 3D scene will be loaded.

# Other Properties


| name | type | description |
| ---- | ---- | ----------- |
| **displayLoadingProgressBar** | _boolean_  | While the scene is being loaded, a progress bar is updated to reflect the progress. This can be turned off by passing `false` (default: `true`) |
| **displayLoadingPoster** | _boolean_  | While the scene is being loaded, a loading image (or poster) is displayed as a placeholder. The default url of the poster resolves to the location where the editor saves the images screenshot from the viewer (which you can capture yourself using the button with a photo icon). This can be turned off by passing `false` (default: `true`) |
| **posterUrl** | _string_ | Overrides the default poster url. |
| **onProgress** | _function_ | This function is called when the loading progress is updated. |
| **onSceneReady** | _function_ | This function is called when the scene is loaded. The scene is given as the first argument. You can then use [Polygonjs API](https://polygonjs.com/api) on the [scene](https://polygonjs.com/docs/api/PolyScene) to update it as you need. |
| **onViewerReady** | _function_ | This function is called when the viewer is loaded. The viewer is given as the first argument. You can then use [Polygonjs API](https://polygonjs.com/api) on the [viewer](https://polygonjs.com/docs/api/TypedViewer) to update it as you need. |
| **render** | _boolean_ | Pauses the rendering when `false`. This can be useful to disable rendering when the component is either not visible, or when you know nothing has changed (default: `true`) |
| **loadScene** | _boolean_ | defines if the scene is loaded or not when the component is mounted. (default: `true`) |

---
_Source: https://npm.io/package/@polygonjs/react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
