openscad icon indicating copy to clipboard operation
openscad copied to clipboard

Provide a simple measurement tool [$305]

Open west1012 opened this issue 3 years ago • 36 comments

$500 to $1000 bounty depending on final capabilities of the tool. Let me know how to set this up so you can verify the money is available and/or in some sort of escrow account.

I love OpenSCAD, but I do enough stuff where I need to I need to measure dimensions to make sure everything is OK that I can't really use OpenSCAD for what I want to do.

I am looking for a tool that does the following:

  • Measure distances between two point
  • Measure angles between three points (so essentially you create a triangle without the hypotenuse side and the angle between the two lines created by the three points is measured)
  • Snap to edges, corners, and midpoints

I have not dug through OpenSCAD's source code to see what is possible, but if this is not infeasible due to the underlying structure of OpenSCAD, I would love to have this tool.

Let me know what you think, and/or if I'm publishing this feature request here correctly. It has been almost ten years since I was a full time software engineer, and GitHub was in its infancy back then. And, also, this is probably a dupe of this feature request, but I didn't want to bump an almost five year old feature request.

https://github.com/openscad/openscad/issues/1768


There is a $305 open bounty on this issue. Add to the bounty at Bountysource.

west1012 avatar Jan 30 '21 02:01 west1012

$500 to $1000 bounty depending on final capabilities of the tool. Let me know how to set this up

Best to wait on the bounty until initial discussions on viability of the request.

MichaelAtOz avatar Jan 30 '21 06:01 MichaelAtOz

@west1012
Am i getting your proposal right. You are not suggesting any language extension but rather some graphical measuring tool to use in the view port on the final result?

TLC123 avatar Jan 30 '21 15:01 TLC123

I am open to different approaches. OpenSCAD seems like an incredible tool, but the fact that you can't (to my knowledge) measure distances and angles between different points to check your work changes OpenSCAD from being something very powerful, to something not very useful. If it could be done easily in the language, and it was easy for a newbie user to use and comprehend what s/he was doing, (and preferably with some sort of graphics on the scene so you could visually verify you are measuring the things you think you are measuring) I would be OK with that.

For what it's worth, my goal here is sort of anti-selfish one. I'm looking for something so all people (who can understand the OpenSCAD language) can use it, easily. It would be nice to have a cheap/free alternative for hobbyists and students, and a measuring tool seems like the "missing piece" in OpenSCAD. I'm sure there are others, which we can definitely talk about in regards to bounties going forward. I am OK funding OpenSCAD work.

west1012 avatar Jan 30 '21 17:01 west1012

@west1012 The only way available to post bounties is via BountySource (link was just added to the issue by automation). With the other issue having a bounty already but a simpler focus, I suppose we will need to keep both open. If this one here is solved, it should cover #1768 too.

So my suggestions for such a big bounty would be to flesh out the description a bit more and then see how it goes. There's a reasonable chance it's going to happen, we had some discussions about how it could be implemented on IRC already and there's someone showing interest in taking on the topic.

@TLC123 has a good point, we should make it clear we are talking about GUI interaction. From our discussion about technical details, it sounds like we may need to restrict measurements to fully rendered mesh view (F6) - if it's possible for preview remains to be seen.

Do you maybe have some references to other tools which could serve as reference for how it may work from user perspective? I only know the Blender protractor which seems powerful but also quite complicated to use.

t-paul avatar Jan 30 '21 17:01 t-paul

I am happy to post $500 to Bountysource if it's confirmed this is possible and someone wants to go through with it.

west1012 avatar Jan 30 '21 17:01 west1012

t-paul, my last comment was posted without me seeing your most recent comment, so apologies if it looks like I didn't reply to your statements properly. We replied at roughly the same time, I didn't see them :)

GUI or via the language is fine, as long as it is easy-ish to use. I trust that you guys aren't going to just implement something to get the bounty and call it a day, but will think about how to implement things so it's both not impossible to code, but also not impossible to use, if that makes sense. So I really leave it up to you. If it's via the language, I'm not sure snap to vertex or, say, midway point of a line is even possible? Maybe it's not necessary if it's easy to refer to a part of a line via the language.

For my background: I'm an old C++ guy who went deep into the language when I used it (metaprogramming for the win! Or at least it was fun). And I have a degree in CS. So feel free to discuss technical stuff with me / I'm not just some random joe on the internet who wants a feature, but can actually talk about technical specifics, if desired. Mostly, because of busy-ness in my life, I would prefer you guys come up with an idea and implementation without my input thought :).

I will go ahead and post a $250 bounty for now to show I'm really interested. To my knowledge, I have no takebacks. So either the money stays within the BountySource system, or it goes to you guys. I will bump to $500 or more once we have more ideas on how we think it can be done.

west1012 avatar Jan 30 '21 17:01 west1012

I have added the $250. I don't know how long the details on the change take to populate to github:

https://www.bountysource.com/issues/96259516-provide-a-simple-measurement-tool

west1012 avatar Jan 30 '21 17:01 west1012

The trouble with midpoints. Once rendered, basic overall metrics like volume surface area, bounding box etc is not to hard to find.

Selecting two or three or more vertices (either by clicking or just read of graphical labels in the view port) and enter into a simple measures dialog. From - To or From - Via - To . From there just report all imaginable combinations of measurements. length, angle, normal, area, center point etc in a console like block.

Corners are essentially always represented by vertices.

Midpoints of edges and faces is more troublesome.

What looks like an edge visually in geometry could be made up of several mesh edges. However if the the previous two point measurement also reported coordinates of midpoint and if the measure tool dialog in addition to indexed vertices also accepted any cartesian point then it would be a matter of cut and paste from one measure to the subsequent .

In other words this proposed measuring tool could be utilized to construct its own intermediate measuring points.

example

dialog

_In a more ambitious path graphical rulers could be stretched out by mouse in the view port. Those in turn could have midpoints for click and construct measures.

TLC123 avatar Jan 30 '21 19:01 TLC123

I have looked into this issue after implementing the mouse selection renderer and we already had a discussion on IRC.

