Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Slaviiiii committed Jul 22, 2024
1 parent f03edec commit 0afc95f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/formatbot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: npm install @biomejs/biome@${{ steps.get-biome-version.outputs.BIOME_VERSION }}

- name: Run formatter
run: npx @biomejs/biome check --apply-unsafe .
run: npx @biomejs/biome check --write --unsafe .

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
2 changes: 1 addition & 1 deletion lib/components/jscad-fixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function JsCadFixture({
}
animate()
}
}, [])
}, [children, wireframe])

return (
<div ref={containerRef} style={{ width: "100%", minHeight: "400px" }} />
Expand Down
29 changes: 14 additions & 15 deletions lib/convert-csg-to-three-geom.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @ts-nocheck
import {
BufferGeometry,
BufferAttribute,
Vector3,
Vector2,
Matrix4,
BufferGeometry,
Color,
Matrix4,
Vector2,
Vector3,
} from "three"

export default function convertCSGToThreeGeom(csg): BufferGeometry {
Expand All @@ -16,8 +16,8 @@ export default function convertCSGToThreeGeom(csg): BufferGeometry {
const colors = []
let idx = 0

csg.polygons.forEach((polygon) => {
polygon.vertices.forEach((vertex) => {
for (const polygon of csg.polygons) {
for (const vertex of polygon.vertices) {
vertex.index = idx
vertices.push(vertex[0], vertex[1], vertex[2])
// Add color for each vertex
Expand All @@ -27,14 +27,14 @@ export default function convertCSGToThreeGeom(csg): BufferGeometry {
colors.push(1, 1, 1) // Default to white if no color
}
idx++
})
}
const first = polygon.vertices[0].index
for (let i = 2; i < polygon.vertices.length; i++) {
for (let i = 2;i < polygon.vertices.length;i++) {
const second = polygon.vertices[i - 1].index
const third = polygon.vertices[i].index
indices.push(first, second, third)
}
})
}

const geo = new BufferGeometry()
geo.setAttribute(
Expand All @@ -59,20 +59,20 @@ export default function convertCSGToThreeGeom(csg): BufferGeometry {
geo.computeVertexNormals()

return geo
} else if (csg.sides) {
} if (csg.sides) {
// 2D shape
const vertices = []
const colors = []

csg.sides.forEach((side) => {
for (const side of csg.sides) {
vertices.push(side[0][0], side[0][1], 0) // Add z-coordinate as 0
// Add color for each vertex
if (csg.color && csg.color.length >= 3) {
colors.push(csg.color[0], csg.color[1], csg.color[2])
} else {
colors.push(1, 1, 1) // Default to white if no color
}
})
}

const geo = new BufferGeometry()
geo.setAttribute(
Expand All @@ -95,8 +95,7 @@ export default function convertCSGToThreeGeom(csg): BufferGeometry {
}

return geo
} else {
console.error("Invalid CSG object: neither polygons nor sides found")
return new BufferGeometry()
}
console.error("Invalid CSG object: neither polygons nor sides found")
return new BufferGeometry()
}
6 changes: 3 additions & 3 deletions lib/create-host-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { Geom3 } from "@jscad/modeling/src/geometries/types"

export function createHostConfig(jscad: JSCADModule) {
const createInstance = (
type: string | Function,
type: string | ((props: any) => any),
props: any,
rootContainerInstance: any,
hostContext: any,
Expand Down Expand Up @@ -119,7 +119,7 @@ export function createHostConfig(jscad: JSCADModule) {
points: (props as PolygonProps).points,
})
}
// biome-ignore lint/suspicious/noFallthroughSwitchClause: <explanation>

case "extrudeLinear": {
const { children, ...extrudeProps } = props as ExtrudeLinearProps

Expand Down Expand Up @@ -258,7 +258,7 @@ export function createHostConfig(jscad: JSCADModule) {
never, // SuspenseInstance
never, // HydratableInstance
JSCADPrimitive, // PublicInstance
{}, // HostContext
object, // HostContext
boolean, // UpdatePayload
never, // ChildSet
number, // TimeoutHandle
Expand Down
4 changes: 2 additions & 2 deletions lib/useJSCADRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function useJSCADRenderer(children) {
const [mesh, setMesh] = useState<THREE.Scene | null>(null)

useEffect(() => {
reconciler.updateContainer(children, root, null, () => {})
reconciler.updateContainer(children, root, null, () => { })

const scene = new THREE.Scene()

Expand All @@ -59,7 +59,7 @@ export function useJSCADRenderer(children) {
})

setMesh(scene)
}, [reconciler, children])
}, [children, root, container])

return mesh
}

0 comments on commit 0afc95f

Please sign in to comment.