mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
moved math + curve + octree mods to fyrox-math crate
This commit is contained in:
Generated
+1
@@ -34,6 +34,7 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/fyrox-animation/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/fyrox-prefab/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/fyrox-graph/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/fyrox-math/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/examples/wasm/target" />
|
||||
</content>
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ members = [
|
||||
"editor-standalone",
|
||||
"template",
|
||||
"fyrox-graph"
|
||||
]
|
||||
, "fyrox-math"]
|
||||
|
||||
[profile.dev]
|
||||
opt-level = 0
|
||||
|
||||
@@ -6,8 +6,8 @@ use crate::{
|
||||
};
|
||||
use fyrox::{
|
||||
core::{
|
||||
curve::Curve,
|
||||
log::Log,
|
||||
math::curve::Curve,
|
||||
pool::{ErasedHandle, Handle, Ticket},
|
||||
uuid::Uuid,
|
||||
variable::InheritableVariable,
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
use fyrox::{
|
||||
asset::{untyped::ResourceKind, Resource},
|
||||
core::{
|
||||
color::Color, curve::Curve, futures::executor::block_on, pool::Handle,
|
||||
color::Color, futures::executor::block_on, math::curve::Curve, pool::Handle,
|
||||
type_traits::prelude::*, visitor::prelude::*, visitor::Visitor,
|
||||
},
|
||||
engine::Engine,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use crate::{
|
||||
core::{
|
||||
algebra::{Vector2, Vector3, Vector4},
|
||||
curve::Curve,
|
||||
math::curve::Curve,
|
||||
math::{quat_from_euler, RotationOrder},
|
||||
reflect::prelude::*,
|
||||
visitor::prelude::*,
|
||||
|
||||
@@ -121,7 +121,7 @@ pub mod value;
|
||||
/// value::ValueBinding,
|
||||
/// Animation,
|
||||
/// core::{
|
||||
/// curve::{Curve, CurveKey, CurveKeyKind},
|
||||
/// math::curve::{Curve, CurveKey, CurveKeyKind},
|
||||
/// pool::Handle,
|
||||
/// },
|
||||
/// };
|
||||
|
||||
@@ -46,6 +46,12 @@ pub fn impl_reflect(input: TokenStream) -> TokenStream {
|
||||
TokenStream::from(reflect_impl)
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn impl_visit(input: TokenStream) -> TokenStream {
|
||||
let ast = parse_macro_input!(input as DeriveInput);
|
||||
TokenStream::from(visit::impl_visit(ast))
|
||||
}
|
||||
|
||||
/// Implements `TypeUuidProvider` trait
|
||||
///
|
||||
/// User has to import `TypeUuidProvider` trait to use this macro.
|
||||
|
||||
@@ -17,7 +17,7 @@ rust-version = "1.72"
|
||||
|
||||
[dependencies]
|
||||
fyrox-core-derive = { path = "../fyrox-core-derive", version = "0.22.0" }
|
||||
|
||||
fyrox-math = { path = "../fyrox-math", version = "0.1.0" }
|
||||
base64 = "0.21.0"
|
||||
byteorder = "1.4.3"
|
||||
rand = "0.8.4"
|
||||
@@ -36,7 +36,6 @@ once_cell = "1.17.1"
|
||||
notify = "6"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
bincode = "1.3.3"
|
||||
rectutils = "0.1.0"
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
web-sys = { version = "0.3.53", features = ["Request", "Window", "Response", "AudioContext", "AudioBuffer", "AudioContextOptions", "AudioNode", "AudioBufferSourceNode", "AudioDestinationNode"] }
|
||||
|
||||
@@ -31,13 +31,11 @@ use std::{
|
||||
|
||||
pub mod color;
|
||||
pub mod color_gradient;
|
||||
pub mod curve;
|
||||
pub mod io;
|
||||
pub mod log;
|
||||
pub mod math;
|
||||
pub mod net;
|
||||
pub mod numeric_range;
|
||||
pub mod octree;
|
||||
pub mod pool;
|
||||
pub mod profiler;
|
||||
pub mod quadtree;
|
||||
|
||||
+104
-1526
File diff suppressed because it is too large
Load Diff
@@ -1 +1 @@
|
||||
pub use rectutils::quadtree::*;
|
||||
pub use crate::math::quadtree::*;
|
||||
|
||||
@@ -1 +1 @@
|
||||
pub use rectutils::pack::RectPacker;
|
||||
pub use crate::math::pack::RectPacker;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "fyrox-math"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
rectutils = "0.1.0"
|
||||
nalgebra = "0.32.3"
|
||||
arrayvec = "0.7.4"
|
||||
num-traits = "0.2.18"
|
||||
uuid = "1.7.0"
|
||||
@@ -1,10 +1,7 @@
|
||||
use crate::{
|
||||
algebra::{Matrix4, Vector3},
|
||||
math::Matrix4Ext,
|
||||
visitor::{Visit, VisitResult, Visitor},
|
||||
};
|
||||
use crate::Matrix4Ext;
|
||||
use nalgebra::{Matrix4, Vector3};
|
||||
|
||||
#[derive(Copy, Clone, Debug, Visit)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct AxisAlignedBoundingBox {
|
||||
pub min: Vector3<f32>,
|
||||
pub max: Vector3<f32>,
|
||||
@@ -305,8 +302,8 @@ impl AxisAlignedBoundingBox {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::algebra::{Matrix4, Vector3};
|
||||
use crate::math::aabb::AxisAlignedBoundingBox;
|
||||
use crate::aabb::AxisAlignedBoundingBox;
|
||||
use nalgebra::{Matrix4, Vector3};
|
||||
|
||||
#[test]
|
||||
fn test_aabb_transform() {
|
||||
@@ -1,8 +1,4 @@
|
||||
use crate::{
|
||||
math::{cubicf, inf_sup_cubicf, lerpf, Rect},
|
||||
reflect::prelude::*,
|
||||
visitor::prelude::*,
|
||||
};
|
||||
use crate::{cubicf, inf_sup_cubicf, lerpf, Rect};
|
||||
use std::cmp::Ordering;
|
||||
use uuid::Uuid;
|
||||
|
||||
@@ -14,7 +10,7 @@ fn stepf(p0: f32, p1: f32, t: f32) -> f32 {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Visit, Default, Clone, Debug, PartialEq, Reflect)]
|
||||
#[derive(Default, Clone, Debug, PartialEq)]
|
||||
pub enum CurveKeyKind {
|
||||
#[default]
|
||||
Constant,
|
||||
@@ -37,10 +33,10 @@ impl CurveKeyKind {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Visit, Clone, Default, Debug, PartialEq)]
|
||||
#[derive(Clone, Default, Debug, PartialEq)]
|
||||
pub struct CurveKey {
|
||||
pub id: Uuid,
|
||||
location: f32,
|
||||
pub location: f32,
|
||||
pub value: f32,
|
||||
pub kind: CurveKeyKind,
|
||||
}
|
||||
@@ -111,16 +107,11 @@ impl CurveKey {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Visit, Reflect, Clone, Debug, PartialEq)]
|
||||
#[reflect(hide_all)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Curve {
|
||||
#[visit(optional)] // Backward compatibility
|
||||
id: Uuid,
|
||||
|
||||
#[visit(optional)] // Backward compatibility
|
||||
name: String,
|
||||
|
||||
keys: Vec<CurveKey>,
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub keys: Vec<CurveKey>,
|
||||
}
|
||||
|
||||
impl Default for Curve {
|
||||
@@ -1,15 +1,12 @@
|
||||
use crate::{
|
||||
algebra::{Matrix4, Vector3},
|
||||
math::{aabb::AxisAlignedBoundingBox, plane::Plane},
|
||||
visitor::{Visit, VisitResult, Visitor},
|
||||
};
|
||||
use crate::{aabb::AxisAlignedBoundingBox, plane::Plane};
|
||||
use nalgebra::Point3;
|
||||
use nalgebra::{Matrix4, Vector3};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub struct Frustum {
|
||||
/// 0 - left, 1 - right, 2 - top, 3 - bottom, 4 - far, 5 - near
|
||||
planes: [Plane; 6],
|
||||
corners: [Vector3<f32>; 8],
|
||||
pub planes: [Plane; 6],
|
||||
pub corners: [Vector3<f32>; 8],
|
||||
}
|
||||
|
||||
impl Default for Frustum {
|
||||
@@ -330,29 +327,12 @@ impl Frustum {
|
||||
}
|
||||
}
|
||||
|
||||
impl Visit for Frustum {
|
||||
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
|
||||
let mut region = visitor.enter_region(name)?;
|
||||
|
||||
self.planes[0].visit("Left", &mut region)?;
|
||||
self.planes[1].visit("Right", &mut region)?;
|
||||
self.planes[2].visit("Top", &mut region)?;
|
||||
self.planes[3].visit("Bottom", &mut region)?;
|
||||
self.planes[4].visit("Far", &mut region)?;
|
||||
self.planes[5].visit("Near", &mut region)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::aabb::AxisAlignedBoundingBox;
|
||||
use crate::{frustum::Frustum, plane::Plane};
|
||||
use nalgebra::{Matrix4, Vector3};
|
||||
|
||||
use crate::math::aabb::AxisAlignedBoundingBox;
|
||||
use crate::math::{frustum::Frustum, plane::Plane};
|
||||
use crate::visitor::{Visit, Visitor};
|
||||
|
||||
#[test]
|
||||
fn test_default_for_frustum() {
|
||||
assert_eq!(
|
||||
@@ -550,18 +530,4 @@ mod test {
|
||||
assert!(f.is_intersects_sphere(Vector3::new(0.0, 0.0, 0.0), 2.0));
|
||||
assert!(!f.is_intersects_sphere(Vector3::new(10.0, 10.0, 10.0), 1.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_visit_for_frustum() {
|
||||
let mut f = Frustum::from_view_projection_matrix(Matrix4::new(
|
||||
1.0, 0.0, 0.0, 0.0, //
|
||||
0.0, 1.0, 0.0, 0.0, //
|
||||
0.0, 0.0, 1.0, 0.0, //
|
||||
0.0, 0.0, 0.0, 1.0,
|
||||
))
|
||||
.unwrap();
|
||||
let mut visitor = Visitor::default();
|
||||
|
||||
assert!(f.visit("name", &mut visitor).is_ok());
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
use crate::algebra::Vector3;
|
||||
use crate::math::{aabb::AxisAlignedBoundingBox, ray::Ray};
|
||||
use crate::{aabb::AxisAlignedBoundingBox, ray::Ray};
|
||||
use arrayvec::ArrayVec;
|
||||
use nalgebra::Vector3;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum OctreeNode {
|
||||
@@ -1,9 +1,6 @@
|
||||
use crate::{
|
||||
algebra::Vector3,
|
||||
visitor::{Visit, VisitResult, Visitor},
|
||||
};
|
||||
use nalgebra::Vector3;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Visit)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub struct Plane {
|
||||
pub normal: Vector3<f32>,
|
||||
pub d: f32,
|
||||
@@ -87,10 +84,9 @@ impl Plane {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::plane::Plane;
|
||||
use nalgebra::Vector3;
|
||||
|
||||
use crate::math::plane::Plane;
|
||||
|
||||
#[test]
|
||||
fn plane_sanity_tests() {
|
||||
// Computation test
|
||||
@@ -1,9 +1,9 @@
|
||||
// Clippy complains about normal mathematical symbols like A, B, C for quadratic equation.
|
||||
#![allow(clippy::many_single_char_names)]
|
||||
|
||||
use crate::algebra::{Matrix4, Point3, Vector3};
|
||||
use crate::math::aabb::AxisAlignedBoundingBox;
|
||||
use crate::math::{is_point_inside_triangle, plane::Plane, solve_quadratic};
|
||||
use crate::aabb::AxisAlignedBoundingBox;
|
||||
use crate::{is_point_inside_triangle, plane::Plane, solve_quadratic};
|
||||
use nalgebra::{Matrix4, Point3, Vector3};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct Ray {
|
||||
@@ -439,10 +439,12 @@ impl Ray {
|
||||
mod test {
|
||||
use nalgebra::Matrix4;
|
||||
|
||||
use crate::math::aabb::AxisAlignedBoundingBox;
|
||||
use crate::math::plane::Plane;
|
||||
use crate::math::ray::{CylinderKind, Ray};
|
||||
use crate::math::Vector3;
|
||||
use crate::{
|
||||
aabb::AxisAlignedBoundingBox,
|
||||
plane::Plane,
|
||||
ray::{CylinderKind, Ray},
|
||||
Vector3,
|
||||
};
|
||||
|
||||
use super::IntersectionResult;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::math;
|
||||
use nalgebra::{Vector2, Vector3};
|
||||
use std::fmt;
|
||||
|
||||
@@ -74,7 +73,7 @@ fn is_ear(poly: &Polygon, prev: &Vertex, ear: &Vertex, next: &Vertex) -> bool {
|
||||
if i != prev.index
|
||||
&& i != ear.index
|
||||
&& i != next.index
|
||||
&& math::is_point_inside_2d_triangle(
|
||||
&& crate::is_point_inside_2d_triangle(
|
||||
vertex.position,
|
||||
prev.position,
|
||||
ear.position,
|
||||
@@ -126,14 +125,14 @@ pub fn triangulate(vertices: &[Vector3<f32>], out_triangles: &mut Vec<[usize; 3]
|
||||
} else {
|
||||
// Ear-clipping for arbitrary polygon (requires one additional memory allocation, so
|
||||
// relatively slow)
|
||||
if let Ok(normal) = math::get_polygon_normal(vertices) {
|
||||
let plane_class = math::classify_plane(normal);
|
||||
if let Ok(normal) = crate::get_polygon_normal(vertices) {
|
||||
let plane_class = crate::classify_plane(normal);
|
||||
let mut polygon = Polygon {
|
||||
vertices: vertices
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, point)| Vertex {
|
||||
position: math::vec3_to_vec2_by_plane(plane_class, normal, *point),
|
||||
position: crate::vec3_to_vec2_by_plane(plane_class, normal, *point),
|
||||
index: i,
|
||||
prev: if i == 0 { vertices.len() - 1 } else { i - 1 },
|
||||
next: if i == vertices.len() - 1 { 0 } else { i + 1 },
|
||||
@@ -172,8 +171,8 @@ pub fn triangulate(vertices: &[Vector3<f32>], out_triangles: &mut Vec<[usize; 3]
|
||||
mod test {
|
||||
use nalgebra::Vector2;
|
||||
|
||||
use crate::algebra::{Point3, Unit, UnitQuaternion, Vector3};
|
||||
use crate::math::triangulator::triangulate;
|
||||
use crate::triangulator::triangulate;
|
||||
use nalgebra::{Point3, Unit, UnitQuaternion, Vector3};
|
||||
|
||||
use super::{Polygon, Vertex};
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
Resource, ResourceData, ResourceLoadError, TypedResourceData, CURVE_RESOURCE_UUID,
|
||||
MODEL_RESOURCE_UUID, SHADER_RESOURCE_UUID, SOUND_BUFFER_RESOURCE_UUID, TEXTURE_RESOURCE_UUID,
|
||||
};
|
||||
use fyrox_core::curve::Curve;
|
||||
use fyrox_core::math::curve::Curve;
|
||||
use fyrox_core::visitor::RegionGuard;
|
||||
use std::ffi::OsStr;
|
||||
use std::fmt::Display;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
use fyrox::{
|
||||
core::{
|
||||
algebra::{UnitQuaternion, UnitVector3, Vector3},
|
||||
curve::{Curve, CurveKey, CurveKeyKind},
|
||||
impl_component_provider,
|
||||
math::curve::{Curve, CurveKey, CurveKeyKind},
|
||||
math::Vector3Ext,
|
||||
reflect::prelude::*,
|
||||
uuid_provider,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::core::{
|
||||
algebra::Vector2,
|
||||
curve::{Curve, CurveKey, CurveKeyKind},
|
||||
math::curve::{Curve, CurveKey, CurveKeyKind},
|
||||
reflect::prelude::*,
|
||||
uuid::Uuid,
|
||||
visitor::prelude::*,
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::{
|
||||
core::{
|
||||
algebra::{Matrix3, Point2, SimdPartialOrd, Vector2, Vector3},
|
||||
color::Color,
|
||||
curve::{Curve, CurveKeyKind},
|
||||
math::curve::{Curve, CurveKeyKind},
|
||||
math::{cubicf, lerpf, wrap_angle, Rect},
|
||||
pool::Handle,
|
||||
type_traits::prelude::*,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
core::{algebra::Vector2, curve::Curve},
|
||||
core::{algebra::Vector2, math::curve::Curve},
|
||||
curve::{CurveEditorBuilder, CurveEditorMessage},
|
||||
inspector::{
|
||||
editors::{
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
algebra::{UnitQuaternion, Vector2, Vector3, Vector4},
|
||||
color::Color,
|
||||
color_gradient::ColorGradient,
|
||||
curve::Curve,
|
||||
math::curve::Curve,
|
||||
math::{Rect, SmoothAngle},
|
||||
parking_lot::{RwLock, RwLockReadGuard},
|
||||
pool::Handle,
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
use crate::{
|
||||
asset::{io::ResourceIo, Resource, ResourceData, CURVE_RESOURCE_UUID},
|
||||
core::{
|
||||
curve::Curve, io::FileLoadError, reflect::prelude::*, uuid::Uuid, visitor::prelude::*,
|
||||
TypeUuidProvider,
|
||||
io::FileLoadError, math::curve::Curve, reflect::prelude::*, uuid::Uuid,
|
||||
visitor::prelude::*, TypeUuidProvider,
|
||||
},
|
||||
};
|
||||
use std::error::Error;
|
||||
|
||||
@@ -15,9 +15,9 @@ use crate::{
|
||||
asset::manager::ResourceManager,
|
||||
core::{
|
||||
algebra::{Matrix4, Point3, UnitQuaternion, Vector2, Vector3, Vector4},
|
||||
curve::{CurveKey, CurveKeyKind},
|
||||
instant::Instant,
|
||||
log::{Log, MessageKind},
|
||||
math::curve::{CurveKey, CurveKeyKind},
|
||||
math::{self, triangulator::triangulate, RotationOrder},
|
||||
pool::Handle,
|
||||
sstorage::ImmutableString,
|
||||
|
||||
@@ -174,7 +174,7 @@ impl BoundValueCollectionExt for BoundValueCollection {
|
||||
/// ```rust
|
||||
/// use fyrox::{
|
||||
/// core::{
|
||||
/// curve::{Curve, CurveKey, CurveKeyKind},
|
||||
/// math::curve::{Curve, CurveKey, CurveKeyKind},
|
||||
/// pool::Handle,
|
||||
/// },
|
||||
/// scene::{animation::prelude::*, base::BaseBuilder, graph::Graph, node::Node},
|
||||
|
||||
@@ -12,7 +12,6 @@ use crate::{
|
||||
algebra::{Matrix3, Matrix4, Point3, Vector2, Vector3, Vector4},
|
||||
arrayvec::ArrayVec,
|
||||
math::{self, ray::Ray, Matrix4Ext, Rect, TriangleDefinition, Vector2Ext},
|
||||
octree::{Octree, OctreeNode},
|
||||
pool::Handle,
|
||||
reflect::prelude::*,
|
||||
sstorage::ImmutableString,
|
||||
@@ -37,6 +36,7 @@ use crate::{
|
||||
utils::{uvgen, uvgen::SurfaceDataPatch},
|
||||
};
|
||||
use fxhash::FxHashMap;
|
||||
use fyrox_core::math::octree::{Octree, OctreeNode};
|
||||
use rayon::prelude::*;
|
||||
use std::{
|
||||
fmt::{Display, Formatter},
|
||||
|
||||
@@ -10,7 +10,6 @@ use crate::{
|
||||
algebra::{Point3, Vector3},
|
||||
arrayvec::ArrayVec,
|
||||
math::{self, plane::Plane, ray::Ray, PositionProvider, TriangleDefinition, Vector3Ext},
|
||||
octree::{Octree, OctreeNode},
|
||||
reflect::prelude::*,
|
||||
visitor::{Visit, VisitResult, Visitor},
|
||||
},
|
||||
@@ -24,6 +23,7 @@ use crate::{
|
||||
},
|
||||
};
|
||||
use fxhash::{FxBuildHasher, FxHashMap};
|
||||
use fyrox_core::math::octree::{Octree, OctreeNode};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
#[derive(Clone, Debug, Default, Visit)]
|
||||
|
||||
Reference in New Issue
Block a user