The Mouse Selection currently requires for every leaf node of the document tree to have a unique 24-bit identifier, which can be encoded into the R/G/B color of the object during the rendering into a framebuffer. The clicked pixel can then be read from the framebuffer, and its R/G/B color is the 24 bit ID. Since all "fancy" things like lightning, shadows, ... are disabled for this render pass, it is quite fast (not that openscad is any strain on modern graphics hardware - it is CPU bound) but more importantly it does not change the color of the object, and therefore its ID (see MouseSelector::select in https://github.com/openscad/openscad/blob/master/src/mouseselector.cc#L152) The ID assignment is done as a shader parameter, since there are few objects compared to vertices.

This approach can be extended by assigning a different color / ID to each vertex, edge and face, with a deterministic mapping to the location and associativity of each object. A single triangle would need up to 7 identifiers: 1 face, 3 edges, 3 vertices (the vertices are shared, but might be duplicated for implementation reasons)

Reducing the number of triangles from 2^24 (== 16.77million) to 2^17 (==131k) can be limiting - but more modern graphics hardware capable of coping with these numbers should be able to implement GL_RGB10_A2 with 2^30 bits of ID space (resulting in 2^23 (~8million) triangles (https://www.khronos.org/opengl/wiki/Image_Format - but I don't know about the portability!)

The hard question to be answered is therefore: how can we generate a deterministic mapping between vertices on the graphics card and their position in 3D space - the answer is the Vertex Buffer Object index - prepared by obliviand but not yet merged (https://github.com/openscad/openscad/pull/1935).

With the VBO in place one can create a geometry shader to convert the VBO index (+ some offset) into a vertex ID, and use a similar method as the edge shader (https://github.com/openscad/openscad/blob/8a905133a2f27e23db07bb424599a242c5d7176d/src/GLView.cc#L207) to encode the ID into the edges and vertices.

To finally calculate the distances between all combinations of face, edge, point with given vertices is highschool math :)

This approach will have problems in preview mode:

Not all expected "vertices" are defined as vertices, think of two cubes subtracted, but one is moved on the x-axis, the four new "corners" are more a graphical oddities (think of overwriting the depth buffer with inverted faces) than actually calculated vertices. Such vertices and edges are only calculated in render mode, or with a render() or some other operations that require a CGAL run.

Tomatower avatar Jan 30 '21 19:01 Tomatower

The coloring logic would only be needed for picking in preview mode, right? I believe when having the full mesh available the traditional "intersect with ray from point of mouse click" should work?

t-paul avatar Jan 30 '21 19:01 t-paul

Maybe you have already discussed this aspect in other places. I imagine the ability to move the camera between selecting individually features is important if you need to measure between things that is not simultaneously visible in the same view.

TLC123 avatar Jan 30 '21 19:01 TLC123

The coloring logic is basically GPU assisted ray intersection - it is up to the test which of the two is easier to implement and faster. If the selection is fast enough it might even be possible to highlight a hovered element in order to visually differentiate between edges, vertices and faces.

@TLC123 : The rendering pass is made at the time of the click, then the ID you clicked on can be remembered and highlighted, you can move the view around, rotate it and then click on the second point - triggering another "Render-To-Click" in a background buffer, just like in the mouse selection logic. Afterwards you have two entities and can decide what you want to measure. With a logic in place to select vertices/edges/faces in 3D space the logic what you want to do with this information is "just" UI.

Tomatower avatar Jan 30 '21 20:01 Tomatower

Thanks guys for all the fast work on this. For what it's worth, I was not hoping to get the function of "midpoint of a face" in my feature request, just "midpoint of an edge, or midpoint between two points". If the "midpoint of a face" is easy to do though, great! Otherwise it is definitely not necessary as I could see how it could be a lot harder to do :)

west1012 avatar Jan 30 '21 20:01 west1012

I was discussing a UI Only modification - so mostly a useful tool for verification, not so much for designing (at least not parametrically), since you would not be able to read these positions in code.

The general architecture of OpenSCAD does not support getting any information about geometry (be it boundingbox, barycenter, or even vertices) from the pipeline, and that would include the midpoint of an edge or face.

Tomatower avatar Jan 30 '21 21:01 Tomatower

I will be honest that I am a little lost on the graphics discussion here as I was always a systems / network guy, and never got into graphics. So I apologize if I'm not understanding that discussion or the implications of it. However, if the tool is possible, I understand that this would be a tool only for verification. OpenSCAD is not FreeCAD / Fusion360, and I understand (or at least I believe) everything has to be designed / modeled through OpenSCAD's language, and not through any UI elements.

west1012 avatar Jan 30 '21 22:01 west1012

@Tomatower Even so, a measure tool provides a important workflow feedback loop if not programmatically. Something like the heavily requested . Import an model, take some dimensions, add or subtract stuff. take some more dimensions, add or subtract. etc

Going forward we could imagine measure tools with shortcut powers like "copy point as translate()" or "copy vector as rotate()" "copy face normal as rotate()" Essentially pushing transformation snippets back to code.

I really appreciate the engaged feedback , Thank you really.

TLC123 avatar Jan 30 '21 22:01 TLC123

I like your Idea! - something like:

  • Enter Measurement mode.
  • Select outer edge face of my box
  • select outer edge of my cylinder
  • See "1.73 units (x: 1, y: 1, z: 1)" with buttons underneath: "copy as vector" and "insert as vector" and "insert as translate([])"
  • inserts the text "translate([1,1,1])" at cursor position into the scad file.

@west1012: TL;DR: It is possible to select entities using the graphics card IF we can uniquely identify these by their Color-As-ID.

I might take a look into this (I do have another OpenSCAD PR that is currently wasting my time...) - but any help or ideas are welcome!

Tomatower avatar Jan 30 '21 22:01 Tomatower

Netfabb (if you run Windows) has a good measurement interface. Capture-netfabb-measure-noted

At 'A.' options are select point on surface, point on edge, corner point, point on cut, corner on cut. Cut is the sliders below, which moves a cut-line, e.g. the red lines, showing the outline surface at that section. At 'B.' options are measure distance, angle, radius. At 'C.' for distance, wall thickness, point to point, point to line*, line to point, line to line, surface to point. * - line is an edge or a cut-line. At 'C2.' for angle, select three points, select two edges. At 'C3.' for radius, select a curved edge, select three point on circle, four points on sphere.

Food for thought.

MichaelAtOz avatar Jan 31 '21 03:01 MichaelAtOz

Thanks for the help. I know you can export to OBJ or STL and measure things in NetFabb or Blender (free as in speech), but that gets a little tiresome when checking and re-checking things regularly. One of the big pluses to OpenSCAD, in my mind, is the ability to model things based on a few variables, and then be able to change those variables and have the entire model completely change. To the best of my knowledge, there's nothing else that does this to the level OpenSCAD can, even the mega expensive professional stuff. However, if I want to check measurements after changing a variable, having to re-export every time really is a pain, especially if you are playing around with changing the variable to few different values to see how they compare, if that makes sense.

west1012 avatar Jan 31 '21 04:01 west1012

Sorry, I was not clear, I was feeding ideas for UI concepts for an OpenSCAD measurement solution.

MichaelAtOz avatar Jan 31 '21 06:01 MichaelAtOz

That looks like they had the same idea but thought it through to the end :) - like they (AutoCAD) were earning money with CAD tools!

I am thinking about how to transport this Idea into the OpenSCAD interface, so continue to spin this idea :)

  • Points / Edges / Faces: "trivial", they are already rendered somehow and it is obvious for the user what we mean.
  • Centerpoints of faces/edges: OpenSCAD is (for the most part) triangles - selecting the center of a cube is therefore not selecting the center of a face (yes - cubes are using quads, but they are triangulated in the first operation!) - Is "center of a face" useful in that case, and if so - how would we (as users) use it?
  • Radius: When traversing the tree it is possible to detect "circular" operations - sphere, circle, rotate_extrude - which bring a defined centerpoint and radius at a given vertex. Handling them specially by allowing radius measurements would be nice - but would make that feature unusable for user-defined spheroids (like in BOSL2). Another option would be to allow to select centerpoint/circle point for measurement (making that a vertex-vertex distance operation), or a three-point circle select. Should
  • Cut Plane: a cut line creates arbitrary vertices / edges in the model one can reference to. What would be the best way to design it from our perspective? Like in https://github.com/openscad/openscad/pull/1424?
  • Would the above benefit from introducing things like construction lines / planes? (thereby "real" 2D planes) - or do we suggest using the %-modifier and cube([100, 100, 0.0001], center=true)? It would be nice to have a simple interface to convert some variables into construction lines.

Tomatower avatar Jan 31 '21 10:01 Tomatower

Inspiring ideas y'all.

  • Centerpoints of faces/edges: Yes visually unified faces often is made of several arbitrary co-planar mesh faces. Getting the intended feature by a single click isn't that straight forward with out extra logic. I suggest some responsibility is laid on the user. i.e. Select 2 or more points or features and calculate their average position center of gravity or some other suitable center functions. Little more cumbersome but the benefit is clarity of user intent.
  • Radius: As above, but in circle measure mode, circles and arcs could be indicated by two points as center and radius or by three points on the circumference, a sphere by four points on its surface, combinations of points and tangential edges etc. It can be messy but powerful. The basic points retrieved is a excellent starting point and could easily be extended by user-defined expressions in a little scad script. circumscribed, inscribed. arc length etc probably goes here as an exercise for the student.
  • Cut Plane Interactive cut planes would be amazing but a lot simpler, but more crude, would be to just do plane cuts in user-space. I have example modules for crop_by_Z() , crop_by_plane(), slice_by_plane() and construction plane on github (not library quality though).
  • Would the above benefit from introducing things like Construction primitive s like point() and line(). Are we talking infinite lines or line segments here?
    I have examples of helper module that act as construction_plane on github(not fully constrained plane or library quality).
  • The Netfabb example show graphical dimensions in the view port. I fail to see how that kind of feature could auto update as expected in OpenSCAD. Is there consensus that such feature lies outside a simple measurement tool #3638? I think that thing fits better in a future blueprint /drawings export.

I hesitate to pile on even more ideas. An analog to a laser range finder would be nifty. Query with ray origin and direction and get first (or all) intersection with range, coordinates, feature ID and what-not . Bloat features aside.

What is the minimum viable solution to simple measuring tool? Tape measure and protractor?

TLC123 avatar Jan 31 '21 15:01 TLC123

I’m not sure if the question is directed at me, or if I’m understanding it right. However, yes, I’m basically looking for a “tape measure” and “protractor”/“angle measurer” for the bounty. More than that would be awesome, but I’ve learned from my software days it’s best just to keep things simple at first and get them out quicker than to start a big project that never gets anywhere just because it’s so big :)

west1012 avatar Jan 31 '21 16:01 west1012

Or maybe I should just say “Point in space” measurer? Like you could click on a vertex (or possibly arbitrary points, maybe?), and know that it was at (X, Y, Z) location. With that, I think you could figure just about everything else out, from lengths of edges, to degrees of angle between edges.

west1012 avatar Jan 31 '21 16:01 west1012

A vertex in "graphics-speak" is a xyz-float position - so that was exactly my point above: using color-encoding to find the entity you have clicked on, and as soon as you have this information it is mostly highschool math (plus a good UI/UX!!) to display more context information.

So the hard parts for this feature are:

  • Get a sexy UI/UX on how a measurement is done (see Michaels screenshot above as a nice solution for that)
  • Retrieve the coordinates and entity type from the viewport upon a click (see the mouse selection magic as an example)
  • If we use the 30-bit color selector: check if it supported on all target hardware
  • Set up a testing environment that can verify these kind of interactions

Tomatower avatar Jan 31 '21 17:01 Tomatower

Even simpler and minimal. no dialog or form.

Noting but select and highlight. Click some point edge or face (shift for multi select)

  • it lights up,
  • info is printed on the console,
  • ctrl-c puts the vertex on clipboard.
  • click outside clears highlight. And from there its up to the user to do what ever, I would paste values into a new scad file and get to work on a a geometry-measurements library.

TLC123 avatar Feb 01 '21 04:02 TLC123

Thats all UI/UX for me :)

