awv3-react

8.1.30 • Public • Published
npm install awv3-react

Example using Canvas, View and a Csys

import * as THREE from 'three'
import React from 'react'
import ReactDOM from 'react-dom'
import { Canvas, View, Csys } from 'awv3-react'

class Test extends React.Component {
    componentDidMount() {
        // Link view
        this.view = this.refs.view.getInterface()
        // Create geometry
        const box = new THREE.Mesh(
            new THREE.BoxBufferGeometry(100, 100, 100),
            new THREE.MeshBasicMaterial({ color: new THREE.Color('red') })
        )
        // Add geometry to scene
        this.view.scene.add(box)
        this.view.updateBounds().controls.focus().zoom()
    }

    render() {
        return (
            <Canvas style={{ position: 'absolute', top: 0, left: 0 }} resolution={1}>
                <View ref="view" up={[0, 1, 0]}>
                    <Csys style={{ position: 'absolute', bottom: 0, width: 90, height: 90 }} />
                </View>
            </Canvas>
        )
    }
}

ReactDOM.render(<Test />, document.querySelector('#root'))

Example using Session

The Session component takes all options that work with the generic awv3-Session.

It has a number of defaults that will create a standard session with a Csys attached, loading a default environment map. It will also create a Redux store-Provider if the store option has been left empty (which means awv3-Session will construct its own store). All direct and nested children will inherit the "session" context. If "store" is passed explicitly no Provider will be created.

import React from 'react'
import ReactDOM from 'react-dom'
import { Session } from 'awv3-react'
import { actions as connectionActions } from 'awv3/session/store/connections'

class Test extends React.Component {
    handleOpenFile = event => this.refs.session.openFile(event)
    render() {
        return (
            <Session ref="session" url="http://localhost:8181/">
                <input type="file" style={{ position: 'relative' }} onChange={this.handleOpenFile} />
            </Session>
        )
    }
}

ReactDOM.render(<Test />, document.querySelector('#root'))

Example using Selection

The Selection element sets up a selector and renders a single function-child with the resulting items.

import React from 'react'
import ReactDOM from 'react-dom'
import { Session, Selection } from 'awv3-react'
import { actions as connectionActions } from 'awv3/session/store/connections'

const TestSelection = () => (
    <Selection>
        {props => `${props.ids} selected, hovered: ${props.hovered && props.hovered.material.id}`}
    </Selection>
)

ReactDOM.render((
    <Session ref="session" url="http://localhost:8181/">
        <TestSelection />
    </Session>
), document.querySelector('#root'))

API

Session

static propTypes = {
    debug: PropTypes.bool,
    pool: PropTypes.func,
    protocol: PropTypes.func,
    url: PropTypes.string,
    materials: PropTypes.object,
    resources: PropTypes.object,
    store: PropTypes.object,
    resolution: PropTypes.number,
    up: PropTypes.array,
    stats: PropTypes.bool,
    updateView: PropTypes.object,
    renderOrder: PropTypes.object,
    lineShader: PropTypes.func,
    lineShaderOptions: PropTypes.object,
    meshShader: PropTypes.func,
    meshShaderOptions: PropTypes.object,
    interpolatePoints: PropTypes.bool,
}
static defaultProps = {
    debug: Defaults.debug,
    pool,
    protocol,
    url: 'http://localhost:8181',
    materials: Defaults.materials,
    resolution: Defaults.resolution,
    up: Defaults.up,
    stats: Defaults.stats,
    updateView: Defaults.updateView,
    renderOrder: Defaults.renderOrder,
    meshShader: Defaults.meshShader,
    meshShaderOptions: Defaults.meshShaderOptions,
    interpolatePoints: false,
}
static childContextTypes = { session: PropTypes.object }

Canvas

static propTypes = { resolution: PropTypes.number }
static childContextTypes = { canvas: PropTypes.object }

View

static propTypes = { up: PropTypes.array, stats: PropTypes.bool, ambientIntensity: PropTypes.number }
static defaultProps = { up: Defaults.up, stats: Defaults.stats, ambientIntensity: Defaults.ambientIntensity }
static childContextTypes = { view: PropTypes.object };

Selection

static contextTypes = { session: PropTypes.object }
static propTypes = { enabled: PropTypes.bool, types: PropTypes.array, limit: PropTypes.number, children: PropTypes.func.isRequired }
static defaultProps = { enabled: true, types: ['Mesh'], limit: Infinity }

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
8.1.300latest
8.0.10beta

Version History

VersionDownloads (Last 7 Days)Published
8.1.300
8.1.290
8.1.280
8.1.270
8.1.260
8.1.250
8.1.240
8.1.230
8.1.220
8.1.210
8.1.200
8.1.190
8.1.180
8.1.170
8.1.160
8.1.150
8.1.140
8.1.130
8.1.120
8.1.110
8.1.101
8.1.90
8.1.81
8.1.70
8.1.60
8.1.50
8.1.40
8.1.30
8.1.20
8.1.10
8.1.00
8.0.41
8.0.30
8.0.21
8.0.10
8.0.00
7.9.00
7.8.50
7.8.40
7.8.30
7.8.20
7.8.10
7.8.00
7.7.10
7.7.00
7.6.00
7.5.00
7.4.30
7.4.20
7.4.11
7.4.01
7.3.20
7.3.10
7.3.00
7.2.00
7.1.00
1.0.400
1.0.390
1.0.380
1.0.370
1.0.361
1.0.350
1.0.340
1.0.330
1.0.320
1.0.310
1.0.300
1.0.290
1.0.280
1.0.270
1.0.260
1.0.250
1.0.230
1.0.220
1.0.210
1.0.200
1.0.190
1.0.180
1.0.170
1.0.160
1.0.150
1.0.140
1.0.130
1.0.120
1.0.110
1.0.90

Package Sidebar

Install

npm i awv3-react

Weekly Downloads

7

Version

8.1.30

License

ISC

Unpacked Size

34.8 kB

Total Files

10

Last publish

Collaborators

  • drcmda
  • phipsy7