@@ -17,14 +17,16 @@ Adds 3D support for <a href="https://github.com/flame-engine/flame">Flame</a> us
1717</p >
1818
1919---
20+
2021<!-- markdownlint-enable MD013 -->
2122
2223<!-- markdownlint-disable-next-line MD002 -->
24+
2325# flame_3d
2426
25- This package provides an experimental implementation of 3D support for Flame. The main focus is to
26- explore the potential capabilities of 3D for Flame while providing a familiar API to existing Flame
27- developers.
27+ This package provides an experimental implementation of 3D support for Flame.
28+ The main focus is to explore the potential capabilities of 3D for Flame while
29+ providing a familiar API to existing Flame developers.
2830
2931Supported platforms:
3032
@@ -35,41 +37,48 @@ Supported platforms:
3537| macOS | ✅ |
3638| Windows | ❌ |
3739| Linux | ❌ |
38- | Web | ❌ |
40+ | Web | ⚠️¹ |
41+
42+ ⚠️¹ Web support is experimental, see [ Web support] ( #web-support-experimental )
43+ below.
3944
4045
4146## Prologue
4247
43- ** STOP** , we know you are hyped up and want to start coding some funky 3D stuff but we first have to
44- set your expectations and clarify some things. So turn down your music, put away the coffee and make
45- some tea instead because you have to do some reading first!
48+ ** STOP** , we know you are hyped up and want to start coding some funky 3D stuff
49+ but we first have to set your expectations and clarify some things. So turn down
50+ your music, put away the coffee and make some tea instead because you have to do
51+ some reading first!
4652
47- This package provides 3D support for Flame but it depends on the still experimental
48- [ Flutter GPU] ( https://github.com/flutter/flutter/wiki/Flutter-GPU ) , which in turn depends on
49- Impeller.
53+ This package provides 3D support for Flame but it depends on the still
54+ experimental [ Flutter GPU] ( https://github.com/flutter/flutter/wiki/Flutter-GPU ) ,
55+ which in turn depends on Impeller.
5056
5157Therefore, this package is also experimental; you can check our
5258[ Roadmap] ( https://github.com/flame-engine/flame/blob/main/packages/flame_3d/ROADMAP.md )
5359for more details on our plans and what is currently supported.
5460
55- This package does not guarantee that it will follow correct [ semver] ( https://semver.org/ ) versioning
56- rules, nor does it assure that its APIs wont break. Be ready to constantly have to refactor your
57- code if you are planning on using this package, and potentially to have to contribute with
61+ This package does not guarantee that it will follow correct
62+ [ semver] ( https://semver.org/ ) versioning rules, nor does it assure that its APIs
63+ wont break. Be ready to constantly have to refactor your code if you are
64+ planning on using this package, and potentially to have to contribute with
5865improvements and fixes. Please do not use this for production environments.
5966
60- Documentation and tests might be lacking for quite a while because of the potential constant changes
61- of the API. Where possible, we will try to provide in-code documentation and code examples to help
62- developers but our main goal for now is to enable the usage of 3D rendering within a Flame
63- ecosystem.
67+ Documentation and tests might be lacking for quite a while because of the
68+ potential constant changes of the API. Where possible, we will try to provide
69+ in-code documentation and code examples to help developers but our main goal for
70+ now is to enable the usage of 3D rendering within a Flame ecosystem.
6471
6572
6673## Prerequisites
6774
68- In order to use flame_3d, you will need to ensure a few things. Firstly, the only platforms that we
69- have explicitly tested so far for support were Android, iOS, and macOS.
75+ In order to use flame_3d, you will need to ensure a few things. Firstly, the
76+ only platforms that we have explicitly tested so far for support were Android,
77+ iOS, and macOS.
7078
71- Then, you need to enable Impeller, if not already enabled by default. For example, for macOS, add
72- the following to the generated ` macos/runner/Info.plist ` directory:
79+ Then, you need to enable Impeller, if not already enabled by default. For
80+ example, for macOS, add the following to the generated ` macos/runner/Info.plist `
81+ directory:
7382
7483``` xml
7584<dict >
@@ -87,43 +96,71 @@ Alternatively, you can run Flutter with this flag instead:
8796flutter run --enable-flutter-gpu
8897```
8998
90- Now everything is set up you can start doing some 3D magic! You can check out the
91- [ example] ( https://github.com/flame-engine/flame/tree/main/packages/flame_3d/example ) to see how you
92- can set up a simple 3D environment using Flame.
99+ Now everything is set up you can start doing some 3D magic! You can check out
100+ the
101+ [ example] ( https://github.com/flame-engine/flame/tree/main/packages/flame_3d/example )
102+ to see how you can set up a simple 3D environment using Flame.
103+
104+ Also check our more advanced examples,
105+ [ Collect the Donut] ( https://github.com/luanpotter/collect_the_donut ) and
106+ [ Defend the Donut] ( https://github.com/flame-engine/defend_the_donut ) .
107+
93108
94- Also check our more advanced examples, [ Collect the Donut] ( https://github.com/luanpotter/collect_the_donut )
95- and [ Defend the Donut] ( https://github.com/flame-engine/defend_the_donut ) .
109+ ## Web support (experimental)
110+
111+ Flame 3D also runs on the web, though this is ** even more experimental** than
112+ the rest of the package. Flutter GPU does not run in the browser (for now), so
113+ on web ` flame_3d ` renders through the browser's native
114+ [ WebGPU] ( https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API ) API
115+ instead, via a separate rendering backend. If you want to run on web add the
116+ following before your ` runApp ` call in ` main.dart ` :
117+
118+ ``` dart
119+ await GpuBackend.initialize();
120+ ```
96121
97122
98123## Building shaders
99124
100- If you are using the ` SpatialMaterial ` provided by ` flame_3d ` , you do not need to worry about shaders.
125+ If you are using the materials provided by ` flame_3d ` , you do not need to worry
126+ about shaders.
101127
102- That being said, you can write your own shaders and use them on custom materials.
103- Currently, Flutter does not do the bundling of shaders for us so this package provides a simple
104- Dart script. Create your fragment and vertex shader in a ` shaders ` directory,
105- make sure the file names are identical. Like so:
128+ That being said, you can write your own shaders and use them on custom
129+ materials. Currently, Flutter does not do the bundling of shaders for us so this
130+ package provides a simple Dart script. Create your fragment and vertex shader in
131+ a ` shaders ` directory, make sure the file names are identical. Like so:
106132
107133- ` my_custom_shader ` .frag
108134- ` my_custom_shader ` .vert
109135
110- You can then run ` dart pub run flame_3d:build_shaders ` to bundle the shaders. They will
111- automatically be placed in ` assets/shaders ` .
136+ You can then run ` dart pub run flame_3d:build_shaders ` to bundle the shaders.
137+ They will automatically be placed in ` assets/shaders ` .
138+
139+ For [ web support] ( #web-support-experimental ) , also pass ` --with-web-gpu ` to
140+ build the WebGPU shader bundles. That step needs the ` naga ` CLI on your ` PATH `
141+ (` cargo install naga-cli ` ).
142+
143+ Shaders can also reuse shared GLSL through ` #include ` . An
144+ ` #include <package_name/file.glsl> ` resolves against the ` shaders/ ` directory of
145+ any package in your dependency graph, so chunks can be shared across packages.
146+ Including ones that ` flame_3d ` itself ships, such as
147+ ` #include <flame_3d/skinning.glsl> ` for vertex skinning.
112148
113149You can check out the
114- [ default shaders] ( https://github.com/flame-engine/flame/tree/main/packages/flame_3d/shaders ) if you
115- want to have some examples.
150+ [ default shaders] ( https://github.com/flame-engine/flame/tree/main/packages/flame_3d/shaders )
151+ if you want to have some examples.
116152
117153
118154## Contributing
119155
120- Have you found a bug or have a suggestion of how to enhance the 3D APIs? Open an issue and we will
121- take a look at it as soon as possible.
156+ Have you found a bug or have a suggestion of how to enhance the 3D APIs? Open an
157+ issue and we will take a look at it as soon as possible.
122158
123- Do you want to contribute with a PR? PRs are always welcome, just make sure to create it from the
124- correct branch (main) and follow the [ checklist] ( .github/pull_request_template.md ) which will
125- appear when you open the PR.
159+ Do you want to contribute with a PR? PRs are always welcome, just make sure to
160+ create it from the correct branch (main) and follow the
161+ [ checklist] ( .github/pull_request_template.md ) which will appear when you open
162+ the PR.
126163
127- For bigger changes, or if in doubt, make sure to talk about your contribution to the team. Either
128- via an issue, GitHub discussion, or reach out to the team using the
129- [ Discord server] ( https://discord.gg/pxrBmy4 ) .
164+ For bigger changes, or if in doubt, make sure to talk about your contribution to
165+ the team. Either via an issue, GitHub discussion, or reach out to the team using
166+ the [ Discord server] ( https://discord.gg/pxrBmy4 ) .
0 commit comments