Giter Club home page Giter Club logo

three-edge-projection's Introduction

three-edge-projection

build github twitter sponsors

Edge projection based on three-mesh-bvh to extract visible projected lines along the y-axis into flattened line segments for scalable 2d rendering. Additonally includes a silhouette mesh generator based on clipper2-js to merge flattened triangles.

Examples

Geometry edge projection

Silhouette projection

Floor plan projection

Use

Generator

More granular API with control over when edge trimming work happens.

const generator = new ProjectionGenerator();
generator.generate( geometry );

let result = task.next();
while ( ! result.done ) {

	result = task.next();

}

const lines = new LineSegments( result.value, material );
scene.add( lines );

Promise

Simpler API with less control over when the work happens.

const generator = new ProjectionGenerator();
const geometry = await generator.generateAsync( geometry );
const mesh = new Mesh( result.value, material );
scene.add( mesh );

API

ProjectionGenerator

.sortEdges

sortEdges = true : Boolean

Whether to sort edges along the Y axis before iterating over the edges.

.iterationTime

iterationTime = 30 : Number

How long to spend trimming edges before yielding.

.angleThreshold

angleThreshold = 50 : Number

The threshold angle in degrees at which edges are generated.

.includeIntersectionEdges

includeIntersectionEdges = true : Boolean

Whether to generate edges representing the intersections between triangles.

.generate

*generate(
	geometry : MeshBVH | BufferGeometry,
	options : {
		onProgress: ( percent : Number ) => void,
	}
) : BufferGeometry

Generate the edge geometry using a generator function.

.generateAsync

generateAsync(
	geometry : MeshBVH | BufferGeometry,
	options : {
		onProgress: ( percent : Number ) => void,
		signal: AbortSignal,
	}
) : Promise<BufferGeometry>

Generate the geometry with a promise-style API.

SilhouetteGenerator

Used for generating a projected silhouette of a geometry using the clipper2-js project. Performing these operations can be extremely slow with more complex geometry and not always yield a stable result.

.iterationTime

iterationTime = 10 : Number

How long to spend trimming edges before yielding.

.doubleSided

doubleSided = false : Boolean

If false then only the triangles facing upwards are included in the silhouette.

.sortTriangles

sortTriangles = false : Boolean

Whether to sort triangles and project them large-to-small. In some cases this can cause the performance to drop since the union operation is best performed with smooth, simple edge shapes.

.output

output = OUTPUT_MESH | OUTPUT_LINE_SEGMENTS | OUTPUT_BOTH

Whether to output mesh geometry, line segments geometry, or both in an array ( [ mesh, line segments ] );

.generate

*generate(
	geometry : BufferGeometry,
	options : {
		onProgress: ( percent : Number ) => void,
	}
) : BufferGeometry

Generate the geometry using a generator function.

.generateAsync

generateAsync(
	geometry : BufferGeometry,
	options : {
		onProgress: ( percent : Number ) => void,
		signal: AbortSignal,
	}
) : Promise<BufferGeometry>

Generate the silhouette geometry with a promise-style API.

three-edge-projection's People

Contributors

dependabot[bot] avatar gkjohnson avatar vis-prime avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

three-edge-projection's Issues

Torus Issue

	model = new Mesh( new TorusGeometry );
	model.geometry.rotateX( Math.PI / 4 );
image

package usage

Hey I cant seem to find in the readme any reference to how to add this to a package. Does this have an npm yet?

Problem cases w/ Box

model.rotation.set(
  Math.PI / 4,
  0,
  Math.PI / 4,
);
image
model.rotation.set(
  3.134526431262873,
  - 0.6533379593860817,
  2.957077820828322,
)
image

Add a perspective projection option

  • Generate edges
    • Side-edges must be generated from triangles and normals transformed by the perspective matrix
  • Transform edges by projection
  • Transform geometry by projection
  • Rotate geometry from Z+ to Y+
  • Regenerate BVH
  • Trim
  • Rotate result back to Z+ ?

Async Task does not stop after Abort signal

While using the generateAsync function, after the abort signal is sent

'ProjectionGenerator: Process aborted via AbortSignal.' message is printed ,

but the task/req anim frame keeps on running.

Adding a return after the reject() in the generateAsync functions seems to fix the issue

Test model errors

Maybe raising the lines could help? Won't work because the same triangle will just hide it

Projection
image

Top Down View
image

Silhouette generator fixes

There are errors in the silhouette currently - try expanding the triangles a little bit to ensure more overlap?

SilhouetteGenerator: Use MeshBVH to filter non visible triangles

Seems difficult - how to determine whether the triangle is fully overlapped?

Other options:

  • Check edge intersection for each triangle, containment by ray counting
  • Get relevant triangle indices by rendering from the top down with a relevant resolution
    • can shift the camera by subpixel to try to find new triangles?
  • Try to derive projected, connected shapes from half edge structure and use those for merging

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.