add ui to select mode

This commit is contained in:
numzero 2026-07-20 14:29:37 +03:00
parent 342e2d25d2
commit f880de181e
6 changed files with 223 additions and 8 deletions

View File

@ -9,24 +9,38 @@ mod render;
const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth16Unorm; const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth16Unorm;
const OUTPUT_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb; const OUTPUT_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb;
#[derive(Debug, Clone, Copy)]
#[repr(u32)]
pub enum Mode {
Solid,
Shell,
Mesh,
}
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
#[repr(C)] #[repr(C)]
pub struct ShapeArgs { pub struct ShapeArgs {
pub mode: Mode,
pub sides: u32, pub sides: u32,
pub layers_up: u32, pub layers_up: u32,
pub layers_down: u32, pub layers_down: u32,
pub base_diameter: f32, pub base_diameter: f32,
pub height: f32, pub height: f32,
pub thickness: f32,
pub line_width: f32,
} }
impl Default for ShapeArgs { impl Default for ShapeArgs {
fn default() -> Self { fn default() -> Self {
Self { Self {
mode: Mode::Shell,
sides: 24, sides: 24,
layers_up: 6, layers_up: 6,
layers_down: 6, layers_down: 6,
base_diameter: 36.0, base_diameter: 36.0,
height: 120.0, height: 120.0,
thickness: 1.6,
line_width: 3.0,
} }
} }
} }
@ -96,7 +110,7 @@ impl Core {
} }
fn render(&self, output: &wgpu::Texture, args: &RedrawArgs) { fn render(&self, output: &wgpu::Texture, args: &RedrawArgs) {
let mesh = mesh::cup(&args.shape); let mesh = mesh::make(&args.shape);
let mesh = faceted_mesh(&mesh); let mesh = faceted_mesh(&mesh);
let mesh = render::Mesh::new(&self.device, &mesh); let mesh = render::Mesh::new(&self.device, &mesh);

View File

@ -4,7 +4,7 @@ use glam::{Mat2, Vec3, Vec3Swizzles, vec2, vec3};
pub type Face = [usize; 3]; pub type Face = [usize; 3];
#[derive(Clone)] #[derive(Clone, Default)]
pub struct Mesh { pub struct Mesh {
pub vertices: Vec<Vec3>, pub vertices: Vec<Vec3>,
pub faces: Vec<Face>, pub faces: Vec<Face>,
@ -109,7 +109,7 @@ pub fn solid(shape: &crate::ShapeArgs) -> Mesh {
pub fn cup(shape: &crate::ShapeArgs) -> Mesh { pub fn cup(shape: &crate::ShapeArgs) -> Mesh {
let sides = shape.sides as usize; let sides = shape.sides as usize;
let thickness = 1.6; let thickness = shape.thickness;
let mut outer = shell(shape); let mut outer = shell(shape);
let shell_vs = outer.vertices.len(); let shell_vs = outer.vertices.len();
@ -141,3 +141,11 @@ pub fn cup(shape: &crate::ShapeArgs) -> Mesh {
mesh mesh
} }
pub fn make(shape: &crate::ShapeArgs) -> Mesh {
match shape.mode {
crate::Mode::Solid => solid(shape),
crate::Mode::Shell => cup(shape),
crate::Mode::Mesh => Default::default(), // TODO implement
}
}

View File

@ -11,12 +11,21 @@ struct alignas(16) Vec4 {
namespace ffi { namespace ffi {
struct Core; struct Core;
enum class Mode: std::uint32_t {
Solid,
Shell,
Mesh,
};
struct ShapeArgs { struct ShapeArgs {
Mode mode;
std::uint32_t sides; std::uint32_t sides;
std::uint32_t layers_up; std::uint32_t layers_up;
std::uint32_t layers_down; std::uint32_t layers_down;
float base_diameter; float base_diameter;
float height; float height;
float thickness;
float line_width;
}; };
struct RedrawArgs { struct RedrawArgs {
@ -29,6 +38,7 @@ struct RedrawArgs {
}; };
} // namespace ffi } // namespace ffi
using ffi::Mode;
using ffi::ShapeArgs; using ffi::ShapeArgs;
using ffi::RedrawArgs; using ffi::RedrawArgs;

View File

@ -6,22 +6,45 @@ Hyperboloid::Hyperboloid(QWidget* parent)
: QMainWindow(parent), : QMainWindow(parent),
m_ui(new Ui::MainWindow) { m_ui(new Ui::MainWindow) {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->mode->setId(m_ui->modeSolid, (int)Mode::Solid);
m_ui->mode->setId(m_ui->modeShell, (int)Mode::Shell);
m_ui->mode->setId(m_ui->modeMesh, (int)Mode::Mesh);
updateModeUi();
updateView(); updateView();
} }
Hyperboloid::~Hyperboloid() = default; Hyperboloid::~Hyperboloid() = default;
void Hyperboloid::updateModeUi() {
const auto mode = (Mode)m_ui->mode->checkedId();
bool has_thickness = false;
bool has_line_width = false;
switch (mode) {
case Mode::Mesh:
has_line_width = true;
case Mode::Shell:
has_thickness = true;
case Mode::Solid:
;
}
m_ui->thickness->setEnabled(has_thickness);
m_ui->lineWidth->setEnabled(has_line_width);
}
void Hyperboloid::updateView() { void Hyperboloid::updateView() {
const int max_layers = (m_ui->sides->value() - 1) / 2; const int max_layers = (m_ui->sides->value() - 1) / 2;
m_ui->layersUp->setMaximum(max_layers); m_ui->layersUp->setMaximum(max_layers);
m_ui->layersDown->setMaximum(max_layers); m_ui->layersDown->setMaximum(max_layers);
const auto color = m_ui->inBackground->color(); const auto color = m_ui->inBackground->color();
const ShapeArgs shape { const ShapeArgs shape {
.mode = (Mode)m_ui->mode->checkedId(),
.sides = (std::uint32_t)m_ui->sides->value(), .sides = (std::uint32_t)m_ui->sides->value(),
.layers_up = (std::uint32_t)m_ui->layersUp->value(), .layers_up = (std::uint32_t)m_ui->layersUp->value(),
.layers_down = (std::uint32_t)m_ui->layersDown->value(), .layers_down = (std::uint32_t)m_ui->layersDown->value(),
.base_diameter = (float)m_ui->dia->value(), .base_diameter = (float)m_ui->dia->value(),
.height = (float)m_ui->height->value(), .height = (float)m_ui->height->value(),
.thickness = (float)m_ui->thickness->value(),
.line_width = (float)m_ui->lineWidth->value(),
}; };
const RedrawArgs args{ const RedrawArgs args{
.shape = shape, .shape = shape,

View File

@ -15,6 +15,7 @@ public:
~Hyperboloid() override; ~Hyperboloid() override;
public slots: public slots:
void updateModeUi();
void updateView(); void updateView();
void updateViewIf(bool update); // for radio buttons void updateViewIf(bool update); // for radio buttons

View File

@ -257,6 +257,97 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Mode</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QRadioButton" name="modeSolid">
<property name="text">
<string>Solid</string>
</property>
<attribute name="buttonGroup">
<string notr="true">mode</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="modeShell">
<property name="text">
<string>Shell</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">mode</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="modeMesh">
<property name="text">
<string>Mesh</string>
</property>
<attribute name="buttonGroup">
<string notr="true">mode</string>
</attribute>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>Thickness</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="thickness">
<property name="suffix">
<string> mm</string>
</property>
<property name="minimum">
<double>0.100000000000000</double>
</property>
<property name="maximum">
<double>10.000000000000000</double>
</property>
<property name="stepType">
<enum>QAbstractSpinBox::StepType::AdaptiveDecimalStepType</enum>
</property>
<property name="value">
<double>1.600000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="text">
<string>Line width</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="lineWidth">
<property name="suffix">
<string> mm</string>
</property>
<property name="minimum">
<double>0.100000000000000</double>
</property>
<property name="maximum">
<double>50.000000000000000</double>
</property>
<property name="value">
<double>3.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBox_5"> <widget class="QGroupBox" name="groupBox_5">
<property name="title"> <property name="title">
@ -324,7 +415,7 @@
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>1585</x> <x>1585</x>
<y>803</y> <y>1036</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>799</x> <x>799</x>
@ -435,8 +526,8 @@
<slot>updateView()</slot> <slot>updateView()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>1472</x> <x>1585</x>
<y>611</y> <y>620</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>1446</x> <x>1446</x>
@ -451,8 +542,8 @@
<slot>updateView()</slot> <slot>updateView()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>1476</x> <x>1585</x>
<y>686</y> <y>682</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>1446</x> <x>1446</x>
@ -460,9 +551,77 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>thickness</sender>
<signal>valueChanged(double)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
<hints>
<hint type="sourcelabel">
<x>1495</x>
<y>852</y>
</hint>
<hint type="destinationlabel">
<x>1459</x>
<y>855</y>
</hint>
</hints>
</connection>
<connection>
<sender>lineWidth</sender>
<signal>valueChanged(double)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
<hints>
<hint type="sourcelabel">
<x>1495</x>
<y>915</y>
</hint>
<hint type="destinationlabel">
<x>1461</x>
<y>913</y>
</hint>
</hints>
</connection>
<connection>
<sender>mode</sender>
<signal>buttonClicked(QAbstractButton*)</signal>
<receiver>MainWindow</receiver>
<slot>updateView()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>799</x>
<y>599</y>
</hint>
</hints>
</connection>
<connection>
<sender>mode</sender>
<signal>buttonClicked(QAbstractButton*)</signal>
<receiver>MainWindow</receiver>
<slot>updateModeUi()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>799</x>
<y>599</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>updateView()</slot> <slot>updateView()</slot>
<slot>updateViewIf(bool)</slot> <slot>updateViewIf(bool)</slot>
<slot>updateModeUi()</slot>
</slots> </slots>
<buttongroups>
<buttongroup name="mode"/>
</buttongroups>
</ui> </ui>