This example is running in WebGL2 and should work in most browsers. You can check the WebGPU examples here.
custom_primitives.rs:
//! This example demonstrates how you can add your own custom primitives to bevy highlighting
//! traits you may want to implement for your primitives to achieve different functionalities.
use ;
use ;
const HEART: Heart = new;
const EXTRUSION: = Extrusion ;
// The transform of the camera in 2D
const TRANSFORM_2D: Transform = Transform ;
// The projection used for the camera in 2D
const PROJECTION_2D: Projection = Orthographic;
// The transform of the camera in 3D
const TRANSFORM_3D: Transform = Transform ;
// The projection used for the camera in 3D
const PROJECTION_3D: Projection = Perspective;
/// State for tracking the currently displayed shape
/// State for tracking the currently displayed shape
/// A marker component for our 2D shapes so we can query them separately from the camera
;
/// A marker component for our 3D shapes so we can query them separately from the camera
;
// Rotate the 2D shapes.
// Draw bounding boxes or circles for the 2D shapes.
// Rotate the 3D shapes.
// Draw the AABBs or bounding spheres for the 3D shapes.
// Switch to the next bounding shape.
// Switch between 2D and 3D cameras.
/// A custom 2D heart primitive. The heart is made up of two circles centered at `Vec2::new(±radius, 0.)` each with the same `radius`.
/// The tip of the heart connects the two circles at a 45° angle from `Vec3::NEG_Y`.
// The `Primitive2d` or `Primitive3d` trait is required by almost all other traits for primitives in bevy.
// Depending on your shape, you should implement either one of them.
// The `Measured2d` and `Measured3d` traits are used to compute the perimeter, the area or the volume of a primitive.
// If you implement `Measured2d` for a 2D primitive, `Measured3d` is automatically implemented for `Extrusion<T>`.
// The `Bounded2d` or `Bounded3d` traits are used to compute the Axis Aligned Bounding Boxes or bounding circles / spheres for primitives.
// You can implement the `BoundedExtrusion` trait to implement `Bounded3d for Extrusion<Heart>`. There is a default implementation for both AABBs and bounding spheres,
// but you may be able to find faster solutions for your specific primitives.
// You can use the `Meshable` trait to create a `MeshBuilder` for the primitive.
// You can include any additional information needed for meshing the primitive in the meshbuilder.
// This trait is needed so that the configuration methods of the builder of the primitive are also available for the builder for the extrusion.
// If you do not want to support these configuration options for extrusions you can just implement them for your 2D mesh builder.
// The `Extrudable` trait can be used to easily implement meshing for extrusions.