Created
May 7, 2016 16:49
-
-
Save Anton-2/848f6ec3642ae616e3eaeae5699db3c1 to your computer and use it in GitHub Desktop.
react-three-renderer : can't change the number of vertices.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import {render} from 'react-dom'; | |
import React3 from 'react-three-renderer'; | |
import THREE from 'three'; | |
const DemoView = (props) => { | |
const vertices = []; | |
const {nbItems} = props; | |
const step = 10 / nbItems; | |
for (let n=0; n<nbItems; n++) { | |
vertices.push(new THREE.Vector3(-4+step*n, 0, 0)); | |
} | |
return ( | |
<React3 mainCamera="camera" width={200} height={100}> | |
<scene> | |
<perspectiveCamera name="camera" fov={75} aspect={2} near={1} far={5} | |
position={new THREE.Vector3(0, 0, 4)} | |
/> | |
<points> | |
<pointsMaterial size={0.8} color = "#DDEEDD" /> | |
<geometry vertices={vertices} /> | |
</points> | |
</scene> | |
</React3> | |
); | |
} | |
class Demo extends Component { | |
constructor(props, context) { | |
super(props, context); | |
this.state = {nbItems: 6}; | |
} | |
render() { | |
return ( | |
<div> | |
<DemoView nbItems={this.state.nbItems}/> | |
<input style={{display:'block'}} type='number' | |
defaultValue={this.state.nbItems} | |
onChange={(e) => this.setState({nbItems:parseInt(e.target.value)})} | |
/> | |
</div> | |
) | |
} | |
} | |
render(<Demo />, document.body); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment