diff --git a/.cargo/config.toml b/.cargo/config.toml index 2ecf2cc528..94420f5835 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [env] -TARGET_DIR={ value = "target" , relative = true } \ No newline at end of file +TARGET_DIR={ value = "target", relative = true } \ No newline at end of file diff --git a/.gitignore b/.gitignore index 397bbabcc2..a253324d9e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,10 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk +.vscode/ + +**global_types.d.tl **/doc **tlconfig.lua -**.log \ No newline at end of file +**.log +**build \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 55701a435a..59ca014622 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -242,15 +242,16 @@ { "type": "lldb", "request": "launch", - "name": "Debug example 'native_types'", + "name": "Debug example 'bevy_api'", "cargo": { "args": [ "build", - "--example=native_types", - "--package=bevy_mod_scripting" + "--example=bevy_api_lua", + "--package=bevy_mod_scripting", + "--features=lua54" ], "filter": { - "name": "native_types", + "name": "bevy_api_lua", "kind": "example" } }, diff --git a/.vscode/settings.json b/.vscode/settings.json index d214711373..845b0a8db1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,9 @@ "rust-analyzer.cargo.features": [ "lua54", "teal", - ] -} \ No newline at end of file + ], + "rust-analyzer.server.extraEnv": { + "RUSTUP_TOOLCHAIN": "stable" + } +} + diff --git a/Cargo.toml b/Cargo.toml index 74ef754168..8f7b29a7b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,13 @@ resolver = "2" members = [ "bevy_mod_scripting", - "bevy_event_priority" + "bevy_event_priority", + "bevy_mod_scripting_derive", + "bevy_api_gen" ] +[profile.dev] +opt-level = 1 + +[profile.dev.package."*"] +opt-level = 3 \ No newline at end of file diff --git a/api_gen_config.toml b/api_gen_config.toml new file mode 100644 index 0000000000..f71480890d --- /dev/null +++ b/api_gen_config.toml @@ -0,0 +1,888 @@ + + +imports = """ +use std::ops::*; +use crate::{lua::bevy::{LuaWorld,LuaTypeRegistration,LuaScriptData}, std::LuaVec, DummyTypeName}; +use crate::{impl_tealr_any_union,ReflectionError,ReflectPathElem,RegisterForeignLuaType,ReflectedValue, api::ValueIndex, APIProvider, LuaDocFragment}; +use std::sync::Mutex; +use crate::{impl_tealr_generic}; +use tealr::{mlu::{mlua,mlua::{prelude::*,MetaMethod}}}; +use bevy::prelude::App; +""" + +other = """ +impl_tealr_generic!(pub(crate) struct T); +impl_tealr_generic!(pub(crate) struct K); +impl_tealr_generic!(pub(crate) struct V); +""" + +primitives = ["usize","isize","f32","f64","u128","u64","u32","u16","u8","i128","i64","i32","i16","i8","String","bool"] + + +[[manual_lua_types]] +name="ReflectedValue" + +[[manual_lua_types]] +name="LuaWorld" +proxy_name="world" +include_global_proxy=true +use_dummy_proxy=true + +[[manual_lua_types]] +name="LuaScriptData" +proxy_name="script" +include_global_proxy=true +use_dummy_proxy=true + +[[manual_lua_types]] +name="LuaEntity" +proxy_name="entity" +include_global_proxy=true +use_dummy_proxy=true +dont_process=true + +[[manual_lua_types]] +name="LuaTypeRegistration" + +[[manual_lua_types]] +name="LuaVec" + + +## BEVY_UI + +[[types]] +type="AlignContent" +source="bevy_ui" + +[[types]] +type="AlignItems" +source="bevy_ui" + +[[types]] +type="AlignSelf" +source="bevy_ui" + +[[types]] +type="Direction" +source="bevy_ui" + +[[types]] +type="FlexDirection" +source="bevy_ui" + +[[types]] +type="FlexWrap" +source="bevy_ui" + +[[types]] +type="FocusPolicy" +source="bevy_ui" + +[[types]] +type="Interaction" +source="bevy_ui" + +[[types]] +type="JustifyContent" +source="bevy_ui" + +[[types]] +type="Overflow" +source="bevy_ui" + +[[types]] +type="PositionType" +source="bevy_ui" + +[[types]] +type="Val" +source="bevy_ui" + +[[types]] +type="CalculatedClip" +source="bevy_ui" + +[[types]] +type="CalculatedSize" +source="bevy_ui" + +[[types]] +type="Node" +source="bevy_ui" + +[[types]] +type="Style" +source="bevy_ui" + +[[types]] +type="UiColor" +source="bevy_ui" + +[[types]] +type="UiImage" +source="bevy_ui" + +[[types]] +type="Button" +source="bevy_ui" + +[[types]] +type="ImageMode" +source="bevy_ui" + +[[types]] +type="Display" +source="bevy_ui" + + +## BEVY_ANIMATION + +[[types]] +type="AnimationPlayer" +source="bevy_animation" + + + +## BEVY_CORE + +[[types]] +type="Name" +source="bevy_core" + + +# ## BEVY_GLTF + +[[types]] +type="GltfExtras" +source="bevy_gltf" + + +## BEVY_HIERARCHY + +[[types]] +type="Children" +source="bevy_hierarchy" + +[[types]] +type="Parent" +source="bevy_hierarchy" + +## BEVY_TEXT + +[[types]] +type="Text2dBounds" +source="bevy_text" + +[[types]] +type="Text2dSize" +source="bevy_text" + +[[types]] +type="Text" +source="bevy_text" + +[[types]] +type="TextAlignment" +source="bevy_text" + +[[types]] +type="TextSection" +source="bevy_text" + +[[types]] +type="TextStyle" +source="bevy_text" + +[[types]] +type="HorizontalAlign" +source="bevy_text" + +[[types]] +type="VerticalAlign" +source="bevy_text" + + + +## BEVY_TIME + +[[types]] +type="Stopwatch" +source="bevy_time" + +[[types]] +type="Timer" +source="bevy_time" + + +## BEVY_UTILS + +# [[types]] +# type="Duration" +# source="bevy_utils" + + + +# ## BEVY_REFLECT + +# [[types]] +# type="DynamicArray" +# source="bevy_reflect" + +# [[types]] +# type="DynamicList" +# source="bevy_reflect" + +# [[types]] +# type="DynamicMap" +# source="bevy_reflect" + +# [[types]] +# type="DynamicStruct" +# source="bevy_reflect" + +# [[types]] +# type="DynamicTuple" +# source="bevy_reflect" + +# [[types]] +# type="DynamicTupleStruct" +# source="bevy_reflect" + + + + + + +## BEVY_ECS +[[types]] +type="Entity" +source="bevy_ecs" + +## BEVY_TRANSFORM + +[[types]] +type="Transform" +source="bevy_transform" + +[[types]] +type="GlobalTransform" +source="bevy_transform" + +## BEVY_PBR + +[[types]] +type="AmbientLight" +source="bevy_pbr" + +[[types]] +type="CubemapVisibleEntities" +source="bevy_pbr" + +[[types]] +type="DirectionalLight" +source="bevy_pbr" + +[[types]] +type="DirectionalLightShadowMap" +source="bevy_pbr" + +[[types]] +type="NotShadowCaster" +source="bevy_pbr" + +[[types]] +type="NotShadowReceiver" +source="bevy_pbr" + +[[types]] +type="PointLight" +source="bevy_pbr" + +[[types]] +type="PointLightShadowMap" +source="bevy_pbr" + + + +[[types]] +type="AlphaMode" +source="bevy_pbr" + +[[types]] +type="Wireframe" +source="bevy_pbr" + +[[types]] +type="WireframeConfig" +source="bevy_pbr" + +## BEVY_CORE_PIPELINE + +[[types]] +type="Camera3dDepthLoadOp" +source="bevy_core_pipeline" + + + +[[types]] +type="ClearColor" +source="bevy_core_pipeline" + +[[types]] +type="ClearColorConfig" +source="bevy_core_pipeline" + +[[types]] +type="Camera2d" +source="bevy_core_pipeline" + +[[types]] +type="Camera3d" +source="bevy_core_pipeline" + +## BEVY_SPRITE + +[[types]] +type="Anchor" +source="bevy_sprite" + +[[types]] +type="Mesh2dHandle" +source="bevy_sprite" + +[[types]] +type="TextureAtlasSprite" +source="bevy_sprite" + + +[[types]] +type="Sprite" +source="bevy_sprite" + +[[types]] +type="Rect" +source="bevy_sprite" + +## BEVY_RENDER + +[[types]] +type="RenderLayers" +source="bevy_render" + +[[types]] +type="Visibility" +source="bevy_render" + +[[types]] +type="VisibleEntities" +source="bevy_render" + +[[types]] +type="ComputedVisibility" +source="bevy_render" + +[[types]] +type="SkinnedMesh" +source="bevy_render" + +[[types]] +type="ScalingMode" +source="bevy_render" + +[[types]] +type="WindowOrigin" +source="bevy_render" + +[[types]] +type="Color" +source="bevy_render" + +[[types]] +type="Aabb" +source="bevy_render" + +[[types]] +type="CubemapFrusta" +source="bevy_render" + +[[types]] +type="Frustum" +source="bevy_render" + +[[types]] +type="Msaa" +source="bevy_render" + + + + +[[types]] +type="Camera" +source="bevy_render" + +[[types]] +type="RenderTarget" +source="bevy_render" + +[[types]] +type="Viewport" +source="bevy_render" + + +[[types]] +type="Projection" +source="bevy_render" +traits=[ + {name="CameraProjection", import_path="bevy::render::camera::CameraProjection"} +] + +[[types]] +type="OrthographicProjection" +source="bevy_render" +traits=[ + {name="CameraProjection", import_path="bevy::render::camera::CameraProjection"} +] + +[[types]] +type="PerspectiveProjection" +source="bevy_render" +traits=[ + {name="CameraProjection", import_path="bevy::render::camera::CameraProjection"} +] + +[[types]] +type="RenderTarget" +source="bevy_render" + +[[types]] +type="DepthCalculation" +source="bevy_render" + +[[types]] +type="CameraRenderGraph" +source="bevy_render" + + +## BEVY_UTILS +# needs a reflect impl +# [[types]] +# type="Uuid" +# source="uuid" + +## BEVY_ASSET + +[[types]] +type="AssetPathId" +source="bevy_asset" + +[[types]] +type="LabelId" +source="bevy_asset" + +[[types]] +type="SourcePathId" +source="bevy_asset" + + +[[types]] +type="HandleId" +source="bevy_asset" + + +## BEVY_MATH +[[types]] +type="Vec2" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::f32::vec2::Vec2" + +[[types]] +type="Vec3" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::f32::vec3::Vec3" + +[[types]] +type="Vec3A" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::f32::sse2::vec3A::Vec3A" + + +[[types]] +type="Vec4" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::f32::sse2::vec4::Vec4" + +[[types]] +type="BVec2" +source="bevy_math" +import_path="glam::f32::sse2::vec2::BVec2" + +[[types]] +type="BVec3" +source="bevy_math" +import_path="glam::f32::sse2::vec3::BVec3" + +[[types]] +type="BVec4" +source="bevy_math" +import_path="glam::f32::sse2::vec4::BVec4" + +[[types]] +type="BVec3A" +source="bevy_math" +import_path="glam::f32::sse2::vec3::BVec3A" + +[[types]] +type="BVec4A" +source="bevy_math" +import_path="glam::f32::sse2::vec4::BVec4A" + +[[types]] +type="DVec2" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f64)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::f64::dvec2::DVec2" + +[[types]] +type="DVec3" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f64)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::f64::dvec3::DVec3" + +[[types]] +type="DVec4" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f64)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::f64::dvec4::DVec4" + +[[types]] +type="IVec2" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,i32)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::i32::ivec2::IVec2" + +[[types]] +type="IVec3" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,i32)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::i32::ivec3::IVec3" + +[[types]] +type="IVec4" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,i32)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::i32::ivec4::IVec4" + +[[types]] +type="UVec2" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,u32)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::u32::uvec2::UVec2" + +[[types]] +type="UVec3" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,u32)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::u32::uvec3::UVec3" + +[[types]] +type="UVec4" +source="bevy_math" +lua_methods=[ + "(MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}", + "mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,u32)| {s.val_mut(|s| Ok(s[idx] = val))?}" +] +import_path="glam::u32::uvec4::UVec4" + +[[types]] +type="Mat3" +source="bevy_math" +lua_methods=[ +""" + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaVec3::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat3".into()}) + } + } + }) + ) + ) + } +""" +] +import_path="glam::f32::mat3::Mat3" + +[[types]] +type="Mat2" +source="bevy_math" +lua_methods=[ +""" + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaVec2::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat2".into()}) + } + } + }) + ) + ) + } +""" +] +import_path="glam::f32::sse2::mat2::Mat2" + + +[[types]] +type="Mat3A" +source="bevy_math" +lua_methods=[ +""" + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaVec3A::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat3A".into()}) + } + } + }) + ) + ) + } +""" +] +import_path="glam::f32::sse2::mat3::Mat3A" + +[[types]] +type="Mat4" +source="bevy_math" +lua_methods=[ +""" + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaVec4::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat4".into()}) + } + } + }) + ) + ) + } +""" +] +import_path="glam::f32::sse2::mat4::Mat4" + + +[[types]] +type="DMat2" +source="bevy_math" +lua_methods=[ +""" + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaDVec2::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat2".into()}) + } + } + }) + ) + ) + } +""" +] +import_path="glam::f64::dmat2::DMat2" + +[[types]] +type="DMat3" +source="bevy_math" +lua_methods=[ +""" + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaDVec3::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat3".into()}) + } + } + }) + ) + ) + } +""" +] +import_path="glam::f64::dmat3::DMat3" + +[[types]] +type="DMat4" +source="bevy_math" +lua_methods=[ +""" + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaDVec4::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat4".into()}) + } + } + }) + ) + ) + } +""" +] +import_path="glam::f64::dmat4::DMat4" + +[[types]] +type="Affine2" +source="bevy_math" +import_path="glam::f32::sse2::mat2::Affine2" + +[[types]] +type="Affine3A" +source="bevy_math" +import_path="glam::f32::sse2::mat3::Affine3A" + +[[types]] +type="DAffine2" +source="bevy_math" +import_path="glam::f64::sse2::mat2::DAffine2" + +[[types]] +type="DAffine3" +source="bevy_math" +import_path="glam::f64::sse2::mat3::DAffine3" + +[[types]] +type="Quat" +source="bevy_math" +import_path="glam::f32::sse2::quat::Quat" + +[[types]] +type="DQuat" +source="bevy_math" +import_path="glam::f64::dquat::DQuat" + +[[types]] +type="EulerRot" +source="bevy_math" +import_path="glam::euler::EulerRot" \ No newline at end of file diff --git a/bevy_api_gen/Cargo.toml b/bevy_api_gen/Cargo.toml new file mode 100644 index 0000000000..7994d9ee4e --- /dev/null +++ b/bevy_api_gen/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "bevy_api_gen" +version = "0.1.0" +authors = ["Maksymilian Mozolewski "] +edition = "2021" +license = "MIT" +description = "Derive macros for bevy_mod_scripting" +repository = "https://github.com/makspll/bevy_scripting" +homepage = "https://github.com/makspll/bevy_scripting" +keywords = ["bevy", "gamedev", "scripting", "lua"] +categories = ["game-development"] +readme = "../readme.md" + +[lib] +name = "bevy_api_gen_lib" +path = "src/lib.rs" + +[[bin]] +name = "bevy_api_gen" +path = "src/main.rs" + + +[dependencies] +rustdoc-types = "0.11.0" +clap = { version = "3.2.6", features = ["derive"] } +serde_json = "1.0.81" +toml = "0.5.9" +serde = { version = "1.0", features = ["derive"] } +serde_derive = "1.0.137" +indexmap = {version= "1.9.1", features= ["serde"]} diff --git a/bevy_api_gen/src/arg_validator.rs b/bevy_api_gen/src/arg_validator.rs new file mode 100644 index 0000000000..949f407cec --- /dev/null +++ b/bevy_api_gen/src/arg_validator.rs @@ -0,0 +1,228 @@ +use rustdoc_types::{GenericArg, GenericArgs, Type}; + +/// A representation of valid argument types +#[derive(Debug)] +pub enum ArgType { + /// The primary identifier of the type + /// + /// Valid types right now follow the following syntax: + /// `(&)? (mut)? ident:ident` + Self_, + Base(String), + Generic { + base: Box, + args: Vec, + }, + Ref { + is_mut: bool, + ref_: Box, + }, +} + +impl fmt::Display for ArgType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ArgType::Base(b) => { + if b == "Self" { + f.write_str("self") + } else { + f.write_str(b) + } + } + ArgType::Ref { is_mut, ref_ } => { + if *is_mut { + f.write_str("&mut ")?; + } else { + f.write_str("&")?; + } + + ref_.fmt(f) + } + ArgType::Self_ => f.write_str("self"), + ArgType::Generic { base, args } => { + base.fmt(f)?; + f.write_str("<")?; + for (a, i) in args.iter().zip(1..) { + a.fmt(f)?; + if i != args.len() { + f.write_str(",")?; + } + } + f.write_str(">") + } + } + } +} + +impl TryFrom for ArgType { + type Error = String; + + fn try_from(value: Type) -> Result { + Self::try_from(&value) + } +} + +impl TryFrom<&Type> for ArgType { + type Error = String; + + fn try_from(value: &Type) -> Result { + match value { + Type::ResolvedPath { name, args, .. } => { + let mut processed_args = Vec::default(); + + for a in args { + if let GenericArgs::AngleBracketed { args, bindings } = a.as_ref() { + for generic in args { + match generic { + GenericArg::Type(type_) => processed_args.push(type_.try_into()?), + _ => { + return Err( + "Only types are allowed as generic arguments".to_owned() + ) + } + } + } + if !bindings.is_empty() { + return Err("Type bindings are not supported".to_owned()); + } + } else { + return Err("Parenthesised generics are not supported".to_owned()); + } + } + let base = Type::Primitive(name.to_string()).try_into()?; + if let base @ ArgType::Base(_) = base { + if !processed_args.is_empty() { + Ok(Self::Generic { + base: Box::new(base), + args: processed_args, + }) + } else { + Ok(base) + } + } else { + Err("Base is invalid".to_owned()) + } + } + Type::Primitive(name) | Type::Generic(name) => { + if name == "Self" { + Ok(Self::Self_) + } else { + Ok(Self::Base(name.split("::").last().unwrap().to_owned())) + } + } + Type::BorrowedRef { mutable, type_, .. } => Ok(Self::Ref { + is_mut: *mutable, + ref_: Box::new(type_.as_ref().try_into()?), + }), + _ => Err("".to_owned()), + } + } +} + +impl ArgType { + /// Produce an arbitrary output given the base identifier of this type or err if this is the base is a self receiver + pub fn map_base(&self, f: F) -> O + where + F: FnOnce(Result<&String, ()>) -> O, + { + match self { + ArgType::Base(b) => f(Ok(b)), + ArgType::Ref { is_mut: _, ref_ } => ref_.map_base(f), + ArgType::Self_ => f(Err(())), + ArgType::Generic { base, .. } => base.map_base(f), + } + } + + /// Produce an arbitrary output given the base identifier of this type, and optionally modify it + pub fn map_base_mut(&mut self, f: F) -> O + where + F: FnOnce(Result<&mut String, ()>) -> O, + { + match self { + ArgType::Base(b) => f(Ok(b)), + ArgType::Ref { is_mut: _, ref_ } => ref_.map_base_mut(f), + ArgType::Self_ => f(Err(())), + ArgType::Generic { base, .. } => base.map_base_mut(f), + } + } + + pub fn is_self(&self) -> bool { + self.map_base(|b| b.is_err()) + } + + /// Retrieves the base ident if this type is resolved otherwise returns None (i.e. in the case of a self receiver) + pub fn base_ident(&self) -> Option<&str> { + match self { + ArgType::Base(b) => Some(b), + ArgType::Ref { is_mut: _, ref_ } => ref_.base_ident(), + ArgType::Self_ => None, + ArgType::Generic { base, .. } => base.base_ident(), + } + } +} + +#[derive(PartialEq, Eq)] +pub enum ArgWrapperType { + Raw, + Wrapped, + /// in case of `self` argument + None, +} + +impl ArgWrapperType { + pub fn with_config(self_type: &str, type_: &ArgType, config: &Config) -> Option { + let base_ident = type_.base_ident().unwrap_or(self_type); + type_ + .is_self() + .then(|| ArgWrapperType::None) + .or_else(|| { + config + .primitives + .contains(base_ident) + .then_some(ArgWrapperType::Raw) + }) + .or_else(|| { + config + .types + .contains_key(base_ident) + .then_some(ArgWrapperType::Wrapped) + }) + } +} + +impl fmt::Display for ArgWrapperType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ArgWrapperType::Raw => f.write_str("Raw"), + ArgWrapperType::Wrapped => f.write_str("Wrapped"), + ArgWrapperType::None => f.write_str("None"), + } + } +} + +pub struct Arg { + pub type_: ArgType, + pub wrapper: ArgWrapperType, +} + +impl Arg { + pub fn new(type_: ArgType, wrapper: ArgWrapperType) -> Self { + Self { type_, wrapper } + } +} + +use std::fmt; + +use crate::Config; +impl fmt::Display for Arg { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let inner = self.type_.to_string(); + + match self.wrapper { + ArgWrapperType::Raw | ArgWrapperType::Wrapped => { + write!(f, "{}({inner})", self.wrapper) + } + ArgWrapperType::None => f.write_str(&inner), + } + } +} diff --git a/bevy_api_gen/src/config.rs b/bevy_api_gen/src/config.rs new file mode 100644 index 0000000000..eb55ebb6d2 --- /dev/null +++ b/bevy_api_gen/src/config.rs @@ -0,0 +1,125 @@ +use std::collections::HashSet; + +use clap::Parser; +use indexmap::IndexMap; +use rustdoc_types::{Crate, Item, ItemEnum, Visibility}; +use serde::Deserialize; + +#[derive(Parser, Debug)] +#[clap(author, version, about, long_about = None)] +pub struct Args { + /// Paths to json files generated by `rustdoc -p --output-format json` + #[clap(short, long, value_parser)] + pub json: Vec, + + /// The path to toml config file which contains the types to be wrapped and overrides + #[clap(short, long, value_parser)] + pub config: String, + + /// if true the excluded methods will show up as commented out code with reasons for exclusion + #[clap(long)] + pub print_errors: bool, +} + +#[derive(Deserialize, Debug)] +pub struct Config { + #[serde(skip_deserializing, default)] + pub types: IndexMap, + + #[serde(rename = "types")] + pub types_: Vec, + + pub imports: String, + pub other: String, + + /// Describes the set of non generic things which are representible + /// as simple lua types and don't need UserData proxies + pub primitives: HashSet, + + pub manual_lua_types: Vec, +} + +#[derive(Deserialize, Debug)] +pub struct ManualLuaType { + pub name: String, + + /// whether or not to exclude this type from the type walker list + #[serde(default)] + pub dont_process: bool, + + /// the name exposed to scripts as global + #[serde(default)] + pub proxy_name: String, + + /// whether or not to include global proxy + #[serde(default)] + pub include_global_proxy: bool, + + /// whether or not to use a dummy instance (DummyTypeName) + #[serde(default)] + pub use_dummy_proxy: bool, +} + +#[derive(Deserialize, Debug, Hash, PartialEq, Eq)] +pub struct Newtype { + #[serde(rename = "type")] + pub type_: String, + + /// Override type-level docstring + pub doc: Option, + + #[serde(default)] + pub source: Source, + + #[serde(default)] + pub lua_methods: Vec, + + #[serde(default)] + pub derive_flags: Vec, + + #[serde(default)] + pub import_path: String, + + #[serde(default)] + pub traits: Vec, +} + +#[derive(Deserialize, Debug, PartialEq, Eq, Hash, Default)] +pub struct TraitMethods { + pub name: String, + pub import_path: String, +} + +#[derive(Deserialize, Debug, PartialEq, Eq, Hash)] +pub struct Source(pub String); + +impl Default for Source { + fn default() -> Self { + Self("bevy".to_string()) + } +} + +impl Newtype { + /// Returns true if this Type: + /// - describes the given item element + /// - if the element is fully described in the source crate + /// - if the element is a struct or enum + /// - if the element has no generics + pub fn matches_result(&self, item: &Item, source: &Crate) -> bool { + match &item.inner { + ItemEnum::Struct(s) => { + if !s.generics.params.is_empty() { + return false; + } + } + ItemEnum::Enum(_) => {} + _ => return false, + }; + + if source.external_crates.contains_key(&item.crate_id) { + return false; + }; + + matches!(item.visibility, Visibility::Public) + } +} diff --git a/bevy_api_gen/src/lib.rs b/bevy_api_gen/src/lib.rs new file mode 100644 index 0000000000..644a5e7829 --- /dev/null +++ b/bevy_api_gen/src/lib.rs @@ -0,0 +1,28 @@ +use rustdoc_types::Type; + +pub mod arg_validator; +pub mod config; +pub mod wrapper; +pub mod writer; + +pub use {arg_validator::*, config::*, wrapper::*, writer::*}; + +/// Currently only used for stringifying simple trait names +pub fn stringify_type(type_: &Type) -> Option { + match type_ { + Type::ResolvedPath { + name, + id: _, + args: _, + param_names: _, + } => Some(name.to_owned()), + Type::Generic(s) | Type::Primitive(s) => Some(s.to_owned()), + Type::QualifiedPath { + name, + args: _, + self_type: _, + trait_: _, + } => Some(name.to_owned()), + _ => None, + } +} diff --git a/bevy_api_gen/src/main.rs b/bevy_api_gen/src/main.rs new file mode 100644 index 0000000000..84d929df8d --- /dev/null +++ b/bevy_api_gen/src/main.rs @@ -0,0 +1,343 @@ +use bevy_api_gen_lib::{stringify_type, Args, Config, PrettyWriter, WrappedItem, WRAPPER_PREFIX}; + +use clap::Parser; +use indexmap::{IndexMap, IndexSet}; +use rustdoc_types::{Crate, Impl, Item, ItemEnum}; +use serde_json::from_reader; +use std::{ + collections::HashSet, + fs::{read_to_string, File}, + io::{self, BufReader}, +}; + +pub(crate) fn write_use_items_from_path( + module_name: &str, + path_components: &[String], + writer: &mut PrettyWriter, +) { + // generate imports for each item + writer.write_no_newline("use "); + + if module_name.starts_with("bevy") && module_name.len() > 5 { + writer.write_inline("bevy::"); + writer.write_inline(&module_name[5..]); + } else { + writer.write_inline(module_name); + } + + for item in path_components { + writer.write_inline("::"); + writer.write_inline(item); + } + writer.write_inline(";"); + writer.newline(); +} + +pub(crate) fn generate_macros( + crates: &[Crate], + config: Config, + args: &Args, +) -> Result { + // the items we want to generate macro instantiations for + let mut unmatched_types: HashSet<&String> = config.types.iter().map(|(k, _v)| k).collect(); + + let mut wrapped_items: Vec<_> = crates + .iter() + .flat_map(|source| { + source + .index + .iter() + .filter(|(_, item)| { + item.name + .as_ref() + .and_then(|k| config.types.get(k)) + .map(|k| k.matches_result(item, source)) + .unwrap_or(false) + }) + .map(|(id, item)| { + // extract all available associated constants,methods etc available to this item + let mut self_impl: Option<&Impl> = None; + let mut impl_items: IndexMap<&str, Vec<(&Impl, &Item)>> = Default::default(); + let mut implemented_traits: IndexSet = Default::default(); + + let impls = match &item.inner { + ItemEnum::Struct(s) => &s.impls, + ItemEnum::Enum(e) => &e.impls, + _ => panic!("Only structs or enums are allowed!"), + }; + + impls.iter().for_each(|id| { + if let ItemEnum::Impl(i) = &source.index.get(id).unwrap().inner { + match &i.trait_ { + Some(t) => { + stringify_type(t).map(|str_| implemented_traits.insert(str_)); + } + None => self_impl = Some(i), + } + i.items.iter().for_each(|id| { + let it = source.index.get(id).unwrap(); + + impl_items + .entry(it.name.as_ref().unwrap().as_str()) + .or_default() + .push((i, it)); + }) + } else { + panic!("Expected impl items here!") + } + }); + + let config = config.types.get(item.name.as_ref().unwrap()).unwrap(); + + let path_components = &source.paths.get(id).unwrap().path; + + let wrapper_name = format!("{WRAPPER_PREFIX}{}", item.name.as_ref().unwrap()); + let wrapped_type = item.name.as_ref().unwrap(); + WrappedItem { + wrapper_name, + wrapped_type, + path_components, + source, + config, + item, + self_impl, + impl_items, + crates, + has_global_methods: false, + implemented_traits, + } + }) + }) + .collect(); + + wrapped_items.iter().for_each(|v| { + unmatched_types.remove(&v.wrapped_type); + }); + + if !unmatched_types.is_empty() { + panic!("Some types were not found in the given crates: {unmatched_types:#?}") + } + + let mut writer = PrettyWriter::new(); + + // we want to preserve the original ordering from the config file + wrapped_items.sort_by_cached_key(|f| config.types.get_index_of(f.wrapped_type).unwrap()); + + writer.write_line("#[allow(clippy::all)]"); + writer.write_line("// This file is generated by `bevy_mod_scripting_derive/main.rs` change the template not this file"); + writer.write_line("extern crate self as bevy_mod_scripting;"); + writer.write_line("use bevy_mod_scripting_derive::impl_script_newtype;"); + + // user defined + config.imports.lines().for_each(|import| { + writer.write_line(import); + }); + // automatic + + wrapped_items.iter().for_each(|item| { + write_use_items_from_path( + &item.config.source.0, + &item.path_components[1..], + &mut writer, + ); + }); + + let mut imported = HashSet::::default(); + + wrapped_items.iter().for_each(|item| { + item.config.traits.iter().for_each(|trait_methods| { + if !imported.contains(&trait_methods.name) { + writer.write_no_newline("use "); + writer.write_inline(&trait_methods.import_path); + writer.write_inline(";"); + writer.newline(); + imported.insert(trait_methods.name.to_owned()); + } + }) + }); + + // make macro calls for each wrapped item + wrapped_items.iter_mut().for_each(|v| { + // macro invocation + writer.write_no_newline("impl_script_newtype!"); + writer.open_brace(); + + v.write_type_docstring(&mut writer, args); + writer.write_indentation(); + v.write_inline_full_path(&mut writer, args); + writer.write_inline(" : "); + writer.newline(); + + v.write_derive_flags_body(&config, &mut writer, args); + + writer.write_line("impl"); + writer.open_brace(); + v.write_impl_block_body(&mut writer, args); + writer.close_brace(); + + writer.close_brace(); + }); + + // write other code + for line in config.other.lines() { + writer.write_line(line); + } + + // now create the BevyAPIProvider + // first the globals + writer.write_line("#[derive(Default)]"); + writer.write_line("pub(crate) struct BevyAPIGlobals;"); + writer.write_no_newline("impl tealr::mlu::ExportInstances for BevyAPIGlobals"); + writer.open_brace(); + writer.write_line("fn add_instances<'lua, T: tealr::mlu::InstanceCollector<'lua>>(self, instances: &mut T) -> LuaResult<()>"); + writer.open_brace(); + for (global_name, type_, dummy_proxy) in wrapped_items + .iter() + .filter_map(|i| { + i.has_global_methods.then_some(( + i.wrapped_type.as_str(), + i.wrapper_name.as_str(), + false, + )) + }) + .chain(config.manual_lua_types.iter().filter_map(|i| { + i.include_global_proxy.then_some(( + i.proxy_name.as_str(), + i.name.as_str(), + i.use_dummy_proxy, + )) + })) + { + writer.write_no_newline("instances.add_instance("); + // type name + writer.write_inline("\""); + writer.write_inline(global_name); + writer.write_inline("\""); + writer.write_inline(".into()"); + // corresponding proxy + if dummy_proxy { + writer.write_inline(", DummyTypeName::<"); + writer.write_inline(type_); + writer.write_inline(">::new"); + writer.write_inline(")?;"); + writer.newline(); + } else { + writer.write_inline(", tealr::mlu::UserDataProxy::<"); + writer.write_inline(type_); + writer.write_inline(">::new)?;"); + writer.newline(); + } + } + + writer.write_line("Ok(())"); + writer.close_brace(); + writer.close_brace(); + + // then the actual provider + writer.write_line("pub struct LuaBevyAPIProvider;"); + + // begin impl { + writer.write_no_newline("impl APIProvider for LuaBevyAPIProvider"); + writer.open_brace(); + + writer.write_line("type APITarget = Mutex;"); + writer.write_line("type ScriptContext = Mutex;"); + writer.write_line("type DocTarget = LuaDocFragment;"); + + // attach_api { + writer.write_no_newline( + "fn attach_api(&mut self, ctx: &mut Self::APITarget) -> Result<(), crate::ScriptError>", + ); + writer.open_brace(); + writer.write_line("let ctx = ctx.get_mut().expect(\"Unable to acquire lock on Lua context\");"); + writer.write_line("Ok(tealr::mlu::set_global_env(BevyAPIGlobals,&ctx)?)"); + writer.close_brace(); + // } attach_api + + // get_doc_fragment + writer.write_no_newline("fn get_doc_fragment(&self) -> Option"); + writer.open_brace(); + writer.write_no_newline("Some(LuaDocFragment::new(|tw|"); + writer.open_brace(); + writer.write_line("tw"); + writer.write_line(".document_global_instance::().expect(\"Something went wrong documenting globals\")"); + + // include external types not generated by this file as well + for (type_, include_proxy) in + wrapped_items + .iter() + .map(|i| (i.wrapper_name.as_str(), i.has_global_methods)) + .chain(config.manual_lua_types.iter().filter_map(|i| { + (!i.dont_process).then_some((i.name.as_str(), i.include_global_proxy)) + })) + { + writer.write_no_newline(".process_type::<"); + writer.write_inline(type_); + writer.write_inline(">()"); + writer.newline(); + + if include_proxy { + writer.write_no_newline(".process_type::>()"); + writer.newline(); + } + } + + writer.close_brace(); + writer.write_line("))"); + + writer.close_brace(); + // } get_doc_fragment + + // register_with_app { + writer.write_no_newline("fn register_with_app(&self, app: &mut App)"); + writer.open_brace(); + for item in wrapped_items + .iter() + .map(|i| i.wrapped_type) + .chain(config.primitives.iter()) + { + writer.write_no_newline("app.register_foreign_lua_type::<"); + writer.write_inline(item); + writer.write_inline(">();"); + writer.newline(); + } + writer.close_brace(); + // } regiser_with_app + + writer.close_brace(); + // } end impl + + Ok(writer.finish()) +} + +pub fn main() -> Result<(), io::Error> { + let args = Args::parse(); + + let crates: Vec<_> = args + .json + .iter() + .map(|json| { + let f = File::open(&json).unwrap_or_else(|_| panic!("Could not open {}", &json)); + let rdr = BufReader::new(f); + from_reader(rdr) + }) + .collect::, _>>()?; + + let f = read_to_string(&args.config)?; + let mut config: Config = toml::from_str(&f)?; + + config.types_.reverse(); + + while !config.types_.is_empty() { + let t = config.types_.remove(config.types_.len() - 1); + config.types.insert(t.type_.to_string(), t); + } + + let out = generate_macros(&crates, config, &args)?; + + println!("{}", out); + + Ok(()) +} diff --git a/bevy_api_gen/src/wrapper.rs b/bevy_api_gen/src/wrapper.rs new file mode 100644 index 0000000000..23c3d25a73 --- /dev/null +++ b/bevy_api_gen/src/wrapper.rs @@ -0,0 +1,472 @@ +use std::collections::HashSet; + +use indexmap::{IndexMap, IndexSet}; +use rustdoc_types::{Crate, Id, Impl, Item, ItemEnum}; + +use crate::{stringify_type, Arg, ArgType, ArgWrapperType, Args, Config, Newtype, PrettyWriter}; + +pub static WRAPPER_PREFIX: &str = "Lua"; + +#[derive(Debug)] +pub struct WrappedItem<'a> { + pub wrapper_name: String, + pub wrapped_type: &'a String, + pub path_components: &'a [String], + pub source: &'a Crate, + pub config: &'a Newtype, + pub item: &'a Item, + /// The items coming from all trait implementations + pub impl_items: IndexMap<&'a str, Vec<(&'a Impl, &'a Item)>>, + pub implemented_traits: IndexSet, + pub self_impl: Option<&'a Impl>, + pub crates: &'a [Crate], + /// If this type has some things which are "static" this is set to true later + pub has_global_methods: bool, +} + +impl WrappedItem<'_> { + /// Writes full type path inline corresponding to `Reflect::type_name` of each type + /// + /// As: + /// ```rust,ignore + /// + /// this + /// | + /// |..........| + /// my_type_path::Type : Value : + /// UnaryOps( ... + /// ``` + pub fn write_inline_full_path(&self, writer: &mut PrettyWriter, _: &Args) { + if self.config.import_path.is_empty() { + writer.write_inline(&self.path_components.join("::")); + } else { + writer.write_inline(&self.config.import_path); + } + } + + /// Writes the docstring for the type over multiple lines + /// + /// As: + /// ```rust,ignore + /// + /// /// generated docstring + /// /// here + /// my_macro_key : Value : + /// UnaryOps( + /// ... + /// ) + /// + + /// ... + /// ``` + pub fn write_type_docstring(&self, writer: &mut PrettyWriter, _: &Args) { + let strings = if let Some(d) = &self.config.doc { + d.to_string() + } else { + self.item + .docs + .as_ref() + .cloned() + .unwrap_or_else(|| "".to_string()) + }; + writer.set_prefix("///".into()); + strings.lines().for_each(|l| { + writer.write_line(l); + }); + writer.clear_prefix(); + } + + /// Writes the docstring for the given auto method over multiple lines + /// + /// As: + /// ```rust,ignore + /// + /// + /// my_macro_key : Value : + /// Methods( + /// /// generated docstring + /// /// here + /// my_method(usize) -> u32 + /// ) + /// + + /// ... + /// ``` + pub fn write_method_docstring(&self, id: &Id, writer: &mut PrettyWriter, _: &Args) { + writer.set_prefix("///".into()); + self.source + .index + .get(id) + .unwrap() + .docs + .as_ref() + .cloned() + .unwrap_or_else(|| "".to_owned()) + .lines() + .for_each(|l| { + writer.write_line(l); + }); + writer.clear_prefix(); + } + + /// Writes the contents of the impl block for this wrapper + /// + /// As: + /// + /// ```rust,ignore + /// impl { + /// ... // this! + /// } + /// ``` + pub fn write_impl_block_body(&self, writer: &mut PrettyWriter, _: &Args) { + self.config.lua_methods.iter().for_each(|v| { + writer.write_postfixed_line(v, ";"); + }) + } + + /// Generates all derive flags for the type, + /// + /// Returns additional imports necessary for the generated methods + /// + /// ```rust,ignore + /// my_type::Type : Value: + /// ... // flags go here + /// ``` + pub fn write_derive_flags_body( + &mut self, + config: &Config, + writer: &mut PrettyWriter, + args: &Args, + ) { + if self.implemented_traits.contains("Clone") { + // this flag requires cloning + writer.write_line("Clone +"); + } + + if self.implemented_traits.contains("Debug") { + // this flag requires cloning + writer.write_line("Debug +"); + } + + let mut used_method_identifiers: HashSet<&str> = HashSet::default(); + + writer.write_line("Methods"); + writer.open_paren(); + let mut has_global_methods = false; + self.impl_items + .iter() + .flat_map(|(_, items)| items.iter()) + .for_each(|(impl_, v)| { + // only select trait methods are allowed + if let Some(trait_) = &impl_.trait_ { + if self + .config + .traits + .iter() + .any(|f| { + stringify_type(trait_) + .and_then(|s| (s == f.name).then_some(())) + .is_some() + }) + { + // keep going + } else { + return; + } + }; + + let (decl, generics) = match &v.inner { + ItemEnum::Function(f) => (&f.decl, &f.generics), + ItemEnum::Method(m) => (&m.decl, &m.generics), + _ => return, + }; + + let mut errors = Vec::default(); + + let mut inner_writer = PrettyWriter::new(); + + self.write_method_docstring(&v.id, &mut inner_writer, args); + + inner_writer.write_inline(v.name.as_ref().unwrap()); + inner_writer.write_inline("("); + let mut is_global_method = true; + decl.inputs + .iter() + .enumerate() + .for_each(|(i, (declaration_name, tp))| { + let arg_type: Result = tp.try_into(); + + if let Ok(arg_type) = arg_type { + // if the underlying ident is self, we shouldn't wrap it when printing it + // if type is unknown no wrapper exists + let wrapper_type: Option = ArgWrapperType::with_config(self.wrapped_type, &arg_type, config); + + match wrapper_type { + Some(w) => { + inner_writer.write_inline(&Arg::new(arg_type, w).to_string()) + } + None => { + inner_writer.write_inline(&format!("")); + errors.push(format!("Unsupported argument {}, not a wrapped type or primitive", arg_type)); + return; + } + }; + + if declaration_name != "self" && i + 1 != decl.inputs.len() { + inner_writer.write_inline(","); + } else if declaration_name == "self" { + is_global_method = false; + // macro needs to recognize the self receiver + inner_writer.write_inline(":"); + } + } else { + errors.push(format!("Unsupported argument, Not a simple type: {}.", arg_type.unwrap_err())) + }; + }); + + if is_global_method { + has_global_methods = true; + } + + inner_writer.write_inline(")"); + + if let Some(tp) = &decl.output{ + let arg_type: Result = tp.try_into(); + if let Ok(arg_type) = arg_type { + if let ArgType::Ref { .. } = arg_type { + errors.push("references are not supported as return types".to_owned()); + return; + } + + // if the underlying ident is self, we shouldn't wrap it when printing it + // if type is unknown, no wrapper type exists + let wrapper_type: Option = ArgWrapperType::with_config(self.wrapped_type, &arg_type, config); + + match wrapper_type { + Some(w) => { + inner_writer.write_inline(" -> "); + inner_writer.write_inline(&Arg::new(arg_type, w).to_string()); + } + None => { + errors.push(format!("Unsupported argument, not a wrapped type or primitive {arg_type}")); + inner_writer.write_inline(&format!("")); + } + } + } else { + errors.push(format!("Unsupported argument, not a simple type: {}", arg_type.unwrap_err())) + } + }; + + if !generics.params.is_empty() { + errors.push("Generics on the method".to_owned()); + } + + if !errors.is_empty() { + if args.print_errors { + writer.set_prefix("// ".into()); + writer.write_line(&format!("Exclusion reason: {}", errors.join(","))); + writer.extend(inner_writer); + writer.clear_prefix(); + writer.newline(); + } + } else { + used_method_identifiers.insert(v.name.as_deref().unwrap()); + inner_writer.write_inline(","); + writer.extend(inner_writer); + writer.newline(); + } + }); + + self.has_global_methods = has_global_methods; + writer.close_paren(); + + writer.write_line("+ Fields"); + writer.open_paren(); + + if let ItemEnum::Struct(struct_) = &self.item.inner { + struct_ + .fields + .iter() + .map(|field_| self.source.index.get(field_).unwrap()) + .filter_map(|field_| match &field_.inner { + ItemEnum::StructField(type_) => { + Some((field_.name.as_ref().unwrap(), type_, field_)) + } + _ => None, + }) + .filter_map(|(name, type_, field_)| { + let arg_type: ArgType = type_.try_into().ok()?; + let base_ident = arg_type + .base_ident() // resolve self + .unwrap_or(self.wrapped_type.as_str()); + + // if the underlying ident is self, we shouldn't wrap it when printing it + let wrapper: ArgWrapperType = arg_type + .is_self() + .then(|| ArgWrapperType::None) + .or_else(|| { + config + .primitives + .contains(base_ident) + .then_some(ArgWrapperType::Raw) + }) + .or_else(|| { + config + .types + .contains_key(base_ident) + .then_some(ArgWrapperType::Wrapped) + }) + // we allow this since we later resolve unknown types to be resolved as ReflectedValues + .unwrap_or(ArgWrapperType::None); + + let arg = Arg::new(arg_type, wrapper); + let mut reflectable_type = arg.to_string(); + + // if we do not have an appropriate wrapper and this is not a primitive or it's not public + // we need to go back to the reflection API + if arg.wrapper == ArgWrapperType::None { + if field_.attrs.iter().any(|attr| attr == "#[reflect(ignore)]") { + return None; + } + + reflectable_type = "Raw(ReflectedValue)".to_owned(); + } + + if let Some(docs) = &field_.docs { + writer.set_prefix("/// ".into()); + docs.lines().for_each(|line| { + writer.write_line(line); + }); + writer.clear_prefix(); + }; + + // add underscore if a method with same name exists + used_method_identifiers + .contains(name.as_str()) + .then(|| writer.write_line(&format!("#[rename(\"_{name}\")]"))); + writer.write_no_newline(name); + writer.write_inline(": "); + writer.write_inline(&reflectable_type); + writer.write_inline(","); + writer.newline(); + + Some(()) + }) + .for_each(drop); + }; + writer.close_paren(); + + static BINARY_OPS: [(&str, &str); 5] = [ + ("add", "Add"), + ("sub", "Sub"), + ("div", "Div"), + ("mul", "Mul"), + ("rem", "Rem"), + ]; + writer.write_line("+ BinOps"); + writer.open_paren(); + BINARY_OPS.into_iter().for_each(|(op, rep)| { + if let Some(items) = self.impl_items.get(op) { + items + .iter() + .filter_map(|(impl_, item)| Some((impl_, item, (&impl_.for_).try_into().ok()?))) + .filter(|(_, _, self_type): &(&&Impl, &&Item, ArgType)| { + let base_ident = + self_type.base_ident().unwrap_or(self.wrapped_type.as_str()); + let is_self_type_the_wrapper = (base_ident == self.wrapped_type) + && config.types.contains_key(base_ident); + let is_primitive = config.primitives.contains(base_ident); + is_self_type_the_wrapper || is_primitive + }) + .for_each(|(impl_, item, _self_type)| { + let _ = match &item.inner { + ItemEnum::Method(m) => { + m.decl + .inputs + .iter() + .map(|(_, t)| { + // check arg is valid + let arg_type: ArgType = t.try_into()?; + + // if the underlying ident is self, we shouldn't wrap it when printing it + let wrapper_type = ArgWrapperType::with_config( + self.wrapped_type, + &arg_type, + config, + ) + .unwrap(); + + Ok(Arg::new(arg_type, wrapper_type).to_string()) + }) + .collect::, _>>() + .map(|v| v.join(&format!(" {} ", rep))) + .and_then(|expr| { + // then provide return type + // for these traits that's on associated types within the impl + let out_type = impl_ + .items + .iter() + .find_map(|v| { + let item = self.source.index.get(v).unwrap(); + if let ItemEnum::AssocType { default, .. } = + &item.inner + { + if let Some("Output") = item.name.as_deref() { + return Some(default.as_ref().unwrap()); + } + } + None + }) + .ok_or_else(|| expr.clone())?; + + let arg_type: ArgType = out_type.try_into()?; + // if the underlying ident is self, we shouldn't wrap it when printing it + let wrapper_type: ArgWrapperType = + ArgWrapperType::with_config( + self.wrapped_type, + &arg_type, + config, + ) + .unwrap(); + + if wrapper_type == ArgWrapperType::None { + return Err(arg_type.to_string()); + } + + let return_string = + Arg::new(arg_type, wrapper_type).to_string(); + + writer.write_no_newline(&expr); + writer.write_inline(" -> "); + writer.write_inline(&return_string); + writer.write_inline(","); + writer.newline(); + Ok(()) + }) + } + _ => panic!("Expected method"), + }; + }) + } + }); + writer.close_paren(); + + static UNARY_OPS: [(&str, &str); 1] = [("neg", "Neg")]; + + writer.write_line("+ UnaryOps"); + writer.open_paren(); + UNARY_OPS.into_iter().for_each(|(op, rep)| { + if let Some(items) = self.impl_items.get(op) { + items.iter().for_each(|(_, _)| { + writer.write_line(&format!("{rep} self -> self")); + }); + } + }); + writer.close_paren(); + + self.config.derive_flags.iter().for_each(|flag| { + writer.write_inline("+ "); + flag.lines().for_each(|line| { + writer.write_line(line); + }); + }); + } +} diff --git a/bevy_api_gen/src/writer.rs b/bevy_api_gen/src/writer.rs new file mode 100644 index 0000000000..2d7305efcc --- /dev/null +++ b/bevy_api_gen/src/writer.rs @@ -0,0 +1,232 @@ +use std::borrow::Cow; + +#[derive(Default)] +struct WriterState { + indentation_level: usize, + open_parenthesis: usize, + open_braces: usize, + open_brackets: usize, + prefix: Option>, +} + +/// Used to generate pretty indented code +#[derive(Default)] +pub struct PrettyWriter { + state: WriterState, + output: String, +} + +impl PrettyWriter { + pub fn new() -> Self { + Self::default() + } + + /// Combines this writer with another one. + /// + /// open brackets are inherited, the current string is indented with additional indentation + /// to match this writers indentation level. + /// If the indentation level is non-zero, it's added to this writer's. + /// Any prefixes are ignored. + pub fn extend(&mut self, other: PrettyWriter) { + for line in other.output.lines() { + self.write_line(line); + } + self.state.open_parenthesis += other.state.open_parenthesis; + self.state.open_braces += other.state.open_braces; + self.state.open_brackets += other.state.open_brackets; + self.state.indentation_level += other.state.indentation_level; + } + + /// Inserts a newline character inline + pub fn newline(&mut self) -> &mut Self { + self.output.push('\n'); + self + } + + /// Writes indentation and prefix without a newline + fn write_indented_prefix(&mut self) { + (0..self.state.indentation_level) + .into_iter() + .for_each(|_| self.output.push('\t')); + + if let Some(prefix) = &self.state.prefix { + self.output.push_str(prefix); + } + } + + /// Writes a line at the current indentation level and append a newline at the end + pub fn write_line(&mut self, line: &str) -> &mut Self { + self.write_indented_prefix(); + self.output.push_str(line); + self.output.push('\n'); + self + } + + /// Writes without adding newline but keeps the indentation + pub fn write_no_newline(&mut self, line: &str) -> &mut Self { + self.write_indented_prefix(); + self.output.push_str(line); + self + } + + /// Writes a postfixed (after main text, before newline) line at the current indentation level and append a newline at the end + pub fn write_postfixed_line(&mut self, line: &str, postfix: &str) -> &mut Self { + self.write_indented_prefix(); + self.output.push_str(line); + self.output.push_str(postfix); + self.output.push('\n'); + self + } + + /// Writes a line without adding indentation or a newline + pub fn write_inline(&mut self, line: &str) -> &mut Self { + self.output.push_str(line); + self + } + + /// Writes indentation only, useful if you need to follow this by `write_inline` + pub fn write_indentation(&mut self) -> &mut Self { + self.write_indented_prefix(); + self + } + + /// Sets a prefix to be appended before every line written + pub fn set_prefix(&mut self, prefix: Cow<'static, str>) -> &mut Self { + self.state.prefix = Some(prefix); + self + } + + /// Clears the set prefix + pub fn clear_prefix(&mut self) -> &mut Self { + self.state.prefix = None; + self + } + + /// Increases intendation level permamently, does not write to the output yet + pub fn indent(&mut self) -> &mut Self { + self.state.indentation_level += 1; + self + } + + /// Decrases intendation level permamently, does not write to the output yet + pub fn dedent(&mut self) -> &mut Self { + self.state.indentation_level = self + .state + .indentation_level + .checked_sub(1) + .expect("No indentation to dedent"); + self + } + + /// Opens parenthesised section + pub fn open_paren(&mut self) -> &mut Self { + self.write_line("("); + self.indent(); + self.state.open_parenthesis += 1; + self + } + + /// Closes parenthesised section + pub fn close_paren(&mut self) -> &mut Self { + self.dedent(); + self.write_line(")"); + self.state.open_parenthesis = self + .state + .open_parenthesis + .checked_sub(1) + .expect("No parenthesis to close"); + self + } + + /// Opens braceed section + pub fn open_brace(&mut self) -> &mut Self { + self.write_line("{"); + self.indent(); + self.state.open_braces += 1; + self + } + + /// Closes braced section + pub fn close_brace(&mut self) -> &mut Self { + self.dedent(); + self.write_line("}"); + self.state.open_braces = self + .state + .open_braces + .checked_sub(1) + .expect("No brace to close"); + self + } + + /// Opens bracketed section + pub fn open_bracket(&mut self) -> &mut Self { + self.write_line("["); + self.indent(); + self.state.open_brackets += 1; + self + } + + /// Closes bracketed section + pub fn close_bracket(&mut self) -> &mut Self { + self.dedent(); + self.write_line("]"); + self.state.open_brackets = self + .state + .open_brackets + .checked_sub(1) + .expect("No bracket to close"); + self + } + + /// Consumes self and produces the output string, panics if there is unclosed parenthesis/brackets etc. + pub fn finish(self) -> String { + if self.state.open_braces > 0 { + panic!("{} unclosed braces", self.state.open_braces) + } else if self.state.open_brackets > 0 { + panic!("{} unclosed brackets", self.state.open_brackets) + } else if self.state.open_parenthesis > 0 { + panic!("{} unclosed parenthesis", self.state.open_parenthesis) + }; + + self.output + } +} + +#[cfg(test)] +mod test { + use crate::PrettyWriter; + + #[test] + fn test_indentation() { + let mut writer = PrettyWriter::new(); + + writer + .write_line("a") + .indent() + .write_line("a") + .indent() + .write_line("a") + .dedent() + .write_line("a") + .dedent() + .write_line("a"); + + assert_eq!(writer.finish(), "a\n\ta\n\t\ta\n\ta\na\n"); + } + + #[test] + fn test_parenthesis() { + let mut writer = PrettyWriter::new(); + + writer + .write_line("a") + .open_paren() + .open_paren() + .write_line("a") + .close_paren() + .close_paren() + .write_line("a"); + + assert_eq!(writer.finish(), "a\n(\n\t(\n\t\ta\n\t)\n)\na\n"); + } +} diff --git a/bevy_event_priority/Cargo.toml b/bevy_event_priority/Cargo.toml index 7e35de0db2..4f7b830d66 100644 --- a/bevy_event_priority/Cargo.toml +++ b/bevy_event_priority/Cargo.toml @@ -16,5 +16,5 @@ name = "bevy_event_priority" path = "src/lib.rs" [dependencies] -bevy = "0.7" +bevy = { version = "0.8.0"} diff --git a/bevy_mod_scripting/Cargo.toml b/bevy_mod_scripting/Cargo.toml index 958790aedc..43d1defce6 100644 --- a/bevy_mod_scripting/Cargo.toml +++ b/bevy_mod_scripting/Cargo.toml @@ -7,6 +7,7 @@ license = "MIT" description = "Bevy plugin for enabling scripting" repository = "https://github.com/makspll/bevy_scripting" homepage = "https://github.com/makspll/bevy_scripting" +documentation = "https://docs.rs/bevy_mod_scripting" keywords = ["bevy", "gamedev", "scripting", "lua"] categories = ["game-development"] readme = "../readme.md" @@ -40,46 +41,68 @@ luajit52 = ["tealr/mlua_luajit52"] mlua_serialize = ["tealr/mlua_serialize"] mlua_macros = ["tealr/mlua_macros"] -# mlua_parking_lot = ["tealr/mlua_parking_lot"] - [dependencies] -bevy = "0.7" -tealr = { git = "https://github.com/lenscas/tealr", features = ["mlua_vendored","mlua_send"] } +bevy = { version = "0.8.0"} +tealr = { version = "0.9.0-alpha1", features=["mlua_vendored","mlua_send"]} rhai = { version = "1.7.0", features = ["sync"] } anyhow = "1.0.57" -beau_collector = "0.2.1" once_cell = "1.10.0" bevy_event_priority = { path = "../bevy_event_priority" } thiserror = "1.0.31" +lazy_static = "1.4.0" +paste = "1.0.7" +parking_lot = "0.12.1" +bevy_mod_scripting_derive = {path = "../bevy_mod_scripting_derive"} serde_json = "1.0.81" +num-traits = "0.2.15" +serde = { version = "1", features = ["derive"] } +smallvec = "1.9.0" [dev-dependencies] -bevy_console = { git = "https://github.com/RichoDemus/bevy-console" } -bevy_asset_loader = {git = "https://github.com/NiklasEi/bevy_asset_loader", features = ["dynamic_assets"]} +# bevy_console = { git = "https://github.com/OnlyGraphs/bevy-console" } +# bevy_asset_loader = {git = "https://github.com/NiklasEi/bevy_asset_loader", features = ["dynamic_assets"]} rand = "0.8.5" +serde = "1.0.137" +criterion = "0.3" + + +# needs bevy 0.8 support from console +# [[example]] +# name = "console_integration_lua" +# path = "examples/console_integration_lua.rs" +# required-features = ["lua54"] + + +# [[example]] +# name = "console_integration_rhai" +# path = "examples/console_integration_rhai.rs" [[example]] -name = "console_integration_lua" -path = "examples/console_integration_lua.rs" +name = "complex_game_loop_lua" +path = "examples/lua/complex_game_loop.rs" required-features = ["lua54"] +[[example]] +name = "game_of_life_lua" +path = "examples/lua/game_of_life.rs" +required-features = ["lua54","teal"] [[example]] -name = "console_integration_rhai" -path = "examples/console_integration_rhai.rs" +name = "event_recipients_lua" +path = "examples/lua/event_recipients.rs" [[example]] -name = "complex_game_loop" -path = "examples/complex_game_loop.rs" +name = "documentation_gen_lua" +path = "examples/lua/documentation_gen.rs" required-features = ["lua54"] [[example]] -name = "event_recipients" -path = "examples/event_recipients.rs" +name = "bevy_api_lua" +path = "examples/lua/bevy_api.rs" required-features = ["lua54"] [[example]] -name = "documentation_gen_lua" -path = "examples/documentation_gen_lua.rs" -required-features = ["lua54","teal"] \ No newline at end of file +name = "wrappers" +path = "examples/wrappers.rs" +required-features = ["lua54"] diff --git a/bevy_mod_scripting/assets/scripts/console_integration.lua b/bevy_mod_scripting/assets/scripts/console_integration.lua index 73a33bce35..5b71a3839c 100644 --- a/bevy_mod_scripting/assets/scripts/console_integration.lua +++ b/bevy_mod_scripting/assets/scripts/console_integration.lua @@ -3,9 +3,9 @@ local a = 0 function on_update() if a % 100 == 0 then - -- print_to_console()() is defined in console_integration.rs + -- print_to_console() is defined in console_integration.rs -- by the api provider - print_to_console(string.format("%d, entity_bits:%d", a,entity)) + print_to_console(string.format("%d, entity_bits:%d", a,entity:bits())) end a = a + 1 diff --git a/bevy_mod_scripting/assets/scripts/game_of_life.tl b/bevy_mod_scripting/assets/scripts/game_of_life.tl new file mode 100644 index 0000000000..3cc1e8316a --- /dev/null +++ b/bevy_mod_scripting/assets/scripts/game_of_life.tl @@ -0,0 +1,57 @@ +math.randomseed(os.time()) + +function init() + + local LifeState = world:get_type_by_name("LifeState") + local life_state = world:get_component(entity,LifeState) as types.LuaLifeState + local cells = life_state.cells as {integer} + + -- set some cells alive + for _=1,10000 do + local index = math.random(#cells) + cells[index] = 255 + end +end + +function on_update() + local LifeState = world:get_type_by_name("LifeState") + local Settings = world:get_type_by_name("Settings") + + local life_state = world:get_component(entity,LifeState) as types.LuaLifeState + local cells = life_state.cells as {integer} + + -- note that here we do not make use of LuaProxyable and just go off pure reflection + local settings = world:get_resource(Settings) as {string:any} + local dimensions = settings.physical_grid_dimensions as {integer} + + + -- primitives are passed by value to lua, keep a hold of old state but turn 255's into 1's + local prev_state = {} + for k,v in pairs(life_state.cells as {integer:integer}) do + prev_state[k] = (not(v == 0)) and 1 or 0 + end + + for i=1,(dimensions[0] * dimensions[1]) do + local north = prev_state[i - dimensions[0]] or 1 + local south = prev_state[i + dimensions[0]] or 1 + local east = prev_state[i + 1] or 1 + local west = prev_state[i - 1] or 1 + local northeast = prev_state[i - dimensions[0] + 1] or 1 + local southeast = prev_state[i + dimensions[0] + 1] or 1 + local northwest = prev_state[i - dimensions[0] - 1] or 1 + local southwest = prev_state[i + dimensions[0] - 1] or 1 + + local neighbours = north + south + east + west + + northeast + southeast + northwest + southwest + + -- was dead and got 3 neighbours now + if prev_state[i] == 0 and neighbours == 3 then + cells[i] = 255 + -- was alive and should die now + elseif prev_state[i] == 1 and ((neighbours < 2) or (neighbours > 3)) then + cells[i] = 0 + end + end + + +end \ No newline at end of file diff --git a/bevy_mod_scripting/assets/scripts/teal_file.tl b/bevy_mod_scripting/assets/scripts/teal_file.tl deleted file mode 100644 index 705ee869c1..0000000000 --- a/bevy_mod_scripting/assets/scripts/teal_file.tl +++ /dev/null @@ -1,16 +0,0 @@ --- this is a teal file! --- the recommended way of developing with teal is --- opening a new vscode window with the top directory --- being `scripts` --- the official teal extension will then automatically pick up --- on all of the types defined in `types/global_types.d.tl` --- and provide type hints, errors and maybe inlined docstrings in the future. - --- teal files will be compiled to lua files when loaded automatically during development time --- when you're ready to ship your game, you will need to compile those scripts to pure .lua files --- with `tl build` in this directory, it's that simple! You don't need to ship any teal files, --- but you might decide to to provide your modders with a level playing ground! -function on_update() - local lol : string = my_api.my_function() - print(lol) -end \ No newline at end of file diff --git a/bevy_mod_scripting/assets/scripts/types/global_types.d.tl b/bevy_mod_scripting/assets/scripts/types/global_types.d.tl deleted file mode 100644 index 7de9091af9..0000000000 --- a/bevy_mod_scripting/assets/scripts/types/global_types.d.tl +++ /dev/null @@ -1,28 +0,0 @@ -local record global_types ---This is module level documentation for our api, it will be shown first --- --- --- - record APIModule - userdata - - -- Pure functions - --Here we document the next function - -- - --## Markdown!: - -- - --```lua - -- local hello = "string" - -- - --``` - my_function: function():(string) - - help: function(string):(string) - - - end -end ---Documentation for the exposed global variable - -global my_api: global_types.APIModule -return global_types \ No newline at end of file diff --git a/bevy_mod_scripting/assets/scripts/types/types.d.tl b/bevy_mod_scripting/assets/scripts/types/types.d.tl new file mode 100644 index 0000000000..56cdbfa03f --- /dev/null +++ b/bevy_mod_scripting/assets/scripts/types/types.d.tl @@ -0,0 +1,13653 @@ +global record types +--Defines how each line is aligned within the flexbox. +-- +-- +-- +--It only applies if [`FlexWrap::Wrap`] is present and if there are multiple lines of items. +-- + record LuaAlignContent + userdata + + -- Meta methods + metamethod __tostring: function(LuaAlignContent):(string) + + + end +--How items are aligned according to the cross axis +-- + record LuaAlignItems + userdata + + -- Meta methods + metamethod __tostring: function(LuaAlignItems):(string) + + + end +--Works like [`AlignItems`] but applies only to a single item +-- + record LuaAlignSelf + userdata + + -- Meta methods + metamethod __tostring: function(LuaAlignSelf):(string) + + + end +--Defines the text direction +-- +-- +-- +--For example English is written LTR (left-to-right) while Arabic is written RTL (right-to-left). +-- + record LuaDirection + userdata + + -- Meta methods + metamethod __tostring: function(LuaDirection):(string) + + + end +--Defines how flexbox items are ordered within a flexbox +-- + record LuaFlexDirection + userdata + + -- Meta methods + metamethod __tostring: function(LuaFlexDirection):(string) + + + end +--Defines if flexbox items appear on a single line or on multiple lines +-- + record LuaFlexWrap + userdata + + -- Meta methods + metamethod __tostring: function(LuaFlexWrap):(string) + + + end +--Describes whether the node should block interactions with lower nodes +-- + record LuaFocusPolicy + userdata + + -- Meta methods + metamethod __tostring: function(LuaFocusPolicy):(string) + + + end +--Describes what type of input interaction has occurred for a UI node. +-- +-- +-- +--This is commonly queried with a `Changed` filter. +-- +-- +-- +--Updated in [`ui_focus_system`]. +-- +-- +-- +--If a UI node has both [`Interaction`] and [`ComputedVisibility`] components, +-- +--[`Interaction`] will always be [`Interaction::None`] +-- +--when [`ComputedVisibility::is_visible()`] is false. +-- +--This ensures that hidden UI nodes are not interactable, +-- +--and do not end up stuck in an active state if hidden at the wrong time. +-- +-- +-- +--Note that you can also control the visibility of a node using the [`Display`](crate::ui_node::Display) property, +-- +--which fully collapses it during layout calculations. +-- + record LuaInteraction + userdata + + -- Meta methods + metamethod __tostring: function(LuaInteraction):(string) + + + end +--Defines how items are aligned according to the main axis +-- + record LuaJustifyContent + userdata + + -- Meta methods + metamethod __tostring: function(LuaJustifyContent):(string) + + + end +--Whether to show or hide overflowing items +-- + record LuaOverflow + userdata + + -- Meta methods + metamethod __tostring: function(LuaOverflow):(string) + + + end +--The strategy used to position this node +-- + record LuaPositionType + userdata + + -- Meta methods + metamethod __tostring: function(LuaPositionType):(string) + + + end +--An enum that describes possible types of value in flexbox layout options +-- + record LuaVal + userdata + + -- Meta methods + metamethod __tostring: function(LuaVal):(string) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + + end +--The calculated clip of the node +-- + record LuaCalculatedClip + userdata + + -- Fields + -- The rect of the clip + clip : LuaRect + + -- Meta methods + metamethod __tostring: function(LuaCalculatedClip):(string) + + + end +--The calculated size of the node +-- + record LuaCalculatedSize + userdata + + -- Fields + -- The size of the node + size : ReflectedValue + + -- Meta methods + metamethod __tostring: function(LuaCalculatedSize):(string) + + + end +--Describes the size of a UI node +-- + record LuaNode + userdata + + -- Fields + -- The size of the node as width and height in pixels + size : LuaVec2 + + -- Meta methods + metamethod __tostring: function(LuaNode):(string) + + + end +--Describes the style of a UI node +-- +-- +-- +--It uses the [Flexbox](https://cssreference.io/flexbox/) system. +-- +-- +-- +--**Note:** Bevy's UI is upside down compared to how Flexbox normally works, to stay consistent with engine paradigms about layouting from +-- +--the upper left corner of the display +-- + record LuaStyle + userdata + + -- Fields + -- Whether to arrange this node and its children with flexbox layout + -- + -- + -- + -- If this is set to [`Display::None`], this node will be collapsed. + display : LuaDisplay + + -- Whether to arrange this node relative to other nodes, or positioned absolutely + position_type : LuaPositionType + + -- Which direction the content of this node should go + direction : LuaDirection + + -- Whether to use column or row layout + flex_direction : LuaFlexDirection + + -- How to wrap nodes + flex_wrap : LuaFlexWrap + + -- How items are aligned according to the cross axis + align_items : LuaAlignItems + + -- Like align_items but for only this item + align_self : LuaAlignSelf + + -- How to align each line, only applies if flex_wrap is set to + -- + -- [`FlexWrap::Wrap`] and there are multiple lines of items + align_content : LuaAlignContent + + -- How items align according to the main axis + justify_content : LuaJustifyContent + + -- The position of the node as described by its Rect + position : ReflectedValue + + -- The margin of the node + margin : ReflectedValue + + -- The padding of the node + padding : ReflectedValue + + -- The border of the node + border : ReflectedValue + + -- Defines how much a flexbox item should grow if there's space available + flex_grow : number + + -- How to shrink if there's not enough space available + flex_shrink : number + + -- The initial size of the item + flex_basis : LuaVal + + -- The size of the flexbox + size : ReflectedValue + + -- The minimum size of the flexbox + min_size : ReflectedValue + + -- The maximum size of the flexbox + max_size : ReflectedValue + + -- The aspect ratio of the flexbox + aspect_ratio : ReflectedValue + + -- How to handle overflow + overflow : LuaOverflow + + -- Meta methods + metamethod __tostring: function(LuaStyle):(string) + + + end +--The color of the node +-- + record LuaUiColor + userdata + + -- Fields + _0 : LuaColor + + -- Meta methods + metamethod __tostring: function(LuaUiColor):(string) + + + end +--The image of the node +-- + record LuaUiImage + userdata + + -- Fields + _0 : ReflectedValue + + -- Meta methods + metamethod __tostring: function(LuaUiImage):(string) + + + end +--Marker struct for buttons +-- + record LuaButton + userdata + + -- Meta methods + metamethod __tostring: function(LuaButton):(string) + + + end +--Describes how to resize the Image node +-- + record LuaImageMode + userdata + + -- Meta methods + metamethod __tostring: function(LuaImageMode):(string) + + + end +--Whether to use a Flexbox layout model. +-- +-- +-- +--Part of the [`Style`] component. +-- + record LuaDisplay + userdata + + -- Meta methods + metamethod __tostring: function(LuaDisplay):(string) + + + end +--Animation controls +-- + record LuaAnimationPlayer + userdata + + -- Pure methods + --Is the animation paused + is_paused: function(LuaAnimationPlayer):(boolean) + + --Speed of the animation playback + speed: function(LuaAnimationPlayer):(number) + + --Time elapsed playing the animation + elapsed: function(LuaAnimationPlayer):(number) + + -- Mutating methods + --Pause the animation + pause: function(LuaAnimationPlayer):() + + --Unpause the animation + resume: function(LuaAnimationPlayer):() + + + end +--Component used to identify an entity. Stores a hash for faster comparisons +-- +--The hash is eagerly re-computed upon each update to the name. +-- +-- +-- +--[`Name`] should not be treated as a globally unique identifier for entities, +-- +--as multiple entities can have the same name. [`bevy_ecs::entity::Entity`] should be +-- +--used instead as the default unique identifier. +-- + record LuaName + userdata + + -- Meta methods + metamethod __tostring: function(LuaName):(string) + + + end +--Collection of static methods for [`LuaName`]. + record LuaNameClass + userdata + + + end + record LuaGltfExtras + userdata + + -- Fields + value : string + + -- Meta methods + metamethod __tostring: function(LuaGltfExtras):(string) + + + end +--Contains references to the child entities of this entity +-- + record LuaChildren + userdata + + -- Mutating methods + --Swaps the child at `a_index` with the child at `b_index` + swap: function(LuaChildren,(integer),(integer)):() + + -- Meta methods + metamethod __tostring: function(LuaChildren):(string) + + + end +--Collection of static methods for [`LuaChildren`]. + record LuaChildrenClass + userdata + + + end +--Holds a reference to the parent entity of this entity. +-- +--This component should only be present on entities that actually have a parent entity. +-- + record LuaParent + userdata + + -- Pure methods + --Gets the [`Entity`] ID of the parent. + get: function(LuaParent):(LuaEntity) + + -- Meta methods + metamethod __tostring: function(LuaParent):(string) + + + end +--The maximum width and height of text. The text will wrap according to the specified size. +-- +--Characters out of the bounds after wrapping will be truncated. Text is aligned according to the +-- +--specified `TextAlignment`. +-- +-- +-- +--Note: only characters that are completely out of the bounds will be truncated, so this is not a +-- +--reliable limit if it is necessary to contain the text strictly in the bounds. Currently this +-- +--component is mainly useful for text wrapping only. +-- + record LuaText2dBounds + userdata + + -- Fields + size : LuaVec2 + + -- Meta methods + metamethod __tostring: function(LuaText2dBounds):(string) + + + end +--The calculated size of text drawn in 2D scene. +-- + record LuaText2dSize + userdata + + -- Fields + size : LuaVec2 + + -- Meta methods + metamethod __tostring: function(LuaText2dSize):(string) + + + end + record LuaText + userdata + + -- Fields + sections : ReflectedValue + + alignment : LuaTextAlignment + + -- Pure methods + --Returns this [`Text`] with a new [`TextAlignment`]. + with_alignment: function(LuaText,LuaTextAlignment):(LuaText) + + -- Meta methods + metamethod __tostring: function(LuaText):(string) + + + end +--Collection of static methods for [`LuaText`]. + record LuaTextClass + userdata + + + end + record LuaTextAlignment + userdata + + -- Fields + vertical : LuaVerticalAlign + + horizontal : LuaHorizontalAlign + + -- Meta methods + metamethod __tostring: function(LuaTextAlignment):(string) + + + end + record LuaTextSection + userdata + + -- Fields + value : string + + style : LuaTextStyle + + -- Pure functions + --Create an empty [`TextSection`] from a style. Useful when the value will be set dynamically. + from_style: function(LuaTextStyle):(LuaTextSection) + + -- Meta methods + metamethod __tostring: function(LuaTextSection):(string) + + + end +--Collection of static methods for [`LuaTextSection`]. + record LuaTextSectionClass + userdata + + -- Pure functions + --Create an empty [`TextSection`] from a style. Useful when the value will be set dynamically. + from_style: function(LuaTextStyle):(LuaTextSection) + + + end + record LuaTextStyle + userdata + + -- Fields + font : ReflectedValue + + font_size : number + + color : LuaColor + + -- Meta methods + metamethod __tostring: function(LuaTextStyle):(string) + + + end +--Describes horizontal alignment preference for positioning & bounds. +-- + record LuaHorizontalAlign + userdata + + -- Meta methods + metamethod __tostring: function(LuaHorizontalAlign):(string) + + + end +--Describes vertical alignment preference for positioning & bounds. Currently a placeholder +-- +--for future functionality. +-- + record LuaVerticalAlign + userdata + + -- Meta methods + metamethod __tostring: function(LuaVerticalAlign):(string) + + + end +--A Stopwatch is a struct that track elapsed time when started. +-- +-- +-- +--# Examples +-- +-- +-- +--``` +-- +--# use bevy_time::*; +-- +--use std::time::Duration; +-- +--let mut stopwatch = Stopwatch::new(); +-- +--assert_eq!(stopwatch.elapsed_secs(), 0.0); +-- +-- +-- +--stopwatch.tick(Duration::from_secs_f32(1.0)); // tick one second +-- +--assert_eq!(stopwatch.elapsed_secs(), 1.0); +-- +-- +-- +--stopwatch.pause(); +-- +--stopwatch.tick(Duration::from_secs_f32(1.0)); // paused stopwatches don't tick +-- +--assert_eq!(stopwatch.elapsed_secs(), 1.0); +-- +-- +-- +--stopwatch.reset(); // reset the stopwatch +-- +--assert!(stopwatch.paused()); +-- +--assert_eq!(stopwatch.elapsed_secs(), 0.0); +-- +--``` +-- + record LuaStopwatch + userdata + + -- Pure methods + --Returns the elapsed time since the last [`reset`](Stopwatch::reset) + -- + --of the stopwatch, in seconds. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut stopwatch = Stopwatch::new(); + -- + --stopwatch.tick(Duration::from_secs(1)); + -- + --assert_eq!(stopwatch.elapsed_secs(), 1.0); + -- + --``` + -- + -- + -- + --# See Also + -- + -- + -- + --[`elapsed`](Stopwatch::elapsed) - if a `Duration` is desirable instead. + elapsed_secs: function(LuaStopwatch):(number) + + --Returns `true` if the stopwatch is paused. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --let mut stopwatch = Stopwatch::new(); + -- + --assert!(!stopwatch.paused()); + -- + --stopwatch.pause(); + -- + --assert!(stopwatch.paused()); + -- + --stopwatch.unpause(); + -- + --assert!(!stopwatch.paused()); + -- + --``` + paused: function(LuaStopwatch):(boolean) + + -- Mutating methods + --Pauses the stopwatch. Any call to [`tick`](Stopwatch::tick) while + -- + --paused will not have any effect on the elapsed time. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut stopwatch = Stopwatch::new(); + -- + --stopwatch.pause(); + -- + --stopwatch.tick(Duration::from_secs_f32(1.5)); + -- + --assert!(stopwatch.paused()); + -- + --assert_eq!(stopwatch.elapsed_secs(), 0.0); + -- + --``` + pause: function(LuaStopwatch):() + + --Unpauses the stopwatch. Resume the effect of ticking on elapsed time. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut stopwatch = Stopwatch::new(); + -- + --stopwatch.pause(); + -- + --stopwatch.tick(Duration::from_secs_f32(1.0)); + -- + --stopwatch.unpause(); + -- + --stopwatch.tick(Duration::from_secs_f32(1.0)); + -- + --assert!(!stopwatch.paused()); + -- + --assert_eq!(stopwatch.elapsed_secs(), 1.0); + -- + --``` + unpause: function(LuaStopwatch):() + + --Resets the stopwatch. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut stopwatch = Stopwatch::new(); + -- + --stopwatch.tick(Duration::from_secs_f32(1.5)); + -- + --stopwatch.reset(); + -- + --assert_eq!(stopwatch.elapsed_secs(), 0.0); + -- + --``` + reset: function(LuaStopwatch):() + + -- Pure functions + --Create a new unpaused `Stopwatch` with no elapsed time. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --let stopwatch = Stopwatch::new(); + -- + --assert_eq!(stopwatch.elapsed_secs(), 0.0); + -- + --assert_eq!(stopwatch.paused(), false); + -- + --``` + new: function():(LuaStopwatch) + + -- Meta methods + metamethod __tostring: function(LuaStopwatch):(string) + + + end +--Collection of static methods for [`LuaStopwatch`]. + record LuaStopwatchClass + userdata + + -- Pure functions + --Create a new unpaused `Stopwatch` with no elapsed time. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --let stopwatch = Stopwatch::new(); + -- + --assert_eq!(stopwatch.elapsed_secs(), 0.0); + -- + --assert_eq!(stopwatch.paused(), false); + -- + --``` + new: function():(LuaStopwatch) + + + end +--Tracks elapsed time. Enters the finished state once `duration` is reached. +-- +-- +-- +--Non repeating timers will stop tracking and stay in the finished state until reset. +-- +--Repeating timers will only be in the finished state on each tick `duration` is reached or +-- +--exceeded, and can still be reset at any given point. +-- +-- +-- +--Paused timers will not have elapsed time increased. +-- + record LuaTimer + userdata + + -- Pure methods + --Returns `true` if the timer has reached its duration. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut timer = Timer::from_seconds(1.0, false); + -- + --timer.tick(Duration::from_secs_f32(1.5)); + -- + --assert!(timer.finished()); + -- + --timer.tick(Duration::from_secs_f32(0.5)); + -- + --assert!(timer.finished()); + -- + --``` + finished: function(LuaTimer):(boolean) + + --Returns `true` only on the tick the timer reached its duration. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut timer = Timer::from_seconds(1.0, false); + -- + --timer.tick(Duration::from_secs_f32(1.5)); + -- + --assert!(timer.just_finished()); + -- + --timer.tick(Duration::from_secs_f32(0.5)); + -- + --assert!(!timer.just_finished()); + -- + --``` + just_finished: function(LuaTimer):(boolean) + + --Returns the time elapsed on the timer as a `f32`. + -- + --See also [`Timer::elapsed`](Timer::elapsed). + elapsed_secs: function(LuaTimer):(number) + + --Returns `true` if the timer is repeating. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --let mut timer = Timer::from_seconds(1.0, true); + -- + --assert!(timer.repeating()); + -- + --``` + repeating: function(LuaTimer):(boolean) + + --Returns `true` if the timer is paused. + -- + -- + -- + --See also [`Stopwatch::paused`](Stopwatch::paused). + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --let mut timer = Timer::from_seconds(1.0, false); + -- + --assert!(!timer.paused()); + -- + --timer.pause(); + -- + --assert!(timer.paused()); + -- + --timer.unpause(); + -- + --assert!(!timer.paused()); + -- + --``` + paused: function(LuaTimer):(boolean) + + --Returns the percentage of the timer elapsed time (goes from 0.0 to 1.0). + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut timer = Timer::from_seconds(2.0, false); + -- + --timer.tick(Duration::from_secs_f32(0.5)); + -- + --assert_eq!(timer.percent(), 0.25); + -- + --``` + percent: function(LuaTimer):(number) + + --Returns the percentage of the timer remaining time (goes from 0.0 to 1.0). + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut timer = Timer::from_seconds(2.0, false); + -- + --timer.tick(Duration::from_secs_f32(0.5)); + -- + --assert_eq!(timer.percent_left(), 0.75); + -- + --``` + percent_left: function(LuaTimer):(number) + + --Returns the number of times a repeating timer + -- + --finished during the last [`tick`](Timer::tick) call. + -- + -- + -- + --For non repeating-timers, this method will only ever + -- + --return 0 or 1. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut timer = Timer::from_seconds(1.0, true); + -- + --timer.tick(Duration::from_secs_f32(6.0)); + -- + --assert_eq!(timer.times_finished_this_tick(), 6); + -- + --timer.tick(Duration::from_secs_f32(2.0)); + -- + --assert_eq!(timer.times_finished_this_tick(), 2); + -- + --timer.tick(Duration::from_secs_f32(0.5)); + -- + --assert_eq!(timer.times_finished_this_tick(), 0); + -- + --``` + times_finished_this_tick: function(LuaTimer):(integer) + + -- Mutating methods + --Sets whether the timer is repeating or not. + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --let mut timer = Timer::from_seconds(1.0, true); + -- + --timer.set_repeating(false); + -- + --assert!(!timer.repeating()); + -- + --``` + set_repeating: function(LuaTimer,boolean):() + + --Pauses the Timer. Disables the ticking of the timer. + -- + -- + -- + --See also [`Stopwatch::pause`](Stopwatch::pause). + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut timer = Timer::from_seconds(1.0, false); + -- + --timer.pause(); + -- + --timer.tick(Duration::from_secs_f32(0.5)); + -- + --assert_eq!(timer.elapsed_secs(), 0.0); + -- + --``` + pause: function(LuaTimer):() + + --Unpauses the Timer. Resumes the ticking of the timer. + -- + -- + -- + --See also [`Stopwatch::unpause()`](Stopwatch::unpause). + -- + -- + -- + --# Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut timer = Timer::from_seconds(1.0, false); + -- + --timer.pause(); + -- + --timer.tick(Duration::from_secs_f32(0.5)); + -- + --timer.unpause(); + -- + --timer.tick(Duration::from_secs_f32(0.5)); + -- + --assert_eq!(timer.elapsed_secs(), 0.5); + -- + --``` + unpause: function(LuaTimer):() + + --Resets the timer. the reset doesn't affect the `paused` state of the timer. + -- + -- + -- + --See also [`Stopwatch::reset`](Stopwatch::reset). + -- + -- + -- + --Examples + -- + --``` + -- + --# use bevy_time::*; + -- + --use std::time::Duration; + -- + --let mut timer = Timer::from_seconds(1.0, false); + -- + --timer.tick(Duration::from_secs_f32(1.5)); + -- + --timer.reset(); + -- + --assert!(!timer.finished()); + -- + --assert!(!timer.just_finished()); + -- + --assert_eq!(timer.elapsed_secs(), 0.0); + -- + --``` + reset: function(LuaTimer):() + + -- Pure functions + --Creates a new timer with a given duration in seconds. + -- + -- + -- + --# Example + -- + --``` + -- + --# use bevy_time::*; + -- + --let mut timer = Timer::from_seconds(1.0, false); + -- + --``` + from_seconds: function((number),(boolean)):(LuaTimer) + + -- Meta methods + metamethod __tostring: function(LuaTimer):(string) + + + end +--Collection of static methods for [`LuaTimer`]. + record LuaTimerClass + userdata + + -- Pure functions + --Creates a new timer with a given duration in seconds. + -- + -- + -- + --# Example + -- + --``` + -- + --# use bevy_time::*; + -- + --let mut timer = Timer::from_seconds(1.0, false); + -- + --``` + from_seconds: function((number),(boolean)):(LuaTimer) + + + end +--Lightweight identifier of an [entity](crate::entity). +-- +-- +-- +--The identifier is implemented using a [generational index]: a combination of an ID and a generation. +-- +--This allows fast insertion after data removal in an array while minimizing loss of spatial locality. +-- +-- +-- +--[generational index]: https://lucassardois.medium.com/generational-indices-guide-8e3c5f7fd594 +-- +-- +-- +--# Usage +-- +-- +-- +--This data type is returned by iterating a `Query` that has `Entity` as part of its query fetch type parameter ([learn more]). +-- +--It can also be obtained by calling [`EntityCommands::id`] or [`EntityMut::id`]. +-- +-- +-- +--``` +-- +--# use bevy_ecs::prelude::*; +-- +--# +-- +--fn setup(mut commands: Commands) { +-- +-- // Calling `spawn` returns `EntityCommands`. +-- +-- let entity = commands.spawn().id(); +-- +--} +-- +-- +-- +--fn exclusive_system(world: &mut World) { +-- +-- // Calling `spawn` returns `EntityMut`. +-- +-- let entity = world.spawn().id(); +-- +--} +-- +--# +-- +--# bevy_ecs::system::assert_is_system(setup); +-- +--# bevy_ecs::system::IntoExclusiveSystem::exclusive_system(exclusive_system); +-- +--``` +-- +-- +-- +--It can be used to refer to a specific entity to apply [`EntityCommands`], or to call [`Query::get`] (or similar methods) to access its components. +-- +-- +-- +--``` +-- +--# use bevy_ecs::prelude::*; +-- +--# +-- +--# #[derive(Component)] +-- +--# struct Expired; +-- +--# +-- +--fn dispose_expired_food(mut commands: Commands, query: Query>) { +-- +-- for food_entity in &query { +-- +-- commands.entity(food_entity).despawn(); +-- +-- } +-- +--} +-- +--# +-- +--# bevy_ecs::system::assert_is_system(dispose_expired_food); +-- +--``` +-- +-- +-- +--[learn more]: crate::system::Query#entity-id-access +-- +--[`EntityCommands::id`]: crate::system::EntityCommands::id +-- +--[`EntityMut::id`]: crate::world::EntityMut::id +-- +--[`EntityCommands`]: crate::system::EntityCommands +-- +--[`Query::get`]: crate::system::Query::get +-- + record LuaEntity + userdata + + -- Pure methods + --Convert to a form convenient for passing outside of rust. + -- + -- + -- + --Only useful for identifying entities within the same instance of an application. Do not use + -- + --for serialization between runs. + -- + -- + -- + --No particular structure is guaranteed for the returned bits. + to_bits: function(LuaEntity):(integer) + + --Return a transiently unique identifier. + -- + -- + -- + --No two simultaneously-live entities share the same ID, but dead entities' IDs may collide + -- + --with both live and dead entities. Useful for compactly representing entities within a + -- + --specific snapshot of the world, such as when serializing. + id: function(LuaEntity):(integer) + + --Returns the generation of this Entity's id. The generation is incremented each time an + -- + --entity with a given id is despawned. This serves as a "count" of the number of times a + -- + --given id has been reused (id, generation) pairs uniquely identify a given Entity. + generation: function(LuaEntity):(integer) + + -- Pure functions + --Creates a new entity reference with the specified `id` and a generation of 0. + -- + -- + -- + --# Note + -- + -- + -- + --Spawning a specific `entity` value is __rarely the right choice__. Most apps should favor + -- + --[`Commands::spawn`](crate::system::Commands::spawn). This method should generally + -- + --only be used for sharing entities across apps, and only when they have a scheme + -- + --worked out to share an ID space (which doesn't happen by default). + -- + -- + -- + --In general, one should not try to synchronize the ECS by attempting to ensure that + -- + --`Entity` lines up between instances, but instead insert a secondary identifier as + -- + --a component. + -- + -- + -- + --There are still some use cases where it might be appropriate to use this function + -- + --externally. + -- + -- + -- + --## Examples + -- + -- + -- + --Initializing a collection (e.g. `array` or `Vec`) with a known size: + -- + -- + -- + --```no_run + -- + --# use bevy_ecs::prelude::*; + -- + --let mut entities: [Entity; 10] = [Entity::from_raw(0); 10]; + -- + -- + -- + --``` + -- + -- + -- + --Deriving `Reflect` for a component that has an `Entity` field: + -- + -- + -- + --```no_run + -- + --# use bevy_ecs::{prelude::*, component::*}; + -- + --# use bevy_reflect::Reflect; + -- + --#[derive(Reflect, Component)] + -- + --#[reflect(Component)] + -- + --pub struct MyStruct { + -- + -- pub entity: Entity, + -- + --} + -- + -- + -- + --impl FromWorld for MyStruct { + -- + -- fn from_world(_world: &mut World) -> Self { + -- + -- Self { + -- + -- entity: Entity::from_raw(u32::MAX), + -- + -- } + -- + -- } + -- + --} + -- + --``` + from_raw: function(integer):(LuaEntity) + + --Reconstruct an `Entity` previously destructured with [`Entity::to_bits`]. + -- + -- + -- + --Only useful when applied to results from `to_bits` in the same instance of an application. + from_bits: function(integer):(LuaEntity) + + -- Meta methods + metamethod __tostring: function(LuaEntity):(string) + + + end +--Collection of static methods for [`LuaEntity`]. + record LuaEntityClass + userdata + + -- Pure functions + --Creates a new entity reference with the specified `id` and a generation of 0. + -- + -- + -- + --# Note + -- + -- + -- + --Spawning a specific `entity` value is __rarely the right choice__. Most apps should favor + -- + --[`Commands::spawn`](crate::system::Commands::spawn). This method should generally + -- + --only be used for sharing entities across apps, and only when they have a scheme + -- + --worked out to share an ID space (which doesn't happen by default). + -- + -- + -- + --In general, one should not try to synchronize the ECS by attempting to ensure that + -- + --`Entity` lines up between instances, but instead insert a secondary identifier as + -- + --a component. + -- + -- + -- + --There are still some use cases where it might be appropriate to use this function + -- + --externally. + -- + -- + -- + --## Examples + -- + -- + -- + --Initializing a collection (e.g. `array` or `Vec`) with a known size: + -- + -- + -- + --```no_run + -- + --# use bevy_ecs::prelude::*; + -- + --let mut entities: [Entity; 10] = [Entity::from_raw(0); 10]; + -- + -- + -- + --``` + -- + -- + -- + --Deriving `Reflect` for a component that has an `Entity` field: + -- + -- + -- + --```no_run + -- + --# use bevy_ecs::{prelude::*, component::*}; + -- + --# use bevy_reflect::Reflect; + -- + --#[derive(Reflect, Component)] + -- + --#[reflect(Component)] + -- + --pub struct MyStruct { + -- + -- pub entity: Entity, + -- + --} + -- + -- + -- + --impl FromWorld for MyStruct { + -- + -- fn from_world(_world: &mut World) -> Self { + -- + -- Self { + -- + -- entity: Entity::from_raw(u32::MAX), + -- + -- } + -- + -- } + -- + --} + -- + --``` + from_raw: function(integer):(LuaEntity) + + --Reconstruct an `Entity` previously destructured with [`Entity::to_bits`]. + -- + -- + -- + --Only useful when applied to results from `to_bits` in the same instance of an application. + from_bits: function(integer):(LuaEntity) + + + end +--Describe the position of an entity. If the entity has a parent, the position is relative +-- +--to its parent position. +-- +-- +-- +--* To place or move an entity, you should set its [`Transform`]. +-- +--* To get the global transform of an entity, you should get its [`GlobalTransform`]. +-- +--* To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. +-- +-- * You may use the [`TransformBundle`](crate::TransformBundle) to guarantee this. +-- +-- +-- +--## [`Transform`] and [`GlobalTransform`] +-- +-- +-- +--[`Transform`] is the position of an entity relative to its parent position, or the reference +-- +--frame if it doesn't have a [`Parent`](bevy_hierarchy::Parent). +-- +-- +-- +--[`GlobalTransform`] is the position of an entity relative to the reference frame. +-- +-- +-- +--[`GlobalTransform`] is updated from [`Transform`] in the system +-- +--[`transform_propagate_system`](crate::transform_propagate_system). +-- +-- +-- +--This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you +-- +--update the [`Transform`] of an entity in this stage or after, you will notice a 1 frame lag +-- +--before the [`GlobalTransform`] is updated. +-- + record LuaTransform + userdata + + -- Fields + -- Position of the entity. In 2d, the last value of the `Vec3` is used for z-ordering. + translation : LuaVec3 + + -- Rotation of the entity. + rotation : LuaQuat + + -- Scale of the entity. + scale : LuaVec3 + + -- Pure methods + --Updates and returns this [`Transform`] by rotating it so that its unit vector in the + -- + --local `Z` direction is toward `target` and its unit vector in the local `Y` direction + -- + --is toward `up`. + looking_at: function(LuaTransform,(LuaVec3),(LuaVec3)):(LuaTransform) + + --Returns this [`Transform`] with a new translation. + with_translation: function(LuaTransform,LuaVec3):(LuaTransform) + + --Returns this [`Transform`] with a new rotation. + with_rotation: function(LuaTransform,LuaQuat):(LuaTransform) + + --Returns this [`Transform`] with a new scale. + with_scale: function(LuaTransform,LuaVec3):(LuaTransform) + + --Returns the 3d affine transformation matrix from this transforms translation, + -- + --rotation, and scale. + compute_matrix: function(LuaTransform):(LuaMat4) + + --Returns the 3d affine transformation matrix from this transforms translation, + -- + --rotation, and scale. + compute_affine: function(LuaTransform):(LuaAffine3A) + + --Get the unit vector in the local `X` direction. + local_x: function(LuaTransform):(LuaVec3) + + --Equivalent to [`-local_x()`][Transform::local_x()] + left: function(LuaTransform):(LuaVec3) + + --Equivalent to [`local_x()`][Transform::local_x()] + right: function(LuaTransform):(LuaVec3) + + --Get the unit vector in the local `Y` direction. + local_y: function(LuaTransform):(LuaVec3) + + --Equivalent to [`local_y()`][Transform::local_y] + up: function(LuaTransform):(LuaVec3) + + --Equivalent to [`-local_y()`][Transform::local_y] + down: function(LuaTransform):(LuaVec3) + + --Get the unit vector in the local `Z` direction. + local_z: function(LuaTransform):(LuaVec3) + + --Equivalent to [`-local_z()`][Transform::local_z] + forward: function(LuaTransform):(LuaVec3) + + --Equivalent to [`local_z()`][Transform::local_z] + back: function(LuaTransform):(LuaVec3) + + --Multiplies `self` with `transform` component by component, returning the + -- + --resulting [`Transform`] + mul_transform: function(LuaTransform,LuaTransform):(LuaTransform) + + --Returns a [`Vec3`] of this [`Transform`] applied to `value`. + mul_vec3: function(LuaTransform,LuaVec3):(LuaVec3) + + -- Mutating methods + --Rotates this [`Transform`] by the given rotation. + -- + -- + -- + --If this [`Transform`] has a parent, the `rotation` is relative to the rotation of the parent. + rotate: function(LuaTransform,LuaQuat):() + + --Rotates this [`Transform`] around the given `axis` by `angle` (in radians). + -- + -- + -- + --If this [`Transform`] has a parent, the `axis` is relative to the rotation of the parent. + rotate_axis: function(LuaTransform,(LuaVec3),(number)):() + + --Rotates this [`Transform`] around the `X` axis by `angle` (in radians). + -- + -- + -- + --If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + rotate_x: function(LuaTransform,number):() + + --Rotates this [`Transform`] around the `Y` axis by `angle` (in radians). + -- + -- + -- + --If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + rotate_y: function(LuaTransform,number):() + + --Rotates this [`Transform`] around the `Z` axis by `angle` (in radians). + -- + -- + -- + --If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + rotate_z: function(LuaTransform,number):() + + --Rotates this [`Transform`] by the given `rotation`. + -- + -- + -- + --The `rotation` is relative to this [`Transform`]'s current rotation. + rotate_local: function(LuaTransform,LuaQuat):() + + --Rotates this [`Transform`] around its local `axis` by `angle` (in radians). + rotate_local_axis: function(LuaTransform,(LuaVec3),(number)):() + + --Rotates this [`Transform`] around its local `X` axis by `angle` (in radians). + rotate_local_x: function(LuaTransform,number):() + + --Rotates this [`Transform`] around its local `Y` axis by `angle` (in radians). + rotate_local_y: function(LuaTransform,number):() + + --Rotates this [`Transform`] around its local `Z` axis by `angle` (in radians). + rotate_local_z: function(LuaTransform,number):() + + --Translates this [`Transform`] around a `point` in space. + -- + -- + -- + --If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. + translate_around: function(LuaTransform,(LuaVec3),(LuaQuat)):() + + --Rotates this [`Transform`] around a `point` in space. + -- + -- + -- + --If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. + rotate_around: function(LuaTransform,(LuaVec3),(LuaQuat)):() + + --Rotates this [`Transform`] so that its local negative `Z` direction is toward + -- + --`target` and its local `Y` direction is toward `up`. + look_at: function(LuaTransform,(LuaVec3),(LuaVec3)):() + + --Changes the `scale` of this [`Transform`], multiplying the current `scale` by + -- + --`scale_factor`. + apply_non_uniform_scale: function(LuaTransform,LuaVec3):() + + -- Pure functions + --Creates a new [`Transform`] at the position `(x, y, z)`. In 2d, the `z` component + -- + --is used for z-ordering elements: higher `z`-value will be in front of lower + -- + --`z`-value. + from_xyz: function((number),(number),(number)):(LuaTransform) + + --Creates a new identity [`Transform`], with no translation, rotation, and a scale of 1 on + -- + --all axes. + identity: function():(LuaTransform) + + --Extracts the translation, rotation, and scale from `matrix`. It must be a 3d affine + -- + --transformation matrix. + from_matrix: function(LuaMat4):(LuaTransform) + + --Creates a new [`Transform`], with `translation`. Rotation will be 0 and scale 1 on + -- + --all axes. + from_translation: function(LuaVec3):(LuaTransform) + + --Creates a new [`Transform`], with `rotation`. Translation will be 0 and scale 1 on + -- + --all axes. + from_rotation: function(LuaQuat):(LuaTransform) + + --Creates a new [`Transform`], with `scale`. Translation will be 0 and rotation 0 on + -- + --all axes. + from_scale: function(LuaVec3):(LuaTransform) + + -- Meta methods + metamethod __tostring: function(LuaTransform):(string) + + -- Meta functions + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaTransform`]. + record LuaTransformClass + userdata + + -- Pure functions + --Creates a new [`Transform`] at the position `(x, y, z)`. In 2d, the `z` component + -- + --is used for z-ordering elements: higher `z`-value will be in front of lower + -- + --`z`-value. + from_xyz: function((number),(number),(number)):(LuaTransform) + + --Creates a new identity [`Transform`], with no translation, rotation, and a scale of 1 on + -- + --all axes. + identity: function():(LuaTransform) + + --Extracts the translation, rotation, and scale from `matrix`. It must be a 3d affine + -- + --transformation matrix. + from_matrix: function(LuaMat4):(LuaTransform) + + --Creates a new [`Transform`], with `translation`. Rotation will be 0 and scale 1 on + -- + --all axes. + from_translation: function(LuaVec3):(LuaTransform) + + --Creates a new [`Transform`], with `rotation`. Translation will be 0 and scale 1 on + -- + --all axes. + from_rotation: function(LuaQuat):(LuaTransform) + + --Creates a new [`Transform`], with `scale`. Translation will be 0 and rotation 0 on + -- + --all axes. + from_scale: function(LuaVec3):(LuaTransform) + + -- Meta functions + metamethod __mul: function((any),(any)):(any) + + + end +--Describe the position of an entity relative to the reference frame. +-- +-- +-- +--* To place or move an entity, you should set its [`Transform`]. +-- +--* To get the global transform of an entity, you should get its [`GlobalTransform`]. +-- +--* For transform hierarchies to work correctly, you must have both a [`Transform`] and a [`GlobalTransform`]. +-- +-- * You may use the [`TransformBundle`](crate::TransformBundle) to guarantee this. +-- +-- +-- +--## [`Transform`] and [`GlobalTransform`] +-- +-- +-- +--[`Transform`] is the position of an entity relative to its parent position, or the reference +-- +--frame if it doesn't have a [`Parent`](bevy_hierarchy::Parent). +-- +-- +-- +--[`GlobalTransform`] is the position of an entity relative to the reference frame. +-- +-- +-- +--[`GlobalTransform`] is updated from [`Transform`] in the system +-- +--[`transform_propagate_system`](crate::transform_propagate_system). +-- +-- +-- +--This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you +-- +--update the [`Transform`] of an entity in this stage or after, you will notice a 1 frame lag +-- +--before the [`GlobalTransform`] is updated. +-- + record LuaGlobalTransform + userdata + + -- Pure methods + --Returns the 3d affine transformation matrix as a [`Mat4`]. + compute_matrix: function(LuaGlobalTransform):(LuaMat4) + + --Returns the 3d affine transformation matrix as an [`Affine3A`]. + affine: function(LuaGlobalTransform):(LuaAffine3A) + + --Returns the transformation as a [`Transform`]. + -- + -- + -- + --The transform is expected to be non-degenerate and without shearing, or the output + -- + --will be invalid. + compute_transform: function(LuaGlobalTransform):(LuaTransform) + + --Return the local right vector (X). + right: function(LuaGlobalTransform):(LuaVec3) + + --Return the local left vector (-X). + left: function(LuaGlobalTransform):(LuaVec3) + + --Return the local up vector (Y). + up: function(LuaGlobalTransform):(LuaVec3) + + --Return the local down vector (-Y). + down: function(LuaGlobalTransform):(LuaVec3) + + --Return the local back vector (Z). + back: function(LuaGlobalTransform):(LuaVec3) + + --Return the local forward vector (-Z). + forward: function(LuaGlobalTransform):(LuaVec3) + + --Get the translation as a [`Vec3`]. + translation: function(LuaGlobalTransform):(LuaVec3) + + --Get the translation as a [`Vec3A`]. + translation_vec3a: function(LuaGlobalTransform):(LuaVec3A) + + --Get an upper bound of the radius from the given `extents`. + radius_vec3a: function(LuaGlobalTransform,LuaVec3A):(number) + + --Returns a [`Vec3`] of this [`Transform`] applied to `value`. + mul_vec3: function(LuaGlobalTransform,LuaVec3):(LuaVec3) + + --Multiplies `self` with `transform` component by component, returning the + -- + --resulting [`GlobalTransform`] + mul_transform: function(LuaGlobalTransform,LuaTransform):(LuaGlobalTransform) + + -- Pure functions + --Creates a new identity [`GlobalTransform`], that maps all points in space to themselves. + identity: function():(LuaGlobalTransform) + + -- Meta methods + metamethod __tostring: function(LuaGlobalTransform):(string) + + -- Meta functions + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaGlobalTransform`]. + record LuaGlobalTransformClass + userdata + + -- Pure functions + --Creates a new identity [`GlobalTransform`], that maps all points in space to themselves. + identity: function():(LuaGlobalTransform) + + -- Meta functions + metamethod __mul: function((any),(any)):(any) + + + end +--An ambient light, which lights the entire scene equally. +-- + record LuaAmbientLight + userdata + + -- Fields + color : LuaColor + + -- A direct scale factor multiplied with `color` before being passed to the shader. + brightness : number + + -- Meta methods + metamethod __tostring: function(LuaAmbientLight):(string) + + + end + record LuaCubemapVisibleEntities + userdata + + -- Meta methods + metamethod __tostring: function(LuaCubemapVisibleEntities):(string) + + + end +--A Directional light. +-- +-- +-- +--Directional lights don't exist in reality but they are a good +-- +--approximation for light sources VERY far away, like the sun or +-- +--the moon. +-- +-- +-- +--Valid values for `illuminance` are: +-- +-- +-- +--| Illuminance (lux) | Surfaces illuminated by | +-- +--|-------------------|------------------------------------------------| +-- +--| 0.0001 | Moonless, overcast night sky (starlight) | +-- +--| 0.002 | Moonless clear night sky with airglow | +-- +--| 0.05–0.3 | Full moon on a clear night | +-- +--| 3.4 | Dark limit of civil twilight under a clear sky | +-- +--| 20–50 | Public areas with dark surroundings | +-- +--| 50 | Family living room lights | +-- +--| 80 | Office building hallway/toilet lighting | +-- +--| 100 | Very dark overcast day | +-- +--| 150 | Train station platforms | +-- +--| 320–500 | Office lighting | +-- +--| 400 | Sunrise or sunset on a clear day. | +-- +--| 1000 | Overcast day; typical TV studio lighting | +-- +--| 10,000–25,000 | Full daylight (not direct sun) | +-- +--| 32,000–100,000 | Direct sunlight | +-- +-- +-- +--Source: [Wikipedia](https://en.wikipedia.org/wiki/Lux) +-- + record LuaDirectionalLight + userdata + + -- Fields + color : LuaColor + + -- Illuminance in lux + illuminance : number + + shadows_enabled : boolean + + shadow_projection : LuaOrthographicProjection + + shadow_depth_bias : number + + -- A bias applied along the direction of the fragment's surface normal. It is scaled to the + -- + -- shadow map's texel size so that it is automatically adjusted to the orthographic projection. + shadow_normal_bias : number + + -- Meta methods + metamethod __tostring: function(LuaDirectionalLight):(string) + + + end + record LuaDirectionalLightShadowMap + userdata + + -- Fields + size : integer + + -- Meta methods + metamethod __tostring: function(LuaDirectionalLightShadowMap):(string) + + + end +--Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not cast shadows. +-- + record LuaNotShadowCaster + userdata + + + end +--Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not receive shadows. +-- + record LuaNotShadowReceiver + userdata + + + end +--A light that emits light in all directions from a central point. +-- +-- +-- +--Real-world values for `intensity` (luminous power in lumens) based on the electrical power +-- +--consumption of the type of real-world light are: +-- +-- +-- +--| Luminous Power (lumen) (i.e. the intensity member) | Incandescent non-halogen (Watts) | Incandescent halogen (Watts) | Compact fluorescent (Watts) | LED (Watts | +-- +--|------|-----|----|--------|-------| +-- +--| 200 | 25 | | 3-5 | 3 | +-- +--| 450 | 40 | 29 | 9-11 | 5-8 | +-- +--| 800 | 60 | | 13-15 | 8-12 | +-- +--| 1100 | 75 | 53 | 18-20 | 10-16 | +-- +--| 1600 | 100 | 72 | 24-28 | 14-17 | +-- +--| 2400 | 150 | | 30-52 | 24-30 | +-- +--| 3100 | 200 | | 49-75 | 32 | +-- +--| 4000 | 300 | | 75-100 | 40.5 | +-- +-- +-- +--Source: [Wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit)#Lighting) +-- + record LuaPointLight + userdata + + -- Fields + color : LuaColor + + intensity : number + + range : number + + radius : number + + shadows_enabled : boolean + + shadow_depth_bias : number + + -- A bias applied along the direction of the fragment's surface normal. It is scaled to the + -- + -- shadow map's texel size so that it can be small close to the camera and gets larger further + -- + -- away. + shadow_normal_bias : number + + -- Meta methods + metamethod __tostring: function(LuaPointLight):(string) + + + end + record LuaPointLightShadowMap + userdata + + -- Fields + size : integer + + -- Meta methods + metamethod __tostring: function(LuaPointLightShadowMap):(string) + + + end +--Alpha mode +-- + record LuaAlphaMode + userdata + + -- Meta methods + metamethod __tostring: function(LuaAlphaMode):(string) + + + end +--Controls whether an entity should rendered in wireframe-mode if the [`WireframePlugin`] is enabled +-- + record LuaWireframe + userdata + + -- Meta methods + metamethod __tostring: function(LuaWireframe):(string) + + + end + record LuaWireframeConfig + userdata + + -- Fields + -- Whether to show wireframes for all meshes. If `false`, only meshes with a [Wireframe] component will be rendered. + global : boolean + + -- Meta methods + metamethod __tostring: function(LuaWireframeConfig):(string) + + + end +--The depth clear operation to perform for the main 3d pass. +-- + record LuaCamera3dDepthLoadOp + userdata + + -- Meta methods + metamethod __tostring: function(LuaCamera3dDepthLoadOp):(string) + + + end +--When used as a resource, sets the color that is used to clear the screen between frames. +-- +-- +-- +--This color appears as the "background" color for simple apps, when +-- +--there are portions of the screen with nothing rendered. +-- + record LuaClearColor + userdata + + -- Fields + _0 : LuaColor + + -- Meta methods + metamethod __tostring: function(LuaClearColor):(string) + + + end + record LuaClearColorConfig + userdata + + -- Meta methods + metamethod __tostring: function(LuaClearColorConfig):(string) + + + end + record LuaCamera2d + userdata + + -- Fields + clear_color : LuaClearColorConfig + + + end +--Configuration for the "main 3d render graph". +-- + record LuaCamera3d + userdata + + -- Fields + -- The clear color operation to perform for the main 3d pass. + clear_color : LuaClearColorConfig + + -- The depth clear operation to perform for the main 3d pass. + depth_load_op : LuaCamera3dDepthLoadOp + + + end +--How a sprite is positioned relative to its [`Transform`](bevy_transform::components::Transform). +-- +--It defaults to `Anchor::Center`. +-- + record LuaAnchor + userdata + + -- Pure methods + as_vec: function(LuaAnchor):(LuaVec2) + + -- Meta methods + metamethod __tostring: function(LuaAnchor):(string) + + + end +--Component for rendering with meshes in the 2d pipeline, usually with a [2d material](crate::Material2d) such as [`ColorMaterial`](crate::ColorMaterial). +-- +-- +-- +--It wraps a [`Handle`] to differentiate from the 3d pipelines which use the handles directly as components +-- + record LuaMesh2dHandle + userdata + + -- Fields + _0 : ReflectedValue + + -- Meta methods + metamethod __tostring: function(LuaMesh2dHandle):(string) + + + end + record LuaTextureAtlasSprite + userdata + + -- Fields + color : LuaColor + + index : integer + + flip_x : boolean + + flip_y : boolean + + -- An optional custom size for the sprite that will be used when rendering, instead of the size + -- + -- of the sprite's image in the atlas + custom_size : ReflectedValue + + anchor : LuaAnchor + + -- Pure functions + new: function(integer):(LuaTextureAtlasSprite) + + -- Meta methods + metamethod __tostring: function(LuaTextureAtlasSprite):(string) + + + end +--Collection of static methods for [`LuaTextureAtlasSprite`]. + record LuaTextureAtlasSpriteClass + userdata + + -- Pure functions + new: function(integer):(LuaTextureAtlasSprite) + + + end + record LuaSprite + userdata + + -- Fields + -- The sprite's color tint + color : LuaColor + + -- Flip the sprite along the `X` axis + flip_x : boolean + + -- Flip the sprite along the `Y` axis + flip_y : boolean + + -- An optional custom size for the sprite that will be used when rendering, instead of the size + -- + -- of the sprite's image + custom_size : ReflectedValue + + -- [`Anchor`] point of the sprite in the world + anchor : LuaAnchor + + -- Meta methods + metamethod __tostring: function(LuaSprite):(string) + + + end +--A rectangle defined by two points. There is no defined origin, so 0,0 could be anywhere +-- +--(top-left, bottom-left, etc) +-- + record LuaRect + userdata + + -- Fields + -- The beginning point of the rect + min : LuaVec2 + + -- The ending point of the rect + max : LuaVec2 + + -- Pure methods + width: function(LuaRect):(number) + + height: function(LuaRect):(number) + + size: function(LuaRect):(LuaVec2) + + -- Meta methods + metamethod __tostring: function(LuaRect):(string) + + + end +--Describes which rendering layers an entity belongs to. +-- +-- +-- +--Cameras with this component will only render entities with intersecting +-- +--layers. +-- +-- +-- +--There are 32 layers numbered `0` - [`TOTAL_LAYERS`](RenderLayers::TOTAL_LAYERS). Entities may +-- +--belong to one or more layers, or no layer at all. +-- +-- +-- +--The [`Default`] instance of `RenderLayers` contains layer `0`, the first layer. +-- +-- +-- +--An entity with this component without any layers is invisible. +-- +-- +-- +--Entities without this component belong to layer `0`. +-- + record LuaRenderLayers + userdata + + -- Pure methods + --Determine if a `RenderLayers` intersects another. + -- + -- + -- + --`RenderLayers`s intersect if they share any common layers. + -- + -- + -- + --A `RenderLayers` with no layers will not match any other + -- + --`RenderLayers`, even another with no layers. + intersects: function(LuaRenderLayers,LuaRenderLayers):(boolean) + + -- Pure functions + --Create a new `RenderLayers` that belongs to all layers. + all: function():(LuaRenderLayers) + + --Create a new `RenderLayers` that belongs to no layers. + none: function():(LuaRenderLayers) + + -- Meta methods + metamethod __tostring: function(LuaRenderLayers):(string) + + + end +--Collection of static methods for [`LuaRenderLayers`]. + record LuaRenderLayersClass + userdata + + -- Pure functions + --Create a new `RenderLayers` that belongs to all layers. + all: function():(LuaRenderLayers) + + --Create a new `RenderLayers` that belongs to no layers. + none: function():(LuaRenderLayers) + + + end +--User indication of whether an entity is visible. Propagates down the entity hierarchy. +-- +--If an entity is hidden in this way, all [`Children`] (and all of their children and so on) will also be hidden. +-- +--This is done by setting the values of their [`ComputedVisibility`] component. +-- + record LuaVisibility + userdata + + -- Fields + -- Indicates whether this entity is visible. Hidden values will propagate down the entity hierarchy. + -- + -- If this entity is hidden, all of its descendants will be hidden as well. See [`Children`] and [`Parent`] for + -- + -- hierarchy info. + is_visible : boolean + + -- Pure functions + --Creates a new [`Visibility`], set as visible + visible: function():(LuaVisibility) + + -- Meta methods + metamethod __tostring: function(LuaVisibility):(string) + + + end +--Collection of static methods for [`LuaVisibility`]. + record LuaVisibilityClass + userdata + + -- Pure functions + --Creates a new [`Visibility`], set as visible + visible: function():(LuaVisibility) + + + end +--Collection of entities visible from the current view. +-- +-- +-- +--This component contains all entities which are visible from the currently +-- +--rendered view. The collection is updated automatically by the [`check_visibility()`] +-- +--system, and renderers can use it to optimize rendering of a particular view, to +-- +--prevent drawing items not visible from that view. +-- +-- +-- +--This component is intended to be attached to the same entity as the [`Camera`] and +-- +--the [`Frustum`] defining the view. +-- +-- +-- +--Currently this component is ignored by the sprite renderer, so sprite rendering +-- +--is not optimized per view. +-- + record LuaVisibleEntities + userdata + + -- Pure methods + len: function(LuaVisibleEntities):(integer) + + is_empty: function(LuaVisibleEntities):(boolean) + + -- Meta methods + metamethod __tostring: function(LuaVisibleEntities):(string) + + + end +--Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering +-- + record LuaComputedVisibility + userdata + + -- Pure methods + --Whether this entity is visible to something this frame. This is true if and only if [`Self::is_visible_in_hierarchy`] and [`Self::is_visible_in_view`] + -- + --are true. This is the canonical method to call to determine if an entity should be drawn. + -- + --This value is updated in [`CoreStage::PostUpdate`] during the [`VisibilitySystems::CheckVisibility`] system label. Reading it from the + -- + --[`CoreStage::Update`] stage will yield the value from the previous frame. + is_visible: function(LuaComputedVisibility):(boolean) + + --Whether this entity is visible in the entity hierarchy, which is determined by the [`Visibility`] component. + -- + --This takes into account "visibility inheritance". If any of this entity's ancestors (see [`Parent`]) are hidden, this entity + -- + --will be hidden as well. This value is updated in the [`CoreStage::PostUpdate`] stage in the + -- + --[`VisibilitySystems::VisibilityPropagate`] system label. + is_visible_in_hierarchy: function(LuaComputedVisibility):(boolean) + + --Whether this entity is visible in _any_ view (Cameras, Lights, etc). Each entity type (and view type) should choose how to set this + -- + --value. For cameras and drawn entities, this will take into account [`RenderLayers`]. + -- + -- + -- + --This value is reset to `false` every frame in [`VisibilitySystems::VisibilityPropagate`] during [`CoreStage::PostUpdate`]. + -- + --Each entity type then chooses how to set this field in the [`CoreStage::PostUpdate`] stage in the + -- + --[`VisibilitySystems::CheckVisibility`] system label. Meshes might use frustum culling to decide if they are visible in a view. + -- + --Other entities might just set this to `true` every frame. + is_visible_in_view: function(LuaComputedVisibility):(boolean) + + -- Mutating methods + --Sets `is_visible_in_view` to `true`. This is not reversible for a given frame, as it encodes whether or not this is visible in + -- + --_any_ view. This will be automatically reset to `false` every frame in [`VisibilitySystems::VisibilityPropagate`] and then set + -- + --to the proper value in [`VisibilitySystems::CheckVisibility`]. This should _only_ be set in systems with the [`VisibilitySystems::CheckVisibility`] + -- + --label. Don't call this unless you are defining a custom visibility system. For normal user-defined entity visibility, see [`Visibility`]. + set_visible_in_view: function(LuaComputedVisibility):() + + -- Pure functions + --Creates a new [`ComputedVisibility`], set as not visible + not_visible: function():(LuaComputedVisibility) + + -- Meta methods + metamethod __tostring: function(LuaComputedVisibility):(string) + + + end +--Collection of static methods for [`LuaComputedVisibility`]. + record LuaComputedVisibilityClass + userdata + + -- Pure functions + --Creates a new [`ComputedVisibility`], set as not visible + not_visible: function():(LuaComputedVisibility) + + + end + record LuaSkinnedMesh + userdata + + -- Fields + inverse_bindposes : ReflectedValue + + joints : ReflectedValue + + -- Meta methods + metamethod __tostring: function(LuaSkinnedMesh):(string) + + + end + record LuaScalingMode + userdata + + -- Meta methods + metamethod __tostring: function(LuaScalingMode):(string) + + + end + record LuaWindowOrigin + userdata + + -- Meta methods + metamethod __tostring: function(LuaWindowOrigin):(string) + + + end + record LuaColor + userdata + + -- Pure methods + --Get red in sRGB colorspace. + r: function(LuaColor):(number) + + --Get green in sRGB colorspace. + g: function(LuaColor):(number) + + --Get blue in sRGB colorspace. + b: function(LuaColor):(number) + + --Get alpha. + a: function(LuaColor):(number) + + --Converts a `Color` to variant `Color::Rgba` + as_rgba: function(LuaColor):(LuaColor) + + --Converts a `Color` to variant `Color::RgbaLinear` + as_rgba_linear: function(LuaColor):(LuaColor) + + --Converts a `Color` to variant `Color::Hsla` + as_hsla: function(LuaColor):(LuaColor) + + --Converts `Color` to a `u32` from sRGB colorspace. + -- + -- + -- + --Maps the RGBA channels in RGBA order to a little-endian byte array (GPUs are little-endian). + -- + --`A` will be the most significant byte and `R` the least significant. + as_rgba_u32: function(LuaColor):(integer) + + --Converts Color to a u32 from linear RGB colorspace. + -- + -- + -- + --Maps the RGBA channels in RGBA order to a little-endian byte array (GPUs are little-endian). + -- + --`A` will be the most significant byte and `R` the least significant. + as_linear_rgba_u32: function(LuaColor):(integer) + + -- Pure functions + --New `Color` from sRGB colorspace. + rgb: function((number),(number),(number)):(LuaColor) + + --New `Color` from sRGB colorspace. + rgba: function((number),(number),(number),(number)):(LuaColor) + + --New `Color` from linear RGB colorspace. + rgb_linear: function((number),(number),(number)):(LuaColor) + + --New `Color` from linear RGB colorspace. + rgba_linear: function((number),(number),(number),(number)):(LuaColor) + + --New `Color` with HSL representation in sRGB colorspace. + hsl: function((number),(number),(number)):(LuaColor) + + --New `Color` with HSL representation in sRGB colorspace. + hsla: function((number),(number),(number),(number)):(LuaColor) + + --New `Color` from sRGB colorspace. + rgb_u8: function((integer),(integer),(integer)):(LuaColor) + + --New `Color` from sRGB colorspace. + rgba_u8: function((integer),(integer),(integer),(integer)):(LuaColor) + + -- Meta methods + metamethod __tostring: function(LuaColor):(string) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaColor`]. + record LuaColorClass + userdata + + -- Pure functions + --New `Color` from sRGB colorspace. + rgb: function((number),(number),(number)):(LuaColor) + + --New `Color` from sRGB colorspace. + rgba: function((number),(number),(number),(number)):(LuaColor) + + --New `Color` from linear RGB colorspace. + rgb_linear: function((number),(number),(number)):(LuaColor) + + --New `Color` from linear RGB colorspace. + rgba_linear: function((number),(number),(number),(number)):(LuaColor) + + --New `Color` with HSL representation in sRGB colorspace. + hsl: function((number),(number),(number)):(LuaColor) + + --New `Color` with HSL representation in sRGB colorspace. + hsla: function((number),(number),(number),(number)):(LuaColor) + + --New `Color` from sRGB colorspace. + rgb_u8: function((integer),(integer),(integer)):(LuaColor) + + --New `Color` from sRGB colorspace. + rgba_u8: function((integer),(integer),(integer),(integer)):(LuaColor) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--An Axis-Aligned Bounding Box +-- + record LuaAabb + userdata + + -- Fields + center : LuaVec3A + + half_extents : LuaVec3A + + -- Pure methods + min: function(LuaAabb):(LuaVec3A) + + max: function(LuaAabb):(LuaVec3A) + + -- Pure functions + from_min_max: function((LuaVec3),(LuaVec3)):(LuaAabb) + + -- Meta methods + metamethod __tostring: function(LuaAabb):(string) + + + end +--Collection of static methods for [`LuaAabb`]. + record LuaAabbClass + userdata + + -- Pure functions + from_min_max: function((LuaVec3),(LuaVec3)):(LuaAabb) + + + end + record LuaCubemapFrusta + userdata + + -- Meta methods + metamethod __tostring: function(LuaCubemapFrusta):(string) + + + end +--A frustum defined by the 6 containing planes +-- +--Planes are ordered left, right, top, bottom, near, far +-- +--Normals point into the contained volume +-- + record LuaFrustum + userdata + + -- Pure methods + intersects_obb: function(LuaFrustum,(LuaAabb),(LuaMat4),(boolean)):(boolean) + + -- Pure functions + from_view_projection: function((LuaMat4),(LuaVec3),(LuaVec3),(number)):(LuaFrustum) + + -- Meta methods + metamethod __tostring: function(LuaFrustum):(string) + + + end +--Collection of static methods for [`LuaFrustum`]. + record LuaFrustumClass + userdata + + -- Pure functions + from_view_projection: function((LuaMat4),(LuaVec3),(LuaVec3),(number)):(LuaFrustum) + + + end +--Configuration resource for [Multi-Sample Anti-Aliasing](https://en.wikipedia.org/wiki/Multisample_anti-aliasing). +-- +-- +-- +--# Example +-- +--``` +-- +--# use bevy_app::prelude::App; +-- +--# use bevy_render::prelude::Msaa; +-- +--App::new() +-- +-- .insert_resource(Msaa { samples: 4 }) +-- +-- .run(); +-- +--``` +-- + record LuaMsaa + userdata + + -- Fields + -- The number of samples to run for Multi-Sample Anti-Aliasing. Higher numbers result in + -- + -- smoother edges. + -- + -- Defaults to 4. + -- + -- + -- + -- Note that WGPU currently only supports 1 or 4 samples. + -- + -- Ultimately we plan on supporting whatever is natively supported on a given device. + -- + -- Check out this issue for more info: + samples : integer + + + end + record LuaCamera + userdata + + -- Fields + -- If set, this camera will render to the given [`Viewport`] rectangle within the configured [`RenderTarget`]. + viewport : ReflectedValue + + -- Cameras with a lower priority will be rendered before cameras with a higher priority. + priority : integer + + -- If this is set to true, this camera will be rendered to its specified [`RenderTarget`]. If false, this + -- + -- camera will not be rendered. + is_active : boolean + + -- The method used to calculate this camera's depth. This will be used for projections and visibility. + depth_calculation : LuaDepthCalculation + + -- The "target" that this camera will render to. + target : LuaRenderTarget + + -- Pure methods + --The projection matrix computed using this camera's [`CameraProjection`]. + projection_matrix: function(LuaCamera):(LuaMat4) + + -- Meta methods + metamethod __tostring: function(LuaCamera):(string) + + + end +--The "target" that a [`Camera`] will render to. For example, this could be a [`Window`](bevy_window::Window) +-- +--swapchain or an [`Image`]. +-- + record LuaRenderTarget + userdata + + -- Meta methods + metamethod __tostring: function(LuaRenderTarget):(string) + + + end +--Render viewport configuration for the [`Camera`] component. +-- +-- +-- +--The viewport defines the area on the render target to which the camera renders its image. +-- +--You can overlay multiple cameras in a single window using viewports to create effects like +-- +--split screen, minimaps, and character viewers. +-- + record LuaViewport + userdata + + -- Fields + -- The physical position to render this viewport to within the [`RenderTarget`] of this [`Camera`]. + -- + -- (0,0) corresponds to the top-left corner + physical_position : LuaUVec2 + + -- The physical size of the viewport rectangle to render to within the [`RenderTarget`] of this [`Camera`]. + -- + -- The origin of the rectangle is in the top-left corner. + physical_size : LuaUVec2 + + -- The minimum and maximum depth to render (on a scale from 0.0 to 1.0). + depth : ReflectedValue + + -- Meta methods + metamethod __tostring: function(LuaViewport):(string) + + + end +--A configurable [`CameraProjection`] that can select its projection type at runtime. +-- + record LuaProjection + userdata + + -- Pure methods + get_projection_matrix: function(LuaProjection):(LuaMat4) + + depth_calculation: function(LuaProjection):(LuaDepthCalculation) + + far: function(LuaProjection):(number) + + -- Mutating methods + update: function(LuaProjection,(number),(number)):() + + -- Meta methods + metamethod __tostring: function(LuaProjection):(string) + + + end + record LuaOrthographicProjection + userdata + + -- Fields + left : number + + right : number + + bottom : number + + top : number + + near : number + + _far : number + + window_origin : LuaWindowOrigin + + scaling_mode : LuaScalingMode + + scale : number + + _depth_calculation : LuaDepthCalculation + + -- Pure methods + get_projection_matrix: function(LuaOrthographicProjection):(LuaMat4) + + depth_calculation: function(LuaOrthographicProjection):(LuaDepthCalculation) + + far: function(LuaOrthographicProjection):(number) + + -- Mutating methods + update: function(LuaOrthographicProjection,(number),(number)):() + + -- Meta methods + metamethod __tostring: function(LuaOrthographicProjection):(string) + + + end + record LuaPerspectiveProjection + userdata + + -- Fields + fov : number + + aspect_ratio : number + + near : number + + _far : number + + -- Pure methods + get_projection_matrix: function(LuaPerspectiveProjection):(LuaMat4) + + depth_calculation: function(LuaPerspectiveProjection):(LuaDepthCalculation) + + far: function(LuaPerspectiveProjection):(number) + + -- Mutating methods + update: function(LuaPerspectiveProjection,(number),(number)):() + + -- Meta methods + metamethod __tostring: function(LuaPerspectiveProjection):(string) + + + end + record LuaDepthCalculation + userdata + + -- Meta methods + metamethod __tostring: function(LuaDepthCalculation):(string) + + + end +--Configures the [`RenderGraph`](crate::render_graph::RenderGraph) name assigned to be run for a given [`Camera`] entity. +-- + record LuaCameraRenderGraph + userdata + + + end +--Collection of static methods for [`LuaCameraRenderGraph`]. + record LuaCameraRenderGraphClass + userdata + + + end +--An unique identifier to an asset path. +-- + record LuaAssetPathId + userdata + + -- Pure methods + --Gets the id of the source path. + source_path_id: function(LuaAssetPathId):(LuaSourcePathId) + + --Gets the id of the sub-asset label. + label_id: function(LuaAssetPathId):(LuaLabelId) + + -- Meta methods + metamethod __tostring: function(LuaAssetPathId):(string) + + + end +--An unique identifier to a sub-asset label. +-- + record LuaLabelId + userdata + + -- Meta methods + metamethod __tostring: function(LuaLabelId):(string) + + + end +--An unique identifier to the source path of an asset. +-- + record LuaSourcePathId + userdata + + -- Meta methods + metamethod __tostring: function(LuaSourcePathId):(string) + + + end +--A unique, stable asset id. +-- + record LuaHandleId + userdata + + -- Meta methods + metamethod __tostring: function(LuaHandleId):(string) + + + end +--Collection of static methods for [`LuaHandleId`]. + record LuaHandleIdClass + userdata + + + end +--A 2-dimensional vector. +-- + record LuaVec2 + userdata + + -- Fields + x : number + + y : number + + -- Pure methods + --Creates a 3D vector from `self` and the given `z` value. + extend: function(LuaVec2,number):(LuaVec3) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaVec2,LuaVec2):(number) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaVec2,LuaVec2):(LuaVec2) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaVec2,LuaVec2):(LuaVec2) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaVec2,(LuaVec2),(LuaVec2)):(LuaVec2) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaVec2):(number) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaVec2):(number) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaVec2,LuaVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaVec2,LuaVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaVec2,LuaVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaVec2,LuaVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaVec2,LuaVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaVec2,LuaVec2):(LuaBVec2) + + --Returns a vector containing the absolute value of each element of `self`. + abs: function(LuaVec2):(LuaVec2) + + --Returns a vector with elements representing the sign of `self`. + -- + -- + -- + --- `1.0` if the number is positive, `+0.0` or `INFINITY` + -- + --- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + -- + --- `NAN` if the number is `NAN` + signum: function(LuaVec2):(LuaVec2) + + --Returns `true` if, and only if, all elements are finite. If any element is either + -- + --`NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaVec2):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaVec2):(boolean) + + --Performs `is_nan` on each element of self, returning a vector mask of the results. + -- + -- + -- + --In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask: function(LuaVec2):(LuaBVec2) + + --Computes the length of `self`. + length: function(LuaVec2):(number) + + --Computes the squared length of `self`. + -- + -- + -- + --This is faster than `length()` as it avoids a square root operation. + length_squared: function(LuaVec2):(number) + + --Computes `1.0 / length()`. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero. + length_recip: function(LuaVec2):(number) + + --Computes the Euclidean distance between two points in space. + distance: function(LuaVec2,LuaVec2):(number) + + --Compute the squared euclidean distance between two points in space. + distance_squared: function(LuaVec2,LuaVec2):(number) + + --Returns `self` normalized to length 1.0. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero, nor very close to zero. + -- + -- + -- + --See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + -- + -- + -- + --Panics + -- + -- + -- + --Will panic if `self` is zero length when `glam_assert` is enabled. + normalize: function(LuaVec2):(LuaVec2) + + --Returns `self` normalized to length 1.0 if possible, else returns zero. + -- + -- + -- + --In particular, if the input is zero (or very close to zero), or non-finite, + -- + --the result of this operation will be zero. + -- + -- + -- + --See also [`Self::try_normalize`]. + normalize_or_zero: function(LuaVec2):(LuaVec2) + + --Returns whether `self` is length `1.0` or not. + -- + -- + -- + --Uses a precision threshold of `1e-6`. + is_normalized: function(LuaVec2):(boolean) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto: function(LuaVec2,LuaVec2):(LuaVec2) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from: function(LuaVec2,LuaVec2):(LuaVec2) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized: function(LuaVec2,LuaVec2):(LuaVec2) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized: function(LuaVec2,LuaVec2):(LuaVec2) + + --Returns a vector containing the nearest integer to a number for each element of `self`. + -- + --Round half-way cases away from 0.0. + round: function(LuaVec2):(LuaVec2) + + --Returns a vector containing the largest integer less than or equal to a number for each + -- + --element of `self`. + floor: function(LuaVec2):(LuaVec2) + + --Returns a vector containing the smallest integer greater than or equal to a number for + -- + --each element of `self`. + ceil: function(LuaVec2):(LuaVec2) + + --Returns a vector containing the fractional part of the vector, e.g. `self - + -- + --self.floor()`. + -- + -- + -- + --Note that this is fast but not precise for large numbers. + fract: function(LuaVec2):(LuaVec2) + + --Returns a vector containing `e^self` (the exponential function) for each element of + -- + --`self`. + exp: function(LuaVec2):(LuaVec2) + + --Returns a vector containing each element of `self` raised to the power of `n`. + powf: function(LuaVec2,number):(LuaVec2) + + --Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip: function(LuaVec2):(LuaVec2) + + --Performs a linear interpolation between `self` and `rhs` based on the value `s`. + -- + -- + -- + --When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + -- + --will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + -- + --extrapolated. + lerp: function(LuaVec2,(LuaVec2),(number)):(LuaVec2) + + --Returns true if the absolute difference of all elements between `self` and `rhs` is + -- + --less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two vectors contain similar elements. It works best when + -- + --comparing with a known value. The `max_abs_diff` that should be used used depends on + -- + --the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaVec2,(LuaVec2),(number)):(boolean) + + --Returns a vector with a length no less than `min` and no more than `max` + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length: function(LuaVec2,(number),(number)):(LuaVec2) + + --Returns a vector with a length no more than `max` + clamp_length_max: function(LuaVec2,number):(LuaVec2) + + --Returns a vector with a length no less than `min` + clamp_length_min: function(LuaVec2,number):(LuaVec2) + + --Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + -- + --error, yielding a more accurate result than an unfused multiply-add. + -- + -- + -- + --Using `mul_add` *may* be more performant than an unfused multiply-add if the target + -- + --architecture has a dedicated fma CPU instruction. However, this is not always true, + -- + --and will be heavily dependant on designing algorithms with specific target hardware in + -- + --mind. + mul_add: function(LuaVec2,(LuaVec2),(LuaVec2)):(LuaVec2) + + --Returns the angle (in radians) between `self` and `rhs`. + -- + -- + -- + --The input vectors do not need to be unit length however they must be non-zero. + angle_between: function(LuaVec2,LuaVec2):(number) + + --Returns a vector that is equal to `self` rotated by 90 degrees. + perp: function(LuaVec2):(LuaVec2) + + --The perpendicular dot product of `self` and `rhs`. + -- + --Also known as the wedge product, 2D cross product, and determinant. + perp_dot: function(LuaVec2,LuaVec2):(number) + + --Returns `rhs` rotated by the angle of `self`. If `self` is normalized, + -- + --then this just rotation. This is what you usually want. Otherwise, + -- + --it will be like a rotation with a multiplication by `self`'s length. + rotate: function(LuaVec2,LuaVec2):(LuaVec2) + + --Casts all elements of `self` to `f64`. + as_dvec2: function(LuaVec2):(LuaDVec2) + + --Casts all elements of `self` to `i32`. + as_ivec2: function(LuaVec2):(LuaIVec2) + + --Casts all elements of `self` to `u32`. + as_uvec2: function(LuaVec2):(LuaUVec2) + + -- Pure functions + --Creates a new vector. + new: function((number),(number)):(LuaVec2) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaVec2) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec2),(LuaVec2),(LuaVec2)):(LuaVec2) + + --Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in + -- + --conjunction with the `rotate` method, e.g. `Vec2::from_angle(PI).rotate(Vec2::Y)` will + -- + --create the vector [-1, 0] and rotate `Vec2::Y` around it returning `-Vec2::Y`. + from_angle: function(number):(LuaVec2) + + -- Meta methods + metamethod __tostring: function(LuaVec2):(string) + + metamethod __unm: function(LuaVec2):(LuaVec2) + + metamethod __index: function(LuaVec2,integer):(number) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaVec2,(integer),(number)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaVec2`]. + record LuaVec2Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((number),(number)):(LuaVec2) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaVec2) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec2),(LuaVec2),(LuaVec2)):(LuaVec2) + + --Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in + -- + --conjunction with the `rotate` method, e.g. `Vec2::from_angle(PI).rotate(Vec2::Y)` will + -- + --create the vector [-1, 0] and rotate `Vec2::Y` around it returning `-Vec2::Y`. + from_angle: function(number):(LuaVec2) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 3-dimensional vector. +-- + record LuaVec3 + userdata + + -- Fields + x : number + + y : number + + z : number + + -- Pure methods + --Creates a 4D vector from `self` and the given `w` value. + extend: function(LuaVec3,number):(LuaVec4) + + --Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. + -- + -- + -- + --Truncation may also be performed by using `self.xy()` or `Vec2::from()`. + truncate: function(LuaVec3):(LuaVec2) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaVec3,LuaVec3):(number) + + --Computes the cross product of `self` and `rhs`. + cross: function(LuaVec3,LuaVec3):(LuaVec3) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaVec3,LuaVec3):(LuaVec3) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaVec3,LuaVec3):(LuaVec3) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaVec3,(LuaVec3),(LuaVec3)):(LuaVec3) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaVec3):(number) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaVec3):(number) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaVec3,LuaVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaVec3,LuaVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaVec3,LuaVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaVec3,LuaVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaVec3,LuaVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaVec3,LuaVec3):(LuaBVec3) + + --Returns a vector containing the absolute value of each element of `self`. + abs: function(LuaVec3):(LuaVec3) + + --Returns a vector with elements representing the sign of `self`. + -- + -- + -- + --- `1.0` if the number is positive, `+0.0` or `INFINITY` + -- + --- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + -- + --- `NAN` if the number is `NAN` + signum: function(LuaVec3):(LuaVec3) + + --Returns `true` if, and only if, all elements are finite. If any element is either + -- + --`NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaVec3):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaVec3):(boolean) + + --Performs `is_nan` on each element of self, returning a vector mask of the results. + -- + -- + -- + --In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask: function(LuaVec3):(LuaBVec3) + + --Computes the length of `self`. + length: function(LuaVec3):(number) + + --Computes the squared length of `self`. + -- + -- + -- + --This is faster than `length()` as it avoids a square root operation. + length_squared: function(LuaVec3):(number) + + --Computes `1.0 / length()`. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero. + length_recip: function(LuaVec3):(number) + + --Computes the Euclidean distance between two points in space. + distance: function(LuaVec3,LuaVec3):(number) + + --Compute the squared euclidean distance between two points in space. + distance_squared: function(LuaVec3,LuaVec3):(number) + + --Returns `self` normalized to length 1.0. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero, nor very close to zero. + -- + -- + -- + --See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + -- + -- + -- + --Panics + -- + -- + -- + --Will panic if `self` is zero length when `glam_assert` is enabled. + normalize: function(LuaVec3):(LuaVec3) + + --Returns `self` normalized to length 1.0 if possible, else returns zero. + -- + -- + -- + --In particular, if the input is zero (or very close to zero), or non-finite, + -- + --the result of this operation will be zero. + -- + -- + -- + --See also [`Self::try_normalize`]. + normalize_or_zero: function(LuaVec3):(LuaVec3) + + --Returns whether `self` is length `1.0` or not. + -- + -- + -- + --Uses a precision threshold of `1e-6`. + is_normalized: function(LuaVec3):(boolean) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto: function(LuaVec3,LuaVec3):(LuaVec3) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from: function(LuaVec3,LuaVec3):(LuaVec3) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized: function(LuaVec3,LuaVec3):(LuaVec3) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized: function(LuaVec3,LuaVec3):(LuaVec3) + + --Returns a vector containing the nearest integer to a number for each element of `self`. + -- + --Round half-way cases away from 0.0. + round: function(LuaVec3):(LuaVec3) + + --Returns a vector containing the largest integer less than or equal to a number for each + -- + --element of `self`. + floor: function(LuaVec3):(LuaVec3) + + --Returns a vector containing the smallest integer greater than or equal to a number for + -- + --each element of `self`. + ceil: function(LuaVec3):(LuaVec3) + + --Returns a vector containing the fractional part of the vector, e.g. `self - + -- + --self.floor()`. + -- + -- + -- + --Note that this is fast but not precise for large numbers. + fract: function(LuaVec3):(LuaVec3) + + --Returns a vector containing `e^self` (the exponential function) for each element of + -- + --`self`. + exp: function(LuaVec3):(LuaVec3) + + --Returns a vector containing each element of `self` raised to the power of `n`. + powf: function(LuaVec3,number):(LuaVec3) + + --Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip: function(LuaVec3):(LuaVec3) + + --Performs a linear interpolation between `self` and `rhs` based on the value `s`. + -- + -- + -- + --When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + -- + --will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + -- + --extrapolated. + lerp: function(LuaVec3,(LuaVec3),(number)):(LuaVec3) + + --Returns true if the absolute difference of all elements between `self` and `rhs` is + -- + --less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two vectors contain similar elements. It works best when + -- + --comparing with a known value. The `max_abs_diff` that should be used used depends on + -- + --the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaVec3,(LuaVec3),(number)):(boolean) + + --Returns a vector with a length no less than `min` and no more than `max` + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length: function(LuaVec3,(number),(number)):(LuaVec3) + + --Returns a vector with a length no more than `max` + clamp_length_max: function(LuaVec3,number):(LuaVec3) + + --Returns a vector with a length no less than `min` + clamp_length_min: function(LuaVec3,number):(LuaVec3) + + --Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + -- + --error, yielding a more accurate result than an unfused multiply-add. + -- + -- + -- + --Using `mul_add` *may* be more performant than an unfused multiply-add if the target + -- + --architecture has a dedicated fma CPU instruction. However, this is not always true, + -- + --and will be heavily dependant on designing algorithms with specific target hardware in + -- + --mind. + mul_add: function(LuaVec3,(LuaVec3),(LuaVec3)):(LuaVec3) + + --Returns the angle (in radians) between two vectors. + -- + -- + -- + --The input vectors do not need to be unit length however they must be non-zero. + angle_between: function(LuaVec3,LuaVec3):(number) + + --Returns some vector that is orthogonal to the given one. + -- + -- + -- + --The input vector must be finite and non-zero. + -- + -- + -- + --The output vector is not necessarily unit-length. + -- + --For that use [`Self::any_orthonormal_vector`] instead. + any_orthogonal_vector: function(LuaVec3):(LuaVec3) + + --Returns any unit-length vector that is orthogonal to the given one. + -- + --The input vector must be finite and non-zero. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` is not normalized when `glam_assert` is enabled. + any_orthonormal_vector: function(LuaVec3):(LuaVec3) + + --Casts all elements of `self` to `f64`. + as_dvec3: function(LuaVec3):(LuaDVec3) + + --Casts all elements of `self` to `i32`. + as_ivec3: function(LuaVec3):(LuaIVec3) + + --Casts all elements of `self` to `u32`. + as_uvec3: function(LuaVec3):(LuaUVec3) + + -- Pure functions + --Creates a new vector. + new: function((number),(number),(number)):(LuaVec3) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaVec3) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec3),(LuaVec3),(LuaVec3)):(LuaVec3) + + -- Meta methods + metamethod __tostring: function(LuaVec3):(string) + + metamethod __unm: function(LuaVec3):(LuaVec3) + + metamethod __index: function(LuaVec3,integer):(number) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaVec3,(integer),(number)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaVec3`]. + record LuaVec3Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((number),(number),(number)):(LuaVec3) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaVec3) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec3),(LuaVec3),(LuaVec3)):(LuaVec3) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 3-dimensional vector with SIMD support. +-- +-- +-- +--This type is 16 byte aligned. A SIMD vector type is used for storage on supported platforms for +-- +--better performance than the `Vec3` type. +-- +-- +-- +--It is possible to convert between `Vec3` and `Vec3A` types using `From` trait implementations. +-- + record LuaVec3A + userdata + + -- Pure methods + --Creates a 4D vector from `self` and the given `w` value. + extend: function(LuaVec3A,number):(LuaVec4) + + --Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. + -- + -- + -- + --Truncation may also be performed by using `self.xy()` or `Vec2::from()`. + truncate: function(LuaVec3A):(LuaVec2) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaVec3A,LuaVec3A):(number) + + --Computes the cross product of `self` and `rhs`. + cross: function(LuaVec3A,LuaVec3A):(LuaVec3A) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaVec3A,LuaVec3A):(LuaVec3A) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaVec3A,LuaVec3A):(LuaVec3A) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaVec3A,(LuaVec3A),(LuaVec3A)):(LuaVec3A) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaVec3A):(number) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaVec3A):(number) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaVec3A,LuaVec3A):(LuaBVec3A) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaVec3A,LuaVec3A):(LuaBVec3A) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaVec3A,LuaVec3A):(LuaBVec3A) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaVec3A,LuaVec3A):(LuaBVec3A) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaVec3A,LuaVec3A):(LuaBVec3A) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaVec3A,LuaVec3A):(LuaBVec3A) + + --Returns a vector containing the absolute value of each element of `self`. + abs: function(LuaVec3A):(LuaVec3A) + + --Returns a vector with elements representing the sign of `self`. + -- + -- + -- + --- `1.0` if the number is positive, `+0.0` or `INFINITY` + -- + --- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + -- + --- `NAN` if the number is `NAN` + signum: function(LuaVec3A):(LuaVec3A) + + --Returns `true` if, and only if, all elements are finite. If any element is either + -- + --`NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaVec3A):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaVec3A):(boolean) + + --Performs `is_nan` on each element of self, returning a vector mask of the results. + -- + -- + -- + --In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask: function(LuaVec3A):(LuaBVec3A) + + --Computes the length of `self`. + length: function(LuaVec3A):(number) + + --Computes the squared length of `self`. + -- + -- + -- + --This is faster than `length()` as it avoids a square root operation. + length_squared: function(LuaVec3A):(number) + + --Computes `1.0 / length()`. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero. + length_recip: function(LuaVec3A):(number) + + --Computes the Euclidean distance between two points in space. + distance: function(LuaVec3A,LuaVec3A):(number) + + --Compute the squared euclidean distance between two points in space. + distance_squared: function(LuaVec3A,LuaVec3A):(number) + + --Returns `self` normalized to length 1.0. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero, nor very close to zero. + -- + -- + -- + --See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + -- + -- + -- + --Panics + -- + -- + -- + --Will panic if `self` is zero length when `glam_assert` is enabled. + normalize: function(LuaVec3A):(LuaVec3A) + + --Returns `self` normalized to length 1.0 if possible, else returns zero. + -- + -- + -- + --In particular, if the input is zero (or very close to zero), or non-finite, + -- + --the result of this operation will be zero. + -- + -- + -- + --See also [`Self::try_normalize`]. + normalize_or_zero: function(LuaVec3A):(LuaVec3A) + + --Returns whether `self` is length `1.0` or not. + -- + -- + -- + --Uses a precision threshold of `1e-6`. + is_normalized: function(LuaVec3A):(boolean) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto: function(LuaVec3A,LuaVec3A):(LuaVec3A) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from: function(LuaVec3A,LuaVec3A):(LuaVec3A) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized: function(LuaVec3A,LuaVec3A):(LuaVec3A) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized: function(LuaVec3A,LuaVec3A):(LuaVec3A) + + --Returns a vector containing the nearest integer to a number for each element of `self`. + -- + --Round half-way cases away from 0.0. + round: function(LuaVec3A):(LuaVec3A) + + --Returns a vector containing the largest integer less than or equal to a number for each + -- + --element of `self`. + floor: function(LuaVec3A):(LuaVec3A) + + --Returns a vector containing the smallest integer greater than or equal to a number for + -- + --each element of `self`. + ceil: function(LuaVec3A):(LuaVec3A) + + --Returns a vector containing the fractional part of the vector, e.g. `self - + -- + --self.floor()`. + -- + -- + -- + --Note that this is fast but not precise for large numbers. + fract: function(LuaVec3A):(LuaVec3A) + + --Returns a vector containing `e^self` (the exponential function) for each element of + -- + --`self`. + exp: function(LuaVec3A):(LuaVec3A) + + --Returns a vector containing each element of `self` raised to the power of `n`. + powf: function(LuaVec3A,number):(LuaVec3A) + + --Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip: function(LuaVec3A):(LuaVec3A) + + --Performs a linear interpolation between `self` and `rhs` based on the value `s`. + -- + -- + -- + --When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + -- + --will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + -- + --extrapolated. + lerp: function(LuaVec3A,(LuaVec3A),(number)):(LuaVec3A) + + --Returns true if the absolute difference of all elements between `self` and `rhs` is + -- + --less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two vectors contain similar elements. It works best when + -- + --comparing with a known value. The `max_abs_diff` that should be used used depends on + -- + --the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaVec3A,(LuaVec3A),(number)):(boolean) + + --Returns a vector with a length no less than `min` and no more than `max` + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length: function(LuaVec3A,(number),(number)):(LuaVec3A) + + --Returns a vector with a length no more than `max` + clamp_length_max: function(LuaVec3A,number):(LuaVec3A) + + --Returns a vector with a length no less than `min` + clamp_length_min: function(LuaVec3A,number):(LuaVec3A) + + --Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + -- + --error, yielding a more accurate result than an unfused multiply-add. + -- + -- + -- + --Using `mul_add` *may* be more performant than an unfused multiply-add if the target + -- + --architecture has a dedicated fma CPU instruction. However, this is not always true, + -- + --and will be heavily dependant on designing algorithms with specific target hardware in + -- + --mind. + mul_add: function(LuaVec3A,(LuaVec3A),(LuaVec3A)):(LuaVec3A) + + --Returns the angle (in radians) between two vectors. + -- + -- + -- + --The input vectors do not need to be unit length however they must be non-zero. + angle_between: function(LuaVec3A,LuaVec3A):(number) + + --Returns some vector that is orthogonal to the given one. + -- + -- + -- + --The input vector must be finite and non-zero. + -- + -- + -- + --The output vector is not necessarily unit-length. + -- + --For that use [`Self::any_orthonormal_vector`] instead. + any_orthogonal_vector: function(LuaVec3A):(LuaVec3A) + + --Returns any unit-length vector that is orthogonal to the given one. + -- + --The input vector must be finite and non-zero. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` is not normalized when `glam_assert` is enabled. + any_orthonormal_vector: function(LuaVec3A):(LuaVec3A) + + --Casts all elements of `self` to `f64`. + as_dvec3: function(LuaVec3A):(LuaDVec3) + + --Casts all elements of `self` to `i32`. + as_ivec3: function(LuaVec3A):(LuaIVec3) + + --Casts all elements of `self` to `u32`. + as_uvec3: function(LuaVec3A):(LuaUVec3) + + -- Pure functions + --Creates a new vector. + new: function((number),(number),(number)):(LuaVec3A) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaVec3A) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec3A),(LuaVec3A),(LuaVec3A)):(LuaVec3A) + + -- Meta methods + metamethod __tostring: function(LuaVec3A):(string) + + metamethod __unm: function(LuaVec3A):(LuaVec3A) + + metamethod __index: function(LuaVec3A,integer):(number) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaVec3A,(integer),(number)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaVec3A`]. + record LuaVec3AClass + userdata + + -- Pure functions + --Creates a new vector. + new: function((number),(number),(number)):(LuaVec3A) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaVec3A) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec3A),(LuaVec3A),(LuaVec3A)):(LuaVec3A) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 4-dimensional vector with SIMD support. +-- +-- +-- +--This type uses 16 byte aligned SIMD vector type for storage. +-- + record LuaVec4 + userdata + + -- Pure methods + --Creates a 2D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. + -- + -- + -- + --Truncation to `Vec3` may also be performed by using `self.xyz()` or `Vec3::from()`. + -- + -- + -- + --To truncate to `Vec3A` use `Vec3A::from()`. + truncate: function(LuaVec4):(LuaVec3) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaVec4,LuaVec4):(number) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaVec4,LuaVec4):(LuaVec4) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaVec4,LuaVec4):(LuaVec4) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaVec4,(LuaVec4),(LuaVec4)):(LuaVec4) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaVec4):(number) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaVec4):(number) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaVec4,LuaVec4):(LuaBVec4A) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaVec4,LuaVec4):(LuaBVec4A) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaVec4,LuaVec4):(LuaBVec4A) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaVec4,LuaVec4):(LuaBVec4A) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaVec4,LuaVec4):(LuaBVec4A) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaVec4,LuaVec4):(LuaBVec4A) + + --Returns a vector containing the absolute value of each element of `self`. + abs: function(LuaVec4):(LuaVec4) + + --Returns a vector with elements representing the sign of `self`. + -- + -- + -- + --- `1.0` if the number is positive, `+0.0` or `INFINITY` + -- + --- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + -- + --- `NAN` if the number is `NAN` + signum: function(LuaVec4):(LuaVec4) + + --Returns `true` if, and only if, all elements are finite. If any element is either + -- + --`NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaVec4):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaVec4):(boolean) + + --Performs `is_nan` on each element of self, returning a vector mask of the results. + -- + -- + -- + --In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask: function(LuaVec4):(LuaBVec4A) + + --Computes the length of `self`. + length: function(LuaVec4):(number) + + --Computes the squared length of `self`. + -- + -- + -- + --This is faster than `length()` as it avoids a square root operation. + length_squared: function(LuaVec4):(number) + + --Computes `1.0 / length()`. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero. + length_recip: function(LuaVec4):(number) + + --Computes the Euclidean distance between two points in space. + distance: function(LuaVec4,LuaVec4):(number) + + --Compute the squared euclidean distance between two points in space. + distance_squared: function(LuaVec4,LuaVec4):(number) + + --Returns `self` normalized to length 1.0. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero, nor very close to zero. + -- + -- + -- + --See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + -- + -- + -- + --Panics + -- + -- + -- + --Will panic if `self` is zero length when `glam_assert` is enabled. + normalize: function(LuaVec4):(LuaVec4) + + --Returns `self` normalized to length 1.0 if possible, else returns zero. + -- + -- + -- + --In particular, if the input is zero (or very close to zero), or non-finite, + -- + --the result of this operation will be zero. + -- + -- + -- + --See also [`Self::try_normalize`]. + normalize_or_zero: function(LuaVec4):(LuaVec4) + + --Returns whether `self` is length `1.0` or not. + -- + -- + -- + --Uses a precision threshold of `1e-6`. + is_normalized: function(LuaVec4):(boolean) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto: function(LuaVec4,LuaVec4):(LuaVec4) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from: function(LuaVec4,LuaVec4):(LuaVec4) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized: function(LuaVec4,LuaVec4):(LuaVec4) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized: function(LuaVec4,LuaVec4):(LuaVec4) + + --Returns a vector containing the nearest integer to a number for each element of `self`. + -- + --Round half-way cases away from 0.0. + round: function(LuaVec4):(LuaVec4) + + --Returns a vector containing the largest integer less than or equal to a number for each + -- + --element of `self`. + floor: function(LuaVec4):(LuaVec4) + + --Returns a vector containing the smallest integer greater than or equal to a number for + -- + --each element of `self`. + ceil: function(LuaVec4):(LuaVec4) + + --Returns a vector containing the fractional part of the vector, e.g. `self - + -- + --self.floor()`. + -- + -- + -- + --Note that this is fast but not precise for large numbers. + fract: function(LuaVec4):(LuaVec4) + + --Returns a vector containing `e^self` (the exponential function) for each element of + -- + --`self`. + exp: function(LuaVec4):(LuaVec4) + + --Returns a vector containing each element of `self` raised to the power of `n`. + powf: function(LuaVec4,number):(LuaVec4) + + --Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip: function(LuaVec4):(LuaVec4) + + --Performs a linear interpolation between `self` and `rhs` based on the value `s`. + -- + -- + -- + --When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + -- + --will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + -- + --extrapolated. + lerp: function(LuaVec4,(LuaVec4),(number)):(LuaVec4) + + --Returns true if the absolute difference of all elements between `self` and `rhs` is + -- + --less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two vectors contain similar elements. It works best when + -- + --comparing with a known value. The `max_abs_diff` that should be used used depends on + -- + --the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaVec4,(LuaVec4),(number)):(boolean) + + --Returns a vector with a length no less than `min` and no more than `max` + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length: function(LuaVec4,(number),(number)):(LuaVec4) + + --Returns a vector with a length no more than `max` + clamp_length_max: function(LuaVec4,number):(LuaVec4) + + --Returns a vector with a length no less than `min` + clamp_length_min: function(LuaVec4,number):(LuaVec4) + + --Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + -- + --error, yielding a more accurate result than an unfused multiply-add. + -- + -- + -- + --Using `mul_add` *may* be more performant than an unfused multiply-add if the target + -- + --architecture has a dedicated fma CPU instruction. However, this is not always true, + -- + --and will be heavily dependant on designing algorithms with specific target hardware in + -- + --mind. + mul_add: function(LuaVec4,(LuaVec4),(LuaVec4)):(LuaVec4) + + --Casts all elements of `self` to `f64`. + as_dvec4: function(LuaVec4):(LuaDVec4) + + --Casts all elements of `self` to `i32`. + as_ivec4: function(LuaVec4):(LuaIVec4) + + --Casts all elements of `self` to `u32`. + as_uvec4: function(LuaVec4):(LuaUVec4) + + -- Pure functions + --Creates a new vector. + new: function((number),(number),(number),(number)):(LuaVec4) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaVec4) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec4A),(LuaVec4),(LuaVec4)):(LuaVec4) + + -- Meta methods + metamethod __tostring: function(LuaVec4):(string) + + metamethod __unm: function(LuaVec4):(LuaVec4) + + metamethod __index: function(LuaVec4,integer):(number) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaVec4,(integer),(number)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaVec4`]. + record LuaVec4Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((number),(number),(number),(number)):(LuaVec4) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaVec4) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec4A),(LuaVec4),(LuaVec4)):(LuaVec4) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 2-dimensional boolean vector. +-- + record LuaBVec2 + userdata + + -- Fields + x : boolean + + y : boolean + + -- Pure methods + --Returns a bitmask with the lowest two bits set from the elements of `self`. + -- + -- + -- + --A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes + -- + --into the first lowest bit, element `y` into the second, etc. + bitmask: function(LuaBVec2):(integer) + + --Returns true if any of the elements are true, false otherwise. + any: function(LuaBVec2):(boolean) + + --Returns true if all the elements are true, false otherwise. + all: function(LuaBVec2):(boolean) + + -- Pure functions + --Creates a new vector mask. + new: function((boolean),(boolean)):(LuaBVec2) + + -- Meta methods + metamethod __tostring: function(LuaBVec2):(string) + + + end +--Collection of static methods for [`LuaBVec2`]. + record LuaBVec2Class + userdata + + -- Pure functions + --Creates a new vector mask. + new: function((boolean),(boolean)):(LuaBVec2) + + + end +--A 3-dimensional boolean vector. +-- + record LuaBVec3 + userdata + + -- Fields + x : boolean + + y : boolean + + z : boolean + + -- Pure methods + --Returns a bitmask with the lowest two bits set from the elements of `self`. + -- + -- + -- + --A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes + -- + --into the first lowest bit, element `y` into the second, etc. + bitmask: function(LuaBVec3):(integer) + + --Returns true if any of the elements are true, false otherwise. + any: function(LuaBVec3):(boolean) + + --Returns true if all the elements are true, false otherwise. + all: function(LuaBVec3):(boolean) + + -- Pure functions + --Creates a new vector mask. + new: function((boolean),(boolean),(boolean)):(LuaBVec3) + + -- Meta methods + metamethod __tostring: function(LuaBVec3):(string) + + + end +--Collection of static methods for [`LuaBVec3`]. + record LuaBVec3Class + userdata + + -- Pure functions + --Creates a new vector mask. + new: function((boolean),(boolean),(boolean)):(LuaBVec3) + + + end +--A 4-dimensional boolean vector. +-- + record LuaBVec4 + userdata + + -- Fields + x : boolean + + y : boolean + + z : boolean + + w : boolean + + -- Pure methods + --Returns a bitmask with the lowest two bits set from the elements of `self`. + -- + -- + -- + --A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes + -- + --into the first lowest bit, element `y` into the second, etc. + bitmask: function(LuaBVec4):(integer) + + --Returns true if any of the elements are true, false otherwise. + any: function(LuaBVec4):(boolean) + + --Returns true if all the elements are true, false otherwise. + all: function(LuaBVec4):(boolean) + + -- Pure functions + --Creates a new vector mask. + new: function((boolean),(boolean),(boolean),(boolean)):(LuaBVec4) + + -- Meta methods + metamethod __tostring: function(LuaBVec4):(string) + + + end +--Collection of static methods for [`LuaBVec4`]. + record LuaBVec4Class + userdata + + -- Pure functions + --Creates a new vector mask. + new: function((boolean),(boolean),(boolean),(boolean)):(LuaBVec4) + + + end +--A 3-dimensional SIMD vector mask. +-- +-- +-- +--This type is 16 byte aligned and is backed by a SIMD vector. If SIMD is not available +-- +--`BVec3A` will be a type alias for `BVec3`. +-- + record LuaBVec3A + userdata + + -- Pure methods + --Returns a bitmask with the lowest two bits set from the elements of `self`. + -- + -- + -- + --A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes + -- + --into the first lowest bit, element `y` into the second, etc. + bitmask: function(LuaBVec3A):(integer) + + --Returns true if any of the elements are true, false otherwise. + any: function(LuaBVec3A):(boolean) + + --Returns true if all the elements are true, false otherwise. + all: function(LuaBVec3A):(boolean) + + -- Pure functions + --Creates a new vector mask. + new: function((boolean),(boolean),(boolean)):(LuaBVec3A) + + -- Meta methods + metamethod __tostring: function(LuaBVec3A):(string) + + + end +--Collection of static methods for [`LuaBVec3A`]. + record LuaBVec3AClass + userdata + + -- Pure functions + --Creates a new vector mask. + new: function((boolean),(boolean),(boolean)):(LuaBVec3A) + + + end +--A 4-dimensional SIMD vector mask. +-- +-- +-- +--This type is 16 byte aligned and is backed by a SIMD vector. If SIMD is not available +-- +--`BVec4A` will be a type alias for `BVec4`. +-- + record LuaBVec4A + userdata + + -- Pure methods + --Returns a bitmask with the lowest two bits set from the elements of `self`. + -- + -- + -- + --A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes + -- + --into the first lowest bit, element `y` into the second, etc. + bitmask: function(LuaBVec4A):(integer) + + --Returns true if any of the elements are true, false otherwise. + any: function(LuaBVec4A):(boolean) + + --Returns true if all the elements are true, false otherwise. + all: function(LuaBVec4A):(boolean) + + -- Pure functions + --Creates a new vector mask. + new: function((boolean),(boolean),(boolean),(boolean)):(LuaBVec4A) + + -- Meta methods + metamethod __tostring: function(LuaBVec4A):(string) + + + end +--Collection of static methods for [`LuaBVec4A`]. + record LuaBVec4AClass + userdata + + -- Pure functions + --Creates a new vector mask. + new: function((boolean),(boolean),(boolean),(boolean)):(LuaBVec4A) + + + end +--A 2-dimensional vector. +-- + record LuaDVec2 + userdata + + -- Fields + x : number + + y : number + + -- Pure methods + --Creates a 3D vector from `self` and the given `z` value. + extend: function(LuaDVec2,number):(LuaDVec3) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaDVec2,LuaDVec2):(number) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaDVec2,LuaDVec2):(LuaDVec2) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaDVec2,LuaDVec2):(LuaDVec2) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaDVec2,(LuaDVec2),(LuaDVec2)):(LuaDVec2) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaDVec2):(number) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaDVec2):(number) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaDVec2,LuaDVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaDVec2,LuaDVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaDVec2,LuaDVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaDVec2,LuaDVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaDVec2,LuaDVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaDVec2,LuaDVec2):(LuaBVec2) + + --Returns a vector containing the absolute value of each element of `self`. + abs: function(LuaDVec2):(LuaDVec2) + + --Returns a vector with elements representing the sign of `self`. + -- + -- + -- + --- `1.0` if the number is positive, `+0.0` or `INFINITY` + -- + --- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + -- + --- `NAN` if the number is `NAN` + signum: function(LuaDVec2):(LuaDVec2) + + --Returns `true` if, and only if, all elements are finite. If any element is either + -- + --`NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaDVec2):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaDVec2):(boolean) + + --Performs `is_nan` on each element of self, returning a vector mask of the results. + -- + -- + -- + --In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask: function(LuaDVec2):(LuaBVec2) + + --Computes the length of `self`. + length: function(LuaDVec2):(number) + + --Computes the squared length of `self`. + -- + -- + -- + --This is faster than `length()` as it avoids a square root operation. + length_squared: function(LuaDVec2):(number) + + --Computes `1.0 / length()`. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero. + length_recip: function(LuaDVec2):(number) + + --Computes the Euclidean distance between two points in space. + distance: function(LuaDVec2,LuaDVec2):(number) + + --Compute the squared euclidean distance between two points in space. + distance_squared: function(LuaDVec2,LuaDVec2):(number) + + --Returns `self` normalized to length 1.0. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero, nor very close to zero. + -- + -- + -- + --See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + -- + -- + -- + --Panics + -- + -- + -- + --Will panic if `self` is zero length when `glam_assert` is enabled. + normalize: function(LuaDVec2):(LuaDVec2) + + --Returns `self` normalized to length 1.0 if possible, else returns zero. + -- + -- + -- + --In particular, if the input is zero (or very close to zero), or non-finite, + -- + --the result of this operation will be zero. + -- + -- + -- + --See also [`Self::try_normalize`]. + normalize_or_zero: function(LuaDVec2):(LuaDVec2) + + --Returns whether `self` is length `1.0` or not. + -- + -- + -- + --Uses a precision threshold of `1e-6`. + is_normalized: function(LuaDVec2):(boolean) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto: function(LuaDVec2,LuaDVec2):(LuaDVec2) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from: function(LuaDVec2,LuaDVec2):(LuaDVec2) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized: function(LuaDVec2,LuaDVec2):(LuaDVec2) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized: function(LuaDVec2,LuaDVec2):(LuaDVec2) + + --Returns a vector containing the nearest integer to a number for each element of `self`. + -- + --Round half-way cases away from 0.0. + round: function(LuaDVec2):(LuaDVec2) + + --Returns a vector containing the largest integer less than or equal to a number for each + -- + --element of `self`. + floor: function(LuaDVec2):(LuaDVec2) + + --Returns a vector containing the smallest integer greater than or equal to a number for + -- + --each element of `self`. + ceil: function(LuaDVec2):(LuaDVec2) + + --Returns a vector containing the fractional part of the vector, e.g. `self - + -- + --self.floor()`. + -- + -- + -- + --Note that this is fast but not precise for large numbers. + fract: function(LuaDVec2):(LuaDVec2) + + --Returns a vector containing `e^self` (the exponential function) for each element of + -- + --`self`. + exp: function(LuaDVec2):(LuaDVec2) + + --Returns a vector containing each element of `self` raised to the power of `n`. + powf: function(LuaDVec2,number):(LuaDVec2) + + --Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip: function(LuaDVec2):(LuaDVec2) + + --Performs a linear interpolation between `self` and `rhs` based on the value `s`. + -- + -- + -- + --When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + -- + --will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + -- + --extrapolated. + lerp: function(LuaDVec2,(LuaDVec2),(number)):(LuaDVec2) + + --Returns true if the absolute difference of all elements between `self` and `rhs` is + -- + --less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two vectors contain similar elements. It works best when + -- + --comparing with a known value. The `max_abs_diff` that should be used used depends on + -- + --the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaDVec2,(LuaDVec2),(number)):(boolean) + + --Returns a vector with a length no less than `min` and no more than `max` + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length: function(LuaDVec2,(number),(number)):(LuaDVec2) + + --Returns a vector with a length no more than `max` + clamp_length_max: function(LuaDVec2,number):(LuaDVec2) + + --Returns a vector with a length no less than `min` + clamp_length_min: function(LuaDVec2,number):(LuaDVec2) + + --Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + -- + --error, yielding a more accurate result than an unfused multiply-add. + -- + -- + -- + --Using `mul_add` *may* be more performant than an unfused multiply-add if the target + -- + --architecture has a dedicated fma CPU instruction. However, this is not always true, + -- + --and will be heavily dependant on designing algorithms with specific target hardware in + -- + --mind. + mul_add: function(LuaDVec2,(LuaDVec2),(LuaDVec2)):(LuaDVec2) + + --Returns the angle (in radians) between `self` and `rhs`. + -- + -- + -- + --The input vectors do not need to be unit length however they must be non-zero. + angle_between: function(LuaDVec2,LuaDVec2):(number) + + --Returns a vector that is equal to `self` rotated by 90 degrees. + perp: function(LuaDVec2):(LuaDVec2) + + --The perpendicular dot product of `self` and `rhs`. + -- + --Also known as the wedge product, 2D cross product, and determinant. + perp_dot: function(LuaDVec2,LuaDVec2):(number) + + --Returns `rhs` rotated by the angle of `self`. If `self` is normalized, + -- + --then this just rotation. This is what you usually want. Otherwise, + -- + --it will be like a rotation with a multiplication by `self`'s length. + rotate: function(LuaDVec2,LuaDVec2):(LuaDVec2) + + --Casts all elements of `self` to `f32`. + as_vec2: function(LuaDVec2):(LuaVec2) + + --Casts all elements of `self` to `i32`. + as_ivec2: function(LuaDVec2):(LuaIVec2) + + --Casts all elements of `self` to `u32`. + as_uvec2: function(LuaDVec2):(LuaUVec2) + + -- Pure functions + --Creates a new vector. + new: function((number),(number)):(LuaDVec2) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaDVec2) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec2),(LuaDVec2),(LuaDVec2)):(LuaDVec2) + + --Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in + -- + --conjunction with the `rotate` method, e.g. `Vec2::from_angle(PI).rotate(Vec2::Y)` will + -- + --create the vector [-1, 0] and rotate `Vec2::Y` around it returning `-Vec2::Y`. + from_angle: function(number):(LuaDVec2) + + -- Meta methods + metamethod __tostring: function(LuaDVec2):(string) + + metamethod __unm: function(LuaDVec2):(LuaDVec2) + + metamethod __index: function(LuaDVec2,integer):(number) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaDVec2,(integer),(number)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaDVec2`]. + record LuaDVec2Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((number),(number)):(LuaDVec2) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaDVec2) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec2),(LuaDVec2),(LuaDVec2)):(LuaDVec2) + + --Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in + -- + --conjunction with the `rotate` method, e.g. `Vec2::from_angle(PI).rotate(Vec2::Y)` will + -- + --create the vector [-1, 0] and rotate `Vec2::Y` around it returning `-Vec2::Y`. + from_angle: function(number):(LuaDVec2) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 3-dimensional vector. +-- + record LuaDVec3 + userdata + + -- Fields + x : number + + y : number + + z : number + + -- Pure methods + --Creates a 4D vector from `self` and the given `w` value. + extend: function(LuaDVec3,number):(LuaDVec4) + + --Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. + -- + -- + -- + --Truncation may also be performed by using `self.xy()` or `DVec2::from()`. + truncate: function(LuaDVec3):(LuaDVec2) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaDVec3,LuaDVec3):(number) + + --Computes the cross product of `self` and `rhs`. + cross: function(LuaDVec3,LuaDVec3):(LuaDVec3) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaDVec3,LuaDVec3):(LuaDVec3) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaDVec3,LuaDVec3):(LuaDVec3) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaDVec3,(LuaDVec3),(LuaDVec3)):(LuaDVec3) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaDVec3):(number) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaDVec3):(number) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaDVec3,LuaDVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaDVec3,LuaDVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaDVec3,LuaDVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaDVec3,LuaDVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaDVec3,LuaDVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaDVec3,LuaDVec3):(LuaBVec3) + + --Returns a vector containing the absolute value of each element of `self`. + abs: function(LuaDVec3):(LuaDVec3) + + --Returns a vector with elements representing the sign of `self`. + -- + -- + -- + --- `1.0` if the number is positive, `+0.0` or `INFINITY` + -- + --- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + -- + --- `NAN` if the number is `NAN` + signum: function(LuaDVec3):(LuaDVec3) + + --Returns `true` if, and only if, all elements are finite. If any element is either + -- + --`NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaDVec3):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaDVec3):(boolean) + + --Performs `is_nan` on each element of self, returning a vector mask of the results. + -- + -- + -- + --In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask: function(LuaDVec3):(LuaBVec3) + + --Computes the length of `self`. + length: function(LuaDVec3):(number) + + --Computes the squared length of `self`. + -- + -- + -- + --This is faster than `length()` as it avoids a square root operation. + length_squared: function(LuaDVec3):(number) + + --Computes `1.0 / length()`. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero. + length_recip: function(LuaDVec3):(number) + + --Computes the Euclidean distance between two points in space. + distance: function(LuaDVec3,LuaDVec3):(number) + + --Compute the squared euclidean distance between two points in space. + distance_squared: function(LuaDVec3,LuaDVec3):(number) + + --Returns `self` normalized to length 1.0. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero, nor very close to zero. + -- + -- + -- + --See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + -- + -- + -- + --Panics + -- + -- + -- + --Will panic if `self` is zero length when `glam_assert` is enabled. + normalize: function(LuaDVec3):(LuaDVec3) + + --Returns `self` normalized to length 1.0 if possible, else returns zero. + -- + -- + -- + --In particular, if the input is zero (or very close to zero), or non-finite, + -- + --the result of this operation will be zero. + -- + -- + -- + --See also [`Self::try_normalize`]. + normalize_or_zero: function(LuaDVec3):(LuaDVec3) + + --Returns whether `self` is length `1.0` or not. + -- + -- + -- + --Uses a precision threshold of `1e-6`. + is_normalized: function(LuaDVec3):(boolean) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto: function(LuaDVec3,LuaDVec3):(LuaDVec3) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from: function(LuaDVec3,LuaDVec3):(LuaDVec3) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized: function(LuaDVec3,LuaDVec3):(LuaDVec3) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized: function(LuaDVec3,LuaDVec3):(LuaDVec3) + + --Returns a vector containing the nearest integer to a number for each element of `self`. + -- + --Round half-way cases away from 0.0. + round: function(LuaDVec3):(LuaDVec3) + + --Returns a vector containing the largest integer less than or equal to a number for each + -- + --element of `self`. + floor: function(LuaDVec3):(LuaDVec3) + + --Returns a vector containing the smallest integer greater than or equal to a number for + -- + --each element of `self`. + ceil: function(LuaDVec3):(LuaDVec3) + + --Returns a vector containing the fractional part of the vector, e.g. `self - + -- + --self.floor()`. + -- + -- + -- + --Note that this is fast but not precise for large numbers. + fract: function(LuaDVec3):(LuaDVec3) + + --Returns a vector containing `e^self` (the exponential function) for each element of + -- + --`self`. + exp: function(LuaDVec3):(LuaDVec3) + + --Returns a vector containing each element of `self` raised to the power of `n`. + powf: function(LuaDVec3,number):(LuaDVec3) + + --Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip: function(LuaDVec3):(LuaDVec3) + + --Performs a linear interpolation between `self` and `rhs` based on the value `s`. + -- + -- + -- + --When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + -- + --will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + -- + --extrapolated. + lerp: function(LuaDVec3,(LuaDVec3),(number)):(LuaDVec3) + + --Returns true if the absolute difference of all elements between `self` and `rhs` is + -- + --less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two vectors contain similar elements. It works best when + -- + --comparing with a known value. The `max_abs_diff` that should be used used depends on + -- + --the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaDVec3,(LuaDVec3),(number)):(boolean) + + --Returns a vector with a length no less than `min` and no more than `max` + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length: function(LuaDVec3,(number),(number)):(LuaDVec3) + + --Returns a vector with a length no more than `max` + clamp_length_max: function(LuaDVec3,number):(LuaDVec3) + + --Returns a vector with a length no less than `min` + clamp_length_min: function(LuaDVec3,number):(LuaDVec3) + + --Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + -- + --error, yielding a more accurate result than an unfused multiply-add. + -- + -- + -- + --Using `mul_add` *may* be more performant than an unfused multiply-add if the target + -- + --architecture has a dedicated fma CPU instruction. However, this is not always true, + -- + --and will be heavily dependant on designing algorithms with specific target hardware in + -- + --mind. + mul_add: function(LuaDVec3,(LuaDVec3),(LuaDVec3)):(LuaDVec3) + + --Returns the angle (in radians) between two vectors. + -- + -- + -- + --The input vectors do not need to be unit length however they must be non-zero. + angle_between: function(LuaDVec3,LuaDVec3):(number) + + --Returns some vector that is orthogonal to the given one. + -- + -- + -- + --The input vector must be finite and non-zero. + -- + -- + -- + --The output vector is not necessarily unit-length. + -- + --For that use [`Self::any_orthonormal_vector`] instead. + any_orthogonal_vector: function(LuaDVec3):(LuaDVec3) + + --Returns any unit-length vector that is orthogonal to the given one. + -- + --The input vector must be finite and non-zero. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` is not normalized when `glam_assert` is enabled. + any_orthonormal_vector: function(LuaDVec3):(LuaDVec3) + + --Casts all elements of `self` to `f32`. + as_vec3: function(LuaDVec3):(LuaVec3) + + --Casts all elements of `self` to `f32`. + as_vec3a: function(LuaDVec3):(LuaVec3A) + + --Casts all elements of `self` to `i32`. + as_ivec3: function(LuaDVec3):(LuaIVec3) + + --Casts all elements of `self` to `u32`. + as_uvec3: function(LuaDVec3):(LuaUVec3) + + -- Pure functions + --Creates a new vector. + new: function((number),(number),(number)):(LuaDVec3) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaDVec3) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec3),(LuaDVec3),(LuaDVec3)):(LuaDVec3) + + -- Meta methods + metamethod __tostring: function(LuaDVec3):(string) + + metamethod __unm: function(LuaDVec3):(LuaDVec3) + + metamethod __index: function(LuaDVec3,integer):(number) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaDVec3,(integer),(number)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaDVec3`]. + record LuaDVec3Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((number),(number),(number)):(LuaDVec3) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaDVec3) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec3),(LuaDVec3),(LuaDVec3)):(LuaDVec3) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 4-dimensional vector. +-- + record LuaDVec4 + userdata + + -- Fields + x : number + + y : number + + z : number + + w : number + + -- Pure methods + --Creates a 2D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. + -- + -- + -- + --Truncation to `DVec3` may also be performed by using `self.xyz()` or `DVec3::from()`. + truncate: function(LuaDVec4):(LuaDVec3) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaDVec4,LuaDVec4):(number) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaDVec4,LuaDVec4):(LuaDVec4) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaDVec4,LuaDVec4):(LuaDVec4) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaDVec4,(LuaDVec4),(LuaDVec4)):(LuaDVec4) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaDVec4):(number) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaDVec4):(number) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaDVec4,LuaDVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaDVec4,LuaDVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaDVec4,LuaDVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaDVec4,LuaDVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaDVec4,LuaDVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaDVec4,LuaDVec4):(LuaBVec4) + + --Returns a vector containing the absolute value of each element of `self`. + abs: function(LuaDVec4):(LuaDVec4) + + --Returns a vector with elements representing the sign of `self`. + -- + -- + -- + --- `1.0` if the number is positive, `+0.0` or `INFINITY` + -- + --- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + -- + --- `NAN` if the number is `NAN` + signum: function(LuaDVec4):(LuaDVec4) + + --Returns `true` if, and only if, all elements are finite. If any element is either + -- + --`NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaDVec4):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaDVec4):(boolean) + + --Performs `is_nan` on each element of self, returning a vector mask of the results. + -- + -- + -- + --In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask: function(LuaDVec4):(LuaBVec4) + + --Computes the length of `self`. + length: function(LuaDVec4):(number) + + --Computes the squared length of `self`. + -- + -- + -- + --This is faster than `length()` as it avoids a square root operation. + length_squared: function(LuaDVec4):(number) + + --Computes `1.0 / length()`. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero. + length_recip: function(LuaDVec4):(number) + + --Computes the Euclidean distance between two points in space. + distance: function(LuaDVec4,LuaDVec4):(number) + + --Compute the squared euclidean distance between two points in space. + distance_squared: function(LuaDVec4,LuaDVec4):(number) + + --Returns `self` normalized to length 1.0. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero, nor very close to zero. + -- + -- + -- + --See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + -- + -- + -- + --Panics + -- + -- + -- + --Will panic if `self` is zero length when `glam_assert` is enabled. + normalize: function(LuaDVec4):(LuaDVec4) + + --Returns `self` normalized to length 1.0 if possible, else returns zero. + -- + -- + -- + --In particular, if the input is zero (or very close to zero), or non-finite, + -- + --the result of this operation will be zero. + -- + -- + -- + --See also [`Self::try_normalize`]. + normalize_or_zero: function(LuaDVec4):(LuaDVec4) + + --Returns whether `self` is length `1.0` or not. + -- + -- + -- + --Uses a precision threshold of `1e-6`. + is_normalized: function(LuaDVec4):(boolean) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto: function(LuaDVec4,LuaDVec4):(LuaDVec4) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be of non-zero length. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from: function(LuaDVec4,LuaDVec4):(LuaDVec4) + + --Returns the vector projection of `self` onto `rhs`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized: function(LuaDVec4,LuaDVec4):(LuaDVec4) + + --Returns the vector rejection of `self` from `rhs`. + -- + -- + -- + --The vector rejection is the vector perpendicular to the projection of `self` onto + -- + --`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + -- + -- + -- + --`rhs` must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized: function(LuaDVec4,LuaDVec4):(LuaDVec4) + + --Returns a vector containing the nearest integer to a number for each element of `self`. + -- + --Round half-way cases away from 0.0. + round: function(LuaDVec4):(LuaDVec4) + + --Returns a vector containing the largest integer less than or equal to a number for each + -- + --element of `self`. + floor: function(LuaDVec4):(LuaDVec4) + + --Returns a vector containing the smallest integer greater than or equal to a number for + -- + --each element of `self`. + ceil: function(LuaDVec4):(LuaDVec4) + + --Returns a vector containing the fractional part of the vector, e.g. `self - + -- + --self.floor()`. + -- + -- + -- + --Note that this is fast but not precise for large numbers. + fract: function(LuaDVec4):(LuaDVec4) + + --Returns a vector containing `e^self` (the exponential function) for each element of + -- + --`self`. + exp: function(LuaDVec4):(LuaDVec4) + + --Returns a vector containing each element of `self` raised to the power of `n`. + powf: function(LuaDVec4,number):(LuaDVec4) + + --Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip: function(LuaDVec4):(LuaDVec4) + + --Performs a linear interpolation between `self` and `rhs` based on the value `s`. + -- + -- + -- + --When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + -- + --will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + -- + --extrapolated. + lerp: function(LuaDVec4,(LuaDVec4),(number)):(LuaDVec4) + + --Returns true if the absolute difference of all elements between `self` and `rhs` is + -- + --less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two vectors contain similar elements. It works best when + -- + --comparing with a known value. The `max_abs_diff` that should be used used depends on + -- + --the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaDVec4,(LuaDVec4),(number)):(boolean) + + --Returns a vector with a length no less than `min` and no more than `max` + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length: function(LuaDVec4,(number),(number)):(LuaDVec4) + + --Returns a vector with a length no more than `max` + clamp_length_max: function(LuaDVec4,number):(LuaDVec4) + + --Returns a vector with a length no less than `min` + clamp_length_min: function(LuaDVec4,number):(LuaDVec4) + + --Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + -- + --error, yielding a more accurate result than an unfused multiply-add. + -- + -- + -- + --Using `mul_add` *may* be more performant than an unfused multiply-add if the target + -- + --architecture has a dedicated fma CPU instruction. However, this is not always true, + -- + --and will be heavily dependant on designing algorithms with specific target hardware in + -- + --mind. + mul_add: function(LuaDVec4,(LuaDVec4),(LuaDVec4)):(LuaDVec4) + + --Casts all elements of `self` to `f32`. + as_vec4: function(LuaDVec4):(LuaVec4) + + --Casts all elements of `self` to `i32`. + as_ivec4: function(LuaDVec4):(LuaIVec4) + + --Casts all elements of `self` to `u32`. + as_uvec4: function(LuaDVec4):(LuaUVec4) + + -- Pure functions + --Creates a new vector. + new: function((number),(number),(number),(number)):(LuaDVec4) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaDVec4) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec4),(LuaDVec4),(LuaDVec4)):(LuaDVec4) + + -- Meta methods + metamethod __tostring: function(LuaDVec4):(string) + + metamethod __unm: function(LuaDVec4):(LuaDVec4) + + metamethod __index: function(LuaDVec4,integer):(number) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaDVec4,(integer),(number)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaDVec4`]. + record LuaDVec4Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((number),(number),(number),(number)):(LuaDVec4) + + --Creates a vector with all elements set to `v`. + splat: function(number):(LuaDVec4) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec4),(LuaDVec4),(LuaDVec4)):(LuaDVec4) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 2-dimensional vector. +-- + record LuaIVec2 + userdata + + -- Fields + x : integer + + y : integer + + -- Pure methods + --Creates a 3D vector from `self` and the given `z` value. + extend: function(LuaIVec2,integer):(LuaIVec3) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaIVec2,LuaIVec2):(integer) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaIVec2,LuaIVec2):(LuaIVec2) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaIVec2,LuaIVec2):(LuaIVec2) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaIVec2,(LuaIVec2),(LuaIVec2)):(LuaIVec2) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaIVec2):(integer) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaIVec2):(integer) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaIVec2,LuaIVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaIVec2,LuaIVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaIVec2,LuaIVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaIVec2,LuaIVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaIVec2,LuaIVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaIVec2,LuaIVec2):(LuaBVec2) + + --Returns a vector containing the absolute value of each element of `self`. + abs: function(LuaIVec2):(LuaIVec2) + + --Returns a vector with elements representing the sign of `self`. + -- + -- + -- + --- `1.0` if the number is positive, `+0.0` or `INFINITY` + -- + --- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + -- + --- `NAN` if the number is `NAN` + signum: function(LuaIVec2):(LuaIVec2) + + --Returns a vector that is equal to `self` rotated by 90 degrees. + perp: function(LuaIVec2):(LuaIVec2) + + --The perpendicular dot product of `self` and `rhs`. + -- + --Also known as the wedge product, 2D cross product, and determinant. + perp_dot: function(LuaIVec2,LuaIVec2):(integer) + + --Returns `rhs` rotated by the angle of `self`. If `self` is normalized, + -- + --then this just rotation. This is what you usually want. Otherwise, + -- + --it will be like a rotation with a multiplication by `self`'s length. + rotate: function(LuaIVec2,LuaIVec2):(LuaIVec2) + + --Casts all elements of `self` to `f32`. + as_vec2: function(LuaIVec2):(LuaVec2) + + --Casts all elements of `self` to `f64`. + as_dvec2: function(LuaIVec2):(LuaDVec2) + + --Casts all elements of `self` to `u32`. + as_uvec2: function(LuaIVec2):(LuaUVec2) + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer)):(LuaIVec2) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaIVec2) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec2),(LuaIVec2),(LuaIVec2)):(LuaIVec2) + + -- Meta methods + metamethod __tostring: function(LuaIVec2):(string) + + metamethod __unm: function(LuaIVec2):(LuaIVec2) + + metamethod __index: function(LuaIVec2,integer):(integer) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaIVec2,(integer),(integer)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaIVec2`]. + record LuaIVec2Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer)):(LuaIVec2) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaIVec2) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec2),(LuaIVec2),(LuaIVec2)):(LuaIVec2) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 3-dimensional vector. +-- + record LuaIVec3 + userdata + + -- Fields + x : integer + + y : integer + + z : integer + + -- Pure methods + --Creates a 4D vector from `self` and the given `w` value. + extend: function(LuaIVec3,integer):(LuaIVec4) + + --Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. + -- + -- + -- + --Truncation may also be performed by using `self.xy()` or `IVec2::from()`. + truncate: function(LuaIVec3):(LuaIVec2) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaIVec3,LuaIVec3):(integer) + + --Computes the cross product of `self` and `rhs`. + cross: function(LuaIVec3,LuaIVec3):(LuaIVec3) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaIVec3,LuaIVec3):(LuaIVec3) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaIVec3,LuaIVec3):(LuaIVec3) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaIVec3,(LuaIVec3),(LuaIVec3)):(LuaIVec3) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaIVec3):(integer) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaIVec3):(integer) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaIVec3,LuaIVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaIVec3,LuaIVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaIVec3,LuaIVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaIVec3,LuaIVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaIVec3,LuaIVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaIVec3,LuaIVec3):(LuaBVec3) + + --Returns a vector containing the absolute value of each element of `self`. + abs: function(LuaIVec3):(LuaIVec3) + + --Returns a vector with elements representing the sign of `self`. + -- + -- + -- + --- `1.0` if the number is positive, `+0.0` or `INFINITY` + -- + --- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + -- + --- `NAN` if the number is `NAN` + signum: function(LuaIVec3):(LuaIVec3) + + --Casts all elements of `self` to `f32`. + as_vec3: function(LuaIVec3):(LuaVec3) + + --Casts all elements of `self` to `f32`. + as_vec3a: function(LuaIVec3):(LuaVec3A) + + --Casts all elements of `self` to `f64`. + as_dvec3: function(LuaIVec3):(LuaDVec3) + + --Casts all elements of `self` to `u32`. + as_uvec3: function(LuaIVec3):(LuaUVec3) + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer),(integer)):(LuaIVec3) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaIVec3) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec3),(LuaIVec3),(LuaIVec3)):(LuaIVec3) + + -- Meta methods + metamethod __tostring: function(LuaIVec3):(string) + + metamethod __unm: function(LuaIVec3):(LuaIVec3) + + metamethod __index: function(LuaIVec3,integer):(integer) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaIVec3,(integer),(integer)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaIVec3`]. + record LuaIVec3Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer),(integer)):(LuaIVec3) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaIVec3) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec3),(LuaIVec3),(LuaIVec3)):(LuaIVec3) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 4-dimensional vector. +-- + record LuaIVec4 + userdata + + -- Fields + x : integer + + y : integer + + z : integer + + w : integer + + -- Pure methods + --Creates a 2D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. + -- + -- + -- + --Truncation to `IVec3` may also be performed by using `self.xyz()` or `IVec3::from()`. + truncate: function(LuaIVec4):(LuaIVec3) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaIVec4,LuaIVec4):(integer) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaIVec4,LuaIVec4):(LuaIVec4) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaIVec4,LuaIVec4):(LuaIVec4) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaIVec4,(LuaIVec4),(LuaIVec4)):(LuaIVec4) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaIVec4):(integer) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaIVec4):(integer) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaIVec4,LuaIVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaIVec4,LuaIVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaIVec4,LuaIVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaIVec4,LuaIVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaIVec4,LuaIVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaIVec4,LuaIVec4):(LuaBVec4) + + --Returns a vector containing the absolute value of each element of `self`. + abs: function(LuaIVec4):(LuaIVec4) + + --Returns a vector with elements representing the sign of `self`. + -- + -- + -- + --- `1.0` if the number is positive, `+0.0` or `INFINITY` + -- + --- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + -- + --- `NAN` if the number is `NAN` + signum: function(LuaIVec4):(LuaIVec4) + + --Casts all elements of `self` to `f32`. + as_vec4: function(LuaIVec4):(LuaVec4) + + --Casts all elements of `self` to `f64`. + as_dvec4: function(LuaIVec4):(LuaDVec4) + + --Casts all elements of `self` to `u32`. + as_uvec4: function(LuaIVec4):(LuaUVec4) + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer),(integer),(integer)):(LuaIVec4) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaIVec4) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec4),(LuaIVec4),(LuaIVec4)):(LuaIVec4) + + -- Meta methods + metamethod __tostring: function(LuaIVec4):(string) + + metamethod __unm: function(LuaIVec4):(LuaIVec4) + + metamethod __index: function(LuaIVec4,integer):(integer) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaIVec4,(integer),(integer)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaIVec4`]. + record LuaIVec4Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer),(integer),(integer)):(LuaIVec4) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaIVec4) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec4),(LuaIVec4),(LuaIVec4)):(LuaIVec4) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 2-dimensional vector. +-- + record LuaUVec2 + userdata + + -- Fields + x : integer + + y : integer + + -- Pure methods + --Creates a 3D vector from `self` and the given `z` value. + extend: function(LuaUVec2,integer):(LuaUVec3) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaUVec2,LuaUVec2):(integer) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaUVec2,LuaUVec2):(LuaUVec2) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaUVec2,LuaUVec2):(LuaUVec2) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaUVec2,(LuaUVec2),(LuaUVec2)):(LuaUVec2) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaUVec2):(integer) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaUVec2):(integer) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaUVec2,LuaUVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaUVec2,LuaUVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaUVec2,LuaUVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaUVec2,LuaUVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaUVec2,LuaUVec2):(LuaBVec2) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaUVec2,LuaUVec2):(LuaBVec2) + + --Casts all elements of `self` to `f32`. + as_vec2: function(LuaUVec2):(LuaVec2) + + --Casts all elements of `self` to `f64`. + as_dvec2: function(LuaUVec2):(LuaDVec2) + + --Casts all elements of `self` to `i32`. + as_ivec2: function(LuaUVec2):(LuaIVec2) + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer)):(LuaUVec2) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaUVec2) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec2),(LuaUVec2),(LuaUVec2)):(LuaUVec2) + + -- Meta methods + metamethod __tostring: function(LuaUVec2):(string) + + metamethod __index: function(LuaUVec2,integer):(integer) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaUVec2,(integer),(integer)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaUVec2`]. + record LuaUVec2Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer)):(LuaUVec2) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaUVec2) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec2),(LuaUVec2),(LuaUVec2)):(LuaUVec2) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 3-dimensional vector. +-- + record LuaUVec3 + userdata + + -- Fields + x : integer + + y : integer + + z : integer + + -- Pure methods + --Creates a 4D vector from `self` and the given `w` value. + extend: function(LuaUVec3,integer):(LuaUVec4) + + --Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. + -- + -- + -- + --Truncation may also be performed by using `self.xy()` or `UVec2::from()`. + truncate: function(LuaUVec3):(LuaUVec2) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaUVec3,LuaUVec3):(integer) + + --Computes the cross product of `self` and `rhs`. + cross: function(LuaUVec3,LuaUVec3):(LuaUVec3) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaUVec3,LuaUVec3):(LuaUVec3) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaUVec3,LuaUVec3):(LuaUVec3) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaUVec3,(LuaUVec3),(LuaUVec3)):(LuaUVec3) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaUVec3):(integer) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaUVec3):(integer) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaUVec3,LuaUVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaUVec3,LuaUVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaUVec3,LuaUVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaUVec3,LuaUVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaUVec3,LuaUVec3):(LuaBVec3) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaUVec3,LuaUVec3):(LuaBVec3) + + --Casts all elements of `self` to `f32`. + as_vec3: function(LuaUVec3):(LuaVec3) + + --Casts all elements of `self` to `f32`. + as_vec3a: function(LuaUVec3):(LuaVec3A) + + --Casts all elements of `self` to `f64`. + as_dvec3: function(LuaUVec3):(LuaDVec3) + + --Casts all elements of `self` to `i32`. + as_ivec3: function(LuaUVec3):(LuaIVec3) + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer),(integer)):(LuaUVec3) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaUVec3) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec3),(LuaUVec3),(LuaUVec3)):(LuaUVec3) + + -- Meta methods + metamethod __tostring: function(LuaUVec3):(string) + + metamethod __index: function(LuaUVec3,integer):(integer) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaUVec3,(integer),(integer)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaUVec3`]. + record LuaUVec3Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer),(integer)):(LuaUVec3) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaUVec3) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec3),(LuaUVec3),(LuaUVec3)):(LuaUVec3) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 4-dimensional vector. +-- + record LuaUVec4 + userdata + + -- Fields + x : integer + + y : integer + + z : integer + + w : integer + + -- Pure methods + --Creates a 2D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. + -- + -- + -- + --Truncation to `UVec3` may also be performed by using `self.xyz()` or `UVec3::from()`. + truncate: function(LuaUVec4):(LuaUVec3) + + --Computes the dot product of `self` and `rhs`. + dot: function(LuaUVec4,LuaUVec4):(integer) + + --Returns a vector containing the minimum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min: function(LuaUVec4,LuaUVec4):(LuaUVec4) + + --Returns a vector containing the maximum values for each element of `self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max: function(LuaUVec4,LuaUVec4):(LuaUVec4) + + --Component-wise clamping of values, similar to [`f32::clamp`]. + -- + -- + -- + --Each element in `min` must be less-or-equal to the corresponding element in `max`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp: function(LuaUVec4,(LuaUVec4),(LuaUVec4)):(LuaUVec4) + + --Returns the horizontal minimum of `self`. + -- + -- + -- + --In other words this computes `min(x, y, ..)`. + min_element: function(LuaUVec4):(integer) + + --Returns the horizontal maximum of `self`. + -- + -- + -- + --In other words this computes `max(x, y, ..)`. + max_element: function(LuaUVec4):(integer) + + --Returns a vector mask containing the result of a `==` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + -- + --elements. + cmpeq: function(LuaUVec4,LuaUVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `!=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + -- + --elements. + cmpne: function(LuaUVec4,LuaUVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `>=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + -- + --elements. + cmpge: function(LuaUVec4,LuaUVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `>` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + -- + --elements. + cmpgt: function(LuaUVec4,LuaUVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `<=` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + -- + --elements. + cmple: function(LuaUVec4,LuaUVec4):(LuaBVec4) + + --Returns a vector mask containing the result of a `<` comparison for each element of + -- + --`self` and `rhs`. + -- + -- + -- + --In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + -- + --elements. + cmplt: function(LuaUVec4,LuaUVec4):(LuaBVec4) + + --Casts all elements of `self` to `f32`. + as_vec4: function(LuaUVec4):(LuaVec4) + + --Casts all elements of `self` to `f64`. + as_dvec4: function(LuaUVec4):(LuaDVec4) + + --Casts all elements of `self` to `i32`. + as_ivec4: function(LuaUVec4):(LuaIVec4) + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer),(integer),(integer)):(LuaUVec4) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaUVec4) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec4),(LuaUVec4),(LuaUVec4)):(LuaUVec4) + + -- Meta methods + metamethod __tostring: function(LuaUVec4):(string) + + metamethod __index: function(LuaUVec4,integer):(integer) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaUVec4,(integer),(integer)):() + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaUVec4`]. + record LuaUVec4Class + userdata + + -- Pure functions + --Creates a new vector. + new: function((integer),(integer),(integer),(integer)):(LuaUVec4) + + --Creates a vector with all elements set to `v`. + splat: function(integer):(LuaUVec4) + + --Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + -- + --for each element of `self`. + -- + -- + -- + --A true element in the mask uses the corresponding element from `if_true`, and false + -- + --uses the element from `if_false`. + select: function((LuaBVec4),(LuaUVec4),(LuaUVec4)):(LuaUVec4) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + metamethod __mod: function((any),(any)):(any) + + + end +--A 3x3 column major matrix. +-- +-- +-- +--This 3x3 matrix type features convenience methods for creating and using linear and +-- +--affine transformations. If you are primarily dealing with 2D affine transformations the +-- +--[`Affine2`](crate::Affine2) type is much faster and more space efficient than +-- +--using a 3x3 matrix. +-- +-- +-- +--Linear transformations including 3D rotation and scale can be created using methods +-- +--such as [`Self::from_diagonal()`], [`Self::from_quat()`], [`Self::from_axis_angle()`], +-- +--[`Self::from_rotation_x()`], [`Self::from_rotation_y()`], or +-- +--[`Self::from_rotation_z()`]. +-- +-- +-- +--The resulting matrices can be use to transform 3D vectors using regular vector +-- +--multiplication. +-- +-- +-- +--Affine transformations including 2D translation, rotation and scale can be created +-- +--using methods such as [`Self::from_translation()`], [`Self::from_angle()`], +-- +--[`Self::from_scale()`] and [`Self::from_scale_angle_translation()`]. +-- +-- +-- +--The [`Self::transform_point2()`] and [`Self::transform_vector2()`] convenience methods +-- +--are provided for performing affine transforms on 2D vectors and points. These multiply +-- +--2D inputs as 3D vectors with an implicit `z` value of `1` for points and `0` for +-- +--vectors respectively. These methods assume that `Self` contains a valid affine +-- +--transform. +-- + record LuaMat3 + userdata + + -- Fields + x_axis : LuaVec3 + + y_axis : LuaVec3 + + z_axis : LuaVec3 + + -- Pure methods + --Returns the matrix column for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 2. + col: function(LuaMat3,integer):(LuaVec3) + + --Returns the matrix row for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 2. + row: function(LuaMat3,integer):(LuaVec3) + + --Returns `true` if, and only if, all elements are finite. + -- + --If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaMat3):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaMat3):(boolean) + + --Returns the transpose of `self`. + transpose: function(LuaMat3):(LuaMat3) + + --Returns the determinant of `self`. + determinant: function(LuaMat3):(number) + + --Returns the inverse of `self`. + -- + -- + -- + --If the matrix is not invertible the returned matrix will be invalid. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse: function(LuaMat3):(LuaMat3) + + --Transforms the given 2D vector as a point. + -- + -- + -- + --This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. + -- + -- + -- + --This method assumes that `self` contains a valid affine transform. + transform_point2: function(LuaMat3,LuaVec2):(LuaVec2) + + --Rotates the given 2D vector. + -- + -- + -- + --This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. + -- + -- + -- + --This method assumes that `self` contains a valid affine transform. + transform_vector2: function(LuaMat3,LuaVec2):(LuaVec2) + + --Transforms a 3D vector. + mul_vec3: function(LuaMat3,LuaVec3):(LuaVec3) + + --Transforms a `Vec3A`. + mul_vec3a: function(LuaMat3,LuaVec3A):(LuaVec3A) + + --Multiplies two 3x3 matrices. + mul_mat3: function(LuaMat3,LuaMat3):(LuaMat3) + + --Adds two 3x3 matrices. + add_mat3: function(LuaMat3,LuaMat3):(LuaMat3) + + --Subtracts two 3x3 matrices. + sub_mat3: function(LuaMat3,LuaMat3):(LuaMat3) + + --Multiplies a 3x3 matrix by a scalar. + mul_scalar: function(LuaMat3,number):(LuaMat3) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two matrices contain similar elements. It works best + -- + --when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaMat3,(LuaMat3),(number)):(boolean) + + as_dmat3: function(LuaMat3):(LuaDMat3) + + -- Pure functions + --Creates a 3x3 matrix from two column vectors. + from_cols: function((LuaVec3),(LuaVec3),(LuaVec3)):(LuaMat3) + + --Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaVec3):(LuaMat3) + + --Creates a 3x3 matrix from a 4x4 matrix, discarding the 3rd row and column. + from_mat4: function(LuaMat4):(LuaMat3) + + --Creates a 3D rotation matrix from the given quaternion. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat: function(LuaQuat):(LuaMat3) + + --Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in + -- + --radians). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaVec3),(number)):(LuaMat3) + + --Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in + -- + --radians). + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + from_rotation_x: function(number):(LuaMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + from_rotation_y: function(number):(LuaMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + from_rotation_z: function(number):(LuaMat3) + + --Creates an affine transformation matrix from the given 2D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_translation: function(LuaVec2):(LuaMat3) + + --Creates an affine transformation matrix from the given 2D rotation `angle` (in + -- + --radians). + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_angle: function(number):(LuaMat3) + + --Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in + -- + --radians) and `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_scale_angle_translation: function((LuaVec2),(number),(LuaVec2)):(LuaMat3) + + --Creates an affine transformation matrix from the given non-uniform 2D `scale`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale: function(LuaVec2):(LuaMat3) + + --Creates an affine transformation matrix from the given 2x2 matrix. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_mat2: function(LuaMat2):(LuaMat3) + + -- Meta methods + metamethod __tostring: function(LuaMat3):(string) + + metamethod __unm: function(LuaMat3):(LuaMat3) + + -- Mutating MetaMethods + metamethod __index: function(LuaMat3,integer):(LuaVec3) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaMat3`]. + record LuaMat3Class + userdata + + -- Pure functions + --Creates a 3x3 matrix from two column vectors. + from_cols: function((LuaVec3),(LuaVec3),(LuaVec3)):(LuaMat3) + + --Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaVec3):(LuaMat3) + + --Creates a 3x3 matrix from a 4x4 matrix, discarding the 3rd row and column. + from_mat4: function(LuaMat4):(LuaMat3) + + --Creates a 3D rotation matrix from the given quaternion. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat: function(LuaQuat):(LuaMat3) + + --Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in + -- + --radians). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaVec3),(number)):(LuaMat3) + + --Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in + -- + --radians). + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + from_rotation_x: function(number):(LuaMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + from_rotation_y: function(number):(LuaMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + from_rotation_z: function(number):(LuaMat3) + + --Creates an affine transformation matrix from the given 2D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_translation: function(LuaVec2):(LuaMat3) + + --Creates an affine transformation matrix from the given 2D rotation `angle` (in + -- + --radians). + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_angle: function(number):(LuaMat3) + + --Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in + -- + --radians) and `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_scale_angle_translation: function((LuaVec2),(number),(LuaVec2)):(LuaMat3) + + --Creates an affine transformation matrix from the given non-uniform 2D `scale`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale: function(LuaVec2):(LuaMat3) + + --Creates an affine transformation matrix from the given 2x2 matrix. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_mat2: function(LuaMat2):(LuaMat3) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A 2x2 column major matrix. +-- + record LuaMat2 + userdata + + -- Pure methods + --Returns the matrix column for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 1. + col: function(LuaMat2,integer):(LuaVec2) + + --Returns the matrix row for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 1. + row: function(LuaMat2,integer):(LuaVec2) + + --Returns `true` if, and only if, all elements are finite. + -- + --If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaMat2):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaMat2):(boolean) + + --Returns the transpose of `self`. + transpose: function(LuaMat2):(LuaMat2) + + --Returns the determinant of `self`. + determinant: function(LuaMat2):(number) + + --Returns the inverse of `self`. + -- + -- + -- + --If the matrix is not invertible the returned matrix will be invalid. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse: function(LuaMat2):(LuaMat2) + + --Transforms a 2D vector. + mul_vec2: function(LuaMat2,LuaVec2):(LuaVec2) + + --Multiplies two 2x2 matrices. + mul_mat2: function(LuaMat2,LuaMat2):(LuaMat2) + + --Adds two 2x2 matrices. + add_mat2: function(LuaMat2,LuaMat2):(LuaMat2) + + --Subtracts two 2x2 matrices. + sub_mat2: function(LuaMat2,LuaMat2):(LuaMat2) + + --Multiplies a 2x2 matrix by a scalar. + mul_scalar: function(LuaMat2,number):(LuaMat2) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two matrices contain similar elements. It works best + -- + --when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaMat2,(LuaMat2),(number)):(boolean) + + as_dmat2: function(LuaMat2):(LuaDMat2) + + -- Pure functions + --Creates a 2x2 matrix from two column vectors. + from_cols: function((LuaVec2),(LuaVec2)):(LuaMat2) + + --Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaVec2):(LuaMat2) + + --Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of + -- + --`angle` (in radians). + from_scale_angle: function((LuaVec2),(number)):(LuaMat2) + + --Creates a 2x2 matrix containing a rotation of `angle` (in radians). + from_angle: function(number):(LuaMat2) + + --Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + from_mat3: function(LuaMat3):(LuaMat2) + + -- Meta methods + metamethod __tostring: function(LuaMat2):(string) + + metamethod __unm: function(LuaMat2):(LuaMat2) + + -- Mutating MetaMethods + metamethod __index: function(LuaMat2,integer):(LuaVec2) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaMat2`]. + record LuaMat2Class + userdata + + -- Pure functions + --Creates a 2x2 matrix from two column vectors. + from_cols: function((LuaVec2),(LuaVec2)):(LuaMat2) + + --Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaVec2):(LuaMat2) + + --Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of + -- + --`angle` (in radians). + from_scale_angle: function((LuaVec2),(number)):(LuaMat2) + + --Creates a 2x2 matrix containing a rotation of `angle` (in radians). + from_angle: function(number):(LuaMat2) + + --Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + from_mat3: function(LuaMat3):(LuaMat2) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A 3x3 column major matrix. +-- +-- +-- +--This 3x3 matrix type features convenience methods for creating and using linear and +-- +--affine transformations. If you are primarily dealing with 2D affine transformations the +-- +--[`Affine2`](crate::Affine2) type is much faster and more space efficient than +-- +--using a 3x3 matrix. +-- +-- +-- +--Linear transformations including 3D rotation and scale can be created using methods +-- +--such as [`Self::from_diagonal()`], [`Self::from_quat()`], [`Self::from_axis_angle()`], +-- +--[`Self::from_rotation_x()`], [`Self::from_rotation_y()`], or +-- +--[`Self::from_rotation_z()`]. +-- +-- +-- +--The resulting matrices can be use to transform 3D vectors using regular vector +-- +--multiplication. +-- +-- +-- +--Affine transformations including 2D translation, rotation and scale can be created +-- +--using methods such as [`Self::from_translation()`], [`Self::from_angle()`], +-- +--[`Self::from_scale()`] and [`Self::from_scale_angle_translation()`]. +-- +-- +-- +--The [`Self::transform_point2()`] and [`Self::transform_vector2()`] convenience methods +-- +--are provided for performing affine transforms on 2D vectors and points. These multiply +-- +--2D inputs as 3D vectors with an implicit `z` value of `1` for points and `0` for +-- +--vectors respectively. These methods assume that `Self` contains a valid affine +-- +--transform. +-- + record LuaMat3A + userdata + + -- Fields + x_axis : LuaVec3A + + y_axis : LuaVec3A + + z_axis : LuaVec3A + + -- Pure methods + --Returns the matrix column for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 2. + col: function(LuaMat3A,integer):(LuaVec3A) + + --Returns the matrix row for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 2. + row: function(LuaMat3A,integer):(LuaVec3A) + + --Returns `true` if, and only if, all elements are finite. + -- + --If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaMat3A):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaMat3A):(boolean) + + --Returns the transpose of `self`. + transpose: function(LuaMat3A):(LuaMat3A) + + --Returns the determinant of `self`. + determinant: function(LuaMat3A):(number) + + --Returns the inverse of `self`. + -- + -- + -- + --If the matrix is not invertible the returned matrix will be invalid. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse: function(LuaMat3A):(LuaMat3A) + + --Transforms the given 2D vector as a point. + -- + -- + -- + --This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. + -- + -- + -- + --This method assumes that `self` contains a valid affine transform. + transform_point2: function(LuaMat3A,LuaVec2):(LuaVec2) + + --Rotates the given 2D vector. + -- + -- + -- + --This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. + -- + -- + -- + --This method assumes that `self` contains a valid affine transform. + transform_vector2: function(LuaMat3A,LuaVec2):(LuaVec2) + + --Transforms a 3D vector. + mul_vec3: function(LuaMat3A,LuaVec3):(LuaVec3) + + --Transforms a `Vec3A`. + mul_vec3a: function(LuaMat3A,LuaVec3A):(LuaVec3A) + + --Multiplies two 3x3 matrices. + mul_mat3: function(LuaMat3A,LuaMat3A):(LuaMat3A) + + --Adds two 3x3 matrices. + add_mat3: function(LuaMat3A,LuaMat3A):(LuaMat3A) + + --Subtracts two 3x3 matrices. + sub_mat3: function(LuaMat3A,LuaMat3A):(LuaMat3A) + + --Multiplies a 3x3 matrix by a scalar. + mul_scalar: function(LuaMat3A,number):(LuaMat3A) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two matrices contain similar elements. It works best + -- + --when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaMat3A,(LuaMat3A),(number)):(boolean) + + as_dmat3: function(LuaMat3A):(LuaDMat3) + + -- Pure functions + --Creates a 3x3 matrix from two column vectors. + from_cols: function((LuaVec3A),(LuaVec3A),(LuaVec3A)):(LuaMat3A) + + --Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaVec3):(LuaMat3A) + + --Creates a 3x3 matrix from a 4x4 matrix, discarding the 3rd row and column. + from_mat4: function(LuaMat4):(LuaMat3A) + + --Creates a 3D rotation matrix from the given quaternion. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat: function(LuaQuat):(LuaMat3A) + + --Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in + -- + --radians). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaVec3),(number)):(LuaMat3A) + + --Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in + -- + --radians). + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaMat3A) + + --Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + from_rotation_x: function(number):(LuaMat3A) + + --Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + from_rotation_y: function(number):(LuaMat3A) + + --Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + from_rotation_z: function(number):(LuaMat3A) + + --Creates an affine transformation matrix from the given 2D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_translation: function(LuaVec2):(LuaMat3A) + + --Creates an affine transformation matrix from the given 2D rotation `angle` (in + -- + --radians). + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_angle: function(number):(LuaMat3A) + + --Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in + -- + --radians) and `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_scale_angle_translation: function((LuaVec2),(number),(LuaVec2)):(LuaMat3A) + + --Creates an affine transformation matrix from the given non-uniform 2D `scale`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale: function(LuaVec2):(LuaMat3A) + + --Creates an affine transformation matrix from the given 2x2 matrix. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_mat2: function(LuaMat2):(LuaMat3A) + + -- Meta methods + metamethod __tostring: function(LuaMat3A):(string) + + metamethod __unm: function(LuaMat3A):(LuaMat3A) + + -- Mutating MetaMethods + metamethod __index: function(LuaMat3A,integer):(LuaVec3A) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaMat3A`]. + record LuaMat3AClass + userdata + + -- Pure functions + --Creates a 3x3 matrix from two column vectors. + from_cols: function((LuaVec3A),(LuaVec3A),(LuaVec3A)):(LuaMat3A) + + --Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaVec3):(LuaMat3A) + + --Creates a 3x3 matrix from a 4x4 matrix, discarding the 3rd row and column. + from_mat4: function(LuaMat4):(LuaMat3A) + + --Creates a 3D rotation matrix from the given quaternion. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat: function(LuaQuat):(LuaMat3A) + + --Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in + -- + --radians). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaVec3),(number)):(LuaMat3A) + + --Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in + -- + --radians). + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaMat3A) + + --Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + from_rotation_x: function(number):(LuaMat3A) + + --Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + from_rotation_y: function(number):(LuaMat3A) + + --Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + from_rotation_z: function(number):(LuaMat3A) + + --Creates an affine transformation matrix from the given 2D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_translation: function(LuaVec2):(LuaMat3A) + + --Creates an affine transformation matrix from the given 2D rotation `angle` (in + -- + --radians). + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_angle: function(number):(LuaMat3A) + + --Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in + -- + --radians) and `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_scale_angle_translation: function((LuaVec2),(number),(LuaVec2)):(LuaMat3A) + + --Creates an affine transformation matrix from the given non-uniform 2D `scale`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale: function(LuaVec2):(LuaMat3A) + + --Creates an affine transformation matrix from the given 2x2 matrix. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_mat2: function(LuaMat2):(LuaMat3A) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A 4x4 column major matrix. +-- +-- +-- +--This 4x4 matrix type features convenience methods for creating and using affine transforms and +-- +--perspective projections. If you are primarily dealing with 3D affine transformations +-- +--considering using [`Affine3A`](crate::Affine3A) which is faster than a 4x4 matrix +-- +--for some affine operations. +-- +-- +-- +--Affine transformations including 3D translation, rotation and scale can be created +-- +--using methods such as [`Self::from_translation()`], [`Self::from_quat()`], +-- +--[`Self::from_scale()`] and [`Self::from_scale_rotation_translation()`]. +-- +-- +-- +--Othographic projections can be created using the methods [`Self::orthographic_lh()`] for +-- +--left-handed coordinate systems and [`Self::orthographic_rh()`] for right-handed +-- +--systems. The resulting matrix is also an affine transformation. +-- +-- +-- +--The [`Self::transform_point3()`] and [`Self::transform_vector3()`] convenience methods +-- +--are provided for performing affine transformations on 3D vectors and points. These +-- +--multiply 3D inputs as 4D vectors with an implicit `w` value of `1` for points and `0` +-- +--for vectors respectively. These methods assume that `Self` contains a valid affine +-- +--transform. +-- +-- +-- +--Perspective projections can be created using methods such as +-- +--[`Self::perspective_lh()`], [`Self::perspective_infinite_lh()`] and +-- +--[`Self::perspective_infinite_reverse_lh()`] for left-handed co-ordinate systems and +-- +--[`Self::perspective_rh()`], [`Self::perspective_infinite_rh()`] and +-- +--[`Self::perspective_infinite_reverse_rh()`] for right-handed co-ordinate systems. +-- +-- +-- +--The resulting perspective project can be use to transform 3D vectors as points with +-- +--perspective correction using the [`Self::project_point3()`] convenience method. +-- + record LuaMat4 + userdata + + -- Fields + x_axis : LuaVec4 + + y_axis : LuaVec4 + + z_axis : LuaVec4 + + w_axis : LuaVec4 + + -- Pure methods + --Returns the matrix column for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 3. + col: function(LuaMat4,integer):(LuaVec4) + + --Returns the matrix row for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 3. + row: function(LuaMat4,integer):(LuaVec4) + + --Returns `true` if, and only if, all elements are finite. + -- + --If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaMat4):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaMat4):(boolean) + + --Returns the transpose of `self`. + transpose: function(LuaMat4):(LuaMat4) + + --Returns the determinant of `self`. + determinant: function(LuaMat4):(number) + + --Returns the inverse of `self`. + -- + -- + -- + --If the matrix is not invertible the returned matrix will be invalid. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse: function(LuaMat4):(LuaMat4) + + --Transforms the given 3D vector as a point, applying perspective correction. + -- + -- + -- + --This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is `1.0`. + -- + --The perspective divide is performed meaning the resulting 3D vector is divided by `w`. + -- + -- + -- + --This method assumes that `self` contains a projective transform. + project_point3: function(LuaMat4,LuaVec3):(LuaVec3) + + --Transforms the given 3D vector as a point. + -- + -- + -- + --This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is + -- + --`1.0`. + -- + -- + -- + --This method assumes that `self` contains a valid affine transform. It does not perform + -- + --a persective divide, if `self` contains a perspective transform, or if you are unsure, + -- + --the [`Self::project_point3()`] method should be used instead. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + transform_point3: function(LuaMat4,LuaVec3):(LuaVec3) + + --Transforms the give 3D vector as a direction. + -- + -- + -- + --This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is + -- + --`0.0`. + -- + -- + -- + --This method assumes that `self` contains a valid affine transform. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + transform_vector3: function(LuaMat4,LuaVec3):(LuaVec3) + + --Transforms the given `Vec3A` as 3D point. + -- + -- + -- + --This is the equivalent of multiplying the `Vec3A` as a 4D vector where `w` is `1.0`. + transform_point3a: function(LuaMat4,LuaVec3A):(LuaVec3A) + + --Transforms the give `Vec3A` as 3D vector. + -- + -- + -- + --This is the equivalent of multiplying the `Vec3A` as a 4D vector where `w` is `0.0`. + transform_vector3a: function(LuaMat4,LuaVec3A):(LuaVec3A) + + --Transforms a 4D vector. + mul_vec4: function(LuaMat4,LuaVec4):(LuaVec4) + + --Multiplies two 4x4 matrices. + mul_mat4: function(LuaMat4,LuaMat4):(LuaMat4) + + --Adds two 4x4 matrices. + add_mat4: function(LuaMat4,LuaMat4):(LuaMat4) + + --Subtracts two 4x4 matrices. + sub_mat4: function(LuaMat4,LuaMat4):(LuaMat4) + + --Multiplies a 4x4 matrix by a scalar. + mul_scalar: function(LuaMat4,number):(LuaMat4) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two matrices contain similar elements. It works best + -- + --when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaMat4,(LuaMat4),(number)):(boolean) + + as_dmat4: function(LuaMat4):(LuaDMat4) + + -- Pure functions + --Creates a 4x4 matrix from two column vectors. + from_cols: function((LuaVec4),(LuaVec4),(LuaVec4),(LuaVec4)):(LuaMat4) + + --Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaVec4):(LuaMat4) + + --Creates an affine transformation matrix from the given 3D `scale`, `rotation` and + -- + --`translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_scale_rotation_translation: function((LuaVec3),(LuaQuat),(LuaVec3)):(LuaMat4) + + --Creates an affine transformation matrix from the given 3D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_rotation_translation: function((LuaQuat),(LuaVec3)):(LuaMat4) + + --Creates an affine transformation matrix from the given `rotation` quaternion. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat: function(LuaQuat):(LuaMat4) + + --Creates an affine transformation matrix from the given 3x3 linear transformation + -- + --matrix. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_mat3: function(LuaMat3):(LuaMat4) + + --Creates an affine transformation matrix from the given 3D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_translation: function(LuaVec3):(LuaMat4) + + --Creates an affine transformation matrix containing a 3D rotation around a normalized + -- + --rotation `axis` of `angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaVec3),(number)):(LuaMat4) + + --Creates a affine transformation matrix containing a rotation from the given euler + -- + --rotation sequence and angles (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the x axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_x: function(number):(LuaMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the y axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_y: function(number):(LuaMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the z axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_z: function(number):(LuaMat4) + + --Creates an affine transformation matrix containing the given 3D non-uniform `scale`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale: function(LuaVec3):(LuaMat4) + + --Creates a left-handed view matrix using a camera position, an up direction, and a focal + -- + --point. + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh: function((LuaVec3),(LuaVec3),(LuaVec3)):(LuaMat4) + + --Creates a right-handed view matrix using a camera position, an up direction, and a focal + -- + --point. + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh: function((LuaVec3),(LuaVec3),(LuaVec3)):(LuaMat4) + + --Creates a right-handed perspective projection matrix with [-1,1] depth range. + -- + --This is the same as the OpenGL `gluPerspective` function. + -- + --See + perspective_rh_gl: function((number),(number),(number),(number)):(LuaMat4) + + --Creates a left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + -- + --enabled. + perspective_lh: function((number),(number),(number),(number)):(LuaMat4) + + --Creates a right-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + -- + --enabled. + perspective_rh: function((number),(number),(number),(number)):(LuaMat4) + + --Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_lh: function((number),(number),(number)):(LuaMat4) + + --Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_reverse_lh: function((number),(number),(number)):(LuaMat4) + + --Creates an infinite right-handed perspective projection matrix with + -- + --`[0,1]` depth range. + perspective_infinite_rh: function((number),(number),(number)):(LuaMat4) + + --Creates an infinite reverse right-handed perspective projection matrix + -- + --with `[0,1]` depth range. + perspective_infinite_reverse_rh: function((number),(number),(number)):(LuaMat4) + + --Creates a right-handed orthographic projection matrix with `[-1,1]` depth + -- + --range. This is the same as the OpenGL `glOrtho` function in OpenGL. + -- + --See + -- + -- + orthographic_rh_gl: function((number),(number),(number),(number),(number),(number)):(LuaMat4) + + --Creates a left-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_lh: function((number),(number),(number),(number),(number),(number)):(LuaMat4) + + --Creates a right-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_rh: function((number),(number),(number),(number),(number),(number)):(LuaMat4) + + -- Meta methods + metamethod __tostring: function(LuaMat4):(string) + + metamethod __unm: function(LuaMat4):(LuaMat4) + + -- Mutating MetaMethods + metamethod __index: function(LuaMat4,integer):(LuaVec4) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaMat4`]. + record LuaMat4Class + userdata + + -- Pure functions + --Creates a 4x4 matrix from two column vectors. + from_cols: function((LuaVec4),(LuaVec4),(LuaVec4),(LuaVec4)):(LuaMat4) + + --Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaVec4):(LuaMat4) + + --Creates an affine transformation matrix from the given 3D `scale`, `rotation` and + -- + --`translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_scale_rotation_translation: function((LuaVec3),(LuaQuat),(LuaVec3)):(LuaMat4) + + --Creates an affine transformation matrix from the given 3D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_rotation_translation: function((LuaQuat),(LuaVec3)):(LuaMat4) + + --Creates an affine transformation matrix from the given `rotation` quaternion. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat: function(LuaQuat):(LuaMat4) + + --Creates an affine transformation matrix from the given 3x3 linear transformation + -- + --matrix. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_mat3: function(LuaMat3):(LuaMat4) + + --Creates an affine transformation matrix from the given 3D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_translation: function(LuaVec3):(LuaMat4) + + --Creates an affine transformation matrix containing a 3D rotation around a normalized + -- + --rotation `axis` of `angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaVec3),(number)):(LuaMat4) + + --Creates a affine transformation matrix containing a rotation from the given euler + -- + --rotation sequence and angles (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the x axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_x: function(number):(LuaMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the y axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_y: function(number):(LuaMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the z axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_z: function(number):(LuaMat4) + + --Creates an affine transformation matrix containing the given 3D non-uniform `scale`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale: function(LuaVec3):(LuaMat4) + + --Creates a left-handed view matrix using a camera position, an up direction, and a focal + -- + --point. + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh: function((LuaVec3),(LuaVec3),(LuaVec3)):(LuaMat4) + + --Creates a right-handed view matrix using a camera position, an up direction, and a focal + -- + --point. + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh: function((LuaVec3),(LuaVec3),(LuaVec3)):(LuaMat4) + + --Creates a right-handed perspective projection matrix with [-1,1] depth range. + -- + --This is the same as the OpenGL `gluPerspective` function. + -- + --See + perspective_rh_gl: function((number),(number),(number),(number)):(LuaMat4) + + --Creates a left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + -- + --enabled. + perspective_lh: function((number),(number),(number),(number)):(LuaMat4) + + --Creates a right-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + -- + --enabled. + perspective_rh: function((number),(number),(number),(number)):(LuaMat4) + + --Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_lh: function((number),(number),(number)):(LuaMat4) + + --Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_reverse_lh: function((number),(number),(number)):(LuaMat4) + + --Creates an infinite right-handed perspective projection matrix with + -- + --`[0,1]` depth range. + perspective_infinite_rh: function((number),(number),(number)):(LuaMat4) + + --Creates an infinite reverse right-handed perspective projection matrix + -- + --with `[0,1]` depth range. + perspective_infinite_reverse_rh: function((number),(number),(number)):(LuaMat4) + + --Creates a right-handed orthographic projection matrix with `[-1,1]` depth + -- + --range. This is the same as the OpenGL `glOrtho` function in OpenGL. + -- + --See + -- + -- + orthographic_rh_gl: function((number),(number),(number),(number),(number),(number)):(LuaMat4) + + --Creates a left-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_lh: function((number),(number),(number),(number),(number),(number)):(LuaMat4) + + --Creates a right-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_rh: function((number),(number),(number),(number),(number),(number)):(LuaMat4) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A 2x2 column major matrix. +-- + record LuaDMat2 + userdata + + -- Fields + x_axis : LuaDVec2 + + y_axis : LuaDVec2 + + -- Pure methods + --Returns the matrix column for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 1. + col: function(LuaDMat2,integer):(LuaDVec2) + + --Returns the matrix row for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 1. + row: function(LuaDMat2,integer):(LuaDVec2) + + --Returns `true` if, and only if, all elements are finite. + -- + --If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaDMat2):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaDMat2):(boolean) + + --Returns the transpose of `self`. + transpose: function(LuaDMat2):(LuaDMat2) + + --Returns the determinant of `self`. + determinant: function(LuaDMat2):(number) + + --Returns the inverse of `self`. + -- + -- + -- + --If the matrix is not invertible the returned matrix will be invalid. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse: function(LuaDMat2):(LuaDMat2) + + --Transforms a 2D vector. + mul_vec2: function(LuaDMat2,LuaDVec2):(LuaDVec2) + + --Multiplies two 2x2 matrices. + mul_mat2: function(LuaDMat2,LuaDMat2):(LuaDMat2) + + --Adds two 2x2 matrices. + add_mat2: function(LuaDMat2,LuaDMat2):(LuaDMat2) + + --Subtracts two 2x2 matrices. + sub_mat2: function(LuaDMat2,LuaDMat2):(LuaDMat2) + + --Multiplies a 2x2 matrix by a scalar. + mul_scalar: function(LuaDMat2,number):(LuaDMat2) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two matrices contain similar elements. It works best + -- + --when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaDMat2,(LuaDMat2),(number)):(boolean) + + as_mat2: function(LuaDMat2):(LuaMat2) + + -- Pure functions + --Creates a 2x2 matrix from two column vectors. + from_cols: function((LuaDVec2),(LuaDVec2)):(LuaDMat2) + + --Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaDVec2):(LuaDMat2) + + --Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of + -- + --`angle` (in radians). + from_scale_angle: function((LuaDVec2),(number)):(LuaDMat2) + + --Creates a 2x2 matrix containing a rotation of `angle` (in radians). + from_angle: function(number):(LuaDMat2) + + --Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + from_mat3: function(LuaDMat3):(LuaDMat2) + + -- Meta methods + metamethod __tostring: function(LuaDMat2):(string) + + metamethod __unm: function(LuaDMat2):(LuaDMat2) + + -- Mutating MetaMethods + metamethod __index: function(LuaDMat2,integer):(LuaDVec2) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaDMat2`]. + record LuaDMat2Class + userdata + + -- Pure functions + --Creates a 2x2 matrix from two column vectors. + from_cols: function((LuaDVec2),(LuaDVec2)):(LuaDMat2) + + --Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaDVec2):(LuaDMat2) + + --Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of + -- + --`angle` (in radians). + from_scale_angle: function((LuaDVec2),(number)):(LuaDMat2) + + --Creates a 2x2 matrix containing a rotation of `angle` (in radians). + from_angle: function(number):(LuaDMat2) + + --Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + from_mat3: function(LuaDMat3):(LuaDMat2) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A 3x3 column major matrix. +-- +-- +-- +--This 3x3 matrix type features convenience methods for creating and using linear and +-- +--affine transformations. If you are primarily dealing with 2D affine transformations the +-- +--[`DAffine2`](crate::DAffine2) type is much faster and more space efficient than +-- +--using a 3x3 matrix. +-- +-- +-- +--Linear transformations including 3D rotation and scale can be created using methods +-- +--such as [`Self::from_diagonal()`], [`Self::from_quat()`], [`Self::from_axis_angle()`], +-- +--[`Self::from_rotation_x()`], [`Self::from_rotation_y()`], or +-- +--[`Self::from_rotation_z()`]. +-- +-- +-- +--The resulting matrices can be use to transform 3D vectors using regular vector +-- +--multiplication. +-- +-- +-- +--Affine transformations including 2D translation, rotation and scale can be created +-- +--using methods such as [`Self::from_translation()`], [`Self::from_angle()`], +-- +--[`Self::from_scale()`] and [`Self::from_scale_angle_translation()`]. +-- +-- +-- +--The [`Self::transform_point2()`] and [`Self::transform_vector2()`] convenience methods +-- +--are provided for performing affine transforms on 2D vectors and points. These multiply +-- +--2D inputs as 3D vectors with an implicit `z` value of `1` for points and `0` for +-- +--vectors respectively. These methods assume that `Self` contains a valid affine +-- +--transform. +-- + record LuaDMat3 + userdata + + -- Fields + x_axis : LuaDVec3 + + y_axis : LuaDVec3 + + z_axis : LuaDVec3 + + -- Pure methods + --Returns the matrix column for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 2. + col: function(LuaDMat3,integer):(LuaDVec3) + + --Returns the matrix row for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 2. + row: function(LuaDMat3,integer):(LuaDVec3) + + --Returns `true` if, and only if, all elements are finite. + -- + --If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaDMat3):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaDMat3):(boolean) + + --Returns the transpose of `self`. + transpose: function(LuaDMat3):(LuaDMat3) + + --Returns the determinant of `self`. + determinant: function(LuaDMat3):(number) + + --Returns the inverse of `self`. + -- + -- + -- + --If the matrix is not invertible the returned matrix will be invalid. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse: function(LuaDMat3):(LuaDMat3) + + --Transforms the given 2D vector as a point. + -- + -- + -- + --This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. + -- + -- + -- + --This method assumes that `self` contains a valid affine transform. + transform_point2: function(LuaDMat3,LuaDVec2):(LuaDVec2) + + --Rotates the given 2D vector. + -- + -- + -- + --This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. + -- + -- + -- + --This method assumes that `self` contains a valid affine transform. + transform_vector2: function(LuaDMat3,LuaDVec2):(LuaDVec2) + + --Transforms a 3D vector. + mul_vec3: function(LuaDMat3,LuaDVec3):(LuaDVec3) + + --Multiplies two 3x3 matrices. + mul_mat3: function(LuaDMat3,LuaDMat3):(LuaDMat3) + + --Adds two 3x3 matrices. + add_mat3: function(LuaDMat3,LuaDMat3):(LuaDMat3) + + --Subtracts two 3x3 matrices. + sub_mat3: function(LuaDMat3,LuaDMat3):(LuaDMat3) + + --Multiplies a 3x3 matrix by a scalar. + mul_scalar: function(LuaDMat3,number):(LuaDMat3) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two matrices contain similar elements. It works best + -- + --when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaDMat3,(LuaDMat3),(number)):(boolean) + + as_mat3: function(LuaDMat3):(LuaMat3) + + -- Pure functions + --Creates a 3x3 matrix from two column vectors. + from_cols: function((LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDMat3) + + --Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaDVec3):(LuaDMat3) + + --Creates a 3x3 matrix from a 4x4 matrix, discarding the 3rd row and column. + from_mat4: function(LuaDMat4):(LuaDMat3) + + --Creates a 3D rotation matrix from the given quaternion. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat: function(LuaDQuat):(LuaDMat3) + + --Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in + -- + --radians). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaDVec3),(number)):(LuaDMat3) + + --Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in + -- + --radians). + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaDMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + from_rotation_x: function(number):(LuaDMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + from_rotation_y: function(number):(LuaDMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + from_rotation_z: function(number):(LuaDMat3) + + --Creates an affine transformation matrix from the given 2D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_translation: function(LuaDVec2):(LuaDMat3) + + --Creates an affine transformation matrix from the given 2D rotation `angle` (in + -- + --radians). + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_angle: function(number):(LuaDMat3) + + --Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in + -- + --radians) and `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_scale_angle_translation: function((LuaDVec2),(number),(LuaDVec2)):(LuaDMat3) + + --Creates an affine transformation matrix from the given non-uniform 2D `scale`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale: function(LuaDVec2):(LuaDMat3) + + --Creates an affine transformation matrix from the given 2x2 matrix. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_mat2: function(LuaDMat2):(LuaDMat3) + + -- Meta methods + metamethod __tostring: function(LuaDMat3):(string) + + metamethod __unm: function(LuaDMat3):(LuaDMat3) + + -- Mutating MetaMethods + metamethod __index: function(LuaDMat3,integer):(LuaDVec3) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaDMat3`]. + record LuaDMat3Class + userdata + + -- Pure functions + --Creates a 3x3 matrix from two column vectors. + from_cols: function((LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDMat3) + + --Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaDVec3):(LuaDMat3) + + --Creates a 3x3 matrix from a 4x4 matrix, discarding the 3rd row and column. + from_mat4: function(LuaDMat4):(LuaDMat3) + + --Creates a 3D rotation matrix from the given quaternion. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat: function(LuaDQuat):(LuaDMat3) + + --Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in + -- + --radians). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaDVec3),(number)):(LuaDMat3) + + --Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in + -- + --radians). + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaDMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + from_rotation_x: function(number):(LuaDMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + from_rotation_y: function(number):(LuaDMat3) + + --Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + from_rotation_z: function(number):(LuaDMat3) + + --Creates an affine transformation matrix from the given 2D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_translation: function(LuaDVec2):(LuaDMat3) + + --Creates an affine transformation matrix from the given 2D rotation `angle` (in + -- + --radians). + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_angle: function(number):(LuaDMat3) + + --Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in + -- + --radians) and `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_scale_angle_translation: function((LuaDVec2),(number),(LuaDVec2)):(LuaDMat3) + + --Creates an affine transformation matrix from the given non-uniform 2D `scale`. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale: function(LuaDVec2):(LuaDMat3) + + --Creates an affine transformation matrix from the given 2x2 matrix. + -- + -- + -- + --The resulting matrix can be used to transform 2D points and vectors. See + -- + --[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_mat2: function(LuaDMat2):(LuaDMat3) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A 4x4 column major matrix. +-- +-- +-- +--This 4x4 matrix type features convenience methods for creating and using affine transforms and +-- +--perspective projections. If you are primarily dealing with 3D affine transformations +-- +--considering using [`DAffine3`](crate::DAffine3) which is faster than a 4x4 matrix +-- +--for some affine operations. +-- +-- +-- +--Affine transformations including 3D translation, rotation and scale can be created +-- +--using methods such as [`Self::from_translation()`], [`Self::from_quat()`], +-- +--[`Self::from_scale()`] and [`Self::from_scale_rotation_translation()`]. +-- +-- +-- +--Othographic projections can be created using the methods [`Self::orthographic_lh()`] for +-- +--left-handed coordinate systems and [`Self::orthographic_rh()`] for right-handed +-- +--systems. The resulting matrix is also an affine transformation. +-- +-- +-- +--The [`Self::transform_point3()`] and [`Self::transform_vector3()`] convenience methods +-- +--are provided for performing affine transformations on 3D vectors and points. These +-- +--multiply 3D inputs as 4D vectors with an implicit `w` value of `1` for points and `0` +-- +--for vectors respectively. These methods assume that `Self` contains a valid affine +-- +--transform. +-- +-- +-- +--Perspective projections can be created using methods such as +-- +--[`Self::perspective_lh()`], [`Self::perspective_infinite_lh()`] and +-- +--[`Self::perspective_infinite_reverse_lh()`] for left-handed co-ordinate systems and +-- +--[`Self::perspective_rh()`], [`Self::perspective_infinite_rh()`] and +-- +--[`Self::perspective_infinite_reverse_rh()`] for right-handed co-ordinate systems. +-- +-- +-- +--The resulting perspective project can be use to transform 3D vectors as points with +-- +--perspective correction using the [`Self::project_point3()`] convenience method. +-- + record LuaDMat4 + userdata + + -- Fields + x_axis : LuaDVec4 + + y_axis : LuaDVec4 + + z_axis : LuaDVec4 + + w_axis : LuaDVec4 + + -- Pure methods + --Returns the matrix column for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 3. + col: function(LuaDMat4,integer):(LuaDVec4) + + --Returns the matrix row for the given `index`. + -- + -- + -- + --# Panics + -- + -- + -- + --Panics if `index` is greater than 3. + row: function(LuaDMat4,integer):(LuaDVec4) + + --Returns `true` if, and only if, all elements are finite. + -- + --If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaDMat4):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaDMat4):(boolean) + + --Returns the transpose of `self`. + transpose: function(LuaDMat4):(LuaDMat4) + + --Returns the determinant of `self`. + determinant: function(LuaDMat4):(number) + + --Returns the inverse of `self`. + -- + -- + -- + --If the matrix is not invertible the returned matrix will be invalid. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse: function(LuaDMat4):(LuaDMat4) + + --Transforms the given 3D vector as a point, applying perspective correction. + -- + -- + -- + --This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is `1.0`. + -- + --The perspective divide is performed meaning the resulting 3D vector is divided by `w`. + -- + -- + -- + --This method assumes that `self` contains a projective transform. + project_point3: function(LuaDMat4,LuaDVec3):(LuaDVec3) + + --Transforms the given 3D vector as a point. + -- + -- + -- + --This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is + -- + --`1.0`. + -- + -- + -- + --This method assumes that `self` contains a valid affine transform. It does not perform + -- + --a persective divide, if `self` contains a perspective transform, or if you are unsure, + -- + --the [`Self::project_point3()`] method should be used instead. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + transform_point3: function(LuaDMat4,LuaDVec3):(LuaDVec3) + + --Transforms the give 3D vector as a direction. + -- + -- + -- + --This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is + -- + --`0.0`. + -- + -- + -- + --This method assumes that `self` contains a valid affine transform. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + transform_vector3: function(LuaDMat4,LuaDVec3):(LuaDVec3) + + --Transforms a 4D vector. + mul_vec4: function(LuaDMat4,LuaDVec4):(LuaDVec4) + + --Multiplies two 4x4 matrices. + mul_mat4: function(LuaDMat4,LuaDMat4):(LuaDMat4) + + --Adds two 4x4 matrices. + add_mat4: function(LuaDMat4,LuaDMat4):(LuaDMat4) + + --Subtracts two 4x4 matrices. + sub_mat4: function(LuaDMat4,LuaDMat4):(LuaDMat4) + + --Multiplies a 4x4 matrix by a scalar. + mul_scalar: function(LuaDMat4,number):(LuaDMat4) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two matrices contain similar elements. It works best + -- + --when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaDMat4,(LuaDMat4),(number)):(boolean) + + as_mat4: function(LuaDMat4):(LuaMat4) + + -- Pure functions + --Creates a 4x4 matrix from two column vectors. + from_cols: function((LuaDVec4),(LuaDVec4),(LuaDVec4),(LuaDVec4)):(LuaDMat4) + + --Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaDVec4):(LuaDMat4) + + --Creates an affine transformation matrix from the given 3D `scale`, `rotation` and + -- + --`translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_scale_rotation_translation: function((LuaDVec3),(LuaDQuat),(LuaDVec3)):(LuaDMat4) + + --Creates an affine transformation matrix from the given 3D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_rotation_translation: function((LuaDQuat),(LuaDVec3)):(LuaDMat4) + + --Creates an affine transformation matrix from the given `rotation` quaternion. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat: function(LuaDQuat):(LuaDMat4) + + --Creates an affine transformation matrix from the given 3x3 linear transformation + -- + --matrix. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_mat3: function(LuaDMat3):(LuaDMat4) + + --Creates an affine transformation matrix from the given 3D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_translation: function(LuaDVec3):(LuaDMat4) + + --Creates an affine transformation matrix containing a 3D rotation around a normalized + -- + --rotation `axis` of `angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaDVec3),(number)):(LuaDMat4) + + --Creates a affine transformation matrix containing a rotation from the given euler + -- + --rotation sequence and angles (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaDMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the x axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_x: function(number):(LuaDMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the y axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_y: function(number):(LuaDMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the z axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_z: function(number):(LuaDMat4) + + --Creates an affine transformation matrix containing the given 3D non-uniform `scale`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale: function(LuaDVec3):(LuaDMat4) + + --Creates a left-handed view matrix using a camera position, an up direction, and a focal + -- + --point. + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh: function((LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDMat4) + + --Creates a right-handed view matrix using a camera position, an up direction, and a focal + -- + --point. + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh: function((LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDMat4) + + --Creates a right-handed perspective projection matrix with [-1,1] depth range. + -- + --This is the same as the OpenGL `gluPerspective` function. + -- + --See + perspective_rh_gl: function((number),(number),(number),(number)):(LuaDMat4) + + --Creates a left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + -- + --enabled. + perspective_lh: function((number),(number),(number),(number)):(LuaDMat4) + + --Creates a right-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + -- + --enabled. + perspective_rh: function((number),(number),(number),(number)):(LuaDMat4) + + --Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_lh: function((number),(number),(number)):(LuaDMat4) + + --Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_reverse_lh: function((number),(number),(number)):(LuaDMat4) + + --Creates an infinite right-handed perspective projection matrix with + -- + --`[0,1]` depth range. + perspective_infinite_rh: function((number),(number),(number)):(LuaDMat4) + + --Creates an infinite reverse right-handed perspective projection matrix + -- + --with `[0,1]` depth range. + perspective_infinite_reverse_rh: function((number),(number),(number)):(LuaDMat4) + + --Creates a right-handed orthographic projection matrix with `[-1,1]` depth + -- + --range. This is the same as the OpenGL `glOrtho` function in OpenGL. + -- + --See + -- + -- + orthographic_rh_gl: function((number),(number),(number),(number),(number),(number)):(LuaDMat4) + + --Creates a left-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_lh: function((number),(number),(number),(number),(number),(number)):(LuaDMat4) + + --Creates a right-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_rh: function((number),(number),(number),(number),(number),(number)):(LuaDMat4) + + -- Meta methods + metamethod __tostring: function(LuaDMat4):(string) + + metamethod __unm: function(LuaDMat4):(LuaDMat4) + + -- Mutating MetaMethods + metamethod __index: function(LuaDMat4,integer):(LuaDVec4) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaDMat4`]. + record LuaDMat4Class + userdata + + -- Pure functions + --Creates a 4x4 matrix from two column vectors. + from_cols: function((LuaDVec4),(LuaDVec4),(LuaDVec4),(LuaDVec4)):(LuaDMat4) + + --Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal: function(LuaDVec4):(LuaDMat4) + + --Creates an affine transformation matrix from the given 3D `scale`, `rotation` and + -- + --`translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_scale_rotation_translation: function((LuaDVec3),(LuaDQuat),(LuaDVec3)):(LuaDMat4) + + --Creates an affine transformation matrix from the given 3D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_rotation_translation: function((LuaDQuat),(LuaDVec3)):(LuaDMat4) + + --Creates an affine transformation matrix from the given `rotation` quaternion. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat: function(LuaDQuat):(LuaDMat4) + + --Creates an affine transformation matrix from the given 3x3 linear transformation + -- + --matrix. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_mat3: function(LuaDMat3):(LuaDMat4) + + --Creates an affine transformation matrix from the given 3D `translation`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_translation: function(LuaDVec3):(LuaDMat4) + + --Creates an affine transformation matrix containing a 3D rotation around a normalized + -- + --rotation `axis` of `angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaDVec3),(number)):(LuaDMat4) + + --Creates a affine transformation matrix containing a rotation from the given euler + -- + --rotation sequence and angles (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaDMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the x axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_x: function(number):(LuaDMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the y axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_y: function(number):(LuaDMat4) + + --Creates an affine transformation matrix containing a 3D rotation around the z axis of + -- + --`angle` (in radians). + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_z: function(number):(LuaDMat4) + + --Creates an affine transformation matrix containing the given 3D non-uniform `scale`. + -- + -- + -- + --The resulting matrix can be used to transform 3D points and vectors. See + -- + --[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale: function(LuaDVec3):(LuaDMat4) + + --Creates a left-handed view matrix using a camera position, an up direction, and a focal + -- + --point. + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh: function((LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDMat4) + + --Creates a right-handed view matrix using a camera position, an up direction, and a focal + -- + --point. + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh: function((LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDMat4) + + --Creates a right-handed perspective projection matrix with [-1,1] depth range. + -- + --This is the same as the OpenGL `gluPerspective` function. + -- + --See + perspective_rh_gl: function((number),(number),(number),(number)):(LuaDMat4) + + --Creates a left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + -- + --enabled. + perspective_lh: function((number),(number),(number),(number)):(LuaDMat4) + + --Creates a right-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + -- + --enabled. + perspective_rh: function((number),(number),(number),(number)):(LuaDMat4) + + --Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_lh: function((number),(number),(number)):(LuaDMat4) + + --Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_reverse_lh: function((number),(number),(number)):(LuaDMat4) + + --Creates an infinite right-handed perspective projection matrix with + -- + --`[0,1]` depth range. + perspective_infinite_rh: function((number),(number),(number)):(LuaDMat4) + + --Creates an infinite reverse right-handed perspective projection matrix + -- + --with `[0,1]` depth range. + perspective_infinite_reverse_rh: function((number),(number),(number)):(LuaDMat4) + + --Creates a right-handed orthographic projection matrix with `[-1,1]` depth + -- + --range. This is the same as the OpenGL `glOrtho` function in OpenGL. + -- + --See + -- + -- + orthographic_rh_gl: function((number),(number),(number),(number),(number),(number)):(LuaDMat4) + + --Creates a left-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_lh: function((number),(number),(number),(number),(number),(number)):(LuaDMat4) + + --Creates a right-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_rh: function((number),(number),(number),(number),(number),(number)):(LuaDMat4) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A 2D affine transform, which can represent translation, rotation, scaling and shear. +-- + record LuaAffine2 + userdata + + -- Fields + matrix2 : LuaMat2 + + translation : LuaVec2 + + -- Pure methods + --Transforms the given 2D point, applying shear, scale, rotation and translation. + transform_point2: function(LuaAffine2,LuaVec2):(LuaVec2) + + --Transforms the given 2D vector, applying shear, scale and rotation (but NOT + -- + --translation). + -- + -- + -- + --To also apply translation, use [`Self::transform_point2`] instead. + transform_vector2: function(LuaAffine2,LuaVec2):(LuaVec2) + + --Returns `true` if, and only if, all elements are finite. + -- + -- + -- + --If any element is either `NaN`, positive or negative infinity, this will return + -- + --`false`. + is_finite: function(LuaAffine2):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaAffine2):(boolean) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two 3x4 matrices contain similar elements. It works + -- + --best when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaAffine2,(LuaAffine2),(number)):(boolean) + + --Return the inverse of this transform. + -- + -- + -- + --Note that if the transform is not invertible the result will be invalid. + inverse: function(LuaAffine2):(LuaAffine2) + + -- Pure functions + --Creates an affine transform from three column vectors. + from_cols: function((LuaVec2),(LuaVec2),(LuaVec2)):(LuaAffine2) + + --Creates an affine transform that changes scale. + -- + --Note that if any scale is zero the transform will be non-invertible. + from_scale: function(LuaVec2):(LuaAffine2) + + --Creates an affine transform from the given rotation `angle`. + from_angle: function(number):(LuaAffine2) + + --Creates an affine transformation from the given 2D `translation`. + from_translation: function(LuaVec2):(LuaAffine2) + + --Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) + from_mat2: function(LuaMat2):(LuaAffine2) + + --Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a + -- + --translation vector. + -- + -- + -- + --Equivalent to + -- + --`Affine2::from_translation(translation) * Affine2::from_mat2(mat2)` + from_mat2_translation: function((LuaMat2),(LuaVec2)):(LuaAffine2) + + --Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and + -- + --`translation`. + -- + -- + -- + --Equivalent to `Affine2::from_translation(translation) * + -- + --Affine2::from_angle(angle) * Affine2::from_scale(scale)` + from_scale_angle_translation: function((LuaVec2),(number),(LuaVec2)):(LuaAffine2) + + --Creates an affine transform from the given 2D rotation `angle` (in radians) and + -- + --`translation`. + -- + -- + -- + --Equivalent to `Affine2::from_translation(translation) * Affine2::from_angle(angle)` + from_angle_translation: function((number),(LuaVec2)):(LuaAffine2) + + --The given `Mat3` must be an affine transform, + from_mat3: function(LuaMat3):(LuaAffine2) + + -- Meta methods + metamethod __tostring: function(LuaAffine2):(string) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaAffine2`]. + record LuaAffine2Class + userdata + + -- Pure functions + --Creates an affine transform from three column vectors. + from_cols: function((LuaVec2),(LuaVec2),(LuaVec2)):(LuaAffine2) + + --Creates an affine transform that changes scale. + -- + --Note that if any scale is zero the transform will be non-invertible. + from_scale: function(LuaVec2):(LuaAffine2) + + --Creates an affine transform from the given rotation `angle`. + from_angle: function(number):(LuaAffine2) + + --Creates an affine transformation from the given 2D `translation`. + from_translation: function(LuaVec2):(LuaAffine2) + + --Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) + from_mat2: function(LuaMat2):(LuaAffine2) + + --Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a + -- + --translation vector. + -- + -- + -- + --Equivalent to + -- + --`Affine2::from_translation(translation) * Affine2::from_mat2(mat2)` + from_mat2_translation: function((LuaMat2),(LuaVec2)):(LuaAffine2) + + --Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and + -- + --`translation`. + -- + -- + -- + --Equivalent to `Affine2::from_translation(translation) * + -- + --Affine2::from_angle(angle) * Affine2::from_scale(scale)` + from_scale_angle_translation: function((LuaVec2),(number),(LuaVec2)):(LuaAffine2) + + --Creates an affine transform from the given 2D rotation `angle` (in radians) and + -- + --`translation`. + -- + -- + -- + --Equivalent to `Affine2::from_translation(translation) * Affine2::from_angle(angle)` + from_angle_translation: function((number),(LuaVec2)):(LuaAffine2) + + --The given `Mat3` must be an affine transform, + from_mat3: function(LuaMat3):(LuaAffine2) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A 3D affine transform, which can represent translation, rotation, scaling and shear. +-- + record LuaAffine3A + userdata + + -- Fields + matrix3 : LuaMat3A + + translation : LuaVec3A + + -- Pure methods + --Transforms the given 3D points, applying shear, scale, rotation and translation. + transform_point3: function(LuaAffine3A,LuaVec3):(LuaVec3) + + --Transforms the given 3D vector, applying shear, scale and rotation (but NOT + -- + --translation). + -- + -- + -- + --To also apply translation, use [`Self::transform_point3`] instead. + transform_vector3: function(LuaAffine3A,LuaVec3):(LuaVec3) + + --Transforms the given `Vec3A`, applying shear, scale, rotation and translation. + transform_point3a: function(LuaAffine3A,LuaVec3A):(LuaVec3A) + + --Transforms the given `Vec3A`, applying shear, scale and rotation (but NOT + -- + --translation). + -- + -- + -- + --To also apply translation, use [`Self::transform_point3`] instead. + transform_vector3a: function(LuaAffine3A,LuaVec3A):(LuaVec3A) + + --Returns `true` if, and only if, all elements are finite. + -- + -- + -- + --If any element is either `NaN`, positive or negative infinity, this will return + -- + --`false`. + is_finite: function(LuaAffine3A):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaAffine3A):(boolean) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two 3x4 matrices contain similar elements. It works + -- + --best when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaAffine3A,(LuaAffine3A),(number)):(boolean) + + --Return the inverse of this transform. + -- + -- + -- + --Note that if the transform is not invertible the result will be invalid. + inverse: function(LuaAffine3A):(LuaAffine3A) + + -- Pure functions + --Creates an affine transform from three column vectors. + from_cols: function((LuaVec3A),(LuaVec3A),(LuaVec3A),(LuaVec3A)):(LuaAffine3A) + + --Creates an affine transform that changes scale. + -- + --Note that if any scale is zero the transform will be non-invertible. + from_scale: function(LuaVec3):(LuaAffine3A) + + --Creates an affine transform from the given `rotation` quaternion. + from_quat: function(LuaQuat):(LuaAffine3A) + + --Creates an affine transform containing a 3D rotation around a normalized + -- + --rotation `axis` of `angle` (in radians). + from_axis_angle: function((LuaVec3),(number)):(LuaAffine3A) + + --Creates an affine transform containing a 3D rotation around the x axis of + -- + --`angle` (in radians). + from_rotation_x: function(number):(LuaAffine3A) + + --Creates an affine transform containing a 3D rotation around the y axis of + -- + --`angle` (in radians). + from_rotation_y: function(number):(LuaAffine3A) + + --Creates an affine transform containing a 3D rotation around the z axis of + -- + --`angle` (in radians). + from_rotation_z: function(number):(LuaAffine3A) + + --Creates an affine transformation from the given 3D `translation`. + from_translation: function(LuaVec3):(LuaAffine3A) + + --Creates an affine transform from a 3x3 matrix (expressing scale, shear and + -- + --rotation) + from_mat3: function(LuaMat3):(LuaAffine3A) + + --Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) + -- + --and a translation vector. + -- + -- + -- + --Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_mat3(mat3)` + from_mat3_translation: function((LuaMat3),(LuaVec3)):(LuaAffine3A) + + --Creates an affine transform from the given 3D `scale`, `rotation` and + -- + --`translation`. + -- + -- + -- + --Equivalent to `Affine3A::from_translation(translation) * + -- + --Affine3A::from_quat(rotation) * Affine3A::from_scale(scale)` + from_scale_rotation_translation: function((LuaVec3),(LuaQuat),(LuaVec3)):(LuaAffine3A) + + --Creates an affine transform from the given 3D `rotation` and `translation`. + -- + -- + -- + --Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_quat(rotation)` + from_rotation_translation: function((LuaQuat),(LuaVec3)):(LuaAffine3A) + + --The given `Mat4` must be an affine transform, + -- + --i.e. contain no perspective transform. + from_mat4: function(LuaMat4):(LuaAffine3A) + + --Creates a left-handed view transform using a camera position, an up direction, and + -- + --a focal point. + -- + -- + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh: function((LuaVec3),(LuaVec3),(LuaVec3)):(LuaAffine3A) + + --Creates a right-handed view transform using a camera position, an up direction, and + -- + --a focal point. + -- + -- + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh: function((LuaVec3),(LuaVec3),(LuaVec3)):(LuaAffine3A) + + -- Meta methods + metamethod __tostring: function(LuaAffine3A):(string) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaAffine3A`]. + record LuaAffine3AClass + userdata + + -- Pure functions + --Creates an affine transform from three column vectors. + from_cols: function((LuaVec3A),(LuaVec3A),(LuaVec3A),(LuaVec3A)):(LuaAffine3A) + + --Creates an affine transform that changes scale. + -- + --Note that if any scale is zero the transform will be non-invertible. + from_scale: function(LuaVec3):(LuaAffine3A) + + --Creates an affine transform from the given `rotation` quaternion. + from_quat: function(LuaQuat):(LuaAffine3A) + + --Creates an affine transform containing a 3D rotation around a normalized + -- + --rotation `axis` of `angle` (in radians). + from_axis_angle: function((LuaVec3),(number)):(LuaAffine3A) + + --Creates an affine transform containing a 3D rotation around the x axis of + -- + --`angle` (in radians). + from_rotation_x: function(number):(LuaAffine3A) + + --Creates an affine transform containing a 3D rotation around the y axis of + -- + --`angle` (in radians). + from_rotation_y: function(number):(LuaAffine3A) + + --Creates an affine transform containing a 3D rotation around the z axis of + -- + --`angle` (in radians). + from_rotation_z: function(number):(LuaAffine3A) + + --Creates an affine transformation from the given 3D `translation`. + from_translation: function(LuaVec3):(LuaAffine3A) + + --Creates an affine transform from a 3x3 matrix (expressing scale, shear and + -- + --rotation) + from_mat3: function(LuaMat3):(LuaAffine3A) + + --Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) + -- + --and a translation vector. + -- + -- + -- + --Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_mat3(mat3)` + from_mat3_translation: function((LuaMat3),(LuaVec3)):(LuaAffine3A) + + --Creates an affine transform from the given 3D `scale`, `rotation` and + -- + --`translation`. + -- + -- + -- + --Equivalent to `Affine3A::from_translation(translation) * + -- + --Affine3A::from_quat(rotation) * Affine3A::from_scale(scale)` + from_scale_rotation_translation: function((LuaVec3),(LuaQuat),(LuaVec3)):(LuaAffine3A) + + --Creates an affine transform from the given 3D `rotation` and `translation`. + -- + -- + -- + --Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_quat(rotation)` + from_rotation_translation: function((LuaQuat),(LuaVec3)):(LuaAffine3A) + + --The given `Mat4` must be an affine transform, + -- + --i.e. contain no perspective transform. + from_mat4: function(LuaMat4):(LuaAffine3A) + + --Creates a left-handed view transform using a camera position, an up direction, and + -- + --a focal point. + -- + -- + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh: function((LuaVec3),(LuaVec3),(LuaVec3)):(LuaAffine3A) + + --Creates a right-handed view transform using a camera position, an up direction, and + -- + --a focal point. + -- + -- + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh: function((LuaVec3),(LuaVec3),(LuaVec3)):(LuaAffine3A) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A 2D affine transform, which can represent translation, rotation, scaling and shear. +-- + record LuaDAffine2 + userdata + + -- Fields + matrix2 : LuaDMat2 + + translation : LuaDVec2 + + -- Pure methods + --Transforms the given 2D point, applying shear, scale, rotation and translation. + transform_point2: function(LuaDAffine2,LuaDVec2):(LuaDVec2) + + --Transforms the given 2D vector, applying shear, scale and rotation (but NOT + -- + --translation). + -- + -- + -- + --To also apply translation, use [`Self::transform_point2`] instead. + transform_vector2: function(LuaDAffine2,LuaDVec2):(LuaDVec2) + + --Returns `true` if, and only if, all elements are finite. + -- + -- + -- + --If any element is either `NaN`, positive or negative infinity, this will return + -- + --`false`. + is_finite: function(LuaDAffine2):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaDAffine2):(boolean) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two 3x4 matrices contain similar elements. It works + -- + --best when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaDAffine2,(LuaDAffine2),(number)):(boolean) + + --Return the inverse of this transform. + -- + -- + -- + --Note that if the transform is not invertible the result will be invalid. + inverse: function(LuaDAffine2):(LuaDAffine2) + + -- Pure functions + --Creates an affine transform from three column vectors. + from_cols: function((LuaDVec2),(LuaDVec2),(LuaDVec2)):(LuaDAffine2) + + --Creates an affine transform that changes scale. + -- + --Note that if any scale is zero the transform will be non-invertible. + from_scale: function(LuaDVec2):(LuaDAffine2) + + --Creates an affine transform from the given rotation `angle`. + from_angle: function(number):(LuaDAffine2) + + --Creates an affine transformation from the given 2D `translation`. + from_translation: function(LuaDVec2):(LuaDAffine2) + + --Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) + from_mat2: function(LuaDMat2):(LuaDAffine2) + + --Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a + -- + --translation vector. + -- + -- + -- + --Equivalent to + -- + --`DAffine2::from_translation(translation) * DAffine2::from_mat2(mat2)` + from_mat2_translation: function((LuaDMat2),(LuaDVec2)):(LuaDAffine2) + + --Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and + -- + --`translation`. + -- + -- + -- + --Equivalent to `DAffine2::from_translation(translation) * + -- + --DAffine2::from_angle(angle) * DAffine2::from_scale(scale)` + from_scale_angle_translation: function((LuaDVec2),(number),(LuaDVec2)):(LuaDAffine2) + + --Creates an affine transform from the given 2D rotation `angle` (in radians) and + -- + --`translation`. + -- + -- + -- + --Equivalent to `DAffine2::from_translation(translation) * DAffine2::from_angle(angle)` + from_angle_translation: function((number),(LuaDVec2)):(LuaDAffine2) + + --The given `DMat3` must be an affine transform, + from_mat3: function(LuaDMat3):(LuaDAffine2) + + -- Meta methods + metamethod __tostring: function(LuaDAffine2):(string) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaDAffine2`]. + record LuaDAffine2Class + userdata + + -- Pure functions + --Creates an affine transform from three column vectors. + from_cols: function((LuaDVec2),(LuaDVec2),(LuaDVec2)):(LuaDAffine2) + + --Creates an affine transform that changes scale. + -- + --Note that if any scale is zero the transform will be non-invertible. + from_scale: function(LuaDVec2):(LuaDAffine2) + + --Creates an affine transform from the given rotation `angle`. + from_angle: function(number):(LuaDAffine2) + + --Creates an affine transformation from the given 2D `translation`. + from_translation: function(LuaDVec2):(LuaDAffine2) + + --Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) + from_mat2: function(LuaDMat2):(LuaDAffine2) + + --Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a + -- + --translation vector. + -- + -- + -- + --Equivalent to + -- + --`DAffine2::from_translation(translation) * DAffine2::from_mat2(mat2)` + from_mat2_translation: function((LuaDMat2),(LuaDVec2)):(LuaDAffine2) + + --Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and + -- + --`translation`. + -- + -- + -- + --Equivalent to `DAffine2::from_translation(translation) * + -- + --DAffine2::from_angle(angle) * DAffine2::from_scale(scale)` + from_scale_angle_translation: function((LuaDVec2),(number),(LuaDVec2)):(LuaDAffine2) + + --Creates an affine transform from the given 2D rotation `angle` (in radians) and + -- + --`translation`. + -- + -- + -- + --Equivalent to `DAffine2::from_translation(translation) * DAffine2::from_angle(angle)` + from_angle_translation: function((number),(LuaDVec2)):(LuaDAffine2) + + --The given `DMat3` must be an affine transform, + from_mat3: function(LuaDMat3):(LuaDAffine2) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A 3D affine transform, which can represent translation, rotation, scaling and shear. +-- + record LuaDAffine3 + userdata + + -- Fields + matrix3 : LuaDMat3 + + translation : LuaDVec3 + + -- Pure methods + --Transforms the given 3D points, applying shear, scale, rotation and translation. + transform_point3: function(LuaDAffine3,LuaDVec3):(LuaDVec3) + + --Transforms the given 3D vector, applying shear, scale and rotation (but NOT + -- + --translation). + -- + -- + -- + --To also apply translation, use [`Self::transform_point3`] instead. + transform_vector3: function(LuaDAffine3,LuaDVec3):(LuaDVec3) + + --Returns `true` if, and only if, all elements are finite. + -- + -- + -- + --If any element is either `NaN`, positive or negative infinity, this will return + -- + --`false`. + is_finite: function(LuaDAffine3):(boolean) + + --Returns `true` if any elements are `NaN`. + is_nan: function(LuaDAffine3):(boolean) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two 3x4 matrices contain similar elements. It works + -- + --best when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaDAffine3,(LuaDAffine3),(number)):(boolean) + + --Return the inverse of this transform. + -- + -- + -- + --Note that if the transform is not invertible the result will be invalid. + inverse: function(LuaDAffine3):(LuaDAffine3) + + -- Pure functions + --Creates an affine transform from three column vectors. + from_cols: function((LuaDVec3),(LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDAffine3) + + --Creates an affine transform that changes scale. + -- + --Note that if any scale is zero the transform will be non-invertible. + from_scale: function(LuaDVec3):(LuaDAffine3) + + --Creates an affine transform from the given `rotation` quaternion. + from_quat: function(LuaDQuat):(LuaDAffine3) + + --Creates an affine transform containing a 3D rotation around a normalized + -- + --rotation `axis` of `angle` (in radians). + from_axis_angle: function((LuaDVec3),(number)):(LuaDAffine3) + + --Creates an affine transform containing a 3D rotation around the x axis of + -- + --`angle` (in radians). + from_rotation_x: function(number):(LuaDAffine3) + + --Creates an affine transform containing a 3D rotation around the y axis of + -- + --`angle` (in radians). + from_rotation_y: function(number):(LuaDAffine3) + + --Creates an affine transform containing a 3D rotation around the z axis of + -- + --`angle` (in radians). + from_rotation_z: function(number):(LuaDAffine3) + + --Creates an affine transformation from the given 3D `translation`. + from_translation: function(LuaDVec3):(LuaDAffine3) + + --Creates an affine transform from a 3x3 matrix (expressing scale, shear and + -- + --rotation) + from_mat3: function(LuaDMat3):(LuaDAffine3) + + --Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) + -- + --and a translation vector. + -- + -- + -- + --Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_mat3(mat3)` + from_mat3_translation: function((LuaDMat3),(LuaDVec3)):(LuaDAffine3) + + --Creates an affine transform from the given 3D `scale`, `rotation` and + -- + --`translation`. + -- + -- + -- + --Equivalent to `DAffine3::from_translation(translation) * + -- + --DAffine3::from_quat(rotation) * DAffine3::from_scale(scale)` + from_scale_rotation_translation: function((LuaDVec3),(LuaDQuat),(LuaDVec3)):(LuaDAffine3) + + --Creates an affine transform from the given 3D `rotation` and `translation`. + -- + -- + -- + --Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_quat(rotation)` + from_rotation_translation: function((LuaDQuat),(LuaDVec3)):(LuaDAffine3) + + --The given `DMat4` must be an affine transform, + -- + --i.e. contain no perspective transform. + from_mat4: function(LuaDMat4):(LuaDAffine3) + + --Creates a left-handed view transform using a camera position, an up direction, and + -- + --a focal point. + -- + -- + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh: function((LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDAffine3) + + --Creates a right-handed view transform using a camera position, an up direction, and + -- + --a focal point. + -- + -- + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh: function((LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDAffine3) + + -- Meta methods + metamethod __tostring: function(LuaDAffine3):(string) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaDAffine3`]. + record LuaDAffine3Class + userdata + + -- Pure functions + --Creates an affine transform from three column vectors. + from_cols: function((LuaDVec3),(LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDAffine3) + + --Creates an affine transform that changes scale. + -- + --Note that if any scale is zero the transform will be non-invertible. + from_scale: function(LuaDVec3):(LuaDAffine3) + + --Creates an affine transform from the given `rotation` quaternion. + from_quat: function(LuaDQuat):(LuaDAffine3) + + --Creates an affine transform containing a 3D rotation around a normalized + -- + --rotation `axis` of `angle` (in radians). + from_axis_angle: function((LuaDVec3),(number)):(LuaDAffine3) + + --Creates an affine transform containing a 3D rotation around the x axis of + -- + --`angle` (in radians). + from_rotation_x: function(number):(LuaDAffine3) + + --Creates an affine transform containing a 3D rotation around the y axis of + -- + --`angle` (in radians). + from_rotation_y: function(number):(LuaDAffine3) + + --Creates an affine transform containing a 3D rotation around the z axis of + -- + --`angle` (in radians). + from_rotation_z: function(number):(LuaDAffine3) + + --Creates an affine transformation from the given 3D `translation`. + from_translation: function(LuaDVec3):(LuaDAffine3) + + --Creates an affine transform from a 3x3 matrix (expressing scale, shear and + -- + --rotation) + from_mat3: function(LuaDMat3):(LuaDAffine3) + + --Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) + -- + --and a translation vector. + -- + -- + -- + --Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_mat3(mat3)` + from_mat3_translation: function((LuaDMat3),(LuaDVec3)):(LuaDAffine3) + + --Creates an affine transform from the given 3D `scale`, `rotation` and + -- + --`translation`. + -- + -- + -- + --Equivalent to `DAffine3::from_translation(translation) * + -- + --DAffine3::from_quat(rotation) * DAffine3::from_scale(scale)` + from_scale_rotation_translation: function((LuaDVec3),(LuaDQuat),(LuaDVec3)):(LuaDAffine3) + + --Creates an affine transform from the given 3D `rotation` and `translation`. + -- + -- + -- + --Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_quat(rotation)` + from_rotation_translation: function((LuaDQuat),(LuaDVec3)):(LuaDAffine3) + + --The given `DMat4` must be an affine transform, + -- + --i.e. contain no perspective transform. + from_mat4: function(LuaDMat4):(LuaDAffine3) + + --Creates a left-handed view transform using a camera position, an up direction, and + -- + --a focal point. + -- + -- + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh: function((LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDAffine3) + + --Creates a right-handed view transform using a camera position, an up direction, and + -- + --a focal point. + -- + -- + -- + --For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh: function((LuaDVec3),(LuaDVec3),(LuaDVec3)):(LuaDAffine3) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A quaternion representing an orientation. +-- +-- +-- +--This quaternion is intended to be of unit length but may denormalize due to +-- +--floating point "error creep" which can occur when successive quaternion +-- +--operations are applied. +-- +-- +-- +--This type is 16 byte aligned. +-- + record LuaQuat + userdata + + -- Pure methods + --Returns the rotation axis scaled by the rotation in radians. + to_scaled_axis: function(LuaQuat):(LuaVec3) + + --Returns the vector part of the quaternion. + xyz: function(LuaQuat):(LuaVec3) + + --Returns the quaternion conjugate of `self`. For a unit quaternion the + -- + --conjugate is also the inverse. + conjugate: function(LuaQuat):(LuaQuat) + + --Returns the inverse of a normalized quaternion. + -- + -- + -- + --Typically quaternion inverse returns the conjugate of a normalized quaternion. + -- + --Because `self` is assumed to already be unit length this method *does not* normalize + -- + --before returning the conjugate. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` is not normalized when `glam_assert` is enabled. + inverse: function(LuaQuat):(LuaQuat) + + --Computes the dot product of `self` and `rhs`. The dot product is + -- + --equal to the cosine of the angle between two quaternion rotations. + dot: function(LuaQuat,LuaQuat):(number) + + --Computes the length of `self`. + length: function(LuaQuat):(number) + + --Computes the squared length of `self`. + -- + -- + -- + --This is generally faster than `length()` as it avoids a square + -- + --root operation. + length_squared: function(LuaQuat):(number) + + --Computes `1.0 / length()`. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero. + length_recip: function(LuaQuat):(number) + + --Returns `self` normalized to length 1.0. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero. + -- + -- + -- + --Panics + -- + -- + -- + --Will panic if `self` is zero length when `glam_assert` is enabled. + normalize: function(LuaQuat):(LuaQuat) + + --Returns `true` if, and only if, all elements are finite. + -- + --If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaQuat):(boolean) + + is_nan: function(LuaQuat):(boolean) + + --Returns whether `self` of length `1.0` or not. + -- + -- + -- + --Uses a precision threshold of `1e-6`. + is_normalized: function(LuaQuat):(boolean) + + is_near_identity: function(LuaQuat):(boolean) + + --Returns the angle (in radians) for the minimal rotation + -- + --for transforming this quaternion into another. + -- + -- + -- + --Both quaternions must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + angle_between: function(LuaQuat,LuaQuat):(number) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two quaternions contain similar elements. It works + -- + --best when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaQuat,(LuaQuat),(number)):(boolean) + + --Performs a linear interpolation between `self` and `rhs` based on + -- + --the value `s`. + -- + -- + -- + --When `s` is `0.0`, the result will be equal to `self`. When `s` + -- + --is `1.0`, the result will be equal to `rhs`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + lerp: function(LuaQuat,(LuaQuat),(number)):(LuaQuat) + + --Performs a spherical linear interpolation between `self` and `end` + -- + --based on the value `s`. + -- + -- + -- + --When `s` is `0.0`, the result will be equal to `self`. When `s` + -- + --is `1.0`, the result will be equal to `end`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + slerp: function(LuaQuat,(LuaQuat),(number)):(LuaQuat) + + --Multiplies a quaternion and a 3D vector, returning the rotated vector. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` is not normalized when `glam_assert` is enabled. + mul_vec3: function(LuaQuat,LuaVec3):(LuaVec3) + + --Multiplies two quaternions. If they each represent a rotation, the result will + -- + --represent the combined rotation. + -- + -- + -- + --Note that due to floating point rounding the result may not be perfectly normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + mul_quat: function(LuaQuat,LuaQuat):(LuaQuat) + + --Multiplies a quaternion and a 3D vector, returning the rotated vector. + mul_vec3a: function(LuaQuat,LuaVec3A):(LuaVec3A) + + as_f64: function(LuaQuat):(LuaDQuat) + + -- Pure functions + --Creates a new rotation quaternion. + -- + -- + -- + --This should generally not be called manually unless you know what you are doing. + -- + --Use one of the other constructors instead such as `identity` or `from_axis_angle`. + -- + -- + -- + --`from_xyzw` is mostly used by unit tests and `serde` deserialization. + -- + -- + -- + --# Preconditions + -- + -- + -- + --This function does not check if the input is normalized, it is up to the user to + -- + --provide normalized input or to normalized the resulting quaternion. + from_xyzw: function((number),(number),(number),(number)):(LuaQuat) + + --Creates a new rotation quaternion from a 4D vector. + -- + -- + -- + --# Preconditions + -- + -- + -- + --This function does not check if the input is normalized, it is up to the user to + -- + --provide normalized input or to normalized the resulting quaternion. + from_vec4: function(LuaVec4):(LuaQuat) + + --Create a quaternion for a normalized rotation `axis` and `angle` (in radians). + -- + --The axis must be normalized (unit-length). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaVec3),(number)):(LuaQuat) + + --Create a quaternion that rotates `v.length()` radians around `v.normalize()`. + -- + -- + -- + --`from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. + from_scaled_axis: function(LuaVec3):(LuaQuat) + + --Creates a quaternion from the `angle` (in radians) around the x axis. + from_rotation_x: function(number):(LuaQuat) + + --Creates a quaternion from the `angle` (in radians) around the y axis. + from_rotation_y: function(number):(LuaQuat) + + --Creates a quaternion from the `angle` (in radians) around the z axis. + from_rotation_z: function(number):(LuaQuat) + + --Creates a quaternion from the given Euler rotation sequence and the angles (in radians). + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaQuat) + + --Creates a quaternion from a 3x3 rotation matrix. + from_mat3: function(LuaMat3):(LuaQuat) + + --Creates a quaternion from a 3x3 rotation matrix inside a homogeneous 4x4 matrix. + from_mat4: function(LuaMat4):(LuaQuat) + + --Gets the minimal rotation for transforming `from` to `to`. The rotation is in the + -- + --plane spanned by the two vectors. Will rotate at most 180 degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`from_rotation_arc(from, to) * from ≈ to`. + -- + -- + -- + --For near-singular cases (from≈to and from≈-to) the current implementation + -- + --is only accurate to about 0.001 (for `f32`). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc: function((LuaVec3),(LuaVec3)):(LuaQuat) + + --Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means + -- + --that the resulting quaternion will rotate `from` so that it is colinear with `to`. + -- + -- + -- + --The rotation is in the plane spanned by the two vectors. Will rotate at most 90 + -- + --degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_colinear: function((LuaVec3),(LuaVec3)):(LuaQuat) + + --Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is + -- + --around the z axis. Will rotate at most 180 degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`from_rotation_arc_2d(from, to) * from ≈ to`. + -- + -- + -- + --For near-singular cases (from≈to and from≈-to) the current implementation + -- + --is only accurate to about 0.001 (for `f32`). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_2d: function((LuaVec2),(LuaVec2)):(LuaQuat) + + --Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. + from_affine3: function(LuaAffine3A):(LuaQuat) + + -- Meta methods + metamethod __tostring: function(LuaQuat):(string) + + metamethod __unm: function(LuaQuat):(LuaQuat) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaQuat`]. + record LuaQuatClass + userdata + + -- Pure functions + --Creates a new rotation quaternion. + -- + -- + -- + --This should generally not be called manually unless you know what you are doing. + -- + --Use one of the other constructors instead such as `identity` or `from_axis_angle`. + -- + -- + -- + --`from_xyzw` is mostly used by unit tests and `serde` deserialization. + -- + -- + -- + --# Preconditions + -- + -- + -- + --This function does not check if the input is normalized, it is up to the user to + -- + --provide normalized input or to normalized the resulting quaternion. + from_xyzw: function((number),(number),(number),(number)):(LuaQuat) + + --Creates a new rotation quaternion from a 4D vector. + -- + -- + -- + --# Preconditions + -- + -- + -- + --This function does not check if the input is normalized, it is up to the user to + -- + --provide normalized input or to normalized the resulting quaternion. + from_vec4: function(LuaVec4):(LuaQuat) + + --Create a quaternion for a normalized rotation `axis` and `angle` (in radians). + -- + --The axis must be normalized (unit-length). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaVec3),(number)):(LuaQuat) + + --Create a quaternion that rotates `v.length()` radians around `v.normalize()`. + -- + -- + -- + --`from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. + from_scaled_axis: function(LuaVec3):(LuaQuat) + + --Creates a quaternion from the `angle` (in radians) around the x axis. + from_rotation_x: function(number):(LuaQuat) + + --Creates a quaternion from the `angle` (in radians) around the y axis. + from_rotation_y: function(number):(LuaQuat) + + --Creates a quaternion from the `angle` (in radians) around the z axis. + from_rotation_z: function(number):(LuaQuat) + + --Creates a quaternion from the given Euler rotation sequence and the angles (in radians). + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaQuat) + + --Creates a quaternion from a 3x3 rotation matrix. + from_mat3: function(LuaMat3):(LuaQuat) + + --Creates a quaternion from a 3x3 rotation matrix inside a homogeneous 4x4 matrix. + from_mat4: function(LuaMat4):(LuaQuat) + + --Gets the minimal rotation for transforming `from` to `to`. The rotation is in the + -- + --plane spanned by the two vectors. Will rotate at most 180 degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`from_rotation_arc(from, to) * from ≈ to`. + -- + -- + -- + --For near-singular cases (from≈to and from≈-to) the current implementation + -- + --is only accurate to about 0.001 (for `f32`). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc: function((LuaVec3),(LuaVec3)):(LuaQuat) + + --Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means + -- + --that the resulting quaternion will rotate `from` so that it is colinear with `to`. + -- + -- + -- + --The rotation is in the plane spanned by the two vectors. Will rotate at most 90 + -- + --degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_colinear: function((LuaVec3),(LuaVec3)):(LuaQuat) + + --Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is + -- + --around the z axis. Will rotate at most 180 degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`from_rotation_arc_2d(from, to) * from ≈ to`. + -- + -- + -- + --For near-singular cases (from≈to and from≈-to) the current implementation + -- + --is only accurate to about 0.001 (for `f32`). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_2d: function((LuaVec2),(LuaVec2)):(LuaQuat) + + --Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. + from_affine3: function(LuaAffine3A):(LuaQuat) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--A quaternion representing an orientation. +-- +-- +-- +--This quaternion is intended to be of unit length but may denormalize due to +-- +--floating point "error creep" which can occur when successive quaternion +-- +--operations are applied. +-- + record LuaDQuat + userdata + + -- Fields + x : number + + y : number + + z : number + + w : number + + -- Pure methods + --Returns the rotation axis scaled by the rotation in radians. + to_scaled_axis: function(LuaDQuat):(LuaDVec3) + + --Returns the vector part of the quaternion. + xyz: function(LuaDQuat):(LuaDVec3) + + --Returns the quaternion conjugate of `self`. For a unit quaternion the + -- + --conjugate is also the inverse. + conjugate: function(LuaDQuat):(LuaDQuat) + + --Returns the inverse of a normalized quaternion. + -- + -- + -- + --Typically quaternion inverse returns the conjugate of a normalized quaternion. + -- + --Because `self` is assumed to already be unit length this method *does not* normalize + -- + --before returning the conjugate. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` is not normalized when `glam_assert` is enabled. + inverse: function(LuaDQuat):(LuaDQuat) + + --Computes the dot product of `self` and `rhs`. The dot product is + -- + --equal to the cosine of the angle between two quaternion rotations. + dot: function(LuaDQuat,LuaDQuat):(number) + + --Computes the length of `self`. + length: function(LuaDQuat):(number) + + --Computes the squared length of `self`. + -- + -- + -- + --This is generally faster than `length()` as it avoids a square + -- + --root operation. + length_squared: function(LuaDQuat):(number) + + --Computes `1.0 / length()`. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero. + length_recip: function(LuaDQuat):(number) + + --Returns `self` normalized to length 1.0. + -- + -- + -- + --For valid results, `self` must _not_ be of length zero. + -- + -- + -- + --Panics + -- + -- + -- + --Will panic if `self` is zero length when `glam_assert` is enabled. + normalize: function(LuaDQuat):(LuaDQuat) + + --Returns `true` if, and only if, all elements are finite. + -- + --If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite: function(LuaDQuat):(boolean) + + is_nan: function(LuaDQuat):(boolean) + + --Returns whether `self` of length `1.0` or not. + -- + -- + -- + --Uses a precision threshold of `1e-6`. + is_normalized: function(LuaDQuat):(boolean) + + is_near_identity: function(LuaDQuat):(boolean) + + --Returns the angle (in radians) for the minimal rotation + -- + --for transforming this quaternion into another. + -- + -- + -- + --Both quaternions must be normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + angle_between: function(LuaDQuat,LuaDQuat):(number) + + --Returns true if the absolute difference of all elements between `self` and `rhs` + -- + --is less than or equal to `max_abs_diff`. + -- + -- + -- + --This can be used to compare if two quaternions contain similar elements. It works + -- + --best when comparing with a known value. The `max_abs_diff` that should be used used + -- + --depends on the values being compared against. + -- + -- + -- + --For more see + -- + --[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq: function(LuaDQuat,(LuaDQuat),(number)):(boolean) + + --Performs a linear interpolation between `self` and `rhs` based on + -- + --the value `s`. + -- + -- + -- + --When `s` is `0.0`, the result will be equal to `self`. When `s` + -- + --is `1.0`, the result will be equal to `rhs`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + lerp: function(LuaDQuat,(LuaDQuat),(number)):(LuaDQuat) + + --Performs a spherical linear interpolation between `self` and `end` + -- + --based on the value `s`. + -- + -- + -- + --When `s` is `0.0`, the result will be equal to `self`. When `s` + -- + --is `1.0`, the result will be equal to `end`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + slerp: function(LuaDQuat,(LuaDQuat),(number)):(LuaDQuat) + + --Multiplies a quaternion and a 3D vector, returning the rotated vector. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` is not normalized when `glam_assert` is enabled. + mul_vec3: function(LuaDQuat,LuaDVec3):(LuaDVec3) + + --Multiplies two quaternions. If they each represent a rotation, the result will + -- + --represent the combined rotation. + -- + -- + -- + --Note that due to floating point rounding the result may not be perfectly normalized. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + mul_quat: function(LuaDQuat,LuaDQuat):(LuaDQuat) + + as_f32: function(LuaDQuat):(LuaQuat) + + -- Pure functions + --Creates a new rotation quaternion. + -- + -- + -- + --This should generally not be called manually unless you know what you are doing. + -- + --Use one of the other constructors instead such as `identity` or `from_axis_angle`. + -- + -- + -- + --`from_xyzw` is mostly used by unit tests and `serde` deserialization. + -- + -- + -- + --# Preconditions + -- + -- + -- + --This function does not check if the input is normalized, it is up to the user to + -- + --provide normalized input or to normalized the resulting quaternion. + from_xyzw: function((number),(number),(number),(number)):(LuaDQuat) + + --Creates a new rotation quaternion from a 4D vector. + -- + -- + -- + --# Preconditions + -- + -- + -- + --This function does not check if the input is normalized, it is up to the user to + -- + --provide normalized input or to normalized the resulting quaternion. + from_vec4: function(LuaDVec4):(LuaDQuat) + + --Create a quaternion for a normalized rotation `axis` and `angle` (in radians). + -- + --The axis must be normalized (unit-length). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaDVec3),(number)):(LuaDQuat) + + --Create a quaternion that rotates `v.length()` radians around `v.normalize()`. + -- + -- + -- + --`from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. + from_scaled_axis: function(LuaDVec3):(LuaDQuat) + + --Creates a quaternion from the `angle` (in radians) around the x axis. + from_rotation_x: function(number):(LuaDQuat) + + --Creates a quaternion from the `angle` (in radians) around the y axis. + from_rotation_y: function(number):(LuaDQuat) + + --Creates a quaternion from the `angle` (in radians) around the z axis. + from_rotation_z: function(number):(LuaDQuat) + + --Creates a quaternion from the given Euler rotation sequence and the angles (in radians). + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaDQuat) + + --Creates a quaternion from a 3x3 rotation matrix. + from_mat3: function(LuaDMat3):(LuaDQuat) + + --Creates a quaternion from a 3x3 rotation matrix inside a homogeneous 4x4 matrix. + from_mat4: function(LuaDMat4):(LuaDQuat) + + --Gets the minimal rotation for transforming `from` to `to`. The rotation is in the + -- + --plane spanned by the two vectors. Will rotate at most 180 degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`from_rotation_arc(from, to) * from ≈ to`. + -- + -- + -- + --For near-singular cases (from≈to and from≈-to) the current implementation + -- + --is only accurate to about 0.001 (for `f32`). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc: function((LuaDVec3),(LuaDVec3)):(LuaDQuat) + + --Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means + -- + --that the resulting quaternion will rotate `from` so that it is colinear with `to`. + -- + -- + -- + --The rotation is in the plane spanned by the two vectors. Will rotate at most 90 + -- + --degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_colinear: function((LuaDVec3),(LuaDVec3)):(LuaDQuat) + + --Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is + -- + --around the z axis. Will rotate at most 180 degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`from_rotation_arc_2d(from, to) * from ≈ to`. + -- + -- + -- + --For near-singular cases (from≈to and from≈-to) the current implementation + -- + --is only accurate to about 0.001 (for `f32`). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_2d: function((LuaDVec2),(LuaDVec2)):(LuaDQuat) + + --Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. + from_affine3: function(LuaDAffine3):(LuaDQuat) + + -- Meta methods + metamethod __tostring: function(LuaDQuat):(string) + + metamethod __unm: function(LuaDQuat):(LuaDQuat) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Collection of static methods for [`LuaDQuat`]. + record LuaDQuatClass + userdata + + -- Pure functions + --Creates a new rotation quaternion. + -- + -- + -- + --This should generally not be called manually unless you know what you are doing. + -- + --Use one of the other constructors instead such as `identity` or `from_axis_angle`. + -- + -- + -- + --`from_xyzw` is mostly used by unit tests and `serde` deserialization. + -- + -- + -- + --# Preconditions + -- + -- + -- + --This function does not check if the input is normalized, it is up to the user to + -- + --provide normalized input or to normalized the resulting quaternion. + from_xyzw: function((number),(number),(number),(number)):(LuaDQuat) + + --Creates a new rotation quaternion from a 4D vector. + -- + -- + -- + --# Preconditions + -- + -- + -- + --This function does not check if the input is normalized, it is up to the user to + -- + --provide normalized input or to normalized the resulting quaternion. + from_vec4: function(LuaDVec4):(LuaDQuat) + + --Create a quaternion for a normalized rotation `axis` and `angle` (in radians). + -- + --The axis must be normalized (unit-length). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle: function((LuaDVec3),(number)):(LuaDQuat) + + --Create a quaternion that rotates `v.length()` radians around `v.normalize()`. + -- + -- + -- + --`from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. + from_scaled_axis: function(LuaDVec3):(LuaDQuat) + + --Creates a quaternion from the `angle` (in radians) around the x axis. + from_rotation_x: function(number):(LuaDQuat) + + --Creates a quaternion from the `angle` (in radians) around the y axis. + from_rotation_y: function(number):(LuaDQuat) + + --Creates a quaternion from the `angle` (in radians) around the z axis. + from_rotation_z: function(number):(LuaDQuat) + + --Creates a quaternion from the given Euler rotation sequence and the angles (in radians). + from_euler: function((LuaEulerRot),(number),(number),(number)):(LuaDQuat) + + --Creates a quaternion from a 3x3 rotation matrix. + from_mat3: function(LuaDMat3):(LuaDQuat) + + --Creates a quaternion from a 3x3 rotation matrix inside a homogeneous 4x4 matrix. + from_mat4: function(LuaDMat4):(LuaDQuat) + + --Gets the minimal rotation for transforming `from` to `to`. The rotation is in the + -- + --plane spanned by the two vectors. Will rotate at most 180 degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`from_rotation_arc(from, to) * from ≈ to`. + -- + -- + -- + --For near-singular cases (from≈to and from≈-to) the current implementation + -- + --is only accurate to about 0.001 (for `f32`). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc: function((LuaDVec3),(LuaDVec3)):(LuaDQuat) + + --Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means + -- + --that the resulting quaternion will rotate `from` so that it is colinear with `to`. + -- + -- + -- + --The rotation is in the plane spanned by the two vectors. Will rotate at most 90 + -- + --degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_colinear: function((LuaDVec3),(LuaDVec3)):(LuaDQuat) + + --Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is + -- + --around the z axis. Will rotate at most 180 degrees. + -- + -- + -- + --The input vectors must be normalized (unit-length). + -- + -- + -- + --`from_rotation_arc_2d(from, to) * from ≈ to`. + -- + -- + -- + --For near-singular cases (from≈to and from≈-to) the current implementation + -- + --is only accurate to about 0.001 (for `f32`). + -- + -- + -- + --# Panics + -- + -- + -- + --Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_2d: function((LuaDVec2),(LuaDVec2)):(LuaDQuat) + + --Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. + from_affine3: function(LuaDAffine3):(LuaDQuat) + + -- Meta functions + metamethod __add: function((any),(any)):(any) + + metamethod __sub: function((any),(any)):(any) + + metamethod __div: function((any),(any)):(any) + + metamethod __mul: function((any),(any)):(any) + + + end +--Euler rotation sequences. +-- +-- +-- +--The angles are applied starting from the right. +-- +--E.g. XYZ will first apply the z-axis rotation. +-- +-- +-- +--YXZ can be used for yaw (y-axis), pitch (x-axis), roll (z-axis). +-- +-- +-- +--The two-axis rotations (e.g. ZYZ) are not fully tested and have to be treated with caution. +-- + record LuaEulerRot + userdata + + -- Meta methods + metamethod __tostring: function(LuaEulerRot):(string) + + + end +--This type represents a generic reflected value. +-- +--If you know the reflected value converts to a LuaType (via LuaProxyable), use the `as` operator to convert to said type. +-- + record ReflectedValue + userdata + + -- Meta methods + metamethod __tostring: function(ReflectedValue):(string) + + -- Mutating MetaMethods + metamethod __index: function(ReflectedValue,any):(ReflectedValue) + + metamethod __newindex: function(ReflectedValue,(any),(any)):() + + + end +--Represents the bevy world all scripts live in. +-- +--Provides ways to interact with and modify the world. +-- + record LuaWorld + userdata + + -- Pure methods + --Retrieves children entities of the parent entity if it has any. + get_children: function(LuaWorld,LuaEntity):({LuaEntity}) + + --Retrieves the parent entity of the given entity if it has any. + get_parent: function(LuaWorld,LuaEntity):(LuaEntity) + + --Attaches children entities to the given parent entity. + push_children: function(LuaWorld,(LuaEntity),({LuaEntity})):() + + --Attaches child entity to the given parent entity. + push_child: function(LuaWorld,(LuaEntity),(LuaEntity)):() + + --Removes children entities from the given parent entity. + remove_children: function(LuaWorld,(LuaEntity),({LuaEntity})):() + + --Removes child entity from the given parent entity. + remove_child: function(LuaWorld,(LuaEntity),(LuaEntity)):() + + --Inserts children entities to the given parent entity at the given index. + -- + --Despawns the given entity and the entity's children recursively + insert_children: function(LuaWorld,(LuaEntity),(integer),({LuaEntity})):() + + --Inserts child entity to the given parent entity at the given index. + insert_child: function(LuaWorld,(LuaEntity),(integer),(LuaEntity)):() + + --Despawns the given entity's children recursively + despawn_children_recursive: function(LuaWorld,LuaEntity):() + + --Despawns the given entity and the entity's children recursively + despawn_recursive: function(LuaWorld,LuaEntity):() + + --Inserts children entities to the given parent entity at the given index. + -- + --Despawns the given entity and the entity's children recursively + insert_children: function(LuaWorld,LuaEntity):() + + --Retrieves type information given either a short (`MyType`) or fully qualified rust type name (`MyModule::MyType`). + -- + --Returns `nil` if no such type exists or if one wasn't registered on the rust side. + -- + -- + -- + -- + --This is used extensively in [`LuaWorld`] + get_type_by_name: function(LuaWorld,string):(LuaTypeRegistration) + + --Inserts a component of the given type to the given entity by instantiating a default version of it. + -- + --The component can then be modified using field access. + add_default_component: function(LuaWorld,(LuaEntity),(LuaTypeRegistration)):(ReflectedValue) + + --Retrieves a component of the given type from the given entity. + -- + --If such a component does not exist returns `nil`. + get_component: function(LuaWorld,(LuaEntity),(LuaTypeRegistration)):(ReflectedValue) + + --Returns `true` if the given entity contains a component of the given type. + has_component: function(LuaWorld,(LuaEntity),(LuaTypeRegistration)):(boolean) + + --Removes the given component from the given entity, does nothing if it doesn't exist on the entity. + remove_component: function(LuaWorld,(LuaEntity),(LuaTypeRegistration)):() + + --Retrieves a resource of the given type from the world. + -- + --If such a resource does not exist returns `nil`. + get_resource: function(LuaWorld,LuaTypeRegistration):(ReflectedValue) + + --Removes the given resource from the world, if one doesn't exist it does nothing. + remove_resource: function(LuaWorld,LuaTypeRegistration):() + + --Returns `true` if the world contains a resource of the given type. + has_resource: function(LuaWorld,LuaTypeRegistration):(boolean) + + --Spawns a new entity and returns its Entity ID + spawn: function(LuaWorld):(LuaEntity) + + --Despawns the given entity if it exists, returns true if deletion was successfull + despawn: function(LuaWorld,LuaEntity):(boolean) + + + end +--Collection of static methods for [`LuaWorld`]. + record LuaWorldClass + userdata + + + end + record LuaScriptData + userdata + + -- Fields + --The unique ID of this script + sid : integer + + + end +--Collection of static methods for [`LuaScriptData`]. + record LuaScriptDataClass + userdata + + + end +--An object representing an existing and registered rust type. +-- +--Can be obtained via [`LuaWorld::get_type_by_name`]. +-- + record LuaTypeRegistration + userdata + + -- Fields + --The [short name](https://docs.rs/bevy/latest/bevy/reflect/struct.TypeRegistration.html#method.get_short_name) of a type + short_name : string + + --The full name of the type + type_name : string + + + end +--A reference to the Vec Rust type. +-- +--The indexing begins at 1. +-- + record LuaVec + userdata + + -- Mutating methods + push: function(LuaVec,any):() + + pop: function(LuaVec):(any) + + clear: function(LuaVec):() + + insert: function(LuaVec,(integer),(any)):() + + remove: function(LuaVec,integer):(any) + + -- Meta methods + metamethod __tostring: function(LuaVec):(string) + + metamethod __index: function(LuaVec,integer):(ReflectedValue) + + metamethod __pairs: function(LuaVec):(function():((any),(any))) + + metamethod __len: function(LuaVec):(integer) + + -- Mutating MetaMethods + metamethod __newindex: function(LuaVec,(integer),(any)):() + + + end + record LuaLifeState + userdata + + -- Fields + cells : LuaVec + + -- Meta methods + metamethod __tostring: function(LuaLifeState):(string) + + + end +end +global Name: types.LuaNameClass +global Children: types.LuaChildrenClass +global Text: types.LuaTextClass +global TextSection: types.LuaTextSectionClass +global Stopwatch: types.LuaStopwatchClass +global Timer: types.LuaTimerClass +global Entity: types.LuaEntityClass +global Transform: types.LuaTransformClass +global GlobalTransform: types.LuaGlobalTransformClass +global TextureAtlasSprite: types.LuaTextureAtlasSpriteClass +global RenderLayers: types.LuaRenderLayersClass +global Visibility: types.LuaVisibilityClass +global ComputedVisibility: types.LuaComputedVisibilityClass +global Color: types.LuaColorClass +global Aabb: types.LuaAabbClass +global Frustum: types.LuaFrustumClass +global CameraRenderGraph: types.LuaCameraRenderGraphClass +global HandleId: types.LuaHandleIdClass +global Vec2: types.LuaVec2Class +global Vec3: types.LuaVec3Class +global Vec3A: types.LuaVec3AClass +global Vec4: types.LuaVec4Class +global BVec2: types.LuaBVec2Class +global BVec3: types.LuaBVec3Class +global BVec4: types.LuaBVec4Class +global BVec3A: types.LuaBVec3AClass +global BVec4A: types.LuaBVec4AClass +global DVec2: types.LuaDVec2Class +global DVec3: types.LuaDVec3Class +global DVec4: types.LuaDVec4Class +global IVec2: types.LuaIVec2Class +global IVec3: types.LuaIVec3Class +global IVec4: types.LuaIVec4Class +global UVec2: types.LuaUVec2Class +global UVec3: types.LuaUVec3Class +global UVec4: types.LuaUVec4Class +global Mat3: types.LuaMat3Class +global Mat2: types.LuaMat2Class +global Mat3A: types.LuaMat3AClass +global Mat4: types.LuaMat4Class +global DMat2: types.LuaDMat2Class +global DMat3: types.LuaDMat3Class +global DMat4: types.LuaDMat4Class +global Affine2: types.LuaAffine2Class +global Affine3A: types.LuaAffine3AClass +global DAffine2: types.LuaDAffine2Class +global DAffine3: types.LuaDAffine3Class +global Quat: types.LuaQuatClass +global DQuat: types.LuaDQuatClass +global world: types.LuaWorld +global script: types.LuaScriptData +global entity: types.LuaEntity +return types \ No newline at end of file diff --git a/bevy_mod_scripting/examples/console_integration_lua.rs b/bevy_mod_scripting/examples/console_integration_lua.rs deleted file mode 100644 index 2a60316eea..0000000000 --- a/bevy_mod_scripting/examples/console_integration_lua.rs +++ /dev/null @@ -1,201 +0,0 @@ -use bevy::{ecs::event::Events, prelude::*}; -use bevy_console::{AddConsoleCommand, ConsoleCommand, ConsolePlugin, PrintConsoleLine}; -use bevy_mod_scripting::{ - events::PriorityEventWriter, - langs::mlu::{mlua, mlua::prelude::*, mlua::Value}, - APIProvider, AddScriptApiProvider, AddScriptHost, AddScriptHostHandler, LuaDocFragment, - LuaEvent, LuaFile, LuaScriptHost, Recipients, Script, ScriptCollection, ScriptData, - ScriptError, ScriptErrorEvent, ScriptingPlugin, -}; -use std::sync::Mutex; - -#[derive(Clone)] -pub struct MyLuaArg; - -impl<'lua> ToLua<'lua> for MyLuaArg { - fn to_lua(self, _: &'lua Lua) -> mlua::Result> { - Ok(Value::Nil) - } -} - -#[derive(Default)] -pub struct LuaAPIProvider; - -/// the custom Lua api, world is provided via a global pointer, -/// and callbacks are defined only once at script creation -impl APIProvider for LuaAPIProvider { - type APITarget = Mutex; - type DocTarget = LuaDocFragment; - type ScriptContext = Mutex; - - fn attach_api(&mut self, ctx: &mut Self::APITarget) -> Result<(), ScriptError> { - // callbacks can receive any `ToLuaMulti` arguments, here '()' and - // return any `FromLuaMulti` arguments, here a `usize` - // check the Rlua documentation for more details - - let ctx = ctx.lock().unwrap(); - - ctx.globals().set( - "print_to_console", - ctx.create_function(|ctx, msg: String| { - // retrieve the world pointer - let world_data: usize = ctx.globals().get("world").unwrap(); - let world: &mut World = unsafe { &mut *(world_data as *mut World) }; - - let mut events: Mut> = world.get_resource_mut().unwrap(); - events.send(PrintConsoleLine { line: msg }); - - // return something - Ok(()) - })?, - )?; - - Ok(()) - } - - fn setup_script( - &mut self, - _: &ScriptData, - _: &mut Self::ScriptContext, - ) -> Result<(), ScriptError> { - Ok(()) - } -} - -/// sends updates to script host which are then handled by the scripts -/// in the designated stage -pub fn trigger_on_update_lua(mut w: PriorityEventWriter>) { - let event = LuaEvent { - hook_name: "on_update".to_string(), - args: Vec::default(), - recipients: Recipients::All, - }; - - w.send(event, 0); -} - -pub fn forward_script_err_to_console( - mut r: EventReader, - mut w: EventWriter, -) { - for e in r.iter() { - w.send(PrintConsoleLine { - line: format!("ERROR:{}", e.err), - }); - } -} - -fn main() -> std::io::Result<()> { - let mut app = App::new(); - app.add_plugins(DefaultPlugins) - .add_plugin(ScriptingPlugin) - .add_plugin(ConsolePlugin) - .add_startup_system(watch_assets) - // register bevy_console commands - .add_console_command::(run_script_cmd) - .add_console_command::(delete_script_cmd) - // choose and register the script hosts you want to use - .add_script_host::, _>(CoreStage::PostUpdate) - .add_api_provider::>(Box::new(LuaAPIProvider)) - .add_script_handler_stage::, _, 0, 0>(CoreStage::PostUpdate) - // add your systems - .add_system(trigger_on_update_lua) - .add_system(forward_script_err_to_console); - - // at runtime press '~' for console then type in help for command formats - app.run(); - - Ok(()) -} - -// we use bevy-debug-console to demonstrate how this can fit in in the runtime of a game -// note that using just the entity id instead of the full Entity has issues, -// but since we aren't despawning/spawning entities this works in our case -#[derive(ConsoleCommand)] -#[console_command(name = "run_script")] -///Runs a Lua script from the `assets/scripts` directory -pub struct RunScriptCmd { - /// the relative path to the script, e.g.: `/hello.lua` for a script located in `assets/scripts/hello.lua` - pub path: String, - - /// the entity id to attach this script to - pub entity: Option, -} - -pub fn run_script_cmd( - mut log: ConsoleCommand, - server: Res, - mut commands: Commands, - mut existing_scripts: Query<&mut ScriptCollection>, -) { - if let Some(RunScriptCmd { path, entity }) = log.take() { - let handle = server.load::(&format!("scripts/{}", &path)); - - match entity { - Some(e) => { - if let Ok(mut scripts) = existing_scripts.get_mut(Entity::from_raw(e)) { - info!("Creating script: scripts/{} {:?}", &path, e); - - scripts - .scripts - .push(Script::::new::>( - path, handle, - )); - } else { - log.reply_failed(format!("Something went wrong")); - }; - } - None => { - info!("Creating script: scripts/{}", &path); - - commands.spawn().insert(ScriptCollection:: { - scripts: vec![Script::::new::>( - path, handle, - )], - }); - } - }; - } -} - -/// optional, hot reloading -fn watch_assets(server: Res) { - server.watch_for_changes().unwrap(); -} - -pub fn delete_script_cmd( - mut log: ConsoleCommand, - mut scripts: Query<(Entity, &mut ScriptCollection)>, -) { - if let Some(DeleteScriptCmd { name, entity_id }) = log.take() { - for (e, mut s) in scripts.iter_mut() { - if e.id() == entity_id { - let old_len = s.scripts.len(); - s.scripts.retain(|s| s.name() != name); - - if old_len > s.scripts.len() { - log.reply_ok(format!("Deleted script {}, on entity: {}", name, entity_id)); - } else { - log.reply_failed(format!( - "Entity {} did own a script named: {}", - entity_id, name - )) - }; - return; - } - } - - log.reply_failed("Could not find given entity ID with a script") - } -} - -#[derive(ConsoleCommand)] -#[console_command(name = "delete_script")] -///Runs a Lua script from the `assets/scripts` directory -pub struct DeleteScriptCmd { - /// the name of the script - pub name: String, - - /// the entity the script is attached to - pub entity_id: u32, -} diff --git a/bevy_mod_scripting/examples/console_integration_rhai.rs b/bevy_mod_scripting/examples/console_integration_rhai.rs deleted file mode 100644 index 172e912409..0000000000 --- a/bevy_mod_scripting/examples/console_integration_rhai.rs +++ /dev/null @@ -1,194 +0,0 @@ -use bevy::{ecs::event::Events, prelude::*}; -use bevy_console::{AddConsoleCommand, ConsoleCommand, ConsolePlugin, PrintConsoleLine}; -use bevy_mod_scripting::{ - events::PriorityEventWriter, langs::rhai::*, APIProvider, AddScriptApiProvider, AddScriptHost, - AddScriptHostHandler, Recipients, RhaiContext, RhaiDocFragment, RhaiEvent, RhaiFile, - RhaiScriptHost, Script, ScriptCollection, ScriptData, ScriptError, ScriptErrorEvent, - ScriptingPlugin, -}; - -/// custom Rhai API, world is provided as a usize (by the script this time), since -/// Rhai does not allow global/local variable access from a callback -#[derive(Default)] -pub struct RhaiAPI; - -impl APIProvider for RhaiAPI { - type APITarget = Engine; - type DocTarget = RhaiDocFragment; - type ScriptContext = RhaiContext; - - fn attach_api(&mut self, engine: &mut Self::APITarget) -> Result<(), ScriptError> { - // rhai allows us to decouple the api from the script context, - // so here we do not have access to the script scope, but the advantage is that - // this single engine is shared with all of our scripts. - // we can also set script wide settings here like this one for all our scripts. - - engine.set_max_expr_depths(0, 0); - - engine.register_fn("print_to_console", |shared_world: usize, msg: String| { - let world: &mut World = unsafe { &mut *(shared_world as *mut World) }; - - let mut events: Mut> = world.get_resource_mut().unwrap(); - events.send(PrintConsoleLine { line: msg }); - - () - }); - - engine.register_fn("entity_id", |entity: Entity| entity.id()); - - Ok(()) - } - - fn setup_script( - &mut self, - _: &ScriptData, - _: &mut Self::ScriptContext, - ) -> Result<(), ScriptError> { - Ok(()) - } -} - -#[derive(Clone)] -pub struct RhaiEventArgs {} - -impl FuncArgs for RhaiEventArgs { - fn parse>(self, _args: &mut ARGS) {} -} - -/// sends updates to script host which are then handled by the scripts -/// in the designated stage -pub fn trigger_on_update_rhai(mut w: PriorityEventWriter>) { - let event = RhaiEvent { - hook_name: "on_update".to_string(), - args: RhaiEventArgs {}, - recipients: Recipients::All, - }; - - w.send(event, 0); -} - -pub fn forward_script_err_to_console( - mut r: EventReader, - mut w: EventWriter, -) { - for e in r.iter() { - w.send(PrintConsoleLine { - line: format!("ERROR:{}", e.err), - }); - } -} - -fn main() -> std::io::Result<()> { - let mut app = App::new(); - app.add_plugins(DefaultPlugins) - .add_plugin(ScriptingPlugin) - .add_plugin(ConsolePlugin) - .add_startup_system(watch_assets) - // register bevy_console commands - .add_console_command::(run_script_cmd) - .add_console_command::(delete_script_cmd) - // choose and register the script hosts you want to use - .add_script_host::, _>(CoreStage::PostUpdate) - .add_api_provider::>(Box::new(RhaiAPI)) - .add_script_handler_stage::, _, 0, 0>(CoreStage::PostUpdate) - // add your systems - .add_system(trigger_on_update_rhai) - .add_system(forward_script_err_to_console); - - // at runtime press '~' for console then type in help for command formats - app.run(); - - Ok(()) -} - -// we use bevy-debug-console to demonstrate how this can fit in in the runtime of a game -// note that using just the entity id instead of the full Entity has issues, -// but since we aren't despawning/spawning entities this works in our case -#[derive(ConsoleCommand)] -#[console_command(name = "run_script")] -///Runs a Lua script from the `assets/scripts` directory -pub struct RunScriptCmd { - /// the relative path to the script, e.g.: `/hello.lua` for a script located in `assets/scripts/hello.lua` - pub path: String, - - /// the entity id to attach this script to - pub entity: Option, -} - -pub fn run_script_cmd( - mut log: ConsoleCommand, - server: Res, - mut commands: Commands, - mut existing_scripts: Query<&mut ScriptCollection>, -) { - if let Some(RunScriptCmd { path, entity }) = log.take() { - let handle = server.load::(&format!("scripts/{}", &path)); - - match entity { - Some(e) => { - if let Ok(mut scripts) = existing_scripts.get_mut(Entity::from_raw(e)) { - info!("Creating script: scripts/{} {:?}", &path, e); - - scripts - .scripts - .push(Script::::new::>( - path, handle, - )); - } else { - log.reply_failed(format!("Something went wrong")); - }; - } - None => { - info!("Creating script: scripts/{}", &path); - - commands.spawn().insert(ScriptCollection:: { - scripts: vec![Script::::new::>( - path, handle, - )], - }); - } - }; - } -} - -/// optional, hot reloading -fn watch_assets(server: Res) { - server.watch_for_changes().unwrap(); -} - -pub fn delete_script_cmd( - mut log: ConsoleCommand, - mut scripts: Query<(Entity, &mut ScriptCollection)>, -) { - if let Some(DeleteScriptCmd { name, entity_id }) = log.take() { - for (e, mut s) in scripts.iter_mut() { - if e.id() == entity_id { - let old_len = s.scripts.len(); - s.scripts.retain(|s| s.name() != name); - - if old_len > s.scripts.len() { - log.reply_ok(format!("Deleted script {}, on entity: {}", name, entity_id)); - } else { - log.reply_failed(format!( - "Entity {} did own a script named: {}", - entity_id, name - )) - }; - return; - } - } - - log.reply_failed("Could not find given entity ID with a script") - } -} - -#[derive(ConsoleCommand)] -#[console_command(name = "delete_script")] -///Runs a Lua script from the `assets/scripts` directory -pub struct DeleteScriptCmd { - /// the name of the script - pub name: String, - - /// the entity the script is attached to - pub entity_id: u32, -} diff --git a/bevy_mod_scripting/examples/lua/bevy_api.rs b/bevy_mod_scripting/examples/lua/bevy_api.rs new file mode 100644 index 0000000000..6d90e347ec --- /dev/null +++ b/bevy_mod_scripting/examples/lua/bevy_api.rs @@ -0,0 +1,233 @@ +use bevy::app::AppExit; +use bevy::math::DQuat; +use bevy::prelude::*; +use bevy_mod_scripting::{ + langs::mlu::mlua::{self, UserData}, + lua::bevy::LuaBevyAPIProvider, + AddScriptApiProvider, AddScriptHost, LuaEvent, LuaScriptHost, Recipients, ReflectLuaProxyable, + RegisterForeignLuaType, ScriptHost, ScriptingPlugin, ValueLuaType, +}; + +/// Let's define a resource, we want it to be "assignable" via lua so we derive `ReflectLuaProxyable` +/// This allows us to reach this value when it's a field under any other Reflectable type + +#[derive(Default, Clone, Reflect)] +#[reflect(Resource, LuaProxyable)] +pub struct MyResource { + pub thing: f64, +} + +/// NOTE: this is a marker enabling an automatic implementation of LuaProxyable +/// By default, because this type implements Clone as well, +/// It will be passed BY VALUE +/// meaning that calling these methods will result in changes to the cloned value on lua side only +/// untill the resource is assigned back to the original component to make the changes on the original type. +/// To have "pass by reference" semantics use a [`bevy_mod_scripting::api::lua::LuaWrapper`] and implement LuaProxyable yourself (see wrappers.rs example) +impl ValueLuaType for MyResource {} + +impl UserData for MyResource { + fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) { + methods.add_method_mut("custom_resource_method", |_, s, v: f64| { + s.thing = v; + + Ok("hello?") + }); + + methods.add_meta_method(mlua::MetaMethod::ToString, |_, s, ()| { + Ok(format!( + "I'm a resource with a custom metatable!: {}", + s.thing + )) + }); + } +} + +#[derive(Component, Default, Reflect)] +#[reflect(Component)] +pub struct MyComponent { + dquat: DQuat, + quat: Quat, + vec2: Vec2, + vec3: Vec3, + uvec2: UVec2, + usize: usize, + f32: f32, + mat3: Mat3, + vec4: Vec4, + u8: u8, + option: Option, + vec_of_option_bools: Vec>, + option_vec_of_bools: Option>, +} + +fn main() -> std::io::Result<()> { + let mut app = App::new(); + + app.add_plugins(DefaultPlugins) + .add_plugin(ScriptingPlugin) + .register_type::() + .register_type::() + // note the implementation for Option is there, but we must register `LuaProxyable` for it + .register_foreign_lua_type::>() + .register_foreign_lua_type::>>() + .register_foreign_lua_type::>() + .register_foreign_lua_type::>>() + .init_resource::() + // this stage handles addition and removal of script contexts, we can safely use `CoreStage::PostUpdate` + .add_script_host::, _>(CoreStage::PostUpdate) + .add_api_provider::>(Box::new(LuaBevyAPIProvider)) + .add_system( + (|world: &mut World| { + + world.spawn() + .insert(MyComponent { + vec2: Vec2::new(1.0, 2.0), + vec3: Vec3::new(1.0, 2.0, 3.0), + vec4: Vec4::new(1.0, 2.0, 3.0, 4.0), + uvec2: UVec2::new(1, 2), + usize: 5, + f32: 6.7, + mat3: Mat3::from_cols( + Vec3::new(1.0, 2.0, 3.0), + Vec3::new(4.0, 5.0, 6.0), + Vec3::new(7.0, 8.0, 9.0), + ), + quat: Quat::from_xyzw(1.0, 2.0, 3.0, 4.0), + dquat: DQuat::from_xyzw(1.0, 2.0, 3.0, 4.0), + u8: 240, + option: None, + vec_of_option_bools: vec![Some(true), None, Some(false)], + option_vec_of_bools: Some(vec![true, true, true]), + }); + + // run script + world.resource_scope(|world, mut host: Mut>| { + host.run_one_shot( + r#" + function once() + -- we first retrieve ID's for our component and resource by their short name (long name/full path also work) + + local my_component_type = world:get_type_by_name("MyComponent") + local my_resource_type = world:get_type_by_name("MyResource") + + -- then ask the world to give us a reference to `MyComponent` on the entity we just spawned + -- normally we could use `entity` but we are running in a one shot environment + + local comp = world:get_component(Entity.from_raw(0), my_component_type) + -- and our resource + + local res = world:get_resource(my_resource_type) + -- we can now arbitrarily affect these + + -- we can even call our custom methods! + + print(string.format(res:custom_resource_method(42))) + + -- we can set any of the fields + -- if the field is `LuaProxyable` like our resource + -- that trait's implementation controls this assignment + comp.u8 = 2 + + -- Option's get converted to nil | Value + + if comp.option == nil then + print(string.format("option was %s", comp.option)) + comp.option = Vec3.new(2,1,3) + print(string.format("option[1] is now %s", comp.option[1])) + comp.option[1] = 5 + print(string.format("and now option[1] is %s", comp.option[1])) + end + + -- Vec references get converted to a special proxy `LuaVec` which is + -- assignable via the Lua Tables + + comp.vec_of_option_bools = {true,false,true} + + -- everything on the bevy side which uses Lua constructs as "Owned" variants + -- indexes from 1, other types map one to one with the bevy implementations and index from zero + + comp.vec_of_option_bools[1] = false + -- there are some additional methods available on LuaVec + + comp.vec_of_option_bools:insert(1,nil) + comp.vec_of_option_bools:push(false) + + -- Note, that Option's are reflected as Value types in Bevy, we are using + -- a custom magical SubReflection system allowing us to do this! + + comp.option_vec_of_bools = {false,true,false} + comp.option_vec_of_bools[1] = true + comp.option_vec_of_bools:insert(1,false) + comp.option_vec_of_bools:push(true) + + print(#comp.vec_of_option_bools) + print(comp.vec_of_option_bools:pop()) + print(comp.option_vec_of_bools:pop()) + + for k,v in pairs(comp.vec_of_option_bools) do + print(string.format("%s:%s",k,v)) + end + + print(#comp.option_vec_of_bools) + + for k,v in pairs(comp.option_vec_of_bools) do + print(string.format("%s:%s",k,v)) + end + + comp.vec_of_option_bools:clear() + + print(#comp.vec_of_option_bools) + + -- Every Bevy type implementing Reflect is available as a LuaProxyable wrapper + -- available types are under `api::lua::bevy::*` and std types in `api::lua::std::*` + -- not all functions are exposed but support for more complex functions will be rolled out + + comp.vec2 = comp.vec2 + comp.vec2 + comp.uvec2 = comp.uvec2 + comp.uvec2 + comp.usize = comp.vec2:min_element() + comp.f32 = comp.f32 + comp.f32 + comp.vec2:min_element() + comp.vec2 = Vec2.new(2,1) + comp.vec3 = Vec3.new(0,1,0):any_orthonormal_vector() + comp.mat3.x_axis + comp.option + comp.vec4 = Vec4.splat(3) + comp.quat = Quat.from_xyzw(3,2,1,4) + comp.dquat = comp.dquat * 2 + local a = Mat3.from_cols(Vec3.new(1,0,0),Vec3.new(0,1,0),Vec3.new(0,0,-1)) + + -- again an instance of sub reflection here, very cool! + + comp.mat3[0][0] = 42 + comp.mat3.x_axis = Vec3.new(69,69,69) + + -- now let's retrieve these again to see if we actually changed their values + + comp = world:get_component(Entity.from_raw(0),my_component_type) + res = world:get_resource(my_resource_type) + + -- notet that our custom resource's value has not affected the original + -- this is because it is a by-value proxy, see wrappers.rs for an alternative + print("After script:") + print(string.format("%s", comp)) + print(string.format("%s", res)) + end + "# + .as_bytes(), + "script.lua", + world, + LuaEvent { + hook_name: "once".to_owned(), + args: (), + recipients: Recipients::All, + }, + ) + .expect("Something went wrong in the script!"); + }); + + world.send_event(AppExit) + }) + .exclusive_system(), + ); + + app.run(); + + Ok(()) +} diff --git a/bevy_mod_scripting/examples/complex_game_loop.rs b/bevy_mod_scripting/examples/lua/complex_game_loop.rs similarity index 88% rename from bevy_mod_scripting/examples/complex_game_loop.rs rename to bevy_mod_scripting/examples/lua/complex_game_loop.rs index fa26e10f68..e7026bbcf5 100644 --- a/bevy_mod_scripting/examples/complex_game_loop.rs +++ b/bevy_mod_scripting/examples/lua/complex_game_loop.rs @@ -1,8 +1,9 @@ -use bevy::{core::FixedTimestep, prelude::*}; -use bevy_console::ConsolePlugin; +use bevy::prelude::*; +use bevy::time::FixedTimestep; use bevy_event_priority::PriorityEventWriter; use bevy_mod_scripting::{ langs::mlu::{mlua, mlua::prelude::*, mlua::Value}, + mlu::mlua::Variadic, APIProvider, AddScriptApiProvider, AddScriptHost, AddScriptHostHandler, LuaDocFragment, LuaEvent, LuaFile, LuaScriptHost, Recipients, Script, ScriptCollection, ScriptData, ScriptError, ScriptingPlugin, @@ -35,7 +36,7 @@ impl APIProvider for LuaAPIProvider { // return any `FromLuaMulti` arguments, here a `usize` // check the Rlua documentation for more details - let ctx = ctx.lock().unwrap(); + let ctx = ctx.get_mut().unwrap(); ctx.globals().set( "print", @@ -60,17 +61,22 @@ impl APIProvider for LuaAPIProvider { static COUNTER: AtomicU32 = AtomicU32::new(0); /// utility for generating random events from a list -fn fire_random_event(w: &mut PriorityEventWriter>, events: &[ScriptEventData]) { +fn fire_random_event( + w: &mut PriorityEventWriter>>, + events: &[ScriptEventData], +) { let mut rng = rand::thread_rng(); let id = COUNTER.fetch_add(1, Relaxed); let arg = MyLuaArg(id as usize); let (event, prio) = events .choose(&mut rng) .map(|v| { + let mut args = Variadic::new(); + args.push(arg); ( LuaEvent { hook_name: v.0.to_string(), - args: vec![arg], + args, recipients: Recipients::All, }, v.1, @@ -85,7 +91,7 @@ fn fire_random_event(w: &mut PriorityEventWriter>, events: &[ w.send(event, prio); } -fn do_some_shit_before_physics(mut w: PriorityEventWriter>) { +fn do_some_shit_before_physics(mut w: PriorityEventWriter>>) { info!("PrePhysics, firing:"); for _ in 0..5 { @@ -94,7 +100,7 @@ fn do_some_shit_before_physics(mut w: PriorityEventWriter>) { } } -fn do_physics(mut w: PriorityEventWriter>) { +fn do_physics(mut w: PriorityEventWriter>>) { info!("Physics, firing:"); for _ in 0..5 { @@ -103,7 +109,7 @@ fn do_physics(mut w: PriorityEventWriter>) { } } -fn do_update(mut w: PriorityEventWriter>) { +fn do_update(mut w: PriorityEventWriter>>) { info!("Update, firing:"); // fire random event, for any stages @@ -133,10 +139,7 @@ fn load_our_script(server: Res, mut commands: Commands) { let handle = server.load::(path); commands.spawn().insert(ScriptCollection:: { - scripts: vec![Script::::new::>( - path.to_string(), - handle, - )], + scripts: vec![Script::::new(path.to_string(), handle)], }); } @@ -153,7 +156,6 @@ fn main() -> std::io::Result<()> { app.add_plugins(DefaultPlugins) .add_plugin(ScriptingPlugin) - .add_plugin(ConsolePlugin) .add_startup_system(load_our_script) // --- main systems stages // physics logic stage (twice a second) @@ -178,7 +180,7 @@ fn main() -> std::io::Result<()> { PRE_PHYSICS_SCRIPTS, SystemStage::single_threaded(), ) - .add_script_handler_stage_with_criteria::, _, _, _, 0, 10>( + .add_script_handler_stage_with_criteria::>, _, _, _, 0, 10>( PRE_PHYSICS_SCRIPTS, FixedTimestep::step(TIMESTEP_2_PER_SECOND), ) @@ -189,7 +191,7 @@ fn main() -> std::io::Result<()> { POST_PHYSICS_SCRIPTS, SystemStage::single_threaded(), ) - .add_script_handler_stage_with_criteria::, _, _, _, 11, 20>( + .add_script_handler_stage_with_criteria::>, _, _, _, 11, 20>( POST_PHYSICS_SCRIPTS, FixedTimestep::step(TIMESTEP_2_PER_SECOND), ) @@ -201,10 +203,10 @@ fn main() -> std::io::Result<()> { POST_UPDATE_SCRIPTS, SystemStage::single_threaded(), ) - .add_script_handler_stage::, _, 21, 30>(POST_UPDATE_SCRIPTS) + .add_script_handler_stage::>, _, 21, 30>(POST_UPDATE_SCRIPTS) // this stage handles addition and removal of script contexts, we can safely use `CoreStage::PostUpdate` - .add_script_host::, _>(CoreStage::PostUpdate) - .add_api_provider::>(Box::new(LuaAPIProvider)); + .add_script_host::>, _>(CoreStage::PostUpdate) + .add_api_provider::>>(Box::new(LuaAPIProvider)); // We have 3 core systems // PrePhysics (twice per second), fires 5 random events diff --git a/bevy_mod_scripting/examples/lua/console_integration.rs b/bevy_mod_scripting/examples/lua/console_integration.rs new file mode 100644 index 0000000000..7472d2ade5 --- /dev/null +++ b/bevy_mod_scripting/examples/lua/console_integration.rs @@ -0,0 +1,205 @@ +fn main() -> std::io::Result<()> { + Ok(()) +} + +// use bevy::{ecs::event::Events, prelude::*}; +// use bevy_console::{AddConsoleCommand, ConsoleCommand, ConsolePlugin, PrintConsoleLine}; +// use bevy_mod_scripting::{ +// events::PriorityEventWriter, +// langs::mlu::{mlua, mlua::prelude::*, mlua::Value}, +// APIProvider, AddScriptApiProvider, AddScriptHost, AddScriptHostHandler, LuaDocFragment, +// LuaEvent, LuaFile, LuaScriptHost, Recipients, Script, ScriptCollection, ScriptData, +// ScriptError, ScriptErrorEvent, ScriptingPlugin, +// }; +// use std::sync::Mutex; + +// #[derive(Clone)] +// pub struct MyLuaArg; + +// impl<'lua> ToLua<'lua> for MyLuaArg { +// fn to_lua(self, _: &'lua Lua) -> mlua::Result> { +// Ok(Value::Nil) +// } +// } + +// #[derive(Default)] +// pub struct LuaAPIProvider; + +// /// the custom Lua api, world is provided via a global pointer, +// /// and callbacks are defined only once at script creation +// impl APIProvider for LuaAPIProvider { +// type APITarget = Mutex; +// type DocTarget = LuaDocFragment; +// type ScriptContext = Mutex; + +// fn attach_api(&mut self, ctx: &mut Self::APITarget) -> Result<(), ScriptError> { +// // callbacks can receive any `ToLuaMulti` arguments, here '()' and +// // return any `FromLuaMulti` arguments, here a `usize` +// // check the Rlua documentation for more details + +// let ctx = ctx.lock().unwrap(); + +// ctx.globals().set( +// "print_to_console", +// ctx.create_function(|ctx, msg: String| { +// // retrieve the world pointer +// let world_data: usize = ctx.globals().get("world").unwrap(); +// let world: &mut World = unsafe { &mut *(world_data as *mut World) }; + +// let mut events: Mut> = world.get_resource_mut().unwrap(); +// events.send(PrintConsoleLine { line: msg }); + +// // return something +// Ok(()) +// })?, +// )?; + +// Ok(()) +// } + +// fn setup_script( +// &mut self, +// _: &ScriptData, +// _: &mut Self::ScriptContext, +// ) -> Result<(), ScriptError> { +// Ok(()) +// } +// } + +// /// sends updates to script host which are then handled by the scripts +// /// in the designated stage +// pub fn trigger_on_update_lua(mut w: PriorityEventWriter>) { +// let event = LuaEvent { +// hook_name: "on_update".to_string(), +// args: Vec::default(), +// recipients: Recipients::All, +// }; + +// w.send(event, 0); +// } + +// pub fn forward_script_err_to_console( +// mut r: EventReader, +// mut w: EventWriter, +// ) { +// for e in r.iter() { +// w.send(PrintConsoleLine { +// line: format!("ERROR:{}", e.err), +// }); +// } +// } + +// fn main() -> std::io::Result<()> { +// let mut app = App::new(); +// app.add_plugins(DefaultPlugins) +// .add_plugin(ScriptingPlugin) +// .add_plugin(ConsolePlugin) +// .add_startup_system(watch_assets) +// // register bevy_console commands +// .add_console_command::(run_script_cmd) +// .add_console_command::(delete_script_cmd) +// // choose and register the script hosts you want to use +// .add_script_host::, _>(CoreStage::PostUpdate) +// .add_api_provider::>(Box::new(LuaAPIProvider)) +// .add_script_handler_stage::, _, 0, 0>(CoreStage::PostUpdate) +// // add your systems +// .add_system(trigger_on_update_lua) +// .add_system(forward_script_err_to_console); + +// // at runtime press '~' for console then type in help for command formats +// app.run(); + +// Ok(()) +// } + +// // we use bevy-debug-console to demonstrate how this can fit in in the runtime of a game +// // note that using just the entity id instead of the full Entity has issues, +// // but since we aren't despawning/spawning entities this works in our case +// #[derive(ConsoleCommand)] +// #[console_command(name = "run_script")] +// ///Runs a Lua script from the `assets/scripts` directory +// pub struct RunScriptCmd { +// /// the relative path to the script, e.g.: `/hello.lua` for a script located in `assets/scripts/hello.lua` +// pub path: String, + +// /// the entity id to attach this script to +// pub entity: Option, +// } + +// pub fn run_script_cmd( +// mut log: ConsoleCommand, +// server: Res, +// mut commands: Commands, +// mut existing_scripts: Query<&mut ScriptCollection>, +// ) { +// if let Some(RunScriptCmd { path, entity }) = log.take() { +// let handle = server.load::(&format!("scripts/{}", &path)); + +// match entity { +// Some(e) => { +// if let Ok(mut scripts) = existing_scripts.get_mut(Entity::from_raw(e)) { +// info!("Creating script: scripts/{} {:?}", &path, e); + +// scripts +// .scripts +// .push(Script::::new::>( +// path, handle, +// )); +// } else { +// log.reply_failed(format!("Something went wrong")); +// }; +// } +// None => { +// info!("Creating script: scripts/{}", &path); + +// commands.spawn().insert(ScriptCollection:: { +// scripts: vec![Script::::new::>( +// path, handle, +// )], +// }); +// } +// }; +// } +// } + +// /// optional, hot reloading +// fn watch_assets(server: Res) { +// server.watch_for_changes().unwrap(); +// } + +// pub fn delete_script_cmd( +// mut log: ConsoleCommand, +// mut scripts: Query<(Entity, &mut ScriptCollection)>, +// ) { +// if let Some(DeleteScriptCmd { name, entity_id }) = log.take() { +// for (e, mut s) in scripts.iter_mut() { +// if e.id() == entity_id { +// let old_len = s.scripts.len(); +// s.scripts.retain(|s| s.name() != name); + +// if old_len > s.scripts.len() { +// log.reply_ok(format!("Deleted script {}, on entity: {}", name, entity_id)); +// } else { +// log.reply_failed(format!( +// "Entity {} did own a script named: {}", +// entity_id, name +// )) +// }; +// return; +// } +// } + +// log.reply_failed("Could not find given entity ID with a script") +// } +// } + +// #[derive(ConsoleCommand)] +// #[console_command(name = "delete_script")] +// ///Runs a Lua script from the `assets/scripts` directory +// pub struct DeleteScriptCmd { +// /// the name of the script +// pub name: String, + +// /// the entity the script is attached to +// pub entity_id: u32, +// } diff --git a/bevy_mod_scripting/examples/documentation_gen_lua.rs b/bevy_mod_scripting/examples/lua/documentation_gen.rs similarity index 72% rename from bevy_mod_scripting/examples/documentation_gen_lua.rs rename to bevy_mod_scripting/examples/lua/documentation_gen.rs index 6137b73fdb..76977c13a2 100644 --- a/bevy_mod_scripting/examples/documentation_gen_lua.rs +++ b/bevy_mod_scripting/examples/lua/documentation_gen.rs @@ -1,11 +1,10 @@ use bevy::prelude::*; -use bevy_console::ConsolePlugin; -use bevy_event_priority::PriorityEventWriter; + use bevy_mod_scripting::{ + api::lua::bevy::LuaBevyAPIProvider, langs::mlu::{mlua, mlua::prelude::*, mlua::Value, TealData}, APIProvider, AddScriptApiProvider, AddScriptHost, AddScriptHostHandler, GenDocumentation, - LuaDocFragment, LuaEvent, LuaFile, LuaScriptHost, Recipients, Script, ScriptCollection, - ScriptData, ScriptError, ScriptingPlugin, + LuaDocFragment, LuaScriptHost, ScriptError, ScriptingPlugin, }; use tealr::TypeName; @@ -28,9 +27,8 @@ pub struct APIModule; impl TealData for APIModule { fn add_methods<'lua, T: tealr::mlu::TealDataMethods<'lua, Self>>(methods: &mut T) { - methods.document_type( - "This is module level documentation for our api, it will be shown first", - ); + methods + .document_type("This is type level documentation for our api, it will be shown first"); methods.document_type(""); methods.document("Here we document the next function"); @@ -41,16 +39,18 @@ impl TealData for APIModule { \n```", ); methods.add_function("my_function", |_, ()| Ok("hello world!")); - methods.generate_help(); } } /// This is tealr's way to export global items /// Here `my_api` will be available globally in the lua script + +#[derive(Default)] struct Export; impl tealr::mlu::ExportInstances for Export { fn add_instances<'lua, T: tealr::mlu::InstanceCollector<'lua>>( + self, instance_collector: &mut T, ) -> mlua::Result<()> { instance_collector.document_instance("Documentation for the exposed global variable"); @@ -73,10 +73,10 @@ impl APIProvider for LuaAPIProvider { // return any `FromLuaMulti` arguments, here a `usize` // check the Rlua documentation for more details - let ctx = ctx.lock().unwrap(); + let ctx = ctx.get_mut().unwrap(); // equivalent to ctx.globals().set() but for multiple items - tealr::mlu::set_global_env::(&ctx).unwrap(); + tealr::mlu::set_global_env(Export, ctx)?; Ok(()) } @@ -88,36 +88,7 @@ impl APIProvider for LuaAPIProvider { .document_global_instance::().unwrap())) } - fn setup_script( - &mut self, - _: &ScriptData, - _: &mut Self::ScriptContext, - ) -> Result<(), ScriptError> { - Ok(()) - } -} - -fn load_our_script(server: Res, mut commands: Commands) { - let path = "scripts/teal_file.tl"; - let handle = server.load::(path); - - commands.spawn().insert(ScriptCollection:: { - scripts: vec![Script::::new::>( - path.to_string(), - handle, - )], - }); -} - -fn fire_our_script(mut w: PriorityEventWriter>) { - w.send( - LuaEvent:: { - hook_name: "on_update".to_string(), - args: vec![MyLuaArg], - recipients: Recipients::All, - }, - 0, - ) + fn register_with_app(&self, _app: &mut App) {} } fn main() -> std::io::Result<()> { @@ -125,20 +96,19 @@ fn main() -> std::io::Result<()> { app.add_plugins(DefaultPlugins) .add_plugin(ScriptingPlugin) - .add_plugin(ConsolePlugin) + // add the providers and script host .add_script_host::, _>(CoreStage::PostUpdate) .add_api_provider::>(Box::new(LuaAPIProvider)) + .add_api_provider::>(Box::new(LuaBevyAPIProvider)) // this needs to be placed after any `add_api_provider` and `add_script_host` calls // it will generate `doc` and `types` folders under `assets/scripts` containing the documentation and teal declaration files // respectively. See example asset folder to see how they look like. The `teal_file.tl` script in example assets shows the usage of one of those // declaration files, use the teal vscode extension to explore the type hints! // Note: This is a noop in optimized builds unless the `doc_always` feature is enabled! .update_documentation::>() - .add_script_handler_stage::, _, 0, 0>(CoreStage::PostUpdate) - .add_startup_system(load_our_script) - .add_system(fire_our_script); + .add_script_handler_stage::, _, 0, 0>(CoreStage::PostUpdate); - app.run(); + // app.run(); no need, documentation gets generated before the app even starts Ok(()) } diff --git a/bevy_mod_scripting/examples/event_recipients.rs b/bevy_mod_scripting/examples/lua/event_recipients.rs similarity index 93% rename from bevy_mod_scripting/examples/event_recipients.rs rename to bevy_mod_scripting/examples/lua/event_recipients.rs index b60844fd7c..ffdac3aee6 100644 --- a/bevy_mod_scripting/examples/event_recipients.rs +++ b/bevy_mod_scripting/examples/lua/event_recipients.rs @@ -1,5 +1,4 @@ use bevy::prelude::*; -use bevy_console::ConsolePlugin; use bevy_event_priority::PriorityEventWriter; use bevy_mod_scripting::{ langs::mlu::{mlua, mlua::prelude::*, mlua::Value}, @@ -35,7 +34,7 @@ impl APIProvider for LuaAPIProvider { // return any `FromLuaMulti` arguments, here a `usize` // check the Rlua documentation for more details - let ctx = ctx.lock().unwrap(); + let ctx = ctx.get_mut().unwrap(); ctx.globals().set( "print", @@ -68,7 +67,7 @@ fn fire_random_event(w: &mut PriorityEventWriter>, events: &[ .choose(&mut rng) .map(|v| LuaEvent { hook_name: v.0.to_string(), - args: vec![arg], + args: arg, recipients: v.1.clone(), }) .unwrap(); @@ -107,9 +106,7 @@ fn load_our_scripts(server: Res, mut commands: Commands) { let handle = server.load::(path); let scripts = (0..2) .into_iter() - .map(|_| { - Script::::new::>(path.to_string(), handle.clone()) - }) + .map(|_| Script::::new(path.to_string(), handle.clone())) .collect(); commands @@ -122,7 +119,6 @@ fn main() -> std::io::Result<()> { app.add_plugins(DefaultPlugins) .add_plugin(ScriptingPlugin) - .add_plugin(ConsolePlugin) .add_startup_system(load_our_scripts) // randomly fire events for either all scripts, // the script with id 0 diff --git a/bevy_mod_scripting/examples/lua/game_of_life.rs b/bevy_mod_scripting/examples/lua/game_of_life.rs new file mode 100644 index 0000000000..cce89eb93f --- /dev/null +++ b/bevy_mod_scripting/examples/lua/game_of_life.rs @@ -0,0 +1,265 @@ +use std::{borrow::Cow, sync::Mutex}; + +use bevy::{ + diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, + prelude::*, + reflect::Reflect, + render::{ + render_resource::{Extent3d, TextureDimension, TextureFormat}, + texture::ImageSampler, + }, + time::FixedTimestep, + window::WindowResized, +}; +use bevy_mod_scripting::{ + api::lua::bevy::LuaBevyAPIProvider, langs::mlu::mlua, lua_path, prelude::*, std::LuaVec, + ReflectLuaProxyable, +}; + +#[derive(Debug, Default, Reflect, Component)] +#[reflect(Component, LuaProxyable)] +pub struct LifeState { + pub cells: Vec, +} + +impl_script_newtype!( + LifeState : Debug + impl { + get "cells" => |lua,s: &LuaLifeState| { + Ok(LuaVec::::new_ref(s.script_ref().index(Cow::Borrowed("cells")))) + }; + set "cells" => |lua,s,o| { + Vec::::apply_lua(&mut s.script_ref().index(Cow::Borrowed("cells")),lua,o) + }; + } +); + +#[derive(Default)] +pub struct LifeAPI; + +impl APIProvider for LifeAPI { + type APITarget = Mutex; + type ScriptContext = Mutex; + type DocTarget = LuaDocFragment; + + fn attach_api(&mut self, _: &mut Self::APITarget) -> Result<(), ScriptError> { + // we don't actually provide anything global + Ok(()) + } + + fn get_doc_fragment(&self) -> Option { + // this will enable us type casting in teal + Some(LuaDocFragment::new(|tw| tw.process_type::())) + } + + fn register_with_app(&self, app: &mut App) { + // this will register the `LuaProxyable` typedata since we derived it + // this will resolve retrievals of this component to our custom lua object + app.register_type::(); + app.register_type::(); + } +} + +#[derive(Reflect)] +#[reflect(Resource)] +pub struct Settings { + physical_grid_dimensions: (u32, u32), + display_grid_dimensions: (u32, u32), + border_thickness: u32, + live_color: u8, + dead_color: u8, +} + +impl Default for Settings { + fn default() -> Self { + Self { + border_thickness: 1, + live_color: 255u8, + dead_color: 0u8, + physical_grid_dimensions: (88, 50), + display_grid_dimensions: (0, 0), + } + } +} + +pub fn setup( + mut commands: Commands, + mut assets: ResMut>, + asset_server: Res, + settings: Res, +) { + let mut image = Image::new_fill( + Extent3d { + width: settings.physical_grid_dimensions.0, + height: settings.physical_grid_dimensions.1, + depth_or_array_layers: 1, + }, + TextureDimension::D2, + &[0u8], + TextureFormat::R8Unorm, + ); + + image.sampler_descriptor = ImageSampler::nearest(); + + // in release builds we want to fetch ".lua" files over ".tl" files + let script_path = lua_path!("game_of_life"); + + commands.spawn_bundle(Camera2dBundle::default()); + commands + .spawn_bundle(SpriteBundle { + texture: assets.add(image), + sprite: Sprite { + custom_size: Some(Vec2::new( + settings.display_grid_dimensions.0 as f32, + settings.display_grid_dimensions.1 as f32, + )), + color: Color::TOMATO, + ..Default::default() + }, + ..Default::default() + }) + .insert(LifeState { + cells: vec![ + 0u8; + (settings.physical_grid_dimensions.0 * settings.physical_grid_dimensions.1) + as usize + ], + }) + .insert(ScriptCollection:: { + scripts: vec![Script::new( + script_path.to_owned(), + asset_server.load(script_path), + )], + }); +} + +pub fn sync_window_size( + mut resize_event: EventReader, + mut settings: ResMut, + mut query: Query<&mut Sprite, With>, + windows: Res, +) { + if resize_event + .iter() + .filter(|w| w.id.is_primary()) + .last() + .is_some() + { + let primary_window = windows.get_primary().unwrap(); + settings.display_grid_dimensions = ( + primary_window.physical_width(), + primary_window.physical_height(), + ); + + // resize all game's of life, retain aspect ratio and fit the entire game in the window + for mut sprite in query.iter_mut() { + let scale = if settings.physical_grid_dimensions.0 > settings.physical_grid_dimensions.1 + { + // horizontal is longer + settings.display_grid_dimensions.1 as f32 + / settings.physical_grid_dimensions.1 as f32 + } else { + // vertical is longer + settings.display_grid_dimensions.0 as f32 + / settings.physical_grid_dimensions.0 as f32 + }; + + sprite.custom_size = Some(Vec2::new( + (settings.physical_grid_dimensions.0 as f32) * scale, + (settings.physical_grid_dimensions.1 as f32) * scale, + )); + } + } +} + +/// Runs after LifeState components are updated, updates their rendered representation +pub fn update_rendered_state( + mut assets: ResMut>, + query: Query<(&LifeState, &Handle)>, +) { + for (new_state, old_rendered_state) in query.iter() { + let old_rendered_state = assets + .get_mut(old_rendered_state) + .expect("World is not setup correctly"); + + old_rendered_state.data = new_state.cells.clone(); + } +} + +/// Sends events allowing scripts to drive update logic +pub fn send_on_update(mut events: PriorityEventWriter>) { + events.send( + LuaEvent { + hook_name: "on_update".to_owned(), + args: (), + recipients: Recipients::All, + }, + 1, + ) +} + +/// Sends initialization event +pub fn send_init(mut events: PriorityEventWriter>) { + events.send( + LuaEvent { + hook_name: "init".to_owned(), + args: (), + recipients: Recipients::All, + }, + 0, + ) +} + +pub enum LifeStages { + Scripts, +} + +impl StageLabel for LifeStages { + fn as_str(&self) -> &'static str { + match self { + LifeStages::Scripts => "Scripts", + } + } +} + +/// how often to step the simulation +const UPDATE_FREQUENCY: f64 = 1.0 / 20.0; + +fn main() -> std::io::Result<()> { + let mut app = App::new(); + + app.add_plugins(DefaultPlugins) + .add_plugin(LogDiagnosticsPlugin::default()) + .add_plugin(FrameTimeDiagnosticsPlugin::default()) + .add_plugin(ScriptingPlugin) + .init_resource::() + .add_startup_system(setup) + .add_startup_system(send_init) + .add_system(sync_window_size.before(update_rendered_state)) + .add_startup_system(|asset_server: ResMut| { + asset_server.watch_for_changes().unwrap() + }) + .add_system_set( + SystemSet::new() + .with_run_criteria(FixedTimestep::step(UPDATE_FREQUENCY)) + .with_system(update_rendered_state) + .with_system(send_on_update), + ) + .add_stage_after( + CoreStage::Update, + LifeStages::Scripts, + SystemStage::single_threaded(), + ) + .add_script_handler_stage_with_criteria::, _, _, _, 0, 1>( + LifeStages::Scripts, + FixedTimestep::step(UPDATE_FREQUENCY), + ) + .add_script_host::, _>(CoreStage::PostUpdate) + .add_api_provider::>(Box::new(LuaBevyAPIProvider)) + .add_api_provider::>(Box::new(LifeAPI)) + .update_documentation::>(); + + app.run(); + + Ok(()) +} diff --git a/bevy_mod_scripting/examples/rhai/console_integration.rs b/bevy_mod_scripting/examples/rhai/console_integration.rs new file mode 100644 index 0000000000..ac0d65af7d --- /dev/null +++ b/bevy_mod_scripting/examples/rhai/console_integration.rs @@ -0,0 +1,268 @@ +// use bevy::{ecs::event::Events, prelude::*}; +// use bevy_console::{AddConsoleCommand, ConsoleCommand, ConsolePlugin, PrintConsoleLine}; +// use bevy_mod_scripting::{ +// events::PriorityEventWriter, langs::rhai::*, APIProvider, AddScriptApiProvider, AddScriptHost, +// AddScriptHostHandler, Recipients, RhaiContext, RhaiDocFragment, RhaiEvent, RhaiFile, +// RhaiScriptHost, Script, ScriptCollection, ScriptData, ScriptError, ScriptErrorEvent, +// ScriptingPlugin, +// }; + +// /// custom Rhai API, world is provided as a usize (by the script this time), since +// /// Rhai does not allow global/local variable access from a callback +// #[derive(Default)] +// pub struct RhaiAPI; + +// impl APIProvider for RhaiAPI { +// type APITarget = Engine; +// type DocTarget = RhaiDocFragment; +// type ScriptContext = RhaiContext; + +// fn attach_api(&mut self, engine: &mut Self::APITarget) -> Result<(), ScriptError> { +// // rhai allows us to decouple the api from the script context, +// // so here we do not have access to the script scope, but the advantage is that +// // this single engine is shared with all of our scripts. +// // we can also set script wide settings here like this one for all our scripts. + +// engine.set_max_expr_depths(0, 0); + +// engine.register_fn("print_to_console", |shared_world: usize, msg: String| { +// let world: &mut World = unsafe { &mut *(shared_world as *mut World) }; + +// let mut events: Mut> = world.get_resource_mut().unwrap(); +// events.send(PrintConsoleLine { line: msg }); + +// () +// }); + +// engine.register_fn("entity_id", |entity: Entity| entity.id()); + +// Ok(()) +// } + +// fn setup_script( +// &mut self, +// _: &ScriptData, +// _: &mut Self::ScriptContext, +// ) -> Result<(), ScriptError> { +// Ok(()) +// } +// } + +// #[derive(Clone)] +// pub struct RhaiEventArgs {} + +// impl FuncArgs for RhaiEventArgs { +// fn parse>(self, _args: &mut ARGS) {} +// } + +// /// sends updates to script host which are then handled by the scripts +// /// in the designated stage +// pub fn trigger_on_update_rhai(mut w: PriorityEventWriter>) { +// let event = RhaiEvent { +// hook_name: "on_update".to_string(), +// args: RhaiEventArgs {}, +// recipients: Recipients::All, +// }; + +// w.send(event, 0); +// } + +// pub fn forward_script_err_to_console( +// mut r: EventReader, +// mut w: EventWriter, +// ) { +// for e in r.iter() { +// w.send(PrintConsoleLine { +// line: format!("ERROR:{}", e.err), +// }); +// } +// } + +fn main() -> std::io::Result<()> { + Ok(()) +} + +// use bevy::{ecs::event::Events, prelude::*}; +// use bevy_console::{AddConsoleCommand, ConsoleCommand, ConsolePlugin, PrintConsoleLine}; +// use bevy_mod_scripting::{ +// events::PriorityEventWriter, langs::rhai::*, APIProvider, AddScriptApiProvider, AddScriptHost, +// AddScriptHostHandler, Recipients, RhaiDocFragment, RhaiEvent, RhaiFile, RhaiScriptHost, Script, +// ScriptCollection, ScriptError, ScriptErrorEvent, ScriptingPlugin, +// }; + +// /// custom Rhai API, world is provided as a usize (by the script this time), since +// /// Rhai does not allow global/local variable access from a callback +// #[derive(Default)] +// pub struct RhaiAPI; + +// impl APIProvider for RhaiAPI { +// type Target = Engine; +// type DocTarget = RhaiDocFragment; + +// fn attach_api(&mut self, engine: &mut Self::Target) -> Result<(), ScriptError> { +// // rhai allows us to decouple the api from the script context, +// // so here we do not have access to the script scope, but the advantage is that +// // this single engine is shared with all of our scripts. +// // we can also set script wide settings here like this one for all our scripts. + +// engine.set_max_expr_depths(0, 0); + +// engine.register_fn("print_to_console", |shared_world: usize, msg: String| { +// let world: &mut World = unsafe { &mut *(shared_world as *mut World) }; + +// let mut events: Mut> = world.get_resource_mut().unwrap(); +// events.send(PrintConsoleLine { line: msg }); + +// () +// }); + +// engine.register_fn("entity_id", |entity: Entity| entity.id()); + +// Ok(()) +// } +// } + +// #[derive(Clone)] +// pub struct RhaiEventArgs {} + +// impl FuncArgs for RhaiEventArgs { +// fn parse>(self, _args: &mut ARGS) {} +// } + +// /// sends updates to script host which are then handled by the scripts +// /// in the designated stage +// pub fn trigger_on_update_rhai(mut w: PriorityEventWriter>) { +// let event = RhaiEvent { +// hook_name: "on_update".to_string(), +// args: RhaiEventArgs {}, +// recipients: Recipients::All, +// }; + +// w.send(event, 0); +// } + +// pub fn forward_script_err_to_console( +// mut r: EventReader, +// mut w: EventWriter, +// ) { +// for e in r.iter() { +// w.send(PrintConsoleLine { +// line: format!("ERROR:{}", e.err), +// }); +// } +// } + +// fn main() -> std::io::Result<()> { +// let mut app = App::new(); +// app.add_plugins(DefaultPlugins) +// .add_plugin(ScriptingPlugin) +// .add_plugin(ConsolePlugin) +// .add_startup_system(watch_assets) +// // register bevy_console commands +// .add_console_command::(run_script_cmd) +// .add_console_command::(delete_script_cmd) +// // choose and register the script hosts you want to use +// .add_script_host::, _>(CoreStage::PostUpdate) +// .add_api_provider::>(Box::new(RhaiAPI)) +// .add_script_handler_stage::, _, 0, 0>(CoreStage::PostUpdate) +// // add your systems +// .add_system(trigger_on_update_rhai) +// .add_system(forward_script_err_to_console); + +// // at runtime press '~' for console then type in help for command formats +// app.run(); + +// Ok(()) +// } + +// // we use bevy-debug-console to demonstrate how this can fit in in the runtime of a game +// // note that using just the entity id instead of the full Entity has issues, +// // but since we aren't despawning/spawning entities this works in our case +// #[derive(ConsoleCommand)] +// #[console_command(name = "run_script")] +// ///Runs a Lua script from the `assets/scripts` directory +// pub struct RunScriptCmd { +// /// the relative path to the script, e.g.: `/hello.lua` for a script located in `assets/scripts/hello.lua` +// pub path: String, + +// /// the entity id to attach this script to +// pub entity: Option, +// } + +// pub fn run_script_cmd( +// mut log: ConsoleCommand, +// server: Res, +// mut commands: Commands, +// mut existing_scripts: Query<&mut ScriptCollection>, +// ) { +// if let Some(RunScriptCmd { path, entity }) = log.take() { +// let handle = server.load::(&format!("scripts/{}", &path)); + +// match entity { +// Some(e) => { +// if let Ok(mut scripts) = existing_scripts.get_mut(Entity::from_raw(e)) { +// info!("Creating script: scripts/{} {:?}", &path, e); + +// scripts +// .scripts +// .push(Script::::new::>( +// path, handle, +// )); +// } else { +// log.reply_failed(format!("Something went wrong")); +// }; +// } +// None => { +// info!("Creating script: scripts/{}", &path); + +// commands.spawn().insert(ScriptCollection:: { +// scripts: vec![Script::::new::>( +// path, handle, +// )], +// }); +// } +// }; +// } +// } + +// /// optional, hot reloading +// fn watch_assets(server: Res) { +// server.watch_for_changes().unwrap(); +// } + +// pub fn delete_script_cmd( +// mut log: ConsoleCommand, +// mut scripts: Query<(Entity, &mut ScriptCollection)>, +// ) { +// if let Some(DeleteScriptCmd { name, entity_id }) = log.take() { +// for (e, mut s) in scripts.iter_mut() { +// if e.id() == entity_id { +// let old_len = s.scripts.len(); +// s.scripts.retain(|s| s.name() != name); + +// if old_len > s.scripts.len() { +// log.reply_ok(format!("Deleted script {}, on entity: {}", name, entity_id)); +// } else { +// log.reply_failed(format!( +// "Entity {} did own a script named: {}", +// entity_id, name +// )) +// }; +// return; +// } +// } + +// log.reply_failed("Could not find given entity ID with a script") +// } +// } + +// #[derive(ConsoleCommand)] +// #[console_command(name = "delete_script")] +// ///Runs a Lua script from the `assets/scripts` directory +// pub struct DeleteScriptCmd { +// /// the name of the script +// pub name: String, + +// /// the entity the script is attached to +// pub entity_id: u32, +// } diff --git a/bevy_mod_scripting/examples/wrappers.rs b/bevy_mod_scripting/examples/wrappers.rs new file mode 100644 index 0000000000..caa2484342 --- /dev/null +++ b/bevy_mod_scripting/examples/wrappers.rs @@ -0,0 +1,142 @@ +use bevy::app::AppExit; +use bevy::prelude::*; +use bevy::reflect::TypeRegistryArc; +use bevy_mod_scripting::{api::lua::bevy::LuaWorld, ScriptRef}; +use bevy_mod_scripting::{langs::mlu::mlua, AddScriptHost, LuaEvent, Recipients, ScriptingPlugin}; +use bevy_mod_scripting::{LuaScriptHost, ScriptHost}; +use bevy_mod_scripting_derive::impl_script_newtype; + +// Step 1. Rust representation +// construct all our types and functionality +// Reflect is neccessary to allow access from scripts +// Clone allows receiving our wrapper as a function parameter (derives FromLua via UserData through mlua's traits) +// We can still use references to NonClone wrappers via AnyUserData in lua methods. +// Even though we are implementing Clone we are still able to reference the original data in script thanks to the script wrapper we are about to implement +// Debug is nice to have, we can forward that implementation to Lua's ToString via our macro +#[derive(Reflect, Default, Clone, Debug)] +#[reflect(Resource)] +pub struct MyThing { + usize: usize, + string: String, +} + +impl MyThing { + pub fn do_something_cool(&self) -> String { + self.string.clone() + } +} + +// Step 2. Script representation +// this macro does some magic and provides you with a `LuaMyThing` (and possibly more for other enabled languages) type with which you can create: +// - owned values of your type via ::new() +// - references to something in the world (or script) via ::new_ref() and the ScriptRef API +// (however this is only really accessible given the world provided to the script via the script host) +// Script references can also be made to subfields (even non reflectable ones) of types via sub reflection +// +// Note: this step is not fully necessary, if your value is reflectable, you'll be able to reach it via +// The bevy API, however doing this means your provide static typing for your scripts in languages which support it, +// To see what else this macro can do see `src/api/generated.rs` +impl_script_newtype!( + MyThing: + Debug + Clone + + Fields( + /// My usize field + usize: Raw(usize), + /// My string field + string: Raw(String) + + ) + Methods( + /// Does something realy cool! + /// this documentation gets forwarded to any utilities provided by the script host wooo + do_something_cool(&self:) + ) + + impl { + // we can also directly add methods to the underlying script traits using their specific syntax + // note that in this case you need to provide an implementation for every language you want to support, + // the flags above automatically do this for you. + + // below is a custom lua function + // the fn here means this is a function and not a method (no self argument) + // normally you'd make these available globally via mlua::create_proxy, but I digress. + fn "make_ref_to_my_resource" => |ctx,()| { + let globals = ctx.globals(); + let lua_world : LuaWorld = globals.get("world")?; + let world = lua_world.upgrade().expect("World is gone! we're doomed!"); + let mut world = world.write(); + + let reflect_resource_data = world.resource_scope(|world, type_registry: Mut| { + let type_registry = type_registry.read(); + let data = type_registry.get_type_data::(std::any::TypeId::of::()).expect("Type not registered properly"); + data.clone() + }); + + // this is absolutely safe! + Ok(LuaMyThing::new_ref(ScriptRef::new_resource_ref(reflect_resource_data, lua_world.as_ref().clone()))) + }; + } + +); + +fn main() -> std::io::Result<()> { + let mut app = App::new(); + + app.add_plugins(DefaultPlugins) + .add_plugin(ScriptingPlugin) + .add_script_host::, _>(CoreStage::PostUpdate) + .register_type::() + .init_resource::() + .add_system( + (|world: &mut World| { + world.insert_resource(MyThing { + usize: 420, + string: "I live in the bevy world, you can't touch me!".to_owned(), + }); + + // run script + world.resource_scope(|world, mut host: Mut>| { + host.run_one_shot( + r#" + function once(my_thing) + local my_thing2 = my_thing.make_ref_to_my_resource() + print(my_thing2) + print(my_thing2.usize) + print(my_thing2.string) + print(my_thing2:do_something_cool()) + + my_thing2.usize = my_thing.usize + my_thing2.string = my_thing.string + + print(my_thing2:do_something_cool()) + end + "# + .as_bytes(), + "script.lua", + world, + LuaEvent { + hook_name: "once".to_owned(), + args: LuaMyThing::new(MyThing { + usize: 42, + string: "Haha! Yes I can!!!!".to_owned(), + }), + recipients: Recipients::All, + }, + ) + .expect("Something went wrong in the script!"); + }); + + // print current state of MyThing + let my_thing = world + .get_resource::() + .expect("Could not find MyThing Resource"); + println!("After script run: {my_thing:#?}"); + // exit app + world.send_event(AppExit) + }) + .exclusive_system(), + ); + + app.run(); + + Ok(()) +} diff --git a/bevy_mod_scripting/src/api/generated.rs b/bevy_mod_scripting/src/api/generated.rs new file mode 100644 index 0000000000..29710d886b --- /dev/null +++ b/bevy_mod_scripting/src/api/generated.rs @@ -0,0 +1,9623 @@ +#[allow(clippy::all)] +// This file is generated by `bevy_mod_scripting_derive/main.rs` change the template not this file +extern crate self as bevy_mod_scripting; +use crate::impl_tealr_generic; +use crate::{ + api::ValueIndex, impl_tealr_any_union, APIProvider, LuaDocFragment, ReflectPathElem, + ReflectedValue, ReflectionError, RegisterForeignLuaType, +}; +use crate::{ + lua::bevy::{LuaScriptData, LuaTypeRegistration, LuaWorld}, + std::LuaVec, + DummyTypeName, +}; +use bevy::animation::AnimationPlayer; +use bevy::asset::AssetPathId; +use bevy::asset::HandleId; +use bevy::asset::LabelId; +use bevy::asset::SourcePathId; +use bevy::core::Name; +use bevy::core_pipeline::clear_color::ClearColor; +use bevy::core_pipeline::clear_color::ClearColorConfig; +use bevy::core_pipeline::core_2d::Camera2d; +use bevy::core_pipeline::core_3d::Camera3d; +use bevy::core_pipeline::core_3d::Camera3dDepthLoadOp; +use bevy::ecs::entity::Entity; +use bevy::gltf::GltfExtras; +use bevy::hierarchy::Children; +use bevy::hierarchy::Parent; +use bevy::math::bool::BVec2; +use bevy::math::bool::BVec3; +use bevy::math::bool::BVec3A; +use bevy::math::bool::BVec4; +use bevy::math::bool::BVec4A; +use bevy::math::f32::Affine2; +use bevy::math::f32::Affine3A; +use bevy::math::f32::Mat2; +use bevy::math::f32::Mat3; +use bevy::math::f32::Mat3A; +use bevy::math::f32::Mat4; +use bevy::math::f32::Quat; +use bevy::math::f32::Vec2; +use bevy::math::f32::Vec3; +use bevy::math::f32::Vec3A; +use bevy::math::f32::Vec4; +use bevy::math::f64::DAffine2; +use bevy::math::f64::DAffine3; +use bevy::math::f64::DMat2; +use bevy::math::f64::DMat3; +use bevy::math::f64::DMat4; +use bevy::math::f64::DQuat; +use bevy::math::f64::DVec2; +use bevy::math::f64::DVec3; +use bevy::math::f64::DVec4; +use bevy::math::i32::IVec2; +use bevy::math::i32::IVec3; +use bevy::math::i32::IVec4; +use bevy::math::u32::UVec2; +use bevy::math::u32::UVec3; +use bevy::math::u32::UVec4; +use bevy::math::EulerRot; +use bevy::pbr::wireframe::Wireframe; +use bevy::pbr::wireframe::WireframeConfig; +use bevy::pbr::AlphaMode; +use bevy::pbr::AmbientLight; +use bevy::pbr::CubemapVisibleEntities; +use bevy::pbr::DirectionalLight; +use bevy::pbr::DirectionalLightShadowMap; +use bevy::pbr::NotShadowCaster; +use bevy::pbr::NotShadowReceiver; +use bevy::pbr::PointLight; +use bevy::pbr::PointLightShadowMap; +use bevy::prelude::App; +use bevy::render::camera::Camera; +use bevy::render::camera::CameraProjection; +use bevy::render::camera::CameraRenderGraph; +use bevy::render::camera::DepthCalculation; +use bevy::render::camera::OrthographicProjection; +use bevy::render::camera::PerspectiveProjection; +use bevy::render::camera::Projection; +use bevy::render::camera::RenderTarget; +use bevy::render::camera::ScalingMode; +use bevy::render::camera::Viewport; +use bevy::render::camera::WindowOrigin; +use bevy::render::color::Color; +use bevy::render::mesh::skinning::SkinnedMesh; +use bevy::render::primitives::Aabb; +use bevy::render::primitives::CubemapFrusta; +use bevy::render::primitives::Frustum; +use bevy::render::view::visibility::ComputedVisibility; +use bevy::render::view::visibility::RenderLayers; +use bevy::render::view::visibility::Visibility; +use bevy::render::view::visibility::VisibleEntities; +use bevy::render::view::Msaa; +use bevy::sprite::Anchor; +use bevy::sprite::Mesh2dHandle; +use bevy::sprite::Rect; +use bevy::sprite::Sprite; +use bevy::sprite::TextureAtlasSprite; +use bevy::text::HorizontalAlign; +use bevy::text::Text; +use bevy::text::Text2dBounds; +use bevy::text::Text2dSize; +use bevy::text::TextAlignment; +use bevy::text::TextSection; +use bevy::text::TextStyle; +use bevy::text::VerticalAlign; +use bevy::time::Stopwatch; +use bevy::time::Timer; +use bevy::transform::components::GlobalTransform; +use bevy::transform::components::Transform; +use bevy::ui::widget::Button; +use bevy::ui::widget::ImageMode; +use bevy::ui::AlignContent; +use bevy::ui::AlignItems; +use bevy::ui::AlignSelf; +use bevy::ui::CalculatedClip; +use bevy::ui::CalculatedSize; +use bevy::ui::Direction; +use bevy::ui::Display; +use bevy::ui::FlexDirection; +use bevy::ui::FlexWrap; +use bevy::ui::FocusPolicy; +use bevy::ui::Interaction; +use bevy::ui::JustifyContent; +use bevy::ui::Node; +use bevy::ui::Overflow; +use bevy::ui::PositionType; +use bevy::ui::Style; +use bevy::ui::UiColor; +use bevy::ui::UiImage; +use bevy::ui::Val; +use bevy_mod_scripting_derive::impl_script_newtype; +use std::ops::*; +use std::sync::Mutex; +use tealr::mlu::{ + mlua, + mlua::{prelude::*, MetaMethod}, +}; +impl_script_newtype! { + ///Defines how each line is aligned within the flexbox. + /// + ///It only applies if [`FlexWrap::Wrap`] is present and if there are multiple lines of items. + bevy_ui::AlignContent : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///How items are aligned according to the cross axis + bevy_ui::AlignItems : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Works like [`AlignItems`] but applies only to a single item + bevy_ui::AlignSelf : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Defines the text direction + /// + ///For example English is written LTR (left-to-right) while Arabic is written RTL (right-to-left). + bevy_ui::Direction : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Defines how flexbox items are ordered within a flexbox + bevy_ui::FlexDirection : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Defines if flexbox items appear on a single line or on multiple lines + bevy_ui::FlexWrap : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Describes whether the node should block interactions with lower nodes + bevy_ui::FocusPolicy : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Describes what type of input interaction has occurred for a UI node. + /// + ///This is commonly queried with a `Changed` filter. + /// + ///Updated in [`ui_focus_system`]. + /// + ///If a UI node has both [`Interaction`] and [`ComputedVisibility`] components, + ///[`Interaction`] will always be [`Interaction::None`] + ///when [`ComputedVisibility::is_visible()`] is false. + ///This ensures that hidden UI nodes are not interactable, + ///and do not end up stuck in an active state if hidden at the wrong time. + /// + ///Note that you can also control the visibility of a node using the [`Display`](crate::ui_node::Display) property, + ///which fully collapses it during layout calculations. + bevy_ui::Interaction : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Defines how items are aligned according to the main axis + bevy_ui::JustifyContent : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Whether to show or hide overflowing items + bevy_ui::Overflow : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///The strategy used to position this node + bevy_ui::PositionType : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///An enum that describes possible types of value in flexbox layout options + bevy_ui::Val : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + self Add Raw(f32) -> Wrapped(Val), + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///The calculated clip of the node + bevy_ui::CalculatedClip : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + /// The rect of the clip + clip: Wrapped(Rect), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///The calculated size of the node + bevy_ui::CalculatedSize : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + /// The size of the node + size: Raw(ReflectedValue), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Describes the size of a UI node + bevy_ui::Node : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + /// The size of the node as width and height in pixels + size: Wrapped(Vec2), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Describes the style of a UI node + /// + ///It uses the [Flexbox](https://cssreference.io/flexbox/) system. + /// + ///**Note:** Bevy's UI is upside down compared to how Flexbox normally works, to stay consistent with engine paradigms about layouting from + ///the upper left corner of the display + bevy_ui::Style : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + /// Whether to arrange this node and its children with flexbox layout + /// + /// If this is set to [`Display::None`], this node will be collapsed. + display: Wrapped(Display), + /// Whether to arrange this node relative to other nodes, or positioned absolutely + position_type: Wrapped(PositionType), + /// Which direction the content of this node should go + direction: Wrapped(Direction), + /// Whether to use column or row layout + flex_direction: Wrapped(FlexDirection), + /// How to wrap nodes + flex_wrap: Wrapped(FlexWrap), + /// How items are aligned according to the cross axis + align_items: Wrapped(AlignItems), + /// Like align_items but for only this item + align_self: Wrapped(AlignSelf), + /// How to align each line, only applies if flex_wrap is set to + /// [`FlexWrap::Wrap`] and there are multiple lines of items + align_content: Wrapped(AlignContent), + /// How items align according to the main axis + justify_content: Wrapped(JustifyContent), + /// The position of the node as described by its Rect + position: Raw(ReflectedValue), + /// The margin of the node + margin: Raw(ReflectedValue), + /// The padding of the node + padding: Raw(ReflectedValue), + /// The border of the node + border: Raw(ReflectedValue), + /// Defines how much a flexbox item should grow if there's space available + flex_grow: Raw(f32), + /// How to shrink if there's not enough space available + flex_shrink: Raw(f32), + /// The initial size of the item + flex_basis: Wrapped(Val), + /// The size of the flexbox + size: Raw(ReflectedValue), + /// The minimum size of the flexbox + min_size: Raw(ReflectedValue), + /// The maximum size of the flexbox + max_size: Raw(ReflectedValue), + /// The aspect ratio of the flexbox + aspect_ratio: Raw(ReflectedValue), + /// How to handle overflow + overflow: Wrapped(Overflow), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///The color of the node + bevy_ui::UiColor : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + 0: Wrapped(Color), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///The image of the node + bevy_ui::UiImage : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + 0: Raw(ReflectedValue), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Marker struct for buttons + bevy_ui::widget::Button : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Describes how to resize the Image node + bevy_ui::widget::ImageMode : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Whether to use a Flexbox layout model. + /// + ///Part of the [`Style`] component. + bevy_ui::Display : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Animation controls + bevy_animation::AnimationPlayer : + Methods + ( + ///Pause the animation + pause(&mut self:), + + ///Unpause the animation + resume(&mut self:), + + ///Is the animation paused + is_paused(&self:) -> Raw(bool), + + ///Speed of the animation playback + speed(&self:) -> Raw(f32), + + ///Time elapsed playing the animation + elapsed(&self:) -> Raw(f32), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Component used to identify an entity. Stores a hash for faster comparisons + ///The hash is eagerly re-computed upon each update to the name. + /// + ///[`Name`] should not be treated as a globally unique identifier for entities, + ///as multiple entities can have the same name. [`bevy_ecs::entity::Entity`] should be + ///used instead as the default unique identifier. + bevy_core::Name : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_gltf::GltfExtras : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + value: Raw(String), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Contains references to the child entities of this entity + bevy_hierarchy::Children : + Debug + + Methods + ( + ///Swaps the child at `a_index` with the child at `b_index` + swap(&mut self:Raw(usize),Raw(usize)), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Holds a reference to the parent entity of this entity. + ///This component should only be present on entities that actually have a parent entity. + bevy_hierarchy::Parent : + Debug + + Methods + ( + ///Gets the [`Entity`] ID of the parent. + get(&self:) -> Wrapped(Entity), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///The maximum width and height of text. The text will wrap according to the specified size. + ///Characters out of the bounds after wrapping will be truncated. Text is aligned according to the + ///specified `TextAlignment`. + /// + ///Note: only characters that are completely out of the bounds will be truncated, so this is not a + ///reliable limit if it is necessary to contain the text strictly in the bounds. Currently this + ///component is mainly useful for text wrapping only. + bevy_text::Text2dBounds : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + size: Wrapped(Vec2), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///The calculated size of text drawn in 2D scene. + bevy_text::Text2dSize : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + size: Wrapped(Vec2), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_text::Text : + Clone + + Debug + + Methods + ( + ///Returns this [`Text`] with a new [`TextAlignment`]. + with_alignment(self:Wrapped(TextAlignment)) -> self, + + ) + + Fields + ( + sections: Raw(ReflectedValue), + alignment: Wrapped(TextAlignment), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_text::TextAlignment : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + vertical: Wrapped(VerticalAlign), + horizontal: Wrapped(HorizontalAlign), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_text::TextSection : + Clone + + Debug + + Methods + ( + ///Create an empty [`TextSection`] from a style. Useful when the value will be set dynamically. + from_style(Wrapped(TextStyle)) -> self, + + ) + + Fields + ( + value: Raw(String), + style: Wrapped(TextStyle), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_text::TextStyle : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + font: Raw(ReflectedValue), + font_size: Raw(f32), + color: Wrapped(Color), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Describes horizontal alignment preference for positioning & bounds. + bevy_text::HorizontalAlign : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Describes vertical alignment preference for positioning & bounds. Currently a placeholder + ///for future functionality. + bevy_text::VerticalAlign : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A Stopwatch is a struct that track elapsed time when started. + /// + ///# Examples + /// + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut stopwatch = Stopwatch::new(); + ///assert_eq!(stopwatch.elapsed_secs(), 0.0); + /// + ///stopwatch.tick(Duration::from_secs_f32(1.0)); // tick one second + ///assert_eq!(stopwatch.elapsed_secs(), 1.0); + /// + ///stopwatch.pause(); + ///stopwatch.tick(Duration::from_secs_f32(1.0)); // paused stopwatches don't tick + ///assert_eq!(stopwatch.elapsed_secs(), 1.0); + /// + ///stopwatch.reset(); // reset the stopwatch + ///assert!(stopwatch.paused()); + ///assert_eq!(stopwatch.elapsed_secs(), 0.0); + ///``` + bevy_time::Stopwatch : + Clone + + Debug + + Methods + ( + ///Create a new unpaused `Stopwatch` with no elapsed time. + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///let stopwatch = Stopwatch::new(); + ///assert_eq!(stopwatch.elapsed_secs(), 0.0); + ///assert_eq!(stopwatch.paused(), false); + ///``` + new() -> self, + + ///Returns the elapsed time since the last [`reset`](Stopwatch::reset) + ///of the stopwatch, in seconds. + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut stopwatch = Stopwatch::new(); + ///stopwatch.tick(Duration::from_secs(1)); + ///assert_eq!(stopwatch.elapsed_secs(), 1.0); + ///``` + /// + ///# See Also + /// + ///[`elapsed`](Stopwatch::elapsed) - if a `Duration` is desirable instead. + elapsed_secs(&self:) -> Raw(f32), + + ///Pauses the stopwatch. Any call to [`tick`](Stopwatch::tick) while + ///paused will not have any effect on the elapsed time. + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut stopwatch = Stopwatch::new(); + ///stopwatch.pause(); + ///stopwatch.tick(Duration::from_secs_f32(1.5)); + ///assert!(stopwatch.paused()); + ///assert_eq!(stopwatch.elapsed_secs(), 0.0); + ///``` + pause(&mut self:), + + ///Unpauses the stopwatch. Resume the effect of ticking on elapsed time. + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut stopwatch = Stopwatch::new(); + ///stopwatch.pause(); + ///stopwatch.tick(Duration::from_secs_f32(1.0)); + ///stopwatch.unpause(); + ///stopwatch.tick(Duration::from_secs_f32(1.0)); + ///assert!(!stopwatch.paused()); + ///assert_eq!(stopwatch.elapsed_secs(), 1.0); + ///``` + unpause(&mut self:), + + ///Returns `true` if the stopwatch is paused. + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///let mut stopwatch = Stopwatch::new(); + ///assert!(!stopwatch.paused()); + ///stopwatch.pause(); + ///assert!(stopwatch.paused()); + ///stopwatch.unpause(); + ///assert!(!stopwatch.paused()); + ///``` + paused(&self:) -> Raw(bool), + + ///Resets the stopwatch. + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut stopwatch = Stopwatch::new(); + ///stopwatch.tick(Duration::from_secs_f32(1.5)); + ///stopwatch.reset(); + ///assert_eq!(stopwatch.elapsed_secs(), 0.0); + ///``` + reset(&mut self:), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Tracks elapsed time. Enters the finished state once `duration` is reached. + /// + ///Non repeating timers will stop tracking and stay in the finished state until reset. + ///Repeating timers will only be in the finished state on each tick `duration` is reached or + ///exceeded, and can still be reset at any given point. + /// + ///Paused timers will not have elapsed time increased. + bevy_time::Timer : + Clone + + Debug + + Methods + ( + ///Creates a new timer with a given duration in seconds. + /// + ///# Example + ///``` + ///# use bevy_time::*; + ///let mut timer = Timer::from_seconds(1.0, false); + ///``` + from_seconds(Raw(f32),Raw(bool)) -> self, + + ///Returns `true` if the timer has reached its duration. + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut timer = Timer::from_seconds(1.0, false); + ///timer.tick(Duration::from_secs_f32(1.5)); + ///assert!(timer.finished()); + ///timer.tick(Duration::from_secs_f32(0.5)); + ///assert!(timer.finished()); + ///``` + finished(&self:) -> Raw(bool), + + ///Returns `true` only on the tick the timer reached its duration. + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut timer = Timer::from_seconds(1.0, false); + ///timer.tick(Duration::from_secs_f32(1.5)); + ///assert!(timer.just_finished()); + ///timer.tick(Duration::from_secs_f32(0.5)); + ///assert!(!timer.just_finished()); + ///``` + just_finished(&self:) -> Raw(bool), + + ///Returns the time elapsed on the timer as a `f32`. + ///See also [`Timer::elapsed`](Timer::elapsed). + elapsed_secs(&self:) -> Raw(f32), + + ///Returns `true` if the timer is repeating. + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///let mut timer = Timer::from_seconds(1.0, true); + ///assert!(timer.repeating()); + ///``` + repeating(&self:) -> Raw(bool), + + ///Sets whether the timer is repeating or not. + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///let mut timer = Timer::from_seconds(1.0, true); + ///timer.set_repeating(false); + ///assert!(!timer.repeating()); + ///``` + set_repeating(&mut self:Raw(bool)), + + ///Pauses the Timer. Disables the ticking of the timer. + /// + ///See also [`Stopwatch::pause`](Stopwatch::pause). + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut timer = Timer::from_seconds(1.0, false); + ///timer.pause(); + ///timer.tick(Duration::from_secs_f32(0.5)); + ///assert_eq!(timer.elapsed_secs(), 0.0); + ///``` + pause(&mut self:), + + ///Unpauses the Timer. Resumes the ticking of the timer. + /// + ///See also [`Stopwatch::unpause()`](Stopwatch::unpause). + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut timer = Timer::from_seconds(1.0, false); + ///timer.pause(); + ///timer.tick(Duration::from_secs_f32(0.5)); + ///timer.unpause(); + ///timer.tick(Duration::from_secs_f32(0.5)); + ///assert_eq!(timer.elapsed_secs(), 0.5); + ///``` + unpause(&mut self:), + + ///Returns `true` if the timer is paused. + /// + ///See also [`Stopwatch::paused`](Stopwatch::paused). + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///let mut timer = Timer::from_seconds(1.0, false); + ///assert!(!timer.paused()); + ///timer.pause(); + ///assert!(timer.paused()); + ///timer.unpause(); + ///assert!(!timer.paused()); + ///``` + paused(&self:) -> Raw(bool), + + ///Resets the timer. the reset doesn't affect the `paused` state of the timer. + /// + ///See also [`Stopwatch::reset`](Stopwatch::reset). + /// + ///Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut timer = Timer::from_seconds(1.0, false); + ///timer.tick(Duration::from_secs_f32(1.5)); + ///timer.reset(); + ///assert!(!timer.finished()); + ///assert!(!timer.just_finished()); + ///assert_eq!(timer.elapsed_secs(), 0.0); + ///``` + reset(&mut self:), + + ///Returns the percentage of the timer elapsed time (goes from 0.0 to 1.0). + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut timer = Timer::from_seconds(2.0, false); + ///timer.tick(Duration::from_secs_f32(0.5)); + ///assert_eq!(timer.percent(), 0.25); + ///``` + percent(&self:) -> Raw(f32), + + ///Returns the percentage of the timer remaining time (goes from 0.0 to 1.0). + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut timer = Timer::from_seconds(2.0, false); + ///timer.tick(Duration::from_secs_f32(0.5)); + ///assert_eq!(timer.percent_left(), 0.75); + ///``` + percent_left(&self:) -> Raw(f32), + + ///Returns the number of times a repeating timer + ///finished during the last [`tick`](Timer::tick) call. + /// + ///For non repeating-timers, this method will only ever + ///return 0 or 1. + /// + ///# Examples + ///``` + ///# use bevy_time::*; + ///use std::time::Duration; + ///let mut timer = Timer::from_seconds(1.0, true); + ///timer.tick(Duration::from_secs_f32(6.0)); + ///assert_eq!(timer.times_finished_this_tick(), 6); + ///timer.tick(Duration::from_secs_f32(2.0)); + ///assert_eq!(timer.times_finished_this_tick(), 2); + ///timer.tick(Duration::from_secs_f32(0.5)); + ///assert_eq!(timer.times_finished_this_tick(), 0); + ///``` + times_finished_this_tick(&self:) -> Raw(u32), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Lightweight identifier of an [entity](crate::entity). + /// + ///The identifier is implemented using a [generational index]: a combination of an ID and a generation. + ///This allows fast insertion after data removal in an array while minimizing loss of spatial locality. + /// + ///[generational index]: https://lucassardois.medium.com/generational-indices-guide-8e3c5f7fd594 + /// + ///# Usage + /// + ///This data type is returned by iterating a `Query` that has `Entity` as part of its query fetch type parameter ([learn more]). + ///It can also be obtained by calling [`EntityCommands::id`] or [`EntityMut::id`]. + /// + ///``` + ///# use bevy_ecs::prelude::*; + ///# + ///fn setup(mut commands: Commands) { + /// // Calling `spawn` returns `EntityCommands`. + /// let entity = commands.spawn().id(); + ///} + /// + ///fn exclusive_system(world: &mut World) { + /// // Calling `spawn` returns `EntityMut`. + /// let entity = world.spawn().id(); + ///} + ///# + ///# bevy_ecs::system::assert_is_system(setup); + ///# bevy_ecs::system::IntoExclusiveSystem::exclusive_system(exclusive_system); + ///``` + /// + ///It can be used to refer to a specific entity to apply [`EntityCommands`], or to call [`Query::get`] (or similar methods) to access its components. + /// + ///``` + ///# use bevy_ecs::prelude::*; + ///# + ///# #[derive(Component)] + ///# struct Expired; + ///# + ///fn dispose_expired_food(mut commands: Commands, query: Query>) { + /// for food_entity in &query { + /// commands.entity(food_entity).despawn(); + /// } + ///} + ///# + ///# bevy_ecs::system::assert_is_system(dispose_expired_food); + ///``` + /// + ///[learn more]: crate::system::Query#entity-id-access + ///[`EntityCommands::id`]: crate::system::EntityCommands::id + ///[`EntityMut::id`]: crate::world::EntityMut::id + ///[`EntityCommands`]: crate::system::EntityCommands + ///[`Query::get`]: crate::system::Query::get + bevy_ecs::entity::Entity : + Clone + + Debug + + Methods + ( + ///Creates a new entity reference with the specified `id` and a generation of 0. + /// + ///# Note + /// + ///Spawning a specific `entity` value is __rarely the right choice__. Most apps should favor + ///[`Commands::spawn`](crate::system::Commands::spawn). This method should generally + ///only be used for sharing entities across apps, and only when they have a scheme + ///worked out to share an ID space (which doesn't happen by default). + /// + ///In general, one should not try to synchronize the ECS by attempting to ensure that + ///`Entity` lines up between instances, but instead insert a secondary identifier as + ///a component. + /// + ///There are still some use cases where it might be appropriate to use this function + ///externally. + /// + ///## Examples + /// + ///Initializing a collection (e.g. `array` or `Vec`) with a known size: + /// + ///```no_run + ///# use bevy_ecs::prelude::*; + ///// Create a new array of size 10 and initialize it with (invalid) entities. + ///let mut entities: [Entity; 10] = [Entity::from_raw(0); 10]; + /// + ///// ... replace the entities with valid ones. + ///``` + /// + ///Deriving `Reflect` for a component that has an `Entity` field: + /// + ///```no_run + ///# use bevy_ecs::{prelude::*, component::*}; + ///# use bevy_reflect::Reflect; + ///#[derive(Reflect, Component)] + ///#[reflect(Component)] + ///pub struct MyStruct { + /// pub entity: Entity, + ///} + /// + ///impl FromWorld for MyStruct { + /// fn from_world(_world: &mut World) -> Self { + /// Self { + /// entity: Entity::from_raw(u32::MAX), + /// } + /// } + ///} + ///``` + from_raw(Raw(u32)) -> Wrapped(Entity), + + ///Convert to a form convenient for passing outside of rust. + /// + ///Only useful for identifying entities within the same instance of an application. Do not use + ///for serialization between runs. + /// + ///No particular structure is guaranteed for the returned bits. + to_bits(self:) -> Raw(u64), + + ///Reconstruct an `Entity` previously destructured with [`Entity::to_bits`]. + /// + ///Only useful when applied to results from `to_bits` in the same instance of an application. + from_bits(Raw(u64)) -> self, + + ///Return a transiently unique identifier. + /// + ///No two simultaneously-live entities share the same ID, but dead entities' IDs may collide + ///with both live and dead entities. Useful for compactly representing entities within a + ///specific snapshot of the world, such as when serializing. + id(self:) -> Raw(u32), + + ///Returns the generation of this Entity's id. The generation is incremented each time an + ///entity with a given id is despawned. This serves as a "count" of the number of times a + ///given id has been reused (id, generation) pairs uniquely identify a given Entity. + generation(self:) -> Raw(u32), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Describe the position of an entity. If the entity has a parent, the position is relative + ///to its parent position. + /// + ///* To place or move an entity, you should set its [`Transform`]. + ///* To get the global transform of an entity, you should get its [`GlobalTransform`]. + ///* To be displayed, an entity must have both a [`Transform`] and a [`GlobalTransform`]. + /// * You may use the [`TransformBundle`](crate::TransformBundle) to guarantee this. + /// + ///## [`Transform`] and [`GlobalTransform`] + /// + ///[`Transform`] is the position of an entity relative to its parent position, or the reference + ///frame if it doesn't have a [`Parent`](bevy_hierarchy::Parent). + /// + ///[`GlobalTransform`] is the position of an entity relative to the reference frame. + /// + ///[`GlobalTransform`] is updated from [`Transform`] in the system + ///[`transform_propagate_system`](crate::transform_propagate_system). + /// + ///This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you + ///update the [`Transform`] of an entity in this stage or after, you will notice a 1 frame lag + ///before the [`GlobalTransform`] is updated. + bevy_transform::components::Transform : + Clone + + Debug + + Methods + ( + ///Creates a new [`Transform`] at the position `(x, y, z)`. In 2d, the `z` component + ///is used for z-ordering elements: higher `z`-value will be in front of lower + ///`z`-value. + from_xyz(Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a new identity [`Transform`], with no translation, rotation, and a scale of 1 on + ///all axes. + identity() -> self, + + ///Extracts the translation, rotation, and scale from `matrix`. It must be a 3d affine + ///transformation matrix. + from_matrix(Wrapped(Mat4)) -> self, + + ///Creates a new [`Transform`], with `translation`. Rotation will be 0 and scale 1 on + ///all axes. + from_translation(Wrapped(Vec3)) -> self, + + ///Creates a new [`Transform`], with `rotation`. Translation will be 0 and scale 1 on + ///all axes. + from_rotation(Wrapped(Quat)) -> self, + + ///Creates a new [`Transform`], with `scale`. Translation will be 0 and rotation 0 on + ///all axes. + from_scale(Wrapped(Vec3)) -> self, + + ///Updates and returns this [`Transform`] by rotating it so that its unit vector in the + ///local `Z` direction is toward `target` and its unit vector in the local `Y` direction + ///is toward `up`. + looking_at(self:Wrapped(Vec3),Wrapped(Vec3)) -> self, + + ///Returns this [`Transform`] with a new translation. + with_translation(self:Wrapped(Vec3)) -> self, + + ///Returns this [`Transform`] with a new rotation. + with_rotation(self:Wrapped(Quat)) -> self, + + ///Returns this [`Transform`] with a new scale. + with_scale(self:Wrapped(Vec3)) -> self, + + ///Returns the 3d affine transformation matrix from this transforms translation, + ///rotation, and scale. + compute_matrix(&self:) -> Wrapped(Mat4), + + ///Returns the 3d affine transformation matrix from this transforms translation, + ///rotation, and scale. + compute_affine(&self:) -> Wrapped(Affine3A), + + ///Get the unit vector in the local `X` direction. + local_x(&self:) -> Wrapped(Vec3), + + ///Equivalent to [`-local_x()`][Transform::local_x()] + left(&self:) -> Wrapped(Vec3), + + ///Equivalent to [`local_x()`][Transform::local_x()] + right(&self:) -> Wrapped(Vec3), + + ///Get the unit vector in the local `Y` direction. + local_y(&self:) -> Wrapped(Vec3), + + ///Equivalent to [`local_y()`][Transform::local_y] + up(&self:) -> Wrapped(Vec3), + + ///Equivalent to [`-local_y()`][Transform::local_y] + down(&self:) -> Wrapped(Vec3), + + ///Get the unit vector in the local `Z` direction. + local_z(&self:) -> Wrapped(Vec3), + + ///Equivalent to [`-local_z()`][Transform::local_z] + forward(&self:) -> Wrapped(Vec3), + + ///Equivalent to [`local_z()`][Transform::local_z] + back(&self:) -> Wrapped(Vec3), + + ///Rotates this [`Transform`] by the given rotation. + /// + ///If this [`Transform`] has a parent, the `rotation` is relative to the rotation of the parent. + rotate(&mut self:Wrapped(Quat)), + + ///Rotates this [`Transform`] around the given `axis` by `angle` (in radians). + /// + ///If this [`Transform`] has a parent, the `axis` is relative to the rotation of the parent. + rotate_axis(&mut self:Wrapped(Vec3),Raw(f32)), + + ///Rotates this [`Transform`] around the `X` axis by `angle` (in radians). + /// + ///If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + rotate_x(&mut self:Raw(f32)), + + ///Rotates this [`Transform`] around the `Y` axis by `angle` (in radians). + /// + ///If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + rotate_y(&mut self:Raw(f32)), + + ///Rotates this [`Transform`] around the `Z` axis by `angle` (in radians). + /// + ///If this [`Transform`] has a parent, the axis is relative to the rotation of the parent. + rotate_z(&mut self:Raw(f32)), + + ///Rotates this [`Transform`] by the given `rotation`. + /// + ///The `rotation` is relative to this [`Transform`]'s current rotation. + rotate_local(&mut self:Wrapped(Quat)), + + ///Rotates this [`Transform`] around its local `axis` by `angle` (in radians). + rotate_local_axis(&mut self:Wrapped(Vec3),Raw(f32)), + + ///Rotates this [`Transform`] around its local `X` axis by `angle` (in radians). + rotate_local_x(&mut self:Raw(f32)), + + ///Rotates this [`Transform`] around its local `Y` axis by `angle` (in radians). + rotate_local_y(&mut self:Raw(f32)), + + ///Rotates this [`Transform`] around its local `Z` axis by `angle` (in radians). + rotate_local_z(&mut self:Raw(f32)), + + ///Translates this [`Transform`] around a `point` in space. + /// + ///If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. + translate_around(&mut self:Wrapped(Vec3),Wrapped(Quat)), + + ///Rotates this [`Transform`] around a `point` in space. + /// + ///If this [`Transform`] has a parent, the `point` is relative to the [`Transform`] of the parent. + rotate_around(&mut self:Wrapped(Vec3),Wrapped(Quat)), + + ///Rotates this [`Transform`] so that its local negative `Z` direction is toward + ///`target` and its local `Y` direction is toward `up`. + look_at(&mut self:Wrapped(Vec3),Wrapped(Vec3)), + + ///Multiplies `self` with `transform` component by component, returning the + ///resulting [`Transform`] + mul_transform(&self:Wrapped(Transform)) -> self, + + ///Returns a [`Vec3`] of this [`Transform`] applied to `value`. + mul_vec3(&self:Wrapped(Vec3)) -> Wrapped(Vec3), + + ///Changes the `scale` of this [`Transform`], multiplying the current `scale` by + ///`scale_factor`. + apply_non_uniform_scale(&mut self:Wrapped(Vec3)), + + ) + + Fields + ( + /// Position of the entity. In 2d, the last value of the `Vec3` is used for z-ordering. + translation: Wrapped(Vec3), + /// Rotation of the entity. + rotation: Wrapped(Quat), + /// Scale of the entity. + scale: Wrapped(Vec3), + ) + + BinOps + ( + self Mul Wrapped(Transform) -> Wrapped(Transform), + self Mul Wrapped(Vec3) -> Wrapped(Vec3), + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Describe the position of an entity relative to the reference frame. + /// + ///* To place or move an entity, you should set its [`Transform`]. + ///* To get the global transform of an entity, you should get its [`GlobalTransform`]. + ///* For transform hierarchies to work correctly, you must have both a [`Transform`] and a [`GlobalTransform`]. + /// * You may use the [`TransformBundle`](crate::TransformBundle) to guarantee this. + /// + ///## [`Transform`] and [`GlobalTransform`] + /// + ///[`Transform`] is the position of an entity relative to its parent position, or the reference + ///frame if it doesn't have a [`Parent`](bevy_hierarchy::Parent). + /// + ///[`GlobalTransform`] is the position of an entity relative to the reference frame. + /// + ///[`GlobalTransform`] is updated from [`Transform`] in the system + ///[`transform_propagate_system`](crate::transform_propagate_system). + /// + ///This system runs in stage [`CoreStage::PostUpdate`](crate::CoreStage::PostUpdate). If you + ///update the [`Transform`] of an entity in this stage or after, you will notice a 1 frame lag + ///before the [`GlobalTransform`] is updated. + bevy_transform::components::GlobalTransform : + Clone + + Debug + + Methods + ( + ///Returns the 3d affine transformation matrix as a [`Mat4`]. + compute_matrix(&self:) -> Wrapped(Mat4), + + ///Returns the 3d affine transformation matrix as an [`Affine3A`]. + affine(&self:) -> Wrapped(Affine3A), + + ///Returns the transformation as a [`Transform`]. + /// + ///The transform is expected to be non-degenerate and without shearing, or the output + ///will be invalid. + compute_transform(&self:) -> Wrapped(Transform), + + ///Creates a new identity [`GlobalTransform`], that maps all points in space to themselves. + identity() -> self, + + ///Return the local right vector (X). + right(&self:) -> Wrapped(Vec3), + + ///Return the local left vector (-X). + left(&self:) -> Wrapped(Vec3), + + ///Return the local up vector (Y). + up(&self:) -> Wrapped(Vec3), + + ///Return the local down vector (-Y). + down(&self:) -> Wrapped(Vec3), + + ///Return the local back vector (Z). + back(&self:) -> Wrapped(Vec3), + + ///Return the local forward vector (-Z). + forward(&self:) -> Wrapped(Vec3), + + ///Get the translation as a [`Vec3`]. + translation(&self:) -> Wrapped(Vec3), + + ///Get the translation as a [`Vec3A`]. + translation_vec3a(&self:) -> Wrapped(Vec3A), + + ///Get an upper bound of the radius from the given `extents`. + radius_vec3a(&self:Wrapped(Vec3A)) -> Raw(f32), + + ///Returns a [`Vec3`] of this [`Transform`] applied to `value`. + mul_vec3(&self:Wrapped(Vec3)) -> Wrapped(Vec3), + + ///Multiplies `self` with `transform` component by component, returning the + ///resulting [`GlobalTransform`] + mul_transform(&self:Wrapped(Transform)) -> self, + + ) + + Fields + ( + ) + + BinOps + ( + self Mul Wrapped(GlobalTransform) -> Wrapped(GlobalTransform), + self Mul Wrapped(Transform) -> Wrapped(GlobalTransform), + self Mul Wrapped(Vec3) -> Wrapped(Vec3), + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///An ambient light, which lights the entire scene equally. + bevy_pbr::AmbientLight : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + color: Wrapped(Color), + /// A direct scale factor multiplied with `color` before being passed to the shader. + brightness: Raw(f32), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_pbr::CubemapVisibleEntities : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A Directional light. + /// + ///Directional lights don't exist in reality but they are a good + ///approximation for light sources VERY far away, like the sun or + ///the moon. + /// + ///Valid values for `illuminance` are: + /// + ///| Illuminance (lux) | Surfaces illuminated by | + ///|-------------------|------------------------------------------------| + ///| 0.0001 | Moonless, overcast night sky (starlight) | + ///| 0.002 | Moonless clear night sky with airglow | + ///| 0.05–0.3 | Full moon on a clear night | + ///| 3.4 | Dark limit of civil twilight under a clear sky | + ///| 20–50 | Public areas with dark surroundings | + ///| 50 | Family living room lights | + ///| 80 | Office building hallway/toilet lighting | + ///| 100 | Very dark overcast day | + ///| 150 | Train station platforms | + ///| 320–500 | Office lighting | + ///| 400 | Sunrise or sunset on a clear day. | + ///| 1000 | Overcast day; typical TV studio lighting | + ///| 10,000–25,000 | Full daylight (not direct sun) | + ///| 32,000–100,000 | Direct sunlight | + /// + ///Source: [Wikipedia](https://en.wikipedia.org/wiki/Lux) + bevy_pbr::DirectionalLight : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + color: Wrapped(Color), + /// Illuminance in lux + illuminance: Raw(f32), + shadows_enabled: Raw(bool), + shadow_projection: Wrapped(OrthographicProjection), + shadow_depth_bias: Raw(f32), + /// A bias applied along the direction of the fragment's surface normal. It is scaled to the + /// shadow map's texel size so that it is automatically adjusted to the orthographic projection. + shadow_normal_bias: Raw(f32), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_pbr::DirectionalLightShadowMap : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + size: Raw(usize), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not cast shadows. + bevy_pbr::NotShadowCaster : + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Add this component to make a [`Mesh`](bevy_render::mesh::Mesh) not receive shadows. + bevy_pbr::NotShadowReceiver : + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A light that emits light in all directions from a central point. + /// + ///Real-world values for `intensity` (luminous power in lumens) based on the electrical power + ///consumption of the type of real-world light are: + /// + ///| Luminous Power (lumen) (i.e. the intensity member) | Incandescent non-halogen (Watts) | Incandescent halogen (Watts) | Compact fluorescent (Watts) | LED (Watts | + ///|------|-----|----|--------|-------| + ///| 200 | 25 | | 3-5 | 3 | + ///| 450 | 40 | 29 | 9-11 | 5-8 | + ///| 800 | 60 | | 13-15 | 8-12 | + ///| 1100 | 75 | 53 | 18-20 | 10-16 | + ///| 1600 | 100 | 72 | 24-28 | 14-17 | + ///| 2400 | 150 | | 30-52 | 24-30 | + ///| 3100 | 200 | | 49-75 | 32 | + ///| 4000 | 300 | | 75-100 | 40.5 | + /// + ///Source: [Wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit)#Lighting) + bevy_pbr::PointLight : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + color: Wrapped(Color), + intensity: Raw(f32), + range: Raw(f32), + radius: Raw(f32), + shadows_enabled: Raw(bool), + shadow_depth_bias: Raw(f32), + /// A bias applied along the direction of the fragment's surface normal. It is scaled to the + /// shadow map's texel size so that it can be small close to the camera and gets larger further + /// away. + shadow_normal_bias: Raw(f32), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_pbr::PointLightShadowMap : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + size: Raw(usize), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Alpha mode + bevy_pbr::AlphaMode : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Controls whether an entity should rendered in wireframe-mode if the [`WireframePlugin`] is enabled + bevy_pbr::wireframe::Wireframe : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_pbr::wireframe::WireframeConfig : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + /// Whether to show wireframes for all meshes. If `false`, only meshes with a [Wireframe] component will be rendered. + global: Raw(bool), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///The depth clear operation to perform for the main 3d pass. + bevy_core_pipeline::core_3d::Camera3dDepthLoadOp : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///When used as a resource, sets the color that is used to clear the screen between frames. + /// + ///This color appears as the "background" color for simple apps, when + ///there are portions of the screen with nothing rendered. + bevy_core_pipeline::clear_color::ClearColor : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + 0: Wrapped(Color), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_core_pipeline::clear_color::ClearColorConfig : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_core_pipeline::core_2d::Camera2d : + Clone + + Methods + ( + ) + + Fields + ( + clear_color: Wrapped(ClearColorConfig), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Configuration for the "main 3d render graph". + bevy_core_pipeline::core_3d::Camera3d : + Clone + + Methods + ( + ) + + Fields + ( + /// The clear color operation to perform for the main 3d pass. + clear_color: Wrapped(ClearColorConfig), + /// The depth clear operation to perform for the main 3d pass. + depth_load_op: Wrapped(Camera3dDepthLoadOp), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///How a sprite is positioned relative to its [`Transform`](bevy_transform::components::Transform). + ///It defaults to `Anchor::Center`. + bevy_sprite::Anchor : + Clone + + Debug + + Methods + ( + as_vec(&self:) -> Wrapped(Vec2), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Component for rendering with meshes in the 2d pipeline, usually with a [2d material](crate::Material2d) such as [`ColorMaterial`](crate::ColorMaterial). + /// + ///It wraps a [`Handle`] to differentiate from the 3d pipelines which use the handles directly as components + bevy_sprite::Mesh2dHandle : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + 0: Raw(ReflectedValue), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_sprite::TextureAtlasSprite : + Clone + + Debug + + Methods + ( + new(Raw(usize)) -> Wrapped(TextureAtlasSprite), + + ) + + Fields + ( + color: Wrapped(Color), + index: Raw(usize), + flip_x: Raw(bool), + flip_y: Raw(bool), + /// An optional custom size for the sprite that will be used when rendering, instead of the size + /// of the sprite's image in the atlas + custom_size: Raw(ReflectedValue), + anchor: Wrapped(Anchor), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_sprite::Sprite : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + /// The sprite's color tint + color: Wrapped(Color), + /// Flip the sprite along the `X` axis + flip_x: Raw(bool), + /// Flip the sprite along the `Y` axis + flip_y: Raw(bool), + /// An optional custom size for the sprite that will be used when rendering, instead of the size + /// of the sprite's image + custom_size: Raw(ReflectedValue), + /// [`Anchor`] point of the sprite in the world + anchor: Wrapped(Anchor), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A rectangle defined by two points. There is no defined origin, so 0,0 could be anywhere + ///(top-left, bottom-left, etc) + bevy_sprite::Rect : + Clone + + Debug + + Methods + ( + width(&self:) -> Raw(f32), + + height(&self:) -> Raw(f32), + + size(&self:) -> Wrapped(Vec2), + + ) + + Fields + ( + /// The beginning point of the rect + min: Wrapped(Vec2), + /// The ending point of the rect + max: Wrapped(Vec2), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Describes which rendering layers an entity belongs to. + /// + ///Cameras with this component will only render entities with intersecting + ///layers. + /// + ///There are 32 layers numbered `0` - [`TOTAL_LAYERS`](RenderLayers::TOTAL_LAYERS). Entities may + ///belong to one or more layers, or no layer at all. + /// + ///The [`Default`] instance of `RenderLayers` contains layer `0`, the first layer. + /// + ///An entity with this component without any layers is invisible. + /// + ///Entities without this component belong to layer `0`. + bevy_render::view::visibility::RenderLayers : + Clone + + Debug + + Methods + ( + ///Create a new `RenderLayers` that belongs to all layers. + all() -> self, + + ///Create a new `RenderLayers` that belongs to no layers. + none() -> self, + + ///Determine if a `RenderLayers` intersects another. + /// + ///`RenderLayers`s intersect if they share any common layers. + /// + ///A `RenderLayers` with no layers will not match any other + ///`RenderLayers`, even another with no layers. + intersects(&self:Wrapped(&RenderLayers)) -> Raw(bool), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///User indication of whether an entity is visible. Propagates down the entity hierarchy. + ///If an entity is hidden in this way, all [`Children`] (and all of their children and so on) will also be hidden. + ///This is done by setting the values of their [`ComputedVisibility`] component. + bevy_render::view::visibility::Visibility : + Clone + + Debug + + Methods + ( + ///Creates a new [`Visibility`], set as visible + visible() -> self, + + ) + + Fields + ( + /// Indicates whether this entity is visible. Hidden values will propagate down the entity hierarchy. + /// If this entity is hidden, all of its descendants will be hidden as well. See [`Children`] and [`Parent`] for + /// hierarchy info. + is_visible: Raw(bool), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Collection of entities visible from the current view. + /// + ///This component contains all entities which are visible from the currently + ///rendered view. The collection is updated automatically by the [`check_visibility()`] + ///system, and renderers can use it to optimize rendering of a particular view, to + ///prevent drawing items not visible from that view. + /// + ///This component is intended to be attached to the same entity as the [`Camera`] and + ///the [`Frustum`] defining the view. + /// + ///Currently this component is ignored by the sprite renderer, so sprite rendering + ///is not optimized per view. + bevy_render::view::visibility::VisibleEntities : + Clone + + Debug + + Methods + ( + len(&self:) -> Raw(usize), + + is_empty(&self:) -> Raw(bool), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Algorithmically-computed indication of whether an entity is visible and should be extracted for rendering + bevy_render::view::visibility::ComputedVisibility : + Clone + + Debug + + Methods + ( + ///Creates a new [`ComputedVisibility`], set as not visible + not_visible() -> self, + + ///Whether this entity is visible to something this frame. This is true if and only if [`Self::is_visible_in_hierarchy`] and [`Self::is_visible_in_view`] + ///are true. This is the canonical method to call to determine if an entity should be drawn. + ///This value is updated in [`CoreStage::PostUpdate`] during the [`VisibilitySystems::CheckVisibility`] system label. Reading it from the + ///[`CoreStage::Update`] stage will yield the value from the previous frame. + is_visible(&self:) -> Raw(bool), + + ///Whether this entity is visible in the entity hierarchy, which is determined by the [`Visibility`] component. + ///This takes into account "visibility inheritance". If any of this entity's ancestors (see [`Parent`]) are hidden, this entity + ///will be hidden as well. This value is updated in the [`CoreStage::PostUpdate`] stage in the + ///[`VisibilitySystems::VisibilityPropagate`] system label. + is_visible_in_hierarchy(&self:) -> Raw(bool), + + ///Whether this entity is visible in _any_ view (Cameras, Lights, etc). Each entity type (and view type) should choose how to set this + ///value. For cameras and drawn entities, this will take into account [`RenderLayers`]. + /// + ///This value is reset to `false` every frame in [`VisibilitySystems::VisibilityPropagate`] during [`CoreStage::PostUpdate`]. + ///Each entity type then chooses how to set this field in the [`CoreStage::PostUpdate`] stage in the + ///[`VisibilitySystems::CheckVisibility`] system label. Meshes might use frustum culling to decide if they are visible in a view. + ///Other entities might just set this to `true` every frame. + is_visible_in_view(&self:) -> Raw(bool), + + ///Sets `is_visible_in_view` to `true`. This is not reversible for a given frame, as it encodes whether or not this is visible in + ///_any_ view. This will be automatically reset to `false` every frame in [`VisibilitySystems::VisibilityPropagate`] and then set + ///to the proper value in [`VisibilitySystems::CheckVisibility`]. This should _only_ be set in systems with the [`VisibilitySystems::CheckVisibility`] + ///label. Don't call this unless you are defining a custom visibility system. For normal user-defined entity visibility, see [`Visibility`]. + set_visible_in_view(&mut self:), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_render::mesh::skinning::SkinnedMesh : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + inverse_bindposes: Raw(ReflectedValue), + joints: Raw(ReflectedValue), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_render::camera::ScalingMode : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_render::camera::WindowOrigin : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_render::color::Color : + Clone + + Debug + + Methods + ( + ///New `Color` from sRGB colorspace. + rgb(Raw(f32),Raw(f32),Raw(f32)) -> Wrapped(Color), + + ///New `Color` from sRGB colorspace. + rgba(Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> Wrapped(Color), + + ///New `Color` from linear RGB colorspace. + rgb_linear(Raw(f32),Raw(f32),Raw(f32)) -> Wrapped(Color), + + ///New `Color` from linear RGB colorspace. + rgba_linear(Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> Wrapped(Color), + + ///New `Color` with HSL representation in sRGB colorspace. + hsl(Raw(f32),Raw(f32),Raw(f32)) -> Wrapped(Color), + + ///New `Color` with HSL representation in sRGB colorspace. + hsla(Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> Wrapped(Color), + + ///New `Color` from sRGB colorspace. + rgb_u8(Raw(u8),Raw(u8),Raw(u8)) -> Wrapped(Color), + + ///New `Color` from sRGB colorspace. + rgba_u8(Raw(u8),Raw(u8),Raw(u8),Raw(u8)) -> Wrapped(Color), + + ///Get red in sRGB colorspace. + r(&self:) -> Raw(f32), + + ///Get green in sRGB colorspace. + g(&self:) -> Raw(f32), + + ///Get blue in sRGB colorspace. + b(&self:) -> Raw(f32), + + ///Get alpha. + a(&self:) -> Raw(f32), + + ///Converts a `Color` to variant `Color::Rgba` + as_rgba(Wrapped(&Color):) -> Wrapped(Color), + + ///Converts a `Color` to variant `Color::RgbaLinear` + as_rgba_linear(Wrapped(&Color):) -> Wrapped(Color), + + ///Converts a `Color` to variant `Color::Hsla` + as_hsla(Wrapped(&Color):) -> Wrapped(Color), + + ///Converts `Color` to a `u32` from sRGB colorspace. + /// + ///Maps the RGBA channels in RGBA order to a little-endian byte array (GPUs are little-endian). + ///`A` will be the most significant byte and `R` the least significant. + as_rgba_u32(Wrapped(Color):) -> Raw(u32), + + ///Converts Color to a u32 from linear RGB colorspace. + /// + ///Maps the RGBA channels in RGBA order to a little-endian byte array (GPUs are little-endian). + ///`A` will be the most significant byte and `R` the least significant. + as_linear_rgba_u32(Wrapped(Color):) -> Raw(u32), + + ) + + Fields + ( + ) + + BinOps + ( + self Add Wrapped(Color) -> Wrapped(Color), + self Add Wrapped(Vec4) -> Wrapped(Color), + self Mul Raw(f32) -> Wrapped(Color), + self Mul Wrapped(Vec4) -> Wrapped(Color), + self Mul Wrapped(Vec3) -> Wrapped(Color), + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///An Axis-Aligned Bounding Box + bevy_render::primitives::Aabb : + Clone + + Debug + + Methods + ( + from_min_max(Wrapped(Vec3),Wrapped(Vec3)) -> self, + + min(&self:) -> Wrapped(Vec3A), + + max(&self:) -> Wrapped(Vec3A), + + ) + + Fields + ( + center: Wrapped(Vec3A), + half_extents: Wrapped(Vec3A), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_render::primitives::CubemapFrusta : + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A frustum defined by the 6 containing planes + ///Planes are ordered left, right, top, bottom, near, far + ///Normals point into the contained volume + bevy_render::primitives::Frustum : + Clone + + Debug + + Methods + ( + from_view_projection(Wrapped(&Mat4),Wrapped(&Vec3),Wrapped(&Vec3),Raw(f32)) -> self, + + intersects_obb(&self:Wrapped(&Aabb),Wrapped(&Mat4),Raw(bool)) -> Raw(bool), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Configuration resource for [Multi-Sample Anti-Aliasing](https://en.wikipedia.org/wiki/Multisample_anti-aliasing). + /// + ///# Example + ///``` + ///# use bevy_app::prelude::App; + ///# use bevy_render::prelude::Msaa; + ///App::new() + /// .insert_resource(Msaa { samples: 4 }) + /// .run(); + ///``` + bevy_render::view::Msaa : + Clone + + Methods + ( + ) + + Fields + ( + /// The number of samples to run for Multi-Sample Anti-Aliasing. Higher numbers result in + /// smoother edges. + /// Defaults to 4. + /// + /// Note that WGPU currently only supports 1 or 4 samples. + /// Ultimately we plan on supporting whatever is natively supported on a given device. + /// Check out this issue for more info: + samples: Raw(u32), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_render::camera::Camera : + Clone + + Debug + + Methods + ( + ///The projection matrix computed using this camera's [`CameraProjection`]. + projection_matrix(&self:) -> Wrapped(Mat4), + + ) + + Fields + ( + /// If set, this camera will render to the given [`Viewport`] rectangle within the configured [`RenderTarget`]. + viewport: Raw(ReflectedValue), + /// Cameras with a lower priority will be rendered before cameras with a higher priority. + priority: Raw(isize), + /// If this is set to true, this camera will be rendered to its specified [`RenderTarget`]. If false, this + /// camera will not be rendered. + is_active: Raw(bool), + /// The method used to calculate this camera's depth. This will be used for projections and visibility. + depth_calculation: Wrapped(DepthCalculation), + /// The "target" that this camera will render to. + target: Wrapped(RenderTarget), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///The "target" that a [`Camera`] will render to. For example, this could be a [`Window`](bevy_window::Window) + ///swapchain or an [`Image`]. + bevy_render::camera::RenderTarget : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Render viewport configuration for the [`Camera`] component. + /// + ///The viewport defines the area on the render target to which the camera renders its image. + ///You can overlay multiple cameras in a single window using viewports to create effects like + ///split screen, minimaps, and character viewers. + bevy_render::camera::Viewport : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + /// The physical position to render this viewport to within the [`RenderTarget`] of this [`Camera`]. + /// (0,0) corresponds to the top-left corner + physical_position: Wrapped(UVec2), + /// The physical size of the viewport rectangle to render to within the [`RenderTarget`] of this [`Camera`]. + /// The origin of the rectangle is in the top-left corner. + physical_size: Wrapped(UVec2), + /// The minimum and maximum depth to render (on a scale from 0.0 to 1.0). + depth: Raw(ReflectedValue), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A configurable [`CameraProjection`] that can select its projection type at runtime. + bevy_render::camera::Projection : + Clone + + Debug + + Methods + ( + get_projection_matrix(&self:) -> Wrapped(Mat4), + + update(&mut self:Raw(f32),Raw(f32)), + + depth_calculation(&self:) -> Wrapped(DepthCalculation), + + far(&self:) -> Raw(f32), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_render::camera::OrthographicProjection : + Clone + + Debug + + Methods + ( + get_projection_matrix(&self:) -> Wrapped(Mat4), + + update(&mut self:Raw(f32),Raw(f32)), + + depth_calculation(&self:) -> Wrapped(DepthCalculation), + + far(&self:) -> Raw(f32), + + ) + + Fields + ( + left: Raw(f32), + right: Raw(f32), + bottom: Raw(f32), + top: Raw(f32), + near: Raw(f32), + #[rename("_far")] + far: Raw(f32), + window_origin: Wrapped(WindowOrigin), + scaling_mode: Wrapped(ScalingMode), + scale: Raw(f32), + #[rename("_depth_calculation")] + depth_calculation: Wrapped(DepthCalculation), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_render::camera::PerspectiveProjection : + Clone + + Debug + + Methods + ( + get_projection_matrix(&self:) -> Wrapped(Mat4), + + update(&mut self:Raw(f32),Raw(f32)), + + depth_calculation(&self:) -> Wrapped(DepthCalculation), + + far(&self:) -> Raw(f32), + + ) + + Fields + ( + fov: Raw(f32), + aspect_ratio: Raw(f32), + near: Raw(f32), + #[rename("_far")] + far: Raw(f32), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + bevy_render::camera::DepthCalculation : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///Configures the [`RenderGraph`](crate::render_graph::RenderGraph) name assigned to be run for a given [`Camera`] entity. + bevy_render::camera::CameraRenderGraph : + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///An unique identifier to an asset path. + bevy_asset::AssetPathId : + Clone + + Debug + + Methods + ( + ///Gets the id of the source path. + source_path_id(&self:) -> Wrapped(SourcePathId), + + ///Gets the id of the sub-asset label. + label_id(&self:) -> Wrapped(LabelId), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///An unique identifier to a sub-asset label. + bevy_asset::LabelId : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///An unique identifier to the source path of an asset. + bevy_asset::SourcePathId : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A unique, stable asset id. + bevy_asset::HandleId : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A 2-dimensional vector. + glam::f32::vec2::Vec2 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(f32),Raw(f32)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(f32)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec2),self,self) -> self, + + ///Creates a 3D vector from `self` and the given `z` value. + extend(self:Raw(f32)) -> Wrapped(Vec3), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(f32), + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(f32), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(f32), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec2), + + ///Returns a vector containing the absolute value of each element of `self`. + abs(self:) -> self, + + ///Returns a vector with elements representing the sign of `self`. + /// + ///- `1.0` if the number is positive, `+0.0` or `INFINITY` + ///- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + ///- `NAN` if the number is `NAN` + signum(self:) -> self, + + ///Returns `true` if, and only if, all elements are finite. If any element is either + ///`NaN`, positive or negative infinity, this will return `false`. + is_finite(self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(self:) -> Raw(bool), + + ///Performs `is_nan` on each element of self, returning a vector mask of the results. + /// + ///In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask(self:) -> Wrapped(BVec2), + + ///Computes the length of `self`. + length(self:) -> Raw(f32), + + ///Computes the squared length of `self`. + /// + ///This is faster than `length()` as it avoids a square root operation. + length_squared(self:) -> Raw(f32), + + ///Computes `1.0 / length()`. + /// + ///For valid results, `self` must _not_ be of length zero. + length_recip(self:) -> Raw(f32), + + ///Computes the Euclidean distance between two points in space. + distance(self:self) -> Raw(f32), + + ///Compute the squared euclidean distance between two points in space. + distance_squared(self:self) -> Raw(f32), + + ///Returns `self` normalized to length 1.0. + /// + ///For valid results, `self` must _not_ be of length zero, nor very close to zero. + /// + ///See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + /// + ///Panics + /// + ///Will panic if `self` is zero length when `glam_assert` is enabled. + normalize(self:) -> self, + + ///Returns `self` normalized to length 1.0 if possible, else returns zero. + /// + ///In particular, if the input is zero (or very close to zero), or non-finite, + ///the result of this operation will be zero. + /// + ///See also [`Self::try_normalize`]. + normalize_or_zero(self:) -> self, + + ///Returns whether `self` is length `1.0` or not. + /// + ///Uses a precision threshold of `1e-6`. + is_normalized(self:) -> Raw(bool), + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from(self:self) -> self, + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized(self:self) -> self, + + ///Returns a vector containing the nearest integer to a number for each element of `self`. + ///Round half-way cases away from 0.0. + round(self:) -> self, + + ///Returns a vector containing the largest integer less than or equal to a number for each + ///element of `self`. + floor(self:) -> self, + + ///Returns a vector containing the smallest integer greater than or equal to a number for + ///each element of `self`. + ceil(self:) -> self, + + ///Returns a vector containing the fractional part of the vector, e.g. `self - + ///self.floor()`. + /// + ///Note that this is fast but not precise for large numbers. + fract(self:) -> self, + + ///Returns a vector containing `e^self` (the exponential function) for each element of + ///`self`. + exp(self:) -> self, + + ///Returns a vector containing each element of `self` raised to the power of `n`. + powf(self:Raw(f32)) -> self, + + ///Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip(self:) -> self, + + ///Performs a linear interpolation between `self` and `rhs` based on the value `s`. + /// + ///When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + ///will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + ///extrapolated. + lerp(self:self,Raw(f32)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` is + ///less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two vectors contain similar elements. It works best when + ///comparing with a known value. The `max_abs_diff` that should be used used depends on + ///the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(self:self,Raw(f32)) -> Raw(bool), + + ///Returns a vector with a length no less than `min` and no more than `max` + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length(self:Raw(f32),Raw(f32)) -> self, + + ///Returns a vector with a length no more than `max` + clamp_length_max(self:Raw(f32)) -> self, + + ///Returns a vector with a length no less than `min` + clamp_length_min(self:Raw(f32)) -> self, + + ///Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + ///error, yielding a more accurate result than an unfused multiply-add. + /// + ///Using `mul_add` *may* be more performant than an unfused multiply-add if the target + ///architecture has a dedicated fma CPU instruction. However, this is not always true, + ///and will be heavily dependant on designing algorithms with specific target hardware in + ///mind. + mul_add(self:self,self) -> self, + + ///Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in + ///conjunction with the `rotate` method, e.g. `Vec2::from_angle(PI).rotate(Vec2::Y)` will + ///create the vector [-1, 0] and rotate `Vec2::Y` around it returning `-Vec2::Y`. + from_angle(Raw(f32)) -> self, + + ///Returns the angle (in radians) between `self` and `rhs`. + /// + ///The input vectors do not need to be unit length however they must be non-zero. + angle_between(self:self) -> Raw(f32), + + ///Returns a vector that is equal to `self` rotated by 90 degrees. + perp(self:) -> self, + + ///The perpendicular dot product of `self` and `rhs`. + ///Also known as the wedge product, 2D cross product, and determinant. + perp_dot(self:self) -> Raw(f32), + + ///Returns `rhs` rotated by the angle of `self`. If `self` is normalized, + ///then this just rotation. This is what you usually want. Otherwise, + ///it will be like a rotation with a multiplication by `self`'s length. + rotate(self:self) -> self, + + ///Casts all elements of `self` to `f64`. + as_dvec2(&self:) -> Wrapped(DVec2), + + ///Casts all elements of `self` to `i32`. + as_ivec2(&self:) -> Wrapped(IVec2), + + ///Casts all elements of `self` to `u32`. + as_uvec2(&self:) -> Wrapped(UVec2), + + ) + + Fields + ( + x: Raw(f32), + y: Raw(f32), + ) + + BinOps + ( + self Add self -> Wrapped(Vec2), + self Add Raw(f32) -> Wrapped(Vec2), + self Add Wrapped(Vec2) -> Wrapped(Vec2), + self Sub self -> Wrapped(Vec2), + self Sub Raw(f32) -> Wrapped(Vec2), + self Sub Wrapped(Vec2) -> Wrapped(Vec2), + self Div self -> Wrapped(Vec2), + self Div Raw(f32) -> Wrapped(Vec2), + self Div Wrapped(Vec2) -> Wrapped(Vec2), + self Mul self -> Wrapped(Vec2), + self Mul Raw(f32) -> Wrapped(Vec2), + self Mul Wrapped(Vec2) -> Wrapped(Vec2), + self Rem self -> Wrapped(Vec2), + self Rem Raw(f32) -> Wrapped(Vec2), + self Rem Wrapped(Vec2) -> Wrapped(Vec2), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 3-dimensional vector. + glam::f32::vec3::Vec3 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(f32)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec3),self,self) -> self, + + ///Creates a 4D vector from `self` and the given `w` value. + extend(self:Raw(f32)) -> Wrapped(Vec4), + + ///Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. + /// + ///Truncation may also be performed by using `self.xy()` or `Vec2::from()`. + truncate(self:) -> Wrapped(Vec2), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(f32), + + ///Computes the cross product of `self` and `rhs`. + cross(self:self) -> self, + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(f32), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(f32), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec3), + + ///Returns a vector containing the absolute value of each element of `self`. + abs(self:) -> self, + + ///Returns a vector with elements representing the sign of `self`. + /// + ///- `1.0` if the number is positive, `+0.0` or `INFINITY` + ///- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + ///- `NAN` if the number is `NAN` + signum(self:) -> self, + + ///Returns `true` if, and only if, all elements are finite. If any element is either + ///`NaN`, positive or negative infinity, this will return `false`. + is_finite(self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(self:) -> Raw(bool), + + ///Performs `is_nan` on each element of self, returning a vector mask of the results. + /// + ///In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask(self:) -> Wrapped(BVec3), + + ///Computes the length of `self`. + length(self:) -> Raw(f32), + + ///Computes the squared length of `self`. + /// + ///This is faster than `length()` as it avoids a square root operation. + length_squared(self:) -> Raw(f32), + + ///Computes `1.0 / length()`. + /// + ///For valid results, `self` must _not_ be of length zero. + length_recip(self:) -> Raw(f32), + + ///Computes the Euclidean distance between two points in space. + distance(self:self) -> Raw(f32), + + ///Compute the squared euclidean distance between two points in space. + distance_squared(self:self) -> Raw(f32), + + ///Returns `self` normalized to length 1.0. + /// + ///For valid results, `self` must _not_ be of length zero, nor very close to zero. + /// + ///See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + /// + ///Panics + /// + ///Will panic if `self` is zero length when `glam_assert` is enabled. + normalize(self:) -> self, + + ///Returns `self` normalized to length 1.0 if possible, else returns zero. + /// + ///In particular, if the input is zero (or very close to zero), or non-finite, + ///the result of this operation will be zero. + /// + ///See also [`Self::try_normalize`]. + normalize_or_zero(self:) -> self, + + ///Returns whether `self` is length `1.0` or not. + /// + ///Uses a precision threshold of `1e-6`. + is_normalized(self:) -> Raw(bool), + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from(self:self) -> self, + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized(self:self) -> self, + + ///Returns a vector containing the nearest integer to a number for each element of `self`. + ///Round half-way cases away from 0.0. + round(self:) -> self, + + ///Returns a vector containing the largest integer less than or equal to a number for each + ///element of `self`. + floor(self:) -> self, + + ///Returns a vector containing the smallest integer greater than or equal to a number for + ///each element of `self`. + ceil(self:) -> self, + + ///Returns a vector containing the fractional part of the vector, e.g. `self - + ///self.floor()`. + /// + ///Note that this is fast but not precise for large numbers. + fract(self:) -> self, + + ///Returns a vector containing `e^self` (the exponential function) for each element of + ///`self`. + exp(self:) -> self, + + ///Returns a vector containing each element of `self` raised to the power of `n`. + powf(self:Raw(f32)) -> self, + + ///Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip(self:) -> self, + + ///Performs a linear interpolation between `self` and `rhs` based on the value `s`. + /// + ///When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + ///will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + ///extrapolated. + lerp(self:self,Raw(f32)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` is + ///less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two vectors contain similar elements. It works best when + ///comparing with a known value. The `max_abs_diff` that should be used used depends on + ///the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(self:self,Raw(f32)) -> Raw(bool), + + ///Returns a vector with a length no less than `min` and no more than `max` + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length(self:Raw(f32),Raw(f32)) -> self, + + ///Returns a vector with a length no more than `max` + clamp_length_max(self:Raw(f32)) -> self, + + ///Returns a vector with a length no less than `min` + clamp_length_min(self:Raw(f32)) -> self, + + ///Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + ///error, yielding a more accurate result than an unfused multiply-add. + /// + ///Using `mul_add` *may* be more performant than an unfused multiply-add if the target + ///architecture has a dedicated fma CPU instruction. However, this is not always true, + ///and will be heavily dependant on designing algorithms with specific target hardware in + ///mind. + mul_add(self:self,self) -> self, + + ///Returns the angle (in radians) between two vectors. + /// + ///The input vectors do not need to be unit length however they must be non-zero. + angle_between(self:self) -> Raw(f32), + + ///Returns some vector that is orthogonal to the given one. + /// + ///The input vector must be finite and non-zero. + /// + ///The output vector is not necessarily unit-length. + ///For that use [`Self::any_orthonormal_vector`] instead. + any_orthogonal_vector(&self:) -> self, + + ///Returns any unit-length vector that is orthogonal to the given one. + ///The input vector must be finite and non-zero. + /// + ///# Panics + /// + ///Will panic if `self` is not normalized when `glam_assert` is enabled. + any_orthonormal_vector(&self:) -> self, + + ///Casts all elements of `self` to `f64`. + as_dvec3(&self:) -> Wrapped(DVec3), + + ///Casts all elements of `self` to `i32`. + as_ivec3(&self:) -> Wrapped(IVec3), + + ///Casts all elements of `self` to `u32`. + as_uvec3(&self:) -> Wrapped(UVec3), + + ) + + Fields + ( + x: Raw(f32), + y: Raw(f32), + z: Raw(f32), + ) + + BinOps + ( + self Add self -> Wrapped(Vec3), + self Add Raw(f32) -> Wrapped(Vec3), + self Add Wrapped(Vec3) -> Wrapped(Vec3), + self Sub self -> Wrapped(Vec3), + self Sub Raw(f32) -> Wrapped(Vec3), + self Sub Wrapped(Vec3) -> Wrapped(Vec3), + self Div self -> Wrapped(Vec3), + self Div Raw(f32) -> Wrapped(Vec3), + self Div Wrapped(Vec3) -> Wrapped(Vec3), + self Mul self -> Wrapped(Vec3), + self Mul Raw(f32) -> Wrapped(Vec3), + self Mul Wrapped(Vec3) -> Wrapped(Vec3), + self Rem self -> Wrapped(Vec3), + self Rem Raw(f32) -> Wrapped(Vec3), + self Rem Wrapped(Vec3) -> Wrapped(Vec3), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 3-dimensional vector with SIMD support. + /// + ///This type is 16 byte aligned. A SIMD vector type is used for storage on supported platforms for + ///better performance than the `Vec3` type. + /// + ///It is possible to convert between `Vec3` and `Vec3A` types using `From` trait implementations. + glam::f32::sse2::vec3A::Vec3A : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(f32)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec3A),self,self) -> self, + + ///Creates a 4D vector from `self` and the given `w` value. + extend(self:Raw(f32)) -> Wrapped(Vec4), + + ///Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. + /// + ///Truncation may also be performed by using `self.xy()` or `Vec2::from()`. + truncate(self:) -> Wrapped(Vec2), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(f32), + + ///Computes the cross product of `self` and `rhs`. + cross(self:self) -> self, + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(f32), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(f32), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec3A), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec3A), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec3A), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec3A), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec3A), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec3A), + + ///Returns a vector containing the absolute value of each element of `self`. + abs(self:) -> self, + + ///Returns a vector with elements representing the sign of `self`. + /// + ///- `1.0` if the number is positive, `+0.0` or `INFINITY` + ///- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + ///- `NAN` if the number is `NAN` + signum(self:) -> self, + + ///Returns `true` if, and only if, all elements are finite. If any element is either + ///`NaN`, positive or negative infinity, this will return `false`. + is_finite(self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(self:) -> Raw(bool), + + ///Performs `is_nan` on each element of self, returning a vector mask of the results. + /// + ///In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask(self:) -> Wrapped(BVec3A), + + ///Computes the length of `self`. + length(self:) -> Raw(f32), + + ///Computes the squared length of `self`. + /// + ///This is faster than `length()` as it avoids a square root operation. + length_squared(self:) -> Raw(f32), + + ///Computes `1.0 / length()`. + /// + ///For valid results, `self` must _not_ be of length zero. + length_recip(self:) -> Raw(f32), + + ///Computes the Euclidean distance between two points in space. + distance(self:self) -> Raw(f32), + + ///Compute the squared euclidean distance between two points in space. + distance_squared(self:self) -> Raw(f32), + + ///Returns `self` normalized to length 1.0. + /// + ///For valid results, `self` must _not_ be of length zero, nor very close to zero. + /// + ///See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + /// + ///Panics + /// + ///Will panic if `self` is zero length when `glam_assert` is enabled. + normalize(self:) -> self, + + ///Returns `self` normalized to length 1.0 if possible, else returns zero. + /// + ///In particular, if the input is zero (or very close to zero), or non-finite, + ///the result of this operation will be zero. + /// + ///See also [`Self::try_normalize`]. + normalize_or_zero(self:) -> self, + + ///Returns whether `self` is length `1.0` or not. + /// + ///Uses a precision threshold of `1e-6`. + is_normalized(self:) -> Raw(bool), + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from(self:self) -> self, + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized(self:self) -> self, + + ///Returns a vector containing the nearest integer to a number for each element of `self`. + ///Round half-way cases away from 0.0. + round(self:) -> self, + + ///Returns a vector containing the largest integer less than or equal to a number for each + ///element of `self`. + floor(self:) -> self, + + ///Returns a vector containing the smallest integer greater than or equal to a number for + ///each element of `self`. + ceil(self:) -> self, + + ///Returns a vector containing the fractional part of the vector, e.g. `self - + ///self.floor()`. + /// + ///Note that this is fast but not precise for large numbers. + fract(self:) -> self, + + ///Returns a vector containing `e^self` (the exponential function) for each element of + ///`self`. + exp(self:) -> self, + + ///Returns a vector containing each element of `self` raised to the power of `n`. + powf(self:Raw(f32)) -> self, + + ///Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip(self:) -> self, + + ///Performs a linear interpolation between `self` and `rhs` based on the value `s`. + /// + ///When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + ///will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + ///extrapolated. + lerp(self:self,Raw(f32)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` is + ///less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two vectors contain similar elements. It works best when + ///comparing with a known value. The `max_abs_diff` that should be used used depends on + ///the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(self:self,Raw(f32)) -> Raw(bool), + + ///Returns a vector with a length no less than `min` and no more than `max` + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length(self:Raw(f32),Raw(f32)) -> self, + + ///Returns a vector with a length no more than `max` + clamp_length_max(self:Raw(f32)) -> self, + + ///Returns a vector with a length no less than `min` + clamp_length_min(self:Raw(f32)) -> self, + + ///Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + ///error, yielding a more accurate result than an unfused multiply-add. + /// + ///Using `mul_add` *may* be more performant than an unfused multiply-add if the target + ///architecture has a dedicated fma CPU instruction. However, this is not always true, + ///and will be heavily dependant on designing algorithms with specific target hardware in + ///mind. + mul_add(self:self,self) -> self, + + ///Returns the angle (in radians) between two vectors. + /// + ///The input vectors do not need to be unit length however they must be non-zero. + angle_between(self:self) -> Raw(f32), + + ///Returns some vector that is orthogonal to the given one. + /// + ///The input vector must be finite and non-zero. + /// + ///The output vector is not necessarily unit-length. + ///For that use [`Self::any_orthonormal_vector`] instead. + any_orthogonal_vector(&self:) -> self, + + ///Returns any unit-length vector that is orthogonal to the given one. + ///The input vector must be finite and non-zero. + /// + ///# Panics + /// + ///Will panic if `self` is not normalized when `glam_assert` is enabled. + any_orthonormal_vector(&self:) -> self, + + ///Casts all elements of `self` to `f64`. + as_dvec3(&self:) -> Wrapped(DVec3), + + ///Casts all elements of `self` to `i32`. + as_ivec3(&self:) -> Wrapped(IVec3), + + ///Casts all elements of `self` to `u32`. + as_uvec3(&self:) -> Wrapped(UVec3), + + ) + + Fields + ( + ) + + BinOps + ( + self Add self -> Wrapped(Vec3A), + self Add Raw(f32) -> Wrapped(Vec3A), + self Add Wrapped(Vec3A) -> Wrapped(Vec3A), + self Sub self -> Wrapped(Vec3A), + self Sub Raw(f32) -> Wrapped(Vec3A), + self Sub Wrapped(Vec3A) -> Wrapped(Vec3A), + self Div self -> Wrapped(Vec3A), + self Div Raw(f32) -> Wrapped(Vec3A), + self Div Wrapped(Vec3A) -> Wrapped(Vec3A), + self Mul self -> Wrapped(Vec3A), + self Mul Raw(f32) -> Wrapped(Vec3A), + self Mul Wrapped(Vec3A) -> Wrapped(Vec3A), + self Rem self -> Wrapped(Vec3A), + self Rem Raw(f32) -> Wrapped(Vec3A), + self Rem Wrapped(Vec3A) -> Wrapped(Vec3A), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 4-dimensional vector with SIMD support. + /// + ///This type uses 16 byte aligned SIMD vector type for storage. + glam::f32::sse2::vec4::Vec4 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(f32)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec4A),self,self) -> self, + + ///Creates a 2D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. + /// + ///Truncation to `Vec3` may also be performed by using `self.xyz()` or `Vec3::from()`. + /// + ///To truncate to `Vec3A` use `Vec3A::from()`. + truncate(self:) -> Wrapped(Vec3), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(f32), + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(f32), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(f32), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec4A), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec4A), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec4A), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec4A), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec4A), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec4A), + + ///Returns a vector containing the absolute value of each element of `self`. + abs(self:) -> self, + + ///Returns a vector with elements representing the sign of `self`. + /// + ///- `1.0` if the number is positive, `+0.0` or `INFINITY` + ///- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + ///- `NAN` if the number is `NAN` + signum(self:) -> self, + + ///Returns `true` if, and only if, all elements are finite. If any element is either + ///`NaN`, positive or negative infinity, this will return `false`. + is_finite(self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(self:) -> Raw(bool), + + ///Performs `is_nan` on each element of self, returning a vector mask of the results. + /// + ///In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask(self:) -> Wrapped(BVec4A), + + ///Computes the length of `self`. + length(self:) -> Raw(f32), + + ///Computes the squared length of `self`. + /// + ///This is faster than `length()` as it avoids a square root operation. + length_squared(self:) -> Raw(f32), + + ///Computes `1.0 / length()`. + /// + ///For valid results, `self` must _not_ be of length zero. + length_recip(self:) -> Raw(f32), + + ///Computes the Euclidean distance between two points in space. + distance(self:self) -> Raw(f32), + + ///Compute the squared euclidean distance between two points in space. + distance_squared(self:self) -> Raw(f32), + + ///Returns `self` normalized to length 1.0. + /// + ///For valid results, `self` must _not_ be of length zero, nor very close to zero. + /// + ///See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + /// + ///Panics + /// + ///Will panic if `self` is zero length when `glam_assert` is enabled. + normalize(self:) -> self, + + ///Returns `self` normalized to length 1.0 if possible, else returns zero. + /// + ///In particular, if the input is zero (or very close to zero), or non-finite, + ///the result of this operation will be zero. + /// + ///See also [`Self::try_normalize`]. + normalize_or_zero(self:) -> self, + + ///Returns whether `self` is length `1.0` or not. + /// + ///Uses a precision threshold of `1e-6`. + is_normalized(self:) -> Raw(bool), + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from(self:self) -> self, + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized(self:self) -> self, + + ///Returns a vector containing the nearest integer to a number for each element of `self`. + ///Round half-way cases away from 0.0. + round(self:) -> self, + + ///Returns a vector containing the largest integer less than or equal to a number for each + ///element of `self`. + floor(self:) -> self, + + ///Returns a vector containing the smallest integer greater than or equal to a number for + ///each element of `self`. + ceil(self:) -> self, + + ///Returns a vector containing the fractional part of the vector, e.g. `self - + ///self.floor()`. + /// + ///Note that this is fast but not precise for large numbers. + fract(self:) -> self, + + ///Returns a vector containing `e^self` (the exponential function) for each element of + ///`self`. + exp(self:) -> self, + + ///Returns a vector containing each element of `self` raised to the power of `n`. + powf(self:Raw(f32)) -> self, + + ///Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip(self:) -> self, + + ///Performs a linear interpolation between `self` and `rhs` based on the value `s`. + /// + ///When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + ///will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + ///extrapolated. + lerp(self:self,Raw(f32)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` is + ///less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two vectors contain similar elements. It works best when + ///comparing with a known value. The `max_abs_diff` that should be used used depends on + ///the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(self:self,Raw(f32)) -> Raw(bool), + + ///Returns a vector with a length no less than `min` and no more than `max` + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length(self:Raw(f32),Raw(f32)) -> self, + + ///Returns a vector with a length no more than `max` + clamp_length_max(self:Raw(f32)) -> self, + + ///Returns a vector with a length no less than `min` + clamp_length_min(self:Raw(f32)) -> self, + + ///Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + ///error, yielding a more accurate result than an unfused multiply-add. + /// + ///Using `mul_add` *may* be more performant than an unfused multiply-add if the target + ///architecture has a dedicated fma CPU instruction. However, this is not always true, + ///and will be heavily dependant on designing algorithms with specific target hardware in + ///mind. + mul_add(self:self,self) -> self, + + ///Casts all elements of `self` to `f64`. + as_dvec4(&self:) -> Wrapped(DVec4), + + ///Casts all elements of `self` to `i32`. + as_ivec4(&self:) -> Wrapped(IVec4), + + ///Casts all elements of `self` to `u32`. + as_uvec4(&self:) -> Wrapped(UVec4), + + ) + + Fields + ( + ) + + BinOps + ( + self Add self -> Wrapped(Vec4), + self Add Raw(f32) -> Wrapped(Vec4), + self Add Wrapped(Vec4) -> Wrapped(Vec4), + self Sub self -> Wrapped(Vec4), + self Sub Raw(f32) -> Wrapped(Vec4), + self Sub Wrapped(Vec4) -> Wrapped(Vec4), + self Div self -> Wrapped(Vec4), + self Div Raw(f32) -> Wrapped(Vec4), + self Div Wrapped(Vec4) -> Wrapped(Vec4), + self Mul self -> Wrapped(Vec4), + self Mul Raw(f32) -> Wrapped(Vec4), + self Mul Wrapped(Vec4) -> Wrapped(Vec4), + self Rem self -> Wrapped(Vec4), + self Rem Raw(f32) -> Wrapped(Vec4), + self Rem Wrapped(Vec4) -> Wrapped(Vec4), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f32)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 2-dimensional boolean vector. + glam::f32::sse2::vec2::BVec2 : + Clone + + Debug + + Methods + ( + ///Creates a new vector mask. + new(Raw(bool),Raw(bool)) -> self, + + ///Returns a bitmask with the lowest two bits set from the elements of `self`. + /// + ///A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes + ///into the first lowest bit, element `y` into the second, etc. + bitmask(self:) -> Raw(u32), + + ///Returns true if any of the elements are true, false otherwise. + any(self:) -> Raw(bool), + + ///Returns true if all the elements are true, false otherwise. + all(self:) -> Raw(bool), + + ) + + Fields + ( + x: Raw(bool), + y: Raw(bool), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A 3-dimensional boolean vector. + glam::f32::sse2::vec3::BVec3 : + Clone + + Debug + + Methods + ( + ///Creates a new vector mask. + new(Raw(bool),Raw(bool),Raw(bool)) -> self, + + ///Returns a bitmask with the lowest two bits set from the elements of `self`. + /// + ///A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes + ///into the first lowest bit, element `y` into the second, etc. + bitmask(self:) -> Raw(u32), + + ///Returns true if any of the elements are true, false otherwise. + any(self:) -> Raw(bool), + + ///Returns true if all the elements are true, false otherwise. + all(self:) -> Raw(bool), + + ) + + Fields + ( + x: Raw(bool), + y: Raw(bool), + z: Raw(bool), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A 4-dimensional boolean vector. + glam::f32::sse2::vec4::BVec4 : + Clone + + Debug + + Methods + ( + ///Creates a new vector mask. + new(Raw(bool),Raw(bool),Raw(bool),Raw(bool)) -> self, + + ///Returns a bitmask with the lowest two bits set from the elements of `self`. + /// + ///A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes + ///into the first lowest bit, element `y` into the second, etc. + bitmask(self:) -> Raw(u32), + + ///Returns true if any of the elements are true, false otherwise. + any(self:) -> Raw(bool), + + ///Returns true if all the elements are true, false otherwise. + all(self:) -> Raw(bool), + + ) + + Fields + ( + x: Raw(bool), + y: Raw(bool), + z: Raw(bool), + w: Raw(bool), + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A 3-dimensional SIMD vector mask. + /// + ///This type is 16 byte aligned and is backed by a SIMD vector. If SIMD is not available + ///`BVec3A` will be a type alias for `BVec3`. + glam::f32::sse2::vec3::BVec3A : + Clone + + Debug + + Methods + ( + ///Creates a new vector mask. + new(Raw(bool),Raw(bool),Raw(bool)) -> self, + + ///Returns a bitmask with the lowest two bits set from the elements of `self`. + /// + ///A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes + ///into the first lowest bit, element `y` into the second, etc. + bitmask(self:) -> Raw(u32), + + ///Returns true if any of the elements are true, false otherwise. + any(self:) -> Raw(bool), + + ///Returns true if all the elements are true, false otherwise. + all(self:) -> Raw(bool), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A 4-dimensional SIMD vector mask. + /// + ///This type is 16 byte aligned and is backed by a SIMD vector. If SIMD is not available + ///`BVec4A` will be a type alias for `BVec4`. + glam::f32::sse2::vec4::BVec4A : + Clone + + Debug + + Methods + ( + ///Creates a new vector mask. + new(Raw(bool),Raw(bool),Raw(bool),Raw(bool)) -> self, + + ///Returns a bitmask with the lowest two bits set from the elements of `self`. + /// + ///A true element results in a `1` bit and a false element in a `0` bit. Element `x` goes + ///into the first lowest bit, element `y` into the second, etc. + bitmask(self:) -> Raw(u32), + + ///Returns true if any of the elements are true, false otherwise. + any(self:) -> Raw(bool), + + ///Returns true if all the elements are true, false otherwise. + all(self:) -> Raw(bool), + + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A 2-dimensional vector. + glam::f64::dvec2::DVec2 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(f64),Raw(f64)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(f64)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec2),self,self) -> self, + + ///Creates a 3D vector from `self` and the given `z` value. + extend(self:Raw(f64)) -> Wrapped(DVec3), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(f64), + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(f64), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(f64), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec2), + + ///Returns a vector containing the absolute value of each element of `self`. + abs(self:) -> self, + + ///Returns a vector with elements representing the sign of `self`. + /// + ///- `1.0` if the number is positive, `+0.0` or `INFINITY` + ///- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + ///- `NAN` if the number is `NAN` + signum(self:) -> self, + + ///Returns `true` if, and only if, all elements are finite. If any element is either + ///`NaN`, positive or negative infinity, this will return `false`. + is_finite(self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(self:) -> Raw(bool), + + ///Performs `is_nan` on each element of self, returning a vector mask of the results. + /// + ///In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask(self:) -> Wrapped(BVec2), + + ///Computes the length of `self`. + length(self:) -> Raw(f64), + + ///Computes the squared length of `self`. + /// + ///This is faster than `length()` as it avoids a square root operation. + length_squared(self:) -> Raw(f64), + + ///Computes `1.0 / length()`. + /// + ///For valid results, `self` must _not_ be of length zero. + length_recip(self:) -> Raw(f64), + + ///Computes the Euclidean distance between two points in space. + distance(self:self) -> Raw(f64), + + ///Compute the squared euclidean distance between two points in space. + distance_squared(self:self) -> Raw(f64), + + ///Returns `self` normalized to length 1.0. + /// + ///For valid results, `self` must _not_ be of length zero, nor very close to zero. + /// + ///See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + /// + ///Panics + /// + ///Will panic if `self` is zero length when `glam_assert` is enabled. + normalize(self:) -> self, + + ///Returns `self` normalized to length 1.0 if possible, else returns zero. + /// + ///In particular, if the input is zero (or very close to zero), or non-finite, + ///the result of this operation will be zero. + /// + ///See also [`Self::try_normalize`]. + normalize_or_zero(self:) -> self, + + ///Returns whether `self` is length `1.0` or not. + /// + ///Uses a precision threshold of `1e-6`. + is_normalized(self:) -> Raw(bool), + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from(self:self) -> self, + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized(self:self) -> self, + + ///Returns a vector containing the nearest integer to a number for each element of `self`. + ///Round half-way cases away from 0.0. + round(self:) -> self, + + ///Returns a vector containing the largest integer less than or equal to a number for each + ///element of `self`. + floor(self:) -> self, + + ///Returns a vector containing the smallest integer greater than or equal to a number for + ///each element of `self`. + ceil(self:) -> self, + + ///Returns a vector containing the fractional part of the vector, e.g. `self - + ///self.floor()`. + /// + ///Note that this is fast but not precise for large numbers. + fract(self:) -> self, + + ///Returns a vector containing `e^self` (the exponential function) for each element of + ///`self`. + exp(self:) -> self, + + ///Returns a vector containing each element of `self` raised to the power of `n`. + powf(self:Raw(f64)) -> self, + + ///Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip(self:) -> self, + + ///Performs a linear interpolation between `self` and `rhs` based on the value `s`. + /// + ///When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + ///will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + ///extrapolated. + lerp(self:self,Raw(f64)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` is + ///less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two vectors contain similar elements. It works best when + ///comparing with a known value. The `max_abs_diff` that should be used used depends on + ///the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(self:self,Raw(f64)) -> Raw(bool), + + ///Returns a vector with a length no less than `min` and no more than `max` + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length(self:Raw(f64),Raw(f64)) -> self, + + ///Returns a vector with a length no more than `max` + clamp_length_max(self:Raw(f64)) -> self, + + ///Returns a vector with a length no less than `min` + clamp_length_min(self:Raw(f64)) -> self, + + ///Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + ///error, yielding a more accurate result than an unfused multiply-add. + /// + ///Using `mul_add` *may* be more performant than an unfused multiply-add if the target + ///architecture has a dedicated fma CPU instruction. However, this is not always true, + ///and will be heavily dependant on designing algorithms with specific target hardware in + ///mind. + mul_add(self:self,self) -> self, + + ///Creates a 2D vector containing `[angle.cos(), angle.sin()]`. This can be used in + ///conjunction with the `rotate` method, e.g. `Vec2::from_angle(PI).rotate(Vec2::Y)` will + ///create the vector [-1, 0] and rotate `Vec2::Y` around it returning `-Vec2::Y`. + from_angle(Raw(f64)) -> self, + + ///Returns the angle (in radians) between `self` and `rhs`. + /// + ///The input vectors do not need to be unit length however they must be non-zero. + angle_between(self:self) -> Raw(f64), + + ///Returns a vector that is equal to `self` rotated by 90 degrees. + perp(self:) -> self, + + ///The perpendicular dot product of `self` and `rhs`. + ///Also known as the wedge product, 2D cross product, and determinant. + perp_dot(self:self) -> Raw(f64), + + ///Returns `rhs` rotated by the angle of `self`. If `self` is normalized, + ///then this just rotation. This is what you usually want. Otherwise, + ///it will be like a rotation with a multiplication by `self`'s length. + rotate(self:self) -> self, + + ///Casts all elements of `self` to `f32`. + as_vec2(&self:) -> Wrapped(Vec2), + + ///Casts all elements of `self` to `i32`. + as_ivec2(&self:) -> Wrapped(IVec2), + + ///Casts all elements of `self` to `u32`. + as_uvec2(&self:) -> Wrapped(UVec2), + + ) + + Fields + ( + x: Raw(f64), + y: Raw(f64), + ) + + BinOps + ( + self Add self -> Wrapped(DVec2), + self Add Raw(f64) -> Wrapped(DVec2), + self Add Wrapped(DVec2) -> Wrapped(DVec2), + self Sub self -> Wrapped(DVec2), + self Sub Raw(f64) -> Wrapped(DVec2), + self Sub Wrapped(DVec2) -> Wrapped(DVec2), + self Div self -> Wrapped(DVec2), + self Div Raw(f64) -> Wrapped(DVec2), + self Div Wrapped(DVec2) -> Wrapped(DVec2), + self Mul self -> Wrapped(DVec2), + self Mul Raw(f64) -> Wrapped(DVec2), + self Mul Wrapped(DVec2) -> Wrapped(DVec2), + self Rem self -> Wrapped(DVec2), + self Rem Raw(f64) -> Wrapped(DVec2), + self Rem Wrapped(DVec2) -> Wrapped(DVec2), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f64)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 3-dimensional vector. + glam::f64::dvec3::DVec3 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(f64)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec3),self,self) -> self, + + ///Creates a 4D vector from `self` and the given `w` value. + extend(self:Raw(f64)) -> Wrapped(DVec4), + + ///Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. + /// + ///Truncation may also be performed by using `self.xy()` or `DVec2::from()`. + truncate(self:) -> Wrapped(DVec2), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(f64), + + ///Computes the cross product of `self` and `rhs`. + cross(self:self) -> self, + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(f64), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(f64), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec3), + + ///Returns a vector containing the absolute value of each element of `self`. + abs(self:) -> self, + + ///Returns a vector with elements representing the sign of `self`. + /// + ///- `1.0` if the number is positive, `+0.0` or `INFINITY` + ///- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + ///- `NAN` if the number is `NAN` + signum(self:) -> self, + + ///Returns `true` if, and only if, all elements are finite. If any element is either + ///`NaN`, positive or negative infinity, this will return `false`. + is_finite(self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(self:) -> Raw(bool), + + ///Performs `is_nan` on each element of self, returning a vector mask of the results. + /// + ///In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask(self:) -> Wrapped(BVec3), + + ///Computes the length of `self`. + length(self:) -> Raw(f64), + + ///Computes the squared length of `self`. + /// + ///This is faster than `length()` as it avoids a square root operation. + length_squared(self:) -> Raw(f64), + + ///Computes `1.0 / length()`. + /// + ///For valid results, `self` must _not_ be of length zero. + length_recip(self:) -> Raw(f64), + + ///Computes the Euclidean distance between two points in space. + distance(self:self) -> Raw(f64), + + ///Compute the squared euclidean distance between two points in space. + distance_squared(self:self) -> Raw(f64), + + ///Returns `self` normalized to length 1.0. + /// + ///For valid results, `self` must _not_ be of length zero, nor very close to zero. + /// + ///See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + /// + ///Panics + /// + ///Will panic if `self` is zero length when `glam_assert` is enabled. + normalize(self:) -> self, + + ///Returns `self` normalized to length 1.0 if possible, else returns zero. + /// + ///In particular, if the input is zero (or very close to zero), or non-finite, + ///the result of this operation will be zero. + /// + ///See also [`Self::try_normalize`]. + normalize_or_zero(self:) -> self, + + ///Returns whether `self` is length `1.0` or not. + /// + ///Uses a precision threshold of `1e-6`. + is_normalized(self:) -> Raw(bool), + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from(self:self) -> self, + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized(self:self) -> self, + + ///Returns a vector containing the nearest integer to a number for each element of `self`. + ///Round half-way cases away from 0.0. + round(self:) -> self, + + ///Returns a vector containing the largest integer less than or equal to a number for each + ///element of `self`. + floor(self:) -> self, + + ///Returns a vector containing the smallest integer greater than or equal to a number for + ///each element of `self`. + ceil(self:) -> self, + + ///Returns a vector containing the fractional part of the vector, e.g. `self - + ///self.floor()`. + /// + ///Note that this is fast but not precise for large numbers. + fract(self:) -> self, + + ///Returns a vector containing `e^self` (the exponential function) for each element of + ///`self`. + exp(self:) -> self, + + ///Returns a vector containing each element of `self` raised to the power of `n`. + powf(self:Raw(f64)) -> self, + + ///Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip(self:) -> self, + + ///Performs a linear interpolation between `self` and `rhs` based on the value `s`. + /// + ///When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + ///will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + ///extrapolated. + lerp(self:self,Raw(f64)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` is + ///less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two vectors contain similar elements. It works best when + ///comparing with a known value. The `max_abs_diff` that should be used used depends on + ///the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(self:self,Raw(f64)) -> Raw(bool), + + ///Returns a vector with a length no less than `min` and no more than `max` + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length(self:Raw(f64),Raw(f64)) -> self, + + ///Returns a vector with a length no more than `max` + clamp_length_max(self:Raw(f64)) -> self, + + ///Returns a vector with a length no less than `min` + clamp_length_min(self:Raw(f64)) -> self, + + ///Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + ///error, yielding a more accurate result than an unfused multiply-add. + /// + ///Using `mul_add` *may* be more performant than an unfused multiply-add if the target + ///architecture has a dedicated fma CPU instruction. However, this is not always true, + ///and will be heavily dependant on designing algorithms with specific target hardware in + ///mind. + mul_add(self:self,self) -> self, + + ///Returns the angle (in radians) between two vectors. + /// + ///The input vectors do not need to be unit length however they must be non-zero. + angle_between(self:self) -> Raw(f64), + + ///Returns some vector that is orthogonal to the given one. + /// + ///The input vector must be finite and non-zero. + /// + ///The output vector is not necessarily unit-length. + ///For that use [`Self::any_orthonormal_vector`] instead. + any_orthogonal_vector(&self:) -> self, + + ///Returns any unit-length vector that is orthogonal to the given one. + ///The input vector must be finite and non-zero. + /// + ///# Panics + /// + ///Will panic if `self` is not normalized when `glam_assert` is enabled. + any_orthonormal_vector(&self:) -> self, + + ///Casts all elements of `self` to `f32`. + as_vec3(&self:) -> Wrapped(Vec3), + + ///Casts all elements of `self` to `f32`. + as_vec3a(&self:) -> Wrapped(Vec3A), + + ///Casts all elements of `self` to `i32`. + as_ivec3(&self:) -> Wrapped(IVec3), + + ///Casts all elements of `self` to `u32`. + as_uvec3(&self:) -> Wrapped(UVec3), + + ) + + Fields + ( + x: Raw(f64), + y: Raw(f64), + z: Raw(f64), + ) + + BinOps + ( + self Add self -> Wrapped(DVec3), + self Add Raw(f64) -> Wrapped(DVec3), + self Add Wrapped(DVec3) -> Wrapped(DVec3), + self Sub self -> Wrapped(DVec3), + self Sub Raw(f64) -> Wrapped(DVec3), + self Sub Wrapped(DVec3) -> Wrapped(DVec3), + self Div self -> Wrapped(DVec3), + self Div Raw(f64) -> Wrapped(DVec3), + self Div Wrapped(DVec3) -> Wrapped(DVec3), + self Mul self -> Wrapped(DVec3), + self Mul Raw(f64) -> Wrapped(DVec3), + self Mul Wrapped(DVec3) -> Wrapped(DVec3), + self Rem self -> Wrapped(DVec3), + self Rem Raw(f64) -> Wrapped(DVec3), + self Rem Wrapped(DVec3) -> Wrapped(DVec3), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f64)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 4-dimensional vector. + glam::f64::dvec4::DVec4 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(f64),Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(f64)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec4),self,self) -> self, + + ///Creates a 2D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. + /// + ///Truncation to `DVec3` may also be performed by using `self.xyz()` or `DVec3::from()`. + truncate(self:) -> Wrapped(DVec3), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(f64), + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(f64), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(f64), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec4), + + ///Returns a vector containing the absolute value of each element of `self`. + abs(self:) -> self, + + ///Returns a vector with elements representing the sign of `self`. + /// + ///- `1.0` if the number is positive, `+0.0` or `INFINITY` + ///- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + ///- `NAN` if the number is `NAN` + signum(self:) -> self, + + ///Returns `true` if, and only if, all elements are finite. If any element is either + ///`NaN`, positive or negative infinity, this will return `false`. + is_finite(self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(self:) -> Raw(bool), + + ///Performs `is_nan` on each element of self, returning a vector mask of the results. + /// + ///In other words, this computes `[x.is_nan(), y.is_nan(), z.is_nan(), w.is_nan()]`. + is_nan_mask(self:) -> Wrapped(BVec4), + + ///Computes the length of `self`. + length(self:) -> Raw(f64), + + ///Computes the squared length of `self`. + /// + ///This is faster than `length()` as it avoids a square root operation. + length_squared(self:) -> Raw(f64), + + ///Computes `1.0 / length()`. + /// + ///For valid results, `self` must _not_ be of length zero. + length_recip(self:) -> Raw(f64), + + ///Computes the Euclidean distance between two points in space. + distance(self:self) -> Raw(f64), + + ///Compute the squared euclidean distance between two points in space. + distance_squared(self:self) -> Raw(f64), + + ///Returns `self` normalized to length 1.0. + /// + ///For valid results, `self` must _not_ be of length zero, nor very close to zero. + /// + ///See also [`Self::try_normalize`] and [`Self::normalize_or_zero`]. + /// + ///Panics + /// + ///Will panic if `self` is zero length when `glam_assert` is enabled. + normalize(self:) -> self, + + ///Returns `self` normalized to length 1.0 if possible, else returns zero. + /// + ///In particular, if the input is zero (or very close to zero), or non-finite, + ///the result of this operation will be zero. + /// + ///See also [`Self::try_normalize`]. + normalize_or_zero(self:) -> self, + + ///Returns whether `self` is length `1.0` or not. + /// + ///Uses a precision threshold of `1e-6`. + is_normalized(self:) -> Raw(bool), + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` is zero length when `glam_assert` is enabled. + project_onto(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be of non-zero length. + /// + ///# Panics + /// + ///Will panic if `rhs` has a length of zero when `glam_assert` is enabled. + reject_from(self:self) -> self, + + ///Returns the vector projection of `self` onto `rhs`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + project_onto_normalized(self:self) -> self, + + ///Returns the vector rejection of `self` from `rhs`. + /// + ///The vector rejection is the vector perpendicular to the projection of `self` onto + ///`rhs`, in rhs words the result of `self - self.project_onto(rhs)`. + /// + ///`rhs` must be normalized. + /// + ///# Panics + /// + ///Will panic if `rhs` is not normalized when `glam_assert` is enabled. + reject_from_normalized(self:self) -> self, + + ///Returns a vector containing the nearest integer to a number for each element of `self`. + ///Round half-way cases away from 0.0. + round(self:) -> self, + + ///Returns a vector containing the largest integer less than or equal to a number for each + ///element of `self`. + floor(self:) -> self, + + ///Returns a vector containing the smallest integer greater than or equal to a number for + ///each element of `self`. + ceil(self:) -> self, + + ///Returns a vector containing the fractional part of the vector, e.g. `self - + ///self.floor()`. + /// + ///Note that this is fast but not precise for large numbers. + fract(self:) -> self, + + ///Returns a vector containing `e^self` (the exponential function) for each element of + ///`self`. + exp(self:) -> self, + + ///Returns a vector containing each element of `self` raised to the power of `n`. + powf(self:Raw(f64)) -> self, + + ///Returns a vector containing the reciprocal `1.0/n` of each element of `self`. + recip(self:) -> self, + + ///Performs a linear interpolation between `self` and `rhs` based on the value `s`. + /// + ///When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result + ///will be equal to `rhs`. When `s` is outside of range `[0, 1]`, the result is linearly + ///extrapolated. + lerp(self:self,Raw(f64)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` is + ///less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two vectors contain similar elements. It works best when + ///comparing with a known value. The `max_abs_diff` that should be used used depends on + ///the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(self:self,Raw(f64)) -> Raw(bool), + + ///Returns a vector with a length no less than `min` and no more than `max` + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp_length(self:Raw(f64),Raw(f64)) -> self, + + ///Returns a vector with a length no more than `max` + clamp_length_max(self:Raw(f64)) -> self, + + ///Returns a vector with a length no less than `min` + clamp_length_min(self:Raw(f64)) -> self, + + ///Fused multiply-add. Computes `(self * a) + b` element-wise with only one rounding + ///error, yielding a more accurate result than an unfused multiply-add. + /// + ///Using `mul_add` *may* be more performant than an unfused multiply-add if the target + ///architecture has a dedicated fma CPU instruction. However, this is not always true, + ///and will be heavily dependant on designing algorithms with specific target hardware in + ///mind. + mul_add(self:self,self) -> self, + + ///Casts all elements of `self` to `f32`. + as_vec4(&self:) -> Wrapped(Vec4), + + ///Casts all elements of `self` to `i32`. + as_ivec4(&self:) -> Wrapped(IVec4), + + ///Casts all elements of `self` to `u32`. + as_uvec4(&self:) -> Wrapped(UVec4), + + ) + + Fields + ( + x: Raw(f64), + y: Raw(f64), + z: Raw(f64), + w: Raw(f64), + ) + + BinOps + ( + self Add self -> Wrapped(DVec4), + self Add Raw(f64) -> Wrapped(DVec4), + self Add Wrapped(DVec4) -> Wrapped(DVec4), + self Sub self -> Wrapped(DVec4), + self Sub Raw(f64) -> Wrapped(DVec4), + self Sub Wrapped(DVec4) -> Wrapped(DVec4), + self Div self -> Wrapped(DVec4), + self Div Raw(f64) -> Wrapped(DVec4), + self Div Wrapped(DVec4) -> Wrapped(DVec4), + self Mul self -> Wrapped(DVec4), + self Mul Raw(f64) -> Wrapped(DVec4), + self Mul Wrapped(DVec4) -> Wrapped(DVec4), + self Rem self -> Wrapped(DVec4), + self Rem Raw(f64) -> Wrapped(DVec4), + self Rem Wrapped(DVec4) -> Wrapped(DVec4), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,f64)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 2-dimensional vector. + glam::i32::ivec2::IVec2 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(i32),Raw(i32)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(i32)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec2),self,self) -> self, + + ///Creates a 3D vector from `self` and the given `z` value. + extend(self:Raw(i32)) -> Wrapped(IVec3), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(i32), + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(i32), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(i32), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec2), + + ///Returns a vector containing the absolute value of each element of `self`. + abs(self:) -> self, + + ///Returns a vector with elements representing the sign of `self`. + /// + ///- `1.0` if the number is positive, `+0.0` or `INFINITY` + ///- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + ///- `NAN` if the number is `NAN` + signum(self:) -> self, + + ///Returns a vector that is equal to `self` rotated by 90 degrees. + perp(self:) -> self, + + ///The perpendicular dot product of `self` and `rhs`. + ///Also known as the wedge product, 2D cross product, and determinant. + perp_dot(self:self) -> Raw(i32), + + ///Returns `rhs` rotated by the angle of `self`. If `self` is normalized, + ///then this just rotation. This is what you usually want. Otherwise, + ///it will be like a rotation with a multiplication by `self`'s length. + rotate(self:self) -> self, + + ///Casts all elements of `self` to `f32`. + as_vec2(&self:) -> Wrapped(Vec2), + + ///Casts all elements of `self` to `f64`. + as_dvec2(&self:) -> Wrapped(DVec2), + + ///Casts all elements of `self` to `u32`. + as_uvec2(&self:) -> Wrapped(UVec2), + + ) + + Fields + ( + x: Raw(i32), + y: Raw(i32), + ) + + BinOps + ( + self Add self -> Wrapped(IVec2), + self Add Raw(i32) -> Wrapped(IVec2), + self Add Wrapped(IVec2) -> Wrapped(IVec2), + self Sub self -> Wrapped(IVec2), + self Sub Raw(i32) -> Wrapped(IVec2), + self Sub Wrapped(IVec2) -> Wrapped(IVec2), + self Div self -> Wrapped(IVec2), + self Div Raw(i32) -> Wrapped(IVec2), + self Div Wrapped(IVec2) -> Wrapped(IVec2), + self Mul self -> Wrapped(IVec2), + self Mul Raw(i32) -> Wrapped(IVec2), + self Mul Wrapped(IVec2) -> Wrapped(IVec2), + self Rem self -> Wrapped(IVec2), + self Rem Raw(i32) -> Wrapped(IVec2), + self Rem Wrapped(IVec2) -> Wrapped(IVec2), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,i32)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 3-dimensional vector. + glam::i32::ivec3::IVec3 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(i32),Raw(i32),Raw(i32)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(i32)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec3),self,self) -> self, + + ///Creates a 4D vector from `self` and the given `w` value. + extend(self:Raw(i32)) -> Wrapped(IVec4), + + ///Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. + /// + ///Truncation may also be performed by using `self.xy()` or `IVec2::from()`. + truncate(self:) -> Wrapped(IVec2), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(i32), + + ///Computes the cross product of `self` and `rhs`. + cross(self:self) -> self, + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(i32), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(i32), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec3), + + ///Returns a vector containing the absolute value of each element of `self`. + abs(self:) -> self, + + ///Returns a vector with elements representing the sign of `self`. + /// + ///- `1.0` if the number is positive, `+0.0` or `INFINITY` + ///- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + ///- `NAN` if the number is `NAN` + signum(self:) -> self, + + ///Casts all elements of `self` to `f32`. + as_vec3(&self:) -> Wrapped(Vec3), + + ///Casts all elements of `self` to `f32`. + as_vec3a(&self:) -> Wrapped(Vec3A), + + ///Casts all elements of `self` to `f64`. + as_dvec3(&self:) -> Wrapped(DVec3), + + ///Casts all elements of `self` to `u32`. + as_uvec3(&self:) -> Wrapped(UVec3), + + ) + + Fields + ( + x: Raw(i32), + y: Raw(i32), + z: Raw(i32), + ) + + BinOps + ( + self Add self -> Wrapped(IVec3), + self Add Raw(i32) -> Wrapped(IVec3), + self Add Wrapped(IVec3) -> Wrapped(IVec3), + self Sub self -> Wrapped(IVec3), + self Sub Raw(i32) -> Wrapped(IVec3), + self Sub Wrapped(IVec3) -> Wrapped(IVec3), + self Div self -> Wrapped(IVec3), + self Div Raw(i32) -> Wrapped(IVec3), + self Div Wrapped(IVec3) -> Wrapped(IVec3), + self Mul self -> Wrapped(IVec3), + self Mul Raw(i32) -> Wrapped(IVec3), + self Mul Wrapped(IVec3) -> Wrapped(IVec3), + self Rem self -> Wrapped(IVec3), + self Rem Raw(i32) -> Wrapped(IVec3), + self Rem Wrapped(IVec3) -> Wrapped(IVec3), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,i32)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 4-dimensional vector. + glam::i32::ivec4::IVec4 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(i32),Raw(i32),Raw(i32),Raw(i32)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(i32)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec4),self,self) -> self, + + ///Creates a 2D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. + /// + ///Truncation to `IVec3` may also be performed by using `self.xyz()` or `IVec3::from()`. + truncate(self:) -> Wrapped(IVec3), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(i32), + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(i32), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(i32), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec4), + + ///Returns a vector containing the absolute value of each element of `self`. + abs(self:) -> self, + + ///Returns a vector with elements representing the sign of `self`. + /// + ///- `1.0` if the number is positive, `+0.0` or `INFINITY` + ///- `-1.0` if the number is negative, `-0.0` or `NEG_INFINITY` + ///- `NAN` if the number is `NAN` + signum(self:) -> self, + + ///Casts all elements of `self` to `f32`. + as_vec4(&self:) -> Wrapped(Vec4), + + ///Casts all elements of `self` to `f64`. + as_dvec4(&self:) -> Wrapped(DVec4), + + ///Casts all elements of `self` to `u32`. + as_uvec4(&self:) -> Wrapped(UVec4), + + ) + + Fields + ( + x: Raw(i32), + y: Raw(i32), + z: Raw(i32), + w: Raw(i32), + ) + + BinOps + ( + self Add self -> Wrapped(IVec4), + self Add Raw(i32) -> Wrapped(IVec4), + self Add Wrapped(IVec4) -> Wrapped(IVec4), + self Sub self -> Wrapped(IVec4), + self Sub Raw(i32) -> Wrapped(IVec4), + self Sub Wrapped(IVec4) -> Wrapped(IVec4), + self Div self -> Wrapped(IVec4), + self Div Raw(i32) -> Wrapped(IVec4), + self Div Wrapped(IVec4) -> Wrapped(IVec4), + self Mul self -> Wrapped(IVec4), + self Mul Raw(i32) -> Wrapped(IVec4), + self Mul Wrapped(IVec4) -> Wrapped(IVec4), + self Rem self -> Wrapped(IVec4), + self Rem Raw(i32) -> Wrapped(IVec4), + self Rem Wrapped(IVec4) -> Wrapped(IVec4), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,i32)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 2-dimensional vector. + glam::u32::uvec2::UVec2 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(u32),Raw(u32)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(u32)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec2),self,self) -> self, + + ///Creates a 3D vector from `self` and the given `z` value. + extend(self:Raw(u32)) -> Wrapped(UVec3), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(u32), + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(u32), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(u32), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec2), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec2), + + ///Casts all elements of `self` to `f32`. + as_vec2(&self:) -> Wrapped(Vec2), + + ///Casts all elements of `self` to `f64`. + as_dvec2(&self:) -> Wrapped(DVec2), + + ///Casts all elements of `self` to `i32`. + as_ivec2(&self:) -> Wrapped(IVec2), + + ) + + Fields + ( + x: Raw(u32), + y: Raw(u32), + ) + + BinOps + ( + self Add self -> Wrapped(UVec2), + self Add Raw(u32) -> Wrapped(UVec2), + self Add Wrapped(UVec2) -> Wrapped(UVec2), + self Sub self -> Wrapped(UVec2), + self Sub Raw(u32) -> Wrapped(UVec2), + self Sub Wrapped(UVec2) -> Wrapped(UVec2), + self Div self -> Wrapped(UVec2), + self Div Raw(u32) -> Wrapped(UVec2), + self Div Wrapped(UVec2) -> Wrapped(UVec2), + self Mul self -> Wrapped(UVec2), + self Mul Raw(u32) -> Wrapped(UVec2), + self Mul Wrapped(UVec2) -> Wrapped(UVec2), + self Rem self -> Wrapped(UVec2), + self Rem Raw(u32) -> Wrapped(UVec2), + self Rem Wrapped(UVec2) -> Wrapped(UVec2), + ) + + UnaryOps + ( + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,u32)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 3-dimensional vector. + glam::u32::uvec3::UVec3 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(u32),Raw(u32),Raw(u32)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(u32)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec3),self,self) -> self, + + ///Creates a 4D vector from `self` and the given `w` value. + extend(self:Raw(u32)) -> Wrapped(UVec4), + + ///Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`. + /// + ///Truncation may also be performed by using `self.xy()` or `UVec2::from()`. + truncate(self:) -> Wrapped(UVec2), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(u32), + + ///Computes the cross product of `self` and `rhs`. + cross(self:self) -> self, + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(u32), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(u32), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec3), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec3), + + ///Casts all elements of `self` to `f32`. + as_vec3(&self:) -> Wrapped(Vec3), + + ///Casts all elements of `self` to `f32`. + as_vec3a(&self:) -> Wrapped(Vec3A), + + ///Casts all elements of `self` to `f64`. + as_dvec3(&self:) -> Wrapped(DVec3), + + ///Casts all elements of `self` to `i32`. + as_ivec3(&self:) -> Wrapped(IVec3), + + ) + + Fields + ( + x: Raw(u32), + y: Raw(u32), + z: Raw(u32), + ) + + BinOps + ( + self Add self -> Wrapped(UVec3), + self Add Raw(u32) -> Wrapped(UVec3), + self Add Wrapped(UVec3) -> Wrapped(UVec3), + self Sub self -> Wrapped(UVec3), + self Sub Raw(u32) -> Wrapped(UVec3), + self Sub Wrapped(UVec3) -> Wrapped(UVec3), + self Div self -> Wrapped(UVec3), + self Div Raw(u32) -> Wrapped(UVec3), + self Div Wrapped(UVec3) -> Wrapped(UVec3), + self Mul self -> Wrapped(UVec3), + self Mul Raw(u32) -> Wrapped(UVec3), + self Mul Wrapped(UVec3) -> Wrapped(UVec3), + self Rem self -> Wrapped(UVec3), + self Rem Raw(u32) -> Wrapped(UVec3), + self Rem Wrapped(UVec3) -> Wrapped(UVec3), + ) + + UnaryOps + ( + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,u32)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 4-dimensional vector. + glam::u32::uvec4::UVec4 : + Clone + + Debug + + Methods + ( + ///Creates a new vector. + new(Raw(u32),Raw(u32),Raw(u32),Raw(u32)) -> self, + + ///Creates a vector with all elements set to `v`. + splat(Raw(u32)) -> self, + + ///Creates a vector from the elements in `if_true` and `if_false`, selecting which to use + ///for each element of `self`. + /// + ///A true element in the mask uses the corresponding element from `if_true`, and false + ///uses the element from `if_false`. + select(Wrapped(BVec4),self,self) -> self, + + ///Creates a 2D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. + /// + ///Truncation to `UVec3` may also be performed by using `self.xyz()` or `UVec3::from()`. + truncate(self:) -> Wrapped(UVec3), + + ///Computes the dot product of `self` and `rhs`. + dot(self:self) -> Raw(u32), + + ///Returns a vector containing the minimum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. + min(self:self) -> self, + + ///Returns a vector containing the maximum values for each element of `self` and `rhs`. + /// + ///In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. + max(self:self) -> self, + + ///Component-wise clamping of values, similar to [`f32::clamp`]. + /// + ///Each element in `min` must be less-or-equal to the corresponding element in `max`. + /// + ///# Panics + /// + ///Will panic if `min` is greater than `max` when `glam_assert` is enabled. + clamp(self:self,self) -> self, + + ///Returns the horizontal minimum of `self`. + /// + ///In other words this computes `min(x, y, ..)`. + min_element(self:) -> Raw(u32), + + ///Returns the horizontal maximum of `self`. + /// + ///In other words this computes `max(x, y, ..)`. + max_element(self:) -> Raw(u32), + + ///Returns a vector mask containing the result of a `==` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all + ///elements. + cmpeq(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `!=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all + ///elements. + cmpne(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `>=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all + ///elements. + cmpge(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `>` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all + ///elements. + cmpgt(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `<=` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all + ///elements. + cmple(self:self) -> Wrapped(BVec4), + + ///Returns a vector mask containing the result of a `<` comparison for each element of + ///`self` and `rhs`. + /// + ///In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all + ///elements. + cmplt(self:self) -> Wrapped(BVec4), + + ///Casts all elements of `self` to `f32`. + as_vec4(&self:) -> Wrapped(Vec4), + + ///Casts all elements of `self` to `f64`. + as_dvec4(&self:) -> Wrapped(DVec4), + + ///Casts all elements of `self` to `i32`. + as_ivec4(&self:) -> Wrapped(IVec4), + + ) + + Fields + ( + x: Raw(u32), + y: Raw(u32), + z: Raw(u32), + w: Raw(u32), + ) + + BinOps + ( + self Add self -> Wrapped(UVec4), + self Add Raw(u32) -> Wrapped(UVec4), + self Add Wrapped(UVec4) -> Wrapped(UVec4), + self Sub self -> Wrapped(UVec4), + self Sub Raw(u32) -> Wrapped(UVec4), + self Sub Wrapped(UVec4) -> Wrapped(UVec4), + self Div self -> Wrapped(UVec4), + self Div Raw(u32) -> Wrapped(UVec4), + self Div Wrapped(UVec4) -> Wrapped(UVec4), + self Mul self -> Wrapped(UVec4), + self Mul Raw(u32) -> Wrapped(UVec4), + self Mul Wrapped(UVec4) -> Wrapped(UVec4), + self Rem self -> Wrapped(UVec4), + self Rem Raw(u32) -> Wrapped(UVec4), + self Rem Wrapped(UVec4) -> Wrapped(UVec4), + ) + + UnaryOps + ( + ) + impl + { + (MetaMethod::Index) => |_,s,idx: usize| {Ok(s.inner()?[idx])}; + mut (MetaMethod::NewIndex) => |_,s,(idx,val): (usize,u32)| {s.val_mut(|s| Ok(s[idx] = val))?}; + } +} +impl_script_newtype! { + ///A 3x3 column major matrix. + /// + ///This 3x3 matrix type features convenience methods for creating and using linear and + ///affine transformations. If you are primarily dealing with 2D affine transformations the + ///[`Affine2`](crate::Affine2) type is much faster and more space efficient than + ///using a 3x3 matrix. + /// + ///Linear transformations including 3D rotation and scale can be created using methods + ///such as [`Self::from_diagonal()`], [`Self::from_quat()`], [`Self::from_axis_angle()`], + ///[`Self::from_rotation_x()`], [`Self::from_rotation_y()`], or + ///[`Self::from_rotation_z()`]. + /// + ///The resulting matrices can be use to transform 3D vectors using regular vector + ///multiplication. + /// + ///Affine transformations including 2D translation, rotation and scale can be created + ///using methods such as [`Self::from_translation()`], [`Self::from_angle()`], + ///[`Self::from_scale()`] and [`Self::from_scale_angle_translation()`]. + /// + ///The [`Self::transform_point2()`] and [`Self::transform_vector2()`] convenience methods + ///are provided for performing affine transforms on 2D vectors and points. These multiply + ///2D inputs as 3D vectors with an implicit `z` value of `1` for points and `0` for + ///vectors respectively. These methods assume that `Self` contains a valid affine + ///transform. + glam::f32::mat3::Mat3 : + Clone + + Debug + + Methods + ( + ///Creates a 3x3 matrix from two column vectors. + from_cols(Wrapped(Vec3),Wrapped(Vec3),Wrapped(Vec3)) -> self, + + ///Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal(Wrapped(Vec3)) -> self, + + ///Creates a 3x3 matrix from a 4x4 matrix, discarding the 3rd row and column. + from_mat4(Wrapped(Mat4)) -> self, + + ///Creates a 3D rotation matrix from the given quaternion. + /// + ///# Panics + /// + ///Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat(Wrapped(Quat)) -> self, + + ///Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in + ///radians). + /// + ///# Panics + /// + ///Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle(Wrapped(Vec3),Raw(f32)) -> self, + + ///Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in + ///radians). + from_euler(Wrapped(EulerRot),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + from_rotation_x(Raw(f32)) -> self, + + ///Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + from_rotation_y(Raw(f32)) -> self, + + ///Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + from_rotation_z(Raw(f32)) -> self, + + ///Creates an affine transformation matrix from the given 2D `translation`. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_translation(Wrapped(Vec2)) -> self, + + ///Creates an affine transformation matrix from the given 2D rotation `angle` (in + ///radians). + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_angle(Raw(f32)) -> self, + + ///Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in + ///radians) and `translation`. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_scale_angle_translation(Wrapped(Vec2),Raw(f32),Wrapped(Vec2)) -> self, + + ///Creates an affine transformation matrix from the given non-uniform 2D `scale`. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + /// + ///# Panics + /// + ///Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale(Wrapped(Vec2)) -> self, + + ///Creates an affine transformation matrix from the given 2x2 matrix. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_mat2(Wrapped(Mat2)) -> self, + + ///Returns the matrix column for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 2. + col(&self:Raw(usize)) -> Wrapped(Vec3), + + ///Returns the matrix row for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 2. + row(&self:Raw(usize)) -> Wrapped(Vec3), + + ///Returns `true` if, and only if, all elements are finite. + ///If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite(&self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(&self:) -> Raw(bool), + + ///Returns the transpose of `self`. + transpose(&self:) -> self, + + ///Returns the determinant of `self`. + determinant(&self:) -> Raw(f32), + + ///Returns the inverse of `self`. + /// + ///If the matrix is not invertible the returned matrix will be invalid. + /// + ///# Panics + /// + ///Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse(&self:) -> self, + + ///Transforms the given 2D vector as a point. + /// + ///This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. + /// + ///This method assumes that `self` contains a valid affine transform. + transform_point2(&self:Wrapped(Vec2)) -> Wrapped(Vec2), + + ///Rotates the given 2D vector. + /// + ///This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. + /// + ///This method assumes that `self` contains a valid affine transform. + transform_vector2(&self:Wrapped(Vec2)) -> Wrapped(Vec2), + + ///Transforms a 3D vector. + mul_vec3(&self:Wrapped(Vec3)) -> Wrapped(Vec3), + + ///Transforms a `Vec3A`. + mul_vec3a(&self:Wrapped(Vec3A)) -> Wrapped(Vec3A), + + ///Multiplies two 3x3 matrices. + mul_mat3(&self:&self) -> self, + + ///Adds two 3x3 matrices. + add_mat3(&self:&self) -> self, + + ///Subtracts two 3x3 matrices. + sub_mat3(&self:&self) -> self, + + ///Multiplies a 3x3 matrix by a scalar. + mul_scalar(&self:Raw(f32)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two matrices contain similar elements. It works best + ///when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(&self:self,Raw(f32)) -> Raw(bool), + + as_dmat3(&self:) -> Wrapped(DMat3), + + ) + + Fields + ( + x_axis: Wrapped(Vec3), + y_axis: Wrapped(Vec3), + z_axis: Wrapped(Vec3), + ) + + BinOps + ( + self Add self -> Wrapped(Mat3), + self Sub self -> Wrapped(Mat3), + self Mul Wrapped(Affine2) -> Wrapped(Mat3), + self Mul self -> Wrapped(Mat3), + self Mul Wrapped(Vec3) -> Wrapped(Vec3), + self Mul Wrapped(Mat3) -> Wrapped(Mat3), + self Mul Raw(f32) -> Wrapped(Mat3), + self Mul Wrapped(Vec3A) -> Wrapped(Vec3A), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaVec3::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat3".into()}) + } + } + }) + ) + ) + } +; + } +} +impl_script_newtype! { + ///A 2x2 column major matrix. + glam::f32::sse2::mat2::Mat2 : + Clone + + Debug + + Methods + ( + ///Creates a 2x2 matrix from two column vectors. + from_cols(Wrapped(Vec2),Wrapped(Vec2)) -> self, + + ///Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal(Wrapped(Vec2)) -> self, + + ///Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of + ///`angle` (in radians). + from_scale_angle(Wrapped(Vec2),Raw(f32)) -> self, + + ///Creates a 2x2 matrix containing a rotation of `angle` (in radians). + from_angle(Raw(f32)) -> self, + + ///Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + from_mat3(Wrapped(Mat3)) -> self, + + ///Returns the matrix column for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 1. + col(&self:Raw(usize)) -> Wrapped(Vec2), + + ///Returns the matrix row for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 1. + row(&self:Raw(usize)) -> Wrapped(Vec2), + + ///Returns `true` if, and only if, all elements are finite. + ///If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite(&self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(&self:) -> Raw(bool), + + ///Returns the transpose of `self`. + transpose(&self:) -> self, + + ///Returns the determinant of `self`. + determinant(&self:) -> Raw(f32), + + ///Returns the inverse of `self`. + /// + ///If the matrix is not invertible the returned matrix will be invalid. + /// + ///# Panics + /// + ///Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse(&self:) -> self, + + ///Transforms a 2D vector. + mul_vec2(&self:Wrapped(Vec2)) -> Wrapped(Vec2), + + ///Multiplies two 2x2 matrices. + mul_mat2(&self:&self) -> self, + + ///Adds two 2x2 matrices. + add_mat2(&self:&self) -> self, + + ///Subtracts two 2x2 matrices. + sub_mat2(&self:&self) -> self, + + ///Multiplies a 2x2 matrix by a scalar. + mul_scalar(&self:Raw(f32)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two matrices contain similar elements. It works best + ///when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(&self:self,Raw(f32)) -> Raw(bool), + + as_dmat2(&self:) -> Wrapped(DMat2), + + ) + + Fields + ( + ) + + BinOps + ( + self Add self -> Wrapped(Mat2), + self Sub self -> Wrapped(Mat2), + self Mul self -> Wrapped(Mat2), + self Mul Wrapped(Vec2) -> Wrapped(Vec2), + self Mul Wrapped(Mat2) -> Wrapped(Mat2), + self Mul Raw(f32) -> Wrapped(Mat2), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaVec2::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat2".into()}) + } + } + }) + ) + ) + } +; + } +} +impl_script_newtype! { + ///A 3x3 column major matrix. + /// + ///This 3x3 matrix type features convenience methods for creating and using linear and + ///affine transformations. If you are primarily dealing with 2D affine transformations the + ///[`Affine2`](crate::Affine2) type is much faster and more space efficient than + ///using a 3x3 matrix. + /// + ///Linear transformations including 3D rotation and scale can be created using methods + ///such as [`Self::from_diagonal()`], [`Self::from_quat()`], [`Self::from_axis_angle()`], + ///[`Self::from_rotation_x()`], [`Self::from_rotation_y()`], or + ///[`Self::from_rotation_z()`]. + /// + ///The resulting matrices can be use to transform 3D vectors using regular vector + ///multiplication. + /// + ///Affine transformations including 2D translation, rotation and scale can be created + ///using methods such as [`Self::from_translation()`], [`Self::from_angle()`], + ///[`Self::from_scale()`] and [`Self::from_scale_angle_translation()`]. + /// + ///The [`Self::transform_point2()`] and [`Self::transform_vector2()`] convenience methods + ///are provided for performing affine transforms on 2D vectors and points. These multiply + ///2D inputs as 3D vectors with an implicit `z` value of `1` for points and `0` for + ///vectors respectively. These methods assume that `Self` contains a valid affine + ///transform. + glam::f32::sse2::mat3::Mat3A : + Clone + + Debug + + Methods + ( + ///Creates a 3x3 matrix from two column vectors. + from_cols(Wrapped(Vec3A),Wrapped(Vec3A),Wrapped(Vec3A)) -> self, + + ///Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal(Wrapped(Vec3)) -> self, + + ///Creates a 3x3 matrix from a 4x4 matrix, discarding the 3rd row and column. + from_mat4(Wrapped(Mat4)) -> self, + + ///Creates a 3D rotation matrix from the given quaternion. + /// + ///# Panics + /// + ///Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat(Wrapped(Quat)) -> self, + + ///Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in + ///radians). + /// + ///# Panics + /// + ///Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle(Wrapped(Vec3),Raw(f32)) -> self, + + ///Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in + ///radians). + from_euler(Wrapped(EulerRot),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + from_rotation_x(Raw(f32)) -> self, + + ///Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + from_rotation_y(Raw(f32)) -> self, + + ///Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + from_rotation_z(Raw(f32)) -> self, + + ///Creates an affine transformation matrix from the given 2D `translation`. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_translation(Wrapped(Vec2)) -> self, + + ///Creates an affine transformation matrix from the given 2D rotation `angle` (in + ///radians). + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_angle(Raw(f32)) -> self, + + ///Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in + ///radians) and `translation`. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_scale_angle_translation(Wrapped(Vec2),Raw(f32),Wrapped(Vec2)) -> self, + + ///Creates an affine transformation matrix from the given non-uniform 2D `scale`. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + /// + ///# Panics + /// + ///Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale(Wrapped(Vec2)) -> self, + + ///Creates an affine transformation matrix from the given 2x2 matrix. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_mat2(Wrapped(Mat2)) -> self, + + ///Returns the matrix column for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 2. + col(&self:Raw(usize)) -> Wrapped(Vec3A), + + ///Returns the matrix row for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 2. + row(&self:Raw(usize)) -> Wrapped(Vec3A), + + ///Returns `true` if, and only if, all elements are finite. + ///If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite(&self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(&self:) -> Raw(bool), + + ///Returns the transpose of `self`. + transpose(&self:) -> self, + + ///Returns the determinant of `self`. + determinant(&self:) -> Raw(f32), + + ///Returns the inverse of `self`. + /// + ///If the matrix is not invertible the returned matrix will be invalid. + /// + ///# Panics + /// + ///Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse(&self:) -> self, + + ///Transforms the given 2D vector as a point. + /// + ///This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. + /// + ///This method assumes that `self` contains a valid affine transform. + transform_point2(&self:Wrapped(Vec2)) -> Wrapped(Vec2), + + ///Rotates the given 2D vector. + /// + ///This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. + /// + ///This method assumes that `self` contains a valid affine transform. + transform_vector2(&self:Wrapped(Vec2)) -> Wrapped(Vec2), + + ///Transforms a 3D vector. + mul_vec3(&self:Wrapped(Vec3)) -> Wrapped(Vec3), + + ///Transforms a `Vec3A`. + mul_vec3a(&self:Wrapped(Vec3A)) -> Wrapped(Vec3A), + + ///Multiplies two 3x3 matrices. + mul_mat3(&self:&self) -> self, + + ///Adds two 3x3 matrices. + add_mat3(&self:&self) -> self, + + ///Subtracts two 3x3 matrices. + sub_mat3(&self:&self) -> self, + + ///Multiplies a 3x3 matrix by a scalar. + mul_scalar(&self:Raw(f32)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two matrices contain similar elements. It works best + ///when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(&self:self,Raw(f32)) -> Raw(bool), + + as_dmat3(&self:) -> Wrapped(DMat3), + + ) + + Fields + ( + x_axis: Wrapped(Vec3A), + y_axis: Wrapped(Vec3A), + z_axis: Wrapped(Vec3A), + ) + + BinOps + ( + self Add self -> Wrapped(Mat3A), + self Sub self -> Wrapped(Mat3A), + self Mul Wrapped(Affine2) -> Wrapped(Mat3A), + self Mul self -> Wrapped(Mat3A), + self Mul Wrapped(Vec3A) -> Wrapped(Vec3A), + self Mul Wrapped(Mat3A) -> Wrapped(Mat3A), + self Mul Raw(f32) -> Wrapped(Mat3A), + self Mul Wrapped(Vec3) -> Wrapped(Vec3), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaVec3A::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat3A".into()}) + } + } + }) + ) + ) + } +; + } +} +impl_script_newtype! { + ///A 4x4 column major matrix. + /// + ///This 4x4 matrix type features convenience methods for creating and using affine transforms and + ///perspective projections. If you are primarily dealing with 3D affine transformations + ///considering using [`Affine3A`](crate::Affine3A) which is faster than a 4x4 matrix + ///for some affine operations. + /// + ///Affine transformations including 3D translation, rotation and scale can be created + ///using methods such as [`Self::from_translation()`], [`Self::from_quat()`], + ///[`Self::from_scale()`] and [`Self::from_scale_rotation_translation()`]. + /// + ///Othographic projections can be created using the methods [`Self::orthographic_lh()`] for + ///left-handed coordinate systems and [`Self::orthographic_rh()`] for right-handed + ///systems. The resulting matrix is also an affine transformation. + /// + ///The [`Self::transform_point3()`] and [`Self::transform_vector3()`] convenience methods + ///are provided for performing affine transformations on 3D vectors and points. These + ///multiply 3D inputs as 4D vectors with an implicit `w` value of `1` for points and `0` + ///for vectors respectively. These methods assume that `Self` contains a valid affine + ///transform. + /// + ///Perspective projections can be created using methods such as + ///[`Self::perspective_lh()`], [`Self::perspective_infinite_lh()`] and + ///[`Self::perspective_infinite_reverse_lh()`] for left-handed co-ordinate systems and + ///[`Self::perspective_rh()`], [`Self::perspective_infinite_rh()`] and + ///[`Self::perspective_infinite_reverse_rh()`] for right-handed co-ordinate systems. + /// + ///The resulting perspective project can be use to transform 3D vectors as points with + ///perspective correction using the [`Self::project_point3()`] convenience method. + glam::f32::sse2::mat4::Mat4 : + Clone + + Debug + + Methods + ( + ///Creates a 4x4 matrix from two column vectors. + from_cols(Wrapped(Vec4),Wrapped(Vec4),Wrapped(Vec4),Wrapped(Vec4)) -> self, + + ///Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal(Wrapped(Vec4)) -> self, + + ///Creates an affine transformation matrix from the given 3D `scale`, `rotation` and + ///`translation`. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + /// + ///# Panics + /// + ///Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_scale_rotation_translation(Wrapped(Vec3),Wrapped(Quat),Wrapped(Vec3)) -> self, + + ///Creates an affine transformation matrix from the given 3D `translation`. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + /// + ///# Panics + /// + ///Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_rotation_translation(Wrapped(Quat),Wrapped(Vec3)) -> self, + + ///Creates an affine transformation matrix from the given `rotation` quaternion. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + /// + ///# Panics + /// + ///Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat(Wrapped(Quat)) -> self, + + ///Creates an affine transformation matrix from the given 3x3 linear transformation + ///matrix. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_mat3(Wrapped(Mat3)) -> self, + + ///Creates an affine transformation matrix from the given 3D `translation`. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_translation(Wrapped(Vec3)) -> self, + + ///Creates an affine transformation matrix containing a 3D rotation around a normalized + ///rotation `axis` of `angle` (in radians). + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + /// + ///# Panics + /// + ///Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle(Wrapped(Vec3),Raw(f32)) -> self, + + ///Creates a affine transformation matrix containing a rotation from the given euler + ///rotation sequence and angles (in radians). + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_euler(Wrapped(EulerRot),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates an affine transformation matrix containing a 3D rotation around the x axis of + ///`angle` (in radians). + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_x(Raw(f32)) -> self, + + ///Creates an affine transformation matrix containing a 3D rotation around the y axis of + ///`angle` (in radians). + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_y(Raw(f32)) -> self, + + ///Creates an affine transformation matrix containing a 3D rotation around the z axis of + ///`angle` (in radians). + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_z(Raw(f32)) -> self, + + ///Creates an affine transformation matrix containing the given 3D non-uniform `scale`. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + /// + ///# Panics + /// + ///Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale(Wrapped(Vec3)) -> self, + + ///Returns the matrix column for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 3. + col(&self:Raw(usize)) -> Wrapped(Vec4), + + ///Returns the matrix row for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 3. + row(&self:Raw(usize)) -> Wrapped(Vec4), + + ///Returns `true` if, and only if, all elements are finite. + ///If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite(&self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(&self:) -> Raw(bool), + + ///Returns the transpose of `self`. + transpose(&self:) -> self, + + ///Returns the determinant of `self`. + determinant(&self:) -> Raw(f32), + + ///Returns the inverse of `self`. + /// + ///If the matrix is not invertible the returned matrix will be invalid. + /// + ///# Panics + /// + ///Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse(&self:) -> self, + + ///Creates a left-handed view matrix using a camera position, an up direction, and a focal + ///point. + ///For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + /// + ///# Panics + /// + ///Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh(Wrapped(Vec3),Wrapped(Vec3),Wrapped(Vec3)) -> self, + + ///Creates a right-handed view matrix using a camera position, an up direction, and a focal + ///point. + ///For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + /// + ///# Panics + /// + ///Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh(Wrapped(Vec3),Wrapped(Vec3),Wrapped(Vec3)) -> self, + + ///Creates a right-handed perspective projection matrix with [-1,1] depth range. + ///This is the same as the OpenGL `gluPerspective` function. + ///See + perspective_rh_gl(Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a left-handed perspective projection matrix with `[0,1]` depth range. + /// + ///# Panics + /// + ///Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + ///enabled. + perspective_lh(Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a right-handed perspective projection matrix with `[0,1]` depth range. + /// + ///# Panics + /// + ///Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + ///enabled. + perspective_rh(Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + /// + ///# Panics + /// + ///Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_lh(Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + /// + ///# Panics + /// + ///Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_reverse_lh(Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates an infinite right-handed perspective projection matrix with + ///`[0,1]` depth range. + perspective_infinite_rh(Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates an infinite reverse right-handed perspective projection matrix + ///with `[0,1]` depth range. + perspective_infinite_reverse_rh(Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a right-handed orthographic projection matrix with `[-1,1]` depth + ///range. This is the same as the OpenGL `glOrtho` function in OpenGL. + ///See + /// + orthographic_rh_gl(Raw(f32),Raw(f32),Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a left-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_lh(Raw(f32),Raw(f32),Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a right-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_rh(Raw(f32),Raw(f32),Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Transforms the given 3D vector as a point, applying perspective correction. + /// + ///This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is `1.0`. + ///The perspective divide is performed meaning the resulting 3D vector is divided by `w`. + /// + ///This method assumes that `self` contains a projective transform. + project_point3(&self:Wrapped(Vec3)) -> Wrapped(Vec3), + + ///Transforms the given 3D vector as a point. + /// + ///This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is + ///`1.0`. + /// + ///This method assumes that `self` contains a valid affine transform. It does not perform + ///a persective divide, if `self` contains a perspective transform, or if you are unsure, + ///the [`Self::project_point3()`] method should be used instead. + /// + ///# Panics + /// + ///Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + transform_point3(&self:Wrapped(Vec3)) -> Wrapped(Vec3), + + ///Transforms the give 3D vector as a direction. + /// + ///This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is + ///`0.0`. + /// + ///This method assumes that `self` contains a valid affine transform. + /// + ///# Panics + /// + ///Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + transform_vector3(&self:Wrapped(Vec3)) -> Wrapped(Vec3), + + ///Transforms the given `Vec3A` as 3D point. + /// + ///This is the equivalent of multiplying the `Vec3A` as a 4D vector where `w` is `1.0`. + transform_point3a(&self:Wrapped(Vec3A)) -> Wrapped(Vec3A), + + ///Transforms the give `Vec3A` as 3D vector. + /// + ///This is the equivalent of multiplying the `Vec3A` as a 4D vector where `w` is `0.0`. + transform_vector3a(&self:Wrapped(Vec3A)) -> Wrapped(Vec3A), + + ///Transforms a 4D vector. + mul_vec4(&self:Wrapped(Vec4)) -> Wrapped(Vec4), + + ///Multiplies two 4x4 matrices. + mul_mat4(&self:&self) -> self, + + ///Adds two 4x4 matrices. + add_mat4(&self:&self) -> self, + + ///Subtracts two 4x4 matrices. + sub_mat4(&self:&self) -> self, + + ///Multiplies a 4x4 matrix by a scalar. + mul_scalar(&self:Raw(f32)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two matrices contain similar elements. It works best + ///when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(&self:self,Raw(f32)) -> Raw(bool), + + as_dmat4(&self:) -> Wrapped(DMat4), + + ) + + Fields + ( + x_axis: Wrapped(Vec4), + y_axis: Wrapped(Vec4), + z_axis: Wrapped(Vec4), + w_axis: Wrapped(Vec4), + ) + + BinOps + ( + self Add self -> Wrapped(Mat4), + self Sub self -> Wrapped(Mat4), + self Mul Wrapped(Affine3A) -> Wrapped(Mat4), + self Mul self -> Wrapped(Mat4), + self Mul Wrapped(Vec4) -> Wrapped(Vec4), + self Mul Wrapped(Mat4) -> Wrapped(Mat4), + self Mul Raw(f32) -> Wrapped(Mat4), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaVec4::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"Mat4".into()}) + } + } + }) + ) + ) + } +; + } +} +impl_script_newtype! { + ///A 2x2 column major matrix. + glam::f64::dmat2::DMat2 : + Clone + + Debug + + Methods + ( + ///Creates a 2x2 matrix from two column vectors. + from_cols(Wrapped(DVec2),Wrapped(DVec2)) -> self, + + ///Creates a 2x2 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal(Wrapped(DVec2)) -> self, + + ///Creates a 2x2 matrix containing the combining non-uniform `scale` and rotation of + ///`angle` (in radians). + from_scale_angle(Wrapped(DVec2),Raw(f64)) -> self, + + ///Creates a 2x2 matrix containing a rotation of `angle` (in radians). + from_angle(Raw(f64)) -> self, + + ///Creates a 2x2 matrix from a 3x3 matrix, discarding the 2nd row and column. + from_mat3(Wrapped(DMat3)) -> self, + + ///Returns the matrix column for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 1. + col(&self:Raw(usize)) -> Wrapped(DVec2), + + ///Returns the matrix row for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 1. + row(&self:Raw(usize)) -> Wrapped(DVec2), + + ///Returns `true` if, and only if, all elements are finite. + ///If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite(&self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(&self:) -> Raw(bool), + + ///Returns the transpose of `self`. + transpose(&self:) -> self, + + ///Returns the determinant of `self`. + determinant(&self:) -> Raw(f64), + + ///Returns the inverse of `self`. + /// + ///If the matrix is not invertible the returned matrix will be invalid. + /// + ///# Panics + /// + ///Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse(&self:) -> self, + + ///Transforms a 2D vector. + mul_vec2(&self:Wrapped(DVec2)) -> Wrapped(DVec2), + + ///Multiplies two 2x2 matrices. + mul_mat2(&self:&self) -> self, + + ///Adds two 2x2 matrices. + add_mat2(&self:&self) -> self, + + ///Subtracts two 2x2 matrices. + sub_mat2(&self:&self) -> self, + + ///Multiplies a 2x2 matrix by a scalar. + mul_scalar(&self:Raw(f64)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two matrices contain similar elements. It works best + ///when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(&self:self,Raw(f64)) -> Raw(bool), + + as_mat2(&self:) -> Wrapped(Mat2), + + ) + + Fields + ( + x_axis: Wrapped(DVec2), + y_axis: Wrapped(DVec2), + ) + + BinOps + ( + self Add self -> Wrapped(DMat2), + self Sub self -> Wrapped(DMat2), + self Mul self -> Wrapped(DMat2), + self Mul Wrapped(DVec2) -> Wrapped(DVec2), + self Mul Wrapped(DMat2) -> Wrapped(DMat2), + self Mul Raw(f64) -> Wrapped(DMat2), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaDVec2::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat2".into()}) + } + } + }) + ) + ) + } +; + } +} +impl_script_newtype! { + ///A 3x3 column major matrix. + /// + ///This 3x3 matrix type features convenience methods for creating and using linear and + ///affine transformations. If you are primarily dealing with 2D affine transformations the + ///[`DAffine2`](crate::DAffine2) type is much faster and more space efficient than + ///using a 3x3 matrix. + /// + ///Linear transformations including 3D rotation and scale can be created using methods + ///such as [`Self::from_diagonal()`], [`Self::from_quat()`], [`Self::from_axis_angle()`], + ///[`Self::from_rotation_x()`], [`Self::from_rotation_y()`], or + ///[`Self::from_rotation_z()`]. + /// + ///The resulting matrices can be use to transform 3D vectors using regular vector + ///multiplication. + /// + ///Affine transformations including 2D translation, rotation and scale can be created + ///using methods such as [`Self::from_translation()`], [`Self::from_angle()`], + ///[`Self::from_scale()`] and [`Self::from_scale_angle_translation()`]. + /// + ///The [`Self::transform_point2()`] and [`Self::transform_vector2()`] convenience methods + ///are provided for performing affine transforms on 2D vectors and points. These multiply + ///2D inputs as 3D vectors with an implicit `z` value of `1` for points and `0` for + ///vectors respectively. These methods assume that `Self` contains a valid affine + ///transform. + glam::f64::dmat3::DMat3 : + Clone + + Debug + + Methods + ( + ///Creates a 3x3 matrix from two column vectors. + from_cols(Wrapped(DVec3),Wrapped(DVec3),Wrapped(DVec3)) -> self, + + ///Creates a 3x3 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal(Wrapped(DVec3)) -> self, + + ///Creates a 3x3 matrix from a 4x4 matrix, discarding the 3rd row and column. + from_mat4(Wrapped(DMat4)) -> self, + + ///Creates a 3D rotation matrix from the given quaternion. + /// + ///# Panics + /// + ///Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat(Wrapped(DQuat)) -> self, + + ///Creates a 3D rotation matrix from a normalized rotation `axis` and `angle` (in + ///radians). + /// + ///# Panics + /// + ///Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle(Wrapped(DVec3),Raw(f64)) -> self, + + ///Creates a 3D rotation matrix from the given euler rotation sequence and the angles (in + ///radians). + from_euler(Wrapped(EulerRot),Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates a 3D rotation matrix from `angle` (in radians) around the x axis. + from_rotation_x(Raw(f64)) -> self, + + ///Creates a 3D rotation matrix from `angle` (in radians) around the y axis. + from_rotation_y(Raw(f64)) -> self, + + ///Creates a 3D rotation matrix from `angle` (in radians) around the z axis. + from_rotation_z(Raw(f64)) -> self, + + ///Creates an affine transformation matrix from the given 2D `translation`. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_translation(Wrapped(DVec2)) -> self, + + ///Creates an affine transformation matrix from the given 2D rotation `angle` (in + ///radians). + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_angle(Raw(f64)) -> self, + + ///Creates an affine transformation matrix from the given 2D `scale`, rotation `angle` (in + ///radians) and `translation`. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_scale_angle_translation(Wrapped(DVec2),Raw(f64),Wrapped(DVec2)) -> self, + + ///Creates an affine transformation matrix from the given non-uniform 2D `scale`. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + /// + ///# Panics + /// + ///Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale(Wrapped(DVec2)) -> self, + + ///Creates an affine transformation matrix from the given 2x2 matrix. + /// + ///The resulting matrix can be used to transform 2D points and vectors. See + ///[`Self::transform_point2()`] and [`Self::transform_vector2()`]. + from_mat2(Wrapped(DMat2)) -> self, + + ///Returns the matrix column for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 2. + col(&self:Raw(usize)) -> Wrapped(DVec3), + + ///Returns the matrix row for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 2. + row(&self:Raw(usize)) -> Wrapped(DVec3), + + ///Returns `true` if, and only if, all elements are finite. + ///If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite(&self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(&self:) -> Raw(bool), + + ///Returns the transpose of `self`. + transpose(&self:) -> self, + + ///Returns the determinant of `self`. + determinant(&self:) -> Raw(f64), + + ///Returns the inverse of `self`. + /// + ///If the matrix is not invertible the returned matrix will be invalid. + /// + ///# Panics + /// + ///Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse(&self:) -> self, + + ///Transforms the given 2D vector as a point. + /// + ///This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `1`. + /// + ///This method assumes that `self` contains a valid affine transform. + transform_point2(&self:Wrapped(DVec2)) -> Wrapped(DVec2), + + ///Rotates the given 2D vector. + /// + ///This is the equivalent of multiplying `rhs` as a 3D vector where `z` is `0`. + /// + ///This method assumes that `self` contains a valid affine transform. + transform_vector2(&self:Wrapped(DVec2)) -> Wrapped(DVec2), + + ///Transforms a 3D vector. + mul_vec3(&self:Wrapped(DVec3)) -> Wrapped(DVec3), + + ///Multiplies two 3x3 matrices. + mul_mat3(&self:&self) -> self, + + ///Adds two 3x3 matrices. + add_mat3(&self:&self) -> self, + + ///Subtracts two 3x3 matrices. + sub_mat3(&self:&self) -> self, + + ///Multiplies a 3x3 matrix by a scalar. + mul_scalar(&self:Raw(f64)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two matrices contain similar elements. It works best + ///when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(&self:self,Raw(f64)) -> Raw(bool), + + as_mat3(&self:) -> Wrapped(Mat3), + + ) + + Fields + ( + x_axis: Wrapped(DVec3), + y_axis: Wrapped(DVec3), + z_axis: Wrapped(DVec3), + ) + + BinOps + ( + self Add self -> Wrapped(DMat3), + self Sub self -> Wrapped(DMat3), + self Mul Wrapped(DAffine2) -> Wrapped(DMat3), + self Mul self -> Wrapped(DMat3), + self Mul Wrapped(DVec3) -> Wrapped(DVec3), + self Mul Wrapped(DMat3) -> Wrapped(DMat3), + self Mul Raw(f64) -> Wrapped(DMat3), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaDVec3::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat3".into()}) + } + } + }) + ) + ) + } +; + } +} +impl_script_newtype! { + ///A 4x4 column major matrix. + /// + ///This 4x4 matrix type features convenience methods for creating and using affine transforms and + ///perspective projections. If you are primarily dealing with 3D affine transformations + ///considering using [`DAffine3`](crate::DAffine3) which is faster than a 4x4 matrix + ///for some affine operations. + /// + ///Affine transformations including 3D translation, rotation and scale can be created + ///using methods such as [`Self::from_translation()`], [`Self::from_quat()`], + ///[`Self::from_scale()`] and [`Self::from_scale_rotation_translation()`]. + /// + ///Othographic projections can be created using the methods [`Self::orthographic_lh()`] for + ///left-handed coordinate systems and [`Self::orthographic_rh()`] for right-handed + ///systems. The resulting matrix is also an affine transformation. + /// + ///The [`Self::transform_point3()`] and [`Self::transform_vector3()`] convenience methods + ///are provided for performing affine transformations on 3D vectors and points. These + ///multiply 3D inputs as 4D vectors with an implicit `w` value of `1` for points and `0` + ///for vectors respectively. These methods assume that `Self` contains a valid affine + ///transform. + /// + ///Perspective projections can be created using methods such as + ///[`Self::perspective_lh()`], [`Self::perspective_infinite_lh()`] and + ///[`Self::perspective_infinite_reverse_lh()`] for left-handed co-ordinate systems and + ///[`Self::perspective_rh()`], [`Self::perspective_infinite_rh()`] and + ///[`Self::perspective_infinite_reverse_rh()`] for right-handed co-ordinate systems. + /// + ///The resulting perspective project can be use to transform 3D vectors as points with + ///perspective correction using the [`Self::project_point3()`] convenience method. + glam::f64::dmat4::DMat4 : + Clone + + Debug + + Methods + ( + ///Creates a 4x4 matrix from two column vectors. + from_cols(Wrapped(DVec4),Wrapped(DVec4),Wrapped(DVec4),Wrapped(DVec4)) -> self, + + ///Creates a 4x4 matrix with its diagonal set to `diagonal` and all other entries set to 0. + from_diagonal(Wrapped(DVec4)) -> self, + + ///Creates an affine transformation matrix from the given 3D `scale`, `rotation` and + ///`translation`. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + /// + ///# Panics + /// + ///Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_scale_rotation_translation(Wrapped(DVec3),Wrapped(DQuat),Wrapped(DVec3)) -> self, + + ///Creates an affine transformation matrix from the given 3D `translation`. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + /// + ///# Panics + /// + ///Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_rotation_translation(Wrapped(DQuat),Wrapped(DVec3)) -> self, + + ///Creates an affine transformation matrix from the given `rotation` quaternion. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + /// + ///# Panics + /// + ///Will panic if `rotation` is not normalized when `glam_assert` is enabled. + from_quat(Wrapped(DQuat)) -> self, + + ///Creates an affine transformation matrix from the given 3x3 linear transformation + ///matrix. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_mat3(Wrapped(DMat3)) -> self, + + ///Creates an affine transformation matrix from the given 3D `translation`. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_translation(Wrapped(DVec3)) -> self, + + ///Creates an affine transformation matrix containing a 3D rotation around a normalized + ///rotation `axis` of `angle` (in radians). + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + /// + ///# Panics + /// + ///Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle(Wrapped(DVec3),Raw(f64)) -> self, + + ///Creates a affine transformation matrix containing a rotation from the given euler + ///rotation sequence and angles (in radians). + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_euler(Wrapped(EulerRot),Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates an affine transformation matrix containing a 3D rotation around the x axis of + ///`angle` (in radians). + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_x(Raw(f64)) -> self, + + ///Creates an affine transformation matrix containing a 3D rotation around the y axis of + ///`angle` (in radians). + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_y(Raw(f64)) -> self, + + ///Creates an affine transformation matrix containing a 3D rotation around the z axis of + ///`angle` (in radians). + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + from_rotation_z(Raw(f64)) -> self, + + ///Creates an affine transformation matrix containing the given 3D non-uniform `scale`. + /// + ///The resulting matrix can be used to transform 3D points and vectors. See + ///[`Self::transform_point3()`] and [`Self::transform_vector3()`]. + /// + ///# Panics + /// + ///Will panic if all elements of `scale` are zero when `glam_assert` is enabled. + from_scale(Wrapped(DVec3)) -> self, + + ///Returns the matrix column for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 3. + col(&self:Raw(usize)) -> Wrapped(DVec4), + + ///Returns the matrix row for the given `index`. + /// + ///# Panics + /// + ///Panics if `index` is greater than 3. + row(&self:Raw(usize)) -> Wrapped(DVec4), + + ///Returns `true` if, and only if, all elements are finite. + ///If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite(&self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(&self:) -> Raw(bool), + + ///Returns the transpose of `self`. + transpose(&self:) -> self, + + ///Returns the determinant of `self`. + determinant(&self:) -> Raw(f64), + + ///Returns the inverse of `self`. + /// + ///If the matrix is not invertible the returned matrix will be invalid. + /// + ///# Panics + /// + ///Will panic if the determinant of `self` is zero when `glam_assert` is enabled. + inverse(&self:) -> self, + + ///Creates a left-handed view matrix using a camera position, an up direction, and a focal + ///point. + ///For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + /// + ///# Panics + /// + ///Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh(Wrapped(DVec3),Wrapped(DVec3),Wrapped(DVec3)) -> self, + + ///Creates a right-handed view matrix using a camera position, an up direction, and a focal + ///point. + ///For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + /// + ///# Panics + /// + ///Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh(Wrapped(DVec3),Wrapped(DVec3),Wrapped(DVec3)) -> self, + + ///Creates a right-handed perspective projection matrix with [-1,1] depth range. + ///This is the same as the OpenGL `gluPerspective` function. + ///See + perspective_rh_gl(Raw(f64),Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates a left-handed perspective projection matrix with `[0,1]` depth range. + /// + ///# Panics + /// + ///Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + ///enabled. + perspective_lh(Raw(f64),Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates a right-handed perspective projection matrix with `[0,1]` depth range. + /// + ///# Panics + /// + ///Will panic if `z_near` or `z_far` are less than or equal to zero when `glam_assert` is + ///enabled. + perspective_rh(Raw(f64),Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + /// + ///# Panics + /// + ///Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_lh(Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates an infinite left-handed perspective projection matrix with `[0,1]` depth range. + /// + ///# Panics + /// + ///Will panic if `z_near` is less than or equal to zero when `glam_assert` is enabled. + perspective_infinite_reverse_lh(Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates an infinite right-handed perspective projection matrix with + ///`[0,1]` depth range. + perspective_infinite_rh(Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates an infinite reverse right-handed perspective projection matrix + ///with `[0,1]` depth range. + perspective_infinite_reverse_rh(Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates a right-handed orthographic projection matrix with `[-1,1]` depth + ///range. This is the same as the OpenGL `glOrtho` function in OpenGL. + ///See + /// + orthographic_rh_gl(Raw(f64),Raw(f64),Raw(f64),Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates a left-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_lh(Raw(f64),Raw(f64),Raw(f64),Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates a right-handed orthographic projection matrix with `[0,1]` depth range. + orthographic_rh(Raw(f64),Raw(f64),Raw(f64),Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Transforms the given 3D vector as a point, applying perspective correction. + /// + ///This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is `1.0`. + ///The perspective divide is performed meaning the resulting 3D vector is divided by `w`. + /// + ///This method assumes that `self` contains a projective transform. + project_point3(&self:Wrapped(DVec3)) -> Wrapped(DVec3), + + ///Transforms the given 3D vector as a point. + /// + ///This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is + ///`1.0`. + /// + ///This method assumes that `self` contains a valid affine transform. It does not perform + ///a persective divide, if `self` contains a perspective transform, or if you are unsure, + ///the [`Self::project_point3()`] method should be used instead. + /// + ///# Panics + /// + ///Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + transform_point3(&self:Wrapped(DVec3)) -> Wrapped(DVec3), + + ///Transforms the give 3D vector as a direction. + /// + ///This is the equivalent of multiplying the 3D vector as a 4D vector where `w` is + ///`0.0`. + /// + ///This method assumes that `self` contains a valid affine transform. + /// + ///# Panics + /// + ///Will panic if the 3rd row of `self` is not `(0, 0, 0, 1)` when `glam_assert` is enabled. + transform_vector3(&self:Wrapped(DVec3)) -> Wrapped(DVec3), + + ///Transforms a 4D vector. + mul_vec4(&self:Wrapped(DVec4)) -> Wrapped(DVec4), + + ///Multiplies two 4x4 matrices. + mul_mat4(&self:&self) -> self, + + ///Adds two 4x4 matrices. + add_mat4(&self:&self) -> self, + + ///Subtracts two 4x4 matrices. + sub_mat4(&self:&self) -> self, + + ///Multiplies a 4x4 matrix by a scalar. + mul_scalar(&self:Raw(f64)) -> self, + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two matrices contain similar elements. It works best + ///when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(&self:self,Raw(f64)) -> Raw(bool), + + as_mat4(&self:) -> Wrapped(Mat4), + + ) + + Fields + ( + x_axis: Wrapped(DVec4), + y_axis: Wrapped(DVec4), + z_axis: Wrapped(DVec4), + w_axis: Wrapped(DVec4), + ) + + BinOps + ( + self Add self -> Wrapped(DMat4), + self Sub self -> Wrapped(DMat4), + self Mul Wrapped(DAffine3) -> Wrapped(DMat4), + self Mul self -> Wrapped(DMat4), + self Mul Wrapped(DVec4) -> Wrapped(DVec4), + self Mul Wrapped(DMat4) -> Wrapped(DMat4), + self Mul Raw(f64) -> Wrapped(DMat4), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + + mut (MetaMethod::Index) => |_,s,idx : usize| { + Ok(LuaDVec4::new_ref( + s.script_ref().sub_ref(ReflectPathElem::SubReflectionIndexed{ + label:"col", + index: idx, + get: |idx,ref_| Err(ReflectionError::InsufficientProvenance{ + path: "".to_owned(), + msg: "Cannot get column of matrix with immutable reference".to_owned() + }), + get_mut: |idx, ref_| { + if ref_.is::(){ + Ok(ref_.downcast_mut::() + .unwrap() + .col_mut(idx)) + } else { + Err(ReflectionError::CannotDowncast{from: ref_.type_name().to_owned().into(), to:"DMat4".into()}) + } + } + }) + ) + ) + } +; + } +} +impl_script_newtype! { + ///A 2D affine transform, which can represent translation, rotation, scaling and shear. + glam::f32::sse2::mat2::Affine2 : + Clone + + Debug + + Methods + ( + ///Creates an affine transform from three column vectors. + from_cols(Wrapped(Vec2),Wrapped(Vec2),Wrapped(Vec2)) -> self, + + ///Creates an affine transform that changes scale. + ///Note that if any scale is zero the transform will be non-invertible. + from_scale(Wrapped(Vec2)) -> self, + + ///Creates an affine transform from the given rotation `angle`. + from_angle(Raw(f32)) -> self, + + ///Creates an affine transformation from the given 2D `translation`. + from_translation(Wrapped(Vec2)) -> self, + + ///Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) + from_mat2(Wrapped(Mat2)) -> self, + + ///Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a + ///translation vector. + /// + ///Equivalent to + ///`Affine2::from_translation(translation) * Affine2::from_mat2(mat2)` + from_mat2_translation(Wrapped(Mat2),Wrapped(Vec2)) -> self, + + ///Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and + ///`translation`. + /// + ///Equivalent to `Affine2::from_translation(translation) * + ///Affine2::from_angle(angle) * Affine2::from_scale(scale)` + from_scale_angle_translation(Wrapped(Vec2),Raw(f32),Wrapped(Vec2)) -> self, + + ///Creates an affine transform from the given 2D rotation `angle` (in radians) and + ///`translation`. + /// + ///Equivalent to `Affine2::from_translation(translation) * Affine2::from_angle(angle)` + from_angle_translation(Raw(f32),Wrapped(Vec2)) -> self, + + ///The given `Mat3` must be an affine transform, + from_mat3(Wrapped(Mat3)) -> self, + + ///Transforms the given 2D point, applying shear, scale, rotation and translation. + transform_point2(&self:Wrapped(Vec2)) -> Wrapped(Vec2), + + ///Transforms the given 2D vector, applying shear, scale and rotation (but NOT + ///translation). + /// + ///To also apply translation, use [`Self::transform_point2`] instead. + transform_vector2(&self:Wrapped(Vec2)) -> Wrapped(Vec2), + + ///Returns `true` if, and only if, all elements are finite. + /// + ///If any element is either `NaN`, positive or negative infinity, this will return + ///`false`. + is_finite(&self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(&self:) -> Raw(bool), + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two 3x4 matrices contain similar elements. It works + ///best when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(&self:self,Raw(f32)) -> Raw(bool), + + ///Return the inverse of this transform. + /// + ///Note that if the transform is not invertible the result will be invalid. + inverse(&self:) -> self, + + ) + + Fields + ( + matrix2: Wrapped(Mat2), + translation: Wrapped(Vec2), + ) + + BinOps + ( + self Add self -> Wrapped(Affine2), + self Sub self -> Wrapped(Affine2), + self Mul Wrapped(Affine2) -> Wrapped(Affine2), + self Mul Wrapped(Affine2) -> Wrapped(Affine2), + self Mul Raw(f32) -> Wrapped(Affine2), + self Mul Wrapped(Mat3) -> Wrapped(Mat3), + self Mul Wrapped(Mat3A) -> Wrapped(Mat3A), + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A 3D affine transform, which can represent translation, rotation, scaling and shear. + glam::f32::sse2::mat3::Affine3A : + Clone + + Debug + + Methods + ( + ///Creates an affine transform from three column vectors. + from_cols(Wrapped(Vec3A),Wrapped(Vec3A),Wrapped(Vec3A),Wrapped(Vec3A)) -> self, + + ///Creates an affine transform that changes scale. + ///Note that if any scale is zero the transform will be non-invertible. + from_scale(Wrapped(Vec3)) -> self, + + ///Creates an affine transform from the given `rotation` quaternion. + from_quat(Wrapped(Quat)) -> self, + + ///Creates an affine transform containing a 3D rotation around a normalized + ///rotation `axis` of `angle` (in radians). + from_axis_angle(Wrapped(Vec3),Raw(f32)) -> self, + + ///Creates an affine transform containing a 3D rotation around the x axis of + ///`angle` (in radians). + from_rotation_x(Raw(f32)) -> self, + + ///Creates an affine transform containing a 3D rotation around the y axis of + ///`angle` (in radians). + from_rotation_y(Raw(f32)) -> self, + + ///Creates an affine transform containing a 3D rotation around the z axis of + ///`angle` (in radians). + from_rotation_z(Raw(f32)) -> self, + + ///Creates an affine transformation from the given 3D `translation`. + from_translation(Wrapped(Vec3)) -> self, + + ///Creates an affine transform from a 3x3 matrix (expressing scale, shear and + ///rotation) + from_mat3(Wrapped(Mat3)) -> self, + + ///Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) + ///and a translation vector. + /// + ///Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_mat3(mat3)` + from_mat3_translation(Wrapped(Mat3),Wrapped(Vec3)) -> self, + + ///Creates an affine transform from the given 3D `scale`, `rotation` and + ///`translation`. + /// + ///Equivalent to `Affine3A::from_translation(translation) * + ///Affine3A::from_quat(rotation) * Affine3A::from_scale(scale)` + from_scale_rotation_translation(Wrapped(Vec3),Wrapped(Quat),Wrapped(Vec3)) -> self, + + ///Creates an affine transform from the given 3D `rotation` and `translation`. + /// + ///Equivalent to `Affine3A::from_translation(translation) * Affine3A::from_quat(rotation)` + from_rotation_translation(Wrapped(Quat),Wrapped(Vec3)) -> self, + + ///The given `Mat4` must be an affine transform, + ///i.e. contain no perspective transform. + from_mat4(Wrapped(Mat4)) -> self, + + ///Creates a left-handed view transform using a camera position, an up direction, and + ///a focal point. + /// + ///For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + /// + ///# Panics + /// + ///Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh(Wrapped(Vec3),Wrapped(Vec3),Wrapped(Vec3)) -> self, + + ///Creates a right-handed view transform using a camera position, an up direction, and + ///a focal point. + /// + ///For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + /// + ///# Panics + /// + ///Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh(Wrapped(Vec3),Wrapped(Vec3),Wrapped(Vec3)) -> self, + + ///Transforms the given 3D points, applying shear, scale, rotation and translation. + transform_point3(&self:Wrapped(Vec3)) -> Wrapped(Vec3), + + ///Transforms the given 3D vector, applying shear, scale and rotation (but NOT + ///translation). + /// + ///To also apply translation, use [`Self::transform_point3`] instead. + transform_vector3(&self:Wrapped(Vec3)) -> Wrapped(Vec3), + + ///Transforms the given `Vec3A`, applying shear, scale, rotation and translation. + transform_point3a(&self:Wrapped(Vec3A)) -> Wrapped(Vec3A), + + ///Transforms the given `Vec3A`, applying shear, scale and rotation (but NOT + ///translation). + /// + ///To also apply translation, use [`Self::transform_point3`] instead. + transform_vector3a(&self:Wrapped(Vec3A)) -> Wrapped(Vec3A), + + ///Returns `true` if, and only if, all elements are finite. + /// + ///If any element is either `NaN`, positive or negative infinity, this will return + ///`false`. + is_finite(&self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(&self:) -> Raw(bool), + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two 3x4 matrices contain similar elements. It works + ///best when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(&self:self,Raw(f32)) -> Raw(bool), + + ///Return the inverse of this transform. + /// + ///Note that if the transform is not invertible the result will be invalid. + inverse(&self:) -> self, + + ) + + Fields + ( + matrix3: Wrapped(Mat3A), + translation: Wrapped(Vec3A), + ) + + BinOps + ( + self Add self -> Wrapped(Affine3A), + self Sub self -> Wrapped(Affine3A), + self Mul Wrapped(Affine3A) -> Wrapped(Affine3A), + self Mul Wrapped(Affine3A) -> Wrapped(Affine3A), + self Mul Raw(f32) -> Wrapped(Affine3A), + self Mul Wrapped(Mat4) -> Wrapped(Mat4), + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A 2D affine transform, which can represent translation, rotation, scaling and shear. + glam::f64::sse2::mat2::DAffine2 : + Clone + + Debug + + Methods + ( + ///Creates an affine transform from three column vectors. + from_cols(Wrapped(DVec2),Wrapped(DVec2),Wrapped(DVec2)) -> self, + + ///Creates an affine transform that changes scale. + ///Note that if any scale is zero the transform will be non-invertible. + from_scale(Wrapped(DVec2)) -> self, + + ///Creates an affine transform from the given rotation `angle`. + from_angle(Raw(f64)) -> self, + + ///Creates an affine transformation from the given 2D `translation`. + from_translation(Wrapped(DVec2)) -> self, + + ///Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) + from_mat2(Wrapped(DMat2)) -> self, + + ///Creates an affine transform from a 2x2 matrix (expressing scale, shear and rotation) and a + ///translation vector. + /// + ///Equivalent to + ///`DAffine2::from_translation(translation) * DAffine2::from_mat2(mat2)` + from_mat2_translation(Wrapped(DMat2),Wrapped(DVec2)) -> self, + + ///Creates an affine transform from the given 2D `scale`, rotation `angle` (in radians) and + ///`translation`. + /// + ///Equivalent to `DAffine2::from_translation(translation) * + ///DAffine2::from_angle(angle) * DAffine2::from_scale(scale)` + from_scale_angle_translation(Wrapped(DVec2),Raw(f64),Wrapped(DVec2)) -> self, + + ///Creates an affine transform from the given 2D rotation `angle` (in radians) and + ///`translation`. + /// + ///Equivalent to `DAffine2::from_translation(translation) * DAffine2::from_angle(angle)` + from_angle_translation(Raw(f64),Wrapped(DVec2)) -> self, + + ///The given `DMat3` must be an affine transform, + from_mat3(Wrapped(DMat3)) -> self, + + ///Transforms the given 2D point, applying shear, scale, rotation and translation. + transform_point2(&self:Wrapped(DVec2)) -> Wrapped(DVec2), + + ///Transforms the given 2D vector, applying shear, scale and rotation (but NOT + ///translation). + /// + ///To also apply translation, use [`Self::transform_point2`] instead. + transform_vector2(&self:Wrapped(DVec2)) -> Wrapped(DVec2), + + ///Returns `true` if, and only if, all elements are finite. + /// + ///If any element is either `NaN`, positive or negative infinity, this will return + ///`false`. + is_finite(&self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(&self:) -> Raw(bool), + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two 3x4 matrices contain similar elements. It works + ///best when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(&self:self,Raw(f64)) -> Raw(bool), + + ///Return the inverse of this transform. + /// + ///Note that if the transform is not invertible the result will be invalid. + inverse(&self:) -> self, + + ) + + Fields + ( + matrix2: Wrapped(DMat2), + translation: Wrapped(DVec2), + ) + + BinOps + ( + self Add self -> Wrapped(DAffine2), + self Sub self -> Wrapped(DAffine2), + self Mul Wrapped(DAffine2) -> Wrapped(DAffine2), + self Mul Wrapped(DAffine2) -> Wrapped(DAffine2), + self Mul Raw(f64) -> Wrapped(DAffine2), + self Mul Wrapped(DMat3) -> Wrapped(DMat3), + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A 3D affine transform, which can represent translation, rotation, scaling and shear. + glam::f64::sse2::mat3::DAffine3 : + Clone + + Debug + + Methods + ( + ///Creates an affine transform from three column vectors. + from_cols(Wrapped(DVec3),Wrapped(DVec3),Wrapped(DVec3),Wrapped(DVec3)) -> self, + + ///Creates an affine transform that changes scale. + ///Note that if any scale is zero the transform will be non-invertible. + from_scale(Wrapped(DVec3)) -> self, + + ///Creates an affine transform from the given `rotation` quaternion. + from_quat(Wrapped(DQuat)) -> self, + + ///Creates an affine transform containing a 3D rotation around a normalized + ///rotation `axis` of `angle` (in radians). + from_axis_angle(Wrapped(DVec3),Raw(f64)) -> self, + + ///Creates an affine transform containing a 3D rotation around the x axis of + ///`angle` (in radians). + from_rotation_x(Raw(f64)) -> self, + + ///Creates an affine transform containing a 3D rotation around the y axis of + ///`angle` (in radians). + from_rotation_y(Raw(f64)) -> self, + + ///Creates an affine transform containing a 3D rotation around the z axis of + ///`angle` (in radians). + from_rotation_z(Raw(f64)) -> self, + + ///Creates an affine transformation from the given 3D `translation`. + from_translation(Wrapped(DVec3)) -> self, + + ///Creates an affine transform from a 3x3 matrix (expressing scale, shear and + ///rotation) + from_mat3(Wrapped(DMat3)) -> self, + + ///Creates an affine transform from a 3x3 matrix (expressing scale, shear and rotation) + ///and a translation vector. + /// + ///Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_mat3(mat3)` + from_mat3_translation(Wrapped(DMat3),Wrapped(DVec3)) -> self, + + ///Creates an affine transform from the given 3D `scale`, `rotation` and + ///`translation`. + /// + ///Equivalent to `DAffine3::from_translation(translation) * + ///DAffine3::from_quat(rotation) * DAffine3::from_scale(scale)` + from_scale_rotation_translation(Wrapped(DVec3),Wrapped(DQuat),Wrapped(DVec3)) -> self, + + ///Creates an affine transform from the given 3D `rotation` and `translation`. + /// + ///Equivalent to `DAffine3::from_translation(translation) * DAffine3::from_quat(rotation)` + from_rotation_translation(Wrapped(DQuat),Wrapped(DVec3)) -> self, + + ///The given `DMat4` must be an affine transform, + ///i.e. contain no perspective transform. + from_mat4(Wrapped(DMat4)) -> self, + + ///Creates a left-handed view transform using a camera position, an up direction, and + ///a focal point. + /// + ///For a view coordinate system with `+X=right`, `+Y=up` and `+Z=forward`. + /// + ///# Panics + /// + ///Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_lh(Wrapped(DVec3),Wrapped(DVec3),Wrapped(DVec3)) -> self, + + ///Creates a right-handed view transform using a camera position, an up direction, and + ///a focal point. + /// + ///For a view coordinate system with `+X=right`, `+Y=up` and `+Z=back`. + /// + ///# Panics + /// + ///Will panic if `up` is not normalized when `glam_assert` is enabled. + look_at_rh(Wrapped(DVec3),Wrapped(DVec3),Wrapped(DVec3)) -> self, + + ///Transforms the given 3D points, applying shear, scale, rotation and translation. + transform_point3(&self:Wrapped(DVec3)) -> Wrapped(DVec3), + + ///Transforms the given 3D vector, applying shear, scale and rotation (but NOT + ///translation). + /// + ///To also apply translation, use [`Self::transform_point3`] instead. + transform_vector3(&self:Wrapped(DVec3)) -> Wrapped(DVec3), + + ///Returns `true` if, and only if, all elements are finite. + /// + ///If any element is either `NaN`, positive or negative infinity, this will return + ///`false`. + is_finite(&self:) -> Raw(bool), + + ///Returns `true` if any elements are `NaN`. + is_nan(&self:) -> Raw(bool), + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two 3x4 matrices contain similar elements. It works + ///best when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(&self:self,Raw(f64)) -> Raw(bool), + + ///Return the inverse of this transform. + /// + ///Note that if the transform is not invertible the result will be invalid. + inverse(&self:) -> self, + + ) + + Fields + ( + matrix3: Wrapped(DMat3), + translation: Wrapped(DVec3), + ) + + BinOps + ( + self Add self -> Wrapped(DAffine3), + self Sub self -> Wrapped(DAffine3), + self Mul Wrapped(DAffine3) -> Wrapped(DAffine3), + self Mul Wrapped(DAffine3) -> Wrapped(DAffine3), + self Mul Raw(f64) -> Wrapped(DAffine3), + self Mul Wrapped(DMat4) -> Wrapped(DMat4), + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_script_newtype! { + ///A quaternion representing an orientation. + /// + ///This quaternion is intended to be of unit length but may denormalize due to + ///floating point "error creep" which can occur when successive quaternion + ///operations are applied. + /// + ///This type is 16 byte aligned. + glam::f32::sse2::quat::Quat : + Clone + + Debug + + Methods + ( + ///Creates a new rotation quaternion. + /// + ///This should generally not be called manually unless you know what you are doing. + ///Use one of the other constructors instead such as `identity` or `from_axis_angle`. + /// + ///`from_xyzw` is mostly used by unit tests and `serde` deserialization. + /// + ///# Preconditions + /// + ///This function does not check if the input is normalized, it is up to the user to + ///provide normalized input or to normalized the resulting quaternion. + from_xyzw(Raw(f32),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a new rotation quaternion from a 4D vector. + /// + ///# Preconditions + /// + ///This function does not check if the input is normalized, it is up to the user to + ///provide normalized input or to normalized the resulting quaternion. + from_vec4(Wrapped(Vec4)) -> self, + + ///Create a quaternion for a normalized rotation `axis` and `angle` (in radians). + ///The axis must be normalized (unit-length). + /// + ///# Panics + /// + ///Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle(Wrapped(Vec3),Raw(f32)) -> self, + + ///Create a quaternion that rotates `v.length()` radians around `v.normalize()`. + /// + ///`from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. + from_scaled_axis(Wrapped(Vec3)) -> self, + + ///Creates a quaternion from the `angle` (in radians) around the x axis. + from_rotation_x(Raw(f32)) -> self, + + ///Creates a quaternion from the `angle` (in radians) around the y axis. + from_rotation_y(Raw(f32)) -> self, + + ///Creates a quaternion from the `angle` (in radians) around the z axis. + from_rotation_z(Raw(f32)) -> self, + + ///Creates a quaternion from the given Euler rotation sequence and the angles (in radians). + from_euler(Wrapped(EulerRot),Raw(f32),Raw(f32),Raw(f32)) -> self, + + ///Creates a quaternion from a 3x3 rotation matrix. + from_mat3(Wrapped(&Mat3)) -> self, + + ///Creates a quaternion from a 3x3 rotation matrix inside a homogeneous 4x4 matrix. + from_mat4(Wrapped(&Mat4)) -> self, + + ///Gets the minimal rotation for transforming `from` to `to`. The rotation is in the + ///plane spanned by the two vectors. Will rotate at most 180 degrees. + /// + ///The input vectors must be normalized (unit-length). + /// + ///`from_rotation_arc(from, to) * from ≈ to`. + /// + ///For near-singular cases (from≈to and from≈-to) the current implementation + ///is only accurate to about 0.001 (for `f32`). + /// + ///# Panics + /// + ///Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc(Wrapped(Vec3),Wrapped(Vec3)) -> self, + + ///Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means + ///that the resulting quaternion will rotate `from` so that it is colinear with `to`. + /// + ///The rotation is in the plane spanned by the two vectors. Will rotate at most 90 + ///degrees. + /// + ///The input vectors must be normalized (unit-length). + /// + ///`to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. + /// + ///# Panics + /// + ///Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_colinear(Wrapped(Vec3),Wrapped(Vec3)) -> self, + + ///Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is + ///around the z axis. Will rotate at most 180 degrees. + /// + ///The input vectors must be normalized (unit-length). + /// + ///`from_rotation_arc_2d(from, to) * from ≈ to`. + /// + ///For near-singular cases (from≈to and from≈-to) the current implementation + ///is only accurate to about 0.001 (for `f32`). + /// + ///# Panics + /// + ///Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_2d(Wrapped(Vec2),Wrapped(Vec2)) -> self, + + ///Returns the rotation axis scaled by the rotation in radians. + to_scaled_axis(self:) -> Wrapped(Vec3), + + ///Returns the vector part of the quaternion. + xyz(self:) -> Wrapped(Vec3), + + ///Returns the quaternion conjugate of `self`. For a unit quaternion the + ///conjugate is also the inverse. + conjugate(self:) -> self, + + ///Returns the inverse of a normalized quaternion. + /// + ///Typically quaternion inverse returns the conjugate of a normalized quaternion. + ///Because `self` is assumed to already be unit length this method *does not* normalize + ///before returning the conjugate. + /// + ///# Panics + /// + ///Will panic if `self` is not normalized when `glam_assert` is enabled. + inverse(self:) -> self, + + ///Computes the dot product of `self` and `rhs`. The dot product is + ///equal to the cosine of the angle between two quaternion rotations. + dot(self:self) -> Raw(f32), + + ///Computes the length of `self`. + length(self:) -> Raw(f32), + + ///Computes the squared length of `self`. + /// + ///This is generally faster than `length()` as it avoids a square + ///root operation. + length_squared(self:) -> Raw(f32), + + ///Computes `1.0 / length()`. + /// + ///For valid results, `self` must _not_ be of length zero. + length_recip(self:) -> Raw(f32), + + ///Returns `self` normalized to length 1.0. + /// + ///For valid results, `self` must _not_ be of length zero. + /// + ///Panics + /// + ///Will panic if `self` is zero length when `glam_assert` is enabled. + normalize(self:) -> self, + + ///Returns `true` if, and only if, all elements are finite. + ///If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite(self:) -> Raw(bool), + + is_nan(self:) -> Raw(bool), + + ///Returns whether `self` of length `1.0` or not. + /// + ///Uses a precision threshold of `1e-6`. + is_normalized(self:) -> Raw(bool), + + is_near_identity(self:) -> Raw(bool), + + ///Returns the angle (in radians) for the minimal rotation + ///for transforming this quaternion into another. + /// + ///Both quaternions must be normalized. + /// + ///# Panics + /// + ///Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + angle_between(self:self) -> Raw(f32), + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two quaternions contain similar elements. It works + ///best when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(self:self,Raw(f32)) -> Raw(bool), + + ///Performs a linear interpolation between `self` and `rhs` based on + ///the value `s`. + /// + ///When `s` is `0.0`, the result will be equal to `self`. When `s` + ///is `1.0`, the result will be equal to `rhs`. + /// + ///# Panics + /// + ///Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + lerp(self:self,Raw(f32)) -> self, + + ///Performs a spherical linear interpolation between `self` and `end` + ///based on the value `s`. + /// + ///When `s` is `0.0`, the result will be equal to `self`. When `s` + ///is `1.0`, the result will be equal to `end`. + /// + ///# Panics + /// + ///Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + slerp(self:self,Raw(f32)) -> self, + + ///Multiplies a quaternion and a 3D vector, returning the rotated vector. + /// + ///# Panics + /// + ///Will panic if `self` is not normalized when `glam_assert` is enabled. + mul_vec3(self:Wrapped(Vec3)) -> Wrapped(Vec3), + + ///Multiplies two quaternions. If they each represent a rotation, the result will + ///represent the combined rotation. + /// + ///Note that due to floating point rounding the result may not be perfectly normalized. + /// + ///# Panics + /// + ///Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + mul_quat(self:self) -> self, + + ///Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. + from_affine3(Wrapped(&Affine3A)) -> self, + + ///Multiplies a quaternion and a 3D vector, returning the rotated vector. + mul_vec3a(self:Wrapped(Vec3A)) -> Wrapped(Vec3A), + + as_f64(self:) -> Wrapped(DQuat), + + ) + + Fields + ( + ) + + BinOps + ( + self Add self -> Wrapped(Quat), + self Sub self -> Wrapped(Quat), + self Div Raw(f32) -> Wrapped(Quat), + self Mul Raw(f32) -> Wrapped(Quat), + self Mul self -> Wrapped(Quat), + self Mul Wrapped(Vec3) -> Wrapped(Vec3), + self Mul Wrapped(Vec3A) -> Wrapped(Vec3A), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + } +} +impl_script_newtype! { + ///A quaternion representing an orientation. + /// + ///This quaternion is intended to be of unit length but may denormalize due to + ///floating point "error creep" which can occur when successive quaternion + ///operations are applied. + glam::f64::dquat::DQuat : + Clone + + Debug + + Methods + ( + ///Creates a new rotation quaternion. + /// + ///This should generally not be called manually unless you know what you are doing. + ///Use one of the other constructors instead such as `identity` or `from_axis_angle`. + /// + ///`from_xyzw` is mostly used by unit tests and `serde` deserialization. + /// + ///# Preconditions + /// + ///This function does not check if the input is normalized, it is up to the user to + ///provide normalized input or to normalized the resulting quaternion. + from_xyzw(Raw(f64),Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates a new rotation quaternion from a 4D vector. + /// + ///# Preconditions + /// + ///This function does not check if the input is normalized, it is up to the user to + ///provide normalized input or to normalized the resulting quaternion. + from_vec4(Wrapped(DVec4)) -> self, + + ///Create a quaternion for a normalized rotation `axis` and `angle` (in radians). + ///The axis must be normalized (unit-length). + /// + ///# Panics + /// + ///Will panic if `axis` is not normalized when `glam_assert` is enabled. + from_axis_angle(Wrapped(DVec3),Raw(f64)) -> self, + + ///Create a quaternion that rotates `v.length()` radians around `v.normalize()`. + /// + ///`from_scaled_axis(Vec3::ZERO)` results in the identity quaternion. + from_scaled_axis(Wrapped(DVec3)) -> self, + + ///Creates a quaternion from the `angle` (in radians) around the x axis. + from_rotation_x(Raw(f64)) -> self, + + ///Creates a quaternion from the `angle` (in radians) around the y axis. + from_rotation_y(Raw(f64)) -> self, + + ///Creates a quaternion from the `angle` (in radians) around the z axis. + from_rotation_z(Raw(f64)) -> self, + + ///Creates a quaternion from the given Euler rotation sequence and the angles (in radians). + from_euler(Wrapped(EulerRot),Raw(f64),Raw(f64),Raw(f64)) -> self, + + ///Creates a quaternion from a 3x3 rotation matrix. + from_mat3(Wrapped(&DMat3)) -> self, + + ///Creates a quaternion from a 3x3 rotation matrix inside a homogeneous 4x4 matrix. + from_mat4(Wrapped(&DMat4)) -> self, + + ///Gets the minimal rotation for transforming `from` to `to`. The rotation is in the + ///plane spanned by the two vectors. Will rotate at most 180 degrees. + /// + ///The input vectors must be normalized (unit-length). + /// + ///`from_rotation_arc(from, to) * from ≈ to`. + /// + ///For near-singular cases (from≈to and from≈-to) the current implementation + ///is only accurate to about 0.001 (for `f32`). + /// + ///# Panics + /// + ///Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc(Wrapped(DVec3),Wrapped(DVec3)) -> self, + + ///Gets the minimal rotation for transforming `from` to either `to` or `-to`. This means + ///that the resulting quaternion will rotate `from` so that it is colinear with `to`. + /// + ///The rotation is in the plane spanned by the two vectors. Will rotate at most 90 + ///degrees. + /// + ///The input vectors must be normalized (unit-length). + /// + ///`to.dot(from_rotation_arc_colinear(from, to) * from).abs() ≈ 1`. + /// + ///# Panics + /// + ///Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_colinear(Wrapped(DVec3),Wrapped(DVec3)) -> self, + + ///Gets the minimal rotation for transforming `from` to `to`. The resulting rotation is + ///around the z axis. Will rotate at most 180 degrees. + /// + ///The input vectors must be normalized (unit-length). + /// + ///`from_rotation_arc_2d(from, to) * from ≈ to`. + /// + ///For near-singular cases (from≈to and from≈-to) the current implementation + ///is only accurate to about 0.001 (for `f32`). + /// + ///# Panics + /// + ///Will panic if `from` or `to` are not normalized when `glam_assert` is enabled. + from_rotation_arc_2d(Wrapped(DVec2),Wrapped(DVec2)) -> self, + + ///Returns the rotation axis scaled by the rotation in radians. + to_scaled_axis(self:) -> Wrapped(DVec3), + + ///Returns the vector part of the quaternion. + xyz(self:) -> Wrapped(DVec3), + + ///Returns the quaternion conjugate of `self`. For a unit quaternion the + ///conjugate is also the inverse. + conjugate(self:) -> self, + + ///Returns the inverse of a normalized quaternion. + /// + ///Typically quaternion inverse returns the conjugate of a normalized quaternion. + ///Because `self` is assumed to already be unit length this method *does not* normalize + ///before returning the conjugate. + /// + ///# Panics + /// + ///Will panic if `self` is not normalized when `glam_assert` is enabled. + inverse(self:) -> self, + + ///Computes the dot product of `self` and `rhs`. The dot product is + ///equal to the cosine of the angle between two quaternion rotations. + dot(self:self) -> Raw(f64), + + ///Computes the length of `self`. + length(self:) -> Raw(f64), + + ///Computes the squared length of `self`. + /// + ///This is generally faster than `length()` as it avoids a square + ///root operation. + length_squared(self:) -> Raw(f64), + + ///Computes `1.0 / length()`. + /// + ///For valid results, `self` must _not_ be of length zero. + length_recip(self:) -> Raw(f64), + + ///Returns `self` normalized to length 1.0. + /// + ///For valid results, `self` must _not_ be of length zero. + /// + ///Panics + /// + ///Will panic if `self` is zero length when `glam_assert` is enabled. + normalize(self:) -> self, + + ///Returns `true` if, and only if, all elements are finite. + ///If any element is either `NaN`, positive or negative infinity, this will return `false`. + is_finite(self:) -> Raw(bool), + + is_nan(self:) -> Raw(bool), + + ///Returns whether `self` of length `1.0` or not. + /// + ///Uses a precision threshold of `1e-6`. + is_normalized(self:) -> Raw(bool), + + is_near_identity(self:) -> Raw(bool), + + ///Returns the angle (in radians) for the minimal rotation + ///for transforming this quaternion into another. + /// + ///Both quaternions must be normalized. + /// + ///# Panics + /// + ///Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + angle_between(self:self) -> Raw(f64), + + ///Returns true if the absolute difference of all elements between `self` and `rhs` + ///is less than or equal to `max_abs_diff`. + /// + ///This can be used to compare if two quaternions contain similar elements. It works + ///best when comparing with a known value. The `max_abs_diff` that should be used used + ///depends on the values being compared against. + /// + ///For more see + ///[comparing floating point numbers](https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/). + abs_diff_eq(self:self,Raw(f64)) -> Raw(bool), + + ///Performs a linear interpolation between `self` and `rhs` based on + ///the value `s`. + /// + ///When `s` is `0.0`, the result will be equal to `self`. When `s` + ///is `1.0`, the result will be equal to `rhs`. + /// + ///# Panics + /// + ///Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + lerp(self:self,Raw(f64)) -> self, + + ///Performs a spherical linear interpolation between `self` and `end` + ///based on the value `s`. + /// + ///When `s` is `0.0`, the result will be equal to `self`. When `s` + ///is `1.0`, the result will be equal to `end`. + /// + ///# Panics + /// + ///Will panic if `self` or `end` are not normalized when `glam_assert` is enabled. + slerp(self:self,Raw(f64)) -> self, + + ///Multiplies a quaternion and a 3D vector, returning the rotated vector. + /// + ///# Panics + /// + ///Will panic if `self` is not normalized when `glam_assert` is enabled. + mul_vec3(self:Wrapped(DVec3)) -> Wrapped(DVec3), + + ///Multiplies two quaternions. If they each represent a rotation, the result will + ///represent the combined rotation. + /// + ///Note that due to floating point rounding the result may not be perfectly normalized. + /// + ///# Panics + /// + ///Will panic if `self` or `rhs` are not normalized when `glam_assert` is enabled. + mul_quat(self:self) -> self, + + ///Creates a quaternion from a 3x3 rotation matrix inside a 3D affine transform. + from_affine3(Wrapped(&DAffine3)) -> self, + + as_f32(self:) -> Wrapped(Quat), + + ) + + Fields + ( + x: Raw(f64), + y: Raw(f64), + z: Raw(f64), + w: Raw(f64), + ) + + BinOps + ( + self Add self -> Wrapped(DQuat), + self Sub self -> Wrapped(DQuat), + self Div Raw(f64) -> Wrapped(DQuat), + self Mul Raw(f64) -> Wrapped(DQuat), + self Mul self -> Wrapped(DQuat), + self Mul Wrapped(DVec3) -> Wrapped(DVec3), + ) + + UnaryOps + ( + Neg self -> self + ) + impl + { + } +} +impl_script_newtype! { + ///Euler rotation sequences. + /// + ///The angles are applied starting from the right. + ///E.g. XYZ will first apply the z-axis rotation. + /// + ///YXZ can be used for yaw (y-axis), pitch (x-axis), roll (z-axis). + /// + ///The two-axis rotations (e.g. ZYZ) are not fully tested and have to be treated with caution. + glam::euler::EulerRot : + Clone + + Debug + + Methods + ( + ) + + Fields + ( + ) + + BinOps + ( + ) + + UnaryOps + ( + ) + impl + { + } +} +impl_tealr_generic!(pub(crate) struct T); +impl_tealr_generic!(pub(crate) struct K); +impl_tealr_generic!(pub(crate) struct V); +#[derive(Default)] +pub(crate) struct BevyAPIGlobals; +impl tealr::mlu::ExportInstances for BevyAPIGlobals { + fn add_instances<'lua, T: tealr::mlu::InstanceCollector<'lua>>( + self, + instances: &mut T, + ) -> LuaResult<()> { + instances.add_instance("Name".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance( + "Children".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance("Text".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance( + "TextSection".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance( + "Stopwatch".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance("Timer".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("Entity".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance( + "Transform".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance( + "GlobalTransform".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance( + "TextureAtlasSprite".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance( + "RenderLayers".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance( + "Visibility".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance( + "ComputedVisibility".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance("Color".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("Aabb".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance( + "Frustum".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance( + "CameraRenderGraph".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance( + "HandleId".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance("Vec2".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("Vec3".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("Vec3A".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("Vec4".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("BVec2".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("BVec3".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("BVec4".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("BVec3A".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("BVec4A".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("DVec2".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("DVec3".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("DVec4".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("IVec2".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("IVec3".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("IVec4".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("UVec2".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("UVec3".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("UVec4".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("Mat3".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("Mat2".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("Mat3A".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("Mat4".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("DMat2".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("DMat3".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("DMat4".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance( + "Affine2".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance( + "Affine3A".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance( + "DAffine2".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance( + "DAffine3".into(), + tealr::mlu::UserDataProxy::::new, + )?; + instances.add_instance("Quat".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("DQuat".into(), tealr::mlu::UserDataProxy::::new)?; + instances.add_instance("world".into(), DummyTypeName::::new)?; + instances.add_instance("script".into(), DummyTypeName::::new)?; + instances.add_instance("entity".into(), DummyTypeName::::new)?; + Ok(()) + } +} +pub struct LuaBevyAPIProvider; +impl APIProvider for LuaBevyAPIProvider { + type APITarget = Mutex; + type ScriptContext = Mutex; + type DocTarget = LuaDocFragment; + fn attach_api(&mut self, ctx: &mut Self::APITarget) -> Result<(), crate::ScriptError> { + let ctx = ctx + .get_mut() + .expect("Unable to acquire lock on Lua context"); + Ok(tealr::mlu::set_global_env(BevyAPIGlobals, ctx)?) + } + fn get_doc_fragment(&self) -> Option { + Some(LuaDocFragment::new(|tw| { + tw.document_global_instance::() + .expect("Something went wrong documenting globals") + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + .process_type::() + .process_type::>() + })) + } + fn register_with_app(&self, app: &mut App) { + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::(); + app.register_foreign_lua_type::