Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 156 additions & 68 deletions rust/kcl-lib/src/execution/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use uuid::Uuid;
use crate::{
KclError, NodePath, SourceRange,
errors::KclErrorDetails,
execution::ArtifactId,
execution::{ArtifactId, id_generator::generate_engine_id},
parsing::ast::types::{Node, Program},
};

Expand Down Expand Up @@ -583,6 +583,9 @@ pub(super) fn build_artifact_graph(
let item_count = initial_graph.item_count;
let mut map = initial_graph.into_map();

#[cfg(target_arch = "wasm32")]
web_sys::console::warn_1(&format!("initial_graph {map:#?}").into());

let mut path_to_plane_id_map = FnvHashMap::default();
let mut current_plane_id = None;

Expand All @@ -594,6 +597,7 @@ pub(super) fn build_artifact_graph(
fill_in_node_paths(exec_artifact, ast, item_count);
}

let mut pi: u32 = 0;
for artifact_command in artifact_commands {
if let ModelingCmd::EnableSketchMode(EnableSketchMode { entity_id, .. }) = artifact_command.command {
current_plane_id = Some(entity_id);
Expand All @@ -620,9 +624,26 @@ pub(super) fn build_artifact_graph(
ast,
item_count,
exec_artifacts,
pi,
)?;
match artifact_command.command {
ModelingCmd::ClosePath(_) => {
pi = 0;
}
ModelingCmd::ExtendPath(_) => {
pi += 1;
}
_ => {}
}

//#[cfg(target_arch = "wasm32")]
//web_sys::console::warn_1(&format!("artifact_command {artifact_command:#?}").into());

for artifact in artifact_updates {
// Merge with existing artifacts.
//#[cfg(target_arch = "wasm32")]
//web_sys::console::warn_1(&format!("artifact to insert {artifact:#?}").into());

merge_artifact_into_map(&mut map, artifact);
}
}
Expand Down Expand Up @@ -741,6 +762,7 @@ fn artifacts_to_update(
ast: &Node<Program>,
cached_body_items: usize,
exec_artifacts: &IndexMap<ArtifactId, Artifact>,
pi: u32,
) -> Result<Vec<Artifact>, KclError> {
let uuid = artifact_command.cmd_id;
let response = responses.get(&uuid);
Expand Down Expand Up @@ -881,8 +903,14 @@ fn artifacts_to_update(
),
});
let mut return_arr = Vec::new();

let base = path_id.into();

let path_modifier = format!("path_{}", pi);
let curve_id = ArtifactId::new(generate_engine_id(base, &path_modifier));

return_arr.push(Artifact::Segment(Segment {
id,
id: curve_id,
path_id,
surface_id: None,
edge_ids: Vec::new(),
Expand All @@ -893,7 +921,7 @@ fn artifacts_to_update(
let path = artifacts.get(&path_id);
if let Some(Artifact::Path(path)) = path {
let mut new_path = path.clone();
new_path.seg_ids = vec![id];
new_path.seg_ids = vec![curve_id];
return_arr.push(Artifact::Path(new_path));
}
if let Some(OkModelingCmdResponse::ClosePath(close_path)) = response {
Expand Down Expand Up @@ -1050,28 +1078,51 @@ fn artifacts_to_update(
}
return Ok(return_arr);
}
ModelingCmd::Solid3dGetExtrusionFaceInfo(_) => {
ModelingCmd::Solid3dGetExtrusionFaceInfo(kcmc::Solid3dGetExtrusionFaceInfo { object_id, .. }) => {
let Some(OkModelingCmdResponse::Solid3dGetExtrusionFaceInfo(face_info)) = response else {
return Ok(Vec::new());
};

#[cfg(target_arch = "wasm32")]
web_sys::console::warn_1(&format!("Solid3dGetExtrusionFaceInfo {face_info:#?}").into());

let mut return_arr = Vec::new();
let mut last_path = None;

let base = *object_id;
let mut pi: u32 = 0;

for face in &face_info.faces {
if face.cap != ExtrusionFaceCapType::None {
continue;
}
let Some(curve_id) = face.curve_id.map(ArtifactId::new) else {
continue;
};
let Some(face_id) = face.face_id.map(ArtifactId::new) else {
continue;
};
// let Some(curve_id) = face.curve_id.map(ArtifactId::new) else {
// continue;
// };
// let Some(_face_id) = face.face_id.map(ArtifactId::new) else {
// continue;
// };

#[cfg(target_arch = "wasm32")]
web_sys::console::warn_1(&format!("artifacts{artifacts:#?}").into());

let path_modifier = format!("path_{}", pi);
pi += 1;
let face_id = ArtifactId::new(generate_engine_id(base, &format!("{}_face", path_modifier)));
let curve_id = ArtifactId::new(generate_engine_id(base, &path_modifier)); // aka edge/segment id, eg.: "path_0"

let Some(Artifact::Segment(seg)) = artifacts.get(&curve_id) else {
#[cfg(target_arch = "wasm32")]
web_sys::console::warn_1(&format!("segment not found {curve_id:#?}, {artifacts:#?}").into());

continue;
};
let Some(Artifact::Path(path)) = artifacts.get(&seg.path_id) else {
#[cfg(target_arch = "wasm32")]
web_sys::console::warn_1(&format!("no path???").into());
continue;
};

last_path = Some(path);
let Some(path_sweep_id) = path.sweep_id else {
// If the path doesn't have a sweep ID, check if it's a
Expand Down Expand Up @@ -1104,6 +1155,11 @@ fn artifacts_to_update(
// TODO: If we didn't find it, it's probably a bug.
.unwrap_or_default();

#[cfg(target_arch = "wasm32")]
web_sys::console::warn_1(
&format!("add wall: face_id: {face_id:#?}, curve_id: {curve_id:#?}, index: {pi:#?}").into(),
);

return_arr.push(Artifact::Wall(Wall {
id: face_id,
seg_id: curve_id,
Expand All @@ -1129,9 +1185,13 @@ fn artifacts_to_update(
ExtrusionFaceCapType::Bottom => CapSubType::Start,
ExtrusionFaceCapType::None | ExtrusionFaceCapType::Both => continue,
};
let Some(face_id) = face.face_id.map(ArtifactId::new) else {
continue;
};
let face_id = ArtifactId::new(generate_engine_id(
base,
match sub_type {
CapSubType::Start => "face_bottom",
CapSubType::End => "face_top",
},
));
let Some(path_sweep_id) = path.sweep_id else {
// If the path doesn't have a sweep ID, check if it's a
// hole.
Expand Down Expand Up @@ -1181,42 +1241,61 @@ fn artifacts_to_update(
}
return Ok(return_arr);
}
ModelingCmd::Solid3dGetAdjacencyInfo(kcmc::Solid3dGetAdjacencyInfo { .. }) => {
ModelingCmd::Solid3dGetAdjacencyInfo(kcmc::Solid3dGetAdjacencyInfo { object_id, .. }) => {
let Some(OkModelingCmdResponse::Solid3dGetAdjacencyInfo(info)) = response else {
return Ok(Vec::new());
};

#[cfg(target_arch = "wasm32")]
web_sys::console::warn_1(&format!("Solid3dGetAdjacencyInfo {info:#?}").into());

let base = *object_id;

let mut return_arr = Vec::new();
let mut pi: u32 = 0;
for (index, edge) in info.edges.iter().enumerate() {
let Some(original_info) = &edge.original_info else {
continue;
};
let edge_id = ArtifactId::new(original_info.edge_id);
let path_modifier = format!("path_{}", pi);
let edge_id = ArtifactId::new(generate_engine_id(base, &path_modifier)); // aka edge/segment id, eg.: "path_0"
let face_id = ArtifactId::new(generate_engine_id(base, &format!("{}_face", path_modifier)));
let next_face_id = ArtifactId::new(generate_engine_id(
base,
&format!("{}_face", format!("path_{}", (pi + 1) % (info.edges.len() as u32))),
));
pi += 1;

let Some(artifact) = artifacts.get(&edge_id) else {
continue;
};

match artifact {
Artifact::Segment(segment) => {
let mut new_segment = segment.clone();
new_segment.common_surface_ids =
original_info.faces.iter().map(|face| ArtifactId::new(*face)).collect();
new_segment.common_surface_ids = vec![
face_id,
ArtifactId::new(generate_engine_id(base, "face_bottom")), // cap start
]
.into_iter()
.filter(|id| artifacts.contains_key(id))
.collect();

return_arr.push(Artifact::Segment(new_segment));
}
Artifact::SweepEdge(sweep_edge) => {
let mut new_sweep_edge = sweep_edge.clone();
new_sweep_edge.common_surface_ids =
original_info.faces.iter().map(|face| ArtifactId::new(*face)).collect();
return_arr.push(Artifact::SweepEdge(new_sweep_edge));
Artifact::SweepEdge(_sweep_edge) => {
// TODO is this ever used?
// let mut new_sweep_edge = sweep_edge.clone();
// new_sweep_edge.common_surface_ids =
// original_info.faces.iter().map(|face| ArtifactId::new(*face)).collect();
// return_arr.push(Artifact::SweepEdge(new_sweep_edge));
}
_ => {}
};

let Some(Artifact::Segment(segment)) = artifacts.get(&edge_id) else {
continue;
};
let Some(surface_id) = segment.surface_id else {
continue;
};

let surface_id = ArtifactId::new(generate_engine_id(base, &format!("{}_face", path_modifier)));

let Some(Artifact::Wall(wall)) = artifacts.get(&surface_id) else {
continue;
};
Expand All @@ -1227,46 +1306,55 @@ fn artifacts_to_update(
continue;
};

if let Some(opposite_info) = &edge.opposite_info {
return_arr.push(Artifact::SweepEdge(SweepEdge {
id: opposite_info.edge_id.into(),
sub_type: SweepEdgeSubType::Opposite,
seg_id: edge_id,
cmd_id: artifact_command.cmd_id,
index,
sweep_id: sweep.id,
common_surface_ids: opposite_info.faces.iter().map(|face| ArtifactId::new(*face)).collect(),
}));
let mut new_segment = segment.clone();
new_segment.edge_ids = vec![opposite_info.edge_id.into()];
return_arr.push(Artifact::Segment(new_segment));
let mut new_sweep = sweep.clone();
new_sweep.edge_ids = vec![opposite_info.edge_id.into()];
return_arr.push(Artifact::Sweep(new_sweep));
let mut new_wall = wall.clone();
new_wall.edge_cut_edge_ids = vec![opposite_info.edge_id.into()];
return_arr.push(Artifact::Wall(new_wall));
}
if let Some(adjacent_info) = &edge.adjacent_info {
return_arr.push(Artifact::SweepEdge(SweepEdge {
id: adjacent_info.edge_id.into(),
sub_type: SweepEdgeSubType::Adjacent,
seg_id: edge_id,
cmd_id: artifact_command.cmd_id,
index,
sweep_id: sweep.id,
common_surface_ids: adjacent_info.faces.iter().map(|face| ArtifactId::new(*face)).collect(),
}));
let mut new_segment = segment.clone();
new_segment.edge_ids = vec![adjacent_info.edge_id.into()];
return_arr.push(Artifact::Segment(new_segment));
let mut new_sweep = sweep.clone();
new_sweep.edge_ids = vec![adjacent_info.edge_id.into()];
return_arr.push(Artifact::Sweep(new_sweep));
let mut new_wall = wall.clone();
new_wall.edge_cut_edge_ids = vec![adjacent_info.edge_id.into()];
return_arr.push(Artifact::Wall(new_wall));
}
let opposite_edge_id = ArtifactId::new(generate_engine_id(base, &format!("{}_opp", path_modifier))); //opposite_info.edge_id.into(),
return_arr.push(Artifact::SweepEdge(SweepEdge {
id: opposite_edge_id,
sub_type: SweepEdgeSubType::Opposite,
seg_id: edge_id,
cmd_id: artifact_command.cmd_id,
index,
sweep_id: sweep.id,
common_surface_ids: vec![
face_id,
ArtifactId::new(generate_engine_id(base, "face_top")), // cap end
]
.into_iter()
.filter(|id| artifacts.contains_key(id))
.collect(),
}));
let mut new_segment = segment.clone();
new_segment.edge_ids = vec![opposite_edge_id];
return_arr.push(Artifact::Segment(new_segment));
let mut new_sweep = sweep.clone();
new_sweep.edge_ids = vec![opposite_edge_id];
return_arr.push(Artifact::Sweep(new_sweep));
let mut new_wall = wall.clone();
new_wall.edge_cut_edge_ids = vec![opposite_edge_id];
return_arr.push(Artifact::Wall(new_wall));

let adjacent_edge_id = ArtifactId::new(generate_engine_id(base, &format!("{}_adj", path_modifier))); //adjacent_info.edge_id.into(),

return_arr.push(Artifact::SweepEdge(SweepEdge {
id: adjacent_edge_id,
sub_type: SweepEdgeSubType::Adjacent,
seg_id: edge_id,
cmd_id: artifact_command.cmd_id,
index,
sweep_id: sweep.id,
common_surface_ids: vec![face_id, next_face_id]
.into_iter()
.filter(|id| artifacts.contains_key(id))
.collect(),
}));
let mut new_segment = segment.clone();
new_segment.edge_ids = vec![adjacent_edge_id];
return_arr.push(Artifact::Segment(new_segment));
let mut new_sweep = sweep.clone();
new_sweep.edge_ids = vec![adjacent_edge_id];
return_arr.push(Artifact::Sweep(new_sweep));
let mut new_wall = wall.clone();
new_wall.edge_cut_edge_ids = vec![adjacent_edge_id];
return_arr.push(Artifact::Wall(new_wall));
}
return Ok(return_arr);
}
Expand Down
Loading
Loading