react-three-renderer polyhedronGeometry错误

时间:2016-07-05 21:11:31

标签: javascript reactjs three.js

我使用react-three-renderer作为项目。我正在创建用于显示的网格。

基于反应三渲染器维基的this example,我做了这个:

var React = require('react');
var ReactDOM = require('react-dom');
var THREE = require('three');
var React3 = require('react-three-renderer');

class Simple extends React.Component {
  constructor(props, context) {
    super(props, context);

    this.cameraPosition = new THREE.Vector3(0, 0, 5);
  }

  render() {
    const width = window.innerWidth;
    const height = window.innerHeight;

    return (<React3
      mainCamera="camera"
      width={width}
      height={height}
    >
      <scene>
        <perspectiveCamera
          name="camera"
          fov={75}
          aspect={width / height}
          near={0.1}
          far={1000}

          position={this.cameraPosition}
        />
        <mesh key={0}>
            <polyhedronGeometry 
                vertices={[0,1.5,0,36.188,0,0,0,0,0,36.188,1.5,0,0,0,3.5,36.188,0,3.5,0,1.5,3.5,36.188,1.5,3.5]}
                indices={[0,1,2,3,1,0,4,1,5,2,1,4,6,2,4,0,2,6,6,3,0,7,3,6,3,5,1,7,5,3,7,4,5,6,4,7]} 
                detail={2} 
                radius={18.178430515311273} 
                name="B1" />
            <meshBasicMaterial color={0x00ff00} />
        </mesh>
      </scene>
    </React3>);
  }
}

ReactDOM.render(<Simple/>, document.getElementById('viewport'));

我得到了逐字工作的示例,但是当我为<boxGeometry/>更改<polyhedronGeometry>时(请参阅documentation),我收到此错误:

  

threeObject.userData._triggerRemount不是函数。

造成这种情况的原因是什么以及如何解决?

1 个答案:

答案 0 :(得分:2)

这是一个错误,它将被修复,see the issue on Github。技术细节:当您修改某些类型的某些道具(如多面体几何体)时,它会触发重新组装几何对象的重新组件,并让三个现在有一个新的几何体。在这种情况下,库开发人员(我)忘记处理在初始构造对象期间发生的边缘情况。