|
| 1 | +# Filament Tools Gradle Plugin |
| 2 | + |
| 3 | +## About |
| 4 | + |
| 5 | +The **Filament Tools Gradle Plugin** helps integrate Filament into your Android project. It |
| 6 | +automates the use of Filament's command-line tools (`matc`, `cmgen`, and `filamesh`). |
| 7 | + |
| 8 | +This plugin handles: |
| 9 | +- **Material Compilation**: Compiles `.mat` material definitions into `.filamat` binaries. |
| 10 | +- **IBL Generation**: Generates Image-Based Lighting assets from HDR environment maps. |
| 11 | +- **Mesh Compilation**: Converts models into Filament's efficient `.filamesh` binary format. *Note: |
| 12 | + This tool is no longer recommended; instead, use glTF and Filament's `gltfio` library for model |
| 13 | + loading.* |
| 14 | + |
| 15 | +The plugin hooks directly into the Android build lifecycle (via `preBuild`) and supports incremental |
| 16 | +builds, so assets are only recompiled when source files change. |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +Apply the plugin in your module's `build.gradle` file and configure the `filament` block. You can |
| 21 | +specify inputs and outputs for any combination of materials, IBLs, or meshes. If a path is not |
| 22 | +configured, the corresponding task will be disabled. |
| 23 | + |
| 24 | +### Example Configuration |
| 25 | + |
| 26 | +```groovy |
| 27 | +plugins { |
| 28 | + id 'filament-plugin' |
| 29 | +} |
| 30 | +
|
| 31 | +filament { |
| 32 | + materialInputDir = project.layout.projectDirectory.dir("src/main/materials") |
| 33 | + materialOutputDir = project.layout.projectDirectory.dir("src/main/assets/materials") |
| 34 | +
|
| 35 | + iblInputFile = project.layout.projectDirectory.file("path/to/environment.hdr") |
| 36 | + iblOutputDir = project.layout.projectDirectory.dir("src/main/assets/envs") |
| 37 | +
|
| 38 | + meshInputFile = project.layout.projectDirectory.file("path/to/model.obj") |
| 39 | + meshOutputDir = project.layout.projectDirectory.dir("src/main/assets/models") |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +### Configuration Details |
| 44 | + |
| 45 | +- **materialInputDir**: The directory containing your source material definitions (`.mat` files). |
| 46 | +- **materialOutputDir**: The directory where the compiled material files (`.filamat`) will be |
| 47 | + generated. |
| 48 | +- **iblInputFile**: The source high-dynamic-range image file (e.g., `.hdr` or `.exr`) used to |
| 49 | + generate Image Based Lighting assets. |
| 50 | +- **iblOutputDir**: The directory where the generated IBL assets (typically `.ktx` files) will be |
| 51 | + placed. |
| 52 | +- **meshInputFile**: The source mesh file (e.g., `.obj`) to be compiled. |
| 53 | +- **meshOutputDir**: The directory where the compiled mesh file (`.filamesh`) will be generated. |
| 54 | + |
| 55 | +Automatically adds tasks to your Android build to compile materials, generate an IBL, and compile a |
| 56 | +mesh. The plugin hooks into `preBuild` to ensure assets are generated before the application is |
| 57 | +built. |
| 58 | + |
| 59 | +### Configuration Flags |
| 60 | + |
| 61 | +You can control specific compilation options using Gradle properties (e.g., in `gradle.properties` |
| 62 | +or via command line `-P`). |
| 63 | + |
| 64 | +- **`com.google.android.filament.exclude-vulkan`** When set to `true`, the Vulkan backend is |
| 65 | + excluded from the compiled materials. This can be useful to reduce the size of the generated |
| 66 | + assets if your application does not target Vulkan. *Default: `false` (Vulkan is included)* |
| 67 | + |
| 68 | +- **`com.google.android.filament.include-webgpu`** When set to `true`, the WebGPU backend is |
| 69 | + included in the compiled materials. Use this if you intend to use the materials in a context |
| 70 | + supporting WebGPU. *Default: `false`* |
| 71 | + |
| 72 | +## Tools Configuration |
| 73 | + |
| 74 | +The Filament Tools plugin requires some binary tools to be available: `matc`, `cmgen`, and |
| 75 | +`filamesh`. |
| 76 | + |
| 77 | +There are three ways to configure Filament tools: |
| 78 | + |
| 79 | +1. **Point to a local path directly** |
| 80 | + |
| 81 | +```groovy |
| 82 | +filament { |
| 83 | + matc { |
| 84 | + path = "/path/to/matc" |
| 85 | + } |
| 86 | +
|
| 87 | + cmgen { |
| 88 | + path = "/path/to/cmgen" |
| 89 | + } |
| 90 | +
|
| 91 | + filamesh { |
| 92 | + path = "/path/to/filamesh" |
| 93 | + } |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | +2. **Point to a Maven artifact** |
| 98 | + |
| 99 | +```groovy |
| 100 | +filament { |
| 101 | + matc { |
| 102 | + // The minor version (the middle number) must match the Filament dependency's. |
| 103 | + artifact = 'com.google.android.filament:matc:1.68.5' |
| 104 | + } |
| 105 | +
|
| 106 | + cmgen { |
| 107 | + artifact = 'com.google.android.filament:cmgen:1.68.5' |
| 108 | + } |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +*Note that the `filamesh` artifact is not hosted on Maven Central, so it must be provided locally or |
| 113 | +via another mechanism if needed.* |
| 114 | + |
| 115 | +Gradle will automatically handle downloading the tool appropriate for your machine (MacOS/Linux/Windows) from Maven. |
| 116 | + |
| 117 | +3. **Set the `com.google.android.filament.tools-dir` Gradle property** |
| 118 | + |
| 119 | +This will override any other configuration. Gradle will attempt to locate the tools under |
| 120 | +`<tools-dir>/bin` (e.g., `.../bin/matc`, `.../bin/cmgen`, `.../bin/filamesh`). |
0 commit comments