ConvexGeometry.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. console.warn( "THREE.ConvexGeometry: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." );
  2. // ConvexGeometry
  3. THREE.ConvexGeometry = function ( points ) {
  4. THREE.Geometry.call( this );
  5. this.fromBufferGeometry( new THREE.ConvexBufferGeometry( points ) );
  6. this.mergeVertices();
  7. };
  8. THREE.ConvexGeometry.prototype = Object.create( THREE.Geometry.prototype );
  9. THREE.ConvexGeometry.prototype.constructor = THREE.ConvexGeometry;
  10. // ConvexBufferGeometry
  11. THREE.ConvexBufferGeometry = function ( points ) {
  12. THREE.BufferGeometry.call( this );
  13. // buffers
  14. var vertices = [];
  15. var normals = [];
  16. if ( THREE.ConvexHull === undefined ) {
  17. console.error( 'THREE.ConvexBufferGeometry: ConvexBufferGeometry relies on THREE.ConvexHull' );
  18. }
  19. var convexHull = new THREE.ConvexHull().setFromPoints( points );
  20. // generate vertices and normals
  21. var faces = convexHull.faces;
  22. for ( var i = 0; i < faces.length; i ++ ) {
  23. var face = faces[ i ];
  24. var edge = face.edge;
  25. // we move along a doubly-connected edge list to access all face points (see HalfEdge docs)
  26. do {
  27. var point = edge.head().point;
  28. vertices.push( point.x, point.y, point.z );
  29. normals.push( face.normal.x, face.normal.y, face.normal.z );
  30. edge = edge.next;
  31. } while ( edge !== face.edge );
  32. }
  33. // build geometry
  34. this.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
  35. this.setAttribute( 'normal', new THREE.Float32BufferAttribute( normals, 3 ) );
  36. };
  37. THREE.ConvexBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  38. THREE.ConvexBufferGeometry.prototype.constructor = THREE.ConvexBufferGeometry;