feature: add dual snap mode => vertex + edge #1158
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the ability to snap vertex AND edge. If both are found, vertex are snapped with higher priority. The main purpose of this changes is to do this dual snap picking with only one depth buffer initialisation to improve performance in comparaison of doing two snap picking simultaneously with different snap mode.
API changes : (BEAKING CHANGES)
snapMode
is only used asframeCtx
property.snapVertex: boolean
&snapEdge: boolean
properties instead ofsnapMode
. (In case of both arefalse
, the snapPick falls back to a regular pick withcanvasPos
andpickSurface: true
)snapVertex: boolean
&snapEdge: boolean
arguments instead ofsnapMode
.pickResult
hassnapType
: null|"vertex"|"edge" property instead ofsnappedToVertex: boolean
&snappedToEdge: boolean
.Implementation :
Only
Renderer
logic, no shader update. No changes for mono type snap (only vertex or only edge).On dual type snap,
frameCtx.snapPickLayerParams
stores empty x 1 then the edge layer params first, then empty x 1, then the vertex layer params. The empty x 1 is because thew
of the drawn snap color is 0 if no snap, and if !== 0, represents the layer params number. The second empty x 1 is to make this line works fine (done by theframeCtx.snapPickLayerNumber++
between the twosnapPickDrawSnapDepths
calls):Indeed, if
layerParamsSurface
has a length of 10, pickResultMiddleXY[3] can be 12 if a vertex snap was drawn but thanks to the % it falls back to the 2 index and layerParamsSurface[foundIndex] is notundefined
.Then, this line allow to know if the snap pick is a vertex pick or an edge pick:
Has edge pick are stored on the first half of the
layerParamsSnap
array and vertex pick on the last half.To go further
In case of a snapPick in center position, the previous implementation got the
pickedLayerParmasSurface
from thelayerParamsSurface
(see here) array which is not correct as snap pick params are stored in thelayerParamsSnap
array. But if this is fine, thelayerParamsSnap
may not be really needed as it is the same values as thelayerParamsSurface
array. It may be interesting to simplify this code to only use thelayerParamsSurface
array.