GithubHelp home page GithubHelp logo

fwcd / mini-cad Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 1.0 1.13 MB

Parametric 3D modeller with a Swift-inspired DSL for macOS and iOS (WWDC 2023 submission)

License: GNU General Public License v3.0

Swift 100.00%
3d cad playground slicer swift constructive-solid-geometry parametric-modelling dsl swift-student-challenge

mini-cad's Introduction

MiniCAD

A parameteric 3D modeller for macOS and iOS featuring a Swift-inspired Domain Specific Language (DSL) for modeling.

Screenshot

Description

MiniCAD is a parametric 3D modeling program that lets users construct models with a Swift-like domain-specific language (DSL), drawing inspiration from apps like OpenSCAD, Blender and Swift Playgrounds. The core idea is simple: Use geometric primitives and combine them with unions, differences and intersections to create complex shapes. The programming-centered approach provides the ability to work abstractly in terms of variables and functions, all while using a familiar syntax in a highly interactive environment.

On a more technical level, the app is implemented using SwiftUI and SceneKit. Text rendering uses Core Text. The UI is structured using the Model-View-ViewModel paradigm and is heavily based around value types and protocols. The DSL uses a combination of recursive-descent and operator precedence parsing to convert the user's program into a syntax tree. From there, it is interpreted asynchronously in the background, leveraging Swift's powerful concurrency model. MiniCAD also includes an implementation of Computational Solid Geometry (CSG) based on Binary Space Partitioning (BSP) and ear-clipping polygon triangulation for the mesh operations. The app supports exporting the user's models to the Standard Tesselated Geometry (STL) file format, which makes it easy to open models in other applications such as Preview or even to slice and 3D-print them.

Open Source

The app includes the Suzanne.stl model, a demo model from the open-source 3D modeling application Blender, to showcase the import of external STL models.

Also the implementation of CSG is based on a port of the wonderfully simple and elegant JavaScript implementation by Evan Wallace: https://github.com/evanw/csg.js/ This code is MIT-licensed with Copyright (c) 2011 Evan Wallace (http://madebyevan.com/).

See also

  • MiniBlocks, an open-world sandbox game built with SceneKit (my 2022 project)
  • MiniCut, a tiny video editor built with SpriteKit (my 2021 project)
  • MiniJam, a tiny digital audio workstation built with SwiftUI (my 2020 project)

mini-cad's People

Contributors

fwcd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

vvhh2002

mini-cad's Issues

Add CI

We could e.g. automatically run the test suite in CI.

Add prefix, postfix and ternary operators

Another thing for the wishlist. Ternaries might be tricky to parse, we'll have to see how well that plays with our precedence climbing parser.

  • Prefix operators
  • Postfix operators (only calls and trailing blocks currently)
  • Ternary operator

Store save state

Our current 'save' always saves as a new file. It would be nice to differentiate between 'save' and 'save as' by memorizing the file path to the opened file.

Investigate whether we can make the preview scene interactive

This could get pretty tricky after we have #3 and #5, since we'd need to track the 'origin' of each triangle throughout the CSG transformations (#22 would probably come in handy too).

But it would still be very cool if the user could e.g. drag/scale/rotate the objects in real-time in the preview as the code updates automatically (and perhaps snap it to the grid (optionally?)).

Note that this might also require inverting the entire tranformation stack. E.g. if the cube dragged by the user is inside a

Translate(...) {
  Rotate(...) {
    ...
  }
}

we'd have to compute how the original position/scales would have to be modified.

Implement slicer

Depends on

Implement a slicer that generates gcode from meshes (and ideally even visualizes it).

Show tips/instructions

We should provide some instructional tips in the UI, e.g.

  • briefly explain the UI
  • provide useful tips, like using Option+Scroll for zooming

Investigate how to make built-ins more type-safe

Currently, our built-ins are defined in a rather weakly typed way. It would be cool if we could somehow abstract over this (e.g. structures with Codable arguments and use a custom decoder to deserialize [Value] or similar).

Add proper `Mesh` type

Instead of generating Cuboids, we should generate actual meshes and then use CSG algorithms to e.g. compute unions, intersections etc.

Display errors inline

Now that we have the line it would be cool if we could display parse errors inline, similar e.g. to Xcode.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.