euv-core 0.57.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Creates a translated, rotated, and scaled copy of `mesh` assigned `material`.
///
/// # Arguments
///
/// - `&Mesh3D` - Source part mesh.
/// - `Vec3` - Translation offset.
/// - `Quat` - Orientation quaternion.
/// - `Vec3` - Non-uniform scale.
/// - `PbrMaterial` - Assigned surface material.
///
/// # Returns
///
/// - `Mesh3D` - Positioned and shaded part mesh.
#[must_use]
pub(crate) fn place_part(
    mesh: &Mesh3D,
    position: Vec3,
    rotation: Quat,
    scale: Vec3,
    material: PbrMaterial,
) -> Mesh3D {
    let xform: Mat4 = Mat4::from_trs_quat(position, rotation, scale);
    let mut placed: Mesh3D = transform_mesh(mesh, &xform);
    placed.set_material(material);
    placed
}

/// Creates an axis-aligned box part centered at `center` with extents `size` and `material`.
///
/// # Arguments
///
/// - `Vec3` - Box center position.
/// - `Vec3` - Box extents `(width, height, depth)`.
/// - `PbrMaterial` - Surface material.
///
/// # Returns
///
/// - `Mesh3D` - Positioned beveled box part.
#[must_use]
pub(crate) fn placed_box(center: Vec3, size: Vec3, material: PbrMaterial) -> Mesh3D {
    let min_dim: f32 = size.get_x().min(size.get_y()).min(size.get_z()).abs();
    let bevel: f32 = (min_dim * 0.06).min(0.06);
    let mut box_m: Mesh3D = rounded_box(size, bevel, 1);
    box_m.set_material(material);
    let xform: Mat4 = Mat4::from_trs(center, 0.0, Vec3::splat(1.0));
    transform_mesh(&box_m, &xform)
}

/// Creates a vertical cylinder part centered at `center` with `radius`, `height`, and `material`.
///
/// # Arguments
///
/// - `Vec3` - Cylinder center position.
/// - `f32` - Bottom radius.
/// - `f32` - Top radius.
/// - `f32` - Height along Y.
/// - `u32` - Radial segment count.
/// - `PbrMaterial` - Surface material.
///
/// # Returns
///
/// - `Mesh3D` - Positioned cylinder part.
#[must_use]
pub(crate) fn placed_cylinder(
    center: Vec3,
    r_bot: f32,
    r_top: f32,
    height: f32,
    segs: u32,
    material: PbrMaterial,
) -> Mesh3D {
    let mut cyl: Mesh3D = cylinder(r_bot, r_top, height, segs, true);
    cyl.set_material(material);
    let xform: Mat4 = Mat4::from_trs(center, 0.0, Vec3::splat(1.0));
    transform_mesh(&cyl, &xform)
}

/// Creates a regular 2D circular cross-section polygon for spline sweeping.
///
/// # Arguments
///
/// - `f32` - Circle radius.
/// - `usize` - Number of polygon sides (`>= 3`).
///
/// # Returns
///
/// - `Vec<Vec2>` - CCW 2D circular profile vertices.
#[must_use]
pub(crate) fn circle_profile_2d(radius: f32, sides: usize) -> Vec<Vec2> {
    let n: usize = sides.max(3);
    let r: f32 = radius.abs().max(1e-4);
    let mut out: Vec<Vec2> = Vec::with_capacity(n);
    for i in 0..n {
        let ang: f32 = ((i as f32) / (n as f32)) * TAU;
        out.push(Vec2::new(r * ang.cos(), r * ang.sin()));
    }
    out
}