Utility for generating 2D projections of 3D geometry.
import { Color, Mesh, TorusKnotGeometry, MeshNormalMaterial, LineSegments, LineBasicMaterial } from 'three';
import { ProjectionGenerator } from 'three-edge-projection';
// scene, camera and renderer are initialized here
// a drawing on light paper
scene.background = new Color( 0xeeeeee );
const mesh = new Mesh( new TorusKnotGeometry( 0.8, 0.25, 100, 16 ), new MeshNormalMaterial() );
mesh.position.y = 1;
mesh.updateMatrixWorld();
scene.add( mesh );
// the edges visible from above, flattened onto the ground below the knot
const task = new ProjectionGenerator().generate( mesh );
let step = task.next();
while ( ! step.done ) step = task.next();
const lines = new LineSegments( step.value.visibleEdges.getLineGeometry(), new LineBasicMaterial( { color: 0x030303 } ) );
lines.position.y = - 1;
scene.add( lines );On this page
Properties
iterationTime: number
How long to spend trimming edges before yielding.
angleThreshold: number
The threshold angle in degrees at which edges are generated.
includeIntersectionEdges: boolean
Whether to generate edges representing the intersections between triangles.
Methods
async generateAsync(
geometry: Object3D | BufferGeometry | Array<Object3D>,
options?: {
onProgress?: ( percent: number, message: string ) => void,
signal?: AbortSignal
}
): ProjectionResultGenerate the geometry with a promise-style API.
generate(
scene: Object3D | BufferGeometry | Array<Object3D>,
options?: {
onProgress?: ( percent: number, message: string ) => void
}
): ProjectionResultGenerate the edge geometry result using a generator function.