Ideas for "Snap to grid"

What would you like to see in future versions of the editor?
Post Reply
iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Ideas for "Snap to grid"

Post by iforce2d » Thu Jun 06, 2013 11:06 am

"Snap to grid" is scoring quite high in the feature voting. I am starting to think about ways to implement it, but since the item types in a Box2D scene are quite different, there does not seem to be any one specific way to handle them all. I'm wondering if people who have something specific in mind could comment here about what would help them out. Mainly I'm looking for people who have actually come across this issue in real situations in the past, rather than a general brainstorm.

Firstly the grid dimensions would need to be defined, which would go in the scene settings dialog, with x,y sizes for grid cells, for each edit mode (body, fixture, vertex, image, joint).

For some edit modes it seems quite straightforward, eg. for bodies, joints and vertices, I guess the position of the body/anchor/vertex could snap to the grid. For fixtures and images though it's not so simple. There does not seem to be any obvious way to align these with a grid, especially fixtures which are not even restricted to being rectangular. Any comments about this would be appreciated.

joolean
Posts: 19
Joined: Mon Jun 24, 2013 7:46 am

Re: Ideas for "Snap to grid"

Post by joolean » Mon Jun 24, 2013 10:05 am

> For fixtures and images though it's not so simple. There does not seem to be any obvious way to align these with a grid

My understanding of snap to grid is simply that whatever you're dragging gets snapped to a grid point. Whether it's fixture vertices, bodies or joints, I don't see what the difference is?

I use this feature in Box2d Body Editor for creating large static fixtures for levels, e.g. mazes. I use arbitrarily shaped polygons but often need various points from different fixtures to line up along the same x/y plane. Without snap to grid, the only way to align them is manually setting the location in the Property panel.

Can you not implement it globally as a modifier to the mouse x/y coordinates if snap to grid is on?

iforce2d
Site Admin
Posts: 860
Joined: Sat Dec 22, 2012 7:20 pm

Re: Ideas for "Snap to grid"

Post by iforce2d » Mon Jun 24, 2013 6:10 pm

joolean wrote:... whatever you're dragging gets snapped to a grid point. Whether it's fixture vertices, bodies or joints, I don't see what the difference is?
The difference is that a body is a single point, which is easy and intuitive to snap to a grid, while a fixture can have hundreds of points.
Take this for example:
spiralFixture.png
spiralFixture.png (18.25 KiB) Viewed 18362 times
It's all very well to say "just snap it to the grid" but how exactly? The only way I can think of is to have every point of the fixture checking for the closest grid-line to itself, and then choose the closest among them. Seems like a reasonable solution, but I was wondering if there was a better way.

You say that you line fixtures up along the same x/y plane... does this involve rotating them? Are we still talking about a grid, or are they being snapped to the position of other fixtures?

Yes, it would be implemented as a modifier to the mouse coordinates.

joolean
Posts: 19
Joined: Mon Jun 24, 2013 7:46 am

Re: Ideas for "Snap to grid"

Post by joolean » Mon Jun 24, 2013 8:05 pm

Ah ok sorry, I see what you mean. When I think of moving fixtures, I was only thinking of individual vertices.
If moving the whole fixture, then your solution of nearest vertex to grid point makes sense. Alternatively, the vertex nearest the mouse point when you start a transpose could be used as the sole anchor to snap to a grid point. I'm sure both use cases would be valid in different situations. The latter would be especially useful for complex polygons which could end up snapping all all over the place.
The same two techniques could be used for rotations and scaling.

Though it would be an order of magnitude more complex, I can see valid use cases for snapping to other vertices/ bodies/ joints as well.

When I was referring to aligning on the xy, I just meant vertices. For example take that image you posted. A common use case would be too make the bottom edge flat and the right edge vertical forming a right angle. Without snap to grid, it's not easy to do.

Jules

bukbukbukark
Posts: 5
Joined: Mon Jul 01, 2013 1:37 am

Re: Ideas for "Snap to grid"

Post by bukbukbukark » Mon Jul 01, 2013 2:30 am

It would be fairly complex to make grid snap cover all the bases.

What I think would work well enough for most cases would be:

- For each item type, have some sensible potentially snappable features, eg vertices, bounding box corners, centre points etc. So a polygon would expose vertices, bounding box corners and centre point. An image would have bounding box corners, actual corners and centre point.
- While the item(s) are selected and before starting the translate, highlight on-screen whichever of these snappable features is closest to the mouse pointer, so the user knows exactly what they're going to get.
- When starting the translate, snap that feature that was closest to the mouse pointer.

I'd love to see options to snap to other items too, eg snap to other vertices or lines in the scene. So you would choose between off, grid, vertex, line etc...

kalium
Posts: 6
Joined: Thu Sep 26, 2013 8:25 pm

Re: Ideas for "Snap to grid"

Post by kalium » Tue Oct 15, 2013 10:11 pm

:idea: There is but one thing I feel is lacking on the "Snap to Grid", "Fixed Increment" and "Snap to X/Y axis" options, is the compatibility with the Add Vertices mode, specially when editing Edge Fixtures to create terrain. Sometimes I just want to make a perfectly flat surface or wall, and I have to either do it with surgical precision or manually align the vertices later using the Vertex Alignment options on the menu.

Post Reply