add interface for simluation
This commit is contained in:
parent
aeac5f5782
commit
38cbae7c9d
@ -28,7 +28,7 @@ enum LoadState {
|
||||
}
|
||||
|
||||
#[pyfunction]
|
||||
fn get_version_str() -> String { "0.2.10.0".to_string() }
|
||||
fn get_version_str() -> String { "0.2.10.1".to_string() }
|
||||
|
||||
#[pyfunction]
|
||||
fn test_call(py_obj: &PyAny) -> PyResult<bool> {
|
||||
@ -44,7 +44,7 @@ fn test_call(py_obj: &PyAny) -> PyResult<bool> {
|
||||
fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(get_version_str, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(test_call, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(simulator::simluation, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(simulator::simulation, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(sr1_data::part_list::read_part_list_py, m)?)?;
|
||||
m.add_function(wrap_pyfunction!(sr1_data::ship::py_raw_ship_from_file, m)?)?;
|
||||
m.add_class::<render::camera::CameraRs>()?;
|
||||
|
@ -206,6 +206,30 @@ pub mod translate {
|
||||
}
|
||||
}
|
||||
|
||||
pub mod physics {
|
||||
use pyo3::prelude::*;
|
||||
|
||||
use crate::simulator::interface::PhysicsSpace;
|
||||
|
||||
#[pyclass]
|
||||
#[pyo3(name = "PhysicsSpace_rs")]
|
||||
pub struct PyPhysicsSpace {
|
||||
pub space: PhysicsSpace,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PyPhysicsSpace {
|
||||
#[new]
|
||||
fn new(gravity: (f64, f64)) -> Self {
|
||||
Self {
|
||||
space: PhysicsSpace::new(gravity),
|
||||
}
|
||||
}
|
||||
|
||||
fn tick_space(&mut self) { self.space.tick_space() }
|
||||
}
|
||||
}
|
||||
|
||||
pub mod console {
|
||||
use pyo3::prelude::*;
|
||||
|
||||
|
@ -10,8 +10,8 @@ use pyo3::prelude::*;
|
||||
use rapier2d_f64::prelude::*;
|
||||
|
||||
#[pyfunction]
|
||||
#[pyo3(name = "simluation")]
|
||||
pub fn simluation() -> () {
|
||||
#[pyo3(name = "simulation")]
|
||||
pub fn simulation() -> () {
|
||||
let mut rigid_body_set = RigidBodySet::new();
|
||||
let mut collider_set = ColliderSet::new();
|
||||
|
||||
@ -62,3 +62,74 @@ pub fn simluation() -> () {
|
||||
println!("Ball altitude: {} {}", ball_body.translation().x, ball_body.translation().y);
|
||||
}
|
||||
}
|
||||
|
||||
pub mod interface {
|
||||
use rapier2d_f64::prelude::*;
|
||||
|
||||
pub struct PhysicsSpace {
|
||||
pub rigid_body_set: RigidBodySet,
|
||||
pub collider_set: ColliderSet,
|
||||
pub gravity: Vector<f64>,
|
||||
pub integration_parameters: IntegrationParameters,
|
||||
pub physics_pipeline: PhysicsPipeline,
|
||||
pub island_manager: IslandManager,
|
||||
pub broad_phase: BroadPhase,
|
||||
pub narrow_phase: NarrowPhase,
|
||||
pub impulse_joint_set: ImpulseJointSet,
|
||||
pub multibody_joint_set: MultibodyJointSet,
|
||||
pub ccd_solver: CCDSolver,
|
||||
pub physics_hooks: (),
|
||||
pub event_handler: (),
|
||||
}
|
||||
|
||||
impl PhysicsSpace {
|
||||
pub fn new(gravity: (f64, f64)) -> Self {
|
||||
let rigid_body_set = RigidBodySet::new();
|
||||
let collider_set = ColliderSet::new();
|
||||
let gravity = vector![gravity.0, gravity.1];
|
||||
let integration_parameters = IntegrationParameters::default();
|
||||
let physics_pipeline = PhysicsPipeline::new();
|
||||
let island_manager = IslandManager::new();
|
||||
let broad_phase = BroadPhase::new();
|
||||
let narrow_phase = NarrowPhase::new();
|
||||
let impulse_joint_set = ImpulseJointSet::new();
|
||||
let multibody_joint_set = MultibodyJointSet::new();
|
||||
let ccd_solver = CCDSolver::new();
|
||||
let physics_hooks = ();
|
||||
let event_handler = ();
|
||||
Self {
|
||||
rigid_body_set,
|
||||
collider_set,
|
||||
gravity,
|
||||
integration_parameters,
|
||||
physics_pipeline,
|
||||
island_manager,
|
||||
broad_phase,
|
||||
narrow_phase,
|
||||
impulse_joint_set,
|
||||
multibody_joint_set,
|
||||
ccd_solver,
|
||||
physics_hooks,
|
||||
event_handler,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tick_space(&mut self) {
|
||||
self.physics_pipeline.step(
|
||||
&self.gravity,
|
||||
&self.integration_parameters,
|
||||
&mut self.island_manager,
|
||||
&mut self.broad_phase,
|
||||
&mut self.narrow_phase,
|
||||
&mut self.rigid_body_set,
|
||||
&mut self.collider_set,
|
||||
&mut self.impulse_joint_set,
|
||||
&mut self.multibody_joint_set,
|
||||
&mut self.ccd_solver,
|
||||
None,
|
||||
&self.physics_hooks,
|
||||
&self.event_handler,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,9 +102,6 @@ pub mod part_list {
|
||||
#[inline]
|
||||
pub fn new(attaches: Vec<AttachPoint>) -> Self { AttachPoints { points: attaches } }
|
||||
|
||||
#[inline]
|
||||
pub fn insert(&mut self, attach: AttachPoint) { self.points.push(attach); }
|
||||
|
||||
#[inline]
|
||||
pub fn unzip(&self) -> Vec<AttachPoint> { self.points.clone() }
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ pub mod sr1 {
|
||||
};
|
||||
use crate::types::math::{Point2D, Rotatable};
|
||||
|
||||
#[allow(unused)]
|
||||
#[inline]
|
||||
pub fn map_ptype_textures(ptype: String) -> String {
|
||||
match ptype.as_str() {
|
||||
|
@ -15,7 +15,7 @@ from Difficult_Rocket.api.mod import ModInfo
|
||||
from Difficult_Rocket.api.types import Options
|
||||
from Difficult_Rocket.client import ClientWindow
|
||||
|
||||
DR_rust_version = Version("0.2.10.0") # DR_mod 的 Rust 编写部分的兼容版本
|
||||
DR_rust_version = Version("0.2.10.1") # DR_mod 的 Rust 编写部分的兼容版本
|
||||
|
||||
|
||||
class _DR_mod_runtime(Options):
|
||||
|
Loading…
Reference in New Issue
Block a user