add ui to select mode
This commit is contained in:
parent
342e2d25d2
commit
f880de181e
16
src/lib.rs
16
src/lib.rs
|
|
@ -9,24 +9,38 @@ mod render;
|
|||
const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth16Unorm;
|
||||
const OUTPUT_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[repr(u32)]
|
||||
pub enum Mode {
|
||||
Solid,
|
||||
Shell,
|
||||
Mesh,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct ShapeArgs {
|
||||
pub mode: Mode,
|
||||
pub sides: u32,
|
||||
pub layers_up: u32,
|
||||
pub layers_down: u32,
|
||||
pub base_diameter: f32,
|
||||
pub height: f32,
|
||||
pub thickness: f32,
|
||||
pub line_width: f32,
|
||||
}
|
||||
|
||||
impl Default for ShapeArgs {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
mode: Mode::Shell,
|
||||
sides: 24,
|
||||
layers_up: 6,
|
||||
layers_down: 6,
|
||||
base_diameter: 36.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) {
|
||||
let mesh = mesh::cup(&args.shape);
|
||||
let mesh = mesh::make(&args.shape);
|
||||
let mesh = faceted_mesh(&mesh);
|
||||
let mesh = render::Mesh::new(&self.device, &mesh);
|
||||
|
||||
|
|
|
|||
12
src/mesh.rs
12
src/mesh.rs
|
|
@ -4,7 +4,7 @@ use glam::{Mat2, Vec3, Vec3Swizzles, vec2, vec3};
|
|||
|
||||
pub type Face = [usize; 3];
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Mesh {
|
||||
pub vertices: Vec<Vec3>,
|
||||
pub faces: Vec<Face>,
|
||||
|
|
@ -109,7 +109,7 @@ pub fn solid(shape: &crate::ShapeArgs) -> Mesh {
|
|||
|
||||
pub fn cup(shape: &crate::ShapeArgs) -> Mesh {
|
||||
let sides = shape.sides as usize;
|
||||
let thickness = 1.6;
|
||||
let thickness = shape.thickness;
|
||||
|
||||
let mut outer = shell(shape);
|
||||
let shell_vs = outer.vertices.len();
|
||||
|
|
@ -141,3 +141,11 @@ pub fn cup(shape: &crate::ShapeArgs) -> 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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,21 @@ struct alignas(16) Vec4 {
|
|||
namespace ffi {
|
||||
struct Core;
|
||||
|
||||
enum class Mode: std::uint32_t {
|
||||
Solid,
|
||||
Shell,
|
||||
Mesh,
|
||||
};
|
||||
|
||||
struct ShapeArgs {
|
||||
Mode mode;
|
||||
std::uint32_t sides;
|
||||
std::uint32_t layers_up;
|
||||
std::uint32_t layers_down;
|
||||
float base_diameter;
|
||||
float height;
|
||||
float thickness;
|
||||
float line_width;
|
||||
};
|
||||
|
||||
struct RedrawArgs {
|
||||
|
|
@ -29,6 +38,7 @@ struct RedrawArgs {
|
|||
};
|
||||
} // namespace ffi
|
||||
|
||||
using ffi::Mode;
|
||||
using ffi::ShapeArgs;
|
||||
using ffi::RedrawArgs;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,22 +6,45 @@ Hyperboloid::Hyperboloid(QWidget* parent)
|
|||
: QMainWindow(parent),
|
||||
m_ui(new Ui::MainWindow) {
|
||||
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();
|
||||
}
|
||||
|
||||
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() {
|
||||
const int max_layers = (m_ui->sides->value() - 1) / 2;
|
||||
m_ui->layersUp->setMaximum(max_layers);
|
||||
m_ui->layersDown->setMaximum(max_layers);
|
||||
const auto color = m_ui->inBackground->color();
|
||||
const ShapeArgs shape {
|
||||
.mode = (Mode)m_ui->mode->checkedId(),
|
||||
.sides = (std::uint32_t)m_ui->sides->value(),
|
||||
.layers_up = (std::uint32_t)m_ui->layersUp->value(),
|
||||
.layers_down = (std::uint32_t)m_ui->layersDown->value(),
|
||||
.base_diameter = (float)m_ui->dia->value(),
|
||||
.height = (float)m_ui->height->value(),
|
||||
.thickness = (float)m_ui->thickness->value(),
|
||||
.line_width = (float)m_ui->lineWidth->value(),
|
||||
};
|
||||
const RedrawArgs args{
|
||||
.shape = shape,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public:
|
|||
~Hyperboloid() override;
|
||||
|
||||
public slots:
|
||||
void updateModeUi();
|
||||
void updateView();
|
||||
void updateViewIf(bool update); // for radio buttons
|
||||
|
||||
|
|
|
|||
|
|
@ -257,6 +257,97 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</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>
|
||||
<widget class="QGroupBox" name="groupBox_5">
|
||||
<property name="title">
|
||||
|
|
@ -324,7 +415,7 @@
|
|||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>1585</x>
|
||||
<y>803</y>
|
||||
<y>1036</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>799</x>
|
||||
|
|
@ -435,8 +526,8 @@
|
|||
<slot>updateView()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>1472</x>
|
||||
<y>611</y>
|
||||
<x>1585</x>
|
||||
<y>620</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>1446</x>
|
||||
|
|
@ -451,8 +542,8 @@
|
|||
<slot>updateView()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>1476</x>
|
||||
<y>686</y>
|
||||
<x>1585</x>
|
||||
<y>682</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>1446</x>
|
||||
|
|
@ -460,9 +551,77 @@
|
|||
</hint>
|
||||
</hints>
|
||||
</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>
|
||||
<slots>
|
||||
<slot>updateView()</slot>
|
||||
<slot>updateViewIf(bool)</slot>
|
||||
<slot>updateModeUi()</slot>
|
||||
</slots>
|
||||
<buttongroups>
|
||||
<buttongroup name="mode"/>
|
||||
</buttongroups>
|
||||
</ui>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user