I would split the mouse selection (to select source-level objects) and measurement (selecting vertices and edges) in source code. When we want to measure we only nee graphics primitives, which can be retrieved from the VBOs, without association to the drawn object.

using gl_VertexID (see https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_VertexID.xhtml) sounds like it could work?

I do not yet have a working Idea on how to generate the colors for the edges and faces that is non-ambiguous, but having a look at gl_PrimitiveID (see https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_PrimitiveIDIn.xhtml) in a geometry shader might be worth a shot. (this will bump us to OpenGL 1.5 - maybe one day we will require opengl 3.3...)

Tomatower avatar Feb 01 '21 11:02 Tomatower

Just checking in. Did people thing this was feasible / yes on a go ahead? I only put down either $200 or $250 on the bounty and a one month time horizon to show that I was serious, but wasn't sure if it was feasible, otherwise I would have put down the whole $500 or more. I'm guessing I will have to renew that bounty when the month is up, as maybe things won't be done by then? Thanks.

west1012 avatar Feb 06 '21 19:02 west1012

I am planning to take this up. I am currently looking at some of the other products for interface ideas.

On Feb 6, 2021, at 2:35 PM, west1012 [email protected] wrote:

Just checking in. Did people thing this was feasible / yes on a go ahead? I only put down either $200 or $250 on the bounty and a one month time horizon to show that I was serious, but wasn't sure if it was feasible, otherwise I would have put down the whole $500 or more. I'm guessing I will have to renew that bounty when the month is up, as maybe things won't be done by then? Thanks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/openscad/openscad/issues/3638#issuecomment-774530412, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGVZBCBG55NFYCN2Z6FKRILS5WKWVANCNFSM4WZ22BZQ.

