Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

SDF Viewer integration for Go libraries

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

yeicor/sdf-viewer-go

Repository files navigation

SDF Viewer integration for Go libraries.This allows you to design 3D models in Go using Signed Distance Functions while visualizing the results as fast aspossible.Check out theSDF Viewer App's README for more information.

Go modules included in this repository:

This project usesTinyGo to build the WebAssembly binary (for now) as the Go Compiler can't exportWebAssembly functions. This means that it won't "be able to compile every Go program out there", but should begood enough for most projects. It is also slower to build (and run) than the Go Compiler.

Quickstart (SDFX)

Write the followingmain.go file:

package mainimport ("fmt"  sdfviewergo"github.com/Yeicor/sdf-viewer-go/sdf-viewer-go"  sdfviewergosdfx"github.com/Yeicor/sdf-viewer-go/sdf-viewer-go-sdfx"  ."github.com/deadsy/sdfx/sdf"  v3"github.com/deadsy/sdfx/vec/v3")//export initfuncinit() {// This is the only function you need to call to initialize the SDF Viewer.sdfviewergo.SetRootSDF(sceneSDF())}//placeholder main to allow compilationfuncmain() {fmt.Println("This is not an executable. Compile this with `"+"tinygo build -o example.wasm -target wasi -opt 2 -x -no-debug ."+"` and use the SDF Viewer app (github.com/Yeicor/sdf-viewer) to visualize the SDF.")}// sceneSDF returns the root SDF of the scene.funcsceneSDF() sdfviewergo.SDF {// Simple scene:box,_:=Box3D(v3.Vec{X:1.,Y:1.,Z:1.},0.25)cyl,_:=Cylinder3D(1.5,0.25,0.25)sdfxSDF:=Union3D(box,cyl)cyl2,_:=Cylinder3D(1.5,0.25,0.25)cyl2rot:=Transform3D(cyl2,RotateY(DtoR(90)))sdfxSDF=Difference3D(sdfxSDF,cyl2rot)returnsdfviewergosdfx.NewSDF(sdfxSDF)}

The build command is:

tinygo build -o example.wasm -target wasi -opt 2 -x -no-debug.

Then just open the generated WebAssembly file withSDF Viewer App:

sdf-viewer app url relative/path/to/example.wasm

Or, on a web browser that also publishes the WebAssembly file:

http://localhost:8080/?cliurl=relative/path/to/example.wasm&envdark

If you want to automate reloading the object when the source code changes

Set up a server process that will automatically build the WebAssembly filewhen the Go file changes, and send the updated file to the SDF Viewer App:

sdf-viewer server -s relative/path/to/example.wasm -w relative/path/to/main.go -b /bin/sh -b\-c -b"cd relative/path/to/ && tinygo build -o example.wasm -target wasi -opt 2 -x -no-debug ."

Connect the app to this server process:

sdf-viewer app url http://localhost:8080/relative/path/to/example.wasm

Or, on a web browser with access to the local server:

http://localhost:8080/?cliurl=http://localhost:8080/relative/path/to/example.wasm&envdark

Demo: phone case

This is the SDFX example generated fromthis source file.View it onlineordownload the WebAssembly file to view it on thedesktop app.

Demo GIF

The demo was recorded at a lower framerate, but it runs in real time on an integrated graphics card.


[8]ページ先頭

©2009-2025 Movatter.jp