New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/drummonds/sdf-ui

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/drummonds/sdf-ui

  • v0.0.0-20220506150300-82fa5aa4c342
  • Source
  • Go
  • Socket score

Version published
Created
Source

SDF-UI

This is a trial port of Yeicor / sdfx-ui to using soypat/sdf version of sdfx

GitHub go.mod Go version of a Go module Go Reference Go Go Report Card

MIT license

SDF-UI is a SDF (2D and 3D) renderer intended for fast development iterations that renders directly to a window. It integrates with your code as a library, meaning that you define your surface and then call the method that starts this UI.

The UI will listen for code updates (you can use your preferred code editor) and displays the new surfaces automatically with the same state (e.g., camera position).

Pull requests are welcome! The priority is to improve the user experience (making a proper UI or adding new capabilities) without losing performance.

Demo

Configuring the Renderer is as simple as creating your signed distance function and calling ui.NewRenderer(anySDF).Run().

package main

import (
	"github.com/Yeicor/sdfx-ui"
	"github.com/soypat/sdfsdf"
)

func main() {
	anySDF, _ := sdf.Box3D(sdf.V3{X: 1, Y: 1, Z: 1}, 0.2)
	_ = ui.NewRenderer(anySDF).Run() // Error handling ignored
}

This is a demo of the workflow for designing your own SDF using this UI (code at examples/spiral/main.go):

Demo video

How does it work?

The first time you run the code, it starts the renderer process. It also starts listening for code changes. When a code change is detected, the app is recompiled by the renderer (taking advantage of Go's fast compilation times) and quickly renders the new surface to the same window (with the same camera position and other settings).

The SDF2 renderer shows the value of the SDF on each pixel using a grayscale: where bright pixels indicate outside the object and darker pixels are inside. The camera can be moved and scaled (using the mouse), rendering only the interesting part of the SDF.

SDF3s are raycasted from a perspective arc-ball camera that can be rotated around a pivot point, move its pivot and move closer or farther away from the pivot (using Blender-like mouse controls). Note that only the shown surface is actually rendered thanks to raycasting from the camera. This also means that the resulting surface can be much more detailed (depending on chosen resolution) than the triangle meshes generated by standard mesh generators.

There is an alternative SDF3 renderer (enabled via ui.Opt3Mesh(...)) which generates a triangle mesh using an algorithm from SDF and then renders that triangle mesh to the screen thanks to FauxGL. It is a software renderer that is still very fast for our purposes (faster than the required mesh generation to use it). The main advantage over the raycast renderer is very fast camera movements and parameter updates, with the disadvantages of low (limited) detail and slower updates (as the initial mesh generation is slow).

SDF-UI uses Ebiten for window management and rendering. Ebiten is cross-platform, so it could also be used to showcase a surface (without automatic updates) creating an application for desktop, web, mobile or Nintendo Switch™.

Browser and mobile

They use the same code as the demo, see compilation instructions at examples/spiral/main.go.

Screenshot_20220107_234547 Screenshot_20220107-234815220

Note that mobile only works with mouse and keyboard for now.

Other demos

Screenshot_20220226_205856

FAQs

Package last updated on 06 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc