Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <github@jessfraz.com>

updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

more

Signed-off-by: Jess Frazelle <github@jessfraz.com>
  • Loading branch information
jessfraz committed Jun 22, 2024
1 parent 0f3f923 commit 41a6ddd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
4 changes: 0 additions & 4 deletions src/clientSideScene/sceneEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,6 @@ export class SceneEntities {
streamDimensions
)
let _entity_id = entity_id
console.log('things', _entity_id, rest)
if (!_entity_id) return
if (
engineCommandManager.defaultPlanes?.xy === _entity_id ||
Expand Down Expand Up @@ -1423,23 +1422,20 @@ export class SceneEntities {
.sub(sceneInfra.camControls.target)

if (engineCommandManager.defaultPlanes?.xy === _entity_id) {
console.log('XY')
zAxis = [0, 0, 1]
yAxis = [0, 1, 0]
if (camVector.z < 0) {
zAxis = [0, 0, -1]
_entity_id = engineCommandManager.defaultPlanes?.negXy || ''
}
} else if (engineCommandManager.defaultPlanes?.yz === _entity_id) {
console.log('YZ')
zAxis = [1, 0, 0]
yAxis = [0, 0, 1]
if (camVector.x < 0) {
zAxis = [-1, 0, 0]
_entity_id = engineCommandManager.defaultPlanes?.negYz || ''
}
} else if (engineCommandManager.defaultPlanes?.xz === _entity_id) {
console.log('XZ')
zAxis = [0, 1, 0]
yAxis = [0, 0, 1]
_entity_id = engineCommandManager.defaultPlanes?.negXz || ''
Expand Down
1 change: 1 addition & 0 deletions src/components/ModelingMachineProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ export const ModelingMachineProvider = ({
})
},
'animate-to-face': async (_, { data }) => {
console.log('animate-to-face', data)
if (data.type === 'extrudeFace') {
const { modifiedAst, pathToNode: pathToNewSketchNode } =
sketchOnExtrudedFace(
Expand Down
58 changes: 41 additions & 17 deletions src/lang/modifyAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,27 @@ export function startSketchOnDefault(
name = ''
): { modifiedAst: Program; id: string; pathToNode: PathToNode } {
const _node = { ...node }
const _name =
name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH)
const surfaceName =
name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SURFACE)

const startSketchOn = createCallExpressionStdLib('startSketchOn', [
createLiteral(axis),
])

const variableDeclaration = createVariableDeclaration(_name, startSketchOn)
_node.body = [...node.body, variableDeclaration]
const surfaceVariableDeclaration = createVariableDeclaration(
surfaceName,
startSketchOn
)
_node.body = [..._node.body, surfaceVariableDeclaration]

// Create the variable for the sketch.
const sketchName =
name || findUniqueName(node, KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH)
const sketchVariableDeclaration = createVariableDeclaration(
sketchName,
createIdentifier(surfaceName)
)
_node.body = [..._node.body, sketchVariableDeclaration]
const sketchIndex = _node.body.length - 1

let pathToNode: PathToNode = [
Expand All @@ -64,7 +76,7 @@ export function startSketchOnDefault(

return {
modifiedAst: _node,
id: _name,
id: sketchName,
pathToNode,
}
}
Expand Down Expand Up @@ -333,10 +345,11 @@ export function sketchOnExtrudedFace(
cap: 'none' | 'start' | 'end' = 'none'
): { modifiedAst: Program; pathToNode: PathToNode } {
let _node = { ...node }
const newSketchName = findUniqueName(
const newSurfaceName = findUniqueName(
node,
KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH
KCL_DEFAULT_CONSTANT_PREFIXES.SURFACE
)

const { node: oldSketchNode } = getNodeFromPath<VariableDeclarator>(
_node,
sketchPathToNode,
Expand Down Expand Up @@ -372,31 +385,42 @@ export function sketchOnExtrudedFace(
_tag = cap.toUpperCase()
}

const newSketch = createVariableDeclaration(
newSketchName,
const newSurface = createVariableDeclaration(
newSurfaceName,
createCallExpressionStdLib('startSketchOn', [
createIdentifier(extrudeName ? extrudeName : oldSketchName),
createLiteral(_tag),
]),
'const'
)

const expressionIndex = Math.max(
sketchPathToNode[1][0] as number,
extrudePathToNode[1][0] as number
console.log('sketchPathToNode', sketchPathToNode)
console.log('extrudePathToNode', extrudePathToNode)
_node.body = [..._node.body, newSurface]

// Create the variable for the sketch.
const newSketchName = findUniqueName(
node,
KCL_DEFAULT_CONSTANT_PREFIXES.SKETCH
)
const sketchVariableDeclaration = createVariableDeclaration(
newSketchName,
createIdentifier(newSurfaceName)
)
_node.body.splice(expressionIndex + 1, 0, newSketch)
const newpathToNode: PathToNode = [
_node.body = [..._node.body, sketchVariableDeclaration]
const sketchIndex = _node.body.length - 1

let newPathToNode: PathToNode = [
['body', ''],
[expressionIndex + 1, 'index'],
[sketchIndex, 'index'],
['declarations', 'VariableDeclaration'],
[0, 'index'],
['0', 'index'],
['init', 'VariableDeclarator'],
]

return {
modifiedAst: _node,
pathToNode: newpathToNode,
pathToNode: newPathToNode,
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export const ONBOARDING_PROJECT_NAME = 'Tutorial Project $nn'
* These are used to generate unique names for new objects.
* */
export const KCL_DEFAULT_CONSTANT_PREFIXES = {
SURFACE: 'surface',
PROFILE: 'profile',
SKETCH: 'sketch',
EXTRUDE: 'extrude',
} as const
Expand Down
4 changes: 3 additions & 1 deletion src/wasm-lib/kcl-test-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[package]
name = "kcl-test-server"
description = "A test server for KCL"
version = "0.1.0"
edition = "2021"
license = "MIT"

[dependencies]
anyhow = "1.0.86"
hyper = { version = "0.14.29", features = ["server"] }
kcl-lib = { path = "../kcl" }
kcl-lib = { version = "0.1.62", path = "../kcl" }
pico-args = "0.5.0"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
Expand Down

0 comments on commit 41a6ddd

Please sign in to comment.