diff --git a/.github/workflows/constraints-demo.yml b/.github/workflows/constraints-demo.yml index 1efbd88c..e2f7cf02 100644 --- a/.github/workflows/constraints-demo.yml +++ b/.github/workflows/constraints-demo.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest defaults: run: - working-directory: ./constraints + working-directory: ./demos/constraints steps: - uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/wasm-demo.yml b/.github/workflows/wasm-demo.yml index b2f02306..2364d79b 100644 --- a/.github/workflows/wasm-demo.yml +++ b/.github/workflows/wasm-demo.yml @@ -14,14 +14,15 @@ jobs: runs-on: ubuntu-latest defaults: run: - working-directory: ./wasm-demo + working-directory: ./demos/web-editor steps: - uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 - name: Install wasm target run: rustup target add wasm32-unknown-unknown - name: Install wasm-pack - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + run: | + curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - name: Install npm dependencies run: npm install - name: Check Prettier diff --git a/Cargo.lock b/Cargo.lock index 4eb8c2f3..10a844ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -634,20 +634,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" -[[package]] -name = "demo" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap", - "env_logger 0.11.2", - "fidget", - "image", - "log", - "nalgebra", - "workspace-hack", -] - [[package]] name = "dispatch" version = "0.2.0" @@ -915,6 +901,37 @@ dependencies = [ "workspace-hack", ] +[[package]] +name = "fidget-cli" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "env_logger 0.11.2", + "fidget", + "image", + "log", + "nalgebra", + "workspace-hack", +] + +[[package]] +name = "fidget-viewer" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "crossbeam-channel", + "eframe", + "env_logger 0.10.2", + "fidget", + "log", + "nalgebra", + "notify", + "rhai", + "workspace-hack", +] + [[package]] name = "filetime" version = "0.2.23" @@ -2379,23 +2396,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "viewer" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap", - "crossbeam-channel", - "eframe", - "env_logger 0.10.2", - "fidget", - "log", - "nalgebra", - "notify", - "rhai", - "workspace-hack", -] - [[package]] name = "walkdir" version = "2.4.0" diff --git a/Cargo.toml b/Cargo.toml index 044fd375..8d3ef956 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,12 +2,12 @@ resolver = "2" members = [ "fidget", - "constraints", - "demo", - "viewer", + "demos/constraints", + "demos/cli", + "demos/viewer", "workspace-hack", ] -exclude = ["wasm-demo"] +exclude = ["demos/web-editor"] [profile.release] debug = true diff --git a/README.md b/README.md index 5f98aa5e..26bf4c42 100644 --- a/README.md +++ b/README.md @@ -51,31 +51,10 @@ Issues and PRs are welcome, although I'm unlikely to merge anything which adds substantial maintenance burden. This is a personal-scale experimental project, so adjust your expectations accordingly. -## Demo applications -In the [repository on Github](https://github.com/mkeeter/fidget), there are -two demo applications: - -- `demo` does bitmap rendering and meshing from the command line -- `viewer` is a minimal GUI for interactive exploration - -These are deliberately not published to [https://crates.io](crates.io), because -they're demo applications and not complete end-user tools. - -## WebAssembly demo -The `wasm-demo` subfolder embeds Fidget into a web application. Building this -demo requires [`wasm-pack`](https://rustwasm.github.io/wasm-pack/) -to be installed on the host system. - -In that folder, run it with -``` -npm install -npm run serve -``` - -Or bundle files for distribution with -``` -npm run build -``` +## Demos +The [`demos` folder](demos/README.md) contains several demo tools and +applications built using the Fidget crate, +ranging from CLI to GUI to web app. ## Support matrix At the moment, Fidget supports a limited number of platforms: diff --git a/demos/.gitignore b/demos/.gitignore new file mode 100644 index 00000000..557a5559 --- /dev/null +++ b/demos/.gitignore @@ -0,0 +1 @@ +!*/screenshot.png diff --git a/demos/README.md b/demos/README.md new file mode 100644 index 00000000..4d9928b9 --- /dev/null +++ b/demos/README.md @@ -0,0 +1,41 @@ +# Fidget demos +## Command-line demo ([`cli`](cli/)) + +Bitmap rendering and meshing from the command line +```shell +$ cargo run -pfidget-cli --release -- -i models/prospero.vm render2d -s512 --eval=vm -oout.png + Finished release [optimized + debuginfo] target(s) in 0.07s + Running `target/release/fidget-cli -i models/prospero.vm render2d -s512 --eval=vm -oout.png` +[2024-06-06T16:08:12Z INFO fidget_cli] Loaded file in 4.528208ms +[2024-06-06T16:08:12Z INFO fidget_cli] Built shape in 2.375208ms +[2024-06-06T16:08:12Z INFO fidget_cli] Rendered 1x at 14.489 ms/frame +``` + +## Script viewer ([`viewer`](viewer/)) +Minimal desktop GUI for interactive exploration, +using [`egui`](https://github.com/emilk/egui) + +```shell +cargo run --release -pfidget-viewer +``` + +![screenshot of script viewer](viewer/screenshot.png) + +## Constraint solving ([`constraints`](constraints/)) +Example of using Fidget for constraint solving. +Uses [`egui`](https://github.com/emilk/egui) +and runs either on the desktop or as a web app. +```shell +cargo run --release -pconstraints +``` + +![screenshot of contraint editor](constraints/screenshot.png) + +See the [subfolder](constraints/) for details on bundling for the web. + +## Web-based editor ([`web-editor`](web-editor/)) +Integrates Fidget into a TypeScript project (web only) + +![screenshot of web editor](web-editor/screenshot.png) + +See the [subfolder](web-editor/) for details on bundling for the web. diff --git a/demo/Cargo.toml b/demos/cli/Cargo.toml similarity index 62% rename from demo/Cargo.toml rename to demos/cli/Cargo.toml index ea76b6bb..03713cf2 100644 --- a/demo/Cargo.toml +++ b/demos/cli/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "demo" +name = "fidget-cli" version = "0.1.0" edition = "2021" [dependencies] -fidget = { path = "../fidget", default-features = false, features = ["render", "mesh"] } +fidget = { path = "../../fidget", default-features = false, features = ["render", "mesh"] } anyhow = "1" clap = { version = "4", features = ["derive"] } @@ -12,7 +12,7 @@ env_logger = "0.11.2" image = { version = "0.24", default-features = false, features = ["png"] } log = "0.4" nalgebra = "0.31" -workspace-hack = { version = "0.1", path = "../workspace-hack" } +workspace-hack = { version = "0.1", path = "../../workspace-hack" } [features] jit = ["fidget/jit"] diff --git a/demo/src/main.rs b/demos/cli/src/main.rs similarity index 100% rename from demo/src/main.rs rename to demos/cli/src/main.rs diff --git a/constraints/.gitignore b/demos/constraints/.gitignore similarity index 100% rename from constraints/.gitignore rename to demos/constraints/.gitignore diff --git a/constraints/Cargo.toml b/demos/constraints/Cargo.toml similarity index 75% rename from constraints/Cargo.toml rename to demos/constraints/Cargo.toml index 05559a60..9b437f7b 100644 --- a/constraints/Cargo.toml +++ b/demos/constraints/Cargo.toml @@ -10,9 +10,9 @@ eframe = { version = "0.27", default-features = false, features = [ "glow", # Use the glow rendering backend. Alternative: "wgpu". ] } -fidget = { path = "../fidget", default-features = false, features = ["solver"] } +fidget = { path = "../../fidget", default-features = false, features = ["solver"] } log = "0.4" -workspace-hack = { version = "0.1", path = "../workspace-hack" } +workspace-hack = { version = "0.1", path = "../../workspace-hack" } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] env_logger = "0.10.0" diff --git a/constraints/README.md b/demos/constraints/README.md similarity index 85% rename from constraints/README.md rename to demos/constraints/README.md index 84d0ebf0..259e2d4c 100644 --- a/constraints/README.md +++ b/demos/constraints/README.md @@ -1,8 +1,9 @@ # Demo of constraint solving ## WebAssembly ### Setup +Install the [`trunk`](https://trunkrs.dev/) bundler with ``` -cargon install +locked trunk # installs the `trunk` bundler +cargo install +locked trunk ``` ### Developing In this folder, run diff --git a/constraints/index.html b/demos/constraints/index.html similarity index 100% rename from constraints/index.html rename to demos/constraints/index.html diff --git a/demos/constraints/screenshot.png b/demos/constraints/screenshot.png new file mode 100644 index 00000000..3e75aa9b Binary files /dev/null and b/demos/constraints/screenshot.png differ diff --git a/constraints/src/main.rs b/demos/constraints/src/main.rs similarity index 100% rename from constraints/src/main.rs rename to demos/constraints/src/main.rs diff --git a/viewer/Cargo.toml b/demos/viewer/Cargo.toml similarity index 76% rename from viewer/Cargo.toml rename to demos/viewer/Cargo.toml index 083b5b9f..7cc00a71 100644 --- a/viewer/Cargo.toml +++ b/demos/viewer/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "viewer" +name = "fidget-viewer" version = "0.1.0" edition = "2021" @@ -15,12 +15,12 @@ eframe = { version = "0.27", default-features = false, features = [ ] } env_logger = "0.10.0" -fidget = { path = "../fidget", default-features = false, features = ["render", "rhai"] } +fidget = { path = "../../fidget", default-features = false, features = ["render", "rhai"] } log = "0.4" nalgebra = "0.31" notify = "5.0" rhai = "1.10" -workspace-hack = { version = "0.1", path = "../workspace-hack" } +workspace-hack = { version = "0.1", path = "../../workspace-hack" } [features] default = ["jit"] diff --git a/demos/viewer/screenshot.png b/demos/viewer/screenshot.png new file mode 100644 index 00000000..6abef16c Binary files /dev/null and b/demos/viewer/screenshot.png differ diff --git a/viewer/src/main.rs b/demos/viewer/src/main.rs similarity index 100% rename from viewer/src/main.rs rename to demos/viewer/src/main.rs diff --git a/wasm-demo/.gitignore b/demos/web-editor/.gitignore similarity index 100% rename from wasm-demo/.gitignore rename to demos/web-editor/.gitignore diff --git a/wasm-demo/Cargo.lock b/demos/web-editor/Cargo.lock similarity index 100% rename from wasm-demo/Cargo.lock rename to demos/web-editor/Cargo.lock diff --git a/wasm-demo/Cargo.toml b/demos/web-editor/Cargo.toml similarity index 75% rename from wasm-demo/Cargo.toml rename to demos/web-editor/Cargo.toml index fa231c85..fca51b5e 100644 --- a/wasm-demo/Cargo.toml +++ b/demos/web-editor/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib"] [dependencies] bincode = "1.3.3" -fidget = {path = "../fidget", default-features = false, features = ["rhai", "mesh", "render"]} +fidget = {path = "../../fidget", default-features = false, features = ["rhai", "mesh", "render"]} wasm-bindgen = "0.2.92" nalgebra = "0.31" diff --git a/demos/web-editor/README.md b/demos/web-editor/README.md new file mode 100644 index 00000000..a705d40d --- /dev/null +++ b/demos/web-editor/README.md @@ -0,0 +1,17 @@ +The `web-editor` subfolder embeds Fidget into a web application. + +Building this demo requires [`wasm-pack`](https://rustwasm.github.io/wasm-pack/) +to be installed on the host system. + +Run the editor demo with + +``` +npm install +npm run serve +``` + +Or bundle files for distribution with + +``` +npm run build +``` diff --git a/wasm-demo/constants.ts b/demos/web-editor/constants.ts similarity index 100% rename from wasm-demo/constants.ts rename to demos/web-editor/constants.ts diff --git a/wasm-demo/index.html b/demos/web-editor/index.html similarity index 100% rename from wasm-demo/index.html rename to demos/web-editor/index.html diff --git a/wasm-demo/index.ts b/demos/web-editor/index.ts similarity index 100% rename from wasm-demo/index.ts rename to demos/web-editor/index.ts diff --git a/wasm-demo/message.ts b/demos/web-editor/message.ts similarity index 100% rename from wasm-demo/message.ts rename to demos/web-editor/message.ts diff --git a/wasm-demo/package-lock.json b/demos/web-editor/package-lock.json similarity index 100% rename from wasm-demo/package-lock.json rename to demos/web-editor/package-lock.json diff --git a/wasm-demo/package.json b/demos/web-editor/package.json similarity index 100% rename from wasm-demo/package.json rename to demos/web-editor/package.json diff --git a/demos/web-editor/screenshot.png b/demos/web-editor/screenshot.png new file mode 100644 index 00000000..dc709324 Binary files /dev/null and b/demos/web-editor/screenshot.png differ diff --git a/wasm-demo/src/lib.rs b/demos/web-editor/src/lib.rs similarity index 100% rename from wasm-demo/src/lib.rs rename to demos/web-editor/src/lib.rs diff --git a/wasm-demo/tsconfig.json b/demos/web-editor/tsconfig.json similarity index 100% rename from wasm-demo/tsconfig.json rename to demos/web-editor/tsconfig.json diff --git a/wasm-demo/webpack.config.js b/demos/web-editor/webpack.config.js similarity index 100% rename from wasm-demo/webpack.config.js rename to demos/web-editor/webpack.config.js diff --git a/wasm-demo/worker.ts b/demos/web-editor/worker.ts similarity index 100% rename from wasm-demo/worker.ts rename to demos/web-editor/worker.ts diff --git a/fidget/src/rhai/core.rhai b/fidget/src/rhai/core.rhai index 44dd8f2a..cb9615f5 100644 --- a/fidget/src/rhai/core.rhai +++ b/fidget/src/rhai/core.rhai @@ -25,7 +25,7 @@ fn intersection(a, b) { } fn inverse(a) { - a.neg() + -a } fn difference(a, b) {