# @edwmurph/threejsr

> A library for creating threejs components with react

Latest version **0.0.23** (published 2022-01-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install @edwmurph/threejsr
pnpm add @edwmurph/threejsr
yarn add @edwmurph/threejsr
bun add @edwmurph/threejsr
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.0.23 |
| Published | 2022-01-23 |
| First published | 2019-07-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | edward |
| Maintainers | edwmurph |

## Links

- npm: https://www.npmjs.com/package/@edwmurph/threejsr
- Repository: https://github.com/edwmurph/threeJSR
- Homepage: https://github.com/edwmurph/threeJSR#readme
- Issues: https://github.com/edwmurph/threeJSR/issues
- npm.io page: https://npm.io/package/@edwmurph/threejsr

## Recent versions

- 0.0.23 (latest) — 2022-01-23
- 0.0.22 — 2021-09-18
- 0.0.21 — 2020-10-27
- 0.0.20 — 2020-09-08
- 0.0.19 — 2020-07-18
- 0.0.18 — 2020-07-10
- 0.0.17 — 2020-03-28
- 0.0.16 — 2020-02-22
- 0.0.15 — 2020-02-05
- 0.0.14 — 2019-12-05
- 0.0.13 — 2019-12-05
- 0.0.12 — 2019-12-05
- 0.0.11 — 2019-11-11
- 0.0.10 — 2019-11-10
- 0.0.9 — 2019-11-09
- … 8 more at https://npm.io/package/@edwmurph/threejsr/versions

## README

# ThreeJSR

*UNDER DEVELOPMENT*

React based library for [three.js](https://threejs.org/) projects.

<a href="https://www.npmjs.com/package/threejs-r"><img src="https://img.shields.io/npm/v/@edwmurph/threejsr.svg?style=flat" alt="npm version"></a>
<a href="https://www.npmjs.com/package/threejs-r" target="_blank"><img src="https://img.shields.io/npm/dm/@edwmurph/threejsr.svg" alt="npm downloads per month"></a>

# Features

- render three.js scene in dimensions set by parent element
- three.js scene and render loop logic is defined with javascript to ensure consistency with the three.js docs
- add post operation passes like the GlitchPass and UnrealBloomPass
- threejs environment requirement error handling with customizable error boundary

See example usage: https://github.com/edwmurph/threejs

# Installation

```
npm i @edwmurph/threejsr
```
Also install required peer dependencies:
```
npm i three@^0 react@^16
```

# Getting started

1. Extend ThreeJSR to build your own threejs scene:

```
// src/threejs/sphere.js
import * as THREE from 'three';
import { ThreeJSR } from '@edwmurph/threejsr';

import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass.js';

class Sphere extends ThreeJSR {
  constructor (ref, newFrameHook) {
    const bloomPass = new UnrealBloomPass();
    super(ref, newFrameHook, { passes: [bloomPass] });
  }

  renderNextFrame({ spin, timestamp }) {
    if (spin) {
      this.mesh.rotation.x += 0.001;
      this.mesh.rotation.y += 0.001;
    }

    return super.renderNextFrame(timestamp);
  }

  createThreeScene() {
    this.scene = new THREE.Scene();

    this.camera = new THREE.PerspectiveCamera(75, 0, 0.1, 1000);
    this.camera.position.z = 100;

    const geometry = new THREE.SphereGeometry(40, 50, 30);
    const material = new THREE.MeshLambertMaterial({ color: 0xffffff, wireframe: true });

    this.mesh = new THREE.Mesh(geometry, material);
    this.scene.add(this.mesh);

    const spotLight = new THREE.SpotLight(0xffffff);
    spotLight.position.set(100, 10, 100);

    this.scene.add(spotLight);
  }
}

export default new Sphere();
```

2. Add ThreeJSRComponent to one of your components:

```
// src/components/app.js
import React from 'react';
import Sphere from '../threejs/sphere';
import { ThreeJSRComponent } from '@edwmurph/threejsr';

const renderLoopData = {
  spin: true
};

const Component = () => {
  return (
    <ThreeJSRComponent
      ThreeJSR={Sphere}
      renderLoopData={renderLoopData}
      style={{ border: '5px solid green' }}
    />
  );
};

export default Component;
```

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