soypat / sdf Goto Github PK
View Code? Open in Web Editor NEWA Go library for signed distance function shape generation. Read as 3D printing shape design.
License: MIT License
A Go library for signed distance function shape generation. Read as 3D printing shape design.
License: MIT License
Hi Patricio
I agree with the way you are doing the SDF function types as I was wrapping the SDFX functions to get the same effect. I am having a go at porting sdfx-ui to using sdf.
I am using go 1.18 and go vet complains about composite literal using unkeyed fields.
So I am testing adding
// New func to replace composite literal construction with unkeyed fields
func NewV2(x, y float64) r2.Vec {
return r2.Vec{X: x, Y: y}
}
to vector.gox`x
So the code changes (example of old and new):
v[1] = NewV2(a.Max.X, a.Min.Y) // br
v[2] = r2.Vec{a.Min.X, a.Max.Y} // tl
If you think it is a good idea I will try and create pull request when I am done.
As pointed out by Yeicor in their PR: #8.
While cloning this entire repo and building everything including examples works, starting with a new project and trying to reference soypat/sdf does not. It gives build errors. Following similar steps with sdfx do work but not in sdf. To reproduce:
mkdir myexample
cd myexample
go mod init github.com/me/myexample
go mod tidy
go build
The following output comes from the build:
# github.com/soypat/sdf/internal/d2
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d2/box.go:16:20: center.Sub undefined (type r2.Vec has no field or method Sub)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d2/box.go:16:38: center.Add undefined (type r2.Vec has no field or method Add)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d2/box.go:39:19: a.Min.Add undefined (type r2.Vec has no field or method Add)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d2/box.go:39:33: a.Max.Add undefined (type r2.Vec has no field or method Add)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d2/box.go:44:15: a.Max.Sub undefined (type r2.Vec has no field or method Sub)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d2/box.go:49:15: a.Min.Add undefined (type r2.Vec has no field or method Add)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d2/box.go:62:19: a.Min.Sub undefined (type r2.Vec has no field or method Sub)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d2/box.go:62:33: a.Max.Add undefined (type r2.Vec has no field or method Add)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d2/transform.go:106:12: xa.Add undefined (type r2.Vec has no field or method Add)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d2/transform.go:107:12: xb.Add undefined (type r2.Vec has no field or method Add)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d2/transform.go:107:12: too many errors
# github.com/soypat/sdf/internal/d3
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d3/box.go:50:19: a.Min.Add undefined (type r3.Vec has no field or method Add)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d3/box.go:50:33: a.Max.Add undefined (type r3.Vec has no field or method Add)
../../go/pkg/mod/github.com/soypat/[email protected]/internal/d3/box.go:55:15: a.Max.Sub undefined (type r3.Vec has no field or method Sub)
Breaking changes are incoming as soon as gonum/gonum#1791 is resolved. This would replace the d3.Box, render.Triangle3 and d2.Box types with their respective gonum types.
This change would allow users to work with the Box types freely in their code. As of now the Box types are hidden behind an internal
wall which makes them invalid for use in external code.
The Triangle type would further decouple the render package and make the Renderer interface more flexible and dependable as the Triangle type would be tied to a solid, trusted and tested library.
Importing the HeartGears2-3.stl file from here:
https://www.thingiverse.com/thing:243278/files
using this code, has lots of artifacts, and holes in the outputed stl file.
package main
import (
"github.com/hschendel/stl"
"github.com/soypat/sdf/helpers/sdfexp"
"github.com/soypat/sdf/render"
)
func main() {
solid, err := stl.ReadFile("HeartGears2-3.stl")
if err != nil {
panic(err)
}
tris := make([]render.Triangle3, len(solid.Triangles))
for i, t := range solid.Triangles {
for k := 0; k < 3; k++ {
tris[i][k].X = float64(t.Vertices[k][0])
tris[i][k].Y = float64(t.Vertices[k][1])
tris[i][k].Z = float64(t.Vertices[k][2])
}
}
object, err := sdfexp.ImportModel(tris, 0)
if err != nil {
panic(err)
}
err = render.CreateSTL("out.stl", render.NewOctreeRenderer(object, 500))
if err != nil {
panic(err)
}
}
When gonum/gonum#1797 is accepted this can be discussed and implemented.
sdf.m44
with r3.Transform
sdf.m33
with r2.Transform
This should not be a breaking change for anyone who has not been using sdf.m44
and sdf.m33
types for anything other than the sdf.Transform3D
and sdf.Transform2D
functions.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.