donc42 avatar Feb 06 '21 20:02 donc42

I am planning to take this up. I am currently looking at some of the other products for interface ideas.

MeshLab has a measuring tool you can take a look at for interface ideas.

mjparme avatar Feb 09 '21 22:02 mjparme

Just wanted to add my thoughts here as well: I'm still very new to OpenSCAD and I love it! That's the first 3D CAD program which I (as being a developer) immediately understood how it works and could start building things productively within half an hour.

The only thing - and that's why I ended up here - I desperately miss is a simply UI tool to measure and thus verify what I have designed in code.

For me even a very simply tool like the one from the free Windows 10 "3D Builder" app would do if just the "snap" feature would work a bit better (and also snaps e. g. to the center of a cylinder) and you could enforce/restrict to vertical/horizontal axis or plane to get a "straight line".

Just like @west1012 wrote not having such a simple measure tool considerable reduces the usefulness of this great program and forces you to often export meshes to use external tools to verify your work which is pretty cumbersome.

Therefore I'm really glad to read here that this is something perhaps being implemented soon! 👍

ab-tools avatar Feb 28 '21 11:02 ab-tools

I've added a bit to the bounty. I'd prefer the intersection method, not the hacky color code ID.

bmuessig avatar May 18 '21 23:05 bmuessig

