@ -6,8 +6,6 @@ use kcmc::{each_cmd as mcmd, ModelingCmd};
|
||||
use kittycad_modeling_cmds::{self as kcmc, shared::Color};
|
||||
use regex::Regex;
|
||||
use rgba_simple::Hex;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
|
||||
use super::args::TyF64;
|
||||
use crate::{
|
||||
@ -20,23 +18,6 @@ lazy_static::lazy_static! {
|
||||
static ref HEX_REGEX: Regex = Regex::new(r"^#[0-9a-fA-F]{6}$").unwrap();
|
||||
}
|
||||
|
||||
/// Data for appearance.
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct AppearanceData {
|
||||
/// Color of the new material, a hex string like "#ff0000".
|
||||
#[schemars(regex(pattern = "#[0-9a-fA-F]{6}"))]
|
||||
pub color: String,
|
||||
/// Metalness of the new material, a percentage like 95.7.
|
||||
#[validate(range(min = 0.0, max = 100.0))]
|
||||
pub metalness: Option<TyF64>,
|
||||
/// Roughness of the new material, a percentage like 95.7.
|
||||
#[validate(range(min = 0.0, max = 100.0))]
|
||||
pub roughness: Option<TyF64>,
|
||||
// TODO(jess): we can also ambient occlusion here I just don't know what it is.
|
||||
}
|
||||
|
||||
/// Set the appearance of a solid. This only works on solids, not sketches or individual paths.
|
||||
pub async fn appearance(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let solids = args.get_unlabeled_kw_arg_typed(
|
||||
@ -48,25 +29,20 @@ pub async fn appearance(exec_state: &mut ExecState, args: Args) -> Result<KclVal
|
||||
let color: String = args.get_kw_arg("color")?;
|
||||
let metalness: Option<TyF64> = args.get_kw_arg_opt_typed("metalness", &RuntimeType::count(), exec_state)?;
|
||||
let roughness: Option<TyF64> = args.get_kw_arg_opt_typed("roughness", &RuntimeType::count(), exec_state)?;
|
||||
let data = AppearanceData {
|
||||
color,
|
||||
metalness,
|
||||
roughness,
|
||||
};
|
||||
|
||||
// Make sure the color if set is valid.
|
||||
if !HEX_REGEX.is_match(&data.color) {
|
||||
if !HEX_REGEX.is_match(&color) {
|
||||
return Err(KclError::Semantic(KclErrorDetails {
|
||||
message: format!("Invalid hex color (`{}`), try something like `#fff000`", data.color),
|
||||
message: format!("Invalid hex color (`{}`), try something like `#fff000`", color),
|
||||
source_ranges: vec![args.source_range],
|
||||
}));
|
||||
}
|
||||
|
||||
let result = inner_appearance(
|
||||
solids,
|
||||
data.color,
|
||||
data.metalness.map(|t| t.n),
|
||||
data.roughness.map(|t| t.n),
|
||||
color,
|
||||
metalness.map(|t| t.n),
|
||||
roughness.map(|t| t.n),
|
||||
exec_state,
|
||||
args,
|
||||
)
|
||||
|
@ -4,7 +4,6 @@ use anyhow::Result;
|
||||
use indexmap::IndexMap;
|
||||
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, shared::CutType, ModelingCmd};
|
||||
use kittycad_modeling_cmds as kcmc;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{args::TyF64, DEFAULT_TOLERANCE};
|
||||
@ -19,8 +18,7 @@ use crate::{
|
||||
};
|
||||
|
||||
/// A tag or a uuid of an edge.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema, Eq, Hash)]
|
||||
#[ts(export)]
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)]
|
||||
#[serde(untagged)]
|
||||
pub enum EdgeReference {
|
||||
/// A uuid of an edge.
|
||||
|
@ -12,7 +12,6 @@ use kittycad_modeling_cmds::{
|
||||
self as kcmc,
|
||||
shared::{Angle, OriginType, Rotation},
|
||||
};
|
||||
use schemars::JsonSchema;
|
||||
use serde::Serialize;
|
||||
use uuid::Uuid;
|
||||
|
||||
@ -33,22 +32,6 @@ use crate::{
|
||||
|
||||
const MUST_HAVE_ONE_INSTANCE: &str = "There must be at least 1 instance of your geometry";
|
||||
|
||||
/// Data for a linear pattern on a 3D model.
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LinearPattern3dData {
|
||||
/// The number of total instances. Must be greater than or equal to 1.
|
||||
/// This includes the original entity. For example, if instances is 2,
|
||||
/// there will be two copies -- the original, and one new copy.
|
||||
/// If instances is 1, this has no effect.
|
||||
pub instances: u32,
|
||||
/// The distance between each repetition. This can also be referred to as spacing.
|
||||
pub distance: TyF64,
|
||||
/// The axis of the pattern.
|
||||
pub axis: [TyF64; 3],
|
||||
}
|
||||
|
||||
/// Repeat some 3D solid, changing each repetition slightly.
|
||||
pub async fn pattern_transform(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
||||
let solids = args.get_unlabeled_kw_arg_typed("solids", &RuntimeType::solids(), exec_state)?;
|
||||
@ -917,8 +900,7 @@ async fn inner_pattern_linear_3d(
|
||||
}
|
||||
|
||||
/// Data for a circular pattern on a 2D sketch.
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[derive(Debug, Clone, Serialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct CircularPattern2dData {
|
||||
/// The number of total instances. Must be greater than or equal to 1.
|
||||
@ -939,10 +921,9 @@ struct CircularPattern2dData {
|
||||
}
|
||||
|
||||
/// Data for a circular pattern on a 3D model.
|
||||
#[derive(Debug, Clone, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
#[derive(Debug, Clone, Serialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CircularPattern3dData {
|
||||
struct CircularPattern3dData {
|
||||
/// The number of total instances. Must be greater than or equal to 1.
|
||||
/// This includes the original entity. For example, if instances is 2,
|
||||
/// there will be two copies -- the original, and one new copy.
|
||||
|
Reference in New Issue
Block a user