Skip to content

Commit

Permalink
Start integrating
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitris Zervas <[email protected]>
  • Loading branch information
dzervas committed Jun 12, 2024
1 parent 60519a5 commit 75b9c9a
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 64 deletions.
1 change: 0 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"pattern": "Local: +http://127.0.0.1:([0-9]+)/",
"uriFormat": "http://127.0.0.1:%s",
"webRoot": "${workspaceFolder}/applications/web/src",
"killOnServerStop": true
}
},
],
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"vite.devCommand": "pnpm run dev",
"vite.showTerminal": true,
"cSpell.words": [
"bindgen",
"isketch",
"Threlte",
"tsify",
"wireframe"
],
"editor.formatOnSave": true
Expand Down
20 changes: 10 additions & 10 deletions applications/web/src/components/FeatureHistory.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import SketchFeature from "./features/Sketch.svelte"
import ExtrusionFeature from "./features/Extrusion.svelte"
import SolidItem from "./SolidItem.svelte"
import {isPoint, isPlane, isExtrusion, isSketch} from "shared/projectUtils"
import {isPoint, isPlane, isSolid, isSketchStep} from "shared/projectUtils"
import type {SetCameraFocus} from "shared/types"
const log = (function () { const context = "[FeatureHistory.svelte]"; const color="pink"; return Function.prototype.bind.call(console.log, console, `%c${context}`, `font-weight:bold;color:${color};`)})() // prettier-ignore
Expand Down Expand Up @@ -55,18 +55,18 @@
<div class="flex flex-col select-none">
<div style="height:{Math.min(height, overallHeight - 12)}px" class="overflow-y-auto">
<div id="history" class="font-bold text-sm px-2 py-2">History ({history.length})</div>
{#each history as feature, featureIdx (feature.data.type + ":" + feature.unique_id)}
{#each history as feature, featureIdx}
<div>
{#if isPoint(feature)}
{#if isPoint(feature.interop_node!)}
<PointFeature name={feature.name} index={featureIdx} />
{:else if isPlane(feature)}
<PlaneFeature name={feature.name} index={featureIdx} plane={feature.data.plane} {setCameraFocus} />
{:else if isSketch(feature)}
<SketchFeature name={feature.name} index={featureIdx} id={feature.unique_id} plane_id={feature.data.plane_description.PlaneId} />
{:else if isExtrusion(feature)}
<ExtrusionFeature name={feature.name} index={featureIdx} data={feature.data.extrusion} id={feature.unique_id} />
{:else if isPlane(feature.interop_node!)}
<PlaneFeature name={feature.name} index={featureIdx} plane={feature.interop_node} {setCameraFocus} />
{:else if isSketchStep(feature)}
<SketchFeature name={feature.name} index={featureIdx} id={`${feature.id}`} plane_id={feature.data.plane_description.PlaneId} />
<!-- {:else if isSolid(feature.interop_node!)} -->
<!-- <ExtrusionFeature name={feature.name} index={featureIdx} data={feature.data.extrusion} id={feature.unique_id} /> -->
{:else}
TODO: {feature.name} {feature.data.type}
TODO: {feature.name} {feature.interop_node}
{/if}
</div>
{/each}
Expand Down
84 changes: 42 additions & 42 deletions applications/web/src/components/PassiveSketch.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts">
import {Matrix4, Euler, MeshStandardMaterial, Vector2, Vector3, type Vector3Like} from "three"
import {Matrix4, Euler, MeshStandardMaterial, Vector2, Vector3} from "three"
import {T, useThrelte} from "@threlte/core"
import {Text, Suspense} from "@threlte/extras"
import {hiddenSketches, previewGeometry, sketchTool} from "shared/stores"
import {hiddenSketches, sketchTool} from "shared/stores"
import Point2D from "./Point2D.svelte"
import Line from "./Line.svelte"
import Circle from "./Circle.svelte"
Expand Down Expand Up @@ -51,46 +51,46 @@
const primitive = sketch.primitives[parseInt(id)]
console.log("[primitive]", primitive, typeof primitive)
}
// const pointIds = Object.keys(sketch.points)
// pointTuples = []
// pointsById = {}
// for (const id of pointIds) {
// const point3D = sketch.points[id]
// const point2D = sketch.points_2d[id]
// pointTuples.push({id, twoD: point2D, threeD: point3D})
// pointsById[id] = {twoD: point2D, threeD: point3D}
// }
// lineTuples = []
// for (const id of Object.keys(sketch.line_segments)) {
// const line = sketch.line_segments[id]
// const start = pointsById[line.start]
// const end = pointsById[line.end]
// lineTuples.push({id, start, end})
// }
// circleTuples = []
// for (const id of Object.keys(sketch.circles)) {
// const circle = sketch.circles[id]
// const center = pointsById[circle.center]
// const radius = circle.radius
// circleTuples.push({id, center, radius})
// }
// arcTuples = []
// for (const id of Object.keys(sketch.arcs)) {
// const arc = sketch.arcs[id]
// const center = pointsById[arc.center]
// const start = pointsById[arc.start]
// const end = pointsById[arc.end]
// arcTuples.push({id, center, start, end})
// }
// faceTuples = []
// for (const id of Object.keys(sketch.faces)) {
// const face = sketch.faces[id]
// faceTuples.push({id, face})
// }
const pointIds = Object.keys(sketch.points)
pointTuples = []
pointsById = {}
for (const id of pointIds) {
const point3D = sketch.points[id]
const point2D = sketch.points_2d[id]
pointTuples.push({id, twoD: point2D, threeD: point3D})
pointsById[id] = {twoD: point2D, threeD: point3D}
}
lineTuples = []
for (const id of Object.keys(sketch.line_segments)) {
const line = sketch.line_segments[id]
const start = pointsById[line.start]
const end = pointsById[line.end]
lineTuples.push({id, start, end})
}
circleTuples = []
for (const id of Object.keys(sketch.circles)) {
const circle = sketch.circles[id]
const center = pointsById[circle.center]
const radius = circle.radius
circleTuples.push({id, center, radius})
}
arcTuples = []
for (const id of Object.keys(sketch.arcs)) {
const arc = sketch.arcs[id]
const center = pointsById[arc.center]
const start = pointsById[arc.start]
const end = pointsById[arc.end]
arcTuples.push({id, center, start, end})
}
faceTuples = []
for (const id of Object.keys(sketch.faces)) {
const face = sketch.faces[id]
faceTuples.push({id, face})
}
}
// Build some Three.js vectors from the props
Expand Down
2 changes: 1 addition & 1 deletion applications/web/src/components/features/Sketch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
let thingSelected = $currentlySelected[0]
if (thingSelected.type === "plane") {
setSketchPlane(id, thingSelected.id)
setSketchPlane(parseInt(id), parseInt(thingSelected.id))
} else if (thingSelected.type === "meshFace") {
log("HOW DO I HANDLE THIS?")
log(thingSelected)
Expand Down
2 changes: 1 addition & 1 deletion packages/cadmium/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Project {
.get(workbench_index as usize)
.unwrap()
.borrow()
.clone() // This single call polutes Clone derives for all MessageHandlers
.clone() // This single call pollutes Clone derives for all MessageHandlers
}

#[wasm_bindgen]
Expand Down
21 changes: 12 additions & 9 deletions packages/shared/projectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {workbenchIsStale, workbenchIndex, workbench, project, featureIndex, wasm
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} from "cadmium"
import type {Primitive, Workbench, MessageResult, IDType, Solid, Step, Node, Point3, Plane, ISketch, SolidArray} from "cadmium"
import {isMessage} from "./typeGuards"

// prettier-ignore
Expand Down Expand Up @@ -36,17 +36,20 @@ export function getWorkbenchSolids(): Solid[] {
return wp.get_workbench_solids(get(workbenchIndex))
}

export function isPoint(feature: HistoryStep): feature is PointHistoryStep {
return feature.data.type === "Point"
export function isPoint(node: Node): node is Node & Point3 {
// const typedObj = node as Point3
// return typedObj.x !== undefined && typedObj.y !== undefined && typedObj.z !== undefined
return "Point" in node
}
export function isPlane(feature: HistoryStep): feature is PlaneHistoryStep {
return feature.data.type === "Plane"
export function isPlane(node: Node): node is Node & Plane {
return "Plane" in node
}
export function isExtrusion(feature: HistoryStep): feature is ExtrusionHistoryStep {
return feature.data.type === "Extrusion"
export type SketchStep = Step & {interop_node: ISketch, data: cad.WorkbenchSketchAdd }
export function isSketchStep(step: Step): step is SketchStep {
return "WorkbenchSketchAdd" in step.data && "Sketch" in step.interop_node!
}
export function isSketch(feature: HistoryStep): feature is SketchHistoryStep {
return feature.data.type === "Sketch"
export function isSolid(node: Node): node is Node & Solid[] {
return "Solid" in node
}

export function arraysEqual(a: any[], b: any[]) {
Expand Down

0 comments on commit 75b9c9a

Please sign in to comment.