1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-05 10:49:36 +02:00
Oinktube/node_modules/three/examples/jsm/geometries/ConvexGeometry.js
2023-12-11 11:59:56 -03:00

60 lines
1.3 KiB
JavaScript

import {
BufferGeometry,
Float32BufferAttribute
} from '../../../build/three.module.js';
import { ConvexHull } from '../math/ConvexHull.js';
// ConvexGeometry
var ConvexGeometry = function ( points ) {
BufferGeometry.call( this );
// buffers
var vertices = [];
var normals = [];
if ( ConvexHull === undefined ) {
console.error( 'THREE.ConvexBufferGeometry: ConvexBufferGeometry relies on ConvexHull' );
}
var convexHull = new ConvexHull().setFromPoints( points );
// generate vertices and normals
var faces = convexHull.faces;
for ( var i = 0; i < faces.length; i ++ ) {
var face = faces[ i ];
var edge = face.edge;
// we move along a doubly-connected edge list to access all face points (see HalfEdge docs)
do {
var point = edge.head().point;
vertices.push( point.x, point.y, point.z );
normals.push( face.normal.x, face.normal.y, face.normal.z );
edge = edge.next;
} while ( edge !== face.edge );
}
// build geometry
this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
};
ConvexGeometry.prototype = Object.create( BufferGeometry.prototype );
ConvexGeometry.prototype.constructor = ConvexGeometry;
export { ConvexGeometry };