rusteal-codegen 0.4.0

Code generator: UHT JSON to Rust bindings and C++ wrappers for rusteal
Documentation
// Plane ↔ OwnedStruct<FPlane> conversions.
// FPlane inherits from FVector (X, Y, Z) and adds W.

use glam::DVec3;
use rusteal_core::{OwnedStruct, Plane};

use crate::core_ue::{FPlane, FPlaneExt, FVector, FVectorExt};

pub trait OwnedFPlaneExt {
    fn to_plane(&self) -> Plane;
}

/// Reinterpret a FPlane struct ref as a FVector struct ref to access inherited X/Y/Z.
#[inline]
unsafe fn plane_as_vector(plane: &rusteal_core::UStructRef<FPlane>) -> rusteal_core::UStructRef<FVector> {
    unsafe { rusteal_core::UStructRef::<FVector>::from_raw(plane.as_ptr().0 as *mut u8) }
}

impl OwnedFPlaneExt for OwnedStruct<FPlane> {
    fn to_plane(&self) -> Plane {
        let r = self.as_ref();
        let vec_ref = unsafe { plane_as_vector(&r) };
        let normal = DVec3::new(vec_ref.get_x(), vec_ref.get_y(), vec_ref.get_z());
        let d = r.get_w();
        Plane::new(normal, d)
    }
}

impl FPlane {
    pub fn from_plane(p: Plane) -> OwnedStruct<FPlane> {
        let s = OwnedStruct::<FPlane>::new();
        let r = s.as_ref();
        let vec_ref = unsafe { plane_as_vector(&r) };
        vec_ref.set_x(p.normal.x);
        vec_ref.set_y(p.normal.y);
        vec_ref.set_z(p.normal.z);
        r.set_w(p.d);
        s
    }
}