Compare commits
No commits in common. "e5599e1d275aab13c3a4279d43ec7bd470a48933" and "d14abcc3e592cff1b7d3f6f046a57ab4c8f615c2" have entirely different histories.
e5599e1d27
...
d14abcc3e5
27 changed files with 125 additions and 476 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
@ -1258,15 +1258,6 @@ dependencies = [
|
|||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.10"
|
||||
|
@ -1422,7 +1413,6 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"lyra-ecs-derive",
|
||||
"lyra-math",
|
||||
"rand",
|
||||
"thiserror",
|
||||
]
|
||||
|
@ -1457,9 +1447,8 @@ dependencies = [
|
|||
"glam",
|
||||
"image",
|
||||
"instant",
|
||||
"itertools 0.11.0",
|
||||
"itertools",
|
||||
"lyra-ecs",
|
||||
"lyra-math",
|
||||
"lyra-reflect",
|
||||
"lyra-resource",
|
||||
"quote",
|
||||
|
@ -1474,19 +1463,11 @@ dependencies = [
|
|||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lyra-math"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"glam",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lyra-reflect"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"lyra-ecs",
|
||||
"lyra-math",
|
||||
"lyra-reflect-derive",
|
||||
]
|
||||
|
||||
|
@ -1522,27 +1503,16 @@ name = "lyra-scripting"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"itertools 0.12.0",
|
||||
"lyra-ecs",
|
||||
"lyra-game",
|
||||
"lyra-reflect",
|
||||
"lyra-resource",
|
||||
"lyra-scripting-derive",
|
||||
"mlua",
|
||||
"thiserror",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lyra-scripting-derive"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mach2"
|
||||
version = "0.4.2"
|
||||
|
|
|
@ -10,7 +10,7 @@ members = [
|
|||
"lyra-ecs",
|
||||
"lyra-reflect",
|
||||
"lyra-scripting",
|
||||
"lyra-game", "lyra-math"]
|
||||
"lyra-game"]
|
||||
|
||||
[features]
|
||||
scripting = ["dep:lyra-scripting"]
|
||||
|
@ -18,4 +18,4 @@ lua_scripting = ["scripting", "lyra-scripting/lua"]
|
|||
|
||||
[dependencies]
|
||||
lyra-game = { path = "lyra-game" }
|
||||
lyra-scripting = { path = "lyra-scripting", optional = true }
|
||||
lyra-scripting = { path = "lyra-scripting", optional = true }
|
|
@ -1,6 +1,6 @@
|
|||
print("Hello World")
|
||||
|
||||
--[[ function on_init()
|
||||
function on_init()
|
||||
print("Lua script was initialized!")
|
||||
end
|
||||
|
||||
|
@ -10,23 +10,16 @@ end
|
|||
|
||||
function on_pre_update()
|
||||
print("Lua's pre-update function was called")
|
||||
end ]]
|
||||
|
||||
function on_update()
|
||||
--print("Lua's update function was called")
|
||||
|
||||
world:view(function (t)
|
||||
print("Found entity at " .. tostring(t))
|
||||
t.translation = t.translation + Vec3.new(0, 0.0008, 0)
|
||||
|
||||
return t
|
||||
end, Transform)
|
||||
end
|
||||
|
||||
--[[ function on_post_update()
|
||||
function on_update()
|
||||
print("Lua's update function was called")
|
||||
end
|
||||
|
||||
function on_post_update()
|
||||
print("Lua's post-update function was called")
|
||||
end
|
||||
|
||||
function on_last()
|
||||
print("Lua's last function was called")
|
||||
end ]]
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
use std::ptr::NonNull;
|
||||
|
||||
use lyra_engine::{math::{self, Vec3}, math::Transform, input::{KeyCode, ActionHandler, Action, ActionKind, LayoutId, ActionMapping, ActionSource, ActionMappingId, InputActionPlugin, MouseInput, MouseAxis, CommonActionLabel}, game::Game, render::{window::{CursorGrabMode, WindowOptions}, light::{PointLight, directional::DirectionalLight, SpotLight}}, change_tracker::Ct, ecs::{system::{Criteria, CriteriaSchedule, BatchedSystem, IntoSystem}, world::World, Component}, DeltaTime, scene::{ModelComponent, CameraComponent}, lua::{LuaScriptingPlugin, LuaScript}, Script, ScriptList};
|
||||
use lyra_engine::{math::{self, Vec3}, math::Transform, input::{KeyCode, ActionHandler, Action, ActionKind, LayoutId, ActionMapping, ActionSource, ActionMappingId, InputActionPlugin, MouseInput, MouseAxis, CommonActionLabel}, game::Game, render::{window::{CursorGrabMode, WindowOptions}, light::{PointLight, directional::DirectionalLight, SpotLight}}, change_tracker::Ct, ecs::{system::{Criteria, CriteriaSchedule, BatchedSystem, IntoSystem}, world::World, Component}, DeltaTime, scene::{TransformComponent, ModelComponent, CameraComponent}, lua::{LuaScriptingPlugin, LuaScript}, Script, ScriptList};
|
||||
use lyra_engine::assets::{ResourceManager, Model};
|
||||
|
||||
mod free_fly_camera;
|
||||
|
@ -77,9 +77,9 @@ struct CubeFlag;
|
|||
async fn main() {
|
||||
let setup_sys = |world: &mut World| -> anyhow::Result<()> {
|
||||
{
|
||||
/* let mut window_options = world.get_resource_mut::<Ct<WindowOptions>>();
|
||||
let mut window_options = world.get_resource_mut::<Ct<WindowOptions>>();
|
||||
window_options.cursor_grab = CursorGrabMode::Confined;
|
||||
window_options.cursor_visible = false; */
|
||||
window_options.cursor_visible = false;
|
||||
}
|
||||
|
||||
let mut resman = world.get_resource_mut::<ResourceManager>();
|
||||
|
@ -92,14 +92,14 @@ async fn main() {
|
|||
|
||||
world.spawn((
|
||||
ModelComponent(antique_camera_model),
|
||||
Transform::from_xyz(0.0, -5.0, -10.0),
|
||||
TransformComponent::from(Transform::from_xyz(0.0, -5.0, -10.0)),
|
||||
));
|
||||
|
||||
{
|
||||
let cube_tran = Transform::from_xyz(-3.5, 0.0, -8.0);
|
||||
//cube_tran.rotate_y(math::Angle::Degrees(180.0));
|
||||
world.spawn((
|
||||
cube_tran,
|
||||
TransformComponent::from(cube_tran),
|
||||
ModelComponent(crate_model.clone()),
|
||||
CubeFlag,
|
||||
));
|
||||
|
@ -117,7 +117,7 @@ async fn main() {
|
|||
diffuse: 1.0,
|
||||
specular: 1.3,
|
||||
},
|
||||
light_tran,
|
||||
TransformComponent::from(light_tran),
|
||||
ModelComponent(cube_model.clone()),
|
||||
));
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ async fn main() {
|
|||
diffuse: 7.0,
|
||||
specular: 1.0,
|
||||
},
|
||||
Transform::from(light_tran),
|
||||
TransformComponent::from(light_tran),
|
||||
ModelComponent(cube_model.clone()),
|
||||
));
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ async fn main() {
|
|||
diffuse: 1.0,
|
||||
specular: 1.3,
|
||||
},
|
||||
Transform::from(light_tran),
|
||||
TransformComponent::from(light_tran),
|
||||
ModelComponent(cube_model),
|
||||
));
|
||||
}
|
||||
|
@ -214,13 +214,13 @@ async fn main() {
|
|||
const SPEED: f32 = 4.0;
|
||||
let delta_time = **world.get_resource::<DeltaTime>();
|
||||
|
||||
for (mut transform, _) in world.view_iter::<(&mut Transform, &CubeFlag)>() {
|
||||
let t = &mut transform;
|
||||
for (mut transform, _) in world.view_iter::<(&mut TransformComponent, &CubeFlag)>() {
|
||||
let t = &mut transform.transform;
|
||||
t.rotate_y(math::Angle::Degrees(SPEED * delta_time));
|
||||
}
|
||||
|
||||
for (mut transform, _s) in world.view_iter::<(&mut Transform, &mut SpotLight)>() {
|
||||
let t = &mut transform;
|
||||
for (mut transform, _s) in world.view_iter::<(&mut TransformComponent, &mut SpotLight)>() {
|
||||
let t = &mut transform.transform;
|
||||
t.rotate_x(math::Angle::Degrees(SPEED * delta_time));
|
||||
}
|
||||
|
||||
|
@ -235,8 +235,8 @@ async fn main() {
|
|||
sys.with_system(spin_system.into_system());
|
||||
//sys.with_system(fps_system);
|
||||
|
||||
//game.with_system("fixed", sys, &[]);
|
||||
//fps_plugin(game);
|
||||
game.with_system("fixed", sys, &[]);
|
||||
fps_plugin(game);
|
||||
};
|
||||
|
||||
let action_handler_plugin = |game: &mut Game| {
|
||||
|
@ -293,9 +293,7 @@ async fn main() {
|
|||
Ok(())
|
||||
}; */
|
||||
|
||||
let world = game.world();
|
||||
world.add_resource(action_handler);
|
||||
world.spawn((Vec3::new(0.5, 0.1, 3.0),));
|
||||
game.world().add_resource(action_handler);
|
||||
game.with_plugin(InputActionPlugin);
|
||||
//game.with_system("input_test", test_system, &[]);
|
||||
};
|
||||
|
|
|
@ -6,13 +6,13 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
math = ["dep:lyra-math"]
|
||||
math = ["dep:glam"]
|
||||
|
||||
[dependencies]
|
||||
lyra-ecs-derive = { path = "./lyra-ecs-derive" }
|
||||
lyra-math = { path = "../lyra-math", optional = true }
|
||||
anyhow = "1.0.75"
|
||||
thiserror = "1.0.50"
|
||||
glam = { version = "0.24.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.8.5" # used for tests
|
||||
|
|
|
@ -210,8 +210,6 @@ impl ArchetypeId {
|
|||
pub struct Archetype {
|
||||
pub id: ArchetypeId,
|
||||
pub(crate) entities: HashMap<Entity, ArchetypeEntityId>,
|
||||
/// map an Archetype entity id to an entity
|
||||
pub(crate) ids_to_entity: HashMap<ArchetypeEntityId, Entity>,
|
||||
pub(crate) columns: Vec<ComponentColumn>,
|
||||
pub capacity: usize,
|
||||
}
|
||||
|
@ -228,7 +226,6 @@ impl Archetype {
|
|||
Archetype {
|
||||
id: new_id,
|
||||
entities: HashMap::new(),
|
||||
ids_to_entity: HashMap::new(),
|
||||
columns,
|
||||
capacity: DEFAULT_CAPACITY,
|
||||
}
|
||||
|
@ -249,17 +246,16 @@ impl Archetype {
|
|||
self.capacity = new_cap;
|
||||
}
|
||||
|
||||
let entity_index = ArchetypeEntityId(self.entities.len() as u64);
|
||||
self.entities.insert(entity, entity_index);
|
||||
self.ids_to_entity.insert(entity_index, entity);
|
||||
let entity_index = self.entities.len();
|
||||
self.entities.insert(entity, ArchetypeEntityId(entity_index as u64));
|
||||
|
||||
bundle.take(|data, type_id, _size| {
|
||||
let col = self.get_column_mut(type_id).unwrap();
|
||||
unsafe { col.set_at(entity_index.0 as usize, data, *tick); }
|
||||
unsafe { col.set_at(entity_index, data, *tick); }
|
||||
col.len += 1;
|
||||
});
|
||||
|
||||
entity_index
|
||||
ArchetypeEntityId(entity_index as u64)
|
||||
}
|
||||
|
||||
/// Removes an entity from the Archetype and frees its components. Returns the entity record that took its place in the component column.
|
||||
|
@ -290,7 +286,6 @@ impl Archetype {
|
|||
|
||||
// safe from the .expect at the start of this method.
|
||||
self.entities.remove(&entity).unwrap();
|
||||
self.ids_to_entity.remove(&entity_index).unwrap();
|
||||
|
||||
// now change the ArchetypeEntityId to be the index that the moved entity was moved into.
|
||||
removed_entity.map(|(e, _a)| (e, entity_index))
|
||||
|
@ -356,15 +351,14 @@ impl Archetype {
|
|||
self.capacity = new_cap;
|
||||
}
|
||||
|
||||
let entity_index = ArchetypeEntityId(self.entities.len() as u64);
|
||||
self.entities.insert(entity, entity_index);
|
||||
self.ids_to_entity.insert(entity_index, entity);
|
||||
let entity_index = self.entities.len();
|
||||
self.entities.insert(entity, ArchetypeEntityId(entity_index as u64));
|
||||
|
||||
for col in self.columns.iter_mut() {
|
||||
col.len += 1;
|
||||
}
|
||||
|
||||
entity_index
|
||||
ArchetypeEntityId(entity_index as u64)
|
||||
}
|
||||
|
||||
/// Moves the entity from this archetype into another one.
|
||||
|
@ -407,10 +401,6 @@ impl Archetype {
|
|||
pub fn entities(&self) -> &HashMap<Entity, ArchetypeEntityId> {
|
||||
&self.entities
|
||||
}
|
||||
|
||||
pub fn entity_of_index(&self, id: ArchetypeEntityId) -> Option<Entity> {
|
||||
self.ids_to_entity.get(&id).cloned()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use crate::Component;
|
||||
|
||||
use lyra_math::{Vec3, Quat, Vec2, Vec4, Mat4, Transform};
|
||||
use glam::{Vec3, Quat, Vec2, Vec4, Mat4};
|
||||
|
||||
macro_rules! impl_external_component {
|
||||
macro_rules! impl_component_math {
|
||||
($type: ident) => {
|
||||
impl Component for $type {
|
||||
fn name() -> &'static str {
|
||||
|
@ -12,9 +12,8 @@ macro_rules! impl_external_component {
|
|||
};
|
||||
}
|
||||
|
||||
impl_external_component!(Vec2);
|
||||
impl_external_component!(Vec3);
|
||||
impl_external_component!(Vec4);
|
||||
impl_external_component!(Mat4);
|
||||
impl_external_component!(Quat);
|
||||
impl_external_component!(Transform);
|
||||
impl_component_math!(Vec2);
|
||||
impl_component_math!(Vec3);
|
||||
impl_component_math!(Vec4);
|
||||
impl_component_math!(Mat4);
|
||||
impl_component_math!(Quat);
|
|
@ -209,16 +209,6 @@ impl World {
|
|||
current_arch.remove_entity(entity, &tick);
|
||||
}
|
||||
|
||||
pub fn entity_archetype(&self, entity: Entity) -> Option<&Archetype> {
|
||||
self.entity_index.get(&entity.id)
|
||||
.and_then(|record| self.archetypes.get(&record.id))
|
||||
}
|
||||
|
||||
pub fn entity_archetype_mut(&mut self, entity: Entity) -> Option<&mut Archetype> {
|
||||
self.entity_index.get_mut(&entity.id)
|
||||
.and_then(|record| self.archetypes.get_mut(&record.id))
|
||||
}
|
||||
|
||||
/// View into the world for a set of entities that satisfy the queries.
|
||||
pub fn view_iter<T: 'static + AsQuery>(&self) -> ViewIter<T::Query> {
|
||||
let archetypes = self.archetypes.values().collect();
|
||||
|
|
|
@ -7,7 +7,6 @@ edition = "2021"
|
|||
lyra-resource = { path = "../lyra-resource" }
|
||||
lyra-ecs = { path = "../lyra-ecs", features = [ "math" ] }
|
||||
lyra-reflect = { path = "../lyra-reflect", features = [ "math" ] }
|
||||
lyra-math = { path = "../lyra-math" }
|
||||
|
||||
winit = "0.28.1"
|
||||
tracing = "0.1.37"
|
||||
|
|
|
@ -7,6 +7,7 @@ extern crate self as lyra_engine;
|
|||
pub mod game;
|
||||
pub mod render;
|
||||
pub mod resources;
|
||||
pub mod math;
|
||||
pub mod input;
|
||||
pub mod castable_any;
|
||||
pub mod plugin;
|
||||
|
@ -25,7 +26,6 @@ pub mod scene;
|
|||
|
||||
pub use lyra_resource as assets;
|
||||
pub use lyra_ecs as ecs;
|
||||
pub use lyra_math as math;
|
||||
|
||||
#[cfg(feature = "scripting")]
|
||||
pub use lyra_scripting as script;
|
||||
|
|
0
lyra-math/src/lib.rs → lyra-game/src/math/mod.rs
Normal file → Executable file
0
lyra-math/src/lib.rs → lyra-game/src/math/mod.rs
Normal file → Executable file
|
@ -1,9 +1,9 @@
|
|||
use glam::{Vec3, Mat4, Quat};
|
||||
|
||||
use super::Angle;
|
||||
use crate::math::angle::Angle;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Transform {
|
||||
pub translation: Vec3,
|
||||
pub rotation: Quat,
|
||||
|
@ -103,18 +103,4 @@ impl Transform {
|
|||
*self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a transform to another one
|
||||
///
|
||||
/// The Translations of each transform is added and rotation and scale is multiplied.
|
||||
impl std::ops::Add for Transform {
|
||||
type Output = Transform;
|
||||
|
||||
fn add(mut self, rhs: Self) -> Self::Output {
|
||||
self.translation += rhs.translation;
|
||||
self.rotation *= rhs.rotation;
|
||||
self.scale *= rhs.scale;
|
||||
self
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ use tracing::debug;
|
|||
|
||||
use std::mem;
|
||||
|
||||
use crate::math::Transform;
|
||||
use crate::{math::Transform, scene::TransformComponent};
|
||||
|
||||
use self::directional::DirectionalLight;
|
||||
|
||||
|
@ -169,29 +169,29 @@ impl LightUniformBuffers {
|
|||
|
||||
pub fn update_lights(&mut self, queue: &wgpu::Queue, world_tick: Tick, world: &World) {
|
||||
for (entity, point_light, transform, light_epoch, transform_epoch)
|
||||
in world.view_iter::<(Entities, &PointLight, &Transform, TickOf<PointLight>, TickOf<Transform>)>() {
|
||||
in world.view_iter::<(Entities, &PointLight, &TransformComponent, TickOf<PointLight>, TickOf<TransformComponent>)>() {
|
||||
|
||||
if !self.point_lights.has_light(entity) || light_epoch == world_tick || transform_epoch == world_tick {
|
||||
let uniform = PointLightUniform::from_bundle(&point_light, &transform);
|
||||
let uniform = PointLightUniform::from_bundle(&point_light, &transform.transform);
|
||||
self.point_lights.update_or_add(&mut self.lights_uniform.point_lights, entity, uniform);
|
||||
debug!("Updated point light");
|
||||
}
|
||||
}
|
||||
|
||||
for (entity, spot_light, transform, light_epoch, transform_epoch)
|
||||
in world.view_iter::<(Entities, &SpotLight, &Transform, TickOf<SpotLight>, TickOf<Transform>)>() {
|
||||
in world.view_iter::<(Entities, &SpotLight, &TransformComponent, TickOf<SpotLight>, TickOf<TransformComponent>)>() {
|
||||
|
||||
if !self.spot_lights.has_light(entity) || light_epoch == world_tick || transform_epoch == world_tick {
|
||||
let uniform = SpotLightUniform::from_bundle(&spot_light, &transform);
|
||||
let uniform = SpotLightUniform::from_bundle(&spot_light, &transform.transform);
|
||||
self.spot_lights.update_or_add(&mut self.lights_uniform.spot_lights, entity, uniform);
|
||||
//debug!("Updated spot light");
|
||||
}
|
||||
}
|
||||
|
||||
if let Some((dir_light, transform)) =
|
||||
world.view_iter::<(&DirectionalLight, &Transform)>().next() {
|
||||
world.view_iter::<(&DirectionalLight, &TransformComponent)>().next() {
|
||||
|
||||
let uniform = DirectionalLightUniform::from_bundle(&dir_light, &transform);
|
||||
let uniform = DirectionalLightUniform::from_bundle(&dir_light, &transform.transform);
|
||||
self.lights_uniform.directional_light = uniform;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ use winit::window::Window;
|
|||
use crate::math::Transform;
|
||||
use crate::render::material::MaterialUniform;
|
||||
use crate::render::render_buffer::BufferWrapperBuilder;
|
||||
use crate::scene::{ModelComponent, CameraComponent};
|
||||
use crate::scene::{ModelComponent, TransformComponent, CameraComponent};
|
||||
|
||||
use super::camera::{RenderCamera, CameraUniform};
|
||||
use super::desc_buf_lay::DescVertexBufferLayout;
|
||||
|
@ -395,13 +395,13 @@ impl Renderer for BasicRenderer {
|
|||
|
||||
let now_inst = Instant::now();
|
||||
|
||||
for (entity, model, model_epoch, transform, transform_epoch) in main_world.view_iter::<(Entities, &ModelComponent, TickOf<ModelComponent>, &Transform, TickOf<Transform>)>() {
|
||||
for (entity, model, model_epoch, transform, transform_epoch) in main_world.view_iter::<(Entities, &ModelComponent, TickOf<ModelComponent>, &TransformComponent, TickOf<TransformComponent>)>() {
|
||||
alive_entities.insert(entity);
|
||||
|
||||
let cached = match self.entity_last_transforms.get_mut(&entity) {
|
||||
Some(last) if transform_epoch == last_epoch => {
|
||||
last.from_transform = last.to_transform;
|
||||
last.to_transform = *transform;
|
||||
last.to_transform = transform.transform;
|
||||
last.last_updated_at = Some(last.cached_at);
|
||||
last.cached_at = now_inst;
|
||||
|
||||
|
@ -412,8 +412,8 @@ impl Renderer for BasicRenderer {
|
|||
let cached = CachedTransform {
|
||||
last_updated_at: None,
|
||||
cached_at: now_inst,
|
||||
from_transform: *transform,
|
||||
to_transform: *transform,
|
||||
from_transform: transform.transform,
|
||||
to_transform: transform.transform,
|
||||
};
|
||||
self.entity_last_transforms.insert(entity, cached.clone());
|
||||
cached
|
||||
|
|
|
@ -4,6 +4,9 @@ pub use mesh::*;
|
|||
pub mod model;
|
||||
pub use model::*;
|
||||
|
||||
pub mod transform;
|
||||
pub use transform::*;
|
||||
|
||||
pub mod camera;
|
||||
pub use camera::*;
|
||||
|
||||
|
|
26
lyra-game/src/scene/transform.rs
Executable file
26
lyra-game/src/scene/transform.rs
Executable file
|
@ -0,0 +1,26 @@
|
|||
use lyra_ecs::Component;
|
||||
|
||||
use crate::math::Transform;
|
||||
|
||||
#[derive(Clone, Component, Default)]
|
||||
pub struct TransformComponent {
|
||||
pub transform: Transform,
|
||||
}
|
||||
|
||||
impl From<Transform> for TransformComponent {
|
||||
fn from(transform: Transform) -> Self {
|
||||
Self {
|
||||
transform
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TransformComponent {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn from_transform(transform: Transform) -> Self {
|
||||
Self::from(transform)
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
[package]
|
||||
name = "lyra-math"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
glam = { version = "0.24.0" }
|
|
@ -6,9 +6,9 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
math = ["dep:lyra-math"]
|
||||
math = ["dep:glam"]
|
||||
|
||||
[dependencies]
|
||||
lyra-reflect-derive = { path = "lyra-reflect-derive" }
|
||||
lyra-ecs = { path = "../lyra-ecs" }
|
||||
lyra-math = { path = "../lyra-math", optional = true }
|
||||
glam = { version = "0.24.0", optional = true }
|
|
@ -4,7 +4,7 @@ use syn::{Token, parenthesized, punctuated::Punctuated};
|
|||
struct Field {
|
||||
name: syn::Ident,
|
||||
_eq: Token![=],
|
||||
ty: syn::Path,
|
||||
ty: syn::Ident,
|
||||
}
|
||||
|
||||
impl syn::parse::Parse for Field {
|
||||
|
|
|
@ -1,19 +1,10 @@
|
|||
use lyra_reflect_derive::{impl_reflect_simple_struct, impl_reflect_trait_value};
|
||||
|
||||
use crate::{lyra_engine, Method, Reflect};
|
||||
use crate::{lyra_engine, Reflect, Method};
|
||||
|
||||
impl_reflect_simple_struct!(lyra_math::Vec2, fields(x = f32, y = f32));
|
||||
impl_reflect_simple_struct!(lyra_math::Vec3, fields(x = f32, y = f32, z = f32));
|
||||
impl_reflect_simple_struct!(lyra_math::Vec4, fields(x = f32, y = f32, z = f32, w = f32));
|
||||
impl_reflect_simple_struct!(lyra_math::Quat, fields(x = f32, y = f32, z = f32, w = f32));
|
||||
impl_reflect_simple_struct!(glam::Vec2, fields(x=f32, y=f32));
|
||||
impl_reflect_simple_struct!(glam::Vec3, fields(x=f32, y=f32, z=f32));
|
||||
impl_reflect_simple_struct!(glam::Vec4, fields(x=f32, y=f32, z=f32, w=f32));
|
||||
impl_reflect_simple_struct!(glam::Quat, fields(x=f32, y=f32, z=f32, w=f32));
|
||||
|
||||
impl_reflect_simple_struct!(
|
||||
lyra_math::Transform,
|
||||
fields(
|
||||
translation = lyra_math::Vec3,
|
||||
rotation = lyra_math::Quat,
|
||||
scale = lyra_math::Vec3
|
||||
)
|
||||
);
|
||||
|
||||
impl_reflect_trait_value!(lyra_math::Mat4);
|
||||
impl_reflect_trait_value!(glam::Mat4);
|
|
@ -21,7 +21,6 @@ tracing = "0.1.37"
|
|||
|
||||
# enabled with lua feature
|
||||
mlua = { version = "0.9.2", features = ["lua54"], optional = true } # luajit maybe?
|
||||
itertools = "0.12.0"
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -220,9 +220,6 @@ pub(crate) struct WrapUsage {
|
|||
|
||||
pub matrix: Option<MatWrapper>,
|
||||
pub vec: Option<VecWrapper>,
|
||||
|
||||
pub custom_methods: Option<syn::Block>,
|
||||
pub custom_fields: Option<syn::Block>,
|
||||
}
|
||||
|
||||
impl syn::parse::Parse for WrapUsage {
|
||||
|
@ -237,8 +234,6 @@ impl syn::parse::Parse for WrapUsage {
|
|||
meta_method_idents: Punctuated::default(),
|
||||
matrix: None,
|
||||
vec: None,
|
||||
custom_methods: None,
|
||||
custom_fields: None,
|
||||
};
|
||||
/* let mut derive_idents = None;
|
||||
let mut field_idents = None;
|
||||
|
@ -303,14 +298,6 @@ impl syn::parse::Parse for WrapUsage {
|
|||
s.meta_method_idents = meta_methods;
|
||||
}
|
||||
},
|
||||
"custom_methods" => {
|
||||
let methods_block = input.parse()?;
|
||||
s.custom_methods = Some(methods_block);
|
||||
},
|
||||
"custom_fields" => {
|
||||
let block = input.parse()?;
|
||||
s.custom_fields = Some(block);
|
||||
}
|
||||
_ => {
|
||||
return Err(syn::Error::new_spanned(ident, "unknown wrapper command"));
|
||||
}
|
||||
|
@ -348,8 +335,6 @@ pub fn wrap_math_vec_copy(input: proc_macro::TokenStream) -> proc_macro::TokenSt
|
|||
vec.to_method_tokens(&path, &wrapper_typename));
|
||||
|
||||
let derive_idents_iter = input.derive_idents.iter();
|
||||
let custom_methods = input.custom_methods;
|
||||
let custom_fields = input.custom_fields;
|
||||
|
||||
let field_get_set_pairs = input.field_idents.iter().map(|i| {
|
||||
let is = i.to_string();
|
||||
|
@ -581,7 +566,7 @@ pub fn wrap_math_vec_copy(input: proc_macro::TokenStream) -> proc_macro::TokenSt
|
|||
fn from_lua(value: mlua::Value<'lua>, _lua: &'lua mlua::Lua) -> mlua::Result<Self> {
|
||||
match value {
|
||||
mlua::Value::UserData(ud) => Ok(*ud.borrow::<Self>()?),
|
||||
_ => panic!("Attempt to get {} from a {} value", stringify!(#wrapper_typename), value.type_name()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -592,8 +577,6 @@ pub fn wrap_math_vec_copy(input: proc_macro::TokenStream) -> proc_macro::TokenSt
|
|||
|
||||
#matrix_wrapper_fields
|
||||
#vec_wrapper_fields
|
||||
|
||||
#custom_fields
|
||||
}
|
||||
|
||||
fn add_methods<'lua, M: mlua::prelude::LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||
|
@ -608,19 +591,15 @@ pub fn wrap_math_vec_copy(input: proc_macro::TokenStream) -> proc_macro::TokenSt
|
|||
});
|
||||
|
||||
#meta_method_idents
|
||||
|
||||
|
||||
#matrix_wrapper_methods
|
||||
#vec_wrapper_methods
|
||||
|
||||
#custom_methods
|
||||
}
|
||||
}
|
||||
|
||||
impl lyra_scripting::lua::LuaWrapper for #wrapper_typename {
|
||||
fn wrapped_type_id() -> std::any::TypeId {
|
||||
let t = std::any::TypeId::of::<#path>();
|
||||
println!("Got id of {}, it is {:?}", stringify!(#path), t);
|
||||
t
|
||||
std::any::TypeId::of::<#path>()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{ptr::NonNull, ops::{Range, Deref}};
|
||||
|
||||
use lyra_ecs::{ComponentColumn, ComponentInfo, Archetype, ArchetypeId, ArchetypeEntityId, query::dynamic::{DynamicType, QueryDynamicType}, query::Fetch, Entity};
|
||||
use lyra_ecs::{ComponentColumn, ComponentInfo, Archetype, ArchetypeId, ArchetypeEntityId, query::dynamic::{DynamicType, QueryDynamicType}, query::Fetch};
|
||||
use lyra_reflect::TypeRegistry;
|
||||
|
||||
#[cfg(feature = "lua")]
|
||||
|
@ -45,11 +45,6 @@ impl<'a> From<lyra_ecs::query::dynamic::FetchDynamicType<'a>> for FetchDynamicTy
|
|||
}
|
||||
}
|
||||
|
||||
pub struct DynamicViewRow {
|
||||
entity: Entity,
|
||||
item: Vec<DynamicType>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DynamicViewIter {
|
||||
world_ptr: ScriptWorldPtr,
|
||||
|
@ -74,15 +69,15 @@ impl<'a> From<lyra_ecs::query::dynamic::DynamicViewIter<'a>> for DynamicViewIter
|
|||
}
|
||||
|
||||
impl Iterator for DynamicViewIter {
|
||||
type Item = DynamicViewRow;
|
||||
type Item = Vec<DynamicType>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
loop {
|
||||
if let Some(entity_index) = self.component_indices.next() {
|
||||
let mut fetch_res = vec![];
|
||||
|
||||
let entity_index = ArchetypeEntityId(entity_index);
|
||||
for fetcher in self.fetchers.iter_mut() {
|
||||
let entity_index = ArchetypeEntityId(entity_index);
|
||||
if !fetcher.can_visit_item(entity_index) {
|
||||
break;
|
||||
} else {
|
||||
|
@ -95,14 +90,7 @@ impl Iterator for DynamicViewIter {
|
|||
continue;
|
||||
}
|
||||
|
||||
let arch = unsafe { self.archetypes.get_unchecked(self.next_archetype - 1).as_ref() };
|
||||
let entity = arch.entity_of_index(entity_index).unwrap();
|
||||
let row = DynamicViewRow {
|
||||
entity,
|
||||
item: fetch_res,
|
||||
};
|
||||
|
||||
return Some(row);
|
||||
return Some(fetch_res);
|
||||
} else {
|
||||
if self.next_archetype >= self.archetypes.len() {
|
||||
return None; // ran out of archetypes to go through
|
||||
|
@ -133,19 +121,6 @@ impl Iterator for DynamicViewIter {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "lua")]
|
||||
pub struct ReflectedItem<'a> {
|
||||
pub proxy: &'a ReflectLuaProxy,
|
||||
pub comp_ptr: NonNull<u8>,
|
||||
pub comp_ud: mlua::AnyUserData<'a>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "lua")]
|
||||
pub struct ReflectedRow<'a> {
|
||||
pub entity: Entity,
|
||||
pub row: Vec<ReflectedItem<'a>>,
|
||||
}
|
||||
|
||||
pub struct ReflectedIterator {
|
||||
pub world: ScriptWorldPtr,
|
||||
pub dyn_view: DynamicViewIter,
|
||||
|
@ -156,7 +131,7 @@ impl ReflectedIterator {
|
|||
|
||||
|
||||
#[cfg(feature = "lua")]
|
||||
pub fn next_lua<'a>(&mut self, lua: &'a mlua::Lua) -> Option<ReflectedRow<'a>> {
|
||||
pub fn next_lua<'a>(&mut self, lua: &'a mlua::Lua) -> Option<Vec<( (&'a ReflectLuaProxy, NonNull<u8>), mlua::AnyUserData<'a>)>> {
|
||||
|
||||
let n = self.dyn_view.next();
|
||||
|
||||
|
@ -167,13 +142,8 @@ impl ReflectedIterator {
|
|||
.map(|r| NonNull::from(r.deref()));
|
||||
}
|
||||
|
||||
/* let mut row = ReflectedRow {
|
||||
entity: row.entity,
|
||||
row: row.item,
|
||||
}; */
|
||||
|
||||
let mut dynamic_row = vec![];
|
||||
for d in row.item.iter() {
|
||||
let mut dynamic_row = Vec::new();
|
||||
for d in row.iter() {
|
||||
let id = d.info.type_id.as_rust();
|
||||
let reflected_components =
|
||||
unsafe { self.reflected_components.as_ref().unwrap().as_ref() };
|
||||
|
@ -185,20 +155,10 @@ impl ReflectedIterator {
|
|||
|
||||
let userdata = (proxy.fn_as_uservalue)(lua, d.ptr).unwrap();
|
||||
|
||||
dynamic_row.push(ReflectedItem {
|
||||
proxy,
|
||||
comp_ptr: d.ptr,
|
||||
comp_ud: userdata
|
||||
});
|
||||
//dynamic_row.push(( (proxy, d.ptr), userdata));
|
||||
dynamic_row.push(( (proxy, d.ptr), userdata));
|
||||
}
|
||||
|
||||
let row = ReflectedRow {
|
||||
entity: row.entity,
|
||||
row: dynamic_row
|
||||
};
|
||||
|
||||
Some(row)
|
||||
Some(dynamic_row)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use lyra_ecs::World;
|
||||
use lyra_game::math;
|
||||
use crate::lua::RegisterLuaType;
|
||||
use crate::lua::wrappers::{LuaVec3, LuaTransform};
|
||||
use crate::lua::wrappers::LuaVec3;
|
||||
|
||||
use crate::{ScriptApiProvider, lua::LuaContext};
|
||||
|
||||
|
@ -13,7 +13,6 @@ impl ScriptApiProvider for LyraMathApiProvider {
|
|||
|
||||
fn prepare_world(&mut self, world: &mut World) {
|
||||
world.register_lua_wrapper::<LuaVec3>();
|
||||
world.register_lua_wrapper::<LuaTransform>();
|
||||
}
|
||||
|
||||
fn expose_api(&mut self, ctx: &mut Self::ScriptContext) -> Result<(), crate::ScriptError> {
|
||||
|
@ -30,7 +29,6 @@ impl ScriptApiProvider for LyraMathApiProvider {
|
|||
|
||||
let globals = ctx.globals();
|
||||
globals.set("Vec3", ctx.create_proxy::<LuaVec3>()?)?;
|
||||
globals.set("Transform", ctx.create_proxy::<LuaTransform>()?)?;
|
||||
//globals.set("Vec3", LuaVec3(math::Vec3::ZERO).into_lua(&ctx)?)?;
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{sync::Arc, ptr::NonNull};
|
||||
use std::sync::Arc;
|
||||
|
||||
use lyra_ecs::query::dynamic::QueryDynamicType;
|
||||
use lyra_reflect::TypeRegistry;
|
||||
|
@ -62,7 +62,7 @@ impl mlua::UserData for ScriptWorldPtr {
|
|||
|
||||
let f = lua.create_function_mut(move |lua, ()| {
|
||||
if let Some(row) = reflected_iter.next_lua(lua) {
|
||||
let row = row.row.into_iter().map(|i| i.comp_ud.into_lua(lua))
|
||||
let row = row.into_iter().map(|(_, ud)| ud.into_lua(lua))
|
||||
.collect::<mlua::Result<Vec<mlua::Value>>>()?;
|
||||
Ok(mlua::MultiValue::from_vec(row))
|
||||
} else {
|
||||
|
@ -73,7 +73,7 @@ impl mlua::UserData for ScriptWorldPtr {
|
|||
Ok(f)
|
||||
});
|
||||
|
||||
methods.add_method_mut("view", |lua, this, (system, queries): (mlua::Function, mlua::Variadic<mlua::AnyUserData>)| {
|
||||
methods.add_method("view", |lua, this, (system, queries): (mlua::Function, mlua::Variadic<mlua::AnyUserData>)| {
|
||||
if queries.is_empty() {
|
||||
return Err(mlua::Error::BadArgument { to: Some("world:view".to_string()), pos: 2, name: Some("...".to_string()), cause:
|
||||
Arc::new(mlua::Error::external(WorldError::LuaInvalidUsage("no component types provided".to_string())))
|
||||
|
@ -99,51 +99,29 @@ impl mlua::UserData for ScriptWorldPtr {
|
|||
reflected_components: None,
|
||||
};
|
||||
|
||||
let mut current = world.current_tick();
|
||||
let mut has_ticked = false;
|
||||
let reg = this.as_ref().get_resource::<TypeRegistry>();
|
||||
|
||||
while let Some(row) = reflected_iter.next_lua(lua) {
|
||||
let (reflects, values): (Vec<(_, _)>, Vec<_>) = row.into_iter().unzip();
|
||||
|
||||
let r = row.row.into_iter()
|
||||
.map(|r| (r.proxy, r.comp_ud, r.comp_ptr))
|
||||
.collect::<Vec<_>>();
|
||||
let (reflects, values, ptrs):
|
||||
(Vec<&ReflectLuaProxy>, Vec<mlua::AnyUserData>, Vec<NonNull<u8>>)
|
||||
= itertools::multiunzip(r);
|
||||
let value_row: Vec<_> = values.into_iter().map(|ud| ud.into_lua(lua)).collect::<mlua::Result<Vec<mlua::Value>>>()?;
|
||||
let mult_val = mlua::MultiValue::from_vec(value_row);
|
||||
let res: mlua::MultiValue = system.call(mult_val)?;
|
||||
|
||||
// if values were returned, find the type in the type registry, and apply the new values
|
||||
if res.len() <= reflects.len() {
|
||||
// we only want to tick one time per system
|
||||
if !has_ticked {
|
||||
current = world.tick();
|
||||
has_ticked = true;
|
||||
}
|
||||
|
||||
for (i, comp) in res.into_iter().enumerate() {
|
||||
let ptr = ptrs[i];
|
||||
let (_proxy, ptr) = reflects[i];
|
||||
|
||||
match comp.as_userdata() {
|
||||
Some(ud) => {
|
||||
let lua_comp = reflect_user_data(ud);
|
||||
let refl_comp = lua_comp.reflect_branch.as_component_unchecked();
|
||||
let lua_typeid = refl_comp.info.type_id.as_rust();
|
||||
|
||||
// update the component tick
|
||||
let world = unsafe { this.inner.as_mut() };
|
||||
let arch = world.entity_archetype_mut(row.entity).unwrap();
|
||||
let idx = arch.entities().get(&row.entity).unwrap().clone();
|
||||
let c = arch.get_column_mut(refl_comp.type_id.into()).unwrap();
|
||||
c.entity_ticks[idx.0 as usize] = current;
|
||||
|
||||
// apply the new component data
|
||||
let reg = this.as_ref().get_resource::<TypeRegistry>();
|
||||
let reg_type = reg.get_type(lua_typeid).unwrap();
|
||||
|
||||
|
||||
let proxy = reg_type.get_data::<ReflectLuaProxy>().unwrap();
|
||||
(proxy.fn_apply)(lua, ptr, ud)?;
|
||||
(proxy.fn_apply)(lua, ptr, ud)?
|
||||
}
|
||||
None => {
|
||||
panic!("A userdata value was not returned!");
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::lyra_engine;
|
|||
use crate as lyra_scripting;
|
||||
|
||||
// f32 types
|
||||
wrap_math_vec_copy!(
|
||||
/* wrap_math_vec_copy!(
|
||||
math::Vec2,
|
||||
derives(PartialEq),
|
||||
fields(x, y),
|
||||
|
@ -17,27 +17,23 @@ wrap_math_vec_copy!(
|
|||
Mod(LuaVec2, f32),
|
||||
Eq, Unm
|
||||
)
|
||||
);
|
||||
); */
|
||||
wrap_math_vec_copy!(
|
||||
math::Vec3,
|
||||
derives(PartialEq),
|
||||
fields(x, y, z),
|
||||
metamethods(
|
||||
Add(LuaVec3),
|
||||
ToString,
|
||||
Eq, Unm
|
||||
)
|
||||
/* metamethods(
|
||||
Add(LuaVec3, f32),
|
||||
Sub(LuaVec3, f32),
|
||||
Div(LuaVec3, f32),
|
||||
Mul(LuaVec3, f32),
|
||||
Mod(LuaVec3, f32),
|
||||
Eq, Unm, ToString,
|
||||
),
|
||||
custom_methods {
|
||||
/* methods.add_meta_method(mlua::MetaMethod::Add, |_, this, (trans,): (LuaTransform,)| {
|
||||
println!("Adding");
|
||||
let mut t = *trans;
|
||||
t.translation += **this;
|
||||
Ok(LuaTransform(t))
|
||||
}); */
|
||||
}
|
||||
Eq, Unm
|
||||
) */
|
||||
);
|
||||
/* wrap_math_vec_copy!(
|
||||
math::Vec3A,
|
||||
|
@ -366,201 +362,4 @@ wrap_math_vec_copy!(
|
|||
Mul(LuaMat2, f32),
|
||||
Unm
|
||||
)
|
||||
); */
|
||||
|
||||
/* wrap_math_vec_copy!(
|
||||
math::Mat4,
|
||||
derives(PartialEq),
|
||||
no_new,
|
||||
matrix {
|
||||
col_type = LuaVec4
|
||||
},
|
||||
metamethods(
|
||||
Eq,
|
||||
Add,
|
||||
Sub,
|
||||
Mul(LuaMat4, f32),
|
||||
Unm
|
||||
)
|
||||
); */
|
||||
|
||||
wrap_math_vec_copy!(
|
||||
math::Quat,
|
||||
derives(PartialEq),
|
||||
no_new,
|
||||
metamethods(
|
||||
Eq,
|
||||
// __mul for LuaVec3 is manually implemented below since it doesn't return Self
|
||||
Mul(LuaQuat, f32),
|
||||
Add,
|
||||
Sub,
|
||||
Div(f32),
|
||||
),
|
||||
custom_methods {
|
||||
methods.add_function("new", |_, (x, y, z, w)| {
|
||||
Ok(Self(math::Quat::from_xyzw(x, y, z, w)))
|
||||
});
|
||||
|
||||
methods.add_function("from_rotation_x", |_, (rad,)| {
|
||||
let q = math::Quat::from_rotation_x(rad);
|
||||
Ok(Self(q))
|
||||
});
|
||||
|
||||
methods.add_function("from_rotation_y", |_, (rad,)| {
|
||||
let q = math::Quat::from_rotation_y(rad);
|
||||
Ok(Self(q))
|
||||
});
|
||||
|
||||
methods.add_function("from_rotation_z", |_, (rad,)| {
|
||||
let q = math::Quat::from_rotation_z(rad);
|
||||
Ok(Self(q))
|
||||
});
|
||||
|
||||
methods.add_method("dot", |_, this, (rhs,): (Self,)| {
|
||||
Ok(this.dot(rhs.0))
|
||||
});
|
||||
|
||||
methods.add_method("length", |_, this, ()| {
|
||||
Ok(this.length())
|
||||
});
|
||||
|
||||
methods.add_method("length_squared", |_, this, ()| {
|
||||
Ok(this.length_squared())
|
||||
});
|
||||
|
||||
methods.add_method("normalize", |_, this, ()| {
|
||||
Ok(Self(this.normalize()))
|
||||
});
|
||||
|
||||
methods.add_method("mult_quat", |_, this, (rhs,): (Self,)| {
|
||||
Ok(Self(this.0 * rhs.0))
|
||||
});
|
||||
|
||||
methods.add_method("mult_vec3", |_, this, (rhs,): (LuaVec3,)| {
|
||||
Ok(LuaVec3(this.0 * rhs.0))
|
||||
});
|
||||
|
||||
// manually implemented here since it doesn't return `Self`
|
||||
methods.add_meta_method(mlua::MetaMethod::Mul, |_, this, (rhs,): (LuaVec3,)| {
|
||||
Ok(LuaVec3(this.0 * rhs.0))
|
||||
});
|
||||
|
||||
methods.add_method("lerp", |_, this, (rhs, alpha): (Self, f32)| {
|
||||
Ok(Self(this.lerp(*rhs, alpha)))
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
wrap_math_vec_copy!(
|
||||
math::Transform,
|
||||
//derives(PartialEq),
|
||||
no_new,
|
||||
metamethods(ToString, Eq),
|
||||
custom_fields {
|
||||
fields.add_field_method_get("translation", |_, this| {
|
||||
Ok(LuaVec3(this.translation))
|
||||
});
|
||||
fields.add_field_method_set("translation", |_, this, v: LuaVec3| {
|
||||
this.translation = *v;
|
||||
Ok(())
|
||||
});
|
||||
|
||||
fields.add_field_method_get("rotation", |_, this| {
|
||||
Ok(LuaQuat(this.rotation))
|
||||
});
|
||||
fields.add_field_method_set("rotation", |_, this, v: LuaQuat| {
|
||||
this.rotation = *v;
|
||||
Ok(())
|
||||
});
|
||||
|
||||
fields.add_field_method_get("scale", |_, this| {
|
||||
Ok(LuaVec3(this.scale))
|
||||
});
|
||||
fields.add_field_method_set("scale", |_, this, v: LuaVec3| {
|
||||
this.scale = *v;
|
||||
Ok(())
|
||||
});
|
||||
},
|
||||
custom_methods {
|
||||
methods.add_function("default", |_, ()| {
|
||||
Ok(Self(math::Transform::default()))
|
||||
});
|
||||
|
||||
methods.add_function("new", |_, (pos, rot, scale): (LuaVec3, LuaQuat, LuaVec3)| {
|
||||
Ok(Self(math::Transform::new(*pos, *rot, *scale)))
|
||||
});
|
||||
|
||||
methods.add_function("from_translation", |_, (pos,): (LuaVec3,)| {
|
||||
Ok(Self(math::Transform::from_translation(*pos)))
|
||||
});
|
||||
|
||||
methods.add_function("from_xyz", |_, (x, y, z)| {
|
||||
Ok(Self(math::Transform::from_xyz(x, y, z)))
|
||||
});
|
||||
|
||||
methods.add_method("forward", |_, this, ()| {
|
||||
Ok(LuaVec3(this.forward()))
|
||||
});
|
||||
|
||||
methods.add_method("left", |_, this, ()| {
|
||||
Ok(LuaVec3(this.left()))
|
||||
});
|
||||
|
||||
methods.add_method("up", |_, this, ()| {
|
||||
Ok(LuaVec3(this.up()))
|
||||
});
|
||||
|
||||
methods.add_method_mut("rotate", |_, this, (quat,): (LuaQuat,)| {
|
||||
this.rotate(*quat);
|
||||
Ok(())
|
||||
});
|
||||
|
||||
methods.add_method_mut("rotate_x", |_, this, (deg,): (f32,)| {
|
||||
this.rotate_x(math::Angle::Degrees(deg));
|
||||
Ok(())
|
||||
});
|
||||
|
||||
methods.add_method_mut("rotate_y", |_, this, (deg,): (f32,)| {
|
||||
this.rotate_y(math::Angle::Degrees(deg));
|
||||
Ok(())
|
||||
});
|
||||
|
||||
methods.add_method_mut("rotate_z", |_, this, (deg,): (f32,)| {
|
||||
this.rotate_z(math::Angle::Degrees(deg));
|
||||
Ok(())
|
||||
});
|
||||
|
||||
methods.add_method_mut("rotate_x_rad", |_, this, (rad,): (f32,)| {
|
||||
this.rotate_x(math::Angle::Radians(rad));
|
||||
Ok(())
|
||||
});
|
||||
|
||||
methods.add_method_mut("rotate_y_rad", |_, this, (rad,): (f32,)| {
|
||||
this.rotate_y(math::Angle::Radians(rad));
|
||||
Ok(())
|
||||
});
|
||||
|
||||
methods.add_method_mut("rotate_z_rad", |_, this, (rad,): (f32,)| {
|
||||
this.rotate_z(math::Angle::Radians(rad));
|
||||
Ok(())
|
||||
});
|
||||
|
||||
methods.add_method("lerp", |_, this, (rhs, alpha): (Self, f32)| {
|
||||
Ok(Self(this.lerp(*rhs, alpha)))
|
||||
});
|
||||
|
||||
// rotate a transform
|
||||
methods.add_meta_method(mlua::MetaMethod::Mul, |_, this, (quat,): (LuaQuat,)| {
|
||||
let mut t = *this;
|
||||
t.rotation *= *quat;
|
||||
Ok(t)
|
||||
});
|
||||
|
||||
// move a transform
|
||||
methods.add_meta_method(mlua::MetaMethod::Add, |_, this, (pos,): (LuaVec3,)| {
|
||||
let mut t = *this;
|
||||
t.translation += *pos;
|
||||
Ok(t)
|
||||
});
|
||||
}
|
||||
);
|
||||
); */
|
Loading…
Add table
Reference in a new issue