firtoz/react-three-renderer

bounding sphere do not recomputed when geometry's vertices updated

Open

#193 opened on Sep 4, 2017

View on GitHub
 (2 comments) (0 reactions) (0 assignees)JavaScript (1,498 stars) (164 forks)batch import
bughelp wanted

Description

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

Contributor guide