-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 3mf convert example stl <-> 3mf * Add triangle example * Create cube example * extract info example * Include create components example * color cube example * beam lattice example. Little tricky as SetBeams() / SetBeam() seem to have issues. Example works with AddBeam() without any issues * Include copyright info to all 7 golang examples * update the one line abstract in golang examples * Include tests for go bindings in deploy (linux, windows and osx) * Get the 3mf binding first * Initialize a go module + Fix lib3mf Go import * Update golang examples * Update golang examples * Clean examples * cleanup golang deployment * Only solution for Golang (tried everything else)
- Loading branch information
1 parent
5fe4bd3
commit c2fd5e6
Showing
9 changed files
with
1,289 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -397,6 +397,17 @@ jobs: | |
cd SDK/CPackExamples/Cpp/build | ||
cmake --build . | ||
./Example_ExtractInfo ../../../Examples/Files/Helix.3mf | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
- name: Go Bindings | ||
run: | | ||
cd SDK/Examples/Go | ||
go mod init lib3mfExamples | ||
go get github.com/3MFConsortium/lib3mf.go/[email protected] | ||
go build -o create_cube create_cube.go | ||
./create_cube | ||
deploy-windows: | ||
runs-on: windows-2019 | ||
|
@@ -451,6 +462,18 @@ jobs: | |
cd SDK/CPackExamples/Cpp/build | ||
cmake --build . --config Release | ||
./Release/Example_ExtractInfo.exe ../../../Examples/Files/Helix.3mf | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
- name: Go Bindings | ||
run: | | ||
cd SDK/Examples/Go | ||
go mod init lib3mfExamples | ||
go get github.com/3MFConsortium/lib3mf.go/[email protected] | ||
go build -o create_cube.exe create_cube.go | ||
./create_cube.exe | ||
deploy-macos: | ||
runs-on: macos-latest | ||
|
@@ -507,6 +530,17 @@ jobs: | |
cd SDK/CPackExamples/Cpp/build | ||
cmake --build . | ||
./Example_ExtractInfo ../../../Examples/Files/Helix.3mf | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
- name: Go Bindings | ||
run: | | ||
cd SDK/Examples/Go | ||
go mod init lib3mfExamples | ||
go get github.com/3MFConsortium/lib3mf.go/[email protected] | ||
go build -o create_cube create_cube.go | ||
./create_cube | ||
deploy-source-code-with-submodules: | ||
runs-on: ubuntu-20.04 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
+++ | ||
Copyright (C) 2019 3MF Consortium (Vijai Kumar Suriyababu) | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions, and the following disclaimer. | ||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions, and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
Abstract: An example to convert between 3MF and STL | ||
Interface version: 2.4.0 | ||
+++ | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
lib3mf "github.com/3MFConsortium/lib3mf.go/v2" | ||
) | ||
|
||
// findExtension returns the file extension from a given filename. | ||
func findExtension(filename string) string { | ||
idx := strings.LastIndex(filename, ".") | ||
if idx != -1 { | ||
return filename[idx:] | ||
} | ||
return "" | ||
} | ||
|
||
// convert performs the conversion between 3MF and STL formats. | ||
func convert(filename string) int { | ||
// Get a wrapper object | ||
wrapper, err := lib3mf.GetWrapper() | ||
if err != nil { | ||
log.Fatal("Error loading 3MF library:", err) | ||
return -1 | ||
} | ||
|
||
// Check the library version (optional, similar to get_version in Python) | ||
nMajor, nMinor, nMicro, err := wrapper.GetLibraryVersion() | ||
if err != nil { | ||
log.Fatal("Error fetching lib3mf version:", err) | ||
return -1 | ||
} | ||
fmt.Printf("lib3mf version: %d.%d.%d\n", nMajor, nMinor, nMicro) | ||
|
||
extension := strings.ToLower(findExtension(filename)) | ||
var readerName, writerName, newExtension string | ||
|
||
switch extension { | ||
case ".stl": | ||
readerName = "stl" | ||
writerName = "3mf" | ||
newExtension = ".3mf" | ||
case ".3mf": | ||
readerName = "3mf" | ||
writerName = "stl" | ||
newExtension = ".stl" | ||
default: | ||
fmt.Printf("Unknown input file extension: %s\n", extension) | ||
return -1 | ||
} | ||
|
||
outputFilename := filename[:len(filename)-len(extension)] + newExtension | ||
|
||
// Create a new 3MF model | ||
model, err := wrapper.CreateModel() | ||
if err != nil { | ||
log.Fatal("Error creating 3MF model:", err) | ||
return -1 | ||
} | ||
|
||
// Read from the input file | ||
reader, err := model.QueryReader(readerName) | ||
if err != nil { | ||
log.Fatal("Error querying reader for format:", readerName) | ||
return -1 | ||
} | ||
fmt.Printf("Reading %s...\n", filename) | ||
err = reader.ReadFromFile(filename) | ||
if err != nil { | ||
log.Fatal("Error reading from file:", err) | ||
return -1 | ||
} | ||
|
||
// Write to the output file | ||
writer, err := model.QueryWriter(writerName) | ||
if err != nil { | ||
log.Fatal("Error querying writer for format:", writerName) | ||
return -1 | ||
} | ||
fmt.Printf("Writing %s...\n", outputFilename) | ||
err = writer.WriteToFile(outputFilename) | ||
if err != nil { | ||
log.Fatal("Error writing to file:", err) | ||
return -1 | ||
} | ||
|
||
fmt.Println("Done") | ||
return 0 | ||
} | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
fmt.Println("Usage:") | ||
fmt.Println("Convert 3MF to STL: go run 3mf_convert.go model.3mf") | ||
fmt.Println("Convert STL to 3MF: go run 3mf_convert.go model.stl") | ||
os.Exit(1) | ||
} else { | ||
if err := convert(os.Args[1]); err != 0 { | ||
os.Exit(err) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.