BSD 3-Clause "New" or "Revised" License

项目介绍

soypat/gsdf 是一个托管在 GitHub 上的开源项目,主要使用 Go 编写,采用 BSD 3-Clause "New" or "Revised" License 许可证,目前获得 98 个 Star、6 次 Fork。

仓库全名
soypat/gsdf
开源许可证
BSD 3-Clause "New" or "Revised" License
Star 数
98
Fork 数
6
未关闭 Issue
3

README 摘要

gsdf gsdf is a CAD 3D design library for Go that uses SDFs for shape definition. Rendering can be done on GPU or CPU for visualization or 3D printing file outputs. Quick jump to usage: bolt example. All images and shapes in readme were generated using this library. Requirements Go Optional: See latest requirements on go-glfw if using GPU Features High test coverage (when GPU available, not the case in CI) NEW…

完整内容见 GitHub 原始 README 或本页 。

常见问题

gsdf 用什么语言开发?

主要使用 Go 编写,采用 BSD 3-Clause "New" or "Revised" License 许可证,目前有 98 个 Star。

gsdf 可以免费商用吗?

仓库采用 BSD 3-Clause "New" or "Revised" License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 gsdf 的源码?

可以直接克隆仓库:git clone https://github.com/soypat/gsdf.git,默认分支为 main;安装与运行步骤见仓库 README。

gsdf 最近还在维护吗?

仓库最近一次更新为 9月29日,当前有 3 个未关闭 Issue;Star 数为 98,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

3D/2D CAD design package written in Go. GPU accelerated.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

GLSL
Go
Go Template

贡献者

README

gsdf

go.dev reference Go Report Card codecov Go sourcegraph

gsdf is a CAD 3D design library for Go that uses SDFs for shape definition. Rendering can be done on GPU or CPU for visualization or 3D printing file outputs. Quick jump to usage: bolt example.

All images and shapes in readme were generated using this library.

bolt-example circle text

Requirements

  • Go
  • Optional: See latest requirements on go-glfw if using GPU

Features

  • High test coverage (when GPU available, not the case in CI)

  • NEW!: Reusable GLSL code between shaders. See glbuild/glsllib

  • Extremely coherent API design.

  • UI for visualizing parts, rendered directly from shaders. See UI 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 :)

Package layout/structure

  • gsdf: Top level package defines exact SDFs primitives and operations for use on CPU or GPU workloads. Consumes glbuild 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 with gsdf. See examples.

Examples

Find examples under examples directory. Run on GPU with: -gpu flag.

Most 3D examples output two files:

  • example-name.glsl: Visualization shader that can be copy pasted into shadertoy to visualize the part, or rendered within your editor with an extension such as the Shader Toy Visual Studio Code extension.
  • example-name.stl: Triangle model file used in 3D printing software such as Cura. Can be visualized online in sites such as View STL.

CPU output and timings on 12th Gen Intel i5-12400F (12) @ 4.400GHz. GPU timings on AMD ATI Radeon RX 6800 (may be outdated).

simplesdf Python-like API

The simplesdf package provides a extremely simplified API for use by makers who want a more Python-like API. This is particularily useful for short one-off scripts. Note this API uses panics to help track down errors and also is not thread-safe. See examples/simple-knurled-cylinder.

package main

import (
	"math"
	"runtime"

	. "github.com/soypat/gsdf/gsdfaux/simplesdf"
)

func init() { runtime.LockOSThread() } // Required if using GPU to render shapes or using UI.

func main() {
	// main body
	f := Cylinder(1, 5, 0.1)

	// knurling
	x := Box(1, 1, 4, 0).RotateZ(math.Pi / 4)
	x = x.Translate(1.6, 0, 0)              // radial placement (fogleman circular_array offset)
	x = x.CircArray(24, 24)                 // 24 instances evenly around the circle
	x = x.Twist(0.75).Union(x.Twist(-0.75)) // diamond pattern via mirrored twist
	f = f.Diff(x.K(0.1))

	// central hole
	f = f.Diff(Cylinder(0.5, 7, 0).K(0.1))

	// vent holes
	c := Cylinder(0.25, 3, 0).RotateY(math.Pi / 2) // orient along X
	f = f.Diff(c.Translate(0, 0, -2.5).K(0.1))
	f = f.Diff(c.Translate(0, 0, 2.5).K(0.1))

	f.Save("knurling.stl", STLConfig{ResolutionDivisions: 200})
}

npt-flange

This was converted from the original sdf library example.

GPU rendering in 1.1 seconds. 0.4M triangles
 time go run ./examples/npt-flange -resdiv 400 -gpu
[-] using GPU   ᵍᵒᵗᵗᵃ ᵍᵒ ᶠᵃˢᵗ
[53.54ms] init GL with compute invocation size  1024
[7.73ms] GPU shader generated and compiled
[61.3ms] instantiating evaluation SDF took
[109.4µs] wrote nptflange.glsl
[706ms] evaluated SDF 46148745 times and rendered 423852 triangles with 95.7 percent evaluations omitted in octree pruning step with resolution 0.21679485
[371ms] wrote nptflange.stl
[1.14s] render done
finished npt-flange example
go run ./examples/npt-flange -resdiv 400 -gpu  0,75s user 0,49s system 102% cpu 1,219 total
CPU rendering in 0.7 seconds. 0.4M triangles
time go run ./examples/npt-flange -resdiv 400
[-] using CPU
[29.7µs] instantiating evaluation SDF took
[-] CPU parallel evaluation on 11 goroutines
[101.6µs] wrote nptflange.glsl
[313ms] evaluated SDF 6711686 times and rendered 423852 triangles with resolution 0.21679485
[341ms] wrote nptflange.stl
[654ms] render done
finished npt-flange example
go run ./examples/npt-flange -resdiv 400  2,78s user 0,38s system 422% cpu 0,747 total

npt-flange-example

fibonacci-showerhead

Note that the amount of triangles is very similar to the NPT flange example, but this part is more computationally complex.

GPU rendering in 0.7 seconds. 0.3M triangles
time go run ./examples/fibonacci-showerhead -resdiv 350 -gpu
[-] using GPU   ᵍᵒᵗᵗᵃ ᵍᵒ ᶠᵃˢᵗ
[47.1ms] init GL with compute invocation size  1024
[62.9ms] GPU shader generated and compiled
[110ms] instantiating evaluation SDF took
[539.3µs] wrote showerhead.glsl
[337ms] evaluated SDF 14646431 times and rendered 309872 triangles with 89.08 percent evaluations omitted in octree pruning step with resolution 0.2979682
[252ms] wrote showerhead.stl
[701ms] render done
showerhead example done
go run ./examples/fibonacci-showerhead -resdiv 350 -gpu  0,60s user 0,36s system 118% cpu 0,814 total
CPU rendering in 1.3 seconds. 0.3M triangles
time go run ./examples/fibonacci-showerhead -resdiv 350
[-] using CPU
[34µs] instantiating evaluation SDF took
[-] CPU parallel evaluation on 11 goroutines
[326.4µs] wrote showerhead.glsl
[909ms] evaluated SDF 1512025 times and rendered 309872 triangles with resolution 0.2979682
[255ms] wrote showerhead.stl
[1.16s] render done
showerhead example done
go run ./examples/fibonacci-showerhead -resdiv 350  8,00s user 0,29s system 663% cpu 1,248 total

fibonacci-showerhead

More examples

iso-screw array-triangles geb-book-cover

评论

暂无评论