Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions examples/flutter/material_editor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
36 changes: 36 additions & 0 deletions examples/flutter/material_editor/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "44a626f4f0027bc38a46dc68aed5964b05a83c18"
channel: "[user-branch]"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 44a626f4f0027bc38a46dc68aed5964b05a83c18
base_revision: 44a626f4f0027bc38a46dc68aed5964b05a83c18
- platform: linux
create_revision: 44a626f4f0027bc38a46dc68aed5964b05a83c18
base_revision: 44a626f4f0027bc38a46dc68aed5964b05a83c18
- platform: macos
create_revision: 44a626f4f0027bc38a46dc68aed5964b05a83c18
base_revision: 44a626f4f0027bc38a46dc68aed5964b05a83c18
- platform: windows
create_revision: 44a626f4f0027bc38a46dc68aed5964b05a83c18
base_revision: 44a626f4f0027bc38a46dc68aed5964b05a83c18

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
62 changes: 62 additions & 0 deletions examples/flutter/material_editor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# material_editor

A Flutter project demonstrating **runtime material compilation and
hot-reload** in Thermion: edit Filament `.mat` source in a text field and see
the change on a live-rendered sphere, without restarting the app.

The top half of the window is a `ViewerWidget` rendering a sphere; the bottom
half is a plain `TextField` holding `.mat` source. Every edit (debounced, or
via the **Apply** button) is compiled to a `.filamat` package *inside the
running engine* and hot-swapped onto the sphere.

## How it works

Two APIs from `thermion_dart` drive the whole loop:

1. **`FilamentApp.compileMaterial(source)`** (runtime compile) — parses and
compiles `.mat` source through the same `matp` + `filamat` pipeline the
offline `matc` tool uses, returning the compiled `.filamat` bytes. On
failure it throws `MaterialCompileException` with the compiler's message,
which the editor shows inline under the text field.

2. **`FilamentApp.reloadMaterialFromBytes(material, bytes)`** (hot-reload) —
builds a new `Material` from the compiled bytes, creates a replacement
`MaterialInstance`, re-points every renderable that used the old instance,
replays recorded instance state (parameters like `baseTint` below) onto the
replacement, and destroys the old material. The sphere never leaves the
scene; only the material under it changes.

Startup (`_onViewerAvailable`) compiles `materials/starter.mat` — a lit
material with `baseTint` / `roughness` / `metallic` parameters — creates an
instance, sets those parameters, and creates the sphere geometry with that
instance. Subsequent compiles go through `reloadMaterialFromBytes`, so the
parameter values set at startup survive every edit: change `shadingModel` to
`unlit`, delete `prepareMaterial`, or introduce a syntax error — the sphere
keeps rendering the last good material while the error is shown inline.

The starter source is a good place to experiment:

- change `material.baseColor = materialParams.baseTint;` to a constant
`float4(1.0, 0.3, 0.1, 1.0)`;
- add `material.clearCoat = 1.0;` after `prepareMaterial(material);`;
- set `shadingModel : unlit` (and drop the roughness/metallic lines) to see
flat unshaded color;
- delete a `}` to see the inline error report.

## Platform support

Runtime compilation is linked into **desktop** engine builds only (Linux,
macOS, Windows). On web `compileMaterial` throws `UnsupportedError`, and on
Android/iOS the native engine reports "not supported" via
`MaterialCompileException`. The example handles both: the sphere still
renders with the default material and the status bar explains why.

## Running

```sh
flutter pub get
flutter run -d linux # or -d macos / -d windows
```

The example targets desktop platforms only (runtime compilation is not
available elsewhere).
28 changes: 28 additions & 0 deletions examples/flutter/material_editor/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
Loading
Loading