diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-07-10 03:25:02 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-07-10 03:25:02 +0400 |
commit | 795034c17d76bef2a15e576ac9c70ae2268a823b (patch) | |
tree | 2db44257f626e9e17edfa08ffb39a37ea6ad454f /source/blender | |
parent | 5569a4b282747f693502130f143395f14e6f297d (diff) |
Fix for bug #36009: Rendered ortho view messes up Freestyle lines in 3D viewport.
Clipping start is negative when the viewport preview is used with the orthographic view,
while Freestyle assumes that imported mesh data are in the camera coordinate system
with the view point located at origin. The present solution is to adjust the clipping
start/end and introduce a Z-axis offset for mesh vertices so as to satisfy the assumption.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp | 35 | ||||
-rw-r--r-- | source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h | 1 |
2 files changed, 31 insertions, 5 deletions
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index 2f98a042e27..85956dbcac8 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -22,10 +22,10 @@ * \ingroup freestyle */ -#include <assert.h> - #include "BlenderFileLoader.h" +#include "BLI_utildefines.h" + #include "BKE_global.h" namespace Freestyle { @@ -60,8 +60,23 @@ NodeGroup *BlenderFileLoader::Load() _viewplane_right = _re->viewplane.xmax; _viewplane_bottom = _re->viewplane.ymin; _viewplane_top = _re->viewplane.ymax; - _z_near = -_re->clipsta; - _z_far = -_re->clipend; + + if ((_re->r.scemode & R_VIEWPORT_PREVIEW) && (_re->r.mode & R_ORTHO)) { + // Adjust clipping start/end and set up a Z offset when the viewport preview + // is used with the orthographic view. In this case, _re->clipsta is negative, + // while Freestyle assumes that imported mesh data are in the camera coordinate + // system with the view point located at origin [bug #36009]. + BLI_assert(_re->clipsta < 0.f); + _z_near = -0.001f; + _z_offset = _re->clipsta + _z_near; + _z_far = -_re->clipend + _z_offset; + } + else { + _z_near = -_re->clipsta; + _z_far = -_re->clipend; + _z_offset = 0.f; + } + #if 0 if (G.debug & G_DEBUG_FREESTYLE) { cout << "Frustum: l " << _viewplane_left << " r " << _viewplane_right @@ -225,7 +240,7 @@ void BlenderFileLoader::clipTriangle(int numTris, float triCoords[][3], float v1 } } } - assert(k == 2 + numTris); + BLI_assert(k == 2 + numTris); } void BlenderFileLoader::addTriangle(struct LoaderState *ls, float v1[3], float v2[3], float v3[3], @@ -378,6 +393,11 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id) if (vlr->v4) mul_m4_v3(obi->mat, v4); } + v1[2] += _z_offset; + v2[2] += _z_offset; + v3[2] += _z_offset; + if (vlr->v4) + v4[2] += _z_offset; #if 0 print_v3("v1", v1); print_v3("v2", v2); @@ -472,6 +492,11 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id) if (vlr->v4) mul_m4_v3(obi->mat, v4); } + v1[2] += _z_offset; + v2[2] += _z_offset; + v3[2] += _z_offset; + if (vlr->v4) + v4[2] += _z_offset; if (_smooth && (vlr->flag & R_SMOOTH)) { copy_v3_v3(n1, vlr->v1->n); copy_v3_v3(n2, vlr->v2->n); diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h index 494dd375be0..c505eab40f1 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h @@ -122,6 +122,7 @@ protected: float _viewplane_bottom; float _viewplane_top; float _z_near, _z_far; + float _z_offset; RenderMonitor *_pRenderMonitor; |