diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2011-11-20 23:03:52 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2011-11-20 23:03:52 +0400 |
commit | bb9976f058ba2090812074e1b774213d20821a30 (patch) | |
tree | 06156685c53688ca02f4424bb0808510f5afdca4 /source/blender/freestyle | |
parent | 624e91a77a6de9f87fbc5ab5f4ce1ea54d104cdf (diff) |
Fix for duplicated feature edges due to a numerical instability of line
clipping by near/far Z planes.
Problem report by vicentecarro together with a .blend file to reproduce
the issue, thanks!
Diffstat (limited to 'source/blender/freestyle')
-rw-r--r-- | source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index c0aa127b962..1ed1cabf161 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -112,12 +112,22 @@ int BlenderFileLoader::countClippedFaces(float v1[3], float v2[3], float v3[3], // the X and Y components are unknown). void BlenderFileLoader::clipLine(float v1[3], float v2[3], float c[3], float z) { + // Order v1 and v2 by Z values to make sure that clipLine(P, Q, c, z) + // and clipLine(Q, P, c, z) gives exactly the same numerical result. + float *p, *q; + if (v1[2] < v2[2]) { + p = v1; + q = v2; + } else { + p = v2; + q = v1; + } double d[3]; for (int i = 0; i < 3; i++) - d[i] = v2[i] - v1[i]; - double t = (z - v1[2]) / d[2]; - c[0] = v1[0] + t * d[0]; - c[1] = v1[1] + t * d[1]; + d[i] = q[i] - p[i]; + double t = (z - p[2]) / d[2]; + c[0] = p[0] + t * d[0]; + c[1] = p[1] + t * d[1]; c[2] = z; } |