sync
This commit is contained in:
parent
92cea44839
commit
b83e6d3a0f
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1697,8 +1697,10 @@ dependencies = [
|
||||
"log",
|
||||
"makepad-widgets",
|
||||
"mp_core",
|
||||
"mp_elements",
|
||||
"native-dialog",
|
||||
"once_cell",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
@ -13,3 +13,5 @@ native-dialog = "0.7.0"
|
||||
once_cell = "1.20.2"
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = "0.3.18"
|
||||
mp_elements = { path = "../mp_elements", version = "*" }
|
||||
tokio = { version = "1.41.1", features = ["full"] }
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
use makepad_widgets::makepad_micro_serde::*;
|
||||
use makepad_widgets::*;
|
||||
use mp_elements::elements::Element;
|
||||
|
||||
use crate::{DATAPOOL, PLUGIN_MANAGER};
|
||||
use crate::{DATAPOOL, GIAPP, PLUGIN_MANAGER};
|
||||
|
||||
live_design! {
|
||||
import makepad_widgets::base::*;
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
use mp_elements;
|
||||
use tokio::runtime::Runtime;
|
||||
pub mod app;
|
||||
pub use makepad_widgets;
|
||||
pub use makepad_widgets::makepad_draw;
|
||||
@ -11,6 +13,7 @@ use mp_core::{config::Setting, datapool::DataPool, plugin_system::PluginManager}
|
||||
use once_cell::sync::Lazy;
|
||||
use std::env;
|
||||
|
||||
pub static RUNTIME: Lazy<Runtime> = Lazy::new(|| Runtime::new().unwrap());
|
||||
pub static CONFIG: Lazy<Setting> = Lazy::new(|| Setting::new());
|
||||
pub static PLUGIN_MANAGER: Lazy<PluginManager> = Lazy::new(|| {
|
||||
PluginManager::new(
|
||||
@ -23,3 +26,10 @@ pub static PLUGIN_MANAGER: Lazy<PluginManager> = Lazy::new(|| {
|
||||
.unwrap()
|
||||
});
|
||||
pub static DATAPOOL: Lazy<DataPool> = Lazy::new(|| DataPool::new(&PLUGIN_MANAGER, 10));
|
||||
pub static GIAPP: Lazy<mp_elements::App> = Lazy::new(|| {
|
||||
RUNTIME.block_on(async {
|
||||
let mut app = mp_elements::App::instant().await;
|
||||
app.init().await;
|
||||
app
|
||||
})
|
||||
});
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 70 KiB |
@ -36,10 +36,11 @@ fn vertex(
|
||||
var out: VertexOutput;
|
||||
|
||||
// Transform position
|
||||
// out.position = common_tools.proj_matrix * common_tools.view_matrix * common_tools.model_matrix * vec4f(position, 1.0);
|
||||
out.position = vec4(position.xyz, 1.0);
|
||||
out.position = common_tools.proj_matrix * common_tools.view_matrix * common_tools.model_matrix * vec4f(position, 1.0);
|
||||
// out.position = vec4(position.xyz, 1.0);
|
||||
out.r_range = r_range;
|
||||
out.idx = 0u;
|
||||
let idx = u32(position.w);
|
||||
out.idx = idx;
|
||||
|
||||
return out;
|
||||
}
|
||||
@ -57,9 +58,10 @@ fn fragment(input: VertexOutput) -> @location(0) vec4f {
|
||||
let value = data[input.idx];
|
||||
let ear = polar_forward(input.position.xyz);
|
||||
// var color = linear_colormap(value);
|
||||
var color = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
|
||||
let r = ear.z;
|
||||
var color = clamp(value / 75.0, 0.0, 1.0);
|
||||
|
||||
// let r = ear.x;
|
||||
// Valid range
|
||||
// let r_range = input.r_range;
|
||||
|
||||
@ -68,6 +70,7 @@ fn fragment(input: VertexOutput) -> @location(0) vec4f {
|
||||
// let is_outside = outside_lower_bound + outside_upper_bound;
|
||||
// color.a *= 1.0 - is_outside;
|
||||
|
||||
return vec4(r,r,r,r);
|
||||
|
||||
return vec4(color,color,color, 1.0);
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use quick_cache::unsync::Cache;
|
||||
use quick_cache::sync::Cache;
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
use crate::elements::{Element, ElementAttach, ElementsRef};
|
||||
@ -7,7 +7,7 @@ use wgpu::{Backends, Instance};
|
||||
|
||||
use encase;
|
||||
|
||||
type DB = std::rc::Rc<wgpu::Buffer>;
|
||||
type DB = std::sync::Arc<wgpu::Buffer>;
|
||||
|
||||
const BACKENDS_DEFAULT: u32 = Backends::DX12.bits()
|
||||
| Backends::METAL.bits()
|
||||
@ -46,10 +46,13 @@ impl App {
|
||||
|
||||
// Request a device and a queue from the adapter. The device is the handle to the GPU, and the queue is used to submit commands to the GPU.
|
||||
let (device, queue) = adapter
|
||||
.request_device(&wgpu::DeviceDescriptor{
|
||||
.request_device(
|
||||
&wgpu::DeviceDescriptor {
|
||||
required_features: wgpu::Features::POLYGON_MODE_LINE,
|
||||
..Default::default()
|
||||
}, None)
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@ -295,14 +298,14 @@ impl DataBufferPool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_or_create_buffer<F>(&mut self, key: BufferKey, f: F) -> Option<&DB>
|
||||
pub fn get_or_create_buffer<F>(&mut self, key: BufferKey, f: F) -> DB
|
||||
where
|
||||
F: FnOnce() -> wgpu::Buffer,
|
||||
{
|
||||
let buffer = self
|
||||
.buffers
|
||||
.get_or_insert_with(&key, || {
|
||||
Ok::<std::rc::Rc<wgpu::Buffer>, ()>(std::rc::Rc::new(f()))
|
||||
Ok::<std::sync::Arc<wgpu::Buffer>, ()>(std::sync::Arc::new(f()))
|
||||
})
|
||||
.unwrap();
|
||||
buffer
|
||||
@ -409,8 +412,9 @@ mod test {
|
||||
fn test_app() {
|
||||
let plugin_manager = PluginManager::new(
|
||||
// r#"/Users/tsuki/projects/mp/loaders"#
|
||||
r#"C:\Users\qwin7\projects\radarmp\loaders"#
|
||||
).unwrap();
|
||||
r#"C:\Users\qwin7\projects\radarmp\loaders"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let data = plugin_manager.try_load_data(
|
||||
// "/Users/tsuki/Desktop/Z_RADR_I_X5775_20230726180000_O_DOR-XPD-CAP-FMT.BIN.zip",
|
||||
|
||||
@ -135,7 +135,7 @@ impl Element for PPI {
|
||||
strip_index_format: None,
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: None,
|
||||
polygon_mode: wgpu::PolygonMode::Line,
|
||||
polygon_mode: wgpu::PolygonMode::Fill,
|
||||
unclipped_depth: false,
|
||||
conservative: false,
|
||||
},
|
||||
@ -190,6 +190,7 @@ impl Element for PPI {
|
||||
) -> ElementAttach {
|
||||
let (vertex, index) = self.bake(data);
|
||||
println!("index: {:?}", &(index.as_ref()).unwrap()[0..24]);
|
||||
println!("vertex: {:?}", &vertex[0..4]);
|
||||
let device = &ctx.device;
|
||||
|
||||
let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
@ -220,14 +221,13 @@ impl Element for PPI {
|
||||
let data_array_f32 = data_array.cast_to::<f32>();
|
||||
|
||||
let key = self.generate_key(data);
|
||||
let buffer = buffer_pool.get_or_create_buffer(key.clone(), || {
|
||||
let data_buffer = buffer_pool.get_or_create_buffer(key.clone(), || {
|
||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("PPI Texture Buffer"),
|
||||
contents: bytemuck::cast_slice(data_array_f32.as_slice().unwrap()),
|
||||
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::STORAGE,
|
||||
})
|
||||
});
|
||||
let data_buffer = buffer.unwrap();
|
||||
|
||||
// Bind Group
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
@ -259,7 +259,8 @@ impl Element for PPI {
|
||||
impl PPI {
|
||||
fn init_shader(device: &wgpu::Device) -> wgpu::ShaderModule {
|
||||
// let shader_str = merge_shader(r#"/Users/tsuki/projects/mp/mp_elements/shaders/ppi.wgsl"#);
|
||||
let shader_str = merge_shader(r#"C:\Users\qwin7\projects\radarmp\mp_elements\shaders\ppi.wgsl"#);
|
||||
let shader_str =
|
||||
merge_shader(r#"C:\Users\qwin7\projects\radarmp\mp_elements\shaders\ppi.wgsl"#);
|
||||
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
||||
label: Some("PPI Shader Module"),
|
||||
source: wgpu::ShaderSource::Wgsl(shader_str.into()),
|
||||
@ -291,35 +292,51 @@ impl PPI {
|
||||
let mut vertexs = Vec::with_capacity(a.len() * r.len() * 4);
|
||||
for (a_idx, _a) in sorted_azimuth.into_iter().enumerate() {
|
||||
for (r_idx, _r) in r.iter().enumerate() {
|
||||
|
||||
let cr = *_r as f32 / r_max;
|
||||
let r_ranges = [cr - r_step_f32, cr + r_step_f32, 0.0, 0.0];
|
||||
let idx = (a_idx * r.len() + r_idx) as u32;
|
||||
let idx = (a_idx * r.len() + r_idx) as f32;
|
||||
|
||||
// Left Top
|
||||
let lt = polar_to_cartesian(cr + r_step_f32, (_a - azi_step) as f32, e);
|
||||
let lt = polar_to_cartesian(
|
||||
cr + r_step_f32,
|
||||
(_a - azi_step).to_radians() as f32,
|
||||
e.to_radians(),
|
||||
);
|
||||
vertexs.push(PPIVertex {
|
||||
position: Vec4::new(lt.0, lt.1, lt.2,0.0),
|
||||
position: Vec4::new(lt.0, lt.1, lt.2, idx),
|
||||
r_ranges,
|
||||
// idx,
|
||||
});
|
||||
// Left Bot
|
||||
let lb = polar_to_cartesian(cr - r_step_f32, (_a - azi_step) as f32, e);
|
||||
let lb = polar_to_cartesian(
|
||||
cr - r_step_f32,
|
||||
(_a - azi_step).to_radians() as f32,
|
||||
e.to_radians(),
|
||||
);
|
||||
vertexs.push(PPIVertex {
|
||||
position: Vec4::new(lb.0, lb.1, lb.2,0.0),
|
||||
position: Vec4::new(lb.0, lb.1, lb.2, idx),
|
||||
r_ranges,
|
||||
// idx,
|
||||
});
|
||||
// Right Top
|
||||
let rt = polar_to_cartesian(cr + r_step_f32, (_a + azi_step) as f32, e);
|
||||
let rt = polar_to_cartesian(
|
||||
cr + r_step_f32,
|
||||
(_a + azi_step).to_radians() as f32,
|
||||
e.to_radians(),
|
||||
);
|
||||
vertexs.push(PPIVertex {
|
||||
position: Vec4::new(rt.0, rt.1, rt.2,0.0),
|
||||
position: Vec4::new(rt.0, rt.1, rt.2, idx),
|
||||
r_ranges,
|
||||
// idx,
|
||||
});
|
||||
// Right Bot
|
||||
let rb = polar_to_cartesian(cr - r_step_f32, (_a + azi_step) as f32, e);
|
||||
let rb = polar_to_cartesian(
|
||||
cr - r_step_f32,
|
||||
(_a + azi_step).to_radians() as f32,
|
||||
e.to_radians(),
|
||||
);
|
||||
vertexs.push(PPIVertex {
|
||||
position: Vec4::new(rb.0, rb.1, rb.2,0.0),
|
||||
position: Vec4::new(rb.0, rb.1, rb.2, idx),
|
||||
r_ranges,
|
||||
// idx,
|
||||
});
|
||||
@ -330,7 +347,7 @@ impl PPI {
|
||||
let mut indice_buffer = Vec::with_capacity(a.len() * r.len() * 6);
|
||||
|
||||
for i in 0..a.len() * r.len() {
|
||||
let start = (i * 2) as u32;
|
||||
let start = (i * 4) as u32;
|
||||
indice_buffer.push(start);
|
||||
indice_buffer.push(start + 1);
|
||||
indice_buffer.push(start + 2);
|
||||
@ -382,5 +399,5 @@ fn polar_to_cartesian(r: f32, azimuth: f32, elevation: f32) -> (f32, f32, f32) {
|
||||
let x = r * azimuth.cos() * elevation.cos();
|
||||
let y = r * azimuth.sin() * elevation.cos();
|
||||
let z = r * elevation.sin();
|
||||
(x, y, z )
|
||||
(x, y, z)
|
||||
}
|
||||
|
||||
@ -3,3 +3,5 @@ pub mod elements;
|
||||
pub mod elementvec;
|
||||
pub mod renderer;
|
||||
mod utils;
|
||||
|
||||
pub use app::App;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user