Code Monkey home page Code Monkey logo

go3mf's Introduction

PkgGoDev Build Status Go Report Card codecov codeclimate 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 https://3mf.io/specification/.

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.
    • spec_production.
    • spec_slice.
    • spec_beamlattice.
    • spec_materials, missing the display resources.

Examples

Read from file

package main

import (
    "fmt"

    "github.com/qmuntal/go3mf"
)

func main() {
    model := new(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 {
          fmt.Println(t.Indices())
        }
        for _, v := range obj.Mesh.Vertices {
          fmt.Println(v.X(), v.Y(), v.Z())
        }
      }
    }
}

Read from HTTP body

package main

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

func main() {
    resp, _ := http.Get("zip file url")
    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    model := new(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/qmuntal/go3mf"
)

func main() {
    file := os.Create("/testdata/cube.3mf")
    model := new(go3mf.Model)
    go3mf.NewEncoder(file).Encode(model)
}

Spec usage

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

package main

import (
    "fmt"

    "github.com/qmuntal/go3mf"
    "github.com/qmuntal/go3mf/material"
    _"github.com/qmuntal/go3mf/production"
    _ "github.com/qmuntal/go3mf/beamlattice"
    _ "github.com/qmuntal/go3mf/slices"
)

func main() {
    model := new(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}},
    }
}

go3mf's People

Contributors

carlotacb avatar qmuntal avatar

Watchers

 avatar

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.