Irev-Dev / curated-code-cad

A list of the various code-cad projects out there.
https://kurthutten.com/blog/curated-code-cad
MIT License
252 stars 10 forks source link

Add JSCAD example #16

Closed Irev-Dev closed 3 years ago

Irev-Dev commented 3 years ago

resolves #15

Want to see if anyone from JSCAD want to review this before I merge since this is kinda public example code for JSCAD.

image

Irev-Dev commented 3 years ago

Looking much better now, Thanks @z3dev image

I took the easy way out with the params, and just passed all of them to every function I made so effectively still globals, (I think globals are not a bad practise for code-cad like they would be for other applications)

BTW, just two things I noticed. I found the polygons would break if the points were laid out in the wrong order. When I ran into this issue I only thought to reverse the order because I've faced a similar issue before it looks like normals are all fliped if you give the points in a counterClockwise direction. There's actually a pretty easy fix for this, by just checking the order of the points and reversing at the start of the polygon function. Here's a good link with example code (not js but you get the point), here's the implementation I did in OpenSCAD (though its an OpenSCAD function so terrible to read, and I actually think I have one of the signs wrong there, lol oh well 😅 everything is working so I'm not going to change it, I'm guessing it just inverts the result.

The other thing I noticed was that expand function seems a bit unstable for repeated use on 2d objects. You might have noticed I used the expand({delta: positiveNumber}) -> expand({delta: negative number}) hack to get internal fillets, but I got some really funky shapes if I tried this with too big on numbers or by going back and forth for external and internal radius expand 10, expand -20, expand 10. Got a bunch of spirals and what not. I get what I'm doing is a bit of a hack, but it's also a really nice hack to be able to use since in general adding fillets can be one of the most difficult things with code-cad.