Skip to content

Commit 3ad7a75

Browse files
fallible-algebratheotherphilCarter0
authored
Explanation for the '3d shapes' example (#19295)
[Explanation](https://bevyengine.org/learn/contribute/helping-out/explaining-examples/) for the 3d shapes example. This shares a lot of detail with the [2d shapes](#19211) example, so it's similar in structure. The explanation for why asset handles are not components has been copied over for now with minor adjustment, I'll do another editing pass on this to make it match the surrounding context and focus before taking it out of drafts. --------- Co-authored-by: theotherphil <phil.j.ellison@gmail.com> Co-authored-by: Carter Weinberg <weinbergcarter@gmail.com>
1 parent 80b059c commit 3ad7a75

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

examples/3d/3d_shapes.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
//! This example demonstrates the built-in 3d shapes in Bevy.
2-
//! The scene includes a patterned texture and a rotation for visualizing the normals and UVs.
1+
//! Here we use shape primitives to generate meshes for 3d objects as well as attaching a runtime-generated patterned texture to each 3d object.
2+
//!
3+
//! "Shape primitives" here are just the mathematical definition of certain shapes, they're not meshes on their own! A sphere with radius `1.0` can be defined with [`Sphere::new(1.0)`][Sphere::new] but all this does is store the radius. So we need to turn these descriptions of shapes into meshes.
4+
//!
5+
//! While a shape is not a mesh, turning it into one in Bevy is easy. In this example we call [`meshes.add(/* Shape here! */)`][Assets<A>::add] on the shape, which works because the [`Assets<A>::add`] method takes anything that can be turned into the asset type it stores. There's an implementation for [`From`] on shape primitives into [`Mesh`], so that will get called internally by [`Assets<A>::add`].
6+
//!
7+
//! [`Extrusion`] lets us turn 2D shape primitives into versions of those shapes that have volume by extruding them. A 1x1 square that gets wrapped in this with an extrusion depth of 2 will give us a rectangular prism of size 1x1x2, but here we're just extruding these 2d shapes by depth 1.
8+
//!
9+
//! The material applied to these shapes is a texture that we generate at run time by looping through a "palette" of RGBA values (stored adjacent to each other in the array) and writing values to positions in another array that represents the buffer for an 8x8 texture. This texture is then registered with the assets system just one time, with that [`Handle<StandardMaterial>`] then applied to all the shapes in this example.
10+
//!
11+
//! The mesh and material are [`Handle<Mesh>`] and [`Handle<StandardMaterial>`] at the moment, neither of which implement `Component` on their own. Handles are put behind "newtypes" to prevent ambiguity, as some entities might want to have handles to meshes (or images, or materials etc.) for different purposes! All we need to do to make them rendering-relevant components is wrap the mesh handle and the material handle in [`Mesh3d`] and [`MeshMaterial3d`] respectively.
312
//!
413
//! You can toggle wireframes with the space bar except on wasm. Wasm does not support
514
//! `POLYGON_MODE_LINE` on the gpu.

0 commit comments

Comments
 (0)