jdc-cunningham / pi-zero-hq-cam

A custom pi zero camera
28 stars 2 forks source link

build123d camera body model #4

Open jdegenstein opened 9 months ago

jdegenstein commented 9 months ago

I made a quick and dirty (partial) re-model of your camera body STLs (front and back still combined) using build123d. image

from build123d import *
# ref = import_stl('camera_front_and_back.stl')
# refc = ref.bounding_box().center()
refc = Vector(-67.6093978881836, -14.69277572631836, 22.66121482849121)
# rx, ry, rz = ref.bounding_box().size
rx, ry, rz = Vector(135.21879597636718, 68.58066578837891, 45.322429856982424)

with BuildPart() as p:
    with BuildSketch(Plane.XZ) as s:
        Rectangle(rx,rz)
    extrude(amount=ry/2,both=True)

    with BuildSketch() as s2:
        Rectangle(rx,ry)
        with Locations((5,ry/2)):
            Trapezoid(rx/2,5,135,90,mode=Mode.SUBTRACT,align=(Align.MIN,Align.MAX))
    extrude(amount=rz/2,both=True,mode=Mode.INTERSECT)     

    with BuildSketch(Plane.XZ) as s3:
        with Locations((0,2)):
            Rectangle(rx,rz-7.5)
        with Locations((7,rz/2-1.5)):
            Trapezoid(rx/2.1,2,135,90,mode=Mode.SUBTRACT,align=(Align.MIN,Align.MAX))
    extrude(amount=ry/2,both=True,mode=Mode.INTERSECT)
    add(p.part) # remove internal faces
    offset(amount=-3.5,mode=Mode.SUBTRACT)
    face1 = p.part.faces().sort_by(Axis.Z)[0]
    with BuildSketch(p.part.faces().sort_by(Axis.Z)[0]) as s4:
        with Locations((-rx/4+4,1)):
            Circle(ry/2-4)
    extrude(amount=7)

    with BuildSketch(face1) as s5:
        with Locations((-rx/4+4,1)):
            Circle(ry/3)
    extrude(amount=10,both=True,mode=Mode.SUBTRACT)

    face2 = p.part.faces().sort_by(Axis.Z)[-1]

    with BuildSketch(face2) as s6:
        Rectangle(44.4,47.17)
    extrude(amount=3,taper=45)

    with BuildSketch() as s6:
        add(p.part.faces().sort_by(Axis.Z)[-1])
        offset(amount=-3)
    extrude(amount=40,mode=Mode.SUBTRACT)

Could be a lot cleaner, but I was reverse engineering from the STL measurements -- so it is not the most elegant approach.

jdc-cunningham commented 9 months ago

This looks cool!

I have to look into this (build123) it's code that produces a 3D model?

Edit: I used an STL exporter for SketchUp to make the STLs I committed.

jdegenstein commented 9 months ago

I have to look into this (build123) it's code that produces a 3D model?

Yes that is correct, and build123d is also python-based which looks appropriate for this project! It is a BREP modeler like e.g. SolidWorks, Fusion360, FreeCAD and can natively perform e.g. fillets/chamfers. build123d can also natively import/export STEP files and can also export STLs.

jdc-cunningham commented 9 months ago

It is interesting, I am used to mouse/rotatable view. So going from that to code, hmm. Eventually I do intend to learn Fusion360 but it's a time sink thing.

Thanks for the example

jdegenstein commented 9 months ago

To be clear, there is a graphical user interface that is view-only that is called OCP CAD Viewer for VSCode (you don't modify the parts there, only in the code). The screenshot above is from this viewer. You can see a demo from my screen recording here:

https://www.youtube.com/watch?v=1MxjyttST4Y

CodeCAD is not for everyone though, I agree!

jdc-cunningham commented 9 months ago

That preview is cool for VS Code. I like that VS Code is hackable.

Thanks for sharing this.