firtoz/react-three-renderer

bounding sphere do not recomputed when geometry's vertices updated

Open

#193 aperta il 4 set 2017

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)JavaScript (164 fork)batch import
bughelp wanted

Metriche repository

Star
 (1498 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

As the title. I met this problem when I update a element's vertices. The bounding sphere do not updated as I updating the vertices. This cause a geometry may 'disappear' as Three.js's frustum check boundingSphere for rendering. I found this problem and fixed it by change your code in './src/lib/descriptors/Geometry/GeometryDescriptor.js' below:

import * as THREE from 'three';
import PropTypes from 'react/lib/ReactPropTypes';

import GeometryDescriptorBase from './GeometryDescriptorBase';
import propTypeInstanceOf from '../../utils/propTypeInstanceOf';

class GeometryDescriptor extends GeometryDescriptorBase {
  constructor(react3RendererInstance) {
    super(react3RendererInstance);

    this.hasProp('vertices', {
      override: true,
      type: PropTypes.arrayOf(propTypeInstanceOf(THREE.Vector3)).isRequired,
      update(threeObject, vertices) {
        if (threeObject.vertices !== vertices) {
          threeObject.vertices = vertices;

          threeObject.verticesNeedUpdate = true;

      ** +    //iamnotstone modified
      +    threeObject.computeBoundingSphere();
      +   console.log('GeometryDescriptor update called') **

        }
      },
      updateInitial: true,
      default: [],
    });
  }

  construct() {
    return new THREE.Geometry();
  }
}

module.exports = GeometryDescriptor;

This solution works for me. And I think there are also the same problems in other descriptors

Guida contributor