firtoz/react-three-renderer

bounding sphere do not recomputed when geometry's vertices updated

Open

#193 aberto em 4 de set. de 2017

Ver no GitHub
 (2 comments) (0 reactions) (0 assignees)JavaScript (164 forks)batch import
bughelp wanted

Métricas do repositório

Stars
 (1.498 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

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

Guia do colaborador