Skip to content

Commit ba0499b

Browse files
authored
Switch to an async API (#339)
* feat: auto-create the canvas element if it doesn’t exist yet when targetting wasm32 * feat: adjusts arcball camera near/far planes Modifies the near and far clipping plane distances for the arcball camera. This improves the camera's depth precision and prevents potential z-fighting issues with the default values. * Renames instancing example to 3D. Renames the instancing example to clarify that it demonstrates 3D instancing. * Adds WASM-compatible instancing examples Introduces two new examples demonstrating instancing capabilities suitable for WASM environments. One example showcases 2D instancing, while the other illustrates 3D instancing, providing practical demonstrations of rendering multiple instances of a shape with different transformations and colors. * Adds async rendering support This change introduces asynchronous rendering capabilities to support WebAssembly more effectively. It removes the `State` trait and `render_loop` methods, replacing them with async alternatives. The instancing2d and instancing3d examples are updated to use `wasm-bindgen-futures` and `pollster` for compatibility with async execution in WASM and native environments. * Introduces a proc-macro for simplified async main functions Adds a procedural macro `#[kiss3d::main]` to simplify the creation of cross-platform kiss3d applications, abstracting away platform-specific async runtime initialization for native and WASM targets. This eliminates the need for boilerplate code related to `pollster` and `wasm_bindgen_futures`, resulting in more concise and readable examples. * Re-exports async runtime dependencies Re-exports `pollster` and `wasm_bindgen_futures` to simplify async main function setup using the `kiss3d-macro` crate. This change eliminates the need for users to manually add these dependencies to their `Cargo.toml` when using the `#[kiss3d::main]` macro. The macro now uses the re-exported dependencies, ensuring compatibility and reducing boilerplate. * Refactors the examples to use async/await for rendering, making then compatible with wasm Removed the non-async variants. * Update the README to reflect the new async main pattern * Simplifies persistent point cloud example Refactors the persistent point cloud example to use the simpler `render_with` API. This removes the need for a custom `State` implementation, making the example easier to understand and maintain. * Adds IntelliJ run configurations for examples Adds IntelliJ run configurations for all kiss3d examples and common development tasks. This includes configurations for both native and WASM builds, as well as utility configurations for check, clippy, and test. The configurations are stored in the .run directory. * chore: cargo fmt * chore: clippy fix * fix cargo test
1 parent f794a98 commit ba0499b

118 files changed

Lines changed: 1882 additions & 370 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cargo/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[target.wasm32-unknown-unknown]
2+
runner = "wasm-server-runner"
3+
# Needed for getrandom/uuid: https://github.com/uuid-rs/uuid/issues/792
4+
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']

.run/README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# IntelliJ/CLion Run Configurations
2+
3+
This directory contains run configurations for all Kiss3d examples and common development tasks.
4+
5+
## Generated Configurations
6+
7+
### Example Configurations (72 total)
8+
9+
For each of the 36 examples, two run configurations are provided:
10+
11+
1. **Native** - `<example>.run.xml`
12+
- Runs the example on the native platform
13+
- Command: `cargo run --package kiss3d --example <name>`
14+
- Useful for quick testing and debugging
15+
16+
2. **Web (WASM)** - `<example> (web).run.xml`
17+
- Builds the example for WebAssembly
18+
- Command: `cargo run --package kiss3d --example <name> --target wasm32-unknown-unknown`
19+
- Produces `.wasm` files in `target/wasm32-unknown-unknown/`
20+
21+
### Examples List
22+
23+
- add_remove
24+
- camera
25+
- cube
26+
- custom_material
27+
- custom_mesh
28+
- custom_mesh_shared
29+
- decomp
30+
- event
31+
- group
32+
- instancing2d
33+
- instancing3d
34+
- lines
35+
- mouse_events
36+
- multi_windows
37+
- obj
38+
- persistent_point_cloud
39+
- planar_lines
40+
- points
41+
- post_processing
42+
- primitives
43+
- primitives2d
44+
- primitives_scale
45+
- procedural
46+
- quad
47+
- rectangle
48+
- scene_cycler
49+
- screenshot
50+
- stereo
51+
- text
52+
- texturing
53+
- texturing_mipmaps
54+
- ui
55+
- window
56+
- wireframe
57+
58+
### Utility Configurations
59+
60+
- **check.run.xml** - Run `cargo check` on the project
61+
- **check (wasm).run.xml** - Run `cargo check` for WASM target
62+
- **clippy.run.xml** - Run Clippy linter
63+
- **test.run.xml** - Run all tests
64+
65+
## Usage
66+
67+
### In IntelliJ/CLion
68+
69+
1. Open the project in IntelliJ IDEA or CLion
70+
2. The run configurations will automatically appear in the run configuration dropdown (top-right)
71+
3. Select any configuration and click Run (▶️) or Debug (🐛)
72+
73+
### Running Examples
74+
75+
#### Native
76+
- Select `<example>` from the dropdown
77+
- Click Run to execute the example
78+
- A window will open showing the 3D scene
79+
80+
#### WASM
81+
- Select `<example> (web)` from the dropdown
82+
- Click Run to run for WebAssembly
83+
- The compiled `.wasm` file will be in `target/wasm32-unknown-unknown/release/examples/`
84+
- Use a web server to serve the WASM file (see `examples/wasm/` for web setup)
85+
86+
## Configuration Format
87+
88+
Each configuration file follows the IntelliJ Cargo Command Run Configuration format:
89+
90+
```xml
91+
<component name="ProjectRunConfigurationManager">
92+
<configuration default="false" name="<name>" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
93+
<option name="command" value="<cargo command>" />
94+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
95+
<!-- ... additional options ... -->
96+
</configuration>
97+
</component>
98+
```
99+
100+
## Regenerating Configurations
101+
102+
If you need to regenerate these configurations (e.g., after adding new examples), you can delete all `.run.xml` files and run the generation script again, or manually create new configuration files following the pattern above.
103+
104+
## Version Control
105+
106+
These files are tracked in git so all team members have the same run configurations available.

.run/add_remove (web).run.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="add_remove (web)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
3+
<option name="command" value="run --package kiss3d --example add_remove --target wasm32-unknown-unknown" />
4+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
5+
<option name="emulateTerminal" value="true" />
6+
<option name="channel" value="DEFAULT" />
7+
<option name="requiredFeatures" value="true" />
8+
<option name="allFeatures" value="false" />
9+
<option name="withSudo" value="false" />
10+
<option name="buildTarget" value="REMOTE" />
11+
<option name="backtrace" value="SHORT" />
12+
<envs />
13+
<option name="isRedirectInput" value="false" />
14+
<option name="redirectInputPath" value="" />
15+
<method v="2">
16+
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
17+
</method>
18+
</configuration>
19+
</component>

.run/add_remove.run.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="add_remove" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
3+
<option name="command" value="run --package kiss3d --example add_remove" />
4+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
5+
<option name="emulateTerminal" value="true" />
6+
<option name="channel" value="DEFAULT" />
7+
<option name="requiredFeatures" value="true" />
8+
<option name="allFeatures" value="false" />
9+
<option name="withSudo" value="false" />
10+
<option name="buildTarget" value="REMOTE" />
11+
<option name="backtrace" value="SHORT" />
12+
<envs />
13+
<option name="isRedirectInput" value="false" />
14+
<option name="redirectInputPath" value="" />
15+
<method v="2">
16+
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
17+
</method>
18+
</configuration>
19+
</component>

.run/camera (web).run.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="camera (web)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
3+
<option name="command" value="run --package kiss3d --example camera --target wasm32-unknown-unknown" />
4+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
5+
<option name="emulateTerminal" value="true" />
6+
<option name="channel" value="DEFAULT" />
7+
<option name="requiredFeatures" value="true" />
8+
<option name="allFeatures" value="false" />
9+
<option name="withSudo" value="false" />
10+
<option name="buildTarget" value="REMOTE" />
11+
<option name="backtrace" value="SHORT" />
12+
<envs />
13+
<option name="isRedirectInput" value="false" />
14+
<option name="redirectInputPath" value="" />
15+
<method v="2">
16+
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
17+
</method>
18+
</configuration>
19+
</component>

.run/camera.run.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="camera" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
3+
<option name="command" value="run --package kiss3d --example camera" />
4+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
5+
<option name="emulateTerminal" value="true" />
6+
<option name="channel" value="DEFAULT" />
7+
<option name="requiredFeatures" value="true" />
8+
<option name="allFeatures" value="false" />
9+
<option name="withSudo" value="false" />
10+
<option name="buildTarget" value="REMOTE" />
11+
<option name="backtrace" value="SHORT" />
12+
<envs />
13+
<option name="isRedirectInput" value="false" />
14+
<option name="redirectInputPath" value="" />
15+
<method v="2">
16+
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
17+
</method>
18+
</configuration>
19+
</component>

.run/check (wasm).run.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="check (wasm)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
3+
<option name="buildProfileId" value="release" />
4+
<option name="command" value="check --target wasm32-unknown-unknown" />
5+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
6+
<envs />
7+
<option name="emulateTerminal" value="true" />
8+
<option name="channel" value="DEFAULT" />
9+
<option name="requiredFeatures" value="true" />
10+
<option name="allFeatures" value="false" />
11+
<option name="withSudo" value="false" />
12+
<option name="buildTarget" value="REMOTE" />
13+
<option name="backtrace" value="SHORT" />
14+
<option name="isRedirectInput" value="false" />
15+
<option name="redirectInputPath" value="" />
16+
<method v="2">
17+
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
18+
</method>
19+
</configuration>
20+
</component>

.run/check.run.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="check" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
3+
<option name="buildProfileId" value="release" />
4+
<option name="command" value="check --examples" />
5+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
6+
<envs />
7+
<option name="emulateTerminal" value="true" />
8+
<option name="channel" value="DEFAULT" />
9+
<option name="requiredFeatures" value="true" />
10+
<option name="allFeatures" value="false" />
11+
<option name="withSudo" value="false" />
12+
<option name="buildTarget" value="REMOTE" />
13+
<option name="backtrace" value="SHORT" />
14+
<option name="isRedirectInput" value="false" />
15+
<option name="redirectInputPath" value="" />
16+
<method v="2">
17+
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
18+
</method>
19+
</configuration>
20+
</component>

.run/clippy.run.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="clippy" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
3+
<option name="buildProfileId" value="release" />
4+
<option name="command" value="clippy" />
5+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
6+
<envs />
7+
<option name="emulateTerminal" value="true" />
8+
<option name="channel" value="DEFAULT" />
9+
<option name="requiredFeatures" value="true" />
10+
<option name="allFeatures" value="false" />
11+
<option name="withSudo" value="false" />
12+
<option name="buildTarget" value="REMOTE" />
13+
<option name="backtrace" value="SHORT" />
14+
<option name="isRedirectInput" value="false" />
15+
<option name="redirectInputPath" value="" />
16+
<method v="2">
17+
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
18+
</method>
19+
</configuration>
20+
</component>

.run/cube (web).run.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="cube (web)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
3+
<option name="command" value="run --package kiss3d --example cube --target wasm32-unknown-unknown" />
4+
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
5+
<option name="emulateTerminal" value="true" />
6+
<option name="channel" value="DEFAULT" />
7+
<option name="requiredFeatures" value="true" />
8+
<option name="allFeatures" value="false" />
9+
<option name="withSudo" value="false" />
10+
<option name="buildTarget" value="REMOTE" />
11+
<option name="backtrace" value="SHORT" />
12+
<envs />
13+
<option name="isRedirectInput" value="false" />
14+
<option name="redirectInputPath" value="" />
15+
<method v="2">
16+
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
17+
</method>
18+
</configuration>
19+
</component>

0 commit comments

Comments
 (0)