8.1.30 • Published 5 years ago

awv3-react v8.1.30

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago
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 }
8.1.30

5 years ago

8.1.29

5 years ago

8.1.28

5 years ago

8.1.27

6 years ago

8.1.26

6 years ago

8.1.25

6 years ago

8.1.24

6 years ago

8.1.23

6 years ago

8.1.22

6 years ago

8.1.21

6 years ago

8.1.20

6 years ago

8.1.19

6 years ago

8.1.18

6 years ago

8.1.17

6 years ago

8.1.16

6 years ago

8.1.15

6 years ago

8.1.14

6 years ago

8.1.13

6 years ago

8.1.12

6 years ago

8.1.11

6 years ago

8.1.10

6 years ago

8.1.9

6 years ago

8.1.8

6 years ago

8.1.7

6 years ago

8.1.6

6 years ago

8.1.5

6 years ago

8.1.4

6 years ago

8.1.3

6 years ago

8.1.2

6 years ago

8.1.1

6 years ago

8.1.0

6 years ago

8.0.4

6 years ago

8.0.3

6 years ago

8.0.2

7 years ago

8.0.1

7 years ago

8.0.0

7 years ago

7.9.0

7 years ago

7.8.5

7 years ago

7.8.4

7 years ago

7.8.3

7 years ago

7.8.2

7 years ago

7.8.1

7 years ago

7.8.0

7 years ago

7.7.1

7 years ago

7.7.0

7 years ago

7.6.0

7 years ago

7.5.0

7 years ago

7.4.3

7 years ago

7.4.2

7 years ago

7.4.1

7 years ago

7.4.0

7 years ago

7.3.2

7 years ago

7.3.1

7 years ago

7.3.0

7 years ago

7.2.0

7 years ago

7.1.0

7 years ago

1.0.40

7 years ago

1.0.39

7 years ago

1.0.38

7 years ago

1.0.37

7 years ago

1.0.36

7 years ago

1.0.35

7 years ago

1.0.34

7 years ago

1.0.33

7 years ago

1.0.32

7 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.9

7 years ago