GraphiteEditor / Graphite

2D vector & raster editor that melds traditional layers & tools with a modern node-based, non-destructive, procedural workflow.
https://graphite.rs
Apache License 2.0
7.31k stars 387 forks source link

CAD-like constraint-based modeling #216

Open giannissc opened 3 years ago

giannissc commented 3 years ago

Coming from the world of CAD I would really like it if constraints were available for modelling. They can be really useful when changing a design but wanting some features to be connected a certain way. The alternative way of doing this without constraints would be to scale every component independently and moving them around until thing look right.

I haven't seen in into any other program (other than point coincident contraint) and I think it would be really useful.

TrueDoctor commented 3 years ago

Could you maybe give a small example (e.g. screenshot)?

giannissc commented 3 years ago

I don't have an example specific to 2D graphics (since none implement constraint but coming from a 3D cad environment one typically uses 2D sketches to implemnt certain aspect of a design

image

On the design below we can see various contraints in place (point coincident, horizontal, vertical contratins, symmetrical contraints, perpendicular constraints and midpoint constraints)

image

giannissc commented 3 years ago

No if I were to change some aspect of this design all the contraint would be checked and the constraint solver would try and upheld them by changing some aspect of the design

giannissc commented 3 years ago

A could program to play around with to get the hang of constraint and see how they might by useful would be solvespace https://github.com/solvespace/solvespace/

giannissc commented 3 years ago

Here I have another example using solvespace this time. It a simple example but more clearly showcases the usefulness of a contraint system (in some situations). A properly constraint design can retain its shape (or any property you choose) in the face of change to the overall design. For this example here I am using the lengh ratio constraint on two squares

https://user-images.githubusercontent.com/20277283/122243189-d4d70680-cebb-11eb-93e6-0d5cad1c30dd.mp4

giannissc commented 3 years ago

Finally another example could be a simpe clock design like so:

image

Where I could constraint the minute hand to be shorter than the radius of the clock and the hour hand to be shorter by some ratio than the minute hand and then modify my design until it is what I want

giannissc commented 3 years ago

I hope that this is enought! I hope you like the idea and it fits into what you have envisioned for Graphite :)

TrueDoctor commented 3 years ago

Yeah, that is certainly very helpful @Keavon probably has more insight into to what extent that is already planned but these examples make your point very clear.

TrueDoctor commented 3 years ago

I would imagine this is also somewhat similar to how skeletal animation software does things with the concept of having something like joints

giannissc commented 3 years ago

I haven't done any skeletal animations before but I would imagine that it would be useuful in that context as well! Nonetheless, I don't think that is a must have but rather a nice to have feature that once you get used to you won't want to go back 😋

Keavon commented 3 years ago

I haven't replied yet to #217 and this one because I want to put in the time to write out my thoughts in detail. But very briefly, I am very excited that you have started a discussion about this in a venue where we can continue discussing it until eventually implementing the results of the proposals. The concept of CAD-like constrain systems, or more broadly the procedural/parametric approach used by CAD software, is something I have been wanting to learn more about to integrate those concepts into Graphite's procedural system. I see many uses for such a system, and probably this and #217 can be implemented in the same system to be useful for UIs and everything else. I'll try to get the time in the next few days to read through this thread and comment about what I imagine is possible and what needs further investigation and thought.

giannissc commented 3 years ago

A good review of the space I have found is found in [1-3]. [1] is more relevant as it describes the problem of constraints in 2D. Early history of contraint solving is related to CAD modelling and the main people you should look research from are Glenn A. Kramer [4-6], Ioannis Fudos [7], Christoph M. Hoffmann [2,7]. This is from a quick research I did I havent read through them just skimmed them. I will update as I read more about them :)

References: [1]: Interactive 2D Constraint-Based Geometric Construction System [2]: Geometric Constraint Solving in Parametric Computer-Aided Design [3]: Constraint-based solid modeling with geometric features Zhang, J., [4]: A geometric constraint engine [5]: Using Degrees of Freedom Analysis To Solve Geometric Constraint Systems [6]: Solving Geometric Constraint Systems [7]: A Graph-constructive Approach to Solving Systems of Geometric Constraints