Face snapping fails on Orthographic view #38358

Closed
opened 2014-01-25 02:08:03 +01:00 by Daniel Salazar · 17 comments
Member

System Information

openSUSE 12.3 64bits
NVIDIA 480GTX SC

Blender Version

Broken: Blender 2.69.10 c0a4089

Short description of error

Face snapping in Blender fails constantly on Orthographic view. Basically it snaps to the back faces of the model.

This problem has always existed in the raytraced snapping. I never reported it because I thought it was unfortunate but normal since I always work in orthographic mode. However I just recently noticed how in perspective mode it works flawlessly!

Exact steps for others to reproduce the error
Open Snap.blend
Slowly move X arrow to the right
Suddenly the vertex snaps to the back surface!

**System Information** openSUSE 12.3 64bits NVIDIA 480GTX SC **Blender Version** Broken: Blender 2.69.10 c0a4089 **Short description of error** Face snapping in Blender fails constantly on Orthographic view. Basically it snaps to the back faces of the model. This problem has always existed in the raytraced snapping. I never reported it because I thought it was unfortunate but normal since I always work in orthographic mode. However I just recently noticed how in perspective mode it works flawlessly! **Exact steps for others to reproduce the error** Open [Snap.blend](https://archive.blender.org/developer/F75361/Snap.blend) Slowly move X arrow to the right Suddenly the vertex snaps to the back surface!
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @zanqdo

Added subscriber: @zanqdo

Added subscriber: @mont29

Added subscriber: @mont29

Added subscribers: @ideasman42, @brecht

Added subscribers: @ideasman42, @brecht

Ok, so issue seems to be in ray/tri intersection code… I made some prints (the cursor is over face 3641, but very close to the boundary with face 3640, ~0.001BU away), r_loc is the intersection point found (i.e. the result):

Good result (i.e. intersection with face 3641 detected):

face: 3640
u: 0.404586 (must be in [-0.000000, 1.000000])
v: 0.765669 (must be above -0.000000), u+v: 1.170255 (must be below 1.000000)
u: 1.141845 (must be in [-0.000000, 1.000000])
v: -0.402490 (must be above -0.000000), u+v: 0.739356 (must be below 1.000000)
face: 3641
u: 0.191688 (must be in [-0.000000, 1.000000])
v: 0.004357 (must be above -0.000000), u+v: 0.196044 (must be below 1.000000)
u: 0.260908 (must be in [-0.000000, 1.000000])
v: -0.243514 (must be above -0.000000), u+v: 0.017394 (must be below 1.000000)
r_loc: 0.049 -0.083 1.501

Next check (just a tad closer to boundary, but still over 3641): bad result (i.e. intersection with neither face 3641 nor 3640 detected):

face: 3640
u: 0.369783 (must be in [-0.000000, 1.000000])
v: 0.748267 (must be above -0.000000), u+v: 1.118050 (must be below 1.000000)
u: 1.071847 (must be in [-0.000000, 1.000000])
v: -0.402490 (must be above -0.000000), u+v: 0.669358 (must be below 1.000000)
face: 3641
u: 0.261392 (must be in [-0.000000, 1.000000])
v: -0.043565 (must be above -0.000000), u+v: 0.217827 (must be below 1.000000)
u: 0.260908 (must be in [-0.000000, 1.000000])
v: -0.260908 (must be above -0.000000), u+v: 0.000000 (must be below 1.000000)
face: 2503
u: 5.999137 (must be in [-0.000000, 1.000000])
v: -5.372747 (must be above -0.000000), u+v: 0.626390 (must be below 1.000000)
u: 0.583749 (must be in [-0.000000, 1.000000])
v: -4.967376 (must be above -0.000000), u+v: -4.383627 (must be below 1.000000)
[goes on checking a bunch of other faces of the "far side"...]
face: 2871
u: -0.633059 (must be in [-0.000000, 1.000000])
v: 0.801875 (must be above -0.000000), u+v: 0.168816 (must be below 1.000000)
u: 0.325691 (must be in [-0.000000, 1.000000])
v: 0.582087 (must be above -0.000000), u+v: 0.907778 (must be below 1.000000)
r_loc: -0.073 0.012 1.523

As far as I can see, it’s another stupid precision issue, I’d say caused by the fact that the org point of ray in ortho view is rather far away (~ 940BU here), while in perspective it is much closer. This is due to ED_view3d_win_to_segment() (in view3d_project.c), which places org point at 1000 when in ortho view. Setting this value to e.g. 10.0f indeed fixes the issue.

Not sure what we can/want to do here, perhaps switch to double, @brecht, @ideasman42, ideas?

Ok, so issue seems to be in ray/tri intersection code… I made some prints (the cursor is over face 3641, but very close to the boundary with face 3640, ~0.001BU away), r_loc is the intersection point found (i.e. the result): Good result (i.e. intersection with face 3641 detected): ``` face: 3640 u: 0.404586 (must be in [-0.000000, 1.000000]) v: 0.765669 (must be above -0.000000), u+v: 1.170255 (must be below 1.000000) u: 1.141845 (must be in [-0.000000, 1.000000]) v: -0.402490 (must be above -0.000000), u+v: 0.739356 (must be below 1.000000) face: 3641 u: 0.191688 (must be in [-0.000000, 1.000000]) v: 0.004357 (must be above -0.000000), u+v: 0.196044 (must be below 1.000000) u: 0.260908 (must be in [-0.000000, 1.000000]) v: -0.243514 (must be above -0.000000), u+v: 0.017394 (must be below 1.000000) r_loc: 0.049 -0.083 1.501 ``` Next check (just a tad closer to boundary, but still over 3641): bad result (i.e. intersection with neither face 3641 nor 3640 detected): ``` face: 3640 u: 0.369783 (must be in [-0.000000, 1.000000]) v: 0.748267 (must be above -0.000000), u+v: 1.118050 (must be below 1.000000) u: 1.071847 (must be in [-0.000000, 1.000000]) v: -0.402490 (must be above -0.000000), u+v: 0.669358 (must be below 1.000000) face: 3641 u: 0.261392 (must be in [-0.000000, 1.000000]) v: -0.043565 (must be above -0.000000), u+v: 0.217827 (must be below 1.000000) u: 0.260908 (must be in [-0.000000, 1.000000]) v: -0.260908 (must be above -0.000000), u+v: 0.000000 (must be below 1.000000) face: 2503 u: 5.999137 (must be in [-0.000000, 1.000000]) v: -5.372747 (must be above -0.000000), u+v: 0.626390 (must be below 1.000000) u: 0.583749 (must be in [-0.000000, 1.000000]) v: -4.967376 (must be above -0.000000), u+v: -4.383627 (must be below 1.000000) [goes on checking a bunch of other faces of the "far side"...] face: 2871 u: -0.633059 (must be in [-0.000000, 1.000000]) v: 0.801875 (must be above -0.000000), u+v: 0.168816 (must be below 1.000000) u: 0.325691 (must be in [-0.000000, 1.000000]) v: 0.582087 (must be above -0.000000), u+v: 0.907778 (must be below 1.000000) r_loc: -0.073 0.012 1.523 ``` As far as I can see, it’s another stupid precision issue, I’d say caused by the fact that the org point of ray in ortho view is rather far away (~ 940BU here), while in perspective it is much closer. This is due to `ED_view3d_win_to_segment()` (in view3d_project.c), which places org point at 1000 when in ortho view. Setting this value to e.g. 10.0f indeed fixes the issue. Not sure what we can/want to do here, perhaps switch to double, @brecht, @ideasman42, ideas?
Bastien Montagne self-assigned this 2014-01-27 15:31:59 +01:00

Doubles would be enough to solve this problem I think, they need to propagate pretty far then though since snapping uses a BVH tree and all that code uses floats.

Another possibility would be to to return different values than ray start/end position from ED_view3d_win_to_segment. In madd_v3_v3v3fl(r_ray_start, vec, rv3d->viewinv- [x], 1000.0f); it does small value vec + large value rv3d->viewinv- [x] * 1000.0f, which causes the small value to be rounded away and precision lost.

If you return a ray position (vec), ray direction (rv3d->viewinv- [x]) and ray start/end distance (1000.0f and -1000.0f) and use those directly in the intersection function, then you would avoid the precision issue here.

If you're lucky you can just modify ED_view3d_win_to_ray to use those values and it works, by getting a more accurate ray direction, but I'm not sure it's enough.

If it's not enough, you end up with a similar issue as doubles though, in that you'll need to modify more code. You would need to carefully ensure the snapping/BVH code can handle a ray distance start/end range with the start distance negative, instead of just a single positive distance starting from 0.0 at the ray start.

Doubles would be enough to solve this problem I think, they need to propagate pretty far then though since snapping uses a BVH tree and all that code uses floats. Another possibility would be to to return different values than ray start/end position from `ED_view3d_win_to_segment`. In `madd_v3_v3v3fl(r_ray_start, vec, rv3d->viewinv- [x], 1000.0f);` it does small value `vec` + large value `rv3d->viewinv- [x] * 1000.0f`, which causes the small value to be rounded away and precision lost. If you return a ray position (`vec`), ray direction (`rv3d->viewinv- [x]`) and ray start/end distance (`1000.0f` and `-1000.0f`) and use those directly in the intersection function, then you would avoid the precision issue here. If you're lucky you can just modify `ED_view3d_win_to_ray` to use those values and it works, by getting a more accurate ray direction, but I'm not sure it's enough. If it's not enough, you end up with a similar issue as doubles though, in that you'll need to modify more code. You would need to carefully ensure the snapping/BVH code can handle a ray distance start/end range with the start distance negative, instead of just a single positive distance starting from 0.0 at the ray start.

Thanks for those hints, @brecht.

I can confirm having a better dir is not enough to fix the issue… I’ll have a look at modifying bvh & co to handle orco + offset, and also check knife code more in depth (Howard had a similar issue, which he fixed by bounding min/max to the object's limits… would avoid me the need to modify bvh & co). No small change in any case.

Thanks for those hints, @brecht. I can confirm having a better dir is not enough to fix the issue… I’ll have a look at modifying bvh & co to handle orco + offset, and also check knife code more in depth (Howard had a similar issue, which he fixed by bounding min/max to the object's limits… would avoid me the need to modify bvh & co). No small change in any case.

This issue was referenced by blender/blender-addons-contrib@77089a3bf2

This issue was referenced by blender/blender-addons-contrib@77089a3bf20319be87a434750656206449c04dbc

This issue was referenced by 77089a3bf2

This issue was referenced by 77089a3bf20319be87a434750656206449c04dbc

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Closed by commit 77089a3bf2.

Closed by commit 77089a3bf2.
Author
Member

@mont29 That's awesome, game changer for me! However my original test file Snap.blend stopped working for some reason! It wont snap. I can't reproduce in a new file tough.

@mont29 That's awesome, game changer for me! However my original test file [Snap.blend](https://archive.blender.org/developer/F75361/Snap.blend) stopped working for some reason! It wont snap. I can't reproduce in a new file tough.

Changed status from 'Resolved' to: 'Open'

Changed status from 'Resolved' to: 'Open'

This issue was referenced by blender/blender-addons-contrib@810c6d1880

This issue was referenced by blender/blender-addons-contrib@810c6d1880b9cb2944ab2bcb5eb60d8dedd97a64

This issue was referenced by 810c6d1880

This issue was referenced by 810c6d1880b9cb2944ab2bcb5eb60d8dedd97a64

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Closed by commit 810c6d1880.

Closed by commit 810c6d1880.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#38358
No description provided.