I would be happy with a simple way of echoing the current [X, Y, Z] something like: translate([a,b,c]) { rotate([ax,ay,az]) { translate([d,e,f]){ echo($X,$Y,$Z); }}}

I can calculate the distances by putting such echo statements at the appropriate places. It would also show that various points are lined up properly.

It would be even better to allow me to set variables to the current position. Simple functions could then calculate distances and angles.

bob-ewart avatar Aug 27 '21 13:08 bob-ewart

Have you considered that the wireframe view already provides numerous points and line segments that could be selected? wireframe

callahanp avatar Sep 29 '21 15:09 callahanp

deleted by author OpenSCAD and MatterControl have a number of bounties which means users are interested in CAD and 3d printing - i'm interested in taking on the challenge of improving CAD software and collecting these bounties - however, to and give user best program-on-the-left visualize-on-the-right experience one needs to step out of current stuck into more powerful tools - we need a new program who takes the best from OpenSCAD and others and adds to it significantly - https://github.com/Sergei-Udris/Calican will be that CAD program, taking step forward - first and most importantly - clojure: Calican will use full unabridged unlimited most powerful language giving user not a script but full a lisp language with REPL to work with - and - that will simplify program as work already done, Calican will just give user the keys and high level functions like OpenSCAD - he will run on JVM - having access to whole ecosystem of libraries for 3d rendering and geometric computation, as of today choice is JOGL and libraries showcased here https://jogamp.org/jogl/www/ - right in the CAD territory - will be built as processes and queues using unmatched clojure/core.async - bringing golang routines power and multiplying it within an REPL-able lisp that runs on JVM with full access to all the goodies

today Calican exposes clojure REPL and just added a 3d canvas on the right with JOGL - first step made

  • next - implementing OpenSCAD amazing examples list and being able to export in at least one format - so Calican will be a born as CAD program
  • then - addressing bounty issues and implementing features like measurement tool
  • work is plenty but exciting and rewarding - as technology of clojure lisp and jvm does not fight against us but is for us

Calican will not be under my namespace nor will i create an organization for him

  • goal is for him to be transferred under an exiting github organization
  • i'm interested in programming him as a bounty-project for an organization - so that i don't waste time on setting up opencollectives and sponsors but am fully focused on features

Sergei-Udris avatar Apr 13 '22 18:04 Sergei-Udris

@Sergei-Udris so what is it? Spamming about other projects or actually discussing the OpenSCAD feature proposed here?

t-paul avatar Apr 13 '22 19:04 t-paul