Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Readme
Constructive Solid Geometry (CSG) is a modeling technique that uses Boolean operations like union and intersection to combine 3D solids. This library implements CSG operations on meshes elegantly and concisely using BSP trees, and is meant to serve as an easily understandable implementation of the algorithm. All edge cases involving overlapping coplanar polygons in both solids are correctly handled.
Example usage:
var cube = CSG.cube();
var sphere = CSG.sphere({ radius: 1.3 });
var polygons = cube.subtract(sphere).toPolygons();
Detailed documentation can be automatically generated using Docco.
All CSG operations are implemented in terms of two functions, clipTo()
and invert()
, which remove parts of a BSP tree inside another BSP tree and swap solid and empty space, respectively. To find the union of a
and b
, we want to remove everything in a
inside b
and everything in b
inside a
, then combine polygons from a
and b
into one solid:
a.clipTo(b);
b.clipTo(a);
a.build(b.allPolygons());
The only tricky part is handling overlapping coplanar polygons in both trees. The code above keeps both copies, but we need to keep them in one tree and remove them in the other tree. To remove them from b
we can clip the inverse of b
against a
. The code for union now looks like this:
a.clipTo(b);
b.clipTo(a);
b.invert();
b.clipTo(a);
b.invert();
a.build(b.allPolygons());
Subtraction and intersection naturally follow from set operations. If union is A | B
, subtraction is A - B = ~(~A | B)
and intersection is A & B = ~(~A | ~B)
where ~
is the complement operator.
Copyright (c) 2011 Evan Wallace (http://madebyevan.com/), under the MIT license.
FAQs
Constructive solid geometry on meshes using BSP trees in JavaScript
We found that csg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).