From bb542224a5dd2ee5760bae10c7a50826738d6258 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Fri, 22 Dec 2023 21:05:42 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=80=E5=9B=9E=E4=B8=80=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E9=87=8D=E6=96=B0=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=20rapier=20=E7=9A=84=20ColliderBuilder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Difficult_Rocket_rs/src/Cargo.lock | 13 +++++++ .../Difficult_Rocket_rs/src/Cargo.toml | 14 +++++--- .../src/src/data_type/dr.rs | 34 ++++++++++--------- .../Difficult_Rocket_rs/src/src/lib.rs | 1 + .../Difficult_Rocket_rs/src/src/python.rs | 1 + .../src/src/python/editor.rs | 19 +++++++++++ 6 files changed, 62 insertions(+), 20 deletions(-) create mode 100644 mods/dr_game/Difficult_Rocket_rs/src/src/python/editor.rs diff --git a/mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock b/mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock index c8f1a22..d5d4e2c 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock +++ b/mods/dr_game/Difficult_Rocket_rs/src/Cargo.lock @@ -131,11 +131,24 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "dict_derive" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b46bc7c421493b2f684e78cee446c4537ad816ee452e7b0f2edb36ef4f29d5d6" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "difficult_rocket_rs" version = "0.3.0" dependencies = [ + "dict_derive", "fs-err", + "nalgebra", "pyo3", "quick-xml", "rapier2d-f64", diff --git a/mods/dr_game/Difficult_Rocket_rs/src/Cargo.toml b/mods/dr_game/Difficult_Rocket_rs/src/Cargo.toml index 679259a..995ba33 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/Cargo.toml +++ b/mods/dr_game/Difficult_Rocket_rs/src/Cargo.toml @@ -11,23 +11,29 @@ authors = ["shenjackyuanjie <3695888@qq.com>"] name = 'difficult_rocket_rs' crate-type = ["cdylib"] -[profile.dev.package.rapier2d-f64] -opt-level = 2 +#[profile.dev.package.rapier2d-f64] +#opt-level = 2 [profile.dev] -opt-level = 1 +opt-level = 0 [profile.release] lto = "fat" # Abort panic info to rapidly terminate program instead of unwinding call stacks. # To check panic info, compile the program in dev mode. panic = "abort" +opt-level = 2 [dependencies] fs-err = "2.11.0" quick-xml = { version = "0.31.0", features = ["serialize"] } -serde = { version = "1.0.193", features = ["derive"] } +serde = { version = "1.0", features = ["derive"] } + xml-rs = "0.8.19" serde-xml-rs = "0.6.0" + +nalgebra = "0.32.3" rapier2d-f64 = { version = "0.17.2", features = ["simd-stable"] } + pyo3 = { version = "0.20.0", features = ["extension-module", "macros"] } +dict_derive = "0.5" diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/data_type/dr.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/data_type/dr.rs index d36c4cd..2de1953 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/data_type/dr.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/data_type/dr.rs @@ -31,37 +31,39 @@ pub struct DRObjectProps<'a> { pub flip_y: bool, pub connections: Option>, pub box_collider_type: bool, - pub box_collider_data: BoxColliderType, + pub box_collider_data: BoxColliderEnum, } /// 为了保证能使用到 所有类型的 碰撞体 /// 写了这么长一个玩意 -pub enum BoxColliderType { +#[cfg(disable)] +use rapier2d_f64::geometry::ColliderBuilder; +pub enum BoxColliderEnum { // rapier2d_f64::geometry::ColliderBuilder /// 球 /// 半径 - Sphere(Real), + Ball(Real), /// 矩形 /// 宽 高 - Rectangle(Real, Real), + Cuboid(Real, Real), /// 圆角矩形 /// 宽 高 圆角半径 - CornerRoundedRectangle(Real, Real, Real), + RoundCuboid(Real, Real, Real), /// 三角形 /// 三个点坐标 Triangle(Point, Point, Point), /// 圆角三角形 /// 三个点坐标 圆角半径 - CornerRoundedTriangle(Point, Point, Point, Real), + RoundTriangle(Point, Point, Point, Real), /// 圆柱体 ( 横向 ) /// 半径 高 - HorizontalCylinder(Real, Real), + CapsuleX(Real, Real), /// 圆柱体 ( 纵向 ) /// 半径 高 - VerticalCylinder(Real, Real), + CapsuleY(Real, Real), /// 复合形状 /// 给一堆坐标 - CompoundedShape(Point, Point), + Segment(Point, Point), /// 三角形面定义的几何体(有限元?) /// 使用由顶点和索引缓冲区定义的三角形网格形状 TriMesh(Vec>, Vec<[u32; 3]>), @@ -71,30 +73,30 @@ pub enum BoxColliderType { /// 给定一个多边形几何体,此方法将其分解为一系列凸多边形 ConvexDecomposition(Vec>, Vec<[u32; 2]>), /// 给定一个圆角的多边形几何体,此方法将其分解为一系列圆角的凸多边形,虽然不知道怎么分 - CornerRoundedConvexDecomposition(Vec>, Vec<[u32; 2]>, Real), + RoundConvexDecomposition(Vec>, Vec<[u32; 2]>, Real), /// 给定一个多边形几何体,此方法将其分解为一系列凸多边形 /// 由VHACDParameters指定算法的参数,这将影响分解的结果或质量 ConvexDecompositionWithParams(Vec>, Vec<[u32; 2]>, VHACDParameters), /// 给定一个圆角的多边形几何体,此方法将其分解为一系列圆角的凸多边形,虽然不知道怎么分 /// 由VHACDParameters指定算法的参数,这将影响分解的结果或质量 - CornerRoundedConvexDecompositionWithParams(Vec>, Vec<[u32; 2]>, VHACDParameters, Real), + RoundConvexDecompositionWithParams(Vec>, Vec<[u32; 2]>, VHACDParameters, Real), /// 给定一系列点,计算出对应的凸包络的多边形 ConvexHull(Vec>), /// 给定一系列点,计算出对应的凸包络的多边形,然后加上圆角 - CornerRoundedConvexHull(Vec>, Real), + RoundConvexHull(Vec>, Real), /// 给定一系列点,按照凸多边形来计算碰撞箱,但不会算出这个凸多边形 /// 如果实际上这些点并没有定义一个凸多边形,在计算过程可能导致bug ConvexPolyline(Vec>), /// 给定一系列点,按照凸多边形加上圆角来计算碰撞箱,但不会算出这个凸多边形 /// 如果实际上这些点并没有定义一个凸多边形,在计算过程可能导致bug - CornerRoundedConvexPolyline(Vec>, Real), + RoundConvexPolyline(Vec>, Real), /// 由顶点定义的多边形 Polyline(Vec<(Real, Real)>), /// 由一系列高度定义的某种东西,大概是地面之类的 - HeightDefined(Vec<(Real, Real)>), + Heightfield(Vec<(Real, Real)>), /// 凸分解的复合形状 /// 就是不知道能不能真用上 - ConvexCompoundedShape(Vec<(Isometry, SharedShape)>), //凸分解,好像可以略微提升复杂刚体碰撞的性能 + Compound(Vec<(Isometry, SharedShape)>), //凸分解,好像可以略微提升复杂刚体碰撞的性能 } pub struct TankProps { @@ -137,7 +139,7 @@ pub struct DRComponentProps<'a, T> { /// shenjack: 折磨我的时候到了 pub shape_can_be_customized: bool, /// 所有 raiper2d 支持的碰撞箱类型 - pub box_collider_data: BoxColliderType, + pub box_collider_data: BoxColliderEnum, // 基本属性 /// 名称 pub name: &'a str, diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs index da75ddd..5706179 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/lib.rs @@ -51,6 +51,7 @@ fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + // m.add_class::()?; Ok(()) } diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs index 6f7cf25..6e4ad7c 100644 --- a/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/python.rs @@ -8,3 +8,4 @@ pub mod console; pub mod data; +pub mod editor; diff --git a/mods/dr_game/Difficult_Rocket_rs/src/src/python/editor.rs b/mods/dr_game/Difficult_Rocket_rs/src/src/python/editor.rs new file mode 100644 index 0000000..7b62154 --- /dev/null +++ b/mods/dr_game/Difficult_Rocket_rs/src/src/python/editor.rs @@ -0,0 +1,19 @@ +/* + * ------------------------------- + * Difficult Rocket + * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com + * All rights reserved + * ------------------------------- + */ + + +use nalgebra::Vector2; +use pyo3::prelude::*; + +use crate::data_type::dr::BoxColliderEnum; + +// #[pyclass] +pub struct EditorArea { + /// 存储所有碰撞箱信息 + pub collision_box: Vec, +}