MCPcopy Index your code
hub / github.com/HPInc/go3mf

github.com/HPInc/go3mf @v0.24.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.24.2 ↗ · + Follow
793 symbols 2,114 edges 65 files 211 documented · 27% updated 2y agov0.24.2 · 2023-02-10★ 591 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

PkgGoDev Build Status Go Report Card Coverage Status License

go3mf

The 3D Manufacturing Format (3MF) is a 3D printing format that allows design applications to send full-fidelity 3D models to a mix of other applications, platforms, services and printers. The 3MF specification allows companies to focus on innovation, rather than on basic interoperability issues, and it is engineered to avoid the problems associated with other 3D file formats. Detailed info about the 3MF specification can be fint at 3mf.io.

Features

  • High parsing speed and moderate memory consumption
  • Complete 3MF Core spec implementation.
  • Clean API.
  • STL importer
  • Spec conformance validation
  • Robust implementation with full coverage and validated against real cases.
  • Extensions
  • Support custom and private extensions.
  • Support lossless decoding and encoding of unknown extensions.
  • spec_production.
  • spec_slice.
  • spec_beamlattice.
  • spec_materials, missing the display resources.

Examples

Read from file

package main

import (
    "fmt"

    "github.com/hpinc/go3mf"
)

func main() {
    var model go3mf.Model
    r, _ := go3mf.OpenReader("/testdata/cube.3mf")
    r.Decode(&model)
    for _, item := range model.Build.Items {
      fmt.Println("item:", *item)
      obj, _ := model.FindObject(item.ObjectPath(), item.ObjectID)
      fmt.Println("object:", *obj)
      if obj.Mesh != nil {
        for _, t := range obj.Mesh.Triangles.Triangle {
          fmt.Println(t)
        }
        for _, v := range obj.Mesh.Vertices.Vertex {
          fmt.Println(v.X(), v.Y(), v.Z())
        }
      }
    }
}

Read from HTTP body

package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "net/http"
    "github.com/hpinc/go3mf"
)

func main() {
    resp, _ := http.Get("zip file url")
    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    var model go3mf.Model
    r, _ := go3mf.NewDecoder(bytes.NewReader(body), int64(len(body)))
    r.Decode(&model)
    fmt.Println(model)
}

Write to file

package main

import (
    "fmt"
    "os"

    "github.com/hpinc/go3mf"
)

func main() {
    var model go3mf.Model
    w, _ := go3mf.CreateWriter("/testdata/cube.3mf")
    w.Encode(&model)
    w.Close()
}

Spec usage

Specs are automatically registered when importing them as a side effect of the init function.

package main

import (
    "fmt"

    "github.com/hpinc/go3mf"
    "github.com/hpinc/go3mf/material"
    "github.com/hpinc/go3mf/production"
)

func main() {
    var model go3mf.Model
    r, _ := go3mf.OpenReader("/testdata/cube.3mf")
    r.Decode(&model)
    fmt.Println(production.GetBuildAttr(&model.Build).UUID)

    model.Resources.Assets = append(model.Resources.Assets, &materials.ColorGroup{
      ID: 10, Colors: []color.RGBA{{R: 255, G: 255, B: 255, A: 255}},
    }
}

Extension points exported contracts — how you extend this code

Asset (Interface)
Asset defines build resource. [8 implementers]
core.go
ValidateSpec (Interface)
If a Spec implemented ValidateSpec, then model.Validate will call Validate and aggregate the resulting erros. model is [8 …
spec/spec.go
Marshaler (Interface)
Marshaler is the interface implemented by objects that can marshal themselves into valid XML elements. [17 implementers]
spec/encoding.go
AttrGroup (Interface)
AttrGroup defines a container for different attributes of the same namespace. It supports encoding and decoding to XML. [7 …
spec/spec.go
UnmarshalerAttr (Interface)
UnmarshalerAttr is the interface implemented by objects that can unmarshal an XML element description of themselves. [7 …
spec/encoding.go
Spec (Interface)
Spec is the interface that must be implemented by a 3mf spec. Specs may implement ValidateSpec. [5 implementers]
spec/spec.go
ElementDecoder (Interface)
ElementDecoder defines the minimum contract to decode a 3MF node. [10 implementers]
spec/encoding.go
PropertyGroup (Interface)
(no doc) [6 implementers]
spec/spec.go

Core symbols most depended-on inside this repo

Append
called by 143
errors/list.go
EncodeToken
called by 71
spec/encoding.go
WrapIndex
called by 45
errors/errors.go
SetAutoClose
called by 32
spec/encoding.go
End
called by 29
spec/encoding.go
Identity
called by 24
math.go
NewMissingFieldError
called by 24
errors/errors.go
Error
called by 23
errors/list.go

Shape

Method 380
Function 230
Struct 147
Interface 19
TypeAlias 17

Languages

Go100%

Modules by API surface

decoder.go61 symbols
core.go54 symbols
read_test.go46 symbols
materials/materials.go38 symbols
encoder.go36 symbols
read.go33 symbols
math.go32 symbols
internal/xml/xml.go32 symbols
materials/decoder.go31 symbols
slices/decoder.go25 symbols
spec/encoding.go22 symbols
beamlattice/decoder.go22 symbols

For agents

$ claude mcp add go3mf \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page