提交 efbb018f 编写于 作者: M Mugen87

JSM: Added module and TS file for ConvexHull and ConvexGeometry.

上级 10ac56be
......@@ -127,6 +127,7 @@
<li>geometries
<ul>
<li>BoxLineGeometry</li>
<li>ConvexGeometry</li>
<li>DecalGeometry</li>
<li>ParametricGeometries</li>
<li>TeapotBufferGeometry</li>
......@@ -164,6 +165,7 @@
<li>math
<ul>
<li>ColorConverter</li>
<li>ConvexHull</li>
<li>ImprovedNoise</li>
<li>Lut</li>
<li>SimplexNoise</li>
......
import {
BufferGeometry,
Geometry,
Vector3
} from '../../../src/Three';
export class ConvexGeometry extends Geometry {
constructor(points: Vector3[]);
}
export class ConvexBufferGeometry extends BufferGeometry {
constructor(points: Vector3[]);
}
/**
* @author Mugen87 / https://github.com/Mugen87
*/
import {
BufferGeometry,
Float32BufferAttribute,
Geometry
} from "../../../build/three.module.js";
import { ConvexHull } from "../math/ConvexHull.js";
// ConvexGeometry
var ConvexGeometry = function ( points ) {
Geometry.call( this );
this.fromBufferGeometry( new ConvexBufferGeometry( points ) );
this.mergeVertices();
};
ConvexGeometry.prototype = Object.create( Geometry.prototype );
ConvexGeometry.prototype.constructor = ConvexGeometry;
// ConvexBufferGeometry
var ConvexBufferGeometry = 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.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
this.addAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
};
ConvexBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
ConvexBufferGeometry.prototype.constructor = ConvexBufferGeometry;
export { ConvexGeometry, ConvexBufferGeometry };
import {
Object3D,
Ray,
Vector3
} from '../../../src/Three';
declare class Face {
constructor();
normal: Vector3;
midpoint: Vector3;
area: number;
constant: number;
outside: VertexNode;
mark: number;
edge: HalfEdge;
static create(a: VertexNode, b: VertexNode, c: VertexNode): Face;
compute(): this;
getEdge(i: number): HalfEdge;
}
declare class HalfEdge {
constructor(vertex: VertexNode, face: Face);
vertex: VertexNode;
prev: HalfEdge;
next: HalfEdge;
twin: HalfEdge;
face: Face;
head(): VertexNode;
length(): number;
lengthSquared(): number;
setTwin(edge: HalfEdge): this;
tail(): VertexNode;
}
declare class VertexNode {
constructor(point: Vector3);
point: Vector3;
prev: VertexNode;
next: VertexNode;
face: Face;
}
declare class VertexList {
constructor();
head: VertexNode;
tail: VertexNode;
append(vertex: VertexNode): this;
appendChain(vertex: VertexNode): this;
clear(): this;
first(): VertexNode;
insertAfter(target: VertexNode, vertex: VertexNode): this;
insertBefore(target: VertexNode, vertex: VertexNode): this;
isEmpty(): boolean;
last(): VertexNode;
remove(vertex: VertexNode): this;
removeSubList(a: VertexNode, b: VertexNode): this;
}
export class ConvexHull {
constructor();
tolerance: number;
faces: Face[];
newFaces: Face[];
assigned: VertexList;
unassigned: VertexList;
vertices: VertexNode[];
addAdjoiningFace(eyeVertex: VertexNode, horizonEdge: HalfEdge): HalfEdge;
addNewFaces(eyeVertex: VertexNode, horizon: HalfEdge[]): this;
addVertexToFace(vertex: VertexNode, face: Face): this;
addVertexToHull(eyeVertex: VertexNode): this;
cleanup(): this;
compute(): this;
computeExtremes(): object;
computeHorizon(eyePoint: Vector3, crossEdge: HalfEdge, face: Face, horizon: HalfEdge[]): this;
computeInitialHull(): this;
containsPoint(point: Vector3): boolean;
deleteFaceVertices(face: Face, absorbingFace: Face): this;
intersectRay(ray: Ray, target: Vector3): Vector3 | null;
intersectsRay(ray: Ray): boolean;
makeEmpty(): this;
nextVertexToAdd(): VertexNode | undefined;
reindexFaces(): this;
removeAllVerticesFromFace(face: Face): VertexNode | undefined;
removeVertexFromFace(vertex: VertexNode, face: Face): this;
resolveUnassignedPoints(newFaces: Face[]): this;
setFromPoints(points: Vector3[]): this;
setFromObject(object: Object3D): this;
}
此差异已折叠。
......@@ -43,6 +43,7 @@ var files = [
{ path: 'exporters/TypedGeometryExporter.js', dependencies: [], ignoreList: [] },
{ path: 'geometries/BoxLineGeometry.js', dependencies: [], ignoreList: [] },
{ path: 'geometries/ConvexGeometry.js', dependencies: [ { name: 'ConvexHull', path: 'math/ConvexHull.js' } ], ignoreList: [] },
{ path: 'geometries/DecalGeometry.js', dependencies: [], ignoreList: [] },
{ path: 'geometries/ParametricGeometries.js', dependencies: [], ignoreList: [] },
{ path: 'geometries/TeapotBufferGeometry.js', dependencies: [], ignoreList: [] },
......@@ -74,6 +75,7 @@ var files = [
{ path: 'loaders/VRMLLoader.js', dependencies: [], ignoreList: [] },
{ path: 'math/ColorConverter.js', dependencies: [], ignoreList: [] },
{ path: 'math/ConvexHull.js', dependencies: [], ignoreList: [] },
{ path: 'math/ImprovedNoise.js', dependencies: [], ignoreList: [] },
{ path: 'math/Lut.js', dependencies: [], ignoreList: [] },
{ path: 'math/SimplexNoise.js', dependencies: [], ignoreList: [] },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册