Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 92dcaf2

Browse files
author
Release Manager
committed
Trac #30613: Fix clipping issue for plots with small/large extents in Three.js
Plots that are very small/large in world-space coordinates can run into clipping issues with the default near and far clipping distances set in the Three.js viewer. For example, the large "cool self-intersecting surface (Eppener surface?)" near the bottom of the documentation for [https://doc.sagemat h.org/html/en/reference/plot3d/sage/plot/plot3d/parametric_plot3d.html Parametric Plots] appears completely blank due to far clipping: {{{ #!python sage: var('u,v') sage: f_x = u - u^3/3 + u*v^2 sage: f_y = v - v^3/3 + v*u^2 sage: f_z = u^2 - v^2 sage: parametric_plot3d([f_x, f_y, f_z], (u,-25,25), (v,-25,25), plot_points=[50,50], frame=False, color="green") Graphics3d Object }}} ...and the following small plot appears empty due to near clipping: {{{ #!python dodecahedron().scale(1/1000) }}} This ticket proposes to fix this problem by scaling both the near and far clipping distances based on the overall size of the plot in world- space coordinates. URL: https://trac.sagemath.org/30613 Reported by: gh-jcamp0x2a Ticket author(s): Joshua Campbell Reviewer(s): Eric Gourgoulhon
2 parents 16741ff + cb818f8 commit 92dcaf2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/sage/ext_data/threejs/threejs_template.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,17 @@
211211

212212
var aspect = window.innerWidth / window.innerHeight;
213213

214+
// Scale the near and far clipping planes along with the overall plot size.
215+
var nearClip = 0.01 * midToCorner;
216+
var farClip = 100 * midToCorner;
217+
214218
if ( options.projection === 'orthographic' ) {
215-
var camera = new THREE.OrthographicCamera( -1, 1, 1, -1, -1000, 1000 );
219+
var camera = new THREE.OrthographicCamera( -1, 1, 1, -1, -farClip, farClip );
216220
updateCameraAspect( camera, aspect );
217221
return camera;
218222
}
219223

220-
return new THREE.PerspectiveCamera( 45, aspect, 0.1, 1000 );
224+
return new THREE.PerspectiveCamera( 45, aspect, nearClip, farClip );
221225

222226
}
223227

0 commit comments

Comments
 (0)