Skip to content

Commit

Permalink
extrusion modifications all work
Browse files Browse the repository at this point in the history
  • Loading branch information
MattFerraro committed May 10, 2024
1 parent cb3f413 commit 10341bf
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/cadmium/src/extrusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const MESH_TOLERANCE: f64 = 0.1;
pub struct Extrusion {
pub sketch_id: String,
pub face_ids: Vec<u64>,
pub face_shas: Vec<String>,
pub faces: Vec<Face>,
pub length: f64,
pub offset: f64,
pub direction: Direction,
Expand All @@ -76,7 +76,7 @@ impl Extrusion {
Extrusion {
sketch_id,
face_ids,
face_shas: vec![],
faces: vec![],
length,
offset,
direction,
Expand Down
15 changes: 10 additions & 5 deletions packages/cadmium/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn stacked_cubes() {
// });``

//
el.find_faces(&workbench_id, &sketch_id);
let face_id = el.find_faces(&workbench_id, &sketch_id);

// extrude the square
let extrusion_id = el.append(Operation::CreateExtrusion {
Expand All @@ -107,10 +107,15 @@ fn stacked_cubes() {
extrusion_id: extrusion_id.clone(),
depth: 100.0,
});
// el.append(Operation::SetExtrusionSketch {
// extrusion_id: extrusion_id.clone(),
// sketch_id: sketch_id.clone(),
// });
el.append(Operation::SetExtrusionSketch {
extrusion_id: extrusion_id.clone(),
sketch_id: sketch_id.clone(),
});
el.append(Operation::SetExtrusionFaces {
extrusion_id: extrusion_id.clone(),
faces: vec![face_id.clone()],
});

// el.append(Operation::SetExtrusionHandles {
// extrusion_id: extrusion_id.clone(),
// handles: vec![handle_id.clone()],
Expand Down
71 changes: 68 additions & 3 deletions packages/cadmium/src/oplog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub struct EvolutionLog {
pub planes: HashMap<Sha, (usize, String)>,
pub sketches: HashMap<Sha, (usize, String)>,
pub extrusions: HashMap<Sha, (usize, usize)>,
pub faces: HashMap<Sha, Face>,
}

impl EvolutionLog {
Expand All @@ -91,6 +92,7 @@ impl EvolutionLog {
planes: HashMap::new(),
sketches: HashMap::new(),
extrusions: HashMap::new(),
faces: HashMap::new(),
}
}

Expand Down Expand Up @@ -202,7 +204,7 @@ impl EvolutionLog {
let extrusion = crate::extrusion::Extrusion {
sketch_id: "".to_owned(),
face_ids: vec![],
face_shas: vec![],
faces: vec![],
length: 25.0,
offset: 0.0,
direction: crate::extrusion::Direction::Normal,
Expand Down Expand Up @@ -231,7 +233,38 @@ impl EvolutionLog {
unreachable!()
};
}

Operation::SetExtrusionFaces {
extrusion_id,
faces,
} => {
let (workbench_idx, extrusion_idx) = self.extrusions.get(&extrusion_id).unwrap();
let mut wb = self.project.workbenches.get_mut(*workbench_idx).unwrap();
if let StepData::Extrusion { extrusion, .. } = &mut wb.history[*extrusion_idx].data
{
let actual_faces = faces
.iter()
.map(|sha| self.faces.get(sha).unwrap().clone())
.collect();
extrusion.faces = actual_faces;
} else {
unreachable!()
};
}
Operation::SetExtrusionSketch {
extrusion_id,
sketch_id,
} => {
let (workbench_idx, extrusion_idx) = self.extrusions.get(&extrusion_id).unwrap();
let (workbench_idx_sketch, sketch_id) = self.sketches.get(&sketch_id).unwrap();
assert_eq!(workbench_idx, workbench_idx_sketch);
let mut wb = self.project.workbenches.get_mut(*workbench_idx).unwrap();
if let StepData::Extrusion { extrusion, .. } = &mut wb.history[*extrusion_idx].data
{
extrusion.sketch_id = sketch_id.clone();
} else {
unreachable!()
};
}
_ => {}
}

Expand Down Expand Up @@ -263,7 +296,12 @@ impl EvolutionLog {
};

for face_op in new_face_ops {
self.append(face_op);
self.append(face_op.clone());
if let Operation::CreateFace { face, .. } = face_op {
self.faces.insert(self.cursor.clone(), face.clone());
} else {
unreachable!()
}
}

self.cursor.clone()
Expand Down Expand Up @@ -569,6 +607,10 @@ pub enum Operation {
extrusion_id: Sha,
depth: f64,
},
SetExtrusionFaces {
extrusion_id: Sha,
faces: Vec<Sha>,
},
}

impl Operation {
Expand Down Expand Up @@ -680,6 +722,15 @@ impl Operation {
extrusion_id,
depth,
} => hasher.update(format!("{extrusion_id}-{depth}").as_bytes()),
Operation::SetExtrusionFaces {
extrusion_id,
faces,
} => {
hasher.update(format!("{extrusion_id}").as_bytes());
for sha in faces {
hasher.update(format!("{sha}").as_bytes())
}
}
}

format!("{:x}", hasher.finalize())
Expand Down Expand Up @@ -887,6 +938,20 @@ impl Operation {
depth
)
}
Operation::SetExtrusionFaces {
extrusion_id,
faces,
} => {
let mut face_str = String::new();
for sha in faces {
face_str.push_str(&format!("{} ", sha.to_owned()[..num_chars].to_string()));
}
format!(
"SetExtrusionFaces: {} {}",
extrusion_id.to_owned()[..num_chars].to_string(),
face_str
)
}
}
}
}
Expand Down

0 comments on commit 10341bf

Please sign in to comment.