Coder Social home page Coder Social logo

soypat / sdf Goto Github PK

View Code? Open in Web Editor NEW
89.0 4.0 9.0 1.14 MB

A Go library for signed distance function shape generation. Read as 3D printing shape design.

License: MIT License

Go 100.00%
3d-models 3d-printing cad go golang mesh-generation sdf signed-distance-functions stl

sdf's Issues

Composite literal uses unkeyed fields

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.

Can't build by adding github.com/soypat/sdf

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:

  1. mkdir myexample
  2. cd myexample
  3. go mod init github.com/me/myexample
  4. Create a file with the contents of one of the example go files from soypat/sdf/examples
  5. go mod tidy
  6. 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: `Box` and `Triangle` types replaced with gonum types

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.

Box change

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.

Triangle change

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 STL files shows all sorts of artifacts

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)
    }
            
} 

Replace Matrix types with gonum Transform

When gonum/gonum#1797 is accepted this can be discussed and implemented.

  • Replace sdf.m44 with r3.Transform
  • Replace 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.

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.