- Notifications
You must be signed in to change notification settings - Fork2
3D/2D CAD design package written in Go. GPU accelerated.
License
soypat/gsdf
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
gsdf
is a CAD 3D design library for Go that uses SDFs for shape definition. Rendering can be done on GPU or CPUfor visualization or 3D printing file outputs. Quick jump to usage:bolt example.
All images and shapes in readme were generated using this library.
High test coverage (when GPU available, not the case in CI)
Extremely coherent API design.
UI for visualizing parts, rendered directly from shaders. SeeUI example by running
go run ./examples/ui-mandala
Generate visualization for your parts as shaders.
GPU and CPU implementations for all shapes and operations. CPU implementations are actually faster for simple parts.
Include arbitrary buffers into GPU calculation. See
Shader
interface.Heapless algorithms for everything. No usage of GC in happy path.
Heapless Octree triangle renderer. Is stupid fast.
- Design your part using one API, switch between CPU and GPU after design.
TinyGo supported for CPU evaluation :)
gsdf
: Top level package defines exact SDFs primitives and operations for use on CPU or GPU workloads. Consumesglbuild
interfaces and logic to build shaders.glbuild
: Automatic shader generation interfaces and logic.gleval
: SDF evaluation interfaces and facilities, both CPU and GPU bound.glrender
: Triangle rendering logic which consumes gleval. STL generation.forge
: Engineering applications. Composed of subpackages.textsdf
package for text generation.threads
package for generating screw threads.
gsdfaux
: High level helper functions to get users started up withgsdf
. Seeexamples.
Find examples underexamples directory. Run on GPU with:-gpu
flag.
Most 3D examples output two files:
example-name.glsl
: Visualization shader that can be copy pasted intoshadertoy to visualize the part, or rendered within your editor with an extension such as theShader Toy Visual Studio Code extension.example-name.stl
: Triangle model file used in 3D printing software such asCura. Can be visualized online in sites such asView STL.
Output and timings for
- CPU: 12th Gen Intel i5-12400F (12) @ 4.400GHz
- GPU: AMD ATI Radeon RX 6800
This was converted from theoriginal sdf library example.
time go run ./examples/npt-flange -resdiv 400 -gpuusing GPU ᵍᵒᵗᵗᵃ ᵍᵒ ᶠᵃˢᵗcompute invocation size 1024instantiating evaluation SDF took 115.587024mswrote nptflange.glslin 97.829µsevaluated SDF 46148621times and rendered 423852 trianglesin 1.103100086s with 95.7 percent evaluations omittedwrote nptflange.stlin 710.038498msfinished npt-flange examplego run ./examples/npt-flange -resdiv 400 -gpu 1,01s user 1,10s system 95% cpu 2,217 total
time go run ./examples/npt-flange -resdiv 400 using CPUinstantiating evaluation SDF took 14.173µswrote nptflange.glslin 73.155µsevaluated SDF 46147934times and rendered 423852 trianglesin 8.482344469s with 95.7 percent evaluations omittedwrote nptflange.stlin 703.931017msfinished npt-flange examplego run ./examples/npt-flange -resdiv 400 9,01s user 0,82s system 103% cpu 9,481 total
Note that the amount of triangles is very similar to the NPT flange example, but the speedup is much more notable due to the complexity of the part.
time go run ./examples/fibonacci-showerhead -resdiv 350 -gpuusing GPU ᵍᵒᵗᵗᵃ ᵍᵒ ᶠᵃˢᵗcompute invocation size 1024instantiating evaluation SDF took 108.241558mswrote showerhead.glslin 581.351µsevaluated SDF 14646305times and rendered 309872 trianglesin 768.731027ms with 89.08 percent evaluations omittedwrote showerhead.stlin 509.470328msshowerhead exampledonego run ./examples/fibonacci-showerhead -resdiv 350 -gpu 0,87s user 0,69s system 94% cpu 1,646 total
time go run ./examples/fibonacci-showerhead -resdiv 350 using CPUinstantiating evaluation SDF took 27.757µswrote showerhead.glslin 507.155µsevaluated SDF 14645989times and rendered 309872 trianglesin 35.794768353s with 89.08 percent evaluations omittedwrote showerhead.stlin 499.13903msSDF caching omitted 21.62 percent of 14645989 SDF evaluationsshowerhead exampledonego run ./examples/fibonacci-showerhead -resdiv 350 36,16s user 0,76s system 100% cpu 36,591 total
About
3D/2D CAD design package written in Go. GPU accelerated.