Skip to content

Commit

Permalink
Fix solids & extrusion
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Zervas <[email protected]>
  • Loading branch information
dzervas committed Jun 14, 2024
1 parent 9aec71b commit 6d98f2f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion applications/web/src/components/Scene.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
{collisionLineMaterial}
/>
{:else if isSolidStep(step)}
{#each step.result as solid}
{#each step.result.solids as solid}
<Solid
name={step.name}
indices={solid.indices}
Expand Down
4 changes: 0 additions & 4 deletions applications/web/src/components/ToolBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
let solving = false
// todo ask Matt why is this a no-op?
const solveSketch = () => {}
const createNewExtrusion = () => {
newExtrusion()
// set that as the current feature being edited
Expand All @@ -18,7 +17,6 @@
newSketchOnPlane()
$featureIndex = $workbench.history.length - 1
}
const stepSketch = () => {}
const debugging = false
const actions = [
Expand All @@ -33,8 +31,6 @@
]
const sketchActions = [
{alt: "solve", src: `${base}/actions/solve_min.svg`, text: "Solve", handler: solveSketch},
{alt: "step", src: `${base}/actions/step_min.svg`, text: "Step", handler: stepSketch},
{alt: "line", src: `${base}/actions/line.svg`, handler: () => ($sketchTool = "line")},
{alt: "circle", src: `${base}/actions/circle.svg`, handler: () => ($sketchTool = "circle")},
{alt: "rectangle", src: `${base}/actions/rectangle.svg`, handler: () => ($sketchTool = "rectangle")},
Expand Down
6 changes: 3 additions & 3 deletions applications/web/src/components/features/Extrusion.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
// $: data, log("[props]", "typeof data.face_ids[0]:", typeof data.face_ids[0], "data.face_ids:", data.face_ids)
// coerce from number[] to string[] for frontend as we use strings for ids here
let faceIdsFromInputs = data.face_ids.sort().map(e => e + "")
let faceIdsFromInputs = data.faces.sort().map(e => e + "")
// reactive update of selected faces
$: if (data && data.face_ids) faceIdsFromInputs = data.face_ids.map(e => e + "").sort()
$: if (data && data.faces) faceIdsFromInputs = data.faces.map(e => e + "").sort()
let length = data.length
Expand Down Expand Up @@ -153,7 +153,7 @@
<button
class="flex-grow bg-sky-500 hover:bg-sky-700 text-white font-bold py-1.5 px-1 shadow"
on:click={() => {
renameStep(index, name)
renameStep(hash, name)
}}>Done</button
>

Expand Down
7 changes: 6 additions & 1 deletion packages/cadmium/src/feature/extrusion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ impl MessageHandler for Add {
workbench.features_next_id += 1;
let id = workbench.features_next_id - 1;

Ok(Some((id, StepResult::Solid(extrusion.to_solids()?))))
Ok(Some((
id,
StepResult::Solid {
solids: extrusion.to_solids()?,
},
)))
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/cadmium/src/step/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,9 @@ pub enum StepResult {
action: SketchActionResult,
faces: Vec<face::Face>,
},
Solid(Vec<solid::Solid>),
// We need the solids to be a named field so that we can serialize it with tag = "type"
// otherwise it would result in { type: "Solid", Solid[] } which isn't valid
Solid {
solids: Vec<solid::Solid>,
},
}
20 changes: 11 additions & 9 deletions packages/shared/projectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type {Message} from "./cadmium-api"
import {workbenchIsStale, workbenchIndex, workbench, project, featureIndex, wasmProject, projectIsStale, messageHistory, workbenchSolids} from "./stores"
import {get} from "svelte/store"
import {Vector2, Vector3, type Vector2Like} from "three"
import type {Entity, ExtrusionHistoryStep, HistoryStep, MessageHistory, PlaneHistoryStep, PointHistoryStep, SketchHistoryStep, WithTarget} from "./types"
import type {Primitive, Workbench, MessageResult, IDType, Solid, Step, Node, Point3, Plane, ISketch, SolidArray, StepHash} from "cadmium"
import type {Entity, MessageHistory, WithTarget} from "./types"
import type {Workbench, MessageResult, Solid, Step, Point3, Plane, ISketch, StepHash} from "cadmium"
import {isSketchActionStep} from "./stepTypeGuards"
import {isMessage} from "./typeGuards"

import * as cad from "./cadmium-api"
Expand Down Expand Up @@ -114,7 +115,7 @@ export function updateExtrusion(extrusionId: number, sketchId: number, length: n
}

export function setSketchPlane(sketchId: number, planeId: number) {
return cad.workbenchSketchSetPlane(get(workbenchIndex), sketchId, {PlaneId: planeId})
return cad.workbenchSketchSetPlane(get(workbenchIndex).toString(), sketchId, {PlaneId: planeId})
}

export function newSketchOnPlane() {
Expand All @@ -127,16 +128,17 @@ export function newExtrusion() {
// log("[newExtrusion] workbench:", workbench)
// log("[newExtrusion] bench:", bench)

let sketchId: IDType = 0
for (let step of bench.history) {
let faces: number[] = []
for (let step of bench.history.reverse()) {
console.warn("[newExtrusion] step:", step)
if (step.data.type === "Sketch") {
// TODO: This doesn't work, we should retrieve the sketch id
sketchId = step.id
if (isSketchActionStep(step) && faces.length === 0) {
faces = Array.from({ length: step.result.faces.length }, (_value, index) => index);
console.log("[newExtrusion] faces:", faces)
return cad.featureExtrusionAdd(get(workbenchIndex).toString(), step.data.sketch_id, faces, 25, 0.0, "Normal", "New")
}
}

return cad.featureExtrusionAdd(get(workbenchIndex).toString(), sketchId, [], 25, 0.0, "Normal", "New")
throw new Error("No sketch faces found to extrude")
}

export function deleteEntities(sketchIdx: string, selection: Entity[]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/stepTypeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function isSketchArcStep(step: Step): step is SketchArcStep {

// --- Solid operations ---
// Any step that produces solids is a solid step
export type SolidStep = Step & {result: {type: "Solid"} & Solid[]}
export type SolidStep = Step & {result: {type: "Solid", solids: Solid[]}}
export function isSolidStep(step: Step): step is SolidStep {
return step.result.type === "Solid"
}
Expand Down

0 comments on commit 6d98f2f

Please sign in to comment.