mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-12 10:15:51 +00:00
Add dedicated type for model parameters
This commit is contained in:
parent
c8223e57ef
commit
556de36cd6
@ -8,7 +8,7 @@ mod window;
|
||||
use std::path::PathBuf;
|
||||
use std::{collections::HashMap, time::Instant};
|
||||
|
||||
use fj_host::Model;
|
||||
use fj_host::{Model, Parameters};
|
||||
use fj_interop::{debug::DebugInfo, mesh::Mesh};
|
||||
use fj_kernel::algorithms::{triangulate, Tolerance};
|
||||
use fj_math::{Aabb, Point, Scalar};
|
||||
@ -83,7 +83,7 @@ fn main() -> anyhow::Result<()> {
|
||||
};
|
||||
|
||||
if let Some(path) = args.export {
|
||||
let shape = model.load_once(¶meters)?;
|
||||
let shape = model.load_once(&Parameters(parameters))?;
|
||||
let shape = shape_processor.process(&shape);
|
||||
|
||||
let vertices =
|
||||
@ -111,7 +111,7 @@ fn main() -> anyhow::Result<()> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let watcher = model.load_and_watch(parameters)?;
|
||||
let watcher = model.load_and_watch(Parameters(parameters))?;
|
||||
|
||||
let event_loop = EventLoop::new();
|
||||
let window = Window::new(&event_loop);
|
||||
|
@ -74,7 +74,7 @@ impl Model {
|
||||
/// model for changes, reloading it continually.
|
||||
pub fn load_once(
|
||||
&self,
|
||||
arguments: &HashMap<String, String>,
|
||||
arguments: &Parameters,
|
||||
) -> Result<fj::Shape, Error> {
|
||||
let manifest_path = self.manifest_path.display().to_string();
|
||||
|
||||
@ -120,7 +120,7 @@ impl Model {
|
||||
/// be queried for changes to the model.
|
||||
pub fn load_and_watch(
|
||||
self,
|
||||
parameters: HashMap<String, String>,
|
||||
parameters: Parameters,
|
||||
) -> Result<Watcher, Error> {
|
||||
let (tx, rx) = mpsc::sync_channel(0);
|
||||
let tx2 = tx.clone();
|
||||
@ -202,7 +202,7 @@ pub struct Watcher {
|
||||
_watcher: Box<dyn notify::Watcher>,
|
||||
channel: mpsc::Receiver<()>,
|
||||
model: Model,
|
||||
parameters: HashMap<String, String>,
|
||||
parameters: Parameters,
|
||||
}
|
||||
|
||||
impl Watcher {
|
||||
@ -243,6 +243,16 @@ impl Watcher {
|
||||
}
|
||||
}
|
||||
|
||||
/// Parameters that are passed to a model
|
||||
pub struct Parameters(pub HashMap<String, String>);
|
||||
|
||||
impl Parameters {
|
||||
/// Construct an empty instance of `Parameters`
|
||||
pub fn empty() -> Self {
|
||||
Self(HashMap::new())
|
||||
}
|
||||
}
|
||||
|
||||
/// An error that can occur when loading or reloading a model
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
@ -263,5 +273,4 @@ pub enum Error {
|
||||
Notify(#[from] notify::Error),
|
||||
}
|
||||
|
||||
type ModelFn =
|
||||
unsafe extern "C" fn(args: &HashMap<String, String>) -> fj::Shape;
|
||||
type ModelFn = unsafe extern "C" fn(args: &Parameters) -> fj::Shape;
|
||||
|
Loading…
Reference in New Issue
Block a user