sabresaurus / SabreCSG

Level design tools for Unity
MIT License
1.37k stars 137 forks source link

Draw tool does not snap to grid correctly #219

Open jmickle66666666 opened 5 years ago

jmickle66666666 commented 5 years ago

sabredraw2

When using the Draw tool, it is snapping to the correct grid size, but not the global position of the grid properly. The Vertex tool and other tools match up with the projected grid perfectly but the draw tool doesn't.

damagefilter commented 5 years ago

It's because the tool tries to account for angled surfaces to attach cleanly to them. It would snap the position in local space rather than the global grid.

Snapping the hit point to the global grid will cause hovering brushes on planes that are not on the grid.

Supposedly, one could work out a check for the surface normal we're attaching to and if it's a straight cardinal direction use a global snap, otherwise keep the local snap to prevent a brush from hovering.

Or alternatively throw away the clean attaching to angled surfaces when grid snapping is enabled and force it to the global grid at all times.

jmickle66666666 commented 5 years ago

The grid corners you can see on the gif are worldspace grid coordinates that exist on the plane, snapping to the global grid does not mean the points would float in space.

jmickle66666666 commented 5 years ago

At the very least it would be incredibly useful to be able to choose to switch between plane-grid and global grid when using the draw tool. Using the draw tool on angled surfaces without drawing on the world grid makes the resulting geometry really unwieldy.

damagefilter commented 5 years ago

What I mean is, if we are to snap the vertex points when drawing to a global grid, they will not attach to a plane that is not intersecting the grid, like here. image

Of course, if that plane is intersecting the grid then there is no issue, image

I suppose that's a bit too naive for snapping. So I figured, perhaps we can find another approach. Maybe only snap 2 components of the hitpoint vector. Something along those lines ...

jmickle66666666 commented 5 years ago

Yeah that's basically what i'm getting at. I understand the current snapping logic but I think it's less useful (in my experience) than the 2 axes system the projected grid represents

jmickle66666666 commented 5 years ago

sabrecgrid even on an axis-aligned surface the grid is offset

damagefilter commented 5 years ago

Yeah. I have noticed that too and fixed that bit for sure.

But the slopes ... I had two versions. One where it would be on-grid on slopes but would not attach to the surface. (It would snap to points below or beneath the surfaces plane on odd angles, the usual)) One where it would attach to the surface but remain off-grid.

Can't seem to wrap my head around that part :C

Point being, I could drop some code and maybe 2 brains can do more than one? Specifically if one of em is my brain. Ain't exactly fluid in maths. Hehe.

Henry00IS commented 5 years ago

@jmickle66666666 is currently working on adding concave shape support to the draw tool as well. You may wish to speak with her before you both end up accidentally fixing the same issue. 😁

jmickle66666666 commented 5 years ago

i actually managed to sort out the grid alignment stuff. i should take that out into a new branch first before doing the concave stuff, since that's gonna be more difficult

damagefilter commented 5 years ago

Yes that's why I said the thing with the 2 brains, so we could perhaps look into that together. Since @jmickle66666666 got a fix for it now though, I'm excited for how the solution